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 7babaf3147
commit 5f4e172c0d
4 changed files with 57 additions and 29 deletions

View File

@ -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);
}

View File

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

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)
{
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.";
}

View File

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