KXmlGui

ktoolbar.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Reginald Stadlbauer <[email protected]>
4  SPDX-FileCopyrightText: 1997, 1998 Stephan Kulow <[email protected]>
5  SPDX-FileCopyrightText: 1997, 1998 Sven Radej <[email protected]>
6  SPDX-FileCopyrightText: 1997, 1998 Mark Donohoe <[email protected]>
7  SPDX-FileCopyrightText: 1997, 1998 Matthias Ettrich <[email protected]>
8  SPDX-FileCopyrightText: 1999, 2000 Kurt Granroth <[email protected]>
9  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
10 
11  SPDX-License-Identifier: LGPL-2.0-only
12 */
13 
14 #ifndef KTOOLBAR_H
15 #define KTOOLBAR_H
16 
17 #include <kxmlgui_export.h>
18 
19 #include <QToolBar>
20 #include <memory>
21 
22 class QDomElement;
23 
24 class KConfigGroup;
25 class KConfig;
26 class KMainWindow;
27 class KXMLGUIClient;
28 
29 /**
30  * @class KToolBar ktoolbar.h KToolBar
31  *
32  * @short Floatable toolbar with auto resize.
33  *
34  * A KDE-style toolbar.
35  *
36  * KToolBar can be used as a standalone widget, but KMainWindow
37  * provides easy factories and management of one or more toolbars.
38  *
39  * KToolBar uses a global config group to load toolbar settings on
40  * construction. It will reread this config group on a
41  * KApplication::appearanceChanged() signal.
42  *
43  * KToolBar respects Kiosk settings (see the KAuthorized namespace in the
44  * KConfig framework). In particular, system administrators can prevent users
45  * from moving toolbars with the "movable_toolbars" action, and from showing or
46  * hiding toolbars with the "options_show_toolbar" action. For example, to
47  * disable both, add the following the application or global configuration:
48  * @verbatim
49  [KDE Action Restrictions][$i]
50  movable_toolbars=false
51  options_show_toolbar=false
52  @endverbatim
53  *
54  * If you can't depend on KXmlGui but still want to integrate better with KDE,
55  * you can use QToolBar and:
56  * - Set ToolButtonStyle to Qt::ToolButtonFollowStyle, this will make QToolBar
57  * use the settings for "Main Toolbar"
58  * - Additionally set QToolBar::setProperty("otherToolbar", true) to use settings
59  * for "Other toolbars"; settings from "Other toolbars" will only work on widget
60  * styles derived from KStyle
61  *
62  * @author Reginald Stadlbauer <[email protected]>
63  * @author Stephan Kulow <[email protected]>
64  * @author Sven Radej <[email protected]>
65  * @author Hamish Rodda <[email protected]>
66  */
67 class KXMLGUI_EXPORT KToolBar : public QToolBar
68 {
69  Q_OBJECT
70 
71 public:
72  /**
73  * Constructor.
74  *
75  * This constructor takes care of adding the toolbar to the mainwindow,
76  * if @p parent is a QMainWindow.
77  *
78  * Normally KDE applications do not call this directly, they either
79  * call KMainWindow::toolBar(), or they use XML-GUI and specify
80  * toolbars using XML.
81  *
82  * @param parent The standard toolbar parent (usually a KMainWindow)
83  * @param isMainToolBar True for the "main toolbar", false for other toolbars. Different settings apply.
84  * @param readConfig whether to apply the configuration (global and application-specific)
85  */
86  explicit KToolBar(QWidget *parent, bool isMainToolBar = false, bool readConfig = true);
87  // KDE5: remove. The one below is preferred so that all debug output from init() shows the right objectName already,
88  // and so that isMainToolBar() and iconSizeDefault() return correct values during loading too.
89 
90  /**
91  * Constructor.
92  *
93  * This constructor takes care of adding the toolbar to the mainwindow,
94  * if @p parent is a QMainWindow.
95  *
96  * Normally KDE applications do not call this directly, they either
97  * call KMainWindow::toolBar(), or they use XML-GUI and specify
98  * toolbars using XML.
99  *
100  * @param objectName The QObject name of this toolbar, required so that QMainWindow can save and load the toolbar position,
101  * and so that KToolBar can find out if it's the main toolbar.
102  * @param parent The standard toolbar parent (usually a KMainWindow)
103  * @param readConfig whether to apply the configuration (global and application-specific)
104  */
105  explicit KToolBar(const QString &objectName, QWidget *parent, bool readConfig = true);
106 
107  /**
108  * Alternate constructor with additional arguments, e.g. to choose in which area
109  * the toolbar should be auto-added. This is rarely used in KDE. When using XMLGUI
110  * you can specify this as an xml attribute instead.
111  *
112  * @param objectName The QObject name of this toolbar, required so that QMainWindow can save and load the toolbar position
113  * @param parentWindow The window that should be the parent of this toolbar
114  * @param area The position of the toolbar. Usually Qt::TopToolBarArea.
115  * @param newLine If true, start a new line in the dock for this toolbar.
116  * @param isMainToolBar True for the "main toolbar", false for other toolbars. Different settings apply.
117  * @param readConfig whether to apply the configuration (global and application-specific)
118  */
119  KToolBar(const QString &objectName,
120  QMainWindow *parentWindow,
121  Qt::ToolBarArea area,
122  bool newLine = false,
123  bool isMainToolBar = false,
124  bool readConfig = true); // KDE5: remove, I don't think anyone is using this.
125 
126  /**
127  * Destroys the toolbar.
128  */
129  ~KToolBar() override;
130 
131  /**
132  * Returns the main window that this toolbar is docked with.
133  */
134  KMainWindow *mainWindow() const;
135 
136  /**
137  * Convenience function to set icon size
138  */
139  void setIconDimensions(int size);
140 
141  /**
142  * Returns the default size for this type of toolbar.
143  *
144  * @return the default size for this type of toolbar.
145  */
146  int iconSizeDefault() const; // KDE5: hide from public API. Doesn't make sense to export this, and it isn't used.
147 
148 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
149  /**
150  * This allows you to enable or disable the context menu.
151  *
152  * @param enable If false, then the context menu will be disabled
153  * @deprecated Since 5.0, use setContextMenuPolicy()
154  */
155  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy)")
156  void setContextMenuEnabled(bool enable = true);
157 #endif
158 
159 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
160  /**
161  * Returns the context menu enabled flag
162  * @return true if the context menu is disabled
163  * @deprecated Since 5.0, use contextMenuPolicy()
164  */
165  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use QWidget::contextMenuPolicy()")
166  bool contextMenuEnabled() const;
167 #endif
168 
169  /**
170  * Save the toolbar settings to group @p cg.
171  */
172  void saveSettings(KConfigGroup &cg);
173 
174  /**
175  * Read the toolbar settings from group @p cg
176  * and apply them.
177  */
178  void applySettings(const KConfigGroup &cg);
179 
180 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
181  /**
182  * Sets the XML gui client.
183  * @deprecated Since 5.0, use addXMLGUIClient()
184  */
185  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KToolBar::addXMLGUIClient(KXMLGUIClient *)")
186  void setXMLGUIClient(KXMLGUIClient *client);
187 #endif
188 
189  /**
190  * Adds an XML gui client that uses this toolbar
191  * @since 4.8.1
192  */
193  void addXMLGUIClient(KXMLGUIClient *client);
194 
195  /**
196  * Removes an XML gui client that uses this toolbar
197  * @since 4.8.5
198  */
199  void removeXMLGUIClient(KXMLGUIClient *client);
200 
201  /**
202  * Load state from an XML @param element, called by KXMLGUIBuilder.
203  */
204  void loadState(const QDomElement &element);
205 
206  /**
207  * Save state into an XML @param element, called by KXMLGUIBuilder.
208  */
209  void saveState(QDomElement &element) const;
210 
211  /**
212  * Reimplemented to support context menu activation on disabled tool buttons.
213  */
214  bool eventFilter(QObject *watched, QEvent *event) override;
215 
216  /**
217  * Returns whether the toolbars are currently editable (drag & drop of actions).
218  */
219  static bool toolBarsEditable();
220 
221  /**
222  * Enable or disable toolbar editing via drag & drop of actions. This is
223  * called by KEditToolBar and should generally be set to disabled whenever
224  * KEditToolBar is not active.
225  */
226  static void setToolBarsEditable(bool editable);
227 
228  /**
229  * Returns whether the toolbars are locked (i.e., moving of the toobars disallowed).
230  */
231  static bool toolBarsLocked();
232 
233  /**
234  * Allows you to lock and unlock all toolbars (i.e., disallow/allow moving of the toobars).
235  */
236  static void setToolBarsLocked(bool locked);
237 
238  /**
239  * Emits a D-Bus signal to tell all toolbars in all applications, that the user settings have
240  * changed.
241  * @since 5.0
242  */
243  static void emitToolbarStyleChanged();
244 
245 protected Q_SLOTS:
246  virtual void slotMovableChanged(bool movable);
247 
248 protected:
249  void contextMenuEvent(QContextMenuEvent *) override;
250  void actionEvent(QActionEvent *) override;
251 
252  // Draggable toolbar configuration
253  void dragEnterEvent(QDragEnterEvent *) override;
254  void dragMoveEvent(QDragMoveEvent *) override;
255  void dragLeaveEvent(QDragLeaveEvent *) override;
256  void dropEvent(QDropEvent *) override;
257  void mousePressEvent(QMouseEvent *) override;
258  void mouseMoveEvent(QMouseEvent *) override;
259  void mouseReleaseEvent(QMouseEvent *) override;
260 
261 private:
262  friend class KToolBarPrivate;
263  std::unique_ptr<class KToolBarPrivate> const d;
264 
265  Q_PRIVATE_SLOT(d, void slotAppearanceChanged())
266  Q_PRIVATE_SLOT(d, void slotContextRight())
267  Q_PRIVATE_SLOT(d, void slotContextTextRight())
268 };
269 
270 #endif
virtual void contextMenuEvent(QContextMenuEvent *event)
Q_SLOTSQ_SLOTS
virtual void actionEvent(QActionEvent *event) override
virtual void dropEvent(QDropEvent *event)
Floatable toolbar with auto resize.
Definition: ktoolbar.h:67
virtual bool eventFilter(QObject *watched, QEvent *event)
ToolBarArea
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void dragLeaveEvent(QDragLeaveEvent *event)
KMainWindow represents a top-level main window.
Definition: kmainwindow.h:69
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void dragEnterEvent(QDragEnterEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void dragMoveEvent(QDragMoveEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:04:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.