1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-13 10:32:11 +01:00

[TabListButton] Show popup menu inside window for tab-list button in tabbar

This commit is contained in:
nowrep 2014-02-13 15:27:02 +01:00
parent 851e19ce01
commit 3ec9e0b893
3 changed files with 26 additions and 2 deletions

View File

@ -58,6 +58,18 @@ void ToolButton::setIcon(const QIcon &image)
QToolButton::setIcon(image); QToolButton::setIcon(image);
} }
void ToolButton::setMenu(QMenu* m)
{
if (m) {
connect(m, SIGNAL(aboutToHide()), this, SLOT(menuAboutToHide()));
}
else if (menu()) {
disconnect(menu(), SIGNAL(aboutToHide()), this, SLOT(menuAboutToHide()));
}
QToolButton::setMenu(m);
}
void ToolButton::setShowMenuInside(bool inside) void ToolButton::setShowMenuInside(bool inside)
{ {
m_showMenuInside = inside; m_showMenuInside = inside;
@ -173,6 +185,8 @@ void ToolButton::showMenu()
return; return;
} }
m->popup(QPoint(0, 0));
QPoint pos = mapToGlobal(rect().bottomRight()); QPoint pos = mapToGlobal(rect().bottomRight());
if (QApplication::layoutDirection() == Qt::RightToLeft) { if (QApplication::layoutDirection() == Qt::RightToLeft) {
pos.setX(pos.x() - rect().width()); pos.setX(pos.x() - rect().width());
@ -181,8 +195,11 @@ void ToolButton::showMenu()
pos.setX(pos.x() - m->sizeHint().width()); pos.setX(pos.x() - m->sizeHint().width());
} }
setDown(true); m->move(pos);
m->exec(pos); }
void ToolButton::menuAboutToHide()
{
setDown(false); setDown(false);
} }

View File

@ -50,6 +50,8 @@ public:
void setFallbackIcon(const QIcon &image); void setFallbackIcon(const QIcon &image);
void setIcon(const QIcon &image); void setIcon(const QIcon &image);
void setMenu(QMenu* m);
void setShowMenuInside(bool inside); void setShowMenuInside(bool inside);
bool showMenuInside() const; bool showMenuInside() const;
@ -65,6 +67,9 @@ signals:
public slots: public slots:
void showMenu(); void showMenu();
private slots:
void menuAboutToHide();
protected: protected:
void mousePressEvent(QMouseEvent* e); void mousePressEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e); void mouseReleaseEvent(QMouseEvent* e);

View File

@ -149,6 +149,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
m_buttonListTabs->setToolTip(tr("List of tabs")); m_buttonListTabs->setToolTip(tr("List of tabs"));
m_buttonListTabs->setAutoRaise(true); m_buttonListTabs->setAutoRaise(true);
m_buttonListTabs->setFocusPolicy(Qt::NoFocus); m_buttonListTabs->setFocusPolicy(Qt::NoFocus);
m_buttonListTabs->setShowMenuInside(true);
m_buttonAddTab = new AddTabButton(this, m_tabBar); m_buttonAddTab = new AddTabButton(this, m_tabBar);
@ -164,6 +165,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
m_buttonListTabs2->setToolTip(tr("List of tabs")); m_buttonListTabs2->setToolTip(tr("List of tabs"));
m_buttonListTabs2->setAutoRaise(true); m_buttonListTabs2->setAutoRaise(true);
m_buttonListTabs2->setFocusPolicy(Qt::NoFocus); m_buttonListTabs2->setFocusPolicy(Qt::NoFocus);
m_buttonListTabs2->setShowMenuInside(true);
m_buttonAddTab2 = new AddTabButton(this, m_tabBar); m_buttonAddTab2 = new AddTabButton(this, m_tabBar);
m_buttonAddTab2->setProperty("outside-tabbar", true); m_buttonAddTab2->setProperty("outside-tabbar", true);