Merge branch '0720-newfrontend' into 'new-fronted'

Update search lineedit.

See merge request kylin-desktop/ukui-search!66
This commit is contained in:
纪笑旭 2021-07-21 09:31:35 +00:00
commit fa20094e04
16 changed files with 374 additions and 537 deletions

View File

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

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* Authors: zhangjiaping <zhangjiaping@kylinos.cn>
*
*/
#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);
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* Authors: zhangjiaping <zhangjiaping@kylinos.cn>
*
*/
#include "search-line-edit.h"
#include <KWindowEffects>
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<const QStyleOptionFrame *>(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;
}
}
}

View File

@ -18,8 +18,8 @@
* Authors: zhangjiaping <zhangjiaping@kylinos.cn>
*
*/
#ifndef INPUTBOX_H
#define INPUTBOX_H
#ifndef SEARCHLINEEDIT_H
#define SEARCHLINEEDIT_H
#include <QWidget>
#include <QHBoxLayout>
#include <QLabel>
@ -33,87 +33,54 @@
#include <QAbstractItemView>
#include <QVector4D>
#include <QListView>
#include <QProxyStyle>
#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

View File

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

View File

@ -23,7 +23,7 @@
#include <QObject>
#include <QStackedWidget>
#include "input-box.h"
#include "search-line-edit.h"
#include "home-page.h"
#include "search-page.h"

View File

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

View File

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

View File

@ -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<QString> *m_search_result_file = nullptr;
QQueue<QString> *m_search_result_dir = nullptr;
QQueue<QPair<QString, QStringList>> *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<QString> *m_search_result_file = nullptr;
QQueue<QString> *m_search_result_dir = nullptr;
QQueue<QPair<QString, QStringList>> *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&);
};
}

View File

