From 793bd00cb6cd8254147765f2be000681e4c3df04 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 14 Jun 2020 14:56:03 +0200 Subject: [PATCH] Avoid repeating default pixmap size of IconButton all over the place --- widgets/buttonoverlay.cpp | 8 ++++---- widgets/iconbutton.cpp | 2 +- widgets/iconbutton.h | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/widgets/buttonoverlay.cpp b/widgets/buttonoverlay.cpp index ce2217d..f35d280 100644 --- a/widgets/buttonoverlay.cpp +++ b/widgets/buttonoverlay.cpp @@ -138,8 +138,8 @@ void ButtonOverlay::setClearButtonEnabled(bool enabled) // enable clear button m_clearButton = new IconButton; m_clearButton->setHidden(isCleared()); - m_clearButton->setPixmap(QIcon::fromTheme(QStringLiteral("edit-clear")).pixmap(16)); - m_clearButton->setGeometry(0, 0, 16, 16); + m_clearButton->setPixmap(QIcon::fromTheme(QStringLiteral("edit-clear")).pixmap(IconButton::defaultPixmapSize)); + m_clearButton->setGeometry(QRect(QPoint(), IconButton::defaultPixmapSize)); m_clearButton->setToolTip(QObject::tr("Clear")); QObject::connect(m_clearButton, &IconButton::clicked, std::bind(&ButtonOverlay::handleClearButtonClicked, this)); m_buttonLayout->addWidget(m_clearButton); @@ -167,7 +167,7 @@ void ButtonOverlay::enableInfoButton(const QPixmap &pixmap, const QString &infoT auto *infoButton = static_cast(m_infoButtonOrAction); if (!infoButton) { m_infoButtonOrAction = infoButton = new IconButton; - infoButton->setGeometry(0, 0, 16, 16); + infoButton->setGeometry(QRect(QPoint(), IconButton::defaultPixmapSize)); QObject::connect(infoButton, &IconButton::clicked, std::bind(&ButtonOverlay::showInfo, this)); if (m_clearButton) { m_buttonLayout->insertWidget(m_buttonLayout->count() - 2, infoButton); @@ -332,7 +332,7 @@ void ButtonOverlay::fallbackToUsingCustomLayout() if ((iconAction = static_cast(m_infoButtonOrAction))) { const auto icon = iconAction->icon(); const auto sizes = icon.availableSizes(); - infoPixmap = icon.pixmap(sizes.empty() ? QSize(16, 16) : sizes.front()); + infoPixmap = icon.pixmap(sizes.empty() ? IconButton::defaultPixmapSize : sizes.front()); infoText = iconAction->toolTip(); disableInfoButton(); } diff --git a/widgets/iconbutton.cpp b/widgets/iconbutton.cpp index 54cd043..fde1958 100644 --- a/widgets/iconbutton.cpp +++ b/widgets/iconbutton.cpp @@ -69,7 +69,7 @@ void IconButton::assignDataFromAction(const QAction *action) auto const icon = action->icon(); const auto sizes = icon.availableSizes(); const auto text = action->text(); - setPixmap(icon.pixmap(sizes.empty() ? QSize(16, 16) : sizes.front())); + setPixmap(icon.pixmap(sizes.empty() ? defaultPixmapSize : sizes.front())); setToolTip(text.isEmpty() ? action->toolTip() : text); } diff --git a/widgets/iconbutton.h b/widgets/iconbutton.h index 68ceb5a..c7ddf43 100644 --- a/widgets/iconbutton.h +++ b/widgets/iconbutton.h @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -24,6 +25,8 @@ public: void setPixmap(const QPixmap &pixmap); QSize sizeHint() const override; + static constexpr auto defaultPixmapSize = QSize(16, 16); + protected: void paintEvent(QPaintEvent *event) override; void keyPressEvent(QKeyEvent *event) override;