kwin/kcmkwin/kwindecoration/utils.cpp
Valerio Pilo 8350c0f2ce [kcmkwin/kwindecoration] Rewrite the KWin decorations settings as a ConfigModule
Summary:
* Wrote new KCM based on KQuickAddons::ConfigModule.
* Remade QMLs for Buttons and Themes tabs.
* Updated bridge model code for new plugin lookup API (fixes warnings).
* Fixed decoration shadow changing messing with the previews sizes.
* Fixed button drag and drop issues (see D18104).
* Fixed default settings button behavior and detection of settings changes.
* Updated Get Hot New Stuff.
* Removed apply button in previewbridge.cpp: After applying changes, a theme's KCModule is invalidated.

BUG: 389431
BUG: 350122
BUG: 346222
BUG: 342816
BUG: 397595

{F6574963} | {F6574962} | {F6574961} | {F6574960}

Test Plan:
* Verified saving and loading for every setting
* Checked shadows of Breeze and Oxygen
* Tested all possible drag&drop operations on both sides of the fake titlebar
* Changed color schemes (with `kcmshell5 colors`) while showing the Themes tab to see if all previews update correctly their palettes
* Tested on a fresh Neon-developer account, via kcmshell and systemsettings

Reviewers: #vdg, abetts, ngraham, #kwin, davidedmundson

Reviewed By: #vdg, #kwin, davidedmundson

Subscribers: zzag, GB_2, ngraham, broulik, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D18458
2019-02-10 13:01:04 +01:00

119 lines
4.5 KiB
C++

/*
* Copyright (c) 2019 Valerio Pilo <vpilo@coldshock.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "utils.h"
#include <KConfigGroup>
#include <KLocalizedString>
namespace
{
const QMap<QString, KDecoration2::BorderSize> s_borderSizes {
{ QStringLiteral("None"), KDecoration2::BorderSize::None },
{ QStringLiteral("NoSides"), KDecoration2::BorderSize::NoSides },
{ QStringLiteral("Tiny"), KDecoration2::BorderSize::Tiny },
{ QStringLiteral("Normal"), KDecoration2::BorderSize::Normal },
{ QStringLiteral("Large"), KDecoration2::BorderSize::Large },
{ QStringLiteral("VeryLarge"), KDecoration2::BorderSize::VeryLarge },
{ QStringLiteral("Huge"), KDecoration2::BorderSize::Huge },
{ QStringLiteral("VeryHuge"), KDecoration2::BorderSize::VeryHuge },
{ QStringLiteral("Oversized"), KDecoration2::BorderSize::Oversized }
};
const QMap<KDecoration2::BorderSize, QString> s_borderSizeNames {
{ KDecoration2::BorderSize::None, i18n("No Borders") },
{ KDecoration2::BorderSize::NoSides, i18n("No Side Borders") },
{ KDecoration2::BorderSize::Tiny, i18n("Tiny") },
{ KDecoration2::BorderSize::Normal, i18n("Normal") },
{ KDecoration2::BorderSize::Large, i18n("Large") },
{ KDecoration2::BorderSize::VeryLarge, i18n("Very Large") },
{ KDecoration2::BorderSize::Huge, i18n("Huge") },
{ KDecoration2::BorderSize::VeryHuge, i18n("Very Huge") },
{ KDecoration2::BorderSize::Oversized, i18n("Oversized") }
};
const QHash<KDecoration2::DecorationButtonType, QChar> s_buttonNames {
{KDecoration2::DecorationButtonType::Menu, QChar('M') },
{KDecoration2::DecorationButtonType::ApplicationMenu, QChar('N') },
{KDecoration2::DecorationButtonType::OnAllDesktops, QChar('S') },
{KDecoration2::DecorationButtonType::ContextHelp, QChar('H') },
{KDecoration2::DecorationButtonType::Minimize, QChar('I') },
{KDecoration2::DecorationButtonType::Maximize, QChar('A') },
{KDecoration2::DecorationButtonType::Close, QChar('X') },
{KDecoration2::DecorationButtonType::KeepAbove, QChar('F') },
{KDecoration2::DecorationButtonType::KeepBelow, QChar('B') },
{KDecoration2::DecorationButtonType::Shade, QChar('L') }
};
}
namespace Utils
{
QString buttonsToString(const DecorationButtonsList &buttons)
{
auto buttonToString = [](KDecoration2::DecorationButtonType button) -> QChar {
const auto it = s_buttonNames.constFind(button);
if (it != s_buttonNames.constEnd()) {
return it.value();
}
return QChar();
};
QString ret;
for (auto button : buttons) {
ret.append(buttonToString(button));
}
return ret;
}
DecorationButtonsList readDecorationButtons(const KConfigGroup &config, const QString &key, const DecorationButtonsList &defaultValue)
{
auto buttonsFromString = [](const QString &buttons) -> DecorationButtonsList {
DecorationButtonsList ret;
for (auto it = buttons.begin(); it != buttons.end(); ++it) {
for (auto it2 = s_buttonNames.constBegin(); it2 != s_buttonNames.constEnd(); ++it2) {
if (it2.value() == (*it)) {
ret << it2.key();
}
}
}
return ret;
};
return buttonsFromString(config.readEntry(key, buttonsToString(defaultValue)));
}
KDecoration2::BorderSize stringToBorderSize(const QString &name)
{
auto it = s_borderSizes.constFind(name);
if (it == s_borderSizes.constEnd()) {
// non sense values are interpreted just like normal
return KDecoration2::BorderSize::Normal;
}
return it.value();
}
QString borderSizeToString(KDecoration2::BorderSize size)
{
return s_borderSizes.key(size);
}
const QMap<KDecoration2::BorderSize, QString> &getBorderSizeNames()
{
return s_borderSizeNames;
}
} // namespace Utils