Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKMainWindow Class Reference

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)
 
KisToolBartoolBar (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
 

Detailed Description

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.

See also
KApplication
Author
Reginald Stadlbauer (reggi.nosp@m.e@kd.nosp@m.e.org) Stephan Kulow (coolo.nosp@m.@kde.nosp@m..org), Matthias Ettrich (ettri.nosp@m.ch@k.nosp@m.de.or.nosp@m.g), Chris Schlaeger (cs@kd.nosp@m.e.or.nosp@m.g), Sven Radej (radej.nosp@m.@kde.nosp@m..org). Maintained by David Faure (faure.nosp@m.@kde.nosp@m..org)

Definition at line 88 of file kmainwindow.h.

Constructor & Destructor Documentation

◆ KisKMainWindow() [1/2]

KisKMainWindow::KisKMainWindow ( QWidget * parent = 0,
Qt::WindowFlags f = Qt::WindowFlags() )
explicit

Construct a main window.

Parameters
parentThe 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.
fSpecify 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:

kmw->setObjectName(...);
KDE top level main window
Definition kmainwindow.h:89
KisKMainWindow(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())

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.

160 : QMainWindow(parent, f), k_ptr(new KisKMainWindowPrivate)
161{
162 k_ptr->init(this);
163}
void init(KisKMainWindow *_q)
KisKMainWindowPrivate *const k_ptr

◆ ~KisKMainWindow()

KisKMainWindow::~KisKMainWindow ( )
override

Destructor.

Will also destroy the toolbars, and menubar if needed.

Definition at line 337 of file kmainwindow.cpp.

338{
339 sMemberList()->removeAll(this);
340 delete static_cast<QObject *>(k_ptr->dockResizeListener); //so we don't get anymore events after k_ptr is destroyed
341 delete k_ptr;
342}
QPointer< QObject > dockResizeListener

References KisKMainWindowPrivate::dockResizeListener, and k_ptr.

◆ KisKMainWindow() [2/2]

KisKMainWindow::KisKMainWindow ( KisKMainWindowPrivate & dd,
QWidget * parent,
Qt::WindowFlags f )
protected

Definition at line 165 of file kmainwindow.cpp.

166 : QMainWindow(parent, f), k_ptr(&dd)
167{
168 k_ptr->init(this);
169}

References KisKMainWindowPrivate::init(), and k_ptr.

Member Function Documentation

◆ appHelpActivated

void KisKMainWindow::appHelpActivated ( void )
slot

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):

toolBar(0)->addAction(KisIconUtils::loadIcon("help-contents"), i18n("Help"),
this, SLOT(appHelpActivated()));
KisToolBar * toolBar(const QString &name=QString())
void appHelpActivated(void)
QIcon loadIcon(const QString &name)

Definition at line 398 of file kmainwindow.cpp.

399{
401 if (!d->helpMenu) {
402 d->helpMenu = new KisKHelpMenu(this);
403 if (!d->helpMenu) {
404 return;
405 }
406 }
407 d->helpMenu->appHelpActivated();
408}
Standard KDE help menu with dialog boxes.
Definition khelpmenu.h:106
#define K_D(Class)

References K_D.

◆ applyMainWindowSettings()

void KisKMainWindow::applyMainWindowSettings ( const KConfigGroup & config)
virtual

Read settings for statusbar, menubar and toolbar from their respective groups in the config file and apply them.

Parameters
configConfig 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.

