From 3bfb7bbbcec4a1e97db508277acbcaaf432d84dd Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Wed, 5 Jun 2013 19:17:11 +0000 Subject: [PATCH] Intercept ::polish events on QMenu, so can add accel manager --- support/CMakeLists.txt | 29 +++++------------------------ support/gtkproxystyle.cpp | 14 +++++++++++++- support/gtkstyle.cpp | 29 +++++++++++++++++++++++------ support/proxystyle.cpp | 37 +++++++++++++++++++++++++++++++++++++ support/proxystyle.h | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 31 deletions(-) create mode 100644 support/proxystyle.cpp create mode 100644 support/proxystyle.h diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 0e405cd69..fb121f784 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -1,25 +1,7 @@ -SET( SUPPORT_SRCS - action.cpp - actioncollection.cpp - fancytabwidget.cpp - messagewidget.cpp - icon.cpp - lineedit.cpp - gtkstyle.cpp - utils.cpp - spinner.cpp - messagebox.cpp - inputdialog.cpp - thread.cpp -) +SET( SUPPORT_SRCS action.cpp actioncollection.cpp fancytabwidget.cpp messagewidget.cpp icon.cpp + lineedit.cpp gtkstyle.cpp utils.cpp spinner.cpp messagebox.cpp inputdialog.cpp thread.cpp) -SET( SUPPORT_MOC_HDRS - action.h - actioncollection.h - fancytabwidget.h - messagewidget.h - thread.h -) +SET( SUPPORT_MOC_HDRS action.h actioncollection.h fancytabwidget.h messagewidget.h thread.h) if (NOT WIN32) SET( SUPPORT_SRCS ${SUPPORT_SRCS} onoffbutton.cpp spinbox.cpp windowmanager.cpp gtkproxystyle.cpp combobox.cpp shortcuthandler.cpp) @@ -41,9 +23,8 @@ if (ENABLE_KDE_SUPPORT ) KDE4_ADD_UI_FILES( SUPPORT_UI_HDRS ${SUPPORT_UIS} ) SET( SUPPORT_SRCS ${SUPPORT_SRCS} dialog.cpp) else (ENABLE_KDE_SUPPORT) - SET( SUPPORT_SRCS ${SUPPORT_SRCS} pathrequester.cpp kmessagewidget.cpp - dialog.cpp pagewidget.cpp shortcutsmodel.cpp shortcutssettingspage.cpp - keysequencewidget.cpp acceleratormanager.cpp) + SET( SUPPORT_SRCS ${SUPPORT_SRCS} pathrequester.cpp kmessagewidget.cpp dialog.cpp pagewidget.cpp shortcutsmodel.cpp + shortcutssettingspage.cpp keysequencewidget.cpp acceleratormanager.cpp proxystyle.cpp) SET( SUPPORT_MOC_HDRS ${SUPPORT_MOC_HDRS} pathrequester.h lineedit.h kmessagewidget.h urllabel.h dialog.h shortcutsmodel.h shortcutssettingspage.h keysequencewidget.h spinner.h acceleratormanager_private.h) SET( SUPPORT_UIS shortcutssettingspage.ui ) diff --git a/support/gtkproxystyle.cpp b/support/gtkproxystyle.cpp index 618e58c75..81d8ad9ed 100644 --- a/support/gtkproxystyle.cpp +++ b/support/gtkproxystyle.cpp @@ -27,6 +27,9 @@ #ifdef ENABLE_OVERLAYSCROLLBARS #include "osthumb.h" #endif +#ifndef ENABLE_KDE_SUPPORT +#include "acceleratormanager.h" +#endif #include #include #include @@ -34,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -44,6 +47,9 @@ const char * GtkProxyStyle::constSlimComboProperty="gtkslim"; static const char * constOnCombo="on-combo"; +#ifndef ENABLE_KDE_SUPPORT +static const char * constAccelProp="catata-accel"; +#endif //static bool revertQGtkStyleOverlayMod() //{ @@ -406,6 +412,12 @@ void GtkProxyStyle::polish(QWidget *widget) } #endif + #ifndef ENABLE_KDE_SUPPORT + if (widget && qobject_cast(widget) && !widget->property(constAccelProp).isValid()) { + AcceleratorManager::manage(widget); + widget->setProperty(constAccelProp, true); + } + #endif baseStyle()->polish(widget); } diff --git a/support/gtkstyle.cpp b/support/gtkstyle.cpp index 78fca5822..0d1ceac21 100644 --- a/support/gtkstyle.cpp +++ b/support/gtkstyle.cpp @@ -31,6 +31,9 @@ #include #include #include +#ifndef ENABLE_KDE_SUPPORT +#include "proxystyle.h" +#endif #if !defined Q_OS_WIN && !defined QT_NO_STYLE_GTK #include "gtkproxystyle.h" #include "windowmanager.h" @@ -202,7 +205,10 @@ QString GtkStyle::iconTheme() } #if !defined Q_OS_WIN && !defined QT_NO_STYLE_GTK -static GtkProxyStyle *style=0; +static GtkProxyStyle *gtkProxyStyle=0; +#endif +#ifndef ENABLE_KDE_SUPPORT +static ProxyStyle *plainProxyStyle=0; #endif static bool symbolicIcons=false; static bool lightIcons=false; @@ -211,6 +217,10 @@ void GtkStyle::applyTheme(QWidget *widget) { #if defined Q_OS_WIN || defined QT_NO_STYLE_GTK Q_UNUSED(widget) + if (!plainProxyStyle) { + plainProxyStyle=new ProxyStyle(); + qApp->setStyle(plainProxyStyle); + } #else if (widget && isActive()) { QString theme=GtkStyle::themeName().toLower(); @@ -242,19 +252,26 @@ void GtkStyle::applyTheme(QWidget *widget) QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus); } } - if (!style) { - style=new GtkProxyStyle(sbType); - qApp->setStyle(style); + if (!gtkProxyStyle) { + gtkProxyStyle=new GtkProxyStyle(sbType); + qApp->setStyle(gtkProxyStyle); } } + + #ifndef ENABLE_KDE_SUPPORT + if (!gtkProxyStyle && !plainProxyStyle) { + plainProxyStyle=new ProxyStyle(); + qApp->setStyle(plainProxyStyle); + } + #endif #endif } void GtkStyle::cleanup() { #if !defined Q_OS_WIN && !defined QT_NO_STYLE_GTK && defined ENABLE_OVERLAYSCROLLBARS - if (style) { - style->destroySliderThumb(); + if (gtkProxyStyle) { + gtkProxyStyle->destroySliderThumb(); } #endif } diff --git a/support/proxystyle.cpp b/support/proxystyle.cpp new file mode 100644 index 000000000..2e5922fa5 --- /dev/null +++ b/support/proxystyle.cpp @@ -0,0 +1,37 @@ +/* + * Cantata + * + * Copyright (c) 2011-2013 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 "proxystyle.h" +#include "acceleratormanager.h" +#include + +static const char * constAccelProp="catata-accel"; + +void ProxyStyle::polish(QWidget *widget) +{ + if (widget && qobject_cast(widget) && !widget->property(constAccelProp).isValid()) { + AcceleratorManager::manage(widget); + widget->setProperty(constAccelProp, true); + } + baseStyle()->polish(widget); +} diff --git a/support/proxystyle.h b/support/proxystyle.h new file mode 100644 index 000000000..d105e4634 --- /dev/null +++ b/support/proxystyle.h @@ -0,0 +1,37 @@ +/* + * Cantata + * + * Copyright (c) 2011-2013 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 PROXYSTYLE_H +#define PROXYSTYLE_H + +#include + +class ProxyStyle : public QProxyStyle +{ +public: + ProxyStyle() { } + + void polish(QWidget *widget); +}; + +#endif