mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
AbstractButtonInterface: Add support for hiding tool button
This commit is contained in:
parent
238a06874d
commit
0e41fd0785
|
@ -307,10 +307,17 @@ void NavigationBar::addToolButton(AbstractButtonInterface *button)
|
|||
return;
|
||||
}
|
||||
|
||||
NavigationBarToolButton *toolButton = new NavigationBarToolButton(button, this);
|
||||
connect(toolButton, &NavigationBarToolButton::visibilityChangeRequested, this, [=]() {
|
||||
if (m_layout->indexOf(toolButton) != -1) {
|
||||
toolButton->updateVisibility();
|
||||
}
|
||||
});
|
||||
|
||||
WidgetData data;
|
||||
data.id = button->id();
|
||||
data.name = button->name();
|
||||
data.widget = new NavigationBarToolButton(button, this);
|
||||
data.widget = toolButton;
|
||||
data.button = button;
|
||||
m_widgets[data.id] = data;
|
||||
|
||||
|
@ -406,7 +413,7 @@ void NavigationBar::aboutToShowToolsMenu()
|
|||
|
||||
for (const WidgetData &data : qAsConst(m_widgets)) {
|
||||
AbstractButtonInterface *button = data.button;
|
||||
if (button && !m_layoutIds.contains(data.id)) {
|
||||
if (button && (!button->isVisible() || !m_layoutIds.contains(data.id))) {
|
||||
QString title = button->title();
|
||||
if (!button->badgeText().isEmpty()) {
|
||||
title.append(QSL(" (%1)").arg(button->badgeText()));
|
||||
|
@ -460,20 +467,28 @@ void NavigationBar::toolActionActivated()
|
|||
return;
|
||||
}
|
||||
|
||||
AbstractButtonInterface::ClickController c;
|
||||
c.visualParent = buttonTools;
|
||||
c.popupPosition = [=](const QSize &size) {
|
||||
AbstractButtonInterface::ClickController *c = new AbstractButtonInterface::ClickController;
|
||||
c->visualParent = buttonTools;
|
||||
c->popupPosition = [=](const QSize &size) {
|
||||
QPoint pos = buttonTools->mapToGlobal(buttonTools->rect().bottomRight());
|
||||
if (QApplication::isRightToLeft()) {
|
||||
pos.setX(pos.x() - buttonTools->rect().width());
|
||||
} else {
|
||||
pos.setX(pos.x() - size.width());
|
||||
}
|
||||
c->popupOpened = true;
|
||||
return pos;
|
||||
};
|
||||
buttonTools->setDown(true);
|
||||
emit data.button->clicked(&c);
|
||||
buttonTools->setDown(false);
|
||||
c->popupClosed = [=]() {
|
||||
buttonTools->setDown(false);
|
||||
delete c;
|
||||
};
|
||||
emit data.button->clicked(c);
|
||||
if (c->popupOpened) {
|
||||
buttonTools->setDown(true);
|
||||
} else {
|
||||
c->popupClosed();
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationBar::loadSettings()
|
||||
|
@ -531,7 +546,12 @@ void NavigationBar::reloadLayout()
|
|||
const WidgetData data = m_widgets.value(id);
|
||||
if (data.widget) {
|
||||
m_layout->addWidget(data.widget);
|
||||
data.widget->show();
|
||||
NavigationBarToolButton *button = qobject_cast<NavigationBarToolButton*>(data.widget);
|
||||
if (button) {
|
||||
button->updateVisibility();
|
||||
} else {
|
||||
data.widget->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,15 @@ NavigationBarToolButton::NavigationBarToolButton(AbstractButtonInterface *button
|
|||
connect(button, &AbstractButtonInterface::activeChanged, this, &NavigationBarToolButton::updateIcon);
|
||||
connect(button, &AbstractButtonInterface::toolTipChanged, this, &NavigationBarToolButton::setToolTip);
|
||||
connect(button, &AbstractButtonInterface::badgeTextChanged, this, &NavigationBarToolButton::updateBadge);
|
||||
connect(button, &AbstractButtonInterface::visibleChanged, this, &NavigationBarToolButton::visibilityChangeRequested);
|
||||
connect(this, &ToolButton::clicked, this, &NavigationBarToolButton::clicked);
|
||||
}
|
||||
|
||||
void NavigationBarToolButton::updateVisibility()
|
||||
{
|
||||
setVisible(m_button->isVisible());
|
||||
}
|
||||
|
||||
void NavigationBarToolButton::clicked()
|
||||
{
|
||||
AbstractButtonInterface::ClickController *c = new AbstractButtonInterface::ClickController;
|
||||
|
@ -68,6 +74,8 @@ void NavigationBarToolButton::clicked()
|
|||
emit m_button->clicked(c);
|
||||
if (c->popupOpened) {
|
||||
setDown(true);
|
||||
} else {
|
||||
c->popupClosed();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,16 @@ class AbstractButtonInterface;
|
|||
|
||||
class QUPZILLA_EXPORT NavigationBarToolButton : public ToolButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NavigationBarToolButton(AbstractButtonInterface *button, QWidget *parent = nullptr);
|
||||
|
||||
void updateVisibility();
|
||||
|
||||
signals:
|
||||
void visibilityChangeRequested();
|
||||
|
||||
private:
|
||||
void clicked();
|
||||
void updateIcon();
|
||||
|
|
|
@ -42,6 +42,21 @@ void AbstractButtonInterface::setActive(bool active)
|
|||
emit activeChanged(m_active);
|
||||
}
|
||||
|
||||
bool AbstractButtonInterface::isVisible() const
|
||||
{
|
||||
return m_visible;
|
||||
}
|
||||
|
||||
void AbstractButtonInterface::setVisible(bool visible)
|
||||
{
|
||||
if (m_visible == visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_visible = visible;
|
||||
emit visibleChanged(m_visible);
|
||||
}
|
||||
|
||||
QString AbstractButtonInterface::title() const
|
||||
{
|
||||
return m_title;
|
||||
|
|
|
@ -48,6 +48,9 @@ public:
|
|||
bool isActive() const;
|
||||
void setActive(bool active);
|
||||
|
||||
bool isVisible() const;
|
||||
void setVisible(bool visible);
|
||||
|
||||
QString title() const;
|
||||
void setTitle(const QString &text);
|
||||
|
||||
|
@ -65,6 +68,7 @@ public:
|
|||
|
||||
signals:
|
||||
void activeChanged(bool active);
|
||||
void visibleChanged(bool visible);
|
||||
void titleChanged(const QString &title);
|
||||
void toolTipChanged(const QString &toolTip);
|
||||
void iconChanged(const QIcon &icon);
|
||||
|
@ -74,6 +78,7 @@ signals:
|
|||
|
||||
private:
|
||||
bool m_active = true;
|
||||
bool m_visible = true;
|
||||
QString m_title;
|
||||
QString m_toolTip;
|
||||
QIcon m_icon;
|
||||
|
|
Loading…
Reference in New Issue
Block a user