563{
565 //qDebug(200) << "KisKMainWindow::applyMainWindowSettings " << cg.name();
566
567 QWidget *focusedWidget = QApplication::focusWidget();
568
569 const bool oldLetDirtySettings = d->letDirtySettings;
570 d->letDirtySettings = false;
571
572 if (!d->sizeApplied) {
573 winId(); // ensure there's a window created
574 KWindowConfig::restoreWindowSize(windowHandle(), cg);
575 // NOTICE: QWindow::setGeometry() does NOT impact the backing QWidget geometry even if the platform
576 // window was created -> QTBUG-40584. We therefore copy the size here.
577 // TODO: remove once this was resolved in QWidget QPA
578 resize(windowHandle()->size());
579 d->sizeApplied = true;
580 }
581
582 QStatusBar *sb = internalStatusBar(this);
583 if (sb) {
584 QString entry = cg.readEntry("StatusBar", "Enabled");
585 sb->setVisible( entry != QLatin1String("Disabled") );
586 }
587
588 QMenuBar *mb = internalMenuBar(this);
589 if (mb && !mb->isNativeMenuBar()) {
590 QString entry = cg.readEntry("MenuBar", "Enabled");
591#ifdef Q_OS_ANDROID
592 // HACK: Previously, since the native menubar was enabled, this made the
593 // value in Config = "Disabled". This makes the menubar not show up on
594 // devices.
595 entry = QLatin1String("Enabled");
596#endif
597 mb->setVisible( entry != QLatin1String("Disabled") );
598 }
599
600 {
601 QString entry = cg.readEntry("ToolBarsMovable", "Disabled");
602 KisToolBar::setToolBarsLocked(entry == QLatin1String("Disabled"));
603 }
604
605 int n = 1; // Toolbar counter. toolbars are counted from 1,
606 foreach (KisToolBar *toolbar, toolBars()) {
607 QByteArray groupName("Toolbar");
608 // Give a number to the toolbar, but prefer a name if there is one,
609 // because there's no real guarantee on the ordering of toolbars
610 groupName += (toolbar->objectName().isEmpty() ? QByteArray::number(n) : QByteArray(" ").append(toolbar->objectName().toUtf8()));
611
612 KConfigGroup toolbarGroup(&cg, groupName.constData());
613 toolbar->applySettings(toolbarGroup);
614 n++;
615 }
616
617 QByteArray state;
618 if (cg.hasKey("State")) {
619 state = cg.readEntry("State", state);
620 state = QByteArray::fromBase64(state);
621 // One day will need to load the version number, but for now, assume 0
622 restoreState(state);
623 }
624
625 if (focusedWidget) {
626 focusedWidget->setFocus();
627 }
628
629 d->settingsDirty = false;
630 d->letDirtySettings = oldLetDirtySettings;
631}
QList< KisToolBar * > toolBars() const
Floatable toolbar with auto resize.
Definition ktoolbar.h:47
void applySettings(const KConfigGroup &cg)
static void setToolBarsLocked(bool locked)
static QStatusBar * internalStatusBar(KisKMainWindow *mw)
static QMenuBar * internalMenuBar(KisKMainWindow *mw)
KRITAWIDGETUTILS_EXPORT void restoreState(QWidget *parent, const QString &dialogName, const QMap< QString, QVariant > &defaults=QMap< QString, QVariant >())
restoreState restores the state of the dialog
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KisToolBar::applySettings(), internalMenuBar(), internalStatusBar(), K_D, KisToolBar::setToolBarsLocked(), and toolBars().

◆ autoSaveConfigGroup()

KConfigGroup KisKMainWindow::autoSaveConfigGroup ( ) const
Returns
the group used for setting-autosaving. Only meaningful if setAutoSaveSettings() was called. This can be useful for forcing an apply, e.g. after using KisKEditToolbar.
Since
4.1

Definition at line 692 of file kmainwindow.cpp.

693{
694 K_D(const KisKMainWindow);
695 return d->autoSaveSettings ? d->autoSaveGroup : KConfigGroup();
696}

References K_D.

◆ autoSaveGroup()

QString KisKMainWindow::autoSaveGroup ( ) const
Returns
the group used for setting-autosaving. Only meaningful if setAutoSaveSettings(QString) was called. This can be useful for forcing a save or an apply, e.g. before and after using KisKEditToolbar.

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.

687{
688 K_D(const KisKMainWindow);
689 return d->autoSaveSettings ? d->autoSaveGroup.name() : QString();
690}

References K_D.

◆ autoSaveSettings()

