diff --git a/gui/application.cpp b/gui/application.cpp index 01240ec55..258002b29 100644 --- a/gui/application.cpp +++ b/gui/application.cpp @@ -23,6 +23,7 @@ #include "application.h" #include "settings.h" +#include "support/proxystyle.h" #include "models/mpdlibrarymodel.h" #include "support/utils.h" #include "mpd-interface/mpdstats.h" @@ -37,8 +38,16 @@ #include "http/httpserver.h" #include "config.h" -void Application::initObjects() +void Application::init() { + #if defined Q_OS_WIN + qApp->setStyle(new ProxyStyle(ProxyStyle::VF_Side)); + #elif defined Q_OS_MAC + qApp->setStyle(new ProxyStyle(ProxyStyle::VF_Side|ProxyStyle::VF_Top)); + #else + qApp->setStyle(new ProxyStyle(0)); + #endif + // Ensure these objects are created in the GUI thread... ThreadCleaner::self(); MPDStatus::self(); diff --git a/gui/application_mac.h b/gui/application_mac.h index a08f825fa..1557c4ce0 100644 --- a/gui/application_mac.h +++ b/gui/application_mac.h @@ -29,7 +29,7 @@ class Application : public SingleApplication { public: - static void initObjects(); + static void init(); Application(int &argc, char **argv); virtual ~Application() { }; }; diff --git a/gui/application_qt.h b/gui/application_qt.h index ea101e91d..6921c54dc 100644 --- a/gui/application_qt.h +++ b/gui/application_qt.h @@ -28,7 +28,7 @@ class Application : public QApplication { public: - static void initObjects(); + static void init(); Application(int &argc, char **argv); virtual ~Application() { } diff --git a/gui/application_win.h b/gui/application_win.h index 1638a7113..c89efb150 100644 --- a/gui/application_win.h +++ b/gui/application_win.h @@ -30,7 +30,7 @@ class Application : public SingleApplication, public QAbstractNativeEventFilter { public: - static void initObjects(); + static void init(); Application(int &argc, char **argv); virtual ~Application() { } bool nativeEventFilter(const QByteArray &, void *message, long *result); diff --git a/gui/main.cpp b/gui/main.cpp index 06751a94f..bff1da5cb 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -270,7 +270,7 @@ int main(int argc, char *argv[]) #endif loadTranslation("cantata", CANTATA_SYS_TRANS_DIR, lang); - Application::initObjects(); + Application::init(); if (Settings::self()->firstRun()) { InitialSettingsWizard wz; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3326bd6f1..0036b2804 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -229,8 +229,6 @@ void MainWindow::init() } #endif - GtkStyle::applyTheme(); - UNITY_MENU_ICON_CHECK toolbar->ensurePolished(); diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 74da89daa..151cc4dcc 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -22,10 +22,6 @@ endif () set(SUPPORT_MOC_HDRS ${SUPPORT_MOC_HDRS} combobox.h) -if (NOT WIN32 AND NOT APPLE) - set(SUPPORT_SRCS ${SUPPORT_SRCS} gtkproxystyle.cpp shortcuthandler.cpp) - set(SUPPORT_MOC_HDRS ${SUPPORT_MOC_HDRS} shortcuthandler.h) -endif () if (APPLE) set(SUPPORT_SRCS ${SUPPORT_SRCS} osxstyle.cpp flattoolbutton.cpp windowmanager.cpp) set(SUPPORT_MOC_HDRS ${SUPPORT_MOC_HDRS} osxstyle.h windowmanager.h) diff --git a/support/gtkproxystyle.cpp b/support/gtkproxystyle.cpp deleted file mode 100644 index de6670e68..000000000 --- a/support/gtkproxystyle.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Cantata - * - * Copyright (c) 2011-2017 Craig Drummond - * - * ---- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "gtkproxystyle.h" -#include "gtkstyle.h" -#include "shortcuthandler.h" -#include "acceleratormanager.h" -#include -#include -#include -#include -#include -#include -#include - -static const char * constAccelProp="catata-accel"; - -static inline void addEventFilter(QObject *object, QObject *filter) -{ - object->removeEventFilter(filter); - object->installEventFilter(filter); -} - -GtkProxyStyle::GtkProxyStyle(int modView) - : ProxyStyle(modView) -{ - shortcutHander=new ShortcutHandler(this); - setBaseStyle(qApp->style()); -} - -GtkProxyStyle::~GtkProxyStyle() -{ -} - -int GtkProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const -{ - switch (hint) { - case SH_DialogButtonBox_ButtonsHaveIcons: - return false; - case SH_UnderlineShortcut: - return widget ? shortcutHander->showShortcut(widget) : true; - default: - break; - } - - return ProxyStyle::styleHint(hint, option, widget, returnData); -} - -void GtkProxyStyle::polish(QWidget *widget) -{ - if (widget && qobject_cast(widget) && !widget->property(constAccelProp).isValid()) { - AcceleratorManager::manage(widget); - widget->setProperty(constAccelProp, true); - } - ProxyStyle::polish(widget); -} - -void GtkProxyStyle::polish(QPalette &pal) -{ - ProxyStyle::polish(pal); -} - -void GtkProxyStyle::polish(QApplication *app) -{ - addEventFilter(app, shortcutHander); - ProxyStyle::polish(app); -} - -void GtkProxyStyle::unpolish(QWidget *widget) -{ - ProxyStyle::unpolish(widget); -} - -void GtkProxyStyle::unpolish(QApplication *app) -{ - app->removeEventFilter(shortcutHander); - ProxyStyle::unpolish(app); -} diff --git a/support/gtkproxystyle.h b/support/gtkproxystyle.h deleted file mode 100644 index 2ffa5de4e..000000000 --- a/support/gtkproxystyle.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Cantata - * - * Copyright (c) 2011-2017 Craig Drummond - * - * ---- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef GTKPROXYSTYLE_H -#define GTKPROXYSTYLE_H - -#include "config.h" -#include "proxystyle.h" - -class ShortcutHandler; - -class GtkProxyStyle : public ProxyStyle -{ -public: - GtkProxyStyle(int modView); - ~GtkProxyStyle(); - int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const; - - void polish(QWidget *widget); - void polish(QPalette &pal); - void polish(QApplication *app); - void unpolish(QWidget *widget); - void unpolish(QApplication *app); - -private: - ShortcutHandler *shortcutHander; -}; - -#endif diff --git a/support/gtkstyle.cpp b/support/gtkstyle.cpp index a635830f2..5bfb16fd5 100644 --- a/support/gtkstyle.cpp +++ b/support/gtkstyle.cpp @@ -37,15 +37,10 @@ #define NO_GTK_SUPPORT #endif -#ifndef NO_GTK_SUPPORT -#include "gtkproxystyle.h" -#endif - -static bool usingGtkStyle=false; - bool GtkStyle::isActive() { - #ifndef NO_GTK_SUPPORT + static bool usingGtkStyle=false; + #if defined Q_OS_WIN || defined Q_OS_MAC || defined QT_NO_STYLE_GTK static bool init=false; if (!init) { init=true; @@ -100,27 +95,4 @@ void GtkStyle::drawSelection(const QStyleOptionViewItem &opt, QPainter *painter, painter->setOpacity(opacityB4); } -// This function should probably be moved somewhere more appropriate! -void GtkStyle::applyTheme() -{ - QProxyStyle *proxyStyle=0; - #ifndef NO_GTK_SUPPORT - if (isActive() && !proxyStyle) { - proxyStyle=new GtkProxyStyle(0); - } - #endif - - #if defined Q_OS_WIN - int modViewFrame=ProxyStyle::VF_Side; - #elif defined Q_OS_MAC - int modViewFrame=ProxyStyle::VF_Side|ProxyStyle::VF_Top; - #else - int modViewFrame=0; - #endif - - if (!proxyStyle) { - proxyStyle=new ProxyStyle(modViewFrame); - } - qApp->setStyle(proxyStyle); -} diff --git a/support/gtkstyle.h b/support/gtkstyle.h index 826ea07bb..c01e3a1e7 100644 --- a/support/gtkstyle.h +++ b/support/gtkstyle.h @@ -34,7 +34,6 @@ namespace GtkStyle { extern bool isActive(); extern void drawSelection(const QStyleOptionViewItem &opt, QPainter *painter, double opacity); - extern void applyTheme(); } #endif diff --git a/support/proxystyle.cpp b/support/proxystyle.cpp index 923fa951f..9d509140b 100644 --- a/support/proxystyle.cpp +++ b/support/proxystyle.cpp @@ -55,6 +55,11 @@ void ProxyStyle::polish(QWidget *widget) baseStyle()->polish(widget); } +int ProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const +{ + return SH_DialogButtonBox_ButtonsHaveIcons == hint ? false : baseStyle()->styleHint(hint, option, widget, returnData); +} + void ProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { baseStyle()->drawPrimitive(element, option, painter, widget); diff --git a/support/proxystyle.h b/support/proxystyle.h index cda942358..ea3db03aa 100644 --- a/support/proxystyle.h +++ b/support/proxystyle.h @@ -45,6 +45,7 @@ public: void polish(QPalette &pal) { QProxyStyle::polish(pal); } void polish(QApplication *app) { QProxyStyle::polish(app); } void polish(QWidget *widget); + int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const; void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const; #if !defined Q_OS_WIN && !defined Q_OS_MAC QPixmap standardPixmap(StandardPixmap sp, const QStyleOption *opt, const QWidget *widget) const; diff --git a/support/shortcuthandler.cpp b/support/shortcuthandler.cpp deleted file mode 100644 index 456a34ee1..000000000 --- a/support/shortcuthandler.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Cantata - * - * Copyright (c) 2011-2017 Craig Drummond - * - * ---- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "shortcuthandler.h" -#include -#include -#include -#include - -ShortcutHandler::ShortcutHandler(QObject *parent) - : QObject(parent) - , altDown(false) -{ -} - -ShortcutHandler::~ShortcutHandler() -{ -} - -bool ShortcutHandler::hasSeenAlt(const QWidget *widget) const -{ - if (widget && !widget->isEnabled()) { - return false; - } - - if (qobject_cast(widget)) { - return openMenus.count() && openMenus.last()==widget; - } else { - return openMenus.isEmpty() && seenAlt.contains(static_cast(widget->window())); - } -} - -bool ShortcutHandler::showShortcut(const QWidget *widget) const -{ - return altDown && hasSeenAlt(widget); -} - -void ShortcutHandler::widgetDestroyed(QObject *o) -{ - updated.remove(static_cast(o)); - openMenus.removeAll(static_cast(o)); -} - -void ShortcutHandler::updateWidget(QWidget *w) -{ - if (!updated.contains(w)) { - updated.insert(w); - w->update(); - connect(w, SIGNAL(destroyed(QObject *)), this, SLOT(widgetDestroyed(QObject *))); - } -} - -bool ShortcutHandler::eventFilter(QObject *o, QEvent *e) -{ - if (!o->isWidgetType()) { - return QObject::eventFilter(o, e); - } - - QWidget *widget = qobject_cast(o); - switch(e->type()) { - case QEvent::KeyPress: - if (Qt::Key_Alt==static_cast(e)->key()) { - altDown = true; - if (qobject_cast(widget)) { - seenAlt.insert(widget); - updateWidget(widget); - if (widget->parentWidget() && widget->parentWidget()->window()) { - seenAlt.insert(widget->parentWidget()->window()); - } - } else { - widget = widget->window(); - seenAlt.insert(widget); - QList l = widget->findChildren(); - for (int pos=0 ; pos < l.size() ; ++pos) { - QWidget *w = l.at(pos); - if (!(w->isWindow() || !w->isVisible())) { // || w->style()->styleHint(QStyle::SH_UnderlineShortcut, 0, w))) - updateWidget(w); - } - } - - QList m = widget->findChildren(); - for (int i = 0; i < m.size(); ++i) { - updateWidget(m.at(i)); - } - } - } - break; - case QEvent::WindowDeactivate: - case QEvent::KeyRelease: - if (QEvent::WindowDeactivate==e->type() || Qt::Key_Alt==static_cast(e)->key()) { - altDown = false; - QSet::ConstIterator it(updated.constBegin()); - QSet::ConstIterator end(updated.constEnd()); - - for (; it!=end; ++it) { - (*it)->update(); - } - if (!updated.contains(widget)) { - widget->update(); - } - seenAlt.clear(); - updated.clear(); - } - break; - case QEvent::Show: - if (qobject_cast(widget)) { - QWidget *prev=openMenus.count() ? openMenus.last() : 0L; - openMenus.append(widget); - if(altDown && prev) { - prev->update(); - } - connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(widgetDestroyed(QObject *))); - } - break; - case QEvent::Hide: - if (qobject_cast(widget)) { - seenAlt.remove(widget); - updated.remove(widget); - openMenus.removeAll(widget); - if (altDown) { - if (openMenus.count()) { - openMenus.last()->update(); - } else if(widget->parentWidget() && widget->parentWidget()->window()) { - widget->parentWidget()->window()->update(); - } - } - } - break; - case QEvent::Close: - // Reset widget when closing - seenAlt.remove(widget); - updated.remove(widget); - seenAlt.remove(widget->window()); - openMenus.removeAll(widget); - if (altDown) { - if(openMenus.count()) { - openMenus.last()->update(); - } else if(widget->parentWidget() && widget->parentWidget()->window()) { - widget->parentWidget()->window()->update(); - } - } - break; - default: - break; - } - return QObject::eventFilter(o, e); -} - diff --git a/support/shortcuthandler.h b/support/shortcuthandler.h deleted file mode 100644 index 14ccfc167..000000000 --- a/support/shortcuthandler.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __SHORTCUT_HANDLER_H__ -#define __SHORTCUT_HANDLER_H__ - -/* - * Cantata - * - * Copyright (c) 2011-2017 Craig Drummond - * - * ---- - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -class QWidget; - -class ShortcutHandler : public QObject -{ - Q_OBJECT - -public: - explicit ShortcutHandler(QObject *parent = 0); - virtual ~ShortcutHandler(); - - bool hasSeenAlt(const QWidget *widget) const; - bool isAltDown() const { return altDown; } - bool showShortcut(const QWidget *widget) const; - -private Q_SLOTS: - void widgetDestroyed(QObject *o); - -protected: - void updateWidget(QWidget *w); - bool eventFilter(QObject *watched, QEvent *event); - -private: - bool altDown; - QSet seenAlt; - QSet updated; - QList openMenus; -}; - -#endif