mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
ClickableLabel: Fix resizing icon with label
This commit is contained in:
parent
be2d14dcb8
commit
2a5c6ecfa1
|
@ -24,32 +24,46 @@ ClickableLabel::ClickableLabel(QWidget* parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ClickableLabel::themeIcon() const
|
||||||
|
{
|
||||||
|
return m_themeIcon;
|
||||||
|
}
|
||||||
|
|
||||||
void ClickableLabel::setThemeIcon(const QString &name)
|
void ClickableLabel::setThemeIcon(const QString &name)
|
||||||
{
|
{
|
||||||
QIcon icon = QIcon::fromTheme(name);
|
m_themeIcon = name;
|
||||||
|
updateIcon();
|
||||||
if (!icon.isNull()) {
|
|
||||||
adjustSize();
|
|
||||||
setPixmap(icon.pixmap(size()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon ClickableLabel::fallbackIcon() const
|
QIcon ClickableLabel::fallbackIcon() const
|
||||||
{
|
{
|
||||||
return pixmap() ? QIcon(*pixmap()) : QIcon();
|
return m_fallbackIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClickableLabel::setFallbackIcon(const QIcon &image)
|
void ClickableLabel::setFallbackIcon(const QIcon &fallbackIcon)
|
||||||
{
|
{
|
||||||
if (!pixmap() || pixmap()->isNull()) {
|
m_fallbackIcon = fallbackIcon;
|
||||||
adjustSize();
|
updateIcon();
|
||||||
setPixmap(image.pixmap(size()));
|
}
|
||||||
|
|
||||||
|
void ClickableLabel::updateIcon()
|
||||||
|
{
|
||||||
|
if (!m_themeIcon.isEmpty()) {
|
||||||
|
const QIcon icon = QIcon::fromTheme(m_themeIcon);
|
||||||
|
if (!icon.isNull()) {
|
||||||
|
setPixmap(icon.pixmap(size()));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ClickableLabel::themeIcon() const
|
if (!m_fallbackIcon.isNull())
|
||||||
|
setPixmap(m_fallbackIcon.pixmap(size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClickableLabel::resizeEvent(QResizeEvent *ev)
|
||||||
{
|
{
|
||||||
return m_themeIcon;
|
QLabel::resizeEvent(ev);
|
||||||
|
updateIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClickableLabel::mouseReleaseEvent(QMouseEvent* ev)
|
void ClickableLabel::mouseReleaseEvent(QMouseEvent* ev)
|
||||||
|
|
|
@ -41,16 +41,20 @@ public:
|
||||||
void setThemeIcon(const QString &name);
|
void setThemeIcon(const QString &name);
|
||||||
|
|
||||||
QIcon fallbackIcon() const;
|
QIcon fallbackIcon() const;
|
||||||
void setFallbackIcon(const QIcon &image);
|
void setFallbackIcon(const QIcon &fallbackIcon);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clicked(QPoint);
|
void clicked(QPoint);
|
||||||
void middleClicked(QPoint);
|
void middleClicked(QPoint);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateIcon();
|
||||||
|
|
||||||
|
void resizeEvent(QResizeEvent *ev);
|
||||||
void mouseReleaseEvent(QMouseEvent* ev);
|
void mouseReleaseEvent(QMouseEvent* ev);
|
||||||
|
|
||||||
QString m_themeIcon;
|
QString m_themeIcon;
|
||||||
|
QIcon m_fallbackIcon;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user