From cbdec6736a637c0d1d36fb77f851392cb4322d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 21 Apr 2010 18:18:45 +0000 Subject: [PATCH] Adding a config dialog for Aurorae themes to change border and button size. This one does not use the normal plugin infrastructure, but is part of the kcm directly. The plugin would require to have one dialog for all aurorae themes and that just does not work. Aurorae saves settings per theme. svn path=/trunk/KDE/kdebase/workspace/; revision=1117280 --- clients/aurorae/src/aurorae.cpp | 4 +- kcmkwin/kwindecoration/CMakeLists.txt | 7 +- kcmkwin/kwindecoration/auroraeconfig.ui | 122 ++++++++++++++++++ kcmkwin/kwindecoration/configdialog.cpp | 4 - kcmkwin/kwindecoration/decorationdelegate.cpp | 64 +++++++-- kcmkwin/kwindecoration/decorationdelegate.h | 9 ++ kcmkwin/kwindecoration/decorationmodel.cpp | 57 ++++++-- kcmkwin/kwindecoration/decorationmodel.h | 7 +- kcmkwin/kwindecoration/kwindecoration.cpp | 1 - 9 files changed, 239 insertions(+), 36 deletions(-) create mode 100644 kcmkwin/kwindecoration/auroraeconfig.ui diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index e3a28c4ce7..d864f63bf9 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -44,8 +44,10 @@ void AuroraeFactory::init() const QString themeName = group.readEntry("ThemeName", "example-deco"); KConfig config("aurorae/themes/" + themeName + '/' + themeName + "rc", KConfig::FullConfig, "data"); + KConfigGroup themeGroup(&conf, themeName); m_theme->loadTheme(themeName, config); - m_theme->setBorderSize(KDecoration::options()->preferredBorderSize(this)); + m_theme->setBorderSize((KDecorationDefines::BorderSize)themeGroup.readEntry("BorderSize", KDecorationDefines::BorderNormal)); + m_theme->setButtonSize((KDecorationDefines::BorderSize)themeGroup.readEntry("ButtonSize", KDecorationDefines::BorderNormal)); m_theme->setShowTooltips(options()->showTooltips()); } diff --git a/kcmkwin/kwindecoration/CMakeLists.txt b/kcmkwin/kwindecoration/CMakeLists.txt index 2d8e4c311f..6a7c536a9f 100644 --- a/kcmkwin/kwindecoration/CMakeLists.txt +++ b/kcmkwin/kwindecoration/CMakeLists.txt @@ -20,7 +20,12 @@ set(kcm_kwindecoration_PART_SRCS ${AURORAE_SOURCE_DIR}/themeconfig.cpp ) -kde4_add_ui_files(kcm_kwindecoration_PART_SRCS buttons.ui config.ui decoration.ui) +kde4_add_ui_files(kcm_kwindecoration_PART_SRCS + auroraeconfig.ui + buttons.ui + config.ui + decoration.ui +) kde4_add_plugin(kcm_kwindecoration ${kcm_kwindecoration_PART_SRCS}) target_link_libraries(kcm_kwindecoration ${KDE4_PLASMA_LIBS} ${KDE4_KNEWSTUFF3_LIBS} kdecorations ${X11_LIBRARIES}) diff --git a/kcmkwin/kwindecoration/auroraeconfig.ui b/kcmkwin/kwindecoration/auroraeconfig.ui new file mode 100644 index 0000000000..6af0950447 --- /dev/null +++ b/kcmkwin/kwindecoration/auroraeconfig.ui @@ -0,0 +1,122 @@ + + + KWinAuroraeConfigForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + QFormLayout::ExpandingFieldsGrow + + + + + Border size: + + + borderSizesCombo + + + + + + + + Tiny + + + + + Normal + + + + + Large + + + + + Very Large + + + + + Huge + + + + + Very Huge + + + + + Oversized + + + + + + + + Button size: + + + buttonSizesCombo + + + + + + + + Tiny + + + + + Normal + + + + + Large + + + + + Very Large + + + + + Huge + + + + + Very Huge + + + + + Oversized + + + + + + + + + diff --git a/kcmkwin/kwindecoration/configdialog.cpp b/kcmkwin/kwindecoration/configdialog.cpp index bfffe31778..646d0b6b87 100644 --- a/kcmkwin/kwindecoration/configdialog.cpp +++ b/kcmkwin/kwindecoration/configdialog.cpp @@ -137,10 +137,6 @@ void KWinDecorationConfigDialog::slotAccepted() KConfigGroup config( m_kwinConfig, "Style" ); emit pluginSave( config ); config.sync(); - // Send signal to all kwin instances - QDBusMessage message = - QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); - QDBusConnection::sessionBus().send(message); } void KWinDecorationConfigDialog::slotSelectionChanged() diff --git a/kcmkwin/kwindecoration/decorationdelegate.cpp b/kcmkwin/kwindecoration/decorationdelegate.cpp index ba0a96d883..3ebabcb086 100644 --- a/kcmkwin/kwindecoration/decorationdelegate.cpp +++ b/kcmkwin/kwindecoration/decorationdelegate.cpp @@ -20,6 +20,8 @@ along with this program. If not, see . #include "decorationdelegate.h" #include "decorationmodel.h" #include "configdialog.h" +#include +#include #include #include #include @@ -30,6 +32,12 @@ along with this program. If not, see . namespace KWin { +KWinAuroraeConfigForm::KWinAuroraeConfigForm( QWidget* parent ) + : QWidget( parent ) + { + setupUi( this ); + } + const int margin = 5; DecorationDelegate::DecorationDelegate( QAbstractItemView* itemView, QObject* parent ) @@ -122,22 +130,52 @@ void DecorationDelegate::slotConfigure() if (!focusedIndex().isValid()) return; - const QModelIndex index = focusedIndex(); - QString name = focusedIndex().model()->data( index , DecorationModel::LibraryNameRole ).toString(); - QList< QVariant > borderSizes = focusedIndex().model()->data( index , DecorationModel::BorderSizesRole ).toList(); - const KDecorationDefines::BorderSize size = - static_cast( itemView()->model()->data( index, DecorationModel::BorderSizeRole ).toInt() ); - QPointer< KWinDecorationConfigDialog > configDialog = - new KWinDecorationConfigDialog( name, borderSizes, size, m_itemView ); - if( configDialog->exec() == KDialog::Accepted ) + const QModelIndex index = static_cast< QSortFilterProxyModel* >( m_itemView->model() )->mapFromSource( focusedIndex() ); + bool reload = false; + if( focusedIndex().model()->data( index , DecorationModel::TypeRole ).toInt() == + DecorationModelData::AuroraeDecoration ) { - DecorationModel* model = static_cast< DecorationModel* >( - static_cast< QSortFilterProxyModel* >( itemView()->model() )->sourceModel() ); - model->setBorderSize( index, configDialog->borderSize() ); - model->regeneratePreview( focusedIndex() ); + QPointer< KDialog > dlg = new KDialog( m_itemView ); + dlg->setCaption( i18n( "Decoration Options" ) ); + dlg->setButtons( KDialog::Ok | KDialog::Cancel ); + KWinAuroraeConfigForm *form = new KWinAuroraeConfigForm( dlg ); + dlg->setMainWidget( form ); + form->borderSizesCombo->setCurrentIndex( index.data( DecorationModel::BorderSizeRole ).toInt() ); + form->buttonSizesCombo->setCurrentIndex( index.data( DecorationModel::ButtonSizeRole ).toInt() ); + if( dlg->exec() == KDialog::Accepted ) + { + m_itemView->model()->setData( index, + form->borderSizesCombo->currentIndex(), + DecorationModel::BorderSizeRole ); + m_itemView->model()->setData( index, + form->buttonSizesCombo->currentIndex(), + DecorationModel::ButtonSizeRole ); + reload = true; + } + delete dlg; } + else + { + QString name = index.data( DecorationModel::LibraryNameRole ).toString(); + QList< QVariant > borderSizes = index.data( DecorationModel::BorderSizesRole ).toList(); + const KDecorationDefines::BorderSize size = + static_cast( index.data( DecorationModel::BorderSizeRole ).toInt() ); + QPointer< KWinDecorationConfigDialog > configDialog = + new KWinDecorationConfigDialog( name, borderSizes, size, m_itemView ); + if( configDialog->exec() == KDialog::Accepted ) + { + m_itemView->model()->setData( index, configDialog->borderSize(), DecorationModel::BorderSizeRole ); + reload = true; + } - delete configDialog; + delete configDialog; + } + if( reload ) + { + // Send signal to all kwin instances + QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); + QDBusConnection::sessionBus().send(message); + } } void DecorationDelegate::slotInfo() diff --git a/kcmkwin/kwindecoration/decorationdelegate.h b/kcmkwin/kwindecoration/decorationdelegate.h index 6c031883e2..013dde51b9 100644 --- a/kcmkwin/kwindecoration/decorationdelegate.h +++ b/kcmkwin/kwindecoration/decorationdelegate.h @@ -19,6 +19,7 @@ along with this program. If not, see . *********************************************************************/ #ifndef PREVIEWDELEGATE_H #define PREVIEWDELEGATE_H +#include "ui_auroraeconfig.h" #include class KPushButton; @@ -26,6 +27,14 @@ class KPushButton; namespace KWin { +class KWinAuroraeConfigForm : public QWidget, public Ui::KWinAuroraeConfigForm +{ + Q_OBJECT + + public: + explicit KWinAuroraeConfigForm( QWidget* parent ); +}; + class DecorationDelegate : public KWidgetItemDelegate { Q_OBJECT diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index 8875747942..c120c6bca6 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -49,6 +49,7 @@ DecorationModel::DecorationModel( KSharedConfigPtr config, QObject* parent ) , m_theme( new Aurorae::AuroraeTheme( this ) ) , m_scene( new Aurorae::AuroraeScene( m_theme, QString(), QString(), true, this ) ) { + m_config = KSharedConfig::openConfig( "auroraerc" ); m_scene->setIcon( KIcon( "xorg" ) ); findDecorations(); } @@ -134,7 +135,9 @@ void DecorationModel::findAuroraeThemes() data.libraryName = "kwin3_aurorae"; data.type = DecorationModelData::AuroraeDecoration; data.auroraeName = packageName; - data.borderSize = KDecorationDefines::BorderNormal; + KConfigGroup config( m_config, data.auroraeName ); + data.borderSize = (KDecorationDefines::BorderSize)config.readEntry< int >( "BorderSize", KDecorationDefines::BorderNormal ); + data.buttonSize = (KDecorationDefines::BorderSize)config.readEntry< int >( "ButtonSize", KDecorationDefines::BorderNormal ); metaData( data, df ); m_decorations.append(data); } @@ -199,11 +202,48 @@ QVariant DecorationModel::data( const QModelIndex& index, int role ) const } return sizes; } + case ButtonSizeRole: + if( m_decorations[ index.row() ].type == DecorationModelData::AuroraeDecoration ) + return static_cast< int >( m_decorations[ index.row() ].buttonSize ); + else + return QVariant(); default: return QVariant(); } } +bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, int role) + { + if( !index.isValid() || ( role != BorderSizeRole && role != ButtonSizeRole ) ) + return QAbstractItemModel::setData( index, value, role ); + + if( role == BorderSizeRole ) + { + m_decorations[ index.row() ].borderSize = (KDecorationDefines::BorderSize)value.toInt(); + if( m_decorations[ index.row() ].type == DecorationModelData::AuroraeDecoration ) + { + KConfigGroup config( m_config, m_decorations[ index.row() ].auroraeName ); + config.writeEntry( "BorderSize", value.toInt() ); + config.sync(); + } + emit dataChanged( index, index ); + regeneratePreview( index ); + return true; + } + if( role == ButtonSizeRole && m_decorations[ index.row() ].type == DecorationModelData::AuroraeDecoration ) + { + m_decorations[ index.row() ].buttonSize = (KDecorationDefines::BorderSize)value.toInt(); + KConfigGroup config( m_config, m_decorations[ index.row() ].auroraeName ); + config.writeEntry( "ButtonSize", value.toInt() ); + config.sync(); + emit dataChanged( index, index ); + regeneratePreview( index ); + return true; + } + return QAbstractItemModel::setData( index, value, role ); + } + + void DecorationModel::changeButtons( bool custom, const QString& left, const QString& right ) { bool regenerate = (custom != m_customButtons); @@ -258,6 +298,7 @@ void DecorationModel::regeneratePreview( const QModelIndex& index, const QSize& KConfig conf( "aurorae/themes/" + data.auroraeName + '/' + data.auroraeName + "rc", KConfig::FullConfig, "data" ); m_theme->loadTheme( data.auroraeName, conf ); m_theme->setBorderSize( data.borderSize ); + m_theme->setButtonSize( data.buttonSize ); int left, top, right, bottom; m_theme->borders( left, top, right, bottom, false ); int padLeft, padRight, padTop, padBottom; @@ -327,21 +368,9 @@ QModelIndex DecorationModel::indexOfAuroraeName( const QString& auroraeName ) co void DecorationModel::setBorderSize( const QModelIndex& index, KDecorationDefines::BorderSize size ) { - if( !index.isValid() ) + if( !index.isValid() || m_decorations[ index.row() ].type == DecorationModelData::AuroraeDecoration ) return; m_decorations[ index.row() ].borderSize = size; } -void DecorationModel::resetAuroraeBorderSizes( KDecorationDefines::BorderSize size ) - { - QList::iterator it = m_decorations.begin(); - - while( it != m_decorations.end() ) - { - if( (*it).type == DecorationModelData::AuroraeDecoration ) - (*it).borderSize = size; - ++it; - } - } - } // namespace KWin diff --git a/kcmkwin/kwindecoration/decorationmodel.h b/kcmkwin/kwindecoration/decorationmodel.h index dca83c0fb8..67ef511957 100644 --- a/kcmkwin/kwindecoration/decorationmodel.h +++ b/kcmkwin/kwindecoration/decorationmodel.h @@ -58,6 +58,7 @@ class DecorationModelData QString license; QString auroraeName; KDecorationDefines::BorderSize borderSize; + KDecorationDefines::BorderSize buttonSize; static bool less( const DecorationModelData& a, const DecorationModelData& b ) { return a.name < b.name; } @@ -81,13 +82,15 @@ class DecorationModel : public QAbstractListModel PackageVersionRole = Qt::UserRole + 9, PackageLicenseRole = Qt::UserRole + 10, BorderSizeRole = Qt::UserRole + 11, - BorderSizesRole = Qt::UserRole + 12 + BorderSizesRole = Qt::UserRole + 12, + ButtonSizeRole = Qt::UserRole + 13 }; DecorationModel( KSharedConfigPtr config, QObject* parent = 0 ); ~DecorationModel(); virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const; + virtual bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ); void reload(); @@ -103,7 +106,6 @@ class DecorationModel : public QAbstractListModel void setButtons( bool custom, const QString& left, const QString& right ); void setBorderSize( const QModelIndex& index, KDecorationDefines::BorderSize size ); - void resetAuroraeBorderSizes( KDecorationDefines::BorderSize size ); QModelIndex indexOfLibrary( const QString& libraryName ) const; QModelIndex indexOfName( const QString& decoName ) const; @@ -125,6 +127,7 @@ class DecorationModel : public QAbstractListModel QString m_rightButtons; Aurorae::AuroraeTheme* m_theme; Aurorae::AuroraeScene* m_scene; + KSharedConfigPtr m_config; }; } // namespace KWin diff --git a/kcmkwin/kwindecoration/kwindecoration.cpp b/kcmkwin/kwindecoration/kwindecoration.cpp index dff4ef3565..71de0187f0 100644 --- a/kcmkwin/kwindecoration/kwindecoration.cpp +++ b/kcmkwin/kwindecoration/kwindecoration.cpp @@ -143,7 +143,6 @@ void KWinDecorationModule::readConfig( const KConfigGroup & conf ) const QModelIndex index = m_proxyModel->mapFromSource( m_model->indexOfAuroraeName( themeName ) ); if( index.isValid() ) { - m_model->resetAuroraeBorderSizes( borderSize ); m_ui->decorationList->setCurrentIndex( index ); } }