kwin/kcmkwin/kwintabbox/layoutconfig.cpp

197 lines
6.7 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
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/>.
*********************************************************************/
// own
#include "layoutconfig.h"
#include "ui_layoutconfig.h"
// tabbox
#include "tabboxconfig.h"
namespace KWin
{
namespace TabBox
{
/***************************************************
* LayoutConfigPrivate
***************************************************/
class LayoutConfigPrivate
2011-01-30 14:34:42 +00:00
{
public:
LayoutConfigPrivate();
~LayoutConfigPrivate() { }
TabBoxConfig config;
Ui::LayoutConfigForm ui;
2011-01-30 14:34:42 +00:00
};
LayoutConfigPrivate::LayoutConfigPrivate()
2011-01-30 14:34:42 +00:00
{
}
/***************************************************
* LayoutConfig
***************************************************/
LayoutConfig::LayoutConfig(QWidget* parent)
: QWidget(parent)
2011-01-30 14:34:42 +00:00
{
d = new LayoutConfigPrivate;
2011-01-30 14:34:42 +00:00
d->ui.setupUi(this);
// init the item layout combo box
2011-01-30 14:34:42 +00:00
d->ui.itemLayoutCombo->addItem(i18n("Informative"));
d->ui.itemLayoutCombo->addItem(i18n("Compact"));
d->ui.itemLayoutCombo->addItem(i18n("Small Icons"));
d->ui.itemLayoutCombo->addItem(i18n("Large Icons"));
d->ui.itemLayoutCombo->addItem(i18n("Text Only"));
// TODO: user defined layouts
// init the selected item layout combo box
2011-01-30 14:34:42 +00:00
d->ui.selectedItemLayoutCombo->addItem(i18n("Informative"));
d->ui.selectedItemLayoutCombo->addItem(i18n("Compact"));
d->ui.selectedItemLayoutCombo->addItem(i18n("Small Icons"));
d->ui.selectedItemLayoutCombo->addItem(i18n("Large Icons"));
d->ui.selectedItemLayoutCombo->addItem(i18n("Text Only"));
connect(d->ui.minWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changed()));
connect(d->ui.minHeightSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changed()));
connect(d->ui.itemLayoutCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(d->ui.layoutCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(d->ui.selectedItemCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(d->ui.selectedItemLayoutCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(d->ui.selectedItemBox, SIGNAL(clicked(bool)), this, SLOT(changed()));
}
LayoutConfig::~LayoutConfig()
2011-01-30 14:34:42 +00:00
{
delete d;
2011-01-30 14:34:42 +00:00
}
TabBoxConfig& LayoutConfig::config() const
2011-01-30 14:34:42 +00:00
{
return d->config;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void LayoutConfig::setConfig(const KWin::TabBox::TabBoxConfig& config)
{
d->config = config;
2011-01-30 14:34:42 +00:00
d->ui.selectedItemBox->setChecked(config.selectedItemViewPosition() != TabBoxConfig::NonePosition);
2011-01-30 14:34:42 +00:00
d->ui.layoutCombo->setCurrentIndex(config.layout());
d->ui.selectedItemCombo->setCurrentIndex(config.selectedItemViewPosition() - 1);
2011-01-30 14:34:42 +00:00
d->ui.minWidthSpinBox->setValue(config.minWidth());
d->ui.minHeightSpinBox->setValue(config.minHeight());
// item layouts
2011-01-30 14:34:42 +00:00
if (config.layoutName().compare("Default", Qt::CaseInsensitive) == 0) {
d->ui.itemLayoutCombo->setCurrentIndex(0);
} else if (config.layoutName().compare("Compact", Qt::CaseInsensitive) == 0) {
d->ui.itemLayoutCombo->setCurrentIndex(1);
} else if (config.layoutName().compare("Small Icons", Qt::CaseInsensitive) == 0) {
d->ui.itemLayoutCombo->setCurrentIndex(2);
} else if (config.layoutName().compare("Big Icons", Qt::CaseInsensitive) == 0) {
d->ui.itemLayoutCombo->setCurrentIndex(3);
} else if (config.layoutName().compare("Text", Qt::CaseInsensitive) == 0) {
d->ui.itemLayoutCombo->setCurrentIndex(4);
} else {
// TODO: user defined layouts
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (config.selectedItemLayoutName().compare("Default", Qt::CaseInsensitive) == 0) {
d->ui.selectedItemLayoutCombo->setCurrentIndex(0);
} else if (config.selectedItemLayoutName().compare("Compact", Qt::CaseInsensitive) == 0) {
d->ui.selectedItemLayoutCombo->setCurrentIndex(1);
} else if (config.selectedItemLayoutName().compare("Small Icons", Qt::CaseInsensitive) == 0) {
d->ui.selectedItemLayoutCombo->setCurrentIndex(2);
} else if (config.selectedItemLayoutName().compare("Big Icons", Qt::CaseInsensitive) == 0) {
d->ui.selectedItemLayoutCombo->setCurrentIndex(3);
} else if (config.selectedItemLayoutName().compare("Text", Qt::CaseInsensitive) == 0) {
d->ui.selectedItemLayoutCombo->setCurrentIndex(4);
} else {
// TODO: user defined layouts
}
2011-01-30 14:34:42 +00:00
}
void LayoutConfig::changed()
2011-01-30 14:34:42 +00:00
{
// it's actually overkill but we just sync all options
2011-01-30 14:34:42 +00:00
d->config.setMinWidth(d->ui.minWidthSpinBox->value());
d->config.setMinHeight(d->ui.minHeightSpinBox->value());
d->config.setLayout(TabBoxConfig::LayoutMode(d->ui.layoutCombo->currentIndex()));
QString layout;
2011-01-30 14:34:42 +00:00
switch(d->ui.itemLayoutCombo->currentIndex()) {
case 0:
layout = "Default";
break;
case 1:
layout = "Compact";
break;
case 2:
layout = "Small Icons";
break;
case 3:
layout = "Big Icons";
break;
case 4:
layout = "Text";
break;
default:
// TODO: user defined layouts
break;
}
d->config.setLayoutName(layout);
if (d->ui.selectedItemBox->isChecked()) {
d->config.setSelectedItemViewPosition(TabBoxConfig::SelectedItemViewPosition(
d->ui.selectedItemCombo->currentIndex() + 1));
QString selectedLayout;
switch(d->ui.selectedItemLayoutCombo->currentIndex()) {
case 0:
2011-01-30 14:34:42 +00:00
selectedLayout = "Default";
break;
case 1:
2011-01-30 14:34:42 +00:00
selectedLayout = "Compact";
break;
case 2:
2011-01-30 14:34:42 +00:00
selectedLayout = "Small Icons";
break;
case 3:
2011-01-30 14:34:42 +00:00
selectedLayout = "Big Icons";
break;
case 4:
2011-01-30 14:34:42 +00:00
selectedLayout = "Text";
break;
default:
// TODO: user defined layouts
break;
}
2011-01-30 14:34:42 +00:00
d->config.setSelectedItemLayoutName(selectedLayout);
} else {
d->config.setSelectedItemViewPosition(TabBoxConfig::NonePosition);
}
2011-01-30 14:34:42 +00:00
}
} // namespace KWin
} // namespace TabBox