bool KisKMainWindow::autoSaveSettings ( ) const
Returns
the current autosave setting, i.e. true if setAutoSaveSettings() was called, false by default or if resetAutoSaveSettings() was called.

Definition at line 680 of file kmainwindow.cpp.

681{
682 K_D(const KisKMainWindow);
683 return d->autoSaveSettings;
684}

References K_D.

◆ canBeRestored()

bool KisKMainWindow::canBeRestored ( int number)
static

If the session did contain so high a number, true is returned, else false.

See also
restore()

Definition at line 344 of file kmainwindow.cpp.

345{
346 if (!qApp->isSessionRestored()) {
347 return false;
348 }
349 KConfig *config = KConfigGui::sessionConfig();
350 if (!config) {
351 return false;
352 }
353
354 KConfigGroup group(config, "Number");
355 const int n = group.readEntry("NumberOfWindows", 1);
356 return number >= 1 && number <= n;
357}

◆ classNameOfToplevel()

const QString KisKMainWindow::classNameOfToplevel ( int number)
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.

360{
361 return QString();
362#if 0
363 if (!qApp->isSessionRestored()) {
364 return QString();
365 }
366 KConfig *config = KConfigGui::sessionConfig();
367 if (!config) {
368 return QString();
369 }
370
371 KConfigGroup group(config, QByteArray(WINDOW_PROPERTIES).append(QByteArray::number(number)).constData());
372 if (!group.hasKey("ClassName")) {
373 return QString();
374 } else {
375 return group.readEntry("ClassName");
376 }
377#endif
378}
static const char WINDOW_PROPERTIES[]

References WINDOW_PROPERTIES.

◆ closeEvent()

void KisKMainWindow::closeEvent ( QCloseEvent * e)
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.

411{
413
414 // Save settings if auto-save is enabled, and settings have changed
415 if (d->settingsTimer && d->settingsTimer->isActive()) {
416 d->settingsTimer->stop();
418 }
419 if (d->sizeTimer && d->sizeTimer->isActive()) {
420 d->sizeTimer->stop();
421 d->_k_slotSaveAutoSaveSize();
422 }
423
424 if (queryClose()) {
425 // widgets will start destroying themselves at this point and we don't
426 // want to save state anymore after this as it might be incorrect
427 d->autoSaveSettings = false;
428 d->letDirtySettings = false;
429 e->accept();
430 } else {
431 e->ignore(); //if the window should not be closed, don't close it
432 }
433}
void saveAutoSaveSettings()
virtual bool queryClose()

References K_D, queryClose(), and saveAutoSaveSettings().

◆ dbusName()

QString KisKMainWindow::dbusName ( ) const

Returns the path under which this window's D-Bus object is exported.

Since
4.0.1

Definition at line 832 of file kmainwindow.cpp.

833{
834 return k_func()->dbusName;
835}

◆ event()

bool KisKMainWindow::event ( QEvent * event)
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.

