mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 12:46:35 +01:00
[ToolButton] Use QImage for multiIcon
Instead of 4 separate QPixmaps, use just one QImage and paint only the current part (according to button state) of the image on button.
This commit is contained in:
parent
0f79797be4
commit
6bdc6f90ce
@ -38,23 +38,16 @@ ToolButton::ToolButton(QWidget* parent)
|
||||
connect(&m_pressTimer, SIGNAL(timeout()), this, SLOT(showMenu()));
|
||||
}
|
||||
|
||||
QPixmap ToolButton::multiIcon() const
|
||||
QImage ToolButton::multiIcon() const
|
||||
{
|
||||
return m_normalIcon;
|
||||
return m_multiIcon;
|
||||
}
|
||||
|
||||
void ToolButton::setMultiIcon(const QPixmap &icon)
|
||||
void ToolButton::setMultiIcon(const QImage &image)
|
||||
{
|
||||
int w = icon.width();
|
||||
int h = icon.height();
|
||||
|
||||
m_normalIcon = icon.copy(0, 0, w, h / 4);
|
||||
m_hoverIcon = icon.copy(0, h / 4, w, h / 4);
|
||||
m_activeIcon = icon.copy(0, h / 2, w, h / 4);
|
||||
m_disabledIcon = icon.copy(0, 3 * h / 4, w, h / 4);
|
||||
|
||||
m_options |= MultiIconOption;
|
||||
setFixedSize(m_normalIcon.size());
|
||||
m_multiIcon = image;
|
||||
setFixedSize(m_multiIcon.width(), m_multiIcon.height() / 4);
|
||||
|
||||
update();
|
||||
}
|
||||
@ -72,7 +65,7 @@ void ToolButton::setThemeIcon(const QString &icon)
|
||||
|
||||
QIcon ToolButton::icon() const
|
||||
{
|
||||
return m_options & MultiIconOption ? multiIcon() : QToolButton::icon();
|
||||
return QToolButton::icon();
|
||||
}
|
||||
|
||||
void ToolButton::setIcon(const QIcon &icon)
|
||||
@ -219,12 +212,15 @@ void ToolButton::paintEvent(QPaintEvent* e)
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
const int w = m_multiIcon.width();
|
||||
const int h4 = m_multiIcon.height() / 4;
|
||||
|
||||
if (!isEnabled())
|
||||
p.drawPixmap(0, 0, m_disabledIcon);
|
||||
p.drawImage(0, 0, m_multiIcon, 0, h4 * 3, w, h4);
|
||||
else if (isDown())
|
||||
p.drawPixmap(0, 0, m_activeIcon);
|
||||
p.drawImage(0, 0, m_multiIcon, 0, h4 * 2, w, h4);
|
||||
else if (underMouse())
|
||||
p.drawPixmap(0, 0, m_hoverIcon);
|
||||
p.drawImage(0, 0, m_multiIcon, 0, h4 * 1, w, h4);
|
||||
else
|
||||
p.drawPixmap(0, 0, m_normalIcon);
|
||||
p.drawImage(0, 0, m_multiIcon, 0, h4 * 0, w, h4);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class QUPZILLA_EXPORT ToolButton : public QToolButton
|
||||
Q_PROPERTY(QSize fixedsize READ size WRITE setFixedSize)
|
||||
Q_PROPERTY(int fixedwidth READ width WRITE setFixedWidth)
|
||||
Q_PROPERTY(int fixedheight READ height WRITE setFixedHeight)
|
||||
Q_PROPERTY(QPixmap multiIcon READ multiIcon WRITE setMultiIcon)
|
||||
Q_PROPERTY(QImage multiIcon READ multiIcon WRITE setMultiIcon)
|
||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(QString themeIcon READ themeIcon WRITE setThemeIcon)
|
||||
|
||||
@ -38,8 +38,8 @@ public:
|
||||
explicit ToolButton(QWidget* parent = 0);
|
||||
|
||||
// MultiIcon - Image containing pixmaps for all button states
|
||||
QPixmap multiIcon() const;
|
||||
void setMultiIcon(const QPixmap &icon);
|
||||
QImage multiIcon() const;
|
||||
void setMultiIcon(const QImage &image);
|
||||
|
||||
// ThemeIcon - Standard QToolButton with theme icon
|
||||
QString themeIcon() const;
|
||||
@ -84,10 +84,7 @@ protected:
|
||||
void paintEvent(QPaintEvent* e);
|
||||
|
||||
private:
|
||||
QPixmap m_normalIcon;
|
||||
QPixmap m_hoverIcon;
|
||||
QPixmap m_activeIcon;
|
||||
QPixmap m_disabledIcon;
|
||||
QImage m_multiIcon;
|
||||
QString m_themeIcon;
|
||||
QTimer m_pressTimer;
|
||||
QMenu* m_menu;
|
||||
|
Loading…
Reference in New Issue
Block a user