From b354f9fdc70cff07ab2d6e319ad99dbd6f1fe079 Mon Sep 17 00:00:00 2001
From: iaom <18504285112@163.com>
Date: Wed, 21 Jul 2021 17:01:34 +0800
Subject: [PATCH] Update search lineedit.
---
frontend/control/control.pri | 4 +-
frontend/control/input-box.cpp | 265 ------------------
frontend/control/search-line-edit.cpp | 191 +++++++++++++
.../{input-box.h => search-line-edit.h} | 115 +++-----
frontend/control/stacked-widget.cpp | 6 +-
frontend/control/stacked-widget.h | 2 +-
frontend/main.cpp | 3 -
frontend/mainwindow.cpp | 126 +++------
frontend/mainwindow.h | 81 +++---
frontend/model/search-result-manager.cpp | 2 +-
frontend/res/icons/system-search.symbolic.png | Bin 0 -> 498 bytes
frontend/resource.qrc | 1 +
.../libukui-search/libukui-search_zh_CN.ts | 60 ++--
translations/ukui-search/bo.ts | 13 +-
translations/ukui-search/tr.ts | 18 +-
translations/ukui-search/zh_CN.ts | 24 +-
16 files changed, 374 insertions(+), 537 deletions(-)
delete mode 100644 frontend/control/input-box.cpp
create mode 100644 frontend/control/search-line-edit.cpp
rename frontend/control/{input-box.h => search-line-edit.h} (51%)
create mode 100644 frontend/res/icons/system-search.symbolic.png
diff --git a/frontend/control/control.pri b/frontend/control/control.pri
index c9c9820..230392d 100644
--- a/frontend/control/control.pri
+++ b/frontend/control/control.pri
@@ -5,13 +5,13 @@ include(list-labels/list-labels.pri)
INCLUDEPATH += $$PWD
HEADERS += \
+ $$PWD/search-line-edit.h \
$$PWD/settings-widget.h \
$$PWD/create-index-ask-dialog.h \
$$PWD/stacked-widget.h \
- $$PWD/input-box.h \
SOURCES += \
+ $$PWD/search-line-edit.cpp \
$$PWD/settings-widget.cpp \
$$PWD/create-index-ask-dialog.cpp \
$$PWD/stacked-widget.cpp \
- $$PWD/input-box.cpp \
diff --git a/frontend/control/input-box.cpp b/frontend/control/input-box.cpp
deleted file mode 100644
index 5b87dc5..0000000
--- a/frontend/control/input-box.cpp
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- *
- * Copyright (C) 2020, 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 .
- *
- * Authors: zhangjiaping
- *
- */
-#include "input-box.h"
-
-using namespace Zeeker;
-/**
- * @brief ukui-search顶部搜索界面
- */
-SeachBarWidget::SeachBarWidget(QWidget *parent): QWidget(parent) {
-}
-
-SeachBarWidget::~SeachBarWidget() {
-}
-
-/**
- * @brief ukui-search 顶部搜索框的ui,包含设置按钮
- */
-SeachBar::SeachBar() {
- setFocusPolicy(Qt::NoFocus);
-}
-
-SearchBarWidgetLayout::SearchBarWidgetLayout() {
-}
-
-SearchBarWidgetLayout::~SearchBarWidgetLayout() {
-}
-
-SeachBar::~SeachBar() {
-}
-
-/**
- * @brief 顶部搜索框所在界面的布局
- */
-SearchBarHLayout::SearchBarHLayout(QWidget *parent): QHBoxLayout(parent) {
- initUI();
-
- m_timer = new QTimer;
- connect(m_timer, &QTimer::timeout, this, [ = ]() {
- m_timer->stop();
- Q_EMIT this->requestSearchKeyword(m_queryLineEdit->text());
- });
- connect(m_queryLineEdit, &SearchLineEdit::textChanged, this, [ = ](QString text) {
- if(m_isEmpty) {
- m_isEmpty = false;
- Q_EMIT this->requestSearchKeyword(text);
- } else {
- if(text == "") {
- m_isEmpty = true;
- m_timer->stop();
- Q_EMIT this->requestSearchKeyword(m_queryLineEdit->text());
- return;
- }
- m_timer->stop();
- m_timer->start(0.1 * 1000);
- }
- });
-}
-
-SearchBarHLayout::~SearchBarHLayout() {
- if(m_timer) {
- delete m_timer;
- m_timer = NULL;
- }
- if(m_queryLineEdit) {
- delete m_queryLineEdit;
- m_queryLineEdit = nullptr;
- }
-}
-
-/**
- * @brief 初始化ui
- */
-void SearchBarHLayout::initUI() {
- m_queryLineEdit = new SearchLineEdit();
- m_queryLineEdit->installEventFilter(this);
- m_queryLineEdit->setTextMargins(30, 1, 0, 1);
- this->setContentsMargins(0, 0, 0, 0);
- this->setAlignment(m_queryLineEdit, Qt::AlignCenter);
- this->addWidget(m_queryLineEdit);
-
- m_queryWidget = new QWidget(m_queryLineEdit);
- m_queryWidget->setFocusPolicy(Qt::NoFocus);
-
- QHBoxLayout* queryWidLayout = new QHBoxLayout;
- queryWidLayout->setContentsMargins(8, 4, 0, 0);
- queryWidLayout->setAlignment(Qt::AlignJustify);
- queryWidLayout->setSpacing(5);
- m_queryWidget->setLayout(queryWidLayout);
-
-
- QPixmap pixmap(QIcon::fromTheme("system-search-symbolic").pixmap(QSize(20, 20)));
- m_queryIcon = new QLabel;
- m_queryIcon->setFixedSize(pixmap.size());
- m_queryIcon->setPixmap(pixmap);
-
- m_queryText = new QLabel;
- m_queryText->setText(tr("Search"));
- m_queryText->setEnabled(false);
- m_queryText->setContentsMargins(0, 0, 0, 4);
- m_queryText->adjustSize();
-
- queryWidLayout->addWidget(m_queryIcon);
- queryWidLayout->addWidget(m_queryText);
- m_queryWidget->setGeometry(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 15)) / 2 - 10, 0,
- m_queryIcon->width() + m_queryText->width() + 20, 35)); //设置图标初始位置
-
- m_animation = new QPropertyAnimation(m_queryWidget, "geometry");
- m_animation->setDuration(100); //动画时长
- connect(m_animation, &QPropertyAnimation::finished, this, [ = ]() {
- if(m_isSearching) {
- m_queryWidget->layout()->removeWidget(m_queryText);
- m_queryText->setParent(nullptr);
- } else {
- m_queryWidget->layout()->addWidget(m_queryText);
- }
- });
-}
-
-void SearchBarHLayout::effectiveSearchRecord() {
- m_queryLineEdit->record();
-}
-
-void SearchBarHLayout::focusIn() {
- m_queryLineEdit->setFocus();
-}
-
-void SearchBarHLayout::focusOut() {
- m_queryLineEdit->clearFocus();
- if(! m_queryText->parent()) {
- m_queryWidget->layout()->addWidget(m_queryText);
- m_queryText->adjustSize();
- }
- m_queryWidget->setGeometry(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 15)) / 2 - 10, 0,
- m_queryIcon->width() + m_queryText->width() + 20, 35)); //使图标回到初始位置
-}
-
-void SearchBarHLayout::reSearch()
-{
- Q_EMIT this->requestSearchKeyword(m_queryLineEdit->text());
-}
-
-void SearchBarHLayout::clearText() {
- m_queryLineEdit->setText("");
-}
-
-QString SearchBarHLayout::text() {
- return m_queryLineEdit->text();
-}
-
-bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event) {
- if(watched == m_queryLineEdit) {
- if(event->type() == QEvent::FocusIn) {
- if(m_queryLineEdit->text().isEmpty()) {
- m_animation->stop();
- m_animation->setStartValue(m_queryWidget->geometry());
- m_animation->setEndValue(QRect(0, 0, m_queryIcon->width() + 10, 35));
- m_animation->setEasingCurve(QEasingCurve::OutQuad);
- m_animation->start();
- }
- m_isSearching = true;
- } else if(event->type() == QEvent::FocusOut) {
- if(m_queryLineEdit->text().isEmpty()) {
- if(m_isSearching) {
- m_animation->stop();
- m_queryText->adjustSize();
- m_animation->setStartValue(QRect(0, 0, m_queryIcon->width() + 5, 35));
- m_animation->setEndValue(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 10)) / 2, 0,
- m_queryIcon->width() + m_queryText->width() + 20, 35));
- m_animation->setEasingCurve(QEasingCurve::InQuad);
- m_animation->start();
- }
- }
- m_isSearching = false;
- }
- }
- return QObject::eventFilter(watched, event);
-}
-
-/**
- * @brief UKuiSearchLineEdit 全局搜索的输入框
- */
-SearchLineEdit::SearchLineEdit() {
- this->setFocusPolicy(Qt::ClickFocus);
- this->installEventFilter(this);
-// this->setContextMenuPolicy(Qt::NoContextMenu);
- this->setMaxLength(100);
-
- m_completer = new QCompleter(this);
- m_model = new QStringListModel(this);
- m_model->setStringList(GlobalSettings::getInstance()->getSearchRecord());
- m_completer->setModel(m_model);
- m_completer->setCompletionMode(QCompleter::InlineCompletion);
- //TODO make a popup window to show the completer.
-// QListView *popView = new QListView(this);
-// popView->setFocusPolicy(Qt::NoFocus);
-// popView->setProperty("useCustomShadow", true);
-// popView->setProperty("customShadowDarkness", 0.5);
-// popView->setProperty("customShadowWidth", 20);
-// popView->setProperty("customShadowRadius", QVector4D(6, 6, 6, 6));
-// popView->setProperty("customShadowMargins", QVector4D(20, 20, 20, 20));
-// popView->setAttribute(Qt::WA_TranslucentBackground);
-// m_completer->setPopup(popView);
- m_completer->setMaxVisibleItems(14);
-
- setCompleter(m_completer);
-
- //这是搜索框图标,要改
-// QAction *searchAction = new QAction(this);
-// searchAction->setIcon(QIcon(":/res/icons/edit-find-symbolic.svg"));
-// this->addAction(searchAction,QLineEdit::LeadingPosition);
-
- /*发送输入框文字改变的dbus*/
- QDBusConnection::sessionBus().unregisterService("org.ukui.search.service");
- QDBusConnection::sessionBus().registerService("org.ukui.search.service");
- QDBusConnection::sessionBus().registerObject("/lineEdit/textChanged", this, QDBusConnection :: ExportAllSlots | QDBusConnection :: ExportAllSignals);
-
- connect(this, &QLineEdit::textChanged, this, &SearchLineEdit::lineEditTextChanged);
- connect(this, &QLineEdit::textChanged, this, [ = ]() {
- m_isRecorded = false;
- });
-}
-
-void SearchLineEdit::record() {
- if(m_isRecorded == true || text().size() <= 1 || text().isEmpty())
- return;
- GlobalSettings::getInstance()->setSearchRecord(text(), QDateTime::currentDateTime());
- m_isRecorded = true;
- m_model->setStringList(GlobalSettings::getInstance()->getSearchRecord());
-}
-
-SearchLineEdit::~SearchLineEdit() {
-
-}
-
-/**
- * @brief lineEditTextChange 监听到搜索框文字的textChanged信号,发送dbus信号给其他程序
- * @param arg 搜索框的文本
- *
- * 需要此点击信号的应用需要做如下绑定
- * QDBusConnection::sessionBus().connect(QString(), QString("/lineEdit/textChanged"), "org.ukui.search.inputbox", "InputBoxTextChanged", this, SLOT(client_get(QString)));
- * 在槽函数client_get(void) 中处理接受到的点击信号
- */
-void SearchLineEdit::lineEditTextChanged(QString arg) {
- QDBusMessage message = QDBusMessage::createSignal("/lineEdit/textChanged", "org.ukui.search.inputbox", "InputBoxTextChanged");
- message << arg;
- QDBusConnection::sessionBus().send(message);
-}
diff --git a/frontend/control/search-line-edit.cpp b/frontend/control/search-line-edit.cpp
new file mode 100644
index 0000000..f5289f1
--- /dev/null
+++ b/frontend/control/search-line-edit.cpp
@@ -0,0 +1,191 @@
+/*
+ *
+ * Copyright (C) 2020, 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 .
+ *
+ * Authors: zhangjiaping
+ *
+ */
+#include "search-line-edit.h"
+#include
+
+QT_BEGIN_NAMESPACE
+extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
+QT_END_NAMESPACE
+using namespace Zeeker;
+/**
+ * @brief UKuiSearchLineEdit 全局搜索的输入框
+ */
+SearchLineEdit::SearchLineEdit(QWidget *parent) : QLineEdit(parent) {
+ setStyle(new LineEditStyle());
+ this->setFocusPolicy(Qt::StrongFocus);
+ this->setFixedSize(680, 50);
+ this->setTextMargins(25, 0, 0, 0);
+ this->setAttribute(Qt::WA_TranslucentBackground);
+ this->setDragEnabled(true);
+
+ m_queryIcon = new QLabel;
+ QPixmap pixmap;
+ if (!QIcon::fromTheme("system-search-symbolic").isNull()) {
+ pixmap = QPixmap(QIcon::fromTheme("system-search-symbolic").pixmap(QSize(18, 18)));
+ } else {
+ pixmap = QPixmap(QIcon(":/res/icons/system-search.symbolic.png").pixmap(QSize(18, 18)));
+ }
+ m_queryIcon->setProperty("useIconHighlightEffect", 0x10);
+ m_queryIcon->setFixedSize(pixmap.size());
+ m_queryIcon->setPixmap(pixmap);
+
+ m_ly = new QHBoxLayout(this);
+ m_ly->addSpacing(4);
+ m_ly->addWidget(m_queryIcon);
+ m_ly->addStretch();
+
+ this->setPlaceholderText(tr("Search"));
+ this->setMaxLength(100);
+
+ m_timer = new QTimer;
+ connect(m_timer, &QTimer::timeout, this, [ = ]() {
+ m_timer->stop();
+ Q_EMIT this->requestSearchKeyword(this->text());
+ });
+ connect(this, &SearchLineEdit::textChanged, this, [ = ](QString text) {
+ if(m_isEmpty) {
+ m_isEmpty = false;
+ Q_EMIT this->requestSearchKeyword(text);
+ } else {
+ if(text == "") {
+ m_isEmpty = true;
+ m_timer->stop();
+ return;
+ }
+ m_timer->start(0.1 * 1000);
+ }
+ });
+}
+
+SearchLineEdit::~SearchLineEdit() {
+
+}
+
+void SearchLineEdit::paintEvent(QPaintEvent *e)
+{
+ QPainter p(this);
+ p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
+ p.setBrush(palette().base());
+ p.setOpacity(GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble());
+ p.setPen(Qt::NoPen);
+ p.drawRoundedRect(this->rect(), 6, 6);
+ return QLineEdit::paintEvent(e);
+}
+
+SeachBarWidget::SeachBarWidget(QWidget *parent): QWidget(parent) {
+ this->setFixedSize(700, 70);
+ m_ly = new QHBoxLayout(this);
+ m_searchLineEdit = new SearchLineEdit(this);
+ m_ly->addWidget(m_searchLineEdit);
+ connect(m_searchLineEdit, &SearchLineEdit::requestSearchKeyword, this, &SeachBarWidget::requestSearchKeyword);
+}
+
+SeachBarWidget::~SeachBarWidget() {
+}
+
+void SeachBarWidget::clear()
+{
+ m_searchLineEdit->clear();
+}
+
+void SeachBarWidget::paintEvent(QPaintEvent *e)
+{
+ Q_UNUSED(e)
+
+ QPainter p(this);
+ p.setRenderHint(QPainter::Antialiasing);
+ QPainterPath rectPath;
+ rectPath.addRoundedRect(this->rect().adjusted(10, 10, -10, -10), 6, 6);
+
+
+ // 画一个黑底
+ QPixmap pixmap(this->rect().size());
+ pixmap.fill(Qt::transparent);
+ QPainter pixmapPainter(&pixmap);
+ pixmapPainter.setRenderHint(QPainter::Antialiasing);
+// pixmapPainter.setCompositionMode(QPainter::CompositionMode_Difference);
+ pixmapPainter.setPen(Qt::transparent);
+ pixmapPainter.setBrush(Qt::black);
+ pixmapPainter.setOpacity(0.65);
+ pixmapPainter.drawPath(rectPath);
+ pixmapPainter.end();
+
+
+ // 模糊这个黑底
+ QImage img = pixmap.toImage();
+ qt_blurImage(img, 10, false, false);
+
+
+ // 挖掉中心
+ pixmap = QPixmap::fromImage(img);
+ QPainter pixmapPainter2(&pixmap);
+ pixmapPainter2.setRenderHint(QPainter::Antialiasing);
+ pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear);
+ pixmapPainter2.setPen(Qt::transparent);
+ pixmapPainter2.setBrush(Qt::transparent);
+ pixmapPainter2.drawPath(rectPath);
+
+
+ // 绘制阴影
+ p.drawPixmap(this->rect(), pixmap, pixmap.rect());
+}
+
+void LineEditStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
+{
+ switch (element) {
+ case PE_PanelLineEdit://UKUI Text edit style
+ {
+ if (const QStyleOptionFrame *f = qstyleoption_cast(option)) {
+ const bool enable = f->state & State_Enabled;
+ const bool focus = f->state & State_HasFocus;
+
+ if (!enable) {
+ painter->save();
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(f->palette.brush(QPalette::Disabled, QPalette::Button));
+ painter->setRenderHint(QPainter::Antialiasing, true);
+ painter->drawRoundedRect(option->rect, 4, 4);
+ painter->restore();
+ return;
+ }
+
+ if (f->state & State_ReadOnly) {
+ painter->save();
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(f->palette.brush(QPalette::Active, QPalette::Button));
+ painter->setRenderHint(QPainter::Antialiasing, true);
+ painter->drawRoundedRect(option->rect, 4, 4);
+ painter->restore();
+ return;
+ }
+
+ if (!focus) {
+ QStyleOptionButton button;
+ button.state = option->state & ~(State_Sunken | State_On);
+ button.rect = option->rect;
+ proxy()->drawPrimitive(PE_PanelButtonCommand, &button, painter, widget);
+ }
+ return;
+ }
+ break;
+ }
+ }
+}
diff --git a/frontend/control/input-box.h b/frontend/control/search-line-edit.h
similarity index 51%
rename from frontend/control/input-box.h
rename to frontend/control/search-line-edit.h
index b581d96..493d291 100644
--- a/frontend/control/input-box.h
+++ b/frontend/control/search-line-edit.h
@@ -18,8 +18,8 @@
* Authors: zhangjiaping
*
*/
-#ifndef INPUTBOX_H
-#define INPUTBOX_H
+#ifndef SEARCHLINEEDIT_H
+#define SEARCHLINEEDIT_H
#include
#include
#include
@@ -33,87 +33,54 @@
#include
#include
#include
+#include
#include "global-settings.h"
namespace Zeeker {
-class SearchLineEdit;
-
-class SeachBarWidget: public QWidget {
-public:
- SeachBarWidget(QWidget *parent = nullptr);
- ~SeachBarWidget();
-};
-
-class SeachBar: public QWidget {
-public:
- SeachBar();
- ~SeachBar();
-
-private:
-// QLineEdit *m_queryLineEdit=nullptr;
-};
-
-class SearchBarHLayout : public QHBoxLayout {
- Q_OBJECT
-public:
- SearchBarHLayout(QWidget *parent = nullptr);
- ~SearchBarHLayout();
- void clearText();
- QString text();
- void focusIn();
- void focusOut();
- void reSearch();
-
-protected:
- bool eventFilter(QObject *watched, QEvent *event);
-
-private:
- void initUI();
- bool m_isEmpty = true;
- QTimer * m_timer = nullptr;
-
- SearchLineEdit * m_queryLineEdit = nullptr;
- QPropertyAnimation * m_animation = nullptr;
- QWidget * m_queryWidget = nullptr;
- QLabel * m_queryIcon = nullptr;
- QLabel * m_queryText = nullptr;
- bool m_isSearching = false;
-
-Q_SIGNALS:
- void requestSearchKeyword(QString text);
-public Q_SLOTS:
- void effectiveSearchRecord();
-
-};
-class SearchBarWidgetLayout : public QHBoxLayout {
-public:
- SearchBarWidgetLayout();
- ~SearchBarWidgetLayout();
-private:
- void initUI();
-
-};
class SearchLineEdit : public QLineEdit {
Q_OBJECT
-
- /*
- * 负责与ukui桌面环境应用通信的dbus
- * 搜索框文本改变的时候发送信号
- */
- Q_CLASSINFO("D-Bus Interface", "org.ukui.search.inputbox")
public:
- SearchLineEdit();
- void record();
+ SearchLineEdit(QWidget *parent = nullptr);
+// void record();
~SearchLineEdit();
-
-private Q_SLOTS:
- void lineEditTextChanged(QString arg);
+protected:
+ void paintEvent(QPaintEvent *);
+Q_SIGNALS:
+ void requestSearchKeyword(QString text);
private:
- QStringListModel *m_model = nullptr;
- QCompleter *m_completer = nullptr;
- bool m_isRecorded = false;
+ QHBoxLayout *m_ly;
+ QLabel *m_queryIcon;
+ QTimer *m_timer;
+ bool m_isEmpty = true;
+};
+
+class SeachBarWidget: public QWidget {
+ Q_OBJECT
+public:
+ SeachBarWidget(QWidget *parent = nullptr);
+ ~SeachBarWidget();
+
+ void clear();
+protected:
+ void paintEvent(QPaintEvent *e);
+
+Q_SIGNALS:
+ void requestSearchKeyword(QString text);
+
+private:
+ SearchLineEdit *m_searchLineEdit;
+ QHBoxLayout *m_ly;
+};
+
+
+
+class LineEditStyle : public QProxyStyle
+{
+public:
+ LineEditStyle() {}
+ void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override;
};
}
-#endif //INPUTBOX_H
+#endif //SEARCHLINEEDIT_H
diff --git a/frontend/control/stacked-widget.cpp b/frontend/control/stacked-widget.cpp
index b1a8aec..32c5550 100644
--- a/frontend/control/stacked-widget.cpp
+++ b/frontend/control/stacked-widget.cpp
@@ -75,9 +75,9 @@ void StackedWidget::appendPlugin(const QString &plugin)
void StackedWidget::initWidgets()
{
//NEW_TODO
- m_homePage = new HomePage;
- this->insertWidget(int(StackedPage::HomePage), m_homePage);
- this->setPage(int(StackedPage::HomePage));
+// m_homePage = new HomePage;
+// this->insertWidget(int(StackedPage::HomePage), m_homePage);
+// this->setPage(int(StackedPage::HomePage));
m_searchPage = new SearchPage;
m_searchPage->setSize(this->width(), this->height());
diff --git a/frontend/control/stacked-widget.h b/frontend/control/stacked-widget.h
index 4304947..4c92e84 100644
--- a/frontend/control/stacked-widget.h
+++ b/frontend/control/stacked-widget.h
@@ -23,7 +23,7 @@
#include
#include
-#include "input-box.h"
+#include "search-line-edit.h"
#include "home-page.h"
#include "search-page.h"
diff --git a/frontend/main.cpp b/frontend/main.cpp
index df3571b..b666afe 100644
--- a/frontend/main.cpp
+++ b/frontend/main.cpp
@@ -274,9 +274,6 @@ int main(int argc, char *argv[]) {
// Processing startup parameters
if(QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) {
centerToScreen(w);
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
- XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), w->m_hints);
-#endif
w->show();
}
diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp
index 5ec49f4..e6ec422 100644
--- a/frontend/mainwindow.cpp
+++ b/frontend/mainwindow.cpp
@@ -37,13 +37,13 @@
#include "qt-single-application.h"
#include "global-settings.h"
-#define MAIN_MARGINS 16,16,16,16
+#define MAIN_MARGINS 0, 0, 0, 0
#define TITLE_MARGINS 0,0,0,0
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
#define SEARCH_METHOD_KEY "indexSearch"
#define WEB_ENGINE_KEY "webEngine"
-#define WINDOW_WIDTH 680
-#define WINDOW_HEIGHT 600
+#define WINDOW_WIDTH 700
+#define WINDOW_HEIGHT 610
#define TITLE_HEIGHT 40
#define WINDOW_ICON_SIZE 24
#define SETTING_BTN_SIZE 30
@@ -63,6 +63,7 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent) {
this->setAttribute(Qt::WA_TranslucentBackground, true);
+ this->setWindowFlag(Qt::FramelessWindowHint);
this->setAutoFillBackground(false);
this->setFocusPolicy(Qt::StrongFocus);
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
@@ -70,21 +71,6 @@ MainWindow::MainWindow(QWidget *parent) :
initUi();
initTimer();
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
-// setProperty("useStyleWindowManager", false); //禁止拖动
- m_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
- m_hints.functions = MWM_FUNC_ALL;
- m_hints.decorations = MWM_DECOR_BORDER;
- XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
-
- QPainterPath path;
- auto rect = this->rect();
- rect.adjust(1, 1, -1, -1);
- path.addRect(rect);
- setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon()));
- KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
-#endif
-
m_sys_tray_icon = new QSystemTrayIcon(this);
m_sys_tray_icon->setIcon(QIcon::fromTheme("system-search-symbolic"));
m_sys_tray_icon->setToolTip(tr("Global Search"));
@@ -117,14 +103,6 @@ MainWindow::~MainWindow() {
delete m_search_gsettings;
m_search_gsettings = NULL;
}
- if(m_searchWidget) {
- delete m_searchWidget;
- m_searchWidget = NULL;
- }
- if(m_searchLayout) {
- delete m_searchLayout;
- m_searchLayout = NULL;
- }
}
/**
@@ -140,34 +118,15 @@ void MainWindow::initUi() {
mainlayout->setContentsMargins(MAIN_MARGINS);
m_frame->setLayout(mainlayout);
-// m_titleFrame = new QFrame(m_frame);//标题栏
-// m_titleFrame->setFixedHeight(TITLE_HEIGHT);
-// m_titleLyt = new QHBoxLayout(m_titleFrame);
-// m_titleLyt->setContentsMargins(TITLE_MARGINS);
-// m_iconLabel = new QLabel(m_titleFrame);
-// m_iconLabel->setFixedSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE);
-// m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE)));
-// m_titleLabel = new QLabel(m_titleFrame);
-// m_titleLabel->setText(tr("Search"));
-// m_settingsBtn = new QPushButton(m_titleFrame);
-// m_settingsBtn->setFixedSize(SETTING_BTN_SIZE, SETTING_BTN_SIZE);
-// m_settingsBtn->setIcon(QIcon::fromTheme("document-properties-symbolic"));
-// m_settingsBtn->setProperty("useIconHighlightEffect", 0x2);
-// m_settingsBtn->setProperty("isWindowButton", 0x01);
-// m_settingsBtn->setFlat(true);
-// m_titleLyt->addWidget(m_iconLabel);
-// m_titleLyt->addWidget(m_titleLabel);
-// m_titleLyt->addStretch();
-// m_titleLyt->addWidget(m_settingsBtn);
m_stackedWidget = new StackedWidget(m_frame);//内容栏
-
- m_searchWidget = new SeachBarWidget(this);
- m_searchLayout = new SearchBarHLayout(this);
- m_searchWidget->setLayout(m_searchLayout);
- m_searchWidget->setFixedHeight(SEARCH_BAR_SIZE);
+ m_seachBarWidget = new SeachBarWidget(this);
+// m_searchWidget = new SeachBarWidget(this);
+// m_searchLayout = new SearchBarHLayout(this);
+// m_searchWidget->setLayout(m_searchLayout);
+// m_searchWidget->setFixedHeight(SEARCH_BAR_SIZE);
// mainlayout->addWidget(m_titleFrame);
- mainlayout->addWidget(m_searchWidget);
+ mainlayout->addWidget(m_seachBarWidget);
mainlayout->addWidget(m_stackedWidget);
//创建索引询问弹窗
@@ -200,8 +159,8 @@ void MainWindow::initConnections()
// connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
// m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE)));
// });
- connect(m_searchLayout, &SearchBarHLayout::requestSearchKeyword, this, &MainWindow::searchKeywordSlot);
- connect(m_stackedWidget, &StackedWidget::effectiveSearch, m_searchLayout, &SearchBarHLayout::effectiveSearchRecord);
+ connect(m_seachBarWidget, &SeachBarWidget::requestSearchKeyword, this, &MainWindow::searchKeywordSlot);
+// connect(m_stackedWidget, &StackedWidget::effectiveSearch, m_searchLayout, &SearchBarHLayout::effectiveSearchRecord);
}
/**
@@ -212,11 +171,8 @@ void MainWindow::bootOptionsFilter(QString opt) {
if(opt == "-s" || opt == "--show") {
clearSearchResult();
centerToScreen(this);
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
- XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
-#endif
this->show();
- this->m_searchLayout->focusIn();
+// this->m_searchLineEdit->focusIn();
this->raise();
this->activateWindow();
}
@@ -226,8 +182,8 @@ void MainWindow::bootOptionsFilter(QString opt) {
* @brief clearSearchResult 清空搜索结果
*/
void MainWindow::clearSearchResult() {
- m_searchLayout->clearText();
- m_searchLayout->focusOut();
+ m_seachBarWidget->clear();
+// m_searchLineEdit->clearFocus();
}
/**
@@ -240,11 +196,8 @@ void MainWindow::trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason)
if(!this->isVisible()) {
clearSearchResult();
centerToScreen(this);
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
- XAtomHelper::getInstance()->setWindowMotifHint(winId(), m_hints);
-#endif
this->show();
- this->m_searchLayout->focusIn(); //打开主界面时输入框夺焦,可直接输入
+// this->m_searchLineEdit->focusIn(); //打开主界面时输入框夺焦,可直接输入
this->raise();
this->activateWindow();
} else {
@@ -482,21 +435,21 @@ void MainWindow::initTimer() {
});
m_researchTimer = new QTimer;
m_researchTimer->setInterval(RESEARCH_TIME);
- connect(m_researchTimer, &QTimer::timeout, this, [ = ]() {
- if(this->isVisible()) {
- m_searchLayout->reSearch();
- }
- m_researchTimer->stop();
- });
- connect(m_searchLayout, &SearchBarHLayout::requestSearchKeyword, this, [ = ](QString text) {
- if(text == "" || text.isEmpty()) {
- m_askTimer->stop();
- } else {
- //允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
- if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH)
- m_askTimer->start();
- }
- });
+// connect(m_researchTimer, &QTimer::timeout, this, [ = ]() {
+// if(this->isVisible()) {
+// m_searchLayout->reSearch();
+// }
+// m_researchTimer->stop();
+// });
+// connect(m_searchLayout, &SearchBarHLayout::requestSearchKeyword, this, [ = ](QString text) {
+// if(text == "" || text.isEmpty()) {
+// m_askTimer->stop();
+// } else {
+// //允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索
+// if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH)
+// m_askTimer->start();
+// }
+// });
}
/**
@@ -558,21 +511,10 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
}
void MainWindow::paintEvent(QPaintEvent *event) {
- Q_UNUSED(event)
- double trans = getTransparentData();
- QStyleOption opt;
- opt.init(this);
- QPainter p(this);
- style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
+ QPainterPath path;
- QRect rect = this->rect();
- p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
- p.setBrush(opt.palette.color(QPalette::Base));
- p.setOpacity(trans);
- p.setPen(Qt::NoPen);
-// p.drawRoundedRect(rect, 6, 6);
- p.drawRect(rect);
- return QWidget::paintEvent(event);
+ path.addRoundedRect(m_seachBarWidget->x()+10, m_seachBarWidget->y()+10, m_seachBarWidget->width()-20, m_seachBarWidget->height()-20, 6, 6);
+ KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
}
diff --git a/frontend/mainwindow.h b/frontend/mainwindow.h
index 1951fa2..4456240 100644
--- a/frontend/mainwindow.h
+++ b/frontend/mainwindow.h
@@ -77,48 +77,6 @@ public:
void centerToScreen(QWidget* widget);
void initGsettings();
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
- MotifWmHints m_hints;
-#endif
-
-private:
-
- QFrame * m_frame = nullptr; // Main frame
- QFrame * m_titleFrame = nullptr; // Title bar frame
- QHBoxLayout * m_titleLyt = nullptr; // Title layout
- QLabel * m_iconLabel = nullptr; // Icon lable
- QLabel * m_titleLabel = nullptr; // Title lable
- QPushButton * m_settingsBtn = nullptr; // Menu button
- StackedWidget * m_stackedWidget = nullptr; // Stacked widget
- SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout
- SeachBarWidget * m_searchWidget = nullptr; // Search bar
-#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
- SettingsWidget * m_settingsWidget = nullptr; // Settings Widget
-#endif
-
- QStringList m_dirList;
-
- QQueue *m_search_result_file = nullptr;
- QQueue *m_search_result_dir = nullptr;
- QQueue> *m_search_result_content = nullptr;
-
- QSystemTrayIcon *m_sys_tray_icon = nullptr;
- CreateIndexAskDialog * m_askDialog = nullptr;
- bool m_isAskDialogVisible = false;
-
- QTimer * m_askTimer = nullptr; //询问是否创建索引弹窗弹出的计时器
- QTimer * m_researchTimer = nullptr; //创建索引后重新执行一次搜索的计时器
- bool m_currentSearchAsked = false; //本次搜索是否已经询问过是否创建索引了
- QGSettings * m_search_gsettings = nullptr;
-
- SearchMethodManager m_searchMethodManager;
-
- void setSearchMethod(const bool&);
- double getTransparentData();
- void initTimer();
- bool tryHideMainwindow();
- void setSearchMethodConfig(const bool&, const bool&);
-
protected:
void paintEvent(QPaintEvent *);
void keyPressEvent(QKeyEvent *event);
@@ -147,6 +105,45 @@ public Q_SLOTS:
void trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason);
void settingsBtnClickedSlot();
void searchKeywordSlot(const QString&);
+
+private:
+
+ QFrame * m_frame = nullptr; // Main frame
+ QFrame * m_titleFrame = nullptr; // Title bar frame
+ QHBoxLayout * m_titleLyt = nullptr; // Title layout
+ QLabel * m_iconLabel = nullptr; // Icon lable
+ QLabel * m_titleLabel = nullptr; // Title lable
+ QPushButton * m_settingsBtn = nullptr; // Menu button
+ StackedWidget * m_stackedWidget = nullptr; // Stacked widget
+// SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout
+// SeachBarWidget * m_searchWidget = nullptr; // Search bar
+ SeachBarWidget *m_seachBarWidget;
+#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
+ SettingsWidget * m_settingsWidget = nullptr; // Settings Widget
+#endif
+
+ QStringList m_dirList;
+
+ QQueue *m_search_result_file = nullptr;
+ QQueue *m_search_result_dir = nullptr;
+ QQueue> *m_search_result_content = nullptr;
+
+ QSystemTrayIcon *m_sys_tray_icon = nullptr;
+ CreateIndexAskDialog * m_askDialog = nullptr;
+ bool m_isAskDialogVisible = false;
+
+ QTimer * m_askTimer = nullptr; //询问是否创建索引弹窗弹出的计时器
+ QTimer * m_researchTimer = nullptr; //创建索引后重新执行一次搜索的计时器
+ bool m_currentSearchAsked = false; //本次搜索是否已经询问过是否创建索引了
+ QGSettings * m_search_gsettings = nullptr;
+
+ SearchMethodManager m_searchMethodManager;
+
+ void setSearchMethod(const bool&);
+ double getTransparentData();
+ void initTimer();
+ bool tryHideMainwindow();
+ void setSearchMethodConfig(const bool&, const bool&);
};
}
diff --git a/frontend/model/search-result-manager.cpp b/frontend/model/search-result-manager.cpp
index fbff1dc..b00c7c0 100644
--- a/frontend/model/search-result-manager.cpp
+++ b/frontend/model/search-result-manager.cpp
@@ -25,7 +25,7 @@ SearchResultManager::SearchResultManager(const QString& plugin_id, QObject *pare
{
m_plugin_id = plugin_id;
m_result_queue = new DataQueue;
- m_get_result_thread = new ReceiveResultThread(m_result_queue);
+ m_get_result_thread = new ReceiveResultThread(m_result_queue, this);
initConnections();
}
diff --git a/frontend/res/icons/system-search.symbolic.png b/frontend/res/icons/system-search.symbolic.png
new file mode 100644
index 0000000000000000000000000000000000000000..170e2a2a05297dedb13f5ffb07a5c53f07251503
GIT binary patch
literal 498
zcmV=FZ%C=REh%IfoIe
zHh^amEi|wnU-1qb*r@`@Fpm@1Q}BHY4{;AahXL%vHO!^euHY#?;ydbSVis+D!cDyD
zx0BA`i+F;o7%%a+u#8ol90YJZ1wTKCIq3kF@CeiWjG4bHA68R%j9dLoi@2}+SbFKA
zSYXyUnP1vH##SBz*ri47R-R!
z)^&$D;7b}0Rs_`XtqAZojm?UHCN_%z8=|+&RtTPndU#d@*b$AZEi!6Y)o?}huC-pK
zG0_>9Mfne-OQOh5ml=res/icons/close.svg
res/qt-translations/qt_zh_CN.qm
res/icons/net-disconnected.svg
+ res/icons/system-search.symbolic.png
diff --git a/translations/libukui-search/libukui-search_zh_CN.ts b/translations/libukui-search/libukui-search_zh_CN.ts
index a7c6f64..e4e88fb 100644
--- a/translations/libukui-search/libukui-search_zh_CN.ts
+++ b/translations/libukui-search/libukui-search_zh_CN.ts
@@ -4,7 +4,7 @@
Zeeker::AppSearch
-
+
应用描述:
@@ -12,29 +12,29 @@
Zeeker::AppSearchPlugin
-
+
打开
-
+
添加到桌面快捷方式
-
+
添加到任务栏快捷方式
-
+
安装
-
-
-
+
+
+
应用搜索
@@ -46,28 +46,28 @@
Zeeker::DirSearchPlugin
-
+
打开
-
+
打开文件所在路径
-
+
复制文件路径
-
-
+
+
目录搜索
-
+
目录搜索。
@@ -75,32 +75,32 @@
Zeeker::FileContengSearchPlugin
-
+
打开
-
+
打开文件所在路径
-
+
复制文件路径
-
+
文本内容搜索
-
+
文本内容搜索。
-
+
文本内容搜索
@@ -108,28 +108,28 @@
Zeeker::FileSearchPlugin
-
+
打开
-
+
打开文件所在路径
-
+
复制文件路径
-
-
+
+
文件搜索
-
+
文件搜索。
@@ -150,18 +150,18 @@
Zeeker::SettingsSearchPlugin
-
+
打开
-
-
+
+
设置
-
+
设置。
diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts
index faec90e..61231e5 100644
--- a/translations/ukui-search/bo.ts
+++ b/translations/ukui-search/bo.ts
@@ -71,25 +71,20 @@
Zeeker::MainWindow
-
+
-
+
-
-
-
-
-
- Zeeker::SearchBarHLayout
+ Zeeker::SearchLineEdit
-
+
diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts
index cde87fc..219d00a 100644
--- a/translations/ukui-search/tr.ts
+++ b/translations/ukui-search/tr.ts
@@ -349,19 +349,18 @@
Zeeker::MainWindow
-
+
-
+
Genel Arama
-
- Ara
+ Ara
@@ -390,9 +389,8 @@
Zeeker::SearchBarHLayout
-
- Ara
+ Ara
@@ -414,6 +412,14 @@
Son değiştirilme zamanı
+
+ Zeeker::SearchLineEdit
+
+
+
+ Ara
+
+
Zeeker::SettingsWidget
diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts
index afa7fe0..e5bfe35 100644
--- a/translations/ukui-search/zh_CN.ts
+++ b/translations/ukui-search/zh_CN.ts
@@ -102,35 +102,34 @@
- 快速入口
+ 快速入口
- 最近
+ 最近
- 常用
+ 常用
Zeeker::MainWindow
-
+
搜索
-
+
搜索
-
- 搜索
+ 搜索
@@ -163,9 +162,8 @@
Zeeker::SearchBarHLayout
-
- 搜索
+ 搜索
@@ -195,6 +193,14 @@
上次修改时间
+
+ Zeeker::SearchLineEdit
+
+
+
+ 搜索
+
+
Zeeker::SettingsWidget