709{
711 switch (ev->type()) {
712#ifdef Q_OS_WIN
713 case QEvent::Move:
714#endif
715 case QEvent::Resize:
716 d->setSizeDirty();
717 break;
718 case QEvent::Polish:
719 d->polish(this);
720 break;
721 case QEvent::ChildPolished: {
722 QChildEvent *event = static_cast<QChildEvent *>(ev);
723 QDockWidget *dock = qobject_cast<QDockWidget *>(event->child());
724 KisToolBar *toolbar = qobject_cast<KisToolBar *>(event->child());
725 QMenuBar *menubar = qobject_cast<QMenuBar *>(event->child());
726 if (dock) {
727 connect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
728 this, SLOT(setSettingsDirty()));
729 connect(dock, SIGNAL(visibilityChanged(bool)),
730 this, SLOT(setSettingsDirty()), Qt::QueuedConnection);
731 connect(dock, SIGNAL(topLevelChanged(bool)),
732 this, SLOT(setSettingsDirty()));
733
734 // there is no signal emitted if the size of the dock changes,
735 // hence install an event filter instead
736 dock->installEventFilter(k_ptr->dockResizeListener);
737 } else if (toolbar) {
738 // there is no signal emitted if the size of the toolbar changes,
739 // hence install an event filter instead
740 toolbar->installEventFilter(k_ptr->dockResizeListener);
741 } else if (menubar) {
742 // there is no signal emitted if the size of the menubar changes,
743 // hence install an event filter instead
744 menubar->installEventFilter(k_ptr->dockResizeListener);
745 }
746 }
747 break;
748 case QEvent::ChildRemoved: {
749 QChildEvent *event = static_cast<QChildEvent *>(ev);
750 QDockWidget *dock = qobject_cast<QDockWidget *>(event->child());
751 KisToolBar *toolbar = qobject_cast<KisToolBar *>(event->child());
752 QMenuBar *menubar = qobject_cast<QMenuBar *>(event->child());
753 if (dock) {
754 disconnect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
755 this, SLOT(setSettingsDirty()));
756 disconnect(dock, SIGNAL(visibilityChanged(bool)),
757 this, SLOT(setSettingsDirty()));
758 disconnect(dock, SIGNAL(topLevelChanged(bool)),
759 this, SLOT(setSettingsDirty()));
760 dock->removeEventFilter(k_ptr->dockResizeListener);
761 } else if (toolbar) {
762 toolbar->removeEventFilter(k_ptr->dockResizeListener);
763 } else if (menubar) {
764 menubar->removeEventFilter(k_ptr->dockResizeListener);
765 }
766 }
767 break;
768 default:
769 break;
770 }
771 return QMainWindow::event(ev);
772}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setSettingsDirty()
bool event(QEvent *event) override

References connect(), KisKMainWindowPrivate::dockResizeListener, event(), K_D, k_ptr, and setSettingsDirty().

◆ hasMenuBar()

bool KisKMainWindow::hasMenuBar ( )

Returns true, if there is a menubar

◆ memberList()

QList< KisKMainWindow * > KisKMainWindow::memberList ( )
static

List of members of KisKMainWindow class.

Definition at line 827 of file kmainwindow.cpp.

828{
829 return *sMemberList();
830}

◆ Q_PRIVATE_SLOT()

KisKMainWindow::Q_PRIVATE_SLOT ( k_func() ,
void _k_slotSettingsChangedint )
private

◆ queryClose()

bool KisKMainWindow::queryClose ( )
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:

switch ( KMessageBox::warningYesNoCancel( this,
i18n("Save changes to document foo?")) ) {
case KMessageBox::Yes :
// save document here. If saving fails, return false;
return true;
case KMessageBox::No :
return true;
default: // cancel
return false;

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.

See also
KApplication::sessionSaving()

Definition at line 435 of file kmainwindow.cpp.

436{
437 return true;
438}

◆ readGlobalProperties()

void KisKMainWindow::readGlobalProperties ( KConfig * sessionConfig)
protectedvirtual

The counterpart of saveGlobalProperties().

Read the application-specific properties in again.

Definition at line 444 of file kmainwindow.cpp.

445{
446}

◆ readProperties()

virtual void KisKMainWindow::readProperties ( const KConfigGroup & )
inlineprotectedvirtual

Read your instance-specific properties.

Is called indirectly by restore().

Definition at line 422 of file kmainwindow.h.

422{}

◆ readPropertiesInternal()

bool KisKMainWindow::readPropertiesInternal ( KConfig * config,
int number )
protected

Definition at line 531 of file kmainwindow.cpp.

532{
534
535 const bool oldLetDirtySettings = d->letDirtySettings;
536 d->letDirtySettings = false;
537
538 if (number == 1) {
539 readGlobalProperties(config);
540 }
541
542 // in order they are in toolbar list
543 KConfigGroup cg(config, QByteArray(WINDOW_PROPERTIES).append(QByteArray::number(number)).constData());
544
545 // restore the object name (window role)
546 if (cg.hasKey("ObjectName")) {
547 setObjectName(cg.readEntry("ObjectName"));
548 }
549
550 d->sizeApplied = false; // since we are changing config file, reload the size of the window
551 // if necessary. Do it before the call to applyMainWindowSettings.
552 applyMainWindowSettings(cg); // Menubar, statusbar and toolbar settings.
553
554 KConfigGroup grp(config, QByteArray::number(number).constData());
555 readProperties(grp);
556
557 d->letDirtySettings = oldLetDirtySettings;
558
559 return true;
560}
virtual void readGlobalProperties(KConfig *sessionConfig)
virtual void readProperties(const KConfigGroup &)
virtual void applyMainWindowSettings(const KConfigGroup &config)

References applyMainWindowSettings(), K_D, readGlobalProperties(), readProperties(), and WINDOW_PROPERTIES.

◆ resetAutoSaveSettings()

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.

672{
674 d->autoSaveSettings = false;
675 if (d->settingsTimer) {
676 d->settingsTimer->stop();
677 }
678}

References K_D.

◆ restore()

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:

if (qApp->isSessionRestored()){
int n = 1;
(new childMW)->restore(n);
n++;
}
} else {
// create default application as usual
}
static bool canBeRestored(int number)
bool restore(int number, bool show=true)

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!

