处理多个scrollbar sliderbar时获取的handlerect不正确的问题

This commit is contained in:
tanjing 2024-01-17 11:02:20 +08:00
parent b5f588c81c
commit ea60b48fae
2 changed files with 44 additions and 26 deletions

View File

@ -410,7 +410,7 @@ bool UKUIConfigStyle::eventFilter(QObject *obj, QEvent *e)
// opt->init(slider); // opt->init(slider);
// qDebug() << "pppppppp;;;;;;;;;:" << subControlRect(CC_Slider, opt, SC_SliderHandle, slider); // qDebug() << "pppppppp;;;;;;;;;:" << subControlRect(CC_Slider, opt, SC_SliderHandle, slider);
QRect handleRect = sliderHandleRec(); QRect handleRect = sliderHandleRec(slider);
if(horizontal){ if(horizontal){
// qDebug() << "mousepressevent1111 pos...." << mousePressEvent->pos().x() << handleRect.x(); // 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(); // qDebug() << "event..." << e->type() << mousePressEvent->button();
const bool horizontal = scrollbar->orientation() == Qt::Horizontal; const bool horizontal = scrollbar->orientation() == Qt::Horizontal;
if(horizontal){ QRect handleRect = scrollbarSliderRec(scrollbar);
if(mousePressEvent->pos().x() <= scrollbarSliderRec().x()){
animator->setExtraProperty("addValue", /*scrollbar->layoutDirection() == Qt::RightToLeft ? true :*/ false);
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); animator->setExtraProperty("addValue", /*scrollbar->layoutDirection() == Qt::RightToLeft ? false :*/ true);
} }
else else
return false; return false;
} }
else{ else{
if(mousePressEvent->pos().y() <= scrollbarSliderRec().y()){ if(mousePressEvent->pos().y() <= handleRect.y()){
animator->setExtraProperty("addValue", false); 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); animator->setExtraProperty("addValue", true);
} }
else 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) if(w){
m_scrollBarSliderRec = rect; 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) if(w){
m_sliderHandleRec = rect; 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 else
handle.setX((option->rect.width() - handle.width()) / 2); handle.setX((option->rect.width() - handle.width()) / 2);
handleOption.rect = handle; handleOption.rect = handle;
setSliderHandleRec(handleOption.rect); setSliderHandleRec(const_cast<QWidget*>(widget), handleOption.rect);
sp->initConfigSliderParameters(isUseDarkPalette(), &handleOption, widget); sp->initConfigSliderParameters(isUseDarkPalette(), &handleOption, widget);
@ -4506,7 +4524,7 @@ void UKUIConfigStyle::drawControl(QStyle::ControlElement element, const QStyleOp
drawRect = bar->rect; drawRect = bar->rect;
} }
setScrollbarSliderRec(QRect(drawRect.x(), drawRect.y(), drawRect.width(), drawRect.height())); setScrollbarSliderRec(const_cast<QWidget*>(widget), QRect(drawRect.x(), drawRect.y(), drawRect.width(), drawRect.height()));
//hover color animation //hover color animation
// animator->setAnimatorDirectionForward("slider_opacity", mouseOver); // animator->setAnimatorDirectionForward("slider_opacity", mouseOver);

View File

@ -144,10 +144,10 @@ protected:
private Q_SLOTS: private Q_SLOTS:
void updateTabletModeValue(bool isTabletMode); void updateTabletModeValue(bool isTabletMode);
QRect scrollbarSliderRec(); QRect scrollbarSliderRec(QWidget *w);
void setScrollbarSliderRec(QRect rect) const; void setScrollbarSliderRec(QWidget *w, QRect rect) const;
QRect sliderHandleRec(); QRect sliderHandleRec(QWidget *w);
void setSliderHandleRec(QRect rect) const; void setSliderHandleRec(QWidget *w,QRect rect) const;
private: private:
bool isUseDarkPalette() const; bool isUseDarkPalette() const;
@ -194,8 +194,8 @@ private:
// UKUIConfigStyleParameters // UKUIConfigStyleParameters
UKUIConfigStyleSpace::UKUIConfigStyleParameters *sp = nullptr; UKUIConfigStyleSpace::UKUIConfigStyleParameters *sp = nullptr;
mutable QRect m_scrollBarSliderRec; mutable QHash<QWidget*, QRect> m_scrollBarSliderRec;
mutable QRect m_sliderHandleRec; mutable QHash<QWidget*, QRect> m_sliderHandleRec;
BlurHelper *m_blur_helper = nullptr; BlurHelper *m_blur_helper = nullptr;
GestureHelper *m_gesture_helper = nullptr; GestureHelper *m_gesture_helper = nullptr;