Fix UI; Fix expand function; Add web search function;
This commit is contained in:
parent
feba503879
commit
3408aca702
|
@ -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 \
|
||||
|
|
|
@ -68,3 +68,8 @@ void TitleLabel::onListLengthChanged(const int &length)
|
|||
{
|
||||
m_showMoreLabel->setVisible(length >= NUM_LIMIT_SHOWN_DEFAULT);
|
||||
}
|
||||
|
||||
void TitleLabel::lableReset()
|
||||
{
|
||||
m_showMoreLabel->resetLabel();
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
|
||||
public Q_SLOTS:
|
||||
void onListLengthChanged(const int &);
|
||||
void lableReset();
|
||||
|
||||
Q_SIGNALS:
|
||||
void startSearch(const QString &);
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#include "web-search-label.h"
|
||||
#include <QIcon>
|
||||
#include <QDesktopServices>
|
||||
#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);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef WEBSEARCHLABEL_H
|
||||
#define WEBSEARCHLABEL_H
|
||||
#include <QLabel>
|
||||
#include "title-label.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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
|
|
@ -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)
|
||||
|
|
|
@ -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<ResultWidget *> 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ Q_SIGNALS:
|
|||
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
|
||||
void effectiveSearch();
|
||||
void resizeHeight(int height);
|
||||
void resizeWidth(const int &);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -45,6 +45,7 @@ private:
|
|||
SearchResultItem * m_item = nullptr;
|
||||
QVector<QString> m_plugin_id_list;
|
||||
bool m_isExpanded = false;
|
||||
QString m_fileActionKey_tmp;
|
||||
};
|
||||
}
|
||||
#endif // BESTLISTMODEL_H
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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 &);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue