From b4b4f051bab510058d28bb48d81a58167f8cb921 Mon Sep 17 00:00:00 2001 From: lixueman Date: Mon, 30 Jan 2023 14:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=85=A8=E5=B1=8F=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=B1=BB=E7=AA=97=E5=8F=A3=E7=BB=93=E6=9E=84?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=A6=82=E7=8E=87=E6=80=A7=E8=A7=A6?= =?UTF-8?q?=E6=91=B8=E6=97=A0=E6=B3=95=E6=BB=91=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UserInterface/ListView/fulllistview.cpp | 4 + src/UserInterface/ListView/klistview.cpp | 11 --- src/UserInterface/ListView/klistview.h | 3 +- src/UserInterface/Other/scrollarea.cpp | 44 +-------- src/UserInterface/Other/scrollarea.h | 3 - .../Widget/full_commonuse_widget.cpp | 98 +++++-------------- .../Widget/full_commonuse_widget.h | 8 -- src/UserInterface/Widget/main_view_widget.cpp | 6 +- src/UserInterface/full_mainwindow.cpp | 6 +- 9 files changed, 39 insertions(+), 144 deletions(-) diff --git a/src/UserInterface/ListView/fulllistview.cpp b/src/UserInterface/ListView/fulllistview.cpp index 5159e10..8ec8aec 100644 --- a/src/UserInterface/ListView/fulllistview.cpp +++ b/src/UserInterface/ListView/fulllistview.cpp @@ -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); diff --git a/src/UserInterface/ListView/klistview.cpp b/src/UserInterface/ListView/klistview.cpp index 28c83c2..64390d9 100644 --- a/src/UserInterface/ListView/klistview.cpp +++ b/src/UserInterface/ListView/klistview.cpp @@ -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(); diff --git a/src/UserInterface/ListView/klistview.h b/src/UserInterface/ListView/klistview.h index 2ac6f3d..7d0a7dc 100644 --- a/src/UserInterface/ListView/klistview.h +++ b/src/UserInterface/ListView/klistview.h @@ -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); diff --git a/src/UserInterface/Other/scrollarea.cpp b/src/UserInterface/Other/scrollarea.cpp index c8592ab..4ab9861 100644 --- a/src/UserInterface/Other/scrollarea.cpp +++ b/src/UserInterface/Other/scrollarea.cpp @@ -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() diff --git a/src/UserInterface/Other/scrollarea.h b/src/UserInterface/Other/scrollarea.h index c8d8d80..49bc992 100644 --- a/src/UserInterface/Other/scrollarea.h +++ b/src/UserInterface/Other/scrollarea.h @@ -28,9 +28,6 @@ class ScrollAreaWid: public QWidget { public: ScrollAreaWid(QWidget *parent); - -protected: - void paintEvent(QPaintEvent *event); }; class ScrollArea : public QScrollArea diff --git a/src/UserInterface/Widget/full_commonuse_widget.cpp b/src/UserInterface/Widget/full_commonuse_widget.cpp index 61c8da2..2bdb2c4 100644 --- a/src/UserInterface/Widget/full_commonuse_widget.cpp +++ b/src/UserInterface/Widget/full_commonuse_widget.cpp @@ -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(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); - } -} diff --git a/src/UserInterface/Widget/full_commonuse_widget.h b/src/UserInterface/Widget/full_commonuse_widget.h index dfea5b5..dd81d5c 100644 --- a/src/UserInterface/Widget/full_commonuse_widget.h +++ b/src/UserInterface/Widget/full_commonuse_widget.h @@ -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); diff --git a/src/UserInterface/Widget/main_view_widget.cpp b/src/UserInterface/Widget/main_view_widget.cpp index c53fc53..ba14d06 100644 --- a/src/UserInterface/Widget/main_view_widget.cpp +++ b/src/UserInterface/Widget/main_view_widget.cpp @@ -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); } diff --git a/src/UserInterface/full_mainwindow.cpp b/src/UserInterface/full_mainwindow.cpp index 499e76d..67179b3 100644 --- a/src/UserInterface/full_mainwindow.cpp +++ b/src/UserInterface/full_mainwindow.cpp @@ -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);