1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

AbstractButtonInterface: Allow delayed hide of popup

This commit is contained in:
David Rosca 2018-01-08 19:04:21 +01:00
parent 20374c8982
commit 238a06874d
3 changed files with 25 additions and 14 deletions

View File

@ -141,31 +141,34 @@ void AdBlockIcon::clicked(ClickController *controller)
const QUrl pageUrl = view->url();
QMenu menu;
menu.addAction(tr("Show AdBlock &Settings"), manager, SLOT(showDialog()));
menu.addSeparator();
QMenu *menu = new QMenu();
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addAction(tr("Show AdBlock &Settings"), manager, SLOT(showDialog()));
menu->addSeparator();
if (!pageUrl.host().isEmpty() && manager->isEnabled() && manager->canRunOnScheme(pageUrl.scheme())) {
const QString host = view->url().host().contains(QLatin1String("www.")) ? pageUrl.host().mid(4) : pageUrl.host();
const QString hostFilter = QString("@@||%1^$document").arg(host);
const QString pageFilter = QString("@@|%1|$document").arg(pageUrl.toString());
QAction* act = menu.addAction(tr("Disable on %1").arg(host));
QAction* act = menu->addAction(tr("Disable on %1").arg(host));
act->setCheckable(true);
act->setChecked(customList->containsFilter(hostFilter));
act->setData(hostFilter);
connect(act, SIGNAL(triggered()), this, SLOT(toggleCustomFilter()));
act = menu.addAction(tr("Disable only on this page"));
act = menu->addAction(tr("Disable only on this page"));
act->setCheckable(true);
act->setChecked(customList->containsFilter(pageFilter));
act->setData(pageFilter);
connect(act, SIGNAL(triggered()), this, SLOT(toggleCustomFilter()));
menu.addSeparator();
}
menu.exec(controller->popupPosition(menu.sizeHint()));
connect(menu, &QMenu::aboutToHide, this, [=]() {
controller->popupClosed();
});
menu->popup(controller->popupPosition(menu->sizeHint()));
}
void AdBlockIcon::blockedRequestsChanged(const QUrl &url)

View File

@ -49,20 +49,26 @@ NavigationBarToolButton::NavigationBarToolButton(AbstractButtonInterface *button
void NavigationBarToolButton::clicked()
{
AbstractButtonInterface::ClickController c;
c.visualParent = this;
c.popupPosition = [this](const QSize &size) {
AbstractButtonInterface::ClickController *c = new AbstractButtonInterface::ClickController;
c->visualParent = this;
c->popupPosition = [=](const QSize &size) {
QPoint pos = mapToGlobal(rect().bottomRight());
if (QApplication::isRightToLeft()) {
pos.setX(pos.x() - rect().width());
} else {
pos.setX(pos.x() - size.width());
}
c->popupOpened = true;
return pos;
};
setDown(true);
emit m_button->clicked(&c);
setDown(false);
c->popupClosed = [=]() {
setDown(false);
delete c;
};
emit m_button->clicked(c);
if (c->popupOpened) {
setDown(true);
}
}
void NavigationBarToolButton::updateIcon()

View File

@ -34,6 +34,8 @@ public:
struct ClickController {
QWidget *visualParent;
std::function<QPoint(QSize)> popupPosition;
bool popupOpened = false;
std::function<void()> popupClosed;
};
explicit AbstractButtonInterface(QObject *parent = nullptr);