File indexing completed on 2024-05-26 04:31:52
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2000 Reginald Stadlbauer (reggie@kde.org) 0003 SPDX-FileCopyrightText: 1997, 1998 Stephan Kulow (coolo@kde.org) 0004 SPDX-FileCopyrightText: 1997, 1998 Sven Radej (radej@kde.org) 0005 SPDX-FileCopyrightText: 1997, 1998 Mark Donohoe (donohoe@kde.org) 0006 SPDX-FileCopyrightText: 1997, 1998 Matthias Ettrich (ettrich@kde.org) 0007 SPDX-FileCopyrightText: 1999, 2000 Kurt Granroth (granroth@kde.org) 0008 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda (rodda@kde.org) 0009 0010 SPDX-License-Identifier: LGPL-2.0-only 0011 */ 0012 0013 #ifndef KTOOLBAR_H 0014 #define KTOOLBAR_H 0015 0016 #include <kritawidgetutils_export.h> 0017 0018 #include <QToolBar> 0019 0020 class QDomElement; 0021 0022 class KConfigGroup; 0023 class KConfig; 0024 class KisKMainWindow; 0025 class KisKXMLGUIClient; 0026 class KisToolBarStateModel; 0027 0028 /** 0029 * @short Floatable toolbar with auto resize. 0030 * 0031 * A KDE-style toolbar. 0032 * 0033 * KisToolBar can be used as a standalone widget, but KisKMainWindow 0034 * provides easy factories and management of one or more toolbars. 0035 * 0036 * KisToolBar uses a global config group to load toolbar settings on 0037 * construction. It will reread this config group on a 0038 * KApplication::appearanceChanged() signal. 0039 * 0040 * @note If you can't depend on KXmlGui but you want to integrate with KDE, you can use QToolBar with: 0041 * Set ToolButtonStyle to Qt::ToolButtonFollowStyle, this will make QToolBar use the settings for "Main Toolbar" 0042 * Additionally set QToolBar::setProperty("otherToolbar", true) to use settings for "Other toolbars" 0043 * Settings from "Other toolbars" will only work on widget styles derived from KStyle 0044 * @author Reginald Stadlbauer <reggie@kde.org>, Stephan Kulow <coolo@kde.org>, Sven Radej <radej@kde.org>, Hamish Rodda <rodda@kde.org>. 0045 */ 0046 class KRITAWIDGETUTILS_EXPORT KisToolBar : public QToolBar 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 /** 0052 * Constructor. 0053 * 0054 * This constructor takes care of adding the toolbar to the mainwindow, 0055 * if @p parent is a QMainWindow. 0056 * 0057 * Normally KDE applications do not call this directly, they either 0058 * call KisKMainWindow::toolBar(name), or they use XML-GUI and specify 0059 * toolbars using XML. 0060 * 0061 * @param objectName The QObject name of this toolbar, required so that QMainWindow can save and load the toolbar position, 0062 * and so that KisToolBar can find out if it's the main toolbar. 0063 * @param parent The standard toolbar parent (usually a KisKMainWindow) 0064 * @param readConfig whether to apply the configuration (global and application-specific) 0065 */ 0066 explicit KisToolBar(const QString &objectName, QWidget *parent, bool readConfig = true); 0067 0068 /** 0069 * Destroys the toolbar. 0070 */ 0071 ~KisToolBar() override; 0072 0073 /** 0074 * Returns the main window that this toolbar is docked with. 0075 */ 0076 KisKMainWindow *mainWindow() const; 0077 0078 /** 0079 * Convenience function to set icon size 0080 */ 0081 void setIconDimensions(int size); 0082 0083 /** 0084 * Returns the default size for this type of toolbar. 0085 * 0086 * @return the default size for this type of toolbar. 0087 */ 0088 int iconSizeDefault() const; // KDE5: hide from public API. Doesn't make sense to export this, and it isn't used. 0089 0090 /** 0091 * Save the toolbar settings to group @p configGroup in @p config. 0092 */ 0093 void saveSettings(KConfigGroup &cg); 0094 0095 /** 0096 * Read the toolbar settings from group @p configGroup in @p config 0097 * and apply them. 0098 */ 0099 void applySettings(const KConfigGroup &cg); 0100 0101 /** 0102 * Adds an XML gui client that uses this toolbar 0103 * @since 4.8.1 0104 */ 0105 void addXMLGUIClient(KisKXMLGUIClient *client); 0106 0107 /** 0108 * Removes an XML gui client that uses this toolbar 0109 * @since 4.8.5 0110 */ 0111 void removeXMLGUIClient(KisKXMLGUIClient *client); 0112 0113 /** 0114 * Load state from an XML @p element, called by KisKXMLGUIBuilder. 0115 */ 0116 void loadState(const QDomElement &element); 0117 0118 /** 0119 * Save state into an XML @p element, called by KisKXMLGUIBuilder. 0120 */ 0121 void saveState(QDomElement &element) const; 0122 0123 /** 0124 * Reimplemented to support context menu activation on disabled tool buttons. 0125 */ 0126 bool eventFilter(QObject *watched, QEvent *event) override; 0127 0128 /** 0129 * Returns whether the toolbars are currently editable (drag & drop of actions). 0130 */ 0131 static bool toolBarsEditable(); 0132 0133 /** 0134 * Enable or disable toolbar editing via drag & drop of actions. This is 0135 * called by KisKEditToolbar and should generally be set to disabled whenever 0136 * KisKEditToolbar is not active. 0137 */ 0138 static void setToolBarsEditable(bool editable); 0139 0140 /** 0141 * Returns whether the toolbars are locked (i.e., moving of the toolbars disallowed). 0142 */ 0143 static bool toolBarsLocked(); 0144 0145 /** 0146 * Allows you to lock and unlock all toolbars (i.e., disallow/allow moving of the toolbars). 0147 */ 0148 static void setToolBarsLocked(bool locked); 0149 0150 /** 0151 * Emits a dbus signal to tell all toolbars in all applications, that the user settings have 0152 * changed. 0153 * @since 5.0 0154 */ 0155 static void emitToolbarStyleChanged(); 0156 0157 static KisToolBarStateModel* toolBarStateModel(); 0158 0159 protected Q_SLOTS: 0160 virtual void slotMovableChanged(bool movable); 0161 0162 protected: 0163 void contextMenuEvent(QContextMenuEvent *) override; 0164 void actionEvent(QActionEvent *) override; 0165 0166 // Draggable toolbar configuration 0167 void dragEnterEvent(QDragEnterEvent *) override; 0168 void dragMoveEvent(QDragMoveEvent *) override; 0169 void dragLeaveEvent(QDragLeaveEvent *) override; 0170 void dropEvent(QDropEvent *) override; 0171 void mousePressEvent(QMouseEvent *) override; 0172 void mouseMoveEvent(QMouseEvent *) override; 0173 void mouseReleaseEvent(QMouseEvent *) override; 0174 0175 private: 0176 class Private; 0177 Private *const d; 0178 0179 Q_PRIVATE_SLOT(d, void slotAppearanceChanged()) 0180 Q_PRIVATE_SLOT(d, void slotContextAboutToShow()) 0181 Q_PRIVATE_SLOT(d, void slotContextAboutToHide()) 0182 Q_PRIVATE_SLOT(d, void slotContextLeft()) 0183 Q_PRIVATE_SLOT(d, void slotContextRight()) 0184 Q_PRIVATE_SLOT(d, void slotContextShowText()) 0185 Q_PRIVATE_SLOT(d, void slotContextTop()) 0186 Q_PRIVATE_SLOT(d, void slotContextBottom()) 0187 Q_PRIVATE_SLOT(d, void slotContextIcons()) 0188 Q_PRIVATE_SLOT(d, void slotContextText()) 0189 Q_PRIVATE_SLOT(d, void slotContextTextRight()) 0190 Q_PRIVATE_SLOT(d, void slotContextTextUnder()) 0191 Q_PRIVATE_SLOT(d, void slotContextIconSize()) 0192 Q_PRIVATE_SLOT(d, void slotLockToolBars(bool)) 0193 Q_PRIVATE_SLOT(d, void slotToolButtonToggled(bool)) 0194 }; 0195 0196 #endif