@ -25,7 +25,7 @@ SearchResultManager::SearchResultManager(const QString& plugin_id, QObject *pare
{
m_plugin_id = plugin_id;
m_result_queue = new DataQueue<SearchPluginIface::ResultInfo>;
m_get_result_thread = new ReceiveResultThread(m_result_queue);
m_get_result_thread = new ReceiveResultThread(m_result_queue, this);
initConnections();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

View File

@ -5,5 +5,6 @@
<file>res/icons/close.svg</file>
<file>res/qt-translations/qt_zh_CN.qm</file>
<file>res/icons/net-disconnected.svg</file>
<file>res/icons/system-search.symbolic.png</file>
</qresource>
</RCC>

View File

@ -4,7 +4,7 @@
<context>
<name>Zeeker::AppSearch</name>
<message>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="196"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="208"/>
<source>Application Description:</source>
<translation></translation>
</message>
@ -12,29 +12,29 @@
<context>
<name>Zeeker::AppSearchPlugin</name>
<message>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="8"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="10"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="9"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="11"/>
<source>Add Shortcut to Desktop</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="10"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="12"/>
<source>Add Shortcut to Panel</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="11"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="13"/>
<source>Install</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="21"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="26"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="31"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="23"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="28"/>
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="33"/>
<source>Applications Search</source>
<translation></translation>
</message>
@ -46,28 +46,28 @@
<context>
<name>Zeeker::DirSearchPlugin</name>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="70"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="92"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="71"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="93"/>
<source>Open path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="72"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="94"/>
<source>Copy Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="80"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="90"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="102"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="112"/>
<source>Dir Search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="85"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="107"/>
<source>Dir search.</source>
<translation></translation>
</message>
@ -75,32 +75,32 @@
<context>
<name>Zeeker::FileContengSearchPlugin</name>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="133"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="165"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="134"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="166"/>
<source>Open path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="135"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="167"/>
<source>Copy Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="143"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="175"/>
<source>File Content Search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="148"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="180"/>
<source>File content search.</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="153"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="185"/>
<source>File content search</source>
<translation></translation>
</message>
@ -108,28 +108,28 @@
<context>
<name>Zeeker::FileSearchPlugin</name>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="7"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="10"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="8"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="11"/>
<source>Open path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="9"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="12"/>
<source>Copy Path</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="17"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="27"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="20"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="30"/>
<source>File Search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="22"/>
<location filename="../../libsearch/index/file-search-plugin.cpp" line="25"/>
<source>File search.</source>
<translation></translation>
</message>
@ -150,18 +150,18 @@
<context>
<name>Zeeker::SettingsSearchPlugin</name>
<message>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="10"/>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="11"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="19"/>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="29"/>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="20"/>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="30"/>
<source>Settings Search</source>
<translation></translation>
</message>
<message>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="24"/>
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="25"/>
<source>Settings search.</source>
<translation></translation>
</message>

View File

@ -71,25 +71,20 @@
<context>
<name>Zeeker::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="69"/>
<location filename="../../frontend/mainwindow.cpp" line="70"/>
<source>ukui-search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="90"/>
<location filename="../../frontend/mainwindow.cpp" line="76"/>
<source>Global Search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="151"/>
<source>Search</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Zeeker::SearchBarHLayout</name>
<name>Zeeker::SearchLineEdit</name>
<message>
<location filename="../../frontend/control/input-box.cpp" line="115"/>
<location filename="../../frontend/control/search-line-edit.cpp" line="55"/>
<source>Search</source>
<translation type="unfinished"></translation>
</message>

View File

@ -349,19 +349,18 @@
<context>
<name>Zeeker::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="69"/>
<location filename="../../frontend/mainwindow.cpp" line="70"/>
<source>ukui-search</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="90"/>
<location filename="../../frontend/mainwindow.cpp" line="76"/>
<source>Global Search</source>
<translation type="unfinished">Genel Arama</translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="151"/>
<source>Search</source>
<translation type="unfinished">Ara</translation>
<translation type="obsolete">Ara</translation>
</message>
</context>
<context>
@ -390,9 +389,8 @@
<context>
<name>Zeeker::SearchBarHLayout</name>
<message>
<location filename="../../frontend/control/input-box.cpp" line="115"/>
<source>Search</source>
<translation type="unfinished">Ara</translation>
<translation type="obsolete">Ara</translation>
</message>
</context>
<context>
@ -414,6 +412,14 @@
<translation type="obsolete">Son değiştirilme zamanı</translation>
</message>
</context>
<context>
<name>Zeeker::SearchLineEdit</name>
<message>
<location filename="../../frontend/control/search-line-edit.cpp" line="55"/>
<source>Search</source>
<translation type="unfinished">Ara</translation>
</message>
</context>
<context>
<name>Zeeker::SettingsWidget</name>
<message>

View File

@ -102,35 +102,34 @@
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="118"/>
<source>Open Quickly</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="120"/>
<source>Recently Opened</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
<message>
<location filename="../../frontend/control/stack-pages/home-page.cpp" line="122"/>
<source>Commonly Used</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
</context>
<context>
<name>Zeeker::MainWindow</name>
<message>
<location filename="../../frontend/mainwindow.cpp" line="69"/>
<location filename="../../frontend/mainwindow.cpp" line="70"/>
<source>ukui-search</source>
<translation></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="90"/>
<location filename="../../frontend/mainwindow.cpp" line="76"/>
<source>Global Search</source>
<translation></translation>
</message>
<message>
<location filename="../../frontend/mainwindow.cpp" line="151"/>
<source>Search</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
</context>
<context>
@ -163,9 +162,8 @@
<context>
<name>Zeeker::SearchBarHLayout</name>
<message>
<location filename="../../frontend/control/input-box.cpp" line="115"/>
<source>Search</source>
<translation></translation>
<translation type="vanished"></translation>
</message>
</context>
<context>
@ -195,6 +193,14 @@
<translation type="vanished"></translation>
</message>
</context>
<context>
<name>Zeeker::SearchLineEdit</name>
<message>
<location filename="../../frontend/control/search-line-edit.cpp" line="55"/>
<source>Search</source>
<translation></translation>
</message>
</context>
<context>
<name>Zeeker::SettingsWidget</name>
<message>