From ea60b48faeeb9d1e994afbe09ae5d7831214dec5 Mon Sep 17 00:00:00 2001 From: tanjing Date: Wed, 17 Jan 2024 11:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=A4=9A=E4=B8=AAscrollbar?= =?UTF-8?q?=20=20sliderbar=E6=97=B6=E8=8E=B7=E5=8F=96=E7=9A=84handlerect?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ukui-config-style.cpp | 58 ++++++++++++------- .../qt5-config-style-ukui/ukui-config-style.h | 12 ++-- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp b/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp index 431cbd2..bd0728b 100644 --- a/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp +++ b/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp @@ -410,7 +410,7 @@ bool UKUIConfigStyle::eventFilter(QObject *obj, QEvent *e) // opt->init(slider); // qDebug() << "pppppppp;;;;;;;;;:" << subControlRect(CC_Slider, opt, SC_SliderHandle, slider); - QRect handleRect = sliderHandleRec(); + QRect handleRect = sliderHandleRec(slider); if(horizontal){ // qDebug() << "mousepressevent1111 pos...." << mousePressEvent->pos().x() << handleRect.x(); @@ -532,23 +532,23 @@ bool UKUIConfigStyle::eventFilter(QObject *obj, QEvent *e) // qDebug() << "event..." << e->type() << mousePressEvent->button(); const bool horizontal = scrollbar->orientation() == Qt::Horizontal; - if(horizontal){ - if(mousePressEvent->pos().x() <= scrollbarSliderRec().x()){ - animator->setExtraProperty("addValue", /*scrollbar->layoutDirection() == Qt::RightToLeft ? true :*/ false); + QRect handleRect = scrollbarSliderRec(scrollbar); + if(horizontal){ + if(mousePressEvent->pos().x() <= handleRect.x()){ + animator->setExtraProperty("addValue", /*scrollbar->layoutDirection() == Qt::RightToLeft ? true :*/ false); } - else if(mousePressEvent->pos().x() >= scrollbarSliderRec().x() + scrollbarSliderRec().width()){ + else if(mousePressEvent->pos().x() >= handleRect.x() + handleRect.width()){ animator->setExtraProperty("addValue", /*scrollbar->layoutDirection() == Qt::RightToLeft ? false :*/ true); } else return false; } else{ - if(mousePressEvent->pos().y() <= scrollbarSliderRec().y()){ + if(mousePressEvent->pos().y() <= handleRect.y()){ animator->setExtraProperty("addValue", false); - } - else if(mousePressEvent->pos().y() >= scrollbarSliderRec().y() + scrollbarSliderRec().height()){ + else if(mousePressEvent->pos().y() >= handleRect.y() + handleRect.height()){ animator->setExtraProperty("addValue", true); } else @@ -909,26 +909,44 @@ void UKUIConfigStyle::updateTabletModeValue(bool isTabletMode) } } -QRect UKUIConfigStyle::scrollbarSliderRec() +QRect UKUIConfigStyle::scrollbarSliderRec(QWidget *w) { - return m_scrollBarSliderRec; + if(w && m_scrollBarSliderRec.contains(w)) + return m_scrollBarSliderRec.value(w); + return QRect(); } -void UKUIConfigStyle::setScrollbarSliderRec(QRect rect) const +void UKUIConfigStyle::setScrollbarSliderRec(QWidget *w, QRect rect) const { - if(m_scrollBarSliderRec != rect) - m_scrollBarSliderRec = rect; + if(w){ + if(m_scrollBarSliderRec.contains(w)){ + QRect r = m_scrollBarSliderRec.value(w); + if(r != rect) + m_scrollBarSliderRec.insert(w, rect); + return; + } + m_scrollBarSliderRec.insert(w, rect); + } } -QRect UKUIConfigStyle::sliderHandleRec() +QRect UKUIConfigStyle::sliderHandleRec(QWidget *w) { - return m_sliderHandleRec; + if(w && m_sliderHandleRec.contains(w)) + return m_sliderHandleRec.value(w); + return QRect(); } -void UKUIConfigStyle::setSliderHandleRec(QRect rect) const +void UKUIConfigStyle::setSliderHandleRec(QWidget *w, QRect rect) const { - if(m_sliderHandleRec != rect) - m_sliderHandleRec = rect; + if(w){ + if(m_sliderHandleRec.contains(w)){ + QRect r = m_sliderHandleRec.value(w); + if(r != rect) + m_sliderHandleRec.insert(w, rect); + return; + } + m_sliderHandleRec.insert(w, rect); + } } @@ -3781,7 +3799,7 @@ void UKUIConfigStyle::drawComplexControl(QStyle::ComplexControl control, const Q else handle.setX((option->rect.width() - handle.width()) / 2); handleOption.rect = handle; - setSliderHandleRec(handleOption.rect); + setSliderHandleRec(const_cast(widget), handleOption.rect); sp->initConfigSliderParameters(isUseDarkPalette(), &handleOption, widget); @@ -4506,7 +4524,7 @@ void UKUIConfigStyle::drawControl(QStyle::ControlElement element, const QStyleOp drawRect = bar->rect; } - setScrollbarSliderRec(QRect(drawRect.x(), drawRect.y(), drawRect.width(), drawRect.height())); + setScrollbarSliderRec(const_cast(widget), QRect(drawRect.x(), drawRect.y(), drawRect.width(), drawRect.height())); //hover color animation // animator->setAnimatorDirectionForward("slider_opacity", mouseOver); diff --git a/ukui-styles/qt5-config-style-ukui/ukui-config-style.h b/ukui-styles/qt5-config-style-ukui/ukui-config-style.h index 5b78807..6a4b64f 100644 --- a/ukui-styles/qt5-config-style-ukui/ukui-config-style.h +++ b/ukui-styles/qt5-config-style-ukui/ukui-config-style.h @@ -144,10 +144,10 @@ protected: private Q_SLOTS: void updateTabletModeValue(bool isTabletMode); - QRect scrollbarSliderRec(); - void setScrollbarSliderRec(QRect rect) const; - QRect sliderHandleRec(); - void setSliderHandleRec(QRect rect) const; + QRect scrollbarSliderRec(QWidget *w); + void setScrollbarSliderRec(QWidget *w, QRect rect) const; + QRect sliderHandleRec(QWidget *w); + void setSliderHandleRec(QWidget *w,QRect rect) const; private: bool isUseDarkPalette() const; @@ -194,8 +194,8 @@ private: // UKUIConfigStyleParameters UKUIConfigStyleSpace::UKUIConfigStyleParameters *sp = nullptr; - mutable QRect m_scrollBarSliderRec; - mutable QRect m_sliderHandleRec; + mutable QHash m_scrollBarSliderRec; + mutable QHash m_sliderHandleRec; BlurHelper *m_blur_helper = nullptr; GestureHelper *m_gesture_helper = nullptr;