新增点击搜索结果展开后置顶当前分类功能;新增展开搜索结果后标题栏置顶悬浮功能;

This commit is contained in:
jixiaoxu 2021-10-20 16:30:20 +08:00
parent 7c0e9f55a2
commit 6f6e6a9377
10 changed files with 148 additions and 50 deletions

View File

@ -30,7 +30,13 @@ ShowMoreLabel::ShowMoreLabel(QWidget *parent) : QWidget(parent) {
void ShowMoreLabel::resetLabel() {
m_isOpen = false;
m_textLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16)));
m_iconLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16)));
}
void ShowMoreLabel::setLabel()
{
m_isOpen = true;
m_iconLabel->setPixmap(QIcon::fromTheme("pan-up-symbolic").pixmap(QSize(16, 16)));
}
/**
@ -46,30 +52,30 @@ void ShowMoreLabel::initUi() {
pal.setColor(QPalette::WindowText, QColor(55, 144, 250, 255));
m_layout = new QHBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 6);
m_textLabel = new QLabel(this);
m_textLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16)));
m_textLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_textLabel->installEventFilter(this);
m_iconLabel = new QLabel(this);
m_iconLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16)));
m_iconLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_iconLabel->installEventFilter(this);
// m_loadingIconLabel = new QLabel(this); //使用图片显示加载状态时取消此label的注释
// m_loadingIconLabel->setFixedSize(18, 18);
// m_loadingIconLabel->hide();
m_layout->setAlignment(Qt::AlignRight | Qt::AlignTop);
m_layout->addWidget(m_textLabel);
m_textLabel->setPalette(pal);
m_textLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_layout->addWidget(m_iconLabel);
m_iconLabel->setPalette(pal);
m_iconLabel->setCursor(QCursor(Qt::PointingHandCursor));
// m_layout->addWidget(m_loadingIconLabel);
}
bool ShowMoreLabel::eventFilter(QObject *watched, QEvent *event) {
if(watched == m_textLabel) {
if(watched == m_iconLabel) {
if(event->type() == QEvent::MouseButtonPress) {
if(! m_timer->isActive()) {
if(!m_isOpen) {
m_textLabel->setPixmap(QIcon::fromTheme("pan-up-symbolic").pixmap(QSize(16, 16)));
m_iconLabel->setPixmap(QIcon::fromTheme("pan-up-symbolic").pixmap(QSize(16, 16)));
m_isOpen = true;
Q_EMIT this->showMoreClicked();
} else {
m_textLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16)));
m_iconLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16)));
m_isOpen = false;
Q_EMIT this->retractClicked();
}

View File

@ -33,6 +33,7 @@ public:
explicit ShowMoreLabel(QWidget *parent = nullptr);
~ShowMoreLabel() = default;
void resetLabel();
void setLabel();
bool getExpanded();
protected:
@ -40,7 +41,7 @@ protected:
private:
QHBoxLayout * m_layout = nullptr;
QLabel * m_textLabel = nullptr;
QLabel * m_iconLabel = nullptr;
QLabel * m_loadingIconLabel = nullptr;
QTimer * m_timer = nullptr;
bool m_isOpen = false;

View File

@ -29,6 +29,12 @@ TitleLabel::TitleLabel(QWidget * parent) : QLabel(parent) {
initConnections();
}
void TitleLabel::setShowMoreLableVisible()
{
m_showMoreLabel->setVisible(true);
m_showMoreLabel->setLabel();
}
void TitleLabel::initUi() {
this->setContentsMargins(8, 0, 0, 0);
this->setFixedHeight(24);

View File

@ -32,6 +32,8 @@ public:
TitleLabel(QWidget * parent = nullptr);
~TitleLabel() = default;
void setShowMoreLableVisible();
protected:
void paintEvent(QPaintEvent *);

View File

@ -38,6 +38,8 @@ using namespace Zeeker;
#define ACTION_HOVER_COLOR QColor(64, 169, 251, 255)
#define ACTION_PRESS_COLOR QColor(41, 108, 217, 255)
#define TITLE_HEIGHT 30
#define FRAME_HEIGHT 516
#define DETAIL_FRAME_WIDTH 376
ResultArea::ResultArea(QWidget *parent) : QScrollArea(parent)
{
@ -425,6 +427,9 @@ void ResultArea::initUi()
m_mainLyt->setContentsMargins(RESULT_LAYOUT_MARGINS);
this->widget()->setContentsMargins(0,0,0,0);
m_mainLyt->setSpacing(0);
m_titleLable = new TitleLabel(this);
m_titleLable->hide();
}
void ResultArea::initConnections()
@ -461,13 +466,75 @@ void ResultArea::initConnections()
m_webSearchWidget->setFixedWidth(size);
});
connect(m_bestListWidget, &BestListWidget::rowClicked, this, &ResultArea::rowClicked);
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] (int value) {//判断显示和隐藏逻辑
Q_FOREACH(auto widget, m_widget_list) {
if (!widget->getExpandState()) {
continue;
}
if (value < (widget->pos().ry() + TITLE_HEIGHT)
or value > (widget->pos().ry() + widget->height() - FRAME_HEIGHT + 2*TITLE_HEIGHT)) {//暂定下一项标题显示完全后悬浮标题隐藏
if (!m_titleLable->isHidden()) {
m_titleLable->hide();
this->setViewportMargins(0,0,0,0);
}
} else {
if (m_titleLable->isHidden()) {
m_titleLable->setText(widget->pluginId());
m_titleLable->setShowMoreLableVisible();//防止多项展开后无法收回其他项
m_titleLable->show();
this->setViewportMargins(0,TITLE_HEIGHT,0,0);
}
break;
}
}
});
connect(this->m_titleLable, &TitleLabel::retractClicked, this, [=] () {
Q_FOREACH(auto widget, m_widget_list) {
if (widget->pluginId() == m_titleLable->text()) {
widget->reduceListSlot();
widget->resetTitleLabel();
if (!m_titleLable->isHidden()) {
m_titleLable->hide();
this->setViewportMargins(0,0,0,0);
}
}
}
});
connect(this, &ResultArea::resizeWidth, this, [=] (int size) {
m_titleLable->setFixedWidth(size);
});
}
void ResultArea::setupConnectionsForWidget(ResultWidget *widget)
{
connect(this, &ResultArea::startSearch, widget, &ResultWidget::startSearch);
connect(this, &ResultArea::startSearch, this, [=] () {
if (!m_titleLable->isHidden()) {
m_titleLable->hide();
this->setViewportMargins(0,0,0,0);
}
});
connect(this, &ResultArea::stopSearch, widget, &ResultWidget::stopSearch);
connect(widget, &ResultWidget::sizeChanged, this, &ResultArea::onWidgetSizeChanged);
connect(widget, &ResultWidget::showMoreClicked, this, [=] () {//点击展开搜索结果后 显示悬浮窗
this->verticalScrollBar()->setValue(widget->pos().ry() + TITLE_HEIGHT); //置顶当前类型搜索结果
if (widget->height() > FRAME_HEIGHT) {//当前widget高度大于搜索结果界面高度则显示悬浮窗
viewport()->stackUnder(m_titleLable);
m_titleLable->setText(widget->pluginId());
m_titleLable->setFixedSize(widget->width(), TITLE_HEIGHT);
m_titleLable->setShowMoreLableVisible();
if (m_titleLable->isHidden()) {
m_titleLable->show();
this->setViewportMargins(0,TITLE_HEIGHT,0,0);
}
}
});
connect(widget, &ResultWidget::retractClicked, this, [=] () {//点击收起搜索结果后
if (!m_titleLable->isHidden()) {
m_titleLable->hide();
this->setViewportMargins(0,0,0,0);
}
});
connect(widget, &ResultWidget::sendBestListData, m_bestListWidget, &BestListWidget::sendBestListData);
}
@ -491,7 +558,7 @@ void DetailArea::initUi()
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
this->setWidgetResizable(true);
this->setFixedSize(376, 516);
this->setFixedSize(DETAIL_FRAME_WIDTH, FRAME_HEIGHT);
// this->setStyleSheet("QScrollArea{border:2px solid red;}");
this->setContentsMargins(0,0,0,0);
m_detailWidget = new DetailWidget(this);

View File

@ -67,6 +67,7 @@ private:
BestListWidget * m_bestListWidget = nullptr;
QList<ResultWidget *> m_widget_list;
WebSearchWidget * m_webSearchWidget = nullptr;
TitleLabel * m_titleLable = nullptr;
bool m_detail_open_state = false;
bool m_is_selected = false;

View File

@ -120,19 +120,19 @@ private:
// StackedWidget * m_stackedWidget = nullptr; // Stacked widget
// SearchBarHLayout * m_searchLayout = nullptr; // Search bar layout
// SeachBarWidget * m_searchWidget = nullptr; // Search bar
SeachBarWidget *m_searchBarWidget;
SearchResultPage *m_searchResultPage;
SeachBarWidget * m_searchBarWidget;
SearchResultPage * m_searchResultPage;
#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;
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;
QSystemTrayIcon * m_sys_tray_icon = nullptr;
CreateIndexAskDialog * m_askDialog = nullptr;
bool m_isAskDialogVisible = false;

View File

@ -105,8 +105,11 @@ void BestListView::onRowDoubleClickedSlot(const QModelIndex &index)
*/
void BestListView::onRowSelectedSlot(const QModelIndex &index)
{
m_is_selected = true;
Q_EMIT this->currentRowChanged(m_model->getPluginInfo(index), m_model->getInfo(index));
if (index.isValid()) {
m_is_selected = true;
this->setCurrentIndex(index);
Q_EMIT this->currentRowChanged(m_model->getPluginInfo(index), m_model->getInfo(index));
}
}
void BestListView::onItemListChanged(const int &count)
@ -155,22 +158,22 @@ void BestListView::mousePressEvent(QMouseEvent *event)
void BestListView::mouseReleaseEvent(QMouseEvent *event)
{
// QModelIndex index = indexAt(event->pos());
// if (index.isValid()) {
// Q_EMIT this->clicked(index);
// } else {
// Q_EMIT this->clicked(this->currentIndex());
// }
QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
Q_EMIT this->clicked(index);
} else {
Q_EMIT this->clicked(this->currentIndex());
}
return QTreeView::mouseReleaseEvent(event);
}
void BestListView::mouseMoveEvent(QMouseEvent *event)
{
// m_tmpCurrentIndex = this->currentIndex();
// m_tmpMousePressIndex = indexAt(event->pos());
// if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
// Q_EMIT this->clicked(m_tmpMousePressIndex);
// }
m_tmpCurrentIndex = this->currentIndex();
m_tmpMousePressIndex = indexAt(event->pos());
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
Q_EMIT this->clicked(m_tmpMousePressIndex);
}
return QTreeView::mouseMoveEvent(event);
}

View File

@ -71,6 +71,17 @@ SearchPluginIface::ResultInfo ResultWidget::getIndexResultInfo(QModelIndex &inde
return m_resultView->getIndexResultInfo(index);
}
void ResultWidget::resetTitleLabel()
{
Q_EMIT this->m_titleLabel->lableReset();
}
void ResultWidget::setTitileLableHide(bool state)
{
m_titleLabel->setVisible(state);
}
/**
* @brief ResultWidget::expandListSlot
*/
@ -128,7 +139,9 @@ void ResultWidget::initConnections()
connect(m_resultView, &ResultView::currentRowChanged, this, &ResultWidget::currentRowChanged);
connect(this, &ResultWidget::clearSelectedRow, m_resultView, &ResultView::clearSelectedRow);
connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &ResultWidget::expandListSlot);
connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &ResultWidget::showMoreClicked);
connect(m_titleLabel, &TitleLabel::retractClicked, this, &ResultWidget::reduceListSlot);
connect(m_titleLabel, &TitleLabel::retractClicked, this, &ResultWidget::retractClicked);
connect(m_resultView, &ResultView::listLengthChanged, this, &ResultWidget::onListLengthChanged);
connect(m_resultView, &ResultView::listLengthChanged, m_titleLabel, &TitleLabel::onListLengthChanged);
connect(m_resultView, &ResultView::clicked, this, &ResultWidget::rowClicked);
@ -236,16 +249,11 @@ void ResultView::onRowDoubleClickedSlot(const QModelIndex &index)
*/
void ResultView::onRowSelectedSlot(const QModelIndex &index)
{
//NEW_TODO
m_is_selected = true;
if(index.isValid()) {
m_is_selected = true;
this->setCurrentIndex(index);
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)
@ -295,22 +303,22 @@ void ResultView::mousePressEvent(QMouseEvent *event)
void ResultView::mouseReleaseEvent(QMouseEvent *event)
{
// QModelIndex index = indexAt(event->pos());
// if (index.isValid()) {
// Q_EMIT this->clicked(index);
// } else {
// Q_EMIT this->clicked(this->currentIndex());
// }
QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
Q_EMIT this->clicked(index);
} else {
Q_EMIT this->clicked(this->currentIndex());
}
return QTreeView::mouseReleaseEvent(event);
}
void ResultView::mouseMoveEvent(QMouseEvent *event)
{
// m_tmpCurrentIndex = this->currentIndex();
// m_tmpMousePressIndex = indexAt(event->pos());
// if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex and event->source() != Qt::MouseEventSynthesizedByQt) {
// Q_EMIT this->clicked(m_tmpMousePressIndex);
// }
m_tmpCurrentIndex = this->currentIndex();
m_tmpMousePressIndex = indexAt(event->pos());
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex and event->source() != Qt::MouseEventSynthesizedByQt) {
Q_EMIT this->clicked(m_tmpMousePressIndex);
}
return QTreeView::mouseMoveEvent(event);
}

View File

@ -75,6 +75,8 @@ public:
QModelIndex getCurrentSelection();
bool getExpandState();
SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index);
void resetTitleLabel();
void setTitileLableHide(bool state);
public Q_SLOTS:
void expandListSlot();
@ -100,6 +102,8 @@ Q_SIGNALS:
void sizeChanged();
void rowClicked();
void resizeWidth(const int &);
void showMoreClicked();
void retractClicked();
};
}