diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2010-11-17 00:00:09 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2010-11-17 00:00:09 (GMT) |
commit | bfdf62fe02987c5db881527b53e3ba758d6b272e (patch) | |
tree | f1bac9346ec01d87b5e4640632a13c4d4ee724b3 | |
parent | 70e9090b13f828b048caadf305d405bdf9098d70 (diff) | |
parent | 0b0957d5d032a65bad995f8a1ba689267a4b3644 (diff) | |
download | Qt-bfdf62fe02987c5db881527b53e3ba758d6b272e.zip Qt-bfdf62fe02987c5db881527b53e3ba758d6b272e.tar.gz Qt-bfdf62fe02987c5db881527b53e3ba758d6b272e.tar.bz2 |
Merge branch 'master-upstream' into master-water
-rw-r--r-- | demos/chip/view.cpp | 54 | ||||
-rw-r--r-- | demos/chip/view.h | 32 | ||||
-rw-r--r-- | src/corelib/animation/qabstractanimation.cpp | 146 | ||||
-rw-r--r-- | src/corelib/animation/qabstractanimation.h | 31 | ||||
-rw-r--r-- | src/corelib/animation/qabstractanimation_p.h | 52 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsview.cpp | 7 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_mac.mm | 2 | ||||
-rw-r--r-- | src/gui/painting/qwindowsurface_raster.cpp | 5 | ||||
-rw-r--r-- | src/gui/text/qfontengine_mac.mm | 2 | ||||
-rw-r--r-- | src/gui/text/qtextengine.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qcomplextext/tst_qcomplextext.cpp | 23 | ||||
-rw-r--r-- | tests/auto/qpauseanimation/tst_qpauseanimation.cpp | 5 |
12 files changed, 324 insertions, 37 deletions
diff --git a/demos/chip/view.cpp b/demos/chip/view.cpp index 7af3074..d6a641e 100644 --- a/demos/chip/view.cpp +++ b/demos/chip/view.cpp @@ -48,15 +48,29 @@ #include <qmath.h> +void GraphicsView::wheelEvent(QWheelEvent *e) +{ + if (e->modifiers() & Qt::ControlModifier) { + if (e->delta() > 0) + view->zoomIn(6); + else + view->zoomOut(6); + e->accept(); + } else { + QGraphicsView::wheelEvent(e); + } +} + View::View(const QString &name, QWidget *parent) : QFrame(parent) { setFrameStyle(Sunken | StyledPanel); - graphicsView = new QGraphicsView; + graphicsView = new GraphicsView(this); graphicsView->setRenderHint(QPainter::Antialiasing, false); graphicsView->setDragMode(QGraphicsView::RubberBandDrag); graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState); graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); + graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); int size = style()->pixelMetric(QStyle::PM_ToolBarIconSize); QSize iconSize(size, size); @@ -111,6 +125,15 @@ View::View(const QString &name, QWidget *parent) // Label layout QHBoxLayout *labelLayout = new QHBoxLayout; label = new QLabel(name); + label2 = new QLabel(tr("Pointer Mode")); + selectModeButton = new QToolButton; + selectModeButton->setText(tr("Select")); + selectModeButton->setCheckable(true); + selectModeButton->setChecked(true); + dragModeButton = new QToolButton; + dragModeButton->setText(tr("Drag")); + dragModeButton->setCheckable(true); + dragModeButton->setChecked(false); antialiasButton = new QToolButton; antialiasButton->setText(tr("Antialiasing")); antialiasButton->setCheckable(true); @@ -126,8 +149,17 @@ View::View(const QString &name, QWidget *parent) printButton = new QToolButton; printButton->setIcon(QIcon(QPixmap(":/fileprint.png"))); + QButtonGroup *pointerModeGroup = new QButtonGroup; + pointerModeGroup->setExclusive(true); + pointerModeGroup->addButton(selectModeButton); + pointerModeGroup->addButton(dragModeButton); + labelLayout->addWidget(label); labelLayout->addStretch(); + labelLayout->addWidget(label2); + labelLayout->addWidget(selectModeButton); + labelLayout->addWidget(dragModeButton); + labelLayout->addStretch(); labelLayout->addWidget(antialiasButton); labelLayout->addWidget(openGlButton); labelLayout->addWidget(printButton); @@ -145,6 +177,8 @@ View::View(const QString &name, QWidget *parent) connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix())); connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled())); connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled())); + connect(selectModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode())); + connect(dragModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode())); connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing())); connect(openGlButton, SIGNAL(toggled(bool)), this, SLOT(toggleOpenGL())); connect(rotateLeftIcon, SIGNAL(clicked()), this, SLOT(rotateLeft())); @@ -158,7 +192,7 @@ View::View(const QString &name, QWidget *parent) QGraphicsView *View::view() const { - return graphicsView; + return static_cast<QGraphicsView *>(graphicsView); } void View::resetView() @@ -188,6 +222,14 @@ void View::setupMatrix() setResetButtonEnabled(); } +void View::togglePointerMode() +{ + graphicsView->setDragMode(selectModeButton->isChecked() + ? QGraphicsView::RubberBandDrag + : QGraphicsView::ScrollHandDrag); + graphicsView->setInteractive(selectModeButton->isChecked()); +} + void View::toggleOpenGL() { #ifndef QT_NO_OPENGL @@ -212,14 +254,14 @@ void View::print() #endif } -void View::zoomIn() +void View::zoomIn(int level) { - zoomSlider->setValue(zoomSlider->value() + 1); + zoomSlider->setValue(zoomSlider->value() + level); } -void View::zoomOut() +void View::zoomOut(int level) { - zoomSlider->setValue(zoomSlider->value() - 1); + zoomSlider->setValue(zoomSlider->value() - level); } void View::rotateLeft() diff --git a/demos/chip/view.h b/demos/chip/view.h index 8047b8b..67c7675 100644 --- a/demos/chip/view.h +++ b/demos/chip/view.h @@ -43,12 +43,27 @@ #define VIEW_H #include <QFrame> +#include <QGraphicsView> -QT_FORWARD_DECLARE_CLASS(QGraphicsView) QT_FORWARD_DECLARE_CLASS(QLabel) QT_FORWARD_DECLARE_CLASS(QSlider) QT_FORWARD_DECLARE_CLASS(QToolButton) +class View; + +class GraphicsView : public QGraphicsView +{ + Q_OBJECT +public: + GraphicsView(View *v) : QGraphicsView(), view(v) { } + +protected: + void wheelEvent(QWheelEvent *); + +private: + View *view; +}; + class View : public QFrame { Q_OBJECT @@ -57,22 +72,27 @@ public: QGraphicsView *view() const; +public slots: + void zoomIn(int level = 1); + void zoomOut(int level = 1); + private slots: void resetView(); void setResetButtonEnabled(); void setupMatrix(); + void togglePointerMode(); void toggleOpenGL(); void toggleAntialiasing(); void print(); - - void zoomIn(); - void zoomOut(); void rotateLeft(); void rotateRight(); - + private: - QGraphicsView *graphicsView; + GraphicsView *graphicsView; QLabel *label; + QLabel *label2; + QToolButton *selectModeButton; + QToolButton *dragModeButton; QToolButton *openGlButton; QToolButton *antialiasButton; QToolButton *printButton; diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 641b42b..9add36e 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -166,11 +166,12 @@ Q_GLOBAL_STATIC(QThreadStorage<QUnifiedTimer *>, unifiedTimer) #endif QUnifiedTimer::QUnifiedTimer() : - QObject(), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), + QObject(), defaultDriver(this), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), currentAnimationIdx(0), consistentTiming(false), slowMode(false), slowdownFactor(5.0f), isPauseTimerActive(false), runningLeafAnimations(0) { time.invalidate(); + driver = &defaultDriver; } @@ -247,14 +248,27 @@ void QUnifiedTimer::restartAnimationTimer() qDebug() << runningPauseAnimations; qDebug() << closestPauseAnimationTimeToFinish(); } + driver->stop(); animationTimer.start(closestTimeToFinish, this); isPauseTimerActive = true; - } else if (!animationTimer.isActive() || isPauseTimerActive) { - animationTimer.start(timingInterval, this); + } else if (!driver->isRunning() || isPauseTimerActive) { + driver->start(); isPauseTimerActive = false; } } +void QUnifiedTimer::setTimingInterval(int interval) +{ + timingInterval = interval; + + if (driver->isRunning() && !isPauseTimerActive) { + //we changed the timing interval + driver->stop(); + driver->start(); + } +} + + void QUnifiedTimer::timerEvent(QTimerEvent *event) { //in the case of consistent timing we make sure the orders in which events come is always the same @@ -369,6 +383,129 @@ int QUnifiedTimer::closestPauseAnimationTimeToFinish() return closestTimeToFinish; } +void QUnifiedTimer::installAnimationDriver(QAnimationDriver *d) +{ + if (driver->isRunning()) { + qWarning("QUnifiedTimer: Cannot change animation driver while animations are running"); + return; + } + + if (driver && driver != &defaultDriver) + delete driver; + + driver = d; +} + +/*! + \class QAnimationDriver + + \brief The QAnimationDriver class is used to exchange the mechanism that drives animations. + + The default animation system is driven by a timer that fires at regular intervals. + In some scenarios, it is better to drive the animation based on other synchronization + mechanisms, such as the vertical refresh rate of the screen. + */ + +QAnimationDriver::QAnimationDriver(QObject *parent) + : QObject(*(new QAnimationDriverPrivate), parent) +{ +} + +QAnimationDriver::QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ +} + + +/*! + Advances the animation based on the current time. This function should + be continuously called by the driver while the animation is running. + */ +void QAnimationDriver::advance() +{ + QUnifiedTimer *instance = QUnifiedTimer::instance(); + + // update current time on all top level animations + instance->updateAnimationsTime(); + instance->restartAnimationTimer(); +} + + +/*! + Installs this animation driver. The animation driver is thread local and + will only apply for the thread its installed in. + */ +void QAnimationDriver::install() +{ + QUnifiedTimer *timer = QUnifiedTimer::instance(true); + timer->installAnimationDriver(this); +} + +bool QAnimationDriver::isRunning() const +{ + return d_func()->running; +} + + +void QAnimationDriver::start() +{ + Q_D(QAnimationDriver); + if (!d->running) { + started(); + d->running = true; + } +} + + +void QAnimationDriver::stop() +{ + Q_D(QAnimationDriver); + if (d->running) { + stopped(); + d->running = false; + } +} + +/*! + \fn QAnimationDriver::started() + + This function is called by the animation framework to notify the driver + that it should start running. + */ + +/*! + \fn QAnimationDriver::stopped() + + This function is called by the animation framework to notify the driver + that it should stop running. + */ + +/*! + The default animation driver just spins the timer... + */ +QDefaultAnimationDriver::QDefaultAnimationDriver(QUnifiedTimer *timer) + : QAnimationDriver(0), m_unified_timer(timer) +{ +} + +void QDefaultAnimationDriver::timerEvent(QTimerEvent *e) +{ + Q_ASSERT(e->timerId() == m_timer.timerId()); + advance(); +} + +void QDefaultAnimationDriver::started() +{ + m_timer.start(m_unified_timer->timingInterval, this); +} + +void QDefaultAnimationDriver::stopped() +{ + m_timer.stop(); +} + + + void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) { Q_Q(QAbstractAnimation); @@ -794,6 +931,9 @@ void QAbstractAnimation::stop() { Q_D(QAbstractAnimation); + if (d->state == Stopped) + return; + d->setState(Stopped); } diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h index d3c0d0d..6abe8c1 100644 --- a/src/corelib/animation/qabstractanimation.h +++ b/src/corelib/animation/qabstractanimation.h @@ -54,6 +54,7 @@ QT_MODULE(Core) class QAnimationGroup; class QSequentialAnimationGroup; +class QAnimationDriver; class QAbstractAnimationPrivate; class Q_CORE_EXPORT QAbstractAnimation : public QObject @@ -132,6 +133,36 @@ private: Q_DECLARE_PRIVATE(QAbstractAnimation) }; +class QAnimationDriverPrivate; +class Q_CORE_EXPORT QAnimationDriver : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QAnimationDriver) + +public: + QAnimationDriver(QObject *parent); + + void advance(); + void install(); + + bool isRunning() const; + +protected: + virtual void started() = 0; + virtual void stopped() = 0; + + QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent = 0); + +private: + friend class QUnifiedTimer; + + void start(); + void stop(); +}; + + + + #endif //QT_NO_ANIMATION QT_END_NAMESPACE diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index d3d4098..d56c130 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -58,6 +58,7 @@ #include <QtCore/qtimer.h> #include <QtCore/qelapsedtimer.h> #include <private/qobject_p.h> +#include <qabstractanimation.h> #ifdef Q_OS_WIN #include <qt_windows.h> @@ -114,30 +115,47 @@ private: Q_DECLARE_PUBLIC(QAbstractAnimation) }; + +class QUnifiedTimer; +class QDefaultAnimationDriver : public QAnimationDriver +{ + Q_OBJECT +public: + QDefaultAnimationDriver(QUnifiedTimer *timer); + void timerEvent(QTimerEvent *e); + + void started(); + void stopped(); + +private: + QBasicTimer m_timer; + QUnifiedTimer *m_unified_timer; +}; + +class Q_CORE_EXPORT QAnimationDriverPrivate : public QObjectPrivate +{ +public: + QAnimationDriverPrivate() : running(false) {} + bool running; +}; + typedef QElapsedTimer ElapsedTimer; -class QUnifiedTimer : public QObject +class Q_CORE_EXPORT QUnifiedTimer : public QObject { private: QUnifiedTimer(); public: //XXX this is needed by dui - static Q_CORE_EXPORT QUnifiedTimer *instance(); + static QUnifiedTimer *instance(); static QUnifiedTimer *instance(bool create); static void registerAnimation(QAbstractAnimation *animation, bool isTopLevel); static void unregisterAnimation(QAbstractAnimation *animation); //defines the timing interval. Default is DEFAULT_TIMER_INTERVAL - void setTimingInterval(int interval) - { - timingInterval = interval; - if (animationTimer.isActive() && !isPauseTimerActive) { - //we changed the timing interval - animationTimer.start(timingInterval, this); - } - } + void setTimingInterval(int interval); /* this allows to have a consistent timer interval at each tick from the timer @@ -161,11 +179,20 @@ public: */ static void updateAnimationTimer(); + void installAnimationDriver(QAnimationDriver *driver); + + void restartAnimationTimer(); + void updateAnimationsTime(); + protected: void timerEvent(QTimerEvent *); private: - // timer used for all active (running) animations + friend class QDefaultAnimationDriver; + + QAnimationDriver *driver; + QDefaultAnimationDriver defaultDriver; + QBasicTimer animationTimer; // timer used to delay the check if we should start/stop the animation timer QBasicTimer startStopAnimationTimer; @@ -195,9 +222,6 @@ private: void registerRunningAnimation(QAbstractAnimation *animation); void unregisterRunningAnimation(QAbstractAnimation *animation); - void restartAnimationTimer(); - - void updateAnimationsTime(); int closestPauseAnimationTimeToFinish(); }; diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 0d39bb5..73f1493 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -80,9 +80,7 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < yourself, you can call setSceneRect(). This will adjust the scroll bars' ranges appropriately. Note that although the scene supports a virtually unlimited size, the range of the scroll bars will never exceed the range of - an integer (INT_MIN, INT_MAX). When the scene is larger than the scroll - bars' values, you can choose to use translate() to navigate the scene - instead. + an integer (INT_MIN, INT_MAX). QGraphicsView visualizes the scene by calling render(). By default, the items are drawn onto the viewport by using a regular QPainter, and using @@ -101,7 +99,8 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < convenience functions rotate(), scale(), translate() or shear(). The most two common transformations are scaling, which is used to implement zooming, and rotation. QGraphicsView keeps the center of the view fixed - during a transformation. + during a transformation. Because of the scene alignment (setAligment()), + translating the view will have no visual impact. You can interact with the items on the scene by using the mouse and keyboard. QGraphicsView translates the mouse and key events into \e scene diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index e5364d0..3aafeb4 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -549,7 +549,7 @@ void qt_mac_update_os_settings() FontMap("QTipLabel", kThemeSmallSystemFont), FontMap("QLabel", kThemeSystemFont), FontMap("QToolButton", kThemeSmallSystemFont), - FontMap("QMenuItem", kThemeMenuItemCmdKeyFont), // It doesn't exist, but its unique. + FontMap("QMenuItem", kThemeMenuItemFont), // It doesn't exist, but its unique. FontMap("QComboLineEdit", kThemeViewsFont), // It doesn't exist, but its unique. FontMap("QSmallFont", kThemeSmallSystemFont), // It doesn't exist, but its unique. FontMap("QMiniFont", kThemeMiniSystemFont), // It doesn't exist, but its unique. diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index 217723f..ae73d7d 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -251,6 +251,11 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi #ifdef Q_WS_MAC + // This is mainly done for native components like native "open file" dialog. + if (widget->testAttribute(Qt::WA_DontShowOnScreen)) { + return; + } + #ifdef QT_MAC_USE_COCOA // Unified toolbar hack. QMainWindow* mWindow = qobject_cast<QMainWindow*>(widget->window()); diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm index 7efb1cc..51e18ec 100644 --- a/src/gui/text/qfontengine_mac.mm +++ b/src/gui/text/qfontengine_mac.mm @@ -694,7 +694,7 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, QFixed subPixelPosition CGContextSetFont(ctx, cgFont); qreal pos_x = -br.x.toReal() + subPixelPosition.toReal(); - qreal pos_y = im.height()+br.y.toReal(); + qreal pos_y = im.height() + br.y.toReal() - 1; CGContextSetTextPosition(ctx, pos_x, pos_y); CGSize advance; diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index f4f2168..06eed55 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -612,7 +612,7 @@ static bool bidiItemize(QTextEngine *engine, QScriptAnalysis *analysis, QBidiCon } else { eor = current; } - dir = QChar::DirON; status.eor = QChar::DirAN; + dir = QChar::DirAN; status.eor = QChar::DirAN; break; case QChar::DirCS: if(status.eor == QChar::DirAN) { diff --git a/tests/auto/qcomplextext/tst_qcomplextext.cpp b/tests/auto/qcomplextext/tst_qcomplextext.cpp index 4a96725..fa8a2d1 100644 --- a/tests/auto/qcomplextext/tst_qcomplextext.cpp +++ b/tests/auto/qcomplextext/tst_qcomplextext.cpp @@ -68,6 +68,7 @@ public slots: private slots: void bidiReorderString_data(); void bidiReorderString(); + void bidiCursor_qtbug2795(); }; tst_QComplexText::tst_QComplexText() @@ -159,6 +160,28 @@ void tst_QComplexText::bidiReorderString() QTEST(visual, "VISUAL"); } +void tst_QComplexText::bidiCursor_qtbug2795() +{ + QString str = QString::fromUtf8("الجزيرة نت"); + QTextLayout l1(str); + + l1.beginLayout(); + QTextLine line1 = l1.createLine(); + l1.endLayout(); + + qreal x1 = line1.cursorToX(0) - line1.cursorToX(str.size()); + + str.append("1"); + QTextLayout l2(str); + l2.beginLayout(); + QTextLine line2 = l2.createLine(); + l2.endLayout(); + + qreal x2 = line2.cursorToX(0) - line2.cursorToX(str.size()); + + // The cursor should remain at the same position after a digit is appended + QVERIFY(x1 == x2); +} QTEST_MAIN(tst_QComplexText) #include "tst_qcomplextext.moc" diff --git a/tests/auto/qpauseanimation/tst_qpauseanimation.cpp b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp index 605cee6..378eb1c 100644 --- a/tests/auto/qpauseanimation/tst_qpauseanimation.cpp +++ b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp @@ -394,7 +394,10 @@ void tst_QPauseAnimation::multipleSequentialGroups() QVERIFY(subgroup3.state() == QAbstractAnimation::Running); QVERIFY(subgroup4.state() == QAbstractAnimation::Running); - QTest::qWait(group.totalDuration() + 100); + // This is a pretty long animation so it tends to get rather out of sync + // when using the consistent timer, so run for an extra half second for good + // measure... + QTest::qWait(group.totalDuration() + 500); #ifdef Q_OS_WIN if (group.state() != QAbstractAnimation::Stopped) |