style(ui): 清理代码,修改import路径

This commit is contained in:
hewenfei 2024-01-18 03:24:01 +08:00
parent 65bbe28fea
commit a869df8770
41 changed files with 141 additions and 1028 deletions

View File

@ -95,17 +95,13 @@ set(SOURCE_FILES
src/commons.h src/commons.cpp
src/menu-dbus-service.cpp src/menu-dbus-service.h
src/ukui-menu-application.cpp src/ukui-menu-application.h
src/settings/settings.cpp src/settings/settings.h
src/uiconfig/theme-palette.cpp src/uiconfig/theme-palette.h
src/windows/menu-main-window.cpp src/windows/menu-main-window.h
src/appdata/app-data-manager.cpp src/appdata/app-data-manager.h
src/appdata/app-icon-provider.cpp src/appdata/app-icon-provider.h
src/settings/settings.cpp src/settings/settings.h
src/settings/user-config.cpp src/settings/user-config.h
src/utils/power-button.cpp src/utils/power-button.h
src/utils/app-manager.cpp src/utils/app-manager.h
src/utils/event-track.cpp src/utils/event-track.h
src/utils/sidebar-button-utils.cpp src/utils/sidebar-button-utils.h
src/items/theme-icon.h src/items/theme-icon.cpp
src/settings/user-config.cpp src/settings/user-config.h
src/extension/menu-extension-plugin.cpp src/extension/menu-extension-plugin.h
src/extension/menu-extension-loader.cpp src/extension/menu-extension-loader.h
src/extension/widget-extension.cpp src/extension/widget-extension.h

View File

@ -18,16 +18,18 @@
import QtQuick 2.12
import org.ukui.menu.core 1.0
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
StyleBackground {
UkuiItems.StyleBackground {
property alias icons: iconGrid.icons
property alias rows: iconGrid.rows
property alias columns: iconGrid.columns
property alias padding: iconGrid.padding
property alias spacing: iconGrid.spacing
paletteRole: Palette.Text
useStyleTransparent: false
paletteRole: Platform.Theme.Text
useStyleTransparency: false
Grid {
id: iconGrid

View File

@ -2,8 +2,8 @@ import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.5
import org.ukui.menu.core 1.0
import org.ukui.quick.platform 1.0 as Platform
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
MouseArea {
id: control
@ -18,7 +18,7 @@ MouseArea {
when: control.activeFocus
PropertyChanges {
target: controlBase
borderColor: Palette.Highlight
borderColor: Platform.Theme.Highlight
border.width: 2
}
}
@ -94,20 +94,23 @@ MouseArea {
}
function updateTextInputColor() {
color = themePalette.paletteColor(Palette.Text);
selectionColor = themePalette.paletteColor(Palette.Highlight);
color = Platform.Theme.text();
selectionColor = Platform.Theme.highlight();
}
onEditingFinished: {
modelManager.getAppModel().renameFolder(id, text);
textChange.editStatusEnd();
}
Platform.Theme.onPaletteChanged: {
updateTextInputColor();
}
Component.onCompleted: {
updateTextInputColor();
themePalette.styleColorChanged.connect(updateTextInputColor);
forceActiveFocus();
}
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor);
}
MouseArea {

View File

@ -1,7 +1,7 @@
import QtQuick 2.0
import org.ukui.menu.core 1.0
import org.ukui.quick.platform 1.0 as Platform
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
Item {
id: root

View File

@ -1,6 +1,9 @@
import QtQuick 2.15
import org.ukui.menu.core 1.0
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
MouseArea {
id: buttonMouseArea
hoverEnabled: true
@ -8,26 +11,27 @@ MouseArea {
property alias highlight: themeIcon.highLight
property alias autoHighLight: themeIcon.autoHighLight
StyleBackground {
UkuiItems.StyleBackground {
id: buttonBase
useStyleTransparent: false
paletteRole: mainWindow.isFullScreen ? Palette.Light : Palette.Text
useStyleTransparency: false
paletteRole: mainWindow.isFullScreen ? Platform.Theme.Light : Platform.Theme.Text
anchors.fill: parent
radius: height / 2
alpha: buttonMouseArea.containsPress ? 0.20 : buttonMouseArea.containsMouse ? 0.16 : 0.10
}
ThemeIcon {
UkuiItems.Icon {
id: themeIcon
anchors.centerIn: parent
width: 16; height: width
source: buttonIcon
mode: UkuiItems.Icon.AutoHighlight
}
states: State {
when: buttonMouseArea.activeFocus
PropertyChanges {
target: buttonBase
borderColor: Palette.Highlight
borderColor: Platform.Theme.Highlight
border.width: 2
}
}

View File

@ -1,6 +1,8 @@
import QtQuick 2.0
import QtQuick.Controls 2.5
import org.ukui.menu.core 1.0
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
ScrollBar {
id: control
@ -14,10 +16,10 @@ ScrollBar {
}
}
contentItem: StyleBackground {
contentItem: UkuiItems.StyleBackground {
radius: width / 2
useStyleTransparent: false
paletteRole: Palette.Text
useStyleTransparency: false
paletteRole: Platform.Theme.Text
alpha: control.pressed ? 0.28 : control.hovered ? 0.18 : 0.10
opacity: ((control.policy === ScrollBar.AlwaysOn || control.size < 1.0 ) && control.visual) ? 1.0 : 0.0
}

View File

@ -1,57 +0,0 @@
import QtQuick 2.12
import org.ukui.menu.core 1.0
Rectangle {
property bool useStyleTransparent: true
property int paletteRole: Palette.Base
property int paletteGroup: Palette.Active
property int borderColor: Palette.Base
property real alpha: 1.0
property real borderAlpha: 1.0
clip: true
border.width: 0
function updateColor() {
if (useStyleTransparent) {
color = themePalette.paletteColorWithTransparency(paletteRole, paletteGroup)
} else {
color = themePalette.paletteColorWithCustomTransparency(paletteRole, paletteGroup, alpha)
}
}
function updateBorderColor() {
border.color = themePalette.paletteColorWithCustomTransparency(borderColor, Palette.Active, borderAlpha)
}
Component.onCompleted: {
updateColor()
updateBorderColor()
themePalette.styleColorChanged.connect(updateColor)
themePalette.styleColorChanged.connect(updateBorderColor)
}
Component.onDestruction: {
themePalette.styleColorChanged.disconnect(updateColor)
themePalette.styleColorChanged.disconnect(updateBorderColor)
}
onUseStyleTransparentChanged: {
updateColor()
}
onPaletteRoleChanged: {
updateColor()
}
onPaletteGroupChanged: {
updateColor()
}
onAlphaChanged: {
updateColor()
}
onBorderAlphaChanged: {
updateBorderColor()
}
onBorderColorChanged: {
updateBorderColor()
}
}

View File

@ -1,33 +0,0 @@
import QtQuick 2.0
import org.ukui.menu.core 1.0
Text {
property int paletteRole: Palette.Text
property real alpha: 1
property real systemFontSize: 10
property real textUltra: 2*systemFontSize
font.pointSize: systemFontSize
function updateColor() {
color = themePalette.paletteColorWithCustomTransparency(paletteRole, Palette.Active, alpha);
}
function updateFont() {
font = themePalette.systemFont();
}
Component.onCompleted: {
updateColor();
updateFont();
themePalette.styleColorChanged.connect(updateColor);
themePalette.systemFontChanged.connect(updateFont);
}
Component.onDestruction: {
themePalette.styleColorChanged.disconnect(updateColor);
themePalette.systemFontChanged.disconnect(updateFont);
}
onPaletteRoleChanged: {
updateColor();
}
onAlphaChanged: {
updateColor();
}
}

View File

@ -1,6 +1,4 @@
module AppControls2
StyleBackground 1.0 StyleBackground.qml
StyleText 1.0 StyleText.qml
ScrollBar 1.0 ScrollBar.qml
AppItem 1.0 AppItem.qml
FolderItem 1.0 FolderItem.qml

View File

@ -24,10 +24,6 @@ Item {
property alias search: appPageSearch
property alias content: appPageContent
AppPageBackend {
id: appPageBackend
}
ColumnLayout {
anchors.fill: parent
anchors.topMargin: 12
@ -39,7 +35,6 @@ Item {
Layout.fillWidth: true
Layout.preferredHeight: 40
focusToPageContent: appPageContent
backend: appPageBackend
}
AppPageContent {
@ -47,7 +42,6 @@ Item {
Layout.fillWidth: true
Layout.fillHeight: true
activeFocusOnTab: false
backend: appPageBackend
}
}
}

View File

@ -23,8 +23,6 @@ import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0
Item {
id: root
property AppPageBackend backend: null
property bool isAppListShow: appList.visible
function resetFocus() {
@ -43,7 +41,7 @@ Item {
id: appListHeader
Layout.fillWidth: true
Layout.preferredHeight: 48
header: backend.appModel.header
header: AppPageBackend.appModel.header
}
Item {
@ -54,7 +52,7 @@ Item {
id: appList
anchors.fill: parent
visible: true
model: backend.appModel
model: AppPageBackend.appModel
view.onContentYChanged: {
if (view.contentY <= 0) {

View File

@ -6,8 +6,6 @@ import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.menu.utils 1.0
Item {
id: root
property AppPageBackend backend: null
property Item focusToPageContent
property bool inputStatus: false
@ -23,12 +21,11 @@ Item {
visible: true
onTextChanged: {
if (text === "") {
root.backend.group = PluginGroup.Display;
AppPageBackend.group = PluginGroup.Display;
inputStatus = false;
} else {
root.backend.group = PluginGroup.Search;
// appPageHeaderUtils.startSearch(text);
root.backend.startSearch(text);
AppPageBackend.group = PluginGroup.Search;
AppPageBackend.startSearch(text);
inputStatus = true;
}
}

View File

@ -92,20 +92,19 @@ Item {
contain.editStatus = false;
}
property int textColor: isFullScreen ? Palette.HighlightedText : Palette.Text
function updateTextInputColor() {
color = themePalette.paletteColor(textColor);
selectionColor = themePalette.paletteColor(Palette.Highlight);
color = isFullScreenFolder ? Platform.Theme.highlightedText() : Platform.Theme.text();
selectionColor = Platform.Theme.highlight();
}
Platform.Theme.onPaletteChanged: {
updateTextInputColor();
}
Component.onCompleted: {
updateTextInputColor();
themePalette.styleColorChanged.connect(updateTextInputColor);
forceActiveFocus();
}
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor);
}
MouseArea {
@ -117,12 +116,11 @@ Item {
anchors.verticalCenter: parent.verticalCenter
visible: textEdit.activeFocus
ThemeIcon {
UkuiItems.Icon {
anchors.centerIn: parent
width: 16; height: width
source: "image://appicon/edit-clear-symbolic"
highLight: isFullScreenFolder
autoHighLight: !isFullScreenFolder
source: "image://theme/edit-clear-symbolic"
mode: isFullScreenFolder ? UkuiItems.Icon.Highlight : UkuiItems.Icon.AutoHighlight
}
onClicked: {

View File

@ -233,7 +233,7 @@ RowLayout {
when: dropArea.activeFocus
PropertyChanges {
target: controlBase
borderColor: Palette.Highlight
borderColor: Platform.Theme.Highlight
border.width: 2
}
}
@ -261,11 +261,11 @@ RowLayout {
ToolTip.delay: 500
ToolTip.text: name
ToolTip.visible: iconText.truncated && containsMouse
AppControls2.StyleBackground {
UkuiItems.StyleBackground {
id: controlBase
anchors.fill: parent
useStyleTransparent: false
paletteRole: Palette.Light
useStyleTransparency: false
paletteRole: Platform.Theme.Light
radius: 16
alpha: appItem.isSelect ? 0.00 : parent.containsPress ? 0.25 : parent.containsMouse ? 0.15 : 0.00
Item {
@ -275,11 +275,11 @@ RowLayout {
height: 108
width: 108
AppControls2.StyleBackground {
UkuiItems.StyleBackground {
id: imageBase
anchors.fill: parent
paletteRole: Palette.Text
useStyleTransparent: false
paletteRole: Platform.Theme.Text
useStyleTransparency: false
alpha: 0.25
radius: 24
visible: false
@ -294,7 +294,7 @@ RowLayout {
}
}
AppControls2.StyleText {
UkuiItems.StyleText {
id: iconText
visible: !appItem.isSelect
width: parent.width
@ -304,7 +304,7 @@ RowLayout {
anchors.horizontalCenter: parent.horizontalCenter
text: name
elide: Text.ElideRight
paletteRole: Palette.HighlightedText
paletteRole: Platform.Theme.HighlightedText
}
}
@ -363,10 +363,10 @@ RowLayout {
ToolTip.delay: 500
ToolTip.text: name
ToolTip.visible: folderText.truncated && containsMouse
AppControls2.StyleBackground {
UkuiItems.StyleBackground {
anchors.fill: parent
useStyleTransparent: false
paletteRole: Palette.Light
useStyleTransparency: false
paletteRole: Platform.Theme.Light
radius: 16
alpha: parent.containsPress ? 0.25 : parent.containsMouse ? 0.15 : 0.00
@ -378,10 +378,10 @@ RowLayout {
anchors.top: parent.top
anchors.topMargin: 14
AppControls2.StyleBackground {
UkuiItems.StyleBackground {
anchors.fill: parent
paletteRole: Palette.Text
useStyleTransparent: false
paletteRole: Platform.Theme.Text
useStyleTransparency: false
alpha: 0.25
radius: 24
visible: folderItem.isSelect
@ -399,7 +399,7 @@ RowLayout {
}
}
AppControls2.StyleText {
UkuiItems.StyleText {
id: folderText
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
@ -408,7 +408,7 @@ RowLayout {
anchors.horizontalCenter: parent.horizontalCenter
elide: Text.ElideRight
text: name
paletteRole: Palette.HighlightedText
paletteRole: Platform.Theme.HighlightedText
}
}

View File

@ -29,10 +29,6 @@ UkuiItems.StyleBackground {
anchors.fill: parent
z: 10
AppPageBackend {
id: appPageBackend
}
//
GridLayout {
anchors.fill: parent
@ -59,7 +55,7 @@ UkuiItems.StyleBackground {
id: actionsItem
anchors.centerIn: parent
height: parent.height
actions: appPageBackend.appModel.header.actions
actions: AppPageBackend.appModel.header.actions
visible: count > 0
}
}
@ -80,10 +76,10 @@ UkuiItems.StyleBackground {
onTextChanged: {
if (text === "") {
appPageBackend.group = PluginGroup.Display;
AppPageBackend.group = PluginGroup.Display;
} else {
appPageBackend.group = PluginGroup.Search;
appPageBackend.startSearch(text);
AppPageBackend.group = PluginGroup.Search;
AppPageBackend.startSearch(text);
}
}
}
@ -121,7 +117,7 @@ UkuiItems.StyleBackground {
Layout.fillWidth: true
Layout.fillHeight: true
sourceModel: appPageBackend.appModel
sourceModel: AppPageBackend.appModel
}
}
}

View File

@ -117,17 +117,21 @@ UkuiItems.StyleBackground {
Keys.onReturnPressed: changeFocusToListView()
//
property int textColor: mainWindow.isFullScreen ? Palette.HighlightedText : Palette.Text
property bool isFullScreen: mainWindow.isFullScreen
onIsFullScreenChanged: updateTextInputColor()
function updateTextInputColor() {
color = themePalette.paletteColor(textColor)
selectionColor = themePalette.paletteColor(Palette.Highlight)
color = isFullScreen ? Platform.Theme.highlightedText() : Platform.Theme.text();
selectionColor = Platform.Theme.highlight();
}
Platform.Theme.onPaletteChanged: {
updateTextInputColor();
}
Component.onCompleted: {
updateTextInputColor();
themePalette.styleColorChanged.connect(updateTextInputColor);
}
onTextColorChanged: updateTextInputColor()
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor)
}
UkuiItems.Button {

View File

@ -32,6 +32,7 @@ Item {
ColumnLayout {
anchors.fill: parent
anchors.topMargin: 12
anchors.bottomMargin: 5
spacing: 5
Item {
@ -70,10 +71,10 @@ Item {
//
UkuiItems.StyleBackground {
useStyleTransparency: false
paletteRole: Palette.Highlight
paletteRole: Platform.Theme.Highlight
alpha: 0
radius: Platform.Theme.minRadius
borderColor: Palette.Highlight
borderColor: Platform.Theme.Highlight
border.width: activeFocus ? 2 : 0
property var extensionData: model.data

View File

@ -20,6 +20,7 @@ import QtQuick 2.12
import AppUI 1.0 as AppUI
import AppControls2 1.0 as AppControls2
import org.ukui.menu.core 1.0
import org.ukui.quick.items 1.0 as UkuiItems
Item {
id: root
@ -102,7 +103,7 @@ Item {
}
}
AppControls2.StyleBackground {
UkuiItems.StyleBackground {
id: backgroundMask
// normalScreen
x: 0; y: 0

View File

@ -19,8 +19,6 @@
<file>AppControls2/qmldir</file>
<file>AppControls2/App.qml</file>
<file>AppControls2/ScrollBar.qml</file>
<file>AppControls2/StyleBackground.qml</file>
<file>AppControls2/StyleText.qml</file>
<file>AppControls2/IconLabel.qml</file>
<file>AppControls2/AppItem.qml</file>
<file>AppControls2/LabelItem.qml</file>

View File

@ -17,8 +17,8 @@
*/
#include "context-menu-manager.h"
#include "app-data-manager.h"
#include "menu-extension-loader.h"
#include "basic-app-model.h"
#include <QMenu>
#include <QCursor>
@ -57,7 +57,7 @@ ContextMenuManager::~ContextMenuManager()
void ContextMenuManager::showMenu(const QString &appid, const MenuInfo::Location location, const QString &lid, const QPoint &point)
{
DataEntity app;
if (AppDataManager::instance()->getApp(appid, app)) {
if (BasicAppModel::instance()->getAppById(appid, app)) {
showMenu(app, location, lid, point);
}
}

View File

@ -17,10 +17,10 @@
*/
#include "favorite-context-menu.h"
#include "favorite-folder-helper.h"
#include "app-data-manager.h"
#include "favorites-model.h"
#include "event-track.h"
#include "basic-app-model.h"
#include "favorites-model.h"
#include "favorite-folder-helper.h"
namespace UkuiMenu {
@ -54,6 +54,7 @@ FavoriteContextMenu::actions(const DataEntity &data, QMenu *parent, const MenuIn
list << new QAction(QObject::tr("Fix to favorite"), parent);
QObject::connect(list.last(), &QAction::triggered, parent, [data] {
FavoritesModel::instance().addAppToFavorites(data.id());
//BasicAppModel::instance()->databaseInterface()->fixAppToFavorite(data.id(), 1);
EventTrack::instance()->sendDefaultEvent("fix_to_favorite", "Right-click Menu");
});
@ -61,6 +62,7 @@ FavoriteContextMenu::actions(const DataEntity &data, QMenu *parent, const MenuIn
list << new QAction(QObject::tr("Remove from favorite"), parent);
QObject::connect(list.last(), &QAction::triggered, parent, [data] {
FavoritesModel::instance().removeAppFromFavorites(data.id());
BasicAppModel::instance()->databaseInterface()->fixAppToFavorite(data.id(), 0);
EventTrack::instance()->sendDefaultEvent("remove_from_favorite", "Right-click Menu");
});
}

View File

@ -18,10 +18,9 @@
#include "favorite-folder-helper.h"
#include "app-data-manager.h"
#include "model-manager.h"
#include "app-model.h"
#include "event-track.h"
#include "favorites-config.h"
#include "basic-app-model.h"
#include <QJsonDocument>
#include <QJsonArray>
@ -344,7 +343,7 @@ QStringList FavoriteFolderHelper::folderIcon(const FavoritesFolder &folder)
int count = qMin(folder.apps.count(), FOLDER_MAX_ICON_NUM);
for (int i = 0; i < count; ++i) {
if (AppDataManager::instance()->getApp(folder.apps.at(i), app)) {
if (BasicAppModel::instance()->getAppById(folder.apps.at(i), app)) {
icons.append(app.icon());
}
}

View File

@ -17,10 +17,10 @@
*/
#include "app-menu-plugin.h"
#include "app-data-manager.h"
#include "settings.h"
#include "app-manager.h"
#include "../context-menu-extension.h"
#include "basic-app-model.h"
#include <QStringLiteral>
#include <QDBusInterface>
@ -91,7 +91,7 @@ void AppContentMenu::addToTop(QObject *parent, const QString &appId, const int &
QString actionName = (appTop == 0) ? QObject::tr("Fixed to all applications") : QObject::tr("Unfixed from all applications");
list << new QAction(actionName, parent);
QObject::connect(list.last(), &QAction::triggered, parent, [appId, appTop] {
AppDataManager::instance()->fixToTop(appId, appTop);
BasicAppModel::instance()->databaseInterface()->fixAppToTop(appId, appTop);
});
}

View File

@ -1,259 +0,0 @@
/*
* Copyright (C) 2023, 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 <https://www.gnu.org/licenses/>.
*
* Authors: hxf <hewenfei@kylinos.cn>
*
*/
#include "theme-icon.h"
#include "settings.h"
#include "app-icon-provider.h"
#include <QUrl>
#include <QPainter>
#include <QImageReader>
#include <QDebug>
#include <QGuiApplication>
#include <QPalette>
#include <QImage>
#include <QtMath>
#include <QPainterPath>
#define COLOR_DIFFERENCE 10
using namespace UkuiMenu;
QColor ThemeIcon::symbolicColor = QColor(31, 32, 34, 192);
ThemeIcon::ThemeIcon(QQuickItem *parent) : QQuickPaintedItem(parent)
{
connect(GlobalSetting::instance(), &GlobalSetting::styleChanged, this, [this] (const GlobalSetting::Key& key) {
if (key == GlobalSetting::StyleName) {
checkThemeName();
}
});
connect(this, &ThemeIcon::widthChanged, this, &ThemeIcon::onSizeChanged);
connect(this, &ThemeIcon::heightChanged, this, &ThemeIcon::onSizeChanged);
}
void ThemeIcon::checkThemeName()
{
if (!m_autoHighlight) {
return;
}
m_highLight = (GlobalSetting::instance()->get(GlobalSetting::StyleName).toString() != UKUI_STYLE_VALUE_LIGHT);
update();
}
void ThemeIcon::loadPixmapBySource(const QString &source)
{
QSize size;
m_pixmap = UkuiMenu::AppIconProvider::getPixmap(source, &size, QSize(width(), height()));
if (m_pixmap.isNull()) {
return;
}
m_isPureColor = isPixmapPureColor(m_pixmap);
}
void ThemeIcon::paint(QPainter *painter)
{
//默认居中绘制
QRect rect(0, 0, static_cast<int>(width()), static_cast<int>(height()));
QPixmap pixmap = m_pixmap;
painter->save();
//抗锯齿,平滑过渡
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
if (m_disabled) {
QPainter p(&pixmap);
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
p.setCompositionMode(QPainter::CompositionMode_SourceIn);
p.fillRect(pixmap.rect(), QGuiApplication::palette().color(QPalette::Disabled, QPalette::ButtonText));
} else if (m_highLight && (m_isPureColor || m_forceHighlight)) {
QPainter p(&pixmap);
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
p.setCompositionMode(QPainter::CompositionMode_SourceIn);
p.fillRect(pixmap.rect(), QGuiApplication::palette().color(QPalette::HighlightedText));
}
if (m_radius > 0) {
int radius = qMin(m_radius, qMin((rect.height() / 2), (rect.width() / 2)));
QPainterPath path;
path.addRoundedRect(rect, radius, radius);
painter->setClipPath(path);
}
painter->drawPixmap(rect, pixmap, pixmap.rect());
painter->restore();
}
QString ThemeIcon::getSource()
{
return m_source;
}
void ThemeIcon::setSource(const QString &source)
{
if (source.isEmpty()) {
qWarning() << "ThemeIcon: source is empty!";
return;
}
QString prefix("image://appicon/");
m_source = source;
if (m_source.startsWith(prefix)) {
m_source = m_source.mid(prefix.size());
}
loadPixmapBySource(m_source);
checkThemeName();
update();
}
QString ThemeIcon::getFallBack()
{
return m_fallback;
}
void ThemeIcon::setFallBack(const QString &fallback)
{
if (fallback.isEmpty()) {
qWarning() << "ThemeIcon: fallback is empty!";
return;
}
m_fallback = fallback;
if (m_pixmap.isNull()) {
setSource(fallback);
}
}
bool ThemeIcon::isHighLight() const
{
return m_highLight;
}
void ThemeIcon::setHighLight(bool highLight)
{
// qDebug() << "set high-light" << highLight;
m_highLight = highLight;
update();
}
bool ThemeIcon::isForceHighlight() const
{
return m_forceHighlight;
}
void ThemeIcon::setForceHighLight(bool force)
{
m_forceHighlight = force;
update();
}
bool ThemeIcon::disable() const
{
return m_disabled;
}
void ThemeIcon::setDisable(bool disable)
{
m_disabled = disable;
update();
}
//copy from ukui-platform-theme
bool ThemeIcon::isPixmapPureColor(const QPixmap &pixmap)
{
if (pixmap.isNull()) {
qWarning("pixmap is null!");
return false;
}
QImage image = pixmap.toImage();
QVector<QColor> vector;
int total_red = 0;
int total_green = 0;
int total_blue = 0;
bool pure = true;
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
if (image.pixelColor(x, y).alphaF() > 0.3) {
QColor color = image.pixelColor(x, y);
vector << color;
total_red += color.red();
total_green += color.green();
total_blue += color.blue();
int dr = qAbs(color.red() - symbolicColor.red());
int dg = qAbs(color.green() - symbolicColor.green());
int db = qAbs(color.blue() - symbolicColor.blue());
if (dr > COLOR_DIFFERENCE || dg > COLOR_DIFFERENCE || db > COLOR_DIFFERENCE)
pure = false;
}
}
}
if (pure)
return true;
qreal squareRoot_red = 0;
qreal squareRoot_green = 0;
qreal squareRoot_blue = 0;
qreal average_red = total_red / vector.count();
qreal average_green = total_green / vector.count();
qreal average_blue = total_blue / vector.count();
for (QColor color : vector) {
squareRoot_red += (color.red() - average_red) * (color.red() - average_red);
squareRoot_green += (color.green() - average_green) * (color.green() - average_green);
squareRoot_blue += (color.blue() - average_blue) * (color.blue() - average_blue);
}
qreal arithmeticSquareRoot_red = qSqrt(squareRoot_red / vector.count());
qreal arithmeticSquareRoot_green = qSqrt(squareRoot_green / vector.count());
qreal arithmeticSquareRoot_blue = qSqrt(squareRoot_blue / vector.count());
return arithmeticSquareRoot_red < 2.0 && arithmeticSquareRoot_green < 2.0 && arithmeticSquareRoot_blue < 2.0;
}
void ThemeIcon::onSizeChanged()
{
if ((width() != 0) && (height() != 0) && (!m_source.isEmpty())) {
loadPixmapBySource(m_source);
}
update();
}
int ThemeIcon::radius()
{
return m_radius;
}
void ThemeIcon::setRadius(int radius)
{
m_radius = radius < 0 ? 0 : radius;
}
bool ThemeIcon::autoHighLight() const
{
return m_autoHighlight;
}
void ThemeIcon::setAutoHighLight(bool autoHighlight)
{
m_autoHighlight = autoHighlight;
checkThemeName();
}

View File

@ -1,89 +0,0 @@
/*
* Copyright (C) 2023, 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 <https://www.gnu.org/licenses/>.
*
* Authors: hxf <hewenfei@kylinos.cn>
*
*/
#ifndef UKUI_MENU_THEME_ICON_H
#define UKUI_MENU_THEME_ICON_H
#include <QQuickPaintedItem>
#include <QIcon>
namespace UkuiMenu {
class ThemeIcon : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(bool disable READ disable WRITE setDisable)
Q_PROPERTY(bool autoHighLight READ autoHighLight WRITE setAutoHighLight)
Q_PROPERTY(bool highLight READ isHighLight WRITE setHighLight)
Q_PROPERTY(bool forceHighlight READ isForceHighlight WRITE setForceHighLight)
Q_PROPERTY(int radius READ radius WRITE setRadius)
Q_PROPERTY(QString source READ getSource WRITE setSource)
Q_PROPERTY(QString fallback READ getFallBack WRITE setFallBack)
public:
explicit ThemeIcon(QQuickItem *parent = nullptr);
void paint(QPainter *painter) override;
QString getSource();
void setSource(const QString &source);
QString getFallBack();
void setFallBack(const QString &fallback);
bool isHighLight() const;
void setHighLight(bool highLight);
bool autoHighLight() const;
void setAutoHighLight(bool autoHighlight);
bool isForceHighlight() const;
void setForceHighLight(bool force);
bool disable() const;
void setDisable(bool disable);
int radius();
void setRadius(int radius);
private:
void checkThemeName();
void loadPixmapBySource(const QString &source);
static bool isPixmapPureColor(const QPixmap &pixmap);
private Q_SLOTS:
void onSizeChanged();
private:
bool m_disabled = false;
bool m_highLight = false;
bool m_forceHighlight = false;
bool m_autoHighlight = true;
bool m_isPureColor = true;
int m_radius = 0;
QString m_source;
QString m_fallback;
QPixmap m_pixmap;
static QColor symbolicColor;
};
}
#endif // UKUI_MENU_THEME_ICON_H

View File

@ -22,6 +22,7 @@
#include "combined-list-model.h"
#include "app-category-model.h"
#include "recently-installed-model.h"
#include "event-track.h"
#include <QAction>
#include <QDebug>
@ -48,12 +49,20 @@ AppCategoryPlugin::AppCategoryPlugin(QObject *parent) : AppListPluginInterface(p
categoryAction->setChecked(true);
firstLatterAction->setChecked(false);
setTitle(categoryAction->text());
QMap<QString, QVariant> map;
map.insert(QStringLiteral("viewName"), QStringLiteral("category"));
EventTrack::instance()->sendClickEvent("switch_app_view", "AppView", map);
});
connect(firstLatterAction, &QAction::triggered, this, [=] {
categoryModel->setMode(AppCategoryModel::FirstLatter);
categoryAction->setChecked(false);
firstLatterAction->setChecked(true);
setTitle(firstLatterAction->text());
QMap<QString, QVariant> map;
map.insert(QStringLiteral("viewName"), QStringLiteral("letter"));
EventTrack::instance()->sendClickEvent("switch_app_view", "AppView", map);
});
m_actions.append(categoryAction);

View File

@ -26,7 +26,7 @@
#include <application-info.h>
#include <QDebug>
#define APP_ICON_PREFIX "image://appicon/"
#define APP_ICON_PREFIX "image://theme/"
namespace UkuiMenu {
@ -330,6 +330,7 @@ bool AppDatabaseWorkerPrivate::getApp(const QString &appid, DataEntity &app)
}
// ====== AppDatabaseInterface ====== //
// TODO: 多线程
AppDatabaseInterface::AppDatabaseInterface(QObject *parent) : QObject(parent), d(new AppDatabaseWorkerPrivate(this))
{

View File

@ -28,6 +28,12 @@
namespace UkuiMenu {
AppPageBackend *AppPageBackend::instance()
{
static AppPageBackend backend;
return &backend;
}
AppPageBackend::AppPageBackend(QObject *parent) : QObject(parent), m_appModel(new AppListModel(this))
{
auto searchPlugin = new AppSearchPlugin(this);

View File

@ -54,7 +54,7 @@ class AppPageBackend : public QObject
Q_PROPERTY(QAbstractItemModel *appModel READ appModel NOTIFY appModelChanged)
Q_PROPERTY(UkuiMenu::AppListPluginGroup::Group group READ group WRITE setGroup NOTIFY groupChanged)
public:
explicit AppPageBackend(QObject *parent = nullptr);
static AppPageBackend *instance();
// 开始菜单主要功能,显示应用列表
AppListModel *appModel() const;
@ -68,6 +68,7 @@ Q_SIGNALS:
void groupChanged();
private:
explicit AppPageBackend(QObject *parent = nullptr);
void switchGroup();
private:

View File

@ -104,7 +104,7 @@ void AppSearchPluginPrivate::run()
app.setType(DataType::Normal);
app.setId(result.getValue(UkuiSearch::SearchProperty::ApplicationDesktopPath).toString());
app.setName(result.getValue(UkuiSearch::SearchProperty::ApplicationLocalName).toString());
app.setIcon("image://appicon/" + result.getValue(UkuiSearch::SearchProperty::ApplicationIconName).toString());
app.setIcon("image://theme/" + result.getValue(UkuiSearch::SearchProperty::ApplicationIconName).toString());
Q_EMIT this->searchedOne(app);
}

View File

@ -162,6 +162,10 @@ void BasicAppModel::onAppDeleted(const QStringList &apps)
int BasicAppModel::indexOfApp(const QString &appid) const
{
if (appid.isEmpty()) {
return -1;
}
auto it = std::find_if(m_apps.constBegin(), m_apps.constEnd(), [&appid] (const DataEntity &app) {
return app.id() == appid;
});
@ -183,4 +187,15 @@ DataEntity BasicAppModel::appOfIndex(int row) const
return m_apps.at(row);
}
bool BasicAppModel::getAppById(const QString &appid, DataEntity &app) const
{
int idx = indexOfApp(appid);
if (idx < 0) {
return false;
}
app = m_apps.at(idx);
return true;
}
} // UkuiMenu

View File

@ -42,6 +42,7 @@ public:
const AppDatabaseInterface *databaseInterface() const;
DataEntity appOfIndex(int row) const;
int indexOfApp(const QString &appid) const;
bool getAppById(const QString &appid, DataEntity &app) const;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;

View File

@ -1,232 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: hxf <hewenfei@kylinos.cn>
*
*/
#include "theme-palette.h"
#include <QGuiApplication>
#include <QColor>
#include <QPalette>
using namespace UkuiMenu;
static ThemePalette *globalInstance = nullptr;
ThemePalette *ThemePalette::getInstance()
{
if (!globalInstance) {
globalInstance = new ThemePalette(nullptr);
}
return globalInstance;
}
ThemePalette::ThemePalette(QObject *parent) : QObject(parent)
{
initStyleSetting();
connect(qGuiApp, &QGuiApplication::paletteChanged, this, [=] {
Q_EMIT styleColorChanged();
});
connect(qGuiApp, &QGuiApplication::fontChanged, this, [=] {
Q_EMIT systemFontChanged();
});
}
QColor ThemePalette::paletteColor(Palette::ColorRole colorRole, Palette::ColorGroup colorGroup) const
{
switch (colorRole) {
default:
case Palette::Window:
return window(colorGroup);
case Palette::WindowText:
return windowText(colorGroup);
case Palette::Base:
return base(colorGroup);
case Palette::Text:
return text(colorGroup);
case Palette::BrightText:
return brightText(colorGroup);
case Palette::AlternateBase:
return alternateBase(colorGroup);
case Palette::Button:
return button(colorGroup);
case Palette::ButtonText:
return buttonText(colorGroup);
case Palette::Light:
return light(colorGroup);
case Palette::MidLight:
return midLight(colorGroup);
case Palette::Dark:
return dark(colorGroup);
case Palette::Mid:
return mid(colorGroup);
case Palette::Shadow:
return shadow(colorGroup);
case Palette::Highlight:
return highlight(colorGroup);
case Palette::HighlightedText:
return highlightedText(colorGroup);
}
}
QColor
ThemePalette::paletteColorWithCustomTransparency(Palette::ColorRole colorRole, Palette::ColorGroup colorGroup,
qreal alphaF) const
{
QColor color = paletteColor(colorRole, colorGroup);
color.setAlphaF(alphaF);
return color;
}
QColor
ThemePalette::paletteColorWithTransparency(Palette::ColorRole colorRole, Palette::ColorGroup colorGroup) const
{
QColor color = paletteColor(colorRole, colorGroup);
color.setAlphaF(m_transparency);
return color;
}
QColor ThemePalette::window(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Window);
}
QColor ThemePalette::windowText(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::WindowText);
}
QColor ThemePalette::text(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Text);
}
QColor ThemePalette::brightText(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::BrightText);
}
QColor ThemePalette::base(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Base);
}
QColor ThemePalette::alternateBase(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::AlternateBase);
}
QColor ThemePalette::button(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Button);
}
QColor ThemePalette::buttonText(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::ButtonText);
}
QColor ThemePalette::light(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Light);
}
QColor ThemePalette::midLight(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Midlight);
}
QColor ThemePalette::dark(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Dark);
}
QColor ThemePalette::mid(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Mid);
}
QColor ThemePalette::shadow(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Shadow);
}
QColor ThemePalette::highlight(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Highlight);
}
QColor ThemePalette::highlightedText(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::HighlightedText);
}
QColor ThemePalette::separator(Palette::ColorGroup colorGroup) const
{
return QGuiApplication::palette().color(switchColorGroup(colorGroup), QPalette::Window);
}
QPalette::ColorGroup ThemePalette::switchColorGroup(Palette::ColorGroup colorGroup)
{
switch (colorGroup) {
default:
case Palette::Active:
return QPalette::Active;
case Palette::Disabled:
return QPalette::Disabled;
case Palette::Inactive:
return QPalette::Inactive;
}
}
void ThemePalette::initStyleSetting()
{
GlobalSetting *setting = GlobalSetting::instance();
m_transparency = setting->get(GlobalSetting::Transparency).toReal();
m_fontSize = setting->get(GlobalSetting::SystemFontSize).toReal();
connect(setting, &GlobalSetting::styleChanged, this, &ThemePalette::styleChangedSlot);
connect(setting, &GlobalSetting::styleChanged, this, &ThemePalette::systemFontSizeChangedSlot);
}
void ThemePalette::styleChangedSlot(const GlobalSetting::Key& key)
{
if (key & GlobalSetting::Transparency) {
m_transparency = GlobalSetting::instance()->get(GlobalSetting::Transparency).toReal();
}
Q_EMIT styleColorChanged();
}
void ThemePalette::systemFontSizeChangedSlot(const GlobalSetting::Key &key)
{
if (key & GlobalSetting::SystemFontSize) {
m_fontSize = GlobalSetting::instance()->get(GlobalSetting::SystemFontSize).toReal();
}
Q_EMIT systemFontSizeChanged();
}
qreal ThemePalette::systemFontSize() const
{
return m_fontSize;
}
QFont ThemePalette::systemFont()
{
return QGuiApplication::font();
}

View File

@ -1,121 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* Authors: hxf <hewenfei@kylinos.cn>
*
*/
#ifndef UKUI_SIDEBAR_THEME_PALETTE_H
#define UKUI_SIDEBAR_THEME_PALETTE_H
#include <QObject>
#include <QPalette>
#include <QFont>
#include "settings.h"
namespace UkuiMenu {
class Palette {
Q_GADGET
public:
// Warning 警告: 谨防 qt版本更新后删除增加或者调整调色板的枚举值
enum ColorGroup {
Active, Disabled, Inactive
};
Q_ENUM(ColorGroup)
enum ColorRole {
Window, WindowText, Base, BrightText, Text, AlternateBase,
Button, ButtonText, Light, MidLight, Dark, Mid, Shadow,
Highlight, HighlightedText
};
Q_ENUM(ColorRole)
};
class ThemePalette : public QObject {
Q_OBJECT
public:
static ThemePalette *getInstance();
/**
*
* @param colorRole
* @return
*/
Q_INVOKABLE QColor
paletteColor(Palette::ColorRole colorRole, Palette::ColorGroup colorGroup = Palette::Active) const;
/**
*
* @param colorRole
* @return
*/
Q_INVOKABLE QColor
paletteColorWithCustomTransparency(Palette::ColorRole colorRole, Palette::ColorGroup colorGroup,
qreal alphaF) const;
/**
*
* @param colorRole
* @return
*/
Q_INVOKABLE QColor paletteColorWithTransparency(Palette::ColorRole colorRole,
Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor window(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor windowText(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor base(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor text(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor brightText(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor alternateBase(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor button(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor buttonText(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor light(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor midLight(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor dark(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor mid(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor shadow(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor highlight(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor highlightedText(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE QColor separator(Palette::ColorGroup colorGroup = Palette::Active) const;
Q_INVOKABLE qreal systemFontSize() const;
Q_INVOKABLE QFont systemFont();
Q_SIGNALS:
void styleColorChanged();
void systemFontChanged();
void systemFontSizeChanged();
private Q_SLOTS:
void styleChangedSlot(const GlobalSetting::Key& key);
void systemFontSizeChangedSlot(const GlobalSetting::Key& key);
private:
explicit ThemePalette(QObject *parent = nullptr);
static QPalette::ColorGroup switchColorGroup(Palette::ColorGroup colorGroup);
void initStyleSetting();
private:
qreal m_transparency = 1.0;
qreal m_fontSize = 12;
};
}
#endif //UKUI_SIDEBAR_THEME_PALETTE_H

View File

@ -20,16 +20,13 @@
#include "menu-dbus-service.h"
#include "settings.h"
#include "commons.h"
#include "theme-palette.h"
#include "app-icon-provider.h"
#include "menu-main-window.h"
#include "power-button.h"
#include "items/theme-icon.h"
#include "app-manager.h"
#include "context-menu-manager.h"
#include "event-track.h"
#include "sidebar-button-utils.h"
#include "extension/widget-model.h"
#include "widget-model.h"
#include "app-page-backend.h"
#include "app-group-model.h"
@ -66,7 +63,8 @@ void UkuiMenuApplication::registerQmlTypes()
qmlRegisterType<WidgetModel>(uri, versionMajor, versionMinor, "WidgetModel");
qmlRegisterType<AppGroupModel>(uri, versionMajor, versionMinor, "AppGroupModel");
qmlRegisterType<AppPageBackend>(uri, versionMajor, versionMinor, "AppPageBackend");
//qmlRegisterType<AppPageBackend>(uri, versionMajor, versionMinor, "AppPageBackend");
qmlRegisterSingletonInstance(uri, versionMajor, versionMinor, "AppPageBackend", AppPageBackend::instance());
qmlRegisterUncreatableType<AppListPluginGroup>(uri, versionMajor, versionMinor, "PluginGroup", "Use enums only.");
// commons
@ -78,11 +76,6 @@ void UkuiMenuApplication::registerQmlTypes()
qmlRegisterUncreatableType<UkuiMenu::MenuInfo>(uri, versionMajor, versionMinor, "MenuInfo", "Use enums only.");
// qmlRegisterUncreatableType<UkuiMenu::DataEntity>(uri, versionMajor, versionMinor, "DataEntity", "unknown");
// vis colors
qmlRegisterType<ThemeIcon>(uri, versionMajor, versionMinor, "ThemeIcon");
qRegisterMetaType<Palette::ColorRole>("Palette::ColorRole");
qRegisterMetaType<Palette::ColorGroup>("Palette::ColorGroup");
qmlRegisterUncreatableType<Palette>(uri, versionMajor, versionMinor, "Palette", "Use enums only.");
qmlRegisterUncreatableType<EventTrack>(uri, versionMajor, versionMinor, "EventTrack", "Attached only.");
}
@ -90,10 +83,8 @@ void UkuiMenuApplication::initQmlEngine()
{
m_engine = new QQmlEngine(this);
m_engine->addImportPath("qrc:/qml");
m_engine->addImageProvider("appicon", new AppIconProvider());
QQmlContext *context = m_engine->rootContext();
context->setContextProperty("themePalette", ThemePalette::getInstance());
context->setContextProperty("menuSetting", MenuSetting::instance());
context->setContextProperty("menuManager", ContextMenuManager::instance());
context->setContextProperty("appManager", AppManager::instance());
@ -124,7 +115,6 @@ void UkuiMenuApplication::loadMenuUI()
}
execCommand(Hide);
// DataProviderManager::instance()->toUpdate(false);
});
}
@ -173,8 +163,8 @@ void UkuiMenuApplication::execCommand(Command command)
default:
break;
}
// bool isShowed = m_mainWindow->isVisible();
// DataProviderManager::instance()->toUpdate(isShowed);
// TODO: 发送窗口显示隐藏信号到插件
}
UkuiMenuApplication::~UkuiMenuApplication()

View File

@ -19,7 +19,7 @@
#include <gio-unix-2.0/gio/gdesktopappinfo.h>
#include "app-manager.h"
#include "app-data-manager.h"
#include "basic-app-model.h"
#include <QDebug>
#include <QDBusReply>
@ -50,7 +50,6 @@ void AppManager::launchApp(const QString &desktopFilePath)
}
Q_EMIT request(UkuiMenuApplication::Hide);
AppDataManager::instance()->appLaunch(desktopFilePath);
QDBusMessage message = QDBusMessage::createMethodCall(KYLIN_APP_MANAGER_NAME, KYLIN_APP_MANAGER_PATH, KYLIN_APP_MANAGER_INTERFACE, "LaunchApp");
message << desktopFilePath;
@ -72,6 +71,8 @@ void AppManager::launchApp(const QString &desktopFilePath)
}
self->deleteLater();
});
BasicAppModel::instance()->databaseInterface()->updateApLaunchedState(desktopFilePath, true);
}
void AppManager::launchBinaryApp(const QString &app, const QString &args)
@ -113,13 +114,9 @@ void AppManager::launchAppWithArguments(const QString &desktopFile, const QStrin
});
}
void AppManager::changeFavoriteState(const QString &desktopFilePath, bool isFavorite)
void AppManager::changeFavoriteState(const QString &appid, bool isFavorite)
{
if (isFavorite) {
Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(desktopFilePath, 0);
} else {
Q_EMIT AppDataManager::instance()->fixToFavoriteSignal(desktopFilePath, 1);
}
BasicAppModel::instance()->databaseInterface()->fixAppToFavorite(appid, isFavorite ? 1 : 0);
}
QString AppManager::parseDesktopFile(const QString &desktopFilePath)

View File

@ -36,7 +36,7 @@ public:
Q_INVOKABLE void launchApp(const QString &desktopFilePath);
Q_INVOKABLE void launchBinaryApp(const QString &app, const QString &args = QString());
Q_INVOKABLE void launchAppWithArguments(const QString &desktopFile, const QStringList &args, const QString &applicationName);
Q_INVOKABLE void changeFavoriteState(const QString &desktopFilePath, bool isFavorite);
Q_INVOKABLE void changeFavoriteState(const QString &appid, bool isFavorite);
private:
explicit AppManager(QObject *parent = nullptr);

View File

@ -57,7 +57,6 @@ struct MotifWmHints {
void WindowModule::defineModule(const char *uri, int versionMajor, int versionMinor)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
qmlRegisterRevision<QWindow, 3>(uri, versionMajor, versionMinor);
qmlRegisterRevision<QQuickWindow, 2>(uri, versionMajor, versionMinor);
@ -73,8 +72,6 @@ void WindowModule::defineModule(const char *uri, int versionMajor, int versionMi
qmlRegisterRevision<QWindow, 1>(uri, versionMajor, versionMinor);
#endif
#endif
#endif
qmlRegisterType<MenuMainWindow>(uri, versionMajor, versionMinor, "MenuMainWindow");
#endif
}
@ -138,84 +135,7 @@ void WindowHelper::windowBlur(QWindow *window, bool enable, const QRegion &regio
KWindowEffects::enableBlurBehind(window->winId(), enable, region);
}
//======MenuMainWindow======//
MenuMainWindow::MenuMainWindow(QWindow *parent) : QQuickWindow(parent), m_geometryHelper(new WindowGeometryHelper(this))
{
init();
connect(m_geometryHelper, &WindowGeometryHelper::geometryChanged, this, [this] {
QEvent event(QEvent::Move);
QCoreApplication::sendEvent(this, &event);
});
}
void MenuMainWindow::init()
{
setTitle(QCoreApplication::applicationName());
setColor("transparent");
setFlags(Qt::FramelessWindowHint);
WindowHelper::setWindowAttribute(this);
}
void MenuMainWindow::exposeEvent(QExposeEvent *event)
{
QQuickWindow::exposeEvent(event);
}
void MenuMainWindow::showEvent(QShowEvent *event)
{
QQuickWindow::showEvent(event);
}
void MenuMainWindow::focusOutEvent(QFocusEvent *event)
{
QQuickWindow::focusOutEvent(event);
}
bool MenuMainWindow::event(QEvent *event)
{
if (event->type() == QEvent::Move || event->type() == QEvent::Resize) {
updateGeometry();
return true;
}
return QQuickWindow::event(event);
}
bool MenuMainWindow::isFullScreen()
{
return m_isFullScreen;
}
void MenuMainWindow::setFullScreen(bool isFullScreen)
{
if (m_isFullScreen == isFullScreen) {
return;
}
m_isFullScreen = isFullScreen;
QEvent event(QEvent::Resize);
QCoreApplication::sendEvent(this, &event);
Q_EMIT fullScreenChanged();
}
void MenuMainWindow::updateGeometry()
{
QRect rect = m_isFullScreen ? m_geometryHelper->fullScreenGeometry() : m_geometryHelper->normalGeometry();
if (rect == geometry()) {
return;
}
WindowHelper::setWindowGeometry(this, rect);
QQuickItem *item = contentItem();
if (item) {
item->setPosition({0, 0});
item->setSize(size());
}
}
// ====== WindowGeometryHelper ====== //
WindowGeometryHelper::WindowGeometryHelper(QObject *parent) : QObject(parent)
{
initPanelSetting();

View File

@ -73,35 +73,6 @@ private:
QRect m_fullScreenGeometry;
};
class MenuMainWindow : public QQuickWindow
{
Q_OBJECT
Q_PROPERTY(bool isFullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
public:
explicit MenuMainWindow(QWindow *parent = nullptr);
bool isFullScreen();
void setFullScreen(bool isFullScreen);
Q_SIGNALS:
void fullScreenChanged();
protected:
void exposeEvent(QExposeEvent *event) override;
void showEvent(QShowEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
bool event(QEvent *event) override;
private:
void init();
void updateGeometry();
private:
bool m_isFullScreen{false};
WindowGeometryHelper *m_geometryHelper{nullptr};
};
class MenuWindow : public QQuickView
{
Q_OBJECT