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
This commit is contained in:
parent
c74bc229ee
commit
cbdec6736a
9 changed files with 239 additions and 36 deletions
|
@ -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<int>("BorderSize", KDecorationDefines::BorderNormal));
|
||||
m_theme->setButtonSize((KDecorationDefines::BorderSize)themeGroup.readEntry<int>("ButtonSize", KDecorationDefines::BorderNormal));
|
||||
m_theme->setShowTooltips(options()->showTooltips());
|
||||
}
|
||||
|
||||
|
|
|
@ -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})
|
||||
|
|
122
kcmkwin/kwindecoration/auroraeconfig.ui
Normal file
122
kcmkwin/kwindecoration/auroraeconfig.ui
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>KWinAuroraeConfigForm</class>
|
||||
<widget class="QWidget" name="KWinAuroraeConfigForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Border size:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>borderSizesCombo</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="borderSizesCombo">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Tiny</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Normal</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Large</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Very Large</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Huge</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Very Huge</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Oversized</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Button size:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>buttonSizesCombo</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="buttonSizesCombo">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Tiny</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Normal</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Large</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Very Large</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Huge</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Very Huge</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Oversized</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -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()
|
||||
|
|
|
@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "decorationdelegate.h"
|
||||
#include "decorationmodel.h"
|
||||
#include "configdialog.h"
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QPainter>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QApplication>
|
||||
|
@ -30,6 +32,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
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<KDecorationDefines::BorderSize>( 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<KDecorationDefines::BorderSize>( 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()
|
||||
|
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*********************************************************************/
|
||||
#ifndef PREVIEWDELEGATE_H
|
||||
#define PREVIEWDELEGATE_H
|
||||
#include "ui_auroraeconfig.h"
|
||||
#include <KWidgetItemDelegate>
|
||||
|
||||
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
|
||||
|
|
|
@ -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<DecorationModelData>::iterator it = m_decorations.begin();
|
||||
|
||||
while( it != m_decorations.end() )
|
||||
{
|
||||
if( (*it).type == DecorationModelData::AuroraeDecoration )
|
||||
(*it).borderSize = size;
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue