KWidgetsAddons

ktoolbarpopupaction.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <[email protected]>
4  SPDX-FileCopyrightText: 1999 Simon Hausmann <[email protected]>
5  SPDX-FileCopyrightText: 2000 Nicolas Hadacek <[email protected]>
6  SPDX-FileCopyrightText: 2000 Kurt Granroth <[email protected]>
7  SPDX-FileCopyrightText: 2000 Michael Koch <[email protected]>
8  SPDX-FileCopyrightText: 2001 Holger Freyther <[email protected]>
9  SPDX-FileCopyrightText: 2002 Ellis Whitehead <[email protected]>
10  SPDX-FileCopyrightText: 2002 Joseph Wenninger <[email protected]>
11  SPDX-FileCopyrightText: 2003 Andras Mantia <[email protected]>
12  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
13 
14  SPDX-License-Identifier: LGPL-2.0-only
15 */
16 
17 #include "ktoolbarpopupaction.h"
18 
19 #include <QMenu>
20 #include <QToolBar>
21 
22 class KToolBarPopupActionPrivate
23 {
24 public:
25  KToolBarPopupActionPrivate()
26  : m_popupMode(QToolButton::MenuButtonPopup)
27 #if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 78)
28  , stickyMenu(true)
29 #endif
30  {
31  }
32 
34 #if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 78)
35  bool stickyMenu : 1;
36 #endif
37 };
38 
40  : QWidgetAction(parent)
41  , d(new KToolBarPopupActionPrivate)
42 {
43  setIcon(icon);
44  setText(text);
45  setMenu(new QMenu);
46 }
47 
49 {
50  delete menu();
51 }
52 
53 #if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 0)
55 {
56  return menu();
57 }
58 #endif
59 
61 {
62  QToolBar *parent = qobject_cast<QToolBar *>(_parent);
63  if (!parent) {
64  return QWidgetAction::createWidget(_parent);
65  }
66  QToolButton *button = new QToolButton(parent);
67  button->setAutoRaise(true);
68  button->setFocusPolicy(Qt::NoFocus);
69  button->setIconSize(parent->iconSize());
70  button->setToolButtonStyle(parent->toolButtonStyle());
71  button->setDefaultAction(this);
72  button->setPopupMode(d->m_popupMode);
73 
77 
78  return button;
79 }
80 
81 #if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 78)
82 bool KToolBarPopupAction::delayed() const
83 {
84  return popupMode() != QToolButton::InstantPopup;
85 }
86 #endif
87 
88 #if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 78)
90 {
91  if (delayed) {
92  if (d->stickyMenu) {
94  } else {
96  }
97  } else {
99  }
100 }
101 #endif
102 
103 #if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 78)
104 bool KToolBarPopupAction::stickyMenu() const
105 {
106  if (popupMode() == QToolButton::InstantPopup) {
107  return d->stickyMenu;
108  } else if (popupMode() == QToolButton::MenuButtonPopup) {
109  return true;
110  } else { // DelayedPopup
111  return false;
112  }
113 }
114 #endif
115 
116 #if KWIDGETSADDONS_BUILD_DEPRECATED_SINCE(5, 78)
118 {
119  if (popupMode() != QToolButton::InstantPopup) {
120  if (sticky) {
122  } else {
124  }
125  }
126 
127  d->stickyMenu = sticky;
128 }
129 #endif
130 
131 QToolButton::ToolButtonPopupMode KToolBarPopupAction::popupMode() const
132 {
133  return d->m_popupMode;
134 }
135 
137 {
138  d->m_popupMode = popupMode;
139 
140  const auto widgets = createdWidgets();
141  for (QWidget *widget : widgets) {
142  if (auto *button = qobject_cast<QToolButton *>(widget)) {
143  button->setPopupMode(d->m_popupMode);
144  }
145  }
146 }
void actionTriggered(QAction *action)
void setFocusPolicy(Qt::FocusPolicy policy)
void iconSizeChanged(const QSize &iconSize)
void setMenu(QMenu *menu)
void setPopupMode(QToolButton::ToolButtonPopupMode popupMode)
Determines the popup mode of the toolbar button.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QMenu * menu() const const
void setIcon(const QIcon &icon)
~KToolBarPopupAction() override
Destroys the toolbar popup action.
void setAutoRaise(bool enable)
void setStickyMenu(bool sticky)
If set to true, this action will create a sticky popup menu when plugged in a KToolBar.
QWidget * createWidget(QWidget *parent) override
Reimplemented from QWidgetAction.
void setText(const QString &text)
void setDefaultAction(QAction *action)
QMenu * popupMenu() const
The popup menu that is shown when clicking (some time) on the toolbar button.
void setIconSize(const QSize &size)
void setToolButtonStyle(Qt::ToolButtonStyle style)
virtual QWidget * createWidget(QWidget *parent)
void setDelayed(bool delayed)
If set to true, this action will create a delayed popup menu when plugged in a KToolBar.
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
void triggered(QAction *action)
KToolBarPopupAction(const QIcon &icon, const QString &text, QObject *parent)
Create a KToolBarPopupAction, with a text, an icon, a parent and a name.
void setPopupMode(QToolButton::ToolButtonPopupMode mode)
QObject * parent() const const
QList< QWidget * > createdWidgets() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:07:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.