diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d342a2e..b695dd6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -113,6 +113,7 @@ set(SOURCES playlist/playlisttabbar.cpp playlist/playlistundocommands.cpp playlist/playlistview.cpp + playlist/playlistproxystyle.cpp playlist/songloaderinserter.cpp playlist/songplaylistitem.cpp playlist/dynamicplaylistcontrols.cpp @@ -359,6 +360,7 @@ set(HEADERS playlist/playlistsequence.h playlist/playlisttabbar.h playlist/playlistview.h + playlist/playlistproxystyle.h playlist/playlistitemmimedata.h playlist/songloaderinserter.h playlist/songmimedata.h diff --git a/src/playlist/playlistproxystyle.cpp b/src/playlist/playlistproxystyle.cpp new file mode 100644 index 00000000..fbfc2d6e --- /dev/null +++ b/src/playlist/playlistproxystyle.cpp @@ -0,0 +1,71 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * Copyright 2018-2023, Jonas Kvinge + * + * Strawberry is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Strawberry is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Strawberry. If not, see . + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include "playlistproxystyle.h" +#include "playlist.h" + +PlaylistProxyStyle::PlaylistProxyStyle(const QString &style) : QProxyStyle(style), common_style_(new QCommonStyle) {} + +void PlaylistProxyStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { + + if (element == CE_HeaderLabel) { + const QStyleOptionHeader *header_option = qstyleoption_cast(option); + const QRect &rect = header_option->rect; + const QString &text = header_option->text; + const QFontMetrics &font_metrics = header_option->fontMetrics; + + // Spaces added to make transition less abrupt + if (rect.width() < font_metrics.horizontalAdvance(text + " ")) { + const Playlist::Column column = static_cast(header_option->section); + QStyleOptionHeader new_option(*header_option); + new_option.text = Playlist::abbreviated_column_name(column); + QProxyStyle::drawControl(element, &new_option, painter, widget); + return; + } + } + + if (element == CE_ItemViewItem) { + common_style_->drawControl(element, option, painter, widget); + } + else { + QProxyStyle::drawControl(element, option, painter, widget); + } + +} + +void PlaylistProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { + + if (element == QStyle::PE_PanelItemViewRow || element == QStyle::PE_PanelItemViewItem) { + common_style_->drawPrimitive(element, option, painter, widget); + } + else { + QProxyStyle::drawPrimitive(element, option, painter, widget); + } + +} diff --git a/src/playlist/playlistproxystyle.h b/src/playlist/playlistproxystyle.h new file mode 100644 index 00000000..4bc51228 --- /dev/null +++ b/src/playlist/playlistproxystyle.h @@ -0,0 +1,53 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * Copyright 2018-2023, Jonas Kvinge + * + * Strawberry is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Strawberry is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Strawberry. If not, see . + * + */ + +#ifndef PLAYLISTPROXYSTYLE_H +#define PLAYLISTPROXYSTYLE_H + +#include "config.h" + +#include +#include +#include + +#include "core/scoped_ptr.h" + +class QPainter; + +// This proxy style works around a bug/feature introduced in Qt 4.7's QGtkStyle +// that uses Gtk to paint row backgrounds, ignoring any custom brush or palette the caller set in the QStyleOption. +// That breaks our currently playing track animation, which relies on the background painted by Qt to be transparent. +// This proxy style uses QCommonStyle to paint the affected elements. + +class PlaylistProxyStyle : public QProxyStyle { + Q_OBJECT + + public: + explicit PlaylistProxyStyle(const QString &style); + + void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; + void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; + + private: + ScopedPtr common_style_; +}; + +#endif // PLAYLISTPROXYSTYLE_H diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index a6e988da..47c7662c 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -32,8 +32,6 @@ #include #include #include -#include -#include #include #include #include @@ -55,9 +53,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -73,6 +69,7 @@ #include "playlistheader.h" #include "playlistview.h" #include "playlistfilter.h" +#include "playlistproxystyle.h" #include "covermanager/currentalbumcoverloader.h" #include "covermanager/albumcoverloaderresult.h" #include "settings/appearancesettingspage.h" @@ -88,46 +85,6 @@ const int PlaylistView::kAutoscrollGraceTimeout = 30; // seconds const int PlaylistView::kDropIndicatorWidth = 2; const int PlaylistView::kDropIndicatorGradientWidth = 5; -PlaylistProxyStyle::PlaylistProxyStyle(const QString &style) : QProxyStyle(style), common_style_(new QCommonStyle) {} - -void PlaylistProxyStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { - - if (element == CE_HeaderLabel) { - const QStyleOptionHeader *header_option = qstyleoption_cast(option); - const QRect &rect = header_option->rect; - const QString &text = header_option->text; - const QFontMetrics &font_metrics = header_option->fontMetrics; - - // Spaces added to make transition less abrupt - if (rect.width() < font_metrics.horizontalAdvance(text + " ")) { - const Playlist::Column column = static_cast(header_option->section); - QStyleOptionHeader new_option(*header_option); - new_option.text = Playlist::abbreviated_column_name(column); - QProxyStyle::drawControl(element, &new_option, painter, widget); - return; - } - } - - if (element == CE_ItemViewItem) { - common_style_->drawControl(element, option, painter, widget); - } - else { - QProxyStyle::drawControl(element, option, painter, widget); - } - -} - -void PlaylistProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { - - if (element == QStyle::PE_PanelItemViewRow || element == QStyle::PE_PanelItemViewItem) { - common_style_->drawPrimitive(element, option, painter, widget); - } - else { - QProxyStyle::drawPrimitive(element, option, painter, widget); - } - -} - PlaylistView::PlaylistView(QWidget *parent) : QTreeView(parent), app_(nullptr), diff --git a/src/playlist/playlistview.h b/src/playlist/playlistview.h index de519d82..511ec75d 100644 --- a/src/playlist/playlistview.h +++ b/src/playlist/playlistview.h @@ -40,12 +40,9 @@ #include #include #include -#include #include #include -#include -#include "core/scoped_ptr.h" #include "core/song.h" #include "covermanager/albumcoverloaderresult.h" #include "settings/appearancesettingspage.h" @@ -72,27 +69,10 @@ class QTimerEvent; class Application; class CollectionBackend; class PlaylistHeader; +class PlaylistProxyStyle; class DynamicPlaylistControls; class RatingItemDelegate; -// This proxy style works around a bug/feature introduced in Qt 4.7's QGtkStyle -// that uses Gtk to paint row backgrounds, ignoring any custom brush or palette the caller set in the QStyleOption. -// That breaks our currently playing track animation, which relies on the background painted by Qt to be transparent. -// This proxy style uses QCommonStyle to paint the affected elements. -// This class is used by internet search view as well. -class PlaylistProxyStyle : public QProxyStyle { - Q_OBJECT - - public: - explicit PlaylistProxyStyle(const QString &style); - - void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; - void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; - - private: - ScopedPtr common_style_; -}; - class PlaylistView : public QTreeView { Q_OBJECT