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