not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / effects / cube_config.cpp
blob98ea07f8cb8fa6ee7b9ce0904f2430af6ce582ad
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 "cube_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 <QVBoxLayout>
31 #include <QColor>
32 #ifndef KDE_USE_FINAL
33 KWIN_EFFECT_CONFIG_FACTORY
34 #endif
36 namespace KWin
39 CubeEffectConfigForm::CubeEffectConfigForm(QWidget* parent) : QWidget(parent)
41 setupUi(this);
44 CubeEffectConfig::CubeEffectConfig(QWidget* parent, const QVariantList& args) :
45 KCModule(EffectFactory::componentData(), parent, args)
47 m_ui = new CubeEffectConfigForm(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 m_ui->wallpaperRequester->setFilter("*.png *.jpeg *.jpg ");
69 connect(m_ui->rotationDurationSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
70 connect(m_ui->cubeOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
71 connect(m_ui->cubeOpacitySpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
72 connect(m_ui->displayDesktopNameBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
73 connect(m_ui->reflectionBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
74 connect(m_ui->backgroundColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
75 connect(m_ui->animateDesktopChangeBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
76 connect(m_ui->bigCubeBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
77 connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
78 connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(capsSelectionChanged()));
79 connect(m_ui->capsImageBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
80 connect(m_ui->capColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
81 connect(m_ui->wallpaperRequester, SIGNAL(textChanged(QString)), this, SLOT(changed()));
82 connect(m_ui->closeOnMouseReleaseBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
83 connect(m_ui->zPositionSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
84 connect(m_ui->walkThroughDesktopBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
86 load();
89 void CubeEffectConfig::load()
91 KCModule::load();
93 KConfigGroup conf = EffectsHandler::effectConfig( "Cube" );
95 int duration = conf.readEntry( "RotationDuration", 0 );
96 float opacity = conf.readEntry( "Opacity", 80 );
97 bool desktopName = conf.readEntry( "DisplayDesktopName", true );
98 bool reflection = conf.readEntry( "Reflection", true );
99 QColor background = conf.readEntry( "BackgroundColor", QColor( Qt::black ) );
100 QColor capColor = conf.readEntry( "CapColor", KColorScheme( QPalette::Active, KColorScheme::Window ).background().color() );
101 bool texturedCaps = conf.readEntry( "TexturedCaps", true );
102 bool caps = conf.readEntry( "Caps", true );
103 bool animateChange = conf.readEntry( "AnimateDesktopChange", false );
104 bool bigCube = conf.readEntry( "BigCube", false );
105 bool closeOnMouseRelease = conf.readEntry( "CloseOnMouseRelease", false );
106 bool walkThroughDesktop = conf.readEntry( "TabBox", false );
107 m_ui->zPositionSlider->setValue( conf.readEntry( "ZPosition", 100 ) );
108 m_ui->wallpaperRequester->setPath( conf.readEntry( "Wallpaper", "" ) );
110 m_ui->rotationDurationSpin->setValue( duration );
111 m_ui->cubeOpacitySlider->setValue( opacity );
112 m_ui->cubeOpacitySpin->setValue( opacity );
113 if( desktopName )
115 m_ui->displayDesktopNameBox->setCheckState( Qt::Checked );
117 else
119 m_ui->displayDesktopNameBox->setCheckState( Qt::Unchecked );
121 if( reflection )
123 m_ui->reflectionBox->setCheckState( Qt::Checked );
125 else
127 m_ui->reflectionBox->setCheckState( Qt::Unchecked );
129 if( caps )
131 m_ui->cubeCapsBox->setCheckState( Qt::Checked );
133 else
135 m_ui->cubeCapsBox->setCheckState( Qt::Unchecked );
137 if( texturedCaps )
139 m_ui->capsImageBox->setCheckState( Qt::Checked );
141 else
143 m_ui->capsImageBox->setCheckState( Qt::Unchecked );
145 if( animateChange )
147 m_ui->animateDesktopChangeBox->setCheckState( Qt::Checked );
149 else
151 m_ui->animateDesktopChangeBox->setCheckState( Qt::Unchecked );
153 if( bigCube )
155 m_ui->bigCubeBox->setCheckState( Qt::Checked );
157 else
159 m_ui->bigCubeBox->setCheckState( Qt::Unchecked );
161 if( closeOnMouseRelease )
163 m_ui->closeOnMouseReleaseBox->setCheckState( Qt::Checked );
165 else
167 m_ui->closeOnMouseReleaseBox->setCheckState( Qt::Unchecked );
169 if( walkThroughDesktop )
171 m_ui->walkThroughDesktopBox->setCheckState( Qt::Checked );
173 else
175 m_ui->walkThroughDesktopBox->setCheckState( Qt::Unchecked );
177 m_ui->backgroundColorButton->setColor( background );
178 m_ui->capColorButton->setColor( capColor );
179 capsSelectionChanged();
181 emit changed(false);
184 void CubeEffectConfig::save()
186 KConfigGroup conf = EffectsHandler::effectConfig( "Cube" );
188 conf.writeEntry( "RotationDuration", m_ui->rotationDurationSpin->value() );
189 conf.writeEntry( "DisplayDesktopName", m_ui->displayDesktopNameBox->checkState() == Qt::Checked ? true : false );
190 conf.writeEntry( "Reflection", m_ui->reflectionBox->checkState() == Qt::Checked ? true : false );
191 conf.writeEntry( "Opacity", m_ui->cubeOpacitySpin->value() );
192 conf.writeEntry( "BackgroundColor", m_ui->backgroundColorButton->color() );
193 conf.writeEntry( "Caps", m_ui->cubeCapsBox->checkState() == Qt::Checked ? true : false );
194 conf.writeEntry( "CapColor", m_ui->capColorButton->color() );
195 conf.writeEntry( "TexturedCaps", m_ui->capsImageBox->checkState() == Qt::Checked ? true : false );
196 conf.writeEntry( "AnimateDesktopChange", m_ui->animateDesktopChangeBox->checkState() == Qt::Checked ? true : false );
197 conf.writeEntry( "BigCube", m_ui->bigCubeBox->checkState() == Qt::Checked ? true : false );
198 conf.writeEntry( "CloseOnMouseRelease", m_ui->closeOnMouseReleaseBox->checkState() == Qt::Checked ? true : false );
199 conf.writeEntry( "Wallpaper", m_ui->wallpaperRequester->url().path() );
200 conf.writeEntry( "ZPosition", m_ui->zPositionSlider->value() );
201 conf.writeEntry( "TabBox", m_ui->walkThroughDesktopBox->checkState() == Qt::Checked ? true : false );
203 m_ui->editor->save();
205 conf.sync();
207 emit changed(false);
208 EffectsHandler::sendReloadMessage( "cube" );
211 void CubeEffectConfig::defaults()
213 m_ui->rotationDurationSpin->setValue( 0 );
214 m_ui->displayDesktopNameBox->setCheckState( Qt::Checked );
215 m_ui->reflectionBox->setCheckState( Qt::Checked );
216 m_ui->cubeOpacitySpin->setValue( 80 );
217 m_ui->cubeOpacitySlider->setValue( 80 );
218 m_ui->backgroundColorButton->setColor( QColor( Qt::black ) );
219 m_ui->cubeCapsBox->setCheckState( Qt::Checked );
220 m_ui->capColorButton->setColor( KColorScheme( QPalette::Active, KColorScheme::Window ).background().color() );
221 m_ui->capsImageBox->setCheckState( Qt::Checked );
222 m_ui->animateDesktopChangeBox->setCheckState( Qt::Unchecked );
223 m_ui->bigCubeBox->setCheckState( Qt::Unchecked );
224 m_ui->closeOnMouseReleaseBox->setCheckState( Qt::Unchecked );
225 m_ui->wallpaperRequester->setPath( "" );
226 m_ui->zPositionSlider->setValue( 100 );
227 m_ui->walkThroughDesktopBox->setCheckState( Qt::Unchecked );
228 m_ui->editor->allDefault();
229 emit changed(true);
232 void CubeEffectConfig::capsSelectionChanged()
234 if( m_ui->cubeCapsBox->checkState() == Qt::Checked )
236 // activate cap color
237 m_ui->capColorButton->setEnabled( true );
238 m_ui->capColorLabel->setEnabled( true );
239 m_ui->capsImageBox->setEnabled( true );
241 else
243 // deactivate cap color
244 m_ui->capColorButton->setEnabled( false );
245 m_ui->capColorLabel->setEnabled( false );
246 m_ui->capsImageBox->setEnabled( false );
250 } // namespace
252 #include "cube_config.moc"