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 #include <memory>
22 
23 class QMenu;
24 class KConfig;
25 class KConfigGroup;
26 class KMWSessionManager;
27 class KMainWindowPrivate;
28 class KToolBar;
29 
30 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 65)
31 
35 #define KDE_DEFAULT_WINDOWFLAGS 0
36 #else
37 #define KDE_DEFAULT_WINDOWFLAGS KDE_DEFAULT_WINDOWFLAGS_is_deprecated_use_Qt_WindowFlags()
38 #endif
39 
91 class KXMLGUI_EXPORT KMainWindow : public QMainWindow
92 {
93  friend class KMWSessionManager;
94  friend class DockResizeListener;
95  Q_OBJECT
96  Q_PROPERTY(bool hasMenuBar READ hasMenuBar)
97  Q_PROPERTY(bool autoSaveSettings READ autoSaveSettings)
98  Q_PROPERTY(QString autoSaveGroup READ autoSaveGroup)
99 
100 public:
141  explicit KMainWindow(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
142 
149  ~KMainWindow() override;
150 
151 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
152 
177  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KHelpMenu directly")
178  QMenu *helpMenu(const QString &aboutAppText = QString(),
179  bool showWhatsThis = true);
180 #endif
181 
182 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
183 
206  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use XMLGUI or KHelpMenu")
207  QMenu *customHelpMenu(bool showWhatsThis = true);
208 #endif
209 
215  static bool canBeRestored(int number);
216 
224  static const QString classNameOfToplevel(int number);
225 
263  bool restore(int number, bool show = true);
264 
268  bool hasMenuBar();
269 
273  static QList<KMainWindow *> memberList();
274 
285  KToolBar *toolBar(const QString &name = QString());
286 
290  QList<KToolBar *> toolBars() const;
291 
323  void setAutoSaveSettings(const QString &groupName = QStringLiteral("MainWindow"),
324  bool saveWindowSize = true);
325 
331  void setAutoSaveSettings(const KConfigGroup &group,
332  bool saveWindowSize = true);
333 
338  void resetAutoSaveSettings();
339 
344  bool autoSaveSettings() const;
345 
355  QString autoSaveGroup() const;
356 
363  KConfigGroup autoSaveConfigGroup() const;
364 
374  virtual void applyMainWindowSettings(const KConfigGroup &config);
375 
382  void saveMainWindowSettings(KConfigGroup &config);
383 
388  QString dbusName() const;
389 
390 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
391 
395  KXMLGUI_DEPRECATED_VERSION(5, 0, "Remove usage, is a no-op now")
396  bool initialGeometrySet() const { return false; }
397 #endif
398 
399 public Q_SLOTS:
407  virtual void setCaption(const QString &caption);
417  virtual void setCaption(const QString &caption, bool modified);
418 
425  virtual void setPlainCaption(const QString &caption);
426 
446  void appHelpActivated();
447 
455  void setSettingsDirty();
456 
457 protected:
463  bool event(QEvent *event) override;
464 
472  void closeEvent(QCloseEvent *) override;
473 
507  virtual bool queryClose();
508 
520  virtual void saveProperties(KConfigGroup &) {}
521 
527  virtual void readProperties(const KConfigGroup &) {}
528 
545  virtual void saveGlobalProperties(KConfig *sessionConfig);
546 
552  virtual void readGlobalProperties(KConfig *sessionConfig);
553  void savePropertiesInternal(KConfig *, int);
554  bool readPropertiesInternal(KConfig *, int);
555 
559  bool settingsDirty() const;
560 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
561 
565  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KWindowConfig::saveWindowSize(...)")
566  void saveWindowSize(KConfigGroup &config) const;
567 #endif
568 
569 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
570 
574  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KWindowConfig::restoreWindowSize(...)")
575  void restoreWindowSize(const KConfigGroup &config);
576 #endif
577 
578 protected Q_SLOTS:
579 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
580 
605  KXMLGUI_DEPRECATED_VERSION(5, 0, "Use KHelpMenu")
606  virtual void showAboutApplication() {}
607 #endif
608 
630  void saveAutoSaveSettings();
631 
632 protected:
633  KMainWindow(KMainWindowPrivate &dd, QWidget *parent, Qt::WindowFlags f);
634 
635  std::unique_ptr<KMainWindowPrivate> const k_ptr;
636  // KF6 TODO: change k_ptr to d_ptr, use normal Q_DECLARE_PRIVATE
637 
638 private:
639  Q_DECLARE_PRIVATE_D(k_ptr, KMainWindow)
640 
641  Q_PRIVATE_SLOT(d_func(), void _k_slotSettingsChanged(int))
642  Q_PRIVATE_SLOT(d_func(), void _k_slotSaveAutoSaveSize())
643  Q_PRIVATE_SLOT(d_func(), void _k_slotSaveAutoSavePosition())
644 };
645 
646 
653 #if KXMLGUI_ENABLE_DEPRECATED_SINCE(5, 0)
654 
660 #define RESTORE(type) { int n = 1;\
661  while (KMainWindow::canBeRestored(n)){\
662  (new type)->restore(n);\
663  n++;}}
664 #endif
665 
671 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
672 
710 template <typename T>
711 inline void kRestoreMainWindows()
712 {
713  for (int n = 1; KMainWindow::canBeRestored(n); ++n) {
714  const QString className = KMainWindow::classNameOfToplevel(n);
715  if (className == QLatin1String(T::staticMetaObject.className())) {
716  (new T)->restore(n);
717  }
718  }
719 }
720 
729 template <typename T0, typename T1, typename ...Tn>
730 inline void kRestoreMainWindows()
731 {
732  kRestoreMainWindows<T0>();
733  kRestoreMainWindows<T1, Tn...>();
734 }
737 #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:527
Top level main window.
Definition: kmainwindow.h:91
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:711
Floatable toolbar with auto resize.
Definition: ktoolbar.h:60
virtual void closeEvent(QCloseEvent *event)
typedef WindowFlags
virtual void saveProperties(KConfigGroup &)
Save your instance-specific properties.
Definition: kmainwindow.h:520
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 22:52:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.