2014-12-09 15:07:27 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
2014-12-09 15:07:27 +00:00
|
|
|
#include "buttonsmodel.h"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
#include <QFontDatabase>
|
|
|
|
|
|
|
|
namespace KDecoration2
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Preview
|
|
|
|
{
|
|
|
|
|
|
|
|
ButtonsModel::ButtonsModel(const QVector< DecorationButtonType > &buttons, QObject *parent)
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
, m_buttons(buttons)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonsModel::ButtonsModel(QObject* parent)
|
|
|
|
: ButtonsModel(QVector<DecorationButtonType>({
|
|
|
|
DecorationButtonType::Menu,
|
2017-01-11 09:21:03 +00:00
|
|
|
DecorationButtonType::ApplicationMenu,
|
2014-12-09 15:07:27 +00:00
|
|
|
DecorationButtonType::OnAllDesktops,
|
|
|
|
DecorationButtonType::Minimize,
|
|
|
|
DecorationButtonType::Maximize,
|
|
|
|
DecorationButtonType::Close,
|
|
|
|
DecorationButtonType::ContextHelp,
|
|
|
|
DecorationButtonType::Shade,
|
|
|
|
DecorationButtonType::KeepBelow,
|
|
|
|
DecorationButtonType::KeepAbove
|
|
|
|
}), parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonsModel::~ButtonsModel() = default;
|
|
|
|
|
|
|
|
int ButtonsModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if (parent.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return m_buttons.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString buttonToName(DecorationButtonType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case DecorationButtonType::Menu:
|
|
|
|
return i18n("Menu");
|
|
|
|
case DecorationButtonType::ApplicationMenu:
|
|
|
|
return i18n("Application menu");
|
|
|
|
case DecorationButtonType::OnAllDesktops:
|
|
|
|
return i18n("On all desktops");
|
|
|
|
case DecorationButtonType::Minimize:
|
|
|
|
return i18n("Minimize");
|
|
|
|
case DecorationButtonType::Maximize:
|
|
|
|
return i18n("Maximize");
|
|
|
|
case DecorationButtonType::Close:
|
|
|
|
return i18n("Close");
|
|
|
|
case DecorationButtonType::ContextHelp:
|
|
|
|
return i18n("Context help");
|
|
|
|
case DecorationButtonType::Shade:
|
|
|
|
return i18n("Shade");
|
|
|
|
case DecorationButtonType::KeepBelow:
|
|
|
|
return i18n("Keep below");
|
|
|
|
case DecorationButtonType::KeepAbove:
|
|
|
|
return i18n("Keep above");
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ButtonsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid() ||
|
|
|
|
index.row() < 0 ||
|
|
|
|
index.row() >= m_buttons.count() ||
|
|
|
|
index.column() != 0) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return buttonToName(m_buttons.at(index.row()));
|
|
|
|
case Qt::UserRole:
|
|
|
|
return QVariant::fromValue(int(m_buttons.at(index.row())));
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash< int, QByteArray > ButtonsModel::roleNames() const
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roles;
|
|
|
|
roles.insert(Qt::DisplayRole, QByteArrayLiteral("display"));
|
|
|
|
roles.insert(Qt::UserRole, QByteArrayLiteral("button"));
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::remove(int row)
|
|
|
|
{
|
|
|
|
if (row < 0 || row >= m_buttons.count()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
m_buttons.removeAt(row);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::down(int index)
|
|
|
|
{
|
|
|
|
if (m_buttons.count() < 2 || index == m_buttons.count() -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
beginMoveRows(QModelIndex(), index, index, QModelIndex(), index + 2);
|
|
|
|
m_buttons.insert(index +1, m_buttons.takeAt(index));
|
|
|
|
endMoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::up(int index)
|
|
|
|
{
|
|
|
|
if (m_buttons.count() < 2 || index == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
beginMoveRows(QModelIndex(), index, index, QModelIndex(), index -1);
|
|
|
|
m_buttons.insert(index -1, m_buttons.takeAt(index));
|
|
|
|
endMoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::add(DecorationButtonType type)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), m_buttons.count(), m_buttons.count());
|
|
|
|
m_buttons.append(type);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::add(int index, int type)
|
|
|
|
{
|
[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-07 15:32:05 +00:00
|
|
|
beginInsertRows(QModelIndex(), index, index);
|
|
|
|
m_buttons.insert(index, KDecoration2::DecorationButtonType(type));
|
2014-12-09 15:07:27 +00:00
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::move(int sourceIndex, int targetIndex)
|
|
|
|
{
|
|
|
|
if (sourceIndex == qMax(0, targetIndex)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-24 15:57:43 +00:00
|
|
|
|
|
|
|
/* When moving an item down, the destination index needs to be incremented
|
|
|
|
by one, as explained in the documentation:
|
2019-03-25 18:11:15 +00:00
|
|
|
https://doc.qt.io/qt-5/qabstractitemmodel.html#beginMoveRows */
|
2017-03-24 15:57:43 +00:00
|
|
|
if (targetIndex > sourceIndex) {
|
|
|
|
// Row will be moved down
|
|
|
|
beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1);
|
|
|
|
} else {
|
|
|
|
beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), qMax(0, targetIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_buttons.move(sourceIndex, qMax(0, targetIndex));
|
2014-12-09 15:07:27 +00:00
|
|
|
endMoveRows();
|
|
|
|
}
|
|
|
|
|
[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-07 15:32:05 +00:00
|
|
|
void ButtonsModel::clear()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
m_buttons.clear();
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::replace(const QVector< DecorationButtonType > &buttons)
|
|
|
|
{
|
|
|
|
if (buttons.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
beginResetModel();
|
|
|
|
m_buttons = buttons;
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
2014-12-09 15:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|