diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fbc14c4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,49 @@ +--- +BasedOnStyle: Microsoft +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AlignConsecutiveMacros: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: true +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: false +BreakInheritanceList: BeforeComma +BreakStringLiterals: false +ColumnLimit: 170 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +Cpp11BracedListStyle: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Regroup +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterTemplateKeyword: false +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpacesInParentheses: false +Standard: c++17 +StatementMacros: [Q_UNUSED LOG DEBUG] +# ForEachMacros: [list_foreach] +TabWidth: 4 +UseTab: Never diff --git a/libappletdecoration/appletdecorationplugin.cpp b/libappletdecoration/appletdecorationplugin.cpp index e869d78..5b00d61 100644 --- a/libappletdecoration/appletdecorationplugin.cpp +++ b/libappletdecoration/appletdecorationplugin.cpp @@ -1,21 +1,21 @@ /* -* Copyright 2018 Michail Vourlakos -* -* This file is part of the libappletdecoration library -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2018 Michail Vourlakos + * + * This file is part of the libappletdecoration library + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #include "appletdecorationplugin.h" @@ -24,55 +24,47 @@ #include "environment.h" #include "padding.h" #include "previewbridge.h" -#include "previewclient.h" #include "previewbutton.h" +#include "previewclient.h" #include "previewsettings.h" #include "previewshareddecoration.h" #include "schemesmodel.h" #include "themeextended.h" +#include "types.h" #include "windowsystem.h" -#include "types.h" - -#include -#include - #include - -namespace Decoration { -namespace Applet { +#include +#include void AppletDecorationPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.appletdecoration")); - qmlRegisterUncreatableType(uri, 0, 1, "Types", "Applet decoration types"); + qmlRegisterUncreatableType(uri, 0, 1, "Types", "Applet decoration types"); - qmlRegisterType(uri, 0, 1, "AuroraeTheme"); - qmlRegisterType(uri, 0, 1, "Bridge"); - qmlRegisterType(uri, 0, 1, "Settings"); - qmlRegisterType(uri, 0, 1, "Button"); - qmlRegisterType(uri, 0, 1, "DecorationsModel"); - qmlRegisterType(uri, 0, 1, "ColorsModel"); - qmlRegisterType(uri, 0, 1, "SharedDecoration"); - qmlRegisterType(uri, 0, 1, "PlasmaThemeExtended"); - qmlRegisterType(uri, 0, 1, "WindowSystem"); + qmlRegisterType(uri, 0, 1, "AuroraeTheme"); + qmlRegisterType(uri, 0, 1, "Bridge"); + qmlRegisterType(uri, 0, 1, "Settings"); + qmlRegisterType(uri, 0, 1, "Button"); + qmlRegisterType(uri, 0, 1, "DecorationsModel"); + qmlRegisterType(uri, 0, 1, "ColorsModel"); + qmlRegisterType(uri, 0, 1, "SharedDecoration"); + qmlRegisterType(uri, 0, 1, "PlasmaThemeExtended"); + qmlRegisterType(uri, 0, 1, "WindowSystem"); #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - qmlRegisterAnonymousType("", 1); - qmlRegisterAnonymousType("", 1); - qmlRegisterAnonymousType("", 1); + qmlRegisterAnonymousType("", 1); + qmlRegisterAnonymousType("", 1); + qmlRegisterAnonymousType("", 1); qmlRegisterAnonymousType("", 1); #else - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); + qmlRegisterType(); + qmlRegisterType(); + qmlRegisterType(); qmlRegisterType(); #endif - qmlRegisterSingletonType(uri, 0, 1, "Environment", &Decoration::Applet::Environment::instance); -} - -} + qmlRegisterSingletonType(uri, 0, 1, "Environment", &Environment::instance); } diff --git a/libappletdecoration/appletdecorationplugin.h b/libappletdecoration/appletdecorationplugin.h index 63a898d..f89458a 100644 --- a/libappletdecoration/appletdecorationplugin.h +++ b/libappletdecoration/appletdecorationplugin.h @@ -1,40 +1,34 @@ /* -* Copyright 2018 Michail Vourlakos -* -* This file is part of the libappletdecoration library -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2018 Michail Vourlakos + * + * This file is part of the libappletdecoration library + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #ifndef APPLETDECORATIONPLUGIN_H #define APPLETDECORATIONPLUGIN_H #include -namespace Decoration { -namespace Applet { class AppletDecorationPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") -public: + public: void registerTypes(const char *uri) override; }; -} -} - #endif - diff --git a/libappletdecoration/auroraetheme.cpp b/libappletdecoration/auroraetheme.cpp index 155fabf..c9f3c63 100644 --- a/libappletdecoration/auroraetheme.cpp +++ b/libappletdecoration/auroraetheme.cpp @@ -1,47 +1,40 @@ /* -* Copyright 2018 Michail Vourlakos -* -* This file is part of the libappletdecoration library -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2018 Michail Vourlakos + * + * This file is part of the libappletdecoration library + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #include "auroraetheme.h" #include "commontools.h" +#include +#include +#include +#include #include #include #include #include -#include -#include -#include - -#include - -namespace Decoration { -namespace Applet { - static const QString s_auroraeSvgTheme = QStringLiteral("__aurorae__svg__"); -static const QString s_auroraerc = QStringLiteral("auroraerc"); +static const QString s_auroraerc = QStringLiteral("auroraerc"); static int i_buttonSizeStep = 4; - -AuroraeTheme::AuroraeTheme(QObject *parent) : - QObject(parent) +AuroraeTheme::AuroraeTheme(QObject *parent) : QObject(parent) { const auto auroraerc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + s_auroraerc; @@ -59,13 +52,13 @@ AuroraeTheme::~AuroraeTheme() int AuroraeTheme::buttonWidth() const { - int f = (int)m_buttonSize; + int f = (int) m_buttonSize; return m_buttonWidth + ((f - 1) * i_buttonSizeStep); } int AuroraeTheme::buttonHeight() const { - int f = (int)m_buttonSize; + int f = (int) m_buttonSize; return m_buttonHeight + ((f - 1) * i_buttonSizeStep); } @@ -82,7 +75,7 @@ int AuroraeTheme::duration() const float AuroraeTheme::buttonRatio() const { - return ((float)m_buttonWidth / (float)m_buttonHeight); + return ((float) m_buttonWidth / (float) m_buttonHeight); } QString AuroraeTheme::theme() const @@ -92,7 +85,8 @@ QString AuroraeTheme::theme() const void AuroraeTheme::setTheme(QString theme) { - if (m_theme == theme || theme.isEmpty()) { + if (m_theme == theme || theme.isEmpty()) + { return; } @@ -139,7 +133,8 @@ QString AuroraeTheme::monochromePrefix() const void AuroraeTheme::auroraeRCChanged(const QString &filename) { - if (!filename.endsWith(s_auroraerc)) { + if (!filename.endsWith(s_auroraerc)) + { return; } @@ -150,15 +145,22 @@ void AuroraeTheme::updateAurorae(const QString &themeName) { const QString separator("__"); const QString name = themeName.section(separator, -1, -1); - QString path = AppletDecoration::standardPath("aurorae/themes/"+name); + QString path = AppletDecoration::standardPath("aurorae/themes/" + name); - if (QFileInfo(path + "/close.svg").exists()) { + if (QFileInfo(path + "/close.svg").exists()) + { m_themeType = "svg"; - } else if (QFileInfo(path + "/close.svgz").exists()) { + } + else if (QFileInfo(path + "/close.svgz").exists()) + { m_themeType = "svgz"; - } else if (QFileInfo(path + "/close.png").exists()) { + } + else if (QFileInfo(path + "/close.png").exists()) + { m_themeType = "png"; - } else { + } + else + { m_themeType = "svg"; } @@ -172,18 +174,22 @@ void AuroraeTheme::loadSettings() { const QString rc(m_themePath + "/" + m_themeName + "rc"); - if (!QFileInfo(rc).exists()) { + if (!QFileInfo(rc).exists()) + { return; } const auto auroraerc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + s_auroraerc; - if (QFileInfo(auroraerc).exists()) { + if (QFileInfo(auroraerc).exists()) + { KSharedConfigPtr auroraePtr = KSharedConfig::openConfig(auroraerc); const KConfigGroup themeGroup = KConfigGroup(auroraePtr, m_themeName); - m_buttonSize = static_cast(themeGroup.readEntry("ButtonSize", (int)Types::NormalButton)); - } else { + m_buttonSize = static_cast(themeGroup.readEntry("ButtonSize", (int) Types::NormalButton)); + } + else + { m_buttonSize = Types::NormalButton; } @@ -197,12 +203,15 @@ void AuroraeTheme::loadSettings() m_buttonHeight = layoutGroup.readEntry("ButtonHeight", 24); m_buttonSpacing = layoutGroup.readEntry("ButtonSpacing", 2); - QString monoprefix = generalGroup.readEntry("MonochromeIconsPrefix",""); + QString monoprefix = generalGroup.readEntry("MonochromeIconsPrefix", ""); - if (!monoprefix.isEmpty()) { + if (!monoprefix.isEmpty()) + { m_hasMonochromeIcons = true; m_monochromePrefix = (monoprefix == "*" ? "" : monoprefix); - } else { + } + else + { m_hasMonochromeIcons = false; m_monochromePrefix = ""; } @@ -214,27 +223,31 @@ void AuroraeTheme::loadSettings() void AuroraeTheme::parseThemeImages() { - QString origBackgroundFilePath = m_themePath + "/decoration."+m_themeType; + QString origBackgroundFilePath = m_themePath + "/decoration." + m_themeType; - if (!QFileInfo(origBackgroundFilePath).exists()) { + if (!QFileInfo(origBackgroundFilePath).exists()) + { qDebug() << "Aurorare decoration file was not found for theme: " << m_themeName; return; } KSvg::Svg *svg = new KSvg::Svg(this); svg->setImagePath(origBackgroundFilePath); - svg->resize(50,50); - QImage img = svg->image(QSize(50,50), "decoration-top"); + svg->resize(50, 50); + QImage img = svg->image(QSize(50, 50), "decoration-top"); int maxOpacity = -1; - for (int y=49; y>=0; --y) { - for (int x=0; x<50; ++x) { + for (int y = 49; y >= 0; --y) + { + for (int x = 0; x < 50; ++x) + { QRgb pix = img.pixel(x, y); int opacity = qAlpha(pix); //! the equality returns better results for more aurorae themes - if (maxOpacity<=opacity) { + if (maxOpacity <= opacity) + { maxOpacity = opacity; m_titleBackgroundColor = QColor(qRed(pix), qGreen(pix), qBlue(pix)); } @@ -243,6 +256,3 @@ void AuroraeTheme::parseThemeImages() svg->deleteLater(); } - -} -} diff --git a/libappletdecoration/auroraetheme.h b/libappletdecoration/auroraetheme.h index 869cce8..7b5e53f 100644 --- a/libappletdecoration/auroraetheme.h +++ b/libappletdecoration/auroraetheme.h @@ -1,34 +1,31 @@ /* -* Copyright 2018 Michail Vourlakos -* -* This file is part of the libappletdecoration library -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2018 Michail Vourlakos + * + * This file is part of the libappletdecoration library + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #ifndef AURORAETHEME_H #define AURORAETHEME_H +#include "types.h" + #include #include -#include "types.h" - -namespace Decoration { -namespace Applet { - -class AuroraeTheme: public QObject +class AuroraeTheme : public QObject { Q_OBJECT Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) @@ -50,9 +47,10 @@ class AuroraeTheme: public QObject Q_PROPERTY(bool hasMonochromeIcons READ hasMonochromeIcons NOTIFY settingsChanged) Q_PROPERTY(QString monochromePrefix READ monochromePrefix NOTIFY settingsChanged) -public: + public: explicit AuroraeTheme(QObject *parent = nullptr); - ~AuroraeTheme() override;; + ~AuroraeTheme() override; + ; QString theme() const; void setTheme(QString theme); @@ -75,28 +73,28 @@ public: bool hasMonochromeIcons() const; QString monochromePrefix() const; -signals: + signals: void settingsChanged(); void themeChanged(); -private slots: + private slots: void parseThemeImages(); void auroraeRCChanged(const QString &filename); -private: + private: void loadSettings(); void updateAurorae(const QString &themeName); -private: - bool m_hasMonochromeIcons{false}; - bool m_hasRestoreButton{false}; + private: + bool m_hasMonochromeIcons{ false }; + bool m_hasRestoreButton{ false }; - int m_buttonHeight{24}; - int m_buttonWidth{24}; - int m_buttonSpacing{2}; - int m_duration{0}; + int m_buttonHeight{ 24 }; + int m_buttonWidth{ 24 }; + int m_buttonSpacing{ 2 }; + int m_duration{ 0 }; - Types::ButtonSize m_buttonSize{Types::NormalButton}; //Normal size + Types::ButtonSize m_buttonSize{ Types::NormalButton }; // Normal size QString m_theme; QString m_themeName; @@ -108,6 +106,4 @@ private: QColor m_titleBackgroundColor; }; -} -} #endif diff --git a/libappletdecoration/buttonsmodel.cpp b/libappletdecoration/buttonsmodel.cpp index 4ab584c..03b87f2 100644 --- a/libappletdecoration/buttonsmodel.cpp +++ b/libappletdecoration/buttonsmodel.cpp @@ -24,31 +24,26 @@ #include "buttonsmodel.h" #include - #include -namespace Decoration { -namespace Applet { - -ButtonsModel::ButtonsModel(const QVector< KDecoration2::DecorationButtonType > &buttons, QObject *parent) - : QAbstractListModel(parent) - , m_buttons(buttons) +ButtonsModel::ButtonsModel(const QVector &buttons, QObject *parent) : QAbstractListModel(parent), m_buttons(buttons) { } ButtonsModel::ButtonsModel(QObject *parent) : ButtonsModel(QVector({ - KDecoration2::DecorationButtonType::Menu, - KDecoration2::DecorationButtonType::ApplicationMenu, - KDecoration2::DecorationButtonType::OnAllDesktops, - KDecoration2::DecorationButtonType::Minimize, - KDecoration2::DecorationButtonType::Maximize, - KDecoration2::DecorationButtonType::Close, - KDecoration2::DecorationButtonType::ContextHelp, - KDecoration2::DecorationButtonType::Shade, - KDecoration2::DecorationButtonType::KeepBelow, - KDecoration2::DecorationButtonType::KeepAbove -}), parent) + KDecoration2::DecorationButtonType::Menu, + KDecoration2::DecorationButtonType::ApplicationMenu, + KDecoration2::DecorationButtonType::OnAllDesktops, + KDecoration2::DecorationButtonType::Minimize, + KDecoration2::DecorationButtonType::Maximize, + KDecoration2::DecorationButtonType::Close, + KDecoration2::DecorationButtonType::ContextHelp, + KDecoration2::DecorationButtonType::Shade, + KDecoration2::DecorationButtonType::KeepBelow, + KDecoration2::DecorationButtonType::KeepAbove, + }), + parent) { } @@ -56,7 +51,8 @@ ButtonsModel::~ButtonsModel() = default; int ButtonsModel::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) { + if (parent.isValid()) + { return 0; } @@ -65,63 +61,50 @@ int ButtonsModel::rowCount(const QModelIndex &parent) const static QString buttonToName(KDecoration2::DecorationButtonType type) { - switch (type) { - case KDecoration2::DecorationButtonType::Menu: - return i18n("Menu"); + switch (type) + { + case KDecoration2::DecorationButtonType::Menu: return i18n("Menu"); - case KDecoration2::DecorationButtonType::ApplicationMenu: - return i18n("Application menu"); + case KDecoration2::DecorationButtonType::ApplicationMenu: return i18n("Application menu"); - case KDecoration2::DecorationButtonType::OnAllDesktops: - return i18n("On all desktops"); + case KDecoration2::DecorationButtonType::OnAllDesktops: return i18n("On all desktops"); - case KDecoration2::DecorationButtonType::Minimize: - return i18n("Minimize"); + case KDecoration2::DecorationButtonType::Minimize: return i18n("Minimize"); - case KDecoration2::DecorationButtonType::Maximize: - return i18n("Maximize"); + case KDecoration2::DecorationButtonType::Maximize: return i18n("Maximize"); - case KDecoration2::DecorationButtonType::Close: - return i18n("Close"); + case KDecoration2::DecorationButtonType::Close: return i18n("Close"); - case KDecoration2::DecorationButtonType::ContextHelp: - return i18n("Context help"); + case KDecoration2::DecorationButtonType::ContextHelp: return i18n("Context help"); - case KDecoration2::DecorationButtonType::Shade: - return i18n("Shade"); + case KDecoration2::DecorationButtonType::Shade: return i18n("Shade"); - case KDecoration2::DecorationButtonType::KeepBelow: - return i18n("Keep below"); + case KDecoration2::DecorationButtonType::KeepBelow: return i18n("Keep below"); - case KDecoration2::DecorationButtonType::KeepAbove: - return i18n("Keep above"); + case KDecoration2::DecorationButtonType::KeepAbove: return i18n("Keep above"); - default: - return QString(); + 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) { + 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())); + switch (role) + { + case Qt::DisplayRole: return buttonToName(m_buttons.at(index.row())); - case Qt::UserRole: - return QVariant::fromValue(int(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 ButtonsModel::roleNames() const { QHash roles; roles.insert(Qt::DisplayRole, QByteArrayLiteral("display")); @@ -131,7 +114,8 @@ QHash< int, QByteArray > ButtonsModel::roleNames() const void ButtonsModel::remove(int row) { - if (row < 0 || row >= m_buttons.count()) { + if (row < 0 || row >= m_buttons.count()) + { return; } @@ -142,7 +126,8 @@ void ButtonsModel::remove(int row) void ButtonsModel::down(int index) { - if (m_buttons.count() < 2 || index == m_buttons.count() - 1) { + if (m_buttons.count() < 2 || index == m_buttons.count() - 1) + { return; } @@ -153,7 +138,8 @@ void ButtonsModel::down(int index) void ButtonsModel::up(int index) { - if (m_buttons.count() < 2 || index == 0) { + if (m_buttons.count() < 2 || index == 0) + { return; } @@ -178,24 +164,24 @@ void ButtonsModel::add(int index, int type) void ButtonsModel::move(int sourceIndex, int targetIndex) { - if (sourceIndex == qMax(0, targetIndex)) { + if (sourceIndex == qMax(0, targetIndex)) + { return; } /* When moving an item down, the destination index needs to be incremented by one, as explained in the documentation: http://doc.qt.nokia.com/qabstractitemmodel.html#beginMoveRows */ - if (targetIndex > sourceIndex) { + if (targetIndex > sourceIndex) + { // Row will be moved down beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), targetIndex + 1); - } else { + } + else + { beginMoveRows(QModelIndex(), sourceIndex, sourceIndex, QModelIndex(), qMax(0, targetIndex)); } m_buttons.move(sourceIndex, qMax(0, targetIndex)); endMoveRows(); } - -} -} - diff --git a/libappletdecoration/buttonsmodel.h b/libappletdecoration/buttonsmodel.h index 1b536d5..03c69f2 100644 --- a/libappletdecoration/buttonsmodel.h +++ b/libappletdecoration/buttonsmodel.h @@ -27,23 +27,21 @@ #include #include -namespace Decoration { -namespace Applet { - class PreviewBridge; class ButtonsModel : public QAbstractListModel { Q_OBJECT -public: - explicit ButtonsModel(const QVector< KDecoration2::DecorationButtonType > &buttons, QObject *parent = 0); + public: + explicit ButtonsModel(const QVector &buttons, QObject *parent = 0); explicit ButtonsModel(QObject *parent = nullptr); virtual ~ButtonsModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; - QHash< int, QByteArray > roleNames() const override; + QHash roleNames() const override; - QVector< KDecoration2::DecorationButtonType > buttons() const { + QVector buttons() const + { return m_buttons; } @@ -55,12 +53,8 @@ public: void add(KDecoration2::DecorationButtonType type); Q_INVOKABLE void add(int index, int type); -private: - QVector< KDecoration2::DecorationButtonType > m_buttons; + private: + QVector m_buttons; }; -} -} - #endif - diff --git a/libappletdecoration/commontools.cpp b/libappletdecoration/commontools.cpp index 3878140..2276823 100644 --- a/libappletdecoration/commontools.cpp +++ b/libappletdecoration/commontools.cpp @@ -20,35 +20,40 @@ #include "commontools.h" -// Qt #include #include -namespace AppletDecoration { - QString standardPath(QString subPath, bool localfirst) { QStringList paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); - if (localfirst) { - for (const auto &pt : paths) { - QString ptF = pt + "/" +subPath; - if (QFileInfo(ptF).exists()) { + if (localfirst) + { + for (const auto &pt : paths) + { + QString ptF = pt + "/" + subPath; + if (QFileInfo(ptF).exists()) + { return ptF; } } - } else { - for (int i=paths.count()-1; i>=0; i--) { - QString ptF = paths[i] + "/" +subPath; - if (QFileInfo(ptF).exists()) { + } + else + { + for (int i = paths.count() - 1; i >= 0; i--) + { + QString ptF = paths[i] + "/" + subPath; + if (QFileInfo(ptF).exists()) + { return ptF; } } } //! in any case that above fails - if (QFileInfo("/usr/share/"+subPath).exists()) { - return "/usr/share/"+subPath; + if (QFileInfo("/usr/share/" + subPath).exists()) + { + return "/usr/share/" + subPath; } return ""; @@ -58,12 +63,16 @@ QStringList standardPaths(bool localfirst) { QStringList paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); - if (localfirst) { + if (localfirst) + { return paths; - } else { + } + else + { QStringList reversed; - for (int i=paths.count()-1; i>=0; i--) { + for (int i = paths.count() - 1; i >= 0; i--) + { reversed << paths[i]; } @@ -77,11 +86,10 @@ QStringList standardPathsFor(QString subPath, bool localfirst) QString separator = subPath.startsWith("/") ? "" : "/"; - for (int i=0; i #include -namespace AppletDecoration { - //! returns the standard path found that contains the subPath //! local paths have higher priority by default QString standardPath(QString subPath, bool localFirst = true); QStringList standardPaths(bool localfirst = true); QStringList standardPathsFor(QString subPath, bool localfirst = true); -} diff --git a/libappletdecoration/decorationpalette.cpp b/libappletdecoration/decorationpalette.cpp index 24dfaed..f649ff9 100644 --- a/libappletdecoration/decorationpalette.cpp +++ b/libappletdecoration/decorationpalette.cpp @@ -22,24 +22,19 @@ along with this program. If not, see . #include "decorationpalette.h" +#include #include #include -#include - #include -#include #include +#include #include -namespace Decoration { -namespace Applet { - DecorationPalette::DecorationPalette(const QString &colorScheme) - : m_colorScheme(QFileInfo(colorScheme).isAbsolute() - ? colorScheme - : QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme)) + : m_colorScheme(QFileInfo(colorScheme).isAbsolute() ? colorScheme : QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme)) { - if (m_colorScheme.isEmpty() && colorScheme == QStringLiteral("kdeglobals")) { + if (m_colorScheme.isEmpty() && colorScheme == QStringLiteral("kdeglobals")) + { // kdeglobals doesn't exist so create it. This is needed to monitor it using QFileSystemWatcher. auto config = KSharedConfig::openConfig(colorScheme, KConfig::SimpleConfig); KConfigGroup wmConfig(config, QStringLiteral("WM")); @@ -50,11 +45,13 @@ DecorationPalette::DecorationPalette(const QString &colorScheme) } m_watcher.addPath(m_colorScheme); - connect(&m_watcher, &QFileSystemWatcher::fileChanged, [this]() { - m_watcher.addPath(m_colorScheme); - update(); - emit changed(); - }); + connect(&m_watcher, &QFileSystemWatcher::fileChanged, + [this]() + { + m_watcher.addPath(m_colorScheme); + update(); + emit changed(); + }); update(); } @@ -66,51 +63,44 @@ bool DecorationPalette::isValid() const QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const { - using KDecoration2::ColorRole; using KDecoration2::ColorGroup; + using KDecoration2::ColorRole; - switch (role) { + switch (role) + { case ColorRole::Frame: - switch (group) { - case ColorGroup::Active: - return m_activeFrameColor; + switch (group) + { + case ColorGroup::Active: return m_activeFrameColor; - case ColorGroup::Inactive: - return m_inactiveFrameColor; + case ColorGroup::Inactive: return m_inactiveFrameColor; - default: - return QColor(); + default: return QColor(); } case ColorRole::TitleBar: - switch (group) { - case ColorGroup::Active: - return m_activeTitleBarColor; + switch (group) + { + case ColorGroup::Active: return m_activeTitleBarColor; - case ColorGroup::Inactive: - return m_inactiveTitleBarColor; + case ColorGroup::Inactive: return m_inactiveTitleBarColor; - default: - return QColor(); + default: return QColor(); } case ColorRole::Foreground: - switch (group) { - case ColorGroup::Active: - return m_activeForegroundColor; + switch (group) + { + case ColorGroup::Active: return m_activeForegroundColor; - case ColorGroup::Inactive: - return m_inactiveForegroundColor; + case ColorGroup::Inactive: return m_inactiveForegroundColor; - case ColorGroup::Warning: - return m_warningForegroundColor; + case ColorGroup::Warning: return m_warningForegroundColor; - default: - return QColor(); + default: return QColor(); } - default: - return QColor(); + default: return QColor(); } } @@ -124,20 +114,21 @@ void DecorationPalette::update() auto config = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig); KConfigGroup wmConfig(config, QStringLiteral("WM")); - if (!wmConfig.exists() && !m_colorScheme.endsWith(QStringLiteral("/kdeglobals"))) { + if (!wmConfig.exists() && !m_colorScheme.endsWith(QStringLiteral("/kdeglobals"))) + { qDebug() << "Invalid color scheme" << m_colorScheme << "lacks WM group"; return; } m_palette = KColorScheme::createApplicationPalette(config); - m_activeFrameColor = wmConfig.readEntry("frame", m_palette.color(QPalette::Active, QPalette::Base)); // !! TODO: Base? - m_inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_activeFrameColor); - m_activeTitleBarColor = wmConfig.readEntry("activeBackground", m_palette.color(QPalette::Active, QPalette::Highlight)); - m_inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_inactiveFrameColor); - m_activeForegroundColor = wmConfig.readEntry("activeForeground", m_palette.color(QPalette::Active, QPalette::HighlightedText)); + m_activeFrameColor = wmConfig.readEntry("frame", m_palette.color(QPalette::Active, QPalette::Base)); // !! TODO: Base? + m_inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_activeFrameColor); + m_activeTitleBarColor = wmConfig.readEntry("activeBackground", m_palette.color(QPalette::Active, QPalette::Highlight)); + m_inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_inactiveFrameColor); + m_activeForegroundColor = wmConfig.readEntry("activeForeground", m_palette.color(QPalette::Active, QPalette::HighlightedText)); -#if QT_VERSION >= QT_VERSION_CHECK(5,13,0) +#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) m_inactiveForegroundColor = wmConfig.readEntry("inactiveForeground", m_activeForegroundColor.darker()); #else m_inactiveForegroundColor = wmConfig.readEntry("inactiveForeground", m_activeForegroundColor.dark()); @@ -145,8 +136,4 @@ void DecorationPalette::update() KConfigGroup windowColorsConfig(config, QStringLiteral("Colors:Window")); m_warningForegroundColor = windowColorsConfig.readEntry("ForegroundNegative", QColor(237, 21, 2)); - -} - -} } diff --git a/libappletdecoration/decorationpalette.h b/libappletdecoration/decorationpalette.h index b4f8b4f..7de1746 100644 --- a/libappletdecoration/decorationpalette.h +++ b/libappletdecoration/decorationpalette.h @@ -27,13 +27,10 @@ along with this program. If not, see . #include #include -namespace Decoration { -namespace Applet { - class DecorationPalette : public QObject { Q_OBJECT -public: + public: DecorationPalette(const QString &colorScheme); bool isValid() const; @@ -41,9 +38,10 @@ public: QColor color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const; QPalette palette() const; -Q_SIGNALS: + Q_SIGNALS: void changed(); -private: + + private: void update(); QString m_colorScheme; @@ -62,7 +60,4 @@ private: QColor m_warningForegroundColor; }; -} -} - #endif diff --git a/libappletdecoration/decorationsmodel.cpp b/libappletdecoration/decorationsmodel.cpp index 67f44f1..ec6ad7f 100644 --- a/libappletdecoration/decorationsmodel.cpp +++ b/libappletdecoration/decorationsmodel.cpp @@ -22,26 +22,19 @@ */ #include "decorationsmodel.h" -// KDecoration2 + +#include #include #include #include -// KDE #include -#include -#include #include #include -#include - -// Qt +#include #include #include #include -namespace Decoration { -namespace Applet { - static const QString s_defaultPlugin = QStringLiteral("org.kde.breeze"); static const QString s_defaultTheme; static const QString s_auroraePlugin = QStringLiteral("org.kde.kwin.aurorae"); @@ -50,14 +43,12 @@ static const QString s_auroraeSvgTheme = QStringLiteral("__aurorae__svg__"); static const QString s_kwinrc = QStringLiteral("kwinrc"); static const QString s_pluginName = QStringLiteral("org.kde.kdecoration2"); -DecorationsModel::DecorationsModel(QObject *parent) - : QAbstractListModel(parent) +DecorationsModel::DecorationsModel(QObject *parent) : QAbstractListModel(parent) { init(); loadCurrents(); - const auto kwinRc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + - QLatin1Char('/') + s_kwinrc; + const auto kwinRc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + s_kwinrc; KDirWatch::self()->addFile(kwinRc); @@ -79,7 +70,8 @@ QString DecorationsModel::currentPlugin() const void DecorationsModel::setCurrentPlugin(QString plugin) { - if (m_currentPlugin == plugin) { + if (m_currentPlugin == plugin) + { return; } @@ -94,7 +86,8 @@ QString DecorationsModel::currentTheme() const void DecorationsModel::setCurrentTheme(QString theme) { - if (m_currentTheme == theme) { + if (m_currentTheme == theme) + { return; } @@ -104,7 +97,8 @@ void DecorationsModel::setCurrentTheme(QString theme) int DecorationsModel::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) { + if (parent.isValid()) + { return 0; } @@ -113,41 +107,36 @@ int DecorationsModel::rowCount(const QModelIndex &parent) const QVariant DecorationsModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= int(m_plugins.size())) { + if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= int(m_plugins.size())) + { return QVariant(); } const Data &d = m_plugins.at(index.row()); - switch (role) { - case Qt::DisplayRole: - return d.visibleName; + switch (role) + { + case Qt::DisplayRole: return d.visibleName; - case Qt::UserRole +4: - return d.pluginName; + case Qt::UserRole + 4: return d.pluginName; - case Qt::UserRole +5: - return d.themeName; + case Qt::UserRole + 5: return d.themeName; - case Qt::UserRole +6: - return d.isAuroraeTheme; + case Qt::UserRole + 6: return d.isAuroraeTheme; - case Qt::UserRole +7: - return d.configuration; + case Qt::UserRole + 7: return d.configuration; } return QVariant(); } -QHash< int, QByteArray > DecorationsModel::roleNames() const +QHash DecorationsModel::roleNames() const { - QHash roles({ - {Qt::DisplayRole, QByteArrayLiteral("display")}, - {Qt::UserRole + 4, QByteArrayLiteral("plugin")}, - {Qt::UserRole + 5, QByteArrayLiteral("theme")}, - {Qt::UserRole + 6, QByteArrayLiteral("isAuroraeTheme")}, - {Qt::UserRole + 7, QByteArrayLiteral("configureable")} - }); + QHash roles({ { Qt::DisplayRole, QByteArrayLiteral("display") }, + { Qt::UserRole + 4, QByteArrayLiteral("plugin") }, + { Qt::UserRole + 5, QByteArrayLiteral("theme") }, + { Qt::UserRole + 6, QByteArrayLiteral("isAuroraeTheme") }, + { Qt::UserRole + 7, QByteArrayLiteral("configureable") } }); return roles; } @@ -155,7 +144,8 @@ static bool isThemeEngine(const QVariantMap &decoSettingsMap) { auto it = decoSettingsMap.find(QStringLiteral("themes")); - if (it == decoSettingsMap.end()) { + if (it == decoSettingsMap.end()) + { return false; } @@ -166,7 +156,8 @@ static bool isConfigureable(const QVariantMap &decoSettingsMap) { auto it = decoSettingsMap.find(QStringLiteral("kcmodule")); - if (it == decoSettingsMap.end()) { + if (it == decoSettingsMap.end()) + { return false; } @@ -177,7 +168,8 @@ static QString themeListKeyword(const QVariantMap &decoSettingsMap) { auto it = decoSettingsMap.find(QStringLiteral("themeListKeyword")); - if (it == decoSettingsMap.end()) { + if (it == decoSettingsMap.end()) + { return QString(); } @@ -188,7 +180,8 @@ static QString findKNewStuff(const QVariantMap &decoSettingsMap) { auto it = decoSettingsMap.find(QStringLiteral("KNewStuff")); - if (it == decoSettingsMap.end()) { + if (it == decoSettingsMap.end()) + { return QString(); } @@ -200,18 +193,22 @@ void DecorationsModel::init() beginResetModel(); m_plugins.clear(); const auto plugins = KPluginMetaData::findPlugins(s_pluginName); - for (const auto &info : plugins) { + for (const auto &info : plugins) + { const auto decoSettingsMap = info.rawData().value("org.kde.kdecoration2").toObject().toVariantMap(); bool config = false; const QString &kns = findKNewStuff(decoSettingsMap); - if (!kns.isEmpty() && !m_knsProvides.contains(kns)) { + if (!kns.isEmpty() && !m_knsProvides.contains(kns)) + { m_knsProvides.insert(kns, info.name().isEmpty() ? info.pluginId() : info.name()); } - if (isThemeEngine(decoSettingsMap)) { + if (isThemeEngine(decoSettingsMap)) + { const QString keyword = themeListKeyword(decoSettingsMap); - if (keyword.isNull()) { + if (keyword.isNull()) + { // We cannot list the themes continue; } @@ -220,7 +217,7 @@ void DecorationsModel::init() // !! How to handle this theme engine? // Data d; // d.pluginName = info.pluginId(); - // d.themeName = + // d.themeName = // d.visibleName = theme->decorationName(); // std::cout << "DecorationsModel::init: " << d.pluginName.toStdString() << " " << d.themeName.toStdString() << std::endl; @@ -229,7 +226,7 @@ void DecorationsModel::init() // d.isAuroraeTheme = true; // } - // m_plugins.emplace_back(std::move(d)); + // m_plugins.emplace_back(std::move(d)); // it's a theme engine, we don't want to show this entry continue; @@ -254,11 +251,11 @@ void DecorationsModel::loadCurrents() const QString plugin = config.readEntry("library", s_defaultPlugin); const QString theme = config.readEntry("theme", s_defaultTheme); - bool exists{false}; - bool isAur{isAurorae(plugin,theme)}; + bool exists{ false }; + bool isAur{ isAurorae(plugin, theme) }; - if ((!isAur && pluginExists(plugin)) - || (isAur && decorationExists(plugin, theme))) { + if ((!isAur && pluginExists(plugin)) || (isAur && decorationExists(plugin, theme))) + { exists = true; } @@ -268,7 +265,8 @@ void DecorationsModel::loadCurrents() void DecorationsModel::kwinChanged(const QString &filename) { - if (!filename.endsWith(s_kwinrc)) { + if (!filename.endsWith(s_kwinrc)) + { return; } @@ -277,12 +275,10 @@ void DecorationsModel::kwinChanged(const QString &filename) bool DecorationsModel::isAurorae(const QString &plugin, const QString &theme) { - auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), - [plugin, theme](const Data & d) { - return d.pluginName == plugin && d.themeName == theme; - }); + auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), [plugin, theme](const Data &d) { return d.pluginName == plugin && d.themeName == theme; }); - if (it == m_plugins.cend()) { + if (it == m_plugins.cend()) + { return false; } @@ -291,12 +287,10 @@ bool DecorationsModel::isAurorae(const QString &plugin, const QString &theme) bool DecorationsModel::decorationExists(const QString &plugin, const QString &theme) { - auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), - [plugin, theme](const Data & d) { - return d.pluginName == plugin && d.themeName == theme; - }); + auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), [plugin, theme](const Data &d) { return d.pluginName == plugin && d.themeName == theme; }); - if (it == m_plugins.cend()) { + if (it == m_plugins.cend()) + { return false; } @@ -305,12 +299,10 @@ bool DecorationsModel::decorationExists(const QString &plugin, const QString &th bool DecorationsModel::pluginExists(const QString &plugin) { - auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), - [plugin](const Data & d) { - return d.pluginName == plugin; - }); + auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), [plugin](const Data &d) { return d.pluginName == plugin; }); - if (it == m_plugins.cend()) { + if (it == m_plugins.cend()) + { return false; } @@ -319,19 +311,14 @@ bool DecorationsModel::pluginExists(const QString &plugin) QModelIndex DecorationsModel::findDecoration(const QString &pluginName, const QString &themeName) const { - auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), - [pluginName, themeName](const Data & d) { - return d.pluginName == pluginName && d.themeName == themeName; - } - ); + auto it = + std::find_if(m_plugins.cbegin(), m_plugins.cend(), [pluginName, themeName](const Data &d) { return d.pluginName == pluginName && d.themeName == themeName; }); - if (it == m_plugins.cend()) { + if (it == m_plugins.cend()) + { return QModelIndex(); } const auto distance = std::distance(m_plugins.cbegin(), it); return createIndex(distance, 0); } - -} -} diff --git a/libappletdecoration/decorationsmodel.h b/libappletdecoration/decorationsmodel.h index 10a8edd..f771466 100644 --- a/libappletdecoration/decorationsmodel.h +++ b/libappletdecoration/decorationsmodel.h @@ -26,9 +26,6 @@ #include -namespace Decoration { -namespace Applet { - class DecorationsModel : public QAbstractListModel { Q_OBJECT @@ -36,17 +33,18 @@ class DecorationsModel : public QAbstractListModel Q_PROPERTY(QString currentPlugin READ currentPlugin NOTIFY currentPluginChanged) Q_PROPERTY(QString currentTheme READ currentTheme NOTIFY currentThemeChanged) -public: + public: explicit DecorationsModel(QObject *parent = nullptr); virtual ~DecorationsModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; - QHash< int, QByteArray > roleNames() const override; + QHash roleNames() const override; QModelIndex findDecoration(const QString &pluginName, const QString &themeName = QString()) const; - QMap knsProviders() const { + QMap knsProviders() const + { return m_knsProvides; } @@ -55,27 +53,26 @@ public: QString currentPlugin() const; QString currentTheme() const; -public Q_SLOTS: + public Q_SLOTS: Q_INVOKABLE bool decorationExists(const QString &plugin, const QString &theme); Q_INVOKABLE bool isAurorae(const QString &plugin, const QString &theme); -signals: + signals: void countChanged(); void currentThemeChanged(); void currentPluginChanged(); -private slots: + private slots: void init(); void loadCurrents(); void kwinChanged(const QString &filename); void setCurrentPlugin(QString plugin); void setCurrentTheme(QString theme); -private: - + private: bool pluginExists(const QString &plugin); -private: + private: struct Data { QString pluginName; @@ -92,7 +89,4 @@ private: QMap m_knsProvides; }; -} -} - #endif diff --git a/libappletdecoration/environment.cpp b/libappletdecoration/environment.cpp index f31a2f2..703f98a 100644 --- a/libappletdecoration/environment.cpp +++ b/libappletdecoration/environment.cpp @@ -1,36 +1,29 @@ /* -* Copyright 2019 Michail Vourlakos -* -* This file is part of Window Buttons Applet -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2019 Michail Vourlakos + * + * This file is part of Window Buttons Applet + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #include "environment.h" -// Qt #include #include - -// Plasma #include -namespace Decoration { -namespace Applet { - -Environment::Environment(QObject *parent) - : QObject(parent) +Environment::Environment(QObject *parent) : QObject(parent) { } @@ -46,7 +39,8 @@ uint Environment::frameworksVersion() const uint Environment::plasmaDesktopVersion() { - if (m_plasmaDesktopVersion == -1) { + if (m_plasmaDesktopVersion == -1) + { m_plasmaDesktopVersion = identifyPlasmaDesktopVersion(); } @@ -68,23 +62,25 @@ uint Environment::identifyPlasmaDesktopVersion() QStringList stringSplit = output.split(" "); - if (stringSplit.count() >= 2) { + if (stringSplit.count() >= 2) + { qDebug() << " /////////////////////////"; QString cleanVersionString = stringSplit[1].remove("\n"); QStringList plasmaDesktopVersionParts = cleanVersionString.split("."); - if (plasmaDesktopVersionParts.count() == 3) { + if (plasmaDesktopVersionParts.count() == 3) + { uint maj = plasmaDesktopVersionParts[0].toUInt(); uint min = plasmaDesktopVersionParts[1].toUInt(); uint rel = plasmaDesktopVersionParts[2].toUInt(); - if (maj > 0) { + if (maj > 0) + { uint desktopVersion = makeVersion(maj, min, rel); - QString message("Plasma Desktop version: " + QString::number(maj) + "." - + QString::number(min) + "." + QString::number(rel) - + " (" + QString::number(desktopVersion) + ")"); + QString message("Plasma Desktop version: " + QString::number(maj) + "." + QString::number(min) + "." + QString::number(rel) + " (" + + QString::number(desktopVersion) + ")"); qDebug() << message; qDebug() << " /////////////////////////"; @@ -97,6 +93,3 @@ uint Environment::identifyPlasmaDesktopVersion() return 0; } - -} -} //end of namespace diff --git a/libappletdecoration/environment.h b/libappletdecoration/environment.h index b7cc15f..e1e1077 100644 --- a/libappletdecoration/environment.h +++ b/libappletdecoration/environment.h @@ -1,32 +1,28 @@ /* -* Copyright 2019 Michail Vourlakos -* -* This file is part of Window Buttons Applet -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2019 Michail Vourlakos + * + * This file is part of Window Buttons Applet + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H -// Qt +#include #include #include -#include - -namespace Decoration { -namespace Applet { class Environment final : public QObject { @@ -34,7 +30,7 @@ class Environment final : public QObject Q_PROPERTY(uint frameworksVersion READ frameworksVersion NOTIFY frameworksVersionChanged) Q_PROPERTY(uint plasmaDesktopVersion READ plasmaDesktopVersion NOTIFY plasmaDesktopVersionChanged) -public: + public: virtual ~Environment(); bool compositingActive() const; @@ -48,29 +44,26 @@ public: Q_UNUSED(engine) Q_UNUSED(scriptEngine) - // NOTE: QML engine is the owner of this resource + // NOTE: QML engine is the owner of this resource return new Environment; } -public slots: + public slots: Q_INVOKABLE uint makeVersion(uint major, uint minor, uint release) const; -signals: + signals: void frameworksVersionChanged(); void plasmaDesktopVersionChanged(); -private: + private: explicit Environment(QObject *parent = nullptr); void loadPlasmaDesktopVersion(); uint identifyPlasmaDesktopVersion(); -private: - int m_plasmaDesktopVersion{ -1}; + private: + int m_plasmaDesktopVersion{ -1 }; }; -} -} - #endif // ENVIRONMENT_H diff --git a/libappletdecoration/padding.cpp b/libappletdecoration/padding.cpp index 96eb314..db7166e 100644 --- a/libappletdecoration/padding.cpp +++ b/libappletdecoration/padding.cpp @@ -22,11 +22,7 @@ #include "padding.h" -namespace Decoration { -namespace Applet { - -Padding::Padding(QObject *parent) : - QObject(parent) +Padding::Padding(QObject *parent) : QObject(parent) { } @@ -41,7 +37,8 @@ int Padding::top() const void Padding::setTop(int top) { - if (m_top == top) { + if (m_top == top) + { return; } @@ -56,7 +53,8 @@ int Padding::left() const void Padding::setLeft(int left) { - if (m_left == left) { + if (m_left == left) + { return; } @@ -64,14 +62,15 @@ void Padding::setLeft(int left) emit leftChanged(); } -int Padding::bottom()const +int Padding::bottom() const { return m_bottom; } void Padding::setBottom(int bottom) { - if (m_bottom == bottom) { + if (m_bottom == bottom) + { return; } @@ -86,13 +85,11 @@ int Padding::right() const void Padding::setRight(int right) { - if (m_right == right) { + if (m_right == right) + { return; } m_right = right; emit rightChanged(); } - -} -} diff --git a/libappletdecoration/padding.h b/libappletdecoration/padding.h index a574700..14eef23 100644 --- a/libappletdecoration/padding.h +++ b/libappletdecoration/padding.h @@ -25,9 +25,6 @@ #include -namespace Decoration { -namespace Applet { - class Padding : public QObject { Q_OBJECT @@ -37,7 +34,7 @@ class Padding : public QObject Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged); Q_PROPERTY(int right READ right WRITE setRight NOTIFY rightChanged); -public: + public: explicit Padding(QObject *parent = nullptr); virtual ~Padding(); @@ -47,26 +44,23 @@ public: int left() const; void setLeft(int left); - int bottom()const; + int bottom() const; void setBottom(int bottom); int right() const; void setRight(int right); -signals: + signals: void topChanged(); void leftChanged(); void bottomChanged(); void rightChanged(); -private: - int m_top{0}; - int m_left{0}; - int m_bottom{0}; - int m_right{0}; + private: + int m_top{ 0 }; + int m_left{ 0 }; + int m_bottom{ 0 }; + int m_right{ 0 }; }; -} -} - #endif diff --git a/libappletdecoration/previewbridge.cpp b/libappletdecoration/previewbridge.cpp index 9c940d4..fa9dd08 100644 --- a/libappletdecoration/previewbridge.cpp +++ b/libappletdecoration/previewbridge.cpp @@ -27,17 +27,15 @@ #include "previewclient.h" #include "previewsettings.h" +#include #include #include - -#include #include -#include #include - -#include +#include #include #include +#include #include #include #include @@ -46,22 +44,14 @@ #include #include -namespace Decoration { -namespace Applet { - static const QString s_pluginName = QStringLiteral("org.kde.kdecoration2"); static const QString s_breezerc = QStringLiteral("breezerc"); -PreviewBridge::PreviewBridge(QObject *parent) - : KDecoration2::DecorationBridge(parent) - , m_lastCreatedClient(nullptr) - , m_lastCreatedSettings(nullptr) - , m_valid(false) +PreviewBridge::PreviewBridge(QObject *parent) : KDecoration2::DecorationBridge(parent), m_lastCreatedClient(nullptr), m_lastCreatedSettings(nullptr), m_valid(false) { connect(this, &PreviewBridge::pluginChanged, this, &PreviewBridge::createFactory); - const auto breezeRc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + - QLatin1Char('/') + s_breezerc; + const auto breezeRc = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + s_breezerc; KDirWatch::self()->addFile(breezeRc); @@ -97,7 +87,8 @@ void PreviewBridge::unregisterButton(PreviewButtonItem *button) void PreviewBridge::setPlugin(const QString &plugin) { - if (m_plugin == plugin) { + if (m_plugin == plugin) + { return; } @@ -113,7 +104,8 @@ QString PreviewBridge::theme() const void PreviewBridge::setTheme(const QString &theme) { - if (m_theme == theme) { + if (m_theme == theme) + { return; } @@ -130,7 +122,8 @@ void PreviewBridge::createFactory() { m_factory.clear(); - if (m_plugin.isNull()) { + if (m_plugin.isNull()) + { setValid(false); qDebug() << "Plugin not set"; return; @@ -153,7 +146,8 @@ bool PreviewBridge::isValid() const void PreviewBridge::setValid(bool valid) { - if (m_valid == valid) { + if (m_valid == valid) + { return; } @@ -163,32 +157,37 @@ void PreviewBridge::setValid(bool valid) KDecoration2::Decoration *PreviewBridge::createDecoration(QObject *parent) { - if (!m_valid) { + if (!m_valid) + { return nullptr; } - QVariantMap args({ {QStringLiteral("bridge"), QVariant::fromValue(this)} }); + QVariantMap args({ { QStringLiteral("bridge"), QVariant::fromValue(this) } }); - if (!m_theme.isNull()) { + if (!m_theme.isNull()) + { args.insert(QStringLiteral("theme"), m_theme); } - return m_factory->create(parent, QVariantList({args})); + return m_factory->create(parent, QVariantList({ args })); } KDecoration2::DecorationButton *PreviewBridge::createButton(KDecoration2::Decoration *decoration, KDecoration2::DecorationButtonType type, QObject *parent) { - if (!m_valid) { + if (!m_valid) + { return nullptr; } - auto button = m_factory->create(parent, QVariantList({QVariant::fromValue(type), QVariant::fromValue(decoration)})); + auto button = m_factory->create(parent, QVariantList({ QVariant::fromValue(type), QVariant::fromValue(decoration) })); - if (!button) { + if (!button) + { // //! support decorations that have not been updated yet to KWin 5.23 decoration plugin approach - // button = m_factory->create(QStringLiteral("button"), parent, QVariantList({QVariant::fromValue(type), QVariant::fromValue(decoration)})); - // if (button) { - // qWarning() << "Loading a KDecoration2::DecorationButton using the button keyword is deprecated in KWin 5.23, register the plugin without a keyword instead" << m_plugin; + // button = m_factory->create(QStringLiteral("button"), parent, QVariantList({QVariant::fromValue(type), + // QVariant::fromValue(decoration)})); if (button) { + // qWarning() << "Loading a KDecoration2::DecorationButton using the button keyword is deprecated in KWin 5.23, register the plugin without a keyword + // instead" << m_plugin; // } qWarning() << "removed button" << (int) type << "from" << m_plugin; @@ -199,7 +198,8 @@ KDecoration2::DecorationButton *PreviewBridge::createButton(KDecoration2::Decora void PreviewBridge::settingsFileChanged(const QString &filename) { - if (!filename.endsWith(s_breezerc)) { + if (!filename.endsWith(s_breezerc)) + { return; } @@ -208,14 +208,13 @@ void PreviewBridge::settingsFileChanged(const QString &filename) void PreviewBridge::reconfigure() { - if (m_lastCreatedSettings) { + if (m_lastCreatedSettings) + { emit m_lastCreatedSettings->decorationSettings()->reconfigured(); } } -BridgeItem::BridgeItem(QObject *parent) - : QObject(parent) - , m_bridge(new PreviewBridge()) +BridgeItem::BridgeItem(QObject *parent) : QObject(parent), m_bridge(new PreviewBridge()) { connect(m_bridge, &PreviewBridge::themeChanged, this, &BridgeItem::themeChanged); connect(m_bridge, &PreviewBridge::pluginChanged, this, &BridgeItem::pluginChanged); @@ -226,6 +225,3 @@ BridgeItem::~BridgeItem() { m_bridge->deleteLater(); } - -} -} diff --git a/libappletdecoration/previewbridge.h b/libappletdecoration/previewbridge.h index e6abda5..ac54e15 100644 --- a/libappletdecoration/previewbridge.h +++ b/libappletdecoration/previewbridge.h @@ -24,17 +24,13 @@ #ifndef KDECORATIONS_PREVIEW_BRIDGE_H #define KDECORATIONS_PREVIEW_BRIDGE_H -#include #include - +#include #include #include class KPluginFactory; -namespace Decoration { -namespace Applet { - class PreviewButtonItem; class PreviewClient; class PreviewSettings; @@ -46,16 +42,18 @@ class PreviewBridge : public KDecoration2::DecorationBridge Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) -public: + public: explicit PreviewBridge(QObject *parent = nullptr); virtual ~PreviewBridge(); std::unique_ptr createClient(KDecoration2::DecoratedClient *client, KDecoration2::Decoration *decoration) override; std::unique_ptr settings(KDecoration2::DecorationSettings *parent) override; - PreviewClient *lastCreatedClient() { + PreviewClient *lastCreatedClient() + { return m_lastCreatedClient; } - PreviewSettings *lastCreatedSettings() { + PreviewSettings *lastCreatedSettings() + { return m_lastCreatedSettings; } @@ -71,18 +69,18 @@ public: KDecoration2::Decoration *createDecoration(QObject *parent = nullptr); KDecoration2::DecorationButton *createButton(KDecoration2::Decoration *decoration, KDecoration2::DecorationButtonType type, QObject *parent = nullptr); -public Q_SLOTS: + public Q_SLOTS: void reconfigure(); -Q_SIGNALS: + Q_SIGNALS: void pluginChanged(); void themeChanged(); void validChanged(); -private slots: + private slots: void settingsFileChanged(const QString &filename); -private: + private: void createFactory(); void setValid(bool valid); PreviewClient *m_lastCreatedClient; @@ -100,45 +98,47 @@ class BridgeItem : public QObject Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) - Q_PROPERTY(Decoration::Applet::PreviewBridge *bridge READ bridge CONSTANT) + Q_PROPERTY(PreviewBridge *bridge READ bridge CONSTANT) -public: + public: explicit BridgeItem(QObject *parent = nullptr); virtual ~BridgeItem(); - void setPlugin(const QString &plugin) { + void setPlugin(const QString &plugin) + { m_bridge->setPlugin(plugin); } - QString plugin() const { + QString plugin() const + { return m_bridge->plugin(); } - void setTheme(const QString &theme) { + void setTheme(const QString &theme) + { m_bridge->setTheme(theme); } - QString theme() const { + QString theme() const + { return m_bridge->theme(); } - bool isValid() const { + bool isValid() const + { return m_bridge->isValid(); } - PreviewBridge *bridge() const { + PreviewBridge *bridge() const + { return m_bridge; } -Q_SIGNALS: + Q_SIGNALS: void pluginChanged(); void themeChanged(); void validChanged(); -private: + private: PreviewBridge *m_bridge; - }; -} -} - -Q_DECLARE_METATYPE(Decoration::Applet::PreviewBridge *) +Q_DECLARE_METATYPE(PreviewBridge *) #endif diff --git a/libappletdecoration/previewbutton.cpp b/libappletdecoration/previewbutton.cpp index 5d658e9..ce28cd2 100644 --- a/libappletdecoration/previewbutton.cpp +++ b/libappletdecoration/previewbutton.cpp @@ -29,20 +29,13 @@ #include "previewsettings.h" #include "previewshareddecoration.h" -#include #include - +#include #include #include #include -namespace Decoration { -namespace Applet { - -PreviewButtonItem::PreviewButtonItem(QQuickItem *parent) - : QQuickPaintedItem(parent), - m_scheme("kdeglobals"), - m_padding(new Padding(this)) +PreviewButtonItem::PreviewButtonItem(QQuickItem *parent) : QQuickPaintedItem(parent), m_scheme("kdeglobals"), m_padding(new Padding(this)) { setAcceptHoverEvents(true); setFiltersChildMouseEvents(true); @@ -71,11 +64,13 @@ PreviewButtonItem::PreviewButtonItem(QQuickItem *parent) PreviewButtonItem::~PreviewButtonItem() { - if (m_bridge) { + if (m_bridge) + { m_bridge->unregisterButton(this); } - if (m_button) { + if (m_button) + { m_button->deleteLater(); } } @@ -87,13 +82,15 @@ bool PreviewButtonItem::isActive() const void PreviewButtonItem::setIsActive(bool active) { - if (m_isActive == active) { + if (m_isActive == active) + { return; } m_isActive = active; - if (m_client) { + if (m_client) + { m_client->setActive(m_isActive); } @@ -107,18 +104,23 @@ bool PreviewButtonItem::isMaximized() const void PreviewButtonItem::setIsMaximized(bool maximized) { - if (m_isMaximized == maximized) { + if (m_isMaximized == maximized) + { return; } m_isMaximized = maximized; - if (m_client && m_button && m_type == KDecoration2::DecorationButtonType::Maximize) { + if (m_client && m_button && m_type == KDecoration2::DecorationButtonType::Maximize) + { - if (m_isMaximized) { + if (m_isMaximized) + { m_client->setMaximizedVertically(true); m_client->setMaximizedHorizontally(true); - } else { + } + else + { m_client->setMaximizedVertically(false); m_client->setMaximizedHorizontally(false); } @@ -134,16 +136,21 @@ bool PreviewButtonItem::isOnAllDesktops() const void PreviewButtonItem::setIsOnAllDesktops(bool onalldesktops) { - if (m_isOnAllDesktops == onalldesktops) { + if (m_isOnAllDesktops == onalldesktops) + { return; } m_isOnAllDesktops = onalldesktops; - if (m_client && m_button && m_type == KDecoration2::DecorationButtonType::OnAllDesktops) { - if (m_isOnAllDesktops) { + if (m_client && m_button && m_type == KDecoration2::DecorationButtonType::OnAllDesktops) + { + if (m_isOnAllDesktops) + { m_client->setDesktop(-1); - } else { + } + else + { m_client->setDesktop(1); } } @@ -158,16 +165,21 @@ bool PreviewButtonItem::isKeepAbove() const void PreviewButtonItem::setIsKeepAbove(bool keepabove) { - if (m_isKeepAbove == keepabove){ + if (m_isKeepAbove == keepabove) + { return; } m_isKeepAbove = keepabove; - if (m_client && m_button && m_type == KDecoration2::DecorationButtonType::KeepAbove) { - if (m_isKeepAbove){ + if (m_client && m_button && m_type == KDecoration2::DecorationButtonType::KeepAbove) + { + if (m_isKeepAbove) + { m_client->setKeepAbove(true); - } else { + } + else + { m_client->setKeepAbove(false); } } @@ -192,7 +204,8 @@ void PreviewButtonItem::setType(int type) void PreviewButtonItem::setType(KDecoration2::DecorationButtonType type) { - if (m_type == type) { + if (m_type == type) + { return; } @@ -207,13 +220,15 @@ QString PreviewButtonItem::scheme() const void PreviewButtonItem::setScheme(QString scheme) { - if (m_scheme == scheme) { + if (m_scheme == scheme) + { return; } m_scheme = scheme.isEmpty() ? "kdeglobals" : scheme; - if (m_client) { + if (m_client) + { m_client->setColorScheme(m_scheme); qDebug() << "buttons scheme update to:" << m_scheme; } @@ -228,17 +243,20 @@ PreviewBridge *PreviewButtonItem::bridge() const void PreviewButtonItem::setBridge(PreviewBridge *bridge) { - if (m_bridge == bridge) { + if (m_bridge == bridge) + { return; } - if (m_bridge) { + if (m_bridge) + { m_bridge->unregisterButton(this); } m_bridge = bridge; - if (m_bridge) { + if (m_bridge) + { m_bridge->registerButton(this); } @@ -257,7 +275,8 @@ int PreviewButtonItem::localX() const void PreviewButtonItem::setLocalX(int x) { - if (m_localX == x) { + if (m_localX == x) + { return; } @@ -273,7 +292,8 @@ int PreviewButtonItem::localY() const void PreviewButtonItem::setLocalY(int y) { - if (m_localY == y) { + if (m_localY == y) + { return; } @@ -284,7 +304,8 @@ void PreviewButtonItem::setLocalY(int y) KDecoration2::Decoration *PreviewButtonItem::decoration() const { - if (!m_sharedDecoration) { + if (!m_sharedDecoration) + { return nullptr; } @@ -298,13 +319,14 @@ SharedDecoration *PreviewButtonItem::sharedDecoration() const void PreviewButtonItem::setSharedDecoration(SharedDecoration *sharedDecoration) { - if (m_sharedDecoration == sharedDecoration) { + if (m_sharedDecoration == sharedDecoration) + { return; } m_sharedDecoration = sharedDecoration; - connect(m_sharedDecoration, &Decoration::Applet::SharedDecoration::decorationChanged, this, &Decoration::Applet::PreviewButtonItem::createButton); + connect(m_sharedDecoration, &SharedDecoration::decorationChanged, this, &PreviewButtonItem::createButton); emit sharedDecorationChanged(); } @@ -317,13 +339,15 @@ void PreviewButtonItem::componentComplete() void PreviewButtonItem::createButton() { - if (m_type == KDecoration2::DecorationButtonType::Custom || !m_sharedDecoration || !m_sharedDecoration->decoration() || !m_bridge) { + if (m_type == KDecoration2::DecorationButtonType::Custom || !m_sharedDecoration || !m_sharedDecoration->decoration() || !m_bridge) + { return; } m_client = m_bridge->lastCreatedClient(); - if (!m_client) { + if (!m_client) + { return; } @@ -333,31 +357,40 @@ void PreviewButtonItem::createButton() m_client->setActive(m_isActive); m_client->setColorScheme(m_scheme); - if (m_isOnAllDesktops) { + if (m_isOnAllDesktops) + { m_client->setDesktop(-1); - } else { + } + else + { m_client->setDesktop(1); } - if (m_isMaximized) { + if (m_isMaximized) + { m_client->setMaximizedVertically(true); m_client->setMaximizedHorizontally(true); - } else { + } + else + { m_client->setMaximizedVertically(false); m_client->setMaximizedHorizontally(false); } - if (m_button) { + if (m_button) + { m_button->deleteLater(); } m_button = m_bridge->createButton(m_sharedDecoration->decoration(), m_type, this); - if (!m_button) { + if (!m_button) + { return; } - if (!m_lastAppliedDecoration.isNull()) { + if (!m_lastAppliedDecoration.isNull()) + { disconnect(m_lastAppliedDecoration.data(), &KDecoration2::Decoration::damaged, this, &PreviewButtonItem::onDecorationDamaged); } @@ -385,7 +418,8 @@ void PreviewButtonItem::syncInternalGeometry() m_fullGeometry = QRect(0, 0, width(), height()); m_visualGeometry = QRect(m_localX + m_padding->left(), m_localY + m_padding->top(), iWidth, iHeight); - if (!m_button) { + if (!m_button) + { return; } @@ -394,23 +428,28 @@ void PreviewButtonItem::syncInternalGeometry() void PreviewButtonItem::onButtonDamaged() { - if (m_sharedDecoration && m_sharedDecoration->decoration()) { + if (m_sharedDecoration && m_sharedDecoration->decoration()) + { emit m_sharedDecoration->decoration()->damaged(m_visualGeometry); - } else { + } + else + { update(); } } void PreviewButtonItem::onDecorationDamaged(const QRegion ®ion) { - if (region.intersects(m_visualGeometry)) { + if (region.intersects(m_visualGeometry)) + { update(); } } void PreviewButtonItem::paint(QPainter *painter) { - if (!m_button) { + if (!m_button) + { return; } @@ -421,7 +460,8 @@ void PreviewButtonItem::paint(QPainter *painter) void PreviewButtonItem::mouseDoubleClickEvent(QMouseEvent *event) { - if (!m_button) { + if (!m_button) + { return; } @@ -430,72 +470,63 @@ void PreviewButtonItem::mouseDoubleClickEvent(QMouseEvent *event) void PreviewButtonItem::mousePressEvent(QMouseEvent *event) { - if (!m_button) { + if (!m_button) + { return; } //! this a workaround in order to send proper coordinates //! that confirm the button visual coordinates - QMouseEvent e(event->type(), - m_visualGeometry.center(), - event->button(), - event->buttons(), - event->modifiers()); + QMouseEvent e(event->type(), m_visualGeometry.center(), event->button(), event->buttons(), event->modifiers()); QCoreApplication::instance()->sendEvent(m_button, &e); } void PreviewButtonItem::mouseReleaseEvent(QMouseEvent *event) { - if (!m_button) { + if (!m_button) + { return; } - bool inItem {m_fullGeometry.contains(event->position().x(), event->position().y())}; + bool inItem{ m_fullGeometry.contains(event->position().x(), event->position().y()) }; //! this a workaround in order to send proper coordinates //! that confirm the button visual coordinates - QMouseEvent e(event->type(), - inItem ? m_visualGeometry.center() : QPoint(-5, -5), - event->button(), - event->buttons(), - event->modifiers()); + QMouseEvent e(event->type(), inItem ? m_visualGeometry.center() : QPoint(-5, -5), event->button(), event->buttons(), event->modifiers()); QCoreApplication::instance()->sendEvent(m_button, event); - if (inItem) { + if (inItem) + { emit clicked(); } } void PreviewButtonItem::mouseMoveEvent(QMouseEvent *event) { - if (!m_button) { + if (!m_button) + { return; } //! this a workaround in order to send proper coordinates //! that confirm the button visual coordinates - QMouseEvent e(event->type(), - m_visualGeometry.center(), - event->button(), - event->buttons(), - event->modifiers()); + QMouseEvent e(event->type(), m_visualGeometry.center(), event->button(), event->buttons(), event->modifiers()); QCoreApplication::instance()->sendEvent(m_button, &e); } void PreviewButtonItem::hoverEnterEvent(QHoverEvent *event) { - if (!m_button) { + if (!m_button) + { return; } //! this a workaround in order to send proper coordinates //! that confirm the button visual coordinates - QHoverEvent e(event->type(), - m_visualGeometry.center(), - QPoint(m_visualGeometry.x() + event->position().x(), m_visualGeometry.y() + event->position().y()), + QHoverEvent e(event->type(), m_visualGeometry.center(), QPoint(m_visualGeometry.x() + event->position().x(), m_visualGeometry.y() + event->position().y()), event->modifiers()); QCoreApplication::instance()->sendEvent(m_button, &e); @@ -503,31 +534,30 @@ void PreviewButtonItem::hoverEnterEvent(QHoverEvent *event) void PreviewButtonItem::hoverLeaveEvent(QHoverEvent *event) { - if (!m_button) { + if (!m_button) + { return; } //! this a workaround in order to send proper coordinates //! that confirm the button visual coordinates - QHoverEvent e(event->type(), - QPoint(-5, -5), - m_visualGeometry.center(), - event->modifiers()); + QHoverEvent e(event->type(), QPoint(-5, -5), m_visualGeometry.center(), event->modifiers()); QCoreApplication::instance()->sendEvent(m_button, &e); } void PreviewButtonItem::hoverMoveEvent(QHoverEvent *event) { - if (!m_button) { + if (!m_button) + { return; } - QPoint newPos (qBound((double)m_visualGeometry.left(), m_visualGeometry.left() + event->position().x(), (double)m_visualGeometry.right()), - qBound((double)m_visualGeometry.top(), m_visualGeometry.top() + event->position().x(), (double)m_visualGeometry.bottom())); + QPoint newPos(qBound((double) m_visualGeometry.left(), m_visualGeometry.left() + event->position().x(), (double) m_visualGeometry.right()), + qBound((double) m_visualGeometry.top(), m_visualGeometry.top() + event->position().x(), (double) m_visualGeometry.bottom())); - QPoint oldPos (qBound((double)m_visualGeometry.left(), m_visualGeometry.left() + event->oldPosF().x(), (double)m_visualGeometry.right()), - qBound((double)m_visualGeometry.top(), m_visualGeometry.top() + event->oldPosF().x(), (double)m_visualGeometry.bottom())); + QPoint oldPos(qBound((double) m_visualGeometry.left(), m_visualGeometry.left() + event->oldPosF().x(), (double) m_visualGeometry.right()), + qBound((double) m_visualGeometry.top(), m_visualGeometry.top() + event->oldPosF().x(), (double) m_visualGeometry.bottom())); //! this a workaround in order to send proper coordinates //! that confirm the button visual coordinates @@ -536,12 +566,7 @@ void PreviewButtonItem::hoverMoveEvent(QHoverEvent *event) QCoreApplication::instance()->sendEvent(m_button, &e); } - void PreviewButtonItem::focusOutEvent(QFocusEvent *event) { QCoreApplication::instance()->sendEvent(m_button, event); } - -} // namespace Applet -} // namespace Decoration - diff --git a/libappletdecoration/previewbutton.h b/libappletdecoration/previewbutton.h index a712079..3b7371a 100644 --- a/libappletdecoration/previewbutton.h +++ b/libappletdecoration/previewbutton.h @@ -25,17 +25,11 @@ #define KDECORATIONS_PREVIEW_BUTTON_ITEM_H #include "previewshareddecoration.h" -#include -#include -#include + #include - -namespace KDecoration2 { -class Decoration; -} - -namespace Decoration { -namespace Applet { +#include +#include +#include class Padding; class PreviewBridge; @@ -44,8 +38,8 @@ class PreviewClient; class PreviewButtonItem : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(Decoration::Applet::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) - Q_PROPERTY(Decoration::Applet::SharedDecoration *sharedDecoration READ sharedDecoration WRITE setSharedDecoration NOTIFY sharedDecorationChanged) + Q_PROPERTY(PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) + Q_PROPERTY(SharedDecoration *sharedDecoration READ sharedDecoration WRITE setSharedDecoration NOTIFY sharedDecorationChanged) Q_PROPERTY(bool isActive READ isActive WRITE setIsActive NOTIFY isActiveChanged); Q_PROPERTY(bool isMaximized READ isMaximized WRITE setIsMaximized NOTIFY isMaximizedChanged) @@ -58,9 +52,9 @@ class PreviewButtonItem : public QQuickPaintedItem Q_PROPERTY(int type READ typeAsInt WRITE setType NOTIFY typeChanged) Q_PROPERTY(QString scheme READ scheme WRITE setScheme NOTIFY schemeChanged) - Q_PROPERTY(Decoration::Applet::Padding *padding READ padding NOTIFY paddingChanged) + Q_PROPERTY(Padding *padding READ padding NOTIFY paddingChanged) -public: + public: explicit PreviewButtonItem(QQuickItem *parent = nullptr); virtual ~PreviewButtonItem(); void paint(QPainter *painter) override; @@ -103,7 +97,7 @@ public: QRect visualGeometry() const; -Q_SIGNALS: + Q_SIGNALS: void bridgeChanged(); void isActiveChanged(); void isMaximizedChanged(); @@ -118,7 +112,7 @@ Q_SIGNALS: void clicked(); -protected: + protected: void mouseDoubleClickEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; @@ -130,27 +124,26 @@ protected: void componentComplete() override; -private Q_SLOTS: + private Q_SLOTS: void createButton(); void syncInternalGeometry(); void onButtonDamaged(); void onDecorationDamaged(const QRegion ®ion); -private: - - QPointer m_bridge; - QPointer m_client; - QPointer m_sharedDecoration; + private: + QPointer m_bridge; + QPointer m_client; + QPointer m_sharedDecoration; QPointer m_lastAppliedDecoration; KDecoration2::DecorationButton *m_button = nullptr; KDecoration2::DecorationButtonType m_type = KDecoration2::DecorationButtonType::Custom; - bool m_isActive{true}; - bool m_isMaximized{false}; - bool m_isOnAllDesktops{false}; - bool m_isKeepAbove{false}; + bool m_isActive{ true }; + bool m_isMaximized{ false }; + bool m_isOnAllDesktops{ false }; + bool m_isKeepAbove{ false }; int m_localX; int m_localY; @@ -163,7 +156,4 @@ private: Padding *m_padding; }; -} // namespace Applet -} // namespace Decoration - #endif diff --git a/libappletdecoration/previewclient.cpp b/libappletdecoration/previewclient.cpp index 430326a..ba74191 100644 --- a/libappletdecoration/previewclient.cpp +++ b/libappletdecoration/previewclient.cpp @@ -22,98 +22,62 @@ */ #include "previewclient.h" -#include -#include -#include +#include +#include #include +#include #include #include -namespace Decoration { -namespace Applet { - PreviewClient::PreviewClient(KDecoration2::DecoratedClient *c, KDecoration2::Decoration *decoration) - : QObject(decoration) - , ApplicationMenuEnabledDecoratedClientPrivate(c, decoration) - , m_icon(QIcon::fromTheme(QStringLiteral("start-here-kde"))) - , m_iconName(m_icon.name()) - // , m_palette(new KWin::Decoration::DecorationPalette(QStringLiteral("kdeglobals"))) - , m_active(true) - , m_closeable(true) - , m_keepBelow(false) - , m_keepAbove(false) - , m_maximizable(true) - , m_maximizedHorizontally(false) - , m_maximizedVertically(false) - , m_minimizable(true) - , m_modal(false) - , m_movable(true) - , m_resizable(true) - , m_shadeable(true) - , m_shaded(false) - , m_providesContextHelp(false) - , m_desktop(1) - , m_width(0) - , m_height(0) - , m_bordersTopEdge(false) - , m_bordersLeftEdge(false) - , m_bordersRightEdge(false) - , m_bordersBottomEdge(false) + : QObject(decoration), ApplicationMenuEnabledDecoratedClientPrivate(c, decoration), m_icon(QIcon::fromTheme(QStringLiteral("start-here-kde"))), + m_iconName(m_icon.name()) + // , m_palette(new KWin::Decoration::DecorationPalette(QStringLiteral("kdeglobals"))) + , + m_active(true), m_closeable(true), m_keepBelow(false), m_keepAbove(false), m_maximizable(true), m_maximizedHorizontally(false), m_maximizedVertically(false), + m_minimizable(true), m_modal(false), m_movable(true), m_resizable(true), m_shadeable(true), m_shaded(false), m_providesContextHelp(false), m_desktop(1), m_width(0), + m_height(0), m_bordersTopEdge(false), m_bordersLeftEdge(false), m_bordersRightEdge(false), m_bordersBottomEdge(false) { - connect(this, &PreviewClient::captionChanged, c, &KDecoration2::DecoratedClient::captionChanged); - connect(this, &PreviewClient::activeChanged, c, &KDecoration2::DecoratedClient::activeChanged); - connect(this, &PreviewClient::closeableChanged, c, &KDecoration2::DecoratedClient::closeableChanged); - connect(this, &PreviewClient::keepAboveChanged, c, &KDecoration2::DecoratedClient::keepAboveChanged); - connect(this, &PreviewClient::keepBelowChanged, c, &KDecoration2::DecoratedClient::keepBelowChanged); - connect(this, &PreviewClient::maximizableChanged, c, &KDecoration2::DecoratedClient::maximizeableChanged); - connect(this, &PreviewClient::maximizedChanged, c, &KDecoration2::DecoratedClient::maximizedChanged); - connect(this, &PreviewClient::maximizedVerticallyChanged, c, &KDecoration2::DecoratedClient::maximizedVerticallyChanged); + connect(this, &PreviewClient::captionChanged, c, &KDecoration2::DecoratedClient::captionChanged); + connect(this, &PreviewClient::activeChanged, c, &KDecoration2::DecoratedClient::activeChanged); + connect(this, &PreviewClient::closeableChanged, c, &KDecoration2::DecoratedClient::closeableChanged); + connect(this, &PreviewClient::keepAboveChanged, c, &KDecoration2::DecoratedClient::keepAboveChanged); + connect(this, &PreviewClient::keepBelowChanged, c, &KDecoration2::DecoratedClient::keepBelowChanged); + connect(this, &PreviewClient::maximizableChanged, c, &KDecoration2::DecoratedClient::maximizeableChanged); + connect(this, &PreviewClient::maximizedChanged, c, &KDecoration2::DecoratedClient::maximizedChanged); + connect(this, &PreviewClient::maximizedVerticallyChanged, c, &KDecoration2::DecoratedClient::maximizedVerticallyChanged); connect(this, &PreviewClient::maximizedHorizontallyChanged, c, &KDecoration2::DecoratedClient::maximizedHorizontallyChanged); - connect(this, &PreviewClient::minimizableChanged, c, &KDecoration2::DecoratedClient::minimizeableChanged); + connect(this, &PreviewClient::minimizableChanged, c, &KDecoration2::DecoratedClient::minimizeableChanged); // connect(this, &PreviewClient::modalChanged, c, &DecoratedClient::modalChanged); - connect(this, &PreviewClient::movableChanged, c, &KDecoration2::DecoratedClient::moveableChanged); - connect(this, &PreviewClient::onAllDesktopsChanged, c, &KDecoration2::DecoratedClient::onAllDesktopsChanged); - connect(this, &PreviewClient::resizableChanged, c, &KDecoration2::DecoratedClient::resizeableChanged); - connect(this, &PreviewClient::shadeableChanged, c, &KDecoration2::DecoratedClient::shadeableChanged); - connect(this, &PreviewClient::shadedChanged, c, &KDecoration2::DecoratedClient::shadedChanged); - connect(this, &PreviewClient::providesContextHelpChanged, c, &KDecoration2::DecoratedClient::providesContextHelpChanged); + connect(this, &PreviewClient::movableChanged, c, &KDecoration2::DecoratedClient::moveableChanged); + connect(this, &PreviewClient::onAllDesktopsChanged, c, &KDecoration2::DecoratedClient::onAllDesktopsChanged); + connect(this, &PreviewClient::resizableChanged, c, &KDecoration2::DecoratedClient::resizeableChanged); + connect(this, &PreviewClient::shadeableChanged, c, &KDecoration2::DecoratedClient::shadeableChanged); + connect(this, &PreviewClient::shadedChanged, c, &KDecoration2::DecoratedClient::shadedChanged); + connect(this, &PreviewClient::providesContextHelpChanged, c, &KDecoration2::DecoratedClient::providesContextHelpChanged); // connect(this, &PreviewClient::onAllDesktopsChanged, c, &KDecoration2::DecoratedClient::onAllDesktopsChanged); - connect(this, &PreviewClient::widthChanged, c, &KDecoration2::DecoratedClient::widthChanged); - connect(this, &PreviewClient::heightChanged, c, &KDecoration2::DecoratedClient::heightChanged); - connect(this, &PreviewClient::iconChanged, c, &KDecoration2::DecoratedClient::iconChanged); - connect(this, &PreviewClient::paletteChanged, c, &KDecoration2::DecoratedClient::paletteChanged); + connect(this, &PreviewClient::widthChanged, c, &KDecoration2::DecoratedClient::widthChanged); + connect(this, &PreviewClient::heightChanged, c, &KDecoration2::DecoratedClient::heightChanged); + connect(this, &PreviewClient::iconChanged, c, &KDecoration2::DecoratedClient::iconChanged); + connect(this, &PreviewClient::paletteChanged, c, &KDecoration2::DecoratedClient::paletteChanged); // connect(this, &PreviewClient::, c, &DecoratedClient::); - connect(this, &PreviewClient::maximizedVerticallyChanged, this, - [this]() { - emit maximizedChanged(isMaximized()); - } - ); - connect(this, &PreviewClient::maximizedHorizontallyChanged, this, - [this]() { - emit maximizedChanged(isMaximized()); - } - ); + connect(this, &PreviewClient::maximizedVerticallyChanged, this, [this]() { emit maximizedChanged(isMaximized()); }); + connect(this, &PreviewClient::maximizedHorizontallyChanged, this, [this]() { emit maximizedChanged(isMaximized()); }); connect(this, &PreviewClient::iconNameChanged, this, - [this]() { - m_icon = QIcon::fromTheme(m_iconName); - emit iconChanged(m_icon); - } - ); - connect(this, &PreviewClient::desktopChanged, this, - [this](int) { - emit onAllDesktopsChanged(isOnAllDesktops()); - } - ); + [this]() + { + m_icon = QIcon::fromTheme(m_iconName); + emit iconChanged(m_icon); + }); + connect(this, &PreviewClient::desktopChanged, this, [this](int) { emit onAllDesktopsChanged(isOnAllDesktops()); }); /* connect(m_palette, &KWin::Decoration::DecorationPalette::changed, [this]() { emit paletteChanged(m_palette->palette()); });*/ - auto emitEdgesChanged = [this, c]() { - c->adjacentScreenEdgesChanged(adjacentScreenEdges()); - }; - connect(this, &PreviewClient::bordersTopEdgeChanged, this, emitEdgesChanged); - connect(this, &PreviewClient::bordersLeftEdgeChanged, this, emitEdgesChanged); - connect(this, &PreviewClient::bordersRightEdgeChanged, this, emitEdgesChanged); + auto emitEdgesChanged = [this, c]() { c->adjacentScreenEdgesChanged(adjacentScreenEdges()); }; + connect(this, &PreviewClient::bordersTopEdgeChanged, this, emitEdgesChanged); + connect(this, &PreviewClient::bordersLeftEdgeChanged, this, emitEdgesChanged); + connect(this, &PreviewClient::bordersRightEdgeChanged, this, emitEdgesChanged); connect(this, &PreviewClient::bordersBottomEdgeChanged, this, emitEdgesChanged); setColorScheme("kdeglobals"); @@ -156,11 +120,13 @@ int PreviewClient::desktop() const void PreviewClient::setDesktop(int desktop) { - if (desktop == 0) { + if (desktop == 0) + { desktop = 1; } - if (m_desktop == desktop) { + if (m_desktop == desktop) + { return; } @@ -280,17 +246,19 @@ QColor PreviewClient::color(KDecoration2::ColorGroup group, KDecoration2::ColorR void PreviewClient::setColorScheme(QString scheme) { - if (m_colorScheme == scheme && !m_colorScheme.isEmpty()) { + if (m_colorScheme == scheme && !m_colorScheme.isEmpty()) + { return; } m_colorScheme = scheme; - if (m_palette) { + if (m_palette) + { m_palette->deleteLater(); } - m_palette = new Decoration::Applet::DecorationPalette(scheme); + m_palette = new DecorationPalette(scheme); emit paletteChanged(m_palette->palette()); } @@ -299,19 +267,23 @@ Qt::Edges PreviewClient::adjacentScreenEdges() const { Qt::Edges edges; - if (m_bordersBottomEdge) { + if (m_bordersBottomEdge) + { edges |= Qt::BottomEdge; } - if (m_bordersLeftEdge) { + if (m_bordersLeftEdge) + { edges |= Qt::LeftEdge; } - if (m_bordersRightEdge) { + if (m_bordersRightEdge) + { edges |= Qt::RightEdge; } - if (m_bordersTopEdge) { + if (m_bordersTopEdge) + { edges |= Qt::TopEdge; } @@ -350,7 +322,8 @@ bool PreviewClient::bordersTopEdge() const void PreviewClient::setBordersBottomEdge(bool enabled) { - if (m_bordersBottomEdge == enabled) { + if (m_bordersBottomEdge == enabled) + { return; } @@ -360,7 +333,8 @@ void PreviewClient::setBordersBottomEdge(bool enabled) void PreviewClient::setBordersLeftEdge(bool enabled) { - if (m_bordersLeftEdge == enabled) { + if (m_bordersLeftEdge == enabled) + { return; } @@ -370,7 +344,8 @@ void PreviewClient::setBordersLeftEdge(bool enabled) void PreviewClient::setBordersRightEdge(bool enabled) { - if (m_bordersRightEdge == enabled) { + if (m_bordersRightEdge == enabled) + { return; } @@ -380,7 +355,8 @@ void PreviewClient::setBordersRightEdge(bool enabled) void PreviewClient::setBordersTopEdge(bool enabled) { - if (m_bordersTopEdge == enabled) { + if (m_bordersTopEdge == enabled) + { return; } @@ -388,28 +364,26 @@ void PreviewClient::setBordersTopEdge(bool enabled) emit bordersTopEdgeChanged(enabled); } - #if KDECORATION2_VERSION_MAJOR > 5 || KDECORATION2_VERSION_MINOR >= 13 void PreviewClient::requestShowToolTip(const QString &text) { Q_UNUSED(text) - //qDebug() << "tooltip show requested with text:" << text; + // qDebug() << "tooltip show requested with text:" << text; } void PreviewClient::requestHideToolTip() { - //qDebug() << "tooltip hide requested"; + // qDebug() << "tooltip hide requested"; } #endif #if KDECORATION2_VERSION_MAJOR > 5 || KDECORATION2_VERSION_MINOR >= 18 QSize PreviewClient::size() const { - return {m_width, m_height}; + return { m_width, m_height }; } #endif - #if KDECORATION2_VERSION_MAJOR <= 5 && KDECORATION2_VERSION_MINOR <= 20 void PreviewClient::requestShowWindowMenu() { @@ -422,7 +396,6 @@ void PreviewClient::requestShowWindowMenu(const QRect &rect) } #endif - void PreviewClient::requestClose() { emit closeRequested(); @@ -435,13 +408,18 @@ void PreviewClient::requestContextHelp() void PreviewClient::requestToggleMaximization(Qt::MouseButtons buttons) { - if (buttons.testFlag(Qt::LeftButton)) { + if (buttons.testFlag(Qt::LeftButton)) + { const bool set = !isMaximized(); setMaximizedHorizontally(set); setMaximizedVertically(set); - } else if (buttons.testFlag(Qt::RightButton)) { + } + else if (buttons.testFlag(Qt::RightButton)) + { setMaximizedHorizontally(!isMaximizedHorizontally()); - } else if (buttons.testFlag(Qt::MiddleButton)) { + } + else if (buttons.testFlag(Qt::MiddleButton)) + { setMaximizedVertically(!isMaximizedVertically()); } } @@ -482,15 +460,16 @@ void PreviewClient::requestToggleShade() setShaded(!isShaded()); } -#define SETTER(type, name, variable) \ - void PreviewClient::name(type variable) \ -{ \ - if (m_##variable == variable) { \ - return; \ -} \ - m_##variable = variable; \ - emit variable##Changed(m_##variable); \ -} +#define SETTER(type, name, variable) \ + void PreviewClient::name(type variable) \ + { \ + if (m_##variable == variable) \ + { \ + return; \ + } \ + m_##variable = variable; \ + emit variable##Changed(m_##variable); \ + } #define SETTER2(name, variable) SETTER(bool, name, variable) @@ -516,6 +495,3 @@ SETTER2(setProvidesContextHelp, providesContextHelp) #undef SETTER2 #undef SETTER - -} // namespace Applet -} // namespace Decoration diff --git a/libappletdecoration/previewclient.h b/libappletdecoration/previewclient.h index 5822412..66f2644 100644 --- a/libappletdecoration/previewclient.h +++ b/libappletdecoration/previewclient.h @@ -26,19 +26,17 @@ #include "decorationpalette.h" -#include - #include #include #include +#include #include class QAbstractItemModel; -namespace Decoration { -namespace Applet { - -class PreviewClient : public QObject, public KDecoration2::ApplicationMenuEnabledDecoratedClientPrivate +class PreviewClient + : public QObject + , public KDecoration2::ApplicationMenuEnabledDecoratedClientPrivate { Q_OBJECT Q_PROPERTY(KDecoration2::Decoration *decoration READ decoration CONSTANT) @@ -64,11 +62,11 @@ class PreviewClient : public QObject, public KDecoration2::ApplicationMenuEnable Q_PROPERTY(bool providesContextHelp READ providesContextHelp WRITE setProvidesContextHelp NOTIFY providesContextHelpChanged) Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) - Q_PROPERTY(bool bordersTopEdge READ bordersTopEdge WRITE setBordersTopEdge NOTIFY bordersTopEdgeChanged) - Q_PROPERTY(bool bordersLeftEdge READ bordersLeftEdge WRITE setBordersLeftEdge NOTIFY bordersLeftEdgeChanged) - Q_PROPERTY(bool bordersRightEdge READ bordersRightEdge WRITE setBordersRightEdge NOTIFY bordersRightEdgeChanged) + Q_PROPERTY(bool bordersTopEdge READ bordersTopEdge WRITE setBordersTopEdge NOTIFY bordersTopEdgeChanged) + Q_PROPERTY(bool bordersLeftEdge READ bordersLeftEdge WRITE setBordersLeftEdge NOTIFY bordersLeftEdgeChanged) + Q_PROPERTY(bool bordersRightEdge READ bordersRightEdge WRITE setBordersRightEdge NOTIFY bordersRightEdgeChanged) Q_PROPERTY(bool bordersBottomEdge READ bordersBottomEdge WRITE setBordersBottomEdge NOTIFY bordersBottomEdgeChanged) -public: + public: explicit PreviewClient(KDecoration2::DecoratedClient *client, KDecoration2::Decoration *decoration); virtual ~PreviewClient(); @@ -166,7 +164,7 @@ public: void setBordersRightEdge(bool enabled); void setBordersBottomEdge(bool enabled); -Q_SIGNALS: + Q_SIGNALS: void captionChanged(const QString &); void iconChanged(const QIcon &); void iconNameChanged(const QString &); @@ -200,12 +198,12 @@ Q_SIGNALS: void minimizeRequested(); void closeRequested(); -private: + private: QString m_caption; QIcon m_icon; QString m_iconName; QString m_colorScheme; - Decoration::Applet::DecorationPalette *m_palette{nullptr}; + DecorationPalette *m_palette{ nullptr }; bool m_active; bool m_closeable; bool m_keepBelow; @@ -229,7 +227,4 @@ private: bool m_bordersBottomEdge; }; -} // namespace Applet -} // namespace Decoration - #endif diff --git a/libappletdecoration/previewsettings.cpp b/libappletdecoration/previewsettings.cpp index 51f4e93..432ae99 100644 --- a/libappletdecoration/previewsettings.cpp +++ b/libappletdecoration/previewsettings.cpp @@ -22,19 +22,15 @@ */ #include "previewsettings.h" -#include "previewbridge.h" + #include "buttonsmodel.h" +#include "previewbridge.h" #include - #include #include -namespace Decoration { -namespace Applet { - -BorderSizesModel::BorderSizesModel(QObject *parent) - : QAbstractListModel(parent) +BorderSizesModel::BorderSizesModel(QObject *parent) : QAbstractListModel(parent) { } @@ -42,11 +38,13 @@ 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) { + if (!index.isValid() || index.row() < 0 || index.row() >= m_borders.count() || index.column() != 0) + { return QVariant(); } - if (role != Qt::DisplayRole && role != Qt::UserRole) { + if (role != Qt::DisplayRole && role != Qt::UserRole) + { return QVariant(); } @@ -55,14 +53,15 @@ QVariant BorderSizesModel::data(const QModelIndex &index, int role) const int BorderSizesModel::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) { + if (parent.isValid()) + { return 0; } return m_borders.count(); } -QHash< int, QByteArray > BorderSizesModel::roleNames() const +QHash BorderSizesModel::roleNames() const { QHash roles; roles.insert(Qt::DisplayRole, QByteArrayLiteral("display")); @@ -70,55 +69,36 @@ QHash< int, QByteArray > BorderSizesModel::roleNames() const } PreviewSettings::PreviewSettings(KDecoration2::DecorationSettings *parent) - : QObject() - , KDecoration2::DecorationSettingsPrivate(parent) - , m_alphaChannelSupported(true) - , m_onAllDesktopsAvailable(true) - , m_closeOnDoubleClick(false) - , m_leftButtons(new ButtonsModel(QVector({ - KDecoration2::DecorationButtonType::Minimize, - KDecoration2::DecorationButtonType::Close, - KDecoration2::DecorationButtonType::Menu, - KDecoration2::DecorationButtonType::ApplicationMenu, - KDecoration2::DecorationButtonType::OnAllDesktops -}), this)) -, m_rightButtons(new ButtonsModel(QVector({ - KDecoration2::DecorationButtonType::ContextHelp, - KDecoration2::DecorationButtonType::Minimize, - KDecoration2::DecorationButtonType::Maximize, - KDecoration2::DecorationButtonType::Close -}), this)) -, m_availableButtons(new ButtonsModel(QVector({ - KDecoration2::DecorationButtonType::Menu, - KDecoration2::DecorationButtonType::ApplicationMenu, - KDecoration2::DecorationButtonType::OnAllDesktops, - KDecoration2::DecorationButtonType::Minimize, - KDecoration2::DecorationButtonType::Maximize, - KDecoration2::DecorationButtonType::Close, - KDecoration2::DecorationButtonType::ContextHelp, - KDecoration2::DecorationButtonType::Shade, - KDecoration2::DecorationButtonType::KeepBelow, - KDecoration2::DecorationButtonType::KeepAbove -}), this)) -, m_borderSizes(new BorderSizesModel(this)) -, m_borderSize(int(KDecoration2::BorderSize::Normal)) -, m_font(QFontDatabase::systemFont(QFontDatabase::TitleFont)) + : QObject(), KDecoration2::DecorationSettingsPrivate(parent), m_alphaChannelSupported(true), m_onAllDesktopsAvailable(true), m_closeOnDoubleClick(false), + m_leftButtons( + new ButtonsModel(QVector({ KDecoration2::DecorationButtonType::Minimize, KDecoration2::DecorationButtonType::Close, + KDecoration2::DecorationButtonType::Menu, KDecoration2::DecorationButtonType::ApplicationMenu, + KDecoration2::DecorationButtonType::OnAllDesktops }), + this)), + m_rightButtons( + new ButtonsModel(QVector({ KDecoration2::DecorationButtonType::ContextHelp, KDecoration2::DecorationButtonType::Minimize, + KDecoration2::DecorationButtonType::Maximize, KDecoration2::DecorationButtonType::Close }), + this)), + m_availableButtons( + new ButtonsModel(QVector({ KDecoration2::DecorationButtonType::Menu, KDecoration2::DecorationButtonType::ApplicationMenu, + KDecoration2::DecorationButtonType::OnAllDesktops, KDecoration2::DecorationButtonType::Minimize, + KDecoration2::DecorationButtonType::Maximize, KDecoration2::DecorationButtonType::Close, + KDecoration2::DecorationButtonType::ContextHelp, KDecoration2::DecorationButtonType::Shade, + KDecoration2::DecorationButtonType::KeepBelow, KDecoration2::DecorationButtonType::KeepAbove }), + this)), + m_borderSizes(new BorderSizesModel(this)), m_borderSize(int(KDecoration2::BorderSize::Normal)), m_font(QFontDatabase::systemFont(QFontDatabase::TitleFont)) { connect(this, &PreviewSettings::alphaChannelSupportedChanged, parent, &KDecoration2::DecorationSettings::alphaChannelSupportedChanged); connect(this, &PreviewSettings::onAllDesktopsAvailableChanged, parent, &KDecoration2::DecorationSettings::onAllDesktopsAvailableChanged); connect(this, &PreviewSettings::closeOnDoubleClickOnMenuChanged, parent, &KDecoration2::DecorationSettings::closeOnDoubleClickOnMenuChanged); connect(this, &PreviewSettings::fontChanged, parent, &KDecoration2::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); + 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); } @@ -151,7 +131,8 @@ bool PreviewSettings::isOnAllDesktopsAvailable() const void PreviewSettings::setAlphaChannelSupported(bool supported) { - if (m_alphaChannelSupported == supported) { + if (m_alphaChannelSupported == supported) + { return; } @@ -161,7 +142,8 @@ void PreviewSettings::setAlphaChannelSupported(bool supported) void PreviewSettings::setOnAllDesktopsAvailable(bool available) { - if (m_onAllDesktopsAvailable == available) { + if (m_onAllDesktopsAvailable == available) + { return; } @@ -171,7 +153,8 @@ void PreviewSettings::setOnAllDesktopsAvailable(bool available) void PreviewSettings::setCloseOnDoubleClickOnMenu(bool enabled) { - if (m_closeOnDoubleClick == enabled) { + if (m_closeOnDoubleClick == enabled) + { return; } @@ -179,12 +162,12 @@ void PreviewSettings::setCloseOnDoubleClickOnMenu(bool enabled) emit closeOnDoubleClickOnMenuChanged(enabled); } -QVector< KDecoration2::DecorationButtonType > PreviewSettings::decorationButtonsLeft() const +QVector PreviewSettings::decorationButtonsLeft() const { return m_leftButtons->buttons(); } -QVector< KDecoration2::DecorationButtonType > PreviewSettings::decorationButtonsRight() const +QVector PreviewSettings::decorationButtonsRight() const { return m_rightButtons->buttons(); } @@ -193,7 +176,8 @@ void PreviewSettings::addButtonToLeft(int row) { QModelIndex index = m_availableButtons->index(row); - if (!index.isValid()) { + if (!index.isValid()) + { return; } @@ -204,7 +188,8 @@ void PreviewSettings::addButtonToRight(int row) { QModelIndex index = m_availableButtons->index(row); - if (!index.isValid()) { + if (!index.isValid()) + { return; } @@ -213,7 +198,8 @@ void PreviewSettings::addButtonToRight(int row) void PreviewSettings::setBorderSizesIndex(int index) { - if (m_borderSize == index) { + if (m_borderSize == index) + { return; } @@ -229,7 +215,8 @@ KDecoration2::BorderSize PreviewSettings::borderSize() const void PreviewSettings::setFont(const QFont &font) { - if (m_font == font) { + if (m_font == font) + { return; } @@ -237,8 +224,7 @@ void PreviewSettings::setFont(const QFont &font) emit fontChanged(m_font); } -Settings::Settings(QObject *parent) - : QObject(parent) +Settings::Settings(QObject *parent) : QObject(parent) { connect(this, &Settings::bridgeChanged, this, &Settings::createSettings); } @@ -247,7 +233,8 @@ Settings::~Settings() = default; void Settings::setBridge(PreviewBridge *bridge) { - if (m_bridge == bridge) { + if (m_bridge == bridge) + { return; } @@ -262,9 +249,12 @@ PreviewBridge *Settings::bridge() const void Settings::createSettings() { - if (m_bridge.isNull()) { + if (m_bridge.isNull()) + { m_settings.reset(); - } else { + } + else + { m_settings = std::make_shared(m_bridge.data()); m_previewSettings = m_bridge->lastCreatedSettings(); m_previewSettings->setBorderSizesIndex(m_borderSize); @@ -286,13 +276,11 @@ KDecoration2::DecorationSettings *Settings::settingsPointer() const void Settings::setBorderSizesIndex(int index) { - if (m_borderSize == index) { + if (m_borderSize == index) + { return; } m_borderSize = index; emit borderSizesIndexChanged(m_borderSize); } - -} -} diff --git a/libappletdecoration/previewsettings.h b/libappletdecoration/previewsettings.h index 3a09962..2f5ef33 100644 --- a/libappletdecoration/previewsettings.h +++ b/libappletdecoration/previewsettings.h @@ -24,46 +24,35 @@ #ifndef KDECOARTIONS_PREVIEW_SETTINGS_H #define KDECOARTIONS_PREVIEW_SETTINGS_H -#include #include -#include +#include #include +#include #include -namespace KDecoration2 { -class DecorationSettings; -} - -namespace Decoration { -namespace Applet { - class ButtonsModel; class PreviewBridge; class BorderSizesModel : public QAbstractListModel { Q_OBJECT -public: + public: explicit BorderSizesModel(QObject *parent = 0); virtual ~BorderSizesModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; - QHash< int, QByteArray > roleNames() const override; -private: - QList m_borders = QList({ - KDecoration2::BorderSize::None, - KDecoration2::BorderSize::NoSides, - KDecoration2::BorderSize::Tiny, - KDecoration2::BorderSize::Normal, - KDecoration2::BorderSize::Large, - KDecoration2::BorderSize::VeryLarge, - KDecoration2::BorderSize::Huge, - KDecoration2::BorderSize::VeryHuge, - KDecoration2::BorderSize::Oversized - }); + QHash roleNames() const override; + + private: + QList m_borders = + QList({ KDecoration2::BorderSize::None, KDecoration2::BorderSize::NoSides, KDecoration2::BorderSize::Tiny, + KDecoration2::BorderSize::Normal, KDecoration2::BorderSize::Large, KDecoration2::BorderSize::VeryLarge, + KDecoration2::BorderSize::Huge, KDecoration2::BorderSize::VeryHuge, KDecoration2::BorderSize::Oversized }); }; -class PreviewSettings : public QObject, public KDecoration2::DecorationSettingsPrivate +class PreviewSettings + : public QObject + , public KDecoration2::DecorationSettingsPrivate { Q_OBJECT Q_PROPERTY(bool onAllDesktopsAvailable READ isOnAllDesktopsAvailable WRITE setOnAllDesktopsAvailable NOTIFY onAllDesktopsAvailableChanged) @@ -75,12 +64,13 @@ class PreviewSettings : public QObject, public KDecoration2::DecorationSettingsP Q_PROPERTY(QAbstractItemModel *borderSizesModel READ borderSizesModel CONSTANT) Q_PROPERTY(int borderSizesIndex READ borderSizesIndex WRITE setBorderSizesIndex NOTIFY borderSizesIndexChanged) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) -public: + public: explicit PreviewSettings(KDecoration2::DecorationSettings *parent); virtual ~PreviewSettings(); bool isAlphaChannelSupported() const override; bool isOnAllDesktopsAvailable() const override; - bool isCloseOnDoubleClickOnMenu() const override { + bool isCloseOnDoubleClickOnMenu() const override + { return m_closeOnDoubleClick; } KDecoration2::BorderSize borderSize() const override; @@ -92,34 +82,37 @@ public: QAbstractItemModel *leftButtonsModel() const; QAbstractItemModel *rightButtonsModel() const; QAbstractItemModel *availableButtonsModel() const; - QAbstractItemModel *borderSizesModel() const { + QAbstractItemModel *borderSizesModel() const + { return m_borderSizes; } - QVector< KDecoration2::DecorationButtonType > decorationButtonsLeft() const override; - QVector< KDecoration2::DecorationButtonType > decorationButtonsRight() const override; + QVector decorationButtonsLeft() const override; + QVector decorationButtonsRight() const override; Q_INVOKABLE void addButtonToLeft(int row); Q_INVOKABLE void addButtonToRight(int row); - int borderSizesIndex() const { + int borderSizesIndex() const + { return m_borderSize; } void setBorderSizesIndex(int index); - QFont font() const override{ + QFont font() const override + { return m_font; } void setFont(const QFont &font); -Q_SIGNALS: + Q_SIGNALS: void onAllDesktopsAvailableChanged(bool); void alphaChannelSupportedChanged(bool); void closeOnDoubleClickOnMenuChanged(bool); void borderSizesIndexChanged(int); void fontChanged(const QFont &); -private: + private: bool m_alphaChannelSupported; bool m_onAllDesktopsAvailable; bool m_closeOnDoubleClick; @@ -134,10 +127,10 @@ private: class Settings : public QObject { Q_OBJECT - Q_PROPERTY(Decoration::Applet::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) + Q_PROPERTY(PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) Q_PROPERTY(KDecoration2::DecorationSettings *settings READ settingsPointer NOTIFY settingsChanged) Q_PROPERTY(int borderSizesIndex READ borderSizesIndex WRITE setBorderSizesIndex NOTIFY borderSizesIndexChanged) -public: + public: explicit Settings(QObject *parent = nullptr); virtual ~Settings(); @@ -146,17 +139,18 @@ public: std::shared_ptr settings() const; KDecoration2::DecorationSettings *settingsPointer() const; - int borderSizesIndex() const { + int borderSizesIndex() const + { return m_borderSize; } void setBorderSizesIndex(int index); -Q_SIGNALS: + Q_SIGNALS: void bridgeChanged(); void settingsChanged(); void borderSizesIndexChanged(int); -private: + private: void createSettings(); QPointer m_bridge; std::shared_ptr m_settings; @@ -164,7 +158,4 @@ private: int m_borderSize = 3; }; -} -} - #endif diff --git a/libappletdecoration/previewshareddecoration.cpp b/libappletdecoration/previewshareddecoration.cpp index 25a3bc2..e10b37c 100644 --- a/libappletdecoration/previewshareddecoration.cpp +++ b/libappletdecoration/previewshareddecoration.cpp @@ -28,14 +28,10 @@ #include -namespace Decoration { -namespace Applet { - -SharedDecoration::SharedDecoration(QObject *parent) : - QObject(parent) +SharedDecoration::SharedDecoration(QObject *parent) : QObject(parent) { - connect(this, &Decoration::Applet::SharedDecoration::bridgeChanged, this, &Decoration::Applet::SharedDecoration::createDecoration); - connect(this, &Decoration::Applet::SharedDecoration::settingsChanged, this, &Decoration::Applet::SharedDecoration::applySettings); + connect(this, &SharedDecoration::bridgeChanged, this, &SharedDecoration::createDecoration); + connect(this, &SharedDecoration::settingsChanged, this, &SharedDecoration::applySettings); } SharedDecoration::~SharedDecoration() @@ -49,17 +45,19 @@ PreviewBridge *SharedDecoration::bridge() const void SharedDecoration::setBridge(PreviewBridge *bridge) { - if (m_bridge == bridge) { + if (m_bridge == bridge) + { return; } - if (m_bridge) { - connect(m_bridge, &Decoration::Applet::PreviewBridge::validChanged, this, &Decoration::Applet::SharedDecoration::createDecoration); + if (m_bridge) + { + connect(m_bridge, &PreviewBridge::validChanged, this, &SharedDecoration::createDecoration); } m_bridge = bridge; - connect(m_bridge, &Decoration::Applet::PreviewBridge::validChanged, this, &Decoration::Applet::SharedDecoration::createDecoration); + connect(m_bridge, &PreviewBridge::validChanged, this, &SharedDecoration::createDecoration); emit bridgeChanged(); } @@ -76,7 +74,8 @@ Settings *SharedDecoration::settings() const void SharedDecoration::setSettings(Settings *settings) { - if (m_settings == settings) { + if (m_settings == settings) + { return; } @@ -89,7 +88,8 @@ void SharedDecoration::setSettings(Settings *settings) void SharedDecoration::applySettings() { - if (!m_decoration || !m_settings) { + if (!m_decoration || !m_settings) + { return; } @@ -99,21 +99,25 @@ void SharedDecoration::applySettings() void SharedDecoration::createDecoration() { - if (!m_bridge || !m_settings) { + if (!m_bridge || !m_settings) + { return; } bool newDecoration = (m_bridge->plugin() != m_lastPlugin || m_bridge->theme() != m_lastTheme); - if (m_decoration && newDecoration) { + if (m_decoration && newDecoration) + { m_decoration->deleteLater(); } - if (newDecoration) { + if (newDecoration) + { m_decoration = m_bridge->createDecoration(this); } - if (m_decoration) { + if (m_decoration) + { m_decoration->setSettings(m_settings->settings()); m_decoration->init(); m_decoration->setObjectName("applet-window-buttons"); @@ -127,10 +131,8 @@ void SharedDecoration::createDecoration() void SharedDecoration::initDecoration() { - if (m_decoration) { + if (m_decoration) + { m_decoration->init(); } } - -} -} diff --git a/libappletdecoration/previewshareddecoration.h b/libappletdecoration/previewshareddecoration.h index ffc5636..1cd195b 100644 --- a/libappletdecoration/previewshareddecoration.h +++ b/libappletdecoration/previewshareddecoration.h @@ -23,18 +23,10 @@ #ifndef PREVIEWSHAREDDECORATION_H #define PREVIEWSHAREDDECORATION_H -#include - #include "previewbridge.h" #include "previewsettings.h" - -namespace KDecoration2 { -class Decoration; -} - -namespace Decoration { -namespace Applet { +#include class PreviewBridge; class PreviewButton; @@ -43,10 +35,10 @@ class Settings; class SharedDecoration : public QObject { Q_OBJECT - Q_PROPERTY(Decoration::Applet::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) - Q_PROPERTY(Decoration::Applet::Settings *settings READ settings WRITE setSettings NOTIFY settingsChanged) + Q_PROPERTY(PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged) + Q_PROPERTY(Settings *settings READ settings WRITE setSettings NOTIFY settingsChanged) -public: + public: explicit SharedDecoration(QObject *parent = nullptr); virtual ~SharedDecoration(); @@ -60,27 +52,24 @@ public: void initDecoration(); -public Q_SLOTS: + public Q_SLOTS: Q_INVOKABLE void createDecoration(); -Q_SIGNALS: + Q_SIGNALS: void bridgeChanged(); void decorationChanged(); void settingsChanged(); -private Q_SLOTS: + private Q_SLOTS: void applySettings(); -private: - QPointer m_bridge; + private: + QPointer m_bridge; QPointer m_decoration; - QPointer m_settings; + QPointer m_settings; QString m_lastPlugin; QString m_lastTheme; }; -} -} - #endif diff --git a/libappletdecoration/schemecolors.cpp b/libappletdecoration/schemecolors.cpp index 67884ed..754c48a 100644 --- a/libappletdecoration/schemecolors.cpp +++ b/libappletdecoration/schemecolors.cpp @@ -20,29 +20,24 @@ #include "schemecolors.h" -#include #include "commontools.h" -#include -#include -#include - #include #include #include +#include +#include +#include +#include using namespace Qt::StringLiterals; -namespace Decoration { -namespace Applet { - -SchemeColors::SchemeColors(QObject *parent, QString scheme, bool plasmaTheme) : - QObject(parent), - m_basedOnPlasmaTheme(plasmaTheme) +SchemeColors::SchemeColors(QObject *parent, QString scheme, bool plasmaTheme) : QObject(parent), m_basedOnPlasmaTheme(plasmaTheme) { QString pSchemeFile = possibleSchemeFile(scheme); - if (QFileInfo(pSchemeFile).exists()) { + if (QFileInfo(pSchemeFile).exists()) + { setSchemeFile(pSchemeFile); m_schemeName = schemeName(pSchemeFile); @@ -142,7 +137,8 @@ QString SchemeColors::SchemeColors::schemeFile() const void SchemeColors::setSchemeFile(QString file) { - if (m_schemeFile == file) { + if (m_schemeFile == file) + { return; } @@ -152,16 +148,19 @@ void SchemeColors::setSchemeFile(QString file) QString SchemeColors::possibleSchemeFile(QString scheme) { - if (scheme.startsWith("/") && scheme.endsWith("colors") && QFileInfo(scheme).exists()) { + if (scheme.startsWith("/") && scheme.endsWith("colors") && QFileInfo(scheme).exists()) + { return scheme; } QString tempScheme = scheme; - if (scheme == "kdeglobals") { + if (scheme == "kdeglobals") + { QString settingsFile = QDir::homePath() + "/.config/kdeglobals"; - if (QFileInfo(settingsFile).exists()) { + if (QFileInfo(settingsFile).exists()) + { KSharedConfigPtr filePtr = KSharedConfig::openConfig(settingsFile); KConfigGroup generalGroup = KConfigGroup(filePtr, u"General"_qs); #if KDECORATION2_VERSION_MAJOR > 5 || KDECORATION2_VERSION_MINOR >= 21 @@ -180,19 +179,22 @@ QString SchemeColors::possibleSchemeFile(QString scheme) QString SchemeColors::schemeName(QString originalFile) { - if (!(originalFile.startsWith("/") && originalFile.endsWith("colors") && QFileInfo(originalFile).exists())) { + if (!(originalFile.startsWith("/") && originalFile.endsWith("colors") && QFileInfo(originalFile).exists())) + { return ""; } - QString fileNameNoExt = originalFile; + QString fileNameNoExt = originalFile; int lastSlash = originalFile.lastIndexOf("/"); - if (lastSlash >= 0) { + if (lastSlash >= 0) + { fileNameNoExt.remove(0, lastSlash + 1); } - if (fileNameNoExt.endsWith(".colors")) { + if (fileNameNoExt.endsWith(".colors")) + { fileNameNoExt.remove(".colors"); } @@ -204,7 +206,8 @@ QString SchemeColors::schemeName(QString originalFile) void SchemeColors::updateScheme() { - if (m_schemeFile.isEmpty() || !QFileInfo(m_schemeFile).exists()) { + if (m_schemeFile.isEmpty() || !QFileInfo(m_schemeFile).exists()) + { return; } @@ -212,15 +215,18 @@ void SchemeColors::updateScheme() KConfigGroup wmGroup = KConfigGroup(filePtr, u"WM"_qs); KConfigGroup selGroup = KConfigGroup(filePtr, u"Colors:Selection"_qs); KConfigGroup viewGroup = KConfigGroup(filePtr, u"Colors:View"_qs); - //KConfigGroup windowGroup = KConfigGroup(filePtr, "Colors:Window"); + // KConfigGroup windowGroup = KConfigGroup(filePtr, "Colors:Window"); KConfigGroup buttonGroup = KConfigGroup(filePtr, u"Colors:Button"_qs); - if (!m_basedOnPlasmaTheme) { + if (!m_basedOnPlasmaTheme) + { m_activeBackgroundColor = wmGroup.readEntry("activeBackground", QColor()); m_activeTextColor = wmGroup.readEntry("activeForeground", QColor()); m_inactiveBackgroundColor = wmGroup.readEntry("inactiveBackground", QColor()); m_inactiveTextColor = wmGroup.readEntry("inactiveForeground", QColor()); - } else { + } + else + { m_activeBackgroundColor = viewGroup.readEntry("BackgroundNormal", QColor()); m_activeTextColor = viewGroup.readEntry("ForegroundNormal", QColor()); m_inactiveBackgroundColor = viewGroup.readEntry("BackgroundAlternate", QColor()); @@ -231,7 +237,8 @@ void SchemeColors::updateScheme() m_highlightedTextColor = selGroup.readEntry("ForegroundNormal", QColor()); m_positiveColor = selGroup.readEntry("ForegroundPositive", QColor()); - m_neutralText = selGroup.readEntry("ForegroundNeutral", QColor());; + m_neutralText = selGroup.readEntry("ForegroundNeutral", QColor()); + ; m_negativeText = selGroup.readEntry("ForegroundNegative", QColor()); m_buttonTextColor = buttonGroup.readEntry("ForegroundNormal", QColor()); @@ -241,6 +248,3 @@ void SchemeColors::updateScheme() emit colorsChanged(); } - -} -} diff --git a/libappletdecoration/schemecolors.h b/libappletdecoration/schemecolors.h index b01e573..fb882ba 100644 --- a/libappletdecoration/schemecolors.h +++ b/libappletdecoration/schemecolors.h @@ -21,13 +21,10 @@ #ifndef SCHEMECOLORS_H #define SCHEMECOLORS_H -#include #include +#include -namespace Decoration { -namespace Applet { - -class SchemeColors: public QObject +class SchemeColors : public QObject { Q_OBJECT Q_PROPERTY(QString schemeFile READ schemeFile NOTIFY schemeFileChanged) @@ -48,7 +45,7 @@ class SchemeColors: public QObject Q_PROPERTY(QColor buttonHoverColor READ buttonHoverColor NOTIFY colorsChanged) Q_PROPERTY(QColor buttonFocusColor READ buttonFocusColor NOTIFY colorsChanged) -public: + public: SchemeColors(QObject *parent, QString scheme, bool plasmaTheme = false); ~SchemeColors() override; @@ -75,15 +72,15 @@ public: static QString possibleSchemeFile(QString scheme); static QString schemeName(QString originalFile); -signals: + signals: void colorsChanged(); void schemeFileChanged(); -public slots: + public slots: void updateScheme(); -private: - bool m_basedOnPlasmaTheme{false}; + private: + bool m_basedOnPlasmaTheme{ false }; QString m_schemeName; QString m_schemeFile; @@ -106,7 +103,4 @@ private: QColor m_buttonFocusColor; }; -} -} - #endif diff --git a/libappletdecoration/schemesmodel.cpp b/libappletdecoration/schemesmodel.cpp index ebb0a6c..12264cb 100644 --- a/libappletdecoration/schemesmodel.cpp +++ b/libappletdecoration/schemesmodel.cpp @@ -26,11 +26,7 @@ #include #include -namespace Decoration { -namespace Applet { - -SchemesModel::SchemesModel(QObject *parent) - : QAbstractListModel(parent) +SchemesModel::SchemesModel(QObject *parent) : QAbstractListModel(parent) { initSchemes(); } @@ -42,36 +38,42 @@ SchemesModel::~SchemesModel() QVariant SchemesModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= m_schemes.count()) { + if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= m_schemes.count()) + { return QVariant(); } const SchemeColors *d = m_schemes[index.row()]; - switch (role) { + switch (role) + { case Qt::DisplayRole: - if (index.row() == 0) { + if (index.row() == 0) + { return "Current"; - } else if (index.row() == 1) { + } + else if (index.row() == 1) + { return "Plasma Theme"; } return d->schemeName(); case Qt::UserRole + 4: - if (index.row() == 0) { + if (index.row() == 0) + { return "kdeglobals"; - } else if (index.row() == 1) { + } + else if (index.row() == 1) + { return "_plasmatheme_"; } return d->schemeFile(); - case Qt::UserRole + 5: - return d->backgroundColor(); + case Qt::UserRole + 5: return d->backgroundColor(); - case Qt::UserRole + 6: - return d->textColor(); + case Qt::UserRole + 6: return d->textColor(); } return QVariant(); @@ -79,32 +81,33 @@ QVariant SchemesModel::data(const QModelIndex &index, int role) const int SchemesModel::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) { + if (parent.isValid()) + { return 0; } return m_schemes.count(); } -QHash< int, QByteArray > SchemesModel::roleNames() const +QHash SchemesModel::roleNames() const { - QHash roles({ - {Qt::DisplayRole, QByteArrayLiteral("display")}, - {Qt::UserRole + 4, QByteArrayLiteral("file")}, - {Qt::UserRole + 5, QByteArrayLiteral("backgroundColor")}, - {Qt::UserRole + 6, QByteArrayLiteral("textColor")} - }); + QHash roles({ { Qt::DisplayRole, QByteArrayLiteral("display") }, + { Qt::UserRole + 4, QByteArrayLiteral("file") }, + { Qt::UserRole + 5, QByteArrayLiteral("backgroundColor") }, + { Qt::UserRole + 6, QByteArrayLiteral("textColor") } }); return roles; } QColor SchemesModel::backgroundOf(const int &index) const { - if (index == 0) { + if (index == 0) + { auto ind = indexOf(m_defaultSchemeFile); - return ind>=0 ? m_schemes[ind]->backgroundColor() : QColor("transparent"); + return ind >= 0 ? m_schemes[ind]->backgroundColor() : QColor("transparent"); } - if (index>0 && index 0 && index < m_schemes.count()) + { return m_schemes[index]->backgroundColor(); } @@ -115,7 +118,7 @@ QString SchemesModel::defaultSchemeFile() const { auto ind = indexOf(m_defaultSchemeFile); - return ind>=0 ? m_schemes[ind]->schemeFile() : QString(); + return ind >= 0 ? m_schemes[ind]->schemeFile() : QString(); } void SchemesModel::initSchemes() @@ -131,12 +134,17 @@ void SchemesModel::initSchemes() QStringList registeredSchemes; - for(auto path : standardPaths) { + for (auto path : standardPaths) + { QDir directory(path); - QStringList tempSchemes = directory.entryList(QStringList() << "*.colors" << "*.COLORS", QDir::Files); + QStringList tempSchemes = directory.entryList(QStringList() << "*.colors" + << "*.COLORS", + QDir::Files); - foreach (QString filename, tempSchemes) { - if (!registeredSchemes.contains(filename)) { + foreach (QString filename, tempSchemes) + { + if (!registeredSchemes.contains(filename)) + { QString fullPath = path + "/" + filename; insertSchemeInList(fullPath); registeredSchemes << filename; @@ -149,20 +157,23 @@ void SchemesModel::insertSchemeInList(QString file) { SchemeColors *tempScheme = new SchemeColors(this, file); - int atPos{0}; + int atPos{ 0 }; - for (int i = 0; i < m_schemes.count(); i++) { + for (int i = 0; i < m_schemes.count(); i++) + { SchemeColors *s = m_schemes[i]; int result = QString::compare(tempScheme->schemeName(), s->schemeName(), Qt::CaseInsensitive); - if (result < 0) { + if (result < 0) + { atPos = i; break; - } else { + } + else + { atPos = i + 1; } - } m_schemes.insert(atPos, tempScheme); @@ -170,24 +181,25 @@ void SchemesModel::insertSchemeInList(QString file) int SchemesModel::indexOf(QString file) const { - if (file.isEmpty() || file == "kdeglobals") { + if (file.isEmpty() || file == "kdeglobals") + { return 0; } - if (file == "_plasmatheme_") { + if (file == "_plasmatheme_") + { return 1; } - for (int i = 0; i < m_schemes.count(); i++) { + for (int i = 0; i < m_schemes.count(); i++) + { SchemeColors *s = m_schemes[i]; - if (s->schemeFile() == file) { + if (s->schemeFile() == file) + { return i; } } return -1; } - -} -} diff --git a/libappletdecoration/schemesmodel.h b/libappletdecoration/schemesmodel.h index 3050cd1..5a3df1b 100644 --- a/libappletdecoration/schemesmodel.h +++ b/libappletdecoration/schemesmodel.h @@ -23,39 +23,33 @@ #include -namespace Decoration { -namespace Applet { - class SchemeColors; class SchemesModel : public QAbstractListModel { Q_OBJECT -public: + public: explicit SchemesModel(QObject *parent = nullptr); virtual ~SchemesModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; - QHash< int, QByteArray > roleNames() const override; + QHash roleNames() const override; Q_INVOKABLE int indexOf(QString file) const; Q_INVOKABLE QColor backgroundOf(const int &index) const; Q_INVOKABLE QString defaultSchemeFile() const; -private slots: + private slots: void initSchemes(); -private: + private: void insertSchemeInList(QString file); -private: + private: QString m_defaultSchemeFile; - QList m_schemes; + QList m_schemes; }; -} -} - #endif diff --git a/libappletdecoration/themeextended.cpp b/libappletdecoration/themeextended.cpp index e9090df..7168180 100644 --- a/libappletdecoration/themeextended.cpp +++ b/libappletdecoration/themeextended.cpp @@ -20,26 +20,18 @@ #include "themeextended.h" -// local #include "commontools.h" #include "schemecolors.h" -// Qt +#include +#include +#include #include #include -// KDE -#include -#include -#include - #define DEFAULTCOLORSCHEME "default.colors" -namespace Decoration { -namespace Applet { - -ExtendedTheme::ExtendedTheme(QObject *parent) : - QObject(parent) +ExtendedTheme::ExtendedTheme(QObject *parent) : QObject(parent) { load(); @@ -64,7 +56,8 @@ QObject *ExtendedTheme::colors() const void ExtendedTheme::setOriginalSchemeFile(const QString &file) { - if (m_originalSchemePath == file) { + if (m_originalSchemePath == file) + { return; } @@ -84,7 +77,8 @@ void ExtendedTheme::setOriginalSchemeFile(const QString &file) void ExtendedTheme::updateDefaultScheme() { QString defaultFilePath = m_extendedThemeDir.path() + "/" + DEFAULTCOLORSCHEME; - if (QFileInfo(defaultFilePath).exists()) { + if (QFileInfo(defaultFilePath).exists()) + { QFile(defaultFilePath).remove(); } @@ -93,7 +87,8 @@ void ExtendedTheme::updateDefaultScheme() updateDefaultSchemeValues(); - if (m_colorsScheme) { + if (m_colorsScheme) + { disconnect(m_colorsScheme, &SchemeColors::colorsChanged, this, &ExtendedTheme::themeChanged); m_colorsScheme->deleteLater(); } @@ -112,7 +107,8 @@ void ExtendedTheme::updateDefaultSchemeValues() KSharedConfigPtr originalPtr = KSharedConfig::openConfig(m_originalSchemePath); KSharedConfigPtr defaultPtr = KSharedConfig::openConfig(m_colorsSchemePath); - if (originalPtr && defaultPtr) { + if (originalPtr && defaultPtr) + { KConfigGroup normalWindowGroup(originalPtr, u"Colors:Window"_qs); KConfigGroup defaultWMGroup(defaultPtr, u"WM"_qs); @@ -127,9 +123,12 @@ void ExtendedTheme::loadThemePaths() { m_themePath = AppletDecoration::standardPath("plasma/desktoptheme/" + m_theme.themeName()); - if (QDir(m_themePath+"/widgets").exists()) { + if (QDir(m_themePath + "/widgets").exists()) + { m_themeWidgetsPath = m_themePath + "/widgets"; - } else { + } + else + { m_themeWidgetsPath = AppletDecoration::standardPath("plasma/desktoptheme/default/widgets"); } @@ -138,37 +137,44 @@ void ExtendedTheme::loadThemePaths() qDebug() << "Window Buttons : theme widgets path ::: " << m_themeWidgetsPath; //! clear kde connections - for (auto &c : m_kdeConnections) { + for (auto &c : m_kdeConnections) + { disconnect(c); } //! assign color schemes QString themeColorScheme = m_themePath + "/colors"; - if (QFileInfo(themeColorScheme).exists()) { + if (QFileInfo(themeColorScheme).exists()) + { setOriginalSchemeFile(themeColorScheme); - } else { + } + else + { //! when plasma theme uses the kde colors //! we track when kde color scheme is changing QString kdeSettingsFile = QDir::homePath() + "/.config/kdeglobals"; KDirWatch::self()->addFile(kdeSettingsFile); - m_kdeConnections[0] = connect(KDirWatch::self(), &KDirWatch::dirty, this, [ &, kdeSettingsFile](const QString & path) { - if (path == kdeSettingsFile) { - this->setOriginalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals")); - } - }); + m_kdeConnections[0] = connect(KDirWatch::self(), &KDirWatch::dirty, this, + [&, kdeSettingsFile](const QString &path) + { + if (path == kdeSettingsFile) + { + this->setOriginalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals")); + } + }); - m_kdeConnections[1] = connect(KDirWatch::self(), &KDirWatch::created, this, [ &, kdeSettingsFile](const QString & path) { - if (path == kdeSettingsFile) { - this->setOriginalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals")); - } - }); + m_kdeConnections[1] = connect(KDirWatch::self(), &KDirWatch::created, this, + [&, kdeSettingsFile](const QString &path) + { + if (path == kdeSettingsFile) + { + this->setOriginalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals")); + } + }); setOriginalSchemeFile(SchemeColors::possibleSchemeFile("kdeglobals")); } } - -} -} diff --git a/libappletdecoration/themeextended.h b/libappletdecoration/themeextended.h index aadf648..7e78e38 100644 --- a/libappletdecoration/themeextended.h +++ b/libappletdecoration/themeextended.h @@ -21,55 +21,42 @@ #ifndef PLASMAEXTENDEDTHEME_H #define PLASMAEXTENDEDTHEME_H -// C++ -#include +#include "schemecolors.h" -// Qt -#include -#include - -// KDE #include #include - -// Plasma #include #include +#include +#include +#include -namespace Decoration { -namespace Applet { -class SchemeColors; -} -} - -namespace Decoration { -namespace Applet { - -class ExtendedTheme: public QObject +class ExtendedTheme : public QObject { Q_OBJECT Q_PROPERTY(QObject *colors READ colors NOTIFY colorsChanged) -public: + public: ExtendedTheme(QObject *parent = nullptr); - ~ExtendedTheme() override;; + ~ExtendedTheme() override; + ; QObject *colors() const; void load(); -signals: + signals: void colorsChanged(); void themeChanged(); -private: + private: void loadThemePaths(); void setOriginalSchemeFile(const QString &file); void updateDefaultScheme(); void updateDefaultSchemeValues(); -private: + private: QString m_themePath; QString m_themeWidgetsPath; QString m_colorsSchemePath; @@ -81,10 +68,7 @@ private: KConfigGroup m_themeGroup; Plasma::Theme m_theme; - SchemeColors *m_colorsScheme{nullptr}; + SchemeColors *m_colorsScheme{ nullptr }; }; -} -} - #endif diff --git a/libappletdecoration/types.cpp b/libappletdecoration/types.cpp index 9f0a3a2..c4bf55c 100644 --- a/libappletdecoration/types.cpp +++ b/libappletdecoration/types.cpp @@ -1,20 +1,20 @@ /* -* Copyright 2018 Michail Vourlakos -* -* This file is part of the libappletdecoration library -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2018 Michail Vourlakos + * + * This file is part of the libappletdecoration library + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #include "types.h" diff --git a/libappletdecoration/types.h b/libappletdecoration/types.h index 254f3dc..25d8343 100644 --- a/libappletdecoration/types.h +++ b/libappletdecoration/types.h @@ -1,39 +1,36 @@ /* -* Copyright 2018 Michail Vourlakos -* -* This file is part of the libappletdecoration library -* -* Latte-Dock 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. -* -* Latte-Dock 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 . -*/ + * Copyright 2018 Michail Vourlakos + * + * This file is part of the libappletdecoration library + * + * Latte-Dock 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. + * + * Latte-Dock 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 . + */ #ifndef TYPES_H #define TYPES_H -#include #include #include - -namespace Decoration { -namespace Applet { +#include class Types { Q_GADGET -public: + public: Types() = delete; - ~Types() {}; + ~Types(){}; enum ButtonType { @@ -96,10 +93,6 @@ public: Latte }; Q_ENUM(ContainmentType) - }; -} -} - #endif diff --git a/libappletdecoration/windowsystem.cpp b/libappletdecoration/windowsystem.cpp index 05ecb28..38100d7 100644 --- a/libappletdecoration/windowsystem.cpp +++ b/libappletdecoration/windowsystem.cpp @@ -23,12 +23,7 @@ #include #include -namespace Decoration { -namespace Applet { - - -WindowSystem::WindowSystem(QObject *parent) - : QObject(parent) +WindowSystem::WindowSystem(QObject *parent) : QObject(parent) { } @@ -48,7 +43,8 @@ bool WindowSystem::kwin_disabledMaximizedBorders() const void WindowSystem::setDisabledMaximizedBorders(bool disable) { - if (kwin_disabledMaximizedBorders() == disable) { + if (kwin_disabledMaximizedBorders() == disable) + { return; } @@ -61,10 +57,8 @@ void WindowSystem::setDisabledMaximizedBorders(bool disable) QDBusInterface iface("org.kde.KWin", "/KWin", "", QDBusConnection::sessionBus()); - if (iface.isValid()) { + if (iface.isValid()) + { iface.call("reconfigure"); } } - -} -} diff --git a/libappletdecoration/windowsystem.h b/libappletdecoration/windowsystem.h index 881b6ea..6502cce 100644 --- a/libappletdecoration/windowsystem.h +++ b/libappletdecoration/windowsystem.h @@ -23,25 +23,18 @@ #include -namespace Decoration { -namespace Applet { - class WindowSystem : public QObject { Q_OBJECT -public: + public: explicit WindowSystem(QObject *parent = nullptr); virtual ~WindowSystem(); -public Q_SLOTS: + public Q_SLOTS: Q_INVOKABLE void setDisabledMaximizedBorders(bool disable); -private: + private: bool kwin_disabledMaximizedBorders() const; }; -} -} - #endif - diff --git a/package/contents/code/tools.js b/package/contents/code/tools.js index de3bce8..27938fb 100644 --- a/package/contents/code/tools.js +++ b/package/contents/code/tools.js @@ -20,39 +20,39 @@ function addButton(preparedArray, buttonType) { if (buttonType === AppletDecoration.Types.Close) { preparedArray.push({ - buttonType: AppletDecoration.Types.Close, - windowOperation: AppletDecoration.Types.ActionClose - }); + buttonType: AppletDecoration.Types.Close, + windowOperation: AppletDecoration.Types.ActionClose + }); } else if (buttonType === AppletDecoration.Types.Maximize) { preparedArray.push({ - buttonType: AppletDecoration.Types.Maximize, - windowOperation: AppletDecoration.Types.ToggleMaximize - }); + buttonType: AppletDecoration.Types.Maximize, + windowOperation: AppletDecoration.Types.ToggleMaximize + }); } else if (buttonType === AppletDecoration.Types.Minimize) { preparedArray.push({ - buttonType: AppletDecoration.Types.Minimize, - windowOperation: AppletDecoration.Types.ToggleMinimize - }); + buttonType: AppletDecoration.Types.Minimize, + windowOperation: AppletDecoration.Types.ToggleMinimize + }); } else if (buttonType === AppletDecoration.Types.OnAllDesktops) { preparedArray.push({ - buttonType: AppletDecoration.Types.OnAllDesktops, - windowOperation: AppletDecoration.Types.TogglePinToAllDesktops - }); + buttonType: AppletDecoration.Types.OnAllDesktops, + windowOperation: AppletDecoration.Types.TogglePinToAllDesktops + }); } else if (buttonType === AppletDecoration.Types.Custom) { preparedArray.push({ - buttonType: AppletDecoration.Types.Custom, - windowOperation: -1 - }); - } else if (buttonType === AppletDecoration.Types.KeepAbove){ + buttonType: AppletDecoration.Types.Custom, + windowOperation: -1 + }); + } else if (buttonType === AppletDecoration.Types.KeepAbove) { preparedArray.push({ - buttonType: AppletDecoration.Types.KeepAbove, - windowOperation: AppletDecoration.Types.ToggleKeepAbove - }); + buttonType: AppletDecoration.Types.KeepAbove, + windowOperation: AppletDecoration.Types.ToggleKeepAbove + }); } } function indexOfSplitter(listModel) { - for (var i=0; i - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd"> + @@ -27,9 +26,9 @@ - - - + + + 0 @@ -44,8 +43,8 @@ - - + + 0 @@ -61,7 +60,7 @@ 100 - + 0 @@ -84,9 +83,9 @@ - - - + + + 0 diff --git a/package/contents/ui/LatteWindowsTracker.qml b/package/contents/ui/LatteWindowsTracker.qml index 8a0137a..4f00093 100644 --- a/package/contents/ui/LatteWindowsTracker.qml +++ b/package/contents/ui/LatteWindowsTracker.qml @@ -21,27 +21,23 @@ import QtQuick Item { id: latteWindowsTracker - property bool filterByScreen: true + property bool filterByScreen: true readonly property bool existsWindowActive: selectedTracker.lastActiveWindow.isValid && !lastActiveTaskItem.isMinimized && lastActiveTaskItem.isActive readonly property bool existsWindowShown: selectedTracker.lastActiveWindow.isValid && !lastActiveTaskItem.isMinimized - readonly property QtObject selectedTracker: filterByScreen ? latteBridge.windowsTracker.currentScreen : latteBridge.windowsTracker.allScreens - - readonly property Item lastActiveTaskItem: Item { + readonly property Item + lastActiveTaskItem: Item { readonly property string title: selectedTracker.lastActiveWindow.display readonly property bool isMinimized: selectedTracker.lastActiveWindow.isMinimized readonly property bool isMaximized: selectedTracker.lastActiveWindow.isMaximized readonly property bool isActive: selectedTracker.lastActiveWindow.isActive readonly property bool isOnAllDesktops: selectedTracker.lastActiveWindow.isOnAllDesktops readonly property bool isKeepAbove: selectedTracker.lastActiveWindow.isKeepAbove - readonly property bool isClosable: selectedTracker.lastActiveWindow.hasOwnProperty("isClosable") ? selectedTracker.lastActiveWindow.isClosable : true readonly property bool isMinimizable: selectedTracker.lastActiveWindow.hasOwnProperty("isMinimizable") ? selectedTracker.lastActiveWindow.isMinimizable : true readonly property bool isMaximizable: selectedTracker.lastActiveWindow.hasOwnProperty("isMaximizable") ? selectedTracker.lastActiveWindow.isMaximizable : true - readonly property bool isVirtualDesktopsChangeable: selectedTracker.lastActiveWindow.hasOwnProperty("isVirtualDesktopsChangeable") ? - selectedTracker.lastActiveWindow.isVirtualDesktopsChangeable : true - + readonly property bool isVirtualDesktopsChangeable: selectedTracker.lastActiveWindow.hasOwnProperty("isVirtualDesktopsChangeable") ? selectedTracker.lastActiveWindow.isVirtualDesktopsChangeable : true readonly property int winId: selectedTracker.lastActiveWindow.hasOwnProperty("winId") ? selectedTracker.lastActiveWindow.winId : -1 } @@ -61,8 +57,8 @@ Item { selectedTracker.lastActiveWindow.requestToggleIsOnAllDesktops(); } - function toggleKeepAbove(){ + function toggleKeepAbove() { selectedTracker.lastActiveWindow.requestToggleKeepAbove(); } -} +} diff --git a/package/contents/ui/PlasmaTasksModel.qml b/package/contents/ui/PlasmaTasksModel.qml index b7cc5aa..e2b415d 100644 --- a/package/contents/ui/PlasmaTasksModel.qml +++ b/package/contents/ui/PlasmaTasksModel.qml @@ -17,22 +17,50 @@ * along with this program. If not, see . */ -import QtQuick 2.7 import QtQml.Models 2.2 - -import org.kde.plasma.plasmoid 2.0 +import QtQuick 2.7 import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.plasmoid 2.0 import org.kde.taskmanager 0.1 as TaskManager Item { id: plasmaTasksItem - property bool filterByScreen: true + property bool filterByScreen: true readonly property bool existsWindowActive: lastActiveTaskItem && tasksRepeater.count > 0 && (root.perScreenActive || lastActiveTaskItem.isActive) readonly property bool existsWindowShown: lastActiveTaskItem && tasksRepeater.count > 0 && !lastActiveTaskItem.isMinimized - property Item lastActiveTaskItem: null + function toggleMaximized() { + if (lastActiveTaskItem) + lastActiveTaskItem.toggleMaximized(); + + } + + function toggleMinimized() { + if (lastActiveTaskItem) + lastActiveTaskItem.toggleMinimized(); + + } + + function toggleClose() { + if (lastActiveTaskItem) + lastActiveTaskItem.toggleClose(); + + } + + function togglePinToAllDesktops() { + if (lastActiveTaskItem) + lastActiveTaskItem.togglePinToAllDesktops(); + + } + + function toggleKeepAbove() { + if (lastActiveTaskItem) + lastActiveTaskItem.toggleKeepAbove(); + + } + // To get current activity name TaskManager.ActivityInfo { id: activityInfo @@ -45,48 +73,38 @@ Item { TaskManager.TasksModel { id: tasksModel + sortMode: TaskManager.TasksModel.SortVirtualDesktop groupMode: TaskManager.TasksModel.GroupDisabled screenGeometry: root.screenGeometry activity: activityInfo.currentActivity virtualDesktop: virtualDesktopInfo.currentDesktop - filterByScreen: plasmaTasksItem.filterByScreen filterByVirtualDesktop: true filterByActivity: true } - Repeater{ + Repeater { id: tasksRepeater - model:DelegateModel { + + model: DelegateModel { model: tasksModel - delegate: Item{ + + delegate: Item { id: task + readonly property string title: display readonly property bool isMinimized: IsMinimized === true ? true : false readonly property bool isMaximized: IsMaximized === true ? true : false readonly property bool isActive: IsActive === true ? true : false readonly property bool isOnAllDesktops: IsOnAllVirtualDesktops === true ? true : false readonly property bool isKeepAbove: IsKeepAbove === true ? true : false - readonly property bool isClosable: IsClosable === true ? true : false readonly property bool isMinimizable: IsMinimizable === true ? true : false readonly property bool isMaximizable: IsMaximizable === true ? true : false readonly property bool isVirtualDesktopsChangeable: IsVirtualDesktopsChangeable === true ? true : false - onIsActiveChanged: { - if (isActive) { - plasmaTasksItem.lastActiveTaskItem = task; - } - } - - Component.onDestruction: { - if (plasmaTasksItem.lastActiveTaskItem === task) { - plasmaTasksItem.lastActiveTaskItem = null; - } - } - - function modelIndex(){ + function modelIndex() { return tasksModel.makeModelIndex(index); } @@ -106,40 +124,24 @@ Item { tasksModel.requestVirtualDesktops(modelIndex(), 0); } - function toggleKeepAbove(){ + function toggleKeepAbove() { tasksModel.requestToggleKeepAbove(modelIndex()); } + + onIsActiveChanged: { + if (isActive) + plasmaTasksItem.lastActiveTaskItem = task; + + } + Component.onDestruction: { + if (plasmaTasksItem.lastActiveTaskItem === task) + plasmaTasksItem.lastActiveTaskItem = null; + + } } + } + } - function toggleMaximized() { - if (lastActiveTaskItem) { - lastActiveTaskItem.toggleMaximized(); - } - } - - function toggleMinimized() { - if (lastActiveTaskItem) { - lastActiveTaskItem.toggleMinimized(); - } - } - - function toggleClose() { - if (lastActiveTaskItem) { - lastActiveTaskItem.toggleClose(); - } - } - - function togglePinToAllDesktops() { - if (lastActiveTaskItem) { - lastActiveTaskItem.togglePinToAllDesktops(); - } - } - - function toggleKeepAbove(){ - if (lastActiveTaskItem) { - lastActiveTaskItem.toggleKeepAbove(); - } - } } diff --git a/package/contents/ui/config/ColorsComboBox.qml b/package/contents/ui/config/ColorsComboBox.qml index 44cb40a..97c8c4f 100644 --- a/package/contents/ui/config/ColorsComboBox.qml +++ b/package/contents/ui/config/ColorsComboBox.qml @@ -25,58 +25,58 @@ ComboBox { id: combobox Connections { - target: popup function onClosed() { root.forceActiveFocus(); } + + target: popup } - delegate: MouseArea{ + delegate: MouseArea { width: combobox.width height: combobox.height hoverEnabled: true - onClicked: { combobox.currentIndex = index; selectedScheme = model.file; combobox.popup.close(); } - Rectangle{ - id:delegateBackground + Rectangle { + id: delegateBackground + + readonly property color selectedColor: Qt.rgba(palette.highlight.r, palette.highlight.g, palette.highlight.b, 0.5) + anchors.fill: parent color: { - if (containsMouse) { + if (containsMouse) return palette.highlight; - } - if (combobox.currentIndex === index) { + + if (combobox.currentIndex === index) return selectedColor; - } return "transparent"; } - readonly property color selectedColor: Qt.rgba(palette.highlight.r, palette.highlight.g, palette.highlight.b, 0.5); - - RowLayout{ + RowLayout { id: delegateRow + height: parent.height - Item{ + Item { Layout.leftMargin: 2 width: 1.25 * label.height height: label.height - opacity: ((file == "kdeglobals") || (file == "_plasmatheme_")) ? 0 : 1 - Rectangle{ + Rectangle { width: height height: 0.75 * label.height color: backgroundColor border.width: 1 border.color: containsMouse || (combobox.currentIndex === index) ? palette.highlightedText : palette.text - Rectangle{ + Rectangle { anchors.horizontalCenter: parent.right anchors.verticalCenter: parent.bottom width: parent.width @@ -85,15 +85,22 @@ ComboBox { border.width: parent.border.width border.color: parent.border.color } + } + } - Label{ + Label { id: label + text: display color: containsMouse ? palette.highlightedText : palette.text } + } + } + } + } diff --git a/package/contents/ui/config/ConfigGeneral.qml b/package/contents/ui/config/ConfigGeneral.qml index b62ad45..873a88f 100644 --- a/package/contents/ui/config/ConfigGeneral.qml +++ b/package/contents/ui/config/ConfigGeneral.qml @@ -20,16 +20,15 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts - -import org.kde.plasma.core as PlasmaCore -import org.kde.plasma.components as PlasmaComponents - -import org.kde.kitemmodels -import org.kde.kirigami as Kirigami - import org.kde.appletdecoration as AppletDecoration +import org.kde.kirigami as Kirigami +import org.kde.kitemmodels +import org.kde.plasma.components as PlasmaComponents +import org.kde.plasma.core as PlasmaCore Item { + ///END Decoration Items + id: root property alias cfg_useCurrentDecoration: root.useCurrent @@ -48,7 +47,6 @@ Item { property alias cfg_lengthFirstMargin: lengthFirstSpn.value property alias cfg_lengthLastMargin: lengthLastSpn.value property alias cfg_lengthMarginsLock: lockItem.locked - property var cfg_buttonSizePercentageDefault property var cfg_buttonsDefault property var cfg_containmentType @@ -70,7 +68,6 @@ Item { property var cfg_useDecorationMetricsDefault property var cfg_visibilityDefault property var title - // used as bridge to communicate properly between configuration and ui property bool useCurrent property int hiddenState @@ -79,41 +76,41 @@ Item { property string selectedScheme property string selectedTheme property string currentButtons - // used from the ui readonly property bool selectedDecorationExists: decorations.decorationExists(root.selectedPlugin, root.selectedTheme) - readonly property real centerFactor: 0.3 readonly property int minimumWidth: 220 property string currentPlugin: root.useCurrent || !selectedDecorationExists ? decorations.currentPlugin : root.selectedPlugin property string currentTheme: root.useCurrent || !selectedDecorationExists ? decorations.currentTheme : root.selectedTheme - - ///START Decoration Items AppletDecoration.Bridge { id: bridgeItem + plugin: currentPlugin theme: currentTheme } AppletDecoration.Settings { id: settingsItem + bridge: bridgeItem.bridge borderSizesIndex: 0 } AppletDecoration.SharedDecoration { id: sharedDecorationItem + bridge: bridgeItem.bridge settings: settingsItem } AppletDecoration.AuroraeTheme { id: auroraeThemeEngine - theme: isEnabled ? currentTheme : "" readonly property bool isEnabled: decorations.isAurorae(root.currentPlugin, root.currentTheme) + + theme: isEnabled ? currentTheme : "" } AppletDecoration.DecorationsModel { @@ -137,34 +134,36 @@ Item { // sort decorations based on display name KSortFilterProxyModel { id: sortedDecorations + sourceModel: decorations sortRoleName: 'display' sortOrder: Qt.AscendingOrder } - ///END Decoration Items - ColumnLayout { - id:mainColumn + id: mainColumn + spacing: Kirigami.Units.largeSpacing Layout.fillWidth: true - RowLayout{ + RowLayout { Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) text: i18n("Decoration:") horizontalAlignment: Text.AlignRight } - DecorationsComboBox{ + DecorationsComboBox { id: decorationCmb + Layout.minimumWidth: 180 Layout.preferredWidth: 0.2 * root.width Layout.maximumWidth: 300 } + } - RowLayout{ + RowLayout { visible: !auroraeThemeEngine.isEnabled Label { @@ -173,55 +172,54 @@ Item { horizontalAlignment: Text.AlignRight } - ColorsComboBox{ - id:colorsCmbBox + ColorsComboBox { + id: colorsCmbBox + Layout.minimumWidth: 250 Layout.preferredWidth: 0.3 * root.width Layout.maximumWidth: 380 - model: colorsModel textRole: "display" - Component.onCompleted: { currentIndex = colorsModel.indexOf(plasmoid.configuration.selectedScheme); } } + } - GridLayout{ + GridLayout { columns: 2 - Label{ + Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) text: i18n("Buttons:") horizontalAlignment: Text.AlignRight } - OrderableListView{ + OrderableListView { id: activeButtons + + readonly property color schemesBackgroundColor: plasmaThemeExtended.isActive ? plasmaThemeExtended.colors.backgroundColor : colorsModel.backgroundOf(colorsCmbBox.currentIndex) + itemWidth: 38 itemHeight: 38 buttonsStr: root.currentButtons orientation: ListView.Horizontal color: !auroraeThemeEngine.isEnabled ? schemesBackgroundColor : auroraeThemeEngine.titleBackgroundColor - buttonSize: buttonSizeSpn.value buttonsFirstMargin: lengthFirstSpn.value buttonsLastMargin: lengthLastSpn.value buttonsSpacing: spacingSpn.value - - readonly property color schemesBackgroundColor: plasmaThemeExtended.isActive ? - plasmaThemeExtended.colors.backgroundColor : - colorsModel.backgroundOf(colorsCmbBox.currentIndex) } + } - GridLayout{ + GridLayout { columns: 2 rows: 4 flow: GridLayout.TopToBottom - Label{ + Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) Layout.rowSpan: 4 Layout.alignment: Qt.AlignTop | Qt.AlignRight @@ -236,58 +234,65 @@ Item { Column { id: column - RadioButton{ + RadioButton { id: alwaysVisibleBtn + text: i18n("Always visible") checked: root.visibility === AppletDecoration.Types.AlwaysVisible onCheckedChanged: { - if (checked) { + if (checked) root.visibility = AppletDecoration.Types.AlwaysVisible; - } + } } - RadioButton{ + + RadioButton { id: activeWindowBtn + text: i18n("Active window is present") checked: root.visibility === AppletDecoration.Types.ActiveWindow onCheckedChanged: { - if (checked) { + if (checked) root.visibility = AppletDecoration.Types.ActiveWindow; - } + } } - RadioButton{ + + RadioButton { id: activeMaximizedBtn - text: plasmoid.configuration.containmentType === AppletDecoration.Types.Latte ? - i18n("Last active window is maximized") : i18n("Active window is maximized") + + text: plasmoid.configuration.containmentType === AppletDecoration.Types.Latte ? i18n("Last active window is maximized") : i18n("Active window is maximized") checked: root.visibility === AppletDecoration.Types.ActiveMaximizedWindow onCheckedChanged: { - if (checked) { + if (checked) root.visibility = AppletDecoration.Types.ActiveMaximizedWindow; - } + } } - RadioButton{ + + RadioButton { id: shownWindowBtn + text: i18n("At least one window is shown") checked: root.visibility === AppletDecoration.Types.ShownWindowExists onCheckedChanged: { - if (checked) { + if (checked) root.visibility = AppletDecoration.Types.ShownWindowExists; - } + } } + } + } - GridLayout{ + GridLayout { columns: 2 rows: 2 flow: GridLayout.TopToBottom - enabled: root.visibility !== AppletDecoration.Types.AlwaysVisible - Label{ + Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) Layout.rowSpan: 2 Layout.alignment: Qt.AlignTop | Qt.AlignRight @@ -302,40 +307,47 @@ Item { Column { id: column2 - RadioButton{ + RadioButton { id: slideOutBtn + text: i18n("Slide out animation") checked: root.hiddenState === AppletDecoration.Types.SlideOut onCheckedChanged: { - if (checked) { + if (checked) root.hiddenState = AppletDecoration.Types.SlideOut; - } + } } - RadioButton{ + + RadioButton { id: emptySpaceBtn + text: i18n("Preserve as empty space") checked: root.hiddenState === AppletDecoration.Types.EmptySpace onCheckedChanged: { - if (checked) { + if (checked) root.hiddenState = AppletDecoration.Types.EmptySpace; - } + } } + } + } - GridLayout{ - Label{ + GridLayout { + Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) text: i18n("Filters:") horizontalAlignment: Text.AlignRight } - CheckBox{ + CheckBox { id: byScreenChk + text: i18n("Show only for windows in current screen") } + } GridLayout { @@ -347,46 +359,51 @@ Item { CheckBox { id: stickyChk + text: i18n("Enabled") } + } - GridLayout{ + GridLayout { columns: 2 rows: 2 flow: GridLayout.TopToBottom - Label{ + Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) Layout.alignment: Qt.AlignTop | Qt.AlignRight Layout.rowSpan: 2 - text: i18n("Appearance:") horizontalAlignment: Text.AlignRight } - CheckBox{ + CheckBox { id: inactiveChk + text: i18n("Draw buttons inactive state when needed") } + } - ColumnLayout{ + ColumnLayout { id: visualSettings - GridLayout{ + GridLayout { id: visualSettingsGroup1 + columns: 2 - Label{ + Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) text: i18n("Metrics:") horizontalAlignment: Text.AlignRight visible: auroraeThemeEngine.isEnabled } - CheckBox{ + CheckBox { id: decorationMetricsChk + text: i18n("Use from decoration if any are found") visible: auroraeThemeEngine.isEnabled } @@ -400,6 +417,7 @@ Item { SpinBox { id: buttonSizeSpn + from: 40 to: 100 // suffix: " %" @@ -415,49 +433,50 @@ Item { SpinBox { id: spacingSpn + from: 0 to: 24 // suffix: " " + i18nc("pixels","px.") enabled: !(auroraeThemeEngine.isEnabled && decorationMetricsChk.checked) } + } - GridLayout{ + GridLayout { id: visualSettingsGroup2 + property int lockerHeight: firstLengthLbl.height + rowSpacing / 2 + columns: 3 rows: 2 flow: GridLayout.TopToBottom columnSpacing: visualSettingsGroup1.columnSpacing rowSpacing: visualSettingsGroup1.rowSpacing - property int lockerHeight: firstLengthLbl.height + rowSpacing/2 - - Label{ + Label { id: firstLengthLbl + Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) - text: plasmoid.configuration.formFactor===PlasmaCore.Types.Horizontal ? - i18n("Left margin:") : i18n("Top margin:") + text: plasmoid.configuration.formFactor === PlasmaCore.Types.Horizontal ? i18n("Left margin:") : i18n("Top margin:") horizontalAlignment: Text.AlignRight } - Label{ + Label { Layout.minimumWidth: Math.max(centerFactor * root.width, minimumWidth) - text: plasmoid.configuration.formFactor===PlasmaCore.Types.Horizontal ? - i18n("Right margin:") : i18n("Bottom margin:") + text: plasmoid.configuration.formFactor === PlasmaCore.Types.Horizontal ? i18n("Right margin:") : i18n("Bottom margin:") horizontalAlignment: Text.AlignRight - enabled: !lockItem.locked } - SpinBox{ - id: lengthFirstSpn - from: 0 - to: 24 + SpinBox { // suffix: " " + i18nc("pixels","px.") + id: lengthFirstSpn + property int lastValue: -1 + from: 0 + to: 24 onValueChanged: { if (lockItem.locked) { var step = value - lastValue > 0 ? 1 : -1; @@ -465,22 +484,23 @@ Item { lengthLastSpn.value = lengthLastSpn.value + step; } } - Component.onCompleted: { lastValue = plasmoid.configuration.lengthFirstMargin; } } - SpinBox{ + SpinBox { id: lengthLastSpn + from: 0 to: 24 // suffix: " " + i18nc("pixels","px.") enabled: !lockItem.locked } - LockItem{ + LockItem { id: lockItem + Layout.minimumWidth: 40 Layout.maximumWidth: 40 Layout.alignment: Qt.AlignTop | Qt.AlignLeft @@ -489,7 +509,11 @@ Item { Layout.topMargin: firstLengthLbl.height / 2 Layout.rowSpan: 2 } + } + } + } + } diff --git a/package/contents/ui/config/DecorationsComboBox.qml b/package/contents/ui/config/DecorationsComboBox.qml index b91419d..8e2e24d 100644 --- a/package/contents/ui/config/DecorationsComboBox.qml +++ b/package/contents/ui/config/DecorationsComboBox.qml @@ -24,34 +24,36 @@ import org.kde.kirigami as Kirigami ComboBox { id: combobox + model: sortedDecorations textRole: "display" valueRole: "plugin" - - Connections{ - target: popup - function onClosed() { - root.forceActiveFocus(); - } - } - onActivated: { var index = combobox.currentIndex; - if (index === -1) { - return; - } + if (index === -1) + return ; - console.log(currentTheme, combobox.currentText, combobox.currentValue) + console.log(currentTheme, combobox.currentText, combobox.currentValue); root.useCurrent = false; root.selectedPlugin = combobox.currentValue; root.selectedTheme = combobox.currentText; } + Component.onCompleted: { + combobox.currentIndex = combobox.find(root.currentTheme); + } + + Connections { + function onClosed() { + root.forceActiveFocus(); + } + + target: popup + } delegate: MouseArea { height: combobox.height width: combobox.width hoverEnabled: true - onClicked: { combobox.currentIndex = index; root.useCurrent = false; @@ -62,32 +64,32 @@ ComboBox { Rectangle { id: delegateBackground + + readonly property color selectedColor: Qt.rgba(palette.highlight.r, palette.highlight.g, palette.highlight.b, 0.5) + anchors.fill: parent color: { - if (containsMouse) { + if (containsMouse) return palette.highlight; - } - if (combobox.currentIndex === index) { + + if (combobox.currentIndex === index) return selectedColor; - } return "transparent"; } - readonly property color selectedColor: Qt.rgba(palette.highlight.r, palette.highlight.g, palette.highlight.b, 0.5); - - Label{ + Label { id: label + anchors.left: parent.left anchors.leftMargin: Kirigami.Units.smallSpacing anchors.verticalCenter: parent.verticalCenter text: display + " (" + plugin + ")" color: containsMouse ? palette.highlightedText : palette.text } + } + } - Component.onCompleted: { - combobox.currentIndex = combobox.find(root.currentTheme); - } } diff --git a/package/contents/ui/config/LockItem.qml b/package/contents/ui/config/LockItem.qml index 8613b01..fbda2a1 100644 --- a/package/contents/ui/config/LockItem.qml +++ b/package/contents/ui/config/LockItem.qml @@ -20,32 +20,31 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts - import org.kde.kirigami as Kirigami -Item{ +Item { id: main property bool locked: true - - readonly property int verticalSubHeight: height - (button.height/2) + readonly property int verticalSubHeight: height - (button.height / 2) SystemPalette { id: palette } - ColumnLayout{ + ColumnLayout { id: column + spacing: 0 opacity: locked ? 1 : 0.5 - Rectangle{ + Rectangle { id: subRectTop - Layout.minimumWidth: button.width/2 + Layout.minimumHeight/2 + + Layout.minimumWidth: button.width / 2 + Layout.minimumHeight / 2 Layout.minimumHeight: 3 Layout.maximumWidth: Layout.minimumWidth Layout.maximumHeight: Layout.minimumHeight - color: palette.text } @@ -60,6 +59,7 @@ Item{ Kirigami.Icon { id: button + width: 24 height: 24 source: locked ? "lock" : "unlock" @@ -74,19 +74,19 @@ Item{ color: palette.text } - Rectangle{ + Rectangle { Layout.minimumWidth: subRectTop.Layout.minimumWidth Layout.minimumHeight: subRectTop.Layout.minimumHeight Layout.maximumWidth: Layout.minimumWidth Layout.maximumHeight: Layout.minimumHeight - color: palette.text } + } - MouseArea{ + MouseArea { anchors.fill: column - onClicked: locked = !locked; + onClicked: locked = !locked } } diff --git a/package/contents/ui/config/OrderableListView.qml b/package/contents/ui/config/OrderableListView.qml index e56bd35..d03f5c6 100644 --- a/package/contents/ui/config/OrderableListView.qml +++ b/package/contents/ui/config/OrderableListView.qml @@ -1,3 +1,4 @@ +import "../../code/tools.js" as ModelTools /* * Copyright 2018 Michail Vourlakos * @@ -17,120 +18,12 @@ * along with this program. If not, see . */ import QtQuick -import QtQuick.Layouts import QtQuick.Controls +import QtQuick.Layouts +import org.kde.appletdecoration 0.1 as AppletDecoration import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.appletdecoration 0.1 as AppletDecoration - -import "../../code/tools.js" as ModelTools - Rectangle { - id: listContent - radius: 4 - anchors.margins: margin - - signal coordinatesChanged(); - - property int orientation - property double itemWidth - property double itemHeight - - property int buttonSize: 100 - property int buttonsFirstMargin: 0 - property int buttonsLastMargin: 0 - property int buttonsSpacing: 0 - - Layout.minimumWidth: width - Layout.preferredWidth: Layout.minimumWidth - Layout.maximumWidth: Layout.maximumWidth - - Layout.minimumHeight: height - Layout.preferredHeight: Layout.minimumHeight - Layout.maximumHeight: Layout.maximumHeight - - property string buttonsStr - - - width: listView.childrenRect.width + 2 * margin//(itemWidth+listView.spacing) * (orientation == ListView.Vertical ? 1 : controlButtonsModel.count) + 2 * margin - height: listView.childrenRect.height + 2 * margin //(itemHeight+listView.spacing) * (orientation == ListView.Horizontal ? 1 : controlButtonsModel.count) - - signal modelOrderChanged() - - property var tasksPreparedArray: [] - - readonly property int margin: 0 - readonly property double iconHeight: itemHeight*(buttonSize/100) - margin * 2 - - readonly property string appliedScheme: { - if (selectedScheme === "_plasmatheme_") { - return plasmaThemeExtended.colors.schemeFile; - } else if (selectedScheme === "kdeglobals") { - return colorsModel.defaultSchemeFile(); - } - - return selectedScheme; - } - - Component.onCompleted: { - initButtons(); - coordinatesChanged(); - } - - function initButtons() { - if (!buttonsRecreator.running){ - buttonsRecreator.start(); - } - } - - function initializeControlButtonsModel() { - sharedDecorationItem.createDecoration(); - - var buttonsList = buttonsStr.split('|'); - - ModelTools.initializeControlButtonsModel(buttonsList,tasksPreparedArray, controlButtonsModel, false); - listView.splitterIndex = ModelTools.indexOfSplitter(controlButtonsModel); - - coordinatesTimer.start(); - } - - function buttonsListStr() { - var str = ""; - - for (var i=0; i= 0 && index < listView.splitterIndex readonly property bool isFirstVisibleButton: index === 0 && listView.splitterIndex > 0 - readonly property bool isLastVisibleButton: index>=0 && index===listView.splitterIndex-1 - readonly property bool isButtonSplitter: index>=0 && index===listView.splitterIndex - - y: (itemHeight - iconHeight) / 2 - width: isButtonSplitter && !loc.buttonIsDragged ? Math.min(listContent.iconHeight/2, 6 + buttonsLastMargin) : - listContent.iconHeight + leftMargin + rightMargin - height: listContent.iconHeight + 2 * listContent.margin - color: { - if (listView.currentIndex === index) { - if (index !== listView.splitterIndex) { - return palette.highlight; - } else { - return "#25ff0000"; - } - } - return "transparent"; - } - + readonly property bool isLastVisibleButton: index >= 0 && index === listView.splitterIndex - 1 + readonly property bool isButtonSplitter: index >= 0 && index === listView.splitterIndex property int leftMargin: 0 property int rightMargin: 0 - Behavior on leftMargin { - NumberAnimation { - duration: 50 - easing.type: Easing.Linear - } - } - - Behavior on rightMargin { - NumberAnimation { - duration: 50 - easing.type: Easing.Linear + y: (itemHeight - iconHeight) / 2 + width: isButtonSplitter && !loc.buttonIsDragged ? Math.min(listContent.iconHeight / 2, 6 + buttonsLastMargin) : listContent.iconHeight + leftMargin + rightMargin + height: listContent.iconHeight + 2 * listContent.margin + color: { + if (listView.currentIndex === index) { + if (index !== listView.splitterIndex) + return palette.highlight; + else + return "#25ff0000"; } + return "transparent"; } Binding { target: decorationButton property: "leftMargin" value: { - if (loc.buttonIsDragged) { + if (loc.buttonIsDragged) return buttonsSpacing / 2; - } - if (isFirstVisibleButton) { + if (isFirstVisibleButton) return buttonsFirstMargin; - } else if (isVisibleButton) { + else if (isVisibleButton) return buttonsSpacing; - } - return listContent.margin; } } @@ -261,38 +233,18 @@ Rectangle { target: decorationButton property: "rightMargin" value: { - if (loc.buttonIsDragged) { + if (loc.buttonIsDragged) return buttonsSpacing / 2; - } - if (isLastVisibleButton) { + if (isLastVisibleButton) return buttonsLastMargin; - } return listContent.margin; } } - AppletDecoration.Button { id: cButton - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - anchors.leftMargin: parent.leftMargin - - opacity: listView.splitterIndex !==-1 && listView.splitterIndex= 0 && index < listView.splitterIndex - readonly property bool isFirstVisibleButton: index === 0 && listView.splitterIndex > 0 - readonly property bool isLastVisibleButton: index>=0 && index===listView.splitterIndex-1 - readonly property bool isButtonSplitter: index>=0 && index===listView.splitterIndex - - y: (itemHeight - iconHeight) / 2 - width: isButtonSplitter && !loc.buttonIsDragged ? Math.min(listContent.iconHeight/2, 6 + buttonsLastMargin) : - auroraeThemeEngine.buttonRatio * listContent.iconHeight + leftMargin + rightMargin - height: listContent.iconHeight + 2 * listContent.margin - color: { - if (listView.currentIndex === index) { - if (index !== listView.splitterIndex) { - return palette.highlight; - } else { - return "#25ff0000"; - } - } - return "transparent"; - } - - property int leftMargin: 0 - property int rightMargin: 0 Behavior on leftMargin { NumberAnimation { duration: 50 easing.type: Easing.Linear } + } Behavior on rightMargin { @@ -360,22 +300,50 @@ Rectangle { duration: 50 easing.type: Easing.Linear } + + } + + } + + } + + Component { + id: auroraeButtonComponent + + Rectangle { + id: auroraeButton + + readonly property bool isVisibleButton: index >= 0 && index < listView.splitterIndex + readonly property bool isFirstVisibleButton: index === 0 && listView.splitterIndex > 0 + readonly property bool isLastVisibleButton: index >= 0 && index === listView.splitterIndex - 1 + readonly property bool isButtonSplitter: index >= 0 && index === listView.splitterIndex + property int leftMargin: 0 + property int rightMargin: 0 + + y: (itemHeight - iconHeight) / 2 + width: isButtonSplitter && !loc.buttonIsDragged ? Math.min(listContent.iconHeight / 2, 6 + buttonsLastMargin) : auroraeThemeEngine.buttonRatio * listContent.iconHeight + leftMargin + rightMargin + height: listContent.iconHeight + 2 * listContent.margin + color: { + if (listView.currentIndex === index) { + if (index !== listView.splitterIndex) + return palette.highlight; + else + return "#25ff0000"; + } + return "transparent"; } Binding { target: auroraeButton property: "leftMargin" value: { - if (loc.buttonIsDragged) { + if (loc.buttonIsDragged) return buttonsSpacing / 2; - } - if (isFirstVisibleButton) { + if (isFirstVisibleButton) return buttonsFirstMargin; - } else if (isVisibleButton) { + else if (isVisibleButton) return buttonsSpacing; - } - return listContent.margin; } } @@ -384,13 +352,11 @@ Rectangle { target: auroraeButton property: "rightMargin" value: { - if (loc.buttonIsDragged) { + if (loc.buttonIsDragged) return buttonsSpacing / 2; - } - if (isLastVisibleButton) { + if (isLastVisibleButton) return buttonsLastMargin; - } return listContent.margin; } @@ -400,21 +366,17 @@ Rectangle { anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: parent.leftMargin - - opacity: listView.splitterIndex !==-1 && listView.splitterIndex. */ +import "../code/tools.js" as ModelTools import QtQuick import QtQuick.Layouts - -import org.kde.plasma.plasmoid -import org.kde.plasma.core as PlasmaCore - import org.kde.appletdecoration as AppletDecoration - -import "../code/tools.js" as ModelTools +import org.kde.plasma.core as PlasmaCore +import org.kde.plasma.plasmoid PlasmoidItem { + // END visual properties + // START window properties + // END Window properties + // END decoration properties + // current Latte v0.9 API + //END Latte based properties + //! + ///START Visual Items + //add new supported buttons if they dont exist in the configuration + id: root - clip: true - - Layout.fillHeight: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? true : false - Layout.fillWidth: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? false : true - - Layout.minimumWidth: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? animatedMinimumWidth : -1 - Layout.minimumHeight: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? -1 : animatedMinimumHeight - Layout.preferredHeight: Layout.minimumHeight - Layout.preferredWidth: Layout.minimumWidth - Layout.maximumHeight: Layout.minimumHeight - Layout.maximumWidth: Layout.minimumWidth - - preferredRepresentation: fullRepresentation - Plasmoid.onFormFactorChanged: plasmoid.configuration.formFactor = plasmoid.formFactor; property int animatedMinimumWidth: minimumWidth property int animatedMinimumHeight: minimumHeight - property int screen: plasmoid.containment.screen - readonly property bool inEditMode: latteInEditMode || plasmoid.userConfiguring - readonly property bool mustHide: { - if (visibility === AppletDecoration.Types.AlwaysVisible || inEditMode) { + if (visibility === AppletDecoration.Types.AlwaysVisible || inEditMode) return false; - } - if (visibility === AppletDecoration.Types.ActiveWindow && !existsWindowActive) { + if (visibility === AppletDecoration.Types.ActiveWindow && !existsWindowActive) return true; - } - if (visibility === AppletDecoration.Types.ActiveMaximizedWindow - && (!isLastActiveWindowMaximized || (inPlasmaPanel && !existsWindowActive))) { + if (visibility === AppletDecoration.Types.ActiveMaximizedWindow && (!isLastActiveWindowMaximized || (inPlasmaPanel && !existsWindowActive))) return true; - } - if (visibility === AppletDecoration.Types.ShownWindowExists && !existsWindowShown) { + + if (visibility === AppletDecoration.Types.ShownWindowExists && !existsWindowShown) return true; - } return false; } - readonly property bool selectedDecorationExists: decorations.decorationExists(plasmoid.configuration.selectedPlugin, plasmoid.configuration.selectedTheme) - - readonly property bool slideAnimationEnabled: ( (visibility !== AppletDecoration.Types.AlwaysVisible) - && (plasmoid.configuration.hiddenState === AppletDecoration.Types.SlideOut) ) + readonly property bool slideAnimationEnabled: ((visibility !== AppletDecoration.Types.AlwaysVisible) && (plasmoid.configuration.hiddenState === AppletDecoration.Types.SlideOut)) readonly property bool isEmptySpaceEnabled: plasmoid.configuration.hiddenState === AppletDecoration.Types.EmptySpace - readonly property int containmentType: plasmoid.configuration.containmentType readonly property int visibility: plasmoid.configuration.visibility readonly property bool perScreenActive: plasmoid.configuration.perScreenActive - readonly property int minimumWidth: { if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) { - if (mustHide && !isEmptySpaceEnabled && slideAnimationEnabled && !plasmoid.userConfiguring && !latteInEditMode){ + if (mustHide && !isEmptySpaceEnabled && slideAnimationEnabled && !plasmoid.userConfiguring && !latteInEditMode) return 0; - } - } + } return plasmoid.formFactor === PlasmaCore.Types.Horizontal ? buttonsArea.width : -1; } - readonly property int minimumHeight: { if (plasmoid.formFactor === PlasmaCore.Types.Vertical) { - if (mustHide && !isEmptySpaceEnabled && slideAnimationEnabled && !plasmoid.userConfiguring && !latteInEditMode){ + if (mustHide && !isEmptySpaceEnabled && slideAnimationEnabled && !plasmoid.userConfiguring && !latteInEditMode) return 0; - } + } - - return plasmoid.formFactor === PlasmaCore.Types.Horizontal ? -1 : buttonsArea.height + return plasmoid.formFactor === PlasmaCore.Types.Horizontal ? -1 : buttonsArea.height; } - readonly property string buttonsStr: plasmoid.configuration.buttons - - Plasmoid.status: { - if (mustHide && !isEmptySpaceEnabled) { - if ((plasmoid.formFactor === PlasmaCore.Types.Horizontal && animatedMinimumWidth === 0) - || (plasmoid.formFactor === PlasmaCore.Types.Vertical && animatedMinimumHeight === 0)) { - return PlasmaCore.Types.HiddenStatus; - } - } - - return PlasmaCore.Types.ActiveStatus; - } - // START visual properties property bool inactiveStateEnabled: inEditMode ? false : plasmoid.configuration.inactiveStateEnabled - property int thickPadding: { - if (auroraeThemeEngine.isEnabled && plasmoid.configuration.useDecorationMetrics) { - return plasmoid.formFactor === PlasmaCore.Types.Horizontal ? - ((root.height - auroraeThemeEngine.buttonHeight) / 2) - 1 : - ((root.width - auroraeThemeEngine.buttonHeight) / 2) - 1; - } + if (auroraeThemeEngine.isEnabled && plasmoid.configuration.useDecorationMetrics) + return plasmoid.formFactor === PlasmaCore.Types.Horizontal ? ((root.height - auroraeThemeEngine.buttonHeight) / 2) - 1 : ((root.width - auroraeThemeEngine.buttonHeight) / 2) - 1; //! Latte padding if (inLatte) { - if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) { - return (root.height - (latteBridge.iconSize * (plasmoid.configuration.buttonSizePercentage/100))) / 2; - } else { - return (root.width - (latteBridge.iconSize * (plasmoid.configuration.buttonSizePercentage/100))) / 2; - } + if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) + return (root.height - (latteBridge.iconSize * (plasmoid.configuration.buttonSizePercentage / 100))) / 2; + else + return (root.width - (latteBridge.iconSize * (plasmoid.configuration.buttonSizePercentage / 100))) / 2; } - //! Plasma panels code - if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) { - return (root.height - (root.height * (plasmoid.configuration.buttonSizePercentage/100))) / 2; - } else { - return (root.width - (root.width * (plasmoid.configuration.buttonSizePercentage/100))) / 2; - } + if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) + return (root.height - (root.height * (plasmoid.configuration.buttonSizePercentage / 100))) / 2; + else + return (root.width - (root.width * (plasmoid.configuration.buttonSizePercentage / 100))) / 2; } - property int lengthFirstMargin: plasmoid.configuration.lengthFirstMargin property int lengthLastMargin: plasmoid.configuration.lengthLastMargin - property int lengthFirstPadding: Math.min(lengthFirstMargin, lengthMidPadding) property int lengthMidPadding: spacing / 2 property int lengthLastPadding: Math.min(lengthLastMargin, lengthMidPadding) - property int spacing: { - if (auroraeThemeEngine.isEnabled && plasmoid.configuration.useDecorationMetrics) { + if (auroraeThemeEngine.isEnabled && plasmoid.configuration.useDecorationMetrics) return auroraeThemeEngine.buttonSpacing; - } return plasmoid.configuration.spacing; } - // END visual properties - - // START window properties - //! make sure that on startup it will always be shown - readonly property bool existsWindowActive: (windowInfoLoader.item && windowInfoLoader.item.existsWindowActive) - || containmentIdentifierTimer.running - readonly property bool existsWindowShown: (windowInfoLoader.item && windowInfoLoader.item.existsWindowShown) - || containmentIdentifierTimer.running - + readonly property bool existsWindowActive: (windowInfoLoader.item && windowInfoLoader.item.existsWindowActive) || containmentIdentifierTimer.running + readonly property bool existsWindowShown: (windowInfoLoader.item && windowInfoLoader.item.existsWindowShown) || containmentIdentifierTimer.running readonly property bool isLastActiveWindowPinned: lastActiveTaskItem && existsWindowShown && lastActiveTaskItem.isOnAllDesktops readonly property bool isLastActiveWindowMaximized: lastActiveTaskItem && existsWindowShown && lastActiveTaskItem.isMaximized readonly property bool isLastActiveWindowKeepAbove: lastActiveTaskItem && existsWindowShown && lastActiveTaskItem.isKeepAbove - readonly property bool isLastActiveWindowClosable: lastActiveTaskItem && existsWindowShown && lastActiveTaskItem.isClosable readonly property bool isLastActiveWindowMaximizable: lastActiveTaskItem && existsWindowShown && lastActiveTaskItem.isMaximizable readonly property bool isLastActiveWindowMinimizable: lastActiveTaskItem && existsWindowShown && lastActiveTaskItem.isMinimizable readonly property bool isLastActiveWindowVirtualDesktopsChangeable: lastActiveTaskItem && existsWindowShown && lastActiveTaskItem.isVirtualDesktopsChangeable - property bool hasDesktopsButton: false property bool hasMaximizedButton: false property bool hasKeepAboveButton: false - readonly property bool inPlasmaPanel: latteBridge === null readonly property bool inLatte: latteBridge !== null - readonly property Item lastActiveTaskItem: windowInfoLoader.item.lastActiveTaskItem - // END Window properties - // START decoration properties - property string currentPlugin: plasmoid.configuration.useCurrentDecoration || !selectedDecorationExists ? - decorations.currentPlugin : plasmoid.configuration.selectedPlugin - property string currentTheme: plasmoid.configuration.useCurrentDecoration || !selectedDecorationExists ? - decorations.currentTheme : plasmoid.configuration.selectedTheme + property string currentPlugin: plasmoid.configuration.useCurrentDecoration || !selectedDecorationExists ? decorations.currentPlugin : plasmoid.configuration.selectedPlugin + property string currentTheme: plasmoid.configuration.useCurrentDecoration || !selectedDecorationExists ? decorations.currentTheme : plasmoid.configuration.selectedTheme property string currentScheme: { - if (plasmaThemeExtended.isActive) { + if (plasmaThemeExtended.isActive) return plasmaThemeExtended.colors.schemeFile; - } - if (enforceLattePalette && plasmoid.configuration.selectedScheme === "kdeglobals") { + if (enforceLattePalette && plasmoid.configuration.selectedScheme === "kdeglobals") return latteBridge.palette.scheme; - } - return plasmoid.configuration.selectedScheme === "kdeglobals" ? - colorsModel.defaultSchemeFile() : - plasmoid.configuration.selectedScheme + return plasmoid.configuration.selectedScheme === "kdeglobals" ? colorsModel.defaultSchemeFile() : plasmoid.configuration.selectedScheme; } - // END decoration properties - //BEGIN Latte Dock Communicator - property QtObject latteBridge: null // current Latte v0.9 API - - onLatteBridgeChanged: { - if (latteBridge) { - plasmoid.configuration.containmentType = AppletDecoration.Types.Latte; - latteBridge.actions.setProperty(plasmoid.id, "latteSideColoringEnabled", false); - latteBridge.actions.setProperty(plasmoid.id, "windowsTrackingEnabled", true); - } - } + property QtObject latteBridge: null //END Latte Dock Communicator //BEGIN Latte based properties //! This applet is a special case and thus the latteBridge.applyPalette is not used. @@ -221,50 +146,96 @@ PlasmoidItem { //! even when Latte informs the applets that need to use the default plasma theme. readonly property bool enforceLattePalette: latteBridge && latteBridge.palette readonly property bool latteInEditMode: latteBridge && latteBridge.inEditMode + property var tasksPreparedArray: [] - //END Latte based properties + ///functions + function initButtons() { + if (!buttonsRecreator.running) + buttonsRecreator.start(); - //START Behaviors - Behavior on animatedMinimumWidth { - enabled: slideAnimationEnabled && plasmoid.formFactor===PlasmaCore.Types.Horizontal - NumberAnimation { - duration: 250 - easing.type: Easing.InCubic + } + + function initializeControlButtonsModel() { + console.log("recreating buttons"); + sharedDecorationItem.createDecoration(); + var buttonsList = buttonsStr.split('|'); + ModelTools.initializeControlButtonsModel(buttonsList, tasksPreparedArray, controlButtonsModel, true); + } + + function discoverButtons() { + var hasMax = false; + var hasPin = false; + var hasKeepAbove = false; + for (var i = 0; i < tasksPreparedArray.length; ++i) { + if (tasksPreparedArray[i].buttonType === AppletDecoration.Types.Maximize) + hasMax = true; + else if (tasksPreparedArray[i].buttonType === AppletDecoration.Types.OnAllDesktops) + hasPin = true; + else if (tasksPreparedArray[i].buttonType === AppletDecoration.Types.KeepAbove) + hasKeepAbove = true; + } + hasMaximizedButton = hasMax; + hasDesktopsButton = hasPin; + hasKeepAboveButton = hasKeepAbove; + } + + function performActiveWindowAction(windowOperation) { + if (windowOperation === AppletDecoration.Types.ActionClose) + windowInfoLoader.item.toggleClose(); + else if (windowOperation === AppletDecoration.Types.ToggleMaximize) + windowInfoLoader.item.toggleMaximized(); + else if (windowOperation === AppletDecoration.Types.ToggleMinimize) + windowInfoLoader.item.toggleMinimized(); + else if (windowOperation === AppletDecoration.Types.TogglePinToAllDesktops) + windowInfoLoader.item.togglePinToAllDesktops(); + else if (windowOperation === AppletDecoration.Types.ToggleKeepAbove) + windowInfoLoader.item.toggleKeepAbove(); + } + + clip: true + Layout.fillHeight: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? true : false + Layout.fillWidth: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? false : true + Layout.minimumWidth: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? animatedMinimumWidth : -1 + Layout.minimumHeight: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? -1 : animatedMinimumHeight + Layout.preferredHeight: Layout.minimumHeight + Layout.preferredWidth: Layout.minimumWidth + Layout.maximumHeight: Layout.minimumHeight + Layout.maximumWidth: Layout.minimumWidth + preferredRepresentation: fullRepresentation + Plasmoid.onFormFactorChanged: plasmoid.configuration.formFactor = plasmoid.formFactor + Plasmoid.status: { + if (mustHide && !isEmptySpaceEnabled) { + if ((plasmoid.formFactor === PlasmaCore.Types.Horizontal && animatedMinimumWidth === 0) || (plasmoid.formFactor === PlasmaCore.Types.Vertical && animatedMinimumHeight === 0)) + return PlasmaCore.Types.HiddenStatus; + + } + return PlasmaCore.Types.ActiveStatus; + } + onLatteBridgeChanged: { + if (latteBridge) { + plasmoid.configuration.containmentType = AppletDecoration.Types.Latte; + latteBridge.actions.setProperty(plasmoid.id, "latteSideColoringEnabled", false); + latteBridge.actions.setProperty(plasmoid.id, "windowsTrackingEnabled", true); } } - - Behavior on animatedMinimumHeight { - enabled: slideAnimationEnabled && plasmoid.formFactor===PlasmaCore.Types.Vertical - NumberAnimation { - duration: 250 - easing.type: Easing.InCubic - } - } - //END Behaviors - - onButtonsStrChanged: initButtons(); - - Connections { - target: bridgeItem - onPluginChanged: initButtons(); - } - - Connections { - target: buttonsRepeater - onCountChanged: discoverButtons(); - } - + onButtonsStrChanged: initButtons() Component.onCompleted: { - if (plasmoid.configuration.buttons.indexOf("9") === -1) { - //add new supported buttons if they dont exist in the configuration + if (plasmoid.configuration.buttons.indexOf("9") === -1) plasmoid.configuration.buttons = plasmoid.configuration.buttons.concat("|9"); - } initButtons(); containmentIdentifierTimer.start(); } - property var tasksPreparedArray: [] + Connections { + target: bridgeItem + onPluginChanged: initButtons() + } + + Connections { + target: buttonsRepeater + onCountChanged: discoverButtons() + } ListModel { id: controlButtonsModel @@ -273,43 +244,47 @@ PlasmoidItem { //! Loader { id: windowInfoLoader - sourceComponent: latteBridge - && latteBridge.windowsTracker - && latteBridge.windowsTracker.currentScreen.lastActiveWindow - && latteBridge.windowsTracker.allScreens.lastActiveWindow ? latteTrackerComponent : plasmaTasksModel - Component{ + sourceComponent: latteBridge && latteBridge.windowsTracker && latteBridge.windowsTracker.currentScreen.lastActiveWindow && latteBridge.windowsTracker.allScreens.lastActiveWindow ? latteTrackerComponent : plasmaTasksModel + + Component { id: latteTrackerComponent - LatteWindowsTracker{ + + LatteWindowsTracker { filterByScreen: plasmoid.configuration.filterByScreen } + } - Component{ + Component { id: plasmaTasksModel - PlasmaTasksModel{ + + PlasmaTasksModel { filterByScreen: plasmoid.configuration.filterByScreen } - } - } - //! + } + + } ///Decoration Items AppletDecoration.Bridge { id: bridgeItem + plugin: currentPlugin theme: currentTheme } AppletDecoration.Settings { id: settingsItem + bridge: bridgeItem.bridge borderSizesIndex: 0 // Normal } AppletDecoration.SharedDecoration { id: sharedDecorationItem + bridge: bridgeItem.bridge settings: settingsItem } @@ -330,87 +305,19 @@ PlasmoidItem { AppletDecoration.AuroraeTheme { id: auroraeThemeEngine - theme: isEnabled ? currentTheme : "" - readonly property bool isEnabled: decorations.isAurorae(currentPlugin, currentTheme); + readonly property bool isEnabled: decorations.isAurorae(currentPlugin, currentTheme) + + theme: isEnabled ? currentTheme : "" } AppletDecoration.WindowSystem { id: windowSystem } - ///functions - function initButtons() { - if (!buttonsRecreator.running){ - buttonsRecreator.start(); - } - } - - function initializeControlButtonsModel() { - console.log("recreating buttons"); - sharedDecorationItem.createDecoration(); - - var buttonsList = buttonsStr.split('|'); - - ModelTools.initializeControlButtonsModel(buttonsList, tasksPreparedArray, controlButtonsModel, true); - } - - function discoverButtons() { - var hasMax = false; - var hasPin = false; - var hasKeepAbove = false; - - for (var i=0; i=0 && index === buttonsRepeater.count - 1) { - //! last button - return lengthLastMargin; - } else { - return lengthMidPadding; - } - } - - padding{ - left: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? firstPadding : thickPadding - right: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? lastPadding : thickPadding - top: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : firstPadding - bottom: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : lastPadding - } - - onClicked: { - root.performActiveWindowAction(windowOperation); - } - /*Rectangle{ anchors.fill: parent color: "transparent" @@ -527,87 +366,78 @@ PlasmoidItem { border.width: 1 border.color: "blue" }*/ - } - } + //! first button + //! last button - Component { - id: auroraeButton - AppletDecoration.AuroraeButton { - id: aButton - width: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? - auroraeTheme.buttonRatio*buttonsArea.buttonThickness + leftPadding + rightPadding : - buttonsArea.buttonThickness + 2 * thickPadding + id: cButton - height: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? - buttonsArea.buttonThickness + 2 * thickPadding : - buttonsArea.buttonThickness + topPadding + bottomPadding + readonly property bool isVisible: { + if (visibility === AppletDecoration.Types.AlwaysVisible || inEditMode) + return true; + if (type === AppletDecoration.Types.Close) + return root.isLastActiveWindowClosable; + else if (type === AppletDecoration.Types.Maximize) + return root.isLastActiveWindowMaximizable; + else if (type === AppletDecoration.Types.Minimize) + return root.isLastActiveWindowMinimizable; + else if (type === AppletDecoration.Types.OnAllDesktops) + return root.isLastActiveWindowVirtualDesktopsChangeable; + return true; + } readonly property int firstPadding: { - if (index === 0) { - //! first button + if (index === 0) return lengthFirstMargin; - } else { + else return lengthMidPadding; - } } - readonly property int lastPadding: { - if (index>=0 && index === buttonsRepeater.count - 1) { - //! last button + if (index >= 0 && index === buttonsRepeater.count - 1) return lengthLastMargin; - } else { + else return lengthMidPadding; - } } - leftPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? firstPadding : thickPadding - rightPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? lastPadding : thickPadding - topPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : firstPadding - bottomPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : lastPadding - + width: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? buttonsArea.buttonThickness + padding.left + padding.right : buttonsArea.buttonThickness + 2 * thickPadding + height: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? buttonsArea.buttonThickness + 2 * thickPadding : buttonsArea.buttonThickness + padding.top + padding.bottom + bridge: bridgeItem.bridge + sharedDecoration: sharedDecorationItem + scheme: root.currentScheme + type: buttonType isActive: { //! FIXME-TEST PERIOD: Disabled because it shows an error from c++ theme when its value is changed //! and breaks in some cases the buttons coloring through the schemeFile - if (root.inactiveStateEnabled && !root.existsWindowActive){ + if (root.inactiveStateEnabled && !root.existsWindowActive) return false; - } return true; } isOnAllDesktops: root.isLastActiveWindowPinned isMaximized: root.isLastActiveWindowMaximized isKeepAbove: root.isLastActiveWindowKeepAbove - buttonType: model.buttonType - auroraeTheme: auroraeThemeEngine - - monochromeIconsEnabled: latteBridge && latteBridge.applyPalette && auroraeThemeEngine.hasMonochromeIcons - monochromeIconsColor: latteBridge ? latteBridge.palette.textColor : "transparent" - + localX: x + localY: y opacity: isVisible ? 1 : 0 visible: (isVisible && !root.isEmptySpaceEnabled) || root.isEmptySpaceEnabled - - readonly property bool isVisible: { - if (visibility === AppletDecoration.Types.AlwaysVisible || inEditMode) { - return true; - } - - if (buttonType === AppletDecoration.Types.Close) { - return root.isLastActiveWindowClosable; - } else if (buttonType === AppletDecoration.Types.Maximize) { - return root.isLastActiveWindowMaximizable; - } else if (buttonType === AppletDecoration.Types.Minimize) { - return root.isLastActiveWindowMinimizable; - } else if (buttonType === AppletDecoration.Types.OnAllDesktops) { - return root.isLastActiveWindowVirtualDesktopsChangeable; - } - - return true; - } - onClicked: { root.performActiveWindowAction(windowOperation); } + padding { + left: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? firstPadding : thickPadding + right: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? lastPadding : thickPadding + top: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : firstPadding + bottom: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : lastPadding + } + + } + + } + + Component { + id: auroraeButton + + AppletDecoration.AuroraeButton { /* Rectangle{ anchors.fill: parent color: "transparent" @@ -625,31 +455,114 @@ PlasmoidItem { border.width: 1 border.color: "blue" } */ + //! first button + //! last button + + id: aButton + + readonly property int firstPadding: { + if (index === 0) + return lengthFirstMargin; + else + return lengthMidPadding; + } + readonly property int lastPadding: { + if (index >= 0 && index === buttonsRepeater.count - 1) + return lengthLastMargin; + else + return lengthMidPadding; + } + readonly property bool isVisible: { + if (visibility === AppletDecoration.Types.AlwaysVisible || inEditMode) + return true; + + if (buttonType === AppletDecoration.Types.Close) + return root.isLastActiveWindowClosable; + else if (buttonType === AppletDecoration.Types.Maximize) + return root.isLastActiveWindowMaximizable; + else if (buttonType === AppletDecoration.Types.Minimize) + return root.isLastActiveWindowMinimizable; + else if (buttonType === AppletDecoration.Types.OnAllDesktops) + return root.isLastActiveWindowVirtualDesktopsChangeable; + return true; + } + + width: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? auroraeTheme.buttonRatio * buttonsArea.buttonThickness + leftPadding + rightPadding : buttonsArea.buttonThickness + 2 * thickPadding + height: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? buttonsArea.buttonThickness + 2 * thickPadding : buttonsArea.buttonThickness + topPadding + bottomPadding + leftPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? firstPadding : thickPadding + rightPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? lastPadding : thickPadding + topPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : firstPadding + bottomPadding: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? thickPadding : lastPadding + isActive: { + //! FIXME-TEST PERIOD: Disabled because it shows an error from c++ theme when its value is changed + //! and breaks in some cases the buttons coloring through the schemeFile + if (root.inactiveStateEnabled && !root.existsWindowActive) + return false; + + return true; + } + isOnAllDesktops: root.isLastActiveWindowPinned + isMaximized: root.isLastActiveWindowMaximized + isKeepAbove: root.isLastActiveWindowKeepAbove + buttonType: model.buttonType + auroraeTheme: auroraeThemeEngine + monochromeIconsEnabled: latteBridge && latteBridge.applyPalette && auroraeThemeEngine.hasMonochromeIcons + monochromeIconsColor: latteBridge ? latteBridge.palette.textColor : "transparent" + opacity: isVisible ? 1 : 0 + visible: (isVisible && !root.isEmptySpaceEnabled) || root.isEmptySpaceEnabled + onClicked: { + root.performActiveWindowAction(windowOperation); + } } + } ///END Visual Items //! this timer is used in order to not call too many times the recreation //! of buttons with no reason. - Timer{ + Timer { id: buttonsRecreator + interval: 200 - onTriggered: initializeControlButtonsModel(); + onTriggered: initializeControlButtonsModel() } //! this timer is used in order to identify in which containment the applet is in //! it should be called only the first time an applet is created and loaded because //! afterwards the applet has no way to move between different processes such //! as Plasma and Latte - Timer{ + Timer { id: containmentIdentifierTimer + interval: 5000 onTriggered: { - if (latteBridge) { + if (latteBridge) plasmoid.configuration.containmentType = AppletDecoration.Types.Latte; - } else { + else plasmoid.configuration.containmentType = AppletDecoration.Types.Plasma; - } } } + + //START Behaviors + Behavior on animatedMinimumWidth { + enabled: slideAnimationEnabled && plasmoid.formFactor === PlasmaCore.Types.Horizontal + + NumberAnimation { + duration: 250 + easing.type: Easing.InCubic + } + + } + + Behavior on animatedMinimumHeight { + enabled: slideAnimationEnabled && plasmoid.formFactor === PlasmaCore.Types.Vertical + + NumberAnimation { + duration: 250 + easing.type: Easing.InCubic + } + + } + //END Behaviors + }