See also
kRestoreMainWindows()
readProperties()
canBeRestored()

Definition at line 380 of file kmainwindow.cpp.

381{
382#if 0
383 if (!canBeRestored(number)) {
384 return false;
385 }
386 KConfig *config = KConfigGui::sessionConfig();
387 if (readPropertiesInternal(config, number)) {
388 if (show) {
389 KisKMainWindow::show();
390 }
391 return false;
392 }
393#endif
394 return false;
395}
bool readPropertiesInternal(KConfig *, int)

References canBeRestored(), and readPropertiesInternal().

◆ saveAutoSaveSettings

void KisKMainWindow::saveAutoSaveSettings ( )
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.

See also
setAutoSaveSettings
setSettingsDirty

Example:

void MyMainWindow::closeEvent( QCloseEvent *e )
{
// Save settings if auto-save is enabled, and settings have changed
..
}
bool settingsDirty() const
bool autoSaveSettings
Definition kmainwindow.h:95

Definition at line 698 of file kmainwindow.cpp.

699{
701 Q_ASSERT(d->autoSaveSettings);
702 //qDebug(200) << "KisKMainWindow::saveAutoSaveSettings -> saving settings";
703 saveMainWindowSettings(d->autoSaveGroup);
704 d->autoSaveGroup.sync();
705 d->settingsDirty = false;
706}
void saveMainWindowSettings(KConfigGroup &config)

References K_D, and saveMainWindowSettings().

◆ saveGlobalProperties()

void KisKMainWindow::saveGlobalProperties ( KConfig * sessionConfig)
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.

441{
442}

◆ saveMainWindowSettings()

void KisKMainWindow::saveMainWindowSettings ( KConfigGroup & config)

Save settings for statusbar, menubar and toolbar to their respective groups in the config group config.

Parameters
configConfig group to save the settings to.

Definition at line 469 of file kmainwindow.cpp.

