From cc61aa262c8792f0efbd32f376893d4e85d1e387 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Wed, 10 Dec 2014 14:45:16 +0100 Subject: [PATCH] Added configuration widget Not (yet) loaded inside kwin decoration kcm --- windec/kdecoration2/CMakeLists.txt | 2 + windec/kdecoration2/breezedecoration.cpp | 8 + windec/kdecoration2/breezedecoration.h | 1 + windec/kdecoration2/breezesettingsdata.kcfg | 8 +- windec/kdecoration2/config/CMakeLists.txt | 24 +++ windec/kdecoration2/config/breezeconfig.cpp | 191 ++++++++++++++++++ windec/kdecoration2/config/breezeconfig.h | 129 ++++++++++++ .../config/breezeconfigwidget.cpp | 109 ++++++++++ .../kdecoration2/config/breezeconfigwidget.h | 100 +++++++++ windec/kdecoration2/config/config.json | 3 + .../config/ui/breezeconfigurationui.ui | 163 +++++++++++++++ 11 files changed, 735 insertions(+), 3 deletions(-) create mode 100644 windec/kdecoration2/config/CMakeLists.txt create mode 100644 windec/kdecoration2/config/breezeconfig.cpp create mode 100644 windec/kdecoration2/config/breezeconfig.h create mode 100644 windec/kdecoration2/config/breezeconfigwidget.cpp create mode 100644 windec/kdecoration2/config/breezeconfigwidget.h create mode 100644 windec/kdecoration2/config/config.json create mode 100644 windec/kdecoration2/config/ui/breezeconfigurationui.ui diff --git a/windec/kdecoration2/CMakeLists.txt b/windec/kdecoration2/CMakeLists.txt index 4068a31e..d3b363eb 100644 --- a/windec/kdecoration2/CMakeLists.txt +++ b/windec/kdecoration2/CMakeLists.txt @@ -25,3 +25,5 @@ target_link_libraries(breezedecoration ) install(TARGETS breezedecoration DESTINATION ${PLUGIN_INSTALL_DIR}/org.kde.kdecoration2) + +add_subdirectory(config) diff --git a/windec/kdecoration2/breezedecoration.cpp b/windec/kdecoration2/breezedecoration.cpp index 29a86f64..a7ce915c 100644 --- a/windec/kdecoration2/breezedecoration.cpp +++ b/windec/kdecoration2/breezedecoration.cpp @@ -80,6 +80,7 @@ namespace Breeze // a change in font might cause the borders to change connect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &Decoration::recalculateBorders); connect(s.data(), &KDecoration2::DecorationSettings::spacingChanged, this, &Decoration::recalculateBorders); + connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::reconfigure); connect(client().data(), &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::recalculateBorders); connect(client().data(), &KDecoration2::DecoratedClient::maximizedHorizontallyChanged, this, &Decoration::recalculateBorders); connect(client().data(), &KDecoration2::DecoratedClient::maximizedVerticallyChanged, this, &Decoration::recalculateBorders); @@ -156,6 +157,13 @@ namespace Breeze return borderSize(settings, false); } + //________________________________________________________________ + void Decoration::reconfigure() + { + m_internalSettings.read(); + recalculateBorders(); + } + //________________________________________________________________ void Decoration::recalculateBorders() { diff --git a/windec/kdecoration2/breezedecoration.h b/windec/kdecoration2/breezedecoration.h index e455c4d0..c3083716 100644 --- a/windec/kdecoration2/breezedecoration.h +++ b/windec/kdecoration2/breezedecoration.h @@ -72,6 +72,7 @@ namespace Breeze void init() override; private Q_SLOTS: + void reconfigure(); void recalculateBorders(); void updateButtonPositions(); void updateTitleBar(); diff --git a/windec/kdecoration2/breezesettingsdata.kcfg b/windec/kdecoration2/breezesettingsdata.kcfg index 86fceceb..9ba1b0b5 100644 --- a/windec/kdecoration2/breezesettingsdata.kcfg +++ b/windec/kdecoration2/breezesettingsdata.kcfg @@ -27,9 +27,11 @@ - - false - + diff --git a/windec/kdecoration2/config/CMakeLists.txt b/windec/kdecoration2/config/CMakeLists.txt new file mode 100644 index 00000000..acaca278 --- /dev/null +++ b/windec/kdecoration2/config/CMakeLists.txt @@ -0,0 +1,24 @@ +add_definitions(-DTRANSLATION_DOMAIN=\"breeze_decoration_config\") + +find_package(Qt5 CONFIG REQUIRED COMPONENTS DBus ) + +set(breezedecoration_config_PART_SRCS + breezeconfig.cpp + breezeconfigwidget.cpp + ) + +set(breezedecoration_config_PART_FORMS + ui/breezeconfigurationui.ui +) + +kconfig_add_kcfg_files(breezedecoration_config_PART_SRCS ../breezesettings.kcfgc) + +ki18n_wrap_ui(breezedecoration_config_PART_FORMS_HEADERS ${breezedecoration_config_PART_FORMS}) +add_library(breezedecoration_config MODULE + ${breezedecoration_config_PART_SRCS} + ${breezedecoration_config_PART_FORMS_HEADERS}) + +target_link_libraries(breezedecoration_config Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus) +target_link_libraries(breezedecoration_config KF5::I18n KF5::ConfigCore KF5::ConfigWidgets) + +install(TARGETS breezedecoration_config DESTINATION ${PLUGIN_INSTALL_DIR}/org.kde.kdecoration2) diff --git a/windec/kdecoration2/config/breezeconfig.cpp b/windec/kdecoration2/config/breezeconfig.cpp new file mode 100644 index 00000000..ec5a953d --- /dev/null +++ b/windec/kdecoration2/config/breezeconfig.cpp @@ -0,0 +1,191 @@ +////////////////////////////////////////////////////////////////////////////// +// config.cpp +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// Copyright (C) 2008 Lubos Lunak +// +// Based on the Quartz configuration module, +// Copyright (c) 2001 Karol Szwed +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezeconfig.h" +#include "../breezesettings.h" + +#include +#include +#include + +#include +#include + +//_______________________________________________________________________ +//* plugin definition +/** + * this is the old style/KDE4 plugin declaration. + * it is used in breeze-settings + */ +extern "C" +{ + Q_DECL_EXPORT QObject* allocate_config( KConfig*, QWidget* parent ) + { return ( new Breeze::Config( parent ) ); } +} + +/** this is the new style/KF5 plugin declaration, used internally by KWin */ +K_PLUGIN_FACTORY_WITH_JSON( + BreezeConfigPlugin, + "config.json", + registerPlugin(QStringLiteral("kcmodule")); +) +#include "breezeconfig.moc" + +namespace Breeze +{ + + // create new configuration + QObject *Config::create(QWidget *parentWidget, QObject *, const QList &) + { return new Config(parentWidget); } + + //_______________________________________________________________________ + Config::Config(QWidget* parent ): + QObject( parent ) + { + + // configuration + m_configuration = KSharedConfig::openConfig( QStringLiteral( "breezerc" ) ); + + // create new configuration widget and add to layout, if any + m_configWidget = new ConfigWidget( parent ); + if( parent && parent->layout() ) parent->layout()->addWidget( m_configWidget ); + else m_configWidget->show(); + + load(); + connect( m_configWidget, SIGNAL(changed(bool)), SLOT(updateChanged()) ); + } + + //_______________________________________________________________________ + Config::~Config() + { delete m_configWidget; } + + //_______________________________________________________________________ + void Config::load( void ) + { + + // load standard configuration + InternalSettingsPtr internalSettings( new InternalSettings() ); + + internalSettings->load(); + loadInternalSettings( internalSettings ); + + updateChanged(); + + } + + //_______________________________________________________________________ + void Config::updateChanged( void ) + { + + bool modified( false ); + + // exceptions + if( m_configWidget->isChanged() ) modified = true; + + // emit relevant signals + if( modified ) emit changed(); + emit changed( modified ); + + } + + //_______________________________________________________________________ + void Config::save( void ) + { + + // create configuration from group + InternalSettingsPtr internalSettings( new InternalSettings() ); + internalSettings->load(); + + // save config widget + m_configWidget->setInternalSettings( internalSettings ); + m_configWidget->save(); + + // save configuration + internalSettings->save(); + + // sync configuration + m_configuration->sync(); + + QDBusMessage message( QDBusMessage::createSignal( QStringLiteral( "/BreezeWindeco" ), QStringLiteral( "org.kde.Breeze.Style" ), QStringLiteral( "reparseConfiguration") ) ); + QDBusConnection::sessionBus().send(message); + + } + + //_______________________________________________________________________ + void Config::defaults( void ) + { + + // install default configuration + InternalSettingsPtr internalSettings( new InternalSettings() ); + internalSettings->setDefaults(); + loadInternalSettings( internalSettings ); + + updateChanged(); + + } + + //_______________________________________________________________________ + void Config::loadInternalSettings( InternalSettingsPtr configuration ) + { + + m_configWidget->setInternalSettings( configuration ); + m_configWidget->load(); + + } + + //_______________________________________________________________________ + ConfigurationModule::ConfigurationModule(QWidget *parent, const QVariantList &args): + KCModule(parent, args) + { + setLayout(new QVBoxLayout(this)); + m_config = new Config( this ); + } + + //_______________________________________________________________________ + void ConfigurationModule::defaults() + { + m_config->defaults(); + KCModule::defaults(); + } + + //_______________________________________________________________________ + void ConfigurationModule::load() + { + m_config->load(); + KCModule::load(); + } + + //_______________________________________________________________________ + void ConfigurationModule::save() + { + m_config->save(); + KCModule::save(); + } + +} diff --git a/windec/kdecoration2/config/breezeconfig.h b/windec/kdecoration2/config/breezeconfig.h new file mode 100644 index 00000000..5827225f --- /dev/null +++ b/windec/kdecoration2/config/breezeconfig.h @@ -0,0 +1,129 @@ +#ifndef breeze_config_h +#define breeze_config_h + +////////////////////////////////////////////////////////////////////////////// +// config.h +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// Copyright (C) 2008 Lubos Lunak +// +// Based on the Quartz configuration module, +// Copyright (c) 2001 Karol Szwed +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezeconfigwidget.h" + +#include +#include + +namespace Breeze { + + class Configuration; + + // breeze configuration object + class Config: public QObject + { + + Q_OBJECT + + public: + + //* constructor + Config( QWidget* parent ); + + //* destructor + ~Config(); + + static QObject *create(QWidget *parentWidget, QObject *parent, const QList &arguments); + + Q_SIGNALS: + + //* emmited whenever configuration is changed + void changed(); + + //* emmited whenever configuration is changed + void changed( bool ); + + public Q_SLOTS: + + //* load configuration + /** although kconfiggroup argument is not used. It is required by KWin API */ + void load( const KConfigGroup& ) + { load(); } + + //* save configuration + /** although kconfiggroup argument is not used. It is required by KWin API */ + void save( KConfigGroup& ) + { save(); } + + //* load configuration + void load( void ); + + //* save configuration + void save( void ); + + //* restore defaults + void defaults( void ); + + private Q_SLOTS: + + //* update change state + void updateChanged( void ); + + private: + + //* load configuration + void loadInternalSettings( InternalSettingsPtr ); + + //* user interface + ConfigWidget* m_configWidget; + + //* kconfiguration object + KSharedConfig::Ptr m_configuration; + + }; + + //* configuration module + class ConfigurationModule: public KCModule + { + + Q_OBJECT + + public: + ConfigurationModule(QWidget *parent, const QVariantList &args); + + public Q_SLOTS: + + void defaults() override; + void load() override; + void save() override; + + private: + + //* configuration + Config* m_config; + + }; + +} //namespace Breeze + +#endif diff --git a/windec/kdecoration2/config/breezeconfigwidget.cpp b/windec/kdecoration2/config/breezeconfigwidget.cpp new file mode 100644 index 00000000..2b960f66 --- /dev/null +++ b/windec/kdecoration2/config/breezeconfigwidget.cpp @@ -0,0 +1,109 @@ +////////////////////////////////////////////////////////////////////////////// +// breezeconfigurationui.cpp +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "breezeconfigwidget.h" + +#include +#include +#include +#include + +#include + +namespace Breeze +{ + + //_________________________________________________________ + ConfigWidget::ConfigWidget( QWidget* parent ): + QWidget( parent ), + m_changed( false ) + { + + m_ui.setupUi( this ); + + // track ui changes + connect( m_ui.titleAlignment, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) ); + connect( m_ui.buttonSize, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) ); + + // track animations changes + connect( m_ui.animationsEnabled, SIGNAL(clicked()), SLOT(updateChanged()) ); + connect( m_ui.animationsDuration, SIGNAL(valueChanged(int)), SLOT(updateChanged()) ); + + } + + //_________________________________________________________ + void ConfigWidget::setInternalSettings( InternalSettingsPtr internalSettings ) + { m_internalSettings = internalSettings; } + + //_________________________________________________________ + void ConfigWidget::load( void ) + { + if( !m_internalSettings ) return; + m_ui.titleAlignment->setCurrentIndex( m_internalSettings->titleAlignment() ); + m_ui.buttonSize->setCurrentIndex( m_internalSettings->buttonSize() ); + m_ui.animationsEnabled->setChecked( m_internalSettings->animationsEnabled() ); + m_ui.animationsDuration->setValue( m_internalSettings->animationsDuration() ); + setChanged( false ); + + } + + //_________________________________________________________ + void ConfigWidget::save( void ) + { + + if( !m_internalSettings ) return; + + // apply modifications from ui + m_internalSettings->setTitleAlignment( m_ui.titleAlignment->currentIndex() ); + m_internalSettings->setButtonSize( m_ui.buttonSize->currentIndex() ); + m_internalSettings->setAnimationsEnabled( m_ui.animationsEnabled->isChecked() ); + m_internalSettings->setAnimationsDuration( m_ui.animationsDuration->value() ); + setChanged( false ); + + + + } + + //_______________________________________________ + void ConfigWidget::updateChanged( void ) + { + + // check configuration + if( !m_internalSettings ) return; + + // track modifications + bool modified( false ); + + if( m_ui.titleAlignment->currentIndex() != m_internalSettings->titleAlignment() ) modified = true; + else if( m_ui.buttonSize->currentIndex() != m_internalSettings->buttonSize() ) modified = true; + + // animations + else if( m_ui.animationsEnabled->isChecked() != m_internalSettings->animationsEnabled() ) modified = true; + else if( m_ui.animationsDuration->value() != m_internalSettings->animationsDuration() ) modified = true; + + setChanged( modified ); + + } +} diff --git a/windec/kdecoration2/config/breezeconfigwidget.h b/windec/kdecoration2/config/breezeconfigwidget.h new file mode 100644 index 00000000..b91d48ba --- /dev/null +++ b/windec/kdecoration2/config/breezeconfigwidget.h @@ -0,0 +1,100 @@ +#ifndef breezeconfigwidget_h +#define breezeconfigwidget_h +////////////////////////////////////////////////////////////////////////////// +// breezeconfigurationui.h +// ------------------- +// +// Copyright (c) 2009 Hugo Pereira Da Costa +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +////////////////////////////////////////////////////////////////////////////// + +#include "ui_breezeconfigurationui.h" +#include "../breezesettings.h" + +#include +#include + +namespace Breeze +{ + typedef QSharedPointer InternalSettingsPtr; + + //_____________________________________________ + class ConfigWidget: public QWidget + { + + Q_OBJECT + + public: + + //* constructor + explicit ConfigWidget( QWidget* ); + + //* destructor + virtual ~ConfigWidget( void ) + {} + + //* set configuration + void setInternalSettings( InternalSettingsPtr ); + + //* load configuration + void load( void ); + + //* save configuration + void save( void ); + + //* true if changed + virtual bool isChanged( void ) const + { return m_changed; } + + Q_SIGNALS: + + //* emmited when changed + void changed( bool ); + + protected Q_SLOTS: + + //* update changed state + virtual void updateChanged(); + + protected: + + //* set changed state + virtual void setChanged( bool value ) + { + m_changed = value; + emit changed( value ); + } + + private: + + //* ui + Ui_BreezeConfigurationUI m_ui; + + //* internal exception + InternalSettingsPtr m_internalSettings; + + //* changed state + bool m_changed; + + }; + +} + +#endif diff --git a/windec/kdecoration2/config/config.json b/windec/kdecoration2/config/config.json new file mode 100644 index 00000000..42c36eb3 --- /dev/null +++ b/windec/kdecoration2/config/config.json @@ -0,0 +1,3 @@ +{ + "X-KDE-PluginInfo-Name": "org.kde.breeze" +} diff --git a/windec/kdecoration2/config/ui/breezeconfigurationui.ui b/windec/kdecoration2/config/ui/breezeconfigurationui.ui new file mode 100644 index 00000000..6193814f --- /dev/null +++ b/windec/kdecoration2/config/ui/breezeconfigurationui.ui @@ -0,0 +1,163 @@ + + + BreezeConfigurationUI + + + + 0 + 0 + 433 + 156 + + + + Form + + + + + + + Very Small + + + + + Small + + + + + Normal + + + + + Large + + + + + Very Large + + + + + + + + Enable animations + + + + + + + + Left + + + + + Center + + + + + Center (Full Width) + + + + + Right + + + + + + + + ms + + + 500 + + + + + + + Tit&le alignment: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + titleAlignment + + + + + + + &Animations duration: + + + animationsDuration + + + + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 187 + 20 + + + + + + + + B&utton size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + buttonSize + + + + + + + Qt::Vertical + + + + 418 + 4 + + + + + + + + +