Move PlaylistProxyStyle to it's own file
This commit is contained in:
parent
52ba1ce17f
commit
395d85c1b4
|
@ -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
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2023, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QProxyStyle>
|
||||
#include <QString>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionHeader>
|
||||
#include <QFontMetrics>
|
||||
|
||||
#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<const QStyleOptionHeader*>(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<Playlist::Column>(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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018-2023, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PLAYLISTPROXYSTYLE_H
|
||||
#define PLAYLISTPROXYSTYLE_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QProxyStyle>
|
||||
#include <QCommonStyle>
|
||||
#include <QString>
|
||||
|
||||
#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<QCommonStyle> common_style_;
|
||||
};
|
||||
|
||||
#endif // PLAYLISTPROXYSTYLE_H
|
|
@ -32,8 +32,6 @@
|
|||
#include <QTreeView>
|
||||
#include <QHeaderView>
|
||||
#include <QClipboard>
|
||||
#include <QCommonStyle>
|
||||
#include <QFontMetrics>
|
||||
#include <QKeySequence>
|
||||
#include <QMimeData>
|
||||
#include <QMetaType>
|
||||
|
@ -55,9 +53,7 @@
|
|||
#include <QPoint>
|
||||
#include <QRect>
|
||||
#include <QRegion>
|
||||
#include <QStyleOptionHeader>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QProxyStyle>
|
||||
#include <QLinearGradient>
|
||||
#include <QScrollBar>
|
||||
#include <QtEvents>
|
||||
|
@ -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<const QStyleOptionHeader*>(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<Playlist::Column>(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),
|
||||
|
|
|
@ -40,12 +40,9 @@
|
|||
#include <QRect>
|
||||
#include <QRegion>
|
||||
#include <QStyleOption>
|
||||
#include <QProxyStyle>
|
||||
#include <QPoint>
|
||||
#include <QBasicTimer>
|
||||
#include <QCommonStyle>
|
||||
|
||||
#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<QCommonStyle> common_style_;
|
||||
};
|
||||
|
||||
class PlaylistView : public QTreeView {
|
||||
Q_OBJECT
|
||||
|
||||
|
|
Loading…
Reference in New Issue