470{
471 if (!windowsLayoutSavingAllowed()) return;
472
474 //qDebug(200) << "KisKMainWindow::saveMainWindowSettings " << cg.name();
475
476 // Called by session management - or if we want to save the window size anyway
477 if (d->autoSaveWindowSize) {
478 KWindowConfig::saveWindowSize(windowHandle(), cg);
479 }
480
481 // One day will need to save the version number, but for now, assume 0
482 // Utilize the QMainWindow::saveState() functionality.
483 const QByteArray state = saveState();
484 cg.writeEntry("State", state.toBase64());
485
486 QStatusBar *sb = internalStatusBar(this);
487 if (sb) {
488 if (!cg.hasDefault("StatusBar") && !sb->isHidden()) {
489 cg.revertToDefault("StatusBar");
490 } else {
491 cg.writeEntry("StatusBar", sb->isHidden() ? "Disabled" : "Enabled");
492 }
493 }
494
495 QMenuBar *mb = internalMenuBar(this);
496 if (mb && !mb->isNativeMenuBar()) {
497 if (!cg.hasDefault("MenuBar") && !mb->isHidden()) {
498 cg.revertToDefault("MenuBar");
499 } else {
500 // with native Menu Bar we don't have an easy way of knowing if it
501 // is Enabled or not, so we assume it is to prevent any mishap if
502 // the flag is toggled
503 if (!QCoreApplication::testAttribute(Qt::AA_DontUseNativeMenuBar)) {
504 cg.writeEntry("MenuBar", "Enabled");
505 }
506 cg.writeEntry("MenuBar", mb->isHidden() ? "Disabled" : "Enabled");
507 }
508 }
509
510 {
511 if (!cg.hasDefault("ToolBarsMovable") && KisToolBar::toolBarsLocked()) {
512 cg.revertToDefault("ToolBarsMovable");
513 } else {
514 cg.writeEntry("ToolBarsMovable", KisToolBar::toolBarsLocked() ? "Disabled" : "Enabled");
515 }
516 }
517
518 int n = 1; // Toolbar counter. toolbars are counted from 1,
519 foreach (KisToolBar *toolbar, toolBars()) {
520 QByteArray groupName("Toolbar");
521 // Give a number to the toolbar, but prefer a name if there is one,
522 // because there's no real guarantee on the ordering of toolbars
523 groupName += (toolbar->objectName().isEmpty() ? QByteArray::number(n) : QByteArray(" ").append(toolbar->objectName().toUtf8()));
524
525 KConfigGroup toolbarGroup(&cg, groupName.constData());
526 toolbar->saveSettings(toolbarGroup);
527 n++;
528 }
529}
virtual bool windowsLayoutSavingAllowed() const
static bool toolBarsLocked()
void saveSettings(KConfigGroup &cg)
Definition ktoolbar.cpp:820
KRITAWIDGETUTILS_EXPORT void saveState(QWidget *parent, const QString &dialogName)
saveState saves the state for the specified widgets

References internalMenuBar(), internalStatusBar(), K_D, KisToolBar::saveSettings(), toolBars(), KisToolBar::toolBarsLocked(), and windowsLayoutSavingAllowed().

◆ saveProperties()

virtual void KisKMainWindow::saveProperties ( KConfigGroup & )
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.

415{}

◆ savePropertiesInternal()

void KisKMainWindow::savePropertiesInternal ( KConfig * config,
int number )
protected

Definition at line 448 of file kmainwindow.cpp.

449{
451 const bool oldASWS = d->autoSaveWindowSize;
452 d->autoSaveWindowSize = true; // make saveMainWindowSettings save the window size
453
454 KConfigGroup cg(config, QByteArray(WINDOW_PROPERTIES).append(QByteArray::number(number)).constData());
455
456 // store objectName, className, Width and Height for later restoring
457 // (Only useful for session management)
458 cg.writeEntry("ObjectName", objectName());
459 cg.writeEntry("ClassName", metaObject()->className());
460
461 saveMainWindowSettings(cg); // Menubar, statusbar and Toolbar settings.
462
463 cg = KConfigGroup(config, QByteArray::number(number).constData());
464 saveProperties(cg);
465
466 d->autoSaveWindowSize = oldASWS;
467}
virtual void saveProperties(KConfigGroup &)

References K_D, saveMainWindowSettings(), saveProperties(), and WINDOW_PROPERTIES.

◆ setAutoSaveSettings() [1/2]

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().

Since
4.1

Definition at line 655 of file kmainwindow.cpp.

657{
659 d->autoSaveSettings = true;
660 d->autoSaveGroup = group;
661 d->autoSaveWindowSize = saveWindowSize;
662
663 if (!saveWindowSize && d->sizeTimer) {
664 d->sizeTimer->stop();
665 }
666
667 // Now read the previously saved settings
668 applyMainWindowSettings(d->autoSaveGroup);
669}

