OSDN Git Service

actually animate QComboBox
authorIvailo Monev <xakepa10@gmail.com>
Tue, 22 Nov 2022 14:00:31 +0000 (16:00 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 22 Nov 2022 14:00:31 +0000 (16:00 +0200)
for some reason the code for it was Q_WS_WIN && !QT_NO_EFFECTS guarded and
I purged Q_WS_WIN code programatically

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/widgets/qcombobox.cpp
src/gui/widgets/qeffects.cpp
src/gui/widgets/qeffects_p.h

index ca8a411..f33f806 100644 (file)
@@ -2337,10 +2337,16 @@ void QComboBox::showPopup()
 
     const bool updatesEnabled = container->updatesEnabled();
 
-// windows are displayed immediately on this platform, which means that the window will
-// be visible before the call to container->show() returns. If updates are disabled at
-// this point we'll miss our chance at painting the popup menu before it's shown, causing
-// flicker since the window then displays the standard gray background.
+    bool scrollDown = (listRect.topLeft() == below);
+    if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo)
+        && !style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this) && !window()->testAttribute(Qt::WA_DontShowOnScreen)) {
+        qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
+    }
+
+    // windows are displayed immediately on this platform, which means that the window will
+    // be visible before the call to container->show() returns. If updates are disabled at
+    // this point we'll miss our chance at painting the popup menu before it's shown, causing
+    // flicker since the window then displays the standard gray background.
     container->setUpdatesEnabled(false);
 
     container->raise();
index be67cf0..aa91f40 100644 (file)
@@ -134,7 +134,7 @@ class QRollEffect : public QWidget, private QEffects
 {
     Q_OBJECT
 public:
-    QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient);
+    QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient, int duration);
 
     void run();
 
@@ -167,9 +167,10 @@ private:
 
 static QRollEffect* q_roll = nullptr;
 
-QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient)
+QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient, int dur)
     : QWidget(0, f),
     widget(w),
+    duration(dur),
     elapsed(0),
     done(false),
     orientation(orient)
@@ -206,7 +207,9 @@ QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient)
     if (orientation & (DownScroll|UpScroll)) {
         dist += totalHeight - currentHeight;
     }
-    duration = qMin(qMax(dist/3, 50), 120);
+    if (!duration) {
+        duration = qMin(qMax(dist/3, 50), 120);
+    }
 
     connect(&anim, SIGNAL(timeout()), this, SLOT(scroll()));
 
@@ -333,7 +336,7 @@ void QRollEffect::scroll()
 /*!
     Scroll widget \a w. \a orient may be 1 (vertical), 2 (horizontal) or 3 (diagonal).
 */
-void qScrollEffect(QWidget* w, QEffects::DirFlags orient)
+void qScrollEffect(QWidget* w, QEffects::DirFlags orient, int duration)
 {
     if (q_roll) {
         q_roll->deleteLater();
@@ -348,7 +351,7 @@ void qScrollEffect(QWidget* w, QEffects::DirFlags orient)
     QApplication::sendPostedEvents(w, QEvent::Resize);
 
     // those can be popups - they would steal the focus, but are disabled
-    q_roll = new QRollEffect(w, Qt::ToolTip, orient);
+    q_roll = new QRollEffect(w, Qt::ToolTip, orient, duration);
 }
 
 /*!
index 4ba2c6e..12d44af 100644 (file)
@@ -54,7 +54,7 @@ struct QEffects
     typedef uint DirFlags;
 };
 
-extern void Q_GUI_EXPORT qScrollEffect(QWidget*, QEffects::DirFlags dir = QEffects::DownScroll);
+extern void Q_GUI_EXPORT qScrollEffect(QWidget*, QEffects::DirFlags dir = QEffects::DownScroll, int duration = 0);
 extern void Q_GUI_EXPORT qFadeEffect(QWidget*);
 
 QT_END_NAMESPACE