kwin/kcmkwin/kwindecoration/configdialog.cpp

180 lines
6.6 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 <mgraesslin@kde.org>
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/>.
*********************************************************************/
#include "configdialog.h"
#include <QDBusConnection>
#include <QDBusMessage>
2013-10-01 06:08:29 +00:00
#include <KSharedConfig>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KPluginFactory>
#include <KPluginLoader>
#include <QDialogButtonBox>
#include <QPushButton>
namespace KWin
{
2011-01-30 14:34:42 +00:00
static const char* const border_names[ KDecorationDefines::BordersCount ] = {
I18N_NOOP2("@item:inlistbox Border size:", "Tiny"),
I18N_NOOP2("@item:inlistbox Border size:", "Normal"),
I18N_NOOP2("@item:inlistbox Border size:", "Large"),
I18N_NOOP2("@item:inlistbox Border size:", "Very Large"),
I18N_NOOP2("@item:inlistbox Border size:", "Huge"),
I18N_NOOP2("@item:inlistbox Border size:", "Very Huge"),
I18N_NOOP2("@item:inlistbox Border size:", "Oversized"),
I18N_NOOP2("@item:inlistbox Border size:", "No Side Border"),
I18N_NOOP2("@item:inlistbox Border size:", "No Border"),
2011-01-30 14:34:42 +00:00
};
KWinAuroraeConfigForm::KWinAuroraeConfigForm(QWidget* parent)
: QWidget(parent)
{
setupUi(this);
connect(borderSizesCombo, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()));
connect(buttonSizesCombo, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()));
connect(closeWindowsDoubleClick, SIGNAL(clicked()), SIGNAL(changed()));
2011-01-30 14:34:42 +00:00
}
void KWinAuroraeConfigForm::enableNoSideBorderSupport(bool enable)
{
if (!enable) {
return;
}
borderSizesCombo->addItem(i18nc("@item:inlistbox Border size:", border_names[KDecorationDefines::BorderNoSides]));
borderSizesCombo->addItem(i18nc("@item:inlistbox Border size:", border_names[KDecorationDefines::BorderNone]));
}
2011-01-30 14:34:42 +00:00
KWinDecorationConfigForm::KWinDecorationConfigForm(QWidget* parent)
: QWidget(parent)
{
setupUi(this);
}
KWinDecorationConfigDialog::KWinDecorationConfigDialog(QString deco, const QList<QVariant>& borderSizes,
KDecorationDefines::BorderSize size,
QWidget* parent, Qt::WFlags flags)
: QDialog(parent, flags)
2011-01-30 14:34:42 +00:00
, m_borderSizes(borderSizes)
, m_kwinConfig(KSharedConfig::openConfig("kwinrc"))
, m_pluginObject(nullptr)
, m_pluginConfigWidget(nullptr)
2011-01-30 14:34:42 +00:00
{
m_ui = new KWinDecorationConfigForm(this);
setWindowTitle(i18n("Decoration Options"));
m_buttons = new QDialogButtonBox(this);
m_buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Reset);
m_buttons->button(QDialogButtonBox::Reset)->setEnabled(false);
QVBoxLayout* layout = new QVBoxLayout;
2011-01-30 14:34:42 +00:00
layout->addWidget(m_ui);
connect(m_buttons, SIGNAL(accepted()), SLOT(accept()));
connect(m_buttons, SIGNAL(rejected()), SLOT(reject()));
KPluginLoader loader(styleToConfigLib(deco));
KPluginFactory *factory = loader.factory();
if (factory) {
m_pluginConfigWidget = new QWidget(this);
m_pluginConfigWidget->setLayout(new QVBoxLayout);
m_pluginObject = factory->create<QObject>(m_pluginConfigWidget, m_pluginConfigWidget, QString(),
QVariantList() << QStringLiteral("kwinrc") << QStringLiteral("Style"));
// connect required signals and slots together...
connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
connect(m_pluginObject, SIGNAL(changed()), this, SLOT(slotSelectionChanged()));
connect(this, SIGNAL(pluginSave(KConfigGroup&)), m_pluginObject, SLOT(save(KConfigGroup&)));
connect(m_buttons->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked(bool)), m_pluginObject, SLOT(defaults()));
connect(m_buttons->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked(bool)), SLOT(slotDefault()));
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (m_pluginConfigWidget) {
layout->addWidget(m_pluginConfigWidget);
}
layout->addWidget(m_buttons);
2011-01-30 14:34:42 +00:00
if (borderSizes.count() >= 2) {
foreach (const QVariant & borderSize, borderSizes) {
KDecorationDefines::BorderSize currentSize =
2011-01-30 14:34:42 +00:00
static_cast<KDecorationDefines::BorderSize>(borderSize.toInt());
m_ui->bordersCombo->addItem(i18nc("@item:inlistbox Border size:", border_names[currentSize]), borderSizeToIndex(currentSize, borderSizes));
}
2011-01-30 14:34:42 +00:00
m_ui->bordersCombo->setCurrentIndex(borderSizeToIndex(size, borderSizes));
} else {
m_ui->bordersCombo->hide();
m_ui->borderLabel->hide();
}
setLayout(layout);
2011-01-30 14:34:42 +00:00
}
KWinDecorationConfigDialog::~KWinDecorationConfigDialog()
2011-01-30 14:34:42 +00:00
{
delete m_pluginObject;
2011-01-30 14:34:42 +00:00
}
KDecorationDefines::BorderSize KWinDecorationConfigDialog::borderSize() const
2011-01-30 14:34:42 +00:00
{
if (m_borderSizes.count() >= 2)
return (KDecorationDefines::BorderSize)m_borderSizes.at(m_ui->bordersCombo->currentIndex()).toInt();
return KDecorationDefines::BorderNormal;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
int KWinDecorationConfigDialog::borderSizeToIndex(KDecorationDefines::BorderSize size, const QList< QVariant >& sizes)
{
int pos = 0;
2011-01-30 14:34:42 +00:00
for (QList< QVariant >::ConstIterator it = sizes.constBegin();
it != sizes.constEnd();
2011-01-30 14:34:42 +00:00
++it, ++pos)
if (size <= (*it).toInt())
break;
return pos;
2011-01-30 14:34:42 +00:00
}
void KWinDecorationConfigDialog::slotAccepted()
2011-01-30 14:34:42 +00:00
{
KConfigGroup config(m_kwinConfig, "Style");
emit pluginSave(config);
config.sync();
2011-01-30 14:34:42 +00:00
}
void KWinDecorationConfigDialog::slotSelectionChanged()
2011-01-30 14:34:42 +00:00
{
m_buttons->button(QDialogButtonBox::Reset)->setEnabled(true);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
QString KWinDecorationConfigDialog::styleToConfigLib(const QString& styleLib) const
{
if (styleLib.startsWith(QLatin1String("kwin3_")))
return "kwin_" + styleLib.mid(6) + "_config";
else
return styleLib + "_config";
2011-01-30 14:34:42 +00:00
}
void KWinDecorationConfigDialog::slotDefault()
2011-01-30 14:34:42 +00:00
{
if (m_borderSizes.count() >= 2)
m_ui->bordersCombo->setCurrentIndex(borderSizeToIndex(BorderNormal, m_borderSizes));
}
} // namespace KWin
#include "configdialog.moc"