1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
6 Copyright (C) 2008 Lucas Murray <lmurray@undefinedfire.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #include "desktopgrid_config.h"
23 #include <kwineffects.h>
25 #include <kconfiggroup.h>
26 #include <KActionCollection>
29 #include <QVBoxLayout>
32 KWIN_EFFECT_CONFIG_FACTORY
38 DesktopGridEffectConfigForm::DesktopGridEffectConfigForm(QWidget
* parent
) : QWidget(parent
)
43 DesktopGridEffectConfig::DesktopGridEffectConfig(QWidget
* parent
, const QVariantList
& args
)
44 : KCModule( EffectFactory::componentData(), parent
, args
)
46 m_ui
= new DesktopGridEffectConfigForm( this );
48 QVBoxLayout
* layout
= new QVBoxLayout( this );
50 layout
->addWidget( m_ui
);
52 m_actionCollection
= new KActionCollection( this, componentData() );
53 m_actionCollection
->setConfigGroup( "DesktopGrid" );
54 m_actionCollection
->setConfigGlobal( true );
56 KAction
* a
= (KAction
*) m_actionCollection
->addAction( "ShowDesktopGrid" );
57 a
->setText( i18n( "Show Desktop Grid" ));
58 a
->setProperty( "isConfigurationAction", true );
59 a
->setGlobalShortcut( KShortcut( Qt::CTRL
+ Qt::Key_F8
));
61 m_ui
->shortcutEditor
->addCollection( m_actionCollection
);
63 m_alignmentItems
.append( Qt::Alignment( 0 ));
64 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Disabled" ));
65 m_alignmentItems
.append( Qt::AlignHCenter
| Qt::AlignTop
);
66 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Top" ));
67 m_alignmentItems
.append( Qt::AlignRight
| Qt::AlignTop
);
68 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Top-Right" ));
69 m_alignmentItems
.append( Qt::AlignRight
| Qt::AlignVCenter
);
70 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Right" ));
71 m_alignmentItems
.append( Qt::AlignRight
| Qt::AlignBottom
);
72 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Bottom-Right" ));
73 m_alignmentItems
.append( Qt::AlignHCenter
| Qt::AlignBottom
);
74 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Bottom" ));
75 m_alignmentItems
.append( Qt::AlignLeft
| Qt::AlignBottom
);
76 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Bottom-Left" ));
77 m_alignmentItems
.append( Qt::AlignLeft
| Qt::AlignVCenter
);
78 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Left" ));
79 m_alignmentItems
.append( Qt::AlignLeft
| Qt::AlignTop
);
80 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Top-Left" ));
81 m_alignmentItems
.append( Qt::AlignCenter
);
82 m_ui
->desktopNameAlignmentCombo
->addItem( i18n( "Center" ));
84 connect( m_ui
->zoomDurationSpin
, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
85 connect( m_ui
->borderWidthSpin
, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
86 connect( m_ui
->desktopNameAlignmentCombo
, SIGNAL( currentIndexChanged( int )), this, SLOT( changed() ));
87 connect( m_ui
->layoutCombo
, SIGNAL( currentIndexChanged( int )), this, SLOT( changed() ));
88 connect( m_ui
->layoutCombo
, SIGNAL( currentIndexChanged( int )), this, SLOT( layoutSelectionChanged() ));
89 connect( m_ui
->layoutRowsSpin
, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
90 connect( m_ui
->shortcutEditor
, SIGNAL( keyChange() ), this, SLOT( changed() ));
95 DesktopGridEffectConfig::~DesktopGridEffectConfig()
97 // If save() is called undoChanges() has no effect
98 m_ui
->shortcutEditor
->undoChanges();
101 void DesktopGridEffectConfig::load()
105 KConfigGroup conf
= EffectsHandler::effectConfig( "DesktopGrid" );
107 m_ui
->zoomDurationSpin
->setValue( conf
.readEntry( "ZoomDuration", 0 ));
108 m_ui
->borderWidthSpin
->setValue( conf
.readEntry( "BorderWidth", 10 ));
110 Qt::Alignment alignment
= Qt::Alignment( conf
.readEntry( "DesktopNameAlignment", 0 ));
111 m_ui
->desktopNameAlignmentCombo
->setCurrentIndex( m_alignmentItems
.indexOf( alignment
));
113 int layoutMode
= conf
.readEntry( "LayoutMode", int( DesktopGridEffect::LayoutPager
));
114 m_ui
->layoutCombo
->setCurrentIndex( layoutMode
);
115 layoutSelectionChanged();
117 m_ui
->layoutRowsSpin
->setValue( conf
.readEntry( "CustomLayoutRows", 2 ));
122 void DesktopGridEffectConfig::save()
126 KConfigGroup conf
= EffectsHandler::effectConfig( "DesktopGrid" );
128 conf
.writeEntry( "ZoomDuration", m_ui
->zoomDurationSpin
->value() );
129 conf
.writeEntry( "BorderWidth", m_ui
->borderWidthSpin
->value() );
131 int alignment
= m_ui
->desktopNameAlignmentCombo
->currentIndex();
132 alignment
= int( m_alignmentItems
[alignment
] );
133 conf
.writeEntry( "DesktopNameAlignment", alignment
);
135 int layoutMode
= m_ui
->layoutCombo
->currentIndex();
136 conf
.writeEntry( "LayoutMode", layoutMode
);
138 conf
.writeEntry( "CustomLayoutRows", m_ui
->layoutRowsSpin
->value() );
140 m_ui
->shortcutEditor
->save();
145 EffectsHandler::sendReloadMessage( "desktopgrid" );
148 void DesktopGridEffectConfig::defaults()
150 m_ui
->zoomDurationSpin
->setValue( 0 );
151 m_ui
->borderWidthSpin
->setValue( 10 );
152 m_ui
->desktopNameAlignmentCombo
->setCurrentIndex( 0 );
153 m_ui
->layoutCombo
->setCurrentIndex( int( DesktopGridEffect::LayoutPager
));
154 m_ui
->layoutRowsSpin
->setValue( 2 );
155 m_ui
->shortcutEditor
->allDefault();
159 void DesktopGridEffectConfig::layoutSelectionChanged()
161 if( m_ui
->layoutCombo
->currentIndex() == DesktopGridEffect::LayoutCustom
)
163 m_ui
->layoutRowsLabel
->setEnabled( true );
164 m_ui
->layoutRowsSpin
->setEnabled( true );
168 m_ui
->layoutRowsLabel
->setEnabled( false );
169 m_ui
->layoutRowsSpin
->setEnabled( false );
175 #include "desktopgrid_config.moc"