diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed96f8..fe04fdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ set(SRCS src/activity.cpp src/capplications.cpp src/notifications.cpp + src/backgroundhelper.cpp src/systemtray/statusnotifieritemsource.cpp src/systemtray/systemtraytypes.cpp diff --git a/qml/SystemTray.qml b/qml/SystemTray.qml index d1d4aed..c3015ae 100644 --- a/qml/SystemTray.qml +++ b/qml/SystemTray.qml @@ -1,6 +1,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 import QtQuick.Controls 2.12 +import QtGraphicalEffects 1.0 import Cutefish.StatusBar 1.0 import FishUI 1.0 as FishUI @@ -90,6 +91,17 @@ ListView { onTriggered: iconItem.updateIcon() } + ColorOverlay { + id: iconOverlay + anchors.centerIn: parent + width: rootItem.iconSize + height: width + source: iconItem + color: rootItem.textColor + opacity: rootItem.darkMode ? 1 : 0.7 + visible: model.canColorOverlay + } + FishUI.IconItem { id: iconItem anchors.centerIn: parent @@ -98,7 +110,7 @@ ListView { source: model.iconName ? model.iconName : model.icon antialiasing: true smooth: true - visible: !dragStarted + visible: !dragStarted && !iconOverlay.visible } onClicked: { diff --git a/qml/main.qml b/qml/main.qml index 3b56e86..fb841cc 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -22,6 +22,7 @@ import QtQuick.Layouts 1.12 import QtQuick.Controls 2.12 import QtQuick.Window 2.12 +import Cutefish.System 1.0 as System import Cutefish.StatusBar 1.0 import Cutefish.NetworkManagement 1.0 as NM import FishUI 1.0 as FishUI @@ -34,7 +35,7 @@ Item { LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft LayoutMirroring.childrenInherit: true - property bool darkMode: FishUI.Theme.darkMode + property bool darkMode: false property color textColor: rootItem.darkMode ? "#FFFFFF" : "#000000"; property var fontSize: rootItem.height ? rootItem.height / 3 : 1 @@ -44,15 +45,43 @@ Item { timeTimer.restart() } + System.Wallpaper { + id: sysWallpaper + + function reload() { + if (sysWallpaper.type === 0) + bgHelper.setBackgound(sysWallpaper.path) + else + bgHelper.setColor(sysWallpaper.color) + } + + Component.onCompleted: sysWallpaper.reload() + + onTypeChanged: sysWallpaper.reload() + onColorChanged: sysWallpaper.reload() + onPathChanged: sysWallpaper.reload() + } + + BackgroundHelper { + id: bgHelper + + onNewColor: { + background.color = color + rootItem.darkMode = lightness < 128 ? true : false + } + } + Rectangle { id: background anchors.fill: parent - color: FishUI.Theme.darkMode ? "#4D4D4D" : "#FFFFFF" - opacity: windowHelper.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.7 : 1.0 + opacity: 0.3 + +// color: FishUI.Theme.darkMode ? "#4D4D4D" : "#FFFFFF" +// opacity: windowHelper.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.7 : 1.0 Behavior on color { ColorAnimation { - duration: 200 + duration: 100 easing.type: Easing.Linear } } diff --git a/src/backgroundhelper.cpp b/src/backgroundhelper.cpp new file mode 100644 index 0000000..aebe521 --- /dev/null +++ b/src/backgroundhelper.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 - 2022 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "backgroundhelper.h" + +#include +#include +#include +#include +#include + +BackgroundHelper::BackgroundHelper(QObject *parent) + : QObject(parent) + , m_statusBarHeight(25 / qApp->devicePixelRatio()) +{ +} + +void BackgroundHelper::setColor(QColor c) +{ + emit newColor(c, c.lightness()); +} + +void BackgroundHelper::setBackgound(const QString &fileName) +{ + QImage img(fileName); + + QSize screenSize = qApp->primaryScreen()->geometry().size(); + img = img.scaled(screenSize.width(), screenSize.height()); + img = img.copy(QRect(0, 0, screenSize.width(), m_statusBarHeight)); + + QSize size(img.size()); + img = img.scaledToWidth(size.width() * 0.8); + size = img.size(); + + long long sumR = 0, sumG = 0, sumB = 0; + int measureArea = size.width() * size.height(); + + for (int y = 0; y < size.height(); ++y) { + QRgb *line = (QRgb *)img.scanLine(y); + + for (int x = 0; x < size.width(); ++x) { + sumR += qRed(line[x]); + sumG += qGreen(line[x]); + sumB += qBlue(line[x]); + } + } + + sumR /= measureArea; + sumG /= measureArea; + sumB /= measureArea; + + QColor c = QColor(sumR, sumG, sumB); + + emit newColor(c, c.lightness()); +} diff --git a/src/backgroundhelper.h b/src/backgroundhelper.h new file mode 100644 index 0000000..8a93f2f --- /dev/null +++ b/src/backgroundhelper.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2021 - 2022 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BACKGROUNDHELPER_H +#define BACKGROUNDHELPER_H + +#include +#include + +class BackgroundHelper : public QObject +{ + Q_OBJECT + +public: + explicit BackgroundHelper(QObject *parent = nullptr); + + Q_INVOKABLE void setColor(QColor c); + Q_INVOKABLE void setBackgound(const QString &fileName); + +signals: + void newColor(QColor color, int lightness); + +private: + int m_statusBarHeight; +}; + +#endif // BACKGROUNDHELPER_H diff --git a/src/main.cpp b/src/main.cpp index a61d5e6..e971c0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,7 @@ #include "appmenu/appmenuapplet.h" #include "poweractions.h" #include "notifications.h" +#include "backgroundhelper.h" #include "appearance.h" #include "brightness.h" @@ -48,6 +49,7 @@ int main(int argc, char *argv[]) qmlRegisterType(uri, 1, 0, "AppMenuApplet"); qmlRegisterType(uri, 1, 0, "PowerActions"); qmlRegisterType(uri, 1, 0, "Notifications"); + qmlRegisterType(uri, 1, 0, "BackgroundHelper"); QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-statusbar/translations/").arg(QLocale::system().name()); if (QFile::exists(qmFilePath)) { diff --git a/src/systemtray/statusnotifieritemsource.cpp b/src/systemtray/statusnotifieritemsource.cpp index ef3e676..8302759 100644 --- a/src/systemtray/statusnotifieritemsource.cpp +++ b/src/systemtray/statusnotifieritemsource.cpp @@ -99,6 +99,11 @@ QString StatusNotifierItemSource::id() const return m_id; } +QString StatusNotifierItemSource::appId() const +{ + return m_appId; +} + QString StatusNotifierItemSource::title() const { return m_title; @@ -267,6 +272,7 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call) if (!QIcon::fromTheme(id).isNull()) { m_iconName = id; } + m_appId = id; // Reion: For icon theme path QString iconThemePath = properties[QStringLiteral("IconThemePath")].toString(); diff --git a/src/systemtray/statusnotifieritemsource.h b/src/systemtray/statusnotifieritemsource.h index ef2e400..96dc485 100644 --- a/src/systemtray/statusnotifieritemsource.h +++ b/src/systemtray/statusnotifieritemsource.h @@ -43,6 +43,7 @@ public: ~StatusNotifierItemSource(); QString id() const; + QString appId() const; QString title() const; QString tooltip() const; QString subtitle() const; @@ -87,6 +88,7 @@ private: bool m_tooltipUpdate : 1; bool m_statusUpdate : 1; + QString m_appId; QString m_id; QString m_title; QString m_tooltip; diff --git a/src/systemtray/systemtraymodel.cpp b/src/systemtray/systemtraymodel.cpp index 3a0985c..1c54258 100644 --- a/src/systemtray/systemtraymodel.cpp +++ b/src/systemtray/systemtraymodel.cpp @@ -25,6 +25,11 @@ #include +static QStringList noColorOverlayList = { + "netease-cloud-music", + "chrome_status_icon_1" +}; + SystemTrayModel::SystemTrayModel(QObject *parent) : QAbstractListModel(parent) { @@ -58,6 +63,7 @@ QHash SystemTrayModel::roleNames() const roles[IconRole] = "icon"; roles[TitleRole] = "title"; roles[ToolTipRole] = "toolTip"; + roles[CanColorOverlay] = "canColorOverlay"; return roles; } @@ -83,6 +89,8 @@ QVariant SystemTrayModel::data(const QModelIndex &index, int role) const return item->title(); case ToolTipRole: return item->tooltip(); + case CanColorOverlay: + return !noColorOverlayList.contains(item->appId()); } return QVariant(); diff --git a/src/systemtray/systemtraymodel.h b/src/systemtray/systemtraymodel.h index 9d81572..5d2368f 100644 --- a/src/systemtray/systemtraymodel.h +++ b/src/systemtray/systemtraymodel.h @@ -40,7 +40,8 @@ public: IconNameRole, IconRole, TitleRole, - ToolTipRole + ToolTipRole, + CanColorOverlay }; explicit SystemTrayModel(QObject *parent = nullptr);