|
Krita Source Code Documentation
|
KDE top level main window More...
#include <kmainwindow.h>
Inheritance diagram for KisKMainWindow:Public Slots | |
| void | appHelpActivated (void) |
| void | setSettingsDirty () |
Public Member Functions | |
| virtual void | applyMainWindowSettings (const KConfigGroup &config) |
| KConfigGroup | autoSaveConfigGroup () const |
| QString | autoSaveGroup () const |
| bool | autoSaveSettings () const |
| QString | dbusName () const |
| bool | hasMenuBar () |
| KisKMainWindow (QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags()) | |
| void | resetAutoSaveSettings () |
| bool | restore (int number, bool show=true) |
| void | saveMainWindowSettings (KConfigGroup &config) |
| void | setAutoSaveSettings (const KConfigGroup &group, bool saveWindowSize=true) |
| void | setAutoSaveSettings (const QString &groupName=QLatin1String("MainWindow"), bool saveWindowSize=true) |
| KisToolBar * | toolBar (const QString &name=QString()) |
| QList< KisToolBar * > | toolBars () const |
| ~KisKMainWindow () override | |
| Destructor. | |
Static Public Member Functions | |
| static bool | canBeRestored (int number) |
| static const QString | classNameOfToplevel (int number) |
| static QList< KisKMainWindow * > | memberList () |
Protected Slots | |
| void | saveAutoSaveSettings () |
Protected Member Functions | |
| void | closeEvent (QCloseEvent *) override |
| bool | event (QEvent *event) override |
| KisKMainWindow (KisKMainWindowPrivate &dd, QWidget *parent, Qt::WindowFlags f) | |
| virtual bool | queryClose () |
| virtual void | readGlobalProperties (KConfig *sessionConfig) |
| virtual void | readProperties (const KConfigGroup &) |
| bool | readPropertiesInternal (KConfig *, int) |
| virtual void | saveGlobalProperties (KConfig *sessionConfig) |
| virtual void | saveProperties (KConfigGroup &) |
| void | savePropertiesInternal (KConfig *, int) |
| bool | settingsDirty () const |
| virtual bool | windowsLayoutSavingAllowed () const |
Protected Attributes | |
| KisKMainWindowPrivate *const | k_ptr |
Properties | |
| QString | autoSaveGroup |
| bool | autoSaveSettings |
| bool | hasMenuBar |
Private Member Functions | |
| Q_PRIVATE_SLOT (k_func(), void _k_slotSettingsChanged(int)) Q_PRIVATE_SLOT(k_func() | |
Friends | |
| class | DockResizeListener |
| class | KMWSessionManager |
KDE top level main window
Top level widget that provides toolbars, a status line and a frame.
It should be used as a top level (parent-less) widget. It manages the geometry for all its children, including your main widget.
Normally, you will inherit from KisKMainWindow, then construct (or use some existing) widget as your main view. You can set only one main view.
You can add as many toolbars as you like. There can be only one menubar and only one statusbar.
The toolbars, menubar, and statusbar can be created by the KisKMainWindow and - unlike the old KisKMainWindow - may, but do not have to, be deleted by you. KisKMainWindow will handle that internally.
Height and width can be operated independently from each other. Simply define the minimum/maximum height/width of your main widget and KisKMainWindow will take this into account. For fixed size windows set your main widget to a fixed size.
Fixed aspect ratios (heightForWidth()) and fixed width widgets are not supported.
KisKMainWindow will set icon, mini icon and caption, which it gets from KApplication. It provides full session management, and will save its position, geometry and positions of toolbars and menubar on logout. If you want to save additional data, reimplement saveProperties() and (to read them again on next login) readProperties(). To save special data about your data, reimplement saveGlobalProperties(). To warn user that application or windows have unsaved data on close or logout, reimplement queryClose().
You have to implement session restoring also in your main() function. There are also kRestoreMainWindows convenience functions which can do this for you and restore all your windows on next login.
Note that KisKMainWindow uses KGlobal::ref() and KGlobal::deref() so that closing the last mainwindow will quit the application unless there is still something that holds a ref in KGlobal - like a KIO job, or a systray icon.
Definition at line 88 of file kmainwindow.h.
|
explicit |
Construct a main window.
| parent | The widget parent. This is usually 0 but it may also be the window group leader. In that case, the KisKMainWindow becomes sort of a secondary window. |
| f | Specify the window flags. The default is none. |
Note that a KisKMainWindow per-default is created with the WA_DeleteOnClose attribute, i.e. it is automatically destroyed when the window is closed. If you do not want this behavior, call setAttribute(Qt::WA_DeleteOnClose, false);
KisKMainWindows must be created on the heap with 'new', like:
IMPORTANT: For session management and window management to work properly, all main windows in the application should have a different name. If you don't do it, KisKMainWindow will create a unique name, but it's recommended to explicitly pass a window name that will also describe the type of the window. If there can be several windows of the same type, append '#' (hash) to the name, and KisKMainWindow will replace it with numbers to make the names unique. For example, for a mail client which has one main window showing the mails and folders, and which can also have one or more windows for composing mails, the name for the folders window should be e.g. "mainwindow" and for the composer windows "composer#".
Definition at line 159 of file kmainwindow.cpp.
|
override |
Destructor.
Will also destroy the toolbars, and menubar if needed.
Definition at line 337 of file kmainwindow.cpp.
References KisKMainWindowPrivate::dockResizeListener, and k_ptr.
|
protected |
Definition at line 165 of file kmainwindow.cpp.
References KisKMainWindowPrivate::init(), and k_ptr.
Open the help page for the application.
The application name is used as a key to determine what to display and the system will attempt to open <appName>/index.html.
This method is intended for use by a help button in the toolbar or components outside the regular help menu. Use helpMenu() when you want to provide access to the help system from the help menu.
Example (adding a help button to the first toolbar):
Definition at line 398 of file kmainwindow.cpp.
References K_D.
|
virtual |
Read settings for statusbar, menubar and toolbar from their respective groups in the config file and apply them.
| config | Config group to read the settings from. KF5 porting note: the unused bool argument was removed, make sure to remove it from your reimplementations too! And add a override for good measure. |
Reimplemented in KXmlGuiWindow.
Definition at line 562 of file kmainwindow.cpp.
References KisToolBar::applySettings(), internalMenuBar(), internalStatusBar(), K_D, KisToolBar::setToolBarsLocked(), and toolBars().
| KConfigGroup KisKMainWindow::autoSaveConfigGroup | ( | ) | const |
Definition at line 692 of file kmainwindow.cpp.
References K_D.
| QString KisKMainWindow::autoSaveGroup | ( | ) | const |
NOTE: you should rather use saveAutoSaveSettings() for saving or autoSaveConfigGroup() for loading. This method doesn't make sense if setAutoSaveSettings(KConfigGroup) was called.
Definition at line 686 of file kmainwindow.cpp.
References K_D.
| bool KisKMainWindow::autoSaveSettings | ( | ) | const |
Definition at line 680 of file kmainwindow.cpp.
References K_D.
|
static |
If the session did contain so high a number, true is returned, else false.
Definition at line 344 of file kmainwindow.cpp.
|
static |
Returns the className() of the number of the toplevel window which should be restored.
This is only useful if your application uses different kinds of toplevel windows.
Definition at line 359 of file kmainwindow.cpp.
References WINDOW_PROPERTIES.
|
overrideprotected |
Reimplemented to autosave settings and call queryClose().
We recommend that you reimplement queryClose() rather than closeEvent(). If you do it anyway, ensure to call the base implementation to keep the feature of auto-saving window settings working.
Definition at line 410 of file kmainwindow.cpp.
References K_D, queryClose(), and saveAutoSaveSettings().
| QString KisKMainWindow::dbusName | ( | ) | const |
Returns the path under which this window's D-Bus object is exported.
Definition at line 832 of file kmainwindow.cpp.
|
overrideprotected |
Reimplemented to catch QEvent::Polish in order to adjust the object name if needed, once all constructor code for the main window has run. Also reimplemented to catch when a QDockWidget is added or removed.
Definition at line 708 of file kmainwindow.cpp.
References connect(), KisKMainWindowPrivate::dockResizeListener, event(), K_D, k_ptr, and setSettingsDirty().
| bool KisKMainWindow::hasMenuBar | ( | ) |
Returns true, if there is a menubar
|
static |
List of members of KisKMainWindow class.
Definition at line 827 of file kmainwindow.cpp.
|
private |
|
protectedvirtual |
Called before the window is closed, either by the user or indirectly by the session manager.
The purpose of this function is to prepare the window in a way that it is safe to close it, i.e. without the user losing some data.
Default implementation returns true. Returning false will cancel the closing, and, if KApplication::sessionSaving() is true, it will also cancel KDE logout.
Reimplement this function to prevent the user from losing data. Example:
Note that you should probably not actually close the document from within this method, as it may be called by the session manager before the session is saved. If the document is closed before the session save occurs, its location might not be properly saved. In addition, the session shutdown may be canceled, in which case the document should remain open.
Definition at line 435 of file kmainwindow.cpp.
|
protectedvirtual |
The counterpart of saveGlobalProperties().
Read the application-specific properties in again.
Definition at line 444 of file kmainwindow.cpp.
|
inlineprotectedvirtual |
Read your instance-specific properties.
Is called indirectly by restore().
Definition at line 422 of file kmainwindow.h.
|
protected |
Definition at line 531 of file kmainwindow.cpp.
References applyMainWindowSettings(), K_D, readGlobalProperties(), readProperties(), and WINDOW_PROPERTIES.
| void KisKMainWindow::resetAutoSaveSettings | ( | ) |
Disable the auto-save-settings feature. You don't normally need to call this, ever.
Definition at line 671 of file kmainwindow.cpp.
References K_D.
| bool KisKMainWindow::restore | ( | int | number, |
| bool | show = true ) |
Try to restore the toplevel widget as defined by number (1..X).
You should call canBeRestored() first.
If the session did not contain so high a number, the configuration is not changed and false returned.
That means clients could simply do the following:
Note that if show is true (default), QWidget::show() is called implicitly in restore.
With this you can easily restore all toplevel windows of your application.
If your application uses different kinds of toplevel windows, then you can use KisKMainWindow::classNameOfToplevel(n) to determine the exact type before calling the childMW constructor in the example from above.
Note that you don't need to deal with this function. Use the kRestoreMainWindows() convenience template function instead!
Definition at line 380 of file kmainwindow.cpp.
References canBeRestored(), and readPropertiesInternal().
|
protectedslot |
This slot should only be called in case you reimplement closeEvent() and if you are using the "auto-save" feature. In all other cases, setSettingsDirty() should be called instead to benefit from the delayed saving.
Example:
Definition at line 698 of file kmainwindow.cpp.
References K_D, and saveMainWindowSettings().
|
protectedvirtual |
Save your application-wide properties. The function is invoked when the session manager requests your application to save its state.
This function is similar to saveProperties() but is only called for the very first main window, regardless how many main window are open.
Override it if you need to save other data about your documents on session end. sessionConfig is a config to which that data should be saved. Normally, you don't need this function. But if you want to save data about your documents that are not in opened windows you might need it.
Default implementation does nothing.
Definition at line 440 of file kmainwindow.cpp.
| void KisKMainWindow::saveMainWindowSettings | ( | KConfigGroup & | config | ) |
Save settings for statusbar, menubar and toolbar to their respective groups in the config group config.
| config | Config group to save the settings to. |
Definition at line 469 of file kmainwindow.cpp.
References internalMenuBar(), internalStatusBar(), K_D, KisToolBar::saveSettings(), toolBars(), KisToolBar::toolBarsLocked(), and windowsLayoutSavingAllowed().
|
inlineprotectedvirtual |
Save your instance-specific properties. The function is invoked when the session manager requests your application to save its state.
Please reimplement these function in childclasses.
Note: No user interaction is allowed in this function!
Definition at line 415 of file kmainwindow.h.
|
protected |
Definition at line 448 of file kmainwindow.cpp.
References K_D, saveMainWindowSettings(), saveProperties(), and WINDOW_PROPERTIES.
| void KisKMainWindow::setAutoSaveSettings | ( | const KConfigGroup & | group, |
| bool | saveWindowSize = true ) |
Overload that lets you specify a KConfigGroup. This allows the settings to be saved into another file than KSharedConfig::openConfig().
Definition at line 655 of file kmainwindow.cpp.
References applyMainWindowSettings(), and K_D.
| void KisKMainWindow::setAutoSaveSettings | ( | const QString & | groupName = QLatin1String("MainWindow"), |
| bool | saveWindowSize = true ) |
Call this to enable "auto-save" of toolbar/menubar/statusbar settings (and optionally window size). If the *bars were moved around/shown/hidden when the window is closed, saveMainWindowSettings( KConfigGroup(KSharedConfig::openConfig(), groupName) ) will be called.
| groupName | a name that identifies this "type of window". You can have several types of window in the same application. |
| saveWindowSize | set it to true to include the window size when saving. |
Typically, you will call setAutoSaveSettings() in your KisKMainWindow-inherited class constructor, and it will take care of restoring and saving automatically. Make sure you call this after all your *bars have been created.
To make sure that KisKMainWindow properly obtains the default size of the window you should do the following:
Definition at line 650 of file kmainwindow.cpp.
References setAutoSaveSettings().
|
slot |
Tell the main window that it should save its settings when being closed. This is part of the auto-save-settings feature. For everything related to toolbars this happens automatically, but you have to call setSettingsDirty() in the slot that toggles the visibility of the statusbar.
Definition at line 633 of file kmainwindow.cpp.
References K_D.
|
protected |
| KisToolBar * KisKMainWindow::toolBar | ( | const QString & | name = QString() | ) |
Returns a pointer to the toolbar with the specified name. This refers to toolbars created dynamically from the XML UI framework. If the toolbar does not exist one will be created.
| name | The internal name of the toolbar. If no name is specified "mainToolBar" is assumed. |
Definition at line 799 of file kmainwindow.cpp.
| QList< KisToolBar * > KisKMainWindow::toolBars | ( | ) | const |
Definition at line 815 of file kmainwindow.cpp.
References toolBar().
|
protectedvirtual |
Reimplemented in KisMainWindow.
Definition at line 645 of file kmainwindow.cpp.
|
friend |
Definition at line 91 of file kmainwindow.h.
|
friend |
Definition at line 90 of file kmainwindow.h.
|
protected |
Definition at line 486 of file kmainwindow.h.
|
read |
Definition at line 96 of file kmainwindow.h.
|
read |
Definition at line 95 of file kmainwindow.h.
|
read |
Definition at line 94 of file kmainwindow.h.