From 14e739b39578bd09d1791129b48d1e5914cf8771 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 14 Apr 2020 16:33:55 +0300 Subject: [PATCH] details:provided layout backgrounds --- app/CMakeLists.txt | 1 + app/layout/abstractlayout.cpp | 30 ++-- app/layout/abstractlayout.h | 1 + .../controllers/layoutscontroller.cpp | 19 ++- app/settings/controllers/layoutscontroller.h | 1 + app/settings/dialogs/detailsdialog.cpp | 22 ++- app/settings/dialogs/detailsdialog.h | 19 ++- app/settings/dialogs/detailsdialog.ui | 152 +++++++++--------- app/settings/handlers/CMakeLists.txt | 2 + app/settings/handlers/detailshandler.cpp | 73 +++++++++ app/settings/handlers/detailshandler.h | 76 +++++++++ app/settings/handlers/detailsinfohandler.cpp | 94 +++++++++++ app/settings/handlers/detailsinfohandler.h | 84 ++++++++++ app/settings/handlers/tablayoutshandler.cpp | 2 +- app/settings/models/layoutsmodel.cpp | 2 +- app/settings/widgets/CMakeLists.txt | 5 + app/settings/widgets/patternwidget.cpp | 124 ++++++++++++++ app/settings/widgets/patternwidget.h | 69 ++++++++ 18 files changed, 680 insertions(+), 96 deletions(-) create mode 100644 app/settings/handlers/detailshandler.cpp create mode 100644 app/settings/handlers/detailshandler.h create mode 100644 app/settings/handlers/detailsinfohandler.cpp create mode 100644 app/settings/handlers/detailsinfohandler.h create mode 100644 app/settings/widgets/CMakeLists.txt create mode 100644 app/settings/widgets/patternwidget.cpp create mode 100644 app/settings/widgets/patternwidget.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index b4cc1ce8d..15c2697be 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -22,6 +22,7 @@ add_subdirectory(settings/handlers) add_subdirectory(settings/models) add_subdirectory(settings/tools) add_subdirectory(settings/views) +add_subdirectory(settings/widgets) add_subdirectory(shortcuts) add_subdirectory(view) add_subdirectory(view/helpers) diff --git a/app/layout/abstractlayout.cpp b/app/layout/abstractlayout.cpp index 79eb198de..ad68ea02d 100644 --- a/app/layout/abstractlayout.cpp +++ b/app/layout/abstractlayout.cpp @@ -222,37 +222,41 @@ void AbstractLayout::clearLastUsedActivity() emit lastUsedActivityChanged(); } -QString AbstractLayout::predefinedTextColor() const +QString AbstractLayout::defaultTextColor(const QString &color) { //! the user is in default layout theme - - if (m_color == "blue") { + if (color == "blue") { return "#D7E3FF"; - } else if (m_color == "brown") { + } else if (color == "brown") { return "#F1DECB"; - } else if (m_color == "darkgrey") { + } else if (color == "darkgrey") { return "#ECECEC"; - } else if (m_color == "gold") { + } else if (color == "gold") { return "#7C3636"; - } else if (m_color == "green") { + } else if (color == "green") { return "#4D7549"; - } else if (m_color == "lightskyblue") { + } else if (color == "lightskyblue") { return "#0C2A43"; - } else if (m_color == "orange") { + } else if (color == "orange") { return "#6F3902"; - } else if (m_color == "pink") { + } else if (color == "pink") { return "#743C46"; - } else if (m_color == "purple") { + } else if (color == "purple") { return "#ECD9FF"; - } else if (m_color == "red") { + } else if (color == "red") { return "#F3E4E4"; - } else if (m_color == "wheat") { + } else if (color == "wheat") { return "#6A4E25"; } else { return "#FCFCFC"; } } +QString AbstractLayout::predefinedTextColor() const +{ + return AbstractLayout::defaultTextColor(m_color); +} + QString AbstractLayout::customTextColor() const { return m_customTextColor; diff --git a/app/layout/abstractlayout.h b/app/layout/abstractlayout.h index bac705231..ae2c1dc80 100644 --- a/app/layout/abstractlayout.h +++ b/app/layout/abstractlayout.h @@ -110,6 +110,7 @@ public: virtual Type type() const; // STATIC + static QString defaultTextColor(const QString &color); static QString layoutName(const QString &fileName); static QList combinedFreeEdges(const QList &edges1, const QList &edges2); diff --git a/app/settings/controllers/layoutscontroller.cpp b/app/settings/controllers/layoutscontroller.cpp index 548cfab61..22b0ec70d 100644 --- a/app/settings/controllers/layoutscontroller.cpp +++ b/app/settings/controllers/layoutscontroller.cpp @@ -172,6 +172,17 @@ bool Layouts::selectedLayoutIsCurrentActive() const return (selectedLayoutCurrent.isActive && (selectedLayoutOriginal.name == m_handler->corona()->layoutsManager()->currentLayoutName())); } +QString Layouts::colorPath(const QString color) const +{ + QString path = m_iconsPath + color + "print.jpg"; + + if (!QFileInfo(path).exists()) { + return m_iconsPath + "blueprint.jpg"; + } + + return path; +} + QString Layouts::iconsPath() const { return m_iconsPath; @@ -380,9 +391,9 @@ void Layouts::loadLayouts() CentralLayout *central = new CentralLayout(this, original.id); original.name = central->name(); - original.background = central->background(); original.color = central->color(); - original.textColor = central->textColor(); + original.background = central->customBackground(); + original.textColor = central->customTextColor(); original.isActive = (m_handler->corona()->layoutsManager()->synchronizer()->layout(original.name) != nullptr); original.isLocked = !central->isWritable(); original.isShownInMenu = central->showInMenu(); @@ -516,8 +527,8 @@ const Data::Layout Layouts::addLayoutForFile(QString file, QString layoutName, b copied.name = uniqueLayoutName(layoutName); copied.color = settings->color(); - copied.textColor = settings->textColor(); - copied.background = settings->background(); + copied.textColor = settings->customTextColor(); + copied.background = settings->customBackground(); copied.isLocked = !settings->isWritable(); copied.isShownInMenu = settings->showInMenu(); copied.hasDisabledBorders = settings->disableBordersForMaximizedWindows(); diff --git a/app/settings/controllers/layoutscontroller.h b/app/settings/controllers/layoutscontroller.h index 24045fea9..5d0c989e3 100644 --- a/app/settings/controllers/layoutscontroller.h +++ b/app/settings/controllers/layoutscontroller.h @@ -81,6 +81,7 @@ public: void toggleSharedForSelected(); QString iconsPath() const; + QString colorPath(const QString color) const; QString layoutNameForFreeActivities() const; void setOriginalLayoutForFreeActivities(const QString &id); diff --git a/app/settings/dialogs/detailsdialog.cpp b/app/settings/dialogs/detailsdialog.cpp index 829bb874f..b69a0a24d 100644 --- a/app/settings/dialogs/detailsdialog.cpp +++ b/app/settings/dialogs/detailsdialog.cpp @@ -22,24 +22,42 @@ // local #include "ui_detailsdialog.h" +#include "../controllers/layoutscontroller.h" +#include "../handlers/detailshandler.h" namespace Latte { namespace Settings { namespace Dialog { -DetailsDialog::DetailsDialog(SettingsDialog *parent) +DetailsDialog::DetailsDialog(SettingsDialog *parent, Controller::Layouts *controller) : QDialog(parent), m_parentDlg(parent), - m_ui(new Ui::DetailsDialog) + m_ui(new Ui::DetailsDialog), + m_layoutsController(controller) { + //! first we need to setup the ui m_ui->setupUi(this); + //! we must create handlers after creating/adjusting the ui + m_handler = new Handler::DetailsHandler(this); + + m_ui->messageWidget->setVisible(false); } DetailsDialog::~DetailsDialog() { } +Controller::Layouts *DetailsDialog::layoutsController() const +{ + return m_layoutsController; +} + +Ui::DetailsDialog *DetailsDialog::ui() const +{ + return m_ui; +} + } } } diff --git a/app/settings/dialogs/detailsdialog.h b/app/settings/dialogs/detailsdialog.h index 64e8399f6..fbeafc384 100644 --- a/app/settings/dialogs/detailsdialog.h +++ b/app/settings/dialogs/detailsdialog.h @@ -32,6 +32,17 @@ namespace Ui { class DetailsDialog; } +namespace Latte { +namespace Settings { +namespace Controller { +class Layouts; +} +namespace Handler { +class DetailsHandler; +} +} +} + namespace Latte { namespace Settings { namespace Dialog { @@ -41,12 +52,18 @@ class DetailsDialog : public QDialog Q_OBJECT public: - DetailsDialog(SettingsDialog *parent); + DetailsDialog(SettingsDialog *parent, Controller::Layouts *controller); ~DetailsDialog(); + Ui::DetailsDialog *ui() const; + Controller::Layouts *layoutsController() const; + private: SettingsDialog *m_parentDlg{nullptr}; Ui::DetailsDialog *m_ui; + Controller::Layouts *m_layoutsController{nullptr}; + + Handler::DetailsHandler *m_handler; }; } diff --git a/app/settings/dialogs/detailsdialog.ui b/app/settings/dialogs/detailsdialog.ui index 61eb974fb..b5aa840b9 100644 --- a/app/settings/dialogs/detailsdialog.ui +++ b/app/settings/dialogs/detailsdialog.ui @@ -59,19 +59,23 @@ + + + + + + + - + - 0 - 40 + 160 + 60 - - ------------------ - @@ -231,6 +235,31 @@ + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + @@ -260,67 +289,6 @@ - - - - - - - 0 - 0 - - - - - 0 - 40 - - - - ------------------ - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - @@ -340,13 +308,6 @@ - - - - - - - @@ -354,6 +315,33 @@ + + + + + + + 160 + 60 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -389,6 +377,9 @@ + + + @@ -401,6 +392,19 @@ + + + KMessageWidget + QFrame +
kmessagewidget.h
+
+ + Latte::Settings::Widget::PatternWidget + QWidget +
settings/widgets/patternwidget.h
+ 1 +
+
diff --git a/app/settings/handlers/CMakeLists.txt b/app/settings/handlers/CMakeLists.txt index 276f36ad9..ce1998942 100644 --- a/app/settings/handlers/CMakeLists.txt +++ b/app/settings/handlers/CMakeLists.txt @@ -1,5 +1,7 @@ set(lattedock-app_SRCS ${lattedock-app_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/detailshandler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/detailsinfohandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generichandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tabpreferenceshandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tablayoutshandler.cpp diff --git a/app/settings/handlers/detailshandler.cpp b/app/settings/handlers/detailshandler.cpp new file mode 100644 index 000000000..379dd7a44 --- /dev/null +++ b/app/settings/handlers/detailshandler.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * 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 "detailshandler.h" + +#include "../dialogs/detailsdialog.h" + +namespace Latte { +namespace Settings { +namespace Handler { + +DetailsHandler::DetailsHandler(Dialog::DetailsDialog *parentDialog) + : Generic(parentDialog), + m_parentDialog(parentDialog), + m_ui(m_parentDialog->ui()), + m_infoHandler(new DetailsInfoHandler(this, parentDialog)) +{ +} + +DetailsHandler::~DetailsHandler() +{ +} + +bool DetailsHandler::dataAreChanged() const +{ + return m_infoHandler->dataAreChanged(); +} + +bool DetailsHandler::inDefaultValues() const +{ + //nothing special + return true; +} + + +void DetailsHandler::reset() +{ +} + +void DetailsHandler::resetDefaults() +{ + //do nothing +} + +void DetailsHandler::save() +{ +} + +void DetailsHandler::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval, QList actions) +{ +} + +} +} +} diff --git a/app/settings/handlers/detailshandler.h b/app/settings/handlers/detailshandler.h new file mode 100644 index 000000000..b1a11fe0c --- /dev/null +++ b/app/settings/handlers/detailshandler.h @@ -0,0 +1,76 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * 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 DETAILSDIALOGHANDLER_H +#define DETAILSDIALOGHANDLER_H + +//! local +#include "generichandler.h" +#include "detailsinfohandler.h" + +namespace Ui { +class DetailsDialog; +} + +namespace Latte{ +namespace Settings{ +namespace Dialog{ +class DetailsDialog; +} +} +} + + +namespace Latte { +namespace Settings { +namespace Handler { + +//! Handlers are objects to handle the UI elements that semantically associate with specific +//! ui::tabs or different windows. They are responsible also to handle the user interaction +//! between controllers and views + +class DetailsHandler : public Generic +{ + Q_OBJECT +public: + DetailsHandler(Dialog::DetailsDialog *parentDialog); + ~DetailsHandler(); + + bool dataAreChanged() const override; + bool inDefaultValues() const override; + + void reset() override; + void resetDefaults() override; + void save() override; + + void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0, QList actions = QList()) override; + +private: + Dialog::DetailsDialog *m_parentDialog{nullptr}; + Ui::DetailsDialog *m_ui{nullptr}; + + DetailsInfoHandler *m_infoHandler{nullptr}; +}; + +} +} +} + +#endif diff --git a/app/settings/handlers/detailsinfohandler.cpp b/app/settings/handlers/detailsinfohandler.cpp new file mode 100644 index 000000000..70039b364 --- /dev/null +++ b/app/settings/handlers/detailsinfohandler.cpp @@ -0,0 +1,94 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * 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 "detailsinfohandler.h" + +// local +#include "ui_detailsdialog.h" +#include "../dialogs/detailsdialog.h" +#include "../widgets/patternwidget.h" +#include "../../layout/abstractlayout.h" + +namespace Latte { +namespace Settings { +namespace Handler { + +DetailsInfoHandler::DetailsInfoHandler(QObject *parent, Dialog::DetailsDialog *parentDialog) + : Generic(parent), + m_parentDialog(parentDialog), + m_ui(m_parentDialog->ui()) +{ + init(); +} + +DetailsInfoHandler::~DetailsInfoHandler() +{ +} + +void DetailsInfoHandler::init() +{ + Settings::Data::Layout selectedLayoutCurrent = m_parentDialog->layoutsController()->selectedLayoutCurrentData(); + initLayout(selectedLayoutCurrent); +} + +void DetailsInfoHandler::initLayout(const Data::Layout &data) +{ + o_data = data; + c_data = data; + + m_ui->colorPatternWidget->setBackground(m_parentDialog->layoutsController()->colorPath(o_data.color)); + m_ui->backPatternWidget->setBackground(o_data.background); + + m_ui->colorPatternWidget->setTextColor(Layout::AbstractLayout::defaultTextColor(o_data.color)); + m_ui->backPatternWidget->setTextColor(o_data.textColor); +} + +bool DetailsInfoHandler::dataAreChanged() const +{ + return true; +} + +bool DetailsInfoHandler::inDefaultValues() const +{ + //nothing special + return true; +} + + +void DetailsInfoHandler::reset() +{ +} + +void DetailsInfoHandler::resetDefaults() +{ + //do nothing +} + +void DetailsInfoHandler::save() +{ +} + +void DetailsInfoHandler::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval, QList actions) +{ +} + +} +} +} diff --git a/app/settings/handlers/detailsinfohandler.h b/app/settings/handlers/detailsinfohandler.h new file mode 100644 index 000000000..56359a1df --- /dev/null +++ b/app/settings/handlers/detailsinfohandler.h @@ -0,0 +1,84 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * 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 DETAILSINFOHANDLER_H +#define DETAILSINFOHANDLER_H + +//! local +#include "generichandler.h" +#include "../data/layoutdata.h" + + +namespace Ui { +class DetailsDialog; +} + +namespace Latte{ +namespace Settings{ +namespace Dialog{ +class DetailsDialog; +} +} +} + + +namespace Latte { +namespace Settings { +namespace Handler { + +//! Handlers are objects to handle the UI elements that semantically associate with specific +//! ui::tabs or different windows. They are responsible also to handle the user interaction +//! between controllers and views + +class DetailsInfoHandler : public Generic +{ + Q_OBJECT +public: + DetailsInfoHandler(QObject *parent, Dialog::DetailsDialog *parentDialog); + ~DetailsInfoHandler(); + + bool dataAreChanged() const override; + bool inDefaultValues() const override; + + void reset() override; + void resetDefaults() override; + void save() override; + + void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0, QList actions = QList()) override; + +private slots: + void init(); + +private: + void initLayout(const Data::Layout &data); + +private: + Dialog::DetailsDialog *m_parentDialog{nullptr}; + Ui::DetailsDialog *m_ui{nullptr}; + + Data::Layout o_data; + Data::Layout c_data; +}; + +} +} +} + +#endif diff --git a/app/settings/handlers/tablayoutshandler.cpp b/app/settings/handlers/tablayoutshandler.cpp index 5f5904ca9..dad61edb8 100644 --- a/app/settings/handlers/tablayoutshandler.cpp +++ b/app/settings/handlers/tablayoutshandler.cpp @@ -669,7 +669,7 @@ void TabLayouts::on_details_action() Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData(); - auto detailsDlg = new Settings::Dialog::DetailsDialog(m_parentDialog); + auto detailsDlg = new Settings::Dialog::DetailsDialog(m_parentDialog, m_layoutsController); detailsDlg->exec(); } diff --git a/app/settings/models/layoutsmodel.cpp b/app/settings/models/layoutsmodel.cpp index 04af61dc8..bb850f551 100644 --- a/app/settings/models/layoutsmodel.cpp +++ b/app/settings/models/layoutsmodel.cpp @@ -396,7 +396,7 @@ QList Layouts::icons(const int &row) const //! background image if (icons.count() == 0) { - QString colorPath = m_layoutsTable[row].background.startsWith("/") ? m_layoutsTable[row].background : m_iconsPath + m_layoutsTable[row].background + "print.jpg"; + QString colorPath = m_layoutsTable[row].background.startsWith("/") ? m_layoutsTable[row].background : m_iconsPath + m_layoutsTable[row].color + "print.jpg"; if (QFileInfo(colorPath).exists()) { Data::LayoutIcon icon; diff --git a/app/settings/widgets/CMakeLists.txt b/app/settings/widgets/CMakeLists.txt new file mode 100644 index 000000000..b73ee5b50 --- /dev/null +++ b/app/settings/widgets/CMakeLists.txt @@ -0,0 +1,5 @@ +set(lattedock-app_SRCS + ${lattedock-app_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/patternwidget.cpp + PARENT_SCOPE +) diff --git a/app/settings/widgets/patternwidget.cpp b/app/settings/widgets/patternwidget.cpp new file mode 100644 index 000000000..2878b54cd --- /dev/null +++ b/app/settings/widgets/patternwidget.cpp @@ -0,0 +1,124 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * 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 "patternwidget.h" + +//! Qt +#include +#include +#include +#include +#include +#include + +//! KDE +#include + +namespace Latte { +namespace Settings { +namespace Widget { + +PatternWidget::PatternWidget(QWidget *parent, Qt::WindowFlags f) + : QWidget(parent, f) +{ + setProperty("isBackground", true); + + initUi(); + + connect(this, &PatternWidget::backgroundChanged, this, &PatternWidget::updateUi); + connect(this, &PatternWidget::textColorChanged, this, &PatternWidget::updateUi); +} + +void PatternWidget::initUi() +{ + QHBoxLayout *l = new QHBoxLayout(this); + m_label = new QLabel(this); + + l->addWidget(m_label); + l->setAlignment(Qt::AlignCenter); + setLayout(l); + + m_label->setText(i18n("Sample Text")); + QFont font = m_label->font(); + font.setBold(true); + m_label->setFont(font); + + //! shadow + QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect(); + effect->setColor(Qt::black); + effect->setBlurRadius(3); + effect->setXOffset(0); + effect->setYOffset(0); + m_label->setGraphicsEffect(effect); +} + +void PatternWidget::setBackground(const QString &file) +{ + if (m_background == file) { + return; + } + + m_background = file; + emit backgroundChanged(); +} + +void PatternWidget::setText(const QString &text) +{ + m_label->setText(text); +} + + +void PatternWidget::setTextColor(const QString &color) +{ + if (m_textColor == color) { + return; + } + + m_textColor = color; + emit textColorChanged(); +} + +void PatternWidget::updateUi() +{ + QString backgroundImage = "url(" + m_background + ");"; + + if (m_background.isEmpty()) { + backgroundImage = "none;"; + } + + setStyleSheet("[isBackground=true] {border: 1px solid black; border-radius: 8px; background-image: " + backgroundImage + "}"); + m_label->setStyleSheet("QLabel {border: 0px; background-image:none; color:" + m_textColor + "}"); +} + +void PatternWidget::paintEvent(QPaintEvent* event) +{ + //! it is needed from Qt, otherwise QWidget is not updated + //! https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + + QWidget::paintEvent(event); +} + +} +} +} diff --git a/app/settings/widgets/patternwidget.h b/app/settings/widgets/patternwidget.h new file mode 100644 index 000000000..426774bc6 --- /dev/null +++ b/app/settings/widgets/patternwidget.h @@ -0,0 +1,69 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * 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 SETTINGSPATTERNWIDGET_H +#define SETTINGSPATTERNWIDGET_H + +// Qt +#include +#include + + +namespace Latte { +namespace Settings { +namespace Widget { + +class PatternWidget : public QWidget +{ + Q_OBJECT + +public: + explicit PatternWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + + void setBackground(const QString &file); + void setText(const QString &text); + void setTextColor(const QString &color); + +signals: + void backgroundChanged(); + void textColorChanged(); + +protected: + void paintEvent(QPaintEvent* event) override; + +private slots: + void updateUi(); + +private: + void initUi(); + +private: + QLabel *m_label{nullptr}; + + QString m_background; + QString m_textColor; + +}; + +} +} +} + +#endif