2007-11-27 22:40:25 +03:00
|
|
|
/********************************************************************
|
2007-09-25 21:52:19 +04:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
2008-08-12 19:22:06 +04:00
|
|
|
Copyright (C) 2008 Lucas Murray <lmurray@undefinedfire.com>
|
2007-09-25 21:52:19 +04:00
|
|
|
|
2007-11-27 22:40:25 +03:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-09-25 21:52:19 +04:00
|
|
|
|
|
|
|
#include "desktopgrid_config.h"
|
|
|
|
#include <kwineffects.h>
|
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
#include <kconfiggroup.h>
|
2007-09-25 21:52:19 +04:00
|
|
|
#include <KActionCollection>
|
|
|
|
#include <kaction.h>
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
2008-08-12 19:22:06 +04:00
|
|
|
|
2007-09-25 21:52:19 +04:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2009-02-05 18:35:38 +03:00
|
|
|
KWIN_EFFECT_CONFIG_FACTORY
|
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
DesktopGridEffectConfigForm::DesktopGridEffectConfigForm(QWidget* parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
DesktopGridEffectConfig::DesktopGridEffectConfig(QWidget* parent, const QVariantList& args)
|
|
|
|
: KCModule( EffectFactory::componentData(), parent, args )
|
2007-09-25 21:52:19 +04:00
|
|
|
{
|
2008-08-12 19:22:06 +04:00
|
|
|
m_ui = new DesktopGridEffectConfigForm( this );
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout( this );
|
|
|
|
|
|
|
|
layout->addWidget( m_ui );
|
|
|
|
|
2009-02-11 03:34:09 +03:00
|
|
|
// Shortcut config. The shortcut belongs to the component "kwin"!
|
|
|
|
m_actionCollection = new KActionCollection( this, KComponentData("kwin") );
|
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
m_actionCollection->setConfigGroup( "DesktopGrid" );
|
|
|
|
m_actionCollection->setConfigGlobal( true );
|
|
|
|
|
|
|
|
KAction* a = (KAction*) m_actionCollection->addAction( "ShowDesktopGrid" );
|
|
|
|
a->setText( i18n( "Show Desktop Grid" ));
|
|
|
|
a->setProperty( "isConfigurationAction", true );
|
|
|
|
a->setGlobalShortcut( KShortcut( Qt::CTRL + Qt::Key_F8 ));
|
|
|
|
|
|
|
|
m_ui->shortcutEditor->addCollection( m_actionCollection );
|
|
|
|
|
|
|
|
m_alignmentItems.append( Qt::Alignment( 0 ));
|
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Disabled" ));
|
|
|
|
m_alignmentItems.append( Qt::AlignHCenter | Qt::AlignTop );
|
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Top" ));
|
|
|
|
m_alignmentItems.append( Qt::AlignRight | Qt::AlignTop );
|
2008-11-17 21:35:18 +03:00
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Top-Right" ));
|
2008-08-12 19:22:06 +04:00
|
|
|
m_alignmentItems.append( Qt::AlignRight | Qt::AlignVCenter );
|
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Right" ));
|
|
|
|
m_alignmentItems.append( Qt::AlignRight | Qt::AlignBottom );
|
2008-11-17 21:35:18 +03:00
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Bottom-Right" ));
|
2008-08-12 19:22:06 +04:00
|
|
|
m_alignmentItems.append( Qt::AlignHCenter | Qt::AlignBottom );
|
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Bottom" ));
|
|
|
|
m_alignmentItems.append( Qt::AlignLeft | Qt::AlignBottom );
|
2008-11-17 21:35:18 +03:00
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Bottom-Left" ));
|
2008-08-12 19:22:06 +04:00
|
|
|
m_alignmentItems.append( Qt::AlignLeft | Qt::AlignVCenter );
|
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Left" ));
|
|
|
|
m_alignmentItems.append( Qt::AlignLeft | Qt::AlignTop );
|
2008-11-17 21:35:18 +03:00
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Top-Left" ));
|
2008-08-12 19:22:06 +04:00
|
|
|
m_alignmentItems.append( Qt::AlignCenter );
|
|
|
|
m_ui->desktopNameAlignmentCombo->addItem( i18n( "Center" ));
|
|
|
|
|
|
|
|
connect( m_ui->zoomDurationSpin, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
|
|
|
|
connect( m_ui->borderWidthSpin, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
|
|
|
|
connect( m_ui->desktopNameAlignmentCombo, SIGNAL( currentIndexChanged( int )), this, SLOT( changed() ));
|
2008-09-04 18:37:07 +04:00
|
|
|
connect( m_ui->layoutCombo, SIGNAL( currentIndexChanged( int )), this, SLOT( changed() ));
|
|
|
|
connect( m_ui->layoutCombo, SIGNAL( currentIndexChanged( int )), this, SLOT( layoutSelectionChanged() ));
|
2008-08-12 19:22:06 +04:00
|
|
|
connect( m_ui->layoutRowsSpin, SIGNAL( valueChanged( int )), this, SLOT( changed() ));
|
|
|
|
connect( m_ui->shortcutEditor, SIGNAL( keyChange() ), this, SLOT( changed() ));
|
|
|
|
|
|
|
|
load();
|
2007-09-25 21:52:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopGridEffectConfig::~DesktopGridEffectConfig()
|
|
|
|
{
|
2008-08-12 19:22:06 +04:00
|
|
|
// If save() is called undoChanges() has no effect
|
|
|
|
m_ui->shortcutEditor->undoChanges();
|
2007-09-25 21:52:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopGridEffectConfig::load()
|
|
|
|
{
|
|
|
|
KCModule::load();
|
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig( "DesktopGrid" );
|
|
|
|
|
2008-08-30 11:25:54 +04:00
|
|
|
m_ui->zoomDurationSpin->setValue( conf.readEntry( "ZoomDuration", 0 ));
|
2009-09-19 16:57:06 +04:00
|
|
|
m_ui->zoomDurationSpin->setSuffix( ki18np( " millisecond", " milliseconds"));
|
2008-08-12 19:22:06 +04:00
|
|
|
m_ui->borderWidthSpin->setValue( conf.readEntry( "BorderWidth", 10 ));
|
2009-07-01 00:09:04 +04:00
|
|
|
m_ui->borderWidthSpin->setSuffix( ki18np( " pixel", " pixels"));
|
2008-08-12 19:22:06 +04:00
|
|
|
|
|
|
|
Qt::Alignment alignment = Qt::Alignment( conf.readEntry( "DesktopNameAlignment", 0 ));
|
|
|
|
m_ui->desktopNameAlignmentCombo->setCurrentIndex( m_alignmentItems.indexOf( alignment ));
|
|
|
|
|
2008-09-04 18:37:07 +04:00
|
|
|
int layoutMode = conf.readEntry( "LayoutMode", int( DesktopGridEffect::LayoutPager ));
|
|
|
|
m_ui->layoutCombo->setCurrentIndex( layoutMode );
|
2008-08-12 19:22:06 +04:00
|
|
|
layoutSelectionChanged();
|
|
|
|
|
|
|
|
m_ui->layoutRowsSpin->setValue( conf.readEntry( "CustomLayoutRows", 2 ));
|
2009-07-01 00:09:04 +04:00
|
|
|
m_ui->layoutRowsSpin->setSuffix( ki18np( " row", " rows"));
|
2008-01-29 16:48:26 +03:00
|
|
|
|
2007-09-25 21:52:19 +04:00
|
|
|
emit changed(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopGridEffectConfig::save()
|
|
|
|
{
|
|
|
|
KCModule::save();
|
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig( "DesktopGrid" );
|
2007-09-25 21:52:19 +04:00
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
conf.writeEntry( "ZoomDuration", m_ui->zoomDurationSpin->value() );
|
|
|
|
conf.writeEntry( "BorderWidth", m_ui->borderWidthSpin->value() );
|
|
|
|
|
|
|
|
int alignment = m_ui->desktopNameAlignmentCombo->currentIndex();
|
|
|
|
alignment = int( m_alignmentItems[alignment] );
|
|
|
|
conf.writeEntry( "DesktopNameAlignment", alignment );
|
|
|
|
|
2008-09-04 18:37:07 +04:00
|
|
|
int layoutMode = m_ui->layoutCombo->currentIndex();
|
|
|
|
conf.writeEntry( "LayoutMode", layoutMode );
|
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
conf.writeEntry( "CustomLayoutRows", m_ui->layoutRowsSpin->value() );
|
2007-09-25 21:52:19 +04:00
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
m_ui->shortcutEditor->save();
|
|
|
|
|
|
|
|
conf.sync();
|
2008-05-26 00:31:33 +04:00
|
|
|
|
2007-09-25 21:52:19 +04:00
|
|
|
emit changed(false);
|
|
|
|
EffectsHandler::sendReloadMessage( "desktopgrid" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopGridEffectConfig::defaults()
|
|
|
|
{
|
2008-08-30 11:25:54 +04:00
|
|
|
m_ui->zoomDurationSpin->setValue( 0 );
|
2008-08-12 19:22:06 +04:00
|
|
|
m_ui->borderWidthSpin->setValue( 10 );
|
|
|
|
m_ui->desktopNameAlignmentCombo->setCurrentIndex( 0 );
|
2008-09-04 18:37:07 +04:00
|
|
|
m_ui->layoutCombo->setCurrentIndex( int( DesktopGridEffect::LayoutPager ));
|
2008-08-12 19:22:06 +04:00
|
|
|
m_ui->layoutRowsSpin->setValue( 2 );
|
|
|
|
m_ui->shortcutEditor->allDefault();
|
2007-09-25 21:52:19 +04:00
|
|
|
emit changed(true);
|
|
|
|
}
|
|
|
|
|
2008-08-12 19:22:06 +04:00
|
|
|
void DesktopGridEffectConfig::layoutSelectionChanged()
|
|
|
|
{
|
2008-09-04 18:37:07 +04:00
|
|
|
if( m_ui->layoutCombo->currentIndex() == DesktopGridEffect::LayoutCustom )
|
2008-08-12 19:22:06 +04:00
|
|
|
{
|
|
|
|
m_ui->layoutRowsLabel->setEnabled( true );
|
|
|
|
m_ui->layoutRowsSpin->setEnabled( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ui->layoutRowsLabel->setEnabled( false );
|
|
|
|
m_ui->layoutRowsSpin->setEnabled( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 21:52:19 +04:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "desktopgrid_config.moc"
|