Modify the trigger logic of app widget.

This commit is contained in:
JunjieBai 2023-01-03 09:20:54 +08:00 committed by iaom
parent 7624347cb8
commit 4143c4ea5b
4 changed files with 57 additions and 29 deletions

View File

@ -90,9 +90,12 @@ MainWindow::MainWindow(QWidget *parent) :
m_appWidgetPlugin = new AppWidgetPlugin; 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->bootOptionsFilter("-s");
this->setText(keyword);
}); });
connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow); connect(ActionTransmiter::getInstance(), &ActionTransmiter::hideUIAction, this, &MainWindow::tryHideMainwindow);
} }

View File

@ -4,7 +4,7 @@ import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import org.ukui.appwidget 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 { AppWidget {
visible: true visible: true
@ -41,6 +41,14 @@ AppWidget {
onDatavalueChanged: updateSearchBarColor(); onDatavalueChanged: updateSearchBarColor();
onUserStatusChangedSignal: {
if (status === "Normal") {
mouseArea.enabled = true;
} else if (status === "Editable") {
mouseArea.enabled = false;
}
}
Rectangle { Rectangle {
id:searchBar id:searchBar
anchors.centerIn: parent anchors.centerIn: parent
@ -48,10 +56,23 @@ AppWidget {
height: 64 * scaling height: 64 * scaling
radius: searchBar.height / 2 radius: searchBar.height / 2
MouseArea {
id: mouseArea
anchors.fill: parent;
propagateComposedEvents: true;
onClicked: {
window.qmldefineeventchangedsignal("clicked", "search", "");
}
onPressAndHold: {
mouse.accepted = false;
}
}
RowLayout { RowLayout {
id: layout id: layout
anchors.fill: parent anchors.fill: parent;
spacing: 0 spacing: 0;
Image { Image {
id: image_search id: image_search
@ -60,36 +81,36 @@ AppWidget {
Layout.preferredWidth: 32 * scaling; Layout.preferredWidth: 32 * scaling;
Layout.preferredHeight: 32 * scaling; Layout.preferredHeight: 32 * scaling;
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter;
source: "file:///usr/share/appwidget/search/ukui-search.svg" source: "file:///usr/share/appwidget/search/ukui-search.svg";
} }
Item { Item {
clip: true; clip: true;
Layout.fillWidth: true Layout.fillWidth: true;
Layout.fillHeight: true; Layout.fillHeight: true;
Layout.rightMargin: 32 * scaling; Layout.rightMargin: 32 * scaling;
TextInput { Label {
id: searchtext id: searchtext
anchors.fill: parent; anchors.fill: parent;
Keys.enabled: true // Keys.enabled: true;
Keys.onEnterPressed: { // Keys.onEnterPressed: {
window.qmldefineeventchangedsignal("enter", "search", searchtext.text); // window.qmldefineeventchangedsignal("enter", "search", searchtext.text);
searchtext.remove(0, searchtext.length); // searchtext.remove(0, searchtext.length);
} // }
Keys.onReturnPressed: { // Keys.onReturnPressed: {
window.qmldefineeventchangedsignal("return", "search", searchtext.text); // window.qmldefineeventchangedsignal("return", "search", searchtext.text);
searchtext.remove(0, searchtext.length); // searchtext.remove(0, searchtext.length);
} // }
focus: true // focus: true;
color: StylePrivate.StyleHelper.windowtextcolorrole // color: StylePrivate.StyleHelper.windowtextcolorrole;
maximumLength: 100 * scaling // maximumLength: 100 * scaling;
selectByMouse: true // selectByMouse: true;
verticalAlignment: Qt.AlignVCenter // verticalAlignment: Qt.AlignVCenter;
font.pixelSize: 21 * scaling // font.pixelSize: 21 * scaling;
property string placeholderText: /*qsTr("search")*/"全局搜索" property string placeholderText: /*qsTr("search")*/"全局搜索"
@ -98,8 +119,8 @@ AppWidget {
text: searchtext.placeholderText text: searchtext.placeholderText
font.pixelSize: 21 * scaling font.pixelSize: 21 * scaling
visible: !searchtext.text visible: !searchtext.text;
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter;
} }
} }
} }

View File

@ -44,9 +44,12 @@ AppWidgetPlugin::AppWidgetPlugin(QString providername, QObject *parent) : KAppWi
void AppWidgetPlugin::appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value) void AppWidgetPlugin::appWidgetRecevie(const QString &eventname, const QString &widgetname, const QDBusVariant &value)
{ {
qDebug() << widgetname << value.variant(); qDebug() << widgetname << value.variant();
if (eventname == "enter" or eventname == "return") { // if (eventname == "enter" or eventname == "return") {
QString keyword = value.variant().toString(); // QString keyword = value.variant().toString();
Q_EMIT this->startSearch(keyword); // Q_EMIT this->startSearch(keyword);
// } else
if (eventname == "clicked") {
Q_EMIT this->start();
} else { } else {
qWarning() << "event:" << eventname << "has no trigger now."; qWarning() << "event:" << eventname << "has no trigger now.";
} }

View File

@ -27,6 +27,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void startSearch(QString); void startSearch(QString);
void start();
private: private:
QDBusInterface* m_interface = nullptr; QDBusInterface* m_interface = nullptr;