!63 调整全屏全部分类窗口结构,解决概率性触摸无法滑动问题

Merge pull request !63 from lixueman/upstream
This commit is contained in:
lixueman 2023-02-09 01:22:25 +00:00 committed by Gitee
commit 166a49604a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 39 additions and 144 deletions

View File

@ -53,6 +53,10 @@ FullListView::~FullListView()
void FullListView::initWidget()
{
viewport()->setAttribute(Qt::WA_TranslucentBackground);
viewport()->setAutoFillBackground(false);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setAutoFillBackground(false);
this->setSelectionMode(QAbstractItemView::SingleSelection);
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

View File

@ -73,17 +73,6 @@ void KListView::onClicked(QModelIndex index)
}
}
void KListView::paintEvent(QPaintEvent *e)
{
double transparency = getTransparency();
QPainter painter(this->viewport());
painter.setBrush(this->palette().base());
painter.setPen(Qt::transparent);
painter.setOpacity(transparency);
painter.drawRect(this->rect());
QListView::paintEvent(e);
}
void KListView::mouseMoveEvent(QMouseEvent *e)
{
this->clearFocus();

View File

@ -38,11 +38,12 @@ public:
QVariant m_pressApp;
QPoint m_pressPos;
UkuiMenuInterface *m_ukuiMenuInterface = nullptr;
protected:
void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
public:
void addData(QStringList data);
void updateData(QStringList data);

View File

@ -26,49 +26,7 @@ ScrollAreaWid::ScrollAreaWid(QWidget *parent):
{
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
}
void ScrollAreaWid::paintEvent(QPaintEvent *event)
{
double transparency = getTransparency();
QPainter painter(this);
// if(QGSettings::isSchemaInstalled(QString("org.ukui.control-center.personalise").toLocal8Bit()))
// {
// QGSettings gsetting(QString("org.ukui.control-center.personalise").toLocal8Bit());
// if(gsetting.keys().contains(QString("effect")))
// {
// if(gsetting.get("effect").toBool())
// {
// painter.setBrush(Qt::black);
//// painter.setBrush(Qt::red);
// painter.setPen(Qt::transparent);
// painter.setOpacity(0.25);
// painter.drawRect(this->rect());
// }
// else
// {
// painter.setBrush(this->palette().base());
// painter.setPen(Qt::transparent);
// painter.setOpacity(transparency);
// painter.drawRect(this->rect());
// }
// }
// else
// {
// painter.setBrush(this->palette().base());
// painter.setPen(Qt::transparent);
// painter.setOpacity(transparency);
// painter.drawRect(this->rect());
// }
// }
// else
// {
painter.setBrush(this->palette().base());
painter.setPen(Qt::transparent);
painter.setOpacity(transparency);
painter.drawRect(this->rect());
// }
QWidget::paintEvent(event);
this->setAutoFillBackground(false);
}
ScrollArea::ScrollArea()

View File

@ -28,9 +28,6 @@ class ScrollAreaWid: public QWidget
{
public:
ScrollAreaWid(QWidget *parent);
protected:
void paintEvent(QPaintEvent *event);
};
class ScrollArea : public QScrollArea

View File

@ -47,14 +47,8 @@ void FullCommonUseWidget::initUi()
mainLayout->setSpacing(0);
m_spaceItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Fixed);
mainLayout->addItem(m_spaceItem);
m_scrollArea = new ScrollArea();
m_scrollAreaWid = new ScrollAreaWid(this);
m_scrollAreaWid->setAttribute(Qt::WA_TranslucentBackground);
m_scrollArea->setFixedSize(Style::m_applistAreaWidth, Style::m_applistWidHeight);
m_scrollArea->setWidget(m_scrollAreaWid);
m_scrollArea->setAlignment(Qt::AlignCenter);
m_scrollArea->setStyleSheet("QWidget{background:transparent;}");
m_scrollArea->setWidgetResizable(true);
m_scrollAreaWid->setFixedSize(Style::m_applistAreaWidth, Style::m_applistWidHeight);
m_scrollAreaWidLayout = new QVBoxLayout(m_scrollAreaWid);
m_scrollAreaWidLayout->setContentsMargins(0, 0, 0, 0);
m_scrollAreaWidLayout->setSpacing(10);
@ -65,9 +59,10 @@ void FullCommonUseWidget::initUi()
m_spaceItem2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
rightButtonLayout->addItem(m_spaceItem2);
m_verticalScrollBar = new QScrollBar(this);
m_verticalScrollBar->hide();
m_verticalScrollBar->installEventFilter(this);
m_verticalScrollBar->setOrientation(Qt::Vertical);
mainLayout->addWidget(m_scrollArea);
mainLayout->addWidget(m_scrollAreaWid);
QSpacerItem *m_spaceItem1 = nullptr;
m_spaceItem1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
mainLayout->addItem(m_spaceItem1);
@ -92,7 +87,6 @@ void FullCommonUseWidget::initUi()
m_ukuiMenuInterface = new UkuiMenuInterface;
initAppListWidget();
fillAppList();
m_scrollAreaWid->adjustSize();
flag = true;
//翻页灵敏度时间调节
time = new QTimer(this);
@ -102,24 +96,19 @@ void FullCommonUseWidget::initUi()
time->stop();
}
});
m_scrollAreaWidHeight = m_scrollAreaWid->height();
initVerticalScrollBar();
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &FullCommonUseWidget::on_setScrollBarValue);
connect(m_listView->verticalScrollBar(), &QScrollBar::valueChanged, this, &FullCommonUseWidget::on_setScrollBarValue);
connect(m_verticalScrollBar, &QScrollBar::valueChanged, this, &FullCommonUseWidget::on_setAreaScrollBarValue);
connect(m_powerOffButton, &QPushButton::customContextMenuRequested, this, &FullCommonUseWidget::on_powerOffButton_customContextMenuRequested);
connect(m_powerOffButton, &QPushButton::clicked, this, &FullCommonUseWidget::on_powerOffButton_clicked);
connect(m_listView->verticalScrollBar(), &QScrollBar::rangeChanged, this, &FullCommonUseWidget::initVerticalScrollBar);
}
void FullCommonUseWidget::initVerticalScrollBar()
{
m_verticalScrollBar->setFixedHeight(200);
int scrollBarSize = 200 * Style::m_applistWidHeight / m_scrollAreaWidHeight + 1;
if (scrollBarSize >= 200) {
m_verticalScrollBar->hide();
} else {
m_verticalScrollBar->show();
}
m_verticalScrollBar->setMaximum(m_listView->verticalScrollBar()->maximum());
int scrollBarSize = 200 * m_listView->verticalScrollBar()->pageStep() / (m_listView->verticalScrollBar()->maximum() - m_listView->verticalScrollBar()->minimum() + m_listView->verticalScrollBar()->pageStep());
m_scrollBarStyle = QString("QScrollBar:vertical{width: %2px; background: rgba(12, 12, 12, %4); "
"margin: 0px,0px,0px,0px; border-radius: %3px;}"
@ -128,6 +117,12 @@ void FullCommonUseWidget::initVerticalScrollBar()
"QScrollBar::add-line:vertical{ height: 0px; width: 0px; subcontrol-position: bottom;}"
"QScrollBar::sub-line:vertical{ height: 0px; width: 0px; subcontrol-position:top;}").arg(scrollBarSize);
m_verticalScrollBar->setStyleSheet(m_scrollBarStyle.arg(4).arg(2).arg(0.25).arg(0.6));
if (scrollBarSize >= 200) {
m_verticalScrollBar->hide();
} else {
m_verticalScrollBar->show();
}
}
void FullCommonUseWidget::on_powerOffButton_clicked()
@ -146,35 +141,18 @@ void FullCommonUseWidget::on_powerOffButton_customContextMenuRequested(const QPo
void FullCommonUseWidget::initAppListWidget()
{
m_listView = new FullListView(this, 0);
m_listView = new FullListView(m_scrollAreaWid, 0);
m_listView->installEventFilter(this);
m_listView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_listView->verticalScrollBar()->setVisible(false);
m_scrollAreaWidLayout->addWidget(m_listView);
m_listView->setFixedWidth(m_scrollAreaWid->width());
m_listView->setFixedSize(m_scrollAreaWid->width(), Style::m_applistWidHeight);
connect(m_listView, &FullListView::sendUpdateAppListSignal, this, &FullCommonUseWidget::updateListViewSlot);
connect(m_listView, &FullListView::sendCollectViewUpdate, this, &FullCommonUseWidget::sendCollectViewUpdate);
connect(m_listView, &FullListView::sendHideMainWindowSignal, this, &FullCommonUseWidget::sendHideMainWindowSignal);
connect(m_listView, &FullListView::sendSetslidebar, this, &FullCommonUseWidget::onSetSlider);
}
void FullCommonUseWidget::resizeScrollAreaControls()
{
QLayoutItem *widItem = m_scrollAreaWidLayout->itemAt(0);
QWidget *wid = widItem->widget();
FullListView *listview = qobject_cast<FullListView *>(wid);
listview->adjustSize();
int dividend = m_scrollArea->width() / Style::m_applistGridSizeWidth;
int rowcount = 0;
if (listview->model()->rowCount() % dividend > 0) {
rowcount = listview->model()->rowCount() / dividend + 1;
} else {
rowcount = listview->model()->rowCount() / dividend;
}
listview->setFixedSize(Style::m_applistAreaWidth, listview->gridSize().height() * rowcount);
m_scrollArea->widget()->setFixedSize(listview->size());
}
void FullCommonUseWidget::fillAppList()
{
m_data.clear();
@ -184,7 +162,6 @@ void FullCommonUseWidget::fillAppList()
}
m_listView->addData(m_data);
resizeScrollAreaControls();
}
void FullCommonUseWidget::selectFirstItem()
@ -194,7 +171,7 @@ void FullCommonUseWidget::selectFirstItem()
void FullCommonUseWidget::on_setScrollBarValue(int value)
{
m_verticalScrollBar->setMaximum(m_scrollAreaWidHeight - Style::m_applistWidHeight);
m_verticalScrollBar->setMaximum(m_listView->verticalScrollBar()->maximum());
m_verticalScrollBar->setValue(value);
}
@ -231,10 +208,10 @@ bool FullCommonUseWidget::eventFilter(QObject *watched, QEvent *event)
void FullCommonUseWidget::onSetSlider(int value)
{
if (value == 0) {
m_scrollArea->verticalScrollBar()->setValue(0);
m_listView->verticalScrollBar()->setValue(0);
} else {
int curvalue = m_scrollArea->verticalScrollBar()->value();
m_scrollArea->verticalScrollBar()->setValue(curvalue + value);
int curvalue = m_listView->verticalScrollBar()->value();
m_listView->verticalScrollBar()->setValue(curvalue + value);
}
}
@ -247,7 +224,7 @@ void FullCommonUseWidget::selectFirstItemTab()
void FullCommonUseWidget::on_setAreaScrollBarValue(int value)
{
m_scrollArea->verticalScrollBar()->setValue(value);
m_listView->verticalScrollBar()->setValue(value);
}
/**
*
@ -267,39 +244,16 @@ void FullCommonUseWidget::updateListView()
}
m_listView->updateData(m_data);
m_data.clear();
resizeScrollAreaControls();
m_scrollAreaWidHeight = m_scrollAreaWid->height();
initVerticalScrollBar();
}
void FullCommonUseWidget::repaintWidget()
{
m_scrollArea->setFixedSize(Style::m_applistAreaWidth, Style::m_applistWidHeight);
m_scrollArea->setWidgetResizable(true);
m_scrollAreaWidLayout->removeWidget(m_listView);
m_listView->setParent(nullptr);
delete m_listView;
initAppListWidget();
fillAppList();
m_scrollAreaWid->adjustSize();
m_scrollAreaWidHeight = m_scrollAreaWid->height();
initVerticalScrollBar();
on_setAreaScrollBarValue(0);
m_scrollAreaWid->setFixedSize(Style::m_applistAreaWidth, Style::m_applistWidHeight);
m_listView->setFixedSize(Style::m_applistAreaWidth, Style::m_applistWidHeight);
m_listView->setGridSize(QSize(Style::m_applistGridSizeWidth, Style::m_applistGridSizeWidth));
}
void FullCommonUseWidget::widgetMakeZero()
{
m_listView->verticalScrollBar()->setSliderPosition(0);
}
void FullCommonUseWidget::moveScrollBar(int type)
{
int height = Style::m_availableScreenHeight;
if (type == 0) {
m_listView->verticalScrollBar()->setSliderPosition(m_listView->verticalScrollBar()->sliderPosition() - height * 100 / 1080);
} else {
m_listView->verticalScrollBar()->setSliderPosition(m_listView->verticalScrollBar()->sliderPosition() + height * 100 / 1080);
}
}

View File

@ -57,13 +57,6 @@ public:
* @brief Repaint window
*/
void repaintWidget();
/**
* @brief Move the scroll bar
* @param type: Scroll way,Only the following parameters can be entered:
* 0: moving up
* 1: moving down
*/
void moveScrollBar(int type);
FullListView *m_listView = nullptr;
@ -95,7 +88,6 @@ protected:
* @brief fill application list
*/
void fillAppList();
void resizeScrollAreaControls();
void initVerticalScrollBar();
bool eventFilter(QObject *watched, QEvent *event);

View File

@ -31,9 +31,9 @@ MainViewWidget::MainViewWidget(QWidget *parent) :
QWidget(parent)
{
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_StyledBackground, true);
this->setAutoFillBackground(false);
this->setAttribute(Qt::WA_TranslucentBackground);
// this->setAttribute(Qt::WA_StyledBackground, true);
// this->setAutoFillBackground(false);
// this->setAttribute(Qt::WA_TranslucentBackground);
this->setFocusPolicy(Qt::StrongFocus);
}

View File

@ -132,7 +132,6 @@ void FullMainWindow::initSearchUI()
m_queryWid->layout()->removeWidget(m_queryText);
m_queryText->setParent(nullptr);
resetEditline();
m_fullCommonPage->repaintWidget();
m_fullFunctionPage->repaintWidget();
m_fullLetterPage->repaintWidget();
}
@ -169,6 +168,8 @@ void FullMainWindow::initSearchUI()
void FullMainWindow::initAppListUI()
{
m_fullStackedWidget = new QStackedWidget(centralwidget);
m_fullStackedWidget->setAttribute(Qt::WA_TranslucentBackground, true);
m_fullStackedWidget->setAutoFillBackground(false);
m_fullCommonPage = new FullCommonUseWidget(m_fullStackedWidget);
m_fullStackedWidget->addWidget(m_fullCommonPage);
m_fullLetterPage = new FullLetterWidget(m_fullStackedWidget);
@ -576,8 +577,7 @@ void FullMainWindow::on_fullSelectMenuButton_triggered(QAction *arg1)
if (arg1 == m_allAction) {
m_fullStackedWidget->setCurrentIndex(0);
m_fullCommonPage->repaintWidget();
//fullCommonPage->updateListView();
m_fullCommonPage->widgetMakeZero();
m_state = 0;
m_fullSelectToolButton->setIcon(QIcon(":/data/img/mainviewwidget/full-all-2x.png"));
m_allAction->setChecked(true);