File indexing completed on 2024-06-16 04:15:42
0001 /* 0002 This file is part of the KDE libraries 0003 Copyright 0004 (C) 2000 Reginald Stadlbauer (reggie@kde.org) 0005 (C) 1997 Stephan Kulow (coolo@kde.org) 0006 (C) 1997-2000 Sven Radej (radej@kde.org) 0007 (C) 1997-2000 Matthias Ettrich (ettrich@kde.org) 0008 (C) 1999 Chris Schlaeger (cs@kde.org) 0009 (C) 2002 Joseph Wenninger (jowenn@kde.org) 0010 (C) 2005-2006 Hamish Rodda (rodda@kde.org) 0011 0012 SPDX-License-Identifier: LGPL-2.0-only 0013 0014 */ 0015 0016 #ifndef KisKXMLGUIWINDOW_H 0017 #define KisKXMLGUIWINDOW_H 0018 0019 #include "kxmlguiclient.h" 0020 #include "kxmlguibuilder.h" 0021 #include "kmainwindow.h" 0022 #include <QMetaClassInfo> 0023 0024 class KMenu; 0025 class KisKXMLGUIFactory; 0026 class KConfig; 0027 class KConfigGroup; 0028 class KisToolBar; 0029 class KXmlGuiWindowPrivate; 0030 0031 /** 0032 * @short %KDE top level main window with predefined action layout 0033 * 0034 * Instead of creating a KisKMainWindow manually and assigning menus, menu entries, 0035 * toolbar buttons and actions to it by hand, this class can be used to load an 0036 * rc file to manage the main window's actions. 0037 * 0038 * See http://techbase.kde.org/Development/Tutorials/Using_KActions#XMLGUI 0039 * for essential information on the XML file format and usage of this class. 0040 * 0041 * @see KisKMainWindow 0042 * @author Reginald Stadlbauer (reggie@kde.org) Stephan Kulow (coolo@kde.org), Matthias Ettrich (ettrich@kde.org), Chris Schlaeger (cs@kde.org), Sven Radej (radej@kde.org). Maintained by Sven Radej (radej@kde.org) 0043 0044 */ 0045 0046 class KRITAWIDGETUTILS_EXPORT KXmlGuiWindow : public KisKMainWindow, public KisKXMLGUIBuilder, virtual public KisKXMLGUIClient 0047 { 0048 XMLGUI_DECLARE_PRIVATE(KXmlGuiWindow) 0049 Q_OBJECT 0050 Q_PROPERTY(bool hasMenuBar READ hasMenuBar) 0051 Q_PROPERTY(bool autoSaveSettings READ autoSaveSettings) 0052 Q_PROPERTY(QString autoSaveGroup READ autoSaveGroup) 0053 Q_PROPERTY(bool standardToolBarMenuEnabled READ isStandardToolBarMenuEnabled WRITE setStandardToolBarMenuEnabled) 0054 Q_FLAGS(StandardWindowOption) 0055 0056 public: 0057 /** 0058 * Construct a main window. 0059 * 0060 * @param parent The widget parent. This is usually 0 but it may also be the window 0061 * group leader. In that case, the KisKMainWindow becomes sort of a 0062 * secondary window. 0063 * 0064 * @param f Specify the widget flags. The default is 0065 * Qt::Window and Qt::WA_DeleteOnClose. Qt::Window indicates that a 0066 * main window is a toplevel window, regardless of whether it has a 0067 * parent or not. Qt::WA_DeleteOnClose indicates that a main window is 0068 * automatically destroyed when its window is closed. Pass 0 if 0069 * you do not want this behavior. 0070 * 0071 * @see http://doc.trolltech.com/qt.html#WindowType-enum 0072 * 0073 * KisKMainWindows must be created on the heap with 'new', like: 0074 * \code 0075 * KisKMainWindow *kmw = new KisKMainWindow(...); 0076 * kmw->setObjectName(...); 0077 * \endcode 0078 * 0079 * IMPORTANT: For session management and window management to work 0080 * properly, all main windows in the application should have a 0081 * different name. If you don't do it, KisKMainWindow will create 0082 * a unique name, but it's recommended to explicitly pass a window name that will 0083 * also describe the type of the window. If there can be several windows of the same 0084 * type, append '#' (hash) to the name, and KisKMainWindow will replace it with numbers to make 0085 * the names unique. For example, for a mail client which has one main window showing 0086 * the mails and folders, and which can also have one or more windows for composing 0087 * mails, the name for the folders window should be e.g. "mainwindow" and 0088 * for the composer windows "composer#". 0089 * 0090 */ 0091 explicit KXmlGuiWindow(QWidget *parent = 0, Qt::WindowFlags f = Qt::WindowFlags()); 0092 0093 /** 0094 * \brief Destructor. 0095 * 0096 * Will also destroy the toolbars, and menubar if 0097 * needed. 0098 */ 0099 ~KXmlGuiWindow() override; 0100 0101 /** 0102 * Enables the build of a standard help menu when calling createGUI/setupGUI(). 0103 * 0104 * The default behavior is to build one, you must call this function 0105 * to disable it 0106 */ 0107 void setHelpMenuEnabled(bool showHelpMenu = true); 0108 0109 /** 0110 * Return @p true when the help menu is enabled 0111 */ 0112 bool isHelpMenuEnabled() const; 0113 0114 virtual KisKXMLGUIFactory *guiFactory(); 0115 0116 /** 0117 * Create a GUI given a local XML file. In a regular app you usually want to use 0118 * setupGUI() instead of this one since it does more things for free 0119 * like setting up the toolbar/shortcut edit actions, etc. 0120 * 0121 * If @p xmlfile is 0, 0122 * then it will try to construct a local XML filename like 0123 * appnameui.xmlgui where 'appname' is your app's name. If that file 0124 * does not exist, then the XML UI code will only use the global 0125 * (standard) XML file for the layout purposes. 0126 * 0127 * @param xmlfile The local xmlfile (relative or absolute) 0128 */ 0129 void createGUI(const QString &xmlfile = QString()); 0130 0131 /** 0132 * Sets whether KisKMainWindow should provide a menu that allows showing/hiding 0133 * the available toolbars ( using KToggleToolBarAction ) . In case there 0134 * is only one toolbar configured a simple 'Show \<toolbar name here\>' menu item 0135 * is shown. 0136 * 0137 * The menu / menu item is implemented using xmlgui. It will be inserted in your 0138 * menu structure in the 'Settings' menu. 0139 * 0140 * If your application uses a non-standard xmlgui resource file then you can 0141 * specify the exact position of the menu / menu item by adding a 0142 * <Merge name="StandardToolBarMenuHandler" /> 0143 * line to the settings menu section of your resource file ( usually appname.xmlgui ). 0144 * 0145 * Note that you should enable this feature before calling createGUI() ( or similar ) . 0146 */ 0147 void setStandardToolBarMenuEnabled(bool enable); 0148 bool isStandardToolBarMenuEnabled() const; 0149 0150 /** 0151 * Sets whether KisKMainWindow should provide a menu that allows showing/hiding 0152 * of the statusbar ( using KToggleStatusBarAction ). 0153 * 0154 * The menu / menu item is implemented using xmlgui. It will be inserted 0155 * in your menu structure in the 'Settings' menu. 0156 * 0157 * Note that you should enable this feature before calling createGUI() 0158 * ( or similar ). 0159 * 0160 * If an application maintains the action on its own (i.e. never calls 0161 * this function) a connection needs to be made to let KisKMainWindow 0162 * know when that status (hidden/shown) of the statusbar has changed. 0163 * For example: 0164 * connect(action, SIGNAL(activated()), 0165 * kmainwindow, SLOT(setSettingsDirty())); 0166 * Otherwise the status (hidden/show) of the statusbar might not be saved 0167 * by KisKMainWindow. 0168 */ 0169 void createStandardStatusBarAction(); 0170 0171 /** 0172 * @see setupGUI() 0173 */ 0174 enum StandardWindowOption { 0175 /** 0176 * adds action to show/hide the toolbar(s) and adds 0177 * action to configure the toolbar(s). 0178 * @see setStandardToolBarMenuEnabled 0179 */ 0180 ToolBar = 1, 0181 0182 /** 0183 * adds action to show the key configure action. 0184 */ 0185 Keys = 2, 0186 0187 /** 0188 * adds action to show/hide the statusbar if the 0189 * statusbar exists. @see createStandardStatusBarAction 0190 */ 0191 StatusBar = 4, 0192 0193 /** 0194 * auto-saves (and loads) the toolbar/menubar/statusbar settings and 0195 * window size using the default name. @see setAutoSaveSettings 0196 * 0197 * Typically you want to let the default window size be determined by 0198 * the widgets size hints. Make sure that setupGUI() is called after 0199 * all the widgets are created ( including setCentralWidget ) so the 0200 * default size's will be correct. @see setAutoSaveSettings for 0201 * more information on this topic. 0202 */ 0203 Save = 8, 0204 0205 /** 0206 * calls createGUI() once ToolBar, Keys and Statusbar have been 0207 * taken care of. @see createGUI 0208 * 0209 * NOTE: when using KParts::MainWindow, remove this flag from the 0210 * setupGUI call, since you'll be using createGUI(part) instead. 0211 * @code 0212 * setupGUI(ToolBar | Keys | StatusBar | Save); 0213 * @endcode 0214 */ 0215 Create = 16, 0216 0217 /** 0218 * All the above option 0219 * (this is the default) 0220 */ 0221 Default = ToolBar | Keys | StatusBar | Save | Create 0222 }; 0223 Q_DECLARE_FLAGS(StandardWindowOptions, StandardWindowOption) 0224 0225 /** 0226 * Configures the current windows and its actions in the typical KDE 0227 * fashion. The options are all enabled by default but can be turned 0228 * off if desired through the params or if the prereqs don't exists. 0229 * 0230 * Typically this function replaces createGUI(). 0231 * 0232 * @see StandardWindowOptions 0233 * @note Since this method will restore the state of the application (toolbar, dockwindows 0234 * positions...), you need to have added all your actions to your toolbars etc before 0235 * calling to this method. (This note is only applicable if you are using the Default or 0236 * Save flag). 0237 * @warning If you are calling createGUI yourself, remember to remove the Create flag from 0238 * the @p options parameter. 0239 * 0240 */ 0241 void setupGUI(StandardWindowOptions options = Default, const QString &xmlfile = QString()); 0242 0243 /** 0244 * Configures the current windows and its actions in the typical KDE 0245 * fashion. The options are all enabled by default but can be turned 0246 * off if desired through the params or if the prereqs don't exists. 0247 * 0248 * @p defaultSize The default size of the window 0249 * 0250 * Typically this function replaces createGUI(). 0251 * 0252 * @see StandardWindowOptions 0253 * @note Since this method will restore the state of the application (toolbar, dockwindows 0254 * positions...), you need to have added all your actions to your toolbars etc before 0255 * calling to this method. (This note is only applicable if you are using the Default or 0256 * Save flag). 0257 * @warning If you are calling createGUI yourself, remember to remove the Create flag from 0258 * the @p options parameter. Also, call setupGUI always after you call createGUI. 0259 */ 0260 void setupGUI(const QSize &defaultSize, StandardWindowOptions options = Default, const QString &xmlfile = QString()); 0261 0262 /** 0263 * Returns a pointer to the mainwindows action responsible for the toolbars menu 0264 */ 0265 QAction *toolBarMenuAction(); 0266 0267 /** 0268 * @internal for KisToolBar 0269 */ 0270 void setupToolbarMenuActions(); 0271 0272 // KDE5 TODO: change it to "using KisKXMLGUIBuilder::finalizeGUI;" 0273 void finalizeGUI(KisKXMLGUIClient *client) override; 0274 0275 /** 0276 * @internal 0277 */ 0278 void finalizeGUI(bool force); 0279 0280 // reimplemented for internal reasons 0281 void applyMainWindowSettings(const KConfigGroup &config) override; 0282 0283 public Q_SLOTS: 0284 /** 0285 * Show a standard configure toolbar dialog. 0286 * 0287 * This slot can be connected directly to the action to configure toolbar. 0288 * This is very simple to do that by adding a single line 0289 * \code 0290 * KStandardAction::configureToolbars( this, SLOT( configureToolbars() ), 0291 * actionCollection() ); 0292 * \endcode 0293 */ 0294 virtual void configureToolbars(); 0295 0296 /** 0297 * Apply a state change 0298 * 0299 * Enable and disable actions as defined in the XML rc file 0300 */ 0301 virtual void slotStateChanged(const QString &newstate); 0302 0303 /** 0304 * Apply a state change 0305 * 0306 * Enable and disable actions as defined in the XML rc file, 0307 * can "reverse" the state (disable the actions which should be 0308 * enabled, and vice-versa) if specified. 0309 */ 0310 void slotStateChanged(const QString &newstate, 0311 bool reverse); 0312 0313 protected: 0314 /** 0315 * Reimplemented to catch QEvent::Polish in order to adjust the object name 0316 * if needed, once all constructor code for the main window has run. 0317 * Also reimplemented to catch when a QDockWidget is added or removed. 0318 */ 0319 bool event(QEvent *event) override; 0320 0321 protected Q_SLOTS: 0322 /** 0323 * Rebuilds the GUI after KisKEditToolbar changed the toolbar layout. 0324 * @see configureToolbars() 0325 */ 0326 virtual void saveNewToolbarConfig(); 0327 0328 private: 0329 Q_PRIVATE_SLOT(k_func(), void _k_slotFactoryMakingChanges(bool)) 0330 }; 0331 0332 Q_DECLARE_OPERATORS_FOR_FLAGS(KXmlGuiWindow::StandardWindowOptions) 0333 0334 #endif