mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
NavigationBar: Add support for badge text in tool buttons
This commit is contained in:
parent
8827b1fb90
commit
15a2afb4b6
|
@ -381,7 +381,11 @@ void NavigationBar::aboutToShowToolsMenu()
|
|||
for (const WidgetData &data : qAsConst(m_widgets)) {
|
||||
AbstractButtonInterface *button = data.button;
|
||||
if (button && !m_layoutIds.contains(data.id)) {
|
||||
m_menuTools->addAction(button->icon(), button->title(), this, &NavigationBar::toolActionActivated)->setData(data.id);
|
||||
QString title = button->title();
|
||||
if (!button->badgeLabelText().isEmpty()) {
|
||||
title.append(QSL(" (%1)").arg(button->badgeLabelText()));
|
||||
}
|
||||
m_menuTools->addAction(button->icon(), title, this, &NavigationBar::toolActionActivated)->setData(data.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "navigationbartoolbutton.h"
|
||||
#include "abstractbuttoninterface.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QApplication>
|
||||
|
||||
NavigationBarToolButton::NavigationBarToolButton(AbstractButtonInterface *button, QWidget *parent)
|
||||
|
@ -28,12 +29,21 @@ NavigationBarToolButton::NavigationBarToolButton(AbstractButtonInterface *button
|
|||
setToolbarButtonLook(true);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
m_badgeLabel = new QLabel(this);
|
||||
m_badgeLabel->setObjectName(QSL("navigation-toolbutton-badge"));
|
||||
QFont f = m_badgeLabel->font();
|
||||
f.setPixelSize(m_badgeLabel->height() / 2.5);
|
||||
m_badgeLabel->setFont(f);
|
||||
m_badgeLabel->hide();
|
||||
|
||||
setToolTip(button->toolTip());
|
||||
updateIcon();
|
||||
updateBadge();
|
||||
|
||||
connect(button, &AbstractButtonInterface::iconChanged, this, &NavigationBarToolButton::updateIcon);
|
||||
connect(button, &AbstractButtonInterface::activeChanged, this, &NavigationBarToolButton::updateIcon);
|
||||
connect(button, &AbstractButtonInterface::toolTipChanged, this, &NavigationBarToolButton::setToolTip);
|
||||
connect(button, &AbstractButtonInterface::badgeLabelTextChanged, this, &NavigationBarToolButton::updateBadge);
|
||||
connect(this, &ToolButton::clicked, this, &NavigationBarToolButton::clicked);
|
||||
}
|
||||
|
||||
|
@ -61,3 +71,15 @@ void NavigationBarToolButton::updateIcon()
|
|||
const QImage img = m_button->icon().pixmap(iconSize(), mode).toImage();
|
||||
setIcon(QPixmap::fromImage(img, Qt::MonoOnly));
|
||||
}
|
||||
|
||||
void NavigationBarToolButton::updateBadge()
|
||||
{
|
||||
if (m_button->badgeLabelText().isEmpty()) {
|
||||
m_badgeLabel->hide();
|
||||
} else {
|
||||
m_badgeLabel->setText(m_button->badgeLabelText());
|
||||
m_badgeLabel->resize(m_badgeLabel->sizeHint());
|
||||
m_badgeLabel->move(width() - m_badgeLabel->width(), 0);
|
||||
m_badgeLabel->show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "qzcommon.h"
|
||||
#include "toolbutton.h"
|
||||
|
||||
class QLabel;
|
||||
|
||||
class AbstractButtonInterface;
|
||||
|
||||
class QUPZILLA_EXPORT NavigationBarToolButton : public ToolButton
|
||||
|
@ -30,6 +32,8 @@ public:
|
|||
private:
|
||||
void clicked();
|
||||
void updateIcon();
|
||||
void updateBadge();
|
||||
|
||||
AbstractButtonInterface *m_button;
|
||||
QLabel *m_badgeLabel = nullptr;
|
||||
};
|
||||
|
|
|
@ -57,6 +57,13 @@
|
|||
qproperty-icon: url(images/menu.png);
|
||||
}
|
||||
|
||||
#navigation-toolbutton-badge
|
||||
{
|
||||
background: palette(dark);
|
||||
color: palette(bright-text);
|
||||
margin: 0px 1px;
|
||||
}
|
||||
|
||||
/*TabWidget*/
|
||||
#tabbar::tab
|
||||
{
|
||||
|
|
|
@ -101,6 +101,13 @@
|
|||
qproperty-multiIcon: url(images/navigation-supermenu.png);
|
||||
}
|
||||
|
||||
#navigation-toolbutton-badge
|
||||
{
|
||||
background: palette(dark);
|
||||
color: palette(bright-text);
|
||||
margin: 0px 1px;
|
||||
}
|
||||
|
||||
ToolButton[toolbar-look="true"]
|
||||
{
|
||||
qproperty-iconSize: 16px 16px;
|
||||
|
|
|
@ -59,6 +59,13 @@
|
|||
qproperty-fallbackIcon: url(images/menu.svg);
|
||||
}
|
||||
|
||||
#navigation-toolbutton-badge
|
||||
{
|
||||
background: palette(dark);
|
||||
color: palette(bright-text);
|
||||
margin: 0px 1px;
|
||||
}
|
||||
|
||||
/*TabWidget*/
|
||||
#tabbar-button-right
|
||||
{
|
||||
|
|
|
@ -102,6 +102,13 @@
|
|||
qproperty-multiIcon: url(images/navigation-supermenu.png);
|
||||
}
|
||||
|
||||
#navigation-toolbutton-badge
|
||||
{
|
||||
background: palette(dark);
|
||||
color: palette(bright-text);
|
||||
margin: 0px 1px;
|
||||
}
|
||||
|
||||
/*TabWidget*/
|
||||
#tabbar-button-right
|
||||
{
|
||||
|
|
|
@ -112,6 +112,13 @@
|
|||
qproperty-iconSize: 23px 22px;
|
||||
}
|
||||
|
||||
#navigation-toolbutton-badge
|
||||
{
|
||||
background: palette(dark);
|
||||
color: palette(bright-text);
|
||||
margin: 0px 1px;
|
||||
}
|
||||
|
||||
/*TabWidget*/
|
||||
#tabbar-button-right
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user