From 5f4e172c0d830f4282e8f4c6fbcd700e0b31adaf Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Tue, 3 Jan 2023 09:20:54 +0800 Subject: [PATCH] Modify the trigger logic of app widget. --- frontend/mainwindow.cpp | 7 +- .../provider/data/search.qml | 69 ++++++++++++------- libsearch/search-app-widget-plugin/search.cpp | 9 ++- libsearch/search-app-widget-plugin/search.h | 1 + 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 832da4a..c4ba6f5 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -90,9 +90,12 @@ MainWindow::MainWindow(QWidget *parent) : m_appWidgetPlugin = new AppWidgetPlugin; - connect(m_appWidgetPlugin, &AppWidgetPlugin::startSearch, this, [ & ] (QString keyword){ +// connect(m_appWidgetPlugin, &AppWidgetPlugin::startSearch, this, [ & ] (QString keyword){ +// this->bootOptionsFilter("-s"); +// this->setText(keyword); +// }); + connect(m_appWidgetPlugin, &AppWidgetPlugin::start, this, [&] { this->bootOptionsFilter("-s"); - this->setText(keyword); }); connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow); } diff --git a/libsearch/search-app-widget-plugin/provider/data/search.qml b/libsearch/search-app-widget-plugin/provider/data/search.qml index 7b9bc02..53acfe0 100755 --- a/libsearch/search-app-widget-plugin/provider/data/search.qml +++ b/libsearch/search-app-widget-plugin/provider/data/search.qml @@ -4,7 +4,7 @@ import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import org.ukui.appwidget 1.0 -import org.ukui.qqc2style.private 1.0 as StylePrivate +//import org.ukui.qqc2style.private 1.0 as StylePrivate AppWidget { visible: true @@ -41,6 +41,14 @@ AppWidget { onDatavalueChanged: updateSearchBarColor(); + onUserStatusChangedSignal: { + if (status === "Normal") { + mouseArea.enabled = true; + } else if (status === "Editable") { + mouseArea.enabled = false; + } + } + Rectangle { id:searchBar anchors.centerIn: parent @@ -48,10 +56,23 @@ AppWidget { height: 64 * scaling radius: searchBar.height / 2 + MouseArea { + id: mouseArea + anchors.fill: parent; + propagateComposedEvents: true; + + onClicked: { + window.qmldefineeventchangedsignal("clicked", "search", ""); + } + onPressAndHold: { + mouse.accepted = false; + } + } + RowLayout { id: layout - anchors.fill: parent - spacing: 0 + anchors.fill: parent; + spacing: 0; Image { id: image_search @@ -60,36 +81,36 @@ AppWidget { Layout.preferredWidth: 32 * scaling; Layout.preferredHeight: 32 * scaling; - Layout.alignment: Qt.AlignVCenter - source: "file:///usr/share/appwidget/search/ukui-search.svg" + Layout.alignment: Qt.AlignVCenter; + source: "file:///usr/share/appwidget/search/ukui-search.svg"; } Item { clip: true; - Layout.fillWidth: true + Layout.fillWidth: true; Layout.fillHeight: true; Layout.rightMargin: 32 * scaling; - TextInput { + Label { id: searchtext anchors.fill: parent; - Keys.enabled: true - Keys.onEnterPressed: { - window.qmldefineeventchangedsignal("enter", "search", searchtext.text); - searchtext.remove(0, searchtext.length); - } - Keys.onReturnPressed: { - window.qmldefineeventchangedsignal("return", "search", searchtext.text); - searchtext.remove(0, searchtext.length); - } +// Keys.enabled: true; +// Keys.onEnterPressed: { +// window.qmldefineeventchangedsignal("enter", "search", searchtext.text); +// searchtext.remove(0, searchtext.length); +// } +// Keys.onReturnPressed: { +// window.qmldefineeventchangedsignal("return", "search", searchtext.text); +// searchtext.remove(0, searchtext.length); +// } - focus: true - color: StylePrivate.StyleHelper.windowtextcolorrole - maximumLength: 100 * scaling - selectByMouse: true - verticalAlignment: Qt.AlignVCenter - font.pixelSize: 21 * scaling +// focus: true; +// color: StylePrivate.StyleHelper.windowtextcolorrole; +// maximumLength: 100 * scaling; +// selectByMouse: true; +// verticalAlignment: Qt.AlignVCenter; +// font.pixelSize: 21 * scaling; property string placeholderText: /*qsTr("search")*/"全局搜索" @@ -98,8 +119,8 @@ AppWidget { text: searchtext.placeholderText font.pixelSize: 21 * scaling - visible: !searchtext.text - anchors.verticalCenter: parent.verticalCenter + visible: !searchtext.text; + anchors.verticalCenter: parent.verticalCenter; } } } diff --git a/libsearch/search-app-widget-plugin/search.cpp b/libsearch/search-app-widget-plugin/search.cpp index 453fa60..503f453 100644 --- a/libsearch/search-app-widget-plugin/search.cpp +++ b/libsearch/search-app-widget-plugin/search.cpp @@ -44,9 +44,12 @@ AppWidgetPlugin::AppWidgetPlugin(QString providername, QObject *parent) : KAppWi void AppWidgetPlugin::appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value) { qDebug() << widgetname << value.variant(); - if (eventname == "enter" or eventname == "return") { - QString keyword = value.variant().toString(); - Q_EMIT this->startSearch(keyword); +// if (eventname == "enter" or eventname == "return") { +// QString keyword = value.variant().toString(); +// Q_EMIT this->startSearch(keyword); +// } else + if (eventname == "clicked") { + Q_EMIT this->start(); } else { qWarning() << "event:" << eventname << "has no trigger now."; } diff --git a/libsearch/search-app-widget-plugin/search.h b/libsearch/search-app-widget-plugin/search.h index c6d0bdd..198b95a 100644 --- a/libsearch/search-app-widget-plugin/search.h +++ b/libsearch/search-app-widget-plugin/search.h @@ -27,6 +27,7 @@ public: Q_SIGNALS: void startSearch(QString); + void start(); private: QDBusInterface* m_interface = nullptr;