add more spacing
[personal-kdebase.git] / workspace / kwin / effects / sphere_config.cpp
bloba97fcaa8b2793a5a48111bcace268076ae912780
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 "sphere_config.h"
21 #include <kwineffects.h>
23 #include <kconfiggroup.h>
24 #include <kcolorscheme.h>
25 #include <KActionCollection>
26 #include <kaction.h>
27 #include <KFileDialog>
28 #include <KImageFilePreview>
30 #include <QGridLayout>
31 #include <QColor>
32 #ifndef KDE_USE_FINAL
33 KWIN_EFFECT_CONFIG_FACTORY
34 #endif
36 namespace KWin
39 SphereEffectConfigForm::SphereEffectConfigForm(QWidget* parent) : QWidget(parent)
41 setupUi(this);
44 SphereEffectConfig::SphereEffectConfig(QWidget* parent, const QVariantList& args) :
45 KCModule(EffectFactory::componentData(), parent, args)
47 m_ui = new SphereEffectConfigForm(this);
49 QVBoxLayout* layout = new QVBoxLayout(this);
51 layout->addWidget(m_ui);
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->backgroundColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
72 connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
73 connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(capsSelectionChanged()));
74 connect(m_ui->capsImageBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
75 connect(m_ui->capColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
76 connect(m_ui->wallpaperRequester, SIGNAL(textChanged(QString)), this, SLOT(changed()));
77 connect(m_ui->closeOnMouseReleaseBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
78 connect(m_ui->zPositionSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
79 connect(m_ui->capDeformationSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
80 connect(m_ui->walkThroughDesktopBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
82 load();
85 void SphereEffectConfig::load()
87 KCModule::load();
89 KConfigGroup conf = EffectsHandler::effectConfig( "Sphere" );
91 int duration = conf.readEntry( "RotationDuration", 0 );
92 float opacity = conf.readEntry( "Opacity", 80 );
93 bool desktopName = conf.readEntry( "DisplayDesktopName", true );
94 QColor background = conf.readEntry( "BackgroundColor", QColor( Qt::black ) );
95 QColor capColor = conf.readEntry( "CapColor", KColorScheme( QPalette::Active, KColorScheme::Window ).background().color() );
96 bool texturedCaps = conf.readEntry( "TexturedCaps", true );
97 bool caps = conf.readEntry( "Caps", true );
98 bool closeOnMouseRelease = conf.readEntry( "CloseOnMouseRelease", false );
99 bool walkThroughDesktop = conf.readEntry( "TabBox", false );
100 m_ui->zPositionSlider->setValue( conf.readEntry( "ZPosition", 450 ) );
101 m_ui->capDeformationSlider->setValue( conf.readEntry( "CapDeformation", 0 ) );
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 );
107 if( desktopName )
109 m_ui->displayDesktopNameBox->setCheckState( Qt::Checked );
111 else
113 m_ui->displayDesktopNameBox->setCheckState( Qt::Unchecked );
115 if( caps )
117 m_ui->cubeCapsBox->setCheckState( Qt::Checked );
119 else
121 m_ui->cubeCapsBox->setCheckState( Qt::Unchecked );
123 if( texturedCaps )
125 m_ui->capsImageBox->setCheckState( Qt::Checked );
127 else
129 m_ui->capsImageBox->setCheckState( Qt::Unchecked );
131 if( closeOnMouseRelease )
133 m_ui->closeOnMouseReleaseBox->setCheckState( Qt::Checked );
135 else
137 m_ui->closeOnMouseReleaseBox->setCheckState( Qt::Unchecked );
139 if( walkThroughDesktop )
141 m_ui->walkThroughDesktopBox->setCheckState( Qt::Checked );
143 else
145 m_ui->walkThroughDesktopBox->setCheckState( Qt::Unchecked );
147 m_ui->backgroundColorButton->setColor( background );
148 m_ui->capColorButton->setColor( capColor );
149 capsSelectionChanged();
151 emit changed(false);
154 void SphereEffectConfig::save()
156 KConfigGroup conf = EffectsHandler::effectConfig( "Sphere" );
158 conf.writeEntry( "RotationDuration", m_ui->rotationDurationSpin->value() );
159 conf.writeEntry( "DisplayDesktopName", m_ui->displayDesktopNameBox->checkState() == Qt::Checked ? true : false );
160 conf.writeEntry( "Opacity", m_ui->cubeOpacitySpin->value() );
161 conf.writeEntry( "BackgroundColor", m_ui->backgroundColorButton->color() );
162 conf.writeEntry( "Caps", m_ui->cubeCapsBox->checkState() == Qt::Checked ? true : false );
163 conf.writeEntry( "CapColor", m_ui->capColorButton->color() );
164 conf.writeEntry( "TexturedCaps", m_ui->capsImageBox->checkState() == Qt::Checked ? true : false );
165 conf.writeEntry( "CloseOnMouseRelease", m_ui->closeOnMouseReleaseBox->checkState() == Qt::Checked ? true : false );
166 conf.writeEntry( "Wallpaper", m_ui->wallpaperRequester->url().path() );
167 conf.writeEntry( "ZPosition", m_ui->zPositionSlider->value() );
168 conf.writeEntry( "CapDeformation", m_ui->capDeformationSlider->value() );
169 conf.writeEntry( "TabBox", m_ui->walkThroughDesktopBox->checkState() == Qt::Checked ? true : false );
171 m_ui->editor->save();
173 conf.sync();
175 emit changed(false);
176 EffectsHandler::sendReloadMessage( "sphere" );
179 void SphereEffectConfig::defaults()
181 m_ui->rotationDurationSpin->setValue( 0 );
182 m_ui->displayDesktopNameBox->setCheckState( Qt::Checked );
183 m_ui->cubeOpacitySpin->setValue( 80 );
184 m_ui->cubeOpacitySlider->setValue( 80 );
185 m_ui->backgroundColorButton->setColor( QColor( Qt::black ) );
186 m_ui->cubeCapsBox->setCheckState( Qt::Checked );
187 m_ui->capColorButton->setColor( KColorScheme( QPalette::Active, KColorScheme::Window ).background().color() );
188 m_ui->capsImageBox->setCheckState( Qt::Checked );
189 m_ui->closeOnMouseReleaseBox->setCheckState( Qt::Unchecked );
190 m_ui->wallpaperRequester->setPath( "" );
191 m_ui->zPositionSlider->setValue( 450 );
192 m_ui->capDeformationSlider->setValue( 0 );
193 m_ui->walkThroughDesktopBox->setCheckState( Qt::Unchecked );
194 m_ui->editor->allDefault();
195 emit changed(true);
198 void SphereEffectConfig::capsSelectionChanged()
200 if( m_ui->cubeCapsBox->checkState() == Qt::Checked )
202 // activate cap color
203 m_ui->capColorButton->setEnabled( true );
204 m_ui->capColorLabel->setEnabled( true );
205 m_ui->capsImageBox->setEnabled( true );
206 m_ui->capDeformationGroupBox->setEnabled( true );
207 m_ui->capDeformationSlider->setEnabled( true );
208 m_ui->capDeformationSphereLabel->setEnabled( true );
209 m_ui->capDeformationPlaneLabel->setEnabled( true );
211 else
213 // deactivate cap color
214 m_ui->capColorButton->setEnabled( false );
215 m_ui->capColorLabel->setEnabled( false );
216 m_ui->capsImageBox->setEnabled( false );
217 m_ui->capDeformationGroupBox->setEnabled( false );
218 m_ui->capDeformationSlider->setEnabled( false );
219 m_ui->capDeformationSphereLabel->setEnabled( false );
220 m_ui->capDeformationPlaneLabel->setEnabled( false );
224 } // namespace
226 #include "sphere_config.moc"