X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fgraphicalui.h;h=42b5785287bd82db7c359bcf4bc20cf2ac234886;hp=9832d104f743fabd4069e0787695330cf4352fac;hb=158443f71d48215eea8b47b836b61afd77654b78;hpb=d452877910888c25d40590b5fff57eb8197ca9b0 diff --git a/src/uisupport/graphicalui.h b/src/uisupport/graphicalui.h index 9832d104..42b57852 100644 --- a/src/uisupport/graphicalui.h +++ b/src/uisupport/graphicalui.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,75 +15,121 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef GRAPHICALUI_H_ -#define GRAPHICALUI_H_ +#pragma once + +#include "uisupport-export.h" #include "abstractui.h" +#include "singleton.h" class ActionCollection; class ContextMenuActionProvider; class ToolBarActionProvider; class UiStyle; -class GraphicalUi : public AbstractUi { - Q_OBJECT +#ifdef Q_OS_WIN +# include +#endif +#ifdef Q_OS_MAC +#include +#endif + +class UISUPPORT_EXPORT GraphicalUi : public AbstractUi, protected Singleton +{ + Q_OBJECT public: - GraphicalUi(QObject *parent = 0); + //! Access global ActionCollections. + /** These ActionCollections are associated with the main window, i.e. they contain global + * actions (and thus, shortcuts). Widgets providing application-wide shortcuts should + * create appropriate Action objects using GraphicalUi::actionCollection(cat)->add\(). + * @param category The category (default: "General") + */ + static ActionCollection *actionCollection(const QString &category = "General", const QString &translatedCategory = QString()); + static QHash actionCollections(); - //! Access global ActionCollections. - /** These ActionCollections are associated with the main window, i.e. they contain global - * actions (and thus, shortcuts). Widgets providing application-wide shortcuts should - * create appropriate Action objects using GraphicalUi::actionCollection(cat)->add\(). - * @param category The category (default: "General") - */ - static ActionCollection *actionCollection(const QString &category = "General"); + //! Load custom shortcuts from ShortcutSettings + /** @note This method assumes that all configurable actions are defined when being called + */ + static void loadShortcuts(); - inline static ContextMenuActionProvider *contextMenuActionProvider(); - inline static ToolBarActionProvider *toolBarActionProvider(); - inline static UiStyle *uiStyle(); - inline static QWidget *mainWidget(); + //! Save custom shortcuts to ShortcutSettings + static void saveShortcuts(); - //! Force the main widget to the front and focus it (may not work in all window systems) - static void activateMainWidget(); + inline static ContextMenuActionProvider *contextMenuActionProvider(); + inline static ToolBarActionProvider *toolBarActionProvider(); + inline static UiStyle *uiStyle(); + inline static QWidget *mainWidget(); - //! Hide main widget (storing the current desktop if possible) - static void hideMainWidget(); + //! Force the main widget to the front and focus it (may not work in all window systems) + static void activateMainWidget(); + + //! Hide main widget (storing the current desktop if possible) + static void hideMainWidget(); + + //! Toggle main widget + static void toggleMainWidget(); + + //! Check if the main widget if (fully, in KDE) visible + static bool isMainWidgetVisible(); protected: - //! This is the widget we associate global actions with, typically the main window - void setMainWidget(QWidget *); + GraphicalUi(QObject *parent = nullptr); + void init() override; - void setContextMenuActionProvider(ContextMenuActionProvider *); - void setToolBarActionProvider(ToolBarActionProvider *); - void setUiStyle(UiStyle *); + //! This is the widget we associate global actions with, typically the main window + void setMainWidget(QWidget *); -private: - static QWidget *_mainWidget; - static QHash _actionCollections; - static ContextMenuActionProvider *_contextMenuActionProvider; - static ToolBarActionProvider *_toolBarActionProvider; - static UiStyle *_uiStyle; - static bool _onAllDesktops; -}; + //! Check if the mainWidget is visible and optionally toggle its visibility + /** With KDE integration, we check if the mainWidget is (partially) obscured in order to determine if + * it should be activated or hidden. Without KDE, we need to resort to checking the current state + * as Qt knows it, ignoring windows covering it. + * @param performToggle If true, toggle the window's state in addition to checking visibility + * @return True, if the window is currently *not* visible (needs activation) + */ + bool checkMainWidgetVisibility(bool performToggle); + + //! Minimize to or restore main widget + virtual void minimizeRestore(bool show); -ContextMenuActionProvider *GraphicalUi::contextMenuActionProvider() { - return _contextMenuActionProvider; -} + //! Whether it is allowed to hide the mainWidget + /** The default implementation returns false, meaning that we won't hide the mainWidget even + * if requested. This is to prevent hiding in case we don't have a tray icon to restore from. + */ + virtual inline bool isHidingMainWidgetAllowed() const; -ToolBarActionProvider *GraphicalUi::toolBarActionProvider() { - return _toolBarActionProvider; -} + void setContextMenuActionProvider(ContextMenuActionProvider *); + void setToolBarActionProvider(ToolBarActionProvider *); + void setUiStyle(UiStyle *); -UiStyle *GraphicalUi::uiStyle() { - return _uiStyle; -} + bool eventFilter(QObject *obj, QEvent *event) override; -QWidget *GraphicalUi::mainWidget() { - return _mainWidget; -} +protected slots: + void disconnectedFromCore() override; +private: + static QWidget *_mainWidget; + static QHash _actionCollections; + static ContextMenuActionProvider *_contextMenuActionProvider; + static ToolBarActionProvider *_toolBarActionProvider; + static UiStyle *_uiStyle; + +#ifdef Q_OS_WIN + DWORD _dwTickCount; +#endif +#ifdef Q_OS_MAC + ProcessSerialNumber _procNum; #endif +}; + + +// inlines + +ContextMenuActionProvider *GraphicalUi::contextMenuActionProvider() { return _contextMenuActionProvider; } +ToolBarActionProvider *GraphicalUi::toolBarActionProvider() { return _toolBarActionProvider; } +UiStyle *GraphicalUi::uiStyle() { return _uiStyle; } +QWidget *GraphicalUi::mainWidget() { return _mainWidget; } +bool GraphicalUi::isHidingMainWidgetAllowed() const { return false; }