References applyMainWindowSettings(), and K_D.

◆ setAutoSaveSettings() [2/2]

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.

Parameters
groupNamea name that identifies this "type of window". You can have several types of window in the same application.
saveWindowSizeset 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:

  • Remove hard coded resize() calls in the constructor or main, they should be removed in favor of letting the automatic resizing determine the default window size. Hard coded window sizes will be wrong for users that have big fonts, use different styles, long/small translations, large toolbars, and other factors.
  • Put the setAutoSaveSettings ( or setupGUI() ) call after all widgets have been created and placed inside the main window (i.e. for 99% of apps setCentralWidget())
  • Widgets that inherit from QWidget (like game boards) should overload "virtual QSize sizeHint() const;" to specify a default size rather than letting QWidget::adjust use the default size of 0x0.

Definition at line 650 of file kmainwindow.cpp.

651{
652 setAutoSaveSettings(KConfigGroup(KSharedConfig::openConfig(), groupName), saveWindowSize);
653}
void setAutoSaveSettings(const QString &groupName=QLatin1String("MainWindow"), bool saveWindowSize=true)

References setAutoSaveSettings().

◆ setSettingsDirty

void KisKMainWindow::setSettingsDirty ( )
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.

634{
636 d->setSettingsDirty();
637}

References K_D.

◆ settingsDirty()

bool KisKMainWindow::settingsDirty ( ) const
protected

For inherited classes

Definition at line 639 of file kmainwindow.cpp.

640{
641 K_D(const KisKMainWindow);
642 return d->settingsDirty;
643}

References K_D.

◆ toolBar()

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.

Parameters
nameThe internal name of the toolbar. If no name is specified "mainToolBar" is assumed.
Returns
A pointer to the toolbar

Definition at line 799 of file kmainwindow.cpp.

800{
801 QString childName = name;
802 if (childName.isEmpty()) {
803 childName = QStringLiteral("mainToolBar");
804 }
805
806 KisToolBar *tb = findChild<KisToolBar *>(childName);
807 if (tb) {
808 return tb;
809 }
810
811 KisToolBar *toolbar = new KisToolBar(childName, this); // non-XMLGUI toolbar
812 return toolbar;
813}
const char * name(StandardAction id)

◆ toolBars()

QList< KisToolBar * > KisKMainWindow::toolBars ( ) const
Returns
A list of all toolbars for this window

Definition at line 815 of file kmainwindow.cpp.

816{
818
819 foreach (QObject *child, children())
820 if (KisToolBar *toolBar = qobject_cast<KisToolBar *>(child)) {
821 ret.append(toolBar);
822 }
823
824 return ret;
825}

References toolBar().

◆ windowsLayoutSavingAllowed()

bool KisKMainWindow::windowsLayoutSavingAllowed ( ) const
protectedvirtual

Reimplemented in KisMainWindow.

Definition at line 645 of file kmainwindow.cpp.

646{
647 return true;
648}

Friends And Related Symbol Documentation

◆ DockResizeListener

friend class DockResizeListener
friend

Definition at line 91 of file kmainwindow.h.

◆ KMWSessionManager

friend class KMWSessionManager
friend

Definition at line 90 of file kmainwindow.h.

Member Data Documentation

◆ k_ptr

KisKMainWindowPrivate* const KisKMainWindow::k_ptr
protected

Definition at line 486 of file kmainwindow.h.

Property Documentation

◆ autoSaveGroup

QString KisKMainWindow::autoSaveGroup
read

Definition at line 96 of file kmainwindow.h.

◆ autoSaveSettings

bool KisKMainWindow::autoSaveSettings
read

Definition at line 95 of file kmainwindow.h.

◆ hasMenuBar

bool KisKMainWindow::hasMenuBar
read

Definition at line 94 of file kmainwindow.h.


The documentation for this class was generated from the following files: