Merge branch 'new-frontend' into 'new-frontend'

Update UI; Update key press event;

See merge request kylin-desktop/ukui-search!95
This commit is contained in:
PengfeiZhang 2021-08-19 02:56:59 +00:00
commit 8ed37895b6
16 changed files with 570 additions and 75 deletions

View File

@ -28,7 +28,7 @@ void WebSearchLabel::initUi()
m_webSearchLyt->addWidget(m_WebSearchLabel);
m_webSearchLyt->addStretch();
this->setLayout(m_webSearchLyt);
m_defultStyleSheet = this->styleSheet();
}
void WebSearchLabel::startSearch()
@ -52,6 +52,11 @@ void WebSearchLabel::startSearch()
}
QString WebSearchLabel::getDefultStyleSheet()
{
return m_defultStyleSheet;
}
bool WebSearchLabel::eventFilter(QObject *watched, QEvent *event)
{
if (watched == this) {
@ -65,7 +70,7 @@ bool WebSearchLabel::eventFilter(QObject *watched, QEvent *event)
this->setStyleSheet("background-color: #87CEFA");//TODO鼠标悬浮颜色待定
return true;
} else if(event->type() == QEvent::Leave) {
this->setStyleSheet("background-color: #DCDCDC");//默认颜色
this->setStyleSheet(m_defultStyleSheet);//默认颜色
return true;
}
}

View File

@ -13,16 +13,19 @@ public:
WebSearchLabel(QWidget * parent = nullptr);
~WebSearchLabel() = default;
void startSearch();
QString getDefultStyleSheet();
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;
QString m_defultStyleSheet;
public Q_SLOTS:
void webSearch(const QString &key);

View File

@ -32,7 +32,7 @@ SearchLineEdit::SearchLineEdit(QWidget *parent) : QLineEdit(parent) {
setStyle(new LineEditStyle());
this->setFocusPolicy(Qt::StrongFocus);
this->setFixedSize(680, 50);
this->setTextMargins(25, 0, 0, 0);
this->setTextMargins(35, 0, 0, 0);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setDragEnabled(true);
@ -91,6 +91,11 @@ void SearchLineEdit::paintEvent(QPaintEvent *e)
return QLineEdit::paintEvent(e);
}
void SearchLineEdit::focusOutEvent(QFocusEvent *e)
{
this->setFocus();
}
SeachBarWidget::SeachBarWidget(QWidget *parent): QWidget(parent) {
m_ly = new QHBoxLayout(this);
m_searchLineEdit = new SearchLineEdit(this);

View File

@ -46,6 +46,8 @@ public:
~SearchLineEdit();
protected:
void paintEvent(QPaintEvent *);
void focusOutEvent(QFocusEvent *);
Q_SIGNALS:
void requestSearchKeyword(QString text);
private:
@ -63,6 +65,7 @@ public:
void clear();
void reSearch();
protected:
void paintEvent(QPaintEvent *e);

View File

@ -75,6 +75,232 @@ void ResultArea::setVisibleList(const QStringList &list)
}
}
void ResultArea::pressEnter()
{
if (false == m_is_selected) {//未选中时默认选取bestlist第一项
int resultNum = m_bestListWidget->getResultNum();
if (0 == resultNum) {//搜索结果为空则选中网页搜索项
m_webSearchLable->setStyleSheet("background-color: #3790FA");//#3790FA选中颜色;
m_selectedPluginID = m_WebTitleLabel->text();
m_is_selected = true;
} else {//选取bestlist第一项
QModelIndex index = m_bestListWidget->getModlIndex(0, 0);
m_bestListWidget->setResultSelection(index);
m_selectedPluginID = m_bestListWidget->getWidgetName();
m_is_selected = true;
}
} else {//选中状态时默认启动action首项
if (m_selectedPluginID == m_WebTitleLabel->text()) {//选中网页搜索则启动搜索
m_webSearchLable->startSearch();
} else {
//先判断详情页是否打开
if (m_detail_open_state) {
if (m_selectedPluginID == m_bestListWidget->getWidgetName()) {//最佳匹配
m_bestListWidget->activateIndex();
} else {
for (ResultWidget * i : m_widget_list) {
if (m_selectedPluginID == i->pluginId()) {
i->activateIndex();
break;
}
}
}
} else {//打开详情页
m_detail_open_state = true;
sendKeyPressSignal(m_selectedPluginID);
}
}
}
}
void ResultArea::pressDown()
{
if (m_selectedPluginID == m_WebTitleLabel->text()) {//当前为web search暂不处理
return;
} else if (m_selectedPluginID == m_bestListWidget->getWidgetName()) {
QModelIndex index = m_bestListWidget->getCurrentSelection();
int maxNum = m_bestListWidget->getExpandState() ?
m_bestListWidget->getResultNum() : (m_bestListWidget->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ?
m_bestListWidget->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT);
if (index.row() < maxNum - 1 and index.row() >= 0) {
int row = index.row();
QModelIndex setIndex = m_bestListWidget->getModlIndex(++row, 0);
m_bestListWidget->setResultSelection(setIndex);
sendKeyPressSignal(m_selectedPluginID);
} else if (index.row() == maxNum - 1 or index.row() < 0) {//跳转下一个widget
m_bestListWidget->clearResultSelection();
for (ResultWidget * plugin : m_widget_list) {
if (plugin->getResultNum() != 0) {
QModelIndex resultIndex = plugin->getModlIndex(0, 0);
plugin->setResultSelection(resultIndex);
m_selectedPluginID = plugin->pluginId();
sendKeyPressSignal(m_selectedPluginID);
break;
}
}
} else {
qWarning() << "QModelIndex error ! row:" << index.row() << "maxNum:" << maxNum;
}
} else {
for (ResultWidget * plugin : m_widget_list) {
if (m_selectedPluginID == plugin->pluginId()) {
QModelIndex index = plugin->getCurrentSelection();
int maxNum = plugin->getExpandState() ?
plugin->getResultNum() : (plugin->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ?
plugin->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT);
if (index.row() < maxNum - 1 and index.row() >= 0) {
int row = index.row();
QModelIndex setIndex = plugin->getModlIndex(++row, 0);
plugin->setResultSelection(setIndex);
sendKeyPressSignal(m_selectedPluginID);
} else if (index.row() == maxNum - 1 or index.row() < 0) {//跳转下一个widget
plugin->clearResultSelection();
int indexNum = m_widget_list.indexOf(plugin);
bool findNextWidget = false;
while (++indexNum < m_widget_list.size()) {
plugin = m_widget_list[indexNum];
if (plugin->getResultNum() != 0) {
QModelIndex resultIndex = plugin->getModlIndex(0, 0);
plugin->setResultSelection(resultIndex);
m_selectedPluginID = plugin->pluginId();
findNextWidget = true;
sendKeyPressSignal(m_selectedPluginID);
break;
}
}
if (indexNum >= m_widget_list.size()) {//下一项是web search
m_webSearchLable->setStyleSheet("background-color: #3790FA");//#3790FA选中颜色;
m_selectedPluginID = m_WebTitleLabel->text();
m_is_selected = true;
}
if (findNextWidget){
break;
}
} else {
qWarning() << "QModelIndex error ! row:" << index.row() << "maxNum:" << maxNum;
}
}
}
}
}
void ResultArea::pressUp()
{
if (!m_is_selected) {
return;
}
if (m_selectedPluginID == m_WebTitleLabel->text()) {//当前为web search
if (m_bestListWidget->getResultNum() == 0) {
return;
}
m_webSearchLable->setStyleSheet(m_webSearchLable->getDefultStyleSheet());
for (int i = 0; i < m_widget_list.size(); i++) {
ResultWidget * plugin = m_widget_list[m_widget_list.size() - (i + 1)];
bool findNextWidget = false;
if (0 != plugin->getResultNum()) {
int maxNum = plugin->getExpandState() ?
plugin->getResultNum() : (plugin->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ?
plugin->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT);
QModelIndex resultIndex = plugin->getModlIndex(maxNum - 1, 0);
plugin->setResultSelection(resultIndex);
m_selectedPluginID = plugin->pluginId();
findNextWidget = true;
sendKeyPressSignal(m_selectedPluginID);
}
if (findNextWidget) {
break;
}
}
} else if (m_selectedPluginID == m_bestListWidget->getWidgetName()) {
QModelIndex index = m_bestListWidget->getCurrentSelection();
int maxNum = m_bestListWidget->getExpandState() ?
m_bestListWidget->getResultNum() : (m_bestListWidget->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ?
m_bestListWidget->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT);
if (index.row() > 0) {
int row = index.row();
QModelIndex setIndex = m_bestListWidget->getModlIndex(--row, 0);
m_bestListWidget->setResultSelection(setIndex);
sendKeyPressSignal(m_selectedPluginID);
} else if (index.row() == 0) {
//已到最上层,暂不处理
} else {
qWarning() << "QModelIndex error ! row:" << index.row() << "maxNum:" << maxNum;
}
} else {
for (ResultWidget * plugin : m_widget_list) {
if (m_selectedPluginID == plugin->pluginId()) {
QModelIndex index = plugin->getCurrentSelection();
if (index.row() > 0) {
int row = index.row();
QModelIndex setIndex = plugin->getModlIndex(--row, 0);
plugin->setResultSelection(setIndex);
sendKeyPressSignal(m_selectedPluginID);
} else if (index.row() == 0) {//跳转下一个widget
plugin->clearResultSelection();
int indexNum = m_widget_list.indexOf(plugin);
bool findNextWidget = false;
while (--indexNum >= 0) {
plugin = m_widget_list[indexNum];
if (plugin->getResultNum() != 0) {
int maxNum = plugin->getExpandState() ?
plugin->getResultNum() : (plugin->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ?
plugin->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT);
QModelIndex resultIndex = plugin->getModlIndex(maxNum - 1, 0);
plugin->setResultSelection(resultIndex);
m_selectedPluginID = plugin->pluginId();
findNextWidget = true;
sendKeyPressSignal(m_selectedPluginID);
break;
}
}
if (indexNum < 0) {//下一项是best list
int bestListNum = m_bestListWidget->getExpandState() ?
m_bestListWidget->getResultNum() : (m_bestListWidget->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ?
m_bestListWidget->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT);
QModelIndex setIndex = m_bestListWidget->getModlIndex(--bestListNum, 0);
m_bestListWidget->setResultSelection(setIndex);
m_selectedPluginID = m_bestListWidget->getWidgetName();
m_is_selected = true;
sendKeyPressSignal(m_selectedPluginID);
}
if (findNextWidget){
break;
}
} else {
int maxNum = plugin->getExpandState() ?
plugin->getResultNum() : (plugin->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ?
plugin->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT);
QModelIndex setIndex = plugin->getModlIndex(maxNum - 1, 0);
plugin->setResultSelection(setIndex);
sendKeyPressSignal(m_selectedPluginID);
}
}
}
}
}
bool ResultArea::getSelectedState()
{
return m_is_selected;
}
void ResultArea::sendKeyPressSignal(QString &pluginID)
{
if (m_detail_open_state) {
if (pluginID == m_bestListWidget->getWidgetName()) {
QModelIndex index = m_bestListWidget->getCurrentSelection();
Q_EMIT this->keyPressChanged(m_bestListWidget->getPluginInfo(index), m_bestListWidget->getIndexResultInfo(index));
} else {
for (ResultWidget *plugin : m_widget_list) {
if (pluginID == plugin->pluginId()) {
QModelIndex index = plugin->getCurrentSelection();
Q_EMIT this->keyPressChanged(m_selectedPluginID, plugin->getIndexResultInfo(index));
}
}
}
}
}
void ResultArea::onWidgetSizeChanged()
{
int whole_height = 0;
@ -91,6 +317,19 @@ void ResultArea::onWidgetSizeChanged()
Q_EMIT this->resizeHeight(whole_height + spacing_height * (m_widget_list.length() - 1));
}
void ResultArea::setSelectionInfo(QString &pluginID)
{
m_detail_open_state = true;
m_is_selected = true;
m_selectedPluginID = pluginID;
if (m_selectedPluginID != m_bestListWidget->getWidgetName()) {
m_bestListWidget->clearResultSelection();
}
if (m_selectedPluginID != m_WebTitleLabel->text()) {
m_webSearchLable->setStyleSheet(m_webSearchLable->getDefultStyleSheet());
}
}
void ResultArea::initUi()
{
// this->verticalScrollBar()->setProperty("drawScrollBarGroove", false);
@ -111,6 +350,7 @@ void ResultArea::initUi()
m_mainLyt = new QVBoxLayout(m_widget);
m_widget->setLayout(m_mainLyt);
m_bestListWidget = new BestListWidget(this);
m_bestListWidget->clearResult();
m_mainLyt->addWidget(m_bestListWidget);
m_WebTitleLabel = new TitleLabel(this);
@ -131,8 +371,23 @@ void ResultArea::initConnections()
{
connect(this, &ResultArea::startSearch, m_bestListWidget, &BestListWidget::startSearch);
connect(this, &ResultArea::startSearch, m_webSearchLable, &WebSearchLabel::webSearch);
connect(this, &ResultArea::startSearch, this, [=] () {
m_detail_open_state = false;
m_is_selected = false;
if (m_selectedPluginID == m_WebTitleLabel->text()) {
m_webSearchLable->setStyleSheet(m_webSearchLable->getDefultStyleSheet());
}
});
connect(m_bestListWidget, &BestListWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged);
connect(m_bestListWidget, &BestListWidget::currentRowChanged, this, &ResultArea::currentRowChanged);
connect(m_bestListWidget, &BestListWidget::currentRowChanged, this, [=] () {
m_detail_open_state = true;
m_is_selected = true;
m_selectedPluginID = m_bestListWidget->getWidgetName();
if (m_selectedPluginID != m_WebTitleLabel->text()) {
m_webSearchLable->setStyleSheet(m_webSearchLable->getDefultStyleSheet());
}
});
connect(this, &ResultArea::clearSelectedRow, m_bestListWidget, &BestListWidget::clearSelectedRow);
connect(this, &ResultArea::resizeWidth, this, [=] (const int &size) {
m_bestListWidget->setFixedWidth(size);

View File

@ -38,14 +38,24 @@ public:
~ResultArea() = default;
void appendWidet(ResultWidget *);
void setVisibleList(const QStringList &);
void pressEnter();
void pressDown();
void pressUp();
void setResultSelection();
bool getSelectedState();
void sendKeyPressSignal(QString &pluginID);
public Q_SLOTS:
void onWidgetSizeChanged();
void setSelectionInfo(QString &pluginID);
private:
void initUi();
void initConnections();
void setupConnectionsForWidget(ResultWidget *);
QWidget * m_widget = nullptr;
QVBoxLayout * m_mainLyt = nullptr;
BestListWidget * m_bestListWidget = nullptr;
@ -53,10 +63,15 @@ private:
TitleLabel * m_WebTitleLabel = nullptr;
WebSearchLabel * m_webSearchLable = nullptr;
bool m_detail_open_state = false;
bool m_is_selected = false;
QString m_selectedPluginID;
Q_SIGNALS:
void startSearch(const QString &);
void stopSearch();
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
void keyPressChanged(const QString &, const SearchPluginIface::ResultInfo&);
void clearSelectedRow();
void resizeHeight(int height);
void resizeWidth(const int &);

View File

@ -55,6 +55,31 @@ void SearchResultPage::appendPlugin(const QString &plugin_id)
setupConnectionsForWidget(widget);
}
void SearchResultPage::pressEnter()
{
this->m_resultArea->pressEnter();
}
void SearchResultPage::pressUp()
{
this->m_resultArea->pressUp();
}
void SearchResultPage::pressDown()
{
this->m_resultArea->pressDown();
}
bool SearchResultPage::getSelectedState()
{
return m_resultArea->getSelectedState();
}
void SearchResultPage::sendResizeWidthSignal(int size)
{
Q_EMIT this->resizeWidth(size);
}
void SearchResultPage::paintEvent(QPaintEvent *event)
{
QPainter p(this);
@ -67,7 +92,6 @@ void SearchResultPage::paintEvent(QPaintEvent *event)
QPainterPath rectPath;
rectPath.addRoundedRect(this->rect().adjusted(10, 10, -10, -10), 6, 6);
// 画一个黑底
QPixmap pixmap(this->rect().size());
pixmap.fill(Qt::transparent);
@ -133,26 +157,34 @@ void SearchResultPage::initConnections()
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);
sendResizeWidthSignal(656);
});
connect(m_resultArea, &ResultArea::keyPressChanged, m_detailArea, &DetailArea::setWidgetInfo);
connect(m_resultArea, &ResultArea::keyPressChanged, this, [=] () {
sendResizeWidthSignal(280);
});
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);
sendResizeWidthSignal(280);
});
connect(this, &SearchResultPage::setSelectionInfo, m_resultArea, &ResultArea::setSelectionInfo);
}
void SearchResultPage::setupConnectionsForWidget(ResultWidget *widget)
{
connect(widget, &ResultWidget::currentRowChanged, m_detailArea, &DetailArea::setWidgetInfo);
connect(widget, &ResultWidget::currentRowChanged, this, &SearchResultPage::currentRowChanged);
connect(widget, &ResultWidget::currentRowChanged, this, [=] {
QString pluginID = widget->pluginId();
Q_EMIT this->setSelectionInfo(pluginID);
});
connect(this, &SearchResultPage::currentRowChanged, widget, &ResultWidget::clearSelectedRow);
connect(widget, &ResultWidget::rowClicked, this, [=] () {
Q_EMIT this->resizeWidth(280);
sendResizeWidthSignal(280);
});
connect(this, &SearchResultPage::resizeWidth, widget, &ResultWidget::resizeWidth);
}

View File

@ -34,6 +34,11 @@ public:
void setSize(const int&, const int&);
void setInternalPlugins();
void appendPlugin(const QString &plugin_id);
void pressEnter();
void pressUp();
void pressDown();
bool getSelectedState();
void sendResizeWidthSignal(int size);
protected:
void paintEvent(QPaintEvent *event);
@ -53,6 +58,7 @@ Q_SIGNALS:
void effectiveSearch();
void resizeHeight(int height);
void resizeWidth(const int &);
void setSelectionInfo(QString &);
};
}

View File

@ -27,7 +27,6 @@
#include <QScreen>
#include <QTranslator>
#include <QLocale>
#include <X11/Xlib.h>
#include <syslog.h>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
#include <ukui-log4qt.h>
@ -40,6 +39,7 @@
#include "global-settings.h"
#include "ukui-search-dbus-service.h"
#include "plugin-manager.h"
#include <X11/Xlib.h>
using namespace Zeeker;

View File

@ -24,7 +24,6 @@
#include <QHBoxLayout>
#include <QDebug>
#include <QDesktopWidget>
#include <QtX11Extras/QX11Info>
#include <syslog.h>
#include <QPalette>
#include <QScreen>
@ -36,6 +35,7 @@
#endif
#include "qt-single-application.h"
#include "global-settings.h"
#include <QtX11Extras/QX11Info>
#define MAIN_MARGINS 0, 0, 0, 0
#define TITLE_MARGINS 0,0,0,0
@ -66,6 +66,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAutoFillBackground(false);
this->setFocusPolicy(Qt::StrongFocus);
this->setFocusProxy(this);
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
this->setWindowTitle(tr("ukui-search"));
initUi();
@ -77,7 +78,6 @@ MainWindow::MainWindow(QWidget *parent) :
m_sys_tray_icon->show();
installEventFilter(this);
initConnections();
//NEW_TODO, register plugins
// SearchPluginManager::getInstance()->registerPlugin(\\);
// m_stackedWidget->setPlugins(SearchPluginManager::getInstance()->getPluginIds());
@ -127,6 +127,7 @@ void MainWindow::initUi() {
m_searchResultPage = new SearchResultPage(this);
m_searchResultPage->hide();
m_searchResultPage->move(0, 58);
// m_searchResultPage->show();
// m_searchWidget = new SeachBarWidget(this);
// m_searchLayout = new SearchBarHLayout(this);
@ -517,8 +518,23 @@ void MainWindow::setSearchMethod(const bool &is_index_search) {
*/
void MainWindow::keyPressEvent(QKeyEvent *event)
{
qDebug() << "press:" << event->key();
if (event->key() == Qt::Key_Escape) {
tryHideMainwindow();
} else if (event->key() == Qt::Key_Return or event->key() == Qt::Key_Enter) {
//显示最佳匹配中第一项的详情页,无搜索结果则调取网页搜索
qDebug() << "Press Enter";
m_searchResultPage->pressEnter();
} else if (event->key() == Qt::Key_Up) {
qDebug() << "Press ↑";
m_searchResultPage->pressUp();
} else if (event->key() == Qt::Key_Down) {
qDebug() << "Press ↓";
if (!m_searchResultPage->getSelectedState()) {
m_searchResultPage->pressEnter();
} else {
m_searchResultPage->pressDown();
}
}
return QWidget::keyPressEvent(event);
}

View File

@ -14,8 +14,7 @@ class BestListModel : public QAbstractItemModel
public:
explicit BestListModel(QObject *parent = nullptr);
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;

View File

@ -44,7 +44,7 @@ class SearchResultModel : public QAbstractItemModel
public:
SearchResultModel(const QString &plugin_id);
~SearchResultModel() = default;
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;

View File

@ -39,6 +39,26 @@ int BestListView::showHeight()
return height;
}
int BestListView::getResultNum()
{
return m_count;
}
QModelIndex BestListView::getModlIndex(int row, int column)
{
return this->m_model->index(row, column);
}
SearchPluginIface::ResultInfo BestListView::getIndexResultInfo(QModelIndex &index)
{
return this->m_model->getInfo(index);
}
const QString BestListView::getPluginInfo(const QModelIndex& index)
{
return this->m_model->getPluginInfo(index);
}
void BestListView::clearSelectedRow()
{
if (!m_is_selected) {
@ -77,17 +97,10 @@ void BestListView::onRowDoubleClickedSlot(const QModelIndex &index)
* @param selected
* @param deselected
*/
void BestListView::onRowSelectedSlot(const QItemSelection &selected, const QItemSelection &deselected)
void BestListView::onRowSelectedSlot(const QModelIndex &index)
{
//NEW_TODO
m_is_selected = true;
Q_EMIT this->currentRowChanged(m_model->getPluginInfo(this->currentIndex()), m_model->getInfo(this->currentIndex()));
m_is_selected = false;
if(!selected.isEmpty()) {
QRegion region = visualRegionForSelection(selected);
QRect rect = region.boundingRect();
// Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft()));
}
Q_EMIT this->currentRowChanged(m_model->getPluginInfo(index), m_model->getInfo(index));
}
void BestListView::onItemListChanged(const int &count)
@ -123,20 +136,20 @@ void BestListView::onMenuTriggered(QAction *action)
void BestListView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
//加一点点延时,等待列表先被选中
QTimer::singleShot(10, this, [ = ] {
QMenu * menu = new QMenu(this);
QStringList actions = m_model->getActions(this->currentIndex());
Q_FOREACH (QString action, actions) {
menu->addAction(new QAction(action, this));
}
menu->move(cursor().pos());
menu->show();
connect(menu, &QMenu::triggered, this, &BestListView::onMenuTriggered);
});
}
Q_EMIT this->rowClicked();
// if (event->button() == Qt::RightButton) {
// //加一点点延时,等待列表先被选中
// QTimer::singleShot(10, this, [ = ] {
// QMenu * menu = new QMenu(this);
// QStringList actions = m_model->getActions(this->currentIndex());
// Q_FOREACH (QString action, actions) {
// menu->addAction(new QAction(action, this));
// }
// menu->move(cursor().pos());
// menu->show();
// connect(menu, &QMenu::triggered, this, &BestListView::onMenuTriggered);
// });
// }
// Q_EMIT this->rowClicked();
return QTreeView::mousePressEvent(event);
}
@ -148,7 +161,7 @@ void BestListView::initConnections()
m_model->startSearch(keyword);
});
connect(this, &BestListView::startSearch, m_model, &BestListModel::startSearch);
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &BestListView::onRowSelectedSlot);
connect(this, &BestListView::clicked, this, &BestListView::onRowSelectedSlot);
connect(this, &BestListView::activated, this, &BestListView::onRowDoubleClickedSlot);
connect(m_model, &BestListModel::itemListChanged, this, &BestListView::onItemListChanged);
connect(this, &BestListView::sendBestListData, m_model, &BestListModel::appendInfo);
@ -160,11 +173,68 @@ BestListWidget::BestListWidget(QWidget *parent) : QWidget(parent)
initConnections();
}
QString BestListWidget::getWidgetName()
{
return m_titleLabel->text();
}
void BestListWidget::setEnabled(const bool &enabled)
{
m_enabled = enabled;
}
void BestListWidget::clearResult()
{
this->setVisible(false);
this->setFixedHeight(0);
}
int BestListWidget::getResultNum()
{
return m_bestListView->getResultNum();
}
void BestListWidget::setResultSelection(const QModelIndex &index)
{
this->m_bestListView->selectionModel()->clearSelection();
this->m_bestListView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
}
void BestListWidget::clearResultSelection()
{
this->m_bestListView->selectionModel()->clearSelection();
}
QModelIndex BestListWidget::getModlIndex(int row, int column)
{
return this->m_bestListView->getModlIndex(row, column);
}
void BestListWidget::activateIndex()
{
this->m_bestListView->onRowDoubleClickedSlot(this->m_bestListView->currentIndex());
}
QModelIndex BestListWidget::getCurrentSelection()
{
return this->m_bestListView->currentIndex();
}
bool BestListWidget::getExpandState()
{
return m_bestListView->isExpanded();
}
SearchPluginIface::ResultInfo BestListWidget::getIndexResultInfo(QModelIndex &index)
{
return m_bestListView->getIndexResultInfo(index);
}
const QString BestListWidget::getPluginInfo(const QModelIndex&index)
{
return this->m_bestListView->getPluginInfo(index);
}
/**
* @brief BestListWidget::expandListSlot
*/
@ -225,7 +295,7 @@ void BestListWidget::initConnections()
connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &BestListWidget::expandListSlot);
connect(m_titleLabel, &TitleLabel::retractClicked, this, &BestListWidget::reduceListSlot);
connect(m_bestListView, &BestListView::listLengthChanged, this, &BestListWidget::onListLengthChanged);
connect(m_bestListView, &BestListView::rowClicked, this, &BestListWidget::rowClicked);
connect(m_bestListView, &BestListView::clicked, this, &BestListWidget::rowClicked);
connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
int whole_height = this->isVisible() ? m_bestListView->showHeight() + TITLE_HEIGHT : 0;
this->setFixedHeight(whole_height);

View File

@ -18,13 +18,18 @@ class BestListView : public QTreeView
public:
BestListView(QWidget *parent = nullptr);
~BestListView() = default;
bool isSelected();
int showHeight();
int getResultNum();
QModelIndex getModlIndex(int row, int column);
SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index);
const QString getPluginInfo(const QModelIndex&index);
public Q_SLOTS:
void clearSelectedRow();
void onRowDoubleClickedSlot(const QModelIndex &);
void onRowSelectedSlot(const QItemSelection &, const QItemSelection &);
void onRowSelectedSlot(const QModelIndex &index);
void onItemListChanged(const int &);
void setExpanded(const bool &);
const bool &isExpanded();
@ -35,6 +40,7 @@ protected:
private:
void initConnections();
BestListModel * m_model = nullptr;
bool m_is_selected = false;
ResultViewDelegate * m_style_delegate = nullptr;
@ -56,22 +62,34 @@ class BestListWidget : public QWidget
public:
BestListWidget(QWidget *parent = nullptr);
~BestListWidget() = default;
QString getWidgetName();
void setEnabled(const bool&);
void clearResult();
int getResultNum();
void setResultSelection(const QModelIndex &index);
void clearResultSelection();
QModelIndex getModlIndex(int row, int column);
void activateIndex();
QModelIndex getCurrentSelection();
bool getExpandState();
SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index);
const QString getPluginInfo(const QModelIndex&index);
private:
void initUi();
void initConnections();
bool m_enabled = true;
QVBoxLayout * m_mainLyt = nullptr;
TitleLabel * m_titleLabel = nullptr;
BestListView * m_bestListView = nullptr;
public Q_SLOTS:
void expandListSlot();
void reduceListSlot();
void onListLengthChanged(const int &);
private:
bool m_enabled = true;
void initUi();
void initConnections();
QVBoxLayout * m_mainLyt = nullptr;
TitleLabel * m_titleLabel = nullptr;
BestListView * m_bestListView = nullptr;
Q_SIGNALS:
void startSearch(const QString &);
void stopSearch();
@ -80,6 +98,7 @@ Q_SIGNALS:
void clearSelectedRow();
void sizeChanged();
void rowClicked();
};
}

View File

@ -28,6 +28,47 @@ void ResultWidget::clearResult()
this->setFixedHeight(0);
}
int ResultWidget::getResultNum()
{
return m_resultView->getResultNum();
}
void ResultWidget::setResultSelection(const QModelIndex &index)
{
this->m_resultView->selectionModel()->clearSelection();
this->m_resultView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
}
void ResultWidget::clearResultSelection()
{
this->m_resultView->selectionModel()->clearSelection();
}
QModelIndex ResultWidget::getModlIndex(int row, int column)
{
return this->m_resultView->getModlIndex(row, column);
}
void ResultWidget::activateIndex()
{
this->m_resultView->onRowDoubleClickedSlot(this->m_resultView->currentIndex());
}
QModelIndex ResultWidget::getCurrentSelection()
{
return this->m_resultView->currentIndex();
}
bool ResultWidget::getExpandState()
{
return m_resultView->isExpanded();
}
SearchPluginIface::ResultInfo ResultWidget::getIndexResultInfo(QModelIndex &index)
{
return m_resultView->getIndexResultInfo(index);
}
/**
* @brief ResultWidget::expandListSlot
*/
@ -88,7 +129,7 @@ void ResultWidget::initConnections()
connect(m_titleLabel, &TitleLabel::retractClicked, this, &ResultWidget::reduceListSlot);
connect(m_resultView, &ResultView::listLengthChanged, this, &ResultWidget::onListLengthChanged);
connect(m_resultView, &ResultView::listLengthChanged, m_titleLabel, &TitleLabel::onListLengthChanged);
connect(m_resultView, &ResultView::rowClicked, this, &ResultWidget::rowClicked);
connect(m_resultView, &ResultView::clicked, this, &ResultWidget::rowClicked);
connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
int whole_height = this->isVisible() ? m_resultView->showHeight() + TITLE_HEIGHT : 0;
this->setFixedHeight(whole_height);
@ -136,6 +177,21 @@ int ResultView::showHeight()
return height;
}
int ResultView::getResultNum()
{
return m_count;
}
QModelIndex ResultView::getModlIndex(int row, int column)
{
return this->m_model->index(row, column);
}
SearchPluginIface::ResultInfo ResultView::getIndexResultInfo(QModelIndex &index)
{
return this->m_model->getInfo(index);
}
void ResultView::clearSelectedRow()
{
if (!m_is_selected) {
@ -175,17 +231,16 @@ void ResultView::onRowDoubleClickedSlot(const QModelIndex &index)
* @param selected
* @param deselected
*/
void ResultView::onRowSelectedSlot(const QItemSelection &selected, const QItemSelection &deselected)
void ResultView::onRowSelectedSlot(const QModelIndex &index)
{
//NEW_TODO
m_is_selected = true;
Q_EMIT this->currentRowChanged(m_plugin_id, m_model->getInfo(this->currentIndex()));
if(!selected.isEmpty()) {
QRegion region = visualRegionForSelection(selected);
QRect rect = region.boundingRect();
// Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft()));
}
Q_EMIT this->currentRowChanged(m_plugin_id, m_model->getInfo(index));
// if(!selected.isEmpty()) {
// QRegion region = visualRegionForSelection(selected);
// QRect rect = region.boundingRect();
//// Q_EMIT this->currentSelectPos(mapToParent(rect.topLeft()));
// }
}
void ResultView::onItemListChanged(const int &count)
@ -221,20 +276,20 @@ void ResultView::onMenuTriggered(QAction *action)
void ResultView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
//加一点点延时,等待列表先被选中
QTimer::singleShot(10, this, [ = ] {
QMenu * menu = new QMenu(this);
QStringList actions = m_model->getActions(this->currentIndex());
Q_FOREACH (QString action, actions) {
menu->addAction(new QAction(action, this));
}
menu->move(cursor().pos());
menu->show();
connect(menu, &QMenu::triggered, this, &ResultView::onMenuTriggered);
});
}
Q_EMIT this->rowClicked();
// if (event->button() == Qt::RightButton) {
// //加一点点延时,等待列表先被选中
// QTimer::singleShot(10, this, [ = ] {
// QMenu * menu = new QMenu(this);
// QStringList actions = m_model->getActions(this->currentIndex());
// Q_FOREACH (QString action, actions) {
// menu->addAction(new QAction(action, this));
// }
// menu->move(cursor().pos());
// menu->show();
// connect(menu, &QMenu::triggered, this, &ResultView::onMenuTriggered);
// });
// }
// Q_EMIT this->rowClicked();
return QTreeView::mousePressEvent(event);
}
@ -247,7 +302,8 @@ void ResultView::initConnections()
m_model->startSearch(keyword);
});
connect(this, &ResultView::stopSearch, m_model, &SearchResultModel::stopSearch);
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ResultView::onRowSelectedSlot);
//connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ResultView::onRowSelectedSlot);
connect(this, &ResultView::clicked, this, &ResultView::onRowSelectedSlot);
connect(this, &ResultView::activated, this, &ResultView::onRowDoubleClickedSlot);
connect(m_model, &SearchResultModel::itemListChanged, this, &ResultView::onItemListChanged);
connect(m_model, &SearchResultModel::sendBestListData, this, &ResultView::sendBestListData);

View File

@ -20,11 +20,14 @@ public:
~ResultView() = default;
bool isSelected();
int showHeight();
int getResultNum();
QModelIndex getModlIndex(int row, int column);
SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index);
public Q_SLOTS:
void clearSelectedRow();
void onRowDoubleClickedSlot(const QModelIndex &);
void onRowSelectedSlot(const QItemSelection &, const QItemSelection &);
void onRowSelectedSlot(const QModelIndex &index);
void onItemListChanged(const int &);
void setExpanded(const bool &);
const bool &isExpanded();
@ -60,6 +63,14 @@ public:
QString pluginId();
void setEnabled(const bool&);
void clearResult();
int getResultNum();
void setResultSelection(const QModelIndex &index);
void clearResultSelection();
QModelIndex getModlIndex(int row, int column);
void activateIndex();
QModelIndex getCurrentSelection();
bool getExpandState();
SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index);
public Q_SLOTS:
void expandListSlot();