From 855315c9eed1cd6c6ca0f65195f5a7585a33050b Mon Sep 17 00:00:00 2001 From: qiqi Date: Wed, 12 Apr 2023 15:22:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=B0=8F=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A1=86=E7=84=A6=E7=82=B9=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=EF=BC=9B=E5=88=A0=E9=99=A4color-helper=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 - qml/AppUI/AppPageHeader.qml | 18 ++++++- qml/AppUI/SearchInputBar.qml | 4 ++ src/uiconfig/color-helper.cpp | 94 ----------------------------------- src/uiconfig/color-helper.h | 72 --------------------------- src/ukui-menu-application.cpp | 4 -- 6 files changed, 21 insertions(+), 172 deletions(-) delete mode 100644 src/uiconfig/color-helper.cpp delete mode 100644 src/uiconfig/color-helper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 15e043a..90f175a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,6 @@ set(SOURCE_FILES src/model/model-manager.cpp src/model/model-manager.h src/model/folder-model.cpp src/model/folder-model.h src/settings/settings.cpp src/settings/settings.h - src/uiconfig/color-helper.cpp src/uiconfig/color-helper.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/data-provider-plugin-iface.h diff --git a/qml/AppUI/AppPageHeader.qml b/qml/AppUI/AppPageHeader.qml index 986c28f..f93d1d6 100644 --- a/qml/AppUI/AppPageHeader.qml +++ b/qml/AppUI/AppPageHeader.qml @@ -67,7 +67,12 @@ Item { Transition { to: "search" SequentialAnimation { - ScriptAction { script: searchBar.visible = true } + ScriptAction { + script: { + searchBar.visible = true; + searchInputBar.textInputFocus(); + } + } NumberAnimation { easing.type: Easing.InOutQuad; properties: "scale,y"; duration: 300} } } @@ -76,6 +81,17 @@ Item { Item { id: searchBar width: parent.width; height: 30 + Component.onCompleted: { + visible = false; + mainWindow.visibleChanged.connect(searchBarHide); + } + Component.onDestruction: mainWindow.visibleChanged.disconnect(searchBarHide); + + function searchBarHide() { + if (!mainWindow.visible) { + root.state = "normal" + } + } RowLayout { anchors.fill: parent diff --git a/qml/AppUI/SearchInputBar.qml b/qml/AppUI/SearchInputBar.qml index 59d2381..9c1a6f2 100644 --- a/qml/AppUI/SearchInputBar.qml +++ b/qml/AppUI/SearchInputBar.qml @@ -34,6 +34,10 @@ AppControls2.StyleBackground { borderAlpha: textInput.activeFocus ? 1 : 0.1 borderColor: textInput.activeFocus ? Palette.Highlight : Palette.Base + function textInputFocus() { + textInput.forceActiveFocus(); + } + Item { id: defaultSearch width: searchIcon.width + defaultText.contentWidth; height: parent.height diff --git a/src/uiconfig/color-helper.cpp b/src/uiconfig/color-helper.cpp deleted file mode 100644 index 3acc20d..0000000 --- a/src/uiconfig/color-helper.cpp +++ /dev/null @@ -1,94 +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 . - * - */ - -#include "color-helper.h" -#include "settings.h" - -#include -#include - -namespace UkuiMenu { - -ColorHelper *ColorHelper::instance() -{ - static ColorHelper colorHelper(nullptr); - return &colorHelper; -} - -ColorHelper::ColorHelper(QObject *parent) : QObject(parent) -{ - m_colors.insert(ColorHelper::Light, {"#000000"}); - m_colors.insert(ColorHelper::Gray, {"#10171D"}); - m_colors.insert(ColorHelper::Dark, {"#FFFFFF"}); - initStyleMonitor(); -} - -QColor ColorHelper::getColor(ColorHelper::Role role) -{ - QMutexLocker locker(&m_mutex); - return m_colors.value(role, {"#000000"}); -} - -QColor ColorHelper::colorWithTheme(ColorHelper::Role role) -{ - QColor color = getColor(role); - color.setAlphaF(m_transparency); - return color; -} - -QColor ColorHelper::colorWithAlpha(ColorHelper::Role role, qreal alpha) -{ - QColor color = getColor(role); - color.setAlphaF(alpha); - return color; -} - -void ColorHelper::initStyleMonitor() -{ - updateStyle(); - connect(GlobalSetting::instance(), &GlobalSetting::styleChanged, this , [this] (const GlobalSetting::Key& key) { - if (key & GlobalSetting::StyleName || key & GlobalSetting::Transparency) { - updateStyle(); - } - }); -} - -void ColorHelper::updateStyle() -{ - 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(); -} - -} // UkuiMenu diff --git a/src/uiconfig/color-helper.h b/src/uiconfig/color-helper.h deleted file mode 100644 index 6064430..0000000 --- a/src/uiconfig/color-helper.h +++ /dev/null @@ -1,72 +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 . - * - */ - -#ifndef UKUI_MENU_COLOR_HELPER_H -#define UKUI_MENU_COLOR_HELPER_H - -#include -#include -#include -#include -#include - -namespace UkuiMenu { - -class ColorHelper : public QObject -{ - Q_OBJECT -public: - enum Role { - Base = 0, - HighLight, - Window, - Light, - Gray, - Dark - }; - Q_ENUM(Role) - - static ColorHelper *instance(); - ColorHelper() = delete; - ColorHelper(const ColorHelper& obj) = delete; - ColorHelper(ColorHelper&& obj) = delete; - - 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(); - -private Q_SLOTS: - void updateStyle(); - -private: - explicit ColorHelper(QObject *parent = nullptr); - void initStyleMonitor(); - -private: - QMutex m_mutex; - QMap m_colors; - bool m_isDarkStyle{false}; - qreal m_transparency{1.0}; -}; - -} // UkuiMenu - -#endif //UKUI_MENU_COLOR_HELPER_H diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp index 3c6f495..63e2718 100644 --- a/src/ukui-menu-application.cpp +++ b/src/ukui-menu-application.cpp @@ -20,7 +20,6 @@ #include "settings.h" #include "commons.h" #include "model-manager.h" -#include "color-helper.h" #include "theme-palette.h" #include "app-icon-provider.h" #include "menu-main-window.h" @@ -73,9 +72,7 @@ void UkuiMenuApplication::registerQmlTypes() qmlRegisterType(uri, versionMajor, versionMinor, "ThemeIcon"); 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() @@ -85,7 +82,6 @@ void UkuiMenuApplication::initQmlEngine() m_engine->addImageProvider("appicon", new AppIconProvider()); QQmlContext *context = m_engine->rootContext(); - context->setContextProperty("colorHelper", ColorHelper::instance()); context->setContextProperty("themePalette", ThemePalette::getInstance()); context->setContextProperty("menuSetting", MenuSetting::instance()); context->setContextProperty("modelManager", ModelManager::instance());