diff --git a/frontend/control/list-labels/list-labels.pri b/frontend/control/list-labels/list-labels.pri index 8a10490..c64cf68 100644 --- a/frontend/control/list-labels/list-labels.pri +++ b/frontend/control/list-labels/list-labels.pri @@ -3,7 +3,9 @@ INCLUDEPATH += $$PWD HEADERS += \ $$PWD/show-more-label.h \ $$PWD/title-label.h \ + $$PWD/web-search-label.h \ SOURCES += \ $$PWD/show-more-label.cpp \ $$PWD/title-label.cpp \ + $$PWD/web-search-label.cpp \ diff --git a/frontend/control/list-labels/title-label.cpp b/frontend/control/list-labels/title-label.cpp index aaf2956..24e3606 100644 --- a/frontend/control/list-labels/title-label.cpp +++ b/frontend/control/list-labels/title-label.cpp @@ -68,3 +68,8 @@ void TitleLabel::onListLengthChanged(const int &length) { m_showMoreLabel->setVisible(length >= NUM_LIMIT_SHOWN_DEFAULT); } + +void TitleLabel::lableReset() +{ + m_showMoreLabel->resetLabel(); +} diff --git a/frontend/control/list-labels/title-label.h b/frontend/control/list-labels/title-label.h index bd4bfbf..6e2b85c 100644 --- a/frontend/control/list-labels/title-label.h +++ b/frontend/control/list-labels/title-label.h @@ -44,6 +44,7 @@ private: public Q_SLOTS: void onListLengthChanged(const int &); + void lableReset(); Q_SIGNALS: void startSearch(const QString &); diff --git a/frontend/control/list-labels/web-search-label.cpp b/frontend/control/list-labels/web-search-label.cpp new file mode 100755 index 0000000..5056e9b --- /dev/null +++ b/frontend/control/list-labels/web-search-label.cpp @@ -0,0 +1,83 @@ +#include "web-search-label.h" +#include +#include +#include "global-settings.h" +using namespace Zeeker; +WebSearchLabel::WebSearchLabel(QWidget *parent) : QLabel(parent) +{ + initUi(); + this->installEventFilter(this); +} + +void WebSearchLabel::initUi() +{ + this->setFixedHeight(30); + this->setContentsMargins(8, 0, 0, 0); + this->setFixedWidth(656); + + m_WebSearchIconlabel = new QLabel(this); + m_WebSearchIconlabel->setFixedHeight(30); + m_WebSearchIconlabel->setPixmap(QIcon::fromTheme("edit-find-symbolic").pixmap(QSize(16, 16))); + + m_WebSearchLabel = new QLabel(this); + m_WebSearchLabel->setFixedHeight(30); + + m_webSearchLyt = new QHBoxLayout(this); + m_webSearchLyt->setContentsMargins(0, 0, 0, 0); + m_webSearchLyt->addWidget(m_WebSearchIconlabel); + m_webSearchLyt->addWidget(m_WebSearchLabel); + m_webSearchLyt->addStretch(); + this->setLayout(m_webSearchLyt); + +} + +void WebSearchLabel::startSearch() +{ + //新打开网页搜索或关键词发生变化,重新load + QString keyword = m_WebSearchLabel->text();//目前网页搜索的关键词,记录此词来判断网页是否需要刷新 + QString address; + QString engine = GlobalSettings::getInstance()->getValue("web_engine").toString(); + if(!engine.isEmpty()) { + if(engine == "360") { + address = "https://so.com/s?q=" + keyword; //360 + } else if(engine == "sougou") { + address = "https://www.sogou.com/web?query=" + keyword; //搜狗 + } else { + address = "http://baidu.com/s?word=" + keyword; //百度 + } + } else { //默认值 + address = "http://baidu.com/s?word=" + keyword; //百度 + } + QDesktopServices::openUrl(address); + +} + +bool WebSearchLabel::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == this) { + if(event->type() == QEvent::MouseButtonPress) { + this->setStyleSheet("background-color: #3790FA");//#3790FA选中颜色, + return true; + } else if(event->type() == QEvent::MouseButtonRelease) { + startSearch(); + return true; + } else if(event->type() == QEvent::Enter) { + this->setStyleSheet("background-color: #87CEFA");//TODO鼠标悬浮颜色待定 + return true; + } else if(event->type() == QEvent::Leave) { + this->setStyleSheet("background-color: #DCDCDC");//默认颜色 + return true; + } + } + return QObject::eventFilter(watched, event); +} + +void WebSearchLabel::initConnections() +{ + +} + +void WebSearchLabel::webSearch(const QString &key) +{ + m_WebSearchLabel->setText(key); +} diff --git a/frontend/control/list-labels/web-search-label.h b/frontend/control/list-labels/web-search-label.h new file mode 100755 index 0000000..6350800 --- /dev/null +++ b/frontend/control/list-labels/web-search-label.h @@ -0,0 +1,31 @@ +#ifndef WEBSEARCHLABEL_H +#define WEBSEARCHLABEL_H +#include +#include "title-label.h" +#include +#include + +namespace Zeeker { +class WebSearchLabel : public QLabel +{ + Q_OBJECT +public: + WebSearchLabel(QWidget * parent = nullptr); + ~WebSearchLabel() = default; + +protected: + bool eventFilter(QObject *watched, QEvent *event); +private: + void initUi(); + void initConnections(); + void startSearch(); + + QHBoxLayout * m_webSearchLyt = nullptr; + QLabel * m_WebSearchIconlabel = nullptr; + QLabel * m_WebSearchLabel = nullptr; + +public Q_SLOTS: + void webSearch(const QString &key); +}; +} +#endif // WEBSEARCHLABEL_H diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 1866a47..34e87ef 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -48,11 +48,16 @@ ResultArea::ResultArea(QWidget *parent) : QScrollArea(parent) void ResultArea::appendWidet(ResultWidget *widget) { //NEW_TODO + m_mainLyt->removeWidget(m_WebTitleLabel); + m_mainLyt->removeWidget(m_webSearchLable); m_mainLyt->addWidget(widget); setupConnectionsForWidget(widget); + widget->clearResult(); m_widget_list.append(widget); int spacing_height = m_widget_list.length() > 1 ? m_mainLyt->spacing() : 0; m_widget->setFixedHeight(m_widget->height() + widget->height() + spacing_height); + m_mainLyt->addWidget(m_WebTitleLabel); + m_mainLyt->addWidget(m_webSearchLable); } /** @@ -78,6 +83,9 @@ void ResultArea::onWidgetSizeChanged() } whole_height += m_bestListWidget->height(); //TODO 网页高度 + whole_height += m_WebTitleLabel->height(); + whole_height += m_webSearchLable->height(); + int spacing_height = m_widget_list.length() > 1 ? m_mainLyt->spacing() : 0; m_widget->setFixedHeight(whole_height + spacing_height * (m_widget_list.length() - 1)); Q_EMIT this->resizeHeight(whole_height + spacing_height * (m_widget_list.length() - 1)); @@ -101,15 +109,34 @@ void ResultArea::initUi() m_widget->setLayout(m_mainLyt); m_bestListWidget = new BestListWidget(this); m_mainLyt->addWidget(m_bestListWidget); + + m_WebTitleLabel = new TitleLabel(this); + m_WebTitleLabel->setFixedWidth(656); + m_WebTitleLabel->setText(tr("Web Page")); + m_WebTitleLabel->setFixedHeight(30); + m_mainLyt->addWidget(m_WebTitleLabel); + m_webSearchLable = new WebSearchLabel(this); + m_webSearchLable->setFixedHeight(30); + m_mainLyt->addWidget(m_webSearchLable); m_mainLyt->setContentsMargins(RESULT_LAYOUT_MARGINS); + this->widget()->setContentsMargins(0,0,0,0); + m_mainLyt->setSpacing(0); + } void ResultArea::initConnections() { connect(this, &ResultArea::startSearch, m_bestListWidget, &BestListWidget::startSearch); + connect(this, &ResultArea::startSearch, m_webSearchLable, &WebSearchLabel::webSearch); connect(m_bestListWidget, &BestListWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged); connect(m_bestListWidget, &BestListWidget::currentRowChanged, this, &ResultArea::currentRowChanged); connect(this, &ResultArea::clearSelectedRow, m_bestListWidget, &BestListWidget::clearSelectedRow); + connect(this, &ResultArea::resizeWidth, this, [=] (const int &size) { + m_bestListWidget->setFixedWidth(size); + m_WebTitleLabel->setFixedWidth(size); + m_webSearchLable->setFixedWidth(size); + }); + connect(m_bestListWidget, &BestListWidget::rowClicked, this, &ResultArea::rowClicked); } void ResultArea::setupConnectionsForWidget(ResultWidget *widget) diff --git a/frontend/control/stack-pages/search-page-section.h b/frontend/control/stack-pages/search-page-section.h index 0d8273f..f8d2905 100644 --- a/frontend/control/stack-pages/search-page-section.h +++ b/frontend/control/stack-pages/search-page-section.h @@ -27,6 +27,7 @@ #include "result-view.h" #include "search-plugin-iface.h" #include "best-list-view.h" +#include "web-search-label.h" namespace Zeeker { class ResultArea : public QScrollArea @@ -47,8 +48,10 @@ private: void setupConnectionsForWidget(ResultWidget *); QWidget * m_widget = nullptr; QVBoxLayout * m_mainLyt = nullptr; - BestListWidget * m_bestListWidget; + BestListWidget * m_bestListWidget = nullptr; QList m_widget_list; + TitleLabel * m_WebTitleLabel = nullptr; + WebSearchLabel * m_webSearchLable = nullptr; Q_SIGNALS: void startSearch(const QString &); @@ -56,6 +59,8 @@ Q_SIGNALS: void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); void clearSelectedRow(); void resizeHeight(int height); + void resizeWidth(const int &); + void rowClicked(); }; class DetailWidget : public QWidget diff --git a/frontend/control/stack-pages/search-result-page.cpp b/frontend/control/stack-pages/search-result-page.cpp index 56866a2..45b2b27 100644 --- a/frontend/control/stack-pages/search-result-page.cpp +++ b/frontend/control/stack-pages/search-result-page.cpp @@ -131,11 +131,18 @@ void SearchResultPage::initConnections() connect(this, &SearchResultPage::stopSearch, m_resultArea, &ResultArea::stopSearch); connect(this, &SearchResultPage::startSearch, m_detailArea, &DetailArea::hide); connect(this, &SearchResultPage::stopSearch, m_detailArea, &DetailArea::hide); + connect(this, &SearchResultPage::startSearch, this, [=] () { + Q_EMIT this->resizeWidth(656); + }); connect(m_resultArea, &ResultArea::currentRowChanged, m_detailArea, &DetailArea::setWidgetInfo); connect(m_resultArea, &ResultArea::currentRowChanged, this, &SearchResultPage::currentRowChanged); connect(this, &SearchResultPage::currentRowChanged, m_resultArea, &ResultArea::clearSelectedRow); connect(m_resultArea, &ResultArea::resizeHeight, this, &SearchResultPage::resizeHeight); + connect(this, &SearchResultPage::resizeWidth, m_resultArea, &ResultArea::resizeWidth); + connect(m_resultArea, &ResultArea::rowClicked, this, [=] () { + Q_EMIT this->resizeWidth(280); + }); } void SearchResultPage::setupConnectionsForWidget(ResultWidget *widget) @@ -143,5 +150,8 @@ void SearchResultPage::setupConnectionsForWidget(ResultWidget *widget) connect(widget, &ResultWidget::currentRowChanged, m_detailArea, &DetailArea::setWidgetInfo); connect(widget, &ResultWidget::currentRowChanged, this, &SearchResultPage::currentRowChanged); connect(this, &SearchResultPage::currentRowChanged, widget, &ResultWidget::clearSelectedRow); -// connect(widget, &ResultWidget::rowClicked, this, &SearchResultPage::effectiveSearch); + connect(widget, &ResultWidget::rowClicked, this, [=] () { + Q_EMIT this->resizeWidth(280); + }); + connect(this, &SearchResultPage::resizeWidth, widget, &ResultWidget::resizeWidth); } diff --git a/frontend/control/stack-pages/search-result-page.h b/frontend/control/stack-pages/search-result-page.h index 18686a7..31dfa6c 100644 --- a/frontend/control/stack-pages/search-result-page.h +++ b/frontend/control/stack-pages/search-result-page.h @@ -52,6 +52,7 @@ Q_SIGNALS: void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&); void effectiveSearch(); void resizeHeight(int height); + void resizeWidth(const int &); }; } diff --git a/frontend/model/best-list-model.cpp b/frontend/model/best-list-model.cpp index 138fc64..3abd751 100644 --- a/frontend/model/best-list-model.cpp +++ b/frontend/model/best-list-model.cpp @@ -105,6 +105,12 @@ QString BestListModel::getKey(const QModelIndex &index) void BestListModel::appendInfo(const QString &pluginId, const SearchPluginIface::ResultInfo &info) { + if (pluginId == "File Search" && m_fileActionKey_tmp != info.actionKey) {//临时保存文件搜索结果的actionKey + m_fileActionKey_tmp = info.actionKey; + } + if (pluginId == "File Content Search" && info.actionKey == m_fileActionKey_tmp) {//文本搜索判断是否和保存的actionKey相同 + return; + } if (m_plugin_id_list.contains(pluginId)) { if (info.name == m_item->m_result_info_list.at(m_plugin_id_list.lastIndexOf(pluginId)).name) { return; diff --git a/frontend/model/best-list-model.h b/frontend/model/best-list-model.h index b6ed8cb..185acd4 100644 --- a/frontend/model/best-list-model.h +++ b/frontend/model/best-list-model.h @@ -45,6 +45,7 @@ private: SearchResultItem * m_item = nullptr; QVector m_plugin_id_list; bool m_isExpanded = false; + QString m_fileActionKey_tmp; }; } #endif // BESTLISTMODEL_H diff --git a/frontend/view/best-list-view.cpp b/frontend/view/best-list-view.cpp index f169dff..f3bb494 100644 --- a/frontend/view/best-list-view.cpp +++ b/frontend/view/best-list-view.cpp @@ -210,12 +210,14 @@ void BestListWidget::initUi() m_mainLyt->addWidget(m_titleLabel); m_mainLyt->addWidget(m_bestListView); this->setFixedHeight(m_bestListView->height() + TITLE_HEIGHT); + this->setFixedWidth(656); } void BestListWidget::initConnections() { connect(this, &BestListWidget::startSearch, m_bestListView, &BestListView::startSearch); connect(this, &BestListWidget::startSearch, m_titleLabel, &TitleLabel::startSearch); + connect(this, &BestListWidget::startSearch, m_titleLabel, &TitleLabel::startSearch); connect(this, &BestListWidget::stopSearch, m_titleLabel, &TitleLabel::stopSearch); connect(this, &BestListWidget::sendBestListData, m_bestListView, &BestListView::sendBestListData); connect(m_bestListView, &BestListView::currentRowChanged, this, &BestListWidget::currentRowChanged); diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index e5cfb2a..c9d3a22 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -22,6 +22,12 @@ void ResultWidget::setEnabled(const bool &enabled) m_enabled = enabled; } +void ResultWidget::clearResult() +{ + this->setVisible(false); + this->setFixedHeight(0); +} + /** * @brief ResultWidget::expandListSlot 展开列表的槽函数 */ @@ -67,6 +73,7 @@ void ResultWidget::initUi() m_mainLyt->addWidget(m_titleLabel); m_mainLyt->addWidget(m_resultView); this->setFixedHeight(m_resultView->height() + TITLE_HEIGHT); + this->setFixedWidth(656); } void ResultWidget::initConnections() @@ -88,6 +95,10 @@ void ResultWidget::initConnections() Q_EMIT this->sizeChanged(); }); connect(m_resultView, &ResultView::sendBestListData, this, &ResultWidget::sendBestListData); + connect(m_resultView, &ResultView::lableReset, m_titleLabel, &TitleLabel::lableReset); + connect(this, &ResultWidget::resizeWidth, this, [=] (const int &size) { + this->setFixedWidth(size); + }); } ResultView::ResultView(const QString &plugin_id, QWidget *parent) : QTreeView(parent) @@ -230,6 +241,8 @@ void ResultView::mousePressEvent(QMouseEvent *event) void ResultView::initConnections() { connect(this, &ResultView::startSearch, [ = ](const QString &keyword) { + setExpanded(false); + Q_EMIT this->lableReset(); m_style_delegate->setSearchKeyword(keyword); m_model->startSearch(keyword); }); diff --git a/frontend/view/result-view.h b/frontend/view/result-view.h index 6e4f88c..931cff9 100644 --- a/frontend/view/result-view.h +++ b/frontend/view/result-view.h @@ -48,6 +48,7 @@ Q_SIGNALS: void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&); void listLengthChanged(const int &); void rowClicked(); + void lableReset(); }; class ResultWidget : public QWidget @@ -58,6 +59,7 @@ public: ~ResultWidget() = default; QString pluginId(); void setEnabled(const bool&); + void clearResult(); public Q_SLOTS: void expandListSlot(); @@ -82,6 +84,7 @@ Q_SIGNALS: void clearSelectedRow(); void sizeChanged(); void rowClicked(); + void resizeWidth(const int &); }; }