完善小窗口搜索框焦点显示;删除color-helper文件

This commit is contained in:
qiqi 2023-04-12 15:22:57 +08:00 committed by hewenfei
parent 40acf2fed9
commit 1b755f6515
6 changed files with 21 additions and 172 deletions

View File

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

View File

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

View File

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

View File

@ -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 <https://www.gnu.org/licenses/>.
*
*/
#include "color-helper.h"
#include "settings.h"
#include <QDebug>
#include <QApplication>
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

View File

@ -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 <https://www.gnu.org/licenses/>.
*
*/
#ifndef UKUI_MENU_COLOR_HELPER_H
#define UKUI_MENU_COLOR_HELPER_H
#include <QObject>
#include <QColor>
#include <QMap>
#include <QMutex>
#include <QMutexLocker>
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<ColorHelper::Role, QColor> m_colors;
bool m_isDarkStyle{false};
qreal m_transparency{1.0};
};
} // UkuiMenu
#endif //UKUI_MENU_COLOR_HELPER_H

View File

@ -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<ThemeIcon>(uri, versionMajor, versionMinor, "ThemeIcon");
qRegisterMetaType<Palette::ColorRole>("Palette::ColorRole");
qRegisterMetaType<Palette::ColorGroup>("Palette::ColorGroup");
qRegisterMetaType<ColorHelper::Role>("ColorHelper::Role");
qmlRegisterUncreatableType<Palette>(uri, versionMajor, versionMinor, "Palette", "Use enums only.");
qmlRegisterUncreatableType<ColorHelper>(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());