diff --git a/autotests/kdeplatformtheme_unittest.cpp b/autotests/kdeplatformtheme_unittest.cpp index 61354a9..6bba325 100644 --- a/autotests/kdeplatformtheme_unittest.cpp +++ b/autotests/kdeplatformtheme_unittest.cpp @@ -1,277 +1,277 @@ /* This file is part of the KDE libraries * Copyright 2013 Alejandro Fiestas Olivares * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kdeplatformtheme_config.h" #include "../src/platformtheme/kdeplatformtheme.h" #include "../src/platformtheme/khintssettings.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void prepareEnvironment() { QStandardPaths::setTestModeEnabled(true); QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); configPath.append("/kdeglobals"); QFile::remove(configPath); QFile::copy(CONFIGFILE, configPath); } Q_COREAPP_STARTUP_FUNCTION(prepareEnvironment); class EventTest : public QObject { public: - EventTest(QObject* tested, QEvent::Type type) + EventTest(QObject *tested, QEvent::Type type) : QObject(), gotEvent(false), m_type(type) { tested->installEventFilter(this); } - virtual bool eventFilter(QObject*, QEvent* e) + virtual bool eventFilter(QObject *, QEvent *e) { if (e->type() == m_type) { gotEvent = true; } return false; } bool gotEvent; QEvent::Type m_type; }; class KdePlatformTheme_UnitTest : public QObject { Q_OBJECT - public: - KdePlatformTheme_UnitTest() - {} - - private: - void sendNotifyChange(KHintsSettings::ChangeType type, int arg = -1) - { - QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange" ); - QList args; - args.append(static_cast(type)); - if (arg >= 0) { - args.append(arg); - } - message.setArguments(args); - QDBusConnection::sessionBus().send(message); - } +public: + KdePlatformTheme_UnitTest() + {} - QEventLoop m_loop; - QToolButton m_toolBtn; - KdePlatformTheme *m_qpa; - private Q_SLOTS: - void initTestCase() - { - m_qpa = new KdePlatformTheme(); - QDBusConnection::sessionBus().connect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings", - "notifyChange", &m_loop, SLOT(quit())); +private: + void sendNotifyChange(KHintsSettings::ChangeType type, int arg = -1) + { + QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange"); + QList args; + args.append(static_cast(type)); + if (arg >= 0) { + args.append(arg); } + message.setArguments(args); + QDBusConnection::sessionBus().send(message); + } - void testPlatformHints() - { - QCOMPARE(m_qpa->themeHint(QPlatformTheme::CursorFlashTime).toInt(), 1042); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::MouseDoubleClickInterval).toInt(), 4343); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragDistance).toInt(), 15); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragTime).toInt(), 555); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolButtonStyle).toInt(), (int) Qt::ToolButtonTextOnly); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolBarIconSize).toInt(), 2); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick).toBool(), false); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::SystemIconThemeName).toString(), QLatin1String("non-existent-icon-theme")); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::SystemIconFallbackThemeName).toString(), QLatin1String("hicolor")); - QVERIFY(m_qpa->themeHint(QPlatformTheme::IconThemeSearchPaths).toString().isEmpty()); - QStringList styles; - styles << "non-existent-widget-style" << "oxygen" << "fusion" << "windows"; - QCOMPARE(m_qpa->themeHint(QPlatformTheme::StyleNames).toStringList(), styles); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt(), (int) QDialogButtonBox::KdeLayout); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::DialogButtonBoxButtonsHaveIcons).toBool(), false); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(), true); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::KeyboardScheme).toInt(), (int) QPlatformTheme::KdeKeyboardScheme); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::UiEffects).toInt(), 0); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::IconPixmapSizes).value >(), QList() << 512 << 256 << 128 << 64 << 32 << 22 << 16 << 8); - - QCOMPARE(qApp->wheelScrollLines(), 1234); - QCOMPARE(qApp->testAttribute(Qt::AA_DontShowIconsInMenus), false); - } + QEventLoop m_loop; + QToolButton m_toolBtn; + KdePlatformTheme *m_qpa; +private Q_SLOTS: + void initTestCase() + { + m_qpa = new KdePlatformTheme(); + QDBusConnection::sessionBus().connect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings", + "notifyChange", &m_loop, SLOT(quit())); + } - void testPlatformPalette() - { - const QPalette *palette = m_qpa->palette(); - QPalette::ColorGroup states[3] = {QPalette::Active, QPalette::Inactive, QPalette::Disabled}; - QColor greenColor(QColor(0, 128,0)); - QBrush greenBrush(greenColor); - for ( int i = 0; i < 3 ; i++ ) { - QCOMPARE(palette->brush(states[i], QPalette::ButtonText), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::WindowText), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::Window), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::Base), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::Text), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::Button), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::ButtonText), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::Highlight), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::HighlightedText), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::ToolTipBase), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::ToolTipText), greenBrush); - - //KColorScheme applies modifications and we can't disable them, so I extracted - //the values and blindly compare them. - QCOMPARE(palette->color(states[i], QPalette::Light).green(), 162); - QCOMPARE(palette->color(states[i], QPalette::Midlight).green(), 144); - QCOMPARE(palette->color(states[i], QPalette::Mid).green(), 109); - QCOMPARE(palette->color(states[i], QPalette::Dark).green(), 62); - QCOMPARE(palette->color(states[i], QPalette::Shadow).green(), 43); - - QCOMPARE(palette->brush(states[i], QPalette::AlternateBase), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::Link), greenBrush); - QCOMPARE(palette->brush(states[i], QPalette::LinkVisited), greenBrush); - } - } + void testPlatformHints() + { + QCOMPARE(m_qpa->themeHint(QPlatformTheme::CursorFlashTime).toInt(), 1042); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::MouseDoubleClickInterval).toInt(), 4343); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragDistance).toInt(), 15); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragTime).toInt(), 555); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolButtonStyle).toInt(), (int) Qt::ToolButtonTextOnly); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolBarIconSize).toInt(), 2); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick).toBool(), false); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::SystemIconThemeName).toString(), QLatin1String("non-existent-icon-theme")); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::SystemIconFallbackThemeName).toString(), QLatin1String("hicolor")); + QVERIFY(m_qpa->themeHint(QPlatformTheme::IconThemeSearchPaths).toString().isEmpty()); + QStringList styles; + styles << "non-existent-widget-style" << "oxygen" << "fusion" << "windows"; + QCOMPARE(m_qpa->themeHint(QPlatformTheme::StyleNames).toStringList(), styles); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt(), (int) QDialogButtonBox::KdeLayout); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::DialogButtonBoxButtonsHaveIcons).toBool(), false); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(), true); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::KeyboardScheme).toInt(), (int) QPlatformTheme::KdeKeyboardScheme); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::UiEffects).toInt(), 0); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::IconPixmapSizes).value >(), QList() << 512 << 256 << 128 << 64 << 32 << 22 << 16 << 8); + + QCOMPARE(qApp->wheelScrollLines(), 1234); + QCOMPARE(qApp->testAttribute(Qt::AA_DontShowIconsInMenus), false); + } - void testPlatformIconEngine() - { - QIconEngine *engine = m_qpa->createIconEngine(QStringLiteral("test-icon")); - QCOMPARE(engine->key(), QStringLiteral("KIconEngine")); + void testPlatformPalette() + { + const QPalette *palette = m_qpa->palette(); + QPalette::ColorGroup states[3] = {QPalette::Active, QPalette::Inactive, QPalette::Disabled}; + QColor greenColor(QColor(0, 128, 0)); + QBrush greenBrush(greenColor); + for (int i = 0; i < 3; i++) { + QCOMPARE(palette->brush(states[i], QPalette::ButtonText), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::WindowText), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::Window), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::Base), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::Text), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::Button), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::ButtonText), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::Highlight), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::HighlightedText), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::ToolTipBase), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::ToolTipText), greenBrush); + + //KColorScheme applies modifications and we can't disable them, so I extracted + //the values and blindly compare them. + QCOMPARE(palette->color(states[i], QPalette::Light).green(), 162); + QCOMPARE(palette->color(states[i], QPalette::Midlight).green(), 144); + QCOMPARE(palette->color(states[i], QPalette::Mid).green(), 109); + QCOMPARE(palette->color(states[i], QPalette::Dark).green(), 62); + QCOMPARE(palette->color(states[i], QPalette::Shadow).green(), 43); + + QCOMPARE(palette->brush(states[i], QPalette::AlternateBase), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::Link), greenBrush); + QCOMPARE(palette->brush(states[i], QPalette::LinkVisited), greenBrush); } + } - void testPlatformIconChanges() - { - QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); - configPath.append("/kdeglobals"); - QFile::remove(configPath); - QFile::copy(CHANGED_CONFIGFILE, configPath); + void testPlatformIconEngine() + { + QIconEngine *engine = m_qpa->createIconEngine(QStringLiteral("test-icon")); + QCOMPARE(engine->key(), QStringLiteral("KIconEngine")); + } - QDBusConnection::sessionBus().connect(QString(), "/KIconLoader", "org.kde.KIconLoader", - "iconChanged", &m_loop, SLOT(quit())); + void testPlatformIconChanges() + { + QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); + configPath.append("/kdeglobals"); + QFile::remove(configPath); + QFile::copy(CHANGED_CONFIGFILE, configPath); - QDBusMessage message = QDBusMessage::createSignal("/KIconLoader", "org.kde.KIconLoader", "iconChanged" ); - message.setArguments(QList() << int(KIconLoader::MainToolbar)); - QDBusConnection::sessionBus().send(message); - m_loop.exec(); + QDBusConnection::sessionBus().connect(QString(), "/KIconLoader", "org.kde.KIconLoader", + "iconChanged", &m_loop, SLOT(quit())); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolBarIconSize).toInt(), 11); - } + QDBusMessage message = QDBusMessage::createSignal("/KIconLoader", "org.kde.KIconLoader", "iconChanged"); + message.setArguments(QList() << int(KIconLoader::MainToolbar)); + QDBusConnection::sessionBus().send(message); + m_loop.exec(); - void testPlatformHintChanges() - { - EventTest tester(&m_toolBtn, QEvent::StyleChange); - sendNotifyChange(KHintsSettings::SettingsChanged, KHintsSettings::SETTINGS_QT); - m_loop.exec(); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolBarIconSize).toInt(), 11); + } - QCOMPARE(m_qpa->themeHint(QPlatformTheme::CursorFlashTime).toInt(), 1022); + void testPlatformHintChanges() + { + EventTest tester(&m_toolBtn, QEvent::StyleChange); + sendNotifyChange(KHintsSettings::SettingsChanged, KHintsSettings::SETTINGS_QT); + m_loop.exec(); - sendNotifyChange(KHintsSettings::SettingsChanged, KHintsSettings::SETTINGS_MOUSE); - m_loop.exec(); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::CursorFlashTime).toInt(), 1022); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick).toBool(), true); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::MouseDoubleClickInterval).toInt(), 401); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragDistance).toInt(), 35); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragTime).toInt(), 501); + sendNotifyChange(KHintsSettings::SettingsChanged, KHintsSettings::SETTINGS_MOUSE); + m_loop.exec(); - QCOMPARE(qApp->wheelScrollLines(), 122); - QCOMPARE(qApp->testAttribute(Qt::AA_DontShowIconsInMenus), true); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick).toBool(), true); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::MouseDoubleClickInterval).toInt(), 401); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragDistance).toInt(), 35); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::StartDragTime).toInt(), 501); - sendNotifyChange(KHintsSettings::ToolbarStyleChanged, 2); - m_loop.exec(); + QCOMPARE(qApp->wheelScrollLines(), 122); + QCOMPARE(qApp->testAttribute(Qt::AA_DontShowIconsInMenus), true); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolButtonStyle).toInt(), (int) Qt::ToolButtonTextUnderIcon); - QCOMPARE(tester.gotEvent, true); + sendNotifyChange(KHintsSettings::ToolbarStyleChanged, 2); + m_loop.exec(); - sendNotifyChange(KHintsSettings::StyleChanged, 2); - m_loop.exec(); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::ToolButtonStyle).toInt(), (int) Qt::ToolButtonTextUnderIcon); + QCOMPARE(tester.gotEvent, true); - QStringList styles; - styles << "another-non-existent-widget-style" << "oxygen" << "fusion" << "windows"; - QCOMPARE(m_qpa->themeHint(QPlatformTheme::StyleNames).toStringList(), styles); + sendNotifyChange(KHintsSettings::StyleChanged, 2); + m_loop.exec(); - sendNotifyChange(KHintsSettings::SettingsChanged, KHintsSettings::SETTINGS_STYLE); - m_loop.exec(); + QStringList styles; + styles << "another-non-existent-widget-style" << "oxygen" << "fusion" << "windows"; + QCOMPARE(m_qpa->themeHint(QPlatformTheme::StyleNames).toStringList(), styles); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::DialogButtonBoxButtonsHaveIcons).toBool(), true); + sendNotifyChange(KHintsSettings::SettingsChanged, KHintsSettings::SETTINGS_STYLE); + m_loop.exec(); - sendNotifyChange(KHintsSettings::IconChanged, 4); - m_loop.exec(); + QCOMPARE(m_qpa->themeHint(QPlatformTheme::DialogButtonBoxButtonsHaveIcons).toBool(), true); - QCOMPARE(m_qpa->themeHint(QPlatformTheme::SystemIconThemeName).toString(), QLatin1String("other-non-existent")); - } + sendNotifyChange(KHintsSettings::IconChanged, 4); + m_loop.exec(); + + QCOMPARE(m_qpa->themeHint(QPlatformTheme::SystemIconThemeName).toString(), QLatin1String("other-non-existent")); + } - void testPlatformPaletteChanges() - { - EventTest tester(QGuiApplication::instance(), QEvent::ApplicationPaletteChange); - sendNotifyChange(KHintsSettings::PaletteChanged, 0); - m_loop.exec(); - QCOMPARE(tester.gotEvent, true); - - const QPalette *palette = m_qpa->palette(); - QPalette::ColorGroup states[3] = {QPalette::Active, QPalette::Inactive, QPalette::Disabled}; - QColor redColor(QColor(174,11,11)); - QBrush redBrush(redColor); - for ( int i = 0; i < 3 ; i++ ) { - QCOMPARE(palette->brush(states[i], QPalette::ButtonText), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::WindowText), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::Window), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::Base), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::Text), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::Button), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::ButtonText), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::Highlight), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::HighlightedText), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::ToolTipBase), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::ToolTipText), redBrush); - - //KColorScheme applies modifications and we can't disable them, so I extracted - //the values and blindly compare them. - QCOMPARE(palette->color(states[i], QPalette::Light).red(), 230); - QCOMPARE(palette->color(states[i], QPalette::Midlight).red(), 203); - QCOMPARE(palette->color(states[i], QPalette::Mid).red(), 149); - QCOMPARE(palette->color(states[i], QPalette::Dark).red(), 84); - QCOMPARE(palette->color(states[i], QPalette::Shadow).red(), 60); - - QCOMPARE(palette->brush(states[i], QPalette::AlternateBase), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::Link), redBrush); - QCOMPARE(palette->brush(states[i], QPalette::LinkVisited), redBrush); - } + void testPlatformPaletteChanges() + { + EventTest tester(QGuiApplication::instance(), QEvent::ApplicationPaletteChange); + sendNotifyChange(KHintsSettings::PaletteChanged, 0); + m_loop.exec(); + QCOMPARE(tester.gotEvent, true); + + const QPalette *palette = m_qpa->palette(); + QPalette::ColorGroup states[3] = {QPalette::Active, QPalette::Inactive, QPalette::Disabled}; + QColor redColor(QColor(174, 11, 11)); + QBrush redBrush(redColor); + for (int i = 0; i < 3; i++) { + QCOMPARE(palette->brush(states[i], QPalette::ButtonText), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::WindowText), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::Window), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::Base), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::Text), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::Button), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::ButtonText), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::Highlight), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::HighlightedText), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::ToolTipBase), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::ToolTipText), redBrush); + + //KColorScheme applies modifications and we can't disable them, so I extracted + //the values and blindly compare them. + QCOMPARE(palette->color(states[i], QPalette::Light).red(), 230); + QCOMPARE(palette->color(states[i], QPalette::Midlight).red(), 203); + QCOMPARE(palette->color(states[i], QPalette::Mid).red(), 149); + QCOMPARE(palette->color(states[i], QPalette::Dark).red(), 84); + QCOMPARE(palette->color(states[i], QPalette::Shadow).red(), 60); + + QCOMPARE(palette->brush(states[i], QPalette::AlternateBase), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::Link), redBrush); + QCOMPARE(palette->brush(states[i], QPalette::LinkVisited), redBrush); } + } }; QTEST_MAIN(KdePlatformTheme_UnitTest) #include "kdeplatformtheme_unittest.moc" diff --git a/autotests/kfontsettingsdata_unittest.cpp b/autotests/kfontsettingsdata_unittest.cpp index dbd1738..41d8b40 100644 --- a/autotests/kfontsettingsdata_unittest.cpp +++ b/autotests/kfontsettingsdata_unittest.cpp @@ -1,116 +1,116 @@ /* This file is part of the KDE libraries * Copyright 2013 Alejandro Fiestas Olivares * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kdeplatformtheme_config.h" #include "../src/platformtheme/kfontsettingsdata.h" #include #include #include #include #include #include #include #include #include #include #include #include static void prepareEnvironment() { qputenv("KDEHOME", QFile::encodeName(QDir::homePath() + QStringLiteral("/.kde5-unit-test-platformtheme"))); qputenv("XDG_DATA_HOME", QFile::encodeName(QDir::homePath() + QStringLiteral("/.kde5-unit-test-platformtheme/xdg/local"))); QByteArray configPath = QFile::encodeName(QDir::homePath() + QStringLiteral("/.kde5-unit-test-platformtheme/xdg/config")); qputenv("XDG_CONFIG_HOME", configPath); qputenv("KDE_SKIP_KDERC", "1"); qunsetenv("KDE_COLOR_DEBUG"); QDir().mkpath(configPath); configPath.append("/kdeglobals"); QFile::remove(configPath); QFile::copy(CONFIGFILE, configPath); } Q_COREAPP_STARTUP_FUNCTION(prepareEnvironment); class KFontSettingsData_UnitTest : public QWidget { Q_OBJECT - public: - virtual bool event(QEvent* e) - { - if (e->type() == QEvent::ApplicationFontChange) { - m_appChangedFont = true; - } - return QWidget::event(e); - } - private: - bool m_appChangedFont; - KFontSettingsData *m_fonts; - private Q_SLOTS: - void initTestCase() - { - m_appChangedFont = false; - m_fonts = new KFontSettingsData; +public: + virtual bool event(QEvent *e) + { + if (e->type() == QEvent::ApplicationFontChange) { + m_appChangedFont = true; } + return QWidget::event(e); + } +private: + bool m_appChangedFont; + KFontSettingsData *m_fonts; +private Q_SLOTS: + void initTestCase() + { + m_appChangedFont = false; + m_fonts = new KFontSettingsData; + } - void testFonts() - { - QCOMPARE(m_fonts->font(KFontSettingsData::GeneralFont)->family(), QStringLiteral("OxyFontTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::FixedFont)->family(), QStringLiteral("OxyFixedTest Mono")); - QCOMPARE(m_fonts->font(KFontSettingsData::ToolbarFont)->family(), QStringLiteral("OxyToolbarTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::MenuFont)->family(), QStringLiteral("OxyMenuTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::WindowTitleFont)->family(), QStringLiteral("OxyActiveTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::TaskbarFont)->family(), QStringLiteral("OxyTaskbarTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::SmallestReadableFont)->family(), QStringLiteral("OxySmallestReadableTest")); - } + void testFonts() + { + QCOMPARE(m_fonts->font(KFontSettingsData::GeneralFont)->family(), QStringLiteral("OxyFontTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::FixedFont)->family(), QStringLiteral("OxyFixedTest Mono")); + QCOMPARE(m_fonts->font(KFontSettingsData::ToolbarFont)->family(), QStringLiteral("OxyToolbarTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::MenuFont)->family(), QStringLiteral("OxyMenuTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::WindowTitleFont)->family(), QStringLiteral("OxyActiveTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::TaskbarFont)->family(), QStringLiteral("OxyTaskbarTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::SmallestReadableFont)->family(), QStringLiteral("OxySmallestReadableTest")); + } - void testFontsChanged() - { - QByteArray configPath = qgetenv("XDG_CONFIG_HOME"); - configPath.append("/kdeglobals"); - QFile::remove(configPath); - QFile::copy(CHANGED_CONFIGFILE, configPath); + void testFontsChanged() + { + QByteArray configPath = qgetenv("XDG_CONFIG_HOME"); + configPath.append("/kdeglobals"); + QFile::remove(configPath); + QFile::copy(CHANGED_CONFIGFILE, configPath); - QEventLoop loop; - QDBusConnection::sessionBus().connect( QString(), "/KDEPlatformTheme", "org.kde.KDEPlatformTheme", - "refreshFonts", &loop, SLOT(quit()) ); + QEventLoop loop; + QDBusConnection::sessionBus().connect(QString(), "/KDEPlatformTheme", "org.kde.KDEPlatformTheme", + "refreshFonts", &loop, SLOT(quit())); - QDBusMessage message = QDBusMessage::createSignal("/KDEPlatformTheme", "org.kde.KDEPlatformTheme", "refreshFonts" ); - QDBusConnection::sessionBus().send(message); - loop.exec(); + QDBusMessage message = QDBusMessage::createSignal("/KDEPlatformTheme", "org.kde.KDEPlatformTheme", "refreshFonts"); + QDBusConnection::sessionBus().send(message); + loop.exec(); - QVERIFY(m_appChangedFont); - QCOMPARE(m_fonts->font(KFontSettingsData::GeneralFont)->family(), QStringLiteral("ChangedFontTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::FixedFont)->family(), QStringLiteral("ChangedFixedTest Mono")); - QCOMPARE(m_fonts->font(KFontSettingsData::ToolbarFont)->family(), QStringLiteral("ChangedToolbarTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::MenuFont)->family(), QStringLiteral("ChangedMenuTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::WindowTitleFont)->family(), QStringLiteral("ChangedActiveTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::TaskbarFont)->family(), QStringLiteral("ChangedTaskbarTest")); - QCOMPARE(m_fonts->font(KFontSettingsData::SmallestReadableFont)->family(), QStringLiteral("ChangedSmallestReadableTest")); - } + QVERIFY(m_appChangedFont); + QCOMPARE(m_fonts->font(KFontSettingsData::GeneralFont)->family(), QStringLiteral("ChangedFontTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::FixedFont)->family(), QStringLiteral("ChangedFixedTest Mono")); + QCOMPARE(m_fonts->font(KFontSettingsData::ToolbarFont)->family(), QStringLiteral("ChangedToolbarTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::MenuFont)->family(), QStringLiteral("ChangedMenuTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::WindowTitleFont)->family(), QStringLiteral("ChangedActiveTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::TaskbarFont)->family(), QStringLiteral("ChangedTaskbarTest")); + QCOMPARE(m_fonts->font(KFontSettingsData::SmallestReadableFont)->family(), QStringLiteral("ChangedSmallestReadableTest")); + } }; QTEST_MAIN(KFontSettingsData_UnitTest) #include "kfontsettingsdata_unittest.moc" \ No newline at end of file diff --git a/src/platformtheme/kdeplatformfiledialoghelper.cpp b/src/platformtheme/kdeplatformfiledialoghelper.cpp index bb3f0de..cf8b0da 100644 --- a/src/platformtheme/kdeplatformfiledialoghelper.cpp +++ b/src/platformtheme/kdeplatformfiledialoghelper.cpp @@ -1,245 +1,247 @@ /* This file is part of the KDE libraries * Copyright 2013 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kdeplatformfiledialoghelper.h" #include #include #include #include #include #include #include #include #include namespace { /* * Map a Qt filter string into a KDE one. */ static QString qt2KdeFilter(const QStringList &f) { QString filter; QTextStream str(&filter, QIODevice::WriteOnly); QStringList list(f); list.replaceInStrings("/", "\\/"); QStringList::const_iterator it(list.begin()), end(list.end()); - bool first=true; - - for (; it!=end; ++it) - { - int ob=it->lastIndexOf('('), - cb=it->lastIndexOf(')'); - - if (-1!=cb && oblastIndexOf('('), + cb = it->lastIndexOf(')'); + + if (-1 != cb && ob < cb) { + if (first) { + first = false; + } else { str << '\n'; - str << it->mid(ob+1, (cb-ob)-1) << '|' << it->mid(0, ob); + } + str << it->mid(ob + 1, (cb - ob) - 1) << '|' << it->mid(0, ob); } } return filter; } /* * Map a KDE filter string into a Qt one. */ static QString kde2QtFilter(const QStringList &list, const QString &kde) { QStringList::const_iterator it(list.begin()), end(list.end()); int pos; QString sel; - for (; it!=end; ++it) { - if (-1!=(pos=it->indexOf(kde)) && pos>0 && - ('('==(*it)[pos-1] || ' '==(*it)[pos-1]) && - it->length()>=kde.length()+pos && - (')'==(*it)[pos+kde.length()] || ' '==(*it)[pos+kde.length()])) - { + for (; it != end; ++it) { + if (-1 != (pos = it->indexOf(kde)) && pos > 0 && + ('(' == (*it)[pos - 1] || ' ' == (*it)[pos - 1]) && + it->length() >= kde.length() + pos && + (')' == (*it)[pos + kde.length()] || ' ' == (*it)[pos + kde.length()])) { return *it; } } return QString(); } } KDEPlatformFileDialog::KDEPlatformFileDialog() : QDialog() , m_fileWidget(new KFileWidget(QUrl(), this)) { setLayout(new QVBoxLayout); connect(m_fileWidget, SIGNAL(selectionChanged()), SLOT(selectionChanged())); connect(m_fileWidget, SIGNAL(fileHighlighted(QUrl)), SLOT(selectionChanged())); connect(m_fileWidget, SIGNAL(filterChanged(QString)), SIGNAL(filterSelected(QString))); connect(m_fileWidget, SIGNAL(accepted()), SLOT(accept())); layout()->addWidget(m_fileWidget); m_buttons = new QDialogButtonBox(this); m_buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(m_buttons, SIGNAL(accepted()), m_fileWidget, SLOT(slotOk())); connect(m_buttons, SIGNAL(rejected()), m_fileWidget, SLOT(slotCancel())); connect(m_buttons, SIGNAL(rejected()), SLOT(reject())); layout()->addWidget(m_buttons); m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!m_fileWidget->selectedUrls().isEmpty()); } void KDEPlatformFileDialog::selectionChanged() { m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!m_fileWidget->dirOperator()->selectedItems().isEmpty()); } QUrl KDEPlatformFileDialog::directory() { return m_fileWidget->baseUrl(); } QList KDEPlatformFileDialog::selectedFiles() { QList ret; KFileItemList items = m_fileWidget->dirOperator()->selectedItems(); - Q_FOREACH(const KFileItem& item, items) { + Q_FOREACH (const KFileItem &item, items) { ret += item.url(); } return ret; } void KDEPlatformFileDialog::selectFile(const QUrl &filename) { m_fileWidget->setUrl(filename); } QString KDEPlatformFileDialog::selectedNameFilter() { return m_fileWidget->filterWidget()->currentFilter(); } void KDEPlatformFileDialog::selectNameFilter(const QString &filter) { m_fileWidget->filterWidget()->setCurrentFilter(filter); } void KDEPlatformFileDialog::setDirectory(const QUrl &directory) { m_fileWidget->setStartDir(directory); } //////////////////////////////////////////////// KDEPlatformFileDialogHelper::KDEPlatformFileDialogHelper() : QPlatformFileDialogHelper() , m_dialog(new KDEPlatformFileDialog) { connect(m_dialog, SIGNAL(currentChanged(QUrl)), SIGNAL(currentChanged(QUrl))); connect(m_dialog, SIGNAL(directoryEntered(QUrl)), SIGNAL(directoryEntered(QUrl))); connect(m_dialog, SIGNAL(fileSelected(QUrl)), SIGNAL(fileSelected(QUrl))); connect(m_dialog, SIGNAL(filesSelected(QList)), SIGNAL(filesSelected(QList))); connect(m_dialog, SIGNAL(filterSelected(QString)), SIGNAL(filterSelected(QString))); connect(m_dialog, SIGNAL(accepted()), SIGNAL(accept())); connect(m_dialog, SIGNAL(rejected()), SIGNAL(reject())); } KDEPlatformFileDialogHelper::~KDEPlatformFileDialogHelper() { delete m_dialog; } void KDEPlatformFileDialogHelper::initializeDialog() { - m_dialog->m_fileWidget->setOperationMode(options()->acceptMode()==QFileDialogOptions::AcceptOpen ? KFileWidget::Opening : KFileWidget::Saving); - if (options()->windowTitle().isEmpty()) + m_dialog->m_fileWidget->setOperationMode(options()->acceptMode() == QFileDialogOptions::AcceptOpen ? KFileWidget::Opening : KFileWidget::Saving); + if (options()->windowTitle().isEmpty()) { m_dialog->setWindowTitle(options()->acceptMode() == QFileDialogOptions::AcceptOpen ? i18n("Opening...") : i18n("Saving...")); - else + } else { m_dialog->setWindowTitle(options()->windowTitle()); + } setDirectory(options()->initialDirectory()); QStringList filters = options()->mimeTypeFilters(); - if (!filters.isEmpty()) + if (!filters.isEmpty()) { m_dialog->m_fileWidget->setMimeFilter(filters); + } QStringList nameFilters = options()->nameFilters(); - if (!nameFilters.isEmpty()) + if (!nameFilters.isEmpty()) { m_dialog->m_fileWidget->setFilter(qt2KdeFilter(nameFilters)); + } } void KDEPlatformFileDialogHelper::exec() { } void KDEPlatformFileDialogHelper::hide() { m_dialog->hide(); } bool KDEPlatformFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) { initializeDialog(); m_dialog->setWindowFlags(windowFlags); m_dialog->setModal(windowModality != Qt::NonModal); - if (windowModality == Qt::NonModal) + if (windowModality == Qt::NonModal) { m_dialog->show(); - else + } else { m_dialog->exec(); + } return true; } QList KDEPlatformFileDialogHelper::selectedFiles() const { return m_dialog->selectedFiles(); } QString KDEPlatformFileDialogHelper::selectedNameFilter() const { return kde2QtFilter(options()->nameFilters(), m_dialog->selectedNameFilter()); } QUrl KDEPlatformFileDialogHelper::directory() const { return m_dialog->directory(); } -void KDEPlatformFileDialogHelper::selectFile(const QUrl& filename) +void KDEPlatformFileDialogHelper::selectFile(const QUrl &filename) { m_dialog->selectFile(filename); } -void KDEPlatformFileDialogHelper::setDirectory(const QUrl& directory) +void KDEPlatformFileDialogHelper::setDirectory(const QUrl &directory) { m_dialog->setDirectory(directory); } -void KDEPlatformFileDialogHelper::selectNameFilter(const QString& filter) +void KDEPlatformFileDialogHelper::selectNameFilter(const QString &filter) { m_dialog->selectNameFilter(qt2KdeFilter(QStringList(filter))); } void KDEPlatformFileDialogHelper::setFilter() { } bool KDEPlatformFileDialogHelper::defaultNameFilterDisables() const { return false; } diff --git a/src/platformtheme/kdeplatformfiledialoghelper.h b/src/platformtheme/kdeplatformfiledialoghelper.h index 3145319..3f69f29 100644 --- a/src/platformtheme/kdeplatformfiledialoghelper.h +++ b/src/platformtheme/kdeplatformfiledialoghelper.h @@ -1,83 +1,83 @@ /* This file is part of the KDE libraries * Copyright 2013 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KDEPLATFORMFONTDIALOGHELPER_H #define KDEPLATFORMFONTDIALOGHELPER_H #include #include class KFileWidget; class QDialogButtonBox; class KDEPlatformFileDialog : public QDialog { -Q_OBJECT + Q_OBJECT public: friend class KDEPlatformFileDialogHelper; explicit KDEPlatformFileDialog(); QUrl directory(); void selectNameFilter(const QString &filter); void setDirectory(const QUrl &directory); void selectFile(const QUrl &filename); QString selectedNameFilter(); QList selectedFiles(); Q_SIGNALS: void fileSelected(const QUrl &file); void filesSelected(const QList &files); void currentChanged(const QUrl &path); void directoryEntered(const QUrl &directory); void filterSelected(const QString &filter); private Q_SLOTS: void selectionChanged(); protected: - KFileWidget* m_fileWidget; - QDialogButtonBox* m_buttons; + KFileWidget *m_fileWidget; + QDialogButtonBox *m_buttons; }; class KDEPlatformFileDialogHelper : public QPlatformFileDialogHelper { public: KDEPlatformFileDialogHelper(); virtual ~KDEPlatformFileDialogHelper(); void initializeDialog(); virtual bool defaultNameFilterDisables() const; virtual QUrl directory() const; virtual QList selectedFiles() const; virtual QString selectedNameFilter() const; virtual void selectNameFilter(const QString &filter); virtual void selectFile(const QUrl &filename); virtual void setFilter(); virtual void setDirectory(const QUrl &directory); virtual void exec(); virtual void hide(); virtual bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent); private: - KDEPlatformFileDialog* m_dialog; + KDEPlatformFileDialog *m_dialog; }; #endif // KDEPLATFORMFONTDIALOGHELPER_H diff --git a/src/platformtheme/kdeplatformtheme.cpp b/src/platformtheme/kdeplatformtheme.cpp index 9b8db3e..dae5dd0 100644 --- a/src/platformtheme/kdeplatformtheme.cpp +++ b/src/platformtheme/kdeplatformtheme.cpp @@ -1,211 +1,211 @@ /* This file is part of the KDE libraries * Copyright 2013 Kevin Ottens * Copyright 2013 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kdeplatformtheme.h" #include "kfontsettingsdata.h" #include "khintssettings.h" #include "kdeplatformfiledialoghelper.h" #include #include #include #include #include #include #include #include #include KdePlatformTheme::KdePlatformTheme() { loadSettings(); } KdePlatformTheme::~KdePlatformTheme() { delete m_fontsData; delete m_hints; } QVariant KdePlatformTheme::themeHint(QPlatformTheme::ThemeHint hintType) const { QVariant hint = m_hints->hint(hintType); if (hint.isValid()) { return hint; } else { return QPlatformTheme::themeHint(hintType); } } const QPalette *KdePlatformTheme::palette(Palette type) const { QPalette *palette = m_hints->palette(type); - if (palette) + if (palette) { return palette; - else + } else { return QPlatformTheme::palette(type); + } } const QFont *KdePlatformTheme::font(Font type) const { KFontSettingsData::FontTypes fdtype; - switch(type) { - case SystemFont: - fdtype = KFontSettingsData::GeneralFont; break; - case MenuFont: - case MenuBarFont: - case MenuItemFont: - fdtype = KFontSettingsData::MenuFont; break; - case MessageBoxFont: - case LabelFont: - case TipLabelFont: - case StatusBarFont: - case PushButtonFont: - case ToolButtonFont: - case ItemViewFont: - case ListViewFont: - case HeaderViewFont: - case ListBoxFont: - case ComboMenuItemFont: - case ComboLineEditFont: - fdtype = KFontSettingsData::GeneralFont; break; - case TitleBarFont: - case MdiSubWindowTitleFont: - case DockWidgetTitleFont: - fdtype = KFontSettingsData::WindowTitleFont; break; - case SmallFont: - case MiniFont: - fdtype = KFontSettingsData::SmallestReadableFont; break; - default: - fdtype = KFontSettingsData::GeneralFont; break; + switch (type) { + case SystemFont: + fdtype = KFontSettingsData::GeneralFont; break; + case MenuFont: + case MenuBarFont: + case MenuItemFont: + fdtype = KFontSettingsData::MenuFont; break; + case MessageBoxFont: + case LabelFont: + case TipLabelFont: + case StatusBarFont: + case PushButtonFont: + case ToolButtonFont: + case ItemViewFont: + case ListViewFont: + case HeaderViewFont: + case ListBoxFont: + case ComboMenuItemFont: + case ComboLineEditFont: + fdtype = KFontSettingsData::GeneralFont; break; + case TitleBarFont: + case MdiSubWindowTitleFont: + case DockWidgetTitleFont: + fdtype = KFontSettingsData::WindowTitleFont; break; + case SmallFont: + case MiniFont: + fdtype = KFontSettingsData::SmallestReadableFont; break; + default: + fdtype = KFontSettingsData::GeneralFont; break; } return m_fontsData->font(fdtype); } QIconEngine *KdePlatformTheme::createIconEngine(const QString &iconName) const { return new KIconEngine(iconName, KIconLoader::global()); } void KdePlatformTheme::loadSettings() { m_fontsData = new KFontSettingsData; m_hints = new KHintsSettings; } - QList KdePlatformTheme::keyBindings(QKeySequence::StandardKey key) const { switch (key) { - case QKeySequence::HelpContents: - return KStandardShortcut::shortcut(KStandardShortcut::Help); - case QKeySequence::WhatsThis: - return KStandardShortcut::shortcut(KStandardShortcut::WhatsThis); - case QKeySequence::Open: - return KStandardShortcut::shortcut(KStandardShortcut::Open); - case QKeySequence::Close: - return KStandardShortcut::shortcut(KStandardShortcut::Close); - case QKeySequence::Save: - return KStandardShortcut::shortcut(KStandardShortcut::Save); - case QKeySequence::New: - return KStandardShortcut::shortcut(KStandardShortcut::New); - case QKeySequence::Cut: - return KStandardShortcut::shortcut(KStandardShortcut::Cut); - case QKeySequence::Copy: - return KStandardShortcut::shortcut(KStandardShortcut::Copy); - case QKeySequence::Paste: - return KStandardShortcut::shortcut(KStandardShortcut::Paste); - case QKeySequence::Undo: - return KStandardShortcut::shortcut(KStandardShortcut::Undo); - case QKeySequence::Redo: - return KStandardShortcut::shortcut(KStandardShortcut::Redo); - case QKeySequence::Back: - return KStandardShortcut::shortcut(KStandardShortcut::Back); - case QKeySequence::Forward: - return KStandardShortcut::shortcut(KStandardShortcut::Forward); - case QKeySequence::Refresh: - return KStandardShortcut::shortcut(KStandardShortcut::Reload); - case QKeySequence::ZoomIn: - return KStandardShortcut::shortcut(KStandardShortcut::ZoomIn); - case QKeySequence::ZoomOut: - return KStandardShortcut::shortcut(KStandardShortcut::ZoomOut); - case QKeySequence::Print: - return KStandardShortcut::shortcut(KStandardShortcut::Print); - case QKeySequence::Find: - return KStandardShortcut::shortcut(KStandardShortcut::Find); - case QKeySequence::FindNext: - return KStandardShortcut::shortcut(KStandardShortcut::FindNext); - case QKeySequence::FindPrevious: - return KStandardShortcut::shortcut(KStandardShortcut::FindPrev); - case QKeySequence::Replace: - return KStandardShortcut::shortcut(KStandardShortcut::Replace); - case QKeySequence::SelectAll: - return KStandardShortcut::shortcut(KStandardShortcut::SelectAll); - case QKeySequence::MoveToNextWord: - return KStandardShortcut::shortcut(KStandardShortcut::ForwardWord); - case QKeySequence::MoveToPreviousWord: - return KStandardShortcut::shortcut(KStandardShortcut::BackwardWord); - case QKeySequence::MoveToNextPage: - return KStandardShortcut::shortcut(KStandardShortcut::Next); - case QKeySequence::MoveToPreviousPage: - return KStandardShortcut::shortcut(KStandardShortcut::Prior); - case QKeySequence::MoveToStartOfLine: - return KStandardShortcut::shortcut(KStandardShortcut::BeginningOfLine); - case QKeySequence::MoveToEndOfLine: - return KStandardShortcut::shortcut(KStandardShortcut::EndOfLine); - case QKeySequence::MoveToStartOfDocument: - return KStandardShortcut::shortcut(KStandardShortcut::Home); - case QKeySequence::MoveToEndOfDocument: - return KStandardShortcut::shortcut(KStandardShortcut::End); - case QKeySequence::SaveAs: - return KStandardShortcut::shortcut(KStandardShortcut::SaveAs); - case QKeySequence::Preferences: - return KStandardShortcut::shortcut(KStandardShortcut::Preferences); - case QKeySequence::Quit: - return KStandardShortcut::shortcut(KStandardShortcut::Quit); - case QKeySequence::FullScreen: - return KStandardShortcut::shortcut(KStandardShortcut::FullScreen); - case QKeySequence::Deselect: - return KStandardShortcut::shortcut(KStandardShortcut::Deselect); - default: - return QPlatformTheme::keyBindings(key); + case QKeySequence::HelpContents: + return KStandardShortcut::shortcut(KStandardShortcut::Help); + case QKeySequence::WhatsThis: + return KStandardShortcut::shortcut(KStandardShortcut::WhatsThis); + case QKeySequence::Open: + return KStandardShortcut::shortcut(KStandardShortcut::Open); + case QKeySequence::Close: + return KStandardShortcut::shortcut(KStandardShortcut::Close); + case QKeySequence::Save: + return KStandardShortcut::shortcut(KStandardShortcut::Save); + case QKeySequence::New: + return KStandardShortcut::shortcut(KStandardShortcut::New); + case QKeySequence::Cut: + return KStandardShortcut::shortcut(KStandardShortcut::Cut); + case QKeySequence::Copy: + return KStandardShortcut::shortcut(KStandardShortcut::Copy); + case QKeySequence::Paste: + return KStandardShortcut::shortcut(KStandardShortcut::Paste); + case QKeySequence::Undo: + return KStandardShortcut::shortcut(KStandardShortcut::Undo); + case QKeySequence::Redo: + return KStandardShortcut::shortcut(KStandardShortcut::Redo); + case QKeySequence::Back: + return KStandardShortcut::shortcut(KStandardShortcut::Back); + case QKeySequence::Forward: + return KStandardShortcut::shortcut(KStandardShortcut::Forward); + case QKeySequence::Refresh: + return KStandardShortcut::shortcut(KStandardShortcut::Reload); + case QKeySequence::ZoomIn: + return KStandardShortcut::shortcut(KStandardShortcut::ZoomIn); + case QKeySequence::ZoomOut: + return KStandardShortcut::shortcut(KStandardShortcut::ZoomOut); + case QKeySequence::Print: + return KStandardShortcut::shortcut(KStandardShortcut::Print); + case QKeySequence::Find: + return KStandardShortcut::shortcut(KStandardShortcut::Find); + case QKeySequence::FindNext: + return KStandardShortcut::shortcut(KStandardShortcut::FindNext); + case QKeySequence::FindPrevious: + return KStandardShortcut::shortcut(KStandardShortcut::FindPrev); + case QKeySequence::Replace: + return KStandardShortcut::shortcut(KStandardShortcut::Replace); + case QKeySequence::SelectAll: + return KStandardShortcut::shortcut(KStandardShortcut::SelectAll); + case QKeySequence::MoveToNextWord: + return KStandardShortcut::shortcut(KStandardShortcut::ForwardWord); + case QKeySequence::MoveToPreviousWord: + return KStandardShortcut::shortcut(KStandardShortcut::BackwardWord); + case QKeySequence::MoveToNextPage: + return KStandardShortcut::shortcut(KStandardShortcut::Next); + case QKeySequence::MoveToPreviousPage: + return KStandardShortcut::shortcut(KStandardShortcut::Prior); + case QKeySequence::MoveToStartOfLine: + return KStandardShortcut::shortcut(KStandardShortcut::BeginningOfLine); + case QKeySequence::MoveToEndOfLine: + return KStandardShortcut::shortcut(KStandardShortcut::EndOfLine); + case QKeySequence::MoveToStartOfDocument: + return KStandardShortcut::shortcut(KStandardShortcut::Home); + case QKeySequence::MoveToEndOfDocument: + return KStandardShortcut::shortcut(KStandardShortcut::End); + case QKeySequence::SaveAs: + return KStandardShortcut::shortcut(KStandardShortcut::SaveAs); + case QKeySequence::Preferences: + return KStandardShortcut::shortcut(KStandardShortcut::Preferences); + case QKeySequence::Quit: + return KStandardShortcut::shortcut(KStandardShortcut::Quit); + case QKeySequence::FullScreen: + return KStandardShortcut::shortcut(KStandardShortcut::FullScreen); + case QKeySequence::Deselect: + return KStandardShortcut::shortcut(KStandardShortcut::Deselect); + default: + return QPlatformTheme::keyBindings(key); } } bool KdePlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const { return type == QPlatformTheme::FileDialog; } -QPlatformDialogHelper* KdePlatformTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const +QPlatformDialogHelper *KdePlatformTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const { - switch(type) { - case QPlatformTheme::FileDialog: - return new KDEPlatformFileDialogHelper; - case QPlatformTheme::FontDialog: - case QPlatformTheme::ColorDialog: - case QPlatformTheme::MessageDialog: - default: - return 0; + switch (type) { + case QPlatformTheme::FileDialog: + return new KDEPlatformFileDialogHelper; + case QPlatformTheme::FontDialog: + case QPlatformTheme::ColorDialog: + case QPlatformTheme::MessageDialog: + default: + return 0; } } diff --git a/src/platformtheme/kdeplatformtheme.h b/src/platformtheme/kdeplatformtheme.h index 600147b..f436eea 100644 --- a/src/platformtheme/kdeplatformtheme.h +++ b/src/platformtheme/kdeplatformtheme.h @@ -1,56 +1,56 @@ /* This file is part of the KDE libraries * Copyright 2013 Kevin Ottens * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KDEPLATFORMTHEME_H #define KDEPLATFORMTHEME_H #include #include #include #include class KHintsSettings; class KFontSettingsData; class QIconEngine; class KdePlatformTheme : public QPlatformTheme { public: KdePlatformTheme(); ~KdePlatformTheme(); virtual QVariant themeHint(ThemeHint hint) const; virtual const QPalette *palette(Palette type = SystemPalette) const; virtual const QFont *font(Font type) const; virtual QIconEngine *createIconEngine(const QString &iconName) const; virtual QList keyBindings(QKeySequence::StandardKey key) const; - virtual QPlatformDialogHelper* createPlatformDialogHelper(DialogType type) const; + virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const; virtual bool usePlatformNativeDialog(DialogType type) const; private: void loadSettings(); KHintsSettings *m_hints; - KFontSettingsData* m_fontsData; + KFontSettingsData *m_fontsData; }; #endif // KDEPLATFORMTHEME_H diff --git a/src/platformtheme/kfontsettingsdata.cpp b/src/platformtheme/kfontsettingsdata.cpp index 9503510..a11b4bc 100644 --- a/src/platformtheme/kfontsettingsdata.cpp +++ b/src/platformtheme/kfontsettingsdata.cpp @@ -1,108 +1,108 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure Copyright 2008 Friedrich W. H. Kossebau Copyright 2013 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kfontsettingsdata.h" #include #include #include #include #include #include #include #include #include KFontSettingsData::KFontSettingsData() : QObject(0) { QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection); - for( int i=0; isetStyleHint( fontData.StyleHint ); + cachedFont = new QFont(fontData.FontName, fontData.Size, fontData.Weight); + cachedFont->setStyleHint(fontData.StyleHint); const KConfigGroup configGroup(KSharedConfig::openConfig("kdeglobals"), fontData.ConfigGroupKey); - QString fontInfo = configGroup.readEntry( fontData.ConfigKey, QString() ); + QString fontInfo = configGroup.readEntry(fontData.ConfigKey, QString()); //If we have serialized information for this font, restore it //NOTE: We are not using KConfig directly because we can't call QFont::QFont from here if (!fontInfo.isEmpty()) { cachedFont->fromString(fontInfo); } mFonts[fontType] = cachedFont; } return cachedFont; } void KFontSettingsData::dropFontSettingsCache() { - for( int i=0; i(QCoreApplication::instance())) { + if (qobject_cast(QCoreApplication::instance())) { QApplication::setFont(*font(KFontSettingsData::GeneralFont)); } else { QGuiApplication::setFont(*font(KFontSettingsData::GeneralFont)); } } void KFontSettingsData::delayedDBusConnects() { - QDBusConnection::sessionBus().connect( QString(), "/KDEPlatformTheme", "org.kde.KDEPlatformTheme", - "refreshFonts", this, SLOT(dropFontSettingsCache()) ); + QDBusConnection::sessionBus().connect(QString(), "/KDEPlatformTheme", "org.kde.KDEPlatformTheme", + "refreshFonts", this, SLOT(dropFontSettingsCache())); } diff --git a/src/platformtheme/kfontsettingsdata.h b/src/platformtheme/kfontsettingsdata.h index ce4de1d..75520d6 100644 --- a/src/platformtheme/kfontsettingsdata.h +++ b/src/platformtheme/kfontsettingsdata.h @@ -1,71 +1,69 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure Copyright 2008 Friedrich W. H. Kossebau Copyright 2013 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KGLOBALSETTINGSDATA_H #define KGLOBALSETTINGSDATA_H #include #include -struct KFontData -{ +struct KFontData { const char *ConfigGroupKey; const char *ConfigKey; const char *FontName; int Size; int Weight; QFont::StyleHint StyleHint; }; class KFontSettingsData : public QObject { - Q_OBJECT - public: + Q_OBJECT +public: // if adding a new type here also add an entry to DefaultFontData - enum FontTypes - { + enum FontTypes { GeneralFont = 0, FixedFont, ToolbarFont, MenuFont, WindowTitleFont, - TaskbarFont , + TaskbarFont, SmallestReadableFont, FontTypesCount }; - public: +public: KFontSettingsData(); ~KFontSettingsData(); - public Q_SLOTS: +public Q_SLOTS: void dropFontSettingsCache(); - private Q_SLOTS: +private Q_SLOTS: void delayedDBusConnects(); - public: // access, is not const due to caching - QFont *font( FontTypes fontType ); +public: // access, is not const due to caching + QFont *font(FontTypes fontType); - protected: +protected: QFont *mFonts[FontTypesCount]; }; #endif diff --git a/src/platformtheme/khintssettings.cpp b/src/platformtheme/khintssettings.cpp index 2dee4b1..c4de4ba 100644 --- a/src/platformtheme/khintssettings.cpp +++ b/src/platformtheme/khintssettings.cpp @@ -1,275 +1,278 @@ /* This file is part of the KDE libraries * Copyright 2013 Kevin Ottens * Copyright 2013 Aleix Pol Gonzalez * Copyright 2013 Alejandro Fiestas Olivares * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "khintssettings.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include KHintsSettings::KHintsSettings() : QObject(0) { KSharedConfig::Ptr ptr = KSharedConfig::openConfig("kdeglobals"); KConfigGroup cg(ptr, "KDE"); m_hints[QPlatformTheme::CursorFlashTime] = qBound(200, cg.readEntry("CursorBlinkRate", 1000), 2000); m_hints[QPlatformTheme::MouseDoubleClickInterval] = cg.readEntry("DoubleClickInterval", 400); m_hints[QPlatformTheme::StartDragDistance] = cg.readEntry("StartDragDist", 10); m_hints[QPlatformTheme::StartDragTime] = cg.readEntry("StartDragTime", 500); KConfigGroup cgToolbar(ptr, "Toolbar style"); m_hints[QPlatformTheme::ToolButtonStyle] = toolButtonStyle(cgToolbar); KConfigGroup cgToolbarIcon(ptr, "MainToolbarIcons"); m_hints[QPlatformTheme::ToolBarIconSize] = cgToolbarIcon.readEntry("Size", 22); m_hints[QPlatformTheme::ItemViewActivateItemOnSingleClick] = cg.readEntry("SingleClick", true); KConfigGroup cgIcons(ptr, "Icons"); m_hints[QPlatformTheme::SystemIconThemeName] = cgIcons.readEntry("Theme", "oxygen"); m_hints[QPlatformTheme::SystemIconFallbackThemeName] = "hicolor"; m_hints[QPlatformTheme::IconThemeSearchPaths] = xdgIconThemePaths(); m_hints[QPlatformTheme::StyleNames] = (QStringList() << cg.readEntry("widgetStyle", QString()) - << "oxygen" - << "fusion" - << "windows"); + << "oxygen" + << "fusion" + << "windows"); m_hints[QPlatformTheme::DialogButtonBoxLayout] = QDialogButtonBox::KdeLayout; m_hints[QPlatformTheme::DialogButtonBoxButtonsHaveIcons] = cg.readEntry("ShowIconsOnPushButtons", true); m_hints[QPlatformTheme::UseFullScreenForPopupMenu] = true; m_hints[QPlatformTheme::KeyboardScheme] = QPlatformTheme::KdeKeyboardScheme; m_hints[QPlatformTheme::UiEffects] = cg.readEntry("GraphicEffectsLevel", 0) != 0 ? QPlatformTheme::GeneralUiEffect : 0; m_hints[QPlatformTheme::IconPixmapSizes] = QVariant::fromValue(QList() << 512 << 256 << 128 << 64 << 32 << 22 << 16 << 8); //TODO Check if we can add themeHints for these two options - if (qobject_cast(QCoreApplication::instance())) { + if (qobject_cast(QCoreApplication::instance())) { QApplication::setWheelScrollLines(cg.readEntry("WheelScrollLines", QApplication::wheelScrollLines())); } bool showIcons = cg.readEntry("ShowIconsInMenuItems", !QApplication::testAttribute(Qt::AA_DontShowIconsInMenus)); QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus, !showIcons); QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "setupIconLoader", Qt::QueuedConnection); loadPalettes(); } KHintsSettings::~KHintsSettings() { qDeleteAll(m_palettes); } QStringList KHintsSettings::xdgIconThemePaths() const { QStringList paths; const QFileInfo homeIconDir(QDir::homePath() + QStringLiteral("/.icons")); - if (homeIconDir.isDir()) + if (homeIconDir.isDir()) { paths << homeIconDir.absoluteFilePath(); + } QString xdgDirString = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); - if (xdgDirString.isEmpty()) + if (xdgDirString.isEmpty()) { xdgDirString = QLatin1String("/usr/local/share/:/usr/share/"); + } foreach (const QString &xdgDir, xdgDirString.split(QLatin1Char(':'))) { const QFileInfo xdgIconsDir(xdgDir + QStringLiteral("/icons")); - if (xdgIconsDir.isDir()) + if (xdgIconsDir.isDir()) { paths << xdgIconsDir.absoluteFilePath(); + } } return paths; } void KHintsSettings::delayedDBusConnects() { QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"), - QStringLiteral("styleChanged"), this, SLOT(toolbarStyleChanged())); + QStringLiteral("styleChanged"), this, SLOT(toolbarStyleChanged())); QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), - QStringLiteral("notifyChange"), this, SLOT(slotNotifyChange(int, int))); + QStringLiteral("notifyChange"), this, SLOT(slotNotifyChange(int,int))); } void KHintsSettings::setupIconLoader() { connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &KHintsSettings::iconChanged); } void KHintsSettings::toolbarStyleChanged() { KSharedConfig::Ptr ptr = KSharedConfig::openConfig("kdeglobals"); ptr->reparseConfiguration(); KConfigGroup cg(ptr, "Toolbar style"); m_hints[QPlatformTheme::ToolButtonStyle] = toolButtonStyle(cg); //from gtksymbol.cpp QWidgetList widgets = QApplication::allWidgets(); for (int i = 0; i < widgets.size(); ++i) { QWidget *widget = widgets.at(i); - if (qobject_cast(widget)) { + if (qobject_cast(widget)) { QEvent event(QEvent::StyleChange); QApplication::sendEvent(widget, &event); } } } void KHintsSettings::slotNotifyChange(int type, int arg) { KSharedConfig::Ptr ptr = KSharedConfig::openConfig("kdeglobals"); ptr->reparseConfiguration(); KConfigGroup cg(ptr, "KDE"); - switch(type) { + switch (type) { case PaletteChanged: { loadPalettes(); QEvent ev(QEvent::ApplicationPaletteChange); QGuiApplication::sendEvent(QGuiApplication::instance(), &ev); } break; case SettingsChanged: { SettingsCategory category = static_cast(arg); if (category == SETTINGS_QT || category == SETTINGS_MOUSE) { updateQtSettings(cg); } else if (category == SETTINGS_STYLE) { m_hints[QPlatformTheme::DialogButtonBoxButtonsHaveIcons] = cg.readEntry("ShowIconsOnPushButtons", true); m_hints[QPlatformTheme::UiEffects] = cg.readEntry("GraphicEffectsLevel", 0) != 0 ? QPlatformTheme::GeneralUiEffect : 0; } break; } case ToolbarStyleChanged: { toolbarStyleChanged(); break; } case IconChanged: iconChanged(arg); //Once the KCM is ported to use IconChanged, this should not be needed break; case StyleChanged: { - QApplication *app = qobject_cast(QCoreApplication::instance()); + QApplication *app = qobject_cast(QCoreApplication::instance()); if (!app) { return; } const QString theme = cg.readEntry("widgetStyle", QString()); if (theme.isEmpty()) { return; } m_hints[QPlatformTheme::StyleNames] = (QStringList() << theme - << "oxygen" - << "fusion" - << "windows"); + << "oxygen" + << "fusion" + << "windows"); app->setStyle(theme); loadPalettes(); break; } default: qWarning() << "Unknown type of change in KGlobalSettings::slotNotifyChange: " << type; } } void KHintsSettings::iconChanged(int group) { KIconLoader::Group iconGroup = (KIconLoader::Group) group; if (iconGroup != KIconLoader::MainToolbar) { KSharedConfig::Ptr ptr = KSharedConfig::openConfig("kdeglobals"); KConfigGroup cgIcons(ptr, "Icons"); m_hints[QPlatformTheme::SystemIconThemeName] = cgIcons.readEntry("Theme", "oxygen"); return; } const int currentSize = KIconLoader::global()->currentSize(KIconLoader::MainToolbar); if (m_hints[QPlatformTheme::ToolBarIconSize] == currentSize) { return; } m_hints[QPlatformTheme::ToolBarIconSize] = currentSize; //If we are not a QApplication, means that we are a QGuiApplication, then we do nothing. - if (!qobject_cast(QCoreApplication::instance())) { + if (!qobject_cast(QCoreApplication::instance())) { return; } QWidgetList widgets = QApplication::allWidgets(); - Q_FOREACH(QWidget* widget, widgets) { - if (qobject_cast(widget) || qobject_cast(widget)) { + Q_FOREACH (QWidget *widget, widgets) { + if (qobject_cast(widget) || qobject_cast(widget)) { QEvent event(QEvent::StyleChange); QApplication::sendEvent(widget, &event); } } } void KHintsSettings::updateQtSettings(KConfigGroup &cg) { int flash = qBound(200, cg.readEntry("CursorBlinkRate", 1000), 2000); m_hints[QPlatformTheme::CursorFlashTime] = flash; int doubleClickInterval = cg.readEntry("DoubleClickInterval", 400); m_hints[QPlatformTheme::MouseDoubleClickInterval] = doubleClickInterval; int startDragDistance = cg.readEntry("StartDragDist", 10); m_hints[QPlatformTheme::StartDragDistance] = startDragDistance; int startDragTime = cg.readEntry("StartDragTime", 10); m_hints[QPlatformTheme::StartDragTime] = startDragTime; m_hints[QPlatformTheme::ItemViewActivateItemOnSingleClick] = cg.readEntry("SingleClick", true); bool showIcons = cg.readEntry("ShowIconsInMenuItems", !QApplication::testAttribute(Qt::AA_DontShowIconsInMenus)); QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus, !showIcons); - QApplication *app = qobject_cast(QCoreApplication::instance()); + QApplication *app = qobject_cast(QCoreApplication::instance()); if (app) { QApplication::setWheelScrollLines(cg.readEntry("WheelScrollLines", QApplication::wheelScrollLines())); } } -Qt::ToolButtonStyle KHintsSettings::toolButtonStyle(const KConfigGroup& cg) const +Qt::ToolButtonStyle KHintsSettings::toolButtonStyle(const KConfigGroup &cg) const { const QString buttonStyle = cg.readEntry("ToolButtonStyle", "TextBesideIcon").toLower(); return buttonStyle == "textbesideicon" ? Qt::ToolButtonTextBesideIcon - : buttonStyle == "icontextright" ? Qt::ToolButtonTextBesideIcon - : buttonStyle == "textundericon" ? Qt::ToolButtonTextUnderIcon - : buttonStyle == "icontextbottom" ? Qt::ToolButtonTextUnderIcon - : buttonStyle == "textonly" ? Qt::ToolButtonTextOnly - : Qt::ToolButtonIconOnly; + : buttonStyle == "icontextright" ? Qt::ToolButtonTextBesideIcon + : buttonStyle == "textundericon" ? Qt::ToolButtonTextUnderIcon + : buttonStyle == "icontextbottom" ? Qt::ToolButtonTextUnderIcon + : buttonStyle == "textonly" ? Qt::ToolButtonTextOnly + : Qt::ToolButtonIconOnly; } void KHintsSettings::loadPalettes() { qDeleteAll(m_palettes); m_palettes.clear(); KSharedConfig::Ptr globals = KSharedConfig::openConfig("kdeglobals"); m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(globals)); } diff --git a/src/platformtheme/khintssettings.h b/src/platformtheme/khintssettings.h index d7262ce..8f35383 100644 --- a/src/platformtheme/khintssettings.h +++ b/src/platformtheme/khintssettings.h @@ -1,83 +1,85 @@ /* This file is part of the KDE libraries * Copyright 2013 Alejandro Fiestas Olivares * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KHINTS_SETTINGS_H #define KHINTS_SETTINGS_H #include #include #include class KConfigGroup; class QPalette; class KHintsSettings : public QObject { Q_OBJECT - public: - /** - * An identifier for change signals. - * @note Copied from KGlobalSettings - */ - enum ChangeType { PaletteChanged = 0, FontChanged, StyleChanged, +public: + /** + * An identifier for change signals. + * @note Copied from KGlobalSettings + */ + enum ChangeType { PaletteChanged = 0, FontChanged, StyleChanged, SettingsChanged, IconChanged, CursorChanged, ToolbarStyleChanged, ClipboardConfigChanged, - BlockShortcuts, NaturalSortingChanged }; - /** - * Valid values for the settingsChanged signal - * @note Copied from KGlobalSettings - */ - enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS, + BlockShortcuts, NaturalSortingChanged + }; + /** + * Valid values for the settingsChanged signal + * @note Copied from KGlobalSettings + */ + enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS, SETTINGS_POPUPMENU, SETTINGS_QT, SETTINGS_SHORTCUTS, - SETTINGS_LOCALE, SETTINGS_STYLE }; - explicit KHintsSettings(); - virtual ~KHintsSettings(); + SETTINGS_LOCALE, SETTINGS_STYLE + }; + explicit KHintsSettings(); + virtual ~KHintsSettings(); - inline QVariant hint(QPlatformTheme::ThemeHint hint) - { - return m_hints[hint]; - } - inline QPalette* palette(QPlatformTheme::Palette type) - { - if (!m_palettes.contains(type)) { - return 0; - } - return m_palettes[type]; + inline QVariant hint(QPlatformTheme::ThemeHint hint) + { + return m_hints[hint]; + } + inline QPalette *palette(QPlatformTheme::Palette type) + { + if (!m_palettes.contains(type)) { + return 0; } + return m_palettes[type]; + } - private Q_SLOTS: - void delayedDBusConnects(); - void setupIconLoader(); - void toolbarStyleChanged(); - void slotNotifyChange(int type, int arg); +private Q_SLOTS: + void delayedDBusConnects(); + void setupIconLoader(); + void toolbarStyleChanged(); + void slotNotifyChange(int type, int arg); - private: - void loadPalettes(); - void iconChanged(int group); - void updateQtSettings(KConfigGroup &cg); - Qt::ToolButtonStyle toolButtonStyle(const KConfigGroup &cg) const; +private: + void loadPalettes(); + void iconChanged(int group); + void updateQtSettings(KConfigGroup &cg); + Qt::ToolButtonStyle toolButtonStyle(const KConfigGroup &cg) const; - QStringList xdgIconThemePaths() const; - QHash m_palettes; - QHash m_hints; + QStringList xdgIconThemePaths() const; + QHash m_palettes; + QHash m_hints; }; #endif //KHINTS_SETTINGS_H diff --git a/tests/qfiledialogtest.cpp b/tests/qfiledialogtest.cpp index 707244a..3ef79a2 100644 --- a/tests/qfiledialogtest.cpp +++ b/tests/qfiledialogtest.cpp @@ -1,52 +1,52 @@ /* This file is part of the KDE libraries * Copyright 2013 Aleix Pol Gonzalez * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include #include -int main(int argc, char** argv) +int main(int argc, char **argv) { QApplication app(argc, argv); QCommandLineParser parser; parser.addOption(QCommandLineOption(QStringList(QStringLiteral("mode")), QStringLiteral("File dialog mode: open or save"), QStringLiteral("type"), QStringLiteral("open"))); parser.addOption(QCommandLineOption(QStringList(QStringLiteral("filter")), QStringLiteral("Dialog filter"), QStringLiteral("filter"), QStringLiteral("Everything (*)"))); parser.addOption(QCommandLineOption(QStringList(QStringLiteral("modal")), QStringLiteral("Test modal dialog"), QStringLiteral("modality"), QStringLiteral("on"))); parser.process(app); QFileDialog dialog; dialog.setAcceptMode(parser.value(QStringLiteral("mode")) == QStringLiteral("open") ? QFileDialog::AcceptOpen : QFileDialog::AcceptSave); dialog.setNameFilter(parser.value(QStringLiteral("filter"))); int ret; if (parser.value(QStringLiteral("modal")) == QStringLiteral("off")) { dialog.show(); ret = app.exec(); } else { ret = dialog.exec(); } if (dialog.result() == QDialog::Accepted) { qDebug() << "selected files" << dialog.selectedFiles(); qDebug() << "selected urls" << dialog.selectedUrls(); qDebug() << "selected name filter" << dialog.selectedNameFilter(); } return ret; }