diff --git a/lib/thumbnailview/contextbarbutton.h b/lib/thumbnailview/contextbarbutton.h --- a/lib/thumbnailview/contextbarbutton.h +++ b/lib/thumbnailview/contextbarbutton.h @@ -18,17 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ - -/* - ***************************************************** - ****************************************************** - **** NOTE: This class is deprecated. Do not use it. ** - **** It will be removed in the QT 6 timeframe. ** - ****************************************************** - ****************************************************** -*/ - - #ifndef CONTEXTBARBUTTON_H #define CONTEXTBARBUTTON_H @@ -54,7 +43,8 @@ ~ContextBarButton(); protected: - void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; + void changeEvent(QEvent *e) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; private: ContextBarButtonPrivate* const d; diff --git a/lib/thumbnailview/contextbarbutton.cpp b/lib/thumbnailview/contextbarbutton.cpp --- a/lib/thumbnailview/contextbarbutton.cpp +++ b/lib/thumbnailview/contextbarbutton.cpp @@ -18,17 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ - -/* - ***************************************************** - ****************************************************** - **** NOTE: This class is deprecated. Do not use it. ** - **** It will be removed in the QT 6 timeframe. ** - ****************************************************** - ****************************************************** -*/ - - // Self #include "contextbarbutton.h" @@ -41,10 +30,13 @@ // Qt #include #include +#include namespace Gwenview { +// KF6 TODO: remove constants + /** How lighter is the border of context bar buttons */ const int CONTEXTBAR_BORDER_LIGHTNESS = 140; @@ -59,61 +51,41 @@ struct ContextBarButtonPrivate { + QString mIconName; }; ContextBarButton::ContextBarButton(const QString& iconName, QWidget* parent) : QToolButton(parent) , d(new ContextBarButtonPrivate) { + d->mIconName = iconName; + + // SmallIcon(...) is not enough when using the "Fusion" widget style + // KF6 TODO: remove if fixed upstream const int size = KIconLoader::global()->currentSize(KIconLoader::Small); setIconSize(QSize(size, size)); - setAutoRaise(true); - setIcon(SmallIcon(iconName)); + + setIcon(SmallIcon(d->mIconName)); } ContextBarButton::~ContextBarButton() { delete d; } -void Gwenview::ContextBarButton::paintEvent(QPaintEvent*) +void ContextBarButton::changeEvent(QEvent *e) { - QStylePainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - QStyleOptionToolButton opt; - initStyleOption(&opt); - - const QColor bgColor = palette().color(backgroundRole()); - QColor color = bgColor.dark(CONTEXTBAR_BACKGROUND_DARKNESS); - QColor borderColor = bgColor.light(CONTEXTBAR_BORDER_LIGHTNESS); - - if (opt.state & QStyle::State_MouseOver && opt.state & QStyle::State_Enabled) { - color = color.light(CONTEXTBAR_MOUSEOVER_LIGHTNESS); - borderColor = borderColor.light(CONTEXTBAR_MOUSEOVER_LIGHTNESS); - } - - const QRectF rectF = QRectF(opt.rect).adjusted(0.5, 0.5, -0.5, -0.5); - const QPainterPath path = PaintUtils::roundedRectangle(rectF, CONTEXTBAR_RADIUS); - - // Background - painter.fillPath(path, color); - - // Top shadow - QLinearGradient gradient(rectF.topLeft(), rectF.topLeft() + QPoint(0, 5)); - gradient.setColorAt(0, QColor::fromHsvF(0, 0, 0, .3)); - gradient.setColorAt(1, Qt::transparent); - painter.fillPath(path, gradient); + QToolButton::changeEvent(e); - // Left shadow - gradient.setFinalStop(rectF.topLeft() + QPoint(5, 0)); - painter.fillPath(path, gradient); - - // Border - painter.setPen(borderColor); - painter.drawPath(path); + if (e->type() == QEvent::PaletteChange) { + setIcon(SmallIcon(d->mIconName)); + } +} - // Content - painter.drawControl(QStyle::CE_ToolButtonLabel, opt); +// KF6 TODO: remove +void Gwenview::ContextBarButton::paintEvent(QPaintEvent *e) +{ + QToolButton::paintEvent(e); } } // namespace diff --git a/lib/thumbnailview/previewitemdelegate.cpp b/lib/thumbnailview/previewitemdelegate.cpp --- a/lib/thumbnailview/previewitemdelegate.cpp +++ b/lib/thumbnailview/previewitemdelegate.cpp @@ -37,7 +37,6 @@ #include #include #include -#include // KDE #include @@ -49,6 +48,7 @@ // Local #include "archiveutils.h" +#include "contextbarbutton.h" #include "itemeditor.h" #include "paintutils.h" #include "thumbnailview.h" @@ -610,20 +610,16 @@ d->mContextBar = new QWidget(d->mView->viewport()); d->mContextBar->hide(); - d->mToggleSelectionButton = new QToolButton; - d->mToggleSelectionButton->setIcon(SmallIcon("list-add")); + d->mToggleSelectionButton = new ContextBarButton("list-add"); connect(d->mToggleSelectionButton, &QToolButton::clicked, this, &PreviewItemDelegate::slotToggleSelectionClicked); - d->mFullScreenButton = new QToolButton; - d->mFullScreenButton->setIcon(SmallIcon("view-fullscreen")); + d->mFullScreenButton = new ContextBarButton("view-fullscreen"); connect(d->mFullScreenButton, &QToolButton::clicked, this, &PreviewItemDelegate::slotFullScreenClicked); - d->mRotateLeftButton = new QToolButton; - d->mRotateLeftButton->setIcon(SmallIcon("object-rotate-left")); + d->mRotateLeftButton = new ContextBarButton("object-rotate-left"); connect(d->mRotateLeftButton, &QToolButton::clicked, this, &PreviewItemDelegate::slotRotateLeftClicked); - d->mRotateRightButton = new QToolButton; - d->mRotateRightButton->setIcon(SmallIcon("object-rotate-right")); + d->mRotateRightButton = new ContextBarButton("object-rotate-right"); connect(d->mRotateRightButton, &QToolButton::clicked, this, &PreviewItemDelegate::slotRotateRightClicked); QHBoxLayout* layout = new QHBoxLayout(d->mContextBar); @@ -635,8 +631,7 @@ layout->addWidget(d->mRotateRightButton); // Save button - d->mSaveButton = new QToolButton(d->mView->viewport()); - d->mSaveButton->setIcon(SmallIcon("document-save")); + d->mSaveButton = new ContextBarButton("document-save", d->mView->viewport()); d->mSaveButton->hide(); connect(d->mSaveButton, &QToolButton::clicked, this, &PreviewItemDelegate::slotSaveClicked); } diff --git a/lib/thumbnailview/thumbnailbarview.cpp b/lib/thumbnailview/thumbnailbarview.cpp --- a/lib/thumbnailview/thumbnailbarview.cpp +++ b/lib/thumbnailview/thumbnailbarview.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -44,6 +43,7 @@ #include "lib/hud/hudtheme.h" #include "lib/paintutils.h" #include "lib/thumbnailview/abstractthumbnailviewhelper.h" +#include "lib/thumbnailview/contextbarbutton.h" namespace Gwenview { @@ -73,17 +73,16 @@ ThumbnailBarItemDelegate* q; ThumbnailView* mView; - QToolButton* mToggleSelectionButton; + ContextBarButton* mToggleSelectionButton; QColor mBorderColor; QPersistentModelIndex mIndexUnderCursor; void setupToggleSelectionButton() { - mToggleSelectionButton = new QToolButton(mView->viewport()); - mToggleSelectionButton->setIcon(SmallIcon("list-add")); + mToggleSelectionButton = new ContextBarButton("list-add", mView->viewport()); mToggleSelectionButton->hide(); - QObject::connect(mToggleSelectionButton, &QToolButton::clicked, q, &ThumbnailBarItemDelegate::toggleSelection); + QObject::connect(mToggleSelectionButton, &ContextBarButton::clicked, q, &ThumbnailBarItemDelegate::toggleSelection); } void showToolTip(QHelpEvent* helpEvent)