feat: adaptive desktop background

main
reionwong 4 years ago
parent 64846357b5
commit 081cd78dc2

@ -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

@ -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: {

@ -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
}
}

@ -0,0 +1,71 @@
/*
* Copyright (C) 2021 - 2022 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "backgroundhelper.h"
#include <QApplication>
#include <QDebug>
#include <QPixmap>
#include <QScreen>
#include <QRgb>
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());
}

@ -0,0 +1,43 @@
/*
* Copyright (C) 2021 - 2022 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef BACKGROUNDHELPER_H
#define BACKGROUNDHELPER_H
#include <QObject>
#include <QColor>
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

@ -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<AppMenuApplet>(uri, 1, 0, "AppMenuApplet");
qmlRegisterType<PowerActions>(uri, 1, 0, "PowerActions");
qmlRegisterType<Notifications>(uri, 1, 0, "Notifications");
qmlRegisterType<BackgroundHelper>(uri, 1, 0, "BackgroundHelper");
QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-statusbar/translations/").arg(QLocale::system().name());
if (QFile::exists(qmFilePath)) {

@ -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();

@ -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;

@ -25,6 +25,11 @@
#include <KWindowSystem>
static QStringList noColorOverlayList = {
"netease-cloud-music",
"chrome_status_icon_1"
};
SystemTrayModel::SystemTrayModel(QObject *parent)
: QAbstractListModel(parent)
{
@ -58,6 +63,7 @@ QHash<int, QByteArray> 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();

@ -40,7 +40,8 @@ public:
IconNameRole,
IconRole,
TitleRole,
ToolTipRole
ToolTipRole,
CanColorOverlay
};
explicit SystemTrayModel(QObject *parent = nullptr);

Loading…
Cancel
Save