1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #include "cylinder_config.h"
21 #include <kwineffects.h>
23 #include <kconfiggroup.h>
24 #include <kcolorscheme.h>
25 #include <KActionCollection>
27 #include <KFileDialog>
28 #include <KImageFilePreview>
30 #include <QVBoxLayout>
33 KWIN_EFFECT_CONFIG_FACTORY
39 CylinderEffectConfigForm::CylinderEffectConfigForm(QWidget
* parent
) : QWidget(parent
)
44 CylinderEffectConfig::CylinderEffectConfig(QWidget
* parent
, const QVariantList
& args
) :
45 KCModule(EffectFactory::componentData(), parent
, args
)
47 m_ui
= new CylinderEffectConfigForm(this);
49 QVBoxLayout
* layout
= new QVBoxLayout(this);
51 layout
->addWidget(m_ui
, 0, 0);
53 m_ui
->tabWidget
->setTabText( 0, i18nc("@title:tab Basic Settings", "Basic") );
54 m_ui
->tabWidget
->setTabText( 1, i18nc("@title:tab Advanced Settings", "Advanced") );
56 m_actionCollection
= new KActionCollection( this, componentData() );
57 m_actionCollection
->setConfigGroup( "Cube" );
58 m_actionCollection
->setConfigGlobal(true);
60 KAction
* a
= (KAction
*) m_actionCollection
->addAction( "Cube" );
61 a
->setText( i18n("Desktop Cube" ));
62 a
->setProperty("isConfigurationAction", true);
63 a
->setGlobalShortcut( KShortcut( Qt::CTRL
+ Qt::Key_F11
));
65 m_ui
->editor
->addCollection(m_actionCollection
);
67 connect(m_ui
->rotationDurationSpin
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
68 connect(m_ui
->cubeOpacitySlider
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
69 connect(m_ui
->cubeOpacitySpin
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
70 connect(m_ui
->displayDesktopNameBox
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
71 connect(m_ui
->reflectionBox
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
72 connect(m_ui
->backgroundColorButton
, SIGNAL(changed(QColor
)), this, SLOT(changed()));
73 connect(m_ui
->cubeCapsBox
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
74 connect(m_ui
->cubeCapsBox
, SIGNAL(stateChanged(int)), this, SLOT(capsSelectionChanged()));
75 connect(m_ui
->capsImageBox
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
76 connect(m_ui
->capColorButton
, SIGNAL(changed(QColor
)), this, SLOT(changed()));
77 connect(m_ui
->wallpaperRequester
, SIGNAL(textChanged(QString
)), this, SLOT(changed()));
78 connect(m_ui
->closeOnMouseReleaseBox
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
79 connect(m_ui
->zPositionSlider
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
80 connect(m_ui
->walkThroughDesktopBox
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
85 void CylinderEffectConfig::load()
89 KConfigGroup conf
= EffectsHandler::effectConfig( "Cylinder" );
91 int duration
= conf
.readEntry( "RotationDuration", 0 );
92 float opacity
= conf
.readEntry( "Opacity", 80 );
93 bool desktopName
= conf
.readEntry( "DisplayDesktopName", true );
94 bool reflection
= conf
.readEntry( "Reflection", true );
95 QColor background
= conf
.readEntry( "BackgroundColor", QColor( Qt::black
) );
96 QColor capColor
= conf
.readEntry( "CapColor", KColorScheme( QPalette::Active
, KColorScheme::Window
).background().color() );
97 bool texturedCaps
= conf
.readEntry( "TexturedCaps", true );
98 bool caps
= conf
.readEntry( "Caps", true );
99 bool closeOnMouseRelease
= conf
.readEntry( "CloseOnMouseRelease", false );
100 bool walkThroughDesktop
= conf
.readEntry( "TabBox", false );
101 m_ui
->zPositionSlider
->setValue( conf
.readEntry( "ZPosition", 100 ) );
102 m_ui
->wallpaperRequester
->setPath( conf
.readEntry( "Wallpaper", "" ) );
104 m_ui
->rotationDurationSpin
->setValue( duration
);
105 m_ui
->cubeOpacitySlider
->setValue( opacity
);
106 m_ui
->cubeOpacitySpin
->setValue( opacity
);
109 m_ui
->displayDesktopNameBox
->setCheckState( Qt::Checked
);
113 m_ui
->displayDesktopNameBox
->setCheckState( Qt::Unchecked
);
117 m_ui
->reflectionBox
->setCheckState( Qt::Checked
);
121 m_ui
->reflectionBox
->setCheckState( Qt::Unchecked
);
125 m_ui
->cubeCapsBox
->setCheckState( Qt::Checked
);
129 m_ui
->cubeCapsBox
->setCheckState( Qt::Unchecked
);
133 m_ui
->capsImageBox
->setCheckState( Qt::Checked
);
137 m_ui
->capsImageBox
->setCheckState( Qt::Unchecked
);
139 if( closeOnMouseRelease
)
141 m_ui
->closeOnMouseReleaseBox
->setCheckState( Qt::Checked
);
145 m_ui
->closeOnMouseReleaseBox
->setCheckState( Qt::Unchecked
);
147 if( walkThroughDesktop
)
149 m_ui
->walkThroughDesktopBox
->setCheckState( Qt::Checked
);
153 m_ui
->walkThroughDesktopBox
->setCheckState( Qt::Unchecked
);
155 m_ui
->backgroundColorButton
->setColor( background
);
156 m_ui
->capColorButton
->setColor( capColor
);
157 capsSelectionChanged();
162 void CylinderEffectConfig::save()
164 KConfigGroup conf
= EffectsHandler::effectConfig( "Cylinder" );
166 conf
.writeEntry( "RotationDuration", m_ui
->rotationDurationSpin
->value() );
167 conf
.writeEntry( "DisplayDesktopName", m_ui
->displayDesktopNameBox
->checkState() == Qt::Checked
? true : false );
168 conf
.writeEntry( "Reflection", m_ui
->reflectionBox
->checkState() == Qt::Checked
? true : false );
169 conf
.writeEntry( "Opacity", m_ui
->cubeOpacitySpin
->value() );
170 conf
.writeEntry( "BackgroundColor", m_ui
->backgroundColorButton
->color() );
171 conf
.writeEntry( "Caps", m_ui
->cubeCapsBox
->checkState() == Qt::Checked
? true : false );
172 conf
.writeEntry( "CapColor", m_ui
->capColorButton
->color() );
173 conf
.writeEntry( "TexturedCaps", m_ui
->capsImageBox
->checkState() == Qt::Checked
? true : false );
174 conf
.writeEntry( "CloseOnMouseRelease", m_ui
->closeOnMouseReleaseBox
->checkState() == Qt::Checked
? true : false );
175 conf
.writeEntry( "Wallpaper", m_ui
->wallpaperRequester
->url().path() );
176 conf
.writeEntry( "ZPosition", m_ui
->zPositionSlider
->value() );
177 conf
.writeEntry( "TabBox", m_ui
->walkThroughDesktopBox
->checkState() == Qt::Checked
? true : false );
179 m_ui
->editor
->save();
184 EffectsHandler::sendReloadMessage( "cylinder" );
187 void CylinderEffectConfig::defaults()
189 m_ui
->rotationDurationSpin
->setValue( 0 );
190 m_ui
->displayDesktopNameBox
->setCheckState( Qt::Checked
);
191 m_ui
->reflectionBox
->setCheckState( Qt::Checked
);
192 m_ui
->cubeOpacitySpin
->setValue( 80 );
193 m_ui
->cubeOpacitySlider
->setValue( 80 );
194 m_ui
->backgroundColorButton
->setColor( QColor( Qt::black
) );
195 m_ui
->cubeCapsBox
->setCheckState( Qt::Checked
);
196 m_ui
->capColorButton
->setColor( KColorScheme( QPalette::Active
, KColorScheme::Window
).background().color() );
197 m_ui
->capsImageBox
->setCheckState( Qt::Checked
);
198 m_ui
->closeOnMouseReleaseBox
->setCheckState( Qt::Unchecked
);
199 m_ui
->wallpaperRequester
->setPath( "" );
200 m_ui
->zPositionSlider
->setValue( 100 );
201 m_ui
->walkThroughDesktopBox
->setCheckState( Qt::Unchecked
);
202 m_ui
->editor
->allDefault();
206 void CylinderEffectConfig::capsSelectionChanged()
208 if( m_ui
->cubeCapsBox
->checkState() == Qt::Checked
)
210 // activate cap color
211 m_ui
->capColorButton
->setEnabled( true );
212 m_ui
->capColorLabel
->setEnabled( true );
213 m_ui
->capsImageBox
->setEnabled( true );
217 // deactivate cap color
218 m_ui
->capColorButton
->setEnabled( false );
219 m_ui
->capColorLabel
->setEnabled( false );
220 m_ui
->capsImageBox
->setEnabled( false );
226 #include "cylinder_config.moc"