Fix the problem that the right side of each result is blocked in tablet mode.

This commit is contained in:
JunjieBai 2022-12-13 11:22:30 +08:00
parent c749aa7b83
commit 1e51726207
4 changed files with 74 additions and 5 deletions

View File

@ -301,6 +301,14 @@ void ResultArea::pressUp()
} }
} }
int ResultArea::getVScrollBarWidth()
{
if (verticalScrollBar()->isVisible()) {
return this->verticalScrollBar()->width();
}
return 0;
}
bool ResultArea::getSelectedState() bool ResultArea::getSelectedState()
{ {
return m_is_selected; return m_is_selected;
@ -414,6 +422,8 @@ bool ResultArea::viewportEvent(QEvent *event)
void ResultArea::initUi() void ResultArea::initUi()
{ {
m_scrollBar = new ResultScrollBar(this);
this->setVerticalScrollBar(m_scrollBar);
// this->verticalScrollBar()->setProperty("drawScrollBarGroove", false); // this->verticalScrollBar()->setProperty("drawScrollBarGroove", false);
QPalette pal = palette(); QPalette pal = palette();
QPalette scroll_bar_pal = this->verticalScrollBar()->palette(); QPalette scroll_bar_pal = this->verticalScrollBar()->palette();
@ -518,6 +528,8 @@ void ResultArea::initConnections()
connect(this, &ResultArea::resizeWidth, this, [=] (int size) { connect(this, &ResultArea::resizeWidth, this, [=] (int size) {
m_titleLabel->setFixedWidth(size); m_titleLabel->setFixedWidth(size);
}); });
connect(m_scrollBar, &ResultScrollBar::scrollBarAppeared, this, &ResultArea::scrollBarAppeared);
connect(m_scrollBar, &ResultScrollBar::scrollBarIsHideen, this, &ResultArea::scrollBarIsHideen);
} }
void ResultArea::setupConnectionsForWidget(ResultWidget *widget) void ResultArea::setupConnectionsForWidget(ResultWidget *widget)
@ -821,3 +833,20 @@ void DetailWidget::clearLayout(QLayout *layout)
// } // }
// } // }
//} //}
ResultScrollBar::ResultScrollBar(QWidget *parent) : QScrollBar(parent)
{
}
void ResultScrollBar::showEvent(QShowEvent *event)
{
Q_EMIT this->scrollBarAppeared();
return QScrollBar::showEvent(event);
}
void ResultScrollBar::hideEvent(QHideEvent *event)
{
Q_EMIT this->scrollBarIsHideen();
return QScrollBar::hideEvent(event);
}

View File

@ -21,6 +21,7 @@
#ifndef SEARCHPAGESECTION_H #ifndef SEARCHPAGESECTION_H
#define SEARCHPAGESECTION_H #define SEARCHPAGESECTION_H
#include <QScrollArea> #include <QScrollArea>
#include <QScrollBar>
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QStyleOption> #include <QStyleOption>
@ -30,6 +31,22 @@
#include "web-search-view.h" #include "web-search-view.h"
namespace UkuiSearch { namespace UkuiSearch {
class ResultScrollBar : public QScrollBar
{
Q_OBJECT
public:
ResultScrollBar(QWidget *parent = nullptr);
~ResultScrollBar() = default;
protected:
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
Q_SIGNALS:
void scrollBarAppeared();
void scrollBarIsHideen();
};
class ResultArea : public QScrollArea class ResultArea : public QScrollArea
{ {
Q_OBJECT Q_OBJECT
@ -44,6 +61,7 @@ public:
void pressEnter(); void pressEnter();
void pressDown(); void pressDown();
void pressUp(); void pressUp();
int getVScrollBarWidth();
void setResultSelection(); void setResultSelection();
bool getSelectedState(); bool getSelectedState();
@ -71,6 +89,7 @@ private:
BestListWidget * m_bestListWidget = nullptr; BestListWidget * m_bestListWidget = nullptr;
QList<ResultWidget *> m_widget_list; QList<ResultWidget *> m_widget_list;
TitleLabel * m_titleLabel = nullptr; TitleLabel * m_titleLabel = nullptr;
ResultScrollBar *m_scrollBar = nullptr;
bool m_detail_open_state = false; bool m_detail_open_state = false;
bool m_is_selected = false; bool m_is_selected = false;
@ -86,6 +105,8 @@ Q_SIGNALS:
void resizeHeight(int height); void resizeHeight(int height);
void resizeWidth(const int &); void resizeWidth(const int &);
void rowClicked(); void rowClicked();
void scrollBarAppeared();
void scrollBarIsHideen();
}; };
class DetailWidget : public QWidget class DetailWidget : public QWidget
@ -153,7 +174,6 @@ Q_SIGNALS:
//protected: //protected:
// bool eventFilter(QObject *, QEvent *); // bool eventFilter(QObject *, QEvent *);
//}; //};
} }
#endif // SEARCHPAGESECTION_H #endif // SEARCHPAGESECTION_H

View File

@ -118,6 +118,15 @@ void SearchResultPage::sendResizeWidthSignal(int size)
Q_EMIT this->resizeWidth(size); Q_EMIT this->resizeWidth(size);
} }
void SearchResultPage::setWidth(int width)
{
int margin = m_resultArea->getVScrollBarWidth();
if (!margin) {
margin = 8;//Default margin is 8
}
this->sendResizeWidthSignal(width - margin);
}
void SearchResultPage::paintEvent(QPaintEvent *event) void SearchResultPage::paintEvent(QPaintEvent *event)
{ {
QPainter p(this); QPainter p(this);
@ -197,11 +206,19 @@ void SearchResultPage::initConnections()
connect(this, &SearchResultPage::startSearch, m_detailArea, &DetailArea::hide); connect(this, &SearchResultPage::startSearch, m_detailArea, &DetailArea::hide);
connect(this, &SearchResultPage::stopSearch, m_detailArea, &DetailArea::hide); connect(this, &SearchResultPage::stopSearch, m_detailArea, &DetailArea::hide);
connect(this, &SearchResultPage::startSearch, this, [=] () { connect(this, &SearchResultPage::startSearch, this, [=] () {
sendResizeWidthSignal(656); // sendResizeWidthSignal(656);
setWidth(672);
});
connect(m_resultArea, &ResultArea::scrollBarAppeared, this, [ & ]{
setWidth(672);
});
connect(m_resultArea, &ResultArea::scrollBarIsHideen, this, [ & ]{
setWidth(672);
}); });
connect(m_resultArea, &ResultArea::keyPressChanged, m_detailArea, &DetailArea::setWidgetInfo); connect(m_resultArea, &ResultArea::keyPressChanged, m_detailArea, &DetailArea::setWidgetInfo);
connect(m_resultArea, &ResultArea::keyPressChanged, this, [=] () { connect(m_resultArea, &ResultArea::keyPressChanged, this, [=] () {
sendResizeWidthSignal(280); // sendResizeWidthSignal(280);
setWidth(296);
}); });
connect(m_resultArea, &ResultArea::currentRowChanged, m_detailArea, &DetailArea::setWidgetInfo); connect(m_resultArea, &ResultArea::currentRowChanged, m_detailArea, &DetailArea::setWidgetInfo);
connect(m_resultArea, &ResultArea::currentRowChanged, this, &SearchResultPage::currentRowChanged); connect(m_resultArea, &ResultArea::currentRowChanged, this, &SearchResultPage::currentRowChanged);
@ -209,7 +226,8 @@ void SearchResultPage::initConnections()
connect(m_resultArea, &ResultArea::resizeHeight, this, &SearchResultPage::resizeHeight); connect(m_resultArea, &ResultArea::resizeHeight, this, &SearchResultPage::resizeHeight);
connect(this, &SearchResultPage::resizeWidth, m_resultArea, &ResultArea::resizeWidth); connect(this, &SearchResultPage::resizeWidth, m_resultArea, &ResultArea::resizeWidth);
connect(m_resultArea, &ResultArea::rowClicked, this, [=] () { connect(m_resultArea, &ResultArea::rowClicked, this, [=] () {
sendResizeWidthSignal(280); // sendResizeWidthSignal(280);
setWidth(296);
}); });
connect(this, &SearchResultPage::setSelectionInfo, m_resultArea, &ResultArea::setSelectionInfo); connect(this, &SearchResultPage::setSelectionInfo, m_resultArea, &ResultArea::setSelectionInfo);
//跟随主题透明度变化 //跟随主题透明度变化
@ -231,7 +249,8 @@ void SearchResultPage::setupConnectionsForWidget(ResultWidget *widget)
}); });
connect(this, &SearchResultPage::currentRowChanged, widget, &ResultWidget::clearSelectedRow); connect(this, &SearchResultPage::currentRowChanged, widget, &ResultWidget::clearSelectedRow);
connect(widget, &ResultWidget::rowClicked, this, [=] () { connect(widget, &ResultWidget::rowClicked, this, [=] () {
sendResizeWidthSignal(280); // sendResizeWidthSignal(280);
setWidth(296);
}); });
connect(this, &SearchResultPage::resizeWidth, widget, &ResultWidget::resizeWidth); connect(this, &SearchResultPage::resizeWidth, widget, &ResultWidget::resizeWidth);
} }

View File

@ -40,6 +40,7 @@ public:
void pressDown(); void pressDown();
bool getSelectedState(); bool getSelectedState();
void sendResizeWidthSignal(int size); void sendResizeWidthSignal(int size);
void setWidth(int width);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);