Index: kstyle/demo/CMakeLists.txt =================================================================== --- kstyle/demo/CMakeLists.txt +++ kstyle/demo/CMakeLists.txt @@ -46,6 +46,12 @@ else() + find_package(KF5ConfigWidgets CONFIG) + if(KF5ConfigWidgets_FOUND) + set(oxygen_demo_SOURCES ${oxygen_demo_SOURCES} oxygenschemechooser.cpp) + add_definitions(-DHAVE_SCHEME_CHOOSER) + endif() + ki18n_wrap_ui(oxygen_demo_FORMS_HEADERS ${oxygen_demo_FORMS}) add_executable(oxygen-demo5 @@ -55,6 +61,9 @@ target_link_libraries(oxygen-demo5 Qt5::Core Qt5::Gui Qt5::Widgets) target_link_libraries(oxygen-demo5 KF5::Completion KF5::ConfigGui KF5::WidgetsAddons KF5::I18n) + if(KF5ConfigWidgets_FOUND) + target_link_libraries(oxygen-demo5 KF5::ConfigWidgets) + endif() ########### install files ############### install(TARGETS oxygen-demo5 ${INSTALL_TARGETS_DEFAULT_ARGS}) Index: kstyle/demo/oxygendemodialog.h =================================================================== --- kstyle/demo/oxygendemodialog.h +++ kstyle/demo/oxygendemodialog.h @@ -75,6 +75,7 @@ //! toggle RightToLeft virtual void toggleRightToLeft( bool ); + virtual void layoutDirectionChanged( Qt::LayoutDirection ); protected: Index: kstyle/demo/oxygendemodialog.cpp =================================================================== --- kstyle/demo/oxygendemodialog.cpp +++ kstyle/demo/oxygendemodialog.cpp @@ -34,6 +34,9 @@ #include "oxygensliderdemowidget.h" #include "oxygentabdemowidget.h" #include "config-liboxygen.h" +#ifdef HAVE_SCHEME_CHOOSER +#include "oxygenschemechooser.h" +#endif #include #include @@ -75,9 +78,17 @@ buttonBox->addButton( _enableCheckBox, QDialogButtonBox::ResetRole ); _rightToLeftCheckBox = new QCheckBox( i18n( "Right to left layout" ) ); + _rightToLeftCheckBox->setChecked( qApp->isRightToLeft() ); connect( _rightToLeftCheckBox, SIGNAL(toggled(bool)), SLOT(toggleRightToLeft(bool)) ); + connect( qApp, SIGNAL(layoutDirectionChanged(Qt::LayoutDirection)), SLOT(layoutDirectionChanged(Qt::LayoutDirection)) ); buttonBox->addButton( _rightToLeftCheckBox, QDialogButtonBox::ResetRole ); +#ifdef HAVE_SCHEME_CHOOSER + ColorSchemeChooser *colChooser = new ColorSchemeChooser(this); + colChooser->setFlat(true); + buttonBox->addButton( colChooser, QDialogButtonBox::ResetRole ); +#endif + // connections connect( pageWidget, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(updateWindowTitle(KPageWidgetItem*)) ); connect( pageWidget, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(updateEnableState(KPageWidgetItem*)) ); @@ -218,6 +229,10 @@ { qApp->setLayoutDirection( value ? Qt::RightToLeft:Qt::LeftToRight ); } //_______________________________________________________________ + void DemoDialog::layoutDirectionChanged( Qt::LayoutDirection direction ) + { _rightToLeftCheckBox->setChecked( direction == Qt::RightToLeft ); } + + //_______________________________________________________________ void DemoDialog::closeEvent( QCloseEvent* event ) { emit abortSimulations(); Index: kstyle/demo/oxygenmdidemowidget.h =================================================================== --- kstyle/demo/oxygenmdidemowidget.h +++ kstyle/demo/oxygenmdidemowidget.h @@ -54,12 +54,15 @@ void setLayoutTiled( void ); void setLayoutCascade( void ); void setLayoutTabbed( void ); + void toggleDirection( void ); + void layoutDirectionChanged( Qt::LayoutDirection ); void benchmark( void ); private: Ui_MdiDemoWidget ui; + QAction *_rightToLeftLayout; }; Index: kstyle/demo/oxygenmdidemowidget.cpp =================================================================== --- kstyle/demo/oxygenmdidemowidget.cpp +++ kstyle/demo/oxygenmdidemowidget.cpp @@ -40,19 +40,36 @@ { setLayout( new QVBoxLayout() ); QMenuBar* menuBar = new QMenuBar( this ); + // let the menubar appear in the MDI window on all platforms + menuBar->setNativeMenuBar( false ); layout()->addWidget( menuBar ); QWidget* widget = new QWidget( this ); layout()->addWidget( widget ); ui.setupUi( widget ); QMenu* menu = menuBar->addMenu( i18n( "Layout" ) ); - connect( menu->addAction( i18n( "Tile" ) ), SIGNAL(triggered()), this, SLOT(setLayoutTiled()) ); - connect( menu->addAction( i18n( "Cascade" ) ), SIGNAL(triggered()), this, SLOT(setLayoutCascade()) ); - connect( menu->addAction( i18n( "Tabs" ) ), SIGNAL(triggered()), this, SLOT(setLayoutTabbed()) ); + QActionGroup *aGroup = new QActionGroup( menu ); + menu->addSection( i18n( "Exclusive actions" ) ); + QAction *action = menu->addAction( i18n( "Tile" ) ); + action->setCheckable( true ); + aGroup->addAction( action ); + connect( action, SIGNAL(triggered()), this, SLOT(setLayoutTiled()) ); + action = menu->addAction( i18n( "Cascade" ) ); + action->setCheckable( true ); + aGroup->addAction( action ); + connect( action, SIGNAL(triggered()), this, SLOT(setLayoutCascade()) ); + action = menu->addAction( i18n( "Tabs" ) ); + action->setCheckable( true ); + aGroup->addAction( action ); + connect( action, SIGNAL(triggered()), this, SLOT(setLayoutTabbed()) ); + + menu->addSeparator(); + + action = menu->addAction( i18n( "<- Check here" ) ); + action->setCheckable( true ); menu = menuBar->addMenu( i18n( "Tools" ) ); - QAction* action; connect( action = menu->addAction( QIcon::fromTheme( QStringLiteral( "arrow-right" ) ), i18n( "Select Next Window" ) ), SIGNAL(triggered()), ui.mdiArea, SLOT(activateNextSubWindow()) ); action->setShortcut( Qt::CTRL + Qt::Key_Tab ); addAction( action ); Index: kstyle/demo/oxygenschemechooser.h =================================================================== --- /dev/null +++ kstyle/demo/oxygenschemechooser.h @@ -0,0 +1,51 @@ +/************************************************************************************* + * This file was part of KDevPlatform and now of Oxygen * + * Copyright 2016 Zhigalin Alexander * + * * + * 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.1 of the License, or (at your option) version 3, or any * + * later version accepted by the membership of KDE e.V. (or its * + * successor approved by the membership of KDE e.V.), which shall * + * act as a proxy defined in Section 6 of version 3 of the license. * + * * + * 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library. If not, see . * + *************************************************************************************/ + +#ifndef COLORSCHEMECHOOSER_H +#define COLORSCHEMECHOOSER_H + +#include +#include +#include +#include + +namespace Oxygen +{ +/** + * Provides a menu that will offer to change the color scheme + * + * Furthermore, it will save the selection in the user configuration. + */ +class ColorSchemeChooser : public QPushButton +{ + Q_OBJECT + public: + explicit ColorSchemeChooser(QWidget* parent); + + QString currentSchemeName() const; + + private: + QString currentDesktopDefaultScheme() const; +}; + +} // namespace Oxygen + +#endif // COLORSCHEMECHOOSER_H Index: kstyle/demo/oxygenschemechooser.cpp =================================================================== --- /dev/null +++ kstyle/demo/oxygenschemechooser.cpp @@ -0,0 +1,75 @@ +/************************************************************************************* + * This file was part of KDevPlatform and now of Oxygen * + * Copyright 2016 Zhigalin Alexander * + * Copyright 2017 René J.V. Bertin * + * * + * 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.1 of the License, or (at your option) version 3, or any * + * later version accepted by the membership of KDE e.V. (or its * + * successor approved by the membership of KDE e.V.), which shall * + * act as a proxy defined in Section 6 of version 3 of the license. * + * * + * 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library. If not, see . * + *************************************************************************************/ + +#include "oxygenschemechooser.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace Oxygen +{ + +ColorSchemeChooser::ColorSchemeChooser(QWidget* parent) + : QPushButton(parent) +{ + auto manager = new KColorSchemeManager(parent); + + const auto scheme(currentSchemeName()); + + auto selectionMenu = manager->createSchemeSelectionMenu(scheme, this); + + manager->activateScheme(manager->indexForScheme(scheme)); + + setMenu(selectionMenu->menu()); + menu()->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-color"))); + menu()->setTitle(i18n("&Color Theme")); + setIcon(menu()->icon()); + setText(menu()->title()); +} + +QString ColorSchemeChooser::currentDesktopDefaultScheme() const +{ + KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("kdeglobals")); + KConfigGroup group(config, "General"); + return group.readEntry("ColorScheme", QStringLiteral("Breeze")); +} + +QString ColorSchemeChooser::currentSchemeName() const +{ + if(!menu()) return currentDesktopDefaultScheme(); + + QAction* const action = menu()->activeAction(); + + if(action) return KLocalizedString::removeAcceleratorMarker(action->text()); + return currentDesktopDefaultScheme(); +} + +} // namespace Oxygen