move layoutDirection from QApplication to QGuiApplication
The concept is needed in both QWidgets and QML, so it has to be in QGuiApplication.
This commit is contained in:
parent
91d2b267f1
commit
5df3d517b4
@ -480,7 +480,6 @@ static int drag_distance = 12; //XXX move to qplatformdefs.h
|
||||
#else
|
||||
static int drag_distance = QT_GUI_DRAG_DISTANCE;
|
||||
#endif
|
||||
static Qt::LayoutDirection layout_direction = Qt::LeftToRight;
|
||||
QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut
|
||||
bool QApplicationPrivate::animate_ui = true;
|
||||
bool QApplicationPrivate::animate_menu = false;
|
||||
@ -502,7 +501,6 @@ QWidget *QApplicationPrivate::oldEditFocus = 0;
|
||||
#endif
|
||||
|
||||
bool qt_tabletChokeMouse = false;
|
||||
static bool force_reverse = false;
|
||||
|
||||
inline bool QApplicationPrivate::isAlien(QWidget *widget)
|
||||
{
|
||||
@ -590,9 +588,6 @@ void QApplicationPrivate::process_cmdline()
|
||||
styleSheet = QLatin1String("file:///");
|
||||
styleSheet.append(QString::fromLocal8Bit(arg.right(arg.length() - 12)));
|
||||
#endif
|
||||
} else if (qstrcmp(arg, "-reverse") == 0) {
|
||||
force_reverse = true;
|
||||
QApplication::setLayoutDirection(Qt::RightToLeft);
|
||||
} else if (qstrcmp(arg, "-widgetcount") == 0) {
|
||||
widgetCount = true;
|
||||
} else if (qstrcmp(arg, "-testability") == 0) {
|
||||
@ -1156,7 +1151,6 @@ QApplication::~QApplication()
|
||||
|
||||
drag_time = 500;
|
||||
drag_distance = 4;
|
||||
layout_direction = Qt::LeftToRight;
|
||||
QApplicationPrivate::app_strut = QSize(0, 0);
|
||||
QApplicationPrivate::animate_ui = true;
|
||||
QApplicationPrivate::animate_menu = false;
|
||||
@ -2337,14 +2331,6 @@ void QApplication::aboutQt()
|
||||
*/
|
||||
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
static bool qt_detectRTLLanguage()
|
||||
{
|
||||
return force_reverse ^
|
||||
(QApplication::tr("QT_LAYOUT_DIRECTION",
|
||||
"Translate this string to the string 'LTR' in left-to-right"
|
||||
" languages or to 'RTL' in right-to-left languages (such as Hebrew"
|
||||
" and Arabic) to get proper widget layout.") == QLatin1String("RTL"));
|
||||
}
|
||||
#if defined(Q_WS_MAC)
|
||||
static const char *application_menu_strings[] = {
|
||||
QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Services"),
|
||||
@ -2401,19 +2387,6 @@ bool QApplication::event(QEvent *e)
|
||||
qt_abortFullScreenEffect();
|
||||
#endif
|
||||
}
|
||||
} else if(e->type() == QEvent::LanguageChange) {
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
setLayoutDirection(qt_detectRTLLanguage()?Qt::RightToLeft:Qt::LeftToRight);
|
||||
#endif
|
||||
#if defined(QT_MAC_USE_COCOA)
|
||||
qt_mac_post_retranslateAppMenu();
|
||||
#endif
|
||||
QWidgetList list = topLevelWidgets();
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QWidget *w = list.at(i);
|
||||
if (!(w->windowType() == Qt::Desktop))
|
||||
postEvent(w, new QEvent(QEvent::LanguageChange));
|
||||
}
|
||||
#ifndef Q_OS_WIN
|
||||
} else if (e->type() == QEvent::LocaleChange) {
|
||||
// on Windows the event propagation is taken care by the
|
||||
@ -2455,6 +2428,19 @@ bool QApplication::event(QEvent *e)
|
||||
}
|
||||
}
|
||||
return QApplicationBase::event(e);
|
||||
|
||||
if(e->type() == QEvent::LanguageChange) {
|
||||
#if defined(QT_MAC_USE_COCOA)
|
||||
qt_mac_post_retranslateAppMenu();
|
||||
#endif
|
||||
QWidgetList list = topLevelWidgets();
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QWidget *w = list.at(i);
|
||||
if (!(w->windowType() == Qt::Desktop))
|
||||
postEvent(w, new QEvent(QEvent::LanguageChange));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#if !defined(Q_WS_X11)
|
||||
|
||||
@ -2464,6 +2450,18 @@ void QApplication::syncX() {} // do nothing
|
||||
|
||||
#endif
|
||||
|
||||
void QApplicationPrivate::notifyLayoutDirectionChange()
|
||||
{
|
||||
Q_Q(QApplication);
|
||||
QWidgetList list = q->topLevelWidgets();
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QWidget *w = list.at(i);
|
||||
QEvent ev(QEvent::ApplicationLayoutDirectionChange);
|
||||
q->sendEvent(w, &ev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\fn Qt::WindowsVersion QApplication::winVersion()
|
||||
|
||||
@ -3548,54 +3546,6 @@ int QApplication::startDragDistance()
|
||||
Use layoutDirection() instead.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QApplication::isRightToLeft()
|
||||
|
||||
Returns true if the application's layout direction is
|
||||
Qt::RightToLeft; otherwise returns false.
|
||||
|
||||
\sa layoutDirection(), isLeftToRight()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QApplication::isLeftToRight()
|
||||
|
||||
Returns true if the application's layout direction is
|
||||
Qt::LeftToRight; otherwise returns false.
|
||||
|
||||
\sa layoutDirection(), isRightToLeft()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\property QApplication::layoutDirection
|
||||
\brief the default layout direction for this application
|
||||
|
||||
On system start-up, the default layout direction depends on the
|
||||
application's language.
|
||||
|
||||
\sa QWidget::layoutDirection, isLeftToRight(), isRightToLeft()
|
||||
*/
|
||||
|
||||
void QApplication::setLayoutDirection(Qt::LayoutDirection direction)
|
||||
{
|
||||
if (layout_direction == direction || direction == Qt::LayoutDirectionAuto)
|
||||
return;
|
||||
|
||||
layout_direction = direction;
|
||||
|
||||
QWidgetList list = topLevelWidgets();
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QWidget *w = list.at(i);
|
||||
QEvent ev(QEvent::ApplicationLayoutDirectionChange);
|
||||
sendEvent(w, &ev);
|
||||
}
|
||||
}
|
||||
|
||||
Qt::LayoutDirection QApplication::layoutDirection()
|
||||
{
|
||||
return layout_direction;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
|
@ -105,7 +105,6 @@ class QApplicationPrivate;
|
||||
class Q_GUI_EXPORT QApplication : public QApplicationBase
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection)
|
||||
Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
|
||||
Q_PROPERTY(int cursorFlashTime READ cursorFlashTime WRITE setCursorFlashTime)
|
||||
Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval)
|
||||
@ -233,12 +232,6 @@ public:
|
||||
static void setStartDragDistance(int l);
|
||||
static int startDragDistance();
|
||||
|
||||
static void setLayoutDirection(Qt::LayoutDirection direction);
|
||||
static Qt::LayoutDirection layoutDirection();
|
||||
|
||||
static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; }
|
||||
static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; }
|
||||
|
||||
static bool isEffectEnabled(Qt::UIEffect);
|
||||
static void setEffectEnabled(Qt::UIEffect, bool enable = true);
|
||||
|
||||
|
@ -303,6 +303,8 @@ public:
|
||||
QApplicationPrivate(int &argc, char **argv, QApplication::Type type, int flags);
|
||||
~QApplicationPrivate();
|
||||
|
||||
virtual void notifyLayoutDirectionChange();
|
||||
|
||||
#if defined(Q_WS_X11)
|
||||
#ifndef QT_NO_SETTINGS
|
||||
static bool x11_apply_settings();
|
||||
|
@ -94,6 +94,9 @@ int QGuiApplicationPrivate::mousePressX = 0;
|
||||
int QGuiApplicationPrivate::mousePressY = 0;
|
||||
int QGuiApplicationPrivate::mouse_double_click_distance = 5;
|
||||
|
||||
static Qt::LayoutDirection layout_direction = Qt::LeftToRight;
|
||||
static bool force_reverse = false;
|
||||
|
||||
QGuiApplicationPrivate *QGuiApplicationPrivate::self = 0;
|
||||
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
@ -103,6 +106,16 @@ QClipboard *QGuiApplicationPrivate::qt_clipboard = 0;
|
||||
Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
|
||||
QFont *QGuiApplicationPrivate::app_font = 0;
|
||||
|
||||
static bool qt_detectRTLLanguage()
|
||||
{
|
||||
return force_reverse ^
|
||||
(QApplication::tr("QT_LAYOUT_DIRECTION",
|
||||
"Translate this string to the string 'LTR' in left-to-right"
|
||||
" languages or to 'RTL' in right-to-left languages (such as Hebrew"
|
||||
" and Arabic) to get proper widget layout.") == QLatin1String("RTL"));
|
||||
}
|
||||
|
||||
|
||||
QGuiApplication::QGuiApplication(int &argc, char **argv, int flags)
|
||||
: QCoreApplication(*new QGuiApplicationPrivate(argc, argv, flags))
|
||||
{
|
||||
@ -213,6 +226,9 @@ void QGuiApplicationPrivate::init()
|
||||
} else if (arg == "-plugin") {
|
||||
if (++i < argc)
|
||||
pluginList << argv[i];
|
||||
} else if (arg == "-reverse") {
|
||||
force_reverse = true;
|
||||
QGuiApplication::setLayoutDirection(Qt::RightToLeft);
|
||||
} else {
|
||||
argv[j++] = argv[i];
|
||||
}
|
||||
@ -245,6 +261,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
|
||||
is_app_running = false;
|
||||
|
||||
QFont::cleanup();
|
||||
|
||||
layout_direction = Qt::LeftToRight;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -314,6 +332,9 @@ bool QGuiApplication::notify(QObject *object, QEvent *event)
|
||||
|
||||
bool QGuiApplication::event(QEvent *e)
|
||||
{
|
||||
if(e->type() == QEvent::LanguageChange) {
|
||||
setLayoutDirection(qt_detectRTLLanguage()?Qt::RightToLeft:Qt::LeftToRight);
|
||||
}
|
||||
return QCoreApplication::event(e);
|
||||
}
|
||||
|
||||
@ -816,4 +837,53 @@ void QGuiApplication::setFont(const QFont &font)
|
||||
*QGuiApplicationPrivate::app_font = font;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool QGuiApplication::isRightToLeft()
|
||||
|
||||
Returns true if the application's layout direction is
|
||||
Qt::RightToLeft; otherwise returns false.
|
||||
|
||||
\sa layoutDirection(), isLeftToRight()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QGuiApplication::isLeftToRight()
|
||||
|
||||
Returns true if the application's layout direction is
|
||||
Qt::LeftToRight; otherwise returns false.
|
||||
|
||||
\sa layoutDirection(), isRightToLeft()
|
||||
*/
|
||||
|
||||
void QGuiApplicationPrivate::notifyLayoutDirectionChange()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QGuiApplication::layoutDirection
|
||||
\brief the default layout direction for this application
|
||||
|
||||
On system start-up, the default layout direction depends on the
|
||||
application's language.
|
||||
|
||||
\sa QWidget::layoutDirection, isLeftToRight(), isRightToLeft()
|
||||
*/
|
||||
|
||||
void QGuiApplication::setLayoutDirection(Qt::LayoutDirection direction)
|
||||
{
|
||||
if (layout_direction == direction || direction == Qt::LayoutDirectionAuto)
|
||||
return;
|
||||
|
||||
layout_direction = direction;
|
||||
|
||||
QGuiApplicationPrivate::self->notifyLayoutDirectionChange();
|
||||
}
|
||||
|
||||
Qt::LayoutDirection QGuiApplication::layoutDirection()
|
||||
{
|
||||
return layout_direction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -59,6 +59,7 @@ class QPlatformNativeInterface;
|
||||
class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection)
|
||||
Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval)
|
||||
Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
|
||||
|
||||
@ -91,6 +92,12 @@ public:
|
||||
static void setKeyboardInputInterval(int);
|
||||
static int keyboardInputInterval();
|
||||
|
||||
static void setLayoutDirection(Qt::LayoutDirection direction);
|
||||
static Qt::LayoutDirection layoutDirection();
|
||||
|
||||
static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; }
|
||||
static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; }
|
||||
|
||||
static QPlatformNativeInterface *platformNativeInterface();
|
||||
|
||||
static int exec();
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
|
||||
void createEventDispatcher();
|
||||
|
||||
virtual void notifyLayoutDirectionChange();
|
||||
|
||||
static int keyboard_input_time;
|
||||
static int mouse_double_click_time;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user