1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include "uisupport-export.h"
25 #include "abstractui.h"
26 #include "singleton.h"
28 class ActionCollection;
29 class ContextMenuActionProvider;
30 class ToolBarActionProvider;
37 # include <Carbon/Carbon.h>
40 class UISUPPORT_EXPORT GraphicalUi : public AbstractUi, protected Singleton<GraphicalUi>
45 //! Access global ActionCollections.
46 /** These ActionCollections are associated with the main window, i.e. they contain global
47 * actions (and thus, shortcuts). Widgets providing application-wide shortcuts should
48 * create appropriate Action objects using GraphicalUi::actionCollection(cat)->add\<Action\>().
49 * @param category The category (default: "General")
51 static ActionCollection* actionCollection(const QString& category = "General", const QString& translatedCategory = QString());
52 static QHash<QString, ActionCollection*> actionCollections();
54 //! Load custom shortcuts from ShortcutSettings
55 /** @note This method assumes that all configurable actions are defined when being called
57 static void loadShortcuts();
59 //! Save custom shortcuts to ShortcutSettings
60 static void saveShortcuts();
62 inline static ContextMenuActionProvider* contextMenuActionProvider();
63 inline static ToolBarActionProvider* toolBarActionProvider();
64 inline static UiStyle* uiStyle();
65 inline static QWidget* mainWidget();
67 //! Force the main widget to the front and focus it (may not work in all window systems)
68 static void activateMainWidget();
70 //! Hide main widget (storing the current desktop if possible)
71 static void hideMainWidget();
73 //! Toggle main widget
74 static void toggleMainWidget();
76 //! Check if the main widget if (fully, in KDE) visible
77 static bool isMainWidgetVisible();
80 GraphicalUi(QObject* parent = nullptr);
83 //! This is the widget we associate global actions with, typically the main window
84 void setMainWidget(QWidget*);
86 //! Check if the mainWidget is visible and optionally toggle its visibility
87 /** With KDE integration, we check if the mainWidget is (partially) obscured in order to determine if
88 * it should be activated or hidden. Without KDE, we need to resort to checking the current state
89 * as Qt knows it, ignoring windows covering it.
90 * @param performToggle If true, toggle the window's state in addition to checking visibility
91 * @return True, if the window is currently *not* visible (needs activation)
93 bool checkMainWidgetVisibility(bool performToggle);
95 //! Minimize to or restore main widget
96 virtual void minimizeRestore(bool show);
98 //! Whether it is allowed to hide the mainWidget
99 /** The default implementation returns false, meaning that we won't hide the mainWidget even
100 * if requested. This is to prevent hiding in case we don't have a tray icon to restore from.
102 virtual inline bool isHidingMainWidgetAllowed() const;
104 void setContextMenuActionProvider(ContextMenuActionProvider*);
105 void setToolBarActionProvider(ToolBarActionProvider*);
106 void setUiStyle(UiStyle*);
108 bool eventFilter(QObject* obj, QEvent* event) override;
111 void disconnectedFromCore() override;
114 static QWidget* _mainWidget;
115 static QHash<QString, ActionCollection*> _actionCollections;
116 static ContextMenuActionProvider* _contextMenuActionProvider;
117 static ToolBarActionProvider* _toolBarActionProvider;
118 static UiStyle* _uiStyle;
124 ProcessSerialNumber _procNum;
130 ContextMenuActionProvider* GraphicalUi::contextMenuActionProvider()
132 return _contextMenuActionProvider;
135 ToolBarActionProvider* GraphicalUi::toolBarActionProvider()
137 return _toolBarActionProvider;
140 UiStyle* GraphicalUi::uiStyle()
145 QWidget* GraphicalUi::mainWidget()
150 bool GraphicalUi::isHidingMainWidgetAllowed() const