diff --git a/CMakeLists.txt b/CMakeLists.txt
index e88bcfe..21b5f69 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -68,7 +68,7 @@ add_compile_definitions(UKUI_MENU_TRANSLATION_DIR="${UKUI_MENU_TRANSLATION_DIR}"
# ukui-menu的源码
set(SOURCE_FILES
src/main.cpp
- src/commons.h
+ src/commons.h src/commons.cpp
src/menu-dbus-service.cpp src/menu-dbus-service.h
src/model/model.cpp src/model/model.h
src/settings/settings.cpp src/settings/settings.h
diff --git a/src/commons.cpp b/src/commons.cpp
new file mode 100644
index 0000000..5c645e5
--- /dev/null
+++ b/src/commons.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2022, KylinSoft Co., Ltd.
+ *
+ * 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
+ * (at your option) 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 "commons.h"
+
+#include
+
+UkuiMenu::DataEntity::DataEntity(const UkuiMenu::DataEntity &obj)
+{
+ m_type = obj.m_type;
+ m_name = obj.m_name;
+ m_icon = obj.m_icon;
+ m_comment = obj.m_comment;
+ m_extraData = obj.m_extraData;
+}
+
+UkuiMenu::DataEntity::DataEntity(UkuiMenu::DataType::Type type, QString name, QString icon, QString comment, QString extraData)
+ : m_type(type), m_name(std::move(name)), m_icon(std::move(icon)), m_comment(std::move(comment)), m_extraData(std::move(extraData))
+{
+
+}
diff --git a/src/commons.h b/src/commons.h
index a8cc66f..79a5803 100644
--- a/src/commons.h
+++ b/src/commons.h
@@ -59,6 +59,10 @@ class DataEntity
Q_PROPERTY(QString comment READ comment WRITE setComment)
Q_PROPERTY(QString extraData READ extraData WRITE setExtraData)
public:
+ DataEntity() = default;
+ DataEntity(const DataEntity& obj);
+ DataEntity(DataType::Type type, QString name, QString icon, QString comment, QString extraData);
+
void setType(DataType::Type type) {m_type = type;}
DataType::Type type() {return m_type;}
diff --git a/src/model/model.cpp b/src/model/model.cpp
index ff167b8..022f85b 100644
--- a/src/model/model.cpp
+++ b/src/model/model.cpp
@@ -46,9 +46,20 @@ QHash AppModel::roleNames() const
return names;
}
-QList AppModel::folderApps(const QString &folderName)
+QVariantList AppModel::folderApps(const QString &folderName)
{
- return {};
+ DataEntity item1{DataType::Normal, "name 1", "icon", "comment", "extra"};
+ DataEntity item2{DataType::Normal, "name 2", "icon", "comment", "extra"};
+ DataEntity item3{DataType::Label, "name 3", "icon", "comment", "extra"};
+ DataEntity item4{DataType::Normal, "name 4", "icon", "comment", "extra"};
+
+ QVariantList list;
+ list.append(QVariant::fromValue(item1));
+ list.append(QVariant::fromValue(item2));
+ list.append(QVariant::fromValue(item3));
+ list.append(QVariant::fromValue(item4));
+
+ return list;
}
} // UkuiMenu
diff --git a/src/model/model.h b/src/model/model.h
index 5611be5..5a7b937 100644
--- a/src/model/model.h
+++ b/src/model/model.h
@@ -19,7 +19,7 @@
#ifndef UKUI_MENU_MODEL_H
#define UKUI_MENU_MODEL_H
-#include
+#include
#include
#include "commons.h"
@@ -36,7 +36,7 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
QHash roleNames() const override;
- Q_INVOKABLE QList folderApps(const QString &folderName);
+ Q_INVOKABLE QVariantList folderApps(const QString &folderName);
};
} // UkuiMenu
diff --git a/src/settings/settings.cpp b/src/settings/settings.cpp
index 1abf0e6..bd3826d 100644
--- a/src/settings/settings.cpp
+++ b/src/settings/settings.cpp
@@ -24,7 +24,7 @@
#define UKUI_MENU_SCHEMA "org.ukui.menu.settings"
#define CONTROL_CENTER_SETTING "org.ukui.control-center.personalise"
-#define CONTROL_CENTER_TRANSPARENCY_KEY "Transparency"
+#define CONTROL_CENTER_TRANSPARENCY_KEY "transparency"
#define UKUI_STYLE_SCHEMA "org.ukui.style"
#define UKUI_STYLE_NAME_KEY "styleName"
diff --git a/src/uiconfig/color-helper.cpp b/src/uiconfig/color-helper.cpp
index 60aa560..3acc20d 100644
--- a/src/uiconfig/color-helper.cpp
+++ b/src/uiconfig/color-helper.cpp
@@ -32,33 +32,29 @@ ColorHelper *ColorHelper::instance()
ColorHelper::ColorHelper(QObject *parent) : QObject(parent)
{
- m_colors.insert(ColorRole::Light, {"#000000"});
- m_colors.insert(ColorRole::Gray, {"#10171D"});
- m_colors.insert(ColorRole::Dark, {"#FFFFFF"});
+ m_colors.insert(ColorHelper::Light, {"#000000"});
+ m_colors.insert(ColorHelper::Gray, {"#10171D"});
+ m_colors.insert(ColorHelper::Dark, {"#FFFFFF"});
initStyleMonitor();
}
-QColor ColorHelper::getColor(ColorRole::Role role)
+QColor ColorHelper::getColor(ColorHelper::Role role)
{
- // TODO 从新设计颜色获取的方式,根据主题切换
- if (m_colors.contains(role)) {
- return m_colors.value(role);
- }
-
- return {"#000000"};
+ QMutexLocker locker(&m_mutex);
+ return m_colors.value(role, {"#000000"});
}
-QColor ColorHelper::colorWithTheme(ColorRole::Role role)
+QColor ColorHelper::colorWithTheme(ColorHelper::Role role)
{
QColor color = getColor(role);
- color.setAlphaF(0.5);
+ color.setAlphaF(m_transparency);
return color;
}
-QColor ColorHelper::colorWithAlpha(ColorRole::Role role, qreal alpha)
+QColor ColorHelper::colorWithAlpha(ColorHelper::Role role, qreal alpha)
{
QColor color = getColor(role);
- color.setAlphaF(0.5);
+ color.setAlphaF(alpha);
return color;
}
@@ -66,18 +62,31 @@ void ColorHelper::initStyleMonitor()
{
updateStyle();
connect(GlobalSetting::instance(), &GlobalSetting::styleChanged, this , [this] (const GlobalSetting::Key& key) {
- if (key & GlobalSetting::StyleName) {
+ if (key & GlobalSetting::StyleName || key & GlobalSetting::Transparency) {
updateStyle();
}
});
-
- connect(qApp, &QApplication::paletteChanged, this, &ColorHelper::colorChanged);
}
void ColorHelper::updateStyle()
{
- QString styleName = GlobalSetting::instance()->get(GlobalSetting::StyleName).toString();
- m_isDarkStyle = (styleName != UKUI_STYLE_VALUE_LIGHT);
+ GlobalSetting *setting = GlobalSetting::instance();
+ m_transparency = setting->get(GlobalSetting::Transparency).toReal();
+
+ QString styleName = setting->get(GlobalSetting::StyleName).toString();
+ bool isDarkStyle = (styleName != UKUI_STYLE_VALUE_LIGHT);
+
+ if (isDarkStyle != m_isDarkStyle) {
+ m_isDarkStyle = isDarkStyle;
+
+ m_mutex.lock();
+
+ m_colors.insert(ColorHelper::Light, {m_isDarkStyle ? "#FFFFFF" : "#000000"});
+ m_colors.insert(ColorHelper::Gray, {m_isDarkStyle ? "#000000" : "#10171D"});
+ m_colors.insert(ColorHelper::Dark, {m_isDarkStyle ? "#000000" : "#FFFFFF"});
+
+ m_mutex.unlock();
+ }
Q_EMIT colorChanged();
}
diff --git a/src/uiconfig/color-helper.h b/src/uiconfig/color-helper.h
index 6834d6f..6064430 100644
--- a/src/uiconfig/color-helper.h
+++ b/src/uiconfig/color-helper.h
@@ -22,13 +22,14 @@
#include
#include
#include
-#include
+#include
+#include
namespace UkuiMenu {
-class ColorRole
+class ColorHelper : public QObject
{
- Q_GADGET
+ Q_OBJECT
public:
enum Role {
Base = 0,
@@ -39,20 +40,15 @@ public:
Dark
};
Q_ENUM(Role)
-};
-class ColorHelper : public QObject
-{
- Q_OBJECT
-public:
static ColorHelper *instance();
ColorHelper() = delete;
ColorHelper(const ColorHelper& obj) = delete;
ColorHelper(ColorHelper&& obj) = delete;
- Q_INVOKABLE QColor getColor(ColorRole::Role role);
- Q_INVOKABLE QColor colorWithTheme(ColorRole::Role role);
- Q_INVOKABLE QColor colorWithAlpha(ColorRole::Role role, qreal alpha);
+ Q_INVOKABLE QColor getColor(ColorHelper::Role role);
+ Q_INVOKABLE QColor colorWithTheme(ColorHelper::Role role);
+ Q_INVOKABLE QColor colorWithAlpha(ColorHelper::Role role, qreal alpha);
Q_SIGNALS:
void colorChanged();
@@ -65,8 +61,10 @@ private:
void initStyleMonitor();
private:
- QMap m_colors;
+ QMutex m_mutex;
+ QMap m_colors;
bool m_isDarkStyle{false};
+ qreal m_transparency{1.0};
};
} // UkuiMenu
diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp
index 31a904c..0daac25 100644
--- a/src/ukui-menu-application.cpp
+++ b/src/ukui-menu-application.cpp
@@ -20,6 +20,8 @@
#include "settings.h"
#include "commons.h"
#include "model-manager.h"
+#include "color-helper.h"
+#include "theme-palette.h"
#include
#include
@@ -49,6 +51,13 @@ void UkuiMenuApplication::registerQmlTypes()
SettingModule::defineModule(uri, versionMajor, versionMinor);
ModelManager::registerMetaTypes();
+
+ // vis colors
+ qRegisterMetaType("Palette::ColorRole");
+ qRegisterMetaType("Palette::ColorGroup");
+ qRegisterMetaType("ColorHelper::Role");
+ qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "Palette", "Use enums only.");
+ qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "ColorHelper", "Use enums only.");
}
void UkuiMenuApplication::initQmlEngine()
@@ -58,6 +67,8 @@ void UkuiMenuApplication::initQmlEngine()
m_applicationEngine->addImportPath("qrc:/qml");
+ m_applicationEngine->rootContext()->setContextProperty("colorHelper", ColorHelper::instance());
+ m_applicationEngine->rootContext()->setContextProperty("themePalette", ThemePalette::getInstance());
m_applicationEngine->rootContext()->setContextProperty("menuSetting", MenuSetting::instance());
m_applicationEngine->rootContext()->setContextProperty("modelManager", new ModelManager(this));