From 123ae472e2668a1f57f7c69a1a2a59336f83d06a Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 25 Mar 2014 13:06:04 +0100 Subject: Fix disappearing transient scrollbars When a transient scrollbar is already at the end and user attempts to scroll further, the scrollbar is "flashed" to indicate that the scroll area is already scrolled to the end. This is done so that the scrollbar is first painted with a flag turned on to make it appear visible and then again with the flag turned off to make qstyle start fading it out. The previous code that relied on paint events to clear the flag was error prone, and caused the scrollbars to get stuck in an inconsistent state. This change makes sure that the flag gets cleared regardless of whether a paint event in each state is received or not. Task-number: QTBUG-37787 Change-Id: I907697c32cd4d55208a490804a221a5dd6bf7b0b Reviewed-by: Gabriel de Dietrich --- src/widgets/widgets/qscrollbar.cpp | 23 ++++++++++++++++++----- src/widgets/widgets/qscrollbar_p.h | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp index 05b8935bb5..5060ca0a70 100644 --- a/src/widgets/widgets/qscrollbar.cpp +++ b/src/widgets/widgets/qscrollbar.cpp @@ -248,8 +248,13 @@ void QScrollBarPrivate::flash() Q_Q(QScrollBar); if (!flashed && q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, q)) { flashed = true; - q->show(); + if (!q->isVisible()) + q->show(); + else + q->update(); } + if (!flashTimer) + flashTimer = q->startTimer(0); } void QScrollBarPrivate::activateControl(uint control, int threshold) @@ -386,6 +391,7 @@ void QScrollBarPrivate::init() pointerOutsidePressedControl = false; transient = q->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, q); flashed = false; + flashTimer = 0; q->setFocusPolicy(Qt::NoFocus); QSizePolicy sp(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::Slider); if (orientation == Qt::Vertical) @@ -476,6 +482,7 @@ void QScrollBar::sliderChange(SliderChange change) */ bool QScrollBar::event(QEvent *event) { + Q_D(QScrollBar); switch(event->type()) { case QEvent::HoverEnter: case QEvent::HoverLeave: @@ -486,6 +493,16 @@ bool QScrollBar::event(QEvent *event) case QEvent::StyleChange: d_func()->setTransient(style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this)); break; + case QEvent::Timer: + if (static_cast(event)->timerId() == d->flashTimer) { + if (d->flashed && style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this)) { + d->flashed = false; + update(); + } + killTimer(d->flashTimer); + d->flashTimer = 0; + } + break; default: break; } @@ -536,10 +553,6 @@ void QScrollBar::paintEvent(QPaintEvent *) opt.activeSubControls = (QStyle::SubControl)d->hoverControl; } style()->drawComplexControl(QStyle::CC_ScrollBar, &opt, &p, this); - if (d->flashed && style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, this)) { - d->flashed = false; - update(); - } } /*! diff --git a/src/widgets/widgets/qscrollbar_p.h b/src/widgets/widgets/qscrollbar_p.h index c62c337a40..5fc714d530 100644 --- a/src/widgets/widgets/qscrollbar_p.h +++ b/src/widgets/widgets/qscrollbar_p.h @@ -81,6 +81,7 @@ public: void setTransient(bool value); bool flashed; + int flashTimer; void flash(); }; -- cgit v1.2.3 From c5805acccda4b3762bfd4d23ee6622053bb7104d Mon Sep 17 00:00:00 2001 From: luyikei Date: Sun, 30 Mar 2014 00:41:18 +0900 Subject: Remove a duplicate code of else-if statement I found a useless else-if statement in qwidgettextcontrol.cpp. It is duplicating.Needless to say,it should be removed. Change-Id: Ic70b995196f7199e4aa5263a4937c1678b130357 Reviewed-by: Giuseppe D'Angelo --- src/widgets/widgets/qwidgettextcontrol.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 03a65aa8e5..3740f3e698 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -239,9 +239,6 @@ bool QWidgetTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e) else if (e == QKeySequence::MoveToPreviousLine) { op = QTextCursor::Up; } - else if (e == QKeySequence::MoveToPreviousLine) { - op = QTextCursor::Up; - } else if (e == QKeySequence::MoveToStartOfLine) { op = QTextCursor::StartOfLine; } -- cgit v1.2.3