2007-04-29 17:35:43 +00:00
|
|
|
/*
|
2010-01-19 13:56:57 +00:00
|
|
|
This is the new kwindecoration kcontrol module
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
Copyright (c) 2001
|
|
|
|
Karol Szwed <gallium@kde.org>
|
|
|
|
http://gallium.n3.net/
|
2013-03-12 12:17:53 +00:00
|
|
|
Copyright 2009, 2010 Martin Gräßlin <mgraesslin@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
Supports new kwin configuration plugins, and titlebar button position
|
|
|
|
modification via dnd interface.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
Based on original "kwintheme" (Window Borders)
|
|
|
|
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
|
2007-04-29 17:35:43 +00: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, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
2010-01-19 13:44:22 +00:00
|
|
|
// own
|
2009-12-27 14:59:39 +00:00
|
|
|
#include "kwindecoration.h"
|
2010-01-19 13:44:22 +00:00
|
|
|
#include "buttonsconfigdialog.h"
|
2010-04-23 19:44:50 +00:00
|
|
|
#include "configdialog.h"
|
2010-01-19 13:44:22 +00:00
|
|
|
#include "decorationmodel.h"
|
2012-01-12 10:28:02 +00:00
|
|
|
#include "auroraetheme.h"
|
2013-10-09 05:26:12 +00:00
|
|
|
#include "preview.h"
|
2010-01-19 13:44:22 +00:00
|
|
|
// Qt
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QScrollBar>
|
2012-08-25 07:54:20 +00:00
|
|
|
#include <QUiLoader>
|
2013-08-03 20:34:58 +00:00
|
|
|
#include <QtCore/QStandardPaths>
|
2013-10-01 10:30:38 +00:00
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QQuickView>
|
2010-01-19 13:44:22 +00:00
|
|
|
// KDE
|
|
|
|
#include <KAboutData>
|
2013-10-01 06:03:28 +00:00
|
|
|
#include <kconfigloader.h>
|
2010-01-19 13:44:22 +00:00
|
|
|
#include <KDialog>
|
2013-03-07 11:55:39 +00:00
|
|
|
#include <KDE/KLocalizedString>
|
2012-08-17 11:19:21 +00:00
|
|
|
#include <KMessageBox>
|
2010-01-19 13:44:22 +00:00
|
|
|
#include <KNS3/DownloadDialog>
|
2012-08-25 07:54:20 +00:00
|
|
|
#include <KDE/KConfigDialogManager>
|
2007-08-28 12:42:05 +00:00
|
|
|
#include <KPluginFactory>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// KCModule plugin interface
|
|
|
|
// =========================
|
2007-08-28 12:42:05 +00:00
|
|
|
K_PLUGIN_FACTORY(KWinDecoFactory,
|
2011-01-30 14:34:42 +00:00
|
|
|
registerPlugin<KWin::KWinDecorationModule>();
|
|
|
|
)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWinDecorationForm::KWinDecorationForm(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
2010-01-19 13:44:22 +00:00
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
setupUi(this);
|
2010-01-19 13:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-28 12:42:05 +00:00
|
|
|
KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList &)
|
2013-10-01 06:12:38 +00:00
|
|
|
: KCModule(parent)
|
2010-01-19 13:44:22 +00:00
|
|
|
, kwinConfig(KSharedConfig::openConfig("kwinrc"))
|
2011-01-30 14:34:42 +00:00
|
|
|
, m_showTooltips(false)
|
2012-11-26 09:05:17 +00:00
|
|
|
, m_model(NULL)
|
|
|
|
, m_proxyModel(NULL)
|
2011-01-30 14:34:42 +00:00
|
|
|
, m_configLoaded(false)
|
2012-01-13 10:48:04 +00:00
|
|
|
, m_decorationButtons(new DecorationButtons(this))
|
2013-10-01 10:30:38 +00:00
|
|
|
, m_listView(new QQuickView())
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2012-01-12 10:28:02 +00:00
|
|
|
qmlRegisterType<Aurorae::AuroraeTheme>("org.kde.kwin.aurorae", 0, 1, "AuroraeTheme");
|
2013-10-09 05:26:12 +00:00
|
|
|
qmlRegisterType<PreviewItem>("org.kde.kwin.kcmdecoration", 0, 1, "PreviewItem");
|
2011-01-30 14:34:42 +00:00
|
|
|
m_ui = new KWinDecorationForm(this);
|
2013-10-01 06:05:23 +00:00
|
|
|
m_ui->configureDecorationButton->setIcon(QIcon::fromTheme("configure"));
|
|
|
|
m_ui->configureButtonsButton->setIcon(QIcon::fromTheme("configure"));
|
|
|
|
m_ui->ghnsButton->setIcon(QIcon::fromTheme("get-hot-new-stuff"));
|
2013-10-01 10:30:38 +00:00
|
|
|
QWidget *container = QWidget::createWindowContainer(m_listView.data(), m_ui->decorationList->viewport());
|
|
|
|
QVBoxLayout *containerLayout = new QVBoxLayout(m_ui->decorationList->viewport());
|
|
|
|
containerLayout->addWidget(container);
|
2011-01-30 14:34:42 +00:00
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
layout->addWidget(m_ui);
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2012-11-26 09:05:17 +00:00
|
|
|
KAboutData *about =
|
2013-10-01 06:05:47 +00:00
|
|
|
new KAboutData(i18n("kcmkwindecoration"), QString(),
|
|
|
|
i18n("Window Decoration Control Module"),
|
|
|
|
QString(), QString(), KAboutData::License_GPL,
|
|
|
|
i18n("(c) 2001 Karol Szwed"));
|
|
|
|
about->addAuthor(i18n("Karol Szwed"), QString(), "gallium@kde.org");
|
2012-11-26 09:05:17 +00:00
|
|
|
setAboutData(about);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KWinDecorationModule::~KWinDecorationModule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::showEvent(QShowEvent *ev)
|
|
|
|
{
|
|
|
|
KCModule::showEvent(ev);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::init()
|
|
|
|
{
|
|
|
|
if (m_model) {
|
|
|
|
// init already called
|
|
|
|
return;
|
|
|
|
}
|
2013-08-03 20:34:58 +00:00
|
|
|
const QString mainQmlPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/kcm_kwindecoration/main.qml");
|
2012-11-26 09:05:17 +00:00
|
|
|
if (mainQmlPath.isNull()) {
|
|
|
|
// TODO 4.11 i18n this
|
|
|
|
KMessageBox::error(this, "<h1>Installation error</h1>"
|
|
|
|
"The resource<h2>kwin/kcm_kwindecoration/main.qml</h2>could not be located in any application data path."
|
|
|
|
"<h2>Please contact your distribution</h2>"
|
|
|
|
"The application will now abort", "Installation Error");
|
|
|
|
abort();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfigGroup style(kwinConfig, "Style");
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
// Set up the decoration lists and other UI settings
|
2011-01-30 14:34:42 +00:00
|
|
|
m_model = new DecorationModel(kwinConfig, this);
|
|
|
|
m_proxyModel = new QSortFilterProxyModel(this);
|
|
|
|
m_proxyModel->setSourceModel(m_model);
|
|
|
|
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2013-10-01 10:30:38 +00:00
|
|
|
|
|
|
|
m_listView->setResizeMode(QQuickView::SizeRootObjectToView);
|
|
|
|
m_listView->rootContext()->setContextProperty("decorationModel", m_proxyModel);
|
|
|
|
m_listView->rootContext()->setContextProperty("decorationBaseModel", m_model);
|
|
|
|
m_listView->rootContext()->setContextProperty("options", m_decorationButtons);
|
|
|
|
m_listView->rootContext()->setContextProperty("highlightColor", m_ui->decorationList->palette().color(QPalette::Highlight));
|
|
|
|
m_listView->rootContext()->setContextProperty("auroraeSource", QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/aurorae/aurorae.qml"));
|
|
|
|
m_listView->rootContext()->setContextProperty("decorationActiveCaptionColor", KDecoration::options()->color(ColorFont, true));
|
|
|
|
m_listView->rootContext()->setContextProperty("decorationInactiveCaptionColor", KDecoration::options()->color(ColorFont, false));
|
|
|
|
m_listView->rootContext()->setContextProperty("decorationActiveTitleBarColor", KDecoration::options()->color(ColorTitleBar, true));
|
|
|
|
m_listView->rootContext()->setContextProperty("decorationInactiveTitleBarColor", KDecoration::options()->color(ColorTitleBar, false));
|
|
|
|
m_listView->setSource(QUrl::fromLocalFile(mainQmlPath));
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
readConfig(style);
|
|
|
|
|
2013-10-01 10:30:38 +00:00
|
|
|
connect(m_listView->rootObject(), SIGNAL(currentIndexChanged()), SLOT(slotSelectionChanged()));
|
2011-01-30 14:34:42 +00:00
|
|
|
connect(m_ui->configureButtonsButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureButtons()));
|
|
|
|
connect(m_ui->ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNSClicked()));
|
|
|
|
connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString)));
|
2013-10-01 10:30:38 +00:00
|
|
|
connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), m_listView->rootObject(), SLOT(returnToBounds()), Qt::QueuedConnection);
|
2013-04-09 16:50:19 +00:00
|
|
|
connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), SLOT(updateScrollbarRange()), Qt::QueuedConnection);
|
2011-01-30 14:34:42 +00:00
|
|
|
connect(m_ui->configureDecorationButton, SIGNAL(clicked(bool)), SLOT(slotConfigureDecoration()));
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-05-22 17:32:53 +00:00
|
|
|
m_ui->decorationList->disconnect(m_ui->decorationList->verticalScrollBar());
|
|
|
|
m_ui->decorationList->verticalScrollBar()->disconnect(m_ui->decorationList);
|
2013-10-01 10:30:38 +00:00
|
|
|
connect(m_listView->rootObject(), SIGNAL(contentYChanged()), SLOT(updateScrollbarValue()));
|
|
|
|
connect(m_listView->rootObject(), SIGNAL(contentHeightChanged()), SLOT(updateScrollbarRange()));
|
2013-05-11 12:09:15 +00:00
|
|
|
connect(m_ui->decorationList->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), SLOT(updateScrollbarRange()));
|
2012-05-22 17:32:53 +00:00
|
|
|
connect(m_ui->decorationList->verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(updateViewPosition(int)));
|
|
|
|
|
|
|
|
m_ui->decorationList->installEventFilter(this);
|
2012-08-08 17:52:38 +00:00
|
|
|
m_ui->decorationList->viewport()->installEventFilter(this);
|
2012-05-24 20:22:50 +00:00
|
|
|
QMetaObject::invokeMethod(this, "updatePreviews", Qt::QueuedConnection);
|
2012-11-26 09:05:17 +00:00
|
|
|
updateScrollbarRange();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is the selection handler setting
|
|
|
|
void KWinDecorationModule::slotSelectionChanged()
|
|
|
|
{
|
2010-01-19 13:56:57 +00:00
|
|
|
emit KCModule::changed(true);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reads the kwin config settings, and sets all UI controls to those settings
|
|
|
|
// Updating the config plugin if required
|
2011-01-30 14:34:42 +00:00
|
|
|
void KWinDecorationModule::readConfig(const KConfigGroup & conf)
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2010-01-19 13:44:22 +00:00
|
|
|
m_showTooltips = conf.readEntry("ShowToolTips", true);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// Find the corresponding decoration name to that of
|
|
|
|
// the current plugin library name
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-10-12 06:25:22 +00:00
|
|
|
QString libraryName = conf.readEntry("PluginLib", "kwin3_oxygen");
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (libraryName.isEmpty()) {
|
|
|
|
// Selected decoration doesn't exist, use the default
|
2012-10-12 06:25:22 +00:00
|
|
|
libraryName = "kwin3_oxygen";
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
const int bsize = conf.readEntry("BorderSize", (int)BorderNormal);
|
2010-01-19 13:44:22 +00:00
|
|
|
BorderSize borderSize = BorderNormal;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (bsize >= BorderTiny && bsize < BordersCount)
|
|
|
|
borderSize = static_cast< BorderSize >(bsize);
|
|
|
|
if (libraryName == "kwin3_aurorae") {
|
|
|
|
KConfig auroraeConfig("auroraerc");
|
|
|
|
KConfigGroup group(&auroraeConfig, "Engine");
|
|
|
|
const QString themeName = group.readEntry("ThemeName", "example-deco");
|
2012-07-27 08:10:28 +00:00
|
|
|
const QString type = group.readEntry("EngineType", "aurorae");
|
|
|
|
const QModelIndex index = m_proxyModel->mapFromSource(m_model->indexOfAuroraeName(themeName, type));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index.isValid()) {
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("currentIndex", index.row());
|
2010-01-19 13:44:22 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
const QModelIndex index = m_proxyModel->mapFromSource(m_model->indexOfLibrary(libraryName));
|
|
|
|
if (index.isValid()) {
|
|
|
|
m_model->setBorderSize(index, borderSize);
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("currentIndex", index.row());
|
2010-01-19 13:44:22 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// Buttons tab
|
|
|
|
// ============
|
2012-01-13 10:48:04 +00:00
|
|
|
m_decorationButtons->setCustomPositions(conf.readEntry("CustomButtonPositions", false));
|
2010-01-19 13:56:57 +00:00
|
|
|
// Menu and onAllDesktops buttons are default on LHS
|
2012-01-13 10:48:04 +00:00
|
|
|
m_decorationButtons->setLeftButtons(conf.readEntry("ButtonsOnLeft", KDecorationOptions::defaultTitleButtonsLeft()));
|
2010-01-19 13:56:57 +00:00
|
|
|
// Help, Minimize, Maximize and Close are default on RHS
|
2012-01-13 10:48:04 +00:00
|
|
|
m_decorationButtons->setRightButtons(conf.readEntry("ButtonsOnRight", KDecorationOptions::defaultTitleButtonsRight()));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_configLoaded)
|
2012-01-13 10:48:04 +00:00
|
|
|
m_model->changeButtons(m_decorationButtons);
|
2011-01-30 14:34:42 +00:00
|
|
|
else {
|
2010-01-19 13:44:22 +00:00
|
|
|
m_configLoaded = true;
|
2012-01-13 10:48:04 +00:00
|
|
|
m_model->setButtons(m_decorationButtons->customPositions(), m_decorationButtons->leftButtons(), m_decorationButtons->rightButtons());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
emit KCModule::changed(false);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Writes the selected user configuration to the kwin config file
|
2011-01-30 14:34:42 +00:00
|
|
|
void KWinDecorationModule::writeConfig(KConfigGroup & conf)
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2013-10-01 10:30:38 +00:00
|
|
|
const QModelIndex index = m_proxyModel->mapToSource(m_proxyModel->index(m_listView->rootObject()->property("currentIndex").toInt(), 0));
|
2011-01-30 14:34:42 +00:00
|
|
|
const QString libName = m_model->data(index, DecorationModel::LibraryNameRole).toString();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// General settings
|
|
|
|
conf.writeEntry("PluginLib", libName);
|
2012-01-13 10:48:04 +00:00
|
|
|
conf.writeEntry("CustomButtonPositions", m_decorationButtons->customPositions());
|
2011-01-30 14:34:42 +00:00
|
|
|
conf.writeEntry("ShowToolTips", m_showTooltips);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// Button settings
|
2012-01-13 10:48:04 +00:00
|
|
|
conf.writeEntry("ButtonsOnLeft", m_decorationButtons->leftButtons());
|
|
|
|
conf.writeEntry("ButtonsOnRight", m_decorationButtons->rightButtons());
|
2011-01-30 14:34:42 +00:00
|
|
|
conf.writeEntry("BorderSize",
|
|
|
|
static_cast<int>(m_model->data(index, DecorationModel::BorderSizeRole).toInt()));
|
|
|
|
|
2012-07-27 08:10:28 +00:00
|
|
|
if (m_model->data(index, DecorationModel::TypeRole).toInt() == DecorationModelData::AuroraeDecoration ||
|
|
|
|
m_model->data(index, DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration) {
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfig auroraeConfig("auroraerc");
|
|
|
|
KConfigGroup group(&auroraeConfig, "Engine");
|
|
|
|
group.writeEntry("ThemeName", m_model->data(index, DecorationModel::AuroraeNameRole).toString());
|
2012-07-27 08:10:28 +00:00
|
|
|
if (m_model->data(index, DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration) {
|
|
|
|
group.writeEntry("EngineType", "qml");
|
|
|
|
} else {
|
|
|
|
group.deleteEntry("EngineType");
|
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
group.sync();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:56:57 +00:00
|
|
|
// We saved, so tell kcmodule that there have been no new user changes made.
|
|
|
|
emit KCModule::changed(false);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Virutal functions required by KCModule
|
|
|
|
void KWinDecorationModule::load()
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
const KConfigGroup config(kwinConfig, "Style");
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
// Reset by re-reading the config
|
2011-01-30 14:34:42 +00:00
|
|
|
readConfig(config);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinDecorationModule::save()
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfigGroup config(kwinConfig, "Style");
|
|
|
|
writeConfig(config);
|
2010-01-19 13:44:22 +00:00
|
|
|
config.sync();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-04-30 11:32:47 +00:00
|
|
|
// Send signal to all kwin instances
|
|
|
|
QDBusMessage message =
|
2008-01-30 16:08:23 +00:00
|
|
|
QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
|
2007-04-30 11:32:47 +00:00
|
|
|
QDBusConnection::sessionBus().send(message);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KWinDecorationModule::defaults()
|
|
|
|
{
|
2010-01-19 13:56:57 +00:00
|
|
|
// Set the KDE defaults
|
2010-01-19 13:44:22 +00:00
|
|
|
m_showTooltips = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
const QModelIndex index = m_proxyModel->mapFromSource(m_model->indexOfName(i18n("Oxygen")));
|
|
|
|
if (index.isValid())
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("currentIndex", index.row());
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-01-13 10:48:04 +00:00
|
|
|
m_decorationButtons->resetToDefaults();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-01-13 10:48:04 +00:00
|
|
|
m_model->changeButtons(m_decorationButtons);
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
emit changed(true);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString KWinDecorationModule::quickHelp() const
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
return i18n("<h1>Window Manager Decoration</h1>"
|
|
|
|
"<p>This module allows you to choose the window border decorations, "
|
|
|
|
"as well as titlebar button positions and custom decoration options.</p>"
|
|
|
|
"To choose a theme for your window decoration click on its name and apply your choice by clicking the \"Apply\" button below."
|
|
|
|
" If you do not want to apply your choice you can click the \"Reset\" button to discard your changes."
|
|
|
|
"<p>You can configure each theme. There are different options specific for each theme.</p>"
|
|
|
|
"<p>On the \"Buttons\" tab check the \"Use custom titlebar button positions\" box "
|
|
|
|
"and you can change the positions of the buttons to your liking.</p>");
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
void KWinDecorationModule::slotConfigureButtons()
|
|
|
|
{
|
2012-01-13 10:48:04 +00:00
|
|
|
QPointer< KWinDecorationButtonsConfigDialog > configDialog = new KWinDecorationButtonsConfigDialog(m_decorationButtons, m_showTooltips, this);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (configDialog->exec() == KDialog::Accepted) {
|
2012-01-13 10:48:04 +00:00
|
|
|
m_decorationButtons->setCustomPositions(configDialog->customPositions());
|
2010-01-19 13:44:22 +00:00
|
|
|
m_showTooltips = configDialog->showTooltips();
|
2012-01-13 10:48:04 +00:00
|
|
|
m_decorationButtons->setLeftButtons(configDialog->buttonsLeft());
|
|
|
|
m_decorationButtons->setRightButtons(configDialog->buttonsRight());
|
|
|
|
m_model->changeButtons(m_decorationButtons);
|
2011-01-30 14:34:42 +00:00
|
|
|
emit changed(true);
|
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
|
|
|
delete configDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::slotGHNSClicked()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
QPointer<KNS3::DownloadDialog> downloadDialog = new KNS3::DownloadDialog("aurorae.knsrc", this);
|
|
|
|
if (downloadDialog->exec() == KDialog::Accepted) {
|
|
|
|
if (!downloadDialog->changedEntries().isEmpty()) {
|
2013-10-01 10:30:38 +00:00
|
|
|
const QModelIndex index = m_proxyModel->mapToSource(m_proxyModel->index(m_listView->rootObject()->property("currentIndex").toInt(), 0));
|
2011-01-30 14:34:42 +00:00
|
|
|
const QString libraryName = m_model->data(index, DecorationModel::LibraryNameRole).toString();
|
|
|
|
bool aurorae = m_model->data(index, DecorationModel::TypeRole).toInt() == DecorationModelData::AuroraeDecoration;
|
2012-07-27 08:10:28 +00:00
|
|
|
bool qml = m_model->data(index, DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration;
|
2011-01-30 14:34:42 +00:00
|
|
|
const QString auroraeName = m_model->data(index, DecorationModel::AuroraeNameRole).toString();
|
2010-01-19 13:44:22 +00:00
|
|
|
m_model->reload();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (aurorae) {
|
2012-07-27 08:10:28 +00:00
|
|
|
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(m_model->indexOfAuroraeName(auroraeName, "aurorae"));
|
|
|
|
if (proxyIndex.isValid())
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("currentIndex", proxyIndex.row());
|
2012-07-27 08:10:28 +00:00
|
|
|
} else if (qml) {
|
|
|
|
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(m_model->indexOfAuroraeName(auroraeName, "qml"));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (proxyIndex.isValid())
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("currentIndex", proxyIndex.row());
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(m_model->indexOfLibrary(libraryName));
|
|
|
|
if (proxyIndex.isValid())
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("currentIndex", proxyIndex.row());
|
2010-01-19 13:44:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
delete downloadDialog;
|
|
|
|
}
|
2010-01-19 13:44:22 +00:00
|
|
|
|
2010-04-23 19:44:50 +00:00
|
|
|
void KWinDecorationModule::slotConfigureDecoration()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-10-01 10:30:38 +00:00
|
|
|
const QModelIndex index = m_proxyModel->mapToSource(m_proxyModel->index(m_listView->rootObject()->property("currentIndex").toInt(), 0));
|
2010-04-23 19:44:50 +00:00
|
|
|
bool reload = false;
|
2012-07-29 09:20:48 +00:00
|
|
|
if (index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::AuroraeDecoration ||
|
|
|
|
index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration) {
|
2011-01-30 14:34:42 +00:00
|
|
|
QPointer< KDialog > dlg = new KDialog(this);
|
|
|
|
dlg->setCaption(i18n("Decoration Options"));
|
|
|
|
dlg->setButtons(KDialog::Ok | KDialog::Cancel);
|
|
|
|
KWinAuroraeConfigForm *form = new KWinAuroraeConfigForm(dlg);
|
2013-01-04 13:02:44 +00:00
|
|
|
form->enableNoSideBorderSupport(index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration);
|
2011-01-30 14:34:42 +00:00
|
|
|
dlg->setMainWidget(form);
|
|
|
|
form->borderSizesCombo->setCurrentIndex(index.data(DecorationModel::BorderSizeRole).toInt());
|
|
|
|
form->buttonSizesCombo->setCurrentIndex(index.data(DecorationModel::ButtonSizeRole).toInt());
|
2012-08-24 13:16:30 +00:00
|
|
|
form->closeWindowsDoubleClick->setChecked(index.data(DecorationModel::CloseOnDblClickRole).toBool());
|
2012-08-25 07:54:20 +00:00
|
|
|
// in case of QmlDecoration look for a config.ui in the package structure
|
|
|
|
KConfigDialogManager *configManager = NULL;
|
|
|
|
if (index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration) {
|
|
|
|
const QString packageName = index.data(DecorationModel::AuroraeNameRole).toString();
|
2013-08-03 20:34:58 +00:00
|
|
|
const QString uiPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/decorations/" + packageName + "/contents/ui/config.ui");
|
|
|
|
const QString configPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kwin/decorations/" + packageName + "/contents/config/main.xml");
|
2012-08-25 07:54:20 +00:00
|
|
|
if (!uiPath.isEmpty() && !configPath.isEmpty()) {
|
|
|
|
// load the KConfigSkeleton
|
|
|
|
QFile configFile(configPath);
|
|
|
|
KSharedConfigPtr auroraeConfig = KSharedConfig::openConfig("auroraerc");
|
|
|
|
KConfigGroup configGroup = auroraeConfig->group(packageName);
|
2013-10-01 06:03:28 +00:00
|
|
|
KConfigLoader *skeleton = new KConfigLoader(configGroup, &configFile, dlg);
|
2012-08-25 07:54:20 +00:00
|
|
|
// load the ui file
|
|
|
|
QUiLoader *loader = new QUiLoader(dlg);
|
|
|
|
QFile uiFile(uiPath);
|
|
|
|
uiFile.open(QFile::ReadOnly);
|
|
|
|
QWidget *customConfigForm = loader->load(&uiFile, form);
|
|
|
|
uiFile.close();
|
|
|
|
form->layout()->addWidget(customConfigForm);
|
|
|
|
// connect the ui file with the skeleton
|
|
|
|
configManager = new KConfigDialogManager(customConfigForm, skeleton);
|
|
|
|
configManager->updateWidgets();
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (dlg->exec() == KDialog::Accepted) {
|
|
|
|
m_model->setData(index, form->borderSizesCombo->currentIndex(), DecorationModel::BorderSizeRole);
|
|
|
|
m_model->setData(index, form->buttonSizesCombo->currentIndex(), DecorationModel::ButtonSizeRole);
|
2012-08-24 13:16:30 +00:00
|
|
|
m_model->setData(index, form->closeWindowsDoubleClick->isChecked(), DecorationModel::CloseOnDblClickRole);
|
2012-08-25 07:54:20 +00:00
|
|
|
if (configManager && configManager->hasChanged()) {
|
|
|
|
// we have a config manager and the settings changed
|
|
|
|
configManager->updateSettings();
|
|
|
|
m_model->notifyConfigChanged(index);
|
|
|
|
}
|
2010-04-23 19:44:50 +00:00
|
|
|
reload = true;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
delete dlg;
|
|
|
|
} else {
|
|
|
|
QString name = index.data(DecorationModel::LibraryNameRole).toString();
|
|
|
|
QList< QVariant > borderSizes = index.data(DecorationModel::BorderSizesRole).toList();
|
2010-04-23 19:44:50 +00:00
|
|
|
const KDecorationDefines::BorderSize size =
|
2011-01-30 14:34:42 +00:00
|
|
|
static_cast<KDecorationDefines::BorderSize>(index.data(DecorationModel::BorderSizeRole).toInt());
|
2010-04-23 19:44:50 +00:00
|
|
|
QPointer< KWinDecorationConfigDialog > configDialog =
|
2011-01-30 14:34:42 +00:00
|
|
|
new KWinDecorationConfigDialog(name, borderSizes, size, this);
|
|
|
|
if (configDialog->exec() == KDialog::Accepted) {
|
|
|
|
m_model->setData(index, configDialog->borderSize(), DecorationModel::BorderSizeRole);
|
2010-04-23 19:44:50 +00:00
|
|
|
reload = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-23 19:44:50 +00:00
|
|
|
|
|
|
|
delete configDialog;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (reload) {
|
2013-10-13 13:52:01 +00:00
|
|
|
save();
|
2010-04-23 19:44:50 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-23 19:44:50 +00:00
|
|
|
|
2012-05-22 17:32:53 +00:00
|
|
|
bool KWinDecorationModule::eventFilter(QObject *o, QEvent *e)
|
|
|
|
{
|
2012-06-07 11:57:23 +00:00
|
|
|
if (o == m_ui->decorationList) {
|
|
|
|
if (e->type() == QEvent::Resize)
|
|
|
|
updateScrollbarRange();
|
|
|
|
else if (e->type() == QEvent::KeyPress) {
|
|
|
|
int d = 0;
|
2013-10-01 10:30:38 +00:00
|
|
|
const int currentRow = m_listView->rootObject()->property("currentIndex").toInt();
|
2012-06-07 11:57:23 +00:00
|
|
|
const int key = static_cast<QKeyEvent*>(e)->key();
|
|
|
|
switch (key) {
|
|
|
|
case Qt::Key_Home:
|
|
|
|
d = -currentRow;
|
|
|
|
break;
|
|
|
|
case Qt::Key_End:
|
|
|
|
d = m_proxyModel->rowCount() - (1 + currentRow);
|
|
|
|
break;
|
|
|
|
case Qt::Key_Up:
|
|
|
|
d = -1;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
d = 1;
|
|
|
|
break;
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
d = 150;
|
2013-10-01 10:30:38 +00:00
|
|
|
if (QObject *decoItem = m_listView->rootObject()->findChild<QObject*>("decorationItem")) {
|
2012-06-07 11:57:23 +00:00
|
|
|
QVariant v = decoItem->property("height");
|
|
|
|
if (v.isValid())
|
|
|
|
d = v.toInt();
|
|
|
|
}
|
|
|
|
if (d > 0)
|
|
|
|
d = qMax(m_ui->decorationList->height() / d, 1);
|
|
|
|
if (key == Qt::Key_PageUp)
|
|
|
|
d = -d;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (d) {
|
|
|
|
d = qMin(qMax(0, currentRow + d), m_proxyModel->rowCount());
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("currentIndex", d);
|
2012-06-07 11:57:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-08-08 17:52:38 +00:00
|
|
|
} else if (m_ui->decorationList->viewport()) {
|
|
|
|
if (e->type() == QEvent::Wheel) {
|
|
|
|
return static_cast<QWheelEvent*>(e)->orientation() == Qt::Horizontal;
|
|
|
|
}
|
2012-06-07 11:57:23 +00:00
|
|
|
}
|
2012-05-22 17:32:53 +00:00
|
|
|
return KCModule::eventFilter(o, e);
|
|
|
|
}
|
2012-05-24 20:22:50 +00:00
|
|
|
|
2012-05-22 17:32:53 +00:00
|
|
|
void KWinDecorationModule::updateScrollbarRange()
|
|
|
|
{
|
|
|
|
m_ui->decorationList->verticalScrollBar()->blockSignals(true);
|
2013-10-01 10:30:38 +00:00
|
|
|
const bool atMinimum = m_listView->rootObject()->property("atYBeginning").toBool();
|
|
|
|
const int h = m_listView->rootObject()->property("contentHeight").toInt();
|
|
|
|
const int y = atMinimum ? m_listView->rootObject()->property("contentY").toInt() : 0;
|
2013-04-09 16:50:19 +00:00
|
|
|
m_ui->decorationList->verticalScrollBar()->setRange(y, y + h - m_ui->decorationList->height());
|
2012-05-22 17:32:53 +00:00
|
|
|
m_ui->decorationList->verticalScrollBar()->setPageStep(m_ui->decorationList->verticalScrollBar()->maximum()/m_model->rowCount());
|
|
|
|
m_ui->decorationList->verticalScrollBar()->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::updateScrollbarValue()
|
|
|
|
{
|
2013-10-01 10:30:38 +00:00
|
|
|
const int v = m_listView->rootObject()->property("contentY").toInt();
|
2012-05-22 17:32:53 +00:00
|
|
|
m_ui->decorationList->verticalScrollBar()->blockSignals(true); // skippig this will kill kinetic scrolling but the scrollwidth is too low
|
|
|
|
m_ui->decorationList->verticalScrollBar()->setValue(v);
|
|
|
|
m_ui->decorationList->verticalScrollBar()->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinDecorationModule::updateViewPosition(int v)
|
|
|
|
{
|
2013-10-01 10:30:38 +00:00
|
|
|
m_listView->rootObject()->setProperty("contentY", v);
|
2012-05-22 17:32:53 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 10:48:04 +00:00
|
|
|
DecorationButtons::DecorationButtons(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_customPositions(false)
|
|
|
|
, m_leftButtons(KDecorationOptions::defaultTitleButtonsLeft())
|
|
|
|
, m_rightButtons(KDecorationOptions::defaultTitleButtonsRight())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DecorationButtons::~DecorationButtons()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DecorationButtons::customPositions() const
|
|
|
|
{
|
|
|
|
return m_customPositions;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &DecorationButtons::leftButtons() const
|
|
|
|
{
|
|
|
|
return m_leftButtons;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &DecorationButtons::rightButtons() const
|
|
|
|
{
|
|
|
|
return m_rightButtons;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecorationButtons::setCustomPositions(bool set)
|
|
|
|
{
|
|
|
|
if (m_customPositions == set) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_customPositions = set;
|
|
|
|
emit customPositionsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecorationButtons::setLeftButtons(const QString &leftButtons)
|
|
|
|
{
|
|
|
|
if (m_leftButtons == leftButtons) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_leftButtons = leftButtons;
|
|
|
|
emit leftButtonsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecorationButtons::setRightButtons (const QString &rightButtons)
|
|
|
|
{
|
|
|
|
if (m_rightButtons == rightButtons) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_rightButtons = rightButtons;
|
|
|
|
emit rightButtonsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecorationButtons::resetToDefaults()
|
|
|
|
{
|
|
|
|
setCustomPositions(false);
|
|
|
|
setLeftButtons(KDecorationOptions::defaultTitleButtonsLeft());
|
|
|
|
setRightButtons(KDecorationOptions::defaultTitleButtonsRight());
|
|
|
|
}
|
|
|
|
|
2010-01-19 13:44:22 +00:00
|
|
|
} // namespace KWin
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "kwindecoration.moc"
|