KXmlGui

kmainwindow.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Reginald Stadlbauer <[email protected]>
4  SPDX-FileCopyrightText: 1997 Stephan Kulow <[email protected]>
5  SPDX-FileCopyrightText: 1997-2000 Sven Radej <[email protected]>
6  SPDX-FileCopyrightText: 1997-2000 Matthias Ettrich <[email protected]>
7  SPDX-FileCopyrightText: 1999 Chris Schlaeger <[email protected]>
8  SPDX-FileCopyrightText: 2002 Joseph Wenninger <[email protected]>
9  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
10  SPDX-FileCopyrightText: 2000-2008 David Faure <[email protected]>
11 
12  SPDX-License-Identifier: LGPL-2.0-only
13 */
14 
15 #ifndef KMAINWINDOW_H
16 #define KMAINWINDOW_H
17 
18 #include <kxmlgui_export.h>
19 
20 #include <QMainWindow>
21 
22 class QMenu;
23 class KConfig;
24 class KConfigGroup;
25 class KMWSessionManager;
26 class KMainWindowPrivate;
27 class KToolBar;
28 
29 // internal, not public API, may change any time
30 #define XMLGUI_DECLARE_PRIVATE(classname) \
31  inline classname ## Private *k_func() { return reinterpret_cast<classname ## Private *>(k_ptr); } \
32  inline const classname ## Private *k_func() const { return reinterpret_cast<classname ## Private *>(k_ptr); } \
33  friend class classname ## Private;
34 
35 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 65)
36 
40 #define KDE_DEFAULT_WINDOWFLAGS 0
41 #else
42 #define KDE_DEFAULT_WINDOWFLAGS KDE_DEFAULT_WINDOWFLAGS_is_deprecated_use_Qt_WindowFlags()
43 #endif
44 
96 class KXMLGUI_EXPORT KMainWindow : public QMainWindow
97 {
98  friend class KMWSessionManager;
99  friend class DockResizeListener;
100  XMLGUI_DECLARE_PRIVATE(KMainWindow)
101  Q_OBJECT
102  Q_PROPERTY(bool hasMenuBar READ hasMenuBar)
103  Q_PROPERTY(bool autoSaveSettings READ autoSaveSettings)
104  Q_PROPERTY(QString autoSaveGroup READ autoSaveGroup)
105 
106 public:
147  explicit KMainWindow(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
148 
155  ~KMainWindow() override;
156 
157 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
158 
183  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KHelpMenu directly")
184  QMenu *helpMenu(const QString &aboutAppText = QString(),
185  bool showWhatsThis = true);
186 #endif
187 
188 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
189 
212  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use XMLGUI or KHelpMenu")
213  QMenu *customHelpMenu(bool showWhatsThis = true);
214 #endif
215 
221  static bool canBeRestored(int number);
222 
230  static const QString classNameOfToplevel(int number);
231 
269  bool restore(int number, bool show = true);
270 
274  bool hasMenuBar();
275 
279  static QList<KMainWindow *> memberList();
280 
291  KToolBar *toolBar(const QString &name = QString());
292 
296  QList<KToolBar *> toolBars() const;
297 
329  void setAutoSaveSettings(const QString &groupName = QStringLiteral("MainWindow"),
330  bool saveWindowSize = true);
331 
337  void setAutoSaveSettings(const KConfigGroup &group,
338  bool saveWindowSize = true);
339 
344  void resetAutoSaveSettings();
345 
350  bool autoSaveSettings() const;
351 
361  QString autoSaveGroup() const;
362 
369  KConfigGroup autoSaveConfigGroup() const;
370 
380  virtual void applyMainWindowSettings(const KConfigGroup &config);
381 
388  void saveMainWindowSettings(KConfigGroup &config);
389 
394  QString dbusName() const;
395 
396 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
397 
401  KXMLGUI_DEPRECATED_VERSION(5, 0, "Remove usage, is a no-op now")
402  bool initialGeometrySet() const { return false; }
403 #endif
404 
405 public Q_SLOTS:
413  virtual void setCaption(const QString &caption);
423  virtual void setCaption(const QString &caption, bool modified);
424 
431  virtual void setPlainCaption(const QString &caption);
432 
452  void appHelpActivated();
453 
461  void setSettingsDirty();
462 
463 protected:
469  bool event(QEvent *event) override;
470 
478  void closeEvent(QCloseEvent *) override;
479 
513  virtual bool queryClose();
514 
526  virtual void saveProperties(KConfigGroup &) {}
527 
533  virtual void readProperties(const KConfigGroup &) {}
534 
551  virtual void saveGlobalProperties(KConfig *sessionConfig);
552 
558  virtual void readGlobalProperties(KConfig *sessionConfig);
559  void savePropertiesInternal(KConfig *, int);
560  bool readPropertiesInternal(KConfig *, int);
561 
565  bool settingsDirty() const;
566 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
567 
571  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KWindowConfig::saveWindowSize(...)")
572  void saveWindowSize(KConfigGroup &config) const;
573 #endif
574 
575 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
576 
580  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KWindowConfig::restoreWindowSize(...)")
581  void restoreWindowSize(const KConfigGroup &config);
582 #endif
583 
584 protected Q_SLOTS:
585 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
586 
611  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KHelpMenu")
612  virtual void showAboutApplication() {}
613 #endif
614 
636  void saveAutoSaveSettings();
637 
638 protected:
639  KMainWindow(KMainWindowPrivate &dd, QWidget *parent, Qt::WindowFlags f);
640 
641  KMainWindowPrivate *const k_ptr;
642 private:
643  Q_PRIVATE_SLOT(k_func(), void _k_slotSettingsChanged(int))
644  Q_PRIVATE_SLOT(k_func(), void _k_slotSaveAutoSaveSize())
645 };
646 
647 
654 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
655 
661 #define RESTORE(type) { int n = 1;\
662  while (KMainWindow::canBeRestored(n)){\
663  (new type)->restore(n);\
664  n++;}}
665 #endif
666 
672 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
673 
711 template <typename T>
712 inline void kRestoreMainWindows()
713 {
714  for (int n = 1; KMainWindow::canBeRestored(n); ++n) {
715  const QString className = KMainWindow::classNameOfToplevel(n);
716  if (className == QLatin1String(T::staticMetaObject.className())) {
717  (new T)->restore(n);
718  }
719  }
720 }
721 
730 template <typename T0, typename T1, typename ...Tn>
731 inline void kRestoreMainWindows()
732 {
733  kRestoreMainWindows<T0>();
734  kRestoreMainWindows<T1, Tn...>();
735 }
738 #endif
static const QString classNameOfToplevel(int number)
Returns the className() of the number of the toplevel window which should be restored.
virtual void readProperties(const KConfigGroup &)
Read your instance-specific properties.
Definition: kmainwindow.h:533
Top level main window.
Definition: kmainwindow.h:96
virtual bool event(QEvent *event) override
static bool canBeRestored(int number)
If the session did contain so high a number, true is returned, else false.
Q_PROPERTY(...)
void kRestoreMainWindows()
Restores the last session.
Definition: kmainwindow.h:712
Floatable toolbar with auto resize.
Definition: ktoolbar.h:59
virtual void closeEvent(QCloseEvent *event)
typedef WindowFlags
virtual void saveProperties(KConfigGroup &)
Save your instance-specific properties.
Definition: kmainwindow.h:526
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 22:50:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.