2014-10-31 06:53:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* 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 "previewsettings.h"
|
|
|
|
#include "previewbridge.h"
|
|
|
|
|
2014-11-03 15:12:54 +00:00
|
|
|
#include <KLocalizedString>
|
|
|
|
|
2014-10-31 06:53:04 +00:00
|
|
|
#include <QFontDatabase>
|
|
|
|
|
|
|
|
namespace KDecoration2
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace Preview
|
|
|
|
{
|
|
|
|
|
2014-12-01 10:53:44 +00:00
|
|
|
ButtonsModel::ButtonsModel(const QVector< DecorationButtonType > &buttons, QObject *parent)
|
2014-10-31 06:53:04 +00:00
|
|
|
: QAbstractListModel(parent)
|
|
|
|
, m_buttons(buttons)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-03 15:12:54 +00:00
|
|
|
ButtonsModel::ButtonsModel(QObject* parent)
|
2014-12-01 10:53:44 +00:00
|
|
|
: ButtonsModel(QVector<DecorationButtonType>({
|
2014-11-03 15:12:54 +00:00
|
|
|
DecorationButtonType::Menu,
|
|
|
|
DecorationButtonType::ApplicationMenu,
|
|
|
|
DecorationButtonType::OnAllDesktops,
|
|
|
|
DecorationButtonType::Minimize,
|
|
|
|
DecorationButtonType::Maximize,
|
|
|
|
DecorationButtonType::Close,
|
2014-11-28 10:27:31 +00:00
|
|
|
DecorationButtonType::ContextHelp,
|
2014-11-03 15:12:54 +00:00
|
|
|
DecorationButtonType::Shade,
|
|
|
|
DecorationButtonType::KeepBelow,
|
|
|
|
DecorationButtonType::KeepAbove
|
|
|
|
}), parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-31 06:53:04 +00:00
|
|
|
ButtonsModel::~ButtonsModel() = default;
|
|
|
|
|
|
|
|
int ButtonsModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if (parent.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return m_buttons.count();
|
|
|
|
}
|
|
|
|
|
2014-11-03 15:12:54 +00:00
|
|
|
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");
|
2014-11-28 10:27:31 +00:00
|
|
|
case DecorationButtonType::ContextHelp:
|
|
|
|
return i18n("Context help");
|
2014-11-03 15:12:54 +00:00
|
|
|
case DecorationButtonType::Shade:
|
|
|
|
return i18n("Shade");
|
|
|
|
case DecorationButtonType::KeepBelow:
|
|
|
|
return i18n("Keep below");
|
|
|
|
case DecorationButtonType::KeepAbove:
|
|
|
|
return i18n("Keep above");
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 06:53:04 +00:00
|
|
|
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:
|
2014-11-03 15:12:54 +00:00
|
|
|
return buttonToName(m_buttons.at(index.row()));
|
2014-10-31 06:53:04 +00:00
|
|
|
case Qt::UserRole:
|
2014-11-03 15:12:54 +00:00
|
|
|
return QVariant::fromValue(int(m_buttons.at(index.row())));
|
2014-10-31 06:53:04 +00:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash< int, QByteArray > ButtonsModel::roleNames() const
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roles;
|
|
|
|
roles.insert(Qt::DisplayRole, QByteArrayLiteral("display"));
|
2014-11-03 15:12:54 +00:00
|
|
|
roles.insert(Qt::UserRole, QByteArrayLiteral("button"));
|
2014-10-31 06:53:04 +00:00
|
|
|
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);
|
2014-12-01 10:53:44 +00:00
|
|
|
m_buttons.insert(index +1, m_buttons.takeAt(index));
|
2014-10-31 06:53:04 +00:00
|
|
|
endMoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::up(int index)
|
|
|
|
{
|
|
|
|
if (m_buttons.count() < 2 || index == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
beginMoveRows(QModelIndex(), index, index, QModelIndex(), index -1);
|
2014-12-01 10:53:44 +00:00
|
|
|
m_buttons.insert(index -1, m_buttons.takeAt(index));
|
2014-10-31 06:53:04 +00:00
|
|
|
endMoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonsModel::add(DecorationButtonType type)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), m_buttons.count(), m_buttons.count());
|
|
|
|
m_buttons.append(type);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
BorderSizesModel::BorderSizesModel(QObject *parent)
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BorderSizesModel::~BorderSizesModel() = default;
|
|
|
|
|
|
|
|
QVariant BorderSizesModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid() || index.row() < 0 || index.row() >= m_borders.count() || index.column() != 0) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
if (role != Qt::DisplayRole && role != Qt::UserRole) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
return QVariant::fromValue<BorderSize>(m_borders.at(index.row()));
|
|
|
|
}
|
|
|
|
|
|
|
|
int BorderSizesModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if (parent.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return m_borders.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash< int, QByteArray > BorderSizesModel::roleNames() const
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roles;
|
|
|
|
roles.insert(Qt::DisplayRole, QByteArrayLiteral("display"));
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewSettings::PreviewSettings(DecorationSettings *parent)
|
|
|
|
: QObject()
|
|
|
|
, DecorationSettingsPrivate(parent)
|
|
|
|
, m_alphaChannelSupported(true)
|
|
|
|
, m_onAllDesktopsAvailable(true)
|
|
|
|
, m_closeOnDoubleClick(false)
|
2014-12-01 10:53:44 +00:00
|
|
|
, m_leftButtons(new ButtonsModel(QVector<DecorationButtonType>({
|
2014-10-31 06:53:04 +00:00
|
|
|
DecorationButtonType::Menu,
|
|
|
|
DecorationButtonType::OnAllDesktops
|
|
|
|
}), this))
|
2014-12-01 10:53:44 +00:00
|
|
|
, m_rightButtons(new ButtonsModel(QVector<DecorationButtonType>({
|
2014-11-28 10:27:31 +00:00
|
|
|
DecorationButtonType::ContextHelp,
|
2014-10-31 06:53:04 +00:00
|
|
|
DecorationButtonType::Minimize,
|
|
|
|
DecorationButtonType::Maximize,
|
|
|
|
DecorationButtonType::Close
|
|
|
|
}), this))
|
2014-12-01 10:53:44 +00:00
|
|
|
, m_availableButtons(new ButtonsModel(QVector<DecorationButtonType>({
|
2014-10-31 06:53:04 +00:00
|
|
|
DecorationButtonType::Menu,
|
|
|
|
DecorationButtonType::ApplicationMenu,
|
|
|
|
DecorationButtonType::OnAllDesktops,
|
|
|
|
DecorationButtonType::Minimize,
|
|
|
|
DecorationButtonType::Maximize,
|
|
|
|
DecorationButtonType::Close,
|
2014-11-28 10:27:31 +00:00
|
|
|
DecorationButtonType::ContextHelp,
|
2014-10-31 06:53:04 +00:00
|
|
|
DecorationButtonType::Shade,
|
|
|
|
DecorationButtonType::KeepBelow,
|
|
|
|
DecorationButtonType::KeepAbove
|
|
|
|
}), this))
|
|
|
|
, m_borderSizes(new BorderSizesModel(this))
|
|
|
|
, m_borderSize(int(BorderSize::Normal))
|
|
|
|
, m_font(QFontDatabase::systemFont(QFontDatabase::TitleFont))
|
|
|
|
{
|
|
|
|
connect(this, &PreviewSettings::alphaChannelSupportedChanged, parent, &DecorationSettings::alphaChannelSupportedChanged);
|
|
|
|
connect(this, &PreviewSettings::onAllDesktopsAvailableChanged, parent, &DecorationSettings::onAllDesktopsAvailableChanged);
|
|
|
|
connect(this, &PreviewSettings::closeOnDoubleClickOnMenuChanged, parent, &DecorationSettings::closeOnDoubleClickOnMenuChanged);
|
|
|
|
connect(this, &PreviewSettings::fontChanged, parent, &DecorationSettings::fontChanged);
|
|
|
|
auto updateLeft = [this, parent]() {
|
|
|
|
parent->decorationButtonsLeftChanged(decorationButtonsLeft());
|
|
|
|
};
|
|
|
|
auto updateRight = [this, parent]() {
|
|
|
|
parent->decorationButtonsRightChanged(decorationButtonsRight());
|
|
|
|
};
|
|
|
|
connect(m_leftButtons, &QAbstractItemModel::rowsRemoved, this, updateLeft);
|
|
|
|
connect(m_leftButtons, &QAbstractItemModel::rowsMoved, this, updateLeft);
|
|
|
|
connect(m_leftButtons, &QAbstractItemModel::rowsInserted, this, updateLeft);
|
|
|
|
connect(m_rightButtons, &QAbstractItemModel::rowsRemoved, this, updateRight);
|
|
|
|
connect(m_rightButtons, &QAbstractItemModel::rowsMoved, this, updateRight);
|
|
|
|
connect(m_rightButtons, &QAbstractItemModel::rowsInserted, this, updateRight);
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewSettings::~PreviewSettings() = default;
|
|
|
|
|
|
|
|
bool PreviewSettings::isAlphaChannelSupported() const
|
|
|
|
{
|
|
|
|
return m_alphaChannelSupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PreviewSettings::isOnAllDesktopsAvailable() const
|
|
|
|
{
|
|
|
|
return m_onAllDesktopsAvailable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewSettings::setAlphaChannelSupported(bool supported)
|
|
|
|
{
|
|
|
|
if (m_alphaChannelSupported == supported) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_alphaChannelSupported = supported;
|
|
|
|
emit alphaChannelSupportedChanged(m_alphaChannelSupported);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewSettings::setOnAllDesktopsAvailable(bool available)
|
|
|
|
{
|
|
|
|
if (m_onAllDesktopsAvailable == available) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_onAllDesktopsAvailable = available;
|
|
|
|
emit onAllDesktopsAvailableChanged(m_onAllDesktopsAvailable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewSettings::setCloseOnDoubleClickOnMenu(bool enabled)
|
|
|
|
{
|
|
|
|
if (m_closeOnDoubleClick == enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_closeOnDoubleClick = enabled;
|
|
|
|
emit closeOnDoubleClickOnMenuChanged(enabled);
|
|
|
|
}
|
|
|
|
|
2014-12-01 10:53:44 +00:00
|
|
|
QVector< DecorationButtonType > PreviewSettings::decorationButtonsLeft() const
|
2014-10-31 06:53:04 +00:00
|
|
|
{
|
|
|
|
return m_leftButtons->buttons();
|
|
|
|
}
|
|
|
|
|
2014-12-01 10:53:44 +00:00
|
|
|
QVector< DecorationButtonType > PreviewSettings::decorationButtonsRight() const
|
2014-10-31 06:53:04 +00:00
|
|
|
{
|
|
|
|
return m_rightButtons->buttons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewSettings::addButtonToLeft(int row)
|
|
|
|
{
|
|
|
|
QModelIndex index = m_availableButtons->index(row);
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_leftButtons->add(index.data(Qt::UserRole).value<DecorationButtonType>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewSettings::addButtonToRight(int row)
|
|
|
|
{
|
|
|
|
QModelIndex index = m_availableButtons->index(row);
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_rightButtons->add(index.data(Qt::UserRole).value<DecorationButtonType>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewSettings::setBorderSizesIndex(int index)
|
|
|
|
{
|
|
|
|
if (m_borderSize == index) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_borderSize = index;
|
|
|
|
emit borderSizesIndexChanged(index);
|
|
|
|
emit decorationSettings()->borderSizeChanged(borderSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
BorderSize PreviewSettings::borderSize() const
|
|
|
|
{
|
|
|
|
return m_borderSizes->index(m_borderSize).data(Qt::UserRole).value<BorderSize>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewSettings::setFont(const QFont &font)
|
|
|
|
{
|
|
|
|
if (m_font == font) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_font = font;
|
|
|
|
emit fontChanged(m_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings::Settings(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
connect(this, &Settings::bridgeChanged, this, &Settings::createSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings::~Settings() = default;
|
|
|
|
|
|
|
|
void Settings::setBridge(PreviewBridge *bridge)
|
|
|
|
{
|
|
|
|
if (m_bridge == bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_bridge = bridge;
|
|
|
|
emit bridgeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewBridge *Settings::bridge() const
|
|
|
|
{
|
|
|
|
return m_bridge.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::createSettings()
|
|
|
|
{
|
|
|
|
if (m_bridge.isNull()) {
|
|
|
|
m_settings.clear();
|
|
|
|
} else {
|
|
|
|
m_settings = QSharedPointer<KDecoration2::DecorationSettings>::create(m_bridge.data());
|
|
|
|
}
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<DecorationSettings> Settings::settings() const
|
|
|
|
{
|
|
|
|
return m_settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecorationSettings *Settings::settingsPointer() const
|
|
|
|
{
|
|
|
|
return m_settings.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|