QGuiApplication::layoutDirectionChanged(Qt::LayoutDirection) [signal]
This allows QQuickApplication to listen to layout direction changes without installing an expensive event filter on the application object. Change-Id: I2d7d8906acecbc092657c4bd918bbdc9aad9744c Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>bb10
parent
61c3ab9967
commit
b69d537d7f
|
|
@ -3077,6 +3077,8 @@ void QGuiApplicationPrivate::saveState()
|
|||
On system start-up, the default layout direction depends on the
|
||||
application's language.
|
||||
|
||||
The notifier signal was introduced in Qt 5.4.
|
||||
|
||||
\sa QWidget::layoutDirection, isLeftToRight(), isRightToLeft()
|
||||
*/
|
||||
|
||||
|
|
@ -3087,7 +3089,10 @@ void QGuiApplication::setLayoutDirection(Qt::LayoutDirection direction)
|
|||
|
||||
layout_direction = direction;
|
||||
|
||||
QGuiApplicationPrivate::self->notifyLayoutDirectionChange();
|
||||
if (qGuiApp) {
|
||||
emit qGuiApp->layoutDirectionChanged(direction);
|
||||
QGuiApplicationPrivate::self->notifyLayoutDirectionChange();
|
||||
}
|
||||
}
|
||||
|
||||
Qt::LayoutDirection QGuiApplication::layoutDirection()
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
|
||||
Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName)
|
||||
Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection)
|
||||
Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
|
||||
Q_PROPERTY(QString platformName READ platformName STORED false)
|
||||
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
|
||||
|
||||
|
|
@ -169,6 +169,7 @@ Q_SIGNALS:
|
|||
void focusObjectChanged(QObject *focusObject);
|
||||
void focusWindowChanged(QWindow *focusWindow);
|
||||
void applicationStateChanged(Qt::ApplicationState state);
|
||||
void layoutDirectionChanged(Qt::LayoutDirection direction);
|
||||
#ifndef QT_NO_SESSIONMANAGER
|
||||
void commitDataRequest(QSessionManager &sessionManager);
|
||||
void saveStateRequest(QSessionManager &sessionManager);
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ private slots:
|
|||
void modalWindow();
|
||||
void quitOnLastWindowClosed();
|
||||
void genericPluginsAndWindowSystemEvents();
|
||||
void layoutDirection();
|
||||
};
|
||||
|
||||
void tst_QGuiApplication::displayName()
|
||||
|
|
@ -848,4 +849,30 @@ void tst_QGuiApplication::genericPluginsAndWindowSystemEvents()
|
|||
QCOMPARE(testReceiver.customEvents, 1);
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Qt::LayoutDirection)
|
||||
void tst_QGuiApplication::layoutDirection()
|
||||
{
|
||||
qRegisterMetaType<Qt::LayoutDirection>();
|
||||
|
||||
Qt::LayoutDirection oldDirection = QGuiApplication::layoutDirection();
|
||||
Qt::LayoutDirection newDirection = oldDirection == Qt::LeftToRight ? Qt::RightToLeft : Qt::LeftToRight;
|
||||
|
||||
QGuiApplication::setLayoutDirection(newDirection);
|
||||
QCOMPARE(QGuiApplication::layoutDirection(), newDirection);
|
||||
|
||||
int argc = 1;
|
||||
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
||||
QGuiApplication app(argc, argv);
|
||||
QSignalSpy signalSpy(&app, SIGNAL(layoutDirectionChanged(Qt::LayoutDirection)));
|
||||
|
||||
QGuiApplication::setLayoutDirection(oldDirection);
|
||||
QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
|
||||
QCOMPARE(signalSpy.count(), 1);
|
||||
QCOMPARE(signalSpy.at(0).at(0).toInt(), static_cast<int>(oldDirection));
|
||||
|
||||
QGuiApplication::setLayoutDirection(oldDirection);
|
||||
QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
|
||||
QCOMPARE(signalSpy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QGuiApplication)
|
||||
|
|
|
|||
Loading…
Reference in New Issue