From 349e04eb7c173ad6e01b866d4c0d517f89e2a201 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 22 Feb 2012 09:25:01 +0200 Subject: Migrate evdev plugins to the new plugin system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7eb283646b7529080c8c2f41c267b0135c8f57e4 Reviewed-by: Samuel Rødal --- src/plugins/generic/evdevkeyboard/evdevkeyboard.json | 3 +++ src/plugins/generic/evdevkeyboard/evdevkeyboard.pro | 3 +++ src/plugins/generic/evdevkeyboard/main.cpp | 7 +++++-- src/plugins/generic/evdevmouse/evdevmouse.json | 3 +++ src/plugins/generic/evdevmouse/evdevmouse.pro | 3 +++ src/plugins/generic/evdevmouse/main.cpp | 7 +++++-- src/plugins/generic/evdevtouch/evdevtouch.json | 3 +++ src/plugins/generic/evdevtouch/evdevtouch.pro | 3 +++ src/plugins/generic/evdevtouch/main.cpp | 7 +++++-- 9 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/plugins/generic/evdevkeyboard/evdevkeyboard.json create mode 100644 src/plugins/generic/evdevmouse/evdevmouse.json create mode 100644 src/plugins/generic/evdevtouch/evdevtouch.json (limited to 'src') diff --git a/src/plugins/generic/evdevkeyboard/evdevkeyboard.json b/src/plugins/generic/evdevkeyboard/evdevkeyboard.json new file mode 100644 index 0000000000..0e24bb0568 --- /dev/null +++ b/src/plugins/generic/evdevkeyboard/evdevkeyboard.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "EvdevKeyboard" ] +} diff --git a/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro b/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro index 997a58ef6e..47608b7154 100644 --- a/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro +++ b/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro @@ -17,3 +17,6 @@ LIBS += -ludev SOURCES = main.cpp \ qevdevkeyboardhandler.cpp \ qevdevkeyboardmanager.cpp + +OTHER_FILES += \ + evdevkeyboard.json diff --git a/src/plugins/generic/evdevkeyboard/main.cpp b/src/plugins/generic/evdevkeyboard/main.cpp index 6df4e29fcb..71d15720bd 100644 --- a/src/plugins/generic/evdevkeyboard/main.cpp +++ b/src/plugins/generic/evdevkeyboard/main.cpp @@ -46,6 +46,9 @@ QT_BEGIN_NAMESPACE class QEvdevKeyboardPlugin : public QGenericPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "evdevkeyboard.json") + public: QEvdevKeyboardPlugin(); @@ -72,6 +75,6 @@ QObject* QEvdevKeyboardPlugin::create(const QString &key, return 0; } -Q_EXPORT_PLUGIN2(qevdevkeyboardplugin, QEvdevKeyboardPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/generic/evdevmouse/evdevmouse.json b/src/plugins/generic/evdevmouse/evdevmouse.json new file mode 100644 index 0000000000..00ddd3a9cf --- /dev/null +++ b/src/plugins/generic/evdevmouse/evdevmouse.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "EvdevMouse" ] +} diff --git a/src/plugins/generic/evdevmouse/evdevmouse.pro b/src/plugins/generic/evdevmouse/evdevmouse.pro index f25199161b..c5d162fb2f 100644 --- a/src/plugins/generic/evdevmouse/evdevmouse.pro +++ b/src/plugins/generic/evdevmouse/evdevmouse.pro @@ -11,3 +11,6 @@ QT += core-private platformsupport-private SOURCES = main.cpp \ qevdevmouse.cpp + +OTHER_FILES += \ + evdevmouse.json diff --git a/src/plugins/generic/evdevmouse/main.cpp b/src/plugins/generic/evdevmouse/main.cpp index 34ca62f960..47a4ddf56b 100644 --- a/src/plugins/generic/evdevmouse/main.cpp +++ b/src/plugins/generic/evdevmouse/main.cpp @@ -46,6 +46,9 @@ QT_BEGIN_NAMESPACE class QEvdevMousePlugin : public QGenericPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "evdevmouse.json") + public: QEvdevMousePlugin(); @@ -72,6 +75,6 @@ QObject* QEvdevMousePlugin::create(const QString &key, return 0; } -Q_EXPORT_PLUGIN2(qevdevmouseplugin, QEvdevMousePlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/generic/evdevtouch/evdevtouch.json b/src/plugins/generic/evdevtouch/evdevtouch.json new file mode 100644 index 0000000000..6a6959c8e6 --- /dev/null +++ b/src/plugins/generic/evdevtouch/evdevtouch.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "EvdevTouch" ] +} diff --git a/src/plugins/generic/evdevtouch/evdevtouch.pro b/src/plugins/generic/evdevtouch/evdevtouch.pro index 78fe551aa2..284f1d1221 100644 --- a/src/plugins/generic/evdevtouch/evdevtouch.pro +++ b/src/plugins/generic/evdevtouch/evdevtouch.pro @@ -12,3 +12,6 @@ SOURCES = main.cpp \ qevdevtouch.cpp QT += core-private platformsupport-private + +OTHER_FILES += \ + evdevtouch.json diff --git a/src/plugins/generic/evdevtouch/main.cpp b/src/plugins/generic/evdevtouch/main.cpp index 526e336fd8..47b026ac96 100644 --- a/src/plugins/generic/evdevtouch/main.cpp +++ b/src/plugins/generic/evdevtouch/main.cpp @@ -46,6 +46,9 @@ QT_BEGIN_NAMESPACE class QTouchScreenPlugin : public QGenericPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "evdevtouch.json") + public: QTouchScreenPlugin(); @@ -71,6 +74,6 @@ QObject* QTouchScreenPlugin::create(const QString &key, return 0; } -Q_EXPORT_PLUGIN2(qevdevtouchplugin, QTouchScreenPlugin) - QT_END_NAMESPACE + +#include "main.moc" -- cgit v1.2.3 From 5d49ca960c942465adf0644ee382b91c35dfb650 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 16 Feb 2012 14:24:22 +0200 Subject: Fix typos Change-Id: Ic0389d36bad001935376fb29d8c925b7ff908e4f Reviewed-by: Joona Petrell --- src/gui/text/qabstracttextdocumentlayout.cpp | 2 +- src/widgets/util/qscrollerproperties.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/text/qabstracttextdocumentlayout.cpp b/src/gui/text/qabstracttextdocumentlayout.cpp index 7bf2a631ea..86de48b1dc 100644 --- a/src/gui/text/qabstracttextdocumentlayout.cpp +++ b/src/gui/text/qabstracttextdocumentlayout.cpp @@ -239,7 +239,7 @@ QT_BEGIN_NAMESPACE /*! \fn int QAbstractTextDocumentLayout::hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const - Returns the cursor postion for the given \a point with the specified + Returns the cursor position for the given \a point with the specified \a accuracy. Returns -1 if no valid cursor position was found. */ diff --git a/src/widgets/util/qscrollerproperties.cpp b/src/widgets/util/qscrollerproperties.cpp index 6a61e4dfd1..8d6ad36014 100644 --- a/src/widgets/util/qscrollerproperties.cpp +++ b/src/widgets/util/qscrollerproperties.cpp @@ -314,7 +314,7 @@ void QScrollerProperties::setScrollMetric(ScrollMetric metric, const QVariant &v \value MousePressEventDelay This is the time a mouse press event is delayed when starting a flick gesture in \c{[s]}. If the gesture is triggered within that time, no mouse press or release is sent to the scrolled object. If it triggers after that delay the delayed - mouse press plus a faked release event at global postion \c{QPoint(-QWIDGETSIZE_MAX, + mouse press plus a faked release event at global position \c{QPoint(-QWIDGETSIZE_MAX, -QWIDGETSIZE_MAX)} is sent. If the gesture is canceled, then both the delayed mouse press plus the real release event are delivered. -- cgit v1.2.3 From 9d173c92183c30144e8bd4f115b2cd93c3da0d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 20 Feb 2012 14:11:29 +0100 Subject: Updated QApplication / QGuiApplication to match Qt 5 reality. Removed obsolete Q_WS_X11/WIN/MAC stuff as well. Change-Id: I8b65a0348a8cb170f3f060023fc6d9d982949b7e Reviewed-by: Casper van Donderen Reviewed-by: Laszlo Agocs --- src/gui/kernel/qguiapplication.cpp | 236 +++++++++- src/widgets/kernel/qapplication.cpp | 627 +-------------------------- src/widgets/kernel/qapplication.h | 52 +-- src/widgets/kernel/qwidgetbackingstore.cpp | 2 - src/widgets/widgets/qwidgetresizehandler.cpp | 2 - 5 files changed, 248 insertions(+), 671 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 7cb3d4b488..17208643ef 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -145,6 +145,141 @@ static bool qt_detectRTLLanguage() } +/*! + \class QGuiApplication + \brief The QGuiApplication class manages the GUI application's control + flow and main settings. + + \inmodule QtGui + + QGuiApplication contains the main event loop, where all events from the window + system and other sources are processed and dispatched. It also handles the + application's initialization and finalization. In addition, QGuiApplication handles + most of the system-wide and application-wide settings. + + For any GUI application using Qt, there is precisely \bold one QGuiApplication + object no matter whether the application has 0, 1, 2 or more windows at + any given time. For non-GUI Qt applications, use QCoreApplication instead, + as it does not depend on the \l QtGui library. + + The QGuiApplication object is accessible through the instance() function, which + returns a pointer equivalent to the global \l qApp pointer. + + QGuiApplication's main areas of responsibility are: + \list + \o It initializes the application with the user's desktop settings, + such as palette(), font() and styleHints(). It keeps + track of these properties in case the user changes the desktop + globally, for example, through some kind of control panel. + + \o It performs event handling, meaning that it receives events + from the underlying window system and dispatches them to the + relevant widgets. You can send your own events to windows by + using sendEvent() and postEvent(). + + \o It parses common command line arguments and sets its internal + state accordingly. See the \l{QGuiApplication::QGuiApplication()} + {constructor documentation} below for more details. + + \o It provides localization of strings that are visible to the + user via translate(). + + \o It provides some magical objects like the clipboard(). + + \o It knows about the application's windows. You can ask which + window is at a certain position using topLevelAt(), get a list of + topLevelWindows(), etc. + + \o It manages the application's mouse cursor handling, see + setOverrideCursor() + \endlist + + Since the QGuiApplication object does so much initialization, it \e{must} be + created before any other objects related to the user interface are created. + QGuiApplication also deals with common command line arguments. Hence, it is + usually a good idea to create it \e before any interpretation or + modification of \c argv is done in the application itself. + + \table + \header + \o{2,1} Groups of functions + + \row + \o System settings + \o desktopSettingsAware(), + setDesktopSettingsAware(), + styleHints(), + palette(), + setPalette(), + font(), + setFont(). + + \row + \o Event handling + \o exec(), + processEvents(), + exit(), + quit(). + sendEvent(), + postEvent(), + sendPostedEvents(), + removePostedEvents(), + hasPendingEvents(), + notify(). + + \row + \o Windows + \o allWindows(), + topLevelWindows(), + focusWindow(), + clipboard(), + topLevelAt(). + + \row + \o Advanced cursor handling + \o overrideCursor(), + setOverrideCursor(), + restoreOverrideCursor(). + + \row + \o Miscellaneous + \o startingUp(), + closingDown(), + type(). + \endtable + + \sa QCoreApplication, QAbstractEventDispatcher, QEventLoop +*/ + +/*! + Initializes the window system and constructs an application object with + \a argc command line arguments in \a argv. + + \warning The data referred to by \a argc and \a argv must stay valid for + the entire lifetime of the QGuiApplication object. In addition, \a argc must + be greater than zero and \a argv must contain at least one valid character + string. + + The global \c qApp pointer refers to this application object. Only one + application object should be created. + + This application object must be constructed before any \l{QPaintDevice} + {paint devices} (including pixmaps, bitmaps etc.). + + \note \a argc and \a argv might be changed as Qt removes command line + arguments that it recognizes. + + All Qt programs automatically support the following command line options: + \list + \o -reverse, sets the application's layout direction to + Qt::RightToLeft + \o -qmljsdebugger=, activates the QML/JS debugger with a specified port. + The value must be of format port:1234[,block], where block is optional + and will make the application wait until a debugger connects to it. + \endlist + + \sa arguments() +*/ QGuiApplication::QGuiApplication(int &argc, char **argv, int flags) : QCoreApplication(*new QGuiApplicationPrivate(argc, argv, flags)) { @@ -159,6 +294,9 @@ QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p) d_func()->init(); } +/*! + Destructs the application. +*/ QGuiApplication::~QGuiApplication() { Q_D(QGuiApplication); @@ -194,6 +332,10 @@ QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags application_type = QCoreApplication::GuiClient; } +/*! + Returns the QWindow that receives events tied to focus, + such as key events. +*/ QWindow *QGuiApplication::focusWindow() { return QGuiApplicationPrivate::focus_window; @@ -208,7 +350,7 @@ QWindow *QGuiApplication::focusWindow() /*! Returns the QObject in currently active window that will be final receiver of events - tied focus, such as key events. + tied to focus, such as key events. */ QObject *QGuiApplication::focusObject() { @@ -249,6 +391,11 @@ QWindowList QGuiApplication::topLevelWindows() return topLevelWindows; } +/*! + Returns the primary (or default) screen of the application. + + This will be the screen where QWindows are shown, unless otherwise specified. +*/ QScreen *QGuiApplication::primaryScreen() { if (QGuiApplicationPrivate::screen_list.isEmpty()) @@ -256,11 +403,18 @@ QScreen *QGuiApplication::primaryScreen() return QGuiApplicationPrivate::screen_list.at(0); } +/*! + Returns a list of all the screens associated with the + windowing system the application is connected to. +*/ QList QGuiApplication::screens() { return QGuiApplicationPrivate::screen_list; } +/*! + Returns the top level window at the given position, if any. +*/ QWindow *QGuiApplication::topLevelAt(const QPoint &pos) { QList screens = QGuiApplication::screens(); @@ -557,27 +711,62 @@ static QClipboard *clipboard(); #endif #endif +/*! + Returns the currently held keyboard modifiers. +*/ Qt::KeyboardModifiers QGuiApplication::keyboardModifiers() { return QGuiApplicationPrivate::modifier_buttons; } +/*! + Returns the currently held mouse buttons. +*/ Qt::MouseButtons QGuiApplication::mouseButtons() { return QGuiApplicationPrivate::mouse_buttons; } +/*! + Returns the platform's native interface, for platform specific + functionality. +*/ QPlatformNativeInterface *QGuiApplication::platformNativeInterface() { QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); return pi->nativeInterface(); } +/*! + Enters the main event loop and waits until exit() is called, and then + returns the value that was set to exit() (which is 0 if exit() is called + via quit()). + + It is necessary to call this function to start event handling. The main + event loop receives events from the window system and dispatches these to + the application widgets. + + Generally, no user interaction can take place before calling exec(). + + To make your application perform idle processing, e.g., executing a special + function whenever there are no pending events, use a QTimer with 0 timeout. + More advanced idle processing schemes can be achieved using processEvents(). + + We recommend that you connect clean-up code to the + \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your + application's \c{main()} function. This is because, on some platforms, the + QApplication::exec() call may not return. + + \sa quitOnLastWindowClosed, quit(), exit(), processEvents(), + QCoreApplication::exec() +*/ int QGuiApplication::exec() { return QCoreApplication::exec(); } +/*! \reimp +*/ bool QGuiApplication::notify(QObject *object, QEvent *event) { #ifndef QT_NO_SHORTCUT @@ -595,6 +784,8 @@ bool QGuiApplication::notify(QObject *object, QEvent *event) return QCoreApplication::notify(object, event); } +/*! \reimp +*/ bool QGuiApplication::event(QEvent *e) { if(e->type() == QEvent::LanguageChange) { @@ -603,6 +794,9 @@ bool QGuiApplication::event(QEvent *e) return QCoreApplication::event(e); } +/*! + \internal +*/ bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) { return QCoreApplication::compressEvent(event, receiver, postedEvents); @@ -1364,6 +1558,9 @@ Qt::DropAction QGuiApplicationPrivate::processDrop(QWindow *w, QMimeData *dropDa } #ifndef QT_NO_CLIPBOARD +/*! + Returns the object for interacting with the clipboard. +*/ QClipboard * QGuiApplication::clipboard() { if (QGuiApplicationPrivate::qt_clipboard == 0) { @@ -1378,9 +1575,9 @@ QClipboard * QGuiApplication::clipboard() #endif /*! - Returns the application palette. + Returns the default application palette. - \sa setPalette(), QWidget::palette() + \sa setPalette() */ QPalette QGuiApplication::palette() { @@ -1392,6 +1589,11 @@ QPalette QGuiApplication::palette() return *QGuiApplicationPrivate::app_pal; } +/*! + Changes the default application palette to \a palette. + + \sa palette() +*/ void QGuiApplication::setPalette(const QPalette &pal) { if (QGuiApplicationPrivate::app_pal && pal.isCopyOf(*QGuiApplicationPrivate::app_pal)) @@ -1402,6 +1604,11 @@ void QGuiApplication::setPalette(const QPalette &pal) *QGuiApplicationPrivate::app_pal = pal; } +/*! + Returns the default application font. + + \sa setFont() +*/ QFont QGuiApplication::font() { QMutexLocker locker(&applicationFontMutex); @@ -1411,6 +1618,11 @@ QFont QGuiApplication::font() return *QGuiApplicationPrivate::app_font; } +/*! + Changes the default application font to \a font. + + \sa font() +*/ void QGuiApplication::setFont(const QFont &font) { QMutexLocker locker(&applicationFontMutex); @@ -1631,7 +1843,7 @@ void QGuiApplication::restoreOverrideCursor() /*! \since 5.0 - returns the style hints. + Returns the application's style hints. The style hints encapsulate a set of platform dependent properties such as double click intervals, full width selection and others. @@ -1675,6 +1887,14 @@ bool QGuiApplication::desktopSettingsAware() return QGuiApplicationPrivate::obey_desktop_settings; } +QInputMethod *QGuiApplication::inputMethod() const +{ + Q_D(const QGuiApplication); + if (!d->inputMethod) + const_cast(d)->inputMethod = new QInputMethod(); + return d->inputMethod; +} + /*! \since 5.0 @@ -1686,14 +1906,6 @@ bool QGuiApplication::desktopSettingsAware() \sa QInputPanel */ -QInputMethod *QGuiApplication::inputMethod() const -{ - Q_D(const QGuiApplication); - if (!d->inputMethod) - const_cast(d)->inputMethod = new QInputMethod(); - return d->inputMethod; -} - QInputPanel *QGuiApplication::inputPanel() const { return inputMethod(); diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index f7153a0f32..134b1809bb 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -76,10 +76,6 @@ #include "private/qkeymapper_p.h" -#ifdef Q_WS_X11 -#include -#endif - #include #include @@ -87,10 +83,6 @@ #include -#if defined(Q_WS_X11) && !defined(QT_NO_EGL) -#include -#endif - #include "qapplication_p.h" #include "private/qevent_p.h" #include "qwidget_p.h" @@ -114,10 +106,6 @@ extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp #include "qdatetime.h" -#ifdef Q_WS_MAC -#include -#endif - //#define ALIEN_DEBUG static void initResources() @@ -156,24 +144,11 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T is_session_restored = false; #endif -#if defined(Q_WS_QWS) && !defined(QT_NO_DIRECTPAINTER) - directPainters = 0; -#endif - #ifndef QT_NO_GESTURES gestureManager = 0; gestureWidget = 0; #endif // QT_NO_GESTURES -#if defined(Q_WS_X11) || defined(Q_WS_WIN) - move_cursor = 0; - copy_cursor = 0; - link_cursor = 0; -#endif -#if defined(Q_WS_WIN) - ignore_cursor = 0; -#endif - if (!self) self = this; } @@ -191,16 +166,14 @@ QApplicationPrivate::~QApplicationPrivate() \inmodule QtWidgets - QApplication contains the main event loop, where all events from the window - system and other sources are processed and dispatched. It also handles the - application's initialization, finalization, and provides session - management. In addition, QApplication handles most of the system-wide and - application-wide settings. + QApplication specializes QGuiApplication with some functionality needed + for QWidget-based applications. It handles widget specific initialization, + finalization, and provides session management. For any GUI application using Qt, there is precisely \bold one QApplication object, no matter whether the application has 0, 1, 2 or more windows at - any given time. For non-GUI Qt applications, use QCoreApplication instead, - as it does not depend on the \l QtGui library. + any given time. For non-QWidget based Qt applications, use QGuiApplication instead, + as it does not depend on the \l QtWidgets library. The QApplication object is accessible through the instance() function that returns a pointer equivalent to the global qApp pointer. @@ -241,9 +214,6 @@ QApplicationPrivate::~QApplicationPrivate() \o It manages the application's mouse cursor handling, see setOverrideCursor() - \o On the X window system, it provides functions to flush and sync - the communication stream, see flushX() and syncX(). - \o It provides support for sophisticated \l{Session Management} {session management}. This makes it possible for applications to terminate gracefully when the user logs out, to cancel a @@ -291,12 +261,7 @@ QApplicationPrivate::~QApplicationPrivate() sendPostedEvents(), removePostedEvents(), hasPendingEvents(), - notify(), - macEventFilter(), - qwsEventFilter(), - x11EventFilter(), - x11ProcessEvent(), - winEventFilter(). + notify(). \row \o GUI Styles @@ -306,8 +271,7 @@ QApplicationPrivate::~QApplicationPrivate() \row \o Color usage \o colorSpec(), - setColorSpec(), - qwsSetCustomColors(). + setColorSpec(). \row \o Text handling @@ -333,11 +297,6 @@ QApplicationPrivate::~QApplicationPrivate() setOverrideCursor(), restoreOverrideCursor(). - \row - \o X Window System synchronization - \o flushX(), - syncX(). - \row \o Session management \o isSessionRestored(), @@ -391,9 +350,6 @@ QApplicationPrivate::~QApplicationPrivate() */ void qt_init(QApplicationPrivate *priv, int type -#ifdef Q_WS_X11 - , Display *display = 0, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0 -#endif ); void qt_cleanup(); @@ -560,19 +516,6 @@ void QApplicationPrivate::process_cmdline() \note \a argc and \a argv might be changed as Qt removes command line arguments that it recognizes. - Qt debugging options (not available if Qt was compiled without the QT_DEBUG - flag defined): - \list - \o -nograb, tells Qt that it must never grab the mouse or the - keyboard. - \o -dograb (only under X11), running under a debugger can cause an - implicit -nograb, use -dograb to override. - \o -sync (only under X11), switches to synchronous mode for - debugging. - \endlist - - See \l{Debugging Techniques} for a more detailed explanation. - All Qt programs automatically support the following command line options: \list \o -style= \e style, sets the application GUI style. Possible values @@ -598,45 +541,6 @@ void QApplicationPrivate::process_cmdline() and will make the application wait until a debugger connects to it. \endlist - The X11 version of Qt supports some traditional X11 command line options: - \list - \o -display \e display, sets the X display (default is $DISPLAY). - \o -geometry \e geometry, sets the client geometry of the first window - that is shown. - \o -fn or \c -font \e font, defines the application font. The font - should be specified using an X logical font description. Note that - this option is ignored when Qt is built with fontconfig support enabled. - \o -bg or \c -background \e color, sets the default background color - and an application palette (light and dark shades are calculated). - \o -fg or \c -foreground \e color, sets the default foreground color. - \o -btn or \c -button \e color, sets the default button color. - \o -name \e name, sets the application name. - \o -title \e title, sets the application title. - \o -visual \c TrueColor, forces the application to use a TrueColor - visual on an 8-bit display. - \o -ncols \e count, limits the number of colors allocated in the color - cube on an 8-bit display, if the application is using the - QApplication::ManyColor color specification. If \e count is 216 - then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, - and 6 of blue); for other values, a cube approximately proportional - to a 2x3x1 cube is used. - \o -cmap, causes the application to install a private color map on an - 8-bit display. - \o -im, sets the input method server (equivalent to setting the - XMODIFIERS environment variable) - \o -inputstyle, defines how the input is inserted into the given - widget, e.g., \c onTheSpot makes the input appear directly in the - widget, while \c overTheSpot makes the input appear in a box - floating over the widget and is not inserted until the editing is - done. - \endlist - - \section1 X11 Notes - - If QApplication fails to open the X11 display, it will terminate - the process. This behavior is consistent with most X11 - applications. - \sa arguments() */ @@ -651,26 +555,18 @@ QApplication::QApplication(int &argc, char **argv, int _internal) /*! Constructs an application object with \a argc command line arguments in - \a argv. If \a GUIenabled is true, a GUI application is constructed, - otherwise a non-GUI (console) application is created. + \a argv. \warning The data referred to by \a argc and \a argv must stay valid for the entire lifetime of the QApplication object. In addition, \a argc must be greater than zero and \a argv must contain at least one valid character string. - Set \a GUIenabled to false for programs without a graphical user interface - that should be able to run without a window system. - - On X11, the window system is initialized if \a GUIenabled is true. If - \a GUIenabled is false, the application does not connect to the X server. - On Windows and Mac OS, currently the window system is always initialized, - regardless of the value of GUIenabled. This may change in future versions - of Qt. - The following example shows how to create an application that uses a graphical interface when available. + \obsolete + \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 0 */ @@ -692,10 +588,6 @@ QApplication::QApplication(int &argc, char **argv, bool GUIenabled , int _intern the entire lifetime of the QApplication object. In addition, \a argc must be greater than zero and \a argv must contain at least one valid character string. - - With Qt for Embedded Linux, passing QApplication::GuiServer for \a type - makes this application the server (equivalent to running with the - \c -qws option). */ QApplication::QApplication(int &argc, char **argv, Type type) : QGuiApplication(*new QApplicationPrivate(argc, argv, type, 0x040000)) @@ -705,22 +597,10 @@ QApplication::QApplication(int &argc, char **argv, Type type , int _internal) : QGuiApplication(*new QApplicationPrivate(argc, argv, type, _internal)) { Q_D(QApplication); d->construct(); } -#if defined(Q_WS_X11) && !defined(QT_NO_EGL) -static int qt_matchLibraryName(dl_phdr_info *info, size_t, void *data) -{ - const char *name = static_cast(data); - return strstr(info->dlpi_name, name) != 0; -} -#endif - /*! \internal */ -void QApplicationPrivate::construct( -#ifdef Q_WS_X11 - Display *dpy, Qt::HANDLE visual, Qt::HANDLE cmap -#endif - ) +void QApplicationPrivate::construct() { initResources(); @@ -728,11 +608,7 @@ void QApplicationPrivate::construct( process_cmdline(); // Must be called before initialize() - qt_init(this, application_type -#ifdef Q_WS_X11 - , dpy, visual, cmap -#endif - ); + qt_init(this, application_type); initialize(); eventDispatcher->startingUp(); @@ -759,82 +635,6 @@ void QApplicationPrivate::construct( #endif } -#if defined(Q_WS_X11) -// ### a string literal is a cont char* -// ### using it as a char* is wrong and could lead to segfaults -// ### if aargv is modified someday -// ########## make it work with argc == argv == 0 -static int aargc = 1; -static char *aargv[] = { (char*)"unknown", 0 }; - -/*! - \fn QApplication::QApplication(Display* display, Qt::HANDLE visual, Qt::HANDLE colormap) - - Creates an application, given an already open display \a display. If - \a visual and \a colormap are non-zero, the application will use those - values as the default Visual and Colormap contexts. - - \warning Qt only supports TrueColor visuals at depths higher than 8 - bits-per-pixel. - - This function is only available on X11. -*/ -QApplication::QApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap) - : QGuiApplication(*new QApplicationPrivate(aargc, aargv, GuiClient, 0x040000)) -{ - if (! dpy) - qWarning("QApplication: Invalid Display* argument"); - Q_D(QApplication); - d->construct(dpy, visual, colormap); -} - -QApplication::QApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap, int _internal) - : QGuiApplication(*new QApplicationPrivate(aargc, aargv, GuiClient, _internal)) -{ - if (! dpy) - qWarning("QApplication: Invalid Display* argument"); - Q_D(QApplication); - d->construct(dpy, visual, colormap); - QApplicationPrivate::app_compile_version = _internal; -} - -/*! - \fn QApplication::QApplication(Display *display, int &argc, char **argv, - Qt::HANDLE visual, Qt::HANDLE colormap) - - Creates an application, given an already open \a display and using \a argc - command line arguments in \a argv. If \a visual and \a colormap are - non-zero, the application will use those values as the default Visual - and Colormap contexts. - - \warning Qt only supports TrueColor visuals at depths higher than 8 - bits-per-pixel. - - This function is only available on X11. -*/ -QApplication::QApplication(Display *dpy, int &argc, char **argv, - Qt::HANDLE visual, Qt::HANDLE colormap) - : QGuiApplication(*new QApplicationPrivate(argc, argv, GuiClient, 0x040000)) -{ - if (! dpy) - qWarning("QApplication: Invalid Display* argument"); - Q_D(QApplication); - d->construct(dpy, visual, colormap); -} - -QApplication::QApplication(Display *dpy, int &argc, char **argv, - Qt::HANDLE visual, Qt::HANDLE colormap, int _internal) - : QGuiApplication(*new QApplicationPrivate(argc, argv, GuiClient, _internal)) -{ - if (! dpy) - qWarning("QApplication: Invalid Display* argument"); - Q_D(QApplication); - d->construct(dpy, visual, colormap); - QApplicationPrivate::app_compile_version = _internal; -} - -#endif // Q_WS_X11 - #ifndef QT_NO_STATEMACHINE void qRegisterGuiStateMachine(); void qUnregisterGuiStateMachine(); @@ -981,15 +781,6 @@ QApplication::~QApplication() delete qt_desktopWidget; qt_desktopWidget = 0; -#if defined(Q_WS_X11) || defined(Q_WS_WIN) - delete d->move_cursor; d->move_cursor = 0; - delete d->copy_cursor; d->copy_cursor = 0; - delete d->link_cursor; d->link_cursor = 0; -#endif -#if defined(Q_WS_WIN) - delete d->ignore_cursor; d->ignore_cursor = 0; -#endif - delete QApplicationPrivate::app_pal; QApplicationPrivate::app_pal = 0; delete QApplicationPrivate::sys_pal; @@ -1731,14 +1522,6 @@ QFont QApplication::font(const QWidget *widget) { FontHash *hash = app_fonts(); -#ifdef Q_WS_MAC - // short circuit for small and mini controls - if (widget->testAttribute(Qt::WA_MacSmallSize)) { - return hash->value("QSmallFont"); - } else if (widget->testAttribute(Qt::WA_MacMiniSize)) { - return hash->value("QMiniFont"); - } -#endif if (widget && hash && hash->size()) { QHash::ConstIterator it = hash->constFind(widget->metaObject()->className()); @@ -1877,11 +1660,6 @@ void QApplication::setWindowIcon(const QIcon &icon) QApplicationPrivate::app_icon = new QIcon(); *QApplicationPrivate::app_icon = icon; if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { -#ifdef Q_WS_MAC - void qt_mac_set_app_icon(const QPixmap &); //qapplication_mac.cpp - QSize size = QApplicationPrivate::app_icon->actualSize(QSize(128, 128)); - qt_mac_set_app_icon(QApplicationPrivate::app_icon->pixmap(size)); -#endif QEvent e(QEvent::ApplicationWindowIconChange); QWidgetList all = QApplication::allWidgets(); for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { @@ -2094,13 +1872,7 @@ void QApplication::closeAllWindows() void QApplication::aboutQt() { #ifndef QT_NO_MESSAGEBOX - QMessageBox::aboutQt( -#ifdef Q_WS_MAC - 0 -#else - activeWindow() -#endif // Q_WS_MAC - ); + QMessageBox::aboutQt(activeWindow()); #endif // QT_NO_MESSAGEBOX } @@ -2184,9 +1956,6 @@ bool QApplication::event(QEvent *e) } if(e->type() == QEvent::LanguageChange) { -#ifdef Q_WS_MAC - qt_mac_post_retranslateAppMenu(); -#endif QWidgetList list = topLevelWidgets(); for (int i = 0; i < list.size(); ++i) { QWidget *w = list.at(i); @@ -2198,13 +1967,14 @@ bool QApplication::event(QEvent *e) return QGuiApplication::event(e); } -#if !defined(Q_WS_X11) - -// The doc and X implementation of this function is in qapplication_x11.cpp - -void QApplication::syncX() {} // do nothing - -#endif +/*! + Was used to synchronize with the X server in 4.x, here for source compatibility. + \internal + \obsolete +*/ +void QApplication::syncX() +{ +} void QApplicationPrivate::notifyLayoutDirectionChange() { @@ -2298,13 +2068,6 @@ void QApplication::setActiveWindow(QWidget* act) sendSpontaneousEvent(w, &activationChange); } -#ifdef Q_WS_MAC - // In case the user clicked on a child window, we need to - // reestablish the stacking order of the window so - // it pops in front of other child windows in cocoa: - qt_cocoaStackChildWindowOnTopOfOtherChildren(window); -#endif - for(int i = 0; i < toBeDeactivated.size(); ++i) { QWidget *w = toBeDeactivated.at(i); sendSpontaneousEvent(w, &windowDeactivate); @@ -2455,10 +2218,6 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) { for (int i = 0; i < leaveList.size(); ++i) { w = leaveList.at(i); if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { -#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC) - if (leaveAfterRelease == w) - leaveAfterRelease = 0; -#endif QApplication::sendEvent(w, &leaveEvent); if (w->testAttribute(Qt::WA_Hover) && (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) { @@ -2511,9 +2270,6 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) { if (!parentOfLeavingCursor->window()->graphicsProxyWidget()) #endif { -#if defined(Q_WS_X11) - qt_x11_enforce_cursor(parentOfLeavingCursor,true); -#endif if (enter == QApplication::desktop()) { qt_qpa_set_cursor(enter, true); } else { @@ -2535,13 +2291,7 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) { } else #endif { -#if defined(Q_WS_WIN) - qt_win_set_cursor(cursorWidget, true); -#elif defined(Q_WS_X11) - qt_x11_enforce_cursor(cursorWidget, true); -#else qt_qpa_set_cursor(cursorWidget, true); -#endif } } #endif @@ -2575,12 +2325,6 @@ bool QApplicationPrivate::isBlockedByModal(QWidget *widget) return false; w = w->parentWidget(); } -#ifdef Q_WS_WIN - if ((widget->testAttribute(Qt::WA_WState_Created) || widget->data->winid) - && (modalWidget->testAttribute(Qt::WA_WState_Created) || modalWidget->data->winid) - && IsChild(modalWidget->data->winid, widget->data->winid)) - return false; -#endif } Qt::WindowModality windowModality = modalWidget->windowModality(); @@ -2708,12 +2452,6 @@ bool QApplicationPrivate::tryModalHelper(QWidget *widget, QWidget **rettop) if (QApplication::activePopupWidget()) return true; -#if defined(Q_WS_MAC) - top = QApplicationPrivate::tryModalHelper_sys(top); - if (rettop) - *rettop = top; -#endif - return !isBlockedByModal(widget->window()); } @@ -3726,16 +3464,6 @@ bool QApplication::notify(QObject *receiver, QEvent *e) case QEvent::DragEnter: { QWidget* w = static_cast(receiver); QDragEnterEvent *dragEvent = static_cast(e); -#ifdef Q_WS_MAC - // HIView has a slight difference in how it delivers events to children and parents - // It will not give a leave to a child's parent when it enters a child. - QWidget *currentTarget = QDragManager::self()->currentTarget(); - if (currentTarget) { - // Assume currentTarget did not get a leave - QDragLeaveEvent event; - QApplication::sendEvent(currentTarget, &event); - } -#endif #ifndef QT_NO_GRAPHICSVIEW // QGraphicsProxyWidget handles its own propagation, // and we must not change QDragManagers currentTarget. @@ -3774,20 +3502,6 @@ bool QApplication::notify(QObject *receiver, QEvent *e) w = qobject_cast(QDragManager::self()->currentTarget()); if (!w) { -#ifdef Q_WS_MAC - // HIView has a slight difference in how it delivers events to children and parents - // It will not give an enter to a child's parent when it leaves the child. - if (e->type() == QEvent::DragLeave) - break; - // Assume that w did not get an enter. - QDropEvent *dropEvent = static_cast(e); - QDragEnterEvent dragEnterEvent(dropEvent->pos(), dropEvent->possibleActions(), - dropEvent->mimeData(), dropEvent->mouseButtons(), - dropEvent->keyboardModifiers()); - QApplication::sendEvent(receiver, &dragEnterEvent); - w = QDragManager::self()->currentTarget(); - if (!w) -#endif break; } if (e->type() == QEvent::DragMove || e->type() == QEvent::Drop) { @@ -3951,24 +3665,6 @@ bool QApplication::notify(QObject *receiver, QEvent *e) break; } #endif // QT_NO_GESTURES -#ifdef Q_WS_MAC - case QEvent::Enter: - if (receiver->isWidgetType()) { - QWidget *w = static_cast(receiver); - if (w->testAttribute(Qt::WA_AcceptTouchEvents)) - qt_widget_private(w)->registerTouchWindow(true); - } - res = d->notify_helper(receiver, e); - break; - case QEvent::Leave: - if (receiver->isWidgetType()) { - QWidget *w = static_cast(receiver); - if (w->testAttribute(Qt::WA_AcceptTouchEvents)) - qt_widget_private(w)->registerTouchWindow(false); - } - res = d->notify_helper(receiver, e); - break; -#endif default: res = d->notify_helper(receiver, e); break; @@ -4304,168 +4000,6 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e) \sa isPhase2() */ -/***************************************************************************** - Stubbed session management support - *****************************************************************************/ -#ifndef QT_NO_SESSIONMANAGER -#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_WS_QWS) - -#if defined(Q_OS_WINCE) -HRESULT qt_CoCreateGuid(GUID* guid) -{ - // We will use the following information to create the GUID - // 1. absolute path to application - wchar_t tempFilename[MAX_PATH]; - if (!GetModuleFileName(0, tempFilename, MAX_PATH)) - return S_FALSE; - unsigned int hash = qHash(QString::fromWCharArray(tempFilename)); - guid->Data1 = hash; - // 2. creation time of file - QFileInfo info(QString::fromWCharArray(tempFilename)); - guid->Data2 = qHash(info.created().toTime_t()); - // 3. current system time - guid->Data3 = qHash(QDateTime::currentDateTime().toTime_t()); - return S_OK; -} -#if !defined(OLE32_MCOMGUID) || defined(QT_WINCE_FORCE_CREATE_GUID) -#define CoCreateGuid qt_CoCreateGuid -#endif - -#endif - -class QSessionManagerPrivate : public QObjectPrivate -{ -public: - QStringList restartCommand; - QStringList discardCommand; - QString sessionId; - QString sessionKey; - QSessionManager::RestartHint restartHint; -}; - -QSessionManager* qt_session_manager_self = 0; -QSessionManager::QSessionManager(QApplication * app, QString &id, QString &key) - : QObject(*new QSessionManagerPrivate, app) -{ - Q_D(QSessionManager); - setObjectName(QLatin1String("qt_sessionmanager")); - qt_session_manager_self = this; -#if defined(Q_WS_WIN) - wchar_t guidstr[40]; - GUID guid; - CoCreateGuid(&guid); - StringFromGUID2(guid, guidstr, 40); - id = QString::fromWCharArray(guidstr); - CoCreateGuid(&guid); - StringFromGUID2(guid, guidstr, 40); - key = QString::fromWCharArray(guidstr); -#endif - d->sessionId = id; - d->sessionKey = key; - d->restartHint = RestartIfRunning; -} - -QSessionManager::~QSessionManager() -{ - qt_session_manager_self = 0; -} - -QString QSessionManager::sessionId() const -{ - Q_D(const QSessionManager); - return d->sessionId; -} - -QString QSessionManager::sessionKey() const -{ - Q_D(const QSessionManager); - return d->sessionKey; -} - - -#if defined(Q_WS_X11) || defined(Q_WS_MAC) -void* QSessionManager::handle() const -{ - return 0; -} -#endif - -#if !defined(Q_WS_WIN) -bool QSessionManager::allowsInteraction() -{ - return true; -} - -bool QSessionManager::allowsErrorInteraction() -{ - return true; -} -void QSessionManager::release() -{ -} - -void QSessionManager::cancel() -{ -} -#endif - - -void QSessionManager::setRestartHint(QSessionManager::RestartHint hint) -{ - Q_D(QSessionManager); - d->restartHint = hint; -} - -QSessionManager::RestartHint QSessionManager::restartHint() const -{ - Q_D(const QSessionManager); - return d->restartHint; -} - -void QSessionManager::setRestartCommand(const QStringList& command) -{ - Q_D(QSessionManager); - d->restartCommand = command; -} - -QStringList QSessionManager::restartCommand() const -{ - Q_D(const QSessionManager); - return d->restartCommand; -} - -void QSessionManager::setDiscardCommand(const QStringList& command) -{ - Q_D(QSessionManager); - d->discardCommand = command; -} - -QStringList QSessionManager::discardCommand() const -{ - Q_D(const QSessionManager); - return d->discardCommand; -} - -void QSessionManager::setManagerProperty(const QString&, const QString&) -{ -} - -void QSessionManager::setManagerProperty(const QString&, const QStringList&) -{ -} - -bool QSessionManager::isPhase2() const -{ - return false; -} - -void QSessionManager::requestPhase2() -{ -} - -#endif -#endif // QT_NO_SESSIONMANAGER - /*! \typedef QApplication::ColorMode \compat @@ -4895,120 +4429,6 @@ bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy) return true; } -/*! \fn QDecoration &QApplication::qwsDecoration() - Return the QWSDecoration used for decorating windows. - - \warning This method is non-portable. It is only available in - Qt for Embedded Linux. - - \sa QDecoration -*/ - -/*! - \fn void QApplication::qwsSetDecoration(QDecoration *decoration) - - Sets the QDecoration derived class to use for decorating the - windows used by Qt for Embedded Linux to the \a decoration - specified. - - This method is non-portable. It is only available in Qt for Embedded Linux. - - \sa QDecoration -*/ - -/*! \fn QDecoration* QApplication::qwsSetDecoration(const QString &decoration) - \overload - - Requests a QDecoration object for \a decoration from the - QDecorationFactory. - - The string must be one of the QDecorationFactory::keys(). Keys are case - insensitive. - - A later call to the QApplication constructor will override the requested - style when a "-style" option is passed in as a commandline parameter. - - Returns 0 if an unknown \a decoration is passed, otherwise the QStyle object - returned is set as the application's GUI style. -*/ - -/*! - \fn bool QApplication::qwsEventFilter(QWSEvent *event) - - This virtual function is only implemented under Qt for Embedded Linux. - - If you create an application that inherits QApplication and - reimplement this function, you get direct access to all QWS (Q - Window System) events that the are received from the QWS master - process. The events are passed in the \a event parameter. - - Return true if you want to stop the event from being processed. - Return false for normal event dispatching. The default - implementation returns false. -*/ - -/*! \fn void QApplication::qwsSetCustomColors(QRgb *colorTable, int start, int numColors) - Set Qt for Embedded Linux custom color table. - - Qt for Embedded Linux on 8-bpp displays allocates a standard 216 color cube. - The remaining 40 colors may be used by setting a custom color - table in the QWS master process before any clients connect. - - \a colorTable is an array of up to 40 custom colors. \a start is - the starting index (0-39) and \a numColors is the number of colors - to be set (1-40). - - This method is non-portable. It is available \e only in - Qt for Embedded Linux. - - \note The custom colors will not be used by the default screen - driver. To make use of the new colors, implement a custom screen - driver, or use QDirectPainter. -*/ - -/*! \fn int QApplication::qwsProcessEvent(QWSEvent* event) - \internal -*/ - -/*! \fn int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only) - \internal -*/ - -/*! \fn int QApplication::x11ProcessEvent(XEvent* event) - This function does the core processing of individual X - \a{event}s, normally by dispatching Qt events to the right - destination. - - It returns 1 if the event was consumed by special handling, 0 if - the \a event was consumed by normal handling, and -1 if the \a - event was for an unrecognized widget. - - \sa x11EventFilter() -*/ - -/*! - \fn bool QApplication::x11EventFilter(XEvent *event) - - \warning This virtual function is only implemented under X11. - - If you create an application that inherits QApplication and - reimplement this function, you get direct access to all X events - that the are received from the X server. The events are passed in - the \a event parameter. - - Return true if you want to stop the event from being processed. - Return false for normal event dispatching. The default - implementation returns false. - - It is only the directly addressed messages that are filtered. - You must install an event filter directly on the event - dispatcher, which is returned by - QAbstractEventDispatcher::instance(), to handle system wide - messages. - - \sa x11ProcessEvent() -*/ - /*! \fn void QApplication::winFocus(QWidget *widget, bool gotFocus) \internal \since 4.1 @@ -5021,11 +4441,6 @@ bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy) \internal */ -/*! \fn void QApplication::syncX() - Synchronizes with the X server in the X11 implementation. - This normally takes some time. Does nothing on other platforms. -*/ - void QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent) { for (int i = 0; i < touchEvent->touchPoints().count(); ++i) { diff --git a/src/widgets/kernel/qapplication.h b/src/widgets/kernel/qapplication.h index 503b36aec6..060765969f 100644 --- a/src/widgets/kernel/qapplication.h +++ b/src/widgets/kernel/qapplication.h @@ -98,12 +98,8 @@ public: #ifndef qdoc QApplication(int &argc, char **argv, int = ApplicationFlags); - QApplication(int &argc, char **argv, bool GUIenabled, int = ApplicationFlags); + QT_DEPRECATED QApplication(int &argc, char **argv, bool GUIenabled, int = ApplicationFlags); QApplication(int &argc, char **argv, Type, int = ApplicationFlags); -#if defined(Q_WS_X11) - QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0, int = ApplicationFlags); - QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0, int = ApplicationFlags); -#endif #endif virtual ~QApplication(); @@ -150,7 +146,7 @@ public: static QWidget *topLevelAt(const QPoint &p); static inline QWidget *topLevelAt(int x, int y) { return topLevelAt(QPoint(x, y)); } - static void syncX(); + QT_DEPRECATED static void syncX(); static void beep(); static void alert(QWidget *widget, int duration = 0); @@ -182,31 +178,8 @@ public: static bool isEffectEnabled(Qt::UIEffect); static void setEffectEnabled(Qt::UIEffect, bool enable = true); -#if defined(Q_WS_MAC) - virtual bool macEventFilter(EventHandlerCallRef, EventRef); -#endif -#if defined(Q_WS_X11) - virtual bool x11EventFilter(XEvent *); - virtual int x11ClientMessage(QWidget*, XEvent*, bool passive_only); - int x11ProcessEvent(XEvent*); -#endif -#if defined(Q_WS_QWS) - virtual bool qwsEventFilter(QWSEvent *); - int qwsProcessEvent(QWSEvent*); - void qwsSetCustomColors(QRgb *colortable, int start, int numColors); -#ifndef QT_NO_QWS_MANAGER - static QDecoration &qwsDecoration(); - static void qwsSetDecoration(QDecoration *); - static QDecoration *qwsSetDecoration(const QString &decoration); -#endif -#endif - static QPlatformNativeInterface *platformNativeInterface(); -#if defined(Q_WS_WIN) - void winFocus(QWidget *, bool); - static void winMouseButtonUp(); -#endif #ifndef QT_NO_SESSIONMANAGER // session management bool isSessionRestored() const; @@ -252,21 +225,14 @@ public Q_SLOTS: static void aboutQt(); protected: -#if defined(Q_WS_QWS) - void setArgs(int, char **); -#endif bool event(QEvent *); bool compressEvent(QEvent *, QObject *receiver, QPostEventList *); #if defined(Q_INTERNAL_QAPP_SRC) || defined(qdoc) QApplication(int &argc, char **argv); - QApplication(int &argc, char **argv, bool GUIenabled); + QT_DEPRECATED QApplication(int &argc, char **argv, bool GUIenabled); QApplication(int &argc, char **argv, Type); -#if defined(Q_WS_X11) - QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0); - QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); -#endif #endif private: @@ -291,21 +257,9 @@ private: #endif friend class QAction; -#if defined(Q_WS_QWS) - friend class QWSDirectPainterSurface; - friend class QDirectPainter; - friend class QDirectPainterPrivate; -#endif #ifndef QT_NO_GESTURES friend class QGestureManager; #endif - -#if defined(Q_WS_MAC) || defined(Q_WS_X11) - Q_PRIVATE_SLOT(d_func(), void _q_alertTimeOut()) -#endif -#if defined(QT_RX71_MULTITOUCH) - Q_PRIVATE_SLOT(d_func(), void _q_readRX71MultiTouchEvents()) -#endif }; QT_END_NAMESPACE diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index 978e989a00..b331356e66 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -220,8 +220,6 @@ void QWidgetBackingStore::showYellowThing(QWidget *widget, const QRegion &toBePa if (pe) pe->setSystemClip(QRegion()); - QApplication::syncX(); - #if defined(Q_OS_UNIX) ::usleep(1000 * msec); #endif diff --git a/src/widgets/widgets/qwidgetresizehandler.cpp b/src/widgets/widgets/qwidgetresizehandler.cpp index aba0ca58c6..5380fb798c 100644 --- a/src/widgets/widgets/qwidgetresizehandler.cpp +++ b/src/widgets/widgets/qwidgetresizehandler.cpp @@ -326,8 +326,6 @@ void QWidgetResizeHandler::mouseMoveEvent(QMouseEvent *e) else widget->setGeometry(geom); } - - QApplication::syncX(); } void QWidgetResizeHandler::setMouseCursor(MousePosition m) -- cgit v1.2.3 From 186692f81f2612c3cf3a4090cbf949f2fb1558f8 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Mon, 30 Jan 2012 14:23:22 +0200 Subject: Remove custom text codec for C strings. This setting is extremely harmful, as code cannot know whether or not to expect it. It also made the behaviour of QString::fromAscii and ::toAscii unintuitive, and caused a lot of people to make mistakes with it. Change-Id: I2f429fa7ef93bd75bb93a7f64c56db15b7283388 Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- src/corelib/codecs/qtextcodec.cpp | 30 +------------- src/corelib/codecs/qtextcodec.h | 5 --- src/corelib/kernel/qvariant.cpp | 6 +-- src/corelib/tools/qchar.cpp | 63 ++++++++---------------------- src/corelib/tools/qchar.h | 13 +++--- src/corelib/tools/qstring.cpp | 76 ++++++------------------------------ src/corelib/tools/qstring.h | 9 ----- src/corelib/tools/qstringbuilder.cpp | 16 -------- src/corelib/tools/qstringbuilder.h | 14 +------ 9 files changed, 40 insertions(+), 192 deletions(-) (limited to 'src') diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 82e5c9a1c3..68866b9000 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1495,35 +1495,7 @@ QString QTextDecoder::toUnicode(const QByteArray &ba) files to be loaded. For details of internationalization, see \l{Internationalization with Qt}. - \sa codecForTr(), setCodecForCStrings() -*/ - - -/*! - \fn QTextCodec* QTextCodec::codecForCStrings() - - Returns the codec used by QString to convert to and from \c{const - char *} and QByteArrays. If this function returns 0 (the default), - QString assumes Latin-1. - - \sa setCodecForCStrings() -*/ - -/*! - \fn void QTextCodec::setCodecForCStrings(QTextCodec *codec) - \nonreentrant - - Sets the codec used by QString to convert to and from \c{const - char *} and QByteArrays. If the \a codec is 0 (the default), - QString assumes Latin-1. - - \warning Some codecs do not preserve the characters in the ASCII - range (0x00 to 0x7F). For example, the Japanese Shift-JIS - encoding maps the backslash character (0x5A) to the Yen - character. To avoid undesirable side-effects, we recommend - avoiding such codecs with setCodecsForCString(). - - \sa codecForCStrings(), setCodecForTr() + \sa codecForTr() */ /*! diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h index 9e46863964..ad37005e92 100644 --- a/src/corelib/codecs/qtextcodec.h +++ b/src/corelib/codecs/qtextcodec.h @@ -75,9 +75,6 @@ public: static QTextCodec* codecForTr(); static void setCodecForTr(QTextCodec *c); - static QTextCodec* codecForCStrings(); - static void setCodecForCStrings(QTextCodec *c); - static QTextCodec *codecForHtml(const QByteArray &ba); static QTextCodec *codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec); @@ -139,8 +136,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QTextCodec::ConversionFlags) inline QTextCodec* QTextCodec::codecForTr() { return validCodecs() ? cftr : 0; } inline void QTextCodec::setCodecForTr(QTextCodec *c) { cftr = c; } -inline QTextCodec* QTextCodec::codecForCStrings() { return validCodecs() ? QString::codecForCStrings : 0; } -inline void QTextCodec::setCodecForCStrings(QTextCodec *c) { QString::codecForCStrings = c; } class Q_CORE_EXPORT QTextEncoder { Q_DISABLE_COPY(QTextEncoder) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 4e7fd94141..9f57cd018c 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1162,8 +1162,8 @@ QVariant::QVariant(QDataStream &s) \fn QVariant::QVariant(const char *val) Constructs a new variant with a string value of \a val. - The variant creates a deep copy of \a val, using the encoding - set by QTextCodec::setCodecForCStrings(). + The variant creates a deep copy of \a val into a QString assuming + UTF-8 encoding on the input \a val. Note that \a val is converted to a QString for storing in the variant and QVariant::type() will return QMetaType::QString for @@ -1171,8 +1171,6 @@ QVariant::QVariant(QDataStream &s) You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII when you compile your applications. - - \sa QTextCodec::setCodecForCStrings() */ #ifndef QT_NO_CAST_FROM_ASCII diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 01241dce6b..0261843a3a 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -413,33 +413,16 @@ QT_BEGIN_NAMESPACE */ /*! + \fn QChar::QChar(char ch) + Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ -QChar::QChar(char ch) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) - // ##### - ucs = QTextCodec::codecForCStrings()->toUnicode(&ch, 1).at(0).unicode(); - else -#endif - ucs = uchar(ch); -} /*! + \fn QChar::QChar(uchar ch) + Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ -QChar::QChar(uchar ch) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) { - // ##### - char c = char(ch); - ucs = QTextCodec::codecForCStrings()->toUnicode(&c, 1).at(0).unicode(); - } else -#endif - ucs = ch; -} /*! \fn QChar::QChar(uchar cell, uchar row) @@ -1256,49 +1239,35 @@ ushort QChar::toCaseFolded(ushort ucs2) Returns the Latin-1 character equivalent to the QChar, or 0. This is mainly useful for non-internationalized software. - \sa toAscii(), unicode(), QTextCodec::codecForCStrings() + \sa toAscii(), unicode() */ /*! - Returns the character value of the QChar obtained using the current - codec used to read C strings, or 0 if the character is not representable - using this codec. The default codec handles Latin-1 encoded text, - but this can be changed to assist developers writing source code using - other encodings. + \fn char QChar::toAscii() const + + Returns the Latin-1 character value of the QChar, or 0 if the character is not + representable. The main purpose of this function is to preserve ASCII characters used in C strings. This is mainly useful for developers of non-internationalized software. - \sa toLatin1(), unicode(), QTextCodec::codecForCStrings() + \note It is not possible to distinguish a non-Latin 1 character from an ASCII 0 + (NUL) character. Prefer to use unicode(), which does not have this ambiguity. + + \sa toLatin1(), unicode() */ -char QChar::toAscii() const -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) - // ##### - return QTextCodec::codecForCStrings()->fromUnicode(QString(*this)).at(0); -#endif - return ucs > 0xff ? 0 : char(ucs); -} /*! + \fn QChar QChar::fromAscii(char) + Converts the ASCII character \a c to it's equivalent QChar. This is mainly useful for non-internationalized software. An alternative is to use QLatin1Char. - \sa fromLatin1(), unicode(), QTextCodec::codecForCStrings() + \sa fromLatin1(), unicode() */ -QChar QChar::fromAscii(char c) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) - // ##### - return QTextCodec::codecForCStrings()->toUnicode(&c, 1).at(0).unicode(); -#endif - return QChar(ushort((uchar)c)); -} #ifndef QT_NO_DATASTREAM /*! diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index df3d7eac33..d55fcdba89 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -86,9 +86,8 @@ public: Q_DECL_CONSTEXPR QChar(QLatin1Char ch) : ucs(ch.unicode()) {} // implicit #ifndef QT_NO_CAST_FROM_ASCII - // these two constructors are NOT inline const_expr! - QT_ASCII_CAST_WARN_CONSTRUCTOR explicit QChar(char c); - QT_ASCII_CAST_WARN_CONSTRUCTOR explicit QChar(uchar c); + QT_ASCII_CAST_WARN_CONSTRUCTOR Q_DECL_CONSTEXPR explicit QChar(char c) : ucs(uchar(c)) { } + QT_ASCII_CAST_WARN_CONSTRUCTOR Q_DECL_CONSTEXPR explicit QChar(uchar c) : ucs(c) { } #endif // Unicode information @@ -222,13 +221,13 @@ public: UnicodeVersion unicodeVersion() const; - char toAscii() const; + inline char toAscii() const; inline char toLatin1() const; inline ushort unicode() const { return ucs; } inline ushort &unicode() { return ucs; } - static QChar fromAscii(char c); - static QChar fromLatin1(char c); + static inline QChar fromAscii(char c); + static inline QChar fromLatin1(char c); inline bool isNull() const { return ucs == 0; } bool isPrint() const; @@ -344,8 +343,10 @@ private: Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE); +inline char QChar::toAscii() const { return ucs > 0xff ? 0 : char(ucs); } inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); } inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); } +inline QChar QChar::fromAscii(char c) { return QChar(ushort(uchar(c))); } inline void QChar::setCell(uchar acell) { ucs = ushort((ucs & 0xff00) + acell); } diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 704545667c..bf50159de2 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -96,10 +96,6 @@ QT_BEGIN_NAMESPACE -#ifndef QT_NO_TEXTCODEC -QTextCodec *QString::codecForCStrings; -#endif - #ifdef QT_USE_ICU // qlocale_icu.cpp extern bool qt_ucol_strcoll(const QChar *source, int sourceLength, const QChar *target, int targetLength, int *result); @@ -471,9 +467,8 @@ const QString::Null QString::null = { }; \snippet doc/src/snippets/qstring/main.cpp 0 QString converts the \c{const char *} data into Unicode using the - fromAscii() function. By default, fromAscii() treats character - above 128 as Latin-1 characters, but this can be changed by - calling QTextCodec::setCodecForCStrings(). + fromAscii() function. fromAscii() treats ordinals above 128 as Latin-1 + characters. In all of the QString functions that take \c{const char *} parameters, the \c{const char *} is interpreted as a classic @@ -611,9 +606,7 @@ const QString::Null QString::null = { }; toLatin1(), toUtf8(), and toLocal8Bit(). \list - \o toAscii() returns an 8-bit string encoded using the codec - specified by QTextCodec::codecForCStrings (by default, that is - Latin 1). + \o toAscii() returns a Latin-1 (ISO 8859-1) encoded 8-bit string. \o toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string. \o toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a superset of US-ASCII (ANSI X3.4-1986) that supports the entire @@ -721,11 +714,11 @@ const QString::Null QString::null = { }; \section1 More Efficient String Construction Many strings are known at compile time. But the trivial - constructor QString("Hello"), will convert the string literal - to a QString using the codecForCStrings(). To avoid this one - can use the QStringLiteral macro to directly create the required - data at compile time. Constructing a QString out of the literal - does then not cause any overhead at runtime. + constructor QString("Hello"), will copy the contents of the string, + treating the contents as Latin-1. To avoid this one can use the + QStringLiteral macro to directly create the required data at compile + time. Constructing a QString out of the literal does then not cause + any overhead at runtime. A slightly less efficient way is to use QLatin1String. This class wraps a C string literal, precalculates it length at compile time and can @@ -3652,9 +3645,7 @@ QByteArray QString::toLatin1() const /*! Returns an 8-bit representation of the string as a QByteArray. - If a codec has been set using QTextCodec::setCodecForCStrings(), - it is used to convert Unicode to 8-bit char; otherwise this - function does the same as toLatin1(). + This function does the same as toLatin1(). Note that, despite the name, this function does not necessarily return an US-ASCII (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. @@ -3663,10 +3654,6 @@ QByteArray QString::toLatin1() const */ QByteArray QString::toAscii() const { -#ifndef QT_NO_TEXTCODEC - if (codecForCStrings) - return codecForCStrings->fromUnicode(*this); -#endif // QT_NO_TEXTCODEC return toLatin1(); } @@ -3800,23 +3787,6 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) QString::Data *QString::fromAscii_helper(const char *str, int size) { -#ifndef QT_NO_TEXTCODEC - if (codecForCStrings) { - Data *d; - if (!str) { - d = const_cast(&shared_null.str); - } else if (size == 0 || (!*str && size < 0)) { - d = const_cast(&shared_empty.str); - } else { - if (size < 0) - size = qstrlen(str); - QString s = codecForCStrings->toUnicode(str, size); - d = s.d; - d->ref.ref(); - } - return d; - } -#endif return fromLatin1_helper(str, size); } @@ -3865,11 +3835,7 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) If \a size is -1 (default), it is taken to be strlen(\a str). - Note that, despite the name, this function actually uses the codec - defined by QTextCodec::setCodecForCStrings() to convert \a str to - Unicode. Depending on the codec, it may not accept valid US-ASCII (ANSI - X3.4-1986) input. If no codec has been set, this function does the same - as fromLatin1(). + This function does the same as fromLatin1(). \sa toAscii(), fromLatin1(), fromUtf8(), fromLocal8Bit() */ @@ -5138,19 +5104,8 @@ QString &QString::vsprintf(const char* cformat, va_list ap) const char *c = cformat; for (;;) { // Copy non-escape chars to result -#ifndef QT_NO_TEXTCODEC - int i = 0; - while (*(c + i) != '\0' && *(c + i) != '%') - ++i; - if (codecForCStrings) - result.append(codecForCStrings->toUnicode(c, i)); - else - result.append(fromLatin1(c, i)); - c += i; -#else while (*c != '\0' && *c != '%') result.append(QLatin1Char(*c++)); -#endif if (*c == '\0') break; @@ -7062,8 +7017,7 @@ bool QString::isRightToLeft() const This operator is mostly useful to pass a QString to a function that accepts a std::string object. - If the QString contains Unicode characters that the - QTextCodec::codecForCStrings() codec cannot handle, using this operator + If the QString contains non-Latin1 Unicode characters, using this can lead to loss of information. This operator is only available if Qt is configured with STL @@ -8736,9 +8690,7 @@ QByteArray QStringRef::toLatin1() const Returns an 8-bit representation of the string as a QByteArray. - If a codec has been set using QTextCodec::setCodecForCStrings(), - it is used to convert Unicode to 8-bit char; otherwise this - function does the same as toLatin1(). + This function does the same as toLatin1(). Note that, despite the name, this function does not necessarily return an US-ASCII (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. @@ -8747,10 +8699,6 @@ QByteArray QStringRef::toLatin1() const */ QByteArray QStringRef::toAscii() const { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) - return QString::codecForCStrings->fromUnicode(unicode(), length()); -#endif // QT_NO_TEXTCODEC return toLatin1(); } diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index f1bad5c028..f49d989e9d 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -605,9 +605,6 @@ private: Data *d; inline QString(Data *dd, int /*dummy*/) : d(dd) {} -#ifndef QT_NO_TEXTCODEC - static QTextCodec *codecForCStrings; -#endif static int grow(int); static void free(Data *); void realloc(); @@ -927,9 +924,6 @@ inline bool operator!=(const QString &s, QString::Null) { return !s.isNull(); } #ifndef QT_NO_CAST_FROM_ASCII inline bool qStringComparisonHelper(const QString &s1, const char *s2) { -# ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) return (s1 == QString::fromAscii(s2, s2 ? int(strlen(s2)) : -1)); -# endif return (s1 == QLatin1String(s2)); } inline bool QString::operator==(const char *s) const @@ -1216,9 +1210,6 @@ inline bool operator>=(const QStringRef &s1, const QStringRef &s2) inline bool qStringComparisonHelper(const QStringRef &s1, const char *s2) { -# ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) return (s1 == QString::fromAscii(s2, s2 ? int(strlen(s2)) : -1)); -# endif return (s1 == QLatin1String(s2)); } diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp index 3d6b0eb709..30c4399cc9 100644 --- a/src/corelib/tools/qstringbuilder.cpp +++ b/src/corelib/tools/qstringbuilder.cpp @@ -105,14 +105,6 @@ QT_BEGIN_NAMESPACE */ void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out) { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings && len) { - QString tmp = QString::fromAscii(a, len > 0 ? len : -1); - memcpy(out, reinterpret_cast(tmp.constData()), sizeof(QChar) * tmp.size()); - out += tmp.length(); - return; - } -#endif if (len == -1) { if (!a) return; @@ -127,14 +119,6 @@ void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out /*! \internal */ void QAbstractConcatenable::convertToAscii(const QChar* a, int len, char*& out) { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) { - QByteArray tmp = QString::codecForCStrings->fromUnicode(a, len); - memcpy(out, tmp.constData(), tmp.size()); - out += tmp.length(); - return; - } -#endif if (len == -1) { while (a->unicode()) convertToLatin1(*a++, out); diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 5a4c27d22a..ebaaaa35c2 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -65,22 +65,12 @@ protected: static void convertToAscii(const QChar *a, int len, char *&out); static inline void convertFromAscii(char a, QChar *&out) { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) - *out++ = QChar::fromAscii(a); - else -#endif - *out++ = QLatin1Char(a); + *out++ = QLatin1Char(a); } static inline void convertToAscii(QChar a, char *&out) { -#ifndef QT_NO_TEXTCODEC - if (QString::codecForCStrings) - *out++ = a.toAscii(); //### - else -#endif - convertToLatin1(a, out); + convertToLatin1(a, out); } static inline void convertToLatin1(QChar a, char *&out) -- cgit v1.2.3 From 7d79e997683930f4f7b3ce1db314683d6e82ea31 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 21 Feb 2012 17:27:39 +0100 Subject: Fail with #error early if the compiler does not support bool or explicit. The fail mode for bool is moved from later in qglobal.h, and explicit is used unguarded throughout Qt, so the macro is already useless. Change-Id: Iff26892b025ba155e360a1f2dc93a67a6622dbc1 Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 33 ++++++++++----------------------- src/corelib/global/qglobal.h | 5 ----- 2 files changed, 10 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 5ab79092d2..8adbdbe453 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -76,7 +76,7 @@ # define Q_CC_SYM /* "explicit" semantics implemented in 8.1e but keyword recognized since 7.5 */ # if defined(__SC__) && __SC__ < 0x750 -# define Q_NO_EXPLICIT_KEYWORD +# error "Compiler not supported" # endif # define Q_NO_USING_KEYWORD @@ -114,8 +114,7 @@ # define Q_CC_BOR # define Q_INLINE_TEMPLATE # if __BORLANDC__ < 0x502 -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD +# error "Compiler not supported" # endif # define Q_NO_USING_KEYWORD @@ -251,12 +250,7 @@ # define Q_CC_XLC # define Q_FULL_TEMPLATE_INSTANTIATION # if __xlC__ < 0x400 -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD -# define Q_NO_USING_KEYWORD -# define Q_OUTOFLINE_TEMPLATE inline -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -# define Q_CANNOT_DELETE_CONSTANT +# error "Compiler not supported" # elif __xlC__ >= 0x0600 # define Q_ALIGNOF(type) __alignof__(type) # define Q_TYPEOF(expr) __typeof__(expr) @@ -280,7 +274,7 @@ - observed on Compaq C++ V6.3-002. In any case versions prior to Compaq C++ V6.0-005 do not have bool. */ # if !defined(_BOOL_EXISTS) -# define Q_NO_BOOL_TYPE +# error "Compiler not supported" # endif /* Spurious (?) error messages observed on Compaq C++ V6.5-014. */ # define Q_NO_USING_KEYWORD @@ -315,7 +309,7 @@ __BOOL_DEFINED Defined in Microsoft C++ mode when bool is a keyword. */ # if !defined(_BOOL) && !defined(__BOOL_DEFINED) -# define Q_NO_BOOL_TYPE +# error "Compiler not supported" # endif /* The Comeau compiler is based on EDG and does define __EDG__ */ @@ -341,9 +335,8 @@ # elif defined(__DCC__) # define Q_CC_DIAB -# undef Q_NO_BOOL_TYPE # if !defined(__bool) -# define Q_NO_BOOL_TYPE +# error "Compiler not supported" # endif /* The UnixWare 7 UDK compiler is based on EDG and does define __EDG__ */ @@ -407,7 +400,7 @@ # define Q_NO_TEMPLATE_FRIENDS # endif # if !defined(_BOOL) -# define Q_NO_BOOL_TYPE +# error "Compiler not supported" # endif # if defined(__SUNPRO_CC_COMPAT) && (__SUNPRO_CC_COMPAT <= 4) # define Q_NO_USING_KEYWORD @@ -415,9 +408,7 @@ # define Q_C_CALLBACKS /* 4.2 compiler or older */ # else -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD -# define Q_NO_USING_KEYWORD +# error "Compiler not supported" # endif /* CDS++ does not seem to define __EDG__ or __EDG according to Reliant @@ -426,7 +417,7 @@ # define Q_CC_EDG # define Q_CC_CDS # if !defined(_BOOL) -# define Q_NO_BOOL_TYPE +# error "Compiler not supported" # endif # define Q_BROKEN_TEMPLATE_SPECIALIZATION @@ -449,11 +440,7 @@ # define Q_DECL_IMPORT Q_DECL_EXPORT # endif # else -# define Q_CC_HP -# define Q_NO_BOOL_TYPE -# define Q_FULL_TEMPLATE_INSTANTIATION -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -# define Q_NO_EXPLICIT_KEYWORD +# error "Compiler not supported" # endif # define Q_NO_USING_KEYWORD /* ### check "using" status */ diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 1fb5778f14..58bdf06fb5 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -275,11 +275,6 @@ typedef unsigned int uint; typedef unsigned long ulong; QT_END_INCLUDE_NAMESPACE -#if defined(Q_NO_BOOL_TYPE) -#error "Compiler doesn't support the bool type" -#endif - - /* Constant bool values */ -- cgit v1.2.3 From 53bb87d1d274a80b94595f6cd31bfa7a8ae81dc3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Feb 2012 15:29:05 +0100 Subject: QEasingCurve: fix a missing */ Change-Id: I344342e950158c9dc832f1cd181d92899ddb1651 Reviewed-by: Thiago Macieira --- src/corelib/tools/qeasingcurve.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 1ca9a55d72..81778f908f 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -1110,6 +1110,7 @@ QEasingCurve::~QEasingCurve() Swaps curve \a other with this curve. This operation is very fast and never fails. +*/ /*! Compare this easing curve with \a other and returns true if they are -- cgit v1.2.3 From 541949aed23ea14a71a7d4391bac244b623add0a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 21 Feb 2012 15:36:01 +0100 Subject: Add further theme hints to QPlatformTheme. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add hints for QDialog/QDialogButtonBox. - Add hint for available popup-menu area. - Add keyboard scheme hint replacing QGuiApplicationPrivate::currentKeyPlatform() Reviewed-by: Samuel Rødal Reviewed-by: Morten Johan Sørvig Task-number: QTBUG-24204 Task-number: QTBUG-24315 Change-Id: I6653786b0dcb49a6fc264d3b9891dbfee502bd3e Reviewed-by: Friedemann Kleint --- src/gui/kernel/qevent.cpp | 2 +- src/gui/kernel/qguiapplication.cpp | 21 -- src/gui/kernel/qguiapplication_p.h | 13 - src/gui/kernel/qkeysequence.cpp | 316 +++++++++++---------- src/gui/kernel/qkeysequence_p.h | 1 + src/gui/kernel/qplatformtheme_qpa.cpp | 24 ++ src/gui/kernel/qplatformtheme_qpa.h | 17 +- .../themes/genericunix/qgenericunixthemes.cpp | 19 +- src/plugins/platforms/cocoa/qcocoatheme.mm | 13 +- src/plugins/platforms/windows/qwindowstheme.cpp | 13 +- src/widgets/dialogs/qdialog.cpp | 10 +- src/widgets/kernel/qicon.cpp | 5 - src/widgets/styles/qcommonstyle.cpp | 19 +- 13 files changed, 256 insertions(+), 217 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index c3a6be692b..ce4594c7ab 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -833,7 +833,7 @@ Qt::KeyboardModifiers QKeyEvent::modifiers() const bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const { uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference - uint platform = QGuiApplicationPrivate::currentKeyPlatform(); + const uint platform = QKeySequencePrivate::currentKeyPlatforms(); uint N = QKeySequencePrivate::numberOfKeyBindings; diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 17208643ef..4b309096c9 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1911,27 +1911,6 @@ QInputPanel *QGuiApplication::inputPanel() const return inputMethod(); } - -// Returns the current platform used by keyBindings -uint QGuiApplicationPrivate::currentKeyPlatform() -{ - uint platform = KB_Win; -#ifdef Q_OS_MAC - platform = KB_Mac; -#elif defined Q_WS_X11 // ## TODO: detect these - platform = KB_X11; -#if 0 - if (X11->desktopEnvironment == DE_KDE) - platform |= KB_KDE; - if (X11->desktopEnvironment == DE_GNOME) - platform |= KB_Gnome; - if (X11->desktopEnvironment == DE_CDE) - platform |= KB_CDE; -#endif -#endif - return platform; -} - /*! \since 4.5 \fn void QGuiApplication::fontDatabaseChanged() diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 7e6e0aa8c7..66670e8e25 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -89,19 +89,6 @@ public: static QPlatformTheme *platformTheme() { return platform_theme; } - - enum KeyPlatform { - KB_Win = 1, - KB_Mac = 2, - KB_X11 = 4, - KB_KDE = 8, - KB_Gnome = 16, - KB_CDE = 32, - KB_All = 0xffff - }; - - static uint currentKeyPlatform(); - static QAbstractEventDispatcher *qt_qpa_core_dispatcher() { return QCoreApplication::instance()->d_func()->threadData->eventDispatcher; } diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index 021135b6fe..bd0f220ae8 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -41,6 +41,7 @@ #include "qkeysequence.h" #include "qkeysequence_p.h" +#include "qplatformtheme_qpa.h" #include "private/qguiapplication_p.h" #ifndef QT_NO_SHORTCUT @@ -640,153 +641,163 @@ static const struct { //Table of key bindings. It must be sorted on key sequence. //A priority of 1 indicates that this is the primary key binding when multiple are defined. +enum KeyPlatform { + KB_Win = (1 << QPlatformTheme::WindowsKeyboardScheme), + KB_Mac = (1 << QPlatformTheme::MacKeyboardScheme), + KB_X11 = (1 << QPlatformTheme::X11KeyboardScheme), + KB_KDE = (1 << QPlatformTheme::KdeKeyboardScheme), + KB_Gnome = (1 << QPlatformTheme::GnomeKeyboardScheme), + KB_CDE = (1 << QPlatformTheme::CdeKeyboardScheme), + KB_All = 0xffff +}; + const QKeyBinding QKeySequencePrivate::keyBindings[] = { // StandardKey Priority Key Sequence Platforms - {QKeySequence::Back, 0, Qt::Key_Backspace, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::InsertParagraphSeparator,0, Qt::Key_Return, QGuiApplicationPrivate::KB_All}, - {QKeySequence::InsertParagraphSeparator,0, Qt::Key_Enter, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Delete, 1, Qt::Key_Delete, QGuiApplicationPrivate::KB_All}, - {QKeySequence::MoveToStartOfLine, 0, Qt::Key_Home, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::MoveToStartOfDocument, 0, Qt::Key_Home, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToEndOfLine, 0, Qt::Key_End, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::MoveToEndOfDocument, 0, Qt::Key_End, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToPreviousChar, 0, Qt::Key_Left, QGuiApplicationPrivate::KB_All}, - {QKeySequence::MoveToPreviousLine, 0, Qt::Key_Up, QGuiApplicationPrivate::KB_All}, - {QKeySequence::MoveToNextChar, 0, Qt::Key_Right, QGuiApplicationPrivate::KB_All}, - {QKeySequence::MoveToNextLine, 0, Qt::Key_Down, QGuiApplicationPrivate::KB_All}, - {QKeySequence::MoveToPreviousPage, 1, Qt::Key_PageUp, QGuiApplicationPrivate::KB_All}, - {QKeySequence::MoveToNextPage, 1, Qt::Key_PageDown, QGuiApplicationPrivate::KB_All}, - {QKeySequence::HelpContents, 0, Qt::Key_F1, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::FindNext, 0, Qt::Key_F3, QGuiApplicationPrivate::KB_X11}, - {QKeySequence::FindNext, 1, Qt::Key_F3, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::Refresh, 0, Qt::Key_F5, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::Undo, 0, Qt::Key_F14, QGuiApplicationPrivate::KB_X11}, //Undo on sun keyboards - {QKeySequence::Copy, 0, Qt::Key_F16, QGuiApplicationPrivate::KB_X11}, //Copy on sun keyboards - {QKeySequence::Paste, 0, Qt::Key_F18, QGuiApplicationPrivate::KB_X11}, //Paste on sun keyboards - {QKeySequence::Cut, 0, Qt::Key_F20, QGuiApplicationPrivate::KB_X11}, //Cut on sun keyboards - {QKeySequence::PreviousChild, 0, Qt::Key_Back, QGuiApplicationPrivate::KB_All}, - {QKeySequence::NextChild, 0, Qt::Key_Forward, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Forward, 0, Qt::SHIFT | Qt::Key_Backspace, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Return, QGuiApplicationPrivate::KB_All}, - {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Enter, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Paste, 0, Qt::SHIFT | Qt::Key_Insert, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::Cut, 0, Qt::SHIFT | Qt::Key_Delete, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, //## Check if this should work on mac - {QKeySequence::SelectStartOfLine, 0, Qt::SHIFT | Qt::Key_Home, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::SelectStartOfDocument, 0, Qt::SHIFT | Qt::Key_Home, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectEndOfLine, 0, Qt::SHIFT | Qt::Key_End, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::SelectEndOfDocument, 0, Qt::SHIFT | Qt::Key_End, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectPreviousChar, 0, Qt::SHIFT | Qt::Key_Left, QGuiApplicationPrivate::KB_All}, - {QKeySequence::SelectPreviousLine, 0, Qt::SHIFT | Qt::Key_Up, QGuiApplicationPrivate::KB_All}, - {QKeySequence::SelectNextChar, 0, Qt::SHIFT | Qt::Key_Right, QGuiApplicationPrivate::KB_All}, - {QKeySequence::SelectNextLine, 0, Qt::SHIFT | Qt::Key_Down, QGuiApplicationPrivate::KB_All}, - {QKeySequence::SelectPreviousPage, 0, Qt::SHIFT | Qt::Key_PageUp, QGuiApplicationPrivate::KB_All}, - {QKeySequence::SelectNextPage, 0, Qt::SHIFT | Qt::Key_PageDown, QGuiApplicationPrivate::KB_All}, - {QKeySequence::WhatsThis, 1, Qt::SHIFT | Qt::Key_F1, QGuiApplicationPrivate::KB_All}, - {QKeySequence::FindPrevious, 0, Qt::SHIFT | Qt::Key_F3, QGuiApplicationPrivate::KB_X11}, - {QKeySequence::FindPrevious, 1, Qt::SHIFT | Qt::Key_F3, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::ZoomIn, 1, Qt::CTRL | Qt::Key_Plus, QGuiApplicationPrivate::KB_All}, - {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Comma, QGuiApplicationPrivate::KB_KDE}, - {QKeySequence::Preferences, 0, Qt::CTRL | Qt::Key_Comma, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::ZoomOut, 1, Qt::CTRL | Qt::Key_Minus, QGuiApplicationPrivate::KB_All}, - {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::Key_Period, QGuiApplicationPrivate::KB_KDE}, - {QKeySequence::HelpContents, 1, Qt::CTRL | Qt::Key_Question, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectAll, 1, Qt::CTRL | Qt::Key_A, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Bold, 1, Qt::CTRL | Qt::Key_B, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Copy, 1, Qt::CTRL | Qt::Key_C, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Delete, 0, Qt::CTRL | Qt::Key_D, QGuiApplicationPrivate::KB_X11}, //emacs (line edit only) - {QKeySequence::Find, 0, Qt::CTRL | Qt::Key_F, QGuiApplicationPrivate::KB_All}, - {QKeySequence::FindNext, 1, Qt::CTRL | Qt::Key_G, QGuiApplicationPrivate::KB_Gnome | QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::FindNext, 0, Qt::CTRL | Qt::Key_G, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, QGuiApplicationPrivate::KB_Gnome}, - {QKeySequence::Italic, 0, Qt::CTRL | Qt::Key_I, QGuiApplicationPrivate::KB_All}, - {QKeySequence::DeleteEndOfLine, 0, Qt::CTRL | Qt::Key_K, QGuiApplicationPrivate::KB_X11}, //emacs (line edit only) - {QKeySequence::New, 1, Qt::CTRL | Qt::Key_N, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Open, 1, Qt::CTRL | Qt::Key_O, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Print, 1, Qt::CTRL | Qt::Key_P, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Quit, 0, Qt::CTRL | Qt::Key_Q, QGuiApplicationPrivate::KB_Gnome | QGuiApplicationPrivate::KB_KDE | QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Refresh, 1, Qt::CTRL | Qt::Key_R, QGuiApplicationPrivate::KB_Gnome | QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_R, QGuiApplicationPrivate::KB_KDE}, - {QKeySequence::Save, 1, Qt::CTRL | Qt::Key_S, QGuiApplicationPrivate::KB_All}, - {QKeySequence::AddTab, 0, Qt::CTRL | Qt::Key_T, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Underline, 1, Qt::CTRL | Qt::Key_U, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Paste, 1, Qt::CTRL | Qt::Key_V, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_W, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_W, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Cut, 1, Qt::CTRL | Qt::Key_X, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Redo, 1, Qt::CTRL | Qt::Key_Y, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::Undo, 1, Qt::CTRL | Qt::Key_Z, QGuiApplicationPrivate::KB_All}, - {QKeySequence::Back, 1, Qt::CTRL | Qt::Key_BracketLeft, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Forward, 1, Qt::CTRL | Qt::Key_BracketRight, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::Key_BraceLeft, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_BraceRight, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_Tab, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Tab, QGuiApplicationPrivate::KB_Mac}, //different priority from above - {QKeySequence::DeleteStartOfWord, 0, Qt::CTRL | Qt::Key_Backspace, QGuiApplicationPrivate::KB_X11 | QGuiApplicationPrivate::KB_Win}, - {QKeySequence::Copy, 0, Qt::CTRL | Qt::Key_Insert, QGuiApplicationPrivate::KB_X11 | QGuiApplicationPrivate::KB_Win}, - {QKeySequence::DeleteEndOfWord, 0, Qt::CTRL | Qt::Key_Delete, QGuiApplicationPrivate::KB_X11 | QGuiApplicationPrivate::KB_Win}, - {QKeySequence::MoveToStartOfDocument, 0, Qt::CTRL | Qt::Key_Home, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::MoveToEndOfDocument, 0, Qt::CTRL | Qt::Key_End, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::Back, 0, Qt::CTRL | Qt::Key_Left, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToPreviousWord, 0, Qt::CTRL | Qt::Key_Left, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::MoveToStartOfLine, 0, Qt::CTRL | Qt::Key_Left, QGuiApplicationPrivate::KB_Mac }, - {QKeySequence::MoveToStartOfDocument, 1, Qt::CTRL | Qt::Key_Up, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Forward, 0, Qt::CTRL | Qt::Key_Right, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToEndOfLine, 0, Qt::CTRL | Qt::Key_Right, QGuiApplicationPrivate::KB_Mac }, - {QKeySequence::MoveToNextWord, 0, Qt::CTRL | Qt::Key_Right, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::MoveToEndOfDocument, 1, Qt::CTRL | Qt::Key_Down, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_F4, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_F4, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_F6, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::FindPrevious, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_G, QGuiApplicationPrivate::KB_Gnome | QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::FindPrevious, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_G, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::AddTab, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_N, QGuiApplicationPrivate::KB_KDE}, - {QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, QGuiApplicationPrivate::KB_Gnome | QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, QGuiApplicationPrivate::KB_Mac },//different priority from above - {QKeySequence::Paste, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Insert, QGuiApplicationPrivate::KB_X11}, - {QKeySequence::SelectStartOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Home, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::SelectEndOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_End, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::SelectPreviousWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::SelectStartOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, QGuiApplicationPrivate::KB_Mac }, - {QKeySequence::SelectStartOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Up, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectNextWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::SelectEndOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, QGuiApplicationPrivate::KB_Mac }, - {QKeySequence::SelectEndOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Down, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_F6, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::Undo, 0, Qt::ALT | Qt::Key_Backspace, QGuiApplicationPrivate::KB_Win}, - {QKeySequence::DeleteStartOfWord, 0, Qt::ALT | Qt::Key_Backspace, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::DeleteEndOfWord, 0, Qt::ALT | Qt::Key_Delete, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Back, 1, Qt::ALT | Qt::Key_Left, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::MoveToPreviousWord, 0, Qt::ALT | Qt::Key_Left, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToStartOfBlock, 0, Qt::ALT | Qt::Key_Up, QGuiApplicationPrivate::KB_Mac}, //mac only - {QKeySequence::MoveToNextWord, 0, Qt::ALT | Qt::Key_Right, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Forward, 1, Qt::ALT | Qt::Key_Right, QGuiApplicationPrivate::KB_Win | QGuiApplicationPrivate::KB_X11}, - {QKeySequence::MoveToEndOfBlock, 0, Qt::ALT | Qt::Key_Down, QGuiApplicationPrivate::KB_Mac}, //mac only - {QKeySequence::MoveToPreviousPage, 0, Qt::ALT | Qt::Key_PageUp, QGuiApplicationPrivate::KB_Mac }, - {QKeySequence::MoveToNextPage, 0, Qt::ALT | Qt::Key_PageDown, QGuiApplicationPrivate::KB_Mac }, - {QKeySequence::Redo, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Backspace,QGuiApplicationPrivate::KB_Win}, - {QKeySequence::SelectPreviousWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Left, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectStartOfBlock, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Up, QGuiApplicationPrivate::KB_Mac}, //mac only - {QKeySequence::SelectNextWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Right, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectEndOfBlock, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Down, QGuiApplicationPrivate::KB_Mac}, //mac only - {QKeySequence::MoveToStartOfBlock, 0, Qt::META | Qt::Key_A, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::Delete, 0, Qt::META | Qt::Key_D, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToEndOfBlock, 0, Qt::META | Qt::Key_E, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_Return, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_Enter, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToStartOfLine, 0, Qt::META | Qt::Key_Left, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_Up, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToEndOfLine, 0, Qt::META | Qt::Key_Right, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_Down, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_PageUp, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_PageDown, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectStartOfBlock, 0, Qt::META | Qt::SHIFT | Qt::Key_A, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectEndOfBlock, 0, Qt::META | Qt::SHIFT | Qt::Key_E, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectStartOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Left, QGuiApplicationPrivate::KB_Mac}, - {QKeySequence::SelectEndOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Right, QGuiApplicationPrivate::KB_Mac} + {QKeySequence::Back, 0, Qt::Key_Backspace, KB_Win}, + {QKeySequence::InsertParagraphSeparator,0, Qt::Key_Return, KB_All}, + {QKeySequence::InsertParagraphSeparator,0, Qt::Key_Enter, KB_All}, + {QKeySequence::Delete, 1, Qt::Key_Delete, KB_All}, + {QKeySequence::MoveToStartOfLine, 0, Qt::Key_Home, KB_Win | KB_X11}, + {QKeySequence::MoveToStartOfDocument, 0, Qt::Key_Home, KB_Mac}, + {QKeySequence::MoveToEndOfLine, 0, Qt::Key_End, KB_Win | KB_X11}, + {QKeySequence::MoveToEndOfDocument, 0, Qt::Key_End, KB_Mac}, + {QKeySequence::MoveToPreviousChar, 0, Qt::Key_Left, KB_All}, + {QKeySequence::MoveToPreviousLine, 0, Qt::Key_Up, KB_All}, + {QKeySequence::MoveToNextChar, 0, Qt::Key_Right, KB_All}, + {QKeySequence::MoveToNextLine, 0, Qt::Key_Down, KB_All}, + {QKeySequence::MoveToPreviousPage, 1, Qt::Key_PageUp, KB_All}, + {QKeySequence::MoveToNextPage, 1, Qt::Key_PageDown, KB_All}, + {QKeySequence::HelpContents, 0, Qt::Key_F1, KB_Win | KB_X11}, + {QKeySequence::FindNext, 0, Qt::Key_F3, KB_X11}, + {QKeySequence::FindNext, 1, Qt::Key_F3, KB_Win}, + {QKeySequence::Refresh, 0, Qt::Key_F5, KB_Win | KB_X11}, + {QKeySequence::Undo, 0, Qt::Key_F14, KB_X11}, //Undo on sun keyboards + {QKeySequence::Copy, 0, Qt::Key_F16, KB_X11}, //Copy on sun keyboards + {QKeySequence::Paste, 0, Qt::Key_F18, KB_X11}, //Paste on sun keyboards + {QKeySequence::Cut, 0, Qt::Key_F20, KB_X11}, //Cut on sun keyboards + {QKeySequence::PreviousChild, 0, Qt::Key_Back, KB_All}, + {QKeySequence::NextChild, 0, Qt::Key_Forward, KB_All}, + {QKeySequence::Forward, 0, Qt::SHIFT | Qt::Key_Backspace, KB_Win}, + {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Return, KB_All}, + {QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Enter, KB_All}, + {QKeySequence::Paste, 0, Qt::SHIFT | Qt::Key_Insert, KB_Win | KB_X11}, + {QKeySequence::Cut, 0, Qt::SHIFT | Qt::Key_Delete, KB_Win | KB_X11}, //## Check if this should work on mac + {QKeySequence::SelectStartOfLine, 0, Qt::SHIFT | Qt::Key_Home, KB_Win | KB_X11}, + {QKeySequence::SelectStartOfDocument, 0, Qt::SHIFT | Qt::Key_Home, KB_Mac}, + {QKeySequence::SelectEndOfLine, 0, Qt::SHIFT | Qt::Key_End, KB_Win | KB_X11}, + {QKeySequence::SelectEndOfDocument, 0, Qt::SHIFT | Qt::Key_End, KB_Mac}, + {QKeySequence::SelectPreviousChar, 0, Qt::SHIFT | Qt::Key_Left, KB_All}, + {QKeySequence::SelectPreviousLine, 0, Qt::SHIFT | Qt::Key_Up, KB_All}, + {QKeySequence::SelectNextChar, 0, Qt::SHIFT | Qt::Key_Right, KB_All}, + {QKeySequence::SelectNextLine, 0, Qt::SHIFT | Qt::Key_Down, KB_All}, + {QKeySequence::SelectPreviousPage, 0, Qt::SHIFT | Qt::Key_PageUp, KB_All}, + {QKeySequence::SelectNextPage, 0, Qt::SHIFT | Qt::Key_PageDown, KB_All}, + {QKeySequence::WhatsThis, 1, Qt::SHIFT | Qt::Key_F1, KB_All}, + {QKeySequence::FindPrevious, 0, Qt::SHIFT | Qt::Key_F3, KB_X11}, + {QKeySequence::FindPrevious, 1, Qt::SHIFT | Qt::Key_F3, KB_Win}, + {QKeySequence::ZoomIn, 1, Qt::CTRL | Qt::Key_Plus, KB_All}, + {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Comma, KB_KDE}, + {QKeySequence::Preferences, 0, Qt::CTRL | Qt::Key_Comma, KB_Mac}, + {QKeySequence::ZoomOut, 1, Qt::CTRL | Qt::Key_Minus, KB_All}, + {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::Key_Period, KB_KDE}, + {QKeySequence::HelpContents, 1, Qt::CTRL | Qt::Key_Question, KB_Mac}, + {QKeySequence::SelectAll, 1, Qt::CTRL | Qt::Key_A, KB_All}, + {QKeySequence::Bold, 1, Qt::CTRL | Qt::Key_B, KB_All}, + {QKeySequence::Copy, 1, Qt::CTRL | Qt::Key_C, KB_All}, + {QKeySequence::Delete, 0, Qt::CTRL | Qt::Key_D, KB_X11}, //emacs (line edit only) + {QKeySequence::Find, 0, Qt::CTRL | Qt::Key_F, KB_All}, + {QKeySequence::FindNext, 1, Qt::CTRL | Qt::Key_G, KB_Gnome | KB_Mac}, + {QKeySequence::FindNext, 0, Qt::CTRL | Qt::Key_G, KB_Win}, + {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, KB_Win}, + {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_H, KB_Gnome}, + {QKeySequence::Italic, 0, Qt::CTRL | Qt::Key_I, KB_All}, + {QKeySequence::DeleteEndOfLine, 0, Qt::CTRL | Qt::Key_K, KB_X11}, //emacs (line edit only) + {QKeySequence::New, 1, Qt::CTRL | Qt::Key_N, KB_All}, + {QKeySequence::Open, 1, Qt::CTRL | Qt::Key_O, KB_All}, + {QKeySequence::Print, 1, Qt::CTRL | Qt::Key_P, KB_All}, + {QKeySequence::Quit, 0, Qt::CTRL | Qt::Key_Q, KB_Gnome | KB_KDE | KB_Mac}, + {QKeySequence::Refresh, 1, Qt::CTRL | Qt::Key_R, KB_Gnome | KB_Mac}, + {QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_R, KB_KDE}, + {QKeySequence::Save, 1, Qt::CTRL | Qt::Key_S, KB_All}, + {QKeySequence::AddTab, 0, Qt::CTRL | Qt::Key_T, KB_All}, + {QKeySequence::Underline, 1, Qt::CTRL | Qt::Key_U, KB_All}, + {QKeySequence::Paste, 1, Qt::CTRL | Qt::Key_V, KB_All}, + {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_W, KB_Win | KB_X11}, + {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_W, KB_Mac}, + {QKeySequence::Cut, 1, Qt::CTRL | Qt::Key_X, KB_All}, + {QKeySequence::Redo, 1, Qt::CTRL | Qt::Key_Y, KB_Win}, + {QKeySequence::Undo, 1, Qt::CTRL | Qt::Key_Z, KB_All}, + {QKeySequence::Back, 1, Qt::CTRL | Qt::Key_BracketLeft, KB_Mac}, + {QKeySequence::Forward, 1, Qt::CTRL | Qt::Key_BracketRight, KB_Mac}, + {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::Key_BraceLeft, KB_Mac}, + {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_BraceRight, KB_Mac}, + {QKeySequence::NextChild, 1, Qt::CTRL | Qt::Key_Tab, KB_Win | KB_X11}, + {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Tab, KB_Mac}, //different priority from above + {QKeySequence::DeleteStartOfWord, 0, Qt::CTRL | Qt::Key_Backspace, KB_X11 | KB_Win}, + {QKeySequence::Copy, 0, Qt::CTRL | Qt::Key_Insert, KB_X11 | KB_Win}, + {QKeySequence::DeleteEndOfWord, 0, Qt::CTRL | Qt::Key_Delete, KB_X11 | KB_Win}, + {QKeySequence::MoveToStartOfDocument, 0, Qt::CTRL | Qt::Key_Home, KB_Win | KB_X11}, + {QKeySequence::MoveToEndOfDocument, 0, Qt::CTRL | Qt::Key_End, KB_Win | KB_X11}, + {QKeySequence::Back, 0, Qt::CTRL | Qt::Key_Left, KB_Mac}, + {QKeySequence::MoveToPreviousWord, 0, Qt::CTRL | Qt::Key_Left, KB_Win | KB_X11}, + {QKeySequence::MoveToStartOfLine, 0, Qt::CTRL | Qt::Key_Left, KB_Mac }, + {QKeySequence::MoveToStartOfDocument, 1, Qt::CTRL | Qt::Key_Up, KB_Mac}, + {QKeySequence::Forward, 0, Qt::CTRL | Qt::Key_Right, KB_Mac}, + {QKeySequence::MoveToEndOfLine, 0, Qt::CTRL | Qt::Key_Right, KB_Mac }, + {QKeySequence::MoveToNextWord, 0, Qt::CTRL | Qt::Key_Right, KB_Win | KB_X11}, + {QKeySequence::MoveToEndOfDocument, 1, Qt::CTRL | Qt::Key_Down, KB_Mac}, + {QKeySequence::Close, 1, Qt::CTRL | Qt::Key_F4, KB_Win}, + {QKeySequence::Close, 0, Qt::CTRL | Qt::Key_F4, KB_Mac}, + {QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_F6, KB_Win}, + {QKeySequence::FindPrevious, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_G, KB_Gnome | KB_Mac}, + {QKeySequence::FindPrevious, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_G, KB_Win}, + {QKeySequence::AddTab, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_N, KB_KDE}, + {QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, KB_Gnome | KB_Mac}, + {QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, KB_Win | KB_X11}, + {QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, KB_Mac}, + {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, KB_Win | KB_X11}, + {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, KB_Mac },//different priority from above + {QKeySequence::Paste, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Insert, KB_X11}, + {QKeySequence::SelectStartOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Home, KB_Win | KB_X11}, + {QKeySequence::SelectEndOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_End, KB_Win | KB_X11}, + {QKeySequence::SelectPreviousWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, KB_Win | KB_X11}, + {QKeySequence::SelectStartOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, KB_Mac }, + {QKeySequence::SelectStartOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Up, KB_Mac}, + {QKeySequence::SelectNextWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, KB_Win | KB_X11}, + {QKeySequence::SelectEndOfLine, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Right, KB_Mac }, + {QKeySequence::SelectEndOfDocument, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Down, KB_Mac}, + {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_F6, KB_Win}, + {QKeySequence::Undo, 0, Qt::ALT | Qt::Key_Backspace, KB_Win}, + {QKeySequence::DeleteStartOfWord, 0, Qt::ALT | Qt::Key_Backspace, KB_Mac}, + {QKeySequence::DeleteEndOfWord, 0, Qt::ALT | Qt::Key_Delete, KB_Mac}, + {QKeySequence::Back, 1, Qt::ALT | Qt::Key_Left, KB_Win | KB_X11}, + {QKeySequence::MoveToPreviousWord, 0, Qt::ALT | Qt::Key_Left, KB_Mac}, + {QKeySequence::MoveToStartOfBlock, 0, Qt::ALT | Qt::Key_Up, KB_Mac}, //mac only + {QKeySequence::MoveToNextWord, 0, Qt::ALT | Qt::Key_Right, KB_Mac}, + {QKeySequence::Forward, 1, Qt::ALT | Qt::Key_Right, KB_Win | KB_X11}, + {QKeySequence::MoveToEndOfBlock, 0, Qt::ALT | Qt::Key_Down, KB_Mac}, //mac only + {QKeySequence::MoveToPreviousPage, 0, Qt::ALT | Qt::Key_PageUp, KB_Mac }, + {QKeySequence::MoveToNextPage, 0, Qt::ALT | Qt::Key_PageDown, KB_Mac }, + {QKeySequence::Redo, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Backspace,KB_Win}, + {QKeySequence::SelectPreviousWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Left, KB_Mac}, + {QKeySequence::SelectStartOfBlock, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Up, KB_Mac}, //mac only + {QKeySequence::SelectNextWord, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Right, KB_Mac}, + {QKeySequence::SelectEndOfBlock, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Down, KB_Mac}, //mac only + {QKeySequence::MoveToStartOfBlock, 0, Qt::META | Qt::Key_A, KB_Mac}, + {QKeySequence::Delete, 0, Qt::META | Qt::Key_D, KB_Mac}, + {QKeySequence::MoveToEndOfBlock, 0, Qt::META | Qt::Key_E, KB_Mac}, + {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_Return, KB_Mac}, + {QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_Enter, KB_Mac}, + {QKeySequence::MoveToStartOfLine, 0, Qt::META | Qt::Key_Left, KB_Mac}, + {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_Up, KB_Mac}, + {QKeySequence::MoveToEndOfLine, 0, Qt::META | Qt::Key_Right, KB_Mac}, + {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_Down, KB_Mac}, + {QKeySequence::MoveToPreviousPage, 0, Qt::META | Qt::Key_PageUp, KB_Mac}, + {QKeySequence::MoveToNextPage, 0, Qt::META | Qt::Key_PageDown, KB_Mac}, + {QKeySequence::SelectStartOfBlock, 0, Qt::META | Qt::SHIFT | Qt::Key_A, KB_Mac}, + {QKeySequence::SelectEndOfBlock, 0, Qt::META | Qt::SHIFT | Qt::Key_E, KB_Mac}, + {QKeySequence::SelectStartOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Left, KB_Mac}, + {QKeySequence::SelectEndOfLine, 0, Qt::META | Qt::SHIFT | Qt::Key_Right, KB_Mac} }; const uint QKeySequencePrivate::numberOfKeyBindings = sizeof(QKeySequencePrivate::keyBindings)/(sizeof(QKeyBinding)); @@ -991,7 +1002,7 @@ static inline int maybeSwapShortcut(int shortcut) */ QList QKeySequence::keyBindings(StandardKey key) { - uint platform = QGuiApplicationPrivate::currentKeyPlatform(); + const uint platform = QKeySequencePrivate::currentKeyPlatforms(); QList list; for (uint i = 0; i < QKeySequencePrivate::numberOfKeyBindings ; ++i) { QKeyBinding keyBinding = QKeySequencePrivate::keyBindings[i]; @@ -1330,6 +1341,19 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence return ret; } +unsigned QKeySequencePrivate::currentKeyPlatforms() +{ + int keyboardScheme = QPlatformTheme::WindowsKeyboardScheme; + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + keyboardScheme = theme->themeHint(QPlatformTheme::KeyboardScheme).toInt(); + unsigned result = 1u << keyboardScheme; + if (keyboardScheme == QPlatformTheme::KdeKeyboardScheme + || keyboardScheme == QPlatformTheme::GnomeKeyboardScheme + || keyboardScheme == QPlatformTheme::CdeKeyboardScheme) + result |= KB_X11; + return result; +} + /*! Creates a shortcut string for \a key. For example, Qt::CTRL+Qt::Key_O gives "Ctrl+O". The strings, "Ctrl", "Shift", etc. are diff --git a/src/gui/kernel/qkeysequence_p.h b/src/gui/kernel/qkeysequence_p.h index 68cbb8778b..4481557121 100644 --- a/src/gui/kernel/qkeysequence_p.h +++ b/src/gui/kernel/qkeysequence_p.h @@ -88,6 +88,7 @@ public: static const QKeyBinding keyBindings[]; static const uint numberOfKeyBindings; + static unsigned currentKeyPlatforms(); }; #endif // QT_NO_SHORTCUT diff --git a/src/gui/kernel/qplatformtheme_qpa.cpp b/src/gui/kernel/qplatformtheme_qpa.cpp index aec465f0ff..3f6b69b902 100644 --- a/src/gui/kernel/qplatformtheme_qpa.cpp +++ b/src/gui/kernel/qplatformtheme_qpa.cpp @@ -84,6 +84,20 @@ QT_BEGIN_NAMESPACE \value StyleNames (QStringList) A list of preferred style names. + \value WindowAutoPlacement (bool) A boolean value indicating whether Windows + (particularly dialogs) are placed by the system + (see _NET_WM_FULL_PLACEMENT in X11). + + \value DialogButtonBoxLayout (int) An integer representing a + QDialogButtonBox::ButtonLayout value. + + \value DialogButtonBoxButtonsHaveIcons (bool) A boolean value indicating whether + the buttons of a QDialogButtonBox should have icons. + + \value UseFullScreenForPopupMenu (bool) Pop menus can cover the full screen including task bar. + + \value KeyboardScheme (int) An integer value (enum KeyboardSchemes) specifying the + keyboard scheme. \sa themeHint(), QStyle::pixelMetric() */ @@ -121,6 +135,14 @@ const QPalette *QPlatformTheme::palette(Palette type) const QVariant QPlatformTheme::themeHint(ThemeHint hint) const { switch (hint) { + case QPlatformTheme::UseFullScreenForPopupMenu: + return QVariant(false); + case QPlatformTheme::WindowAutoPlacement: + return QVariant(false); + case QPlatformTheme::DialogButtonBoxLayout: + return QVariant(int(0)); + case QPlatformTheme::DialogButtonBoxButtonsHaveIcons: + return QVariant(false); case QPlatformTheme::ItemViewActivateItemOnSingleClick: return QVariant(false); case QPlatformTheme::ToolButtonStyle: @@ -140,6 +162,8 @@ QVariant QPlatformTheme::themeHint(ThemeHint hint) const return QVariant(false); case MaximumScrollBarDragDistance: return QVariant(-1); + case KeyboardScheme: + return QVariant(int(WindowsKeyboardScheme)); } return QVariant(); } diff --git a/src/gui/kernel/qplatformtheme_qpa.h b/src/gui/kernel/qplatformtheme_qpa.h index 036432054e..31a52a9391 100644 --- a/src/gui/kernel/qplatformtheme_qpa.h +++ b/src/gui/kernel/qplatformtheme_qpa.h @@ -69,7 +69,12 @@ public: SystemIconThemeName, SystemIconFallbackThemeName, IconThemeSearchPaths, - StyleNames + StyleNames, + WindowAutoPlacement, + DialogButtonBoxLayout, + DialogButtonBoxButtonsHaveIcons, + UseFullScreenForPopupMenu, + KeyboardScheme }; enum DialogType { @@ -84,6 +89,16 @@ public: NPalettes }; + enum KeyboardSchemes + { + WindowsKeyboardScheme, + MacKeyboardScheme, + X11KeyboardScheme, + KdeKeyboardScheme, + GnomeKeyboardScheme, + CdeKeyboardScheme + }; + virtual QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const; virtual QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const; diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index a9f05f6084..257fe9156f 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -89,12 +89,15 @@ QVariant QGenericUnixTheme::themeHint(ThemeHint hint) const return QVariant(QString(QStringLiteral("hicolor"))); case QPlatformTheme::IconThemeSearchPaths: return xdgIconThemePaths(); + case QPlatformTheme::DialogButtonBoxButtonsHaveIcons: + return QVariant(true); case QPlatformTheme::StyleNames: { QStringList styleNames; styleNames << QStringLiteral("Plastique") << QStringLiteral("Windows"); return QVariant(styleNames); } - break; + case QPlatformTheme::KeyboardScheme: + return QVariant(int(X11KeyboardScheme)); default: break; } @@ -229,6 +232,12 @@ static QStringList kdeIconThemeSearchPaths(const QString &kdeHome) QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const { switch (hint) { + case QPlatformTheme::UseFullScreenForPopupMenu: + return QVariant(true); + case QPlatformTheme::DialogButtonBoxButtonsHaveIcons: + return QVariant(true); + case QPlatformTheme::DialogButtonBoxLayout: + return QVariant(2); // QDialogButtonBox::KdeLayout case QPlatformTheme::ToolButtonStyle: return QVariant(m_toolButtonStyle); case QPlatformTheme::ToolBarIconSize: @@ -241,6 +250,8 @@ QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QVariant(kdeIconThemeSearchPaths(m_kdeHome)); case QPlatformTheme::StyleNames: return QVariant(m_styleNames); + case QPlatformTheme::KeyboardScheme: + return QVariant(int(KdeKeyboardScheme)); default: break; } @@ -282,6 +293,10 @@ QPlatformTheme *QKdeTheme::createKdeTheme() QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const { switch (hint) { + case QPlatformTheme::DialogButtonBoxButtonsHaveIcons: + return QVariant(true); + case QPlatformTheme::DialogButtonBoxLayout: + return QVariant(3); // QDialogButtonBox::GnomeLayout case QPlatformTheme::SystemIconThemeName: case QPlatformTheme::SystemIconFallbackThemeName: return QVariant(QString(QStringLiteral("gnome"))); @@ -292,6 +307,8 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const styleNames << QStringLiteral("GTK+") << QStringLiteral("cleanlooks") << QStringLiteral("windows"); return QVariant(styleNames); } + case QPlatformTheme::KeyboardScheme: + return QVariant(int(GnomeKeyboardScheme)); default: break; } diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index ad20c2fb27..0fef3234b4 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -105,13 +105,16 @@ QPlatformDialogHelper * QCocoaTheme::createPlatformDialogHelper(DialogType dialo QVariant QCocoaTheme::themeHint(ThemeHint hint) const { switch (hint) { - case QPlatformTheme::StyleNames: - return QStringList() << QLatin1Literal("macintosh"); - break; - default: - return QPlatformTheme::themeHint(hint); + case QPlatformTheme::StyleNames: + return QStringList(QStringLiteral("macintosh")); + case QPlatformTheme::DialogButtonBoxLayout: + return QVariant(1); // QDialogButtonBox::MacLayout + case KeyboardScheme: + return QVariant(int(MacKeyboardScheme)); + default: break; } + return QPlatformTheme::themeHint(hint); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index a59b74cef3..7276db4bb6 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -220,11 +220,12 @@ static inline QStringList styleNames() QVariant QWindowsTheme::themeHint(ThemeHint hint) const { switch (hint) { - case SystemIconThemeName: - break; + case UseFullScreenForPopupMenu: + return QVariant(true); + case DialogButtonBoxLayout: + return QVariant(int(0)); // QDialogButtonBox::WinLayout case IconThemeSearchPaths: return QVariant(iconThemeSearchPaths()); - break; case StyleNames: return QVariant(styleNames()); case TextCursorWidth: @@ -233,8 +234,12 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const return QVariant(booleanSystemParametersInfo(SPI_GETDROPSHADOW, false)); case MaximumScrollBarDragDistance: return QVariant(qRound(qreal(QWindowsContext::instance()->defaultDPI()) * 1.375)); + case KeyboardScheme: + return QVariant(int(WindowsKeyboardScheme)); + default: + break; } - return QVariant(); + return QPlatformTheme::themeHint(hint); } void QWindowsTheme::refresh() diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index 49b4dd3a23..5ffb5466d6 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -55,6 +55,7 @@ #include "qplatformtheme_qpa.h" #include "private/qdialog_p.h" #include "private/qguiapplication_p.h" +#include "qplatformtheme_qpa.h" #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" #endif @@ -790,11 +791,10 @@ void QDialog::showEvent(QShowEvent *event) /*! \internal */ void QDialog::adjustPosition(QWidget* w) { -#ifdef Q_WS_X11 - // if the WM advertises that it will place the windows properly for us, let it do it :) - if (X11->isSupportedByWM(ATOM(_NET_WM_FULL_PLACEMENT))) - return; -#endif + + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + if (theme->themeHint(QPlatformTheme::WindowAutoPlacement).toBool()) + return; QPoint p(0, 0); int extraw = 0, extrah = 0, scrn = 0; if (w) diff --git a/src/widgets/kernel/qicon.cpp b/src/widgets/kernel/qicon.cpp index e579fac4f4..eebd57f97e 100644 --- a/src/widgets/kernel/qicon.cpp +++ b/src/widgets/kernel/qicon.cpp @@ -60,11 +60,6 @@ #include #endif -#ifdef Q_WS_X11 -#include "private/qt_x11_p.h" -#include "private/qkde_p.h" -#endif - #include "private/qhexstring_p.h" #ifndef QT_NO_ICON diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 75476faeeb..174e94e63d 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -83,12 +83,6 @@ # include "private/qtextengine_p.h" #endif -#ifdef Q_WS_X11 -# include -#elif defined(Q_WS_MAC) -# include -#endif - #include QT_BEGIN_NAMESPACE @@ -4920,12 +4914,8 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget break; case SH_DialogButtonLayout: ret = QDialogButtonBox::WinLayout; -#ifdef Q_WS_X11 - if (X11->desktopEnvironment == DE_KDE) - ret = QDialogButtonBox::KdeLayout; - else if (X11->desktopEnvironment == DE_GNOME) - ret = QDialogButtonBox::GnomeLayout; -#endif + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + ret = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt(); break; case SH_ComboBox_PopupFrameStyle: ret = QFrame::StyledPanel | QFrame::Plain; @@ -4934,10 +4924,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = Qt::LinksAccessibleByMouse; break; case SH_DialogButtonBox_ButtonsHaveIcons: -#ifdef Q_WS_X11 - return true; -#endif ret = 0; + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + ret = theme->themeHint(QPlatformTheme::DialogButtonBoxButtonsHaveIcons).toBool() ? 1 : 0; break; case SH_SpellCheckUnderlineStyle: ret = QTextCharFormat::WaveUnderline; -- cgit v1.2.3 From 4d0d49a92cca46555a5e3ed482b7d7f50ea3655a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 21 Feb 2012 19:45:05 +0100 Subject: Use QMAKE_SUBSTITUTIONS conditionals Instead of generating CMake conditionals. Change-Id: I3d987cc08666270e618222be9292558e73bc961e Reviewed-by: Oswald Buddenhagen --- src/corelib/Qt5CoreConfigExtras.cmake.in | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index 37af42d6bd..41dbf2c2a2 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -8,11 +8,11 @@ set(QT_RCC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/rcc$$CMAK list(APPEND Qt5Core_INCLUDE_DIRS \"${_qt5_corelib_install_prefix}/mkspecs/default\") -if (NOT \"$${CMAKE_ADD_FPIE_FLAGS}\" STREQUAL \"\") - set(Qt5Core_EXECUTABLE_COMPILE_FLAGS "-fPIE") -endif() +!!IF !isEmpty(CMAKE_ADD_FPIE_FLAGS) +set(Qt5Core_EXECUTABLE_COMPILE_FLAGS "-fPIE") +!!ENDIF -if (NOT \"$$QT_NAMESPACE\" STREQUAL \"\") - list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE) - list(APPEND Qt5Core_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE) -endif() +!!IF !isEmpty(QT_NAMESPACE) +list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE) +list(APPEND Qt5Core_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE) +!!ENDIF -- cgit v1.2.3 From f783ec5347ac9962d011b2ff470082e083216367 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 21 Feb 2012 22:18:26 +0100 Subject: Remove use of Q_BROKEN_DEBUG_STREAM. No supported compiler defines it, and it was not used consistently so it didn't work anyway. Change-Id: Icc9e911e22daaedaee3d9316c15d19be26cd2e72 Reviewed-by: Thiago Macieira --- src/corelib/itemmodels/qabstractitemmodel.cpp | 6 ------ src/corelib/itemmodels/qitemselectionmodel.cpp | 6 ------ src/corelib/kernel/qobject.cpp | 6 ------ src/corelib/kernel/qvariant.cpp | 24 ++++++------------------ src/corelib/kernel/qvariant_p.h | 2 +- src/gui/kernel/qevent.cpp | 6 ------ src/gui/kernel/qguivariant.cpp | 4 ++-- src/gui/kernel/qkeysequence.cpp | 6 ------ src/gui/painting/qbrush.cpp | 6 ------ src/gui/painting/qcolor.cpp | 6 ------ src/gui/painting/qpen.cpp | 6 ------ src/gui/painting/qpolygon.cpp | 12 ------------ src/sql/kernel/qsqlfield.cpp | 6 ------ src/widgets/kernel/qwidgetsvariant.cpp | 4 ++-- 14 files changed, 11 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 1d6610af05..a8c3921f45 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -431,15 +431,9 @@ bool QPersistentModelIndex::isValid() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QModelIndex &idx) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column() << ',' << idx.internalPointer() << ',' << idx.model() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QModelIndex to QDebug"); - return dbg; - Q_UNUSED(idx); -#endif } QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx) diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 7f31128770..c6c1f6f3cf 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -1622,15 +1622,9 @@ void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelectio #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QItemSelectionRange &range) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QItemSelectionRange(" << range.topLeft() << ',' << range.bottomRight() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QItemSelectionRange to QDebug"); - return dbg; - Q_UNUSED(range); -#endif } #endif diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 252a713872..8fa5dcdcff 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -3617,7 +3617,6 @@ QObjectUserData* QObject::userData(uint id) const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QObject *o) { -#ifndef Q_BROKEN_DEBUG_STREAM if (!o) return dbg << "QObject(0x0) "; dbg.nospace() << o->metaObject()->className() << '(' << (void *)o; @@ -3625,11 +3624,6 @@ QDebug operator<<(QDebug dbg, const QObject *o) { dbg << ", name = " << o->objectName(); dbg << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QObject to QDebug"); - return dbg; - Q_UNUSED(o); -#endif } #endif diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 9f57cd018c..0b7866c3eb 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -732,7 +732,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, return true; } -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast(&v.data_ptr()); @@ -752,7 +752,7 @@ const QVariant::Handler qt_kernel_variant_handler = { compare, convert, 0, -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) streamDebug #else 0 @@ -764,7 +764,7 @@ static void dummyClear(QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Try static bool dummyIsNull(const QVariant::Private *d) { Q_ASSERT_X(false, "QVariant::isNull", "Trying to call isNull on an unknown type"); return d->is_null; } static bool dummyCompare(const QVariant::Private *, const QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to compare an unknown types"); return false; } static bool dummyConvert(const QVariant::Private *, QVariant::Type , void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; } -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) static void dummyStreamDebug(QDebug, const QVariant &) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); } #endif const QVariant::Handler qt_dummy_variant_handler = { @@ -778,7 +778,7 @@ const QVariant::Handler qt_dummy_variant_handler = { dummyCompare, dummyConvert, 0, -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) dummyStreamDebug #else 0 @@ -847,7 +847,7 @@ static bool customConvert(const QVariant::Private *, QVariant::Type, void *, boo return false; } -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) static void customStreamDebug(QDebug, const QVariant &) {} #endif @@ -862,7 +862,7 @@ const QVariant::Handler qt_custom_variant_handler = { customCompare, customConvert, 0, -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) customStreamDebug #else 0 @@ -2644,28 +2644,16 @@ bool QVariant::isNull() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QVariant &v) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QVariant(" << QMetaType::typeName(v.userType()) << ", "; handlerManager[v.d.type]->debugStream(dbg, v); dbg.nospace() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QVariant to QDebug"); - return dbg; - Q_UNUSED(v); -#endif } QDebug operator<<(QDebug dbg, const QVariant::Type p) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QVariant::" << QMetaType::typeName(p); return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QVariant::Type to QDebug"); - return dbg; - Q_UNUSED(p); -#endif } #endif diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index cdae8997a7..c428d81bb4 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -410,7 +410,7 @@ Q_CORE_EXPORT void registerHandler(const int /* Modules::Names */ name, const QV Q_CORE_EXPORT void unregisterHandler(const int /* Modules::Names */ name); } -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) template class QVariantDebugStream { diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index ce4594c7ab..f99f3ddec3 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -2887,7 +2887,6 @@ QShortcutEvent::~QShortcutEvent() #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QEvent *e) { -#ifndef Q_BROKEN_DEBUG_STREAM // More useful event output could be added here if (!e) return dbg << "QEvent(this = 0x0)"; @@ -3168,11 +3167,6 @@ QDebug operator<<(QDebug dbg, const QEvent *e) { dbg.nospace() << 'Q' << n << "Event(" << (const void *)e << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QEvent to QDebug"); - return dbg; - Q_UNUSED(e); -#endif } #endif diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 8378650dcb..2ebfb32bc3 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -342,7 +342,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, return qcoreVariantHandler()->convert(d, t, result, ok); } -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast(&v.data_ptr()); @@ -362,7 +362,7 @@ const QVariant::Handler qt_gui_variant_handler = { compare, convert, 0, -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) streamDebug #else 0 diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index bd0f220ae8..7053f01196 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -1735,14 +1735,8 @@ QDataStream &operator>>(QDataStream &s, QKeySequence &keysequence) #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QKeySequence &p) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QKeySequence(" << p.toString() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QKeySequence to QDebug"); - return dbg; - Q_UNUSED(p); -#endif } #endif diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index c8dc370a8b..6850eac59e 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -957,7 +957,6 @@ bool QBrush::operator==(const QBrush &b) const */ QDebug operator<<(QDebug dbg, const QBrush &b) { -#ifndef Q_BROKEN_DEBUG_STREAM static const char *BRUSH_STYLES[] = { "NoBrush", "SolidPattern", @@ -983,11 +982,6 @@ QDebug operator<<(QDebug dbg, const QBrush &b) dbg.nospace() << "QBrush(" << b.color() << ',' << BRUSH_STYLES[b.style()] << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QBrush to QDebug"); - return dbg; - Q_UNUSED(b); -#endif } #endif diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 2c95434843..96491918cd 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -2399,7 +2399,6 @@ void QColor::invalidate() #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QColor &c) { -#ifndef Q_BROKEN_DEBUG_STREAM if (!c.isValid()) dbg.nospace() << "QColor(Invalid)"; else if (c.spec() == QColor::Rgb) @@ -2413,11 +2412,6 @@ QDebug operator<<(QDebug dbg, const QColor &c) dbg.nospace() << "QColor(AHSL " << c.alphaF() << ", " << c.hslHueF() << ", " << c.hslSaturationF() << ", " << c.lightnessF() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QColor to QDebug"); - return dbg; - Q_UNUSED(c); -#endif } #endif diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp index b6966b12c3..8d05eb56ff 100644 --- a/src/gui/painting/qpen.cpp +++ b/src/gui/painting/qpen.cpp @@ -985,7 +985,6 @@ QDataStream &operator>>(QDataStream &s, QPen &p) #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QPen &p) { -#ifndef Q_BROKEN_DEBUG_STREAM const char *PEN_STYLES[] = { "NoPen", "SolidLine", @@ -1002,11 +1001,6 @@ QDebug operator<<(QDebug dbg, const QPen &p) << ',' << p.dashOffset() << ',' << p.miterLimit() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QPen to QDebug"); - return dbg; - Q_UNUSED(p); -#endif } #endif diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index 3a4860a559..ee1f7967cb 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -468,17 +468,11 @@ QRect QPolygon::boundingRect() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QPolygon &a) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QPolygon("; for (int i = 0; i < a.count(); ++i) dbg.nospace() << a.at(i); dbg.nospace() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QPolygon to QDebug"); - return dbg; - Q_UNUSED(a); -#endif } #endif @@ -814,17 +808,11 @@ QDataStream &operator>>(QDataStream &s, QPolygonF &a) #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QPolygonF &a) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QPolygonF("; for (int i = 0; i < a.count(); ++i) dbg.nospace() << a.at(i); dbg.nospace() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QPolygonF to QDebug"); - return dbg; - Q_UNUSED(a); -#endif } #endif diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp index 5d01df1b8e..3160d25ef5 100644 --- a/src/sql/kernel/qsqlfield.cpp +++ b/src/sql/kernel/qsqlfield.cpp @@ -504,7 +504,6 @@ bool QSqlField::isValid() const #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QSqlField &f) { -#ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QSqlField(" << f.name() << ", " << QVariant::typeToName(f.type()); if (f.length() >= 0) dbg.nospace() << ", length: " << f.length(); @@ -520,11 +519,6 @@ QDebug operator<<(QDebug dbg, const QSqlField &f) dbg.nospace() << ", auto-value: \"" << f.defaultValue() << '\"'; dbg.nospace() << ')'; return dbg.space(); -#else - qWarning("This compiler doesn't support streaming QSqlField to QDebug"); - return dbg; - Q_UNUSED(f); -#endif } #endif diff --git a/src/widgets/kernel/qwidgetsvariant.cpp b/src/widgets/kernel/qwidgetsvariant.cpp index 72080d9e6b..cf85cbf063 100644 --- a/src/widgets/kernel/qwidgetsvariant.cpp +++ b/src/widgets/kernel/qwidgetsvariant.cpp @@ -127,7 +127,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type type, void *resul return false; } -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast(&v.data_ptr()); @@ -157,7 +157,7 @@ static const QVariant::Handler widgets_handler = { compare, convert, 0, -#if !defined(QT_NO_DEBUG_STREAM) && !defined(Q_BROKEN_DEBUG_STREAM) +#if !defined(QT_NO_DEBUG_STREAM) streamDebug #else 0 -- cgit v1.2.3 From 58cd93efe6545ea74e9d3ba2003bcd5478e6c582 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 21 Feb 2012 17:26:45 +0100 Subject: Remove detection of GCC versions which are not supported anywhere. Change-Id: If254af51880e20be486b14f5237e6e1d4e4d6af3 Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 39 +++++++-------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 8adbdbe453..fa5c424772 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -139,45 +139,22 @@ # define Q_CC_MINGW # endif # if defined(__INTEL_COMPILER) -/* Intel C++ also masquerades as GCC 3.2.0 */ +/* Intel C++ also masquerades as GCC */ # define Q_CC_INTEL # endif # if defined(__clang__) -/* Clang also masquerades as GCC 4.2.1 */ +/* Clang also masquerades as GCC */ # define Q_CC_CLANG # endif # ifdef __APPLE__ # define Q_NO_DEPRECATED_CONSTRUCTORS # endif -# if __GNUC__ == 2 && __GNUC_MINOR__ <= 7 -# define Q_FULL_TEMPLATE_INSTANTIATION -# endif -/* GCC 2.95 knows "using" but does not support it correctly */ -# if __GNUC__ == 2 && __GNUC_MINOR__ <= 95 -# define Q_NO_USING_KEYWORD -# endif -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) -# define Q_ALIGNOF(type) __alignof__(type) -# define Q_TYPEOF(expr) __typeof__(expr) -# define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) -# endif -# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) -# define Q_LIKELY(expr) __builtin_expect(!!(expr), true) -# define Q_UNLIKELY(expr) __builtin_expect(!!(expr), false) -# endif -/* GCC 3.1 and GCC 3.2 wrongly define _SB_CTYPE_MACROS on HP-UX */ -# if defined(Q_OS_HPUX) && __GNUC__ == 3 && __GNUC_MINOR__ >= 1 -# define Q_WRONG_SB_CTYPE_MACROS -# endif -/* GCC <= 3.3 cannot handle template friends */ -# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ <= 3) -# define Q_NO_TEMPLATE_FRIENDS -# endif -/* Apple's GCC 3.1 chokes on our streaming qDebug() */ -# if defined(Q_OS_DARWIN) && __GNUC__ == 3 && (__GNUC_MINOR__ >= 1 && __GNUC_MINOR__ < 3) -# define Q_BROKEN_DEBUG_STREAM -# endif -# if (defined(Q_CC_GNU) || defined(Q_CC_INTEL)) && !defined(QT_MOC_CPP) +# define Q_ALIGNOF(type) __alignof__(type) +# define Q_TYPEOF(expr) __typeof__(expr) +# define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) +# define Q_LIKELY(expr) __builtin_expect(!!(expr), true) +# define Q_UNLIKELY(expr) __builtin_expect(!!(expr), false) +# if !defined(QT_MOC_CPP) # define Q_PACKED __attribute__ ((__packed__)) # define Q_NO_PACKED_REFERENCE # ifndef __ARM_EABI__ -- cgit v1.2.3 From 26cf615c9601cf4dbe4450aa95ad6e2020639513 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 21 Feb 2012 23:00:57 +0100 Subject: Add the QT_LIBINFIX to the CMake config files. Change-Id: If7bec54eca2d28cba314ce94a1ab1831c024ad31 Reviewed-by: Alexander Neundorf Reviewed-by: Stephen Kelly --- src/corelib/Qt5CoreConfigExtras.cmake.in | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index 41dbf2c2a2..4b5ac73bce 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -16,3 +16,7 @@ set(Qt5Core_EXECUTABLE_COMPILE_FLAGS "-fPIE") list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE) list(APPEND Qt5Core_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE) !!ENDIF + +!!IF !isEmpty(QT_LIBINFIX) +set(QT_LIBINFIX \"$${QT_LIBINFIX}\") +!!ENDIF -- cgit v1.2.3 From 126eaa7cddbf27d73d14394dfd8b0776376a6460 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 21 Feb 2012 17:25:28 +0100 Subject: Remove unused Q_CANNOT_DELETE_CONSTANT Change-Id: I697f3f786d84fa766b3bc48d93fc265deee5fdcf Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index fa5c424772..f76dfbaaa5 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -83,7 +83,6 @@ #elif defined(_MSC_VER) # define Q_CC_MSVC # define Q_CC_MSVC_NET -# define Q_CANNOT_DELETE_CONSTANT # define Q_OUTOFLINE_TEMPLATE inline # define Q_NO_TEMPLATE_FRIENDS # define Q_ALIGNOF(type) __alignof(type) @@ -259,7 +258,6 @@ DEC C++ V5.5-004. */ # if __DECCXX_VER < 60060000 # define Q_BROKEN_TEMPLATE_SPECIALIZATION -# define Q_CANNOT_DELETE_CONSTANT # endif /* avoid undefined symbol problems with out-of-line template members */ # define Q_OUTOFLINE_TEMPLATE inline -- cgit v1.2.3 From 13c7de63a15c2b47e07516650ba4f1b70f94680e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 22 Feb 2012 18:17:53 +0100 Subject: Don't do macro self-expansion for moc anymore. Change-Id: Ia34cc244a160c6c4abe6dacd7a2ce29bc4fc7bfb Reviewed-by: Olivier Goffart --- src/corelib/global/qglobal.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 58bdf06fb5..485f08bfce 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -310,9 +310,7 @@ QT_END_INCLUDE_NAMESPACE /* Warnings and errors when using deprecated methods */ -#if defined(Q_MOC_RUN) -# define Q_DECL_DEPRECATED Q_DECL_DEPRECATED -#elif (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2))) || defined(Q_CC_RVCT) +#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2))) || defined(Q_CC_RVCT) # define Q_DECL_DEPRECATED __attribute__ ((__deprecated__)) #elif defined(Q_CC_MSVC) # define Q_DECL_DEPRECATED __declspec(deprecated) @@ -327,9 +325,7 @@ QT_END_INCLUDE_NAMESPACE # define Q_DECL_VARIABLE_DEPRECATED Q_DECL_DEPRECATED #endif #ifndef Q_DECL_CONSTRUCTOR_DEPRECATED -# if defined(Q_MOC_RUN) -# define Q_DECL_CONSTRUCTOR_DEPRECATED Q_DECL_CONSTRUCTOR_DEPRECATED -# elif defined(Q_NO_DEPRECATED_CONSTRUCTORS) +# if defined(Q_NO_DEPRECATED_CONSTRUCTORS) # define Q_DECL_CONSTRUCTOR_DEPRECATED # else # define Q_DECL_CONSTRUCTOR_DEPRECATED Q_DECL_DEPRECATED -- cgit v1.2.3 From 949127264d16050113aff0932d2e0197921952d2 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Mon, 13 Feb 2012 17:27:36 +0200 Subject: Remove unneeded code to convert to ASCII/Latin1. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This isn't used, and isn't wanted with the upcoming utf8 switch. Change-Id: Ibec0fa7f36549df6a1c240353ffcd44beb2976f0 Reviewed-by: JoĂ£o Abecasis Reviewed-by: Thiago Macieira --- src/corelib/tools/qstringbuilder.cpp | 13 ------------- src/corelib/tools/qstringbuilder.h | 32 -------------------------------- 2 files changed, 45 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp index 30c4399cc9..6999972172 100644 --- a/src/corelib/tools/qstringbuilder.cpp +++ b/src/corelib/tools/qstringbuilder.cpp @@ -116,17 +116,4 @@ void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out } } -/*! \internal */ -void QAbstractConcatenable::convertToAscii(const QChar* a, int len, char*& out) -{ - if (len == -1) { - while (a->unicode()) - convertToLatin1(*a++, out); - } else { - for (int i = 0; i < len; ++i) - convertToLatin1(a[i], out); - } -} - - QT_END_NAMESPACE diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index ebaaaa35c2..4c963185ad 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -62,21 +62,10 @@ struct Q_CORE_EXPORT QAbstractConcatenable { protected: static void convertFromAscii(const char *a, int len, QChar *&out); - static void convertToAscii(const QChar *a, int len, char *&out); static inline void convertFromAscii(char a, QChar *&out) { *out++ = QLatin1Char(a); } - - static inline void convertToAscii(QChar a, char *&out) - { - convertToLatin1(a, out); - } - - static inline void convertToLatin1(QChar a, char *&out) - { - *out++ = a.unicode() > 0xff ? '?' : char(a.unicode()); - } }; template struct QConcatenable {}; @@ -182,10 +171,6 @@ template <> struct QConcatenable : private QAbstractConcatenable static int size(const QChar) { return 1; } static inline void appendTo(const QChar c, QChar *&out) { *out++ = c; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QChar c, char *&out) - { convertToAscii(c, out); } -#endif }; template <> struct QConcatenable : private QAbstractConcatenable @@ -196,10 +181,6 @@ template <> struct QConcatenable : private QAbstractConcatenable static int size(const QCharRef &) { return 1; } static inline void appendTo(const QCharRef &c, QChar *&out) { *out++ = QChar(c); } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QCharRef &c, char *&out) - { convertToAscii(c, out); } -#endif }; template <> struct QConcatenable @@ -232,10 +213,6 @@ template <> struct QConcatenable : private QAbstractConcatenable memcpy(out, reinterpret_cast(a.constData()), sizeof(QChar) * n); out += n; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QString &a, char *&out) - { convertToAscii(a.constData(), a.length(), out); } -#endif }; template struct QConcatenable > : private QAbstractConcatenable @@ -249,10 +226,6 @@ template struct QConcatenable > : private QAbstra memcpy(out, reinterpret_cast(a.ptr->data), sizeof(QChar) * N); out += N; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const type &a, char *&out) - { convertToAscii(a.ptr->data, N, out); } -#endif }; template <> struct QConcatenable : private QAbstractConcatenable @@ -267,11 +240,6 @@ template <> struct QConcatenable : private QAbstractConcatenable memcpy(out, reinterpret_cast(a.constData()), sizeof(QChar) * n); out += n; } -#ifndef QT_NO_CAST_TO_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const QStringRef &a, char *&out) - { convertToAscii(a.constData(), a.length(), out); } -#endif - }; template struct QConcatenable : private QAbstractConcatenable -- cgit v1.2.3 From eec25d44e43e80d200f4bfaa7b78e094e6a01df6 Mon Sep 17 00:00:00 2001 From: Rick Stockton Date: Thu, 16 Feb 2012 19:20:35 -0800 Subject: Suppport up to 27 mouse buttons from DirectFB Plugin. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous to this update, our plugin accepts only 3 moue buttons (from DirectFB, to be translated into Qt::MouseButton values.) This update changes our Plugin, so that it will successfully translate up to 27 mouse button numbers. It is unclear, to the author, which configurations of DirectFB on Linux might be capable of actually sending high-numbered mouse button Events to Qt. But, if/when a DirectFB configuration does so, this change makes Qt ready to recognize and work with the button event. Task-number: QTBUG-24335 Change-Id: I8839ed386eb3d261a187355a244e80d511399ea8 Reviewed-by: Samuel Rødal --- .../platforms/directfb/qdirectfbconvenience.cpp | 62 ++++++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/directfb/qdirectfbconvenience.cpp b/src/plugins/platforms/directfb/qdirectfbconvenience.cpp index 7b253b7220..e41a2e0440 100644 --- a/src/plugins/platforms/directfb/qdirectfbconvenience.cpp +++ b/src/plugins/platforms/directfb/qdirectfbconvenience.cpp @@ -128,13 +128,65 @@ IDirectFBSurface *QDirectFbConvenience::dfbSurfaceForPlatformPixmap(QPlatformPix Qt::MouseButton QDirectFbConvenience::mouseButton(DFBInputDeviceButtonIdentifier identifier) { - switch (identifier){ - case DIBI_LEFT: + // The Enum contains values for DIBI_FIRST (= DIBI_LEFT), DIBI_LAST (= 0x1f,) and + // just 3 enumerated Mouse Buttons. To convert into *ALL* possible Qt::MoueButton values, + // the parameter is cast as integer. + + switch (int(identifier)) { + case DIBI_LEFT: // value is 0x00 return Qt::LeftButton; - case DIBI_MIDDLE: - return Qt::MidButton; - case DIBI_RIGHT: + case DIBI_RIGHT: // value is 0x01 return Qt::RightButton; + case DIBI_MIDDLE: // value is 0x02 + return Qt::MidButton; + case 0x03: + return Qt::BackButton; + case 0x04: + return Qt::ForwardButton; + case 0x05: + return Qt::ExtraButton3; + case 0x06: + return Qt::ExtraButton4; + case 0x07: + return Qt::ExtraButton5; + case 0x08: + return Qt::ExtraButton6; + case 0x09: + return Qt::ExtraButton7; + case 0x0a: + return Qt::ExtraButton8; + case 0x0b: + return Qt::ExtraButton9; + case 0x0c: + return Qt::ExtraButton10; + case 0x0d: + return Qt::ExtraButton11; + case 0x0e: + return Qt::ExtraButton12; + case 0x0f: + return Qt::ExtraButton13; + case 0x10: + return Qt::ExtraButton14; + case 0x11: + return Qt::ExtraButton15; + case 0x12: + return Qt::ExtraButton16; + case 0x13: + return Qt::ExtraButton17; + case 0x14: + return Qt::ExtraButton18; + case 0x15: + return Qt::ExtraButton19; + case 0x16: + return Qt::ExtraButton20; + case 0x17: + return Qt::ExtraButton21; + case 0x18: + return Qt::ExtraButton22; + case 0x19: + return Qt::ExtraButton23; + case 0x1a: + return Qt::ExtraButton24; default: return Qt::NoButton; } -- cgit v1.2.3 From 5942556d65924f07750c4e1e96a7a9e908e77d11 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 23 Feb 2012 01:05:46 +0100 Subject: Use the CMake definition of Windows for CMake macros. Change-Id: I599ddaaf9176f76f2e144c893e607757957dfef2 Reviewed-by: Clinton Stimpson Reviewed-by: Stephen Kelly --- src/corelib/Qt5CoreMacros.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/Qt5CoreMacros.cmake b/src/corelib/Qt5CoreMacros.cmake index abfe49ec84..4a10fad9eb 100644 --- a/src/corelib/Qt5CoreMacros.cmake +++ b/src/corelib/Qt5CoreMacros.cmake @@ -83,7 +83,7 @@ macro(QT5_GET_MOC_FLAGS _moc_flags) set(${_moc_flags} ${${_moc_flags}} "-D${_current}") endforeach() - if(Q_WS_WIN) + if(WIN32) set(${_moc_flags} ${${_moc_flags}} -DWIN32) endif() endmacro() -- cgit v1.2.3 From 8bf009e2162ec1a8fd7a6756c10f85e1236cfc15 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 22 Feb 2012 13:28:44 +0100 Subject: Silence coverity warning about sizeof(Node*) vs sizeof(Node) in QList Coverity was complaining about QList::node_copy using sizeof(Node *) instead of sizeof(Node). The complete message from Coverity is: "Passing argument "from" of type "struct QList::Node *" and argument "(to - from) * sizeof (struct QList::Node *) /*4*/" to function "memcpy" is suspicious. Did you intend to use "sizeof(struct QList::Node)" instead of "sizeof (struct QList::Node *)" ? In this particular case sizeof(struct QList::Node *) happens to be equal to sizeof(struct QList::Node), but this is not a portable assumption." Task-number: QTBUG-24443 Change-Id: I583887a8b4177a224664065e14f8780a9586c9a3 Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 8f36e5c2ae..bf6933732c 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -402,7 +402,7 @@ Q_INLINE_TEMPLATE void QList::node_copy(Node *from, Node *to, Node *src) } } else { if (src != from && to - from > 0) - memcpy(from, src, (to - from) * sizeof(Node *)); + memcpy(from, src, (to - from) * sizeof(Node)); } } -- cgit v1.2.3 From 034ac599f6d5b3149b3fe4983c8f539a4d0ffe05 Mon Sep 17 00:00:00 2001 From: Marko Kenttala Date: Tue, 31 Jan 2012 13:19:02 +0200 Subject: Fix height of some Thai characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some Thai characters with two above glyphs were higher than fonts ascent. This caused them to be clipped in for example qtcomponents buttons. Added checking for this and calculation of new lower offset between glyphs if needed. Task-Number: ou1cimx1#898104 Reviewed-by: Lars Knoll Reviewed-by: Sami Merilä Reviewed-by: Pasi Pentikäinen (cherry picked from commit d7c7bf721c93fe7629f725c181b52ad9ca645a7a) Change-Id: Ie4ac69de75f50b68b2ba87353d83098846f319f4 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp b/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp index 0734442fe0..af0ee52e9a 100644 --- a/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp +++ b/src/3rdparty/harfbuzz/src/harfbuzz-shaper.cpp @@ -265,6 +265,34 @@ static inline void positionCluster(HB_ShaperItem *item, int gfrom, int glast) //qreal offsetBase = (size - 4) / 4 + qMin(size, 4) + 1; // qDebug("offset = %f", offsetBase); + // To fix some Thai character heights check for two above glyphs + if (nmarks == 2 && (attributes[gfrom+1].combiningClass == HB_Combining_AboveRight || + attributes[gfrom+1].combiningClass == HB_Combining_AboveLeft || + attributes[gfrom+1].combiningClass == HB_Combining_Above)) + if (attributes[gfrom+2].combiningClass == 23 || + attributes[gfrom+2].combiningClass == 24 || + attributes[gfrom+2].combiningClass == 25 || + attributes[gfrom+2].combiningClass == 27 || + attributes[gfrom+2].combiningClass == 28 || + attributes[gfrom+2].combiningClass == 30 || + attributes[gfrom+2].combiningClass == 31 || + attributes[gfrom+2].combiningClass == 33 || + attributes[gfrom+2].combiningClass == 34 || + attributes[gfrom+2].combiningClass == 35 || + attributes[gfrom+2].combiningClass == 36 || + attributes[gfrom+2].combiningClass == 107 || + attributes[gfrom+2].combiningClass == 122) { + // Two above glyphs, check total height + int markTotalHeight = baseMetrics.height; + HB_GlyphMetrics markMetrics; + item->font->klass->getGlyphMetrics(item->font, glyphs[gfrom+1], &markMetrics); + markTotalHeight += markMetrics.height; + item->font->klass->getGlyphMetrics(item->font, glyphs[gfrom+2], &markMetrics); + markTotalHeight += markMetrics.height; + if ((markTotalHeight + 2 * offsetBase) > (size * 10)) + offsetBase = ((size * 10) - markTotalHeight) / 2; // Use offset that just fits + } + bool rightToLeft = item->item.bidiLevel % 2; int i; -- cgit v1.2.3 From 5b4a44f83d6d3571731fd1029061b1deea27d7b1 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Wed, 8 Feb 2012 10:12:03 +0000 Subject: Harfbuzz-thai - fix to_tis620 function for latin characters This was an obvious typo - a missing "else" in a group of if statements. Reviewed-by: Jiang Jiang Reviewed-by: Adrian Yanes Reviewed-by: Lars Knoll (cherry picked from commit a784bdcabe895ab927cbc28118d427c6e932b9fc) Change-Id: Icbd458034e42cf7f2af33c1ecc9b0e4f1aa8724a Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/3rdparty/harfbuzz/src/harfbuzz-thai.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/3rdparty/harfbuzz/src/harfbuzz-thai.c b/src/3rdparty/harfbuzz/src/harfbuzz-thai.c index deff61be7e..59f5f7d448 100644 --- a/src/3rdparty/harfbuzz/src/harfbuzz-thai.c +++ b/src/3rdparty/harfbuzz/src/harfbuzz-thai.c @@ -74,7 +74,7 @@ static void to_tis620(const HB_UChar16 *string, hb_uint32 len, const char *cstr) for (i = 0; i < len; ++i) { if (string[i] <= 0xa0) result[i] = (unsigned char)string[i]; - if (string[i] >= 0xe01 && string[i] <= 0xe5b) + else if (string[i] >= 0xe01 && string[i] <= 0xe5b) result[i] = (unsigned char)(string[i] - 0xe00 + 0xa0); else result[i] = '?'; -- cgit v1.2.3 From c065ac562af6b13d6e103b0378c44e39a6c715aa Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Wed, 8 Feb 2012 10:12:08 +0000 Subject: Harfbuzz-thai - When calling HB_OpenTypePosition we must set doLogClusters to true for thai This bug resulted in word wrapping not working correctly for thai. Reviewed-by: Adrian Yanes Reviewed-by: Lars Knoll (cherry picked from commit 7495f2c7c55917a98c903547858be923028b7827) Change-Id: Iedb26a10078c6cc4e90d090176ab63499293d69d Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/3rdparty/harfbuzz/src/harfbuzz-thai.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/3rdparty/harfbuzz/src/harfbuzz-thai.c b/src/3rdparty/harfbuzz/src/harfbuzz-thai.c index 59f5f7d448..386fd5c252 100644 --- a/src/3rdparty/harfbuzz/src/harfbuzz-thai.c +++ b/src/3rdparty/harfbuzz/src/harfbuzz-thai.c @@ -353,7 +353,7 @@ HB_Bool HB_ThaiShape (HB_ShaperItem *shaper_item) const int availableGlyphs = shaper_item->num_glyphs; if ( HB_SelectScript (shaper_item, thai_features) ) { HB_OpenTypeShape (shaper_item, /*properties*/0); - return HB_OpenTypePosition (shaper_item, availableGlyphs, /*doLogClusters*/false); + return HB_OpenTypePosition (shaper_item, availableGlyphs, /*doLogClusters*/true); } #endif -- cgit v1.2.3 From 1501f1ddd499320c264dc3ab16d4ce8b408991bb Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Wed, 22 Feb 2012 18:29:51 -0800 Subject: QMenuBar: Clean up Q_WS_WIN - Replace Q_WS_WIN with Q_OS_WIN - Remove useless #ifdef Q_OS_WINCE which located in another #ifdef Q_OS_WINCE Change-Id: I6279b6d74902ab3ca6bdb7292c2936a76e3e6952 Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qmenubar.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index d797a4e315..16e486e77f 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1075,7 +1075,7 @@ void QMenuBar::mousePressEvent(QMouseEvent *e) d->activeMenu = 0; menu->hide(); } -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN if((d->closePopupMode = style()->styleHint(QStyle::SH_MenuBar_DismissOnSecondClick))) update(d->actionRect(action)); #endif @@ -1845,15 +1845,12 @@ void QMenuBar::setDefaultAction(QAction *act) Q_D(QMenuBar); if (d->defaultAction == act) return; -#ifdef Q_OS_WINCE if (qt_wince_is_mobile()) if (d->defaultAction) { disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); disconnect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); } -#endif d->defaultAction = act; -#ifdef Q_OS_WINCE if (qt_wince_is_mobile()) if (d->defaultAction) { connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); @@ -1862,7 +1859,6 @@ void QMenuBar::setDefaultAction(QAction *act) if (d->wce_menubar) { d->wce_menubar->rebuild(); } -#endif } /*! -- cgit v1.2.3 From ef9a86db5615a438c72a78745a8e558e687bf829 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 23 Feb 2012 15:02:23 +1000 Subject: Fix rounding error in QInputMethod::cursorRectangle(). Use QRectF consistently to avoid the rounding done in the conversion to QRect. Task-number: QTBUG-24463 Change-Id: If9ea858ebabf8c449ea058b9d379d4a57cb6c82d Reviewed-by: Joona Petrell --- src/gui/kernel/qinputmethod.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qinputmethod.cpp b/src/gui/kernel/qinputmethod.cpp index de00396e40..9e724446ff 100644 --- a/src/gui/kernel/qinputmethod.cpp +++ b/src/gui/kernel/qinputmethod.cpp @@ -154,9 +154,9 @@ QRectF QInputMethod::cursorRectangle() const QInputMethodQueryEvent query(Qt::ImCursorRectangle); QGuiApplication::sendEvent(d->inputItem.data(), &query); - QRect r = query.value(Qt::ImCursorRectangle).toRect(); + QRectF r = query.value(Qt::ImCursorRectangle).toRectF(); if (!r.isValid()) - return QRect(); + return QRectF(); return d->inputItemTransform.mapRect(r); } -- cgit v1.2.3 From d2f65aa470fe30849a01380e4a50e8a4ebbce07e Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Sun, 25 Dec 2011 00:47:41 +0800 Subject: Fix conflict between QMainWindow::restoreState() and QWidget::setStylesheet() If QMainWindow::restoreState() then QWidget::setStylesheet() were called before the QMainWindow is shown, the size of QDockWidget can not be restored. QWidget::setStylesheet() will generate QEvent::StyleChange event, which will cause the function QDockAreaLayout::fitLayout() to be called before the layout of MainWindow is activated. Although the state info has been stored in a QMainWindowLayoutState variable by QMainWindow::restoreState(), but QMainWindowLayout::setGeometry() still isn't called at present. So QDockAreaLayout::fitLayout() will force the size of dockwidgets and centralwidget to be calculated using the wrong geometry, which will break the state restored by QMainWindow::restoreState(). This is a side effect of 692e9103ebb85b90e79377206d5d03b704d43d42. Task-number: QTBUG-15080 Change-Id: I8cda6a529d178f7467a59b780db80df0a44d4769 Reviewed-by: Olivier Goffart --- src/widgets/widgets/qdockarealayout.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index df083ccbfe..a07ab73ad0 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -3321,7 +3321,8 @@ void QDockAreaLayout::keepSize(QDockWidget *w) void QDockAreaLayout::styleChangedEvent() { sep = mainWindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainWindow); - fitLayout(); + if (isValid()) + fitLayout(); } QT_END_NAMESPACE -- cgit v1.2.3 From a6e20e4874d3f46f311625e471f1b7fbc64964b2 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 21 Feb 2012 14:45:07 +0100 Subject: Handle theme change in QApplication/QGuiApplication. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-initialize palette and fonts. Change-Id: Ib312747886a31e8370f8d99536d52cbcf8afe8a4 Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qguiapplication.cpp | 70 ++++++++++++++++++++----- src/gui/kernel/qguiapplication_p.h | 3 ++ src/plugins/platforms/windows/qwindowstheme.cpp | 5 +- src/widgets/kernel/qapplication.cpp | 33 +++++++++--- src/widgets/kernel/qapplication_p.h | 4 +- 5 files changed, 93 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 4b309096c9..2e7441d62c 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -99,6 +99,14 @@ QPlatformTheme *QGuiApplicationPrivate::platform_theme = 0; QList QGuiApplicationPrivate::generic_plugin_list; +enum ApplicationResourceFlags +{ + ApplicationPaletteExplicitlySet = 0x1, + ApplicationFontExplicitlySet = 0x2 +}; + +static unsigned applicationResourceFlags = 0; + bool QGuiApplicationPrivate::app_do_modal = false; QPalette *QGuiApplicationPrivate::app_pal = 0; // default application palette @@ -144,6 +152,33 @@ static bool qt_detectRTLLanguage() " and Arabic) to get proper widget layout.") == QLatin1String("RTL")); } +static void initPalette() +{ + if (!QGuiApplicationPrivate::app_pal) + if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette()) + QGuiApplicationPrivate::app_pal = new QPalette(*themePalette); + if (!QGuiApplicationPrivate::app_pal) + QGuiApplicationPrivate::app_pal = new QPalette(Qt::black); +} + +static inline void clearPalette() +{ + delete QGuiApplicationPrivate::app_pal; + QGuiApplicationPrivate::app_pal = 0; +} + +static void initFontUnlocked() +{ + if (!QGuiApplicationPrivate::app_font) + QGuiApplicationPrivate::app_font = + new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont()); +} + +static inline void clearFontUnlocked() +{ + delete QGuiApplicationPrivate::app_font; + QGuiApplicationPrivate::app_font = 0; +} /*! \class QGuiApplication @@ -312,8 +347,7 @@ QGuiApplication::~QGuiApplication() delete QGuiApplicationPrivate::qt_clipboard; QGuiApplicationPrivate::qt_clipboard = 0; - delete QGuiApplicationPrivate::app_pal; - QGuiApplicationPrivate::app_pal = 0; + clearPalette(); qUnregisterGuiVariant(); @@ -671,8 +705,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate() delete generic_plugin_list.at(i); generic_plugin_list.clear(); - delete app_font; - app_font = 0; + clearFontUnlocked(); + QFont::cleanup(); #ifndef QT_NO_CURSOR @@ -1090,6 +1124,8 @@ void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfa void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce) { + if (self) + self->notifyThemeChanged(); if (QWindow *window = tce->window.data()) { QEvent e(QEvent::ThemeChange); QGuiApplication::sendSpontaneousEvent(window, &e); @@ -1579,13 +1615,10 @@ QClipboard * QGuiApplication::clipboard() \sa setPalette() */ + QPalette QGuiApplication::palette() { - if (!QGuiApplicationPrivate::app_pal) - if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette()) - QGuiApplicationPrivate::app_pal = new QPalette(*themePalette); - if (!QGuiApplicationPrivate::app_pal) - QGuiApplicationPrivate::app_pal = new QPalette(Qt::black); + initPalette(); return *QGuiApplicationPrivate::app_pal; } @@ -1602,6 +1635,7 @@ void QGuiApplication::setPalette(const QPalette &pal) QGuiApplicationPrivate::app_pal = new QPalette(pal); else *QGuiApplicationPrivate::app_pal = pal; + applicationResourceFlags |= ApplicationPaletteExplicitlySet; } /*! @@ -1612,9 +1646,7 @@ void QGuiApplication::setPalette(const QPalette &pal) QFont QGuiApplication::font() { QMutexLocker locker(&applicationFontMutex); - if (!QGuiApplicationPrivate::app_font) - QGuiApplicationPrivate::app_font = - new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont()); + initFontUnlocked(); return *QGuiApplicationPrivate::app_font; } @@ -1630,6 +1662,7 @@ void QGuiApplication::setFont(const QFont &font) QGuiApplicationPrivate::app_font = new QFont(font); else *QGuiApplicationPrivate::app_font = font; + applicationResourceFlags |= ApplicationFontExplicitlySet; } /*! @@ -2034,4 +2067,17 @@ QPixmap QGuiApplicationPrivate::getPixmapCursor(Qt::CursorShape cshape) return QPixmap(); } +void QGuiApplicationPrivate::notifyThemeChanged() +{ + if (!(applicationResourceFlags & ApplicationPaletteExplicitlySet)) { + clearPalette(); + initPalette(); + } + if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) { + QMutexLocker locker(&applicationFontMutex); + clearFontUnlocked(); + initFontUnlocked(); + } +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 66670e8e25..68546ce0cf 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -200,6 +200,9 @@ public: }; QHash synthesizedMousePoints; +protected: + virtual void notifyThemeChanged(); + private: void init(); diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 7276db4bb6..5350b3ca3f 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -52,6 +52,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -265,10 +266,10 @@ QPlatformDialogHelper *QWindowsTheme::createPlatformDialogHelper(DialogType type return QWindowsDialogs::createHelper(type); } -void QWindowsTheme::windowsThemeChanged(QWindow * /* window */) +void QWindowsTheme::windowsThemeChanged(QWindow * window) { refresh(); - // QWindowSystemInterface::handleThemeChange(window); + QWindowSystemInterface::handleThemeChange(window); } QT_END_NAMESPACE diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 134b1809bb..650d4af38b 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -128,6 +128,21 @@ Q_CORE_EXPORT void qt_call_post_routines(); QApplicationPrivate *QApplicationPrivate::self = 0; +static void initSystemPalette() +{ + if (!QApplicationPrivate::sys_pal) + if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette()) + QApplicationPrivate::setSystemPalette(*themePalette); + if (!QApplicationPrivate::sys_pal && QApplicationPrivate::app_style) + QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette()); +} + +static void clearSystemPalette() +{ + delete QApplicationPrivate::sys_pal; + QApplicationPrivate::sys_pal = 0; +} + #ifdef Q_OS_WINCE int QApplicationPrivate::autoMaximizeThreshold = -1; bool QApplicationPrivate::autoSipEnabled = false; @@ -365,6 +380,7 @@ QString QApplicationPrivate::styleSheet; // default application styles QPointer QApplicationPrivate::leaveAfterRelease = 0; int QApplicationPrivate::app_cspec = QApplication::NormalColor; + QPalette *QApplicationPrivate::sys_pal = 0; // default system palette QPalette *QApplicationPrivate::set_pal = 0; // default palette set by programmer @@ -783,8 +799,7 @@ QApplication::~QApplication() delete QApplicationPrivate::app_pal; QApplicationPrivate::app_pal = 0; - delete QApplicationPrivate::sys_pal; - QApplicationPrivate::sys_pal = 0; + clearSystemPalette(); delete QApplicationPrivate::set_pal; QApplicationPrivate::set_pal = 0; app_palettes()->clear(); @@ -1084,11 +1099,8 @@ QStyle *QApplication::style() // take ownership of the style QApplicationPrivate::app_style->setParent(qApp); - if (!QApplicationPrivate::sys_pal) - if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette()) - QApplicationPrivate::setSystemPalette(*themePalette); - if (!QApplicationPrivate::sys_pal) - QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette()); + initSystemPalette(); + if (QApplicationPrivate::set_pal) // repolish set palette with the new style QApplication::setPalette(*QApplicationPrivate::set_pal); @@ -4631,6 +4643,13 @@ void QApplicationPrivate::translateTouchCancel(QTouchDevice *device, ulong times } } +void QApplicationPrivate::notifyThemeChanged() +{ + QGuiApplicationPrivate::notifyThemeChanged(); + clearSystemPalette(); + initSystemPalette(); +} + #ifndef QT_NO_GESTURES QGestureManager* QGestureManager::instance() { diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index e728868182..7a880986bf 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -260,7 +260,9 @@ public: static QPalette *sys_pal; static QPalette *set_pal; -private: +protected: + void notifyThemeChanged(); + public: static QFont *sys_font; static QFont *set_font; -- cgit v1.2.3 From 04652b9856f70c5d38eefd4907a02bd929059705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 21 Feb 2012 13:40:57 +0100 Subject: Added documentation for QSurfaceFormat. Change-Id: I3b42b09e6e42092c098e4fc20c5ba7dd7e354116 Reviewed-by: Gunnar Sletta --- src/gui/kernel/qsurfaceformat.cpp | 151 ++++++++++++++++++++++++++++++++++---- 1 file changed, 136 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qsurfaceformat.cpp b/src/gui/kernel/qsurfaceformat.cpp index b97852dc1d..9021d82e20 100644 --- a/src/gui/kernel/qsurfaceformat.cpp +++ b/src/gui/kernel/qsurfaceformat.cpp @@ -106,10 +106,86 @@ public: int minor; }; +/*! + \class QSurfaceFormat + \brief The QSurfaceFormat class represents the format of a QSurface. + + The format includes the size of the color buffers, red, green, and blue; + the size of the alpha buffer; the size of the depth and stencil buffers; + and number of samples per pixel for multisampling. In addition, the format + contains surface configuration parameters such as OpenGL profile and + version for rendering, whether or not enable stereo buffers, and swap + behaviour. +*/ + +/*! + \enum QSurfaceFormat::FormatOption + + This enum contains format options for use with QSurfaceFormat. + + \value StereoBuffers Used to request stereo buffers in the surface format. + \value DebugContext Used to request a debug context with extra debugging information. + This requires OpenGL version 3.0 or higher. + \value DeprecatedFunctions Used to request that deprecated functions be included + in the OpenGL context profile. If not specified, you should get a forward compatible context + without support functionality marked as deprecated. This requires OpenGL version 3.0 or higher. +*/ + +/*! + \enum QSurfaceFormat::SwapBehavior + + This enum is used by QSurfaceFormat to specify the swap behaviour of a surface. The swap behaviour + is mostly transparent to the application, but it affects factors such as rendering latency and + throughput. + + \value DefaultSwapBehavior The default, unspecified swap behaviour of the platform. + \value SingleBuffer Used to request single buffering, which might result in flickering + when OpenGL rendering is done directly to screen without an intermediate offscreen + buffer. + \value DoubleBuffer This is typically the default swap behaviour on desktop platforms, + consisting of one back buffer and one front buffer. Rendering is done to the back + buffer, and then the back buffer and front buffer are swapped, or the contents of + the back buffer are copied to the front buffer, depending on the implementation. + \value TripleBuffer This swap behaviour is sometimes used in order to decrease the + risk of skipping a frame when the rendering rate is just barely keeping up with + the screen refresh rate. Depending on the platform it might also lead to slightly + more efficient use of the GPU due to improved pipelining behaviour. Triple buffering + comes at the cost of an extra frame of memory usage and latency, and might not be + supported depending on the underlying platform. +*/ + +/*! + \enum QSurfaceFormat::OpenGLContextProfile + + This enum is used to specify the OpenGL context profile, in + conjunction with QSurfaceFormat::setMajorVersion() and + QSurfaceFormat::setMinorVersion(). + + Profiles are exposed in OpenGL 3.2 and above, and are used + to choose between a restricted core profile, and a compatibility + profile which might contain deprecated support functionality. + + Note that the core profile might still contain functionality that + is deprecated and scheduled for removal in a higher version. To + get access to the deprecated functionality for the core profile + in the set OpenGL version you can use the QSurfaceFormat format option + QSurfaceFormat::DeprecatedFunctions. + + \value NoProfile OpenGL version is lower than 3.2. + \value CoreProfile Functionality deprecated in OpenGL version 3.0 is not available. + \value CompatibilityProfile Functionality from earlier OpenGL versions is available. +*/ + +/*! + Constructs a default initialized QSurfaceFormat. +*/ QSurfaceFormat::QSurfaceFormat() : d(new QSurfaceFormatPrivate) { } +/*! + Constructs a QSurfaceFormat with the given format \a options. +*/ QSurfaceFormat::QSurfaceFormat(QSurfaceFormat::FormatOptions options) : d(new QSurfaceFormatPrivate(options)) { @@ -131,7 +207,6 @@ void QSurfaceFormat::detach() /*! Constructs a copy of \a other. */ - QSurfaceFormat::QSurfaceFormat(const QSurfaceFormat &other) { d = other.d; @@ -141,7 +216,6 @@ QSurfaceFormat::QSurfaceFormat(const QSurfaceFormat &other) /*! Assigns \a other to this object. */ - QSurfaceFormat &QSurfaceFormat::operator=(const QSurfaceFormat &other) { if (d != other.d) { @@ -182,7 +256,6 @@ QSurfaceFormat::~QSurfaceFormat() \sa stereo() */ - void QSurfaceFormat::setStereo(bool enable) { QSurfaceFormat::FormatOptions newOptions = d->opts; @@ -199,8 +272,7 @@ void QSurfaceFormat::setStereo(bool enable) /*! Returns the number of samples per pixel when multisampling is - enabled. By default, the highest number of samples that is - available is used. + enabled. By default, multisampling is disabled. \sa setSampleBuffers(), sampleBuffers(), setSamples() */ @@ -211,8 +283,7 @@ int QSurfaceFormat::samples() const /*! Set the preferred number of samples per pixel when multisampling - is enabled to \a numSamples. By default, the highest number of - samples available is used. + is enabled to \a numSamples. By default, multisampling is disabled. \sa setSampleBuffers(), sampleBuffers(), samples() */ @@ -229,7 +300,6 @@ void QSurfaceFormat::setSamples(int numSamples) \sa testOption() */ - void QSurfaceFormat::setOption(QSurfaceFormat::FormatOptions opt) { const QSurfaceFormat::FormatOptions newOptions = d->opts | opt; @@ -244,7 +314,6 @@ void QSurfaceFormat::setOption(QSurfaceFormat::FormatOptions opt) \sa setOption() */ - bool QSurfaceFormat::testOption(QSurfaceFormat::FormatOptions opt) const { return d->opts & opt; @@ -273,6 +342,13 @@ int QSurfaceFormat::depthBufferSize() const return d->depthSize; } +/*! + Set the swap behaviour of the surface. + + The swap behaviour specifies whether single, double, or triple + buffering is desired. The default, SwapBehavior::DefaultSwapBehavior, + gives the default swap behavior of the platform. +*/ void QSurfaceFormat::setSwapBehavior(SwapBehavior behavior) { if (d->swapBehavior != behavior) { @@ -281,19 +357,29 @@ void QSurfaceFormat::setSwapBehavior(SwapBehavior behavior) } } +/*! + Returns the configured swap behaviour. + \sa setSwapBehavior() +*/ QSurfaceFormat::SwapBehavior QSurfaceFormat::swapBehavior() const { return d->swapBehavior; } +/*! + Returns true if the alpha buffer size is greater than zero. + + This means that the surface might be used with per pixel + translucency effects. +*/ bool QSurfaceFormat::hasAlpha() const { return d->alphaBufferSize > 0; } /*! - Set the preferred stencil buffer size to \a size. + Set the preferred stencil buffer size to \a size bits. \sa stencilBufferSize(), setStencil(), stencil() */ @@ -306,7 +392,7 @@ void QSurfaceFormat::setStencilBufferSize(int size) } /*! - Returns the stencil buffer size. + Returns the stencil buffer size in bits. \sa stencil(), setStencil(), setStencilBufferSize() */ @@ -315,26 +401,41 @@ int QSurfaceFormat::stencilBufferSize() const return d->stencilSize; } +/*! + Get the size in bits of the red channel of the color buffer. +*/ int QSurfaceFormat::redBufferSize() const { return d->redBufferSize; } +/*! + Get the size in bits of the green channel of the color buffer. +*/ int QSurfaceFormat::greenBufferSize() const { return d->greenBufferSize; } +/*! + Get the size in bits of the blue channel of the color buffer. +*/ int QSurfaceFormat::blueBufferSize() const { return d->blueBufferSize; } +/*! + Get the size in bits of the alpha channel of the color buffer. +*/ int QSurfaceFormat::alphaBufferSize() const { return d->alphaBufferSize; } +/*! + Set the desired size in bits of the red channel of the color buffer. +*/ void QSurfaceFormat::setRedBufferSize(int size) { if (d->redBufferSize != size) { @@ -343,6 +444,9 @@ void QSurfaceFormat::setRedBufferSize(int size) } } +/*! + Set the desired size in bits of the green channel of the color buffer. +*/ void QSurfaceFormat::setGreenBufferSize(int size) { if (d->greenBufferSize != size) { @@ -351,6 +455,9 @@ void QSurfaceFormat::setGreenBufferSize(int size) } } +/*! + Set the desired size in bits of the blue channel of the color buffer. +*/ void QSurfaceFormat::setBlueBufferSize(int size) { if (d->blueBufferSize != size) { @@ -359,6 +466,9 @@ void QSurfaceFormat::setBlueBufferSize(int size) } } +/*! + Set the desired size in bits of the alpha channel of the color buffer. +*/ void QSurfaceFormat::setAlphaBufferSize(int size) { if (d->alphaBufferSize != size) { @@ -368,10 +478,10 @@ void QSurfaceFormat::setAlphaBufferSize(int size) } /*! - Sets the desired OpenGL context profile. + Sets the desired OpenGL context profile. - This setting is ignored if the requested OpenGL version is - less than 3.2. + This setting is ignored if the requested OpenGL version is + less than 3.2. */ void QSurfaceFormat::setProfile(OpenGLContextProfile profile) { @@ -381,6 +491,12 @@ void QSurfaceFormat::setProfile(OpenGLContextProfile profile) } } +/*! + Get the configured OpenGL context profile. + + This setting is ignored if the requested OpenGL version is + less than 3.2. +*/ QSurfaceFormat::OpenGLContextProfile QSurfaceFormat::profile() const { return d->profile; @@ -428,6 +544,12 @@ int QSurfaceFormat::minorVersion() const return d->minor; } +/*! + Returns true if all the options of the two QSurfaceFormat objects + are equal. + + \relates QSurfaceFormat +*/ bool operator==(const QSurfaceFormat& a, const QSurfaceFormat& b) { return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts @@ -450,7 +572,6 @@ bool operator==(const QSurfaceFormat& a, const QSurfaceFormat& b) \relates QSurfaceFormat */ - bool operator!=(const QSurfaceFormat& a, const QSurfaceFormat& b) { return !(a == b); -- cgit v1.2.3 From 88b69ab0c482183afa4e1575d666185bbd631890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 21 Feb 2012 10:44:33 +0100 Subject: Fleshed out the QWindow documentation to be less sparse. Change-Id: Ia3873687a2c3e0dd85c56e4f9e34d2e194e2ff50 Reviewed-by: Gunnar Sletta --- src/gui/kernel/qwindow.cpp | 594 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 541 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 9c6b6c4bf7..77731f776b 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -63,15 +63,17 @@ QT_BEGIN_NAMESPACE /*! \class QWindow - \brief The QWindow class encapsulates an independent window in a Windowing System. + \brief The QWindow class represents a window in the underlying windowing system. - A window that is supplied a parent become a native child window of + A window that is supplied a parent becomes a native child window of their parent window. + \section1 Resource management + Windows can potentially use a lot of memory. A usual measurement is - width * height * depth. A window might also include multiple buffers - to support double and triple buffering. To release a windows memory - resources, the destroy() function. + width times height times color depth. A window might also include multiple + buffers to support double and triple buffering, as well as depth and stencil + buffers. To release a window's memory resources, the destroy() function. \section1 Window and content orientation @@ -90,6 +92,29 @@ QT_BEGIN_NAMESPACE the contents instead, especially when doing rotation animations between different orientations. The windowing system might use this value to determine the layout of system popups or dialogs. + + \section1 Visibility and Windowing system exposure. + + By default, the window is not visible, and you must call setVisible(true), + or show() or similar to make it visible. To make a window hidden again, + call setVisible(false) or hide(). The visible property describes the state + the application wants the window to be in. Depending on the underlying + system, a visible window might still not be shown on the screen. It could, + for instance, be covered by other opaque windows or moved outside the + physical area of the screen. On windowing systems that have exposure + notifications, the isExposed() accessor describes whether the window should + be treated as directly visible on screen. The exposeEvent() function is + called whenever the windows exposure in the windowing system changes. On + windowing systems that do not make this information visible to the + application, isExposed() will simply return the same value as isVisible(). +*/ + +/*! + Creates a window as a top level on the given screen. + + The window is not shown until setVisible(true), show(), or similar is called. + + \sa setScreen() */ QWindow::QWindow(QScreen *targetScreen) : QObject(*new QWindowPrivate(), 0) @@ -108,6 +133,15 @@ QWindow::QWindow(QScreen *targetScreen) QGuiApplicationPrivate::window_list.prepend(this); } +/*! + Creates a window as a child of the given \a parent window. + + The window will be embedded inside the parent window, its coordinates relative to the parent. + + The screen is inherited from the parent. + + \sa setParent() +*/ QWindow::QWindow(QWindow *parent) : QObject(*new QWindowPrivate(), parent) , QSurface(QSurface::Window) @@ -134,6 +168,9 @@ QWindow::QWindow(QWindowPrivate &dd, QWindow *parent) QGuiApplicationPrivate::window_list.prepend(this); } +/*! + Destroys the window. +*/ QWindow::~QWindow() { if (QGuiApplicationPrivate::focus_window == this) @@ -146,18 +183,43 @@ QSurface::~QSurface() { } +/*! + Set the \a surfaceType of the window. + + Specifies whether the window is meant for raster rendering with + QBackingStore, or OpenGL rendering with QOpenGLContext. + + \sa QBackingStore, QOpenGLContext +*/ void QWindow::setSurfaceType(SurfaceType surfaceType) { Q_D(QWindow); d->surfaceType = surfaceType; } +/*! + Returns the surface type of the window. + + \sa setSurfaceType() +*/ QWindow::SurfaceType QWindow::surfaceType() const { Q_D(const QWindow); return d->surfaceType; } +/*! + \property QWindow::visible + \brief whether the window is visible or not + \since 5.0 + + This property controls the visibility of the window in the windowing system. + + By default, the window is not visible, you must call setVisible(true), or + show() or similar to make it visible. + + \sa show() +*/ void QWindow::setVisible(bool visible) { Q_D(QWindow); @@ -186,7 +248,10 @@ void QWindow::setVisible(bool visible) } } - +/*! + Returns true if the window is set to visible. + \obsolete +*/ bool QWindow::visible() const { return isVisible(); @@ -199,6 +264,20 @@ bool QWindow::isVisible() const return d->visible; } +/*! + Allocates the platform resources associated with the window. + + It is at this point that the surface format set using setFormat() gets resolved + into an actual native surface. However, the window remains hidden until setVisible() is called. + + Note that it is not usually necessary to call this function directly, as it will be implicitly + called by show(), setVisible(), and other functions that require access to the platform + resources. + + Call destroy() to free the platform resources if necessary. + + \sa destroy() +*/ void QWindow::create() { Q_D(QWindow); @@ -216,6 +295,14 @@ void QWindow::create() } } +/*! + Returns the window's platform id. + + For platforms where this id might be useful, the value returned + will uniquely represent the window inside the corresponding screen. + + \sa screen() +*/ WId QWindow::winId() const { Q_D(const QWindow); @@ -228,16 +315,22 @@ WId QWindow::winId() const return id; } +/*! + Returns the parent window, if any. + + A window without a parent is known as a top level window. +*/ QWindow *QWindow::parent() const { Q_D(const QWindow); return d->parentWindow; } -/** - Sets the parent Window. This will lead to the windowing system managing the clip of the window, so it will be clipped to the parent window. - Setting parent to be 0(NULL) means map it as a top level window. If the parent window has grabbed its window system resources, then the current window will also grab its window system resources. - **/ +/*! + Sets the parent Window. This will lead to the windowing system managing the clip of the window, so it will be clipped to the parent window. + + Setting parent to be 0 will make the window become a top level window. +*/ void QWindow::setParent(QWindow *parent) { @@ -257,46 +350,66 @@ void QWindow::setParent(QWindow *parent) } /*! - Returns whether the window is top level, i.e. has no parent window. - */ + Returns whether the window is top level, i.e. has no parent window. +*/ bool QWindow::isTopLevel() const { Q_D(const QWindow); return d->parentWindow == 0; } +/*! + Returns whether the window is modal. + + A modal window prevents other windows from getting any input. +*/ bool QWindow::isModal() const { Q_D(const QWindow); return d->modality != Qt::NonModal; } +/*! + Returns the window's modality. + + \sa setWindowModality() +*/ Qt::WindowModality QWindow::windowModality() const { Q_D(const QWindow); return d->modality; } +/*! + Sets the window's modality to \a windowModality. +*/ void QWindow::setWindowModality(Qt::WindowModality windowModality) { Q_D(QWindow); d->modality = windowModality; } +/*! + Sets the window's surface \a format. + + The format determines properties such as color depth, alpha, + depth and stencil buffer size, etc. +*/ void QWindow::setFormat(const QSurfaceFormat &format) { Q_D(QWindow); d->requestedFormat = format; } - /*! Returns the requested surfaceformat of this window. If the requested format was not supported by the platform implementation, the requestedFormat will differ from the actual window format. - \sa format. + This is the value set with setFormat(). + + \sa setFormat(), format() */ QSurfaceFormat QWindow::requestedFormat() const { @@ -304,6 +417,15 @@ QSurfaceFormat QWindow::requestedFormat() const return d->requestedFormat; } +/*! + Returns the actual format of this window. + + After the window has been created, this function will return the actual surface format + of the window. It might differ from the requested format if the requested format could + not be fulfilled by the platform. + + \sa create(), requestedFormat() +*/ QSurfaceFormat QWindow::format() const { Q_D(const QWindow); @@ -312,6 +434,15 @@ QSurfaceFormat QWindow::format() const return d->requestedFormat; } +/*! + Sets the window flags of the window to \a flags. + + The window flags control the window's appearance in the windowing system, + whether it's a dialog, popup, or a regular window, and whether it should + have a title bar, etc. + + \sa windowFlags() +*/ void QWindow::setWindowFlags(Qt::WindowFlags flags) { Q_D(QWindow); @@ -321,18 +452,46 @@ void QWindow::setWindowFlags(Qt::WindowFlags flags) d->windowFlags = flags; } +/*! + Returns the window flags of the window. + + This might differ from the flags set with setWindowFlags() if the + requested flags could not be fulfilled. + + \sa setWindowFlags() +*/ Qt::WindowFlags QWindow::windowFlags() const { Q_D(const QWindow); return d->windowFlags; } +/*! + Returns the type of the window. + + This returns the part of the window flags that represents + whether the window is a dialog, tooltip, popup, regular window, etc. + + \sa windowFlags(), setWindowFlags() +*/ Qt::WindowType QWindow::windowType() const { Q_D(const QWindow); return static_cast(int(d->windowFlags & Qt::WindowType_Mask)); } +/*! + \property QWindow::windowTitle + \brief the window's title in the windowing system + \since 5.0 + + The window title might appear in the title area of the window decorations, + depending on the windowing system and the window flags. It might also + be used by the windowing system to identify the window in other contexts, + such as in the task switcher. + + \sa windowFlags() +*/ void QWindow::setWindowTitle(const QString &title) { Q_D(QWindow); @@ -348,6 +507,11 @@ QString QWindow::windowTitle() const return d->windowTitle; } +/*! + Raise the window in the windowing system. + + Requests that the window be raised to appear above other windows. +*/ void QWindow::raise() { Q_D(QWindow); @@ -356,6 +520,11 @@ void QWindow::raise() } } +/*! + Lower the window in the windowing system. + + Requests that the window be lowered to appear below other windows. +*/ void QWindow::lower() { Q_D(QWindow); @@ -364,6 +533,16 @@ void QWindow::lower() } } +/*! + Sets the window's opacity in the windowing system to \a level. + + If the windowing system supports window opacity, this can be used to fade the + window in and out, or to make it semitransparent. + + A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below + is treated as fully transparent. Values inbetween represent varying levels of + translucency between the two extremes. +*/ void QWindow::setOpacity(qreal level) { Q_D(QWindow); @@ -372,6 +551,11 @@ void QWindow::setOpacity(qreal level) } } +/*! + Requests the window to be activated, i.e. receive keyboard focus. + + \sa isActive(), QGuiApplication::focusWindow() +*/ void QWindow::requestActivateWindow() { Q_D(QWindow); @@ -379,7 +563,6 @@ void QWindow::requestActivateWindow() d->platformWindow->requestActivateWindow(); } - /*! Returns if this window is exposed in the windowing system. @@ -388,8 +571,9 @@ void QWindow::requestActivateWindow() should minimize rendering and other graphical activities. An exposeEvent() is sent every time this value changes. - */ + \sa exposeEvent() +*/ bool QWindow::isExposed() const { Q_D(const QWindow); @@ -424,22 +608,26 @@ bool QWindow::isActive() const } /*! - Reports that the orientation of the window's contents have changed. + \property QWindow::contentOrientation + \since 5.0 + \brief the orientation of the window's contents + + This is a hint to the window manager in case it needs to display + additional content like popups, dialogs, status bars, or similar + in relation to the window. - This is a hint to the window manager in case it needs to display - additional content like popups, dialogs, status bars, or similar - in relation to the window. + The recommended orientation is QScreen::orientation() but + an application doesn't have to support all possible orientations, + and thus can opt to ignore the current screen orientation. - The recommended orientation is QScreen::orientation() but - an application doesn't have to support all possible orientations, - and thus can opt to ignore the current screen orientation. + The difference between the window and the content orientation + determines how much to rotate the content by. QScreen::angleBetween(), + QScreen::transformBetween(), and QScreen::mapBetween() can be used + to compute the necessary transform. - The difference between the window and the content orientation - determines how much to rotate the content by. QScreen::angleBetween(), - QScreen::transformBetween(), and QScreen::mapBetween() can be used - to compute the necessary transform. + The default value is Qt::PrimaryOrientation - \sa requestWindowOrientation(), QScreen::orientation() + \sa requestWindowOrientation(), QScreen::orientation() */ void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation) { @@ -454,12 +642,6 @@ void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation) emit contentOrientationChanged(orientation); } -/*! - Returns the actual content orientation. - - This is the last value set with reportContentOrientationChange(). It defaults - to Qt::PrimaryOrientation. -*/ Qt::ScreenOrientation QWindow::contentOrientation() const { Q_D(const QWindow); @@ -506,12 +688,27 @@ Qt::ScreenOrientation QWindow::windowOrientation() const return d->windowOrientation; } +/*! + Returns the window state. + + \sa setWindowState() +*/ Qt::WindowState QWindow::windowState() const { Q_D(const QWindow); return d->windowState; } +/*! + Sets the desired window \a state. + + The window state represents whether the window appears in the + windowing system as maximized, minimized, fullscreen, or normal. + + The enum value Qt::WindowActive is not an accepted parameter. + + \sa windowState(), showNormal(), showFullScreen(), showMinimized(), showMaximized() +*/ void QWindow::setWindowState(Qt::WindowState state) { if (state == Qt::WindowActive) { @@ -527,7 +724,11 @@ void QWindow::setWindowState(Qt::WindowState state) } /*! - Sets the transient parent, which is a hint to the window manager that this window is a dialog or pop-up on behalf of the given window. + Sets the transient parent + + This is a hint to the window manager that this window is a dialog or pop-up on behalf of the given window. + + \sa transientParent(), parent() */ void QWindow::setTransientParent(QWindow *parent) { @@ -538,6 +739,11 @@ void QWindow::setTransientParent(QWindow *parent) d->transientParent = parent; } +/*! + Returns the transient parent of the window. + + \sa setTransientParent(), parent() +*/ QWindow *QWindow::transientParent() const { Q_D(const QWindow); @@ -555,8 +761,8 @@ QWindow *QWindow::transientParent() const */ /*! - Returns true if the window is an ancestor of the given child. If mode is - IncludeTransients transient parents are also considered ancestors. + Returns true if the window is an ancestor of the given child. If mode is + IncludeTransients transient parents are also considered ancestors. */ bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const { @@ -567,30 +773,57 @@ bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode)); } +/*! + Returns the minimum size of the window. + + \sa setMinimumSize() +*/ QSize QWindow::minimumSize() const { Q_D(const QWindow); return d->minimumSize; } +/*! + Returns the maximum size of the window. + + \sa setMaximumSize() +*/ QSize QWindow::maximumSize() const { Q_D(const QWindow); return d->maximumSize; } +/*! + Returns the base size of the window. + + \sa setBaseSize() +*/ QSize QWindow::baseSize() const { Q_D(const QWindow); return d->baseSize; } +/*! + Returns the size increment of the window. + + \sa setSizeIncrement() +*/ QSize QWindow::sizeIncrement() const { Q_D(const QWindow); return d->sizeIncrement; } +/*! + Sets the minimum size of the window. + + This is a hint to the window manager to prevent resizing below the specified \a size. + + \sa setMaximumSize(), minimumSize() +*/ void QWindow::setMinimumSize(const QSize &size) { Q_D(QWindow); @@ -602,6 +835,13 @@ void QWindow::setMinimumSize(const QSize &size) d->platformWindow->propagateSizeHints(); } +/*! + Sets the maximum size of the window. + + This is a hint to the window manager to prevent resizing above the specified \a size. + + \sa setMinimumSize(), maximumSize() +*/ void QWindow::setMaximumSize(const QSize &size) { Q_D(QWindow); @@ -613,6 +853,14 @@ void QWindow::setMaximumSize(const QSize &size) d->platformWindow->propagateSizeHints(); } +/*! + Sets the base size of the window. + + The base size is used to calculate a proper window size if the + window defines sizeIncrement(). + + \sa setMinimumSize(), setMaximumSize(), setSizeIncrement(), baseSize() +*/ void QWindow::setBaseSize(const QSize &size) { Q_D(QWindow); @@ -623,6 +871,20 @@ void QWindow::setBaseSize(const QSize &size) d->platformWindow->propagateSizeHints(); } +/*! + Sets the size increment of the window. + + When the user resizes the window, the size will move in steps of + sizeIncrement().width() pixels horizontally and + sizeIncrement().height() pixels vertically, with baseSize() as the + basis. + + By default, this property contains a size with zero width and height. + + The windowing system might not support size increments. + + \sa setBaseSize(), setMinimumSize(), setMaximumSize() +*/ void QWindow::setSizeIncrement(const QSize &size) { Q_D(QWindow); @@ -634,7 +896,12 @@ void QWindow::setSizeIncrement(const QSize &size) } /*! - Sets the geometry of the window excluding its window frame. + Sets the geometry of the window, excluding its window frame, to \a rect. + + To make sure the window is visible, make sure the geometry is within + the virtual geometry of its screen. + + \sa geometry(), screen(), QScreen::virtualGeometry() */ void QWindow::setGeometry(const QRect &rect) { @@ -661,7 +928,33 @@ void QWindow::setGeometry(const QRect &rect) } /*! - Returns the geometry of the window excluding its window frame. + \property QWindow::x + \since 5.0 + \brief the x position of the window's geometry +*/ + +/*! + \property QWindow::y + \since 5.0 + \brief the y position of the window's geometry +*/ + +/*! + \property QWindow::width + \since 5.0 + \brief the width of the window's geometry +*/ + +/*! + \property QWindow::height + \since 5.0 + \brief the height of the window's geometry +*/ + +/*! + Returns the geometry of the window, excluding its window frame. + + \sa frameMargins(), frameGeometry() */ QRect QWindow::geometry() const { @@ -673,6 +966,8 @@ QRect QWindow::geometry() const /*! Returns the window frame margins surrounding the window. + + \sa geometry(), frameGeometry() */ QMargins QWindow::frameMargins() const { @@ -683,7 +978,9 @@ QMargins QWindow::frameMargins() const } /*! - Returns the geometry of the window including its window frame. + Returns the geometry of the window, including its window frame. + + \sa geometry(), frameMargins() */ QRect QWindow::frameGeometry() const { @@ -696,7 +993,11 @@ QRect QWindow::frameGeometry() const } /*! - Returns the top left position of the window including its window frame. + Returns the top left position of the window, including its window frame. + + This returns the same value as frameGeometry().topLeft(). + + \sa geometry(), frameGeometry() */ QPoint QWindow::framePos() const { @@ -710,6 +1011,8 @@ QPoint QWindow::framePos() const /*! Sets the upper left position of the window including its window frame. + + \sa setGeometry(), frameGeometry() */ void QWindow::setFramePos(const QPoint &point) { @@ -722,6 +1025,11 @@ void QWindow::setFramePos(const QPoint &point) } } +/*! + Sets the size of the window to be \a newSize. + + \sa setGeometry() +*/ void QWindow::resize(const QSize &newSize) { Q_D(QWindow); @@ -732,18 +1040,23 @@ void QWindow::resize(const QSize &newSize) } } +/*! + Sets the window icon to the given \a icon image. + + The window icon might be used by the windowing system for example to decorate the window, + or in the task switcher. +*/ void QWindow::setWindowIcon(const QImage &icon) const { Q_UNUSED(icon); qDebug() << "unimplemented:" << __FILE__ << __LINE__; } - - /*! Releases the native platform resources associated with this window. - */ + \sa create() +*/ void QWindow::destroy() { Q_D(QWindow); @@ -761,18 +1074,37 @@ void QWindow::destroy() d->platformWindow = 0; } +/*! + Returns the platform window corresponding to the window. + + \internal +*/ QPlatformWindow *QWindow::handle() const { Q_D(const QWindow); return d->platformWindow; } +/*! + Returns the platform surface corresponding to the window. + + \internal +*/ QPlatformSurface *QWindow::surfaceHandle() const { Q_D(const QWindow); return d->platformWindow; } +/*! + Set whether keyboard grab should be enabled or not. + + If the return value is true, the window receives all key events until setKeyboardGrabEnabled(false) is + called; other windows get no key events at all. Mouse events are not affected. + Use setMouseGrabEnabled() if you want to grab that. + + \sa setMouseGrabEnabled() +*/ bool QWindow::setKeyboardGrabEnabled(bool grab) { Q_D(QWindow); @@ -781,6 +1113,15 @@ bool QWindow::setKeyboardGrabEnabled(bool grab) return false; } +/*! + Sets whether mouse grab should be enabled or not. + + If the return value is true, the window receives all mouse events until setMouseGrabEnabled(false) is + called; other windows get no mouse events at all. Keyboard events are not affected. + Use setKeyboardGrabEnabled() if you want to grab that. + + \sa setKeyboardGrabEnabled() +*/ bool QWindow::setMouseGrabEnabled(bool grab) { Q_D(QWindow); @@ -789,12 +1130,30 @@ bool QWindow::setMouseGrabEnabled(bool grab) return false; } +/*! + Returns the screen on which the window is shown. + + The value returned will not change when the window is moved + between virtual screens (as returned by QScreen::virtualSiblings()). + + \sa setScreen(), QScreen::virtualSiblings() +*/ QScreen *QWindow::screen() const { Q_D(const QWindow); return d->screen; } +/*! + Sets the screen on which the window should be shown. + + If the window has been created, it will be recreated on the new screen. + + Note that if the screen is part of a virtual desktop of multiple screens, + the window can appear on any of the screens returned by QScreen::virtualSiblings(). + + \sa screen(), QScreen::virtualSiblings() +*/ void QWindow::setScreen(QScreen *newScreen) { Q_D(QWindow); @@ -849,14 +1208,22 @@ QAccessibleInterface *QWindow::accessibleRoot() const */ /*! - Returns the QObject that will be the final receiver of events tied focus, such - as key events. + Returns the QObject that will be the final receiver of events tied focus, such + as key events. */ QObject *QWindow::focusObject() const { return const_cast(this); } +/*! + Shows the window. + + This equivalent to calling showFullScreen() or showNormal(), depending + on whether the platform defaults to windows being fullscreen or not. + + \sa showFullScreen(), showNormal(), hide(), QStyleHints::showIsFullScreen() +*/ void QWindow::show() { if (qApp->styleHints()->showIsFullScreen()) @@ -865,23 +1232,54 @@ void QWindow::show() showNormal(); } +/*! + Hides the window. + + Equivalent to calling setVisible(false). + + \sa show(), setVisible() +*/ void QWindow::hide() { setVisible(false); } +/*! + Shows the window as minimized. + + Equivalent to calling setWindowState(Qt::WindowMinimized) and then + setVisible(true). + + \sa setWindowState(), setVisible() +*/ void QWindow::showMinimized() { setWindowState(Qt::WindowMinimized); setVisible(true); } +/*! + Shows the window as maximized. + + Equivalent to calling setWindowState(Qt::WindowMaximized) and then + setVisible(true). + + \sa setWindowState(), setVisible() +*/ void QWindow::showMaximized() { setWindowState(Qt::WindowMaximized); setVisible(true); } +/*! + Shows the window as fullscreen. + + Equivalent to calling setWindowState(Qt::WindowFullScreen) and then + setVisible(true). + + \sa setWindowState(), setVisible() +*/ void QWindow::showFullScreen() { setWindowState(Qt::WindowFullScreen); @@ -889,12 +1287,28 @@ void QWindow::showFullScreen() requestActivateWindow(); } +/*! + Shows the window as normal, i.e. neither maximized, minimized, nor fullscreen. + + Equivalent to calling setWindowState(Qt::WindowNoState) and then + setVisible(true). + + \sa setWindowState(), setVisible() +*/ void QWindow::showNormal() { setWindowState(Qt::WindowNoState); setVisible(true); } +/*! + Close the window. + + This closes the window, effectively calling destroy(), and + potentially quitting the application + + \sa destroy(), QGuiApplication::quitOnLastWindowClosed() +*/ bool QWindow::close() { Q_D(QWindow); @@ -912,8 +1326,6 @@ bool QWindow::close() return true; } - - /*! The expose event is sent by the window system whenever the window's exposure on screen changes. @@ -923,33 +1335,60 @@ bool QWindow::close() value of isExposed() might change to false. When this happens, an application should stop its rendering as it is no longer visible to the user. - */ + \sa isExposed() +*/ void QWindow::exposeEvent(QExposeEvent *ev) { ev->ignore(); } +/*! + Override this to handle mouse events. +*/ void QWindow::moveEvent(QMoveEvent *ev) { ev->ignore(); } +/*! + Override this to handle resize events. + + The resize event is called whenever the window is resized in the windowing system, + either directly through the windowing system acknowledging a setGeometry() or resize() request, + or indirectly through the user resizing the window manually. +*/ void QWindow::resizeEvent(QResizeEvent *ev) { ev->ignore(); } +/*! + Override this to handle show events. + + The show event is called when the window becomes visible in the windowing system. +*/ void QWindow::showEvent(QShowEvent *ev) { ev->ignore(); } +/*! + Override this to handle show events. + + The show event is called when the window becomes hidden in the windowing system. +*/ void QWindow::hideEvent(QHideEvent *ev) { ev->ignore(); } +/*! + Override this to handle any event sent to the window. + + Remembet to call the base class version if you wish for mouse events, + key events, resize events, etc to be dispatched as usual. +*/ bool QWindow::event(QEvent *ev) { switch (ev->type()) { @@ -1032,58 +1471,111 @@ bool QWindow::event(QEvent *ev) return true; } +/*! + Override this to handle key press events. + + \sa keyReleaseEvent +*/ void QWindow::keyPressEvent(QKeyEvent *ev) { ev->ignore(); } +/*! + Override this to handle key release events. + + \sa keyPressEvent +*/ void QWindow::keyReleaseEvent(QKeyEvent *ev) { ev->ignore(); } +/*! + Override this to handle focus in events. + + Focus in events are sent when the window receives keyboard focus. + + \sa focusOutEvent +*/ void QWindow::focusInEvent(QFocusEvent *ev) { ev->ignore(); } +/*! + Override this to handle focus out events. + + Focus out events are sent when the window loses keyboard focus. + + \sa focusInEvent +*/ void QWindow::focusOutEvent(QFocusEvent *ev) { ev->ignore(); } +/*! + Override this to handle mouse press events. + + \sa mouseReleaseEvent() +*/ void QWindow::mousePressEvent(QMouseEvent *ev) { ev->ignore(); } +/*! + Override this to handle mouse release events. + + \sa mousePressEvent() +*/ void QWindow::mouseReleaseEvent(QMouseEvent *ev) { ev->ignore(); } +/*! + Override this to handle mouse double click events. + + \sa mousePressEvent(), QStyleHints::mouseDoubleClickInterval() +*/ void QWindow::mouseDoubleClickEvent(QMouseEvent *ev) { ev->ignore(); } +/*! + Override this to handle mouse move events. +*/ void QWindow::mouseMoveEvent(QMouseEvent *ev) { ev->ignore(); } #ifndef QT_NO_WHEELEVENT +/*! + Override this to handle mouse wheel or other wheel events. +*/ void QWindow::wheelEvent(QWheelEvent *ev) { ev->ignore(); } #endif //QT_NO_WHEELEVENT +/*! + Override this to handle touch events. +*/ void QWindow::touchEvent(QTouchEvent *ev) { ev->ignore(); } +/*! + Override this to handle platform dependent events. + + This might make your application non-portable. +*/ bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) { Q_UNUSED(eventType); @@ -1101,14 +1593,12 @@ bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *resu \sa mapFromGlobal() */ - QPoint QWindow::mapToGlobal(const QPoint &pos) const { return pos + d_func()->globalPosition(); } - /*! \fn QPoint QWindow::mapFromGlobal(const QPoint &pos) const @@ -1117,14 +1607,12 @@ QPoint QWindow::mapToGlobal(const QPoint &pos) const \sa mapToGlobal() */ - QPoint QWindow::mapFromGlobal(const QPoint &pos) const { return pos - d_func()->globalPosition(); } - Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window) { return window->d_func(); -- cgit v1.2.3 From 422b6ba9ecf0595da5772afec8c5a0a00983d95d Mon Sep 17 00:00:00 2001 From: Jan Arne Petersen Date: Fri, 2 Dec 2011 15:20:04 +0100 Subject: Add WindowDoesNotAcceptFocus flag and use it in xcb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add window flag to support windows which should not get the input focus. Sets the input field in the WM_HINTS structure of the window to false if the WindowDoesNotAcceptFocus flag is set on a window in xcb. Change-Id: Ifbc10695b83484c17dca0eb13ea826d74f174833 Reviewed-by: Samuel Rødal --- src/corelib/global/qnamespace.h | 1 + src/corelib/global/qnamespace.qdoc | 3 +++ src/plugins/platforms/xcb/qxcbwindow.cpp | 24 ++++++++++++++++++++++++ src/plugins/platforms/xcb/qxcbwindow.h | 1 + 4 files changed, 29 insertions(+) (limited to 'src') diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 2087d763de..4ea62c77a6 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -293,6 +293,7 @@ public: WindowStaysOnTopHint = 0x00040000, WindowTransparentForInput = 0x00080000, WindowOverridesSystemGestures = 0x00100000, + WindowDoesNotAcceptFocus = 0x00200000, CustomizeWindowHint = 0x02000000, WindowStaysOnBottomHint = 0x04000000, diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index d50960f68b..895feb7f53 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2112,6 +2112,9 @@ implements its own set of gestures and that system level gestures, like for instance three-finger desktop switching, should be disabled. + \value WindowDoesNotAcceptFocus Informs the window system that this window should + not receive the input focus. + \value WindowType_Mask A mask for extracting the window type part of the window flags. diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 43e4a6b7d9..067cb775c8 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -77,6 +77,7 @@ #define xcb_size_hints_set_win_gravity xcb_icccm_size_hints_set_win_gravity #define xcb_wm_hints_set_iconic xcb_icccm_wm_hints_set_iconic #define xcb_wm_hints_set_normal xcb_icccm_wm_hints_set_normal +#define xcb_wm_hints_set_input xcb_icccm_wm_hints_set_input #define xcb_wm_hints_t xcb_icccm_wm_hints_t #define XCB_WM_STATE_ICONIC XCB_ICCCM_WM_STATE_ICONIC #define XCB_WM_STATE_WITHDRAWN XCB_ICCCM_WM_STATE_WITHDRAWN @@ -322,6 +323,8 @@ void QXcbWindow::create() memset(&hints, 0, sizeof(hints)); xcb_wm_hints_set_normal(&hints); + xcb_wm_hints_set_input(&hints, !(window()->windowFlags() & Qt::WindowDoesNotAcceptFocus)); + xcb_set_wm_hints(xcb_connection(), m_window, &hints); xcb_window_t leader = m_screen->clientLeader(); @@ -509,6 +512,8 @@ void QXcbWindow::show() else xcb_wm_hints_set_normal(&hints); + xcb_wm_hints_set_input(&hints, !(window()->windowFlags() & Qt::WindowDoesNotAcceptFocus)); + xcb_set_wm_hints(xcb_connection(), m_window, &hints); // update WM_NORMAL_HINTS @@ -730,6 +735,7 @@ Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags) setMotifWindowFlags(flags); setTransparentForMouseEvents(flags & Qt::WindowTransparentForInput); + updateDoesNotAcceptFocus(flags & Qt::WindowDoesNotAcceptFocus); return flags; } @@ -1062,6 +1068,24 @@ void QXcbWindow::setTransparentForMouseEvents(bool transparent) m_transparent = transparent; } +void QXcbWindow::updateDoesNotAcceptFocus(bool doesNotAcceptFocus) +{ + xcb_get_property_cookie_t cookie = xcb_get_wm_hints(xcb_connection(), m_window); + + xcb_generic_error_t *error; + + xcb_wm_hints_t hints; + xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, &error); + + if (error) { + connection()->handleXcbError(error); + free(error); + return; + } + + xcb_wm_hints_set_input(&hints, !doesNotAcceptFocus); + xcb_set_wm_hints(xcb_connection(), m_window, &hints); +} WId QXcbWindow::winId() const { diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index 365c8b0549..6ae55e77e6 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -132,6 +132,7 @@ private: void updateNetWmStateBeforeMap(); void setTransparentForMouseEvents(bool transparent); + void updateDoesNotAcceptFocus(bool doesNotAcceptFocus); void create(); void destroy(); -- cgit v1.2.3 From b067f6cfe30a5a687316130d04678ac406837d09 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 8 Feb 2012 15:55:29 +0100 Subject: Add the quitlock feature to QThread. Change-Id: Ib44ee9739499ba4c5f0fecbef3976251ea22836d Reviewed-by: Bradley T. Hughes Reviewed-by: Thiago Macieira --- src/corelib/kernel/qeventloop.cpp | 19 +++++++++++++++++-- src/corelib/kernel/qeventloop.h | 1 + src/corelib/thread/qthread.cpp | 9 +++++++++ src/corelib/thread/qthread.h | 2 ++ src/corelib/thread/qthread_p.h | 17 +++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 8b0ec85679..2fb351797c 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -322,13 +322,19 @@ class QEventLoopLockerPrivate { public: explicit QEventLoopLockerPrivate(QEventLoopPrivate *loop) - : loop(loop), app(0) + : loop(loop), thread(0), app(0) { loop->ref(); } + explicit QEventLoopLockerPrivate(QThreadPrivate *thread) + : loop(0), thread(thread), app(0) + { + thread->ref(); + } + explicit QEventLoopLockerPrivate(QCoreApplicationPrivate *app) - : loop(0), app(app) + : loop(0), thread(0), app(app) { app->ref(); } @@ -337,12 +343,15 @@ public: { if (loop) loop->deref(); + else if (thread) + thread->deref(); else app->deref(); } private: QEventLoopPrivate *loop; + QThreadPrivate *thread; QCoreApplicationPrivate *app; }; @@ -390,6 +399,12 @@ QEventLoopLocker::QEventLoopLocker(QEventLoop *loop) } +QEventLoopLocker::QEventLoopLocker(QThread *thread) + : d_ptr(new QEventLoopLockerPrivate(static_cast(QObjectPrivate::get(thread)))) +{ + +} + /*! Destroys this event loop locker object */ diff --git a/src/corelib/kernel/qeventloop.h b/src/corelib/kernel/qeventloop.h index 0e7195d6a7..ba082d7d9d 100644 --- a/src/corelib/kernel/qeventloop.h +++ b/src/corelib/kernel/qeventloop.h @@ -96,6 +96,7 @@ class Q_CORE_EXPORT QEventLoopLocker public: QEventLoopLocker(); explicit QEventLoopLocker(QEventLoop *loop); + explicit QEventLoopLocker(QThread *thread); ~QEventLoopLocker(); private: diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index be0a98d3b5..a071463178 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -763,5 +763,14 @@ void QThread::setEventDispatcher(QAbstractEventDispatcher *eventDispatcher) } } +bool QThread::event(QEvent *event) +{ + if (event->type() == QEvent::Quit) { + quit(); + return true; + } else { + return QObject::event(event); + } +} QT_END_NAMESPACE diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index 719f4afbbb..ba119afb5d 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -95,6 +95,8 @@ public: QAbstractEventDispatcher *eventDispatcher() const; void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher); + bool event(QEvent *event); + public Q_SLOTS: void start(Priority = InheritPriority); void terminate(); diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index d8374e9805..6597b56893 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -60,6 +60,7 @@ #include "QtCore/qstack.h" #include "QtCore/qwaitcondition.h" #include "QtCore/qmap.h" +#include "QtCore/qcoreapplication.h" #include "private/qobject_p.h" @@ -144,6 +145,7 @@ public: ~QThreadPrivate(); mutable QMutex mutex; + QAtomicInt quitLockRef; bool running; bool finished; @@ -179,6 +181,18 @@ public: QThreadData *data; static void createEventDispatcher(QThreadData *data); + + void ref() + { + quitLockRef.ref(); + } + + void deref() + { + if (!quitLockRef.deref() && running) { + QCoreApplication::instance()->postEvent(q_ptr, new QEvent(QEvent::Quit)); + } + } }; #else // QT_NO_THREAD @@ -195,6 +209,9 @@ public: static QThread *threadForId(int) { return QThread::currentThread(); } static void createEventDispatcher(QThreadData *data); + void ref() {} + void deref() {} + Q_DECLARE_PUBLIC(QThread) }; -- cgit v1.2.3 From cc6f28e2d653473d92ace43334e448604b7c23f2 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 23 Feb 2012 11:41:47 +0000 Subject: Fix fontconfig.pri file to allow QPA plugins to build Change-Id: I5ebcffb7153f4216d69921d4818051e6b3d14d8a Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/platformsupport/fontdatabases/fontconfig/fontconfig.pri | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/platformsupport/fontdatabases/fontconfig/fontconfig.pri b/src/platformsupport/fontdatabases/fontconfig/fontconfig.pri index 2c896ef2cc..af9bd0a01c 100644 --- a/src/platformsupport/fontdatabases/fontconfig/fontconfig.pri +++ b/src/platformsupport/fontdatabases/fontconfig/fontconfig.pri @@ -1,5 +1,5 @@ HEADERS += $$PWD/qfontconfigdatabase_p.h \ - fontdatabases/fontconfig/qfontenginemultifontconfig_p.h + $$PWD/qfontenginemultifontconfig_p.h SOURCES += $$PWD/qfontconfigdatabase.cpp \ - fontdatabases/fontconfig/qfontenginemultifontconfig.cpp + $$PWD/qfontenginemultifontconfig.cpp DEFINES -= QT_NO_FONTCONFIG -- cgit v1.2.3 From 60c6ed0e042fa18d76d4961d394b8f99226e9892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Mon, 13 Feb 2012 13:06:40 +0100 Subject: Rename QMetaTypeSwitcher::UnknownType to NotBuiltinType. UnknownType suggest that a type is unknown to QMetaType, but QMetaTypeSwitcher is not checking for custom types. Change-Id: I6b8b692e0f20bed286c713672b35fb15757d389e Reviewed-by: Olivier Goffart --- src/corelib/kernel/qmetatype.cpp | 12 ++++++------ src/corelib/kernel/qmetatypeswitcher_p.h | 4 ++-- src/corelib/kernel/qvariant_p.h | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index a1baf28f10..0021c0ced2 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1318,7 +1318,7 @@ public: template void delegate(const T *where) { DestroyerImpl::Destroy(m_type, const_cast(where)); } void delegate(const void *) {} - void delegate(const QMetaTypeSwitcher::UnknownType *where) { customTypeDestroyer(m_type, (void*)where); } + void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestroyer(m_type, (void*)where); } private: static void customTypeDestroyer(const int type, void *where) @@ -1380,7 +1380,7 @@ public: template void *delegate(const T *copy) { return ConstructorImpl::Construct(m_type, m_where, copy); } void *delegate(const void *) { return m_where; } - void *delegate(const QMetaTypeSwitcher::UnknownType *copy) { return customTypeConstructor(m_type, m_where, copy); } + void *delegate(const QMetaTypeSwitcher::NotBuiltinType *copy) { return customTypeConstructor(m_type, m_where, copy); } private: static void *customTypeConstructor(const int type, void *where, const void *copy) @@ -1468,7 +1468,7 @@ public: template void delegate(const T *where) { DestructorImpl::Destruct(m_type, const_cast(where)); } void delegate(const void *) {} - void delegate(const QMetaTypeSwitcher::UnknownType *where) { customTypeDestructor(m_type, (void*)where); } + void delegate(const QMetaTypeSwitcher::NotBuiltinType *where) { customTypeDestructor(m_type, (void*)where); } private: static void customTypeDestructor(const int type, void *where) @@ -1536,7 +1536,7 @@ public: template int delegate(const T*) { return SizeOfImpl::Size(m_type); } - int delegate(const QMetaTypeSwitcher::UnknownType*) { return customTypeSizeOf(m_type); } + int delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeSizeOf(m_type); } private: static int customTypeSizeOf(const int type) { @@ -1606,7 +1606,7 @@ public: template quint32 delegate(const T*) { return FlagsImpl::Flags(m_type); } quint32 delegate(const void*) { return 0; } - quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return customTypeFlags(m_type); } + quint32 delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customTypeFlags(m_type); } private: const int m_type; static quint32 customTypeFlags(const int type) @@ -1793,7 +1793,7 @@ public: template void delegate(const T*) { TypeInfoImpl(m_type, info); } void delegate(const void*) {} - void delegate(const QMetaTypeSwitcher::UnknownType*) { customTypeInfo(m_type); } + void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); } private: void customTypeInfo(const uint type) { diff --git a/src/corelib/kernel/qmetatypeswitcher_p.h b/src/corelib/kernel/qmetatypeswitcher_p.h index c1cccfca63..05db2cb4c7 100644 --- a/src/corelib/kernel/qmetatypeswitcher_p.h +++ b/src/corelib/kernel/qmetatypeswitcher_p.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE class QMetaTypeSwitcher { public: - typedef void *UnknownType; + typedef void *NotBuiltinType; template static ReturnType switcher(DelegateObject &logic, int type, const void *data); }; @@ -91,7 +91,7 @@ ReturnType QMetaTypeSwitcher::switcher(DelegateObject &logic, int type, const vo QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS) default: - return logic.delegate(static_cast(data)); + return logic.delegate(static_cast(data)); } } diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index c428d81bb4..708a427860 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -345,7 +345,7 @@ public: FilteredConstructor(*this); } - void delegate(const QMetaTypeSwitcher::UnknownType*) + void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { qWarning("Trying to construct an instance of an invalid type, type id: %i", m_x->type); m_x->type = QVariant::Invalid; @@ -395,7 +395,7 @@ public: FilteredDestructor cleaner(m_d); } - void delegate(const QMetaTypeSwitcher::UnknownType*) + void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { qWarning("Trying to destruct an instance of an invalid type, type id: %i", m_d->type); } @@ -441,7 +441,7 @@ public: Filtered streamIt(m_debugStream, m_d); } - void delegate(const QMetaTypeSwitcher::UnknownType*) + void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { qWarning("Trying to stream an instance of an invalid type, type id: %i", m_d->type); } -- cgit v1.2.3 From 52c253fa33162c1db2d0cb0916e0de188b9a0aae Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 23 Feb 2012 00:22:59 +0100 Subject: Remove QT_ASCII_CAST_WARN_CONSTRUCTOR GCC version < 3 which it was created for is not supported anymore. Change-Id: I0b4df4c99600cacbaafbf0bc4270cd4978600956 Reviewed-by: Thiago Macieira --- src/corelib/global/qglobal.h | 7 ------- src/corelib/kernel/qvariant.h | 2 +- src/corelib/tools/qchar.h | 4 ++-- src/corelib/tools/qstring.h | 4 ++-- 4 files changed, 5 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 485f08bfce..e7a6b59f2e 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -385,15 +385,8 @@ QT_END_INCLUDE_NAMESPACE #ifdef QT_ASCII_CAST_WARNINGS # define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED -# if defined(Q_CC_GNU) && __GNUC__ < 4 - /* gcc < 4 doesn't like Q_DECL_DEPRECATED in front of constructors */ -# define QT_ASCII_CAST_WARN_CONSTRUCTOR -# else -# define QT_ASCII_CAST_WARN_CONSTRUCTOR Q_DECL_CONSTRUCTOR_DEPRECATED -# endif #else # define QT_ASCII_CAST_WARN -# define QT_ASCII_CAST_WARN_CONSTRUCTOR #endif #if defined(__i386__) || defined(_WIN32) || defined(_WIN32_WCE) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 5fcfe3e696..20d3946ea1 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -210,7 +210,7 @@ class Q_CORE_EXPORT QVariant QVariant(double d); QVariant(float f) { d.is_null = false; d.type = QMetaType::Float; d.data.f = f; } #ifndef QT_NO_CAST_FROM_ASCII - QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant(const char *str); + QT_ASCII_CAST_WARN QVariant(const char *str); #endif QVariant(const QByteArray &bytearray); diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index d55fcdba89..3209ffb0f2 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -86,8 +86,8 @@ public: Q_DECL_CONSTEXPR QChar(QLatin1Char ch) : ucs(ch.unicode()) {} // implicit #ifndef QT_NO_CAST_FROM_ASCII - QT_ASCII_CAST_WARN_CONSTRUCTOR Q_DECL_CONSTEXPR explicit QChar(char c) : ucs(uchar(c)) { } - QT_ASCII_CAST_WARN_CONSTRUCTOR Q_DECL_CONSTEXPR explicit QChar(uchar c) : ucs(c) { } + QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(char c) : ucs(uchar(c)) { } + QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(uchar c) : ucs(c) { } #endif // Unicode information diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index f49d989e9d..b1ade85a30 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -498,10 +498,10 @@ public: // ASCII compatibility #ifndef QT_NO_CAST_FROM_ASCII - inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const char *ch) + inline QT_ASCII_CAST_WARN QString(const char *ch) : d(fromAscii_helper(ch, ch ? int(strlen(ch)) : -1)) {} - inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const QByteArray &a) + inline QT_ASCII_CAST_WARN QString(const QByteArray &a) : d(fromAscii_helper(a.constData(), qstrnlen(a.constData(), a.size()))) {} inline QT_ASCII_CAST_WARN QString &operator=(const char *ch) -- cgit v1.2.3 From cf2ca62dcd2494155b9c07d6a14df7c453226c1e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 22 Feb 2012 14:25:33 +0100 Subject: Require compiler support for deprecated constructors. Change-Id: I1d4cdcbbddb7895e6529e4f6b5295312e9a3a0e6 Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 3 --- src/corelib/global/qglobal.h | 7 ------- 2 files changed, 10 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index f76dfbaaa5..b3787261be 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -145,9 +145,6 @@ /* Clang also masquerades as GCC */ # define Q_CC_CLANG # endif -# ifdef __APPLE__ -# define Q_NO_DEPRECATED_CONSTRUCTORS -# endif # define Q_ALIGNOF(type) __alignof__(type) # define Q_TYPEOF(expr) __typeof__(expr) # define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index e7a6b59f2e..acafde595d 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -324,13 +324,6 @@ QT_END_INCLUDE_NAMESPACE #ifndef Q_DECL_VARIABLE_DEPRECATED # define Q_DECL_VARIABLE_DEPRECATED Q_DECL_DEPRECATED #endif -#ifndef Q_DECL_CONSTRUCTOR_DEPRECATED -# if defined(Q_NO_DEPRECATED_CONSTRUCTORS) -# define Q_DECL_CONSTRUCTOR_DEPRECATED -# else -# define Q_DECL_CONSTRUCTOR_DEPRECATED Q_DECL_DEPRECATED -# endif -#endif #if defined(QT_NO_DEPRECATED) # undef QT_DEPRECATED -- cgit v1.2.3 From 785e95ef0a95ca8fb39ef57678cd4876ee657c43 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Wed, 8 Feb 2012 10:12:13 +0000 Subject: Harfbuzz-thai: Hide ZWJ and ZWNJ characters and show Inherited characters Thai is not supposed to have ZWJ and ZWNJ characters or any other of the Inherited Unicode Scripts (http://www.verisigninc.com/assets/idn-inherited-unicode-script.pdf) - they don't have a mapping to the thai encoding tis620 which libthai requires. However it is an unfortunate fact that there are many websites etc that liberally place these ZWJ and ZWNJ characters throughout thai text to force word boundaries, so we must also deal with them. We deal with all Inherited characters by mapping them to the invalid code ~0 in tis620 encoding, following what libthai does internally in its own tis620 encoding functions, and then replacing this character with the original unicode and setting dontPrint to true to hide the ZWJ and ZWNJ characters. Includes a unit test to check the behaviour. Change-Id: I1ee8388b650cb5fc61bcb265efb9843c73f327ac Reviewed-by: Adrian Yanes Reviewed-by: Lars Knoll Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/3rdparty/harfbuzz/src/harfbuzz-thai.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/3rdparty/harfbuzz/src/harfbuzz-thai.c b/src/3rdparty/harfbuzz/src/harfbuzz-thai.c index 386fd5c252..bf6c35b19c 100644 --- a/src/3rdparty/harfbuzz/src/harfbuzz-thai.c +++ b/src/3rdparty/harfbuzz/src/harfbuzz-thai.c @@ -77,7 +77,7 @@ static void to_tis620(const HB_UChar16 *string, hb_uint32 len, const char *cstr) else if (string[i] >= 0xe01 && string[i] <= 0xe5b) result[i] = (unsigned char)(string[i] - 0xe00 + 0xa0); else - result[i] = '?'; + result[i] = (unsigned char)~0; // Same encoding as libthai uses for invalid chars } result[len] = 0; @@ -259,8 +259,13 @@ static HB_Bool HB_ThaiConvertStringToGlyphIndices (HB_ShaperItem *item) for (int lgi = 0; lgi < lgn; lgi++) { if ( rglyphs[lgi] == 0xdd/*TH_BLANK_BASE_GLYPH*/ ) { glyphString[slen++] = C_DOTTED_CIRCLE; - } - else { + } else if (cstr[i] == (signed char)~0) { + // The only glyphs that should be passed to this function that cannot be mapped to + // tis620 are the ones of type Inherited class. Pass these glyphs untouched. + glyphString[slen++] = string[i]; + if (string[i] == 0x200D || string[i] == 0x200C) + item->attributes[slen-1].dontPrint = true; // Hide ZWJ and ZWNJ characters + } else { glyphString[slen++] = (HB_UChar16) thai_get_glyph_index (font_type, rglyphs[lgi]); } } -- cgit v1.2.3 From 2b23d7214f1bb90369ee418a30958fcc5d96cd8f Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Wed, 8 Feb 2012 10:12:16 +0000 Subject: QTextEngine - treat a fullstop (0x2E) as the same script as the preceeding text when dividing up strings Many languages use a fullstop to indicate an abbreviation, making the fullstop part of the word. For languages like thai, it is required to pass the fullstop along for correct word breaking. Change-Id: I5ad0ddbc66ea96e08913446dad8fd3c5d5dd0905 Reviewed-by: Lars Knoll Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextengine.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index bc7f4f7ad6..30170759a0 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -115,7 +115,20 @@ private: return; const int end = start + length; for (int i = start + 1; i < end; ++i) { - if ((m_analysis[i] == m_analysis[start]) + // According to the unicode spec we should be treating characters in the Common script + // (punctuation, spaces, etc) as being the same script as the surrounding text for the + // purpose of splitting up text. This is important because, for example, a fullstop + // (0x2E) can be used to indicate an abbreviation and so must be treated as part of a + // word. Thus it must be passed along with the word in languages that have to calculate + // word breaks. For example the thai word "ครม." has no word breaks but the word "ครม" + // does. + // Unfortuntely because we split up the strings for both wordwrapping and for setting + // the font and because Japanese and Chinese are also aliases of the script "Common", + // doing this would break too many things. So instead we only pass the full stop + // along, and nothing else. + if (m_analysis[i].bidiLevel == m_analysis[start].bidiLevel + && m_analysis[i].flags == m_analysis[start].flags + && (m_analysis[i].script == m_analysis[start].script || m_string[i] == QLatin1Char('.')) && m_analysis[i].flags < QScriptAnalysis::SpaceTabOrObject && i - start < MaxItemLength) continue; -- cgit v1.2.3 From 031389e62eef062d0bc93539d9144265996fa86f Mon Sep 17 00:00:00 2001 From: Martin Petersson Date: Thu, 23 Feb 2012 13:18:47 +0100 Subject: QWindowsPipeWriter could terminate the process to early When the QWindowsPipeWriter is deleted it will wait for the thread to exit. This wait was set to 100 ms which will not always be enough time for the thread to exit, in that case the thread will be terminated. This will increase the timeout to 30 seconds that should be more then enough time for the thread to exit by itself. Task-number: QTBUG-4425 Change-Id: I9b1910c0213376c622c091be050df2a1c4c6b190 Reviewed-by: Joerg Bornemann Reviewed-by: Bradley T. Hughes --- src/corelib/io/qwindowspipewriter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index e31337d0fd..aa3745237b 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -67,7 +67,7 @@ QWindowsPipeWriter::~QWindowsPipeWriter() quitNow = true; waitCondition.wakeOne(); lock.unlock(); - if (!wait(100)) + if (!wait(30000)) terminate(); #if !defined(Q_OS_WINCE) || (_WIN32_WCE >= 0x600) CloseHandle(writePipe); -- cgit v1.2.3 From 19a562a92318f417bb4dca0cae2b97f28a98a7e2 Mon Sep 17 00:00:00 2001 From: Martin Petersson Date: Tue, 21 Feb 2012 15:28:18 +0100 Subject: QSslSocket::verify certificates when on-demand loading is used Task-number: QTBUG-24350 Change-Id: I5a328efe6606f5d438bb4787a5c02a425ce42aca Reviewed-by: Richard J. Moore --- src/network/ssl/qsslsocket_openssl.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index f62f3c1229..20ad82407c 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -1384,6 +1384,10 @@ QList QSslSocketBackendPrivate::verify(QList certifi return errors; } + if (s_loadRootCertsOnDemand) { + setDefaultCaCertificates(defaultCaCertificates() + systemCaCertificates()); + } + QList expiredCerts; foreach (const QSslCertificate &caCertificate, QSslSocket::defaultCaCertificates()) { -- cgit v1.2.3 From ca028e1fe07f2fb268d1da73eeaccb0f7f264a04 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 23 Feb 2012 13:52:16 +0100 Subject: Bump the moc output revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit aee1f6cc413f56bf4962324799ee3887c3dd037f changed the values of some built-in meta-type ids. Since the ids of built-in types are directly encoded -- not as the symbolic QMetaType::Type name, but as a raw integer -- in the flags for meta-properties, the moc output prior to that change is incompatible with the current output. Change-Id: I970484825137a4f19c80726cfe2024e741e3e879 Reviewed-by: JÄ™drzej Nowacki Reviewed-by: Roberto Raggi Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart --- src/corelib/kernel/qobjectdefs.h | 2 +- src/tools/moc/outputrevision.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 0b1fa8839f..ec51251531 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -54,7 +54,7 @@ class QByteArray; class QString; #ifndef Q_MOC_OUTPUT_REVISION -#define Q_MOC_OUTPUT_REVISION 63 +#define Q_MOC_OUTPUT_REVISION 64 #endif // The following macros are our "extensions" to C++ diff --git a/src/tools/moc/outputrevision.h b/src/tools/moc/outputrevision.h index 15661a43aa..2ce5b9b765 100644 --- a/src/tools/moc/outputrevision.h +++ b/src/tools/moc/outputrevision.h @@ -43,6 +43,6 @@ #define OUTPUTREVISION_H // if the output revision changes, you MUST change it in qobjectdefs.h too -enum { mocOutputRevision = 63 }; // moc format output revision +enum { mocOutputRevision = 64 }; // moc format output revision #endif // OUTPUTREVISION_H -- cgit v1.2.3 From 804e93462e939ecae671570f3a6ed943ebf3270a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 21 Feb 2012 12:46:44 +0100 Subject: Added documentation for QOpenGLContext and QOpenGLContextGroup. Change-Id: I00e3e3b3fd37b27b31d4705de3c8c34be9211707 Reviewed-by: Casper van Donderen Reviewed-by: Gunnar Sletta --- src/gui/kernel/qopenglcontext.cpp | 276 ++++++++++++++++++++++++++++++++------ 1 file changed, 233 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index ba51653fcf..c263a2a84e 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -74,6 +74,76 @@ QHash QOpenGLContextPrivate::makeCurrentTracker; QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex; #endif +/*! + \class QOpenGLContext + \brief The QOpenGLContext represents a native OpenGL context, enabling + OpenGL rendering on a QSurface. + + QOpenGLContext represents the OpenGL state of an underlying OpenGL context. + To set up a context, set its screen and format such that they match those + of the surface or surfaces with which the context is meant to be used, if + necessary make it share resources with other contexts with + setShareContext(), and finally call create(). Use isValid() to check if the + context was successfully initialized. + + A context can be made current against a given surface by calling + makeCurrent(). When OpenGL rendering is done, call swapBuffers() to swap + the front and back buffers of the surface, so that the newly rendered + content becomes visible. To be able to support certain platforms, + QOpenGLContext requires that you call makeCurrent() again before starting + rendering a new frame, after calling swapBuffers(). + + If the context is temporarily not needed, such as when the application is + not rendering, it can be useful to call destroy() to free resources. + However, if you do so you will need to call create() again before the + context can be used, and you might need to recreate any OpenGL resources + and reinitialize the OpenGL state. You can connect to the + aboutToBeDestroyed() signal to clean up any resources that have been + allocated with different ownership from the QOpenGLContext itself. + + Once a QOpenGLContext has been made current, you can render to it in a + platform independent way by using Qt's OpenGL enablers such as + QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and + QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL + API directly, without using the Qt enablers, although potentially at the + cost of portability. The latter is necessary when wanting to use OpenGL 1.x + or OpenGL ES 1.x. + + For more information about the OpenGL API, refer to the official + \l{OpenGL documentation}. + + \section1 Thread affinity + + QOpenGLContext can be moved to a different thread with moveToThread(). Do + not call makeCurrent() from a different thread than the one to which the + QOpenGLContext object belongs. A context can only be current in one thread + and against one surface at a time, and a thread only has one context + current at a time. + + \section1 Context resource sharing + + Resources, such as framebuffer objects, textures, and vertex buffer objects + can be shared between contexts. Use setShareContext() before calling + create() to specify that the contexts should share these resources. + QOpenGLContext internally keeps track of a QOpenGLContextGroup object which + can be accessed with shareGroup(), and which can be used to find all the + contexts in a given share group. A share group consists of all contexts that + have been succesfully initialized and are sharing with an existing context in + the share group. A non-sharing context has a share group consisting of a + single context. + + \section1 Default framebuffer + + On certain platforms, a framebuffer other than 0 might be the default frame + buffer depending on the current surface. Instead of calling + glBindFramebuffer(0), it is recommended that you use + glBindFramebuffer(ctx->defaultFramebufferObject()), to ensure that your + application is portable between different platforms. However, if you use + QOpenGLFunctions::glBindFramebuffer(), this is done automatically for you. + + \sa QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, QOpenGLFramebufferObject +*/ + void QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context) { QGuiGLThreadContext *threadContext = qwindow_context_storage.localData(); @@ -89,7 +159,8 @@ void QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context) } /*! - Returns the last context which called makeCurrent. This function is thread aware. + Returns the last context which called makeCurrent in the current thread, + or 0, if no context is current. */ QOpenGLContext* QOpenGLContext::currentContext() { @@ -100,17 +171,31 @@ QOpenGLContext* QOpenGLContext::currentContext() return 0; } +/*! + Returns true if the two contexts are sharing OpenGL resources. +*/ bool QOpenGLContext::areSharing(QOpenGLContext *first, QOpenGLContext *second) { return first->shareGroup() == second->shareGroup(); } +/*! + Returns the underlying platform context. + + \internal +*/ QPlatformOpenGLContext *QOpenGLContext::handle() const { Q_D(const QOpenGLContext); return d->platformGLContext; } +/*! + Returns the underlying platform context with which this context is sharing. + + \internal +*/ + QPlatformOpenGLContext *QOpenGLContext::shareHandle() const { Q_D(const QOpenGLContext); @@ -120,7 +205,11 @@ QPlatformOpenGLContext *QOpenGLContext::shareHandle() const } /*! - Creates a new GL context instance, you need to call create() before it can be used. + Creates a new OpenGL context instance. + + Before it can be used you need to set the proper format and call create(). + + \sa create(), makeCurrent() */ QOpenGLContext::QOpenGLContext(QObject *parent) : QObject(*new QOpenGLContextPrivate(), parent) @@ -130,7 +219,8 @@ QOpenGLContext::QOpenGLContext(QObject *parent) } /*! - Sets the format the GL context should be compatible with. You need to call create() before it takes effect. + Sets the \a format the OpenGL context should be compatible with. You need + to call create() before it takes effect. */ void QOpenGLContext::setFormat(const QSurfaceFormat &format) { @@ -139,7 +229,8 @@ void QOpenGLContext::setFormat(const QSurfaceFormat &format) } /*! - Sets the context to share textures, shaders, and other GL resources with. You need to call create() before it takes effect. + Sets the context to share textures, shaders, and other OpenGL resources + with. You need to call create() before it takes effect. */ void QOpenGLContext::setShareContext(QOpenGLContext *shareContext) { @@ -148,7 +239,8 @@ void QOpenGLContext::setShareContext(QOpenGLContext *shareContext) } /*! - Sets the screen the GL context should be valid for. You need to call create() before it takes effect. + Sets the \a screen the GL context should be valid for. You need to call + create() before it takes effect. */ void QOpenGLContext::setScreen(QScreen *screen) { @@ -159,9 +251,15 @@ void QOpenGLContext::setScreen(QScreen *screen) } /*! - Attempts to create the GL context with the desired parameters. + Attempts to create the OpenGL context with the current configuration. + + The current configuration includes the format, the share context, and the + screen. - Returns true if the native context was successfully created and is ready to be used. + Returns true if the native context was successfully created and is ready to + be used with makeCurrent(), swapBuffers(), etc. + + \sa makeCurrent(), destroy() */ bool QOpenGLContext::create() { @@ -179,6 +277,22 @@ bool QOpenGLContext::create() return d->platformGLContext; } +/*! + Destroy the underlying platform context associated with this context. + + If any other context is directly or indirectly sharing resources with this + context, the shared resources, which includes vertex buffer objects, shader + objects, textures, and framebuffer objects, are not freed. However, + destroying the underlying platform context frees any state associated with + the context. + + After destroy() has been called, you must call create() if you wish to + use the context again. + + \note This implicitly calls doneCurrent() if the context is current. + + \sa create() +*/ void QOpenGLContext::destroy() { Q_D(QOpenGLContext); @@ -199,15 +313,20 @@ void QOpenGLContext::destroy() \fn void QOpenGLContext::aboutToBeDestroyed() This signal is emitted before the underlying native OpenGL context is - destroyed, such that users may clean up OpenGL resources that might otherwise - be left dangling in the case of shared OpenGL contexts. + destroyed, such that users may clean up OpenGL resources that might + otherwise be left dangling in the case of shared OpenGL contexts. - If you wish to make the context current in order to do clean-up, make sure to - only connect to the signal using a direct connection. + If you wish to make the context current in order to do clean-up, make sure + to only connect to the signal using a direct connection. */ /*! - If this is the current context for the thread, doneCurrent is called + Destroys the QOpenGLContext object. + + This implicitly calls destroy(), so if this is the current context for the + thread, doneCurrent() is also called. + + \sa destroy() */ QOpenGLContext::~QOpenGLContext() { @@ -219,7 +338,9 @@ QOpenGLContext::~QOpenGLContext() } /*! - Returns if this context is valid, i.e. has been successfully created. + Returns if this context is valid, i.e. has been successfully created. + + \sa create() */ bool QOpenGLContext::isValid() const { @@ -228,11 +349,13 @@ bool QOpenGLContext::isValid() const } /*! - Get the QOpenGLFunctions instance for this context. + Get the QOpenGLFunctions instance for this context. - The context or a sharing context must be current. -*/ + QOpenGLContext offers this as a convenient way to access QOpenGLFunctions + without having to manage it manually. + The context or a sharing context must be current. +*/ QOpenGLFunctions *QOpenGLContext::functions() const { Q_D(const QOpenGLContext); @@ -242,15 +365,17 @@ QOpenGLFunctions *QOpenGLContext::functions() const } /*! - Call this to get the default framebuffer object for the current surface. + Call this to get the default framebuffer object for the current surface. - On some platforms the default framebuffer object depends on the surface being rendered to, - and might be different from 0. Thus, instead of calling glBindFramebuffer(0), you should - call glBindFramebuffer(ctx->defaultFramebufferObject()) if you want your application to - work across different Qt platforms. + On some platforms the default framebuffer object depends on the surface + being rendered to, and might be different from 0. Thus, instead of calling + glBindFramebuffer(0), you should call + glBindFramebuffer(ctx->defaultFramebufferObject()) if you want your + application to work across different Qt platforms. - If you use the glBindFramebuffer() in QOpenGLFunctions you do not have to worry about this, - as it automatically binds the current context's defaultFramebufferObject() when 0 is passed. + If you use the glBindFramebuffer() in QOpenGLFunctions you do not have to + worry about this, as it automatically binds the current context's + defaultFramebufferObject() when 0 is passed. */ GLuint QOpenGLContext::defaultFramebufferObject() const { @@ -265,12 +390,18 @@ GLuint QOpenGLContext::defaultFramebufferObject() const } /*! - If surface is 0 this is equivalent to calling doneCurrent(). + Makes the context current in the current thread, against the given + \a surface. + + If \a surface is 0 this is equivalent to calling doneCurrent(). - Do not call this function from a different thread than the one the QOpenGLContext instance lives in. If - you wish to use QOpenGLContext from a different thread you should first call make sure it's not current - in the current thread, by calling doneCurrent() if necessary. Then call moveToThread(otherThread) - before using it in the other thread. + Do not call this function from a different thread than the one the + QOpenGLContext instance lives in. If you wish to use QOpenGLContext from a + different thread you should first call make sure it's not current in the + current thread, by calling doneCurrent() if necessary. Then call + moveToThread(otherThread) before using it in the other thread. + + \sa functions(), doneCurrent() */ bool QOpenGLContext::makeCurrent(QSurface *surface) { @@ -313,6 +444,10 @@ bool QOpenGLContext::makeCurrent(QSurface *surface) /*! Convenience function for calling makeCurrent with a 0 surface. + + This results in no context being current in the current thread. + + \sa makeCurrent(), currentContext() */ void QOpenGLContext::doneCurrent() { @@ -330,7 +465,9 @@ void QOpenGLContext::doneCurrent() } /*! - Returns the surface the context is current for. + Returns the surface the context has been made current with. + + This is the surface passed as an argument to makeCurrent(). */ QSurface *QOpenGLContext::surface() const { @@ -391,6 +528,11 @@ void QOpenGLContext::swapBuffers(QSurface *surface) d->platformGLContext->swapBuffers(surfaceHandle); } +/*! + Resolves the function pointer to an OpenGL extension function, identified by \a procName + + Returns 0 if no such function can be found. +*/ QFunctionPointer QOpenGLContext::getProcAddress(const QByteArray &procName) { Q_D(QOpenGLContext); @@ -399,6 +541,11 @@ QFunctionPointer QOpenGLContext::getProcAddress(const QByteArray &procName) return d->platformGLContext->getProcAddress(procName); } +/*! + Returns the format of the underlying platform context, if create() has been called. + + Otherwise, returns the requested format. +*/ QSurfaceFormat QOpenGLContext::format() const { Q_D(const QOpenGLContext); @@ -407,27 +554,41 @@ QSurfaceFormat QOpenGLContext::format() const return d->platformGLContext->format(); } +/*! + Returns the share group this context belongs to. +*/ QOpenGLContextGroup *QOpenGLContext::shareGroup() const { Q_D(const QOpenGLContext); return d->shareGroup; } +/*! + Returns the share context this context was created with. + + If the underlying platform was not able to support the requested + sharing, this will return 0. +*/ QOpenGLContext *QOpenGLContext::shareContext() const { Q_D(const QOpenGLContext); return d->shareContext; } +/*! + Returns the screen the context was created for. +*/ QScreen *QOpenGLContext::screen() const { Q_D(const QOpenGLContext); return d->screen; } -/* - internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant - have any type information. +/*! + internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant + have any type information. + + \internal */ void *QOpenGLContext::qGLContextHandle() const { @@ -435,6 +596,9 @@ void *QOpenGLContext::qGLContextHandle() const return d->qGLContextHandle; } +/*! + \internal +*/ void QOpenGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)) { Q_D(QOpenGLContext); @@ -442,6 +606,9 @@ void QOpenGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFun d->qGLContextDeleteFunction = qGLContextDeleteFunction; } +/*! + \internal +*/ void QOpenGLContext::deleteQGLContext() { Q_D(QOpenGLContext); @@ -452,23 +619,45 @@ void QOpenGLContext::deleteQGLContext() } } +/*! + \class QOpenGLContextGroup + \brief The QOpenGLContextGroup represents a group of contexts sharing + OpenGL resources. + + QOpenGLContextGroup is automatically created and managed by QOpenGLContext + instances. Its purpose is to identify all the contexts that are sharing + resources. + + \sa QOpenGLContext::shareGroup() +*/ QOpenGLContextGroup::QOpenGLContextGroup() : QObject(*new QOpenGLContextGroupPrivate()) { } +/*! + \internal +*/ QOpenGLContextGroup::~QOpenGLContextGroup() { Q_D(QOpenGLContextGroup); d->cleanup(); } +/*! + Returns all the QOpenGLContext objects in this share group. +*/ QList QOpenGLContextGroup::shares() const { Q_D(const QOpenGLContextGroup); return d->m_shares; } +/*! + Returns the QOpenGLContextGroup corresponding to the current context. + + \sa QOpenGLContext::currentContext() +*/ QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup() { QOpenGLContext *current = QOpenGLContext::currentContext(); @@ -544,9 +733,10 @@ void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx) \class QOpenGLSharedResource \internal \since 5.0 - \brief The QOpenGLSharedResource class is used to keep track of resources that - are shared between OpenGL contexts (like textures, framebuffer objects, shader - programs, etc), and clean them up in a safe way when they're no longer needed. + \brief The QOpenGLSharedResource class is used to keep track of resources + that are shared between OpenGL contexts (like textures, framebuffer + objects, shader programs, etc), and clean them up in a safe way when + they're no longer needed. The QOpenGLSharedResource instance should never be deleted, instead free() should be called when it's no longer needed. Thus it will be put on a queue @@ -556,11 +746,11 @@ void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx) The sub-class needs to implement two pure virtual functions. The first, freeResource() must be implemented to actually do the freeing, for example call glDeleteTextures() on a texture id. Qt makes sure a valid context in - the resource's share group is current at the time. The other, invalidateResource(), - is called by Qt in the circumstance when the last context in the share group is - destroyed before free() has been called. The implementation of invalidateResource() - should set any identifiers to 0 or set a flag to prevent them from being used - later on. + the resource's share group is current at the time. The other, + invalidateResource(), is called by Qt in the circumstance when the last + context in the share group is destroyed before free() has been called. The + implementation of invalidateResource() should set any identifiers to 0 or + set a flag to prevent them from being used later on. */ QOpenGLSharedResource::QOpenGLSharedResource(QOpenGLContextGroup *group) : m_group(group) @@ -616,9 +806,9 @@ void QOpenGLSharedResourceGuard::freeResource(QOpenGLContext *context) \since 5.0 \brief The QOpenGLMultiGroupSharedResource keeps track of a shared resource that might be needed from multiple contexts, like a glyph cache or gradient - cache. One instance of the object is created for each group when - necessary. The shared resource instance should have a constructor that - takes a QOpenGLContext *. To get an instance for a given context one calls + cache. One instance of the object is created for each group when necessary. + The shared resource instance should have a constructor that takes a + QOpenGLContext *. To get an instance for a given context one calls T *QOpenGLMultiGroupSharedResource::value(context), where T is a sub-class of QOpenGLSharedResource. -- cgit v1.2.3 From b2c37a81382219b0e1479d30ad4fb57deddd52bf Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Mon, 20 Feb 2012 22:17:11 +0100 Subject: improve documentation language style Change-Id: Ic7daa90fff764578bd8122986a73c2ea6280e784 Reviewed-by: Robin Burchell --- src/sql/models/qsqltablemodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 932bbbfd6b..5c84dda1d9 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -659,7 +659,7 @@ bool QSqlTableModel::deleteRowFromTable(int row) Note: In OnManualSubmit mode, already submitted changes won't be cleared from the cache when submitAll() fails. This allows - transactions to be rolled back and resubmitted again without + transactions to be rolled back and resubmitted without losing data. \sa revertAll(), lastError() -- cgit v1.2.3 From 083af1b8cf9e9c805ec41c675728d644d6890578 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Thu, 16 Feb 2012 14:21:07 +0100 Subject: QSqlTableModel: document edit strategy behavior Change-Id: Ib674288e950837aa343cf1206ed081386b1fff0d Reviewed-by: Robin Burchell --- src/sql/models/qsqltablemodel.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 5c84dda1d9..309c01d7ee 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -1050,6 +1050,8 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent) Returns false if the parameters are out of bounds; otherwise returns true. + Does not submit rows, regardless of edit strategy, not even OnFieldChange. + \sa primeInsert(), insertRecord() */ bool QSqlTableModel::insertRows(int row, int count, const QModelIndex &parent) @@ -1097,7 +1099,11 @@ bool QSqlTableModel::insertRows(int row, int count, const QModelIndex &parent) Returns true if the record could be inserted, otherwise false. - \sa insertRows(), removeRows() + Changes are submitted immediately for OnFieldChange and + OnRowChange. Note the contrast with setRecord() in respect to + OnRowChange. + + \sa insertRows(), removeRows(), setRecord() */ bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record) { @@ -1210,7 +1216,13 @@ Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const Returns true if all the values could be set; otherwise returns false. - \sa record() + The edit strategy affects automatic submitting. + With OnFieldChange, setRecord() commits its changed row. + With OnRowChange, setRecord() does not commit its changed row, + but making a change to another row causes previous changes to + be submitted. + + \sa record(), editStrategy() */ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record) { -- cgit v1.2.3 From 5d516234bef7bf9d86cb1dbb1cddeb7e4c8fc8ec Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 15 Feb 2012 15:05:28 +0100 Subject: fix style Change-Id: I8ad0b4d15484662be7b38daa797a688727377c88 Reviewed-by: Robin Burchell --- src/sql/models/qsqltablemodel.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 309c01d7ee..f30352e2fe 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -513,10 +513,9 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in QSqlTableModelPrivate::ModifiedRow &row = d->cache[index.row()]; - if (row.op() == QSqlTableModelPrivate::None) { + if (row.op() == QSqlTableModelPrivate::None) row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, d->rec); - } row.setValue(index.column(), value); emit dataChanged(index, index); -- cgit v1.2.3 From 3a863280dc7f1845bf3daa74fe235b1df9bc26ae Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 15 Feb 2012 10:22:15 +0100 Subject: QSqlTableModel: avoid extra QMap lookup The consensus on #qt-labs seems to be that there is little or no point in checking with contains() before using value(), even if the map does not contain the key in most cases. Change-Id: I34740a91d5c3af65e20937a5ae3b4bab32406440 Reviewed-by: Robin Burchell --- src/sql/models/qsqltablemodel.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index f30352e2fe..0cb7c3921b 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -439,13 +439,11 @@ QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, in { Q_D(const QSqlTableModel); if (orientation == Qt::Vertical && role == Qt::DisplayRole) { - if (d->cache.contains(section)) { - const QSqlTableModelPrivate::Op op = d->cache.value(section).op(); - if (op == QSqlTableModelPrivate::Insert) - return QLatin1String("*"); - else if (op == QSqlTableModelPrivate::Delete) - return QLatin1String("!"); - } + const QSqlTableModelPrivate::Op op = d->cache.value(section).op(); + if (op == QSqlTableModelPrivate::Insert) + return QLatin1String("*"); + else if (op == QSqlTableModelPrivate::Delete) + return QLatin1String("!"); } return QSqlQueryModel::headerData(section, orientation, role); } -- cgit v1.2.3 From 3d763dc83adce6fc270c17933fd66ae5c539517c Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 15 Feb 2012 01:31:07 +0100 Subject: QSqlTableModel: rename parameter to avoid name clash with method Change-Id: Ib8fa6b0ca71ffdd9f1f8416c448b5c830988ed08 Reviewed-by: Robin Burchell --- src/sql/models/qsqltablemodel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 0cb7c3921b..c895c39212 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -1221,7 +1221,7 @@ Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const \sa record(), editStrategy() */ -bool QSqlTableModel::setRecord(int row, const QSqlRecord &record) +bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) { Q_D(QSqlTableModel); Q_ASSERT_X(row >= 0, "QSqlTableModel::setRecord()", "Cannot set a record to a row less than 0"); @@ -1239,9 +1239,9 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record) // Check field names and remember mapping typedef QMap Map; Map map; - for (int i = 0; i < record.count(); ++i) { - if (record.isGenerated(i)) { - int idx = d->nameToIndex(record.fieldName(i)); + for (int i = 0; i < values.count(); ++i) { + if (values.isGenerated(i)) { + int idx = d->nameToIndex(values.fieldName(i)); if (idx == -1) return false; map[i] = idx; @@ -1256,7 +1256,7 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record) Map::const_iterator i = map.constBegin(); const Map::const_iterator e = map.constEnd(); for ( ; i != e; ++i) - mrow.setValue(i.value(), record.value(i.key())); + mrow.setValue(i.value(), values.value(i.key())); if (columnCount()) emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1)); -- cgit v1.2.3 From bd5096d012327d4acb44449464cb00c488450cc5 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 23 Feb 2012 17:05:41 +0100 Subject: Add the QtMain windows library to the CMake files. Change-Id: Iff8b9bdd4b069721103e1cd5854e56b6116d7549 Reviewed-by: Andreas Holzammer Reviewed-by: Oswald Buddenhagen Reviewed-by: Alexander Neundorf Reviewed-by: Stephen Kelly --- src/corelib/Qt5CoreConfigExtras.cmake.in | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index 4b5ac73bce..4873391f52 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -20,3 +20,26 @@ list(APPEND Qt5Core_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE) !!IF !isEmpty(QT_LIBINFIX) set(QT_LIBINFIX \"$${QT_LIBINFIX}\") !!ENDIF + +!!IF !isEmpty(CMAKE_WINDOWS_BUILD) +set(Qt5Core_QTMAIN_LIBRARIES Qt5::WinMain) + +if (NOT _Qt5WinMain_target) + set(_Qt5WinMain_target 1) + add_library(Qt5::WinMain STATIC IMPORTED) +endif() + +!!IF !isEmpty(debug_type) +set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) +set_target_properties(Qt5::WinMain PROPERTIES + IMPORTED_LOCATION_DEBUG "${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}" +) +!!ENDIF + +!!IF !isEmpty(release_type) +set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) +set_target_properties(Qt5::WinMain PROPERTIES + IMPORTED_LOCATION_RELEASE \"${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\" +) +!!ENDIF +!!ENDIF -- cgit v1.2.3 From d91cf1e53b450483d92c50965fd3c33ab1da4300 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 21 Feb 2012 16:09:30 +0100 Subject: clean up qmake-generated projects remove "header" and assignmets which are defaults or bogus, reorder some assignments. Change-Id: I67403872168c890ca3b696753ceb01c605d19be7 Reviewed-by: Rohan McGovern --- src/testlib/testlib.pro | 1 - src/tools/moc/util/generate_keywords.pro | 8 -------- 2 files changed, 9 deletions(-) (limited to 'src') diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro index 26769f95db..2f5b3229e4 100644 --- a/src/testlib/testlib.pro +++ b/src/testlib/testlib.pro @@ -13,7 +13,6 @@ unix:!embedded:QMAKE_PKGCONFIG_DESCRIPTION = Qt \ Testing \ Library -# Input HEADERS = qbenchmark.h \ qsignalspy.h \ qtestaccessible.h \ diff --git a/src/tools/moc/util/generate_keywords.pro b/src/tools/moc/util/generate_keywords.pro index eb04409922..88e5553f54 100644 --- a/src/tools/moc/util/generate_keywords.pro +++ b/src/tools/moc/util/generate_keywords.pro @@ -1,12 +1,4 @@ -###################################################################### -# Automatically generated by qmake (1.08a) Mon Feb 23 13:08:28 2004 -###################################################################### - -TEMPLATE = app CONFIG -= moc mac:CONFIG -= app_bundle -INCLUDEPATH += . -# Input SOURCES += generate_keywords.cpp -CONFIG += qt create_prl link_prl -- cgit v1.2.3 From 4df6e058490b4202a5bb5ac0a34b7b2b18493250 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Wed, 22 Feb 2012 11:41:28 -0800 Subject: Clean up some Q_WS_WIN Q_WS_WIN does not exist any more. Change-Id: Icb7f542cfcd4d21e994f246ff665583cb6b57610 Reviewed-by: Oswald Buddenhagen Reviewed-by: Friedemann Kleint --- src/sql/drivers/sqlite2/qsql_sqlite2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp index b42f82e800..2ffd88e8c5 100644 --- a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp +++ b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp @@ -53,7 +53,7 @@ #include #include -#if !defined Q_WS_WIN32 +#if !defined Q_OS_WIN # include #endif #include @@ -208,7 +208,7 @@ bool QSQLite2ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int // keep trying while busy, wish I could implement this better. while ((res = sqlite_step(currentMachine, &colNum, &fvals, &cnames)) == SQLITE_BUSY) { // sleep instead requesting result again immidiately. -#if defined Q_WS_WIN32 +#if defined Q_OS_WIN Sleep(1000); #else sleep(1); -- cgit v1.2.3 From bb5c7b75a87ec87218d489313ffc5a2b9cb4e3d5 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 24 Feb 2012 18:30:40 +1000 Subject: XCB No longer lists ThreadedOpenGL capability Even with the more recent libxcb, it's a bit flaky. Just don't list having this capability until it is more stable. Change-Id: I1c2b39d757803fc23295944bc9a00e39ff4e1bbf Reviewed-by: Gunnar Sletta --- src/plugins/platforms/xcb/qxcbintegration.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index e7cdef4da9..98f69e9e16 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -204,12 +204,7 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const case ThreadedPixmaps: return true; case OpenGL: return true; - case ThreadedOpenGL: -#ifdef XCB_POLL_FOR_QUEUED_EVENT - return true; -#else - return false; -#endif + case ThreadedOpenGL: return false; default: return QPlatformIntegration::hasCapability(cap); } } -- cgit v1.2.3 From 9610458e0c460fc9a478678528fdb406b6d0f8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 21 Feb 2012 13:24:39 +0100 Subject: Use "OpenGL" instead of just "GL" in documentation. Change-Id: I81a0beebc0241b9699ce321174e13a93e76e45e8 Reviewed-by: Gunnar Sletta --- src/gui/kernel/qopenglcontext.cpp | 2 +- src/gui/opengl/qopenglbuffer.cpp | 44 ++++++++++++++--------------- src/gui/opengl/qopenglframebufferobject.cpp | 22 +++++++-------- src/gui/opengl/qopenglfunctions.cpp | 2 +- src/gui/opengl/qopenglpaintdevice.cpp | 6 ++-- 5 files changed, 38 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index c263a2a84e..f9ebf8820c 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -239,7 +239,7 @@ void QOpenGLContext::setShareContext(QOpenGLContext *shareContext) } /*! - Sets the \a screen the GL context should be valid for. You need to call + Sets the \a screen the OpenGL context should be valid for. You need to call create() before it takes effect. */ void QOpenGLContext::setScreen(QScreen *screen) diff --git a/src/gui/opengl/qopenglbuffer.cpp b/src/gui/opengl/qopenglbuffer.cpp index e6879a9e60..f47f71c121 100644 --- a/src/gui/opengl/qopenglbuffer.cpp +++ b/src/gui/opengl/qopenglbuffer.cpp @@ -49,16 +49,16 @@ QT_BEGIN_NAMESPACE /*! \class QOpenGLBuffer - \brief The QOpenGLBuffer class provides functions for creating and managing GL buffer objects. + \brief The QOpenGLBuffer class provides functions for creating and managing OpenGL buffer objects. \since 5.0 \ingroup painting-3D - Buffer objects are created in the GL server so that the + Buffer objects are created in the OpenGL server so that the client application can avoid uploading vertices, indices, texture image data, etc every time they are needed. QOpenGLBuffer objects can be copied around as a reference to the - underlying GL buffer object: + underlying OpenGL buffer object: \code QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer); @@ -74,16 +74,16 @@ QT_BEGIN_NAMESPACE /*! \enum QOpenGLBuffer::Type - This enum defines the type of GL buffer object to create with QOpenGLBuffer. + This enum defines the type of OpenGL buffer object to create with QOpenGLBuffer. \value VertexBuffer Vertex buffer object for use when specifying vertex arrays. \value IndexBuffer Index buffer object for use with \c{glDrawElements()}. \value PixelPackBuffer Pixel pack buffer object for reading pixel - data from the GL server (for example, with \c{glReadPixels()}). + data from the OpenGL server (for example, with \c{glReadPixels()}). Not supported under OpenGL/ES. \value PixelUnpackBuffer Pixel unpack buffer object for writing pixel - data to the GL server (for example, with \c{glTexImage2D()}). + data to the OpenGL server (for example, with \c{glTexImage2D()}). Not supported under OpenGL/ES. */ @@ -95,26 +95,26 @@ QT_BEGIN_NAMESPACE for drawing operations. Under OpenGL/ES 1.1 this is identical to StaticDraw. \value StreamRead The data will be set once and used a few times - for reading data back from the GL server. Not supported + for reading data back from the OpenGL server. Not supported under OpenGL/ES. \value StreamCopy The data will be set once and used a few times - for reading data back from the GL server for use in further + for reading data back from the OpenGL server for use in further drawing operations. Not supported under OpenGL/ES. \value StaticDraw The data will be set once and used many times for drawing operations. \value StaticRead The data will be set once and used many times - for reading data back from the GL server. Not supported + for reading data back from the OpenGL server. Not supported under OpenGL/ES. \value StaticCopy The data will be set once and used many times - for reading data back from the GL server for use in further + for reading data back from the OpenGL server for use in further drawing operations. Not supported under OpenGL/ES. \value DynamicDraw The data will be modified repeatedly and used many times for drawing operations. \value DynamicRead The data will be modified repeatedly and used - many times for reading data back from the GL server. + many times for reading data back from the OpenGL server. Not supported under OpenGL/ES. \value DynamicCopy The data will be modified repeatedly and used - many times for reading data back from the GL server for + many times for reading data back from the OpenGL server for use in further drawing operations. Not supported under OpenGL/ES. */ @@ -152,7 +152,7 @@ public: Constructs a new buffer object of type QOpenGLBuffer::VertexBuffer. Note: this constructor just creates the QOpenGLBuffer instance. The actual - buffer object in the GL server is not created until create() is called. + buffer object in the OpenGL server is not created until create() is called. \sa create() */ @@ -165,7 +165,7 @@ QOpenGLBuffer::QOpenGLBuffer() Constructs a new buffer object of \a type. Note: this constructor just creates the QOpenGLBuffer instance. The actual - buffer object in the GL server is not created until create() is called. + buffer object in the OpenGL server is not created until create() is called. \sa create() */ @@ -188,7 +188,7 @@ QOpenGLBuffer::QOpenGLBuffer(const QOpenGLBuffer &other) /*! Destroys this buffer object, including the storage being - used in the GL server. + used in the OpenGL server. */ QOpenGLBuffer::~QOpenGLBuffer() { @@ -256,14 +256,14 @@ namespace { } /*! - Creates the buffer object in the GL server. Returns true if + Creates the buffer object in the OpenGL server. Returns true if the object was created; false otherwise. This function must be called with a current QOpenGLContext. The buffer will be bound to and can only be used in that context (or any other context that is shared with it). - This function will return false if the GL implementation + This function will return false if the OpenGL implementation does not support buffers, or there is no current QOpenGLContext. \sa isCreated(), allocate(), write(), destroy() @@ -303,7 +303,7 @@ bool QOpenGLBuffer::isCreated() const /*! Destroys this buffer object, including the storage being - used in the GL server. All references to the buffer will + used in the OpenGL server. All references to the buffer will become invalid. */ void QOpenGLBuffer::destroy() @@ -398,8 +398,8 @@ void QOpenGLBuffer::allocate(const void *data, int count) /*! Binds the buffer associated with this object to the current - GL context. Returns false if binding was not possible, usually because - type() is not supported on this GL implementation. + OpenGL context. Returns false if binding was not possible, usually because + type() is not supported on this OpenGL implementation. The buffer must be bound to the same QOpenGLContext current when create() was called, or to another QOpenGLContext that is sharing with it. @@ -431,7 +431,7 @@ bool QOpenGLBuffer::bind() /*! Releases the buffer associated with this object from the - current GL context. + current OpenGL context. This function must be called with the same QOpenGLContext current as when bind() was called on the buffer. @@ -470,7 +470,7 @@ void QOpenGLBuffer::release(QOpenGLBuffer::Type type) } /*! - Returns the GL identifier associated with this buffer; zero if + Returns the OpenGL identifier associated with this buffer; zero if the buffer has not been created. \sa isCreated() diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 0eb264b2d9..a523cd2cf1 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE { \ GLenum err = glGetError(); \ if (err != GL_NO_ERROR) { \ - qDebug("[%s line %d] GL Error: %d", \ + qDebug("[%s line %d] OpenGL Error: %d", \ __FILE__, __LINE__, (int)err); \ } \ } @@ -649,13 +649,13 @@ void QOpenGLFramebufferObjectPrivate::initAttachments(QOpenGLContext *ctx, QOpen The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object, defined by the \c{GL_EXT_framebuffer_object} extension. In addition it provides a rendering surface that can be painted on - with a QPainter, rendered to using native GL calls, or both. This - surface can be bound and used as a regular texture in your own GL + with a QPainter, rendered to using native OpenGL calls, or both. This + surface can be bound and used as a regular texture in your own OpenGL drawing code. By default, the QOpenGLFramebufferObject class - generates a 2D GL texture (using the \c{GL_TEXTURE_2D} target), + generates a 2D OpenGL texture (using the \c{GL_TEXTURE_2D} target), which is used as the internal rendering target. - \bold{It is important to have a current GL context when creating a + \bold{It is important to have a current OpenGL context when creating a QOpenGLFramebufferObject, otherwise initialization will fail.} When using a QPainter to paint to a QOpenGLFramebufferObject you should take @@ -708,11 +708,11 @@ void QOpenGLFramebufferObjectPrivate::initAttachments(QOpenGLContext *ctx, QOpen /*! \fn QOpenGLFramebufferObject::QOpenGLFramebufferObject(const QSize &size, GLenum target) - Constructs an OpenGL framebuffer object and binds a 2D GL texture + Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the size \a size. The texture is bound to the \c GL_COLOR_ATTACHMENT0 target in the framebuffer object. - The \a target parameter is used to specify the GL texture + The \a target parameter is used to specify the OpenGL texture target. The default target is \c GL_TEXTURE_2D. Keep in mind that \c GL_TEXTURE_2D textures must have a power of 2 width and height (e.g. 256x512), unless you are using OpenGL 2.0 or higher. @@ -723,7 +723,7 @@ void QOpenGLFramebufferObjectPrivate::initAttachments(QOpenGLContext *ctx, QOpen The default internal texture format is \c GL_RGBA8 for desktop OpenGL, and \c GL_RGBA for OpenGL/ES. - It is important that you have a current GL context set when + It is important that you have a current OpenGL context set when creating the QOpenGLFramebufferObject, otherwise the initialization will fail. @@ -739,7 +739,7 @@ QOpenGLFramebufferObject::QOpenGLFramebufferObject(const QSize &size, GLenum tar /*! \overload - Constructs an OpenGL framebuffer object and binds a 2D GL texture + Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the given \a width and \a height. \sa size(), texture() @@ -931,7 +931,7 @@ bool QOpenGLFramebufferObject::release() Returns the texture id for the texture attached as the default rendering target in this framebuffer object. This texture id can - be bound as a normal texture in your own GL code. + be bound as a normal texture in your own OpenGL code. If a multisample framebuffer object is used then the value returned from this function will be invalid. @@ -1109,7 +1109,7 @@ bool QOpenGLFramebufferObject::hasOpenGLFramebufferObjects() /*! \fn GLuint QOpenGLFramebufferObject::handle() const - Returns the GL framebuffer object handle for this framebuffer + Returns the OpenGL framebuffer object handle for this framebuffer object (returned by the \c{glGenFrameBuffersEXT()} function). This handle can be used to attach new images or buffers to the framebuffer. The user is responsible for cleaning up and diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp index 13f91e2ad8..c2e177c162 100644 --- a/src/gui/opengl/qopenglfunctions.cpp +++ b/src/gui/opengl/qopenglfunctions.cpp @@ -421,7 +421,7 @@ bool QOpenGLExtensions::hasOpenGLExtension(QOpenGLExtensions::OpenGLExtension ex } /*! - Initializes GL function resolution for the current context. + Initializes OpenGL function resolution for the current context. After calling this function, the QOpenGLFunctions object can only be used with the current context and other contexts that share with it. diff --git a/src/gui/opengl/qopenglpaintdevice.cpp b/src/gui/opengl/qopenglpaintdevice.cpp index 118fe63122..32da27a078 100644 --- a/src/gui/opengl/qopenglpaintdevice.cpp +++ b/src/gui/opengl/qopenglpaintdevice.cpp @@ -63,10 +63,10 @@ QT_BEGIN_NAMESPACE \ingroup painting-3D When painting to a QOpenGLPaintDevice using QPainter, the state of - the current GL context will be altered by the paint engine to reflect - its needs. Applications should not rely upon the GL state being reset + the current OpenGL context will be altered by the paint engine to reflect + its needs. Applications should not rely upon the OpenGL state being reset to its original conditions, particularly the current shader program, - GL viewport, texture units, and drawing modes. + OpenGL viewport, texture units, and drawing modes. */ class QOpenGLPaintDevicePrivate -- cgit v1.2.3 From 7b4e718b849b20b4dc98fa2e14c7f541ee36fc15 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Tue, 14 Feb 2012 13:09:46 +0100 Subject: Add UDev helper class for evdev plugins Adopt evdevkeyboard plugin to use new UDev helper Change-Id: Ie914c77dde9a28a8cf7f7cd972acd963c13bc698 Reviewed-by: Laszlo Agocs --- src/platformsupport/udev/qudevhelper_p.h | 1 + src/platformsupport/udev/qudevicehelper.cpp | 235 +++++++++++++++++++++ src/platformsupport/udev/qudevicehelper_p.h | 98 +++++++++ src/platformsupport/udev/udev.pri | 4 +- .../generic/evdevkeyboard/evdevkeyboard.pro | 2 +- .../evdevkeyboard/qevdevkeyboardmanager.cpp | 188 ++++------------- .../generic/evdevkeyboard/qevdevkeyboardmanager.h | 21 +- 7 files changed, 379 insertions(+), 170 deletions(-) create mode 100644 src/platformsupport/udev/qudevicehelper.cpp create mode 100644 src/platformsupport/udev/qudevicehelper_p.h (limited to 'src') diff --git a/src/platformsupport/udev/qudevhelper_p.h b/src/platformsupport/udev/qudevhelper_p.h index e6046ca085..3895da87b6 100644 --- a/src/platformsupport/udev/qudevhelper_p.h +++ b/src/platformsupport/udev/qudevhelper_p.h @@ -43,6 +43,7 @@ #define QUDEVHELPER_P_H #include +#include QT_BEGIN_NAMESPACE diff --git a/src/platformsupport/udev/qudevicehelper.cpp b/src/platformsupport/udev/qudevicehelper.cpp new file mode 100644 index 0000000000..bf3ce67b43 --- /dev/null +++ b/src/platformsupport/udev/qudevicehelper.cpp @@ -0,0 +1,235 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qudevicehelper_p.h" + +#include +#include +#include +#include +#include + +#include + +//#define QT_QPA_UDEVICE_HELPER_DEBUG + +#ifdef QT_QPA_UDEVICE_HELPER_DEBUG +#include +#endif + +QT_BEGIN_NAMESPACE + +QUDeviceHelper *QUDeviceHelper::createUDeviceHelper(QUDeviceTypes types, QObject *parent) +{ +#ifdef QT_QPA_UDEVICE_HELPER_DEBUG + qWarning() << "Try to create new UDeviceHelper"; +#endif + + QUDeviceHelper *helper = 0; + struct udev *udev; + + udev = udev_new(); + if (udev) { + helper = new QUDeviceHelper(types, udev, parent); + } else { + qWarning("Failed to get udev library context."); + } + + return helper; +} + +QUDeviceHelper::QUDeviceHelper(QUDeviceTypes types, struct udev *udev, QObject *parent) : + QObject(parent), + m_udev(udev), m_types(types), m_udevMonitor(0), m_udevMonitorFileDescriptor(-1), m_udevSocketNotifier(0) +{ +#ifdef QT_QPA_UDEVICE_HELPER_DEBUG + qWarning() << "New UDeviceHelper created for type" << types; +#endif + + if (!m_udev) + return; + + m_udevMonitor = udev_monitor_new_from_netlink(m_udev, "udev"); + if (!m_udevMonitor) { +#ifdef QT_QPA_UDEVICE_HELPER_DEBUG + qWarning("Unable to create an Udev monitor. No devices can be detected."); +#endif + return; + } + + udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "input", 0); + udev_monitor_enable_receiving(m_udevMonitor); + m_udevMonitorFileDescriptor = udev_monitor_get_fd(m_udevMonitor); + + m_udevSocketNotifier = new QSocketNotifier(m_udevMonitorFileDescriptor, QSocketNotifier::Read, this); + connect(m_udevSocketNotifier, SIGNAL(activated(int)), this, SLOT(handleUDevNotification())); +} + +QUDeviceHelper::~QUDeviceHelper() +{ + if (m_udevMonitor) + udev_monitor_unref(m_udevMonitor); + + if (m_udev) + udev_unref(m_udev); +} + +QStringList QUDeviceHelper::scanConnectedDevices() +{ + QStringList devices; + + if (!m_udev) + return devices; + + udev_enumerate *ue = udev_enumerate_new(m_udev); + udev_enumerate_add_match_subsystem(ue, "input"); + + if (m_types & UDev_Mouse) + udev_enumerate_add_match_property(ue, "ID_INPUT_MOUSE", "1"); + if (m_types & UDev_Touchpad) + udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1"); + if (m_types & UDev_Touchscreen) + udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHSCREEN", "1"); + if (m_types & UDev_Keyboard) + udev_enumerate_add_match_property(ue, "ID_INPUT_KEYBOARD", "1"); + + if (udev_enumerate_scan_devices(ue) != 0) { +#ifdef QT_QPA_UDEVICE_HELPER_DEBUG + qWarning() << "UDeviceHelper scan connected devices for enumeration failed"; +#endif + return devices; + } + + udev_list_entry *entry; + udev_list_entry_foreach (entry, udev_enumerate_get_list_entry(ue)) { + const char *syspath = udev_list_entry_get_name(entry); + udev_device *udevice = udev_device_new_from_syspath(m_udev, syspath); + QString candidate = QString::fromUtf8(udev_device_get_devnode(udevice)); + if (candidate.startsWith(QLatin1String("/dev/input/event"))) + devices << candidate; + + udev_device_unref(udevice); + } + udev_enumerate_unref(ue); + +#ifdef QT_QPA_UDEVICE_HELPER_DEBUG + qWarning() << "UDeviceHelper found matching devices" << devices; +#endif + + return devices; +} + +void QUDeviceHelper::handleUDevNotification() +{ + if (!m_udevMonitor) + return; + + struct udev_device *dev; + QString devNode; + QUDeviceTypes types = QFlag(UDev_Unknown); + + dev = udev_monitor_receive_device(m_udevMonitor); + if (!dev) + goto cleanup; + + const char *action; + action = udev_device_get_action(dev); + if (!action) + goto cleanup; + + const char *str; + str = udev_device_get_devnode(dev); + if (!str) + goto cleanup; + + devNode = QString::fromUtf8(str); + if (!devNode.startsWith(QLatin1String("/dev/input/event"))) + goto cleanup; + + // does not increase the refcount + dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", 0); + if (!dev) + goto cleanup; + + types = checkDeviceType(dev); + + if (types && (qstrcmp(action, "add") == 0)) + emit deviceDetected(devNode, types); + + if (types && (qstrcmp(action, "remove") == 0)) + emit deviceRemoved(devNode, types); + +cleanup: + udev_device_unref(dev); +} + +QUDeviceHelper::QUDeviceTypes QUDeviceHelper::checkDeviceType(udev_device *dev) +{ + QUDeviceTypes types = QFlag(UDev_Unknown); + + if ((m_types & UDev_Keyboard) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD"), "1") == 0 )) { + const char *capabilities_key = udev_device_get_sysattr_value(dev, "capabilities/key"); + QStringList val = QString::fromUtf8(capabilities_key).split(QString::fromUtf8(" "), QString::SkipEmptyParts); + if (!val.isEmpty()) { + bool ok; + unsigned long long keys = val.last().toULongLong(&ok, 16); + if (ok) { + // Tests if the letter Q is valid for the device. We may want to alter this test, but it seems mostly reliable. + bool test = (keys >> KEY_Q) & 1; + if (test) + types |= UDev_Keyboard; + } + } + } + + if ((m_types & UDev_Mouse) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_MOUSE"), "1") == 0)) + types |= UDev_Mouse; + + if ((m_types & UDev_Touchpad) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD"), "1") == 0)) + types |= UDev_Touchpad; + + if ((m_types & UDev_Touchscreen) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN"), "1") == 0)) + types |= UDev_Touchscreen; + + return types; +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/udev/qudevicehelper_p.h b/src/platformsupport/udev/qudevicehelper_p.h new file mode 100644 index 0000000000..b7544fa6c2 --- /dev/null +++ b/src/platformsupport/udev/qudevicehelper_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QUDEVICEHELPER_H +#define QUDEVICEHELPER_H + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QUDeviceHelper : public QObject +{ + Q_OBJECT + Q_ENUMS(QUDeviceType) + +public: + enum QUDeviceType { + UDev_Unknown = 0x00, + UDev_Mouse = 0x01, + UDev_Touchpad = 0x02, + UDev_Touchscreen = 0x04, + UDev_Keyboard = 0x08 + }; + Q_DECLARE_FLAGS(QUDeviceTypes, QUDeviceType) + + static QUDeviceHelper *createUDeviceHelper(QUDeviceTypes type, QObject *parent); + ~QUDeviceHelper(); + + QStringList scanConnectedDevices(); + +signals: + void deviceDetected(const QString &deviceNode, QUDeviceTypes types); + void deviceRemoved(const QString &deviceNode, QUDeviceTypes types); + +private slots: + void handleUDevNotification(); + +private: + QUDeviceHelper(QUDeviceTypes types, struct udev *udev, QObject *parent = 0); + + void startWatching(); + void stopWatching(); + + QUDeviceTypes checkDeviceType(struct udev_device *dev); + + struct udev *m_udev; + QUDeviceTypes m_types; + struct udev_monitor *m_udevMonitor; + int m_udevMonitorFileDescriptor; + QSocketNotifier *m_udevSocketNotifier; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QUDeviceHelper::QUDeviceTypes) + +QT_END_NAMESPACE + +#endif // QUDEVICEHELPER_H diff --git a/src/platformsupport/udev/udev.pri b/src/platformsupport/udev/udev.pri index ac3f7df40a..48ad9d36af 100644 --- a/src/platformsupport/udev/udev.pri +++ b/src/platformsupport/udev/udev.pri @@ -1,5 +1,5 @@ contains(QT_CONFIG, libudev) { - HEADERS += $$PWD/qudevhelper_p.h - SOURCES += $$PWD/qudevhelper.cpp + HEADERS += $$PWD/qudevhelper_p.h $$PWD/qudevicehelper_p.h + SOURCES += $$PWD/qudevhelper.cpp $$PWD/qudevicehelper.cpp LIBS += -ludev } diff --git a/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro b/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro index 47608b7154..82edf170a8 100644 --- a/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro +++ b/src/plugins/generic/evdevkeyboard/evdevkeyboard.pro @@ -10,7 +10,7 @@ HEADERS = \ qevdevkeyboardhandler.h \ qevdevkeyboardmanager.h -QT += core-private +QT += core-private platformsupport-private LIBS += -ludev diff --git a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp index cb23d3a49c..0938fdc2e4 100644 --- a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp +++ b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.cpp @@ -42,28 +42,27 @@ #include "qevdevkeyboardmanager.h" #include -#include #include -#include -#include - //#define QT_QPA_KEYMAP_DEBUG +#ifdef QT_QPA_KEYMAP_DEBUG +#include +#endif + QT_BEGIN_NAMESPACE QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString &specification) - : m_udev(0), m_udevMonitor(0), m_udevMonitorFileDescriptor(-1), m_udevSocketNotifier(0) { Q_UNUSED(key); - bool useUDev = false; + bool useUDev = true; QStringList args = specification.split(QLatin1Char(':')); QStringList devices; foreach (const QString &arg, args) { - if (arg.startsWith("udev") && !arg.contains("no")) { - useUDev = true; + if (arg.startsWith("udev") && arg.contains("no")) { + useUDev = false; } else if (arg.startsWith("/dev/")) { // if device is specified try to use it devices.append(arg); @@ -71,182 +70,69 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & } } + // build new specification without /dev/ elements m_spec = args.join(":"); // add all keyboards for devices specified in the argument list foreach (const QString &device, devices) addKeyboard(device); - // no udev and no devices specified, try a fallback - if (!useUDev && devices.isEmpty()) { - addKeyboard(); - return; - } + if (useUDev) { +#ifdef QT_QPA_KEYMAP_DEBUG + qWarning() << "Use UDev for device discovery"; +#endif + + m_udeviceHelper = QUDeviceHelper::createUDeviceHelper(QUDeviceHelper::UDev_Keyboard, this); + if (m_udeviceHelper) { + // scan and add already connected keyboards + QStringList devices = m_udeviceHelper->scanConnectedDevices(); + foreach (QString device, devices) { + addKeyboard(device); + } - m_udev = udev_new(); - if (!m_udev) { - qWarning() << "Failed to read udev configuration. Try to open a keyboard without it"; - addKeyboard(); - } else { - // Look for already attached devices: - parseConnectedDevices(); - // Watch for device add/remove - startWatching(); + connect(m_udeviceHelper, SIGNAL(deviceDetected(QString,QUDeviceTypes)), this, SLOT(addKeyboard(QString))); + connect(m_udeviceHelper, SIGNAL(deviceRemoved(QString,QUDeviceTypes)), this, SLOT(removeKeyboard(QString))); + } } } QEvdevKeyboardManager::~QEvdevKeyboardManager() { - // cleanup udev related resources - stopWatching(); - if (m_udev) - udev_unref(m_udev); - - // cleanup all resources of connected keyboards qDeleteAll(m_keyboards); m_keyboards.clear(); } -void QEvdevKeyboardManager::addKeyboard(const QString &devnode) +void QEvdevKeyboardManager::addKeyboard(const QString &deviceNode) { +#ifdef QT_QPA_KEYMAP_DEBUG + qWarning() << "Adding keyboard at" << deviceNode; +#endif + QString specification = m_spec; - QString deviceString = devnode; - if (!deviceString.isEmpty()) { + if (!deviceNode.isEmpty()) { specification.append(":"); - specification.append(deviceString); - } else { - deviceString = "default"; + specification.append(deviceNode); } -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Adding keyboard at" << deviceString; -#endif - QEvdevKeyboardHandler *keyboard; keyboard = QEvdevKeyboardHandler::createLinuxInputKeyboardHandler("EvdevKeyboard", specification); if (keyboard) - m_keyboards.insert(deviceString, keyboard); + m_keyboards.insert(deviceNode, keyboard); else - qWarning() << "Failed to open keyboard"; + qWarning("Failed to open keyboard"); } -void QEvdevKeyboardManager::removeKeyboard(const QString &devnode) +void QEvdevKeyboardManager::removeKeyboard(const QString &deviceNode) { - if (m_keyboards.contains(devnode)) { + if (m_keyboards.contains(deviceNode)) { #ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Removing keyboard at" << devnode; + qWarning() << "Removing keyboard at" << deviceNode; #endif - QEvdevKeyboardHandler *keyboard = m_keyboards.value(devnode); - m_keyboards.remove(devnode); + QEvdevKeyboardHandler *keyboard = m_keyboards.value(deviceNode); + m_keyboards.remove(deviceNode); delete keyboard; } } -void QEvdevKeyboardManager::startWatching() -{ - m_udevMonitor = udev_monitor_new_from_netlink(m_udev, "udev"); - if (!m_udevMonitor) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning("Unable to create an Udev monitor. No devices can be detected."); -#endif - return; - } - - udev_monitor_filter_add_match_subsystem_devtype(m_udevMonitor, "input", NULL); - udev_monitor_enable_receiving(m_udevMonitor); - m_udevMonitorFileDescriptor = udev_monitor_get_fd(m_udevMonitor); - - m_udevSocketNotifier = new QSocketNotifier(m_udevMonitorFileDescriptor, QSocketNotifier::Read, this); - connect(m_udevSocketNotifier, SIGNAL(activated(int)), this, SLOT(deviceDetected())); -} - -void QEvdevKeyboardManager::stopWatching() -{ - if (m_udevSocketNotifier) - delete m_udevSocketNotifier; - - if (m_udevMonitor) - udev_monitor_unref(m_udevMonitor); - - m_udevSocketNotifier = 0; - m_udevMonitor = 0; - m_udevMonitorFileDescriptor = 0; -} - -void QEvdevKeyboardManager::deviceDetected() -{ - if (!m_udevMonitor) - return; - - struct udev_device *dev; - dev = udev_monitor_receive_device(m_udevMonitor); - if (!dev) - return; - - if (qstrcmp(udev_device_get_action(dev), "add") == 0) { - checkDevice(dev); - } else { - // We can't determine what the device was, so we handle false positives outside of this class - QString str = udev_device_get_devnode(dev); - if (!str.isEmpty()) - removeKeyboard(str); - } - - udev_device_unref(dev); -} - -void QEvdevKeyboardManager::parseConnectedDevices() -{ - struct udev_enumerate *enumerate; - struct udev_list_entry *devices; - struct udev_list_entry *dev_list_entry; - struct udev_device *dev; - const char *str; - - enumerate = udev_enumerate_new(m_udev); - udev_enumerate_add_match_subsystem(enumerate, "input"); - udev_enumerate_scan_devices(enumerate); - devices = udev_enumerate_get_list_entry(enumerate); - - udev_list_entry_foreach(dev_list_entry, devices) { - str = udev_list_entry_get_name(dev_list_entry); - dev = udev_device_new_from_syspath(m_udev, str); - checkDevice(dev); - } - - udev_enumerate_unref(enumerate); -} - -void QEvdevKeyboardManager::checkDevice(udev_device *dev) -{ - const char *str; - QString devnode; - - str = udev_device_get_devnode(dev); - if (!str) - return; - - devnode = str; - - dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", NULL); - if (!dev) - return; - - str = udev_device_get_sysattr_value(dev, "capabilities/key"); - QStringList val = QString(str).split(' ', QString::SkipEmptyParts); - - bool ok; - unsigned long long keys = val.last().toULongLong(&ok, 16); - if (!ok) - return; - - // Tests if the letter Q is valid for the device. We may want to alter this test, but it seems mostly reliable. - bool test = (keys >> KEY_Q) & 1; - if (test) { - addKeyboard(devnode); - return; - } -} - QT_END_NAMESPACE diff --git a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h index 3caed6ff43..c776af2ec5 100644 --- a/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h +++ b/src/plugins/generic/evdevkeyboard/qevdevkeyboardmanager.h @@ -44,12 +44,12 @@ #include "qevdevkeyboardhandler.h" +#include + #include #include #include -#include - QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -62,24 +62,13 @@ public: ~QEvdevKeyboardManager(); private slots: - void deviceDetected(); + void addKeyboard(const QString &deviceNode = QString()); + void removeKeyboard(const QString &deviceNode); private: - void startWatching(); - void stopWatching(); - void parseConnectedDevices(); - void checkDevice(struct udev_device *dev); - - void addKeyboard(const QString &devnode = QString()); - void removeKeyboard(const QString &devnode); - QString m_spec; QHash m_keyboards; - - struct udev *m_udev; - struct udev_monitor *m_udevMonitor; - int m_udevMonitorFileDescriptor; - QSocketNotifier *m_udevSocketNotifier; + QUDeviceHelper *m_udeviceHelper; }; QT_END_HEADER -- cgit v1.2.3 From e5d362f333ca74e4f63d8105b50044841e8fc8cd Mon Sep 17 00:00:00 2001 From: Jonathan Liu Date: Fri, 24 Feb 2012 23:03:49 +1100 Subject: Fix Windows -no-freetype build The localizedName and getEnglishName functions were defined in qwindowsfontdatabase_ft.cpp but used in qwindowsfontdatabase.cpp. However if -no-freetype is specified during configure then qwindowsfontdatabase_ft.cpp is not compiled which results in an undefined reference. To resolve this, the functions are moved to qwindowsfontdatabase.cpp which is always compiled whether -no-freetype is specified or not. Change-Id: I085d84cecb29065ba5e6495b52eef7a678947bdc Reviewed-by: Jiang Jiang --- .../platforms/windows/qwindowsfontdatabase.cpp | 179 +++++++++++++++++++- .../platforms/windows/qwindowsfontdatabase_ft.cpp | 181 +-------------------- 2 files changed, 180 insertions(+), 180 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index 1df985c8a7..fba7794a12 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -329,8 +329,183 @@ static inline QFontDatabase::WritingSystem writingSystemFromScript(const QString return QFontDatabase::Any; } -extern bool localizedName(const QString &name); -extern QString getEnglishName(const QString &familyName); +#ifdef MAKE_TAG +#undef MAKE_TAG +#endif +// GetFontData expects the tags in little endian ;( +#define MAKE_TAG(ch1, ch2, ch3, ch4) (\ + (((quint32)(ch4)) << 24) | \ + (((quint32)(ch3)) << 16) | \ + (((quint32)(ch2)) << 8) | \ + ((quint32)(ch1)) \ + ) + +bool localizedName(const QString &name) +{ + const QChar *c = name.unicode(); + for (int i = 0; i < name.length(); ++i) { + if (c[i].unicode() >= 0x100) + return true; + } + return false; +} + +static inline quint16 getUShort(const unsigned char *p) +{ + quint16 val; + val = *p++ << 8; + val |= *p; + + return val; +} + +static QString getEnglishName(const uchar *table, quint32 bytes) +{ + QString i18n_name; + enum { + NameRecordSize = 12, + FamilyId = 1, + MS_LangIdEnglish = 0x009 + }; + + // get the name table + quint16 count; + quint16 string_offset; + const unsigned char *names; + + int microsoft_id = -1; + int apple_id = -1; + int unicode_id = -1; + + if (getUShort(table) != 0) + goto error; + + count = getUShort(table+2); + string_offset = getUShort(table+4); + names = table + 6; + + if (string_offset >= bytes || 6 + count*NameRecordSize > string_offset) + goto error; + + for (int i = 0; i < count; ++i) { + // search for the correct name entry + + quint16 platform_id = getUShort(names + i*NameRecordSize); + quint16 encoding_id = getUShort(names + 2 + i*NameRecordSize); + quint16 language_id = getUShort(names + 4 + i*NameRecordSize); + quint16 name_id = getUShort(names + 6 + i*NameRecordSize); + + if (name_id != FamilyId) + continue; + + enum { + PlatformId_Unicode = 0, + PlatformId_Apple = 1, + PlatformId_Microsoft = 3 + }; + + quint16 length = getUShort(names + 8 + i*NameRecordSize); + quint16 offset = getUShort(names + 10 + i*NameRecordSize); + if (DWORD(string_offset + offset + length) >= bytes) + continue; + + if ((platform_id == PlatformId_Microsoft + && (encoding_id == 0 || encoding_id == 1)) + && (language_id & 0x3ff) == MS_LangIdEnglish + && microsoft_id == -1) + microsoft_id = i; + // not sure if encoding id 4 for Unicode is utf16 or ucs4... + else if (platform_id == PlatformId_Unicode && encoding_id < 4 && unicode_id == -1) + unicode_id = i; + else if (platform_id == PlatformId_Apple && encoding_id == 0 && language_id == 0) + apple_id = i; + } + { + bool unicode = false; + int id = -1; + if (microsoft_id != -1) { + id = microsoft_id; + unicode = true; + } else if (apple_id != -1) { + id = apple_id; + unicode = false; + } else if (unicode_id != -1) { + id = unicode_id; + unicode = true; + } + if (id != -1) { + quint16 length = getUShort(names + 8 + id*NameRecordSize); + quint16 offset = getUShort(names + 10 + id*NameRecordSize); + if (unicode) { + // utf16 + + length /= 2; + i18n_name.resize(length); + QChar *uc = (QChar *) i18n_name.unicode(); + const unsigned char *string = table + string_offset + offset; + for (int i = 0; i < length; ++i) + uc[i] = getUShort(string + 2*i); + } else { + // Apple Roman + + i18n_name.resize(length); + QChar *uc = (QChar *) i18n_name.unicode(); + const unsigned char *string = table + string_offset + offset; + for (int i = 0; i < length; ++i) + uc[i] = QLatin1Char(string[i]); + } + } + } +error: + //qDebug("got i18n name of '%s' for font '%s'", i18n_name.latin1(), familyName.toLocal8Bit().data()); + return i18n_name; +} + +QString getEnglishName(const QString &familyName) +{ + QString i18n_name; + + HDC hdc = GetDC( 0 ); + LOGFONT lf; + memset(&lf, 0, sizeof(LOGFONT)); + memcpy(lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.length()) * sizeof(wchar_t)); + lf.lfCharSet = DEFAULT_CHARSET; + HFONT hfont = CreateFontIndirect(&lf); + + if (!hfont) { + ReleaseDC(0, hdc); + return QString(); + } + + HGDIOBJ oldobj = SelectObject( hdc, hfont ); + + const DWORD name_tag = MAKE_TAG( 'n', 'a', 'm', 'e' ); + + // get the name table + unsigned char *table = 0; + + DWORD bytes = GetFontData( hdc, name_tag, 0, 0, 0 ); + if ( bytes == GDI_ERROR ) { + // ### Unused variable + // int err = GetLastError(); + goto error; + } + + table = new unsigned char[bytes]; + GetFontData(hdc, name_tag, 0, table, bytes); + if ( bytes == GDI_ERROR ) + goto error; + + i18n_name = getEnglishName(table, bytes); +error: + delete [] table; + SelectObject( hdc, oldobj ); + DeleteObject( hfont ); + ReleaseDC( 0, hdc ); + + //qDebug("got i18n name of '%s' for font '%s'", i18n_name.latin1(), familyName.toLocal8Bit().data()); + return i18n_name; +} Q_GUI_EXPORT void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias); diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp index 031d6ad1a6..e972ae23ee 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp @@ -102,184 +102,6 @@ static inline QFont::Weight weightFromInteger(long weight) return QFont::Black; } -#ifdef MAKE_TAG -#undef MAKE_TAG -#endif -// GetFontData expects the tags in little endian ;( -#define MAKE_TAG(ch1, ch2, ch3, ch4) (\ - (((quint32)(ch4)) << 24) | \ - (((quint32)(ch3)) << 16) | \ - (((quint32)(ch2)) << 8) | \ - ((quint32)(ch1)) \ - ) - -bool localizedName(const QString &name) -{ - const QChar *c = name.unicode(); - for (int i = 0; i < name.length(); ++i) { - if (c[i].unicode() >= 0x100) - return true; - } - return false; -} - -static inline quint16 getUShort(const unsigned char *p) -{ - quint16 val; - val = *p++ << 8; - val |= *p; - - return val; -} - -static QString getEnglishName(const uchar *table, quint32 bytes) -{ - QString i18n_name; - enum { - NameRecordSize = 12, - FamilyId = 1, - MS_LangIdEnglish = 0x009 - }; - - // get the name table - quint16 count; - quint16 string_offset; - const unsigned char *names; - - int microsoft_id = -1; - int apple_id = -1; - int unicode_id = -1; - - if (getUShort(table) != 0) - goto error; - - count = getUShort(table+2); - string_offset = getUShort(table+4); - names = table + 6; - - if (string_offset >= bytes || 6 + count*NameRecordSize > string_offset) - goto error; - - for (int i = 0; i < count; ++i) { - // search for the correct name entry - - quint16 platform_id = getUShort(names + i*NameRecordSize); - quint16 encoding_id = getUShort(names + 2 + i*NameRecordSize); - quint16 language_id = getUShort(names + 4 + i*NameRecordSize); - quint16 name_id = getUShort(names + 6 + i*NameRecordSize); - - if (name_id != FamilyId) - continue; - - enum { - PlatformId_Unicode = 0, - PlatformId_Apple = 1, - PlatformId_Microsoft = 3 - }; - - quint16 length = getUShort(names + 8 + i*NameRecordSize); - quint16 offset = getUShort(names + 10 + i*NameRecordSize); - if (DWORD(string_offset + offset + length) >= bytes) - continue; - - if ((platform_id == PlatformId_Microsoft - && (encoding_id == 0 || encoding_id == 1)) - && (language_id & 0x3ff) == MS_LangIdEnglish - && microsoft_id == -1) - microsoft_id = i; - // not sure if encoding id 4 for Unicode is utf16 or ucs4... - else if (platform_id == PlatformId_Unicode && encoding_id < 4 && unicode_id == -1) - unicode_id = i; - else if (platform_id == PlatformId_Apple && encoding_id == 0 && language_id == 0) - apple_id = i; - } - { - bool unicode = false; - int id = -1; - if (microsoft_id != -1) { - id = microsoft_id; - unicode = true; - } else if (apple_id != -1) { - id = apple_id; - unicode = false; - } else if (unicode_id != -1) { - id = unicode_id; - unicode = true; - } - if (id != -1) { - quint16 length = getUShort(names + 8 + id*NameRecordSize); - quint16 offset = getUShort(names + 10 + id*NameRecordSize); - if (unicode) { - // utf16 - - length /= 2; - i18n_name.resize(length); - QChar *uc = (QChar *) i18n_name.unicode(); - const unsigned char *string = table + string_offset + offset; - for (int i = 0; i < length; ++i) - uc[i] = getUShort(string + 2*i); - } else { - // Apple Roman - - i18n_name.resize(length); - QChar *uc = (QChar *) i18n_name.unicode(); - const unsigned char *string = table + string_offset + offset; - for (int i = 0; i < length; ++i) - uc[i] = QLatin1Char(string[i]); - } - } - } -error: - //qDebug("got i18n name of '%s' for font '%s'", i18n_name.latin1(), familyName.toLocal8Bit().data()); - return i18n_name; -} - -QString getEnglishName(const QString &familyName) -{ - QString i18n_name; - - HDC hdc = GetDC( 0 ); - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - memcpy(lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.length()) * sizeof(wchar_t)); - lf.lfCharSet = DEFAULT_CHARSET; - HFONT hfont = CreateFontIndirect(&lf); - - if (!hfont) { - ReleaseDC(0, hdc); - return QString(); - } - - HGDIOBJ oldobj = SelectObject( hdc, hfont ); - - const DWORD name_tag = MAKE_TAG( 'n', 'a', 'm', 'e' ); - - // get the name table - unsigned char *table = 0; - - DWORD bytes = GetFontData( hdc, name_tag, 0, 0, 0 ); - if ( bytes == GDI_ERROR ) { - // ### Unused variable - // int err = GetLastError(); - goto error; - } - - table = new unsigned char[bytes]; - GetFontData(hdc, name_tag, 0, table, bytes); - if ( bytes == GDI_ERROR ) - goto error; - - i18n_name = getEnglishName(table, bytes); -error: - delete [] table; - SelectObject( hdc, oldobj ); - DeleteObject( hfont ); - ReleaseDC( 0, hdc ); - - //qDebug("got i18n name of '%s' for font '%s'", i18n_name.latin1(), familyName.toLocal8Bit().data()); - return i18n_name; -} - static FontFile * createFontFile(const QString &fileName, int index) { FontFile *fontFile = new FontFile; @@ -288,6 +110,9 @@ static FontFile * createFontFile(const QString &fileName, int index) return fontFile; } +extern bool localizedName(const QString &name); +extern QString getEnglishName(const QString &familyName); + Q_GUI_EXPORT void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias); static bool addFontToDatabase(QString familyName, const QString &scriptName, -- cgit v1.2.3 From de5ebd342f46567a04b58ed28a55ebae48041847 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 23 Feb 2012 00:45:22 +0100 Subject: Remove unused define QT_NO_COP. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It used to relate to QCop and QWS, which are no more. Change-Id: Ie70c64a3a6ef60664009108b79eed7f33ea59f32 Reviewed-by: Jørgen Lind --- src/corelib/global/qglobal.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index acafde595d..ecd981614a 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -489,10 +489,6 @@ Q_DECL_CONSTEXPR inline const T &qBound(const T &min, const T &val, const T &max class QDataStream; -#if !defined(QT_NO_COP) -# define QT_NO_COP -#endif - #if defined(Q_OS_VXWORKS) # define QT_NO_CRASHHANDLER // no popen # define QT_NO_PROCESS // no exec*, no fork -- cgit v1.2.3 From 5a3496ce884dc6b2135ed9154b1da00aa0b64188 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 23 Feb 2012 00:47:54 +0100 Subject: Remove QT_NO_QWS_MULTIPROCESS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1d6731dc5268919d0c36d5d27285321742be708f Reviewed-by: Jørgen Lind --- src/corelib/global/qglobal.h | 2 -- src/plugins/platforms/vnc/qvncserver.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index ecd981614a..382a05deea 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -495,7 +495,6 @@ class QDataStream; # define QT_NO_LPR # define QT_NO_SHAREDMEMORY // only POSIX, no SysV and in the end... # define QT_NO_SYSTEMSEMAPHORE // not needed at all in a flat address space -# define QT_NO_QWS_MULTIPROCESS // no processes #endif # include @@ -1452,7 +1451,6 @@ Q_CORE_EXPORT int qrand(); #ifdef Q_OS_QNX // QNX doesn't have SYSV style shared memory. Multiprocess QWS apps, // shared fonts and QSystemSemaphore + QSharedMemory are not available -# define QT_NO_QWS_MULTIPROCESS # define QT_NO_QWS_SHARE_FONTS # define QT_NO_SYSTEMSEMAPHORE # define QT_NO_SHAREDMEMORY diff --git a/src/plugins/platforms/vnc/qvncserver.h b/src/plugins/platforms/vnc/qvncserver.h index b0c53dde95..e8b093764f 100644 --- a/src/plugins/platforms/vnc/qvncserver.h +++ b/src/plugins/platforms/vnc/qvncserver.h @@ -262,7 +262,7 @@ public: int refreshRate; QVNCServer *vncServer; -#if !defined(QT_NO_QWS_MULTIPROCESS) && !defined(QT_NO_SHAREDMEMORY) +#if !defined(QT_NO_SHAREDMEMORY) QSharedMemory shm; #endif -- cgit v1.2.3 From 9c92df82ddd420867fc5b66616046695557fe7f6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 23 Feb 2012 00:48:54 +0100 Subject: Remove unused QT_NO_QWS_SHARE_FONTS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I47e8111d6caffd9b45096e52695acaa55945c612 Reviewed-by: Jørgen Lind --- src/corelib/global/qglobal.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 382a05deea..47d56d7c1b 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1451,7 +1451,6 @@ Q_CORE_EXPORT int qrand(); #ifdef Q_OS_QNX // QNX doesn't have SYSV style shared memory. Multiprocess QWS apps, // shared fonts and QSystemSemaphore + QSharedMemory are not available -# define QT_NO_QWS_SHARE_FONTS # define QT_NO_SYSTEMSEMAPHORE # define QT_NO_SHAREDMEMORY #endif -- cgit v1.2.3 From cbf2575740b324b8dfa1a79adac1ea4a97a7adad Mon Sep 17 00:00:00 2001 From: Jan-Arve Saether Date: Mon, 20 Feb 2012 15:00:47 +0100 Subject: Minor fixes for RelationFlag. * Document AllRelations * Assigned new values (starting from 1) for the remaining members of the enum. Change-Id: I55ec197f24ff7d43ff3c0d101edd33b9615f9287 Reviewed-by: Frederik Gladhorn --- src/gui/accessible/qaccessible.cpp | 2 ++ src/gui/accessible/qaccessible.h | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index 0d00df2a17..3f1295ab5e 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -364,6 +364,8 @@ QT_BEGIN_NAMESPACE \value Labelled The first object is labelled by the second object. \value Controller The first object controls the second object. \value Controlled The first object is controlled by the second object. + \value AllRelations Used as a mask to specify that we are interesting in information + about all relations Implementations of relations() return a combination of these flags. Some values are mutually exclusive. diff --git a/src/gui/accessible/qaccessible.h b/src/gui/accessible/qaccessible.h index e57033d9bf..a72b91a90f 100644 --- a/src/gui/accessible/qaccessible.h +++ b/src/gui/accessible/qaccessible.h @@ -306,10 +306,10 @@ public: }; enum RelationFlag { - Label = 0x00020000, - Labelled = 0x00040000, - Controller = 0x00080000, - Controlled = 0x00100000, + Label = 0x00000001, + Labelled = 0x00000002, + Controller = 0x00000004, + Controlled = 0x00000008, AllRelations = 0xffffffff }; Q_DECLARE_FLAGS(Relation, RelationFlag) -- cgit v1.2.3 From 9387a9de6d779590727474e546799bfb9730e57b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 Feb 2012 13:21:26 +0100 Subject: QMimeMagicRule: declare as Q_MOVABLE_TYPE Change-Id: I3725696e7369eb59eeb08095ffe0b8aa7537b4f3 Reviewed-by: David Faure --- src/corelib/mimetypes/qmimemagicrule_p.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/corelib/mimetypes/qmimemagicrule_p.h b/src/corelib/mimetypes/qmimemagicrule_p.h index 655ca365fa..e35c1923f9 100644 --- a/src/corelib/mimetypes/qmimemagicrule_p.h +++ b/src/corelib/mimetypes/qmimemagicrule_p.h @@ -83,6 +83,7 @@ public: private: const QScopedPointer d; }; +Q_DECLARE_TYPEINFO(QMimeMagicRule, Q_MOVABLE_TYPE); QT_END_NAMESPACE -- cgit v1.2.3 From e8952aba2914722b0ad0e6f07e2193ead7f2e39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Thu, 23 Feb 2012 09:56:12 +0100 Subject: QHeaderView - change not needed if to Q_ASSERT This removes an if that should always be false. If it isn't false we had more logical indexes than sections. Unless visualIndices and logicalIndices are both 0-sized (meaning that visual and logical indexes are the same) then they better have exactly as many indexes as sectionCount. Otherwise there must be inconsistent data - some logicalindex would refer to non-existing visual sections or some visualindeces wouldn't be hit by logicalIndices. Change-Id: I2dc92f40895438d912bba20612131baf63df4fbe Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qheaderview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 6a1f949258..c457f16a2c 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -1802,9 +1802,8 @@ void QHeaderViewPrivate::_q_sectionsRemoved(const QModelIndex &parent, if (logicalFirst == logicalLast) { // Remove just one index. int l = logicalFirst; int visual = visualIndices.at(l); + Q_ASSERT(sectionCount == logicalIndices.count()); for (int v = 0; v < sectionCount; ++v) { - if (v >= logicalIndices.count()) - continue; // the section doesn't exist if (v > visual) { int logical = logicalIndices.at(v); --(visualIndices[logical]); -- cgit v1.2.3 From 5a2efb490bc3549ef42420a0dafcf22072785e0d Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Mon, 9 Jan 2012 11:25:40 +0100 Subject: QWheelEvent high-resolution delta support. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support pixel-based deltas as well as sending dx and dy values in the same event. Keep source and behavior compatibility with Qt 4. New API: QPoint pixelDelta() const QPoint angleDelta() const Deprecate delta() and orientation(). Both pixel-based deltas and combined updates are necessary for smooth trackpad-based scrolling on OS X. Qt 4 compatible behavior is achieved by sending an extra wheel event in cases where the initial event has a combined dx and dy update. This extra event sends dx in delta() and orientation(), with pixelDelta() and angleDelta() set to null. Modify the Cocoa implementation to provide pixel deltas. It is expected that not all platforms can provide these. Angle deltas will always be available. Change-Id: I20c10f0df338ddcd6a3f7a4d40949ed5ae3b4795 Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qevent.cpp | 70 ++++++++++++++++++++++++--- src/gui/kernel/qevent.h | 24 ++++++--- src/gui/kernel/qguiapplication.cpp | 3 +- src/gui/kernel/qwindowsysteminterface_qpa.cpp | 49 ++++++++++++++++++- src/gui/kernel/qwindowsysteminterface_qpa.h | 3 ++ src/gui/kernel/qwindowsysteminterface_qpa_p.h | 12 +++-- src/plugins/platforms/cocoa/qnsview.mm | 48 +++++++++--------- src/widgets/kernel/qapplication.cpp | 4 +- src/widgets/kernel/qwidgetwindow_qpa.cpp | 2 +- 9 files changed, 168 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index f99f3ddec3..281d4f61bc 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -453,7 +453,13 @@ QHoverEvent::~QHoverEvent() Wheel events are sent to the widget under the mouse cursor, but if that widget does not handle the event they are sent to the - focus widget. The rotation distance is provided by delta(). + focus widget. Wheel events are generated for both mouse wheels + and trackpad scroll gestures. There are two ways to read the + wheel event delta: angleDelta() returns the delta in wheel + degrees. This value is always provided. pixelDelta() returns + the delta in screen pixels and is available on platforms that + have high-resolution trackpads, such as Mac OS X. + The functions pos() and globalPos() return the mouse cursor's location at the time of the event. @@ -483,8 +489,11 @@ QHoverEvent::~QHoverEvent() */ /*! + \obsolete Constructs a wheel event object. + Use the QPoint-based constructor instead. + The position, \a pos, is the location of the mouse cursor within the widget. The globalPos() is initialized to QCursor::pos() which is usually, but not always, correct. @@ -496,13 +505,13 @@ QHoverEvent::~QHoverEvent() \a modifiers holds the keyboard modifier flags at the time of the event, and \a orient holds the wheel's orientation. - \sa pos() delta() state() + \sa pos() pixelDelta() angleDelta() state() */ #ifndef QT_NO_WHEELEVENT QWheelEvent::QWheelEvent(const QPointF &pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient) - : QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient) + : QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons) { g = QCursor::pos(); } @@ -515,26 +524,69 @@ QWheelEvent::~QWheelEvent() } /*! + \obsolete Constructs a wheel event object. + Use the QPoint-based constructor instead. + The \a pos provides the location of the mouse cursor within the widget. The position in global coordinates is specified by \a globalPos. \a delta contains the rotation distance, \a modifiers holds the keyboard modifier flags at the time of the event, and \a orient holds the wheel's orientation. - \sa pos() globalPos() delta() state() + + \sa pos() pixelDelta() angleDelta() state() */ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient) - : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient) + : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons) {} +/*! + Constructs a wheel event object. + + The \a pos provides the location of the mouse cursor + within the window. The position in global coordinates is specified + by \a globalPos. \pixelDelta contains the scrolling distance + in pixels on screen, \a angleDelta contains the wheel rotation distance. + \pixelDelta is optional and can be null. + + \a modifiers holds the keyboard modifier flags at the time of the event. + + \a pixelDelta contains the scrolling delta in pixels, + \a angleDelta contains the rotation distance, and + \a orient holds the wheel's orientation. + + \sa pos() globalPos() delta() state() +*/ + +QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, + QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) + : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), + angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons) +{} + + #endif // QT_NO_WHEELEVENT /*! - \fn int QWheelEvent::delta() const + \fn QPoint QWheelEvent::pixelDelta() const + + Returns the scrolling distance in pixels on screen. This value is + provided on platforms that support high-resolution pixel-based + delta values, such as Mac OS X. The value should be used directly + to scroll content on screen. + + Example: + + \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0 +*/ + +/*! + \fn QPoint QWheelEvent::angleDelta() const Returns the distance that the wheel is rotated, in eighths of a degree. A positive value indicates that the wheel was rotated @@ -555,6 +607,12 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0 */ +/*! + \fn int QWheelEvent::delta() const + + This function has been deprecated, use pixelDelta() or angleDelta() instead. +*/ + /*! \fn const QPoint &QWheelEvent::pos() const diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 93dea41de9..ca93095a94 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -148,9 +148,21 @@ public: QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient = Qt::Vertical); + QWheelEvent(const QPointF &pos, const QPointF& globalPos, + QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); + ~QWheelEvent(); - inline int delta() const { return d; } + + inline QPoint pixelDelta() const { return pixelD; } + inline QPoint angleDelta() const { return angleD; } + +#if QT_DEPRECATED_SINCE(5, 0) + inline QT_DEPRECATED int delta() const { return qt4D; } + inline QT_DEPRECATED Qt::Orientation orientation() const { return qt4O; } +#endif + #ifndef QT_NO_INTEGER_EVENT_COORDINATES inline QPoint pos() const { return p.toPoint(); } inline QPoint globalPos() const { return g.toPoint(); } @@ -163,15 +175,15 @@ public: inline const QPointF &globalPosF() const { return g; } inline Qt::MouseButtons buttons() const { return mouseState; } - Qt::Orientation orientation() const { return o; } - - protected: QPointF p; QPointF g; - int d; + QPoint pixelD; + QPoint angleD; + int qt4D; + Qt::Orientation qt4O; Qt::MouseButtons mouseState; - Qt::Orientation o; + int reserved; }; #endif diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 2e7441d62c..1cd448a6bb 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1032,8 +1032,7 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh QWindow *window = e->window.data(); if (window) { - QWheelEvent ev(e->localPos, e->globalPos, e->delta, buttons, e->modifiers, - e->orient); + QWheelEvent ev(e->localPos, e->globalPos, e->pixelDelta, e->angleDelta, e->qt4Delta, e->qt4Orientation, buttons, e->modifiers); ev.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(window, &ev); return; diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index e6c4454104..40a4ec07a6 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -189,8 +189,53 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods) { - QWindowSystemInterfacePrivate::WheelEvent *e = - new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, d, o, mods); + QPoint point = (o == Qt::Vertical) ? QPoint(0, d) : QPoint(d, 0); + handleWheelEvent(tlw, timestamp, local, global, point, point, mods); +} + +void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods) +{ + unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); + handleWheelEvent(w, time, local, global, pixelDelta, angleDelta, mods); +} + +void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods) +{ + // Qt 4 sends two separate wheel events for horizontal and vertical + // deltas. For Qt 5 we want to send the deltas in one event, but at the + // same time preserve source and behavior compatibility with Qt 4. + // + // In addition high-resolution pixel-based deltas are also supported. + // Platforms that does not support these may pass a null point here. + // Angle deltas must always be sent in addition to pixel deltas. + QWindowSystemInterfacePrivate::WheelEvent *e; + + if (angleDelta.isNull()) + return; + + // Simple case: vertical deltas only: + if (angleDelta.y() != 0 && angleDelta.x() == 0) { + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods); + QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); + return; + } + + // Simple case: horizontal deltas only: + if (angleDelta.y() == 0 && angleDelta.x() != 0) { + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods); + QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); + return; + } + + // Both horizontal and vertical deltas: Send two wheel events. + // The first event contains the Qt 5 pixel and angle delta as points, + // and in addition the Qt 4 compatibility vertical angle delta. + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods); + QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); + + // The second event contains null pixel and angle points and the + // Qt 4 compatibility horizontal angle delta. + e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods); QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 78152a1178..836fb40bd7 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -80,7 +80,10 @@ public: quint32 nativeModifiers, const QString& text = QString(), bool autorep = false, ushort count = 1); + static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods = Qt::NoModifier); + // Wheel event compatibility functions. Will be removed: do not use. static void handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h index 661b39da88..f5c141b4c9 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h @@ -157,13 +157,15 @@ public: class WheelEvent : public InputEvent { public: - WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, int d, - Qt::Orientation o, Qt::KeyboardModifiers mods) - : InputEvent(w, time, Wheel, mods), delta(d), localPos(local), globalPos(global), orient(o) { } - int delta; + WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O, + Qt::KeyboardModifiers mods) + : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global) { } + QPoint pixelDelta; + QPoint angleDelta; + int qt4Delta; + Qt::Orientation qt4Orientation; QPointF localPos; QPointF globalPos; - Qt::Orientation orient; }; class KeyEvent : public InputEvent { diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 577e0751c6..a43b3fe893 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -371,14 +371,11 @@ static QTouchDevice *touchDevice = 0; #ifndef QT_NO_WHEELEVENT - (void)scrollWheel:(NSEvent *)theEvent { - int deltaX = 0; - int deltaY = 0; - int deltaZ = 0; - const EventRef carbonEvent = (EventRef)[theEvent eventRef]; const UInt32 carbonEventKind = carbonEvent ? ::GetEventKind(carbonEvent) : 0; const bool scrollEvent = carbonEventKind == kEventMouseScroll; + QPoint angleDelta; if (scrollEvent) { // The mouse device contains pixel scroll wheel support (Mighty Mouse, Trackpad). // Since deviceDelta is delivered as pixels rather than degrees, we need to @@ -389,40 +386,45 @@ static QTouchDevice *touchDevice = 0; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 if ([theEvent respondsToSelector:@selector(scrollingDeltaX)]) { - deltaX = [theEvent scrollingDeltaX] * pixelsToDegrees; - deltaY = [theEvent scrollingDeltaY] * pixelsToDegrees; - // scrollingDeltaZ API is missing. + angleDelta.setX([theEvent scrollingDeltaX] * pixelsToDegrees); + angleDelta.setY([theEvent scrollingDeltaY] * pixelsToDegrees); } else #endif { - deltaX = [theEvent deviceDeltaX] * pixelsToDegrees; - deltaY = [theEvent deviceDeltaY] * pixelsToDegrees; - deltaZ = [theEvent deviceDeltaZ] * pixelsToDegrees; + angleDelta.setX([theEvent deviceDeltaX] * pixelsToDegrees); + angleDelta.setY([theEvent deviceDeltaY] * pixelsToDegrees); } } else { // carbonEventKind == kEventMouseWheelMoved // Remove acceleration, and use either -120 or 120 as delta: - deltaX = qBound(-120, int([theEvent deltaX] * 10000), 120); - deltaY = qBound(-120, int([theEvent deltaY] * 10000), 120); - deltaZ = qBound(-120, int([theEvent deltaZ] * 10000), 120); + angleDelta.setX(qBound(-120, int([theEvent deltaX] * 10000), 120)); + angleDelta.setY(qBound(-120, int([theEvent deltaY] * 10000), 120)); } + QPoint pixelDelta; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + if ([theEvent respondsToSelector:@selector(scrollingDeltaX)]) { + if ([theEvent hasPreciseScrollingDeltas]) { + pixelDelta.setX([theEvent scrollingDeltaX]); + pixelDelta.setY([theEvent scrollingDeltaY]); + } else { + // docs: "In the case of !hasPreciseScrollingDeltas, multiply the delta with the line width." + // scrollingDeltaX seems to return a minimum value of 0.1 in this case, map that to two pixels. + const CGFloat lineWithEstimate = 20.0; + pixelDelta.setX([theEvent scrollingDeltaX] * lineWithEstimate); + pixelDelta.setY([theEvent scrollingDeltaY] * lineWithEstimate); + } + } +#endif + + NSPoint windowPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil]; QPoint qt_windowPoint(windowPoint.x, windowPoint.y); NSTimeInterval timestamp = [theEvent timestamp]; ulong qt_timestamp = timestamp * 1000; - if (deltaX != 0) - QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_windowPoint, deltaX, Qt::Horizontal); - - if (deltaY != 0) - QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_windowPoint, deltaY, Qt::Vertical); - - if (deltaZ != 0) - // Qt doesn't explicitly support wheels with a Z component. In a misguided attempt to - // try to be ahead of the pack, I'm adding this extra value. - QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_windowPoint, deltaY, (Qt::Orientation)3); + QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_windowPoint, pixelDelta, angleDelta); } #endif //QT_NO_WHEELEVENT diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 650d4af38b..c350223278 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3357,8 +3357,8 @@ bool QApplication::notify(QObject *receiver, QEvent *e) } while (w) { - QWheelEvent we(relpos, wheel->globalPos(), wheel->delta(), wheel->buttons(), - wheel->modifiers(), wheel->orientation()); + QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), + wheel->modifiers()); we.spont = wheel->spontaneous(); res = d->notify_helper(w, w == receiver ? wheel : &we); eventAccepted = ((w == receiver) ? wheel : &we)->isAccepted(); diff --git a/src/widgets/kernel/qwidgetwindow_qpa.cpp b/src/widgets/kernel/qwidgetwindow_qpa.cpp index c04d8a9dc3..4d5e9d5774 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa.cpp +++ b/src/widgets/kernel/qwidgetwindow_qpa.cpp @@ -364,7 +364,7 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event) QPoint mapped = widget->mapFrom(m_widget, event->pos()); - QWheelEvent translated(mapped, event->globalPos(), event->delta(), event->buttons(), event->modifiers(), event->orientation()); + QWheelEvent translated(mapped, event->globalPos(), event->pixelDelta(), event->pixelDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers()); QGuiApplication::sendSpontaneousEvent(widget, &translated); } -- cgit v1.2.3 From 12c2a3d85256abcc5a69f05a7504e01e72f24593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Sun, 12 Feb 2012 21:11:04 +0100 Subject: QHeaderView - fix setOffsetToSectionPosition a bit It might be silly to have sections with size 0 without using hideSection. Nevertheless we should still use the principle of least surprise. It does not make sense that hiding a row 'far' away should affect the semantics of setOffsetToSectionPosition on lower indexes. Change-Id: Iaf847eba2ea4d28fc7bcfe3a27d62f432f6f61e0 Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qheaderview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index c457f16a2c..ed71c5a918 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3390,11 +3390,11 @@ int QHeaderViewPrivate::viewSectionSizeHint(int logical) const int QHeaderViewPrivate::adjustedVisualIndex(int visualIndex) const { - if (hiddenSectionSize.count() > 0) { + if (!sectionHidden.isEmpty()) { int adjustedVisualIndex = visualIndex; int currentVisualIndex = 0; for (int i = 0; i < sectionSpans.count(); ++i) { - if (sectionSpans.at(i).size == 0) + if (sectionHidden.testBit(i)) ++adjustedVisualIndex; else ++currentVisualIndex; -- cgit v1.2.3 From 92f37f00f91fbfc3164ab514d521f0975dc6c5d8 Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 21 Feb 2012 11:21:06 +0100 Subject: Remove unused toolTip member variable (qt3 leftover) Change-Id: Ia68fb00afb81a0f521f9fbc3f0dbfc7e43075bbe Reviewed-by: laurent montel Reviewed-by: Stephen Kelly --- src/widgets/widgets/qworkspace.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qworkspace.cpp b/src/widgets/widgets/qworkspace.cpp index be3f7836d5..80f0a7e44a 100644 --- a/src/widgets/widgets/qworkspace.cpp +++ b/src/widgets/widgets/qworkspace.cpp @@ -290,9 +290,6 @@ public: QWorkspaceTitleBarPrivate() : lastControl(QStyle::SC_None), -#ifndef QT_NO_TOOLTIP - toolTip(0), -#endif act(0), window(0), movable(1), pressed(0), autoraise(0), moving(0) { } @@ -301,9 +298,6 @@ public: QStyle::SubControl buttonDown; QStyle::SubControl lastControl; QPoint moveOffset; -#ifndef QT_NO_TOOLTIP - QToolTip *toolTip; -#endif bool act :1; QPointer window; bool movable :1; -- cgit v1.2.3 From 5ae1caed435139cea5881609dae51026f54ad1fe Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 23 Feb 2012 18:56:12 +0100 Subject: qmimetypeparser: more optimized definition of string constants Change-Id: I0cbc0fef63814ab037bea66ab35b3aa8b6ec800c Reviewed-by: Oswald Buddenhagen --- src/corelib/mimetypes/qmimetypeparser.cpp | 42 +++++++++++++++---------------- src/corelib/mimetypes/qmimetypeparser_p.h | 24 ------------------ 2 files changed, 21 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/corelib/mimetypes/qmimetypeparser.cpp b/src/corelib/mimetypes/qmimetypeparser.cpp index 23f57367e3..4a2ec0a0b2 100644 --- a/src/corelib/mimetypes/qmimetypeparser.cpp +++ b/src/corelib/mimetypes/qmimetypeparser.cpp @@ -58,29 +58,29 @@ QT_BEGIN_NAMESPACE // XML tags in MIME files -const char *const mimeInfoTagC = "mime-info"; -const char *const mimeTypeTagC = "mime-type"; -const char *const mimeTypeAttributeC = "type"; -const char *const subClassTagC = "sub-class-of"; -const char *const commentTagC = "comment"; -const char *const genericIconTagC = "generic-icon"; -const char *const iconTagC = "icon"; -const char *const nameAttributeC = "name"; -const char *const globTagC = "glob"; -const char *const aliasTagC = "alias"; -const char *const patternAttributeC = "pattern"; -const char *const weightAttributeC = "weight"; -const char *const caseSensitiveAttributeC = "case-sensitive"; -const char *const localeAttributeC = "xml:lang"; +static const char mimeInfoTagC[] = "mime-info"; +static const char mimeTypeTagC[] = "mime-type"; +static const char mimeTypeAttributeC[] = "type"; +static const char subClassTagC[] = "sub-class-of"; +static const char commentTagC[] = "comment"; +static const char genericIconTagC[] = "generic-icon"; +static const char iconTagC[] = "icon"; +static const char nameAttributeC[] = "name"; +static const char globTagC[] = "glob"; +static const char aliasTagC[] = "alias"; +static const char patternAttributeC[] = "pattern"; +static const char weightAttributeC[] = "weight"; +static const char caseSensitiveAttributeC[] = "case-sensitive"; +static const char localeAttributeC[] = "xml:lang"; -const char *const magicTagC = "magic"; -const char *const priorityAttributeC = "priority"; +static const char magicTagC[] = "magic"; +static const char priorityAttributeC[] = "priority"; -const char *const matchTagC = "match"; -const char *const matchValueAttributeC = "value"; -const char *const matchTypeAttributeC = "type"; -const char *const matchOffsetAttributeC = "offset"; -const char *const matchMaskAttributeC = "mask"; +static const char matchTagC[] = "match"; +static const char matchValueAttributeC[] = "value"; +static const char matchTypeAttributeC[] = "type"; +static const char matchOffsetAttributeC[] = "offset"; +static const char matchMaskAttributeC[] = "mask"; /*! \class QMimeTypeParser diff --git a/src/corelib/mimetypes/qmimetypeparser_p.h b/src/corelib/mimetypes/qmimetypeparser_p.h index 455c07063c..af01e1641a 100644 --- a/src/corelib/mimetypes/qmimetypeparser_p.h +++ b/src/corelib/mimetypes/qmimetypeparser_p.h @@ -50,30 +50,6 @@ QT_BEGIN_NAMESPACE class QIODevice; -// XML tags in MIME files -extern const char *const mimeInfoTagC; -extern const char *const mimeTypeTagC; -extern const char *const mimeTypeAttributeC; -extern const char *const subClassTagC; -extern const char *const commentTagC; -extern const char *const genericIconTagC; -extern const char *const nameAttributeC; -extern const char *const globTagC; -extern const char *const aliasTagC; -extern const char *const patternAttributeC; -extern const char *const weightAttributeC; -extern const char *const caseSensitiveAttributeC; -extern const char *const localeAttributeC; - -extern const char *const magicTagC; -extern const char *const priorityAttributeC; - -extern const char *const matchTagC; -extern const char *const matchValueAttributeC; -extern const char *const matchTypeAttributeC; -extern const char *const matchOffsetAttributeC; -extern const char *const matchMaskAttributeC; - class QMimeTypeParserBase { Q_DISABLE_COPY(QMimeTypeParserBase) -- cgit v1.2.3 From ed7f78acba45e1142157e39154466a13f9d3ce4e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Feb 2012 17:27:47 +0100 Subject: Fix tst_qlineedit. - Fix key handling in QWidgetLineControl according to the keyboard scheme returned by the QPlatformTheme, remove #ifdefs. - Do the same in the test. Task-number: QTBUG-21402 Change-Id: I36d836584e7122309061af72819a4147cadd0a74 Reviewed-by: Miikka Heikkinen Reviewed-by: Bradley T. Hughes --- src/widgets/widgets/qwidgetlinecontrol.cpp | 49 +++++++++++++++++++----------- src/widgets/widgets/qwidgetlinecontrol_p.h | 3 ++ 2 files changed, 34 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 2f5793bcba..73c3d14f9b 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -45,6 +45,8 @@ #include "qabstractitemview.h" #include "qclipboard.h" +#include +#include #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" #endif @@ -374,6 +376,14 @@ void QWidgetLineControl::init(const QString &txt) m_text = txt; updateDisplayText(); m_cursor = m_text.length(); + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + m_keyboardScheme = theme->themeHint(QPlatformTheme::KeyboardScheme).toInt(); + // Generalize for X11 + if (m_keyboardScheme == QPlatformTheme::KdeKeyboardScheme + || m_keyboardScheme == QPlatformTheme::GnomeKeyboardScheme + || m_keyboardScheme == QPlatformTheme::CdeKeyboardScheme) { + m_keyboardScheme = QPlatformTheme::X11KeyboardScheme; + } } /*! @@ -1630,10 +1640,11 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) else if (event == QKeySequence::Paste) { if (!isReadOnly()) { QClipboard::Mode mode = QClipboard::Clipboard; -#ifdef Q_WS_X11 - if (event->modifiers() == (Qt::CTRL | Qt::SHIFT) && event->key() == Qt::Key_Insert) + if (m_keyboardScheme == QPlatformTheme::X11KeyboardScheme + && event->modifiers() == (Qt::CTRL | Qt::SHIFT) + && event->key() == Qt::Key_Insert) { mode = QClipboard::Selection; -#endif + } paste(mode); } } @@ -1664,12 +1675,14 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) end(1); } else if (event == QKeySequence::MoveToNextChar) { -#if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER) - if (hasSelectedText()) { +#if defined(QT_NO_COMPLETER) + const bool inlineCompletion = false; #else - if (hasSelectedText() && m_completer - && m_completer->completionMode() == QCompleter::InlineCompletion) { + const bool inlineCompletion = m_completer && m_completer->completionMode() == QCompleter::InlineCompletion; #endif + if (hasSelectedText() + && (m_keyboardScheme != QPlatformTheme::WindowsKeyboardScheme + || inlineCompletion)) { moveCursor(selectionEnd(), false); } else { cursorForward(0, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1)); @@ -1679,12 +1692,14 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) cursorForward(1, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1)); } else if (event == QKeySequence::MoveToPreviousChar) { -#if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER) - if (hasSelectedText()) { +#if defined(QT_NO_COMPLETER) + const bool inlineCompletion = false; #else - if (hasSelectedText() && m_completer - && m_completer->completionMode() == QCompleter::InlineCompletion) { + const bool inlineCompletion = m_completer && m_completer->completionMode() == QCompleter::InlineCompletion; #endif + if (hasSelectedText() + && (m_keyboardScheme != QPlatformTheme::WindowsKeyboardScheme + || inlineCompletion)) { moveCursor(selectionStart(), false); } else { cursorForward(0, visual ? -1 : (layoutDirection() == Qt::LeftToRight ? -1 : 1)); @@ -1737,8 +1752,8 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) #endif // QT_NO_SHORTCUT else { bool handled = false; -#ifdef Q_WS_MAC - if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) { + if (m_keyboardScheme == QPlatformTheme::MacKeyboardScheme + && (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)) { Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier); if (myModifiers & Qt::ShiftModifier) { if (myModifiers == (Qt::ControlModifier|Qt::ShiftModifier) @@ -1756,7 +1771,6 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) } handled = true; } -#endif if (event->modifiers() & Qt::ControlModifier) { switch (event->key()) { case Qt::Key_Backspace: @@ -1771,13 +1785,13 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) complete(event->key()); break; #endif -#if defined(Q_WS_X11) case Qt::Key_E: - end(0); + if (m_keyboardScheme == QPlatformTheme::X11KeyboardScheme) + end(0); break; case Qt::Key_U: - if (!isReadOnly()) { + if (m_keyboardScheme == QPlatformTheme::X11KeyboardScheme && !isReadOnly()) { setSelection(0, text().size()); #ifndef QT_NO_CLIPBOARD copy(); @@ -1785,7 +1799,6 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event) del(); } break; -#endif default: if (!handled) unknown = true; diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index a0191188a7..72f25e9068 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -100,6 +100,7 @@ public: , m_threadChecks(false) , m_textLayoutThread(0) #endif + , m_keyboardScheme(0) { init(txt); } @@ -527,6 +528,8 @@ private Q_SLOTS: void _q_clipboardChanged(); void _q_deleteSelected(); +private: + int m_keyboardScheme; }; QT_END_NAMESPACE -- cgit v1.2.3 From b1995f2c96f90b20feb54a3368c2b8c2cfc1fa84 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Feb 2012 16:40:58 +0100 Subject: rcc: micro-optimization Declare a char array instead of a pointer variable. Change-Id: I2beff815d05b6dc9c35bb0a55d7294189afbf17e Reviewed-by: Marius Storm-Olsen Reviewed-by: Olivier Goffart --- src/tools/rcc/rcc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 5fbda35fc6..b31c47e7ad 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -687,7 +687,7 @@ bool RCCResourceLibrary::output(QIODevice &outDevice, QIODevice &errorDevice) void RCCResourceLibrary::writeHex(quint8 tmp) { - const char * const digits = "0123456789abcdef"; + const char digits[] = "0123456789abcdef"; writeChar('0'); writeChar('x'); if (tmp < 16) { -- cgit v1.2.3 From 5f320e2f97df1ef48a7877feb418e3f63421b485 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Feb 2012 13:13:29 +0100 Subject: Use new plugin system for network bearer plugins. Change-Id: Ic4a28d379033518f75d0e3e449ddf012109ed9ea Reviewed-by: Lars Knoll --- src/plugins/bearer/connman/connman.json | 3 +++ src/plugins/bearer/connman/connman.pro | 2 ++ src/plugins/bearer/connman/main.cpp | 8 +++++--- src/plugins/bearer/corewlan/corewlan.json | 3 +++ src/plugins/bearer/corewlan/corewlan.pro | 2 ++ src/plugins/bearer/corewlan/main.cpp | 8 +++++--- src/plugins/bearer/generic/generic.json | 3 +++ src/plugins/bearer/generic/generic.pro | 2 ++ src/plugins/bearer/generic/main.cpp | 8 +++++--- src/plugins/bearer/nativewifi/main.cpp | 8 +++++--- src/plugins/bearer/nativewifi/nativewifi.json | 3 +++ src/plugins/bearer/nativewifi/nativewifi.pro | 2 ++ src/plugins/bearer/networkmanager/main.cpp | 8 +++++--- src/plugins/bearer/networkmanager/networkmanager.json | 3 +++ src/plugins/bearer/networkmanager/networkmanager.pro | 2 ++ src/plugins/bearer/nla/main.cpp | 8 +++++--- src/plugins/bearer/nla/nla.json | 3 +++ src/plugins/bearer/nla/nla.pro | 4 +++- 18 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 src/plugins/bearer/connman/connman.json create mode 100644 src/plugins/bearer/corewlan/corewlan.json create mode 100644 src/plugins/bearer/generic/generic.json create mode 100644 src/plugins/bearer/nativewifi/nativewifi.json create mode 100644 src/plugins/bearer/networkmanager/networkmanager.json create mode 100644 src/plugins/bearer/nla/nla.json (limited to 'src') diff --git a/src/plugins/bearer/connman/connman.json b/src/plugins/bearer/connman/connman.json new file mode 100644 index 0000000000..7a80b8c9be --- /dev/null +++ b/src/plugins/bearer/connman/connman.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "connman" ] +} diff --git a/src/plugins/bearer/connman/connman.pro b/src/plugins/bearer/connman/connman.pro index 25243f8e0a..679637b37f 100644 --- a/src/plugins/bearer/connman/connman.pro +++ b/src/plugins/bearer/connman/connman.pro @@ -15,6 +15,8 @@ SOURCES += main.cpp \ qconnmanengine.cpp \ ../qnetworksession_impl.cpp +OTHER_FILES += connman.json + DESTDIR = $$QT.network.plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer INSTALLS += target diff --git a/src/plugins/bearer/connman/main.cpp b/src/plugins/bearer/connman/main.cpp index f612f0ca9f..be934c7282 100644 --- a/src/plugins/bearer/connman/main.cpp +++ b/src/plugins/bearer/connman/main.cpp @@ -51,6 +51,9 @@ QT_BEGIN_NAMESPACE class QConnmanEnginePlugin : public QBearerEnginePlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QBearerEngineFactoryInterface" FILE "connman.json") + public: QConnmanEnginePlugin(); ~QConnmanEnginePlugin(); @@ -84,10 +87,9 @@ QBearerEngine *QConnmanEnginePlugin::create(const QString &key) const return 0; } -Q_EXPORT_STATIC_PLUGIN(QConnmanEnginePlugin) -Q_EXPORT_PLUGIN2(qconnmanbearer, QConnmanEnginePlugin) - QT_END_NAMESPACE +#include "main.moc" + #endif #endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/corewlan/corewlan.json b/src/plugins/bearer/corewlan/corewlan.json new file mode 100644 index 0000000000..b43519ea90 --- /dev/null +++ b/src/plugins/bearer/corewlan/corewlan.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "corewlan" ] +} diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro index 6a214ac340..82a514fb14 100644 --- a/src/plugins/bearer/corewlan/corewlan.pro +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -19,6 +19,8 @@ SOURCES += main.cpp \ OBJECTIVE_SOURCES += qcorewlanengine.mm +OTHER_FILES += corewlan.json + DESTDIR = $$QT.network.plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer INSTALLS += target diff --git a/src/plugins/bearer/corewlan/main.cpp b/src/plugins/bearer/corewlan/main.cpp index 0f5ad2c7fb..f2ba8bd879 100644 --- a/src/plugins/bearer/corewlan/main.cpp +++ b/src/plugins/bearer/corewlan/main.cpp @@ -51,6 +51,9 @@ QT_BEGIN_NAMESPACE class QCoreWlanEnginePlugin : public QBearerEnginePlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QBearerEngineFactoryInterface" FILE "corewlan.json") + public: QCoreWlanEnginePlugin(); ~QCoreWlanEnginePlugin(); @@ -80,9 +83,8 @@ QBearerEngine *QCoreWlanEnginePlugin::create(const QString &key) const return 0; } -Q_EXPORT_STATIC_PLUGIN(QCoreWlanEnginePlugin) -Q_EXPORT_PLUGIN2(qcorewlanbearer, QCoreWlanEnginePlugin) - QT_END_NAMESPACE +#include "main.moc" + #endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/generic/generic.json b/src/plugins/bearer/generic/generic.json new file mode 100644 index 0000000000..e9357f4c72 --- /dev/null +++ b/src/plugins/bearer/generic/generic.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "generic" ] +} diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index 4f86c2a38c..e66c5b2c7a 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -11,6 +11,8 @@ SOURCES += qgenericengine.cpp \ ../qnetworksession_impl.cpp \ main.cpp +OTHER_FILES += generic.json + DESTDIR = $$QT.network.plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer INSTALLS += target diff --git a/src/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp index 0311bcbef0..5f5ad7c238 100644 --- a/src/plugins/bearer/generic/main.cpp +++ b/src/plugins/bearer/generic/main.cpp @@ -51,6 +51,9 @@ QT_BEGIN_NAMESPACE class QGenericEnginePlugin : public QBearerEnginePlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QBearerEngineFactoryInterface" FILE "generic.json") + public: QGenericEnginePlugin(); ~QGenericEnginePlugin(); @@ -80,9 +83,8 @@ QBearerEngine *QGenericEnginePlugin::create(const QString &key) const return 0; } -Q_EXPORT_STATIC_PLUGIN(QGenericEnginePlugin) -Q_EXPORT_PLUGIN2(qgenericbearer, QGenericEnginePlugin) - QT_END_NAMESPACE +#include "main.moc" + #endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp index 74129c1d0a..8baa977a9d 100644 --- a/src/plugins/bearer/nativewifi/main.cpp +++ b/src/plugins/bearer/nativewifi/main.cpp @@ -92,6 +92,9 @@ static void resolveLibrary() class QNativeWifiEnginePlugin : public QBearerEnginePlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QBearerEngineFactoryInterface" FILE "nativewifi.json") + public: QNativeWifiEnginePlugin(); ~QNativeWifiEnginePlugin(); @@ -135,9 +138,8 @@ QBearerEngine *QNativeWifiEnginePlugin::create(const QString &key) const return engine; } -Q_EXPORT_STATIC_PLUGIN(QNativeWifiEnginePlugin) -Q_EXPORT_PLUGIN2(qnativewifibearer, QNativeWifiEnginePlugin) - QT_END_NAMESPACE +#include "main.moc" + #endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/nativewifi/nativewifi.json b/src/plugins/bearer/nativewifi/nativewifi.json new file mode 100644 index 0000000000..f3db199150 --- /dev/null +++ b/src/plugins/bearer/nativewifi/nativewifi.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "nativewifi" ] +} diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro index ec86cc0b93..3124d58ff2 100644 --- a/src/plugins/bearer/nativewifi/nativewifi.pro +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -12,6 +12,8 @@ SOURCES += main.cpp \ qnativewifiengine.cpp \ ../qnetworksession_impl.cpp +OTHER_FILES += nativewifi.json + DESTDIR = $$QT.network.plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer INSTALLS += target diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index 2278d221fd..c8a8a74e46 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -52,6 +52,9 @@ QT_BEGIN_NAMESPACE class QNetworkManagerEnginePlugin : public QBearerEnginePlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QBearerEngineFactoryInterface" FILE "networkmanager.json") + public: QNetworkManagerEnginePlugin(); ~QNetworkManagerEnginePlugin(); @@ -86,10 +89,9 @@ QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const return 0; } -Q_EXPORT_STATIC_PLUGIN(QNetworkManagerEnginePlugin) -Q_EXPORT_PLUGIN2(qnmbearer, QNetworkManagerEnginePlugin) - QT_END_NAMESPACE +#include "main.moc" + #endif // QT_NO_DBUS #endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/networkmanager/networkmanager.json b/src/plugins/bearer/networkmanager/networkmanager.json new file mode 100644 index 0000000000..3d408d5c20 --- /dev/null +++ b/src/plugins/bearer/networkmanager/networkmanager.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "networkmanager" ] +} diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 262f60a69c..c1c6664897 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -15,6 +15,8 @@ SOURCES += main.cpp \ qnetworkmanagerengine.cpp \ ../qnetworksession_impl.cpp +OTHER_FILES += networkmanager.json + DESTDIR = $$QT.network.plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer INSTALLS += target diff --git a/src/plugins/bearer/nla/main.cpp b/src/plugins/bearer/nla/main.cpp index 4337c1748a..4a2c915d13 100644 --- a/src/plugins/bearer/nla/main.cpp +++ b/src/plugins/bearer/nla/main.cpp @@ -49,6 +49,9 @@ QT_BEGIN_NAMESPACE class QNlaEnginePlugin : public QBearerEnginePlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QBearerEngineFactoryInterface" FILE "nla.json") + public: QNlaEnginePlugin(); ~QNlaEnginePlugin(); @@ -78,7 +81,6 @@ QBearerEngine *QNlaEnginePlugin::create(const QString &key) const return 0; } -Q_EXPORT_STATIC_PLUGIN(QNlaEnginePlugin) -Q_EXPORT_PLUGIN2(qnlabearer, QNlaEnginePlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/bearer/nla/nla.json b/src/plugins/bearer/nla/nla.json new file mode 100644 index 0000000000..2554d2c5c4 --- /dev/null +++ b/src/plugins/bearer/nla/nla.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "nla" ] +} diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 76da098dbf..5444269f1f 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -1,7 +1,7 @@ TARGET = qnlabearer load(qt_plugin) -QT = core network +QT = core core-private network network-private !wince* { LIBS += -lWs2_32 @@ -18,6 +18,8 @@ SOURCES += main.cpp \ qnlaengine.cpp \ ../qnetworksession_impl.cpp +OTHER_FILES += nla.json + DESTDIR = $$QT.network.plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer INSTALLS += target -- cgit v1.2.3 From 71fe29711fcb88adcc191f1350e13f7c2544c642 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Feb 2012 15:18:35 +0100 Subject: Use new plugin system for SQL drivers. Change-Id: I1d4db9ecc7e1cbca66674d13748070f4b19d5b8c Reviewed-by: Lars Knoll --- src/plugins/sqldrivers/db2/db2.json | 3 +++ src/plugins/sqldrivers/db2/db2.pro | 1 + src/plugins/sqldrivers/db2/main.cpp | 12 ++++++------ src/plugins/sqldrivers/ibase/ibase.json | 3 +++ src/plugins/sqldrivers/ibase/ibase.pro | 1 + src/plugins/sqldrivers/ibase/main.cpp | 12 ++++++------ src/plugins/sqldrivers/mysql/main.cpp | 8 +++++--- src/plugins/sqldrivers/mysql/mysql.json | 3 +++ src/plugins/sqldrivers/mysql/mysql.pro | 1 + src/plugins/sqldrivers/oci/main.cpp | 8 +++++--- src/plugins/sqldrivers/oci/oci.json | 3 +++ src/plugins/sqldrivers/oci/oci.pro | 1 + src/plugins/sqldrivers/odbc/main.cpp | 8 +++++--- src/plugins/sqldrivers/odbc/odbc.json | 3 +++ src/plugins/sqldrivers/odbc/odbc.pro | 1 + src/plugins/sqldrivers/psql/main.cpp | 8 +++++--- src/plugins/sqldrivers/psql/psql.json | 3 +++ src/plugins/sqldrivers/psql/psql.pro | 1 + src/plugins/sqldrivers/sqlite/smain.cpp | 12 ++++++------ src/plugins/sqldrivers/sqlite/sqlite.json | 3 +++ src/plugins/sqldrivers/sqlite/sqlite.pro | 1 + src/plugins/sqldrivers/sqlite2/smain.cpp | 12 ++++++------ src/plugins/sqldrivers/sqlite2/sqlite2.json | 3 +++ src/plugins/sqldrivers/sqlite2/sqlite2.pro | 1 + src/plugins/sqldrivers/tds/main.cpp | 8 +++++--- src/plugins/sqldrivers/tds/tds.json | 3 +++ src/plugins/sqldrivers/tds/tds.pro | 1 + 27 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 src/plugins/sqldrivers/db2/db2.json create mode 100644 src/plugins/sqldrivers/ibase/ibase.json create mode 100644 src/plugins/sqldrivers/mysql/mysql.json create mode 100644 src/plugins/sqldrivers/oci/oci.json create mode 100644 src/plugins/sqldrivers/odbc/odbc.json create mode 100644 src/plugins/sqldrivers/psql/psql.json create mode 100644 src/plugins/sqldrivers/sqlite/sqlite.json create mode 100644 src/plugins/sqldrivers/sqlite2/sqlite2.json create mode 100644 src/plugins/sqldrivers/tds/tds.json (limited to 'src') diff --git a/src/plugins/sqldrivers/db2/db2.json b/src/plugins/sqldrivers/db2/db2.json new file mode 100644 index 0000000000..3f8678ae7a --- /dev/null +++ b/src/plugins/sqldrivers/db2/db2.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QDB2" ] +} diff --git a/src/plugins/sqldrivers/db2/db2.pro b/src/plugins/sqldrivers/db2/db2.pro index e053f3756b..d04e6f191b 100644 --- a/src/plugins/sqldrivers/db2/db2.pro +++ b/src/plugins/sqldrivers/db2/db2.pro @@ -1,6 +1,7 @@ TARGET = qsqldb2 SOURCES = main.cpp +OTHER_FILES += db2.json include(../../../sql/drivers/db2/qsql_db2.pri) include(../qsqldriverbase.pri) diff --git a/src/plugins/sqldrivers/db2/main.cpp b/src/plugins/sqldrivers/db2/main.cpp index af5eb10c67..186eacf2e9 100644 --- a/src/plugins/sqldrivers/db2/main.cpp +++ b/src/plugins/sqldrivers/db2/main.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QDB2DriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "db2.json") + public: QDB2DriverPlugin(); @@ -70,12 +73,9 @@ QSqlDriver* QDB2DriverPlugin::create(const QString &name) QStringList QDB2DriverPlugin::keys() const { - QStringList l; - l.append(QLatin1String("QDB2")); - return l; + return QStringList(QStringLiteral("QDB2")); } -Q_EXPORT_STATIC_PLUGIN(QDB2DriverPlugin) -Q_EXPORT_PLUGIN2(qsqldb2, QDB2DriverPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/sqldrivers/ibase/ibase.json b/src/plugins/sqldrivers/ibase/ibase.json new file mode 100644 index 0000000000..e2186b32cd --- /dev/null +++ b/src/plugins/sqldrivers/ibase/ibase.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QIBASE" ] +} diff --git a/src/plugins/sqldrivers/ibase/ibase.pro b/src/plugins/sqldrivers/ibase/ibase.pro index 7870ec8465..ca2a91aa2e 100644 --- a/src/plugins/sqldrivers/ibase/ibase.pro +++ b/src/plugins/sqldrivers/ibase/ibase.pro @@ -1,6 +1,7 @@ TARGET = qsqlibase SOURCES = main.cpp +OTHER_FILES += ibase.json include(../../../sql/drivers/ibase/qsql_ibase.pri) include(../qsqldriverbase.pri) diff --git a/src/plugins/sqldrivers/ibase/main.cpp b/src/plugins/sqldrivers/ibase/main.cpp index c1018944fd..e820c6a333 100644 --- a/src/plugins/sqldrivers/ibase/main.cpp +++ b/src/plugins/sqldrivers/ibase/main.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QIBaseDriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "ibase.json") + public: QIBaseDriverPlugin(); @@ -70,12 +73,9 @@ QSqlDriver* QIBaseDriverPlugin::create(const QString &name) QStringList QIBaseDriverPlugin::keys() const { - QStringList l; - l << QLatin1String("QIBASE"); - return l; + return QStringList(QStringLiteral("QIBASE")); } -Q_EXPORT_STATIC_PLUGIN(QIBaseDriverPlugin) -Q_EXPORT_PLUGIN2(qsqlibase, QIBaseDriverPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/sqldrivers/mysql/main.cpp b/src/plugins/sqldrivers/mysql/main.cpp index 86cae58701..70937218c3 100644 --- a/src/plugins/sqldrivers/mysql/main.cpp +++ b/src/plugins/sqldrivers/mysql/main.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QMYSQLDriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "mysql.json") + public: QMYSQLDriverPlugin(); @@ -76,7 +79,6 @@ QStringList QMYSQLDriverPlugin::keys() const return l; } -Q_EXPORT_STATIC_PLUGIN(QMYSQLDriverPlugin) -Q_EXPORT_PLUGIN2(qsqlmysql, QMYSQLDriverPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/sqldrivers/mysql/mysql.json b/src/plugins/sqldrivers/mysql/mysql.json new file mode 100644 index 0000000000..0caaadb7ce --- /dev/null +++ b/src/plugins/sqldrivers/mysql/mysql.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QMYSQL3", "QMYSQL" ] +} diff --git a/src/plugins/sqldrivers/mysql/mysql.pro b/src/plugins/sqldrivers/mysql/mysql.pro index b6d42fffc8..05d1073701 100644 --- a/src/plugins/sqldrivers/mysql/mysql.pro +++ b/src/plugins/sqldrivers/mysql/mysql.pro @@ -1,6 +1,7 @@ TARGET = qsqlmysql SOURCES = main.cpp +OTHER_FILES += mysql.json include(../../../sql/drivers/mysql/qsql_mysql.pri) include(../qsqldriverbase.pri) diff --git a/src/plugins/sqldrivers/oci/main.cpp b/src/plugins/sqldrivers/oci/main.cpp index 4e5a07a64c..205bfae783 100644 --- a/src/plugins/sqldrivers/oci/main.cpp +++ b/src/plugins/sqldrivers/oci/main.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QOCIDriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "oci.json") + public: QOCIDriverPlugin(); @@ -76,7 +79,6 @@ QStringList QOCIDriverPlugin::keys() const return l; } -Q_EXPORT_STATIC_PLUGIN(QOCIDriverPlugin) -Q_EXPORT_PLUGIN2(qsqloci, QOCIDriverPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/sqldrivers/oci/oci.json b/src/plugins/sqldrivers/oci/oci.json new file mode 100644 index 0000000000..cbed8fc1ac --- /dev/null +++ b/src/plugins/sqldrivers/oci/oci.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QOCI8", "QOCI" ] +} diff --git a/src/plugins/sqldrivers/oci/oci.pro b/src/plugins/sqldrivers/oci/oci.pro index d7dcce9e35..89642f3653 100644 --- a/src/plugins/sqldrivers/oci/oci.pro +++ b/src/plugins/sqldrivers/oci/oci.pro @@ -1,6 +1,7 @@ TARGET = qsqloci SOURCES = main.cpp +OTHER_FILES += oci.json include(../../../sql/drivers/oci/qsql_oci.pri) include(../qsqldriverbase.pri) diff --git a/src/plugins/sqldrivers/odbc/main.cpp b/src/plugins/sqldrivers/odbc/main.cpp index eada54da9e..c55af6e6fc 100644 --- a/src/plugins/sqldrivers/odbc/main.cpp +++ b/src/plugins/sqldrivers/odbc/main.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QODBCDriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "odbc.json") + public: QODBCDriverPlugin(); @@ -76,7 +79,6 @@ QStringList QODBCDriverPlugin::keys() const return l; } -Q_EXPORT_STATIC_PLUGIN(QODBCDriverPlugin) -Q_EXPORT_PLUGIN2(qsqlodbc, QODBCDriverPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/sqldrivers/odbc/odbc.json b/src/plugins/sqldrivers/odbc/odbc.json new file mode 100644 index 0000000000..41640776fb --- /dev/null +++ b/src/plugins/sqldrivers/odbc/odbc.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QODBC3", "QODBC" ] +} diff --git a/src/plugins/sqldrivers/odbc/odbc.pro b/src/plugins/sqldrivers/odbc/odbc.pro index 677eb6eedf..5ebd34fd17 100644 --- a/src/plugins/sqldrivers/odbc/odbc.pro +++ b/src/plugins/sqldrivers/odbc/odbc.pro @@ -1,6 +1,7 @@ TARGET = qsqlodbc SOURCES = main.cpp +OTHER_FILES += odbc.json include(../../../sql/drivers/odbc/qsql_odbc.pri) include(../qsqldriverbase.pri) diff --git a/src/plugins/sqldrivers/psql/main.cpp b/src/plugins/sqldrivers/psql/main.cpp index db233b9486..117df561ab 100644 --- a/src/plugins/sqldrivers/psql/main.cpp +++ b/src/plugins/sqldrivers/psql/main.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QPSQLDriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "psql.json") + public: QPSQLDriverPlugin(); @@ -76,7 +79,6 @@ QStringList QPSQLDriverPlugin::keys() const return l; } -Q_EXPORT_STATIC_PLUGIN(QPSQLDriverPlugin) -Q_EXPORT_PLUGIN2(qsqlpsql, QPSQLDriverPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/sqldrivers/psql/psql.json b/src/plugins/sqldrivers/psql/psql.json new file mode 100644 index 0000000000..1579b99160 --- /dev/null +++ b/src/plugins/sqldrivers/psql/psql.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QPSQL7", "QPSQL" ] +} diff --git a/src/plugins/sqldrivers/psql/psql.pro b/src/plugins/sqldrivers/psql/psql.pro index 8276c0ae90..cb0d27e171 100644 --- a/src/plugins/sqldrivers/psql/psql.pro +++ b/src/plugins/sqldrivers/psql/psql.pro @@ -1,6 +1,7 @@ TARGET = qsqlpsql SOURCES = main.cpp +OTHER_FILES += psql.json include(../../../sql/drivers/psql/qsql_psql.pri) include(../qsqldriverbase.pri) diff --git a/src/plugins/sqldrivers/sqlite/smain.cpp b/src/plugins/sqldrivers/sqlite/smain.cpp index 47cb08b75c..90ed72eedc 100644 --- a/src/plugins/sqldrivers/sqlite/smain.cpp +++ b/src/plugins/sqldrivers/sqlite/smain.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QSQLiteDriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "sqlite.json") + public: QSQLiteDriverPlugin(); @@ -70,12 +73,9 @@ QSqlDriver* QSQLiteDriverPlugin::create(const QString &name) QStringList QSQLiteDriverPlugin::keys() const { - QStringList l; - l << QLatin1String("QSQLITE"); - return l; + return QStringList(QStringLiteral("QSQLITE")); } -Q_EXPORT_STATIC_PLUGIN(QSQLiteDriverPlugin) -Q_EXPORT_PLUGIN2(qsqlite, QSQLiteDriverPlugin) - QT_END_NAMESPACE + +#include "smain.moc" diff --git a/src/plugins/sqldrivers/sqlite/sqlite.json b/src/plugins/sqldrivers/sqlite/sqlite.json new file mode 100644 index 0000000000..3061d83145 --- /dev/null +++ b/src/plugins/sqldrivers/sqlite/sqlite.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QSQLITE" ] +} diff --git a/src/plugins/sqldrivers/sqlite/sqlite.pro b/src/plugins/sqldrivers/sqlite/sqlite.pro index f4c1671a4b..d1f4aa7233 100644 --- a/src/plugins/sqldrivers/sqlite/sqlite.pro +++ b/src/plugins/sqldrivers/sqlite/sqlite.pro @@ -1,6 +1,7 @@ TARGET = qsqlite SOURCES = smain.cpp +OTHER_FILES += sqlite.json include(../../../sql/drivers/sqlite/qsql_sqlite.pri) wince*: DEFINES += HAVE_LOCALTIME_S=0 diff --git a/src/plugins/sqldrivers/sqlite2/smain.cpp b/src/plugins/sqldrivers/sqlite2/smain.cpp index f16057c0a6..49cfd1cdfb 100644 --- a/src/plugins/sqldrivers/sqlite2/smain.cpp +++ b/src/plugins/sqldrivers/sqlite2/smain.cpp @@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE class QSQLite2DriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "sqlite2.json") + public: QSQLite2DriverPlugin(); @@ -70,12 +73,9 @@ QSqlDriver* QSQLite2DriverPlugin::create(const QString &name) QStringList QSQLite2DriverPlugin::keys() const { - QStringList l; - l << QLatin1String("QSQLITE2"); - return l; + return QStringList(QStringLiteral("QSQLITE2")); } -Q_EXPORT_STATIC_PLUGIN(QSQLite2DriverPlugin) -Q_EXPORT_PLUGIN2(qsqlite2, QSQLite2DriverPlugin) - QT_END_NAMESPACE + +#include "smain.moc" diff --git a/src/plugins/sqldrivers/sqlite2/sqlite2.json b/src/plugins/sqldrivers/sqlite2/sqlite2.json new file mode 100644 index 0000000000..47bdae4d60 --- /dev/null +++ b/src/plugins/sqldrivers/sqlite2/sqlite2.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QSQLITE2" ] +} diff --git a/src/plugins/sqldrivers/sqlite2/sqlite2.pro b/src/plugins/sqldrivers/sqlite2/sqlite2.pro index e6197b9906..1cbd31c3dc 100644 --- a/src/plugins/sqldrivers/sqlite2/sqlite2.pro +++ b/src/plugins/sqldrivers/sqlite2/sqlite2.pro @@ -1,6 +1,7 @@ TARGET = qsqlite2 SOURCES = smain.cpp +OTHER_FILES += sqlite2.json include(../../../sql/drivers/sqlite2/qsql_sqlite2.pri) include(../qsqldriverbase.pri) diff --git a/src/plugins/sqldrivers/tds/main.cpp b/src/plugins/sqldrivers/tds/main.cpp index 97ca1c0ed0..c63f0e5606 100644 --- a/src/plugins/sqldrivers/tds/main.cpp +++ b/src/plugins/sqldrivers/tds/main.cpp @@ -54,6 +54,9 @@ QT_BEGIN_NAMESPACE class QTDSDriverPlugin : public QSqlDriverPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "tds.json") + public: QTDSDriverPlugin(); @@ -83,7 +86,6 @@ QStringList QTDSDriverPlugin::keys() const return l; } -Q_EXPORT_STATIC_PLUGIN(QTDSDriverPlugin) -Q_EXPORT_PLUGIN2(qsqltds, QTDSDriverPlugin) - QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/sqldrivers/tds/tds.json b/src/plugins/sqldrivers/tds/tds.json new file mode 100644 index 0000000000..35955db9fa --- /dev/null +++ b/src/plugins/sqldrivers/tds/tds.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QTDS7", "QTDS" ] +} diff --git a/src/plugins/sqldrivers/tds/tds.pro b/src/plugins/sqldrivers/tds/tds.pro index b8e8ded321..9f7c2a193f 100644 --- a/src/plugins/sqldrivers/tds/tds.pro +++ b/src/plugins/sqldrivers/tds/tds.pro @@ -1,6 +1,7 @@ TARGET = qsqltds SOURCES = main.cpp +OTHER_FILES += tds.json include(../../../sql/drivers/tds/qsql_tds.pri) include(../qsqldriverbase.pri) -- cgit v1.2.3 From bf66eebbc28b1f405a49a68d3f6c341d433159ea Mon Sep 17 00:00:00 2001 From: jian liang Date: Sat, 18 Feb 2012 08:43:29 +0800 Subject: Fix to exit of adopted thread watcher in Windows Don't register the thread handle and QThread object pointer to watch list for adopted thread watcher thread in Windows. Otherwise the watcher thread will never exit and can't clean up its own QThreadData and QAdoptedThread object. Task-number: QTBUG-23961 Change-Id: Ia84326cf3cfd978d2b003ccc1bb6861db950e899 Reviewed-by: Friedemann Kleint Reviewed-by: Joerg Bornemann --- src/corelib/thread/qthread_win.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index afcfb2c949..38fb6ef8dd 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -72,7 +72,7 @@ QT_BEGIN_NAMESPACE void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread); -void qt_adopted_thread_watcher_function(void *); +DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID); static DWORD qt_current_thread_data_tls_index = TLS_OUT_OF_INDEXES; void qt_create_tls() @@ -147,7 +147,7 @@ void QAdoptedThread::init() static QVector qt_adopted_thread_handles; static QVector qt_adopted_qthreads; static QMutex qt_adopted_thread_watcher_mutex; -static HANDLE qt_adopted_thread_watcher_handle = 0; +static DWORD qt_adopted_thread_watcher_id = 0; static HANDLE qt_adopted_thread_wakeup = 0; /*! \internal @@ -158,18 +158,25 @@ static HANDLE qt_adopted_thread_wakeup = 0; void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread) { QMutexLocker lock(&qt_adopted_thread_watcher_mutex); + + if (GetCurrentThreadId() == qt_adopted_thread_watcher_id) { +#if !defined(Q_OS_WINCE) || (defined(_WIN32_WCE) && (_WIN32_WCE>=0x600)) + CloseHandle(adoptedThreadHandle); +#endif + return; + } + qt_adopted_thread_handles.append(adoptedThreadHandle); qt_adopted_qthreads.append(qthread); // Start watcher thread if it is not already running. - if (qt_adopted_thread_watcher_handle == 0) { + if (qt_adopted_thread_watcher_id == 0) { if (qt_adopted_thread_wakeup == 0) { qt_adopted_thread_wakeup = CreateEvent(0, false, false, 0); qt_adopted_thread_handles.prepend(qt_adopted_thread_wakeup); } - qt_adopted_thread_watcher_handle = - (HANDLE)_beginthread(qt_adopted_thread_watcher_function, 0, NULL); + CreateThread(0, 0, qt_adopted_thread_watcher_function, 0, 0, &qt_adopted_thread_watcher_id); } else { SetEvent(qt_adopted_thread_wakeup); } @@ -180,13 +187,13 @@ void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread) When this happens it derefs the QThreadData for the adopted thread to make sure it gets cleaned up properly. */ -void qt_adopted_thread_watcher_function(void *) +DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID) { forever { qt_adopted_thread_watcher_mutex.lock(); if (qt_adopted_thread_handles.count() == 1) { - qt_adopted_thread_watcher_handle = 0; + qt_adopted_thread_watcher_id = 0; qt_adopted_thread_watcher_mutex.unlock(); break; } @@ -244,6 +251,12 @@ void qt_adopted_thread_watcher_function(void *) qt_adopted_qthreads.remove(qthreadIndex); } } + + QThreadData *threadData = reinterpret_cast(TlsGetValue(qt_current_thread_data_tls_index)); + if (threadData) + threadData->deref(); + + return 0; } #if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINCE) -- cgit v1.2.3 From 6ee0135e9d43bfd56d948d088781dc014ef39aa1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 20 Feb 2012 15:16:25 +0100 Subject: QFutureWatcher: Make constructors explicit Change-Id: I363665725869993b10985004c1c6441ded435dbc Reviewed-by: Bradley T. Hughes --- src/concurrent/qfuturewatcher.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/concurrent/qfuturewatcher.h b/src/concurrent/qfuturewatcher.h index 11dab42174..439a25d844 100644 --- a/src/concurrent/qfuturewatcher.h +++ b/src/concurrent/qfuturewatcher.h @@ -63,7 +63,7 @@ class Q_CONCURRENT_EXPORT QFutureWatcherBase : public QObject Q_DECLARE_PRIVATE(QFutureWatcherBase) public: - QFutureWatcherBase(QObject *parent = 0); + explicit QFutureWatcherBase(QObject *parent = 0); int progressValue() const; int progressMinimum() const; @@ -119,7 +119,7 @@ template class QFutureWatcher : public QFutureWatcherBase { public: - QFutureWatcher(QObject *_parent = 0) + explicit QFutureWatcher(QObject *_parent = 0) : QFutureWatcherBase(_parent) { } ~QFutureWatcher() @@ -189,7 +189,7 @@ template <> class QFutureWatcher : public QFutureWatcherBase { public: - QFutureWatcher(QObject *_parent = 0) + explicit QFutureWatcher(QObject *_parent = 0) : QFutureWatcherBase(_parent) { } ~QFutureWatcher() -- cgit v1.2.3 From e430ddfafcc6e8fa9fecb9c816908c3edce08d77 Mon Sep 17 00:00:00 2001 From: Teemu Katajisto Date: Thu, 23 Feb 2012 16:50:29 +0200 Subject: Implement isSharing() and isValid() methods for QCocoaGLContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shared resources may have been used when initializing NSOpenGLContext but QCocoaGLContext did not implement isSharing(). This caused default implementation to return false always and therefore shared resource test case failed. Implemented also another missing method, isValid(). Task-number: QTBUG-23061 Change-Id: Ia912450035b584ea90a02a7d88d6ae531c3cbadf Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaglcontext.h | 4 ++++ src/plugins/platforms/cocoa/qcocoaglcontext.mm | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h index b8582022f6..4f80511f61 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.h +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h @@ -71,10 +71,14 @@ public: static NSOpenGLPixelFormat *createNSOpenGLPixelFormat(const QSurfaceFormat &format); NSOpenGLContext *nsOpenGLContext() const; + bool isSharing() const; + bool isValid() const; + private: void setActiveWindow(QWindow *window); NSOpenGLContext *m_context; + NSOpenGLContext *m_shareContext; QSurfaceFormat m_format; QWeakPointer m_currentWindow; }; diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index 960163d727..637678c19e 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -51,13 +51,19 @@ QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share) : m_format(format) { - QCocoaAutoReleasePool pool; // For the SG Canvas render thread. + QCocoaAutoReleasePool pool; // For the SG Canvas render thread NSOpenGLPixelFormat *pixelFormat = static_cast (qcgl_createNSOpenGLPixelFormat(format)); - NSOpenGLContext *actualShare = share ? static_cast(share)->m_context : 0; + m_shareContext = share ? static_cast(share)->nsOpenGLContext() : nil; m_context = [NSOpenGLContext alloc]; - [m_context initWithFormat:pixelFormat shareContext:actualShare]; + [m_context initWithFormat:pixelFormat shareContext:m_shareContext]; + + if (!m_context && m_shareContext) { + // try without shared context + m_shareContext = nil; + [m_context initWithFormat:pixelFormat shareContext:nil]; + } const GLint interval = 1; [m_context setValues:&interval forParameter:NSOpenGLCPSwapInterval]; @@ -139,3 +145,12 @@ NSOpenGLContext *QCocoaGLContext::nsOpenGLContext() const return m_context; } +bool QCocoaGLContext::isValid() const +{ + return m_context != nil; +} + +bool QCocoaGLContext::isSharing() const +{ + return m_shareContext != nil; +} -- cgit v1.2.3 From 71660ee5652f1509ff9632a45e4aa1bc0040387d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 25 Feb 2012 11:07:52 +0100 Subject: Fix compilation without QT_DEPRECATED_SINCE QAbstractItemModel::reset() is deprecated Change-Id: I2d9aa9fade1660df14945ca11123341fce504050 Reviewed-by: Stephen Kelly --- src/corelib/itemmodels/qsortfilterproxymodel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index ebd1ce2a70..b7ef69423f 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -883,9 +883,10 @@ void QSortFilterProxyModelPrivate::source_items_removed( if (proxy_count > source_to_proxy.size()) { // mapping is in an inconsistent state -- redo the whole mapping qWarning("QSortFilterProxyModel: inconsistent changes reported by source model"); - remove_from_mapping(source_parent); Q_Q(QSortFilterProxyModel); - q->reset(); + q->beginResetModel(); + remove_from_mapping(source_parent); + q->endResetModel(); return; } -- cgit v1.2.3 From 1118f28b86993282b9fcf78e938bff5ef2017a09 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 24 Feb 2012 15:18:15 +0100 Subject: Fix a crash in QSystemLocalePrivate::uiLanguages(). Use the correct calling convention. Discovered by the mimetype test in Qt 5. Change-Id: I79b97325dd69466885a64c238935107bf14e9a0d Reviewed-by: Oswald Buddenhagen Reviewed-by: Marius Storm-Olsen (cherry picked from commit bc6e35d94325f4b18caec7ce0824c5beab95cdd7) Reviewed-by: Friedemann Kleint --- src/corelib/tools/qlocale_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp index cd9fffc7a5..e787f2fa2a 100644 --- a/src/corelib/tools/qlocale_win.cpp +++ b/src/corelib/tools/qlocale_win.cpp @@ -525,7 +525,7 @@ QVariant QSystemLocalePrivate::toCurrencyString(const QSystemLocale::CurrencyToS QVariant QSystemLocalePrivate::uiLanguages() { if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) { - typedef BOOL (*GetUserPreferredUILanguagesFunc) ( + typedef BOOL (WINAPI *GetUserPreferredUILanguagesFunc) ( DWORD dwFlags, PULONG pulNumLanguages, PWSTR pwszLanguagesBuffer, -- cgit v1.2.3 From d91add71e79dcae45f9cac02f6d3d542afee899c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 Feb 2012 19:19:32 +0100 Subject: QSslError: fix wrong #endif placement This would break a namespaced Qt when QT_NO_DEBUG_STREAM was in effect. Unlikely to hit, but nevertheless fixworthy. Change-Id: Ie2a4cf4334a6a610c84233ab1ca89b928386c91a Reviewed-by: Richard J. Moore --- src/network/ssl/qsslerror.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp index acb8d70d09..224ef9db8f 100644 --- a/src/network/ssl/qsslerror.cpp +++ b/src/network/ssl/qsslerror.cpp @@ -95,9 +95,9 @@ #include "qsslsocket.h" #ifndef QT_NO_DEBUG_STREAM #include +#endif QT_BEGIN_NAMESPACE -#endif class QSslErrorPrivate { -- cgit v1.2.3 From 4f4491e0b682e705cc958829a1d122298990dac7 Mon Sep 17 00:00:00 2001 From: ABBAPOH Date: Sun, 26 Feb 2012 11:48:53 +0400 Subject: Fix doc according to current method signature Change-Id: I23d0f7a88f4c092c1e7cd2742fdf6e6f68ad485a Reviewed-by: David Faure --- src/corelib/mimetypes/qmimetype.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp index 77592880a0..4099487f9b 100644 --- a/src/corelib/mimetypes/qmimetype.cpp +++ b/src/corelib/mimetypes/qmimetype.cpp @@ -300,7 +300,6 @@ QString QMimeType::name() const Returns the description of the MIME type to be displayed on user interfaces. The system language (QLocale::system().name()) is used to select the appropriate translation. - Another language can be specified by setting the \a localeName argument. */ QString QMimeType::comment() const { -- cgit v1.2.3 From 5cc1a87250a45068e3ed4cf3e83611ea79b9e37a Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 26 Feb 2012 11:00:44 +0100 Subject: Remove usage of deprecated QRect::unite Change-Id: I1920da995fde6ff2a8b2e3facddeee6e3c17b44c Reviewed-by: Frederik Gladhorn --- src/widgets/itemviews/qcolumnview.cpp | 2 +- src/widgets/widgets/qworkspace.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp index 5dec62acc2..6758aeb337 100644 --- a/src/widgets/itemviews/qcolumnview.cpp +++ b/src/widgets/itemviews/qcolumnview.cpp @@ -481,7 +481,7 @@ QRegion QColumnView::visualRegionForSelection(const QItemSelection &selection) c QRegion firstRegion = visualRect(firstIdx); QRegion lastRegion = visualRect(lastIdx); - return firstRegion.unite(lastRegion); + return firstRegion.united(lastRegion); } /*! diff --git a/src/widgets/widgets/qworkspace.cpp b/src/widgets/widgets/qworkspace.cpp index 80f0a7e44a..0031a71ccd 100644 --- a/src/widgets/widgets/qworkspace.cpp +++ b/src/widgets/widgets/qworkspace.cpp @@ -3204,7 +3204,7 @@ QRect QWorkspacePrivate::updateWorkspace() QWorkspaceChild *child = *it; ++it; if (!child->isHidden()) - r = r.unite(child->geometry()); + r = r.united(child->geometry()); } vbar->blockSignals(true); hbar->blockSignals(true); -- cgit v1.2.3 From 7679fcfeb504ac9641ce331704dbe669ea4b329d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 21 Feb 2012 13:41:53 +0100 Subject: QPrinterInfo: remove unused variable Change-Id: I1a3db07e7fe25066a6b13ca41854566ccb1298df Reviewed-by: Olivier Goffart --- src/printsupport/kernel/qprinterinfo_unix.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/printsupport/kernel/qprinterinfo_unix.cpp b/src/printsupport/kernel/qprinterinfo_unix.cpp index fba3b4d0a3..ae0885c0f4 100644 --- a/src/printsupport/kernel/qprinterinfo_unix.cpp +++ b/src/printsupport/kernel/qprinterinfo_unix.cpp @@ -587,7 +587,6 @@ void qt_parseEtcLpMember(QList *printers) if (dirs.isEmpty()) return; - QString tmp; for (int i = 0; i < dirs.size(); ++i) { QFileInfo printer = dirs.at(i); // I haven't found any real documentation, so I'm guessing that -- cgit v1.2.3 From 47525e689694df0eec0a2f03e8bf67eed91da295 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 26 Feb 2012 03:11:19 +0000 Subject: uic: remove unused QRegExp #includes QRegExp is not used, so they're unnecessary. Change-Id: I3480bcbe013a0bf15e2ee4fa30862fe035820eea Reviewed-by: Thiago Macieira --- src/tools/uic/driver.cpp | 1 - src/tools/uic/uic.cpp | 1 - 2 files changed, 2 deletions(-) (limited to 'src') diff --git a/src/tools/uic/driver.cpp b/src/tools/uic/driver.cpp index 16dc12f277..ea1d4f21f3 100644 --- a/src/tools/uic/driver.cpp +++ b/src/tools/uic/driver.cpp @@ -43,7 +43,6 @@ #include "uic.h" #include "ui4.h" -#include #include #include diff --git a/src/tools/uic/uic.cpp b/src/tools/uic/uic.cpp index 2de3352cfc..4ae04149e8 100644 --- a/src/tools/uic/uic.cpp +++ b/src/tools/uic/uic.cpp @@ -58,7 +58,6 @@ #include #include -#include #include #include -- cgit v1.2.3 From 3e4a3bafb639f2ec77d44c80662157745b68f546 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Feb 2012 15:18:27 +0100 Subject: QFixed{,Size}: reformulate some functions in a constexpr-friendly way The main change is the addition of a new constructor that passes its argument into 'val' verbatim. In order to disambiguate it from the existing QFixed(int) constructor, it takes a second 'int' argument. This is too ugly for public API, so it's private, and only used by static QFixed fromFixed(int), which is the existing named constructor with the same semantics. The rest of the changes simply reformulate their operations in terms of fromFixed(). This makes them ready to be constexpr'ed. Change-Id: I2a3813d62bd4124064755de6b00526a60fc82c1d Reviewed-by: Olivier Goffart --- src/gui/painting/qfixed_p.h | 47 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/gui/painting/qfixed_p.h b/src/gui/painting/qfixed_p.h index d30328b0fa..95fb6893b3 100644 --- a/src/gui/painting/qfixed_p.h +++ b/src/gui/painting/qfixed_p.h @@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE struct QFixed { +private: + QFixed(int val, int) : val(val) {} // 2nd int is just a dummy for disambiguation public: QFixed() : val(0) {} QFixed(int i) : val(i<<6) {} @@ -67,8 +69,8 @@ public: QFixed &operator=(int i) { val = (i<<6); return *this; } QFixed &operator=(long i) { val = (i<<6); return *this; } - static QFixed fromReal(qreal r) { QFixed f; f.val = (int)(r*qreal(64)); return f; } - static QFixed fromFixed(int fixed) { QFixed f; f.val = fixed; return f; } + static QFixed fromReal(qreal r) { return fromFixed((int)(r*qreal(64))); } + static QFixed fromFixed(int fixed) { return QFixed(fixed,0); } // uses private ctor inline int value() const { return val; } inline void setValue(int value) { val = value; } @@ -77,23 +79,23 @@ public: inline qreal toReal() const { return ((qreal)val)/(qreal)64; } inline int truncate() const { return val>>6; } - inline QFixed round() const { QFixed f; f.val = ((val)+32) & -64; return f; } - inline QFixed floor() const { QFixed f; f.val = (val) & -64; return f; } - inline QFixed ceil() const { QFixed f; f.val = (val+63) & -64; return f; } + inline QFixed round() const { return fromFixed(((val)+32) & -64); } + inline QFixed floor() const { return fromFixed((val) & -64); } + inline QFixed ceil() const { return fromFixed((val+63) & -64); } - inline QFixed operator+(int i) const { QFixed f; f.val = (val + (i<<6)); return f; } - inline QFixed operator+(uint i) const { QFixed f; f.val = (val + (i<<6)); return f; } - inline QFixed operator+(const QFixed &other) const { QFixed f; f.val = (val + other.val); return f; } + inline QFixed operator+(int i) const { return fromFixed((val + (i<<6))); } + inline QFixed operator+(uint i) const { return fromFixed((val + (i<<6))); } + inline QFixed operator+(const QFixed &other) const { return fromFixed((val + other.val)); } inline QFixed &operator+=(int i) { val += (i<<6); return *this; } inline QFixed &operator+=(uint i) { val += (i<<6); return *this; } inline QFixed &operator+=(const QFixed &other) { val += other.val; return *this; } - inline QFixed operator-(int i) const { QFixed f; f.val = (val - (i<<6)); return f; } - inline QFixed operator-(uint i) const { QFixed f; f.val = (val - (i<<6)); return f; } - inline QFixed operator-(const QFixed &other) const { QFixed f; f.val = (val - other.val); return f; } + inline QFixed operator-(int i) const { return fromFixed((val - (i<<6))); } + inline QFixed operator-(uint i) const { return fromFixed((val - (i<<6))); } + inline QFixed operator-(const QFixed &other) const { return fromFixed((val - other.val)); } inline QFixed &operator-=(int i) { val -= (i<<6); return *this; } inline QFixed &operator-=(uint i) { val -= (i<<6); return *this; } inline QFixed &operator-=(const QFixed &other) { val -= other.val; return *this; } - inline QFixed operator-() const { QFixed f; f.val = -val; return f; } + inline QFixed operator-() const { return fromFixed(-val); } inline bool operator==(const QFixed &other) const { return val == other.val; } inline bool operator!=(const QFixed &other) const { return val != other.val; } @@ -120,7 +122,7 @@ public: } return *this; } - inline QFixed operator/(int d) const { QFixed f; f.val = val/d; return f; } + inline QFixed operator/(int d) const { return fromFixed(val/d); } inline QFixed operator/(QFixed b) const { QFixed f = *this; return (f /= b); } inline QFixed operator>>(int d) const { QFixed f = *this; f.val >>= d; return f; } inline QFixed &operator*=(int i) { val *= i; return *this; } @@ -136,21 +138,21 @@ public: val = neg ? -res : res; return *this; } - inline QFixed operator*(int i) const { QFixed f = *this; return (f *= i); } - inline QFixed operator*(uint i) const { QFixed f = *this; return (f *= i); } + inline QFixed operator*(int i) const { return fromFixed(val * i); } + inline QFixed operator*(uint i) const { return fromFixed(val * i); } inline QFixed operator*(const QFixed &o) const { QFixed f = *this; return (f *= o); } private: QFixed(qreal i) : val((int)(i*qreal(64))) {} QFixed &operator=(qreal i) { val = (int)(i*qreal(64)); return *this; } - inline QFixed operator+(qreal i) const { QFixed f; f.val = (val + (int)(i*qreal(64))); return f; } + inline QFixed operator+(qreal i) const { return fromFixed((val + (int)(i*qreal(64)))); } inline QFixed &operator+=(qreal i) { val += (int)(i*64); return *this; } - inline QFixed operator-(qreal i) const { QFixed f; f.val = (val - (int)(i*qreal(64))); return f; } + inline QFixed operator-(qreal i) const { return fromFixed((val - (int)(i*qreal(64)))); } inline QFixed &operator-=(qreal i) { val -= (int)(i*64); return *this; } inline QFixed &operator/=(qreal r) { val = (int)(val/r); return *this; } - inline QFixed operator/(qreal d) const { QFixed f; f.val = (int)(val/d); return f; } + inline QFixed operator/(qreal d) const { return fromFixed((int)(val/d)); } inline QFixed &operator*=(qreal d) { val = (int) (val*d); return *this; } - inline QFixed operator*(qreal d) const { QFixed f = *this; return (f *= d); } + inline QFixed operator*(qreal d) const { return fromFixed((int) (val*d)); } int val; }; Q_DECLARE_TYPEINFO(QFixed, Q_PRIMITIVE_TYPE); @@ -206,12 +208,11 @@ inline QFixedPoint operator+(const QFixedPoint &p1, const QFixedPoint &p2) struct QFixedSize { QFixed width; QFixed height; + QFixedSize() {} + QFixedSize(QFixed _width, QFixed _height) : width(_width), height(_height) {} QSizeF toSizeF() const { return QSizeF(width.toReal(), height.toReal()); } static QFixedSize fromSizeF(const QSizeF &s) { - QFixedSize size; - size.width = QFixed::fromReal(s.width()); - size.height = QFixed::fromReal(s.height()); - return size; + return QFixedSize(QFixed::fromReal(s.width()), QFixed::fromReal(s.height())); } }; Q_DECLARE_TYPEINFO(QFixedSize, Q_PRIMITIVE_TYPE); -- cgit v1.2.3 From 5f65d8ea25dcb5c4165890ad957a7b8869caa180 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Feb 2012 15:27:40 +0100 Subject: QFixed: make constexpr Make most QFixed{,Size,Point} members constexpr. See f3141c58badbd2da9eb42021e9704742c3e52a9b for rationale. Change-Id: I0b44f59bb768e1f79c57e1c9a0dc67afb515e03f Reviewed-by: Olivier Goffart --- src/gui/painting/qfixed_p.h | 136 ++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/gui/painting/qfixed_p.h b/src/gui/painting/qfixed_p.h index 95fb6893b3..44772a4bb5 100644 --- a/src/gui/painting/qfixed_p.h +++ b/src/gui/painting/qfixed_p.h @@ -61,49 +61,49 @@ QT_BEGIN_NAMESPACE struct QFixed { private: - QFixed(int val, int) : val(val) {} // 2nd int is just a dummy for disambiguation + Q_DECL_CONSTEXPR QFixed(int val, int) : val(val) {} // 2nd int is just a dummy for disambiguation public: - QFixed() : val(0) {} - QFixed(int i) : val(i<<6) {} - QFixed(long i) : val(i<<6) {} + Q_DECL_CONSTEXPR QFixed() : val(0) {} + Q_DECL_CONSTEXPR QFixed(int i) : val(i<<6) {} + Q_DECL_CONSTEXPR QFixed(long i) : val(i<<6) {} QFixed &operator=(int i) { val = (i<<6); return *this; } QFixed &operator=(long i) { val = (i<<6); return *this; } - static QFixed fromReal(qreal r) { return fromFixed((int)(r*qreal(64))); } - static QFixed fromFixed(int fixed) { return QFixed(fixed,0); } // uses private ctor + Q_DECL_CONSTEXPR static QFixed fromReal(qreal r) { return fromFixed((int)(r*qreal(64))); } + Q_DECL_CONSTEXPR static QFixed fromFixed(int fixed) { return QFixed(fixed,0); } // uses private ctor - inline int value() const { return val; } + Q_DECL_CONSTEXPR inline int value() const { return val; } inline void setValue(int value) { val = value; } - inline int toInt() const { return (((val)+32) & -64)>>6; } - inline qreal toReal() const { return ((qreal)val)/(qreal)64; } + Q_DECL_CONSTEXPR inline int toInt() const { return (((val)+32) & -64)>>6; } + Q_DECL_CONSTEXPR inline qreal toReal() const { return ((qreal)val)/(qreal)64; } - inline int truncate() const { return val>>6; } - inline QFixed round() const { return fromFixed(((val)+32) & -64); } - inline QFixed floor() const { return fromFixed((val) & -64); } - inline QFixed ceil() const { return fromFixed((val+63) & -64); } + Q_DECL_CONSTEXPR inline int truncate() const { return val>>6; } + Q_DECL_CONSTEXPR inline QFixed round() const { return fromFixed(((val)+32) & -64); } + Q_DECL_CONSTEXPR inline QFixed floor() const { return fromFixed((val) & -64); } + Q_DECL_CONSTEXPR inline QFixed ceil() const { return fromFixed((val+63) & -64); } - inline QFixed operator+(int i) const { return fromFixed((val + (i<<6))); } - inline QFixed operator+(uint i) const { return fromFixed((val + (i<<6))); } - inline QFixed operator+(const QFixed &other) const { return fromFixed((val + other.val)); } + Q_DECL_CONSTEXPR inline QFixed operator+(int i) const { return fromFixed((val + (i<<6))); } + Q_DECL_CONSTEXPR inline QFixed operator+(uint i) const { return fromFixed((val + (i<<6))); } + Q_DECL_CONSTEXPR inline QFixed operator+(const QFixed &other) const { return fromFixed((val + other.val)); } inline QFixed &operator+=(int i) { val += (i<<6); return *this; } inline QFixed &operator+=(uint i) { val += (i<<6); return *this; } inline QFixed &operator+=(const QFixed &other) { val += other.val; return *this; } - inline QFixed operator-(int i) const { return fromFixed((val - (i<<6))); } - inline QFixed operator-(uint i) const { return fromFixed((val - (i<<6))); } - inline QFixed operator-(const QFixed &other) const { return fromFixed((val - other.val)); } + Q_DECL_CONSTEXPR inline QFixed operator-(int i) const { return fromFixed((val - (i<<6))); } + Q_DECL_CONSTEXPR inline QFixed operator-(uint i) const { return fromFixed((val - (i<<6))); } + Q_DECL_CONSTEXPR inline QFixed operator-(const QFixed &other) const { return fromFixed((val - other.val)); } inline QFixed &operator-=(int i) { val -= (i<<6); return *this; } inline QFixed &operator-=(uint i) { val -= (i<<6); return *this; } inline QFixed &operator-=(const QFixed &other) { val -= other.val; return *this; } - inline QFixed operator-() const { return fromFixed(-val); } + Q_DECL_CONSTEXPR inline QFixed operator-() const { return fromFixed(-val); } - inline bool operator==(const QFixed &other) const { return val == other.val; } - inline bool operator!=(const QFixed &other) const { return val != other.val; } - inline bool operator<(const QFixed &other) const { return val < other.val; } - inline bool operator>(const QFixed &other) const { return val > other.val; } - inline bool operator<=(const QFixed &other) const { return val <= other.val; } - inline bool operator>=(const QFixed &other) const { return val >= other.val; } - inline bool operator!() const { return !val; } + Q_DECL_CONSTEXPR inline bool operator==(const QFixed &other) const { return val == other.val; } + Q_DECL_CONSTEXPR inline bool operator!=(const QFixed &other) const { return val != other.val; } + Q_DECL_CONSTEXPR inline bool operator<(const QFixed &other) const { return val < other.val; } + Q_DECL_CONSTEXPR inline bool operator>(const QFixed &other) const { return val > other.val; } + Q_DECL_CONSTEXPR inline bool operator<=(const QFixed &other) const { return val <= other.val; } + Q_DECL_CONSTEXPR inline bool operator>=(const QFixed &other) const { return val >= other.val; } + Q_DECL_CONSTEXPR inline bool operator!() const { return !val; } inline QFixed &operator/=(int x) { val /= x; return *this; } inline QFixed &operator/=(const QFixed &o) { @@ -122,7 +122,7 @@ public: } return *this; } - inline QFixed operator/(int d) const { return fromFixed(val/d); } + Q_DECL_CONSTEXPR inline QFixed operator/(int d) const { return fromFixed(val/d); } inline QFixed operator/(QFixed b) const { QFixed f = *this; return (f /= b); } inline QFixed operator>>(int d) const { QFixed f = *this; f.val >>= d; return f; } inline QFixed &operator*=(int i) { val *= i; return *this; } @@ -138,50 +138,50 @@ public: val = neg ? -res : res; return *this; } - inline QFixed operator*(int i) const { return fromFixed(val * i); } - inline QFixed operator*(uint i) const { return fromFixed(val * i); } + Q_DECL_CONSTEXPR inline QFixed operator*(int i) const { return fromFixed(val * i); } + Q_DECL_CONSTEXPR inline QFixed operator*(uint i) const { return fromFixed(val * i); } inline QFixed operator*(const QFixed &o) const { QFixed f = *this; return (f *= o); } private: - QFixed(qreal i) : val((int)(i*qreal(64))) {} + Q_DECL_CONSTEXPR QFixed(qreal i) : val((int)(i*qreal(64))) {} QFixed &operator=(qreal i) { val = (int)(i*qreal(64)); return *this; } - inline QFixed operator+(qreal i) const { return fromFixed((val + (int)(i*qreal(64)))); } + Q_DECL_CONSTEXPR inline QFixed operator+(qreal i) const { return fromFixed((val + (int)(i*qreal(64)))); } inline QFixed &operator+=(qreal i) { val += (int)(i*64); return *this; } - inline QFixed operator-(qreal i) const { return fromFixed((val - (int)(i*qreal(64)))); } + Q_DECL_CONSTEXPR inline QFixed operator-(qreal i) const { return fromFixed((val - (int)(i*qreal(64)))); } inline QFixed &operator-=(qreal i) { val -= (int)(i*64); return *this; } inline QFixed &operator/=(qreal r) { val = (int)(val/r); return *this; } - inline QFixed operator/(qreal d) const { return fromFixed((int)(val/d)); } + Q_DECL_CONSTEXPR inline QFixed operator/(qreal d) const { return fromFixed((int)(val/d)); } inline QFixed &operator*=(qreal d) { val = (int) (val*d); return *this; } - inline QFixed operator*(qreal d) const { return fromFixed((int) (val*d)); } + Q_DECL_CONSTEXPR inline QFixed operator*(qreal d) const { return fromFixed((int) (val*d)); } int val; }; Q_DECLARE_TYPEINFO(QFixed, Q_PRIMITIVE_TYPE); #define QFIXED_MAX (INT_MAX/256) -inline int qRound(const QFixed &f) { return f.toInt(); } -inline int qFloor(const QFixed &f) { return f.floor().truncate(); } - -inline QFixed operator*(int i, const QFixed &d) { return d*i; } -inline QFixed operator+(int i, const QFixed &d) { return d+i; } -inline QFixed operator-(int i, const QFixed &d) { return -(d-i); } -inline QFixed operator*(uint i, const QFixed &d) { return d*i; } -inline QFixed operator+(uint i, const QFixed &d) { return d+i; } -inline QFixed operator-(uint i, const QFixed &d) { return -(d-i); } -// inline QFixed operator*(qreal d, const QFixed &d2) { return d2*d; } - -inline bool operator==(const QFixed &f, int i) { return f.value() == (i<<6); } -inline bool operator==(int i, const QFixed &f) { return f.value() == (i<<6); } -inline bool operator!=(const QFixed &f, int i) { return f.value() != (i<<6); } -inline bool operator!=(int i, const QFixed &f) { return f.value() != (i<<6); } -inline bool operator<=(const QFixed &f, int i) { return f.value() <= (i<<6); } -inline bool operator<=(int i, const QFixed &f) { return (i<<6) <= f.value(); } -inline bool operator>=(const QFixed &f, int i) { return f.value() >= (i<<6); } -inline bool operator>=(int i, const QFixed &f) { return (i<<6) >= f.value(); } -inline bool operator<(const QFixed &f, int i) { return f.value() < (i<<6); } -inline bool operator<(int i, const QFixed &f) { return (i<<6) < f.value(); } -inline bool operator>(const QFixed &f, int i) { return f.value() > (i<<6); } -inline bool operator>(int i, const QFixed &f) { return (i<<6) > f.value(); } +Q_DECL_CONSTEXPR inline int qRound(const QFixed &f) { return f.toInt(); } +Q_DECL_CONSTEXPR inline int qFloor(const QFixed &f) { return f.floor().truncate(); } + +Q_DECL_CONSTEXPR inline QFixed operator*(int i, const QFixed &d) { return d*i; } +Q_DECL_CONSTEXPR inline QFixed operator+(int i, const QFixed &d) { return d+i; } +Q_DECL_CONSTEXPR inline QFixed operator-(int i, const QFixed &d) { return -(d-i); } +Q_DECL_CONSTEXPR inline QFixed operator*(uint i, const QFixed &d) { return d*i; } +Q_DECL_CONSTEXPR inline QFixed operator+(uint i, const QFixed &d) { return d+i; } +Q_DECL_CONSTEXPR inline QFixed operator-(uint i, const QFixed &d) { return -(d-i); } +// Q_DECL_CONSTEXPR inline QFixed operator*(qreal d, const QFixed &d2) { return d2*d; } + +Q_DECL_CONSTEXPR inline bool operator==(const QFixed &f, int i) { return f.value() == (i<<6); } +Q_DECL_CONSTEXPR inline bool operator==(int i, const QFixed &f) { return f.value() == (i<<6); } +Q_DECL_CONSTEXPR inline bool operator!=(const QFixed &f, int i) { return f.value() != (i<<6); } +Q_DECL_CONSTEXPR inline bool operator!=(int i, const QFixed &f) { return f.value() != (i<<6); } +Q_DECL_CONSTEXPR inline bool operator<=(const QFixed &f, int i) { return f.value() <= (i<<6); } +Q_DECL_CONSTEXPR inline bool operator<=(int i, const QFixed &f) { return (i<<6) <= f.value(); } +Q_DECL_CONSTEXPR inline bool operator>=(const QFixed &f, int i) { return f.value() >= (i<<6); } +Q_DECL_CONSTEXPR inline bool operator>=(int i, const QFixed &f) { return (i<<6) >= f.value(); } +Q_DECL_CONSTEXPR inline bool operator<(const QFixed &f, int i) { return f.value() < (i<<6); } +Q_DECL_CONSTEXPR inline bool operator<(int i, const QFixed &f) { return (i<<6) < f.value(); } +Q_DECL_CONSTEXPR inline bool operator>(const QFixed &f, int i) { return f.value() > (i<<6); } +Q_DECL_CONSTEXPR inline bool operator>(int i, const QFixed &f) { return (i<<6) > f.value(); } #ifndef QT_NO_DEBUG_STREAM inline QDebug &operator<<(QDebug &dbg, const QFixed &f) @@ -191,27 +191,27 @@ inline QDebug &operator<<(QDebug &dbg, const QFixed &f) struct QFixedPoint { QFixed x; QFixed y; - inline QFixedPoint() {} - inline QFixedPoint(const QFixed &_x, const QFixed &_y) : x(_x), y(_y) {} - QPointF toPointF() const { return QPointF(x.toReal(), y.toReal()); } - static QFixedPoint fromPointF(const QPointF &p) { + Q_DECL_CONSTEXPR inline QFixedPoint() {} + Q_DECL_CONSTEXPR inline QFixedPoint(const QFixed &_x, const QFixed &_y) : x(_x), y(_y) {} + Q_DECL_CONSTEXPR QPointF toPointF() const { return QPointF(x.toReal(), y.toReal()); } + Q_DECL_CONSTEXPR static QFixedPoint fromPointF(const QPointF &p) { return QFixedPoint(QFixed::fromReal(p.x()), QFixed::fromReal(p.y())); } }; Q_DECLARE_TYPEINFO(QFixedPoint, Q_PRIMITIVE_TYPE); -inline QFixedPoint operator-(const QFixedPoint &p1, const QFixedPoint &p2) +Q_DECL_CONSTEXPR inline QFixedPoint operator-(const QFixedPoint &p1, const QFixedPoint &p2) { return QFixedPoint(p1.x - p2.x, p1.y - p2.y); } -inline QFixedPoint operator+(const QFixedPoint &p1, const QFixedPoint &p2) +Q_DECL_CONSTEXPR inline QFixedPoint operator+(const QFixedPoint &p1, const QFixedPoint &p2) { return QFixedPoint(p1.x + p2.x, p1.y + p2.y); } struct QFixedSize { QFixed width; QFixed height; - QFixedSize() {} - QFixedSize(QFixed _width, QFixed _height) : width(_width), height(_height) {} - QSizeF toSizeF() const { return QSizeF(width.toReal(), height.toReal()); } - static QFixedSize fromSizeF(const QSizeF &s) { + Q_DECL_CONSTEXPR QFixedSize() {} + Q_DECL_CONSTEXPR QFixedSize(QFixed _width, QFixed _height) : width(_width), height(_height) {} + Q_DECL_CONSTEXPR QSizeF toSizeF() const { return QSizeF(width.toReal(), height.toReal()); } + Q_DECL_CONSTEXPR static QFixedSize fromSizeF(const QSizeF &s) { return QFixedSize(QFixed::fromReal(s.width()), QFixed::fromReal(s.height())); } }; -- cgit v1.2.3 From 3688fac0402d0737985b2e70dcb0b96117902d93 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 25 Feb 2012 10:39:34 +0100 Subject: RemoveRef should not remove the const This does not fix anything, because AreArgumentsCompatible already do all the type checks. But it make RemoveRef consistant with std::remove_reference Change-Id: Ic42c872356172d7f5ea10de050254b5d10e50a6e Reviewed-by: Thiago Macieira --- src/corelib/kernel/qobject_impl.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/corelib/kernel/qobject_impl.h b/src/corelib/kernel/qobject_impl.h index 5adffb708f..419fcc1dd4 100644 --- a/src/corelib/kernel/qobject_impl.h +++ b/src/corelib/kernel/qobject_impl.h @@ -52,7 +52,6 @@ QT_BEGIN_NAMESPACE namespace QtPrivate { template struct RemoveRef { typedef T Type; }; - template struct RemoveRef { typedef T Type; }; template struct RemoveRef { typedef T Type; }; template struct RemoveConstRef { typedef T Type; }; template struct RemoveConstRef { typedef T Type; }; -- cgit v1.2.3 From 2a771cef4a939d26f6ffc45caa690330b33882c9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 Feb 2012 17:33:25 +0100 Subject: QFlags<>: let the compiler generate copy ctor/op= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The user-defined copy constructor and copy-assignment operators were 100% equivalent to the ones the compiler would generate, so let the compiler generate them (so we reap move constructors, too, even though they're not needed on this class). Change-Id: Iecdd579fa5a819d083ec9b2f25734ddba85515e6 Reviewed-by: JoĂ£o Abecasis Reviewed-by: Olivier Goffart --- src/corelib/global/qglobal.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 47d56d7c1b..b159a877b7 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1225,12 +1225,15 @@ class QFlags int i; public: typedef Enum enum_type; - Q_DECL_CONSTEXPR inline QFlags(const QFlags &f) : i(f.i) {} + // compiler-generated copy/move ctor/assignment operators are fine! +#ifdef qdoc + inline QFlags(const QFlags &other); + inline QFlags &operator=(const QFlags &other); +#endif Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(f) {} Q_DECL_CONSTEXPR inline QFlags(Zero = 0) : i(0) {} inline QFlags(QFlag f) : i(f) {} - inline QFlags &operator=(const QFlags &f) { i = f.i; return *this; } inline QFlags &operator&=(int mask) { i &= mask; return *this; } inline QFlags &operator&=(uint mask) { i &= mask; return *this; } inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; } -- cgit v1.2.3 From 1a49a529ee3e721ea8736bd0c34a0086a2dbad4d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 22 Feb 2012 14:49:13 +0100 Subject: Remove more support for unsupported GCC versions. Change-Id: I827c9f982a7d7d20913b99c8fdaf98437a0a73db Reviewed-by: Thiago Macieira --- src/corelib/global/qglobal.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index b159a877b7..5fbc8cdd19 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -191,7 +191,7 @@ namespace QT_NAMESPACE {} #endif #ifndef Q_REQUIRED_RESULT -# if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) +# if defined(Q_CC_GNU) # define Q_REQUIRED_RESULT __attribute__ ((warn_unused_result)) # else # define Q_REQUIRED_RESULT @@ -310,7 +310,7 @@ QT_END_INCLUDE_NAMESPACE /* Warnings and errors when using deprecated methods */ -#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2))) || defined(Q_CC_RVCT) +#if defined(Q_CC_GNU) || defined(Q_CC_RVCT) # define Q_DECL_DEPRECATED __attribute__ ((__deprecated__)) #elif defined(Q_CC_MSVC) # define Q_DECL_DEPRECATED __declspec(deprecated) @@ -384,11 +384,7 @@ QT_END_INCLUDE_NAMESPACE #if defined(__i386__) || defined(_WIN32) || defined(_WIN32_WCE) # if defined(Q_CC_GNU) -#if !defined(Q_CC_INTEL) && ((100*(__GNUC__ - 0) + 10*(__GNUC_MINOR__ - 0) + __GNUC_PATCHLEVEL__) >= 332) # define QT_FASTCALL __attribute__((regparm(3))) -#else -# define QT_FASTCALL -#endif # elif defined(Q_CC_MSVC) # define QT_FASTCALL __fastcall # else -- cgit v1.2.3 From 51f2a0c3318549a6f9388e3d4920eb23a60f8b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Fri, 10 Feb 2012 12:21:25 +0100 Subject: Cleanup usage of QVariant::Type. QVariant::Type is marked as obsolete. It is not possible to get rid of it completely, in a source compatible way, but at least we can remove it safely from a method arguments list. Change-Id: I26b58099bfa6d32f3a583a8ae0047f0bb36bcd0d Reviewed-by: Thiago Macieira --- src/corelib/kernel/qvariant.cpp | 68 +++++++++++++++++----------------- src/corelib/kernel/qvariant.h | 18 ++++----- src/dbus/qdbusargument.cpp | 6 +-- src/gui/kernel/qguivariant.cpp | 2 +- src/widgets/kernel/qwidgetsvariant.cpp | 4 +- 5 files changed, 49 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 0b7866c3eb..1c18883fde 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -279,7 +279,7 @@ inline bool qt_convertToBool(const QVariant::Private *const d) Converts \a d to type \a t, which is placed in \a result. */ -static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok) +static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) { Q_ASSERT(d->type != uint(t)); Q_ASSERT(result); @@ -763,7 +763,7 @@ static void dummyConstruct(QVariant::Private *, const void *) { Q_ASSERT_X(false static void dummyClear(QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to clear an unknown type"); } static bool dummyIsNull(const QVariant::Private *d) { Q_ASSERT_X(false, "QVariant::isNull", "Trying to call isNull on an unknown type"); return d->is_null; } static bool dummyCompare(const QVariant::Private *, const QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to compare an unknown types"); return false; } -static bool dummyConvert(const QVariant::Private *, QVariant::Type , void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; } +static bool dummyConvert(const QVariant::Private *, int, void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; } #if !defined(QT_NO_DEBUG_STREAM) static void dummyStreamDebug(QDebug, const QVariant &) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); } #endif @@ -840,7 +840,7 @@ static bool customCompare(const QVariant::Private *a, const QVariant::Private *b return !memcmp(a_ptr, b_ptr, QMetaType::sizeOf(a->type)); } -static bool customConvert(const QVariant::Private *, QVariant::Type, void *, bool *ok) +static bool customConvert(const QVariant::Private *, int, void *, bool *ok) { if (ok) *ok = false; @@ -1062,9 +1062,9 @@ Q_CORE_EXPORT void QVariantPrivate::unregisterHandler(const int /* Modules::Name /*! - \fn QVariant::QVariant(int typeOrUserType, const void *copy) + \fn QVariant::QVariant(int typeId, const void *copy) - Constructs variant of type \a typeOrUserType, and initializes with + Constructs variant of type \a typeId, and initializes with \a copy if \a copy is not 0. Note that you have to pass the address of the variable you want stored. @@ -1166,7 +1166,7 @@ QVariant::QVariant(QDataStream &s) UTF-8 encoding on the input \a val. Note that \a val is converted to a QString for storing in the - variant and QVariant::type() will return QMetaType::QString for + variant and QVariant::userType() will return QMetaType::QString for the variant. You can disable this operator by defining \c @@ -1373,19 +1373,19 @@ QVariant::QVariant(const char *val) QVariant::QVariant(Type type) { create(type, 0); } -QVariant::QVariant(int typeOrUserType, const void *copy) -{ create(typeOrUserType, copy); d.is_null = false; } +QVariant::QVariant(int typeId, const void *copy) +{ create(typeId, copy); d.is_null = false; } /*! \internal flags is true if it is a pointer type */ -QVariant::QVariant(int typeOrUserType, const void *copy, uint flags) +QVariant::QVariant(int typeId, const void *copy, uint flags) { if (flags) { //type is a pointer type - d.type = typeOrUserType; + d.type = typeId; d.data.ptr = *reinterpret_cast(copy); } else { - create(typeOrUserType, copy); + create(typeId, copy); } d.is_null = false; } @@ -1563,7 +1563,7 @@ void QVariant::detach() */ const char *QVariant::typeName() const { - return typeToName(Type(d.type)); + return typeToName(d.type); } /*! @@ -1580,17 +1580,17 @@ void QVariant::clear() } /*! - Converts the enum representation of the storage type, \a typ, to + Converts the int representation of the storage type, \a typeId, to its string representation. Returns a null pointer if the type is QVariant::Invalid or doesn't exist. */ -const char *QVariant::typeToName(Type typ) +const char *QVariant::typeToName(int typeId) { - if (typ == Invalid) + if (typeId == Invalid) return 0; - return QMetaType::typeName(typ); + return QMetaType::typeName(typeId); } @@ -1840,7 +1840,7 @@ QDataStream& operator<<(QDataStream &s, const QVariant::Type p) template inline T qVariantToHelper(const QVariant::Private &d, const HandlersManager &handlerManager) { - const QVariant::Type targetType = static_cast(qMetaTypeId()); + const uint targetType = qMetaTypeId(); if (d.type == targetType) return *v_cast(&d); @@ -2161,7 +2161,7 @@ inline T qNumVariantToHelper(const QVariant::Private &d, return val; T ret = 0; - if (!handlerManager[d.type]->convert(&d, QVariant::Type(t), &ret, ok) && ok) + if (!handlerManager[d.type]->convert(&d, t, &ret, ok) && ok) *ok = false; return ret; } @@ -2405,7 +2405,7 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] = /*! Returns true if the variant's type can be cast to the requested - type, \a t. Such casting is done automatically when calling the + type, \a targetTypeId. Such casting is done automatically when calling the toInt(), toBool(), ... methods. The following casts are done automatically: @@ -2437,18 +2437,18 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] = \sa convert() */ -bool QVariant::canConvert(Type t) const +bool QVariant::canConvert(int targetTypeId) const { // TODO Reimplement this function, currently it works but it is a historical mess. const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type); - if (uint(t) == uint(QMetaType::Float)) t = QVariant::Double; + if (uint(targetTypeId) == uint(QMetaType::Float)) targetTypeId = QVariant::Double; - if (currentType == uint(t)) + if (currentType == uint(targetTypeId)) return true; // FIXME It should be LastCoreType intead of Uuid - if (currentType > QVariant::Uuid || t > QVariant::Uuid) { - switch (uint(t)) { + if (currentType > int(QMetaType::QUuid) || targetTypeId > int(QMetaType::QUuid)) { + switch (uint(targetTypeId)) { case QVariant::Int: return currentType == QVariant::KeySequence || currentType == QMetaType::ULong @@ -2490,14 +2490,14 @@ bool QVariant::canConvert(Type t) const } } - if(t == String && currentType == StringList) + if (targetTypeId == String && currentType == StringList) return v_cast(&d)->count() == 1; else - return qCanConvertMatrix[t] & (1 << currentType); + return qCanConvertMatrix[targetTypeId] & (1 << currentType); } /*! - Casts the variant to the requested type, \a t. If the cast cannot be + Casts the variant to the requested type, \a targetTypeId. If the cast cannot be done, the variant is cleared. Returns true if the current type of the variant was successfully cast; otherwise returns false. @@ -2508,23 +2508,23 @@ bool QVariant::canConvert(Type t) const \sa canConvert(), clear() */ -bool QVariant::convert(Type t) +bool QVariant::convert(int targetTypeId) { - if (d.type == uint(t)) + if (d.type == uint(targetTypeId)) return true; QVariant oldValue = *this; clear(); - if (!oldValue.canConvert(t)) + if (!oldValue.canConvert(targetTypeId)) return false; - create(t, 0); + create(targetTypeId, 0); if (oldValue.isNull()) return false; bool isOk = true; - if (!handlerManager[d.type]->convert(&oldValue.d, t, data(), &isOk)) + if (!handlerManager[d.type]->convert(&oldValue.d, targetTypeId, data(), &isOk)) isOk = false; d.is_null = !isOk; return isOk; @@ -2538,7 +2538,7 @@ bool QVariant::convert(Type t) bool QVariant::convert(const int type, void *ptr) const { Q_ASSERT(type < int(QMetaType::User)); - return handlerManager[type]->convert(&d, QVariant::Type(type), ptr, 0); + return handlerManager[type]->convert(&d, type, ptr, 0); } @@ -2605,7 +2605,7 @@ bool QVariant::cmp(const QVariant &v) const else return toLongLong() == v.toLongLong(); } - if (!v2.canConvert(Type(d.type)) || !v2.convert(Type(d.type))) + if (!v2.canConvert(d.type) || !v2.convert(d.type)) return false; } return handlerManager[d.type]->compare(&d, &v2.d); diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 20d3946ea1..5da482d5cd 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -194,8 +194,8 @@ class Q_CORE_EXPORT QVariant inline QVariant(); ~QVariant(); QVariant(Type type); - QVariant(int typeOrUserType, const void *copy); - QVariant(int typeOrUserType, const void *copy, uint flags); + QVariant(int typeId, const void *copy); + QVariant(int typeId, const void *copy, uint flags); QVariant(const QVariant &other); #ifndef QT_NO_DATASTREAM @@ -257,8 +257,8 @@ class Q_CORE_EXPORT QVariant int userType() const; const char *typeName() const; - bool canConvert(Type t) const; - bool convert(Type t); + bool canConvert(int targetTypeId) const; + bool convert(int targetTypeId); inline bool isValid() const; bool isNull() const; @@ -311,7 +311,7 @@ class Q_CORE_EXPORT QVariant void load(QDataStream &ds); void save(QDataStream &ds) const; #endif - static const char *typeToName(Type type); + static const char *typeToName(int typeId); static Type nameToType(const char *name); void *data(); @@ -331,7 +331,7 @@ class Q_CORE_EXPORT QVariant template bool canConvert() const - { return canConvert(Type(qMetaTypeId())); } + { return canConvert(qMetaTypeId()); } public: #ifndef qdoc @@ -381,8 +381,8 @@ class Q_CORE_EXPORT QVariant typedef void (*f_save)(const Private *, QDataStream &); #endif typedef bool (*f_compare)(const Private *, const Private *); - typedef bool (*f_convert)(const QVariant::Private *d, Type t, void *, bool *); - typedef bool (*f_canConvert)(const QVariant::Private *d, Type t); + typedef bool (*f_convert)(const QVariant::Private *d, int t, void *, bool *); + typedef bool (*f_canConvert)(const QVariant::Private *d, int t); typedef void (*f_debugStream)(QDebug, const QVariant &); struct Handler { f_construct construct; @@ -527,7 +527,7 @@ namespace QtPrivate { return *reinterpret_cast(v.constData()); if (vid < int(QMetaType::User)) { T t; - if (v.convert(QVariant::Type(vid), &t)) + if (v.convert(vid, &t)) return t; } return T(); diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp index 1c2cb6f0f0..6e6e676dae 100644 --- a/src/dbus/qdbusargument.cpp +++ b/src/dbus/qdbusargument.cpp @@ -89,7 +89,7 @@ QByteArray QDBusArgumentPrivate::createSignature(int id) if (signature.isEmpty() || !ok || !QDBusUtil::isValidSingleSignature(QString::fromLatin1(signature))) { qWarning("QDBusMarshaller: type `%s' produces invalid D-BUS signature `%s' " "(Did you forget to call beginStructure() ?)", - QVariant::typeToName( QVariant::Type(id) ), + QMetaType::typeName(id), signature.isEmpty() ? "" : signature.constData()); return ""; } else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) || @@ -97,9 +97,9 @@ QByteArray QDBusArgumentPrivate::createSignature(int id) signature.at(1) == DBUS_TYPE_STRING))) { qWarning("QDBusMarshaller: type `%s' attempts to redefine basic D-BUS type '%s' (%s) " "(Did you forget to call beginStructure() ?)", - QVariant::typeToName( QVariant::Type(id) ), + QMetaType::typeName(id), signature.constData(), - QVariant::typeToName( QVariant::Type(QDBusMetaType::signatureToType(signature))) ); + QMetaType::typeName(QDBusMetaType::signatureToType(signature))); return ""; } return signature; diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 2ebfb32bc3..0492e48bee 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -221,7 +221,7 @@ static bool compare(const QVariant::Private *a, const QVariant::Private *b) return QMetaTypeSwitcher::switcher(comparator, a->type, 0); } -static bool convert(const QVariant::Private *d, QVariant::Type t, +static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) { switch (t) { diff --git a/src/widgets/kernel/qwidgetsvariant.cpp b/src/widgets/kernel/qwidgetsvariant.cpp index cf85cbf063..81847681e4 100644 --- a/src/widgets/kernel/qwidgetsvariant.cpp +++ b/src/widgets/kernel/qwidgetsvariant.cpp @@ -117,7 +117,7 @@ static bool compare(const QVariant::Private *a, const QVariant::Private *b) return false; } -static bool convert(const QVariant::Private *d, QVariant::Type type, void *result, bool *ok) +static bool convert(const QVariant::Private *d, int type, void *result, bool *ok) { Q_UNUSED(d); Q_UNUSED(type); @@ -141,7 +141,7 @@ static void streamDebug(QDebug dbg, const QVariant &v) dbg.nospace() << *v_cast(d); break; default: - dbg.nospace() << "QVariant::Type(" << d->type << ")"; + dbg.nospace() << "QMetaType::Type(" << d->type << ")"; } } #endif -- cgit v1.2.3 From b58631ce472ce2bfce6319874468aa4e7e11b405 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 26 Feb 2012 10:54:07 +0100 Subject: Don't use deprecated QAbstractItemModel::reset() Change-Id: Idf9971668a372a12ba319d954c35e157d8a08bd1 Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qlistwidget.cpp | 3 ++- src/widgets/itemviews/qstandarditemmodel.cpp | 3 ++- src/widgets/itemviews/qtablewidget.cpp | 3 ++- src/widgets/itemviews/qtreewidget.cpp | 3 ++- src/widgets/util/qcompleter.cpp | 3 ++- src/widgets/util/qundoview.cpp | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index 97fbea6c3d..bb39546ec8 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -75,6 +75,7 @@ QListModel::~QListModel() void QListModel::clear() { + beginResetModel(); for (int i = 0; i < items.count(); ++i) { if (items.at(i)) { items.at(i)->d->theid = -1; @@ -83,7 +84,7 @@ void QListModel::clear() } } items.clear(); - reset(); + endResetModel(); } QListWidgetItem *QListModel::at(int row) const diff --git a/src/widgets/itemviews/qstandarditemmodel.cpp b/src/widgets/itemviews/qstandarditemmodel.cpp index 112b533f4f..5616d76c4a 100644 --- a/src/widgets/itemviews/qstandarditemmodel.cpp +++ b/src/widgets/itemviews/qstandarditemmodel.cpp @@ -2097,13 +2097,14 @@ void QStandardItemModel::setItemRoleNames(const QHash &roleNames void QStandardItemModel::clear() { Q_D(QStandardItemModel); + beginResetModel(); d->root.reset(new QStandardItem); d->root->d_func()->setModel(this); qDeleteAll(d->columnHeaderItems); d->columnHeaderItems.clear(); qDeleteAll(d->rowHeaderItems); d->rowHeaderItems.clear(); - reset(); + endResetModel(); } /*! diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index 82055ad11e..5932f20327 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -755,6 +755,7 @@ void QTableModel::clear() void QTableModel::clearContents() { + beginResetModel(); for (int i = 0; i < tableItems.count(); ++i) { if (tableItems.at(i)) { tableItems.at(i)->view = 0; @@ -762,7 +763,7 @@ void QTableModel::clearContents() tableItems[i] = 0; } } - reset(); + endResetModel(); } void QTableModel::itemChanged(QTableWidgetItem *item) diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index ca8b9c4e09..cec709a816 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -160,6 +160,7 @@ QTreeModel::~QTreeModel() void QTreeModel::clear() { SkipSorting skipSorting(this); + beginResetModel(); for (int i = 0; i < rootItem->childCount(); ++i) { QTreeWidgetItem *item = rootItem->children.at(i); item->par = 0; @@ -168,7 +169,7 @@ void QTreeModel::clear() } rootItem->children.clear(); sortPendingTimer.stop(); - reset(); + endResetModel(); } /*! diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 503e5aa596..d416f26f51 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -421,7 +421,8 @@ void QCompletionModel::filter(const QStringList& parts) void QCompletionModel::resetModel() { if (rowCount() == 0) { - reset(); + beginResetModel(); + endResetModel(); return; } diff --git a/src/widgets/util/qundoview.cpp b/src/widgets/util/qundoview.cpp index 4b09d5fc70..a87e9e0f05 100644 --- a/src/widgets/util/qundoview.cpp +++ b/src/widgets/util/qundoview.cpp @@ -142,7 +142,8 @@ void QUndoModel::stackDestroyed(QObject *obj) void QUndoModel::stackChanged() { - reset(); + beginResetModel(); + endResetModel(); m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect); } -- cgit v1.2.3 From 96cfca6151b674f0266e879013d69de826ce3311 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 25 Feb 2012 21:27:03 +0100 Subject: Remove usage of deprecated QAbstractItemModel::setRoleNames Change-Id: If41bf0d6d50969156269c67a15e006d38edc8e1f Reviewed-by: Stephen Kelly --- src/widgets/dialogs/qfilesystemmodel.cpp | 10 ++++------ src/widgets/itemviews/qdirmodel.cpp | 8 +++----- 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index 7ea4302a56..0211b2512c 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -1926,12 +1926,10 @@ void QFileSystemModelPrivate::init() q, SIGNAL(directoryLoaded(QString))); q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection); - QHash roles = q->roleNames(); - roles.insertMulti(QFileSystemModel::FileIconRole, "fileIcon"); // == Qt::decoration - roles.insert(QFileSystemModel::FilePathRole, "filePath"); - roles.insert(QFileSystemModel::FileNameRole, "fileName"); - roles.insert(QFileSystemModel::FilePermissions, "filePermissions"); - q->setRoleNames(roles); + roleNames.insertMulti(QFileSystemModel::FileIconRole, QByteArrayLiteral("fileIcon")); // == Qt::decoration + roleNames.insert(QFileSystemModel::FilePathRole, QByteArrayLiteral("filePath")); + roleNames.insert(QFileSystemModel::FileNameRole, QByteArrayLiteral("fileName")); + roleNames.insert(QFileSystemModel::FilePermissions, QByteArrayLiteral("filePermissions")); } /*! diff --git a/src/widgets/itemviews/qdirmodel.cpp b/src/widgets/itemviews/qdirmodel.cpp index 67a16a836d..ee097e5c41 100644 --- a/src/widgets/itemviews/qdirmodel.cpp +++ b/src/widgets/itemviews/qdirmodel.cpp @@ -1169,11 +1169,9 @@ void QDirModelPrivate::init() root.parent = 0; root.info = QFileInfo(); clear(&root); - QHash roles = q->roleNames(); - roles.insertMulti(QDirModel::FileIconRole, "fileIcon"); // == Qt::decoration - roles.insert(QDirModel::FilePathRole, "filePath"); - roles.insert(QDirModel::FileNameRole, "fileName"); - q->setRoleNames(roles); + roleNames.insertMulti(QDirModel::FileIconRole, QByteArrayLiteral("fileIcon")); // == Qt::decoration + roleNames.insert(QDirModel::FilePathRole, QByteArrayLiteral("filePath")); + roleNames.insert(QDirModel::FileNameRole, QByteArrayLiteral("fileName")); } QDirModelPrivate::QDirNode *QDirModelPrivate::node(int row, QDirNode *parent) const -- cgit v1.2.3 From ec739707d70d6450a261f7dd4726380e59d403ef Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 25 Feb 2012 11:42:57 +0100 Subject: Remove deprecated usage of QKeySequence from qguivariant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The implicit conversion operators are deprecated. Change-Id: I0e94c0671413da1ab58c6c7b8bb31614e2696409 Reviewed-by: JÄ™drzej Nowacki --- src/gui/kernel/qguivariant.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 0492e48bee..50d3f0b7d1 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -236,7 +236,7 @@ static bool convert(const QVariant::Private *d, int t, switch (d->type) { #ifndef QT_NO_SHORTCUT case QVariant::KeySequence: - *str = QString(*v_cast(d)); + *str = (*v_cast(d)).toString(QKeySequence::NativeText); return true; #endif case QVariant::Font: @@ -285,7 +285,8 @@ static bool convert(const QVariant::Private *d, int t, #ifndef QT_NO_SHORTCUT case QVariant::Int: if (d->type == QVariant::KeySequence) { - *static_cast(result) = (int)(*(v_cast(d))); + const QKeySequence &seq = *v_cast(d); + *static_cast(result) = seq.isEmpty() ? 0 : seq[0]; return true; } break; -- cgit v1.2.3 From beab403d9fcf1fb41f3c133fc6d58e1e864a8d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Fri, 10 Feb 2012 09:14:41 +0100 Subject: Reduce QtCore lib binary size by around ~3KB, by removing template code Reusing a template is much better then creating a new one, even if it should inline the same code. For some reason replacing T* by void* force gcc to remove a few bytes per template instantiation too, it is not really significant, but it alows us to simplify the code. Benchmarks don't show any regressions. Change-Id: I4fdf1e4dc311b23021eb5758605602937d05b183 Reviewed-by: Bradley T. Hughes Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmetatype.cpp | 8 ++--- src/corelib/kernel/qmetatype.h | 66 ++++++++++++++++------------------------ src/corelib/kernel/qmetatype_p.h | 47 ++++------------------------ 3 files changed, 37 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 0021c0ced2..003ad1c32d 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1290,7 +1290,7 @@ namespace { class TypeDestroyer { template::IsAccepted> struct DestroyerImpl { - static void Destroy(const int /* type */, T *where) { delete where; } + static void Destroy(const int /* type */, void *where) { qMetaTypeDeleteHelper(where); } }; template struct DestroyerImpl { @@ -1354,11 +1354,11 @@ namespace { class TypeConstructor { template::IsAccepted> struct ConstructorImpl { - static void *Construct(const int /*type*/, void *where, const T *copy) { return qMetaTypeConstructHelper(where, copy); } + static void *Construct(const int /*type*/, void *where, const void *copy) { return qMetaTypeConstructHelper(where, copy); } }; template struct ConstructorImpl { - static void *Construct(const int type, void *where, const T *copy) + static void *Construct(const int type, void *where, const void *copy) { if (QTypeModuleInfo::IsGui) return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; @@ -1440,7 +1440,7 @@ namespace { class TypeDestructor { template::IsAccepted> struct DestructorImpl { - static void Destruct(const int /* type */, T *where) { qMetaTypeDestructHelper(where); } + static void Destruct(const int /* type */, void *where) { qMetaTypeDestructHelper(where); } }; template struct DestructorImpl { diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 4af77fcedc..4e75e1414b 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -318,46 +318,57 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaType::TypeFlags) template -void qMetaTypeDeleteHelper(T *t) +void qMetaTypeDeleteHelper(void *t) { - delete t; + delete static_cast(t); } +template <> inline void qMetaTypeDeleteHelper(void *) {} template -void *qMetaTypeCreateHelper(const T *t) +void *qMetaTypeCreateHelper(const void *t) { if (t) return new T(*static_cast(t)); return new T(); } +template <> inline void *qMetaTypeCreateHelper(const void *) { return 0; } + template -void qMetaTypeDestructHelper(T *t) +void qMetaTypeDestructHelper(void *t) { Q_UNUSED(t) // Silence MSVC that warns for POD types. - t->~T(); + static_cast(t)->~T(); } +template <> inline void qMetaTypeDestructHelper(void *) {} + template -void *qMetaTypeConstructHelper(void *where, const T *t) +void *qMetaTypeConstructHelper(void *where, const void *t) { if (t) return new (where) T(*static_cast(t)); return new (where) T; } +template <> inline void *qMetaTypeConstructHelper(void *, const void *) { return 0; } + #ifndef QT_NO_DATASTREAM template -void qMetaTypeSaveHelper(QDataStream &stream, const T *t) +void qMetaTypeSaveHelper(QDataStream &stream, const void *t) { - stream << *t; + stream << *static_cast(t); } +template <> inline void qMetaTypeSaveHelper(QDataStream &, const void *) {} + template -void qMetaTypeLoadHelper(QDataStream &stream, T *t) +void qMetaTypeLoadHelper(QDataStream &stream, void *t) { - stream >> *t; + stream >> *static_cast(t); } + +template <> inline void qMetaTypeLoadHelper(QDataStream &, void *) {} #endif // QT_NO_DATASTREAM template @@ -442,15 +453,6 @@ int qRegisterMetaType(const char *typeName if (typedefOf != -1) return QMetaType::registerTypedef(typeName, typedefOf); - typedef void*(*CreatePtr)(const T*); - CreatePtr cptr = qMetaTypeCreateHelper; - typedef void(*DeletePtr)(T*); - DeletePtr dptr = qMetaTypeDeleteHelper; - typedef void*(*ConstructPtr)(void *, const T*); - ConstructPtr ipcptr = qMetaTypeConstructHelper; - typedef void(*DestructPtr)(T*); - DestructPtr ipdptr = qMetaTypeDestructHelper; - QMetaType::TypeFlags flags; if (!QTypeInfo::isStatic) flags |= QMetaType::MovableType; @@ -461,10 +463,10 @@ int qRegisterMetaType(const char *typeName if (QtPrivate::IsPointerToTypeDerivedFromQObject::Value) flags |= QMetaType::PointerToQObject; - return QMetaType::registerType(typeName, reinterpret_cast(dptr), - reinterpret_cast(cptr), - reinterpret_cast(ipdptr), - reinterpret_cast(ipcptr), + return QMetaType::registerType(typeName, qMetaTypeDeleteHelper, + qMetaTypeCreateHelper, + qMetaTypeDestructHelper, + qMetaTypeConstructHelper, sizeof(T), flags); } @@ -477,14 +479,8 @@ void qRegisterMetaTypeStreamOperators(const char *typeName #endif ) { - typedef void(*SavePtr)(QDataStream &, const T *); - typedef void(*LoadPtr)(QDataStream &, T *); - SavePtr sptr = qMetaTypeSaveHelper; - LoadPtr lptr = qMetaTypeLoadHelper; - qRegisterMetaType(typeName); - QMetaType::registerStreamOperators(typeName, reinterpret_cast(sptr), - reinterpret_cast(lptr)); + QMetaType::registerStreamOperators(typeName, qMetaTypeSaveHelper, qMetaTypeLoadHelper); } #endif // QT_NO_DATASTREAM @@ -516,16 +512,8 @@ inline int qRegisterMetaType( template inline int qRegisterMetaTypeStreamOperators() { - typedef void(*SavePtr)(QDataStream &, const T *); - typedef void(*LoadPtr)(QDataStream &, T *); - SavePtr sptr = qMetaTypeSaveHelper; - LoadPtr lptr = qMetaTypeLoadHelper; - register int id = qMetaTypeId(); - QMetaType::registerStreamOperators(id, - reinterpret_cast(sptr), - reinterpret_cast(lptr)); - + QMetaType::registerStreamOperators(id, qMetaTypeSaveHelper, qMetaTypeLoadHelper); return id; } #endif diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index e48c5d3033..b50521c7a6 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -122,31 +122,6 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER) class QMetaTypeInterface { public: - template - struct Impl { - static void *creator(const T *t) - { - if (t) - return new T(*t); - return new T(); - } - - static void deleter(T *t) { delete t; } - static void saver(QDataStream &stream, const T *t) { stream << *t; } - static void loader(QDataStream &stream, T *t) { stream >> *t; } - static void destructor(T *t) - { - Q_UNUSED(t) // Silence MSVC that warns for POD types. - t->~T(); - } - static void *constructor(void *where, const T *t) - { - if (t) - return new (where) T(*static_cast(t)); - return new (where) T; - } - }; - QMetaType::Creator creator; QMetaType::Deleter deleter; QMetaType::SaveOperator saveOp; @@ -157,20 +132,10 @@ public: quint32 flags; // same as QMetaType::TypeFlags }; -template<> -struct QMetaTypeInterface::Impl { - static void *creator(const void *) { return 0; } - static void deleter(void *) {} - static void saver(QDataStream &, const void *) {} - static void loader(QDataStream &, void *) {} - static void destructor(void *){} - static void *constructor(void *, const void *) { return 0; } -}; - #ifndef QT_NO_DATASTREAM # define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \ - /*saveOp*/(reinterpret_cast(QMetaTypeInterface::Impl::saver)), \ - /*loadOp*/(reinterpret_cast(QMetaTypeInterface::Impl::loader)), + /*saveOp*/(qMetaTypeSaveHelper), \ + /*loadOp*/(qMetaTypeLoadHelper), # define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \ /*saveOp*/ 0, \ /*loadOp*/ 0, @@ -184,11 +149,11 @@ struct QMetaTypeInterface::Impl { #define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \ { \ - /*creator*/(reinterpret_cast(QMetaTypeInterface::Impl::creator)), \ - /*deleter*/(reinterpret_cast(QMetaTypeInterface::Impl::deleter)), \ + /*creator*/(qMetaTypeCreateHelper), \ + /*deleter*/(qMetaTypeDeleteHelper), \ DATASTREAM_DELEGATE(Type) \ - /*constructor*/(reinterpret_cast(QMetaTypeInterface::Impl::constructor)), \ - /*destructor*/(reinterpret_cast(QMetaTypeInterface::Impl::destructor)), \ + /*constructor*/(qMetaTypeConstructHelper), \ + /*destructor*/(qMetaTypeDestructHelper), \ /*size*/(QTypeInfo::sizeOf), \ /*flags*/(!QTypeInfo::isStatic * QMetaType::MovableType) \ | (QTypeInfo::isComplex * QMetaType::NeedsConstruction) \ -- cgit v1.2.3 From 184c9e346e298bbda2cc8f30e2f318c1c11e4b13 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 23 Feb 2012 12:59:21 +0100 Subject: Optimize space for the QEventLoopQuitLocker. Use a union and a type enum instead of three pointers. Change-Id: I02b11733a4f2e95099064fa9325497d4e04ac615 Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qeventloop.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 2fb351797c..dfdd178c35 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -322,37 +322,51 @@ class QEventLoopLockerPrivate { public: explicit QEventLoopLockerPrivate(QEventLoopPrivate *loop) - : loop(loop), thread(0), app(0) + : loop(loop), type(EventLoop) { loop->ref(); } explicit QEventLoopLockerPrivate(QThreadPrivate *thread) - : loop(0), thread(thread), app(0) + : thread(thread), type(Thread) { thread->ref(); } explicit QEventLoopLockerPrivate(QCoreApplicationPrivate *app) - : loop(0), thread(0), app(app) + : app(app), type(Application) { app->ref(); } ~QEventLoopLockerPrivate() { - if (loop) + switch (type) + { + case EventLoop: loop->deref(); - else if (thread) + break; + case Thread: thread->deref(); - else + break; + default: app->deref(); + break; + } } private: - QEventLoopPrivate *loop; - QThreadPrivate *thread; - QCoreApplicationPrivate *app; + union { + QEventLoopPrivate * loop; + QThreadPrivate * thread; + QCoreApplicationPrivate * app; + }; + enum Type { + EventLoop, + Thread, + Application + }; + const Type type; }; /*! -- cgit v1.2.3 From 6df396286a3221d12e810c0aaa71c4aa68db3331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Fri, 24 Feb 2012 14:27:01 +0100 Subject: Simplify QMetaTypeSwitcher. We do not need to distinguish between different types in the switcher. Before this patch it was not possible to overload DelegateObject::delegate with a pointer type. Now it is fixed. Change-Id: Icd73a53e73e5e66b1b6f6407ba4e0f79e584d930 Reviewed-by: Olivier Goffart --- src/corelib/kernel/qmetatypeswitcher_p.h | 31 ++++++------------------------- src/corelib/kernel/qvariant_p.h | 3 ++- 2 files changed, 8 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qmetatypeswitcher_p.h b/src/corelib/kernel/qmetatypeswitcher_p.h index 05db2cb4c7..e9c15ea214 100644 --- a/src/corelib/kernel/qmetatypeswitcher_p.h +++ b/src/corelib/kernel/qmetatypeswitcher_p.h @@ -59,46 +59,27 @@ QT_BEGIN_NAMESPACE class QMetaTypeSwitcher { public: - - typedef void *NotBuiltinType; + class NotBuiltinType; template static ReturnType switcher(DelegateObject &logic, int type, const void *data); }; -#define QT_METATYPE_SWICHER_CASE_PRIMITIVE(TypeName, TypeId, Name)\ - case QMetaType::TypeName: return logic.delegate(static_cast(data)); - -#define QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER(TypeName, TypeId, Name)\ - case QMetaType::TypeName: return logic.delegate(static_cast< Name * const *>(data)); - -#define QT_METATYPE_SWICHER_CASE_POINTER(TypeName, TypeId, Name)\ - case QMetaType::TypeName: return logic.delegate(static_cast< QT_PREPEND_NAMESPACE(Name) * const *>(data)); - -#define QT_METATYPE_SWICHER_CASE_QCLASS(TypeName, TypeId, Name)\ - case QMetaType::TypeName: return logic.delegate(static_cast(data)); +#define QT_METATYPE_SWICHER_CASE(TypeName, TypeId, Name)\ + case QMetaType::TypeName: return logic.delegate(static_cast(data)); template ReturnType QMetaTypeSwitcher::switcher(DelegateObject &logic, int type, const void *data) { switch (QMetaType::Type(type)) { - QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_SWICHER_CASE_PRIMITIVE) - QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER) - QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_SWICHER_CASE_POINTER) - QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS) - QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_SWICHER_CASE_QCLASS) - QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS) - QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_SWICHER_CASE_QCLASS) + QT_FOR_EACH_STATIC_TYPE(QT_METATYPE_SWICHER_CASE) default: - return logic.delegate(static_cast(data)); + return logic.delegate(static_cast(data)); } } -#undef QT_METATYPE_SWICHER_CASE_PRIMITIVE -#undef QT_METATYPE_SWICHER_CASE_PRIMITIVE_POINTER -#undef QT_METATYPE_SWICHER_CASE_QCLASS -#undef QT_METATYPE_SWICHER_CASE_POINTER +#undef QT_METATYPE_SWICHER_CASE QT_END_NAMESPACE diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 708a427860..a754bc4363 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -188,7 +188,7 @@ public: } bool delegate(const void*) { return true; } - + bool delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return false; } protected: const QVariant::Private *m_a; const QVariant::Private *m_b; @@ -282,6 +282,7 @@ public: } // we need that as sizof(void) is undefined and it is needed in HasIsNullMethod bool delegate(const void *) { return m_d->is_null; } + bool delegate(const QMetaTypeSwitcher::NotBuiltinType *) { return m_d->is_null; } protected: const QVariant::Private *m_d; }; -- cgit v1.2.3 From efde205586a70320d0525e941e5a1cd9657bdd30 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Feb 2012 12:26:10 +0100 Subject: Use new plugin system in qtbase. - AccessibleWidgets - Windows printer support - Examples Change-Id: Icc162bd7fc284b3c76d9966210f983728085c743 Reviewed-by: Lars Knoll --- src/plugins/accessible/widgets/main.cpp | 10 +++--- src/plugins/accessible/widgets/widgets.json | 52 +++++++++++++++++++++++++++ src/plugins/printsupport/windows/main.cpp | 4 +-- src/plugins/printsupport/windows/windows.json | 3 ++ src/plugins/printsupport/windows/windows.pro | 2 ++ 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 src/plugins/accessible/widgets/widgets.json create mode 100644 src/plugins/printsupport/windows/windows.json (limited to 'src') diff --git a/src/plugins/accessible/widgets/main.cpp b/src/plugins/accessible/widgets/main.cpp index dfa9594d5b..ca8bf816b6 100644 --- a/src/plugins/accessible/widgets/main.cpp +++ b/src/plugins/accessible/widgets/main.cpp @@ -61,6 +61,9 @@ QT_BEGIN_NAMESPACE class AccessibleFactory : public QAccessiblePlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QAccessibleFactoryInterface" FILE "widgets.json") + public: AccessibleFactory(); @@ -109,7 +112,6 @@ QStringList AccessibleFactory::keys() const list << QLatin1String("QStatusBar"); list << QLatin1String("QProgressBar"); list << QLatin1String("QMenuBar"); - list << QLatin1String("Q3PopupMenu"); list << QLatin1String("QMenu"); list << QLatin1String("QHeaderView"); list << QLatin1String("QTabBar"); @@ -251,8 +253,6 @@ QAccessibleInterface *AccessibleFactory::create(const QString &classname, QObjec #ifndef QT_NO_MENU } else if (classname == QLatin1String("QMenu")) { iface = new QAccessibleMenu(widget); - } else if (classname == QLatin1String("Q3PopupMenu")) { - iface = new QAccessibleMenu(widget); #endif #ifndef QT_NO_ITEMVIEWS } else if (classname == QLatin1String("QAbstractItemView")) { @@ -345,9 +345,9 @@ QAccessibleInterface *AccessibleFactory::create(const QString &classname, QObjec return iface; } -Q_EXPORT_STATIC_PLUGIN(AccessibleFactory) -Q_EXPORT_PLUGIN2(qtaccessiblewidgets, AccessibleFactory) QT_END_NAMESPACE +#include "main.moc" + #endif // QT_NO_ACCESSIBILITY diff --git a/src/plugins/accessible/widgets/widgets.json b/src/plugins/accessible/widgets/widgets.json new file mode 100644 index 0000000000..fdeb6f2b52 --- /dev/null +++ b/src/plugins/accessible/widgets/widgets.json @@ -0,0 +1,52 @@ +{ + "Keys": [ + "QLineEdit", + "QComboBox", + "QAbstractSpinBox", + "QSpinBox", + "QDoubleSpinBox", + "QScrollBar", + "QSlider", + "QAbstractSlider", + "QToolButton", + "QCheckBox", + "QRadioButton", + "QPushButton", + "QAbstractButton", + "QDialog", + "QMessageBox", + "QMainWindow", + "QLabel", + "QLCDNumber", + "QGroupBox", + "QStatusBar", + "QProgressBar", + "QMenuBar", + "QMenu", + "QHeaderView", + "QTabBar", + "QToolBar", + "QWorkspaceChild", + "QSizeGrip", + "QAbstractItemView", + "QWidget", + "QSplitter", + "QSplitterHandle", + "QTextEdit", + "QTipLabel", + "QFrame", + "QStackedWidget", + "QToolBox", + "QMdiArea", + "QMdiSubWindow", + "QWorkspace", + "QDialogButtonBox", + "QDial", + "QRubberBand", + "QTextBrowser", + "QAbstractScrollArea", + "QScrollArea", + "QCalendarWidget", + "QDockWidget", + "QAccessibleWidget" ] +} diff --git a/src/plugins/printsupport/windows/main.cpp b/src/plugins/printsupport/windows/main.cpp index baf18504ee..e29705a8a7 100644 --- a/src/plugins/printsupport/windows/main.cpp +++ b/src/plugins/printsupport/windows/main.cpp @@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE class QWindowsPrinterSupportPlugin : public QPlatformPrinterSupportPlugin { Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.QPlatformPrinterSupportFactoryInterface" FILE "windows.json") + public: QStringList keys() const; QPlatformPrinterSupport *create(const QString &); @@ -67,8 +69,6 @@ QPlatformPrinterSupport *QWindowsPrinterSupportPlugin::create(const QString &key return 0; } -Q_EXPORT_PLUGIN2(windowsprint, QWindowsPrinterSupportPlugin) - QT_END_NAMESPACE #include "main.moc" diff --git a/src/plugins/printsupport/windows/windows.json b/src/plugins/printsupport/windows/windows.json new file mode 100644 index 0000000000..803052854e --- /dev/null +++ b/src/plugins/printsupport/windows/windows.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "windowsprintsupport" ] +} diff --git a/src/plugins/printsupport/windows/windows.pro b/src/plugins/printsupport/windows/windows.pro index 2032125f4b..97d90a6a9d 100644 --- a/src/plugins/printsupport/windows/windows.pro +++ b/src/plugins/printsupport/windows/windows.pro @@ -15,6 +15,8 @@ SOURCES += \ HEADERS += \ qwindowsprintersupport.h +OTHER_FILES += windows.json + target.path += $$[QT_INSTALL_PLUGINS]/printsupport INSTALLS += target LIBS += -lWinspool -lComdlg32 -- cgit v1.2.3 From 568e714fdf9d3243bfc684a5650332e432e70461 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 24 Feb 2012 22:12:18 +0100 Subject: remove library version matching from qt.conf this feature was introduced in feb 2005 by Sam with this comment: > I have implemented a versioning into the keys and do environment > expansion there as well, these aren't immediately usefull but Marius > and I agreed that distributors will probably want such features at > times. The versioning fallbacks will be usefull to us over time no > doubt. imo the versioning is a contestant for the most useless feature ever: - (linux) distributors couldn't care less - they simply configure qtcore correctly. additionally, the packaging policies state that no config files should live in the binary dir at all, so no qt.conf for them. - ISVs don't care, because they ship their software with a particular qt version anyway. - SDK distributors don't care, because it doesn't solve any real problem for them: a) they will isolate the (qmake) versions and b) a distinction based on version number (as opposed to build configuration) is utterly useless in the first place. i left in the variable expansion, as it could at least theoretically be useful for creating relocatable packages. debatable - the file it easy enough to modify at installation time. Change-Id: Ida8a50b16d55d8d8613d1a98a51df56753f6a6e3 Reviewed-by: Bradley T. Hughes Reviewed-by: Lars Knoll --- src/corelib/global/qlibraryinfo.cpp | 67 ++----------------------------------- 1 file changed, 2 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 61c750acaf..c871675334 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -348,71 +348,8 @@ QLibraryInfo::location(LibraryLocation loc) QSettings *config = QLibraryInfoPrivate::configuration(); config->beginGroup(QLatin1String("Paths")); - QString subKey; - { - /* - find the child group whose version number is closest - to the library version. for example and we have the - following groups: - - Paths - Paths/4.0 - Paths/4.1.2 - Paths/4.2.5 - Paths/5 - - if QT_VERSION is 4.0.1, then we use 'Paths/4.0' - if QT_VERSION is 4.1.5, then we use 'Paths/4.1.2' - if QT_VERSION is 4.6.3, then we use 'Paths/4.2.5' - if QT_VERSION is 6.0.2, then we use 'Paths/5' - - note: any of the trailing version numbers may be - omitted (in which case, they default to zero), - i.e. 4 == 4.0.0, 4.1 == 4.1.0, and so on - */ - enum { - QT_MAJOR = ((QT_VERSION >> 16) & 0xFF), - QT_MINOR = ((QT_VERSION >> 8) & 0xFF), - QT_PATCH = (QT_VERSION & 0xFF) - }; - int maj = 0, min = 0, pat = 0; - QStringList children = config->childGroups(); - for(int child = 0; child < children.size(); ++child) { - QString cver = children.at(child); - QStringList cver_list = cver.split(QLatin1Char('.')); - if(cver_list.size() > 0 && cver_list.size() < 4) { - bool ok; - int cmaj = -1, cmin = -1, cpat = -1; - cmaj = cver_list[0].toInt(&ok); - if(!ok || cmaj < 0) - continue; - if(cver_list.size() >= 2) { - cmin = cver_list[1].toInt(&ok); - if(!ok) - continue; - if(cmin < 0) - cmin = -1; - } - if(cver_list.size() >= 3) { - cpat = cver_list[2].toInt(&ok); - if(!ok) - continue; - if(cpat < 0) - cpat = -1; - } - if((cmaj >= maj && cmaj <= QT_MAJOR) && - (cmin == -1 || (cmin >= min && cmin <= QT_MINOR)) && - (cpat == -1 || (cpat >= pat && cpat <= QT_PATCH)) && - config->contains(cver + QLatin1Char('/') + key)) { - subKey = cver + QLatin1Char('/'); - maj = cmaj; - min = cmin; - pat = cpat; - } - } - } - } - ret = config->value(subKey + key, defaultValue).toString(); + ret = config->value(key, defaultValue).toString(); + // expand environment variables in the form $(ENVVAR) int rep; QRegExp reg_var(QLatin1String("\\$\\(.*\\)")); -- cgit v1.2.3 From 136c2bf18446f2bbe7052d638c29edbc0b8ef6bc Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 26 Feb 2012 01:45:53 +0000 Subject: QRegExp: fix crash Fixes a crash when invoking various QRegExp methods on an object *before* doing any match. For instance fixes: QRegExp re; re.matchedLength(); // crash Task-number: QTBUG-23352 Change-Id: I9c239ff790a139c7820ef1aeced89d31320ae6b0 Reviewed-by: Andy Shaw Reviewed-by: Thiago Macieira --- src/corelib/tools/qregexp.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index e8c0d4eccc..d7bcd0edbc 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -3934,6 +3934,7 @@ static void invalidateEngine(QRegExpPrivate *priv) QRegExp::QRegExp() { priv = new QRegExpPrivate; + prepareEngine(priv); } /*! @@ -3949,6 +3950,7 @@ QRegExp::QRegExp() QRegExp::QRegExp(const QString &pattern, Qt::CaseSensitivity cs, PatternSyntax syntax) { priv = new QRegExpPrivate(QRegExpEngineKey(pattern, syntax, cs)); + prepareEngine(priv); } /*! -- cgit v1.2.3 From 3d3b3de83adf62b3dc4c76e8bfd178e3a4969d07 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 24 Feb 2012 15:17:23 +0100 Subject: QtTest: add missing \since 5.0 to the new macros Change-Id: I8f7060c41df1e0bf1a8c35930400a31a4239a3d6 Reviewed-by: Jason McDonald --- src/testlib/qtestcase.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index e867b9629a..b8678ba04c 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -166,6 +166,7 @@ QT_BEGIN_NAMESPACE */ /*! \macro QTRY_VERIFY_WITH_TIMEOUT(condition, timeout) + \since 5.0 \relates QTest @@ -183,6 +184,7 @@ QT_BEGIN_NAMESPACE /*! \macro QTRY_VERIFY(condition) + \since 5.0 \relates QTest @@ -195,6 +197,7 @@ QT_BEGIN_NAMESPACE */ /*! \macro QTRY_COMPARE_WITH_TIMEOUT(actual, expected, timeout) + \since 5.0 \relates QTest @@ -211,6 +214,7 @@ QT_BEGIN_NAMESPACE */ /*! \macro QTRY_COMPARE(actual, expected) + \since 5.0 \relates QTest @@ -360,6 +364,7 @@ QT_BEGIN_NAMESPACE */ /*! \macro QFINDTESTDATA(filename) + \since 5.0 \relates QTest @@ -449,6 +454,7 @@ QT_BEGIN_NAMESPACE */ /*! \macro QTEST_GUILESS_MAIN(TestClass) + \since 5.0 \relates QTest -- cgit v1.2.3 From 5a0eb4e768435b9ce32b074e620fca33be4df2fb Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 27 Feb 2012 12:38:04 +0100 Subject: Fix icon loading in style sheets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QIcon was moved to QtWidgets, while the parser is still in QtGui. Introduce a QCss::IconValue struct that contains the icon data and convert to QIcon in widgets. Change-Id: I09ac8a12a4b02bdca91ee2e8fcc28c86b5a001e7 Reviewed-by: Morten Johan Sørvig --- src/gui/text/qcssparser.cpp | 40 ++++++++++++--------------------- src/gui/text/qcssparser_p.h | 21 +++++++++++++++-- src/widgets/styles/qstylesheetstyle.cpp | 19 +++++++++++++--- 3 files changed, 49 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index 38070458b7..fd01934eae 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -1272,11 +1272,9 @@ void ValueExtractor::extractFont() extractFont(&f, &dummy); } -bool ValueExtractor::extractImage(QIcon *icon, Qt::Alignment *a, QSize *size) +bool ValueExtractor::extractImage(QCss::IconValue *icon, Qt::Alignment *a, QSize *size) { bool hit = false; -#if 0 - // ### Qt5 for (int i = 0; i < declarations.count(); ++i) { const Declaration &decl = declarations.at(i); switch (decl.d->propertyId) { @@ -1297,7 +1295,6 @@ bool ValueExtractor::extractImage(QIcon *icon, Qt::Alignment *a, QSize *size) } hit = true; } -#endif return hit; } @@ -1646,30 +1643,27 @@ void Declaration::borderImageValue(QString *image, int *cuts, *h = *v; } -#if 0 -// ### Qt 5 -QIcon Declaration::iconValue() const +IconValue Declaration::iconValue() const { if (d->parsed.isValid()) - return qvariant_cast(d->parsed); + return qvariant_cast(d->parsed); - QIcon icon; + IconValue icon; for (int i = 0; i < d->values.count();) { const Value &value = d->values.at(i++); if (value.type != Value::Uri) break; - QString uri = value.variant.toString(); - QIcon::Mode mode = QIcon::Normal; - QIcon::State state = QIcon::Off; + IconValue::IconEntry entry; + entry.uri = value.variant.toString(); for (int j = 0; j < 2; j++) { if (i != d->values.count() && d->values.at(i).type == Value::KnownIdentifier) { switch (d->values.at(i).variant.toInt()) { - case Value_Disabled: mode = QIcon::Disabled; break; - case Value_Active: mode = QIcon::Active; break; - case Value_Selected: mode = QIcon::Selected; break; - case Value_Normal: mode = QIcon::Normal; break; - case Value_On: state = QIcon::On; break; - case Value_Off: state = QIcon::Off; break; + case Value_Disabled: entry.mode = IconValue::Disabled; break; + case Value_Active: entry.mode = IconValue::Active; break; + case Value_Selected: entry.mode = IconValue::Selected; break; + case Value_Normal: entry.mode = IconValue::Normal; break; + case Value_On: entry.state = IconValue::On; break; + case Value_Off: entry.state = IconValue::Off; break; default: break; } ++i; @@ -1677,12 +1671,7 @@ QIcon Declaration::iconValue() const break; } } - - // QIcon is soo broken - if (icon.isNull()) - icon = QIcon(uri); - else - icon.addPixmap(uri, mode, state); + icon.entries.push_back(entry); if (i == d->values.count()) break; @@ -1691,10 +1680,9 @@ QIcon Declaration::iconValue() const i++; } - d->parsed = QVariant::fromValue(icon); + d->parsed = QVariant::fromValue(icon); return icon; } -#endif /////////////////////////////////////////////////////////////////////////////// // Selector diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h index d50b87dcd5..b19fd8326e 100644 --- a/src/gui/text/qcssparser_p.h +++ b/src/gui/text/qcssparser_p.h @@ -411,6 +411,22 @@ struct BorderData { BrushData color; }; +struct Q_GUI_EXPORT IconValue +{ + enum Mode { Normal, Disabled, Active, Selected }; // In sync with QIcon. + enum State { On, Off }; + + struct Q_GUI_EXPORT IconEntry + { + IconEntry() : mode(Normal) , state(On) {} + + Mode mode; + State state; + QString uri; + }; + + QList entries; +}; // 1. StyleRule - x:hover, y:clicked > z:checked { prop1: value1; prop2: value2; } // 2. QVector - x:hover, y:clicked z:checked @@ -455,7 +471,7 @@ struct Q_GUI_EXPORT Declaration QSize sizeValue() const; QRect rectValue() const; QString uriValue() const; -// QIcon iconValue() const; + IconValue iconValue() const; void borderImageValue(QString *image, int *cuts, TileMode *h, TileMode *v) const; }; @@ -582,7 +598,7 @@ struct Q_GUI_EXPORT ValueExtractor bool extractOutline(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii, int *offsets); bool extractPalette(QBrush *fg, QBrush *sfg, QBrush *sbg, QBrush *abg); int extractStyleFeatures(); - bool extractImage(QIcon *icon, Qt::Alignment *a, QSize *size); + bool extractImage(QCss::IconValue *icon, Qt::Alignment *a, QSize *size); int lengthValue(const Declaration &decl); @@ -842,6 +858,7 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE( QCss::BackgroundData ) Q_DECLARE_METATYPE( QCss::LengthData ) Q_DECLARE_METATYPE( QCss::BorderData ) +Q_DECLARE_METATYPE( QCss::IconValue ) #endif // QT_NO_CSSPARSER diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 30c6ed5e74..5c0ee254d4 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -860,6 +860,19 @@ static QStyle::StandardPixmap subControlIcon(int pe) return QStyle::SP_CustomBase; } +static inline QIcon cssIconValueToIcon(const QCss::IconValue &iconValue) +{ + if (iconValue.entries.isEmpty()) + return QIcon(); + QIcon icon = QIcon(iconValue.entries.first().uri); + for (int i = 1; i < iconValue.entries.size(); ++i) { + const QCss::IconValue::IconEntry &entry = iconValue.entries.at(i); + icon.addPixmap(entry.uri, static_cast(entry.mode), + static_cast(entry.state)); + } + return icon; +} + QRenderRule::QRenderRule(const QVector &declarations, const QWidget *widget) : features(0), hasFont(false), pal(0), b(0), bg(0), bd(0), ou(0), geo(0), p(0), img(0), clipset(0) { @@ -919,11 +932,11 @@ QRenderRule::QRenderRule(const QVector &declarations, const QWidget if (v.extractPalette(&fg, &sfg, &sbg, &abg)) pal = new QStyleSheetPaletteData(fg, sfg, sbg, abg); - QIcon icon; alignment = Qt::AlignCenter; QSize size; - if (v.extractImage(&icon, &alignment, &size)) - img = new QStyleSheetImageData(icon, alignment, size); + QCss::IconValue iconValue; + if (v.extractImage(&iconValue, &alignment, &size)) + img = new QStyleSheetImageData(cssIconValueToIcon(iconValue), alignment, size); int adj = -255; hasFont = v.extractFont(&font, &adj); -- cgit v1.2.3 From 63017136a1a6625c3528f9b237468a55b7fab12c Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 24 Feb 2012 10:51:18 -0800 Subject: QClipboard: Fix autotest fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tst_qclipboard.cpp still has Q_WS_WIN which must be clear away. After clean up, auto test will fail under windows: When setMimeData() is called, dataChanged() signal will be emited twice. The solution for QTBUG-24184 has partially solved the problem, but it still there. Make sure emitChanged() only called by QPlatformClipboard will give our more control for this. Task-number: QTBUG-24484 Change-Id: I23566c6d3b32828b6865234c311af3635fe9e299 Reviewed-by: Friedemann Kleint Reviewed-by: Samuel Rødal --- src/gui/kernel/qclipboard_qpa.cpp | 2 -- src/gui/kernel/qplatformclipboard_qpa.cpp | 2 ++ src/plugins/platforms/windows/qwindowsclipboard.cpp | 3 +-- src/plugins/platforms/xcb/qxcbclipboard.cpp | 1 + src/plugins/platforms/xlib/qxlibclipboard.cpp | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qclipboard_qpa.cpp b/src/gui/kernel/qclipboard_qpa.cpp index b33ccd42a2..0d97fdd0be 100644 --- a/src/gui/kernel/qclipboard_qpa.cpp +++ b/src/gui/kernel/qclipboard_qpa.cpp @@ -76,8 +76,6 @@ void QClipboard::setMimeData(QMimeData* src, Mode mode) if (!clipboard->supportsMode(mode)) return; clipboard->setMimeData(src,mode); - - emitChanged(mode); } bool QClipboard::supportsMode(Mode mode) const diff --git a/src/gui/kernel/qplatformclipboard_qpa.cpp b/src/gui/kernel/qplatformclipboard_qpa.cpp index 9e0c60b3f6..bc08a73a7f 100644 --- a/src/gui/kernel/qplatformclipboard_qpa.cpp +++ b/src/gui/kernel/qplatformclipboard_qpa.cpp @@ -96,6 +96,8 @@ void QPlatformClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) //we know its clipboard Q_UNUSED(mode); q_clipboardData()->setSource(data); + + emitChanged(mode); } bool QPlatformClipboard::supportsMode(QClipboard::Mode mode) const diff --git a/src/plugins/platforms/windows/qwindowsclipboard.cpp b/src/plugins/platforms/windows/qwindowsclipboard.cpp index 4f083e93d2..cd555d71a1 100644 --- a/src/plugins/platforms/windows/qwindowsclipboard.cpp +++ b/src/plugins/platforms/windows/qwindowsclipboard.cpp @@ -287,8 +287,7 @@ bool QWindowsClipboard::clipboardViewerWndProc(HWND hwnd, UINT message, WPARAM w const bool owned = ownsClipboard(); if (QWindowsContext::verboseOLE) qDebug("Clipboard changed owned %d", owned); - if (!owned) // changed is emitted by QClipboard in that case. - emitChanged(QClipboard::Clipboard); + emitChanged(QClipboard::Clipboard); // clean up the clipboard object if we no longer own the clipboard if (!owned && m_data) releaseIData(); diff --git a/src/plugins/platforms/xcb/qxcbclipboard.cpp b/src/plugins/platforms/xcb/qxcbclipboard.cpp index bad80568e3..f8d35ed4da 100644 --- a/src/plugins/platforms/xcb/qxcbclipboard.cpp +++ b/src/plugins/platforms/xcb/qxcbclipboard.cpp @@ -295,6 +295,7 @@ void QXcbClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) qWarning("QClipboard::setData: Cannot set X11 selection owner"); } + emitChanged(mode); } bool QXcbClipboard::supportsMode(QClipboard::Mode mode) const diff --git a/src/plugins/platforms/xlib/qxlibclipboard.cpp b/src/plugins/platforms/xlib/qxlibclipboard.cpp index 920b4a4cff..69a0f20777 100644 --- a/src/plugins/platforms/xlib/qxlibclipboard.cpp +++ b/src/plugins/platforms/xlib/qxlibclipboard.cpp @@ -223,6 +223,7 @@ void QXlibClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) qWarning("QClipboard::setData: Cannot set X11 selection owner"); } + emitChanged(mode); } bool QXlibClipboard::supportsMode(QClipboard::Mode mode) const -- cgit v1.2.3 From 446d63be1b85284d6175b4781859d14668755ae3 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 24 Feb 2012 13:46:33 -0800 Subject: Fix tst_qmenu. Clear away Q_WS_WIN/Q_WS_X11 from QMenu. Using the hint returned by the QPlatformTheme. Task-number: QTBUG-24325 Change-Id: Iaa4da26c74273d7cfc1fbec6519c52d09e10f7bb Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qmenu.cpp | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index e619cdf4fc..dad12fe6ab 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -70,10 +70,8 @@ #include #include #include - -#ifdef Q_WS_X11 -# include -#endif +#include +#include QT_BEGIN_NAMESPACE @@ -177,31 +175,23 @@ int QMenuPrivate::scrollerHeight() const //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry(const QWidget *widget) const { -#ifdef Q_WS_WIN - return QApplication::desktop()->screenGeometry(widget); -#elif defined Q_WS_X11 - if (X11->desktopEnvironment == DE_KDE) + if (QGuiApplicationPrivate::platformTheme() && + QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool()) { return QApplication::desktop()->screenGeometry(widget); - else - return QApplication::desktop()->availableGeometry(widget); -#else + } else { return QApplication::desktop()->availableGeometry(widget); -#endif + } } //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry(int screen) const { -#ifdef Q_WS_WIN - return QApplication::desktop()->screenGeometry(screen); -#elif defined Q_WS_X11 - if (X11->desktopEnvironment == DE_KDE) + if (QGuiApplicationPrivate::platformTheme() && + QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool()) { return QApplication::desktop()->screenGeometry(screen); - else - return QApplication::desktop()->availableGeometry(screen); -#else + } else { return QApplication::desktop()->availableGeometry(screen); -#endif + } } QList > QMenuPrivate::calcCausedStack() const @@ -2261,7 +2251,7 @@ void QMenu::mouseReleaseEvent(QMouseEvent *e) if (action && action == d->currentAction) { if (!action->menu()){ -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) //On Windows only context menus can be activated with the right button if (e->button() == Qt::LeftButton || d->topCausedWidget() == 0) #endif @@ -3000,7 +2990,7 @@ void QMenu::internalDelayedPopup() */ void QMenu::setNoReplayFor(QWidget *noReplayFor) { -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN d_func()->noReplayFor = noReplayFor; #else Q_UNUSED(noReplayFor); -- cgit v1.2.3 From 5bbfe4d6d8752067e51983b34169a99f563088f8 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 21 Feb 2012 21:41:28 +0100 Subject: remove over-uses of $$list() not sure why anyone would do *that* ... Change-Id: Id91e9e8bd602a9d9275ade2ca86aaa4f4698ff72 Reviewed-by: Joerg Bornemann --- src/src.pro | 4 ++-- src/tools/tools.pro | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/src.pro b/src/src.pro index f3f6937c50..6e1517fb07 100644 --- a/src/src.pro +++ b/src/src.pro @@ -90,8 +90,8 @@ for(subname, SRC_SUBDIRS) { subdir = $$replace(subdir, $$reg_src, $$QT_BUILD_TREE) subdir = $$replace(subdir, /, $$QMAKE_DIR_SEP) subdir = $$replace(subdir, \\\\, $$QMAKE_DIR_SEP) - SUB_TEMPLATE = $$list($$fromfile($$subpro, TEMPLATE)) - !isEqual(subname, src_tools_bootstrap):if(isEqual($$SUB_TEMPLATE, lib) | isEqual($$SUB_TEMPLATE, subdirs)):!separate_debug_info { + SUB_TEMPLATE = $$fromfile($$subpro, TEMPLATE) + !isEqual(subname, src_tools_bootstrap):if(isEqual(SUB_TEMPLATE, lib) | isEqual(SUB_TEMPLATE, subdirs)):!separate_debug_info { #debug debug-$${subtarget}.depends = $${subdir}$${QMAKE_DIR_SEP}$(MAKEFILE) $$EXTRA_DEBUG_TARGETS debug-$${subtarget}.commands = (cd $$subdir && $(MAKE) -f $(MAKEFILE) debug) diff --git a/src/tools/tools.pro b/src/tools/tools.pro index e6b9eefc69..cf10163539 100644 --- a/src/tools/tools.pro +++ b/src/tools/tools.pro @@ -32,8 +32,8 @@ for(subname, TOOLS_SUBDIRS) { subdir = $$replace(subdir, $$reg_src, $$QT_BUILD_TREE) subdir = $$replace(subdir, /, $$QMAKE_DIR_SEP) subdir = $$replace(subdir, \\\\, $$QMAKE_DIR_SEP) - SUB_TEMPLATE = $$list($$fromfile($$subpro, TEMPLATE)) - !isEqual(subname, src_tools_bootstrap):if(isEqual($$SUB_TEMPLATE, lib) | isEqual($$SUB_TEMPLATE, subdirs)):!separate_debug_info { + SUB_TEMPLATE = $$fromfile($$subpro, TEMPLATE) + !isEqual(subname, src_tools_bootstrap):if(isEqual(SUB_TEMPLATE, lib) | isEqual(SUB_TEMPLATE, subdirs)):!separate_debug_info { #debug debug-$${subtarget}.depends = $${subdir}$${QMAKE_DIR_SEP}$(MAKEFILE) $$EXTRA_DEBUG_TARGETS debug-$${subtarget}.commands = (cd $$subdir && $(MAKE) -f $(MAKEFILE) debug) -- cgit v1.2.3 From 64e0560ff451676fc96dfadd21bef436ac25bb52 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 27 Feb 2012 13:54:21 +0200 Subject: Fix submenu positioning Submenus are now positioned to the correct side of the parent menu based on layout direction, if there is enough space on screen to fit the menu. If there is insufficient space, then the menu is positioned to the other side of the parent menu. In case that also causes submenu to be partially ofscreen (very wide menu relative to the screen), then the submenu will be aligned with the screen edge and will overlap the parent menu. This seems like a lesser evil compared to having submenu partially offscreen, which could obscure important details such as checkmarks. Task-number: QTBUG-23568 Change-Id: I6a9ab2c232713a2ee5a6dde3227c40419d46bd3d Reviewed-by: Bradley T. Hughes Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qmenu.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index dad12fe6ab..2c97f3355c 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -1898,13 +1898,21 @@ void QMenu::popup(const QPoint &p, QAction *atAction) if ((pos.x() + menuSize.width() > parentActionRect.left() - subMenuOffset) && (pos.x() < parentActionRect.right())) { + pos.rx() = parentActionRect.left() - menuSize.width(); + if (pos.x() < screen.x()) pos.rx() = parentActionRect.right(); + if (pos.x() + menuSize.width() > screen.x() + screen.width()) + pos.rx() = screen.x(); } } else { if ((pos.x() < parentActionRect.right() + subMenuOffset) && (pos.x() + menuSize.width() > parentActionRect.left())) { + pos.rx() = parentActionRect.right(); + if (pos.x() + menuSize.width() > screen.x() + screen.width()) pos.rx() = parentActionRect.left() - menuSize.width(); + if (pos.x() < screen.x()) + pos.rx() = screen.x() + screen.width() - menuSize.width(); } } } -- cgit v1.2.3 From e2f295e27c10a9f3633344427959219caf63753d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 27 Feb 2012 12:00:07 +0100 Subject: Detect QMetaType::QReal from the definition of qreal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of relying to complex preprocessor expression that need to be maintained to be kept the same as in qglobal.h This aslo fix the case where QT_COORD_TYPE is defined (It is meant to be defined to float or double, any other type would not make sense) So now there should hopefully be only one place to change if one need to adjust the type of qreal Change-Id: I778312112603173562dbe675ab491b53d6cd2174 Reviewed-by: JÄ™drzej Nowacki --- src/corelib/kernel/qmetatype.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 4e75e1414b..beb7294abd 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -200,14 +200,7 @@ public: LastWidgetsType = QSizePolicy, HighestInternalId = LastWidgetsType, -// This logic must match the one in qglobal.h -#if defined(QT_COORD_TYPE) - QReal = 0, -#elif defined(QT_NO_FPU) || defined(Q_PROCESSOR_ARM) || defined(Q_OS_WINCE) - QReal = Float, -#else - QReal = Double, -#endif + QReal = sizeof(qreal) == sizeof(double) ? Double : Float, User = 256 }; -- cgit v1.2.3 From 05e24901a14f1a656359bc649686674a9bca1473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Thu, 23 Feb 2012 08:24:21 +0100 Subject: QHeaderView - minor cleanup in viewportEvent This is an improvement to a previous fix with SHA e62e71162606fec134600955a89b7e0c34a7840b We actually never want to call resizeSections if the parent is hidden. Therefore we can both simplify and improve the code with this patch. When we do show/hide on parent then the visible status is updated before we get into this code. I have verified the patch on the code from: Task-number: QTBUG-14234 Change-Id: If7bfa3b3813c97b4a545e48423526e9cfe118de4 Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qheaderview.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index ed71c5a918..5d2aceaade 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2433,20 +2433,15 @@ bool QHeaderView::viewportEvent(QEvent *e) } return true; } #endif // QT_NO_STATUSTIP - case QEvent::Hide: { - d->invalidateCachedSizeHint(); + case QEvent::Hide: + case QEvent::Show: + case QEvent::FontChange: + case QEvent::StyleChange:{ QAbstractScrollArea *parent = qobject_cast(parentWidget()); if (parent && parent->isVisible()) // Only resize if we have a visible parent resizeSections(); emit geometriesChanged(); break;} - case QEvent::Show: - case QEvent::FontChange: - case QEvent::StyleChange: - d->invalidateCachedSizeHint(); - resizeSections(); - emit geometriesChanged(); - break; case QEvent::ContextMenu: { d->state = QHeaderViewPrivate::NoState; d->pressed = d->section = d->target = -1; -- cgit v1.2.3 From bc6ad75d18a029da363afc4f6007aefc7962a8ad Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 26 Feb 2012 10:56:49 +0100 Subject: Remove use of deprecated conversion from QKeySequence Note: UNICODE_ACCEL is Qt3 compatibility and is equal to 0 Change-Id: I808a66772abceb3822d515d69386728264eb1b40 Reviewed-by: Lars Knoll --- src/plugins/accessible/widgets/simplewidgets.cpp | 2 +- src/widgets/accessible/qaccessiblewidget.cpp | 2 +- src/widgets/dialogs/qmessagebox.cpp | 6 +++--- src/widgets/kernel/qaction.cpp | 2 +- src/widgets/widgets/qlineedit.cpp | 3 ++- src/widgets/widgets/qmenu.cpp | 4 ++-- src/widgets/widgets/qwidgettextcontrol.cpp | 4 +++- src/widgets/widgets/qworkspace.cpp | 3 ++- 8 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index 0fdd4490f7..39d7e03a1b 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -115,7 +115,7 @@ QString QAccessibleButton::text(QAccessible::Text t) const #ifndef QT_NO_SHORTCUT QPushButton *pb = qobject_cast(object()); if (pb && pb->isDefault()) - str = (QString)QKeySequence(Qt::Key_Enter); + str = QKeySequence(Qt::Key_Enter).toString(QKeySequence::NativeText); #endif if (str.isEmpty()) str = qt_accHotKey(button()->text()); diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index feac42780d..790b51102c 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -128,7 +128,7 @@ QString Q_WIDGETS_EXPORT qt_accHotKey(const QString &text) } if (ac.isNull()) return QString(); - return (QString)QKeySequence(Qt::ALT) + ac.toUpper(); + return QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + ac.toUpper(); #else Q_UNUSED(text); return QString(); diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 634e911cd1..a737584e3f 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1365,13 +1365,13 @@ void QMessageBox::keyPressEvent(QKeyEvent *e) #ifndef QT_NO_SHORTCUT if (!(e->modifiers() & Qt::AltModifier)) { - int key = e->key() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL); + int key = e->key() & ~Qt::MODIFIER_MASK; if (key) { const QList buttons = d->buttonBox->buttons(); for (int i = 0; i < buttons.count(); ++i) { QAbstractButton *pb = buttons.at(i); - int acc = pb->shortcut() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL); - if (acc == key) { + QKeySequence shortcut = pb->shortcut(); + if (!shortcut.isEmpty() && key == (shortcut[0] & ~Qt::MODIFIER_MASK)) { pb->animateClick(); return; } diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp index d3d63a8c7b..f450d13a39 100644 --- a/src/widgets/kernel/qaction.cpp +++ b/src/widgets/kernel/qaction.cpp @@ -1119,7 +1119,7 @@ QAction::event(QEvent *e) "QAction::event", "Received shortcut event from incorrect shortcut"); if (se->isAmbiguous()) - qWarning("QAction::eventFilter: Ambiguous shortcut overload: %s", QString(se->key()).toLatin1().constData()); + qWarning("QAction::eventFilter: Ambiguous shortcut overload: %s", se->key().toString(QKeySequence::NativeText).toLatin1().constData()); else activate(Trigger); return true; diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 77d6f5422a..7118881ef2 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -75,7 +75,8 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include "qkeysequence.h" -#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString()) +#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ + QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) #else #define ACCEL_KEY(k) QString() #endif diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 2c97f3355c..7ebfdbecae 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -295,7 +295,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const } else { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) - tabWidth = qMax(int(tabWidth), qfm.width(seq)); + tabWidth = qMax(int(tabWidth), qfm.width(seq.toString(QKeySequence::NativeText))); #endif } sz.setWidth(fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, s).width()); @@ -1187,7 +1187,7 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) if (textAndAccel.indexOf(QLatin1Char('\t')) == -1) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) - textAndAccel += QLatin1Char('\t') + QString(seq); + textAndAccel += QLatin1Char('\t') + seq.toString(QKeySequence::NativeText); } #endif option->text = textAndAccel; diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index a2c7915a5e..9eeffc1231 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -84,7 +84,9 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include -#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString()) +#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ + QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) + #else #define ACCEL_KEY(k) QString() #endif diff --git a/src/widgets/widgets/qworkspace.cpp b/src/widgets/widgets/qworkspace.cpp index 0031a71ccd..5cc8e363f1 100644 --- a/src/widgets/widgets/qworkspace.cpp +++ b/src/widgets/widgets/qworkspace.cpp @@ -1079,7 +1079,8 @@ QWorkspacePrivate::init() actions[QWorkspacePrivate::CloseAct] = new QAction(QIcon(q->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, q)), QWorkspace::tr("&Close") #ifndef QT_NO_SHORTCUT - +QLatin1Char('\t')+(QString)QKeySequence(Qt::CTRL+Qt::Key_F4) + + QLatin1Char('\t') + + QKeySequence(Qt::CTRL+Qt::Key_F4).toString(QKeySequence::NativeText) #endif ,q); QObject::connect(actions[QWorkspacePrivate::CloseAct], SIGNAL(triggered()), q, SLOT(closeActiveWindow())); -- cgit v1.2.3 From b51296c06433d4923e4dcfd2bc104ae3ab67fb43 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Fri, 3 Feb 2012 12:28:13 +0100 Subject: Add SHA-224, SHA-256, SHA-384, and SHA-512 support to QCryptographicHash This adds Sha224, Sha256, Sha384, and Sha512 enum values to QCryptographicHash::Algorithm. The implementation comes from RFC 6234, http://tools.ietf.org/html/rfc6234, which is added to src/3rdparty/rfc6234. Only the headers and SHA-2 code is included in src/3rdparty/rfc6234 (the SHA1, HMAC, and HKDF code is not included). Change-Id: I85139fd118291f15efc22899a5ddd1cc83810cfb Reviewed-by: Lars Knoll --- src/3rdparty/rfc6234/sha-private.h | 28 + src/3rdparty/rfc6234/sha.h | 356 ++++++++++ src/3rdparty/rfc6234/sha224-256.c | 583 +++++++++++++++++ src/3rdparty/rfc6234/sha384-512.c | 1034 ++++++++++++++++++++++++++++++ src/corelib/tools/qcryptographichash.cpp | 95 ++- src/corelib/tools/qcryptographichash.h | 6 +- 6 files changed, 2099 insertions(+), 3 deletions(-) create mode 100644 src/3rdparty/rfc6234/sha-private.h create mode 100644 src/3rdparty/rfc6234/sha.h create mode 100644 src/3rdparty/rfc6234/sha224-256.c create mode 100644 src/3rdparty/rfc6234/sha384-512.c (limited to 'src') diff --git a/src/3rdparty/rfc6234/sha-private.h b/src/3rdparty/rfc6234/sha-private.h new file mode 100644 index 0000000000..6e9c4520fb --- /dev/null +++ b/src/3rdparty/rfc6234/sha-private.h @@ -0,0 +1,28 @@ +/************************ sha-private.h ************************/ +/***************** See RFC 6234 for details. *******************/ +#ifndef _SHA_PRIVATE__H +#define _SHA_PRIVATE__H +/* + * These definitions are defined in FIPS 180-3, section 4.1. + * Ch() and Maj() are defined identically in sections 4.1.1, + * 4.1.2, and 4.1.3. + * + * The definitions used in FIPS 180-3 are as follows: + */ + +#ifndef USE_MODIFIED_MACROS +#define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) +#define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) +#else /* USE_MODIFIED_MACROS */ +/* + * The following definitions are equivalent and potentially faster. + */ + +#define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) +#define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) + +#endif /* USE_MODIFIED_MACROS */ + +#define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z)) + +#endif /* _SHA_PRIVATE__H */ diff --git a/src/3rdparty/rfc6234/sha.h b/src/3rdparty/rfc6234/sha.h new file mode 100644 index 0000000000..1ffd688079 --- /dev/null +++ b/src/3rdparty/rfc6234/sha.h @@ -0,0 +1,356 @@ +/**************************** sha.h ****************************/ +/***************** See RFC 6234 for details. *******************/ +/* + Copyright (c) 2011 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + - Redistributions of source code must retain the above + copyright notice, this list of conditions and + the following disclaimer. + + - Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + - Neither the name of Internet Society, IETF or IETF Trust, nor + the names of specific contributors, may be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef _SHA_H_ +#define _SHA_H_ + +/* + * Description: + * This file implements the Secure Hash Algorithms + * as defined in the U.S. National Institute of Standards + * and Technology Federal Information Processing Standards + * Publication (FIPS PUB) 180-3 published in October 2008 + * and formerly defined in its predecessors, FIPS PUB 180-1 + * and FIP PUB 180-2. + * + * A combined document showing all algorithms is available at + * http://csrc.nist.gov/publications/fips/ + * fips180-3/fips180-3_final.pdf + * + * The five hashes are defined in these sizes: + * SHA-1 20 byte / 160 bit + * SHA-224 28 byte / 224 bit + * SHA-256 32 byte / 256 bit + * SHA-384 48 byte / 384 bit + * SHA-512 64 byte / 512 bit + * + * Compilation Note: + * These files may be compiled with two options: + * USE_32BIT_ONLY - use 32-bit arithmetic only, for systems + * without 64-bit integers + * + * USE_MODIFIED_MACROS - use alternate form of the SHA_Ch() + * and SHA_Maj() macros that are equivalent + * and potentially faster on many systems + * + */ + +#include +/* + * If you do not have the ISO standard stdint.h header file, then you + * must typedef the following: + * name meaning + * uint64_t unsigned 64-bit integer + * uint32_t unsigned 32-bit integer + * uint8_t unsigned 8-bit integer (i.e., unsigned char) + * int_least16_t integer of >= 16 bits + * + * See stdint-example.h + */ + +#ifndef _SHA_enum_ +#define _SHA_enum_ +/* + * All SHA functions return one of these values. + */ +enum { + shaSuccess = 0, + shaNull, /* Null pointer parameter */ + shaInputTooLong, /* input data too long */ + shaStateError, /* called Input after FinalBits or Result */ + shaBadParam /* passed a bad parameter */ +}; +#endif /* _SHA_enum_ */ + +/* + * These constants hold size information for each of the SHA + * hashing operations + */ +enum { + SHA1_Message_Block_Size = 64, SHA224_Message_Block_Size = 64, + SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128, + SHA512_Message_Block_Size = 128, + USHA_Max_Message_Block_Size = SHA512_Message_Block_Size, + + SHA1HashSize = 20, SHA224HashSize = 28, SHA256HashSize = 32, + SHA384HashSize = 48, SHA512HashSize = 64, + USHAMaxHashSize = SHA512HashSize, + + SHA1HashSizeBits = 160, SHA224HashSizeBits = 224, + SHA256HashSizeBits = 256, SHA384HashSizeBits = 384, + SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits +}; + +/* + * These constants are used in the USHA (Unified SHA) functions. + */ +typedef enum SHAversion { + SHA1, SHA224, SHA256, SHA384, SHA512 +} SHAversion; + +/* + * This structure will hold context information for the SHA-1 + * hashing operation. + */ +typedef struct SHA1Context { + uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ + + uint32_t Length_High; /* Message length in bits */ + uint32_t Length_Low; /* Message length in bits */ + + int_least16_t Message_Block_Index; /* Message_Block array index */ + /* 512-bit message blocks */ + uint8_t Message_Block[SHA1_Message_Block_Size]; + + int Computed; /* Is the hash computed? */ + int Corrupted; /* Cumulative corruption code */ +} SHA1Context; + +/* + * This structure will hold context information for the SHA-256 + * hashing operation. + */ +typedef struct SHA256Context { + uint32_t Intermediate_Hash[SHA256HashSize/4]; /* Message Digest */ + + uint32_t Length_High; /* Message length in bits */ + uint32_t Length_Low; /* Message length in bits */ + + int_least16_t Message_Block_Index; /* Message_Block array index */ + /* 512-bit message blocks */ + uint8_t Message_Block[SHA256_Message_Block_Size]; + + int Computed; /* Is the hash computed? */ + int Corrupted; /* Cumulative corruption code */ +} SHA256Context; + +/* + * This structure will hold context information for the SHA-512 + * hashing operation. + */ +typedef struct SHA512Context { +#ifdef USE_32BIT_ONLY + uint32_t Intermediate_Hash[SHA512HashSize/4]; /* Message Digest */ + uint32_t Length[4]; /* Message length in bits */ +#else /* !USE_32BIT_ONLY */ + uint64_t Intermediate_Hash[SHA512HashSize/8]; /* Message Digest */ + uint64_t Length_High, Length_Low; /* Message length in bits */ +#endif /* USE_32BIT_ONLY */ + + int_least16_t Message_Block_Index; /* Message_Block array index */ + /* 1024-bit message blocks */ + uint8_t Message_Block[SHA512_Message_Block_Size]; + + int Computed; /* Is the hash computed?*/ + int Corrupted; /* Cumulative corruption code */ +} SHA512Context; + +/* + * This structure will hold context information for the SHA-224 + * hashing operation. It uses the SHA-256 structure for computation. + */ +typedef struct SHA256Context SHA224Context; + +/* + * This structure will hold context information for the SHA-384 + * hashing operation. It uses the SHA-512 structure for computation. + */ +typedef struct SHA512Context SHA384Context; + +/* + * This structure holds context information for all SHA + * hashing operations. + */ +typedef struct USHAContext { + int whichSha; /* which SHA is being used */ + union { + SHA1Context sha1Context; + SHA224Context sha224Context; SHA256Context sha256Context; + SHA384Context sha384Context; SHA512Context sha512Context; + } ctx; +} USHAContext; + +/* + * This structure will hold context information for the HMAC + * keyed-hashing operation. + */ +typedef struct HMACContext { + int whichSha; /* which SHA is being used */ + int hashSize; /* hash size of SHA being used */ + int blockSize; /* block size of SHA being used */ + USHAContext shaContext; /* SHA context */ + unsigned char k_opad[USHA_Max_Message_Block_Size]; + /* outer padding - key XORd with opad */ + int Computed; /* Is the MAC computed? */ + int Corrupted; /* Cumulative corruption code */ + +} HMACContext; + +/* + * This structure will hold context information for the HKDF + * extract-and-expand Key Derivation Functions. + */ +typedef struct HKDFContext { + int whichSha; /* which SHA is being used */ + HMACContext hmacContext; + int hashSize; /* hash size of SHA being used */ + unsigned char prk[USHAMaxHashSize]; + /* pseudo-random key - output of hkdfInput */ + int Computed; /* Is the key material computed? */ + int Corrupted; /* Cumulative corruption code */ +} HKDFContext; + +/* + * Function Prototypes + */ + +/* SHA-1 */ +extern int SHA1Reset(SHA1Context *); +extern int SHA1Input(SHA1Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA1FinalBits(SHA1Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA1Result(SHA1Context *, + uint8_t Message_Digest[SHA1HashSize]); + +/* SHA-224 */ +extern int SHA224Reset(SHA224Context *); +extern int SHA224Input(SHA224Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA224FinalBits(SHA224Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA224Result(SHA224Context *, + uint8_t Message_Digest[SHA224HashSize]); + +/* SHA-256 */ +extern int SHA256Reset(SHA256Context *); +extern int SHA256Input(SHA256Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA256FinalBits(SHA256Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA256Result(SHA256Context *, + uint8_t Message_Digest[SHA256HashSize]); + +/* SHA-384 */ +extern int SHA384Reset(SHA384Context *); +extern int SHA384Input(SHA384Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA384FinalBits(SHA384Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA384Result(SHA384Context *, + uint8_t Message_Digest[SHA384HashSize]); + +/* SHA-512 */ +extern int SHA512Reset(SHA512Context *); +extern int SHA512Input(SHA512Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA512FinalBits(SHA512Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA512Result(SHA512Context *, + uint8_t Message_Digest[SHA512HashSize]); + +/* Unified SHA functions, chosen by whichSha */ +extern int USHAReset(USHAContext *context, SHAversion whichSha); +extern int USHAInput(USHAContext *context, + const uint8_t *bytes, unsigned int bytecount); +extern int USHAFinalBits(USHAContext *context, + uint8_t bits, unsigned int bit_count); +extern int USHAResult(USHAContext *context, + uint8_t Message_Digest[USHAMaxHashSize]); +extern int USHABlockSize(enum SHAversion whichSha); +extern int USHAHashSize(enum SHAversion whichSha); +extern int USHAHashSizeBits(enum SHAversion whichSha); +extern const char *USHAHashName(enum SHAversion whichSha); + +/* + * HMAC Keyed-Hashing for Message Authentication, RFC 2104, + * for all SHAs. + * This interface allows a fixed-length text input to be used. + */ +extern int hmac(SHAversion whichSha, /* which SHA algorithm to use */ + const unsigned char *text, /* pointer to data stream */ + int text_len, /* length of data stream */ + const unsigned char *key, /* pointer to authentication key */ + int key_len, /* length of authentication key */ + uint8_t digest[USHAMaxHashSize]); /* caller digest to fill in */ + +/* + * HMAC Keyed-Hashing for Message Authentication, RFC 2104, + * for all SHAs. + * This interface allows any length of text input to be used. + */ +extern int hmacReset(HMACContext *context, enum SHAversion whichSha, + const unsigned char *key, int key_len); +extern int hmacInput(HMACContext *context, const unsigned char *text, + int text_len); +extern int hmacFinalBits(HMACContext *context, uint8_t bits, + unsigned int bit_count); +extern int hmacResult(HMACContext *context, + uint8_t digest[USHAMaxHashSize]); + +/* + * HKDF HMAC-based Extract-and-Expand Key Derivation Function, + * RFC 5869, for all SHAs. + */ +extern int hkdf(SHAversion whichSha, const unsigned char *salt, + int salt_len, const unsigned char *ikm, int ikm_len, + const unsigned char *info, int info_len, + uint8_t okm[ ], int okm_len); +extern int hkdfExtract(SHAversion whichSha, const unsigned char *salt, + int salt_len, const unsigned char *ikm, + int ikm_len, uint8_t prk[USHAMaxHashSize]); +extern int hkdfExpand(SHAversion whichSha, const uint8_t prk[ ], + int prk_len, const unsigned char *info, + int info_len, uint8_t okm[ ], int okm_len); + +/* + * HKDF HMAC-based Extract-and-Expand Key Derivation Function, + * RFC 5869, for all SHAs. + * This interface allows any length of text input to be used. + */ +extern int hkdfReset(HKDFContext *context, enum SHAversion whichSha, + const unsigned char *salt, int salt_len); +extern int hkdfInput(HKDFContext *context, const unsigned char *ikm, + int ikm_len); +extern int hkdfFinalBits(HKDFContext *context, uint8_t ikm_bits, + unsigned int ikm_bit_count); +extern int hkdfResult(HKDFContext *context, + uint8_t prk[USHAMaxHashSize], + const unsigned char *info, int info_len, + uint8_t okm[USHAMaxHashSize], int okm_len); +#endif /* _SHA_H_ */ diff --git a/src/3rdparty/rfc6234/sha224-256.c b/src/3rdparty/rfc6234/sha224-256.c new file mode 100644 index 0000000000..9546540ea5 --- /dev/null +++ b/src/3rdparty/rfc6234/sha224-256.c @@ -0,0 +1,583 @@ +/************************* sha224-256.c ************************/ +/***************** See RFC 6234 for details. *******************/ +/* Copyright (c) 2011 IETF Trust and the persons identified as */ +/* authors of the code. All rights reserved. */ +/* See sha.h for terms of use and redistribution. */ + +/* + * Description: + * This file implements the Secure Hash Algorithms SHA-224 and + * SHA-256 as defined in the U.S. National Institute of Standards + * and Technology Federal Information Processing Standards + * Publication (FIPS PUB) 180-3 published in October 2008 + * and formerly defined in its predecessors, FIPS PUB 180-1 + * and FIP PUB 180-2. + * + * A combined document showing all algorithms is available at + * http://csrc.nist.gov/publications/fips/ + * fips180-3/fips180-3_final.pdf + * + * The SHA-224 and SHA-256 algorithms produce 224-bit and 256-bit + * message digests for a given data stream. It should take about + * 2**n steps to find a message with the same digest as a given + * message and 2**(n/2) to find any two messages with the same + * digest, when n is the digest size in bits. Therefore, this + * algorithm can serve as a means of providing a + * "fingerprint" for a message. + * + * Portability Issues: + * SHA-224 and SHA-256 are defined in terms of 32-bit "words". + * This code uses (included via "sha.h") to define 32- + * and 8-bit unsigned integer types. If your C compiler does not + * support 32-bit unsigned integers, this code is not + * appropriate. + * + * Caveats: + * SHA-224 and SHA-256 are designed to work with messages less + * than 2^64 bits long. This implementation uses SHA224/256Input() + * to hash the bits that are a multiple of the size of an 8-bit + * octet, and then optionally uses SHA224/256FinalBits() + * to hash the final few bits of the input. + */ + +#include "sha.h" +#include "sha-private.h" + +/* Define the SHA shift, rotate left, and rotate right macros */ +#define SHA256_SHR(bits,word) ((word) >> (bits)) +#define SHA256_ROTL(bits,word) \ + (((word) << (bits)) | ((word) >> (32-(bits)))) +#define SHA256_ROTR(bits,word) \ + (((word) >> (bits)) | ((word) << (32-(bits)))) + +/* Define the SHA SIGMA and sigma macros */ +#define SHA256_SIGMA0(word) \ + (SHA256_ROTR( 2,word) ^ SHA256_ROTR(13,word) ^ SHA256_ROTR(22,word)) +#define SHA256_SIGMA1(word) \ + (SHA256_ROTR( 6,word) ^ SHA256_ROTR(11,word) ^ SHA256_ROTR(25,word)) +#define SHA256_sigma0(word) \ + (SHA256_ROTR( 7,word) ^ SHA256_ROTR(18,word) ^ SHA256_SHR( 3,word)) +#define SHA256_sigma1(word) \ + (SHA256_ROTR(17,word) ^ SHA256_ROTR(19,word) ^ SHA256_SHR(10,word)) + +/* + * Add "length" to the length. + * Set Corrupted when overflow has occurred. + */ +/* addTemp commented out by Nokia, static variables are not thread-safe */ +/* static uint32_t addTemp; */ +/* 'M' appended to Macro name by Nokia */ +#define SHA224_256AddLengthM(context, length) \ + (addTemp = (context)->Length_Low, (context)->Corrupted = \ + (((context)->Length_Low += (length)) < addTemp) && \ + (++(context)->Length_High == 0) ? shaInputTooLong : \ + (context)->Corrupted ) + +/* Local Function Prototypes */ +static int SHA224_256Reset(SHA256Context *context, uint32_t *H0); +static void SHA224_256ProcessMessageBlock(SHA256Context *context); +static void SHA224_256Finalize(SHA256Context *context, + uint8_t Pad_Byte); +static void SHA224_256PadMessage(SHA256Context *context, + uint8_t Pad_Byte); +static int SHA224_256ResultN(SHA256Context *context, + uint8_t Message_Digest[ ], int HashSize); + +/* Initial Hash Values: FIPS 180-3 section 5.3.2 */ +static uint32_t SHA224_H0[SHA256HashSize/4] = { + 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, + 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4 +}; + +/* Initial Hash Values: FIPS 180-3 section 5.3.3 */ +static uint32_t SHA256_H0[SHA256HashSize/4] = { + 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, + 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 +}; + +/* + * SHA224Reset + * + * Description: + * This function will initialize the SHA224Context in preparation + * for computing a new SHA224 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + */ +int SHA224Reset(SHA224Context *context) +{ + return SHA224_256Reset(context, SHA224_H0); +} + +/* + * SHA224Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_array[ ]: [in] + * An array of octets representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array. + * + * Returns: + * sha Error Code. + * + */ +int SHA224Input(SHA224Context *context, const uint8_t *message_array, + unsigned int length) +{ + return SHA256Input(context, message_array, length); +} + +/* + * SHA224FinalBits + * + * Description: + * This function will add in any final bits of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_bits: [in] + * The final bits of the message, in the upper portion of the + * byte. (Use 0b###00000 instead of 0b00000### to input the + * three bits ###.) + * length: [in] + * The number of bits in message_bits, between 1 and 7. + * + * Returns: + * sha Error Code. + */ +int SHA224FinalBits(SHA224Context *context, + uint8_t message_bits, unsigned int length) +{ + return SHA256FinalBits(context, message_bits, length); +} + +/* + * SHA224Result + * + * Description: + * This function will return the 224-bit message digest + * into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 27. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + */ +int SHA224Result(SHA224Context *context, + uint8_t Message_Digest[SHA224HashSize]) +{ + return SHA224_256ResultN(context, Message_Digest, SHA224HashSize); +} + +/* + * SHA256Reset + * + * Description: + * This function will initialize the SHA256Context in preparation + * for computing a new SHA256 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + */ +int SHA256Reset(SHA256Context *context) +{ + return SHA224_256Reset(context, SHA256_H0); +} + +/* + * SHA256Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_array[ ]: [in] + * An array of octets representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array. + * + * Returns: + * sha Error Code. + */ +int SHA256Input(SHA256Context *context, const uint8_t *message_array, + unsigned int length) +{ + if (!context) return shaNull; + if (!length) return shaSuccess; + if (!message_array) return shaNull; + if (context->Computed) return context->Corrupted = shaStateError; + if (context->Corrupted) return context->Corrupted; + + while (length--) { + context->Message_Block[context->Message_Block_Index++] = + *message_array; + + if ((SHA224_256AddLength(context, 8) == shaSuccess) && + (context->Message_Block_Index == SHA256_Message_Block_Size)) + SHA224_256ProcessMessageBlock(context); + + message_array++; + } + + return context->Corrupted; + +} + +/* + * SHA256FinalBits + * + * Description: + * This function will add in any final bits of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_bits: [in] + * The final bits of the message, in the upper portion of the + * byte. (Use 0b###00000 instead of 0b00000### to input the + * three bits ###.) + * length: [in] + * The number of bits in message_bits, between 1 and 7. + * + * Returns: + * sha Error Code. + */ +int SHA256FinalBits(SHA256Context *context, + uint8_t message_bits, unsigned int length) +{ + static uint8_t masks[8] = { + /* 0 0b00000000 */ 0x00, /* 1 0b10000000 */ 0x80, + /* 2 0b11000000 */ 0xC0, /* 3 0b11100000 */ 0xE0, + /* 4 0b11110000 */ 0xF0, /* 5 0b11111000 */ 0xF8, + /* 6 0b11111100 */ 0xFC, /* 7 0b11111110 */ 0xFE + }; + static uint8_t markbit[8] = { + /* 0 0b10000000 */ 0x80, /* 1 0b01000000 */ 0x40, + /* 2 0b00100000 */ 0x20, /* 3 0b00010000 */ 0x10, + /* 4 0b00001000 */ 0x08, /* 5 0b00000100 */ 0x04, + /* 6 0b00000010 */ 0x02, /* 7 0b00000001 */ 0x01 + }; + + if (!context) return shaNull; + if (!length) return shaSuccess; + if (context->Corrupted) return context->Corrupted; + if (context->Computed) return context->Corrupted = shaStateError; + if (length >= 8) return context->Corrupted = shaBadParam; + + SHA224_256AddLength(context, length); + SHA224_256Finalize(context, (uint8_t) + ((message_bits & masks[length]) | markbit[length])); + + return context->Corrupted; +} + +/* + * SHA256Result + * + * Description: + * This function will return the 256-bit message digest + * into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 31. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + */ +int SHA256Result(SHA256Context *context, + uint8_t Message_Digest[SHA256HashSize]) +{ + return SHA224_256ResultN(context, Message_Digest, SHA256HashSize); +} + +/* + * SHA224_256Reset + * + * Description: + * This helper function will initialize the SHA256Context in + * preparation for computing a new SHA-224 or SHA-256 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * H0[ ]: [in] + * The initial hash value array to use. + * + * Returns: + * sha Error Code. + */ +static int SHA224_256Reset(SHA256Context *context, uint32_t *H0) +{ + if (!context) return shaNull; + + context->Length_High = context->Length_Low = 0; + context->Message_Block_Index = 0; + + context->Intermediate_Hash[0] = H0[0]; + context->Intermediate_Hash[1] = H0[1]; + context->Intermediate_Hash[2] = H0[2]; + context->Intermediate_Hash[3] = H0[3]; + context->Intermediate_Hash[4] = H0[4]; + context->Intermediate_Hash[5] = H0[5]; + context->Intermediate_Hash[6] = H0[6]; + context->Intermediate_Hash[7] = H0[7]; + + context->Computed = 0; + context->Corrupted = shaSuccess; + + return shaSuccess; +} + +/* + * SHA224_256ProcessMessageBlock + * + * Description: + * This helper function will process the next 512 bits of the + * message stored in the Message_Block array. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * + * Returns: + * Nothing. + * + * Comments: + * Many of the variable names in this code, especially the + * single character names, were used because those were the + * names used in the Secure Hash Standard. + */ +static void SHA224_256ProcessMessageBlock(SHA256Context *context) +{ + /* Constants defined in FIPS 180-3, section 4.2.2 */ + static const uint32_t K[64] = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, + 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, + 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, + 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, + 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, + 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, + 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, + 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, + 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, + 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + }; + int t, t4; /* Loop counter */ + uint32_t temp1, temp2; /* Temporary word value */ + uint32_t W[64]; /* Word sequence */ + uint32_t A, B, C, D, E, F, G, H; /* Word buffers */ + + /* + * Initialize the first 16 words in the array W + */ + for (t = t4 = 0; t < 16; t++, t4 += 4) + W[t] = (((uint32_t)context->Message_Block[t4]) << 24) | + (((uint32_t)context->Message_Block[t4 + 1]) << 16) | + (((uint32_t)context->Message_Block[t4 + 2]) << 8) | + (((uint32_t)context->Message_Block[t4 + 3])); + + for (t = 16; t < 64; t++) + W[t] = SHA256_sigma1(W[t-2]) + W[t-7] + + SHA256_sigma0(W[t-15]) + W[t-16]; + + A = context->Intermediate_Hash[0]; + B = context->Intermediate_Hash[1]; + C = context->Intermediate_Hash[2]; + D = context->Intermediate_Hash[3]; + E = context->Intermediate_Hash[4]; + F = context->Intermediate_Hash[5]; + G = context->Intermediate_Hash[6]; + H = context->Intermediate_Hash[7]; + + for (t = 0; t < 64; t++) { + temp1 = H + SHA256_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t]; + temp2 = SHA256_SIGMA0(A) + SHA_Maj(A,B,C); + H = G; + G = F; + F = E; + E = D + temp1; + D = C; + C = B; + B = A; + A = temp1 + temp2; + } + + context->Intermediate_Hash[0] += A; + context->Intermediate_Hash[1] += B; + context->Intermediate_Hash[2] += C; + context->Intermediate_Hash[3] += D; + context->Intermediate_Hash[4] += E; + context->Intermediate_Hash[5] += F; + context->Intermediate_Hash[6] += G; + context->Intermediate_Hash[7] += H; + + context->Message_Block_Index = 0; +} + +/* + * SHA224_256Finalize + * + * Description: + * This helper function finishes off the digest calculations. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * Pad_Byte: [in] + * The last byte to add to the message block before the 0-padding + * and length. This will contain the last bits of the message + * followed by another single bit. If the message was an + * exact multiple of 8-bits long, Pad_Byte will be 0x80. + * + * Returns: + * sha Error Code. + */ +static void SHA224_256Finalize(SHA256Context *context, + uint8_t Pad_Byte) +{ + int i; + SHA224_256PadMessage(context, Pad_Byte); + /* message may be sensitive, so clear it out */ + for (i = 0; i < SHA256_Message_Block_Size; ++i) + context->Message_Block[i] = 0; + context->Length_High = 0; /* and clear length */ + context->Length_Low = 0; + context->Computed = 1; +} + +/* + * SHA224_256PadMessage + * + * Description: + * According to the standard, the message must be padded to the next + * even multiple of 512 bits. The first padding bit must be a '1'. + * The last 64 bits represent the length of the original message. + * All bits in between should be 0. This helper function will pad + * the message according to those rules by filling the + * Message_Block array accordingly. When it returns, it can be + * assumed that the message digest has been computed. + * + * Parameters: + * context: [in/out] + * The context to pad. + * Pad_Byte: [in] + * The last byte to add to the message block before the 0-padding + * and length. This will contain the last bits of the message + * followed by another single bit. If the message was an + * exact multiple of 8-bits long, Pad_Byte will be 0x80. + * + * Returns: + * Nothing. + */ +static void SHA224_256PadMessage(SHA256Context *context, + uint8_t Pad_Byte) +{ + /* + * Check to see if the current message block is too small to hold + * the initial padding bits and length. If so, we will pad the + * block, process it, and then continue padding into a second + * block. + */ + if (context->Message_Block_Index >= (SHA256_Message_Block_Size-8)) { + context->Message_Block[context->Message_Block_Index++] = Pad_Byte; + while (context->Message_Block_Index < SHA256_Message_Block_Size) + context->Message_Block[context->Message_Block_Index++] = 0; + SHA224_256ProcessMessageBlock(context); + } else + context->Message_Block[context->Message_Block_Index++] = Pad_Byte; + + while (context->Message_Block_Index < (SHA256_Message_Block_Size-8)) + context->Message_Block[context->Message_Block_Index++] = 0; + + /* + * Store the message length as the last 8 octets + */ + context->Message_Block[56] = (uint8_t)(context->Length_High >> 24); + context->Message_Block[57] = (uint8_t)(context->Length_High >> 16); + context->Message_Block[58] = (uint8_t)(context->Length_High >> 8); + context->Message_Block[59] = (uint8_t)(context->Length_High); + context->Message_Block[60] = (uint8_t)(context->Length_Low >> 24); + context->Message_Block[61] = (uint8_t)(context->Length_Low >> 16); + context->Message_Block[62] = (uint8_t)(context->Length_Low >> 8); + context->Message_Block[63] = (uint8_t)(context->Length_Low); + + SHA224_256ProcessMessageBlock(context); +} + +/* + * SHA224_256ResultN + * + * Description: + * This helper function will return the 224-bit or 256-bit message + * digest into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 27/31. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * HashSize: [in] + * The size of the hash, either 28 or 32. + * + * Returns: + * sha Error Code. + */ +static int SHA224_256ResultN(SHA256Context *context, + uint8_t Message_Digest[ ], int HashSize) +{ + int i; + + if (!context) return shaNull; + if (!Message_Digest) return shaNull; + if (context->Corrupted) return context->Corrupted; + + if (!context->Computed) + SHA224_256Finalize(context, 0x80); + + for (i = 0; i < HashSize; ++i) + Message_Digest[i] = (uint8_t) + (context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) )); + + return shaSuccess; +} diff --git a/src/3rdparty/rfc6234/sha384-512.c b/src/3rdparty/rfc6234/sha384-512.c new file mode 100644 index 0000000000..7d9ba3fa52 --- /dev/null +++ b/src/3rdparty/rfc6234/sha384-512.c @@ -0,0 +1,1034 @@ +/************************* sha384-512.c ************************/ +/***************** See RFC 6234 for details. *******************/ +/* Copyright (c) 2011 IETF Trust and the persons identified as */ +/* authors of the code. All rights reserved. */ +/* See sha.h for terms of use and redistribution. */ + +/* + * Description: + * This file implements the Secure Hash Algorithms SHA-384 and + * SHA-512 as defined in the U.S. National Institute of Standards + * and Technology Federal Information Processing Standards + * Publication (FIPS PUB) 180-3 published in October 2008 + * and formerly defined in its predecessors, FIPS PUB 180-1 + * and FIP PUB 180-2. + * + * A combined document showing all algorithms is available at + * http://csrc.nist.gov/publications/fips/ + * fips180-3/fips180-3_final.pdf + * + * The SHA-384 and SHA-512 algorithms produce 384-bit and 512-bit + * message digests for a given data stream. It should take about + * 2**n steps to find a message with the same digest as a given + * message and 2**(n/2) to find any two messages with the same + * digest, when n is the digest size in bits. Therefore, this + * algorithm can serve as a means of providing a + * "fingerprint" for a message. + * + * Portability Issues: + * SHA-384 and SHA-512 are defined in terms of 64-bit "words", + * but if USE_32BIT_ONLY is #defined, this code is implemented in + * terms of 32-bit "words". This code uses (included + * via "sha.h") to define the 64-, 32- and 8-bit unsigned integer + * types. If your C compiler does not support 64-bit unsigned + * integers and you do not #define USE_32BIT_ONLY, this code is + * not appropriate. + * + * Caveats: + * SHA-384 and SHA-512 are designed to work with messages less + * than 2^128 bits long. This implementation uses SHA384/512Input() + * to hash the bits that are a multiple of the size of an 8-bit + * octet, and then optionally uses SHA384/256FinalBits() + * to hash the final few bits of the input. + * + */ + +#include "sha.h" + +#ifdef USE_32BIT_ONLY +/* + * Define 64-bit arithmetic in terms of 32-bit arithmetic. + * Each 64-bit number is represented in a 2-word array. + * All macros are defined such that the result is the last parameter. + */ + +/* + * Define shift, rotate left, and rotate right functions + */ +#define SHA512_SHR(bits, word, ret) ( \ + /* (((uint64_t)((word))) >> (bits)) */ \ + (ret)[0] = (((bits) < 32) && ((bits) >= 0)) ? \ + ((word)[0] >> (bits)) : 0, \ + (ret)[1] = ((bits) > 32) ? ((word)[0] >> ((bits) - 32)) : \ + ((bits) == 32) ? (word)[0] : \ + ((bits) >= 0) ? \ + (((word)[0] << (32 - (bits))) | \ + ((word)[1] >> (bits))) : 0 ) + +#define SHA512_SHL(bits, word, ret) ( \ + /* (((uint64_t)(word)) << (bits)) */ \ + (ret)[0] = ((bits) > 32) ? ((word)[1] << ((bits) - 32)) : \ + ((bits) == 32) ? (word)[1] : \ + ((bits) >= 0) ? \ + (((word)[0] << (bits)) | \ + ((word)[1] >> (32 - (bits)))) : \ + 0, \ + (ret)[1] = (((bits) < 32) && ((bits) >= 0)) ? \ + ((word)[1] << (bits)) : 0 ) + +/* + * Define 64-bit OR + */ +#define SHA512_OR(word1, word2, ret) ( \ + (ret)[0] = (word1)[0] | (word2)[0], \ + (ret)[1] = (word1)[1] | (word2)[1] ) + +/* + * Define 64-bit XOR + */ +#define SHA512_XOR(word1, word2, ret) ( \ + (ret)[0] = (word1)[0] ^ (word2)[0], \ + (ret)[1] = (word1)[1] ^ (word2)[1] ) + +/* + * Define 64-bit AND + */ +#define SHA512_AND(word1, word2, ret) ( \ + (ret)[0] = (word1)[0] & (word2)[0], \ + (ret)[1] = (word1)[1] & (word2)[1] ) + +/* + * Define 64-bit TILDA + */ +#define SHA512_TILDA(word, ret) \ + ( (ret)[0] = ~(word)[0], (ret)[1] = ~(word)[1] ) + +/* + * Define 64-bit ADD + */ +#define SHA512_ADD(word1, word2, ret) ( \ + (ret)[1] = (word1)[1], (ret)[1] += (word2)[1], \ + (ret)[0] = (word1)[0] + (word2)[0] + ((ret)[1] < (word1)[1]) ) + +/* + * Add the 4word value in word2 to word1. + */ +static uint32_t ADDTO4_temp, ADDTO4_temp2; +#define SHA512_ADDTO4(word1, word2) ( \ + ADDTO4_temp = (word1)[3], \ + (word1)[3] += (word2)[3], \ + ADDTO4_temp2 = (word1)[2], \ + (word1)[2] += (word2)[2] + ((word1)[3] < ADDTO4_temp), \ + ADDTO4_temp = (word1)[1], \ + (word1)[1] += (word2)[1] + ((word1)[2] < ADDTO4_temp2), \ + (word1)[0] += (word2)[0] + ((word1)[1] < ADDTO4_temp) ) + +/* + * Add the 2word value in word2 to word1. + */ +static uint32_t ADDTO2_temp; +#define SHA512_ADDTO2(word1, word2) ( \ + ADDTO2_temp = (word1)[1], \ + (word1)[1] += (word2)[1], \ + (word1)[0] += (word2)[0] + ((word1)[1] < ADDTO2_temp) ) + +/* + * SHA rotate ((word >> bits) | (word << (64-bits))) + */ +static uint32_t ROTR_temp1[2], ROTR_temp2[2]; +#define SHA512_ROTR(bits, word, ret) ( \ + SHA512_SHR((bits), (word), ROTR_temp1), \ + SHA512_SHL(64-(bits), (word), ROTR_temp2), \ + SHA512_OR(ROTR_temp1, ROTR_temp2, (ret)) ) + +/* + * Define the SHA SIGMA and sigma macros + * + * SHA512_ROTR(28,word) ^ SHA512_ROTR(34,word) ^ SHA512_ROTR(39,word) + */ +static uint32_t SIGMA0_temp1[2], SIGMA0_temp2[2], + SIGMA0_temp3[2], SIGMA0_temp4[2]; +#define SHA512_SIGMA0(word, ret) ( \ + SHA512_ROTR(28, (word), SIGMA0_temp1), \ + SHA512_ROTR(34, (word), SIGMA0_temp2), \ + SHA512_ROTR(39, (word), SIGMA0_temp3), \ + SHA512_XOR(SIGMA0_temp2, SIGMA0_temp3, SIGMA0_temp4), \ + SHA512_XOR(SIGMA0_temp1, SIGMA0_temp4, (ret)) ) + +/* + * SHA512_ROTR(14,word) ^ SHA512_ROTR(18,word) ^ SHA512_ROTR(41,word) + */ +static uint32_t SIGMA1_temp1[2], SIGMA1_temp2[2], + SIGMA1_temp3[2], SIGMA1_temp4[2]; +#define SHA512_SIGMA1(word, ret) ( \ + SHA512_ROTR(14, (word), SIGMA1_temp1), \ + SHA512_ROTR(18, (word), SIGMA1_temp2), \ + SHA512_ROTR(41, (word), SIGMA1_temp3), \ + SHA512_XOR(SIGMA1_temp2, SIGMA1_temp3, SIGMA1_temp4), \ + SHA512_XOR(SIGMA1_temp1, SIGMA1_temp4, (ret)) ) + +/* + * (SHA512_ROTR( 1,word) ^ SHA512_ROTR( 8,word) ^ SHA512_SHR( 7,word)) + */ +static uint32_t sigma0_temp1[2], sigma0_temp2[2], + sigma0_temp3[2], sigma0_temp4[2]; +#define SHA512_sigma0(word, ret) ( \ + SHA512_ROTR( 1, (word), sigma0_temp1), \ + SHA512_ROTR( 8, (word), sigma0_temp2), \ + SHA512_SHR( 7, (word), sigma0_temp3), \ + SHA512_XOR(sigma0_temp2, sigma0_temp3, sigma0_temp4), \ + SHA512_XOR(sigma0_temp1, sigma0_temp4, (ret)) ) + +/* + * (SHA512_ROTR(19,word) ^ SHA512_ROTR(61,word) ^ SHA512_SHR( 6,word)) + */ +static uint32_t sigma1_temp1[2], sigma1_temp2[2], + sigma1_temp3[2], sigma1_temp4[2]; +#define SHA512_sigma1(word, ret) ( \ + SHA512_ROTR(19, (word), sigma1_temp1), \ + SHA512_ROTR(61, (word), sigma1_temp2), \ + SHA512_SHR( 6, (word), sigma1_temp3), \ + SHA512_XOR(sigma1_temp2, sigma1_temp3, sigma1_temp4), \ + SHA512_XOR(sigma1_temp1, sigma1_temp4, (ret)) ) + +#ifndef USE_MODIFIED_MACROS +/* + * These definitions are the ones used in FIPS 180-3, section 4.1.3 + * Ch(x,y,z) ((x & y) ^ (~x & z)) + */ +static uint32_t Ch_temp1[2], Ch_temp2[2], Ch_temp3[2]; +#define SHA_Ch(x, y, z, ret) ( \ + SHA512_AND(x, y, Ch_temp1), \ + SHA512_TILDA(x, Ch_temp2), \ + SHA512_AND(Ch_temp2, z, Ch_temp3), \ + SHA512_XOR(Ch_temp1, Ch_temp3, (ret)) ) + +/* + * Maj(x,y,z) (((x)&(y)) ^ ((x)&(z)) ^ ((y)&(z))) + */ +static uint32_t Maj_temp1[2], Maj_temp2[2], + Maj_temp3[2], Maj_temp4[2]; +#define SHA_Maj(x, y, z, ret) ( \ + SHA512_AND(x, y, Maj_temp1), \ + SHA512_AND(x, z, Maj_temp2), \ + SHA512_AND(y, z, Maj_temp3), \ + SHA512_XOR(Maj_temp2, Maj_temp3, Maj_temp4), \ + SHA512_XOR(Maj_temp1, Maj_temp4, (ret)) ) +#else /* !USE_MODIFIED_MACROS */ +/* + * These definitions are potentially faster equivalents for the ones + * used in FIPS 180-3, section 4.1.3. + * ((x & y) ^ (~x & z)) becomes + * ((x & (y ^ z)) ^ z) + */ +#define SHA_Ch(x, y, z, ret) ( \ + (ret)[0] = (((x)[0] & ((y)[0] ^ (z)[0])) ^ (z)[0]), \ + (ret)[1] = (((x)[1] & ((y)[1] ^ (z)[1])) ^ (z)[1]) ) + +/* + * ((x & y) ^ (x & z) ^ (y & z)) becomes + * ((x & (y | z)) | (y & z)) + */ +#define SHA_Maj(x, y, z, ret) ( \ + ret[0] = (((x)[0] & ((y)[0] | (z)[0])) | ((y)[0] & (z)[0])), \ + ret[1] = (((x)[1] & ((y)[1] | (z)[1])) | ((y)[1] & (z)[1])) ) +#endif /* USE_MODIFIED_MACROS */ + +/* + * Add "length" to the length. + * Set Corrupted when overflow has occurred. + */ +static uint32_t addTemp[4] = { 0, 0, 0, 0 }; +#define SHA384_512AddLength(context, length) ( \ + addTemp[3] = (length), SHA512_ADDTO4((context)->Length, addTemp), \ + (context)->Corrupted = (((context)->Length[3] < (length)) && \ + ((context)->Length[2] == 0) && ((context)->Length[1] == 0) && \ + ((context)->Length[0] == 0)) ? shaInputTooLong : \ + (context)->Corrupted ) + +/* Local Function Prototypes */ +static int SHA384_512Reset(SHA512Context *context, + uint32_t H0[SHA512HashSize/4]); +static void SHA384_512ProcessMessageBlock(SHA512Context *context); +static void SHA384_512Finalize(SHA512Context *context, + uint8_t Pad_Byte); +static void SHA384_512PadMessage(SHA512Context *context, + uint8_t Pad_Byte); +static int SHA384_512ResultN( SHA512Context *context, + uint8_t Message_Digest[ ], int HashSize); + +/* Initial Hash Values: FIPS 180-3 sections 5.3.4 and 5.3.5 */ +static uint32_t SHA384_H0[SHA512HashSize/4] = { + 0xCBBB9D5D, 0xC1059ED8, 0x629A292A, 0x367CD507, 0x9159015A, + 0x3070DD17, 0x152FECD8, 0xF70E5939, 0x67332667, 0xFFC00B31, + 0x8EB44A87, 0x68581511, 0xDB0C2E0D, 0x64F98FA7, 0x47B5481D, + 0xBEFA4FA4 +}; +static uint32_t SHA512_H0[SHA512HashSize/4] = { + 0x6A09E667, 0xF3BCC908, 0xBB67AE85, 0x84CAA73B, 0x3C6EF372, + 0xFE94F82B, 0xA54FF53A, 0x5F1D36F1, 0x510E527F, 0xADE682D1, + 0x9B05688C, 0x2B3E6C1F, 0x1F83D9AB, 0xFB41BD6B, 0x5BE0CD19, + 0x137E2179 +}; + +#else /* !USE_32BIT_ONLY */ + +#include "sha-private.h" + +/* Define the SHA shift, rotate left and rotate right macros */ +#define SHA512_SHR(bits,word) (((uint64_t)(word)) >> (bits)) +#define SHA512_ROTR(bits,word) ((((uint64_t)(word)) >> (bits)) | \ + (((uint64_t)(word)) << (64-(bits)))) + +/* + * Define the SHA SIGMA and sigma macros + * + * SHA512_ROTR(28,word) ^ SHA512_ROTR(34,word) ^ SHA512_ROTR(39,word) + */ +#define SHA512_SIGMA0(word) \ + (SHA512_ROTR(28,word) ^ SHA512_ROTR(34,word) ^ SHA512_ROTR(39,word)) +#define SHA512_SIGMA1(word) \ + (SHA512_ROTR(14,word) ^ SHA512_ROTR(18,word) ^ SHA512_ROTR(41,word)) +#define SHA512_sigma0(word) \ + (SHA512_ROTR( 1,word) ^ SHA512_ROTR( 8,word) ^ SHA512_SHR( 7,word)) +#define SHA512_sigma1(word) \ + (SHA512_ROTR(19,word) ^ SHA512_ROTR(61,word) ^ SHA512_SHR( 6,word)) + +/* + * Add "length" to the length. + * Set Corrupted when overflow has occurred. + */ +/* addTemp commented out by Nokia, static variables are not thread-safe */ +/* static uint64_t addTemp; */ +/* 'M' appended to Macro name by Nokia */ +#define SHA384_512AddLengthM(context, length) \ + (addTemp = context->Length_Low, context->Corrupted = \ + ((context->Length_Low += length) < addTemp) && \ + (++context->Length_High == 0) ? shaInputTooLong : \ + (context)->Corrupted) + +/* Local Function Prototypes */ +static int SHA384_512Reset(SHA512Context *context, + uint64_t H0[SHA512HashSize/8]); +static void SHA384_512ProcessMessageBlock(SHA512Context *context); +static void SHA384_512Finalize(SHA512Context *context, + uint8_t Pad_Byte); +static void SHA384_512PadMessage(SHA512Context *context, + uint8_t Pad_Byte); +static int SHA384_512ResultN(SHA512Context *context, + uint8_t Message_Digest[ ], int HashSize); + +/* Initial Hash Values: FIPS 180-3 sections 5.3.4 and 5.3.5 */ +static uint64_t SHA384_H0[ ] = { + 0xCBBB9D5DC1059ED8ll, 0x629A292A367CD507ll, 0x9159015A3070DD17ll, + 0x152FECD8F70E5939ll, 0x67332667FFC00B31ll, 0x8EB44A8768581511ll, + 0xDB0C2E0D64F98FA7ll, 0x47B5481DBEFA4FA4ll +}; +static uint64_t SHA512_H0[ ] = { + 0x6A09E667F3BCC908ll, 0xBB67AE8584CAA73Bll, 0x3C6EF372FE94F82Bll, + 0xA54FF53A5F1D36F1ll, 0x510E527FADE682D1ll, 0x9B05688C2B3E6C1Fll, + 0x1F83D9ABFB41BD6Bll, 0x5BE0CD19137E2179ll +}; + +#endif /* USE_32BIT_ONLY */ + +/* + * SHA384Reset + * + * Description: + * This function will initialize the SHA384Context in preparation + * for computing a new SHA384 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + * + */ +int SHA384Reset(SHA384Context *context) +{ + return SHA384_512Reset(context, SHA384_H0); +} + +/* + * SHA384Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_array[ ]: [in] + * An array of octets representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array. + * + * Returns: + * sha Error Code. + * + */ +int SHA384Input(SHA384Context *context, + const uint8_t *message_array, unsigned int length) +{ + return SHA512Input(context, message_array, length); +} + +/* + * SHA384FinalBits + * + * Description: + * This function will add in any final bits of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_bits: [in] + * The final bits of the message, in the upper portion of the + * byte. (Use 0b###00000 instead of 0b00000### to input the + * three bits ###.) + * length: [in] + * The number of bits in message_bits, between 1 and 7. + * + * Returns: + * sha Error Code. + * + */ +int SHA384FinalBits(SHA384Context *context, + uint8_t message_bits, unsigned int length) +{ + return SHA512FinalBits(context, message_bits, length); +} + +/* + * SHA384Result + * + * Description: + * This function will return the 384-bit message digest + * into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 47. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + * + */ +int SHA384Result(SHA384Context *context, + uint8_t Message_Digest[SHA384HashSize]) +{ + return SHA384_512ResultN(context, Message_Digest, SHA384HashSize); +} + +/* + * SHA512Reset + * + * Description: + * This function will initialize the SHA512Context in preparation + * for computing a new SHA512 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + * + */ +int SHA512Reset(SHA512Context *context) +{ + return SHA384_512Reset(context, SHA512_H0); +} + +/* + * SHA512Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_array[ ]: [in] + * An array of octets representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array. + * + * Returns: + * sha Error Code. + * + */ +int SHA512Input(SHA512Context *context, + const uint8_t *message_array, + unsigned int length) +{ + if (!context) return shaNull; + if (!length) return shaSuccess; + if (!message_array) return shaNull; + if (context->Computed) return context->Corrupted = shaStateError; + if (context->Corrupted) return context->Corrupted; + + while (length--) { + context->Message_Block[context->Message_Block_Index++] = + *message_array; + + if ((SHA384_512AddLength(context, 8) == shaSuccess) && + (context->Message_Block_Index == SHA512_Message_Block_Size)) + SHA384_512ProcessMessageBlock(context); + + message_array++; + } + + return context->Corrupted; +} + +/* + * SHA512FinalBits + * + * Description: + * This function will add in any final bits of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_bits: [in] + * The final bits of the message, in the upper portion of the + * byte. (Use 0b###00000 instead of 0b00000### to input the + * three bits ###.) + * length: [in] + * The number of bits in message_bits, between 1 and 7. + * + * Returns: + * sha Error Code. + * + */ +int SHA512FinalBits(SHA512Context *context, + uint8_t message_bits, unsigned int length) +{ + static uint8_t masks[8] = { + /* 0 0b00000000 */ 0x00, /* 1 0b10000000 */ 0x80, + /* 2 0b11000000 */ 0xC0, /* 3 0b11100000 */ 0xE0, + /* 4 0b11110000 */ 0xF0, /* 5 0b11111000 */ 0xF8, + /* 6 0b11111100 */ 0xFC, /* 7 0b11111110 */ 0xFE + }; + static uint8_t markbit[8] = { + /* 0 0b10000000 */ 0x80, /* 1 0b01000000 */ 0x40, + /* 2 0b00100000 */ 0x20, /* 3 0b00010000 */ 0x10, + /* 4 0b00001000 */ 0x08, /* 5 0b00000100 */ 0x04, + /* 6 0b00000010 */ 0x02, /* 7 0b00000001 */ 0x01 + }; + + if (!context) return shaNull; + if (!length) return shaSuccess; + if (context->Corrupted) return context->Corrupted; + if (context->Computed) return context->Corrupted = shaStateError; + if (length >= 8) return context->Corrupted = shaBadParam; + + SHA384_512AddLength(context, length); + SHA384_512Finalize(context, (uint8_t) + ((message_bits & masks[length]) | markbit[length])); + + return context->Corrupted; +} + +/* + * SHA512Result + * + * Description: + * This function will return the 512-bit message digest + * into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 63. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + * + */ +int SHA512Result(SHA512Context *context, + uint8_t Message_Digest[SHA512HashSize]) +{ + return SHA384_512ResultN(context, Message_Digest, SHA512HashSize); +} + +/* + * SHA384_512Reset + * + * Description: + * This helper function will initialize the SHA512Context in + * preparation for computing a new SHA384 or SHA512 message + * digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * H0[ ]: [in] + * The initial hash value array to use. + * + * Returns: + * sha Error Code. + * + */ +#ifdef USE_32BIT_ONLY +static int SHA384_512Reset(SHA512Context *context, + uint32_t H0[SHA512HashSize/4]) +#else /* !USE_32BIT_ONLY */ +static int SHA384_512Reset(SHA512Context *context, + uint64_t H0[SHA512HashSize/8]) +#endif /* USE_32BIT_ONLY */ +{ + int i; + if (!context) return shaNull; + + context->Message_Block_Index = 0; + +#ifdef USE_32BIT_ONLY + context->Length[0] = context->Length[1] = + context->Length[2] = context->Length[3] = 0; + + for (i = 0; i < SHA512HashSize/4; i++) + context->Intermediate_Hash[i] = H0[i]; +#else /* !USE_32BIT_ONLY */ + context->Length_High = context->Length_Low = 0; + + for (i = 0; i < SHA512HashSize/8; i++) + context->Intermediate_Hash[i] = H0[i]; +#endif /* USE_32BIT_ONLY */ + + context->Computed = 0; + context->Corrupted = shaSuccess; + + return shaSuccess; +} + +/* + * SHA384_512ProcessMessageBlock + * + * Description: + * This helper function will process the next 1024 bits of the + * message stored in the Message_Block array. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * + * Returns: + * Nothing. + * + * Comments: + * Many of the variable names in this code, especially the + * single character names, were used because those were the + * names used in the Secure Hash Standard. + * + * + */ +static void SHA384_512ProcessMessageBlock(SHA512Context *context) +{ +#ifdef USE_32BIT_ONLY + /* Constants defined in FIPS 180-3, section 4.2.3 */ + static const uint32_t K[80*2] = { + 0x428A2F98, 0xD728AE22, 0x71374491, 0x23EF65CD, 0xB5C0FBCF, + 0xEC4D3B2F, 0xE9B5DBA5, 0x8189DBBC, 0x3956C25B, 0xF348B538, + 0x59F111F1, 0xB605D019, 0x923F82A4, 0xAF194F9B, 0xAB1C5ED5, + 0xDA6D8118, 0xD807AA98, 0xA3030242, 0x12835B01, 0x45706FBE, + 0x243185BE, 0x4EE4B28C, 0x550C7DC3, 0xD5FFB4E2, 0x72BE5D74, + 0xF27B896F, 0x80DEB1FE, 0x3B1696B1, 0x9BDC06A7, 0x25C71235, + 0xC19BF174, 0xCF692694, 0xE49B69C1, 0x9EF14AD2, 0xEFBE4786, + 0x384F25E3, 0x0FC19DC6, 0x8B8CD5B5, 0x240CA1CC, 0x77AC9C65, + 0x2DE92C6F, 0x592B0275, 0x4A7484AA, 0x6EA6E483, 0x5CB0A9DC, + 0xBD41FBD4, 0x76F988DA, 0x831153B5, 0x983E5152, 0xEE66DFAB, + 0xA831C66D, 0x2DB43210, 0xB00327C8, 0x98FB213F, 0xBF597FC7, + 0xBEEF0EE4, 0xC6E00BF3, 0x3DA88FC2, 0xD5A79147, 0x930AA725, + 0x06CA6351, 0xE003826F, 0x14292967, 0x0A0E6E70, 0x27B70A85, + 0x46D22FFC, 0x2E1B2138, 0x5C26C926, 0x4D2C6DFC, 0x5AC42AED, + 0x53380D13, 0x9D95B3DF, 0x650A7354, 0x8BAF63DE, 0x766A0ABB, + 0x3C77B2A8, 0x81C2C92E, 0x47EDAEE6, 0x92722C85, 0x1482353B, + 0xA2BFE8A1, 0x4CF10364, 0xA81A664B, 0xBC423001, 0xC24B8B70, + 0xD0F89791, 0xC76C51A3, 0x0654BE30, 0xD192E819, 0xD6EF5218, + 0xD6990624, 0x5565A910, 0xF40E3585, 0x5771202A, 0x106AA070, + 0x32BBD1B8, 0x19A4C116, 0xB8D2D0C8, 0x1E376C08, 0x5141AB53, + 0x2748774C, 0xDF8EEB99, 0x34B0BCB5, 0xE19B48A8, 0x391C0CB3, + 0xC5C95A63, 0x4ED8AA4A, 0xE3418ACB, 0x5B9CCA4F, 0x7763E373, + 0x682E6FF3, 0xD6B2B8A3, 0x748F82EE, 0x5DEFB2FC, 0x78A5636F, + 0x43172F60, 0x84C87814, 0xA1F0AB72, 0x8CC70208, 0x1A6439EC, + 0x90BEFFFA, 0x23631E28, 0xA4506CEB, 0xDE82BDE9, 0xBEF9A3F7, + 0xB2C67915, 0xC67178F2, 0xE372532B, 0xCA273ECE, 0xEA26619C, + 0xD186B8C7, 0x21C0C207, 0xEADA7DD6, 0xCDE0EB1E, 0xF57D4F7F, + 0xEE6ED178, 0x06F067AA, 0x72176FBA, 0x0A637DC5, 0xA2C898A6, + 0x113F9804, 0xBEF90DAE, 0x1B710B35, 0x131C471B, 0x28DB77F5, + 0x23047D84, 0x32CAAB7B, 0x40C72493, 0x3C9EBE0A, 0x15C9BEBC, + 0x431D67C4, 0x9C100D4C, 0x4CC5D4BE, 0xCB3E42B6, 0x597F299C, + 0xFC657E2A, 0x5FCB6FAB, 0x3AD6FAEC, 0x6C44198C, 0x4A475817 + }; + int t, t2, t8; /* Loop counter */ + uint32_t temp1[2], temp2[2], /* Temporary word values */ + temp3[2], temp4[2], temp5[2]; + uint32_t W[2*80]; /* Word sequence */ + uint32_t A[2], B[2], C[2], D[2], /* Word buffers */ + E[2], F[2], G[2], H[2]; + + /* Initialize the first 16 words in the array W */ + for (t = t2 = t8 = 0; t < 16; t++, t8 += 8) { + W[t2++] = ((((uint32_t)context->Message_Block[t8 ])) << 24) | + ((((uint32_t)context->Message_Block[t8 + 1])) << 16) | + ((((uint32_t)context->Message_Block[t8 + 2])) << 8) | + ((((uint32_t)context->Message_Block[t8 + 3]))); + W[t2++] = ((((uint32_t)context->Message_Block[t8 + 4])) << 24) | + ((((uint32_t)context->Message_Block[t8 + 5])) << 16) | + ((((uint32_t)context->Message_Block[t8 + 6])) << 8) | + ((((uint32_t)context->Message_Block[t8 + 7]))); + } + + for (t = 16; t < 80; t++, t2 += 2) { + /* W[t] = SHA512_sigma1(W[t-2]) + W[t-7] + + SHA512_sigma0(W[t-15]) + W[t-16]; */ + uint32_t *Wt2 = &W[t2-2*2]; + uint32_t *Wt7 = &W[t2-7*2]; + uint32_t *Wt15 = &W[t2-15*2]; + uint32_t *Wt16 = &W[t2-16*2]; + SHA512_sigma1(Wt2, temp1); + SHA512_ADD(temp1, Wt7, temp2); + SHA512_sigma0(Wt15, temp1); + SHA512_ADD(temp1, Wt16, temp3); + SHA512_ADD(temp2, temp3, &W[t2]); + } + + A[0] = context->Intermediate_Hash[0]; + A[1] = context->Intermediate_Hash[1]; + B[0] = context->Intermediate_Hash[2]; + B[1] = context->Intermediate_Hash[3]; + C[0] = context->Intermediate_Hash[4]; + C[1] = context->Intermediate_Hash[5]; + D[0] = context->Intermediate_Hash[6]; + D[1] = context->Intermediate_Hash[7]; + E[0] = context->Intermediate_Hash[8]; + E[1] = context->Intermediate_Hash[9]; + F[0] = context->Intermediate_Hash[10]; + F[1] = context->Intermediate_Hash[11]; + G[0] = context->Intermediate_Hash[12]; + G[1] = context->Intermediate_Hash[13]; + H[0] = context->Intermediate_Hash[14]; + H[1] = context->Intermediate_Hash[15]; + + for (t = t2 = 0; t < 80; t++, t2 += 2) { + /* + * temp1 = H + SHA512_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t]; + */ + SHA512_SIGMA1(E,temp1); + SHA512_ADD(H, temp1, temp2); + SHA_Ch(E,F,G,temp3); + SHA512_ADD(temp2, temp3, temp4); + SHA512_ADD(&K[t2], &W[t2], temp5); + SHA512_ADD(temp4, temp5, temp1); + /* + * temp2 = SHA512_SIGMA0(A) + SHA_Maj(A,B,C); + */ + SHA512_SIGMA0(A,temp3); + SHA_Maj(A,B,C,temp4); + SHA512_ADD(temp3, temp4, temp2); + H[0] = G[0]; H[1] = G[1]; + G[0] = F[0]; G[1] = F[1]; + F[0] = E[0]; F[1] = E[1]; + SHA512_ADD(D, temp1, E); + D[0] = C[0]; D[1] = C[1]; + C[0] = B[0]; C[1] = B[1]; + B[0] = A[0]; B[1] = A[1]; + SHA512_ADD(temp1, temp2, A); + } + + SHA512_ADDTO2(&context->Intermediate_Hash[0], A); + SHA512_ADDTO2(&context->Intermediate_Hash[2], B); + SHA512_ADDTO2(&context->Intermediate_Hash[4], C); + SHA512_ADDTO2(&context->Intermediate_Hash[6], D); + SHA512_ADDTO2(&context->Intermediate_Hash[8], E); + SHA512_ADDTO2(&context->Intermediate_Hash[10], F); + SHA512_ADDTO2(&context->Intermediate_Hash[12], G); + SHA512_ADDTO2(&context->Intermediate_Hash[14], H); + +#else /* !USE_32BIT_ONLY */ + /* Constants defined in FIPS 180-3, section 4.2.3 */ + static const uint64_t K[80] = { + 0x428A2F98D728AE22ll, 0x7137449123EF65CDll, 0xB5C0FBCFEC4D3B2Fll, + 0xE9B5DBA58189DBBCll, 0x3956C25BF348B538ll, 0x59F111F1B605D019ll, + 0x923F82A4AF194F9Bll, 0xAB1C5ED5DA6D8118ll, 0xD807AA98A3030242ll, + 0x12835B0145706FBEll, 0x243185BE4EE4B28Cll, 0x550C7DC3D5FFB4E2ll, + 0x72BE5D74F27B896Fll, 0x80DEB1FE3B1696B1ll, 0x9BDC06A725C71235ll, + 0xC19BF174CF692694ll, 0xE49B69C19EF14AD2ll, 0xEFBE4786384F25E3ll, + 0x0FC19DC68B8CD5B5ll, 0x240CA1CC77AC9C65ll, 0x2DE92C6F592B0275ll, + 0x4A7484AA6EA6E483ll, 0x5CB0A9DCBD41FBD4ll, 0x76F988DA831153B5ll, + 0x983E5152EE66DFABll, 0xA831C66D2DB43210ll, 0xB00327C898FB213Fll, + 0xBF597FC7BEEF0EE4ll, 0xC6E00BF33DA88FC2ll, 0xD5A79147930AA725ll, + 0x06CA6351E003826Fll, 0x142929670A0E6E70ll, 0x27B70A8546D22FFCll, + 0x2E1B21385C26C926ll, 0x4D2C6DFC5AC42AEDll, 0x53380D139D95B3DFll, + 0x650A73548BAF63DEll, 0x766A0ABB3C77B2A8ll, 0x81C2C92E47EDAEE6ll, + 0x92722C851482353Bll, 0xA2BFE8A14CF10364ll, 0xA81A664BBC423001ll, + 0xC24B8B70D0F89791ll, 0xC76C51A30654BE30ll, 0xD192E819D6EF5218ll, + 0xD69906245565A910ll, 0xF40E35855771202All, 0x106AA07032BBD1B8ll, + 0x19A4C116B8D2D0C8ll, 0x1E376C085141AB53ll, 0x2748774CDF8EEB99ll, + 0x34B0BCB5E19B48A8ll, 0x391C0CB3C5C95A63ll, 0x4ED8AA4AE3418ACBll, + 0x5B9CCA4F7763E373ll, 0x682E6FF3D6B2B8A3ll, 0x748F82EE5DEFB2FCll, + 0x78A5636F43172F60ll, 0x84C87814A1F0AB72ll, 0x8CC702081A6439ECll, + 0x90BEFFFA23631E28ll, 0xA4506CEBDE82BDE9ll, 0xBEF9A3F7B2C67915ll, + 0xC67178F2E372532Bll, 0xCA273ECEEA26619Cll, 0xD186B8C721C0C207ll, + 0xEADA7DD6CDE0EB1Ell, 0xF57D4F7FEE6ED178ll, 0x06F067AA72176FBAll, + 0x0A637DC5A2C898A6ll, 0x113F9804BEF90DAEll, 0x1B710B35131C471Bll, + 0x28DB77F523047D84ll, 0x32CAAB7B40C72493ll, 0x3C9EBE0A15C9BEBCll, + 0x431D67C49C100D4Cll, 0x4CC5D4BECB3E42B6ll, 0x597F299CFC657E2All, + 0x5FCB6FAB3AD6FAECll, 0x6C44198C4A475817ll + }; + int t, t8; /* Loop counter */ + uint64_t temp1, temp2; /* Temporary word value */ + uint64_t W[80]; /* Word sequence */ + uint64_t A, B, C, D, E, F, G, H; /* Word buffers */ + + /* + * Initialize the first 16 words in the array W + */ + for (t = t8 = 0; t < 16; t++, t8 += 8) + W[t] = ((uint64_t)(context->Message_Block[t8 ]) << 56) | + ((uint64_t)(context->Message_Block[t8 + 1]) << 48) | + ((uint64_t)(context->Message_Block[t8 + 2]) << 40) | + ((uint64_t)(context->Message_Block[t8 + 3]) << 32) | + ((uint64_t)(context->Message_Block[t8 + 4]) << 24) | + ((uint64_t)(context->Message_Block[t8 + 5]) << 16) | + ((uint64_t)(context->Message_Block[t8 + 6]) << 8) | + ((uint64_t)(context->Message_Block[t8 + 7])); + + for (t = 16; t < 80; t++) + W[t] = SHA512_sigma1(W[t-2]) + W[t-7] + + SHA512_sigma0(W[t-15]) + W[t-16]; + A = context->Intermediate_Hash[0]; + B = context->Intermediate_Hash[1]; + C = context->Intermediate_Hash[2]; + D = context->Intermediate_Hash[3]; + E = context->Intermediate_Hash[4]; + F = context->Intermediate_Hash[5]; + G = context->Intermediate_Hash[6]; + H = context->Intermediate_Hash[7]; + + for (t = 0; t < 80; t++) { + temp1 = H + SHA512_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t]; + temp2 = SHA512_SIGMA0(A) + SHA_Maj(A,B,C); + H = G; + G = F; + F = E; + E = D + temp1; + D = C; + C = B; + B = A; + A = temp1 + temp2; + } + + context->Intermediate_Hash[0] += A; + context->Intermediate_Hash[1] += B; + context->Intermediate_Hash[2] += C; + context->Intermediate_Hash[3] += D; + context->Intermediate_Hash[4] += E; + context->Intermediate_Hash[5] += F; + context->Intermediate_Hash[6] += G; + context->Intermediate_Hash[7] += H; +#endif /* USE_32BIT_ONLY */ + + context->Message_Block_Index = 0; +} + +/* + * SHA384_512Finalize + * + * Description: + * This helper function finishes off the digest calculations. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * Pad_Byte: [in] + * The last byte to add to the message block before the 0-padding + * and length. This will contain the last bits of the message + * followed by another single bit. If the message was an + * exact multiple of 8-bits long, Pad_Byte will be 0x80. + * + * Returns: + * sha Error Code. + * + */ +static void SHA384_512Finalize(SHA512Context *context, + uint8_t Pad_Byte) +{ + int_least16_t i; + SHA384_512PadMessage(context, Pad_Byte); + /* message may be sensitive, clear it out */ + for (i = 0; i < SHA512_Message_Block_Size; ++i) + context->Message_Block[i] = 0; +#ifdef USE_32BIT_ONLY /* and clear length */ + context->Length[0] = context->Length[1] = 0; + context->Length[2] = context->Length[3] = 0; +#else /* !USE_32BIT_ONLY */ + context->Length_High = context->Length_Low = 0; +#endif /* USE_32BIT_ONLY */ + context->Computed = 1; +} + +/* + * SHA384_512PadMessage + * + * Description: + * According to the standard, the message must be padded to the next + * even multiple of 1024 bits. The first padding bit must be a '1'. + * The last 128 bits represent the length of the original message. + * All bits in between should be 0. This helper function will + * pad the message according to those rules by filling the + * Message_Block array accordingly. When it returns, it can be + * assumed that the message digest has been computed. + * + * Parameters: + * context: [in/out] + * The context to pad. + * Pad_Byte: [in] + * The last byte to add to the message block before the 0-padding + * and length. This will contain the last bits of the message + * followed by another single bit. If the message was an + * exact multiple of 8-bits long, Pad_Byte will be 0x80. + * + * Returns: + * Nothing. + * + */ +static void SHA384_512PadMessage(SHA512Context *context, + uint8_t Pad_Byte) +{ + /* + * Check to see if the current message block is too small to hold + * the initial padding bits and length. If so, we will pad the + * block, process it, and then continue padding into a second + * block. + */ + if (context->Message_Block_Index >= (SHA512_Message_Block_Size-16)) { + context->Message_Block[context->Message_Block_Index++] = Pad_Byte; + while (context->Message_Block_Index < SHA512_Message_Block_Size) + context->Message_Block[context->Message_Block_Index++] = 0; + + SHA384_512ProcessMessageBlock(context); + } else + context->Message_Block[context->Message_Block_Index++] = Pad_Byte; + + while (context->Message_Block_Index < (SHA512_Message_Block_Size-16)) + context->Message_Block[context->Message_Block_Index++] = 0; + + /* + * Store the message length as the last 16 octets + */ +#ifdef USE_32BIT_ONLY + context->Message_Block[112] = (uint8_t)(context->Length[0] >> 24); + context->Message_Block[113] = (uint8_t)(context->Length[0] >> 16); + context->Message_Block[114] = (uint8_t)(context->Length[0] >> 8); + context->Message_Block[115] = (uint8_t)(context->Length[0]); + context->Message_Block[116] = (uint8_t)(context->Length[1] >> 24); + context->Message_Block[117] = (uint8_t)(context->Length[1] >> 16); + context->Message_Block[118] = (uint8_t)(context->Length[1] >> 8); + context->Message_Block[119] = (uint8_t)(context->Length[1]); + + context->Message_Block[120] = (uint8_t)(context->Length[2] >> 24); + context->Message_Block[121] = (uint8_t)(context->Length[2] >> 16); + context->Message_Block[122] = (uint8_t)(context->Length[2] >> 8); + context->Message_Block[123] = (uint8_t)(context->Length[2]); + context->Message_Block[124] = (uint8_t)(context->Length[3] >> 24); + context->Message_Block[125] = (uint8_t)(context->Length[3] >> 16); + context->Message_Block[126] = (uint8_t)(context->Length[3] >> 8); + context->Message_Block[127] = (uint8_t)(context->Length[3]); +#else /* !USE_32BIT_ONLY */ + context->Message_Block[112] = (uint8_t)(context->Length_High >> 56); + context->Message_Block[113] = (uint8_t)(context->Length_High >> 48); + context->Message_Block[114] = (uint8_t)(context->Length_High >> 40); + context->Message_Block[115] = (uint8_t)(context->Length_High >> 32); + context->Message_Block[116] = (uint8_t)(context->Length_High >> 24); + context->Message_Block[117] = (uint8_t)(context->Length_High >> 16); + context->Message_Block[118] = (uint8_t)(context->Length_High >> 8); + context->Message_Block[119] = (uint8_t)(context->Length_High); + + context->Message_Block[120] = (uint8_t)(context->Length_Low >> 56); + context->Message_Block[121] = (uint8_t)(context->Length_Low >> 48); + context->Message_Block[122] = (uint8_t)(context->Length_Low >> 40); + context->Message_Block[123] = (uint8_t)(context->Length_Low >> 32); + context->Message_Block[124] = (uint8_t)(context->Length_Low >> 24); + context->Message_Block[125] = (uint8_t)(context->Length_Low >> 16); + context->Message_Block[126] = (uint8_t)(context->Length_Low >> 8); + context->Message_Block[127] = (uint8_t)(context->Length_Low); +#endif /* USE_32BIT_ONLY */ + + SHA384_512ProcessMessageBlock(context); +} + +/* + * SHA384_512ResultN + * + * Description: + * This helper function will return the 384-bit or 512-bit message + * digest into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 47/63. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * HashSize: [in] + * The size of the hash, either 48 or 64. + * + * Returns: + * sha Error Code. + * + */ +static int SHA384_512ResultN(SHA512Context *context, + uint8_t Message_Digest[ ], int HashSize) +{ + int i; +#ifdef USE_32BIT_ONLY + int i2; +#endif /* USE_32BIT_ONLY */ + + if (!context) return shaNull; + if (!Message_Digest) return shaNull; + if (context->Corrupted) return context->Corrupted; + + if (!context->Computed) + SHA384_512Finalize(context, 0x80); + +#ifdef USE_32BIT_ONLY + for (i = i2 = 0; i < HashSize; ) { + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2]>>24); + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2]>>16); + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2]>>8); + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2++]); + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2]>>24); + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2]>>16); + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2]>>8); + Message_Digest[i++]=(uint8_t)(context->Intermediate_Hash[i2++]); + } +#else /* !USE_32BIT_ONLY */ + for (i = 0; i < HashSize; ++i) + Message_Digest[i] = (uint8_t) + (context->Intermediate_Hash[i>>3] >> 8 * ( 7 - ( i % 8 ) )); +#endif /* USE_32BIT_ONLY */ + + return shaSuccess; +} diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 164660f818..9c27af032f 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -46,8 +46,42 @@ #include "../../3rdparty/md4/md4.h" #include "../../3rdparty/md4/md4.cpp" #include "../../3rdparty/sha1/sha1.cpp" + +/* + These 2 functions replace macros of the same name in sha224-256.c and + sha384-512.c. Originally, these macros relied on a global static 'addTemp' + variable. We do not want this for 2 reasons: + + 1. since we are including the sources directly, the declaration of the 2 conflict + + 2. static variables are not thread-safe, we do not want multiple threads + computing a hash to corrupt one another +*/ +// Header from rfc6234 without modifications +#include "../../3rdparty/rfc6234/sha.h" +static int SHA224_256AddLength(SHA256Context *context, unsigned int length); +static int SHA384_512AddLength(SHA512Context *context, unsigned int length); + +// Sources from rfc6234, with 4 modifications: +// sha224-256.c - commented out 'static uint32_t addTemp;' on line 68 +// sha224-256.c - appended 'M' to the SHA224_256AddLength macro on line 70 +#include "../../3rdparty/rfc6234/sha224-256.c" +// sha384-512.c - commented out 'static uint64_t addTemp;' on line 302 +// sha384-512.c - appended 'M' to the SHA224_256AddLength macro on line 304 +#include "../../3rdparty/rfc6234/sha384-512.c" + #include +static inline int SHA224_256AddLength(SHA256Context *context, unsigned int length) +{ + uint32_t addTemp; + return SHA224_256AddLengthM(context, length); +} +static inline int SHA384_512AddLength(SHA512Context *context, unsigned int length) +{ + uint64_t addTemp; + return SHA384_512AddLengthM(context, length); +} QT_BEGIN_NAMESPACE @@ -59,6 +93,10 @@ public: MD5Context md5Context; md4_context md4Context; Sha1State sha1Context; + SHA224Context sha224Context; + SHA256Context sha256Context; + SHA384Context sha384Context; + SHA512Context sha512Context; }; QByteArray result; }; @@ -75,7 +113,7 @@ public: QCryptographicHash can be used to generate cryptographic hashes of binary or text data. - Currently MD4, MD5, and SHA-1 are supported. + Currently MD4, MD5, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 are supported. */ /*! @@ -83,7 +121,11 @@ public: \value Md4 Generate an MD4 hash sum \value Md5 Generate an MD5 hash sum - \value Sha1 Generate an SHA1 hash sum + \value Sha1 Generate an SHA-1 hash sum + \value Sha224 Generate an SHA-224 hash sum + \value Sha256 Generate an SHA-256 hash sum + \value Sha384 Generate an SHA-384 hash sum + \value Sha512 Generate an SHA-512 hash sum */ /*! @@ -119,6 +161,18 @@ void QCryptographicHash::reset() case Sha1: sha1InitState(&d->sha1Context); break; + case Sha224: + SHA224Reset(&d->sha224Context); + break; + case Sha256: + SHA256Reset(&d->sha256Context); + break; + case Sha384: + SHA384Reset(&d->sha384Context); + break; + case Sha512: + SHA512Reset(&d->sha512Context); + break; } d->result.clear(); } @@ -139,6 +193,18 @@ void QCryptographicHash::addData(const char *data, int length) case Sha1: sha1Update(&d->sha1Context, (const unsigned char *)data, length); break; + case Sha224: + SHA224Input(&d->sha224Context, reinterpret_cast(data), length); + break; + case Sha256: + SHA256Input(&d->sha256Context, reinterpret_cast(data), length); + break; + case Sha384: + SHA384Input(&d->sha384Context, reinterpret_cast(data), length); + break; + case Sha512: + SHA512Input(&d->sha512Context, reinterpret_cast(data), length); + break; } d->result.clear(); } @@ -201,6 +267,31 @@ QByteArray QCryptographicHash::result() const d->result.resize(20); sha1FinalizeState(©); sha1ToHash(©, (unsigned char *)d->result.data()); + break; + } + case Sha224: { + SHA224Context copy = d->sha224Context; + d->result.resize(SHA224HashSize); + SHA224Result(©, reinterpret_cast(d->result.data())); + break; + } + case Sha256:{ + SHA256Context copy = d->sha256Context; + d->result.resize(SHA256HashSize); + SHA256Result(©, reinterpret_cast(d->result.data())); + break; + } + case Sha384:{ + SHA384Context copy = d->sha384Context; + d->result.resize(SHA384HashSize); + SHA384Result(©, reinterpret_cast(d->result.data())); + break; + } + case Sha512:{ + SHA512Context copy = d->sha512Context; + d->result.resize(SHA512HashSize); + SHA512Result(©, reinterpret_cast(d->result.data())); + break; } } return d->result; diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h index 59314e1963..2bfc03373a 100644 --- a/src/corelib/tools/qcryptographichash.h +++ b/src/corelib/tools/qcryptographichash.h @@ -58,7 +58,11 @@ public: enum Algorithm { Md4, Md5, - Sha1 + Sha1, + Sha224, + Sha256, + Sha384, + Sha512 }; QCryptographicHash(Algorithm method); -- cgit v1.2.3 From 394e45199fa1aa45036dd787c5052ef7bcd98c52 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 25 Feb 2012 12:12:09 +0100 Subject: directfb: Switch to the new style plugins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The plugin might advertize more keys than supported at runtime. E.g. the directfbegl key might not be available. I would like to have a directfb.json.in and then generate the right file or if moc would pre-process the file... Change-Id: Ia8ad4e1367c06f5e35d02822d4f830ce1e9dc577 Reviewed-by: Jørgen Lind --- src/plugins/platforms/directfb/directfb.json | 3 +++ src/plugins/platforms/directfb/directfb.pro | 2 ++ src/plugins/platforms/directfb/main.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/plugins/platforms/directfb/directfb.json (limited to 'src') diff --git a/src/plugins/platforms/directfb/directfb.json b/src/plugins/platforms/directfb/directfb.json new file mode 100644 index 0000000000..5c74095fe6 --- /dev/null +++ b/src/plugins/platforms/directfb/directfb.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "directfb", "directfbegl" ] +} diff --git a/src/plugins/platforms/directfb/directfb.pro b/src/plugins/platforms/directfb/directfb.pro index 0585777889..ae47ec397b 100644 --- a/src/plugins/platforms/directfb/directfb.pro +++ b/src/plugins/platforms/directfb/directfb.pro @@ -43,3 +43,5 @@ directfbegl: { CONFIG += qpa/genericunixfontdatabase target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target + +OTHER_FILES += directfb.json diff --git a/src/plugins/platforms/directfb/main.cpp b/src/plugins/platforms/directfb/main.cpp index 048e9ed611..26bdd719ca 100644 --- a/src/plugins/platforms/directfb/main.cpp +++ b/src/plugins/platforms/directfb/main.cpp @@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE class QDirectFbIntegrationPlugin : public QPlatformIntegrationPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPlatformIntegrationFactoryInterface" FILE "directfb.json") public: QStringList keys() const; QPlatformIntegration *create(const QString&, const QStringList&); @@ -86,6 +88,6 @@ QPlatformIntegration * QDirectFbIntegrationPlugin::create(const QString& system, return integration; } -Q_EXPORT_PLUGIN2(directfb, QDirectFbIntegrationPlugin) - QT_END_NAMESPACE + +#include "main.moc" -- cgit v1.2.3 From c2baf45c73beaa01df91d466296fd4efca25ee7a Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 18 Feb 2012 20:05:53 +0000 Subject: Prevent stack corruption when using OpenGL Core Profile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an OpenGL Core Profile context is requested the function glGetStringi() is used to query the supported extensions as glGetString(GL_EXTENSIONS) has been removed in the core profile. The signature for glGetStringi used in Qt missed off the APIENTRY calling convention. This results in stack corruption on windows each time glGetStringi() is called leading to a crash. Change-Id: Iff62c42e2bb5fc4a5c0561fae97ddc5a8ae3a45e Reviewed-by: Samuel Rødal --- src/gui/opengl/qopengl.cpp | 3 ++- src/opengl/qgl.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/opengl/qopengl.cpp b/src/gui/opengl/qopengl.cpp index f39dc12239..290fcb287e 100644 --- a/src/gui/opengl/qopengl.cpp +++ b/src/gui/opengl/qopengl.cpp @@ -42,6 +42,7 @@ #include "qopengl_p.h" #include "qopenglcontext.h" +#include "qopenglfunctions.h" QT_BEGIN_NAMESPACE @@ -50,7 +51,7 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher(const char *str) init(str); } -typedef GLubyte * (*qt_glGetStringi)(GLenum, GLuint); +typedef const GLubyte * (QOPENGLF_APIENTRYP qt_glGetStringi)(GLenum, GLuint); #ifndef GL_NUM_EXTENSIONS #define GL_NUM_EXTENSIONS 0x821D diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 836e7225be..31d6064e90 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -4680,7 +4680,7 @@ QPaintEngine *QGLWidget::paintEngine() const return qt_qgl_paint_engine(); } -typedef GLubyte * (*qt_glGetStringi)(GLenum, GLuint); +typedef const GLubyte * (QGLF_APIENTRYP qt_glGetStringi)(GLenum, GLuint); #ifndef GL_NUM_EXTENSIONS #define GL_NUM_EXTENSIONS 0x821D -- cgit v1.2.3 From 7df4890d8a98d872deaebd46ca8d92473a3c6585 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Mon, 27 Feb 2012 09:51:46 +0100 Subject: Fix divide by zero when glyphWidth is 0 Change-Id: Ic0108b76b8d73cc977f8d64e036a65cb93db4684 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextengine.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 30170759a0..c63f0fede8 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2702,6 +2702,8 @@ int QTextEngine::positionInLigature(const QScriptItem *si, int end, QFixed glyphWidth = glyphs.effectiveAdvance(glyph_pos); // the approximate width of each individual element of the ligature QFixed perItemWidth = glyphWidth / clusterLength; + if (perItemWidth <= 0) + return si->position + clusterStart; QFixed left = x > edge ? edge : edge - glyphWidth; int n = ((x - left) / perItemWidth).floor().toInt(); QFixed dist = x - left - n * perItemWidth; -- cgit v1.2.3 From 99d5decbcfbce35b6d20f816a07c5ed1625aadae Mon Sep 17 00:00:00 2001 From: Jan-Arve Saether Date: Thu, 23 Feb 2012 23:09:06 +0100 Subject: Make accessible interfaces private for Qt 5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we're not yet confident if they serve their purpose well enough, we have decided to make them internal so that we are free to tune them later Change-Id: Id79d154e0537aca07303afea5d057cfcb0773384 Reviewed-by: Morten Johan Sørvig --- src/gui/accessible/qaccessible.cpp | 4 ++++ src/gui/accessible/qaccessible2.cpp | 8 ++++++++ src/gui/accessible/qaccessiblebridge.cpp | 2 ++ src/gui/accessible/qaccessibleobject.cpp | 1 + src/gui/accessible/qaccessibleplugin.cpp | 1 + src/gui/kernel/qwindow.cpp | 2 +- 6 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index 3f1295ab5e..37e7a1dbb4 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -61,6 +61,7 @@ QT_BEGIN_NAMESPACE \class QAccessible \brief The QAccessible class provides enums and static functions related to accessibility. + \internal \ingroup accessibility \inmodule QtWidgets @@ -692,6 +693,7 @@ void QAccessible::updateAccessibility(const QAccessibleEvent &event) \class QAccessibleEvent \brief The QAccessibleEvent is use to notify about changes that are relevant for accessibility in the application. + \internal \ingroup accessibility \inmodule QtGui @@ -727,6 +729,7 @@ QAccessibleInterface *QAccessibleEvent::accessibleInterface() const \class QAccessibleInterface \brief The QAccessibleInterface class defines an interface that exposes information about accessible objects. + \internal \ingroup accessibility \inmodule QtGui @@ -1172,6 +1175,7 @@ const char *qAccessibleEventString(QAccessible::Event event) return QAccessible::staticMetaObject.enumerator(eventEnum).valueToKey(event); } +/*! \internal */ bool operator==(const QAccessible::State &first, const QAccessible::State &second) { return memcmp(&first, &second, sizeof(QAccessible::State)) == 0; diff --git a/src/gui/accessible/qaccessible2.cpp b/src/gui/accessible/qaccessible2.cpp index 0f854c6158..db3028b371 100644 --- a/src/gui/accessible/qaccessible2.cpp +++ b/src/gui/accessible/qaccessible2.cpp @@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE /*! \namespace QAccessible2 \ingroup accessibility + \internal \brief The QAccessible2 namespace defines constants relating to IAccessible2-based interfaces @@ -60,6 +61,7 @@ QT_BEGIN_NAMESPACE /*! \class QAccessibleTextInterface + \internal \ingroup accessibility @@ -180,6 +182,7 @@ QT_BEGIN_NAMESPACE /*! \class QAccessibleEditableTextInterface \ingroup accessibility + \internal \brief The QAccessibleEditableTextInterface class implements support for objects with editable text. @@ -247,6 +250,7 @@ QT_BEGIN_NAMESPACE /*! \class QAccessibleSimpleEditableTextInterface \ingroup accessibility + \internal \brief The QAccessibleSimpleEditableTextInterface class is a convenience class for text-based widgets. It can be inherited instead of \l QAccessibleEditableTextInterface. @@ -259,6 +263,7 @@ QT_BEGIN_NAMESPACE /*! \class QAccessibleValueInterface \ingroup accessibility + \internal \brief The QAccessibleValueInterface class implements support for objects that manipulate a value. @@ -323,6 +328,7 @@ QT_BEGIN_NAMESPACE /*! \class QAccessibleTableCellInterface \ingroup accessibility + \internal \brief The QAccessibleTableCellInterface class implements support for the IAccessibleTable2 Cell interface. @@ -333,6 +339,7 @@ QT_BEGIN_NAMESPACE /*! \class QAccessibleTableInterface \ingroup accessibility + \internal \brief The QAccessibleTableInterface class implements support for the IAccessibleTable2 interface. @@ -344,6 +351,7 @@ QT_BEGIN_NAMESPACE /*! \class QAccessibleActionInterface \ingroup accessibility + \internal \brief The QAccessibleActionInterface class implements support for invocable actions in the interface. diff --git a/src/gui/accessible/qaccessiblebridge.cpp b/src/gui/accessible/qaccessiblebridge.cpp index 8fcf0474a1..d6d0796701 100644 --- a/src/gui/accessible/qaccessiblebridge.cpp +++ b/src/gui/accessible/qaccessiblebridge.cpp @@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE \class QAccessibleBridge \brief The QAccessibleBridge class is the base class for accessibility back-ends. + \internal \ingroup accessibility \inmodule QtWidgets @@ -100,6 +101,7 @@ QT_BEGIN_NAMESPACE \class QAccessibleBridgePlugin \brief The QAccessibleBridgePlugin class provides an abstract base for accessibility bridge plugins. + \internal \ingroup plugins \ingroup accessibility diff --git a/src/gui/accessible/qaccessibleobject.cpp b/src/gui/accessible/qaccessibleobject.cpp index d277f39c43..e587ad077c 100644 --- a/src/gui/accessible/qaccessibleobject.cpp +++ b/src/gui/accessible/qaccessibleobject.cpp @@ -92,6 +92,7 @@ QList QAccessibleObjectPrivate::actionList() const \class QAccessibleObject \brief The QAccessibleObject class implements parts of the QAccessibleInterface for QObjects. + \internal \ingroup accessibility \inmodule QtWidgets diff --git a/src/gui/accessible/qaccessibleplugin.cpp b/src/gui/accessible/qaccessibleplugin.cpp index 8823d63b79..c2fe9c7a7a 100644 --- a/src/gui/accessible/qaccessibleplugin.cpp +++ b/src/gui/accessible/qaccessibleplugin.cpp @@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE \class QAccessiblePlugin \brief The QAccessiblePlugin class provides an abstract base for accessibility plugins. + \internal \ingroup plugins \ingroup accessibility diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 77731f776b..04c2617838 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1192,7 +1192,7 @@ void QWindow::screenDestroyed(QObject *object) /*! Returns the accessibility interface for the object that the window represents - \preliminary + \internal \sa QAccessible */ QAccessibleInterface *QWindow::accessibleRoot() const -- cgit v1.2.3 From 8cacf68cdf5a8211811ca8a30a75f6979682cb1f Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 27 Feb 2012 14:01:47 +1000 Subject: testlib: Remove commented-out code from plain text logger. Change-Id: Ica2e294d1f08cac4697d037dbc2803012e0ba58a Reviewed-by: Rohan McGovern --- src/testlib/qplaintestlogger.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index bd4f26b493..ca86387216 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -251,7 +251,6 @@ void QPlainTestLogger::printMessage(const char *type, const char *msg, const cha outputMessage(buf.data()); } -//void QPlainTestLogger::printBenchmarkResult(const char *bmtag, int value, int iterations) void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) { const char *bmtag = QTest::benchmarkResult2String(); @@ -381,7 +380,6 @@ void QPlainTestLogger::addIncident(IncidentTypes type, const char *description, void QPlainTestLogger::addBenchmarkResult(const QBenchmarkResult &result) { -// printBenchmarkResult(QTest::benchmarkResult2String(), value, iterations); printBenchmarkResult(result); } -- cgit v1.2.3 From cbc777374a26134e87054b2292a800d4b3835d82 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 27 Feb 2012 16:31:03 +1000 Subject: testlib: Improve the silent logging mode Previously the silent logging mode suppressed passes, skips and internal testlib info messages, but did not suppress debugging output, making it hard to see the fails in a noisy test. This commit changes silent mode so that it suppresses all output except test failures and fatal errors, making silent mode truly useful for seeing just the important test output. This commit also adds a selftest to verify the behaviour of silent mode. Change-Id: I75420aead03682306210746a87e2a3b608b58fc6 Reviewed-by: Rohan McGovern --- src/testlib/qplaintestlogger.cpp | 14 +++++++++----- src/testlib/qtestcase.cpp | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index ca86387216..2f87e08c3c 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -371,8 +371,9 @@ void QPlainTestLogger::leaveTestFunction() void QPlainTestLogger::addIncident(IncidentTypes type, const char *description, const char *file, int line) { - // suppress PASS in silent mode - if (type == QAbstractTestLogger::Pass && QTestLog::verboseLevel() < 0) + // suppress PASS and XFAIL in silent mode + if ((type == QAbstractTestLogger::Pass || type == QAbstractTestLogger::XFail) + && QTestLog::verboseLevel() < 0) return; printMessage(QTest::incidentType2String(type), description, file, line); @@ -380,15 +381,18 @@ void QPlainTestLogger::addIncident(IncidentTypes type, const char *description, void QPlainTestLogger::addBenchmarkResult(const QBenchmarkResult &result) { + // suppress benchmark results in silent mode + if (QTestLog::verboseLevel() < 0) + return; + printBenchmarkResult(result); } void QPlainTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line) { - // suppress PASS in silent mode - if ((type == QAbstractTestLogger::Skip || type == QAbstractTestLogger::Info) - && QTestLog::verboseLevel() < 0) + // suppress non-fatal messages in silent mode + if (type != QAbstractTestLogger::QFatal && QTestLog::verboseLevel() < 0) return; printMessage(QTest::messageType2String(type), message, file, line); diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index b8678ba04c..a4f1a39bbd 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1192,7 +1192,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) " *** If no output format is specified, -txt is assumed.\n" "\n" " Detail options:\n" - " -silent : Only outputs warnings and failures\n" + " -silent : Only output failures and fatal errors in plain text output\n" " -v1 : Print enter messages for each testfunction\n" " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n" " -vs : Print every signal emitted\n" -- cgit v1.2.3 From 53338de52b9e654e667df38ca47acc4984b2de2a Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 15 Feb 2012 15:02:05 +0100 Subject: QSqlTableModel::isDirty(): simplify and improve logic Change-Id: Ic1332befa9078a94f872e38ff779e5b4cec7c100 Reviewed-by: Yunqiao Yin --- src/sql/models/qsqltablemodel.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index c895c39212..b36a54bbe9 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -461,23 +461,14 @@ bool QSqlTableModel::isDirty(const QModelIndex &index) const if (!index.isValid()) return false; - switch (d->strategy) { - case OnFieldChange: - return false; - case OnRowChange: { - const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); - return row.op() == QSqlTableModelPrivate::Update - && row.rec().isGenerated(index.column()); - } - case OnManualSubmit: { - const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); - return row.op() == QSqlTableModelPrivate::Insert - || row.op() == QSqlTableModelPrivate::Delete - || (row.op() == QSqlTableModelPrivate::Update - && row.rec().isGenerated(index.column())); - } - } - return false; + const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); + if (row.submitted()) + return false; + + return row.op() == QSqlTableModelPrivate::Insert + || row.op() == QSqlTableModelPrivate::Delete + || (row.op() == QSqlTableModelPrivate::Update + && row.rec().isGenerated(index.column())); } /*! -- cgit v1.2.3 From 52dab549868d41fbfb6f3f612c380fb750755aa3 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 14 Feb 2012 22:26:43 +0100 Subject: QSqlTableModel: unify code for cache-clearing before select The code in submitAll() had the same goal as the code in select, so it has been unified. The new code in select() avoids sending lots of dataChanged() signals for rows that are going to be removed by QSqlQueryModel anyway. Change-Id: Ic22e038223720185e47ed0cc573147745ecc8fc9 Reviewed-by: Yunqiao Yin --- src/sql/models/qsqltablemodel.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index b36a54bbe9..571c28f515 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -378,13 +378,19 @@ bool QSqlTableModel::select() if (query.isEmpty()) return false; - // clear the submitted flags so revertAll can do its job - for (QSqlTableModelPrivate::CacheMap::Iterator it = d->cache.begin(); - it != d->cache.constEnd(); - ++it) - it.value().setSubmitted(false); + QSqlTableModelPrivate::CacheMap::Iterator it = d->cache.end(); + while (it != d->cache.constBegin()) { + --it; + // rows must be accounted for + if (it.value().op() == QSqlTableModelPrivate::Insert) { + beginRemoveRows(QModelIndex(), it.key(), it.key()); + it = d->cache.erase(it); + endRemoveRows(); + } else { + it = d->cache.erase(it); + } + } - revertAll(); QSqlQuery qu(query, d->db); setQuery(qu); @@ -681,19 +687,6 @@ bool QSqlTableModel::submitAll() it.value().setSubmitted(true); } - // all changes have been committed - - // clean up inserted rows - QSqlTableModelPrivate::CacheMap::Iterator it = d->cache.end(); - while (it != d->cache.constBegin()) { - --it; - if (it.value().op() == QSqlTableModelPrivate::Insert) { - beginRemoveRows(QModelIndex(), it.key(), it.key()); - it = d->cache.erase(it); - endRemoveRows(); - } - } - d->clearCache(); return select(); } -- cgit v1.2.3 From 838f828a1d76c1f9fc1fba669d336e91f622fb94 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 27 Feb 2012 17:09:43 +0100 Subject: QComboBox: Use platform theme hint to determine popup geometry. Change-Id: I1f81be1394455715c5dfcd2d426758c4c7cd91fc Reviewed-by: Bradley T. Hughes --- src/widgets/widgets/qcombobox.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index d6af8d6044..c5f5d6e6e1 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -43,6 +43,7 @@ #ifndef QT_NO_COMBOBOX #include +#include #include #include #include @@ -57,15 +58,13 @@ #include #include #include +#include #include #include #include #include #include #include -#ifdef Q_WS_X11 -#include -#endif #if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC) #include #include @@ -219,16 +218,12 @@ void QComboBoxPrivate::_q_modelDestroyed() //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't QRect QComboBoxPrivate::popupGeometry(int screen) const { -#ifdef Q_WS_WIN - return QApplication::desktop()->screenGeometry(screen); -#elif defined Q_WS_X11 - if (X11->desktopEnvironment == DE_KDE) - return QApplication::desktop()->screenGeometry(screen); - else - return QApplication::desktop()->availableGeometry(screen); -#else - return QApplication::desktop()->availableGeometry(screen); -#endif + bool useFullScreenForPopupMenu = false; + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(); + return useFullScreenForPopupMenu ? + QApplication::desktop()->screenGeometry(screen) : + QApplication::desktop()->availableGeometry(screen); } bool QComboBoxPrivate::updateHoverControl(const QPoint &pos) -- cgit v1.2.3 From ced029e87d9bf4b0d7f526d8e611c0e1e8c56a45 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 24 Feb 2012 18:11:16 -0800 Subject: Fix QSettings autotest fails under Windows The Windows registry and INI files use case-insensitive key. This is a side effect of 1d01bc1e83560cb2fc4f9f7f00762ffa5134448a Task-number: QTBUG-24145 Change-Id: I862bddae68ef27569e6ffa901f98ca107d3f300b Reviewed-by: Miikka Heikkinen Reviewed-by: Bradley T. Hughes --- src/corelib/io/qsettings_p.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/corelib/io/qsettings_p.h b/src/corelib/io/qsettings_p.h index f4f285bae4..534c377102 100644 --- a/src/corelib/io/qsettings_p.h +++ b/src/corelib/io/qsettings_p.h @@ -66,7 +66,9 @@ QT_BEGIN_NAMESPACE +#ifndef Q_OS_WIN #define QT_QSETTINGS_ALWAYS_CASE_SENSITIVE_AND_FORGET_ORIGINAL_KEY_ORDER +#endif // used in testing framework #define QSETTINGS_P_H_VERSION 3 -- cgit v1.2.3 From 3518db0bbecd2b10fac714e006f52d66a4f7a992 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 28 Feb 2012 00:11:28 +0100 Subject: QDomNode: don't needlessly call virtual functions Commit 4dabe78387d10495f9f6d0a7395f2ba3c80432bd changed these functions from virtuals to inlines that check the return value of the remaining virtual function nodeType(). However, two of the functions call nodeType() more than once, which we know will return the same result each time, but requires a compiler with interprocedural optimization capabilities to figure out by itself. So instead of repeatedly calling nodeType(), call it once and store its return value in a temporary, and use the temp for further comparisions. Change-Id: Idbeafb7fd93d275d475218c6df2ad7fdc9162cc5 Reviewed-by: Richard J. Moore --- src/xml/dom/qdom.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index c16fd03613..0171fc7bef 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -172,14 +172,16 @@ public: bool isDocumentType() const { return nodeType() == QDomNode::DocumentTypeNode; } bool isElement() const { return nodeType() == QDomNode::ElementNode; } bool isEntityReference() const { return nodeType() == QDomNode::EntityReferenceNode; } - bool isText() const { return (nodeType() == QDomNode::TextNode) - || (nodeType() == QDomNode::CDATASectionNode); } + bool isText() const { const QDomNode::NodeType nt = nodeType(); + return (nt == QDomNode::TextNode) + || (nt == QDomNode::CDATASectionNode); } bool isEntity() const { return nodeType() == QDomNode::EntityNode; } bool isNotation() const { return nodeType() == QDomNode::NotationNode; } bool isProcessingInstruction() const { return nodeType() == QDomNode::ProcessingInstructionNode; } - bool isCharacterData() const { return (nodeType() == QDomNode::CharacterDataNode) - || (nodeType() == QDomNode::TextNode) - || (nodeType() == QDomNode::CommentNode); } + bool isCharacterData() const { const QDomNode::NodeType nt = nodeType(); + return (nt == QDomNode::CharacterDataNode) + || (nt == QDomNode::TextNode) + || (nt == QDomNode::CommentNode); } bool isComment() const { return nodeType() == QDomNode::CommentNode; } virtual QDomNode::NodeType nodeType() const { return QDomNode::BaseNode; } -- cgit v1.2.3 From 0d9714f44549bf2e3a39d5c9833a4744cc3e6410 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 25 Feb 2012 20:48:56 +0100 Subject: moc: Only generate IndexOfMethod for signals. moc is currently generating code to convert from a pointer to member function of a slot or signal to its index. The idea was that it could be usefull for slots to have the new syntax do the same as the old one (connecting signal index to slot index). But in practice, the new syntax do not use the IndexOfMethod for slots. Also, it does not work for all the slots (no Q_PRIVATE_SLOT, no static slots) So since it is not used, and that it would take room in the binaries to generate all the code to get the index of slots, we remove it. If ever we need it, we can still add it later. Change-Id: Ia417e3e524d7915ca86433ea86c66ac2b299c81a Reviewed-by: Kent Hansen --- src/tools/moc/generator.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index c7c7d96487..ac602fd6e8 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -951,13 +951,17 @@ void Generator::generateStaticMetacall() } fprintf(out, " default: ;\n"); fprintf(out, " }\n"); - - fprintf(out, " } else if (_c == QMetaObject::IndexOfMethod) {\n"); + fprintf(out, " }"); + needElse = true; + } + if (!cdef->signalList.isEmpty()) { + Q_ASSERT(needElse); // if there is signal, there was method. + fprintf(out, " else if (_c == QMetaObject::IndexOfMethod) {\n"); fprintf(out, " int *result = reinterpret_cast(_a[0]);\n"); fprintf(out, " void **func = reinterpret_cast(_a[1]);\n"); bool anythingUsed = false; - for (int methodindex = 0; methodindex < methodList.size(); ++methodindex) { - const FunctionDef &f = methodList.at(methodindex); + for (int methodindex = 0; methodindex < cdef->signalList.size(); ++methodindex) { + const FunctionDef &f = cdef->signalList.at(methodindex); if (f.wasCloned || !f.inPrivateClass.isEmpty() || f.isStatic) continue; anythingUsed = true; -- cgit v1.2.3 From 87366cc7ab7e2e5f23614a8501f33b6cb0b65f97 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 19 Jan 2012 20:10:43 +0000 Subject: Initial import of the Blackberry QPA plugin for Qt5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is dependent upon the following Change Id's: I5ebcffb7153f4216d69921d4818051e6b3d14d8a Iec065f528f5edd848be580807a607488dc2e401f Change-Id: I234e3c4272d7474d8f8e20fc4fea20d95c829cb5 Reviewed-by: Kevin Krammer Reviewed-by: Jørgen Lind --- src/plugins/platforms/blackberry/blackberry.pro | 71 + src/plugins/platforms/blackberry/main.cpp | 72 + src/plugins/platforms/blackberry/qbbbuffer.cpp | 165 ++ src/plugins/platforms/blackberry/qbbbuffer.h | 74 + src/plugins/platforms/blackberry/qbbclipboard.cpp | 132 ++ src/plugins/platforms/blackberry/qbbclipboard.h | 67 + .../platforms/blackberry/qbbeventthread.cpp | 559 +++++++ src/plugins/platforms/blackberry/qbbeventthread.h | 90 ++ .../platforms/blackberry/qbbglbackingstore.cpp | 189 +++ .../platforms/blackberry/qbbglbackingstore.h | 95 ++ src/plugins/platforms/blackberry/qbbglcontext.cpp | 356 ++++ src/plugins/platforms/blackberry/qbbglcontext.h | 93 ++ .../platforms/blackberry/qbbinputcontext_imf.cpp | 1696 ++++++++++++++++++++ .../platforms/blackberry/qbbinputcontext_imf.h | 132 ++ .../platforms/blackberry/qbbinputcontext_noimf.cpp | 187 +++ .../platforms/blackberry/qbbinputcontext_noimf.h | 84 + .../platforms/blackberry/qbbintegration.cpp | 293 ++++ src/plugins/platforms/blackberry/qbbintegration.h | 119 ++ .../platforms/blackberry/qbbkeytranslator.h | 269 ++++ .../platforms/blackberry/qbbnavigatorthread.cpp | 279 ++++ .../platforms/blackberry/qbbnavigatorthread.h | 78 + .../platforms/blackberry/qbbrasterbackingstore.cpp | 166 ++ .../platforms/blackberry/qbbrasterbackingstore.h | 81 + src/plugins/platforms/blackberry/qbbrootwindow.cpp | 257 +++ src/plugins/platforms/blackberry/qbbrootwindow.h | 81 + src/plugins/platforms/blackberry/qbbscreen.cpp | 315 ++++ src/plugins/platforms/blackberry/qbbscreen.h | 121 ++ .../platforms/blackberry/qbbvirtualkeyboard.cpp | 500 ++++++ .../platforms/blackberry/qbbvirtualkeyboard.h | 130 ++ src/plugins/platforms/blackberry/qbbwindow.cpp | 665 ++++++++ src/plugins/platforms/blackberry/qbbwindow.h | 133 ++ src/plugins/platforms/platforms.pro | 4 + 32 files changed, 7553 insertions(+) create mode 100644 src/plugins/platforms/blackberry/blackberry.pro create mode 100644 src/plugins/platforms/blackberry/main.cpp create mode 100644 src/plugins/platforms/blackberry/qbbbuffer.cpp create mode 100644 src/plugins/platforms/blackberry/qbbbuffer.h create mode 100644 src/plugins/platforms/blackberry/qbbclipboard.cpp create mode 100644 src/plugins/platforms/blackberry/qbbclipboard.h create mode 100644 src/plugins/platforms/blackberry/qbbeventthread.cpp create mode 100644 src/plugins/platforms/blackberry/qbbeventthread.h create mode 100644 src/plugins/platforms/blackberry/qbbglbackingstore.cpp create mode 100644 src/plugins/platforms/blackberry/qbbglbackingstore.h create mode 100644 src/plugins/platforms/blackberry/qbbglcontext.cpp create mode 100644 src/plugins/platforms/blackberry/qbbglcontext.h create mode 100644 src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp create mode 100644 src/plugins/platforms/blackberry/qbbinputcontext_imf.h create mode 100644 src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp create mode 100644 src/plugins/platforms/blackberry/qbbinputcontext_noimf.h create mode 100644 src/plugins/platforms/blackberry/qbbintegration.cpp create mode 100644 src/plugins/platforms/blackberry/qbbintegration.h create mode 100644 src/plugins/platforms/blackberry/qbbkeytranslator.h create mode 100644 src/plugins/platforms/blackberry/qbbnavigatorthread.cpp create mode 100644 src/plugins/platforms/blackberry/qbbnavigatorthread.h create mode 100644 src/plugins/platforms/blackberry/qbbrasterbackingstore.cpp create mode 100644 src/plugins/platforms/blackberry/qbbrasterbackingstore.h create mode 100644 src/plugins/platforms/blackberry/qbbrootwindow.cpp create mode 100644 src/plugins/platforms/blackberry/qbbrootwindow.h create mode 100644 src/plugins/platforms/blackberry/qbbscreen.cpp create mode 100644 src/plugins/platforms/blackberry/qbbscreen.h create mode 100644 src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp create mode 100644 src/plugins/platforms/blackberry/qbbvirtualkeyboard.h create mode 100644 src/plugins/platforms/blackberry/qbbwindow.cpp create mode 100644 src/plugins/platforms/blackberry/qbbwindow.h (limited to 'src') diff --git a/src/plugins/platforms/blackberry/blackberry.pro b/src/plugins/platforms/blackberry/blackberry.pro new file mode 100644 index 0000000000..94b9c5dbc8 --- /dev/null +++ b/src/plugins/platforms/blackberry/blackberry.pro @@ -0,0 +1,71 @@ +TARGET = blackberry +include(../../qpluginbase.pri) + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms +QT += opengl opengl-private platformsupport platformsupport-private widgets-private + +# Uncomment this to build with support for IMF once it becomes available in the BBNDK +#CONFIG += qbb_imf + +# Uncomment these to enable debugging output for various aspects of the plugin +#DEFINES += QBBBUFFER_DEBUG +#DEFINES += QBBCLIPBOARD_DEBUG +#DEFINES += QBBEVENTTHREAD_DEBUG +#DEFINES += QBBGLBACKINGSTORE_DEBUG +#DEFINES += QBBGLCONTEXT_DEBUG +#DEFINES += QBBINPUTCONTEXT_DEBUG +#DEFINES += QBBINPUTCONTEXT_IMF_EVENT_DEBUG +#DEFINES += QBBINTEGRATION_DEBUG +#DEFINES += QBBNAVIGATORTHREAD_DEBUG +#DEFINES += QBBRASTERBACKINGSTORE_DEBUG +#DEFINES += QBBROOTWINDOW_DEBUG +#DEFINES += QBBSCREEN_DEBUG +#DEFINES += QBBVIRTUALKEYBOARD_DEBUG +#DEFINES += QBBWINDOW_DEBUG + +SOURCES = main.cpp \ + qbbbuffer.cpp \ + qbbeventthread.cpp \ + qbbglcontext.cpp \ + qbbglbackingstore.cpp \ + qbbintegration.cpp \ + qbbnavigatorthread.cpp \ + qbbscreen.cpp \ + qbbwindow.cpp \ + qbbrasterbackingstore.cpp \ + qbbvirtualkeyboard.cpp \ + qbbclipboard.cpp \ + qbbrootwindow.cpp + +HEADERS = qbbbuffer.h \ + qbbeventthread.h \ + qbbkeytranslator.h \ + qbbintegration.h \ + qbbnavigatorthread.h \ + qbbglcontext.h \ + qbbglbackingstore.h \ + qbbscreen.h \ + qbbwindow.h \ + qbbrasterbackingstore.h \ + qbbvirtualkeyboard.h \ + qbbclipboard.h \ + qbbrootwindow.h + +CONFIG(qbb_imf) { + DEFINES += QBB_IMF + HEADERS += qbbinputcontext_imf.h + SOURCES += qbbinputcontext_imf.cpp +} else { + HEADERS += qbbinputcontext_noimf.h + SOURCES += qbbinputcontext_noimf.cpp +} + +QMAKE_CXXFLAGS += -I./private + +LIBS += -lpps -lscreen -lEGL -lclipboard + +include (../../../platformsupport/eglconvenience/eglconvenience.pri) +include (../../../platformsupport/fontdatabases/fontdatabases.pri) + +target.path += $$[QT_INSTALL_PLUGINS]/platforms +INSTALLS += target diff --git a/src/plugins/platforms/blackberry/main.cpp b/src/plugins/platforms/blackberry/main.cpp new file mode 100644 index 0000000000..b9e09c0384 --- /dev/null +++ b/src/plugins/platforms/blackberry/main.cpp @@ -0,0 +1,72 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qbbintegration.h" + +QT_BEGIN_NAMESPACE + +class QBBIntegrationPlugin : public QPlatformIntegrationPlugin +{ +public: + QStringList keys() const; + QPlatformIntegration *create(const QString&, const QStringList&); +}; + +QStringList QBBIntegrationPlugin::keys() const +{ + QStringList list; + list << QLatin1String("blackberry"); + return list; +} + +QPlatformIntegration *QBBIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + Q_UNUSED(paramList); + if (system.toLower() == QLatin1String("blackberry")) + return new QBBIntegration; + + return 0; +} + +Q_EXPORT_PLUGIN2(blackberry, QBBIntegrationPlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbbuffer.cpp b/src/plugins/platforms/blackberry/qbbbuffer.cpp new file mode 100644 index 0000000000..c4ac04898d --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbbuffer.cpp @@ -0,0 +1,165 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbbuffer.h" + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +QBBBuffer::QBBBuffer() + : m_buffer(0) +{ +#if defined(QBBBUFFER_DEBUG) + qDebug() << "QBBBuffer::QBBBuffer - empty"; +#endif +} + +QBBBuffer::QBBBuffer(screen_buffer_t buffer) + : m_buffer(buffer) +{ +#if defined(QBBBUFFER_DEBUG) + qDebug() << "QBBBuffer::QBBBuffer - normal"; +#endif + + // Get size of buffer + errno = 0; + int size[2]; + int result = screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_BUFFER_SIZE, size); + if (result != 0) { + qFatal("QBB: failed to query buffer size, errno=%d", errno); + } + + // Get stride of buffer + errno = 0; + int stride; + result = screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE, &stride); + if (result != 0) { + qFatal("QBB: failed to query buffer stride, errno=%d", errno); + } + + // Get access to buffer's data + errno = 0; + uchar *dataPtr = 0; + result = screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER, (void **)&dataPtr); + if (result != 0) { + qFatal("QBB: failed to query buffer pointer, errno=%d", errno); + } + if (dataPtr == NULL) { + qFatal("QBB: buffer pointer is NULL, errno=%d", errno); + } + + // Get format of buffer + errno = 0; + int screenFormat; + result = screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_FORMAT, &screenFormat); + if (result != 0) { + qFatal("QBB: failed to query buffer format, errno=%d", errno); + } + + // Convert screen format to QImage format + QImage::Format imageFormat = QImage::Format_Invalid; + switch (screenFormat) { + case SCREEN_FORMAT_RGBX4444: + imageFormat = QImage::Format_RGB444; + break; + case SCREEN_FORMAT_RGBA4444: + imageFormat = QImage::Format_ARGB4444_Premultiplied; + break; + case SCREEN_FORMAT_RGBX5551: + imageFormat = QImage::Format_RGB555; + break; + case SCREEN_FORMAT_RGB565: + imageFormat = QImage::Format_RGB16; + break; + case SCREEN_FORMAT_RGBX8888: + imageFormat = QImage::Format_RGB32; + break; + case SCREEN_FORMAT_RGBA8888: + imageFormat = QImage::Format_ARGB32_Premultiplied; + break; + default: + qFatal("QBB: unsupported buffer format, format=%d", screenFormat); + } + + // wrap buffer in an image + m_image = QImage(dataPtr, size[0], size[1], stride, imageFormat); +} + +QBBBuffer::QBBBuffer(const QBBBuffer &other) + : m_buffer(other.m_buffer), + m_image(other.m_image) +{ +#if defined(QBBBUFFER_DEBUG) + qDebug() << "QBBBuffer::QBBBuffer - copy"; +#endif +} + +QBBBuffer::~QBBBuffer() +{ +#if defined(QBBBUFFER_DEBUG) + qDebug() << "QBBBuffer::~QBBBuffer"; +#endif +} + +void QBBBuffer::invalidateInCache() +{ +#if defined(QBBBUFFER_DEBUG) + qDebug() << "QBBBuffer::invalidateInCache"; +#endif + + // Verify native buffer exists + if (m_buffer == 0) { + qFatal("QBB: can't invalidate cache for null buffer"); + } + + // Evict buffer's data from cache + errno = 0; + int result = msync(m_image.bits(), m_image.height() * m_image.bytesPerLine(), MS_INVALIDATE | MS_CACHE_ONLY); + if (result != 0) { + qFatal("QBB: failed to invalidate cache, errno=%d", errno); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbbuffer.h b/src/plugins/platforms/blackberry/qbbbuffer.h new file mode 100644 index 0000000000..45cedb21a8 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbbuffer.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBBUFFER_H +#define QBBBUFFER_H + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QBBBuffer +{ +public: + QBBBuffer(); + QBBBuffer(screen_buffer_t buffer); + QBBBuffer(const QBBBuffer &other); + virtual ~QBBBuffer(); + + screen_buffer_t nativeBuffer() const { return m_buffer; } + const QImage *image() const { return (m_buffer != NULL) ? &m_image : NULL; } + QImage *image() { return (m_buffer != NULL) ? &m_image : NULL; } + + QRect rect() const { return m_image.rect(); } + + void invalidateInCache(); + +private: + screen_buffer_t m_buffer; + QImage m_image; +}; + +QT_END_NAMESPACE + +#endif // QBBBUFFER_H diff --git a/src/plugins/platforms/blackberry/qbbclipboard.cpp b/src/plugins/platforms/blackberry/qbbclipboard.cpp new file mode 100644 index 0000000000..fce016d5ee --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbclipboard.cpp @@ -0,0 +1,132 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT_NO_CLIPBOARD + +#include "qbbclipboard.h" + +#include + +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE +static const char *typeList[] = {"text/html", "text/plain", "application/x-color"}; + +QBBClipboard::QBBClipboard() +{ + m_mimeData = 0; +} + +QBBClipboard::~QBBClipboard() +{ + delete m_mimeData; +} + +void QBBClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) +{ + if (mode != QClipboard::Clipboard) + return; + + if (m_mimeData != data) { + delete m_mimeData; + m_mimeData = data; + } + + empty_clipboard(); + + if (data == 0) + return; + + QStringList format = data->formats(); + for (int i = 0; i < format.size(); ++i) { + QString type = format.at(i); + QByteArray buf = data->data(type); + if (!buf.size()) + continue; + + int ret = set_clipboard_data(type.toUtf8().data(), buf.size(), buf.data()); +#if defined(QBBCLIPBOARD_DEBUG) + qDebug() << "QBB: set " << type.toUtf8().data() << "to clipboard, size=" << buf.size() << ";ret=" << ret; +#else + Q_UNUSED(ret); +#endif + } +} + +void QBBClipboard::readClipboardBuff(const char *type) +{ + char *pbuffer; + if (is_clipboard_format_present(type) == 0) { + int size = get_clipboard_data(type, &pbuffer); + if (size != -1 && pbuffer) { + QString qtype = type; +#if defined(QBBCLIPBOARD_DEBUG) + qDebug() << "QBB: clipboard has " << qtype; +#endif + m_mimeData->setData(qtype, QByteArray(pbuffer, size)); + delete pbuffer; + } + } +} + +QMimeData *QBBClipboard::mimeData(QClipboard::Mode mode) +{ + if (mode != QClipboard::Clipboard) + return 0; + + if (!m_mimeData) + m_mimeData = new QMimeData(); + + m_mimeData->clear(); + + for (int i = 0; i < 3; i++) + readClipboardBuff(typeList[i]); + + return m_mimeData; +} + +QT_END_NAMESPACE +#endif //QT_NO_CLIPBOAR diff --git a/src/plugins/platforms/blackberry/qbbclipboard.h b/src/plugins/platforms/blackberry/qbbclipboard.h new file mode 100644 index 0000000000..b9de9b3e36 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbclipboard.h @@ -0,0 +1,67 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBCLIPBOARD_H +#define QBBCLIPBOARD_H + +#ifndef QT_NO_CLIPBOARD +#include +#include + +QT_BEGIN_NAMESPACE + +class QBBClipboard : public QPlatformClipboard +{ +public: + QBBClipboard(); + virtual ~QBBClipboard(); + virtual QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard); + virtual void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard); + +private: + QMimeData *m_mimeData; + void readClipboardBuff(const char *type); +}; + +QT_END_NAMESPACE + +#endif //QT_NO_CLIPBOARD +#endif //QBBCLIPBOARD_H diff --git a/src/plugins/platforms/blackberry/qbbeventthread.cpp b/src/plugins/platforms/blackberry/qbbeventthread.cpp new file mode 100644 index 0000000000..547428d1c4 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbeventthread.cpp @@ -0,0 +1,559 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbeventthread.h" +#include "qbbintegration.h" +#include "qbbkeytranslator.h" + +#if defined(QBB_IMF) +#include "qbbinputcontext_imf.h" +#else +#include "qbbinputcontext_noimf.h" +#endif + +#include +#include +#include + +#include + +#include +#include +#include + +#include + +QBBEventThread::QBBEventThread(screen_context_t context, QPlatformScreen& screen) + : QThread(), + m_screenContext(context), + m_platformScreen(screen), + m_quit(false), + m_lastButtonState(Qt::NoButton), + m_lastMouseWindow(0) +{ + // Create a touch device + m_touchDevice = new QTouchDevice; + m_touchDevice->setType(QTouchDevice::TouchScreen); + m_touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::Pressure | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(m_touchDevice); + + // initialize array of touch points + for (int i = 0; i < MaximumTouchPoints; i++) { + + // map array index to id + m_touchPoints[i].id = i; + + // pressure is not supported - use default + m_touchPoints[i].pressure = 1.0; + + // nothing touching + m_touchPoints[i].state = Qt::TouchPointReleased; + } +} + +QBBEventThread::~QBBEventThread() +{ + // block until thread terminates + shutdown(); +} + +void QBBEventThread::run() +{ + screen_event_t event; + + // create screen event + errno = 0; + int result = screen_create_event(&event); + if (result) { + qFatal("QBB: failed to create event, errno=%d", errno); + } + +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: event loop started"; +#endif + + // loop indefinitely + while (!m_quit) { + + // block until screen event is available + errno = 0; + result = screen_get_event(m_screenContext, event, -1); + if (result) { + qFatal("QBB: failed to get event, errno=%d", errno); + } + + // process received event + dispatchEvent(event); + } + +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: event loop stopped"; +#endif + + // cleanup + screen_destroy_event(event); +} + +void QBBEventThread::shutdown() +{ + screen_event_t event; + + // create screen event + errno = 0; + int result = screen_create_event(&event); + if (result) { + qFatal("QBB: failed to create event, errno=%d", errno); + } + + // set the event type as user + errno = 0; + int type = SCREEN_EVENT_USER; + result = screen_set_event_property_iv(event, SCREEN_PROPERTY_TYPE, &type); + if (result) { + qFatal("QBB: failed to set event type, errno=%d", errno); + } + + // NOTE: ignore SCREEN_PROPERTY_USER_DATA; treat all user events as shutdown events + + // post event to event loop so it will wake up and die + errno = 0; + result = screen_send_event(m_screenContext, event, getpid()); + if (result) { + qFatal("QBB: failed to set event type, errno=%d", errno); + } + + // cleanup + screen_destroy_event(event); + +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: event loop shutdown begin"; +#endif + + // block until thread terminates + wait(); + +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: event loop shutdown end"; +#endif +} + +void QBBEventThread::dispatchEvent(screen_event_t event) +{ + // get the event type + errno = 0; + int qnxType; + int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType); + if (result) { + qFatal("QBB: failed to query event type, errno=%d", errno); + } + + switch (qnxType) { + case SCREEN_EVENT_MTOUCH_TOUCH: + case SCREEN_EVENT_MTOUCH_MOVE: + case SCREEN_EVENT_MTOUCH_RELEASE: + handleTouchEvent(event, qnxType); + break; + + case SCREEN_EVENT_KEYBOARD: + handleKeyboardEvent(event); + break; + + case SCREEN_EVENT_POINTER: + handlePointerEvent(event); + break; + + case SCREEN_EVENT_CLOSE: + handleCloseEvent(event); + break; + + case SCREEN_EVENT_USER: + // treat all user events as shutdown requests +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: QNX user event"; +#endif + m_quit = true; + break; + + default: + // event ignored +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: QNX unknown event"; +#endif + break; + } +} + +void QBBEventThread::handleKeyboardEvent(screen_event_t event) +{ + // get flags of key event + errno = 0; + int flags; + int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags); + if (result) { + qFatal("QBB: failed to query event flags, errno=%d", errno); + } + + // get key code + errno = 0; + int sym; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym); + if (result) { + qFatal("QBB: failed to query event sym, errno=%d", errno); + } + + int modifiers; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &modifiers); + if (result) { + qFatal("QBB: failed to query event modifiers, errno=%d", errno); + } + + int scan; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SCAN, &scan); + if (result) { + qFatal("QBB: failed to query event modifiers, errno=%d", errno); + } + + int cap; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap); + if (result) { + qFatal("QBB: failed to query event cap, errno=%d", errno); + } + + injectKeyboardEvent(flags, sym, modifiers, scan, cap); +} + +void QBBEventThread::injectKeyboardEvent(int flags, int sym, int modifiers, int scan, int cap) +{ + Q_UNUSED(scan); + + Qt::KeyboardModifiers qtMod = Qt::NoModifier; + if (modifiers & KEYMOD_SHIFT) + qtMod |= Qt::ShiftModifier; + if (modifiers & KEYMOD_CTRL) + qtMod |= Qt::ControlModifier; + if (modifiers & KEYMOD_ALT) + qtMod |= Qt::AltModifier; + + // determine event type + QEvent::Type type = (flags & KEY_DOWN) ? QEvent::KeyPress : QEvent::KeyRelease; + + // Check if the key cap is valid + if (flags & KEY_CAP_VALID) { + Qt::Key key; + QString keyStr; + + if (cap >= 0x20 && cap <= 0x0ff) { + key = Qt::Key(std::toupper(cap)); // Qt expects the CAP to be upper case. + + if ( qtMod & Qt::ControlModifier ) { + keyStr = QChar((int)(key & 0x3f)); + } else { + if (flags & KEY_SYM_VALID) { + keyStr = QChar(sym); + } + } + } else if ((cap > 0x0ff && cap < UNICODE_PRIVATE_USE_AREA_FIRST) || cap > UNICODE_PRIVATE_USE_AREA_LAST) { + key = (Qt::Key)cap; + keyStr = QChar(sym); + } else { + if (isKeypadKey(cap)) + qtMod |= Qt::KeypadModifier; // Is this right? + key = keyTranslator(cap); + } + + QWindowSystemInterface::handleKeyEvent(QGuiApplication::focusWindow(), type, key, qtMod, keyStr); +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt key t=" << type << ", k=" << key << ", s=" << keyStr; +#endif + } +} + +void QBBEventThread::handlePointerEvent(screen_event_t event) +{ + errno = 0; + + // Query the window that was clicked + screen_window_t qnxWindow; + void *handle; + int result = screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, &handle); + if (result) { + qFatal("QBB: failed to query event window, errno=%d", errno); + } + qnxWindow = static_cast(handle); + + // Query the button states + int buttonState = 0; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_BUTTONS, &buttonState); + if (result) { + qFatal("QBB: failed to query event button state, errno=%d", errno); + } + + // Query the window position + int windowPos[2]; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, windowPos); + if (result) { + qFatal("QBB: failed to query event window position, errno=%d", errno); + } + + // Query the screen position + int pos[2]; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, pos); + if (result) { + qFatal("QBB: failed to query event position, errno=%d", errno); + } + + // Query the wheel delta + int wheelDelta = 0; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_MOUSE_WHEEL, &wheelDelta); + if (result) { + qFatal("QBB: failed to query event wheel delta, errno=%d", errno); + } + + // Map window handle to top-level QWindow + QWindow *w = QBBIntegration::window(qnxWindow); + + // Generate enter and leave events as needed. + if (qnxWindow != m_lastMouseWindow) { + QWindow *wOld = QBBIntegration::window(m_lastMouseWindow); + + if (wOld) { + QWindowSystemInterface::handleLeaveEvent(wOld); +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt leave, w=" << wOld; +#endif + } + + if (w) { + QWindowSystemInterface::handleEnterEvent(w); +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt enter, w=" << w; +#endif + } + } + m_lastMouseWindow = qnxWindow; + + // Apply scaling to wheel delta and invert value for Qt. We'll probably want to scale + // this via a system preference at some point. But for now this is a sane value and makes + // the wheel usable. + wheelDelta *= -10; + + // convert point to local coordinates + QPoint globalPoint(pos[0], pos[1]); + QPoint localPoint(windowPos[0], windowPos[1]); + + // Convert buttons. + Qt::MouseButtons buttons = Qt::NoButton; + if (buttonState & 1) + buttons |= Qt::LeftButton; + if (buttonState & 2) + buttons |= Qt::MidButton; + if (buttonState & 4) + buttons |= Qt::RightButton; + + if (w) { + // Inject mouse event into Qt only if something has changed. + if (m_lastGlobalMousePoint != globalPoint || + m_lastLocalMousePoint != localPoint || + m_lastButtonState != buttons) { + QWindowSystemInterface::handleMouseEvent(w, localPoint, globalPoint, buttons); +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt mouse, w=" << w << ", (" << localPoint.x() << "," << localPoint.y() << "), b=" << static_cast(buttons); +#endif + } + + if (wheelDelta) { + // Screen only supports a single wheel, so we will assume Vertical orientation for + // now since that is pretty much standard. + QWindowSystemInterface::handleWheelEvent(w, localPoint, globalPoint, wheelDelta, Qt::Vertical); +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt wheel, w=" << w << ", (" << localPoint.x() << "," << localPoint.y() << "), d=" << static_cast(wheelDelta); +#endif + } + } + + m_lastGlobalMousePoint = globalPoint; + m_lastLocalMousePoint = localPoint; + m_lastButtonState = buttons; +} + +void QBBEventThread::handleTouchEvent(screen_event_t event, int qnxType) +{ + // get display coordinates of touch + errno = 0; + int pos[2]; + int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, pos); + if (result) { + qFatal("QBB: failed to query event position, errno=%d", errno); + } + + // get window coordinates of touch + errno = 0; + int windowPos[2]; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, windowPos); + if (result) { + qFatal("QBB: failed to query event window position, errno=%d", errno); + } + + // determine which finger touched + errno = 0; + int touchId; + result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, &touchId); + if (result) { + qFatal("QBB: failed to query event touch id, errno=%d", errno); + } + + // determine which window was touched + errno = 0; + void *handle; + result = screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, &handle); + if (result) { + qFatal("QBB: failed to query event window, errno=%d", errno); + } + screen_window_t qnxWindow = static_cast(handle); + + // check if finger is valid + if (touchId < MaximumTouchPoints) { + + // Map window handle to top-level QWindow + QWindow *w = QBBIntegration::window(qnxWindow); + + // Generate enter and leave events as needed. + if (qnxWindow != m_lastMouseWindow) { + QWindow *wOld = QBBIntegration::window(m_lastMouseWindow); + + if (wOld) { + QWindowSystemInterface::handleLeaveEvent(wOld); + #if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt leave, w=" << wOld; + #endif + } + + if (w) { + QWindowSystemInterface::handleEnterEvent(w); + #if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt enter, w=" << w; + #endif + } + } + m_lastMouseWindow = qnxWindow; + + if (w) { + // convert primary touch to mouse event + if (touchId == 0) { + + // convert point to local coordinates + QPoint globalPoint(pos[0], pos[1]); + QPoint localPoint(windowPos[0], windowPos[1]); + + // map touch state to button state + Qt::MouseButtons buttons = (qnxType == SCREEN_EVENT_MTOUCH_RELEASE) ? Qt::NoButton : Qt::LeftButton; + + // inject event into Qt + QWindowSystemInterface::handleMouseEvent(w, localPoint, globalPoint, buttons); +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt mouse, w=" << w << ", (" << localPoint.x() << "," << localPoint.y() << "), b=" << buttons; +#endif + } + + // get size of screen which contains window + QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(w); + QSizeF screenSize = platformScreen->physicalSize(); + + // update cached position of current touch point + m_touchPoints[touchId].normalPosition = QPointF( static_cast(pos[0]) / screenSize.width(), static_cast(pos[1]) / screenSize.height() ); + m_touchPoints[touchId].area = QRectF( pos[0], pos[1], 0.0, 0.0 ); + + // determine event type and update state of current touch point + QEvent::Type type = QEvent::None; + switch (qnxType) { + case SCREEN_EVENT_MTOUCH_TOUCH: + m_touchPoints[touchId].state = Qt::TouchPointPressed; + type = QEvent::TouchBegin; + break; + case SCREEN_EVENT_MTOUCH_MOVE: + m_touchPoints[touchId].state = Qt::TouchPointMoved; + type = QEvent::TouchUpdate; + break; + case SCREEN_EVENT_MTOUCH_RELEASE: + m_touchPoints[touchId].state = Qt::TouchPointReleased; + type = QEvent::TouchEnd; + break; + } + + // build list of active touch points + QList pointList; + for (int i = 0; i < MaximumTouchPoints; i++) { + if (i == touchId) { + // current touch point is always active + pointList.append(m_touchPoints[i]); + } else if (m_touchPoints[i].state != Qt::TouchPointReleased) { + // finger is down but did not move + m_touchPoints[i].state = Qt::TouchPointStationary; + pointList.append(m_touchPoints[i]); + } + } + + // inject event into Qt + QWindowSystemInterface::handleTouchEvent(w, m_touchDevice, pointList); +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: Qt touch, w=" << w << ", p=(" << pos[0] << "," << pos[1] << "), t=" << type; +#endif + } + } +} + +void QBBEventThread::handleCloseEvent(screen_event_t event) +{ + // Query the window that was closed + void *handle; + int result = screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, &handle); + if (result != 0) { + qFatal("QBB: failed to query event window, errno=%d", errno); + } + screen_window_t qnxWindow = static_cast(handle); + + // Map window handle to top-level QWindow + QWindow *w = QBBIntegration::window(qnxWindow); + if (w != 0) { + QWindowSystemInterface::handleCloseEvent(w); + } +} + diff --git a/src/plugins/platforms/blackberry/qbbeventthread.h b/src/plugins/platforms/blackberry/qbbeventthread.h new file mode 100644 index 0000000000..afa738830c --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbeventthread.h @@ -0,0 +1,90 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBEVENTTHREAD_H +#define QBBEVENTTHREAD_H + +#include + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QBBEventThread : public QThread +{ +public: + QBBEventThread(screen_context_t context, QPlatformScreen& screen); + virtual ~QBBEventThread(); + + static void injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap); + +protected: + virtual void run(); + +private: + enum { + MaximumTouchPoints = 10 + }; + + void shutdown(); + void dispatchEvent(screen_event_t event); + void handleKeyboardEvent(screen_event_t event); + void handlePointerEvent(screen_event_t event); + void handleTouchEvent(screen_event_t event, int type); + void handleCloseEvent(screen_event_t event); + + screen_context_t m_screenContext; + QPlatformScreen& m_platformScreen; + bool m_quit; + QPoint m_lastGlobalMousePoint; + QPoint m_lastLocalMousePoint; + Qt::MouseButtons m_lastButtonState; + screen_window_t m_lastMouseWindow; + QTouchDevice *m_touchDevice; + QWindowSystemInterface::TouchPoint m_touchPoints[MaximumTouchPoints]; +}; + +QT_END_NAMESPACE + +#endif // QBBEVENTTHREAD_H diff --git a/src/plugins/platforms/blackberry/qbbglbackingstore.cpp b/src/plugins/platforms/blackberry/qbbglbackingstore.cpp new file mode 100644 index 0000000000..91b07770e1 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbglbackingstore.cpp @@ -0,0 +1,189 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbglbackingstore.h" +#include "qbbglcontext.h" +#include "qbbwindow.h" +#include "qbbscreen.h" + +#include + +#include +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +QBBGLPaintDevice::QBBGLPaintDevice(QWindow *window) + : QGLPaintDevice(), + m_window(0), + m_glContext(0) +{ + m_window = static_cast(window->handle()); + + // Extract the QPlatformOpenGLContext from the window + QPlatformOpenGLContext *platformOpenGLContext = m_window->platformOpenGLContext(); + + // Convert this to a QGLContext + m_glContext = QGLContext::fromOpenGLContext(platformOpenGLContext->context()); +} + +QBBGLPaintDevice::~QBBGLPaintDevice() +{ + // Cleanup GL context + delete m_glContext; +} + +QPaintEngine *QBBGLPaintDevice::paintEngine() const +{ + // Select a paint engine based on configued OpenGL version + return qt_qgl_paint_engine(); +} + +QSize QBBGLPaintDevice::size() const +{ + // Get size of EGL surface + return m_window->geometry().size(); +} + + +QBBGLBackingStore::QBBGLBackingStore(QWindow *window) + : QPlatformBackingStore(window), + m_openGLContext(0), + m_paintDevice(0), + m_requestedSize(), + m_size() +{ +#if defined(QBBGLBACKINGSTORE_DEBUG) + qDebug() << "QBBGLBackingStore::QBBGLBackingStore - w=" << window; +#endif + + // Create an OpenGL paint device which in turn creates a QGLContext for us + m_paintDevice = new QBBGLPaintDevice(window); + m_openGLContext = m_paintDevice->context()->contextHandle(); +} + +QBBGLBackingStore::~QBBGLBackingStore() +{ +#if defined(QBBGLBACKINGSTORE_DEBUG) + qDebug() << "QBBGLBackingStore::~QBBGLBackingStore - w=" << window(); +#endif + + // cleanup OpenGL paint device + delete m_paintDevice; +} + +void QBBGLBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(region); + Q_UNUSED(offset); + +#if defined(QBBGLBACKINGSTORE_DEBUG) + qDebug() << "QBBGLBackingStore::flush - w=" << window; +#endif + + // update the display with newly rendered content + m_openGLContext->swapBuffers(window); +} + +void QBBGLBackingStore::resize(const QSize &size, const QRegion &staticContents) +{ + Q_UNUSED(staticContents); +#if defined(QBBGLBACKINGSTORE_DEBUG) + qDebug() << "QBBGLBackingStore::resize - w=" << window() << ", s=" << size; +#endif + // NOTE: defer resizing window buffers until next paint as + // resize() can be called multiple times before a paint occurs + m_requestedSize = size; +} + +void QBBGLBackingStore::beginPaint(const QRegion ®ion) +{ + Q_UNUSED(region); + +#if defined(QBBGLBACKINGSTORE_DEBUG) + qDebug() << "QBBGLBackingStore::beginPaint - w=" << window(); +#endif + + // resize EGL surface if window surface resized + if (m_size != m_requestedSize) { + resizeSurface(m_requestedSize); + } +} + +void QBBGLBackingStore::endPaint(const QRegion ®ion) +{ + Q_UNUSED(region); +#if defined(QBBGLBACKINGSTORE_DEBUG) + qDebug() << "QBBGLBackingStore::endPaint - w=" << window(); +#endif +} + +void QBBGLBackingStore::resizeSurface(const QSize &size) +{ + // need to destroy surface so make sure its not current + bool restoreCurrent = false; + QBBGLContext *platformContext = static_cast(m_openGLContext->handle()); + if (platformContext->isCurrent()) { + m_openGLContext->doneCurrent(); + restoreCurrent = true; + } + + // destroy old EGL surface + platformContext->destroySurface(); + + // resize window's buffers + static_cast(window()->handle())->setBufferSize(size); + + // re-create EGL surface with new size + m_size = size; + platformContext->createSurface(window()->handle()); + + // make context current again + if (restoreCurrent) { + m_openGLContext->makeCurrent(window()); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbglbackingstore.h b/src/plugins/platforms/blackberry/qbbglbackingstore.h new file mode 100644 index 0000000000..5455c5767c --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbglbackingstore.h @@ -0,0 +1,95 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBGLBACKINGSTORE_H +#define QBBGLBACKINGSTORE_H + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QGLContext; +class QBBGLContext; +class QBBScreen; +class QBBWindow; + +class QBBGLPaintDevice : public QGLPaintDevice +{ +public: + QBBGLPaintDevice(QWindow *window); + virtual ~QBBGLPaintDevice(); + + virtual QPaintEngine *paintEngine() const; + virtual QSize size() const; + virtual QGLContext *context() const { return m_glContext; } + +private: + QBBWindow *m_window; + QGLContext *m_glContext; +}; + +class QBBGLBackingStore : public QPlatformBackingStore +{ +public: + QBBGLBackingStore(QWindow *window); + virtual ~QBBGLBackingStore(); + + virtual QPaintDevice *paintDevice() { return m_paintDevice; } + virtual void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + virtual void resize(const QSize &size, const QRegion &staticContents); + virtual void beginPaint(const QRegion ®ion); + virtual void endPaint(const QRegion ®ion); + + void resizeSurface(const QSize &size); + +private: + QOpenGLContext *m_openGLContext; + QBBGLPaintDevice *m_paintDevice; + QSize m_requestedSize; + QSize m_size; +}; + +QT_END_NAMESPACE + +#endif // QBBGLBACKINGSTORE_H diff --git a/src/plugins/platforms/blackberry/qbbglcontext.cpp b/src/plugins/platforms/blackberry/qbbglcontext.cpp new file mode 100644 index 0000000000..fb74fdb5d2 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbglcontext.cpp @@ -0,0 +1,356 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbglcontext.h" +#include "qbbrootwindow.h" +#include "qbbscreen.h" +#include "qbbwindow.h" + +#include "private/qeglconvenience_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +EGLDisplay QBBGLContext::ms_eglDisplay = EGL_NO_DISPLAY; + +static EGLenum checkEGLError(const char *msg) +{ + static const char *errmsg[] = + { + "EGL function succeeded", + "EGL is not initialized, or could not be initialized, for the specified display", + "EGL cannot access a requested resource", + "EGL failed to allocate resources for the requested operation", + "EGL fail to access an unrecognized attribute or attribute value was passed in an attribute list", + "EGLConfig argument does not name a valid EGLConfig", + "EGLContext argument does not name a valid EGLContext", + "EGL current surface of the calling thread is no longer valid", + "EGLDisplay argument does not name a valid EGLDisplay", + "EGL arguments are inconsistent", + "EGLNativePixmapType argument does not refer to a valid native pixmap", + "EGLNativeWindowType argument does not refer to a valid native window", + "EGL one or more argument values are invalid", + "EGLSurface argument does not name a valid surface configured for rendering", + "EGL power management event has occurred", + }; + EGLenum error = eglGetError(); + fprintf(stderr, "%s: %s\n", msg, errmsg[error - EGL_SUCCESS]); + return error; +} + +QBBGLContext::QBBGLContext(QOpenGLContext *glContext) + : QPlatformOpenGLContext(), + m_glContext(glContext), + m_eglSurface(EGL_NO_SURFACE) +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + QSurfaceFormat format = m_glContext->format(); + + // Set current rendering API + EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to set EGL API, err=%d", eglGetError()); + } + + // Get colour channel sizes from window format + int alphaSize = format.alphaBufferSize(); + int redSize = format.redBufferSize(); + int greenSize = format.greenBufferSize(); + int blueSize = format.blueBufferSize(); + + // Check if all channels are don't care + if (alphaSize == -1 && redSize == -1 && greenSize == -1 && blueSize == -1) { + // Set colour channels based on depth of window's screen + QBBScreen *screen = static_cast(QBBScreen::screens().first()); + int depth = screen->depth(); + if (depth == 32) { + // SCREEN_FORMAT_RGBA8888 + alphaSize = 8; + redSize = 8; + greenSize = 8; + blueSize = 8; + } else { + // SCREEN_FORMAT_RGB565 + alphaSize = 0; + redSize = 5; + greenSize = 6; + blueSize = 5; + } + } else { + // Choose best match based on supported pixel formats + if (alphaSize <= 0 && redSize <= 5 && greenSize <= 6 && blueSize <= 5) { + // SCREEN_FORMAT_RGB565 + alphaSize = 0; + redSize = 5; + greenSize = 6; + blueSize = 5; + } else { + // SCREEN_FORMAT_RGBA8888 + alphaSize = 8; + redSize = 8; + greenSize = 8; + blueSize = 8; + } + } + + // Update colour channel sizes in window format + format.setAlphaBufferSize(alphaSize); + format.setRedBufferSize(redSize); + format.setGreenBufferSize(greenSize); + format.setBlueBufferSize(blueSize); + format.setSamples(2); + + // Select EGL config based on requested window format + m_eglConfig = q_configFromGLFormat(ms_eglDisplay, format); + if (m_eglConfig == 0) { + qFatal("QBB: failed to find EGL config"); + } + + m_eglContext = eglCreateContext(ms_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAttrs()); + if (m_eglContext == EGL_NO_CONTEXT) { + checkEGLError("eglCreateContext"); + qFatal("QBB: failed to create EGL context, err=%d", eglGetError()); + } + + // Query/cache window format of selected EGL config + m_windowFormat = q_glFormatFromConfig(ms_eglDisplay, m_eglConfig); +} + +QBBGLContext::~QBBGLContext() +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + // Cleanup EGL context if it exists + if (m_eglContext != EGL_NO_CONTEXT) { + eglDestroyContext(ms_eglDisplay, m_eglContext); + } + + // Cleanup EGL surface if it exists + destroySurface(); +} + +void QBBGLContext::initialize() +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Initialize connection to EGL + ms_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (ms_eglDisplay == EGL_NO_DISPLAY) { + checkEGLError("eglGetDisplay"); + qFatal("QBB: failed to obtain EGL display"); + } + + EGLBoolean eglResult = eglInitialize(ms_eglDisplay, 0, 0); + if (eglResult != EGL_TRUE) { + checkEGLError("eglInitialize"); + qFatal("QBB: failed to initialize EGL display, err=%d", eglGetError()); + } +} + +void QBBGLContext::shutdown() +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Close connection to EGL + eglTerminate(ms_eglDisplay); +} + +bool QBBGLContext::makeCurrent(QPlatformSurface *surface) +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Set current rendering API + EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to set EGL API, err=%d", eglGetError()); + } + + if (m_eglSurface == EGL_NO_SURFACE) + createSurface(surface); + + eglResult = eglMakeCurrent(ms_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext); + if (eglResult != EGL_TRUE) { + checkEGLError("eglMakeCurrent"); + qFatal("QBB: failed to set current EGL context, err=%d", eglGetError()); + } + return (eglResult == EGL_TRUE); +} + +void QBBGLContext::doneCurrent() +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // set current rendering API + EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to set EGL API, err=%d", eglGetError()); + } + + // clear curent EGL context and unbind EGL surface + eglResult = eglMakeCurrent(ms_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to clear current EGL context, err=%d", eglGetError()); + } +} + +void QBBGLContext::swapBuffers(QPlatformSurface *surface) +{ + Q_UNUSED(surface); +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + // Set current rendering API + EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to set EGL API, err=%d", eglGetError()); + } + + // Post EGL surface to window + eglResult = eglSwapBuffers(ms_eglDisplay, m_eglSurface); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to swap EGL buffers, err=%d", eglGetError()); + } +} + +QFunctionPointer QBBGLContext::getProcAddress(const QByteArray &procName) +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + // Set current rendering API + EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to set EGL API, err=%d", eglGetError()); + } + + // Lookup EGL extension function pointer + return static_cast(eglGetProcAddress(procName.constData())); +} + +EGLint *QBBGLContext::contextAttrs() +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + // Choose EGL settings based on OpenGL version +#if defined(QT_OPENGL_ES_2) + static EGLint attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; + return attrs; +#else + return 0; +#endif +} + +bool QBBGLContext::isCurrent() const +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + return (eglGetCurrentContext() == m_eglContext); +} + +void QBBGLContext::createSurface(QPlatformSurface *surface) +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Get a pointer to the corresponding platform window + QBBWindow *platformWindow = dynamic_cast(surface); + if (!platformWindow) { + qFatal("QBB: unable to create EGLSurface without a QBBWindow"); + } + + // If the platform window does not yet have any buffers, we create + // a temporary set of buffers with a size of 1x1 pixels. This will + // suffice until such time as the platform window has obtained + // buffers of the proper size + if (!platformWindow->hasBuffers()) { + platformWindow->setPlatformOpenGLContext(this); + m_surfaceSize = platformWindow->geometry().size(); + platformWindow->setBufferSize(m_surfaceSize); + } + + // Obtain the native handle for our window + screen_window_t handle = platformWindow->nativeHandle(); + + const EGLint eglSurfaceAttrs[] = + { + EGL_RENDER_BUFFER, EGL_BACK_BUFFER, + EGL_NONE + }; + + // Create EGL surface + m_eglSurface = eglCreateWindowSurface(ms_eglDisplay, m_eglConfig, (EGLNativeWindowType) handle, eglSurfaceAttrs); + if (m_eglSurface == EGL_NO_SURFACE) { + checkEGLError("eglCreateWindowSurface"); + qFatal("QBB: failed to create EGL surface, err=%d", eglGetError()); + } +} + +void QBBGLContext::destroySurface() +{ +#if defined(QBBGLCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + // Destroy EGL surface if it exists + if (m_eglSurface != EGL_NO_SURFACE) { + EGLBoolean eglResult = eglDestroySurface(ms_eglDisplay, m_eglSurface); + if (eglResult != EGL_TRUE) { + qFatal("QBB: failed to destroy EGL surface, err=%d", eglGetError()); + } + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbglcontext.h b/src/plugins/platforms/blackberry/qbbglcontext.h new file mode 100644 index 0000000000..8ea1df5f40 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbglcontext.h @@ -0,0 +1,93 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBGLCONTEXT_H +#define QBBGLCONTEXT_H + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QBBWindow; + +class QBBGLContext : public QPlatformOpenGLContext +{ +public: + QBBGLContext(QOpenGLContext *glContext); + virtual ~QBBGLContext(); + + static void initialize(); + static void shutdown(); + + virtual bool makeCurrent(QPlatformSurface *surface); + virtual void doneCurrent(); + virtual void swapBuffers(QPlatformSurface *surface); + virtual QFunctionPointer getProcAddress(const QByteArray &procName); + + virtual QSurfaceFormat format() const { return m_windowFormat; } + + bool isCurrent() const; + + void createSurface(QPlatformSurface *surface); + void destroySurface(); + +private: + /** \todo Should this be non-static so we can use additional displays? */ + static EGLDisplay ms_eglDisplay; + + QSurfaceFormat m_windowFormat; + QOpenGLContext *m_glContext; + + EGLConfig m_eglConfig; + EGLContext m_eglContext; + EGLSurface m_eglSurface; + QSize m_surfaceSize; + + static EGLint *contextAttrs(); +}; + +QT_END_NAMESPACE + +#endif // QBBGLCONTEXT_H diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp b/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp new file mode 100644 index 0000000000..fab3d3f151 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbinputcontext_imf.cpp @@ -0,0 +1,1696 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbinputcontext_imf.h" +#include "qbbeventthread.h" +#include "qbbvirtualkeyboard.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include "imf/imf_client.h" +#include "imf/input_control.h" +#include +#include + +/** TODO: + Support inputMethodHints to restrict input (needs additional features in IMF). +*/ + +#define STRX(x) #x +#define STR(x) STRX(x) + +// Someone tell me why input_control methods are in this namespace, but the rest is not. +using namespace InputMethodSystem; + +#define qs(x) QString::fromLatin1(x) +#define iarg(name) event->mArgs[qs(#name)] = QVariant::fromValue(name) +#define parg(name) event->mArgs[qs(#name)] = QVariant::fromValue((void*)name) +namespace +{ + +spannable_string_t *toSpannableString(const QString &text); +static const input_session_t *sInputSession = 0; +bool isSessionOkay(input_session_t *ic) +{ + return ic !=0 && sInputSession != 0 && ic->component_id == sInputSession->component_id; +} + +enum ImfEventType +{ + ImfBeginBatchEdit, + ImfClearMetaKeyStates, + ImfCommitText, + ImfDeleteSurroundingText, + ImfEndBatchEdit, + ImfFinishComposingText, + ImfGetCursorCapsMode, + ImfGetCursorPosition, + ImfGetExtractedText, + ImfGetSelectedText, + ImfGetTextAfterCursor, + ImfGetTextBeforeCursor, + ImfPerformEditorAction, + ImfReportFullscreenMode, + ImfSendEvent, + ImfSendAsyncEvent, + ImfSetComposingRegion, + ImfSetComposingText, + ImfSetSelection +}; + +// We use this class as a round about way to support a posting synchronous event into +// Qt's main thread from the IMF thread. +class ImfEventResult +{ +public: + ImfEventResult() + { + m_mutex.lock(); + } + + ~ImfEventResult() + { + m_mutex.unlock(); + } + + void wait() + { + m_wait.wait(&m_mutex); + } + + void signal() + { + m_wait.wakeAll(); + } + + void setResult(const QVariant& result) + { + m_mutex.lock(); + m_retVal = result; + signal(); + m_mutex.unlock(); + } + + QVariant result() + { + return m_retVal; + } + +private: + QVariant m_retVal; + QMutex m_mutex; + QWaitCondition m_wait; +}; + +class ImfEvent : public QEvent +{ + public: + ImfEvent(input_session_t *session, ImfEventType type, ImfEventResult *result) : + QEvent((QEvent::Type)sUserEventType), + m_session(session), + m_imfType(type), + m_result(result) + { + } + ~ImfEvent() { } + + input_session_t *m_session; + ImfEventType m_imfType; + QVariantHash m_args; + ImfEventResult *m_result; + + static int sUserEventType; +}; +int ImfEvent::sUserEventType = QEvent::registerEventType(); + +static int32_t imfBeginBatchEdit(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfBeginBatchEdit, &result); + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + + return ret; +} + +static int32_t imfClearMetaKeyStates(input_session_t *ic, int32_t states) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfClearMetaKeyStates, &result); + iarg(states); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + + return ret; +} + +static int32_t imfCommitText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfCommitText, &result); + parg(text); + iarg(new_cursor_position); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + + return ret; +} + +static int32_t imfDeleteSurroundingText(input_session_t *ic, int32_t left_length, int32_t right_length) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfDeleteSurroundingText, &result); + iarg(left_length); + iarg(right_length); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + + return ret; +} + +static int32_t imfEndBatchEdit(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfEndBatchEdit, &result); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + + return ret; +} + +static int32_t imfFinishComposingText(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfFinishComposingText, &result); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + + return ret; +} + +static int32_t imfGetCursorCapsMode(input_session_t *ic, int32_t req_modes) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfGetCursorCapsMode, &result); + iarg(req_modes); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + int32_t ret = result.result().value(); + return ret; +} + +static int32_t imfGetCursorPosition(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfGetCursorPosition, &result); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + + return ret; +} + +static extracted_text_t *imfGetExtractedText(input_session_t *ic, extracted_text_request_t *request, int32_t flags) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) { + extracted_text_t *et = (extracted_text_t *)calloc(sizeof(extracted_text_t),1); + et->text = (spannable_string_t *)calloc(sizeof(spannable_string_t),1); + return et; + } + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfGetExtractedText, &result); + parg(request); + iarg(flags); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + return result.result().value(); +} + +static spannable_string_t *imfGetSelectedText(input_session_t *ic, int32_t flags) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return toSpannableString(""); + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfGetSelectedText, &result); + iarg(flags); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + return result.result().value(); +} + +static spannable_string_t *imfGetTextAfterCursor(input_session_t *ic, int32_t n, int32_t flags) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return toSpannableString(""); + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfGetTextAfterCursor, &result); + iarg(n); + iarg(flags); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + return result.result().value(); +} + +static spannable_string_t *imfGetTextBeforeCursor(input_session_t *ic, int32_t n, int32_t flags) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return toSpannableString(""); + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfGetTextBeforeCursor, &result); + iarg(n); + iarg(flags); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + return result.result().value(); +} + +static int32_t imfPerformEditorAction(input_session_t *ic, int32_t editor_action) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfPerformEditorAction, &result); + iarg(editor_action); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + return ret; +} + +static int32_t imfReportFullscreenMode(input_session_t *ic, int32_t enabled) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfReportFullscreenMode, &result); + iarg(enabled); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + return ret; +} + +static int32_t imfSendEvent(input_session_t *ic, event_t *event) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEvent *imfEvent = new ImfEvent(ic, ImfSendEvent, 0); + imfEvent->m_args[qs("event")] = QVariant::fromValue(static_cast(event)); + + QCoreApplication::postEvent(QCoreApplication::instance(), imfEvent); + + return 0; +} + +static int32_t imfSendAsyncEvent(input_session_t *ic, event_t *event) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEvent *imfEvent = new ImfEvent(ic, ImfSendAsyncEvent, 0); + imfEvent->m_args[qs("event")] = QVariant::fromValue(static_cast(event)); + + QCoreApplication::postEvent(QCoreApplication::instance(), imfEvent); + + return 0; +} + +static int32_t imfSetComposingRegion(input_session_t *ic, int32_t start, int32_t end) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfSetComposingRegion, &result); + iarg(start); + iarg(end); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + return ret; +} + +static int32_t imfSetComposingText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfSetComposingText, &result); + parg(text); + iarg(new_cursor_position); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + return ret; +} + +static int32_t imfSetSelection(input_session_t *ic, int32_t start, int32_t end) +{ +#if defined(QBBINPUTCONTEXT_IMF_EVENT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + ImfEventResult result; + ImfEvent *event = new ImfEvent(ic, ImfSetSelection, &result); + iarg(start); + iarg(end); + + QCoreApplication::postEvent(QCoreApplication::instance(), event); + + result.wait(); + int32_t ret = result.result().value(); + return ret; +} + +static connection_interface_t ic_funcs = { + imfBeginBatchEdit, + imfClearMetaKeyStates, + imfCommitText, + imfDeleteSurroundingText, + imfEndBatchEdit, + imfFinishComposingText, + imfGetCursorCapsMode, + imfGetCursorPosition, + imfGetExtractedText, + imfGetSelectedText, + imfGetTextAfterCursor, + imfGetTextBeforeCursor, + imfPerformEditorAction, + imfReportFullscreenMode, + NULL, //ic_send_key_event + imfSendEvent, + imfSendAsyncEvent, + imfSetComposingRegion, + imfSetComposingText, + imfSetSelection, + NULL, //ic_set_candidates, +}; + +static void +initEvent(event_t *pEvent, const input_session_t *pSession, EventType eventType, int eventId) +{ + static int s_transactionId; + + // Make sure structure is squeaky clean since it's not clear just what is significant. + memset(pEvent, 0, sizeof(event_t)); + pEvent->event_type = eventType; + pEvent->event_id = eventId; + pEvent->pid = getpid(); + pEvent->component_id = pSession->component_id; + pEvent->transaction_id = ++s_transactionId; +} + +spannable_string_t *toSpannableString(const QString &text) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << text; +#endif + + spannable_string_t *pString = reinterpret_cast(malloc(sizeof(spannable_string_t))); + pString->str = (wchar_t *)malloc(sizeof(wchar_t) * text.length() + 1); + pString->length = text.length(); + pString->spans = NULL; + pString->spans_count = 0; + + const QChar *pData = text.constData(); + wchar_t *pDst = pString->str; + + while (!pData->isNull()) + { + *pDst = pData->unicode(); + pDst++; + pData++; + } + *pDst = 0; + + return pString; +} + +} // namespace + +static const input_session_t *(*p_ictrl_open_session)(connection_interface_t *) = 0; +static void (*p_ictrl_close_session)(input_session_t *) = 0; +static int32_t (*p_ictrl_dispatch_event)(event_t*) = 0; +static int32_t (*p_imf_client_init)() = 0; +static void (*p_imf_client_disconnect)() = 0; +static int32_t (*p_vkb_init_selection_service)() = 0; +static int32_t (*p_ictrl_get_num_active_sessions)() = 0; +static bool s_imfInitFailed = false; + +static bool imfAvailable() +{ + static bool s_imfDisabled = getenv("DISABLE_IMF") != NULL; + static bool s_imfReady = false; + + if ( s_imfInitFailed || s_imfDisabled) { + return false; + } + else if ( s_imfReady ) { + return true; + } + + if ( p_imf_client_init == NULL ) { + void *handle = dlopen("libinput_client.so.1", 0); + if ( handle ) { + p_imf_client_init = (int32_t (*)()) dlsym(handle, "imf_client_init"); + p_imf_client_disconnect = (void (*)()) dlsym(handle, "imf_client_disconnect"); + p_ictrl_open_session = (const input_session_t *(*)(connection_interface_t *))dlsym(handle, "ictrl_open_session"); + p_ictrl_close_session = (void (*)(input_session_t *))dlsym(handle, "ictrl_close_session"); + p_ictrl_dispatch_event = (int32_t (*)(event_t *))dlsym(handle, "ictrl_dispatch_event"); + p_vkb_init_selection_service = (int32_t (*)())dlsym(handle, "vkb_init_selection_service"); + p_ictrl_get_num_active_sessions = (int32_t (*)())dlsym(handle, "ictrl_get_num_active_sessions"); + } + else + { + qCritical() << Q_FUNC_INFO << "libinput_client.so.1 is not present - IMF services are disabled."; + s_imfDisabled = true; + return false; + } + if ( p_imf_client_init && p_ictrl_open_session && p_ictrl_dispatch_event ) { + s_imfReady = true; + } + else { + p_ictrl_open_session = NULL; + p_ictrl_dispatch_event = NULL; + s_imfDisabled = true; + qCritical() << Q_FUNC_INFO << "libinput_client.so.1 did not contain the correct symbols, library mismatch? IMF services are disabled."; + return false; + } + } + + return s_imfReady; +} + +QBBInputContext::QBBInputContext(): + QPlatformInputContext(), + m_lastCaretPos(0), + m_isComposing(false), + m_inputPanelVisible(false), + m_inputPanelLocale(QLocale::c()) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!imfAvailable()) + return; + + if ( p_imf_client_init() != 0 ) { + s_imfInitFailed = true; + qCritical("imf_client_init failed - IMF services will be unavailable"); + } + + QCoreApplication::instance()->installEventFilter(this); + + // p_vkb_init_selection_service(); + + QBBVirtualKeyboard &keyboard = QBBVirtualKeyboard::instance(); + connect(&keyboard, SIGNAL(visibilityChanged(bool)), this, SLOT(keyboardVisibilityChanged(bool))); + connect(&keyboard, SIGNAL(localeChanged(QLocale)), this, SLOT(keyboardLocaleChanged(QLocale))); + keyboardVisibilityChanged(keyboard.isVisible()); + keyboardLocaleChanged(keyboard.locale()); + + QInputMethod *inputMethod = qApp->inputMethod(); + connect(inputMethod, SIGNAL(inputItemChanged()), this, SLOT(inputItemChanged())); + +} + +QBBInputContext::~QBBInputContext() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!imfAvailable()) + return; + + QCoreApplication::instance()->removeEventFilter(this); + p_imf_client_disconnect(); +} + +#define getarg(type, name) type name = imfEvent->mArgs[qs(#name)].value() +#define getparg(type, name) type name = (type)(imfEvent->mArgs[qs(#name)].value()) + +bool QBBInputContext::isValid() const +{ + return imfAvailable(); +} + +bool QBBInputContext::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == ImfEvent::sUserEventType) { + // Forward the event to our real handler. + ImfEvent *imfEvent = static_cast(event); + switch (imfEvent->m_imfType) { + case ImfBeginBatchEdit: { + int32_t ret = onBeginBatchEdit(imfEvent->m_session); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfClearMetaKeyStates: { + getarg(int32_t, states); + int32_t ret = onClearMetaKeyStates(imfEvent->m_session, states); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfCommitText: { + getparg(spannable_string_t*, text); + getarg(int32_t, new_cursor_position); + int32_t ret = onCommitText(imfEvent->m_session, text, new_cursor_position); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfDeleteSurroundingText: { + getarg(int32_t, left_length); + getarg(int32_t, right_length); + int32_t ret = onDeleteSurroundingText(imfEvent->m_session, left_length, right_length); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfEndBatchEdit: { + int32_t ret = onEndBatchEdit(imfEvent->m_session); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfFinishComposingText: { + int32_t ret = onFinishComposingText(imfEvent->m_session); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfGetCursorCapsMode: { + getarg(int32_t, req_modes); + int32_t ret = onGetCursorCapsMode(imfEvent->m_session, req_modes); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfGetCursorPosition: { + int32_t ret = onGetCursorPosition(imfEvent->m_session); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfGetExtractedText: { + getparg(extracted_text_request_t*, request); + getarg(int32_t, flags); + extracted_text_t *ret = onGetExtractedText(imfEvent->m_session, request, flags); + imfEvent->m_result->setResult(QVariant::fromValue(static_cast(ret))); + break; + } + + case ImfGetSelectedText: { + getarg(int32_t, flags); + spannable_string_t *ret = onGetSelectedText(imfEvent->m_session, flags); + imfEvent->m_result->setResult(QVariant::fromValue(static_cast(ret))); + break; + } + + case ImfGetTextAfterCursor: { + getarg(int32_t, n); + getarg(int32_t, flags); + spannable_string_t *ret = onGetTextAfterCursor(imfEvent->m_session, n, flags); + imfEvent->m_result->setResult(QVariant::fromValue(static_cast(ret))); + break; + } + + case ImfGetTextBeforeCursor: { + getarg(int32_t, n); + getarg(int32_t, flags); + spannable_string_t *ret = onGetTextBeforeCursor(imfEvent->m_session, n, flags); + imfEvent->m_result->setResult(QVariant::fromValue((void*)ret)); + break; + } + + case ImfPerformEditorAction: { + getarg(int32_t, editor_action); + int32_t ret = onPerformEditorAction(imfEvent->m_session, editor_action); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfReportFullscreenMode: { + getarg(int32_t, enabled); + int32_t ret = onReportFullscreenMode(imfEvent->m_session, enabled); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfSendEvent: { + getparg(event_t*, event); + onSendEvent(imfEvent->m_session, event); + break; + } + + case ImfSendAsyncEvent: { + getparg(event_t*, event); + onSendAsyncEvent(imfEvent->m_session, event); + break; + } + + case ImfSetComposingRegion: { + getarg(int32_t, start); + getarg(int32_t, end); + int32_t ret = onSetComposingRegion(imfEvent->m_session, start, end); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfSetComposingText: { + getparg(spannable_string_t*, text); + getarg(int32_t, new_cursor_position); + int32_t ret = onSetComposingText(imfEvent->m_session, text, new_cursor_position); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + + case ImfSetSelection: { + getarg(int32_t, start); + getarg(int32_t, end); + int32_t ret = onSetSelection(imfEvent->m_session, start, end); + imfEvent->m_result->setResult(QVariant::fromValue(ret)); + break; + } + }; //switch + + return true; + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } +} + +bool QBBInputContext::filterEvent( const QEvent *event ) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << event; +#endif + switch (event->type()) { + case QEvent::CloseSoftwareInputPanel: { + return dispatchCloseSoftwareInputPanel(); + } + case QEvent::RequestSoftwareInputPanel: { + return dispatchRequestSoftwareInputPanel(); + } + default: + return false; + } +} + +void QBBInputContext::reset() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + endComposition(); +} + +void QBBInputContext::update(Qt::InputMethodQueries queries) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + reset(); + + QPlatformInputContext::update(queries); +} + +void QBBInputContext::closeSession() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO +#endif + if (!imfAvailable()) + return; + + if (sInputSession) { + p_ictrl_close_session((input_session_t *)sInputSession); + sInputSession = 0; + } +} + +void QBBInputContext::openSession() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO +#endif + if (!imfAvailable()) + return; + + closeSession(); + sInputSession = p_ictrl_open_session(&ic_funcs); +} + +bool QBBInputContext::hasSession() +{ + return sInputSession != 0; +} + +bool QBBInputContext::hasSelectedText() +{ + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!input) + return false; + + QInputMethodQueryEvent query(Qt::ImCurrentSelection); + QCoreApplication::sendEvent(input, &query); + + return !query.value(Qt::ImCurrentSelection).toString().isEmpty(); +} + +bool QBBInputContext::dispatchRequestSoftwareInputPanel() +{ + QBBVirtualKeyboard::instance().showKeyboard(); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << "QBB: requesting virtual keyboard"; +#endif + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return true; + + if (!hasSession()) + openSession(); + + // This also means that the caret position has moved + QInputMethodQueryEvent query(Qt::ImCursorPosition); + QCoreApplication::sendEvent(input, &query); + int caretPos = query.value(Qt::ImCursorPosition).toInt(); + caret_event_t caretEvent; + memset(&caretEvent, 0, sizeof(caret_event_t)); + initEvent(&caretEvent.event, sInputSession, EVENT_CARET, CARET_POS_CHANGED); + caretEvent.old_pos = m_lastCaretPos; + m_lastCaretPos = caretEvent.new_pos = caretPos; + p_ictrl_dispatch_event((event_t *)&caretEvent); + return true; +} + +bool QBBInputContext::dispatchCloseSoftwareInputPanel() +{ + QBBVirtualKeyboard::instance().hideKeyboard(); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << "QBB: hiding virtual keyboard"; +#endif + + // This also means we are stopping composition, but we should already have done that. + return true; +} + +/** + * IMF Event Dispatchers. + */ +bool QBBInputContext::dispatchFocusEvent(FocusEventId id, int hints) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!sInputSession) { + qWarning() << Q_FUNC_INFO << "Attempt to dispatch a focus event with no input session."; + return false; + } + + if (!imfAvailable()) + return false; + + // Set the last caret position to 0 since we don't really have one and we don't + // want to have the old one. + m_lastCaretPos = 0; + + focus_event_t focusEvent; + memset(&focusEvent, 0, sizeof(focusEvent)); + initEvent(&focusEvent.event, sInputSession, EVENT_FOCUS, id); + focusEvent.style = DEFAULT_STYLE; + + if (hints && Qt::ImhNoPredictiveText) + focusEvent.style |= NO_PREDICTION | NO_AUTO_CORRECTION; + if (hints && Qt::ImhNoAutoUppercase) + focusEvent.style |= NO_AUTO_TEXT; + + p_ictrl_dispatch_event((event_t *)&focusEvent); + + return true; +} + +bool QBBInputContext::handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap) +{ + if (!imfAvailable()) + return false; + + int key = (flags & KEY_SYM_VALID) ? sym : cap; + bool navKey = false; + switch ( key ) { + case KEYCODE_RETURN: + /* In a single line edit we should end composition because enter might be used by something. + endComposition(); + return false;*/ + break; + + case KEYCODE_BACKSPACE: + case KEYCODE_DELETE: + // If there is a selection range, then we want a delete key to operate on that (by + // deleting the contents of the select range) rather than operating on the composition + // range. + if (hasSelectedText()) + return false; + break; + case KEYCODE_LEFT: + key = NAVIGATE_LEFT; + navKey = true; + break; + case KEYCODE_RIGHT: + key = NAVIGATE_RIGHT; + navKey = true; + break; + case KEYCODE_UP: + key = NAVIGATE_UP; + navKey = true; + break; + case KEYCODE_DOWN: + key = NAVIGATE_DOWN; + navKey = true; + break; + case KEYCODE_CAPS_LOCK: + case KEYCODE_LEFT_SHIFT: + case KEYCODE_RIGHT_SHIFT: + case KEYCODE_LEFT_CTRL: + case KEYCODE_RIGHT_CTRL: + case KEYCODE_LEFT_ALT: + case KEYCODE_RIGHT_ALT: + case KEYCODE_MENU: + case KEYCODE_LEFT_HYPER: + case KEYCODE_RIGHT_HYPER: + case KEYCODE_INSERT: + case KEYCODE_HOME: + case KEYCODE_PG_UP: + case KEYCODE_END: + case KEYCODE_PG_DOWN: + // Don't send these + key = 0; + break; + } + + if ( mod & KEYMOD_CTRL ) { + // If CTRL is pressed, just let AIR handle it. But terminate any composition first + //endComposition(); + return false; + } + + // Pass the keys we don't know about on through + if ( key == 0 ) + return false; + + // IMF doesn't need key releases so just swallow them. + if (!(flags & KEY_DOWN)) + return true; + + if ( navKey ) { + // Even if we're forwarding up events, we can't do this for + // navigation keys. + if ( flags & KEY_DOWN ) { + navigation_event_t navEvent; + initEvent(&navEvent.event, sInputSession, EVENT_NAVIGATION, key); + navEvent.magnitude = 1; +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "dispatch navigation event " << key; +#endif + p_ictrl_dispatch_event(&navEvent.event); + } + } + else { + key_event_t keyEvent; + initEvent(&keyEvent.event, sInputSession, EVENT_KEY, flags & KEY_DOWN ? IMF_KEY_DOWN : IMF_KEY_UP); + keyEvent.key_code = key; + keyEvent.character = 0; + keyEvent.meta_key_state = 0; + + p_ictrl_dispatch_event(&keyEvent.event); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "dispatch key event " << key; +#endif + } + + scan = 0; + return true; +} + +void QBBInputContext::endComposition() +{ + if (!m_isComposing) + return; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return; + + QList attributes; + QInputMethodEvent event(QLatin1String(""), attributes); + event.setCommitString(m_composingText); + m_composingText = QString(); + m_isComposing = false; + QCoreApplication::sendEvent(input, &event); + + action_event_t actionEvent; + memset(&actionEvent, 0, sizeof(actionEvent)); + initEvent(&actionEvent.event, sInputSession, EVENT_ACTION, ACTION_END_COMPOSITION); + p_ictrl_dispatch_event(&actionEvent.event); +} + +void QBBInputContext::setComposingText(QString const& composingText) +{ + m_composingText = composingText; + m_isComposing = true; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return; + + QList attributes; + QTextCharFormat format; + format.setFontUnderline(true); + attributes.push_back(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, composingText.length(), format)); + + QInputMethodEvent event(composingText, attributes); + + QCoreApplication::sendEvent(input, &event); +} + +int32_t QBBInputContext::processEvent(event_t *event) +{ + int32_t result = -1; + switch (event->event_type) { + case EVENT_SPELL_CHECK: { + #if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "EVENT_SPELL_CHECK"; + #endif + result = 0; + break; + } + + case EVENT_NAVIGATION: { + #if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "EVENT_NAVIGATION"; + #endif + + int key = event->event_id == NAVIGATE_UP ? KEYCODE_UP : + event->event_id == NAVIGATE_DOWN ? KEYCODE_DOWN : + event->event_id == NAVIGATE_LEFT ? KEYCODE_LEFT : + event->event_id == NAVIGATE_RIGHT ? KEYCODE_RIGHT : 0; + + QBBEventThread::injectKeyboardEvent(KEY_DOWN | KEY_CAP_VALID, key, 0, 0, 0); + QBBEventThread::injectKeyboardEvent(KEY_CAP_VALID, key, 0, 0, 0); + result = 0; + break; + } + + case EVENT_KEY: { + #if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "EVENT_KEY"; + #endif + key_event_t *kevent = static_cast(event); + + QBBEventThread::injectKeyboardEvent(KEY_DOWN | KEY_SYM_VALID | KEY_CAP_VALID, kevent->key_code, 0, 0, kevent->key_code); + QBBEventThread::injectKeyboardEvent(KEY_SYM_VALID | KEY_CAP_VALID, kevent->key_code, 0, 0, kevent->key_code); + + result = 0; + break; + } + + case EVENT_ACTION: + // Don't care, indicates that IMF is done. + break; + + case EVENT_CARET: + case EVENT_NOTHING: + case EVENT_FOCUS: + case EVENT_USER_ACTION: + case EVENT_STROKE: + case EVENT_INVOKE_LATER: + qCritical() << Q_FUNC_INFO << "Unsupported event type: " << event->event_type; + break; + default: + qCritical() << Q_FUNC_INFO << "Unknown event type: " << event->event_type; + } + return result; +} + +/** + * IMF Event Handlers + */ + +int32_t QBBInputContext::onBeginBatchEdit(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + // We don't care. + return 0; +} + +int32_t QBBInputContext::onClearMetaKeyStates(input_session_t *ic, int32_t states) +{ + Q_UNUSED(states); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + // Should never get called. + qCritical() << Q_FUNC_INFO << "onClearMetaKeyStates is unsupported."; + return 0; +} + +int32_t QBBInputContext::onCommitText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position) +{ + Q_UNUSED(new_cursor_position); // TODO: How can we set the cursor position it's not part of the API. + if (!isSessionOkay(ic)) + return 0; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return 0; + + QString commitString = QString::fromWCharArray(text->str, text->length); + +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "Committing [" << commitString << "]"; +#endif + + QList attributes; + QInputMethodEvent event(QLatin1String(""), attributes); + event.setCommitString(commitString, 0, 0); + + QCoreApplication::sendEvent(input, &event); + m_composingText = QString(); + + return 0; +} + +int32_t QBBInputContext::onDeleteSurroundingText(input_session_t *ic, int32_t left_length, int32_t right_length) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "L:" << left_length << " R:" << right_length; +#endif + + if (!isSessionOkay(ic)) + return 0; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return 0; + + if (hasSelectedText()) { + QBBEventThread::injectKeyboardEvent(KEY_DOWN | KEY_CAP_VALID, KEYCODE_DELETE, 0, 0, 0); + QBBEventThread::injectKeyboardEvent(KEY_CAP_VALID, KEYCODE_DELETE, 0, 0, 0); + reset(); + return 0; + } + + int replacementLength = left_length + right_length; + int replacementStart = -left_length; + + QList attributes; + QInputMethodEvent event(QLatin1String(""), attributes); + event.setCommitString(QLatin1String(""), replacementStart, replacementLength); + QCoreApplication::sendEvent(input, &event); + + return 0; +} + +int32_t QBBInputContext::onEndBatchEdit(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + return 0; +} + +int32_t QBBInputContext::onFinishComposingText(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return 0; + + // Only update the control, no need to send a message back to imf (don't call + // end composition) + QList attributes; + QInputMethodEvent event(QLatin1String(""), attributes); + event.setCommitString(m_composingText); + m_composingText = QString(); + m_isComposing = false; + QCoreApplication::sendEvent(input, &event); + + return 0; +} + +int32_t QBBInputContext::onGetCursorCapsMode(input_session_t *ic, int32_t req_modes) +{ + Q_UNUSED(req_modes); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + // Should never get called. + qCritical() << Q_FUNC_INFO << "onGetCursorCapsMode is unsupported."; + + return 0; +} + +int32_t QBBInputContext::onGetCursorPosition(input_session_t *ic) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return 0; + + QInputMethodQueryEvent query(Qt::ImCursorPosition); + QCoreApplication::sendEvent(input, &query); + m_lastCaretPos = query.value(Qt::ImCursorPosition).toInt(); + + return m_lastCaretPos; +} + +extracted_text_t *QBBInputContext::onGetExtractedText(input_session_t *ic, extracted_text_request_t *request, int32_t flags) +{ + Q_UNUSED(flags); + Q_UNUSED(request); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) { + extracted_text_t *et = (extracted_text_t *)calloc(sizeof(extracted_text_t),1); + et->text = reinterpret_cast(calloc(sizeof(spannable_string_t),1)); + return et; + } + + // Used to update dictionaries, but not supported right now. + extracted_text_t *et = (extracted_text_t *)calloc(sizeof(extracted_text_t),1); + et->text = reinterpret_cast(calloc(sizeof(spannable_string_t),1)); + + return et; +} + +spannable_string_t *QBBInputContext::onGetSelectedText(input_session_t *ic, int32_t flags) +{ + Q_UNUSED(flags); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return toSpannableString(""); + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return 0; + + QInputMethodQueryEvent query(Qt::ImCurrentSelection); + QCoreApplication::sendEvent(input, &query); + QString text = query.value(Qt::ImCurrentSelection).toString(); + + return toSpannableString(text); +} + +spannable_string_t *QBBInputContext::onGetTextAfterCursor(input_session_t *ic, int32_t n, int32_t flags) +{ + Q_UNUSED(flags); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return toSpannableString(""); + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return toSpannableString(""); + + QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImSurroundingText); + QCoreApplication::sendEvent(input, &query); + QString text = query.value(Qt::ImSurroundingText).toString(); + m_lastCaretPos = query.value(Qt::ImCursorPosition).toInt(); + + return toSpannableString(text.mid(m_lastCaretPos+1, n)); +} + +spannable_string_t *QBBInputContext::onGetTextBeforeCursor(input_session_t *ic, int32_t n, int32_t flags) +{ + Q_UNUSED(flags); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return toSpannableString(""); + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return toSpannableString(""); + + QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImSurroundingText); + QCoreApplication::sendEvent(input, &query); + QString text = query.value(Qt::ImSurroundingText).toString(); + m_lastCaretPos = query.value(Qt::ImCursorPosition).toInt(); + + if (n < m_lastCaretPos) { + return toSpannableString(text.mid(m_lastCaretPos - n, n)); + } else { + return toSpannableString(text.mid(0, m_lastCaretPos)); + } +} + +int32_t QBBInputContext::onPerformEditorAction(input_session_t *ic, int32_t editor_action) +{ + Q_UNUSED(editor_action); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + // Should never get called. + qCritical() << Q_FUNC_INFO << "onPerformEditorAction is unsupported."; + + return 0; +} + +int32_t QBBInputContext::onReportFullscreenMode(input_session_t *ic, int32_t enabled) +{ + Q_UNUSED(enabled); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + // Should never get called. + qCritical() << Q_FUNC_INFO << "onReportFullscreenMode is unsupported."; + + return 0; +} + +int32_t QBBInputContext::onSendEvent(input_session_t *ic, event_t *event) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + return processEvent(event); +} + +int32_t QBBInputContext::onSendAsyncEvent(input_session_t *ic, event_t *event) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + return processEvent(event); +} + +int32_t QBBInputContext::onSetComposingRegion(input_session_t *ic, int32_t start, int32_t end) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return 0; + + QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImSurroundingText); + QCoreApplication::sendEvent(input, &query); + QString text = query.value(Qt::ImSurroundingText).toString(); + m_lastCaretPos = query.value(Qt::ImCursorPosition).toInt(); + + QString empty = QString::fromLatin1(""); + text = text.mid(start, end - start); + + // Delete the current text. + QList attributes; + QInputMethodEvent event(empty, attributes); + event.setCommitString(empty, start - m_lastCaretPos, end - start); + QCoreApplication::sendEvent(input, &event); + + // Move the specified text into a preedit string. + setComposingText(text); + + return 0; +} + +int32_t QBBInputContext::onSetComposingText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position) +{ + Q_UNUSED(new_cursor_position); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + QInputPanel *panel = qApp->inputPanel(); + QObject *input = panel->inputItem(); + if (!imfAvailable() || !input) + return 0; + + m_isComposing = true; + + QString preeditString = QString::fromWCharArray(text->str, text->length); + setComposingText(preeditString); + + return 0; +} + +int32_t QBBInputContext::onSetSelection(input_session_t *ic, int32_t start, int32_t end) +{ + Q_UNUSED(start); + Q_UNUSED(end); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + + if (!isSessionOkay(ic)) + return 0; + + // Should never get called. + qCritical() << Q_FUNC_INFO << "onSetSelection is unsupported."; + + return 0; +} + +void QBBInputContext::showInputPanel() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + dispatchRequestSoftwareInputPanel(); +} + +void QBBInputContext::hideInputPanel() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + dispatchCloseSoftwareInputPanel(); +} + +bool QBBInputContext::isInputPanelVisible() const +{ + return m_inputPanelVisible; +} + +QLocale QBBInputContext::locale() const +{ + return m_inputPanelLocale; +} + +void QBBInputContext::keyboardVisibilityChanged(bool visible) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "visible=" << visible; +#endif + if (m_inputPanelVisible != visible) { + m_inputPanelVisible = visible; + emitInputPanelVisibleChanged(); + } +} + +void QBBInputContext::keyboardLocaleChanged(const QLocale &locale) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "locale=" << locale; +#endif + if (m_inputPanelLocale != locale) { + m_inputPanelLocale = locale; + emitLocaleChanged(); + } +} + +void QBBInputContext::inputItemChanged() +{ + QInputMethod *inputMethod = qApp->inputMethod(); + QObject *inputItem = inputMethod->inputItem(); + +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "input item=" << inputItem; +#endif + + if (!inputItem) { + if (m_inputPanelVisible) + hideInputPanel(); + } else { + if (qobject_cast(inputItem)) { + QBBVirtualKeyboard::instance().setKeyboardMode(QBBVirtualKeyboard::NumPunc); + } else { + QBBVirtualKeyboard::instance().setKeyboardMode(QBBVirtualKeyboard::Default); + } + if (!m_inputPanelVisible) + showInputPanel(); + } +} diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_imf.h b/src/plugins/platforms/blackberry/qbbinputcontext_imf.h new file mode 100644 index 0000000000..135ec02971 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbinputcontext_imf.h @@ -0,0 +1,132 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBINPUTCONTEXT_H +#define QBBINPUTCONTEXT_H + +#include + +#include +#include +#include + +#include "imf/imf_client.h" +#include "imf/input_control.h" + +QT_BEGIN_NAMESPACE + +class QBBInputContext : public QPlatformInputContext +{ + Q_OBJECT +public: + QBBInputContext(); + ~QBBInputContext(); + + virtual bool isValid() const; + + virtual bool filterEvent(const QEvent *event); + virtual void reset(); + virtual void update(Qt::InputMethodQueries); + bool handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap); + + virtual void showInputPanel(); + virtual void hideInputPanel(); + virtual bool isInputPanelVisible() const; + + virtual QLocale locale() const; + +protected: + // Filters only for IMF events. + bool eventFilter(QObject *obj, QEvent *event); + +private Q_SLOTS: + void keyboardVisibilityChanged(bool visible); + void keyboardLocaleChanged(const QLocale &locale); + void inputItemChanged(); + +private: + // IMF Event dispatchers + bool dispatchFocusEvent(FocusEventId id, int hints = Qt::ImhNone); + bool dispatchRequestSoftwareInputPanel(); + bool dispatchCloseSoftwareInputPanel(); + int32_t processEvent(event_t *event); + + void closeSession(); + void openSession(); + bool hasSession(); + void endComposition(); + void setComposingText(QString const &composingText); + bool hasSelectedText(); + + // IMF Event handlers - these events will come in from QCoreApplication. + int32_t onBeginBatchEdit(input_session_t *ic); + int32_t onClearMetaKeyStates(input_session_t *ic, int32_t states); + int32_t onCommitText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position); + int32_t onDeleteSurroundingText(input_session_t *ic, int32_t left_length, int32_t right_length); + int32_t onEndBatchEdit(input_session_t *ic); + int32_t onFinishComposingText(input_session_t *ic); + int32_t onGetCursorCapsMode(input_session_t *ic, int32_t req_modes); + int32_t onGetCursorPosition(input_session_t *ic); + extracted_text_t *onGetExtractedText(input_session_t *ic, extracted_text_request_t *request, int32_t flags); + spannable_string_t *onGetSelectedText(input_session_t *ic, int32_t flags); + spannable_string_t *onGetTextAfterCursor(input_session_t *ic, int32_t n, int32_t flags); + spannable_string_t *onGetTextBeforeCursor(input_session_t *ic, int32_t n, int32_t flags); + int32_t onPerformEditorAction(input_session_t *ic, int32_t editor_action); + int32_t onReportFullscreenMode(input_session_t *ic, int32_t enabled); + int32_t onSendEvent(input_session_t *ic, event_t *event); + int32_t onSendAsyncEvent(input_session_t *ic, event_t *event); + int32_t onSetComposingRegion(input_session_t *ic, int32_t start, int32_t end); + int32_t onSetComposingText(input_session_t *ic, spannable_string_t *text, int32_t new_cursor_position); + int32_t onSetSelection(input_session_t *ic, int32_t start, int32_t end); + int32_t onForceUpdate(); + + int m_lastCaretPos; + bool m_isComposing; + QString m_composingText; + bool m_inputPanelVisible; + QLocale m_inputPanelLocale; +}; + +Q_DECLARE_METATYPE(extracted_text_t*) + +QT_END_NAMESPACE + +#endif // QBBINPUTCONTEXT_H diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp new file mode 100644 index 0000000000..abe84e2e53 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.cpp @@ -0,0 +1,187 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbinputcontext_noimf.h" +#include "qbbvirtualkeyboard.h" + +#include +#include +#include + +QBBInputContext::QBBInputContext() : + QPlatformInputContext(), + m_inputPanelVisible(false), + m_inputPanelLocale(QLocale::c()) +{ + QBBVirtualKeyboard &keyboard = QBBVirtualKeyboard::instance(); + connect(&keyboard, SIGNAL(visibilityChanged(bool)), this, SLOT(keyboardVisibilityChanged(bool))); + connect(&keyboard, SIGNAL(localeChanged(QLocale)), this, SLOT(keyboardLocaleChanged(QLocale))); + keyboardVisibilityChanged(keyboard.isVisible()); + keyboardLocaleChanged(keyboard.locale()); + + QInputMethod *inputMethod = qApp->inputMethod(); + connect(inputMethod, SIGNAL(inputItemChanged()), this, SLOT(inputItemChanged())); +} + +QBBInputContext::~QBBInputContext() +{ +} + +bool QBBInputContext::isValid() const +{ + return true; +} + +bool QBBInputContext::hasPhysicalKeyboard() +{ + // TODO: This should query the system to check if a USB keyboard is connected. + return false; +} + +void QBBInputContext::reset() +{ +} + +bool QBBInputContext::filterEvent( const QEvent *event ) +{ + if (hasPhysicalKeyboard()) + return false; + + if (event->type() == QEvent::CloseSoftwareInputPanel) { + QBBVirtualKeyboard::instance().hideKeyboard(); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << "QBB: hiding virtual keyboard"; +#endif + return false; + } + + if (event->type() == QEvent::RequestSoftwareInputPanel) { + QBBVirtualKeyboard::instance().showKeyboard(); +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << "QBB: requesting virtual keyboard"; +#endif + return false; + } + + return false; + +} + +bool QBBInputContext::handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap) +{ + Q_UNUSED(flags); + Q_UNUSED(sym); + Q_UNUSED(mod); + Q_UNUSED(scan); + Q_UNUSED(cap); + return false; +} + +void QBBInputContext::showInputPanel() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + QBBVirtualKeyboard::instance().showKeyboard(); +} + +void QBBInputContext::hideInputPanel() +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + QBBVirtualKeyboard::instance().hideKeyboard(); +} + +bool QBBInputContext::isInputPanelVisible() const +{ + return m_inputPanelVisible; +} + +QLocale QBBInputContext::locale() const +{ + return m_inputPanelLocale; +} + +void QBBInputContext::keyboardVisibilityChanged(bool visible) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "visible=" << visible; +#endif + if (m_inputPanelVisible != visible) { + m_inputPanelVisible = visible; + emitInputPanelVisibleChanged(); + } +} + +void QBBInputContext::keyboardLocaleChanged(const QLocale &locale) +{ +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "locale=" << locale; +#endif + if (m_inputPanelLocale != locale) { + m_inputPanelLocale = locale; + emitLocaleChanged(); + } +} + +void QBBInputContext::inputItemChanged() +{ + QInputMethod *inputMethod = qApp->inputMethod(); + QObject *inputItem = inputMethod->inputItem(); + +#if defined(QBBINPUTCONTEXT_DEBUG) + qDebug() << Q_FUNC_INFO << "input item=" << inputItem; +#endif + + if (!inputItem) { + if (m_inputPanelVisible) + hideInputPanel(); + } else { + if (qobject_cast(inputItem)) { + QBBVirtualKeyboard::instance().setKeyboardMode(QBBVirtualKeyboard::NumPunc); + } else { + QBBVirtualKeyboard::instance().setKeyboardMode(QBBVirtualKeyboard::Default); + } + if (!m_inputPanelVisible) + showInputPanel(); + } +} diff --git a/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h new file mode 100644 index 0000000000..3d4d6da830 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbinputcontext_noimf.h @@ -0,0 +1,84 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBINPUTCONTEXT_H +#define QBBINPUTCONTEXT_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QBBInputContext : public QPlatformInputContext +{ + Q_OBJECT +public: + explicit QBBInputContext(); + ~QBBInputContext(); + + virtual bool isValid() const; + + void reset(); + virtual bool filterEvent( const QEvent *event ); + bool handleKeyboardEvent(int flags, int sym, int mod, int scan, int cap); + + virtual void showInputPanel(); + virtual void hideInputPanel(); + virtual bool isInputPanelVisible() const; + + virtual QLocale locale() const; + +private Q_SLOTS: + void keyboardVisibilityChanged(bool visible); + void keyboardLocaleChanged(const QLocale &locale); + void inputItemChanged(); + +private: + bool hasPhysicalKeyboard(); + + bool m_inputPanelVisible; + QLocale m_inputPanelLocale; +}; + +QT_END_NAMESPACE + +#endif // QBBINPUTCONTEXT_H diff --git a/src/plugins/platforms/blackberry/qbbintegration.cpp b/src/plugins/platforms/blackberry/qbbintegration.cpp new file mode 100644 index 0000000000..9f922a419e --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbintegration.cpp @@ -0,0 +1,293 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbintegration.h" +#include "qbbeventthread.h" +#include "qbbglbackingstore.h" +#include "qbbglcontext.h" +#include "qbbnavigatorthread.h" +#include "qbbrasterbackingstore.h" +#include "qbbscreen.h" +#include "qbbwindow.h" +#include "qbbvirtualkeyboard.h" +#include "qbbclipboard.h" +#include "qbbglcontext.h" + +#if defined(QBB_IMF) +#include "qbbinputcontext_imf.h" +#else +#include "qbbinputcontext_noimf.h" +#endif + +#include "private/qgenericunixfontdatabase_p.h" +#include "private/qgenericunixeventdispatcher_p.h" + +#include +#include +#include + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +QBBWindowMapper QBBIntegration::ms_windowMapper; +QMutex QBBIntegration::ms_windowMapperMutex; + +QBBIntegration::QBBIntegration() + : QPlatformIntegration() + , m_eventThread(0) + , m_navigatorThread(0) + , m_inputContext(0) + , m_fontDatabase(new QGenericUnixFontDatabase()) + , m_paintUsingOpenGL(false) + , m_eventDispatcher(createUnixEventDispatcher()) +#ifndef QT_NO_CLIPBOARD + , m_clipboard(0) +#endif +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Open connection to QNX composition manager + errno = 0; + int result = screen_create_context(&m_screenContext, SCREEN_APPLICATION_CONTEXT); + if (result != 0) { + qFatal("QBB: failed to connect to composition manager, errno=%d", errno); + } + + // Create displays for all possible screens (which may not be attached) + QBBScreen::createDisplays(m_screenContext); + Q_FOREACH (QPlatformScreen *screen, QBBScreen::screens()) { + screenAdded(screen); + } + + // Initialize global OpenGL resources + QBBGLContext::initialize(); + + // Create/start event thread + m_eventThread = new QBBEventThread(m_screenContext, *QBBScreen::primaryDisplay()); + m_eventThread->start(); + + // Create/start navigator thread + m_navigatorThread = new QBBNavigatorThread(*QBBScreen::primaryDisplay()); + m_navigatorThread->start(); + + // Create/start the keyboard class. + QBBVirtualKeyboard::instance(); + + // Set up the input context + m_inputContext = new QBBInputContext; +} + +QBBIntegration::~QBBIntegration() +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << "QBB: platform plugin shutdown begin"; +#endif + // Destroy the keyboard class. + QBBVirtualKeyboard::destroy(); + +#ifndef QT_NO_CLIPBOARD + // Delete the clipboard + delete m_clipboard; +#endif + + // Stop/destroy event thread + delete m_eventThread; + + // Stop/destroy navigator thread + delete m_navigatorThread; + + // Destroy all displays + QBBScreen::destroyDisplays(); + + // Close connection to QNX composition manager + screen_destroy_context(m_screenContext); + + // Cleanup global OpenGL resources + QBBGLContext::shutdown(); + +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << "QBB: platform plugin shutdown end"; +#endif +} + +bool QBBIntegration::hasCapability(QPlatformIntegration::Capability cap) const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + switch (cap) { + case ThreadedPixmaps: return true; +#if defined(QT_OPENGL_ES) + case OpenGL: + return true; +#endif + default: return QPlatformIntegration::hasCapability(cap); + } +} + +QPlatformWindow *QBBIntegration::createPlatformWindow(QWindow *window) const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // New windows are created on the primary display. + return new QBBWindow(window, m_screenContext); +} + +QPlatformBackingStore *QBBIntegration::createPlatformBackingStore(QWindow *window) const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + if (paintUsingOpenGL()) + return new QBBGLBackingStore(window); + else + return new QBBRasterBackingStore(window); +} + +QPlatformOpenGLContext *QBBIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + return new QBBGLContext(context); +} + +QPlatformInputContext *QBBIntegration::inputContext() const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + return m_inputContext; +} + +void QBBIntegration::moveToScreen(QWindow *window, int screen) +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << "QBBIntegration::moveToScreen - w=" << window << ", s=" << screen; +#endif + + // get platform window used by widget + QBBWindow *platformWindow = static_cast(window->handle()); + + // lookup platform screen by index + QBBScreen *platformScreen = static_cast(QBBScreen::screens().at(screen)); + + // move the platform window to the platform screen + platformWindow->setScreen(platformScreen); +} + +QList QBBIntegration::screens() const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + return QBBScreen::screens(); +} + +QAbstractEventDispatcher *QBBIntegration::guiThreadEventDispatcher() const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + return m_eventDispatcher; +} + +#ifndef QT_NO_CLIPBOARD +QPlatformClipboard *QBBIntegration::clipboard() const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + if (!m_clipboard) { + m_clipboard = new QBBClipboard; + } + return m_clipboard; +} +#endif + +QVariant QBBIntegration::styleHint(QPlatformIntegration::StyleHint hint) const +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + if (hint == ShowIsFullScreen) + return true; + + return QPlatformIntegration::styleHint(hint); +} + +QWindow *QBBIntegration::window(screen_window_t qnxWindow) +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + QMutexLocker locker(&ms_windowMapperMutex); + Q_UNUSED(locker); + return ms_windowMapper.value(qnxWindow, 0); +} + +void QBBIntegration::addWindow(screen_window_t qnxWindow, QWindow *window) +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + QMutexLocker locker(&ms_windowMapperMutex); + Q_UNUSED(locker); + ms_windowMapper.insert(qnxWindow, window); +} + +void QBBIntegration::removeWindow(screen_window_t qnxWindow) +{ +#if defined(QBBINTEGRATION_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + QMutexLocker locker(&ms_windowMapperMutex); + Q_UNUSED(locker); + ms_windowMapper.remove(qnxWindow); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h new file mode 100644 index 0000000000..6b54329dac --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbintegration.h @@ -0,0 +1,119 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBINTEGRATION_H +#define QBBINTEGRATION_H + +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QBBEventThread; +class QBBInputContext; +class QBBNavigatorThread; +class QBBWindow; + +#ifndef QT_NO_CLIPBOARD +class QBBClipboard; +#endif + +template class QHash; +typedef QHash QBBWindowMapper; + +class QBBIntegration : public QPlatformIntegration +{ +public: + QBBIntegration(); + virtual ~QBBIntegration(); + + virtual bool hasCapability(QPlatformIntegration::Capability cap) const; + + virtual QPlatformWindow *createPlatformWindow(QWindow *window) const; + virtual QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; + virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; + + virtual QPlatformInputContext *inputContext() const; + + virtual QList screens() const; + virtual void moveToScreen(QWindow *window, int screen); + + virtual QAbstractEventDispatcher *guiThreadEventDispatcher() const; + + virtual QPlatformFontDatabase *fontDatabase() const { return m_fontDatabase; } + +#ifndef QT_NO_CLIPBOARD + virtual QPlatformClipboard *clipboard() const; +#endif + + virtual QVariant styleHint(StyleHint hint) const; + + bool paintUsingOpenGL() const { return m_paintUsingOpenGL; } + + static QWindow *window(screen_window_t qnxWindow); + +private: + static void addWindow(screen_window_t qnxWindow, QWindow *window); + static void removeWindow(screen_window_t qnxWindow); + + screen_context_t m_screenContext; + QBBEventThread *m_eventThread; + QBBNavigatorThread *m_navigatorThread; + QBBInputContext *m_inputContext; + QPlatformFontDatabase *m_fontDatabase; + bool m_paintUsingOpenGL; + QAbstractEventDispatcher *m_eventDispatcher; +#ifndef QT_NO_CLIPBOARD + mutable QBBClipboard* m_clipboard; +#endif + + static QBBWindowMapper ms_windowMapper; + static QMutex ms_windowMapperMutex; + + friend class QBBWindow; +}; + +QT_END_NAMESPACE + +#endif // QBBINTEGRATION_H diff --git a/src/plugins/platforms/blackberry/qbbkeytranslator.h b/src/plugins/platforms/blackberry/qbbkeytranslator.h new file mode 100644 index 0000000000..fdc1220aba --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbkeytranslator.h @@ -0,0 +1,269 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBKEYTRANSLATOR_H +#define QBBKEYTRANSLATOR_H + +#include + +#if defined(QBBEVENTTHREAD_DEBUG) +#include +#endif + +QT_BEGIN_NAMESPACE + +Qt::Key keyTranslator( int key ) +{ + switch (key) { + case KEYCODE_PAUSE: + return Qt::Key_Pause; + + case KEYCODE_SCROLL_LOCK: + return Qt::Key_ScrollLock; + + case KEYCODE_PRINT: + return Qt::Key_Print; + + case KEYCODE_SYSREQ: + return Qt::Key_SysReq; + +// case KEYCODE_BREAK: + + case KEYCODE_ESCAPE: + return Qt::Key_Escape; + + case KEYCODE_BACKSPACE: + return Qt::Key_Backspace; + + case KEYCODE_TAB: + return Qt::Key_Tab; + + case KEYCODE_BACK_TAB: + return Qt::Key_Backtab; + + case KEYCODE_RETURN: + return Qt::Key_Return; + + case KEYCODE_CAPS_LOCK: + return Qt::Key_CapsLock; + + case KEYCODE_LEFT_SHIFT: + case KEYCODE_RIGHT_SHIFT: + return Qt::Key_Shift; + + case KEYCODE_LEFT_CTRL: + case KEYCODE_RIGHT_CTRL: + return Qt::Key_Control; + + case KEYCODE_LEFT_ALT: + case KEYCODE_RIGHT_ALT: + return Qt::Key_Alt; + + case KEYCODE_MENU: + return Qt::Key_Menu; + + case KEYCODE_LEFT_HYPER: + return Qt::Key_Hyper_L; + + case KEYCODE_RIGHT_HYPER: + return Qt::Key_Hyper_R; + + case KEYCODE_INSERT: + return Qt::Key_Insert; + + case KEYCODE_HOME: + return Qt::Key_Home; + + case KEYCODE_PG_UP: + return Qt::Key_PageUp; + + case KEYCODE_DELETE: + return Qt::Key_Delete; + + case KEYCODE_END: + return Qt::Key_End; + + case KEYCODE_PG_DOWN: + return Qt::Key_PageDown; + + case KEYCODE_LEFT: + return Qt::Key_Left; + + case KEYCODE_RIGHT: + return Qt::Key_Right; + + case KEYCODE_UP: + return Qt::Key_Up; + + case KEYCODE_DOWN: + return Qt::Key_Down; + + case KEYCODE_NUM_LOCK: + return Qt::Key_NumLock; + + case KEYCODE_KP_PLUS: + return Qt::Key_Plus; + + case KEYCODE_KP_MINUS: + return Qt::Key_Minus; + + case KEYCODE_KP_MULTIPLY: + return Qt::Key_Asterisk; + + case KEYCODE_KP_DIVIDE: + return Qt::Key_Slash; + + case KEYCODE_KP_ENTER: + return Qt::Key_Enter; + + case KEYCODE_KP_HOME: + return Qt::Key_Home; + + case KEYCODE_KP_UP: + return Qt::Key_Up; + + case KEYCODE_KP_PG_UP: + return Qt::Key_PageUp; + + case KEYCODE_KP_LEFT: + return Qt::Key_Left; + + // Is this right? + case KEYCODE_KP_FIVE: + return Qt::Key_5; + + case KEYCODE_KP_RIGHT: + return Qt::Key_Right; + + case KEYCODE_KP_END: + return Qt::Key_End; + + case KEYCODE_KP_DOWN: + return Qt::Key_Down; + + case KEYCODE_KP_PG_DOWN: + return Qt::Key_PageDown; + + case KEYCODE_KP_INSERT: + return Qt::Key_Insert; + + case KEYCODE_KP_DELETE: + return Qt::Key_Delete; + + case KEYCODE_F1: + return Qt::Key_F1; + + case KEYCODE_F2: + return Qt::Key_F2; + + case KEYCODE_F3: + return Qt::Key_F3; + + case KEYCODE_F4: + return Qt::Key_F4; + + case KEYCODE_F5: + return Qt::Key_F5; + + case KEYCODE_F6: + return Qt::Key_F6; + + case KEYCODE_F7: + return Qt::Key_F7; + + case KEYCODE_F8: + return Qt::Key_F8; + + case KEYCODE_F9: + return Qt::Key_F9; + + case KEYCODE_F10: + return Qt::Key_F10; + + case KEYCODE_F11: + return Qt::Key_F11; + + case KEYCODE_F12: + return Qt::Key_F12; + + // See keycodes.h for more, but these are all the basics. And printables are already included. + + default: +#if defined(QBBEVENTTHREAD_DEBUG) + qDebug() << "QBB: unknown key for translation:" << key; +#endif + break; + } + + return Qt::Key_Escape; +} + +bool isKeypadKey( int key ) +{ + switch (key) + { + case KEYCODE_KP_PLUS: + case KEYCODE_KP_MINUS: + case KEYCODE_KP_MULTIPLY: + case KEYCODE_KP_DIVIDE: + case KEYCODE_KP_ENTER: + case KEYCODE_KP_HOME: + case KEYCODE_KP_UP: + case KEYCODE_KP_PG_UP: + case KEYCODE_KP_LEFT: + case KEYCODE_KP_FIVE: + case KEYCODE_KP_RIGHT: + case KEYCODE_KP_END: + case KEYCODE_KP_DOWN: + case KEYCODE_KP_PG_DOWN: + case KEYCODE_KP_INSERT: + case KEYCODE_KP_DELETE: + return true; + default: + break; + } + + return false; +} + +QT_END_NAMESPACE + +#endif // QBBKEYTRANSLATOR_H diff --git a/src/plugins/platforms/blackberry/qbbnavigatorthread.cpp b/src/plugins/platforms/blackberry/qbbnavigatorthread.cpp new file mode 100644 index 0000000000..65cbb77d31 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbnavigatorthread.cpp @@ -0,0 +1,279 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbnavigatorthread.h" +#include "qbbscreen.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static const char *navigatorControlPath = "/pps/services/navigator/control"; +static const int ppsBufferSize = 4096; + +QBBNavigatorThread::QBBNavigatorThread(QBBScreen& primaryScreen) + : m_primaryScreen(primaryScreen), + m_fd(-1), + m_readNotifier(0) +{ +} + +QBBNavigatorThread::~QBBNavigatorThread() +{ + // block until thread terminates + shutdown(); + + delete m_readNotifier; +} + +void QBBNavigatorThread::run() +{ +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "QBB: navigator thread started"; +#endif + + // open connection to navigator + errno = 0; + m_fd = open(navigatorControlPath, O_RDWR); + if (m_fd == -1) { + qWarning("QBB: failed to open navigator pps, errno=%d", errno); + return; + } + + m_readNotifier = new QSocketNotifier(m_fd, QSocketNotifier::Read); + // using direct connection to get the slot called in this thread's context + connect(m_readNotifier, SIGNAL(activated(int)), this, SLOT(readData()), Qt::DirectConnection); + + exec(); + + // close connection to navigator + close(m_fd); + +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "QBB: navigator thread stopped"; +#endif +} + +void QBBNavigatorThread::shutdown() +{ +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "QBB: navigator thread shutdown begin"; +#endif + + // signal thread to terminate + quit(); + + // block until thread terminates + wait(); + +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "QBB: navigator thread shutdown end"; +#endif +} + +void QBBNavigatorThread::parsePPS(const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id) +{ +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: data=" << ppsData; +#endif + + // tokenize pps data into lines + QList lines = ppsData.split('\n'); + + // validate pps object + if (lines.size() == 0 || lines.at(0) != "@control") { + qFatal("QBB: unrecognized pps object, data=%s", ppsData.constData()); + } + + // parse pps object attributes and extract values + for (int i = 1; i < lines.size(); i++) { + + // tokenize current attribute + const QByteArray &attr = lines.at(i); + +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: attr=" << attr; +#endif + + int firstColon = attr.indexOf(':'); + if (firstColon == -1) { + // abort - malformed attribute + continue; + } + + int secondColon = attr.indexOf(':', firstColon + 1); + if (secondColon == -1) { + // abort - malformed attribute + continue; + } + + QByteArray key = attr.left(firstColon); + QByteArray value = attr.mid(secondColon + 1); + +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: key=" << key; + qDebug() << "PPS: val=" << value; +#endif + + // save attribute value + if (key == "msg") { + msg = value; + } else if (key == "dat") { + dat = value; + } else if (key == "id") { + id = value; + } else { + qFatal("QBB: unrecognized pps attribute, attr=%s", key.constData()); + } + } +} + +void QBBNavigatorThread::replyPPS(const QByteArray &res, const QByteArray &id, const QByteArray &dat) +{ + // construct pps message + QByteArray ppsData = "res::"; + ppsData += res; + ppsData += "\nid::"; + ppsData += id; + if (!dat.isEmpty()) { + ppsData += "\ndat::"; + ppsData += dat; + } + ppsData += "\n"; + +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS reply=" << ppsData; +#endif + + // send pps message to navigator + errno = 0; + int bytes = write(m_fd, ppsData.constData(), ppsData.size()); + if (bytes == -1) { + qFatal("QBB: failed to write navigator pps, errno=%d", errno); + } +} + +void QBBNavigatorThread::handleMessage(const QByteArray &msg, const QByteArray &dat, const QByteArray &id) +{ +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: msg=" << msg << ", dat=" << dat << ", id=" << id; +#endif + + // check message type + if (msg == "orientationCheck") { + + // reply to navigator that (any) orientation is acceptable +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: orientation check, o=" << dat; +#endif + replyPPS(msg, id, "true"); + + } else if (msg == "orientation") { + + // update screen geometry and reply to navigator that we're ready +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: orientation, o=" << dat; +#endif + m_primaryScreen.setRotation( dat.toInt() ); + QWindowSystemInterface::handleScreenGeometryChange(0, m_primaryScreen.geometry()); + replyPPS(msg, id, ""); + + } else if (msg == "SWIPE_DOWN") { + + // simulate menu key press +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: menu"; +#endif + QWindow *w = QGuiApplication::focusWindow(); + QWindowSystemInterface::handleKeyEvent(w, QEvent::KeyPress, Qt::Key_Menu, Qt::NoModifier); + QWindowSystemInterface::handleKeyEvent(w, QEvent::KeyRelease, Qt::Key_Menu, Qt::NoModifier); + + } else if (msg == "exit") { + + // shutdown everything +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "PPS: exit"; +#endif + QCoreApplication::quit(); + } +} + +void QBBNavigatorThread::readData() +{ +#if defined(QBBNAVIGATORTHREAD_DEBUG) + qDebug() << "QBB: reading navigator data"; +#endif + // allocate buffer for pps data + char buffer[ppsBufferSize]; + + // attempt to read pps data + errno = 0; + int bytes = read(m_fd, buffer, ppsBufferSize - 1); + if (bytes == -1) { + qFatal("QBB: failed to read navigator pps, errno=%d", errno); + } + + // check if pps data was received + if (bytes > 0) { + + // ensure data is null terminated + buffer[bytes] = '\0'; + + // process received message + QByteArray ppsData(buffer); + QByteArray msg; + QByteArray dat; + QByteArray id; + parsePPS(ppsData, msg, dat, id); + handleMessage(msg, dat, id); + } +} diff --git a/src/plugins/platforms/blackberry/qbbnavigatorthread.h b/src/plugins/platforms/blackberry/qbbnavigatorthread.h new file mode 100644 index 0000000000..fda24b0c67 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbnavigatorthread.h @@ -0,0 +1,78 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBNAVIGATORTHREAD_H +#define QBBNAVIGATORTHREAD_H + +#include + +QT_BEGIN_NAMESPACE + +class QBBScreen; +class QSocketNotifier; + +class QBBNavigatorThread : public QThread +{ + Q_OBJECT +public: + QBBNavigatorThread(QBBScreen &primaryScreen); + virtual ~QBBNavigatorThread(); + +protected: + virtual void run(); + +private Q_SLOTS: + void readData(); + +private: + void shutdown(); + void parsePPS(const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id); + void replyPPS(const QByteArray &res, const QByteArray &id, const QByteArray &dat); + void handleMessage(const QByteArray &msg, const QByteArray &dat, const QByteArray &id); + + QBBScreen &m_primaryScreen; + int m_fd; + QSocketNotifier *m_readNotifier; +}; + +QT_END_NAMESPACE + +#endif // QBBNAVIGATORTHREAD_H diff --git a/src/plugins/platforms/blackberry/qbbrasterbackingstore.cpp b/src/plugins/platforms/blackberry/qbbrasterbackingstore.cpp new file mode 100644 index 0000000000..405e09260f --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbrasterbackingstore.cpp @@ -0,0 +1,166 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbrasterbackingstore.h" +#include "qbbwindow.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +QBBRasterBackingStore::QBBRasterBackingStore(QWindow *window) + : QPlatformBackingStore(window) +{ +#if defined(QBBRASTERBACKINGSTORE_DEBUG) + qDebug() << "QBBRasterBackingStore::QBBRasterBackingStore - w=" << window; +#endif + + // save platform window associated with widget + m_platformWindow = static_cast(window->handle()); +} + +QBBRasterBackingStore::~QBBRasterBackingStore() +{ +#if defined(QBBRasterBackingStore_DEBUG) + qDebug() << "QBBRasterBackingStore::~QBBRasterBackingStore - w=" << window(); +#endif +} + +QPaintDevice *QBBRasterBackingStore::paintDevice() +{ + return m_platformWindow->renderBuffer().image(); +} + +void QBBRasterBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(window); + Q_UNUSED(offset); + +#if defined(QBBRASTERBACKINGSTORE_DEBUG) + qDebug() << "QBBRasterBackingStore::flush - w=" << this->window(); +#endif + + // visit all pending scroll operations + for (int i = m_scrollOpList.size() - 1; i >= 0; i--) { + + // do the scroll operation + ScrollOp &op = m_scrollOpList[i]; + QRegion srcArea = op.totalArea.intersected( op.totalArea.translated(-op.dx, -op.dy) ); + m_platformWindow->scroll(srcArea, op.dx, op.dy); + } + + // clear all pending scroll operations + m_scrollOpList.clear(); + + // update the display with newly rendered content + m_platformWindow->post(region); +} + +void QBBRasterBackingStore::resize(const QSize &size, const QRegion &staticContents) +{ + Q_UNUSED(size); + Q_UNUSED(staticContents); +#if defined(QBBRASTERBACKINGSTORE_DEBUG) + qDebug() << "QBBRasterBackingStore::resize - w=" << window() << ", s=" << size; +#endif + + // NOTE: defer resizing window buffers until next paint as + // resize() can be called multiple times before a paint occurs +} + +bool QBBRasterBackingStore::scroll(const QRegion &area, int dx, int dy) +{ +#if defined(QBBRASTERBACKINGSTORE_DEBUG) + qDebug() << "QBBRasterBackingStore::scroll - w=" << window(); +#endif + + // calculate entire region affected by scroll operation (src + dst) + QRegion totalArea = area.translated(dx, dy); + totalArea += area; + + // visit all pending scroll operations + for (int i = m_scrollOpList.size() - 1; i >= 0; i--) { + + ScrollOp &op = m_scrollOpList[i]; + if (op.totalArea == totalArea) { + // same area is being scrolled again - update delta + op.dx += dx; + op.dy += dy; + return true; + } else if (op.totalArea.intersects(totalArea)) { + // current scroll overlaps previous scroll but is + // not equal in area - just paint everything + qWarning("QBB: pending scroll operations overlap but not equal"); + return false; + } + } + + // create new scroll operation + m_scrollOpList.append( ScrollOp(totalArea, dx, dy) ); + return true; +} + +void QBBRasterBackingStore::beginPaint(const QRegion ®ion) +{ + Q_UNUSED(region); + +#if defined(QBBRASTERBACKINGSTORE_DEBUG) + qDebug() << "QBBRasterBackingStore::beginPaint - w=" << window(); +#endif + + // resize window buffers if surface resized + QSize s = window()->size(); + if (s != m_platformWindow->bufferSize()) { + m_platformWindow->setBufferSize(s); + } +} + +void QBBRasterBackingStore::endPaint(const QRegion ®ion) +{ + Q_UNUSED(region); +#if defined(QBBRasterBackingStore_DEBUG) + qDebug() << "QBBRasterBackingStore::endPaint - w=" << window(); +#endif +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbrasterbackingstore.h b/src/plugins/platforms/blackberry/qbbrasterbackingstore.h new file mode 100644 index 0000000000..ca1e27bcc8 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbrasterbackingstore.h @@ -0,0 +1,81 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBRASTERWINDOWSURFACE_H +#define QBBRASTERWINDOWSURFACE_H + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QBBWindow; + +class QBBRasterBackingStore : public QPlatformBackingStore +{ +public: + QBBRasterBackingStore(QWindow *window); + virtual ~QBBRasterBackingStore(); + + virtual QPaintDevice *paintDevice(); + virtual void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + virtual void resize(const QSize &size, const QRegion &staticContents); + virtual bool scroll(const QRegion &area, int dx, int dy); + virtual void beginPaint(const QRegion ®ion); + virtual void endPaint(const QRegion ®ion); + +private: + class ScrollOp { + public: + ScrollOp(const QRegion &a, int x, int y) : totalArea(a), dx(x), dy(y) {} + QRegion totalArea; + int dx; + int dy; + }; + + QBBWindow *m_platformWindow; + QList m_scrollOpList; +}; + +QT_END_NAMESPACE + +#endif // QBBRASTERWINDOWSURFACE_H diff --git a/src/plugins/platforms/blackberry/qbbrootwindow.cpp b/src/plugins/platforms/blackberry/qbbrootwindow.cpp new file mode 100644 index 0000000000..831b0774f9 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbrootwindow.cpp @@ -0,0 +1,257 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbrootwindow.h" + +#include "qbbscreen.h" + +#include + +#if defined(QBBROOTWINDOW_DEBUG) +#include +#endif + +#include +#include + +static const int MAGIC_ZORDER_FOR_NO_NAV = 10; + +QBBRootWindow::QBBRootWindow(QBBScreen *screen) + : m_screen(screen), + m_window(0), + m_windowGroupName() +{ +#if defined(QBBROOTWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Create one top-level QNX window to act as a container for child windows + // since navigator only supports one application window + errno = 0; + int result = screen_create_window(&m_window, m_screen->nativeContext()); + int val[2]; + if (result != 0) { + qFatal("QBBRootWindow: failed to create window, errno=%d", errno); + } + + // Move window to proper display + errno = 0; + screen_display_t display = m_screen->nativeDisplay(); + result = screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window display, errno=%d", errno); + } + + // Make sure window is above navigator but below keyboard if running as root + // since navigator won't automatically set our z-order in this case + if (getuid() == 0) { + errno = 0; + val[0] = MAGIC_ZORDER_FOR_NO_NAV; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ZORDER, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window z-order, errno=%d", errno); + } + } + + // Window won't be visible unless it has some buffers so make one dummy buffer that is 1x1 + errno = 0; + val[0] = SCREEN_USAGE_NATIVE; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_USAGE, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window buffer usage, errno=%d", errno); + } + + errno = 0; + val[0] = m_screen->nativeFormat(); + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window pixel format, errno=%d", errno); + } + + errno = 0; + val[0] = 1; + val[1] = 1; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window buffer size, errno=%d", errno); + } + + errno = 0; + result = screen_create_window_buffers(m_window, 1); + if (result != 0) { + qFatal("QBB: failed to create window buffer, errno=%d", errno); + } + + // Window is always the size of the display + errno = 0; + QRect geometry = m_screen->geometry(); + val[0] = geometry.width(); + val[1] = geometry.height(); + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window size, errno=%d", errno); + } + + // Fill the window with solid black + errno = 0; + val[0] = 0; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_COLOR, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window colour, errno=%d", errno); + } + + // Make the window opaque + errno = 0; + val[0] = SCREEN_TRANSPARENCY_NONE; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window transparency, errno=%d", errno); + } + + // Set the swap interval to 1 + errno = 0; + val[0] = 1; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SWAP_INTERVAL, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window swap interval, errno=%d", errno); + } + + // Set viewport size equal to window size but move outside buffer so the fill colour is used exclusively + errno = 0; + val[0] = geometry.width(); + val[1] = geometry.height(); + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window source size, errno=%d", errno); + } + + errno = 0; + val[0] = 1; + val[1] = 0; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_POSITION, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window source position, errno=%d", errno); + } + + createWindowGroup(); + post(); +} + +QBBRootWindow::~QBBRootWindow() +{ + // Cleanup top-level QNX window + screen_destroy_window(m_window); +} + +void QBBRootWindow::post() const +{ +#if defined(QBBROOTWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + errno = 0; + screen_buffer_t buffer; + int result = screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&buffer); + if (result != 0) { + qFatal("QBBRootWindow: failed to query window buffer, errno=%d", errno); + } + + errno = 0; + int dirtyRect[] = {0, 0, 1, 1}; + result = screen_post_window(m_window, buffer, 1, dirtyRect, 0); + if (result != 0) { + qFatal("QBB: failed to post window buffer, errno=%d", errno); + } +} + +void QBBRootWindow::flush() const +{ +#if defined(QBBROOTWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Force immediate display update + errno = 0; + int result = screen_flush_context(m_screen->nativeContext(), 0); + if (result != 0) { + qFatal("QBBRootWindow: failed to flush context, errno=%d", errno); + } +} + +void QBBRootWindow::setRotation(int rotation) +{ +#if defined(QBBROOTWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "angle =" << rotation; +#endif + errno = 0; + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ROTATION, &rotation); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window rotation, errno=%d", errno); + } +} + +void QBBRootWindow::resize(const QSize &size) +{ + errno = 0; + int val[] = {size.width(), size.height()}; + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window size, errno=%d", errno); + } + + errno = 0; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val); + if (result != 0) { + qFatal("QBBRootWindow: failed to set window source size, errno=%d", errno); + } + + // NOTE: display will update when child windows relayout and repaint +} + +void QBBRootWindow::createWindowGroup() +{ + // Generate a random window group name + m_windowGroupName = QUuid::createUuid().toString().toAscii(); + + // Create window group so child windows can be parented by container window + errno = 0; + int result = screen_create_window_group(m_window, m_windowGroupName.constData()); + if (result != 0) { + qFatal("QBBRootWindow: failed to create app window group, errno=%d", errno); + } +} diff --git a/src/plugins/platforms/blackberry/qbbrootwindow.h b/src/plugins/platforms/blackberry/qbbrootwindow.h new file mode 100644 index 0000000000..0b89f52a5e --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbrootwindow.h @@ -0,0 +1,81 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBROOTWINDOW_H +#define QBBROOTWINDOW_H + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QBBScreen; + +class QBBRootWindow +{ +public: + QBBRootWindow(QBBScreen *screen); + ~QBBRootWindow(); + + screen_window_t nativeHandle() const { return m_window; } + + void post() const; + void flush() const; + + void setRotation(int rotation); + + void resize(const QSize &size); + + QByteArray groupName() const { return m_windowGroupName; } + +private: + void createWindowGroup(); + + QBBScreen *m_screen; + screen_window_t m_window; + QByteArray m_windowGroupName; +}; + +QT_END_NAMESPACE + +#endif // QBBROOTWINDOW_H diff --git a/src/plugins/platforms/blackberry/qbbscreen.cpp b/src/plugins/platforms/blackberry/qbbscreen.cpp new file mode 100644 index 0000000000..39d2136b7d --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbscreen.cpp @@ -0,0 +1,315 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbscreen.h" +#include "qbbvirtualkeyboard.h" +#include "qbbwindow.h" + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +QList QBBScreen::ms_screens; +QList QBBScreen::ms_childWindows; + +QBBScreen::QBBScreen(screen_context_t screenContext, screen_display_t display, bool primaryScreen) + : m_screenContext(screenContext), + m_display(display), + m_rootWindow(), + m_primaryScreen(primaryScreen), + m_posted(false), + m_platformContext(0) +{ +#if defined(QBBSCREEN_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Cache initial orientation of this display + // TODO: use ORIENTATION environment variable? + errno = 0; + int result = screen_get_display_property_iv(m_display, SCREEN_PROPERTY_ROTATION, &m_initialRotation); + if (result != 0) { + qFatal("QBBScreen: failed to query display rotation, errno=%d", errno); + } + m_currentRotation = m_initialRotation; + + // Cache size of this display in pixels + // TODO: use WIDTH and HEIGHT environment variables? + errno = 0; + int val[2]; + result = screen_get_display_property_iv(m_display, SCREEN_PROPERTY_SIZE, val); + if (result != 0) { + qFatal("QBBScreen: failed to query display size, errno=%d", errno); + } + + m_currentGeometry = m_initialGeometry = QRect(0, 0, val[0], val[1]); + + // Cache size of this display in millimeters + errno = 0; + result = screen_get_display_property_iv(m_display, SCREEN_PROPERTY_PHYSICAL_SIZE, val); + if (result != 0) { + qFatal("QBBScreen: failed to query display physical size, errno=%d", errno); + } + + // Peg the DPI to 96 (for now) so fonts are a reasonable size. We'll want to match + // everything with a QStyle later, and at that point the physical size can be used + // instead. + { + static const int dpi = 96; + int width = m_currentGeometry.width() / dpi * qreal(25.4) ; + int height = m_currentGeometry.height() / dpi * qreal(25.4) ; + + m_currentPhysicalSize = m_initialPhysicalSize = QSize(width,height); + } + + // We only create the root window if we are the primary display. + if (primaryScreen) + m_rootWindow = QSharedPointer(new QBBRootWindow(this)); +} + +QBBScreen::~QBBScreen() +{ +#if defined(QBBSCREEN_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif +} + +/* static */ +void QBBScreen::createDisplays(screen_context_t context) +{ +#if defined(QBBSCREEN_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Query number of displays + errno = 0; + int displayCount; + int result = screen_get_context_property_iv(context, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount); + if (result != 0) { + qFatal("QBBScreen: failed to query display count, errno=%d", errno); + } + + // Get all displays + errno = 0; + screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount); + result = screen_get_context_property_pv(context, SCREEN_PROPERTY_DISPLAYS, (void **)displays); + if (result != 0) { + qFatal("QBBScreen: failed to query displays, errno=%d", errno); + } + + for (int i=0; i +#include + +#include + +QT_BEGIN_NAMESPACE + +class QBBWindow; + +class QBBScreen : public QPlatformScreen +{ +public: + static QList screens() { return ms_screens; } + static void createDisplays(screen_context_t context); + static void destroyDisplays(); + static QBBScreen *primaryDisplay() { return static_cast(ms_screens.at(0)); } + static int defaultDepth(); + + virtual QRect geometry() const { return m_currentGeometry; } + virtual QRect availableGeometry() const; + virtual int depth() const { return defaultDepth(); } + virtual QImage::Format format() const { return (depth() == 32) ? QImage::Format_RGB32 : QImage::Format_RGB16; } + virtual QSizeF physicalSize() const { return m_currentPhysicalSize; } + + bool isPrimaryScreen() const { return m_primaryScreen; } + + int rotation() const { return m_currentRotation; } + void setRotation(int rotation); + + int nativeFormat() const { return (depth() == 32) ? SCREEN_FORMAT_RGBA8888 : SCREEN_FORMAT_RGB565; } + screen_display_t nativeDisplay() const { return m_display; } + screen_context_t nativeContext() const { return m_screenContext; } + const char *windowGroupName() const { return m_rootWindow->groupName().constData(); } + + /* Window hierarchy management */ + static void addWindow(QBBWindow *child); + static void removeWindow(QBBWindow *child); + static void raiseWindow(QBBWindow *window); + static void lowerWindow(QBBWindow *window); + static void updateHierarchy(); + + void onWindowPost(QBBWindow *window); + + QSharedPointer rootWindow() const { return m_rootWindow; } + +private: + QBBScreen(screen_context_t context, screen_display_t display, bool primaryScreen); + virtual ~QBBScreen(); + + static bool orthogonal(int rotation1, int rotation2); + + screen_context_t m_screenContext; + screen_display_t m_display; + QSharedPointer m_rootWindow; + bool m_primaryScreen; + bool m_posted; + bool m_usingOpenGL; + + int m_initialRotation; + int m_currentRotation; + QSize m_initialPhysicalSize; + QSize m_currentPhysicalSize; + QRect m_initialGeometry; + QRect m_currentGeometry; + QPlatformOpenGLContext *m_platformContext; + + static QList ms_screens; + static QList ms_childWindows; +}; + +QT_END_NAMESPACE + +#endif // QBBSCREEN_H diff --git a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp new file mode 100644 index 0000000000..082ef9b19d --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.cpp @@ -0,0 +1,500 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbvirtualkeyboard.h" +#include "qbbscreen.h" + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char *QBBVirtualKeyboard::ms_PPSPath = "/pps/services/input/control?wait"; +const size_t QBBVirtualKeyboard::ms_bufferSize = 2048; + +static QBBVirtualKeyboard *s_instance = 0; + +// Huge hack for keyboard shadow (see QNX PR 88400). Should be removed ASAP. +#define KEYBOARD_SHADOW_HEIGHT 8 + +QBBVirtualKeyboard::QBBVirtualKeyboard() : + m_encoder(NULL), + m_decoder(NULL), + m_buffer(NULL), + m_height(0), + m_fd(-1), + m_keyboardMode(Default), + m_visible(false), + m_locale(QLatin1String("en_US")) +{ + connect(); +} + +QBBVirtualKeyboard::~QBBVirtualKeyboard() +{ + close(); +} + +/* static */ +QBBVirtualKeyboard& QBBVirtualKeyboard::instance() +{ + if (!s_instance) { + s_instance = new QBBVirtualKeyboard(); + s_instance->start(); + } + + return *s_instance; +} + +/* static */ +void QBBVirtualKeyboard::destroy() +{ + if (s_instance) { + delete s_instance; + s_instance = 0; + } +} + +void QBBVirtualKeyboard::close() +{ + if (m_fd) { + // any reads will fail after we close the fd, which is basically what we want. + ::close(m_fd); + } + + // Wait for the thread to die (should be immediate), then continue the cleanup. + wait(); + + if (m_fd) { + m_fd = -1; + } + + + if (m_decoder) + { + pps_decoder_cleanup(m_decoder); + delete m_decoder; + m_decoder = NULL; + } + + if (m_encoder) + { + pps_encoder_cleanup(m_encoder); + delete m_encoder; + m_encoder = NULL; + } + + delete [] m_buffer; + m_buffer = NULL; +} + +bool QBBVirtualKeyboard::connect() +{ + close(); + + m_encoder = new pps_encoder_t; + m_decoder = new pps_decoder_t; + + pps_encoder_initialize(m_encoder, false); + pps_decoder_initialize(m_decoder, NULL); + + errno = 0; + m_fd = ::open(ms_PPSPath, O_RDWR); + if (m_fd == -1) + { + qCritical("QBBVirtualKeyboard: Unable to open \"%s\" for keyboard: %s (%d).", + ms_PPSPath, strerror(errno), errno); + close(); + return false; + } + + m_buffer = new char[ms_bufferSize]; + if (!m_buffer) { + qCritical("QBBVirtualKeyboard: Unable to allocate buffer of %d bytes. Size is unavailable.", ms_bufferSize); + return false; + } + + if (!queryPPSInfo()) + return false; + + start(); + + return true; +} + +bool QBBVirtualKeyboard::queryPPSInfo() +{ + // Request info, requires id to regenerate res message. + pps_encoder_add_string(m_encoder, "msg", "info"); + pps_encoder_add_string(m_encoder, "id", "libWebView"); + + if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { + close(); + return false; + } + + pps_encoder_reset(m_encoder); + + return true; +} + +void QBBVirtualKeyboard::notifyClientActiveStateChange(bool active) +{ + if (!active) + hideKeyboard(); +} + +void QBBVirtualKeyboard::run() +{ + ppsDataReady(); +} + +void QBBVirtualKeyboard::ppsDataReady() +{ + while (1) { + ssize_t nread = read(m_fd, m_buffer, ms_bufferSize - 1); + +#ifdef QBBVIRTUALKEYBOARD_DEBUG + qDebug() << "QBB: keyboardMessage size: " << nread; +#endif + if (nread < 0) + break; + + // nread is the real space necessary, not the amount read. + if (static_cast(nread) > ms_bufferSize - 1) { + qCritical("QBBVirtualKeyboard: Keyboard buffer size too short; need %u.", nread + 1); + break; + } + + m_buffer[nread] = 0; + pps_decoder_parse_pps_str(m_decoder, m_buffer); + pps_decoder_push(m_decoder, NULL); +#ifdef QBBVIRTUALKEYBOARD_DEBUG + pps_decoder_dump_tree(m_decoder, stderr); +#endif + + const char *value; + if (pps_decoder_get_string(m_decoder, "error", &value) == PPS_DECODER_OK) { + qCritical("QBBVirtualKeyboard: Keyboard PPS decoder error: %s", value ? value : "[null]"); + continue; + } + + if (pps_decoder_get_string(m_decoder, "msg", &value) == PPS_DECODER_OK) { + if (strcmp(value, "show") == 0) { + const bool oldVisible = m_visible; + m_visible = true; + handleKeyboardStateChangeMessage(true); + if (oldVisible != m_visible) + emit visibilityChanged(m_visible); + } else if (strcmp(value, "hide") == 0) { + const bool oldVisible = m_visible; + m_visible = false; + handleKeyboardStateChangeMessage(false); + if (oldVisible != m_visible) + emit visibilityChanged(m_visible); + } else if (strcmp(value, "info") == 0) + handleKeyboardInfoMessage(); + else if (strcmp(value, "connect") == 0) { } + else + qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS msg value: %s", value ? value : "[null]"); + } else if (pps_decoder_get_string(m_decoder, "res", &value) == PPS_DECODER_OK) { + if (strcmp(value, "info") == 0) + handleKeyboardInfoMessage(); + else + qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS res value: %s", value ? value : "[null]"); + } else + qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS message type"); + } + +#ifdef QBBVIRTUALKEYBOARD_DEBUG + qDebug() << "QBB: exiting keyboard thread"; +#endif + + if (m_decoder) + pps_decoder_cleanup(m_decoder); +} + +void QBBVirtualKeyboard::handleKeyboardInfoMessage() +{ + int newHeight = 0; + const char *value; + + if (pps_decoder_push(m_decoder, "dat") != PPS_DECODER_OK) { + qCritical("QBBVirtualKeyboard: Keyboard PPS dat object not found"); + return; + } + if (pps_decoder_get_int(m_decoder, "size", &newHeight) != PPS_DECODER_OK) { + qCritical("QBBVirtualKeyboard: Keyboard PPS size field not found"); + return; + } + if (pps_decoder_push(m_decoder, "locale") != PPS_DECODER_OK) { + qCritical("QBBVirtualKeyboard: Keyboard PPS locale object not found"); + return; + } + if (pps_decoder_get_string(m_decoder, "languageId", &value) != PPS_DECODER_OK) { + qCritical("QBBVirtualKeyboard: Keyboard PPS languageId field not found"); + return; + } + const QString languageId = QString::fromLatin1(value); + if (pps_decoder_get_string(m_decoder, "countryId", &value) != PPS_DECODER_OK) { + qCritical("QBBVirtualKeyboard: Keyboard PPS size countryId not found"); + return; + } + const QString countryId = QString::fromLatin1(value); + + // HUGE hack, should be removed ASAP. + newHeight -= KEYBOARD_SHADOW_HEIGHT; // We want to ignore the 8 pixel shadow above the keyboard. (PR 88400) + + if (newHeight != m_height) { + m_height = newHeight; + updateAvailableScreenGeometry(); + } + + const QLocale locale = QLocale(languageId + QLatin1Char('_') + countryId); + if (locale != m_locale) { + m_locale = locale; + emit localeChanged(locale); + } + +#ifdef QBBVIRTUALKEYBOARD_DEBUG + qDebug() << "QBB: handleKeyboardInfoMessage size=" << m_height << "locale=" << m_locale; +#endif +} + +void QBBVirtualKeyboard::handleKeyboardStateChangeMessage(bool visible) +{ + +#ifdef QBBVIRTUALKEYBOARD_DEBUG + qDebug() << "QBB: handleKeyboardStateChangeMessage " << visible; +#endif + updateAvailableScreenGeometry(); + + if (visible) + showKeyboard(); + else + hideKeyboard(); +} + +void QBBVirtualKeyboard::updateAvailableScreenGeometry() +{ +#ifdef QBBVIRTUALKEYBOARD_DEBUG + qDebug() << "QBB: updateAvailableScreenGeometry: keyboard visible=" << m_visible << ", keyboard height=" << m_height; +#endif + + // TODO: What screen index should be used? I assume primaryScreen here because it works, and + // we do it for handleScreenGeometryChange elsewhere but since we have support + // for more than one screen, that's not going to always work. + QBBScreen *platformScreen = QBBScreen::primaryDisplay(); + QWindowSystemInterface::handleScreenAvailableGeometryChange(platformScreen->screen(), platformScreen->availableGeometry()); +} + +bool QBBVirtualKeyboard::showKeyboard() +{ +#ifdef QBBVIRTUALKEYBOARD_DEBUG + qDebug() << "QBB: showKeyboard()"; +#endif + + // Try to connect. + if (m_fd == -1 && !connect()) + return false; + + // NOTE: This must be done everytime the keyboard is shown even if there is no change because + // hiding the keyboard wipes the setting. + applyKeyboardModeOptions(); + + pps_encoder_reset(m_encoder); + + // Send the show message. + pps_encoder_add_string(m_encoder, "msg", "show"); + + if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { + close(); + return false; + } + + pps_encoder_reset(m_encoder); + + // Return true if no error occurs. Sizing response will be triggered when confirmation of + // the change arrives. + return true; +} + +bool QBBVirtualKeyboard::hideKeyboard() +{ +#ifdef QBBVIRTUALKEYBOARD_DEBUG + qDebug() << "QBB: hideKeyboard()"; +#endif + + if (m_fd == -1 && !connect()) + return false; + + pps_encoder_add_string(m_encoder, "msg", "hide"); + + if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { + close(); + + //Try again. + if (connect()) { + if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { + close(); + return false; + } + } + else + return false; + } + + pps_encoder_reset(m_encoder); + + // Return true if no error occurs. Sizing response will be triggered when confirmation of + // the change arrives. + return true; +} + +void QBBVirtualKeyboard::setKeyboardMode(KeyboardMode mode) +{ + m_keyboardMode = mode; +} + +void QBBVirtualKeyboard::applyKeyboardModeOptions() +{ + // Try to connect. + if (m_fd == -1 && !connect()) + return; + + // Send the options message. + pps_encoder_add_string(m_encoder, "msg", "options"); + + pps_encoder_start_object(m_encoder, "dat"); + switch (m_keyboardMode) { + case Url: + addUrlModeOptions(); + break; + case Email: + addEmailModeOptions(); + break; + case Web: + addWebModeOptions(); + break; + case NumPunc: + addNumPuncModeOptions(); + break; + case Symbol: + addSymbolModeOptions(); + break; + case Phone: + addPhoneModeOptions(); + break; + case Pin: + addPinModeOptions(); + break; + case Default: + default: + addDefaultModeOptions(); + break; + } + + pps_encoder_end_object(m_encoder); + + if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) { + close(); + } + + pps_encoder_reset(m_encoder); +} + +void QBBVirtualKeyboard::addDefaultModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "default"); +} + +void QBBVirtualKeyboard::addUrlModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "url"); +} + +void QBBVirtualKeyboard::addEmailModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "email"); +} + +void QBBVirtualKeyboard::addWebModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "web"); +} + +void QBBVirtualKeyboard::addNumPuncModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "numPunc"); +} + +void QBBVirtualKeyboard::addPhoneModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "phone"); +} + +void QBBVirtualKeyboard::addPinModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "pin"); +} + +void QBBVirtualKeyboard::addSymbolModeOptions() +{ + pps_encoder_add_string(m_encoder, "enter", "enter.default"); + pps_encoder_add_string(m_encoder, "type", "symbol"); +} diff --git a/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h new file mode 100644 index 0000000000..14003ee897 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbvirtualkeyboard.h @@ -0,0 +1,130 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIRTUALKEYBOARD_H_ +#define VIRTUALKEYBOARD_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/* Shamelessly copied from the browser - this should be rewritten once we have a proper PPS wrapper class */ +class QBBVirtualKeyboard : public QThread +{ + Q_OBJECT +public: + // NOTE: Not all the following keyboard modes are currently used. + // Default - Regular Keyboard + // Url/Email - Enhanced keys for each types. + // Web - Regular keyboard with two blank keys, currently unused. + // NumPunc - Numbers & Punctionation, alternate to Symbol + // Symbol - All symbols, alternate to NumPunc, currently unused. + // Phone - Phone enhanced keyboard - currently unused as no alternate keyboard available to access a-zA-Z + // Pin - Keyboard for entering Pins (Hex values) currently unused. + // + // SPECIAL NOTE: Usage of NumPunc may have to be removed, ABC button is non-functional. + // + enum KeyboardMode { Default, Url, Email, Web, NumPunc, Symbol, Phone, Pin }; + + static QBBVirtualKeyboard& instance(); + static void destroy(); + + bool showKeyboard(); + bool hideKeyboard(); + int height() { return m_visible ? m_height : 0; } + void setKeyboardMode(KeyboardMode); + void notifyClientActiveStateChange(bool); + bool isVisible() const { return m_visible; } + QLocale locale() const { return m_locale; } + +Q_SIGNALS: + void localeChanged(const QLocale &locale); + void visibilityChanged(bool visible); + +private: + QBBVirtualKeyboard(); + virtual ~QBBVirtualKeyboard(); + + // Will be called internally if needed. + bool connect(); + void close(); + void ppsDataReady(); + bool queryPPSInfo(); + void handleKeyboardInfoMessage(); + void handleKeyboardStateChangeMessage(bool visible); + void updateAvailableScreenGeometry(); + + void applyKeyboardModeOptions(); + void addDefaultModeOptions(); + void addUrlModeOptions(); + void addEmailModeOptions(); + void addWebModeOptions(); + void addNumPuncModeOptions(); + void addSymbolModeOptions(); + void addPhoneModeOptions(); + void addPinModeOptions(); + + // QThread overrides + virtual void run(); + + pps_encoder_t *m_encoder; + pps_decoder_t *m_decoder; + char *m_buffer; + int m_height; + int m_fd; + KeyboardMode m_keyboardMode; + bool m_visible; + QLocale m_locale; + + // Path to keyboardManager in PPS. + static const char *ms_PPSPath; + static const size_t ms_bufferSize; +}; + +#endif /* VIRTUALKEYBOARD_H_ */ diff --git a/src/plugins/platforms/blackberry/qbbwindow.cpp b/src/plugins/platforms/blackberry/qbbwindow.cpp new file mode 100644 index 0000000000..bc9f112b01 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbwindow.cpp @@ -0,0 +1,665 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbbwindow.h" +#include "qbbglcontext.h" +#include "qbbintegration.h" +#include "qbbscreen.h" + +#include +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +QBBWindow::QBBWindow(QWindow *window, screen_context_t context) + : QPlatformWindow(window), + m_screenContext(context), + m_window(0), + m_currentBufferIndex(-1), + m_previousBufferIndex(-1), + m_platformOpenGLContext(0), + m_screen(0), + m_parentWindow(0), + m_visible(true) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window << ", size =" << window->size(); +#endif + int result; + + // Create child QNX window + errno = 0; + result = screen_create_window_type(&m_window, m_screenContext, SCREEN_CHILD_WINDOW); + if (result != 0) { + qFatal("QBBWindow: failed to create window, errno=%d", errno); + } + + // Set window buffer usage based on rendering API + int val; + QSurface::SurfaceType surfaceType = window->surfaceType(); + switch (surfaceType) { + case QSurface::RasterSurface: + val = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE; + break; + case QSurface::OpenGLSurface: + val = SCREEN_USAGE_OPENGL_ES2; + break; + default: + qFatal("QBBWindow: unsupported window API"); + break; + } + + errno = 0; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_USAGE, &val); + if (result != 0) { + qFatal("QBBWindow: failed to set window buffer usage, errno=%d", errno); + } + + // Alpha channel is always pre-multiplied if present + errno = 0; + val = SCREEN_PRE_MULTIPLIED_ALPHA; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ALPHA_MODE, &val); + if (result != 0) { + qFatal("QBBWindow: failed to set window alpha mode, errno=%d", errno); + } + + // Make the window opaque + errno = 0; + val = SCREEN_TRANSPARENCY_NONE; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, &val); + if (result != 0) { + qFatal("QBBWindow: failed to set window transparency, errno=%d", errno); + } + + // Set the window swap interval + errno = 0; + val = 1; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SWAP_INTERVAL, &val); + if (result != 0) { + qFatal("QBBWindow: failed to set window swap interval, errno=%d", errno); + } + + // Assign the window to the primary display (this is the default specified by screen). + setScreen(QBBScreen::primaryDisplay()); + + // Add the window to the root of the hierarchy + QBBScreen::addWindow(this); + + // Add window to plugin's window mapper + QBBIntegration::addWindow(m_window, window); +} + +QBBWindow::~QBBWindow() +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + // Remove from plugin's window mapper + QBBIntegration::removeWindow(m_window); + + // Remove from parent's Hierarchy. + removeFromParent(); + QBBScreen::updateHierarchy(); + + // We shouldn't allow this case unless QT allows it. Does it? Or should we send the + // handleCloseEvent on all children when this window is deleted? + if (m_childWindows.size() > 0) + qFatal("QBBWindow: window destroyed before children!"); + + // Cleanup QNX window and its buffers + screen_destroy_window(m_window); +} + +void QBBWindow::setGeometry(const QRect &rect) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window() << ", (" << rect.x() << "," << rect.y() << "," << rect.width() << "," << rect.height() << ")"; +#endif + + QRect oldGeometry = geometry(); + + // Call base class method + QPlatformWindow::setGeometry(rect); + + // Set window geometry equal to widget geometry + errno = 0; + int val[2]; + val[0] = rect.x(); + val[1] = rect.y(); + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val); + if (result != 0) { + qFatal("QBBWindow: failed to set window position, errno=%d", errno); + } + + errno = 0; + val[0] = rect.width(); + val[1] = rect.height(); + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val); + if (result != 0) { + qFatal("QBBWindow: failed to set window size, errno=%d", errno); + } + + // Set viewport size equal to window size + errno = 0; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val); + if (result != 0) { + qFatal("QBBWindow: failed to set window source size, errno=%d", errno); + } + + // Now move all children. + QPoint offset; + if (!oldGeometry.isEmpty()) { + offset = rect.topLeft(); + offset -= oldGeometry.topLeft(); + + QList::iterator it; + for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) { + (*it)->offset(offset); + } + } +} + +void QBBWindow::offset(const QPoint &offset) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + // Move self and then children. + QRect newGeometry = geometry(); + newGeometry.translate(offset); + + // Call the base class + QPlatformWindow::setGeometry(newGeometry); + + int val[2]; + + errno = 0; + val[0] = newGeometry.x(); + val[1] = newGeometry.y(); + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val); + if (result != 0) { + qFatal("QBBWindow: failed to set window position, errno=%d", errno); + } + + QList::iterator it; + for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) { + (*it)->offset(offset); + } +} + +void QBBWindow::setVisible(bool visible) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window() << "visible =" << visible; +#endif + + m_visible = visible; + + QBBWindow *root = this; + while (root->m_parentWindow) + root = root->m_parentWindow; + + root->updateVisibility(root->m_visible); + + window()->requestActivateWindow(); +} + +void QBBWindow::updateVisibility(bool parentVisible) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "parentVisible =" << parentVisible << "window =" << window(); +#endif + // Set window visibility + errno = 0; + int val = (m_visible && parentVisible) ? 1 : 0; + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &val); + if (result != 0) { + qFatal("QBBWindow: failed to set window visibility, errno=%d", errno); + } + + QList::iterator it; + for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) { + (*it)->updateVisibility(m_visible && parentVisible); + } +} + +void QBBWindow::setOpacity(qreal level) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window() << "opacity =" << level; +#endif + // Set window global alpha + errno = 0; + int val = (int)(level * 255); + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_GLOBAL_ALPHA, &val); + if (result != 0) { + qFatal("QBBWindow: failed to set window global alpha, errno=%d", errno); + } + + // TODO: How to handle children of this window? If we change all the visibilities, then + // the transparency will look wrong... +} + +void QBBWindow::setBufferSize(const QSize &size) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window() << "size =" << size; +#endif + // Set window buffer size + errno = 0; + int val[2] = { size.width(), size.height() }; + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val); + if (result != 0) { + qFatal("QBBWindow: failed to set window buffer size, errno=%d", errno); + } + + // Create window buffers if they do not exist + if (!hasBuffers()) { + // Get pixel format from EGL config if using OpenGL; + // otherwise inherit pixel format of window's screen + if (m_platformOpenGLContext != 0) { + val[0] = platformWindowFormatToNativeFormat(m_platformOpenGLContext->format()); + } else { + val[0] = m_screen->nativeFormat(); + } + + errno = 0; + result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val); + if (result != 0) { + qFatal("QBBWindow: failed to set window pixel format, errno=%d", errno); + } + + errno = 0; + result = screen_create_window_buffers(m_window, MAX_BUFFER_COUNT); + if (result != 0) { + qFatal("QBBWindow: failed to create window buffers, errno=%d", errno); + } + } + + // Cache new buffer size + m_bufferSize = size; + + // Buffers were destroyed; reacquire them + m_currentBufferIndex = -1; + m_previousDirty = QRegion(); + m_scrolled = QRegion(); +} + +QBBBuffer &QBBWindow::renderBuffer() +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + // Check if render buffer is invalid + if (m_currentBufferIndex == -1) { + // Get all buffers available for rendering + errno = 0; + screen_buffer_t buffers[MAX_BUFFER_COUNT]; + int result = screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)buffers); + if (result != 0) { + qFatal("QBBWindow: failed to query window buffers, errno=%d", errno); + } + + // Wrap each buffer + for (int i = 0; i < MAX_BUFFER_COUNT; ++i) { + m_buffers[i] = QBBBuffer(buffers[i]); + } + + // Use the first available render buffer + m_currentBufferIndex = 0; + m_previousBufferIndex = -1; + } + + return m_buffers[m_currentBufferIndex]; +} + +void QBBWindow::scroll(const QRegion ®ion, int dx, int dy, bool flush) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + copyBack(region, dx, dy, flush); + m_scrolled += region; +} + +void QBBWindow::post(const QRegion &dirty) +{ + // Check if render buffer exists and something was rendered + if (m_currentBufferIndex != -1 && !dirty.isEmpty()) { +#if defined(QBBWINDOW_DEBUG) + qDebug() << "QBBWindow::post - window =" << window(); +#endif + QBBBuffer ¤tBuffer = m_buffers[m_currentBufferIndex]; + + // Copy unmodified region from old render buffer to new render buffer; + // required to allow partial updates + QRegion preserve = m_previousDirty - dirty - m_scrolled; + copyBack(preserve, 0, 0); + + // Calculate region that changed + QRegion modified = preserve + dirty + m_scrolled; + QRect rect = modified.boundingRect(); + int dirtyRect[4] = { rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height() }; + + // Update the display with contents of render buffer + errno = 0; + int result = screen_post_window(m_window, currentBuffer.nativeBuffer(), 1, dirtyRect, 0); + if (result != 0) { + qFatal("QBBWindow: failed to post window buffer, errno=%d", errno); + } + + // Advance to next nender buffer + m_previousBufferIndex = m_currentBufferIndex++; + if (m_currentBufferIndex >= MAX_BUFFER_COUNT) { + m_currentBufferIndex = 0; + } + + // Save modified region and clear scrolled region + m_previousDirty = dirty; + m_scrolled = QRegion(); + + // Notify screen that window posted + if (m_screen != 0) { + m_screen->onWindowPost(this); + } + } +} + +void QBBWindow::setScreen(QBBScreen *platformScreen) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window() << "platformScreen =" << platformScreen; +#endif + + if (m_screen == platformScreen) + return; + + m_screen = platformScreen; + + // Move window to proper screen/display + errno = 0; + screen_display_t display = platformScreen->nativeDisplay(); + int result = screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display); + if (result != 0) { + qFatal("QBBWindow: failed to set window display, errno=%d", errno); + } + + // Add window to display's window group + errno = 0; + result = screen_join_window_group(m_window, platformScreen->windowGroupName()); + if (result != 0) { + qFatal("QBBWindow: failed to join window group, errno=%d", errno); + } + + QList::iterator it; + for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) { + // Only subwindows and tooltips need necessarily be moved to another display with the window. + if ((window()->windowType() & Qt::WindowType_Mask) == Qt::SubWindow || + (window()->windowType() & Qt::WindowType_Mask) == Qt::ToolTip) + (*it)->setScreen(platformScreen); + } + + QBBScreen::updateHierarchy(); +} + +void QBBWindow::removeFromParent() +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + // Remove from old Hierarchy position + if (m_parentWindow) { + if (m_parentWindow->m_childWindows.removeAll(this)) + m_parentWindow = 0; + else + qFatal("QBBWindow: Window Hierarchy broken; window has parent, but parent hasn't got child."); + } else { + QBBScreen::removeWindow(this); + } +} + +void QBBWindow::setParent(const QPlatformWindow *window) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << this->window() << "platformWindow =" << window; +#endif + // Cast away the const, we need to modify the hierarchy. + QBBWindow *newParent = 0; + + if (window) + newParent = static_cast((QPlatformWindow *)window); + + if (newParent == m_parentWindow) + return; + + removeFromParent(); + m_parentWindow = newParent; + + // Add to new hierarchy position. + if (m_parentWindow) { + if (m_parentWindow->m_screen != m_screen) + setScreen(m_parentWindow->m_screen); + + m_parentWindow->m_childWindows.push_back(this); + } else { + QBBScreen::addWindow(this); + } + + QBBScreen::updateHierarchy(); +} + +void QBBWindow::raise() +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + + QBBWindow *oldParent = m_parentWindow; + if (oldParent) { + removeFromParent(); + oldParent->m_childWindows.push_back(this); + } else { + QBBScreen::raiseWindow(this); + } + + QBBScreen::updateHierarchy(); +} + +void QBBWindow::lower() +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + + QBBWindow *oldParent = m_parentWindow; + if (oldParent) { + removeFromParent(); + oldParent->m_childWindows.push_front(this); + } else { + QBBScreen::lowerWindow(this); + } + + QBBScreen::updateHierarchy(); +} + +void QBBWindow::requestActivateWindow() +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + + // TODO: Tell screen to set keyboard focus to this window. + + // Notify that we gained focus. + gainedFocus(); +} + +void QBBWindow::gainedFocus() +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + + // Got focus + QWindowSystemInterface::handleWindowActivated(window()); +} + +void QBBWindow::setPlatformOpenGLContext(QBBGLContext *platformOpenGLContext) +{ + // This function does not take ownership of the platform gl context. + // It is owned by the frontend QOpenGLContext + m_platformOpenGLContext = platformOpenGLContext; +} + +void QBBWindow::updateZorder(int &topZorder) +{ + errno = 0; + int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ZORDER, &topZorder); + topZorder++; + + if (result != 0) + qFatal("QBBWindow: failed to set window z-order=%d, errno=%d, mWindow=%p", topZorder, errno, m_window); + + QList::const_iterator it; + + for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) + (*it)->updateZorder(topZorder); +} + +void QBBWindow::copyBack(const QRegion ®ion, int dx, int dy, bool flush) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO << "window =" << window(); +#endif + int result; + + // Abort if previous buffer is invalid + if (m_previousBufferIndex == -1) { + return; + } + + // Abort if nothing to copy + if (region.isEmpty()) { + return; + } + + QBBBuffer ¤tBuffer = m_buffers[m_currentBufferIndex]; + QBBBuffer &previousBuffer = m_buffers[m_previousBufferIndex]; + + // Break down region into non-overlapping rectangles + QVector rects = region.rects(); + for (int i = rects.size() - 1; i >= 0; i--) { + // Clip rectangle to bounds of target + QRect rect = rects[i].intersected( currentBuffer.rect() ); + + if (rect.isEmpty()) + continue; + + // Setup blit operation + int attribs[] = { SCREEN_BLIT_SOURCE_X, rect.x(), + SCREEN_BLIT_SOURCE_Y, rect.y(), + SCREEN_BLIT_SOURCE_WIDTH, rect.width(), + SCREEN_BLIT_SOURCE_HEIGHT, rect.height(), + SCREEN_BLIT_DESTINATION_X, rect.x() + dx, + SCREEN_BLIT_DESTINATION_Y, rect.y() + dy, + SCREEN_BLIT_DESTINATION_WIDTH, rect.width(), + SCREEN_BLIT_DESTINATION_HEIGHT, rect.height(), + SCREEN_BLIT_END }; + + // Queue blit operation + errno = 0; + result = screen_blit(m_screenContext, currentBuffer.nativeBuffer(), previousBuffer.nativeBuffer(), attribs); + if (result != 0) { + qFatal("QBBWindow: failed to blit buffers, errno=%d", errno); + } + } + + // Check if flush requested + if (flush) { + // Wait for all blits to complete + errno = 0; + result = screen_flush_blits(m_screenContext, SCREEN_WAIT_IDLE); + if (result != 0) { + qFatal("QBBWindow: failed to flush blits, errno=%d", errno); + } + + // Buffer was modified outside the CPU + currentBuffer.invalidateInCache(); + } +} + +int QBBWindow::platformWindowFormatToNativeFormat(const QSurfaceFormat &format) +{ +#if defined(QBBWINDOW_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + // Extract size of colour channels from window format + int redSize = format.redBufferSize(); + if (redSize == -1) { + qFatal("QBBWindow: red size not defined"); + } + + int greenSize = format.greenBufferSize(); + if (greenSize == -1) { + qFatal("QBBWindow: green size not defined"); + } + + int blueSize = format.blueBufferSize(); + if (blueSize == -1) { + qFatal("QBBWindow: blue size not defined"); + } + + // select matching native format + if (redSize == 5 && greenSize == 6 && blueSize == 5) { + return SCREEN_FORMAT_RGB565; + } else if (redSize == 8 && greenSize == 8 && blueSize == 8) { + return SCREEN_FORMAT_RGBA8888; + } else { + qFatal("QBBWindow: unsupported pixel format"); + return 0; + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbwindow.h b/src/plugins/platforms/blackberry/qbbwindow.h new file mode 100644 index 0000000000..ffdeba423a --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbwindow.h @@ -0,0 +1,133 @@ +/*************************************************************************** +** +** Copyright (C) 2011 - 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBWINDOW_H +#define QBBWINDOW_H + +#include + +#include "qbbbuffer.h" + +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +// all surfaces double buffered +#define MAX_BUFFER_COUNT 2 + +class QBBGLContext; +class QBBScreen; + +class QPlatformGLContext; +class QSurfaceFormat; + +class QBBWindow : public QPlatformWindow +{ +friend class QBBScreen; +public: + QBBWindow(QWindow *window, screen_context_t context); + virtual ~QBBWindow(); + + virtual void setGeometry(const QRect &rect); + virtual void setVisible(bool visible); + virtual void setOpacity(qreal level); + + virtual WId winId() const { return (WId)m_window; } + screen_window_t nativeHandle() const { return m_window; } + + void setBufferSize(const QSize &size); + QSize bufferSize() const { return m_bufferSize; } + bool hasBuffers() const { return !m_bufferSize.isEmpty(); } + + QBBBuffer &renderBuffer(); + void scroll(const QRegion ®ion, int dx, int dy, bool flush=false); + void post(const QRegion &dirty); + + void setScreen(QBBScreen *platformScreen); + + virtual void setParent(const QPlatformWindow *window); + virtual void raise(); + virtual void lower(); + virtual void requestActivateWindow(); + + void gainedFocus(); + + QBBScreen *screen() const { return m_screen; } + const QList& children() const { return m_childWindows; } + + void setPlatformOpenGLContext(QBBGLContext *platformOpenGLContext); + QBBGLContext *platformOpenGLContext() const { return m_platformOpenGLContext; } + +private: + void removeFromParent(); + void offset(const QPoint &offset); + void updateVisibility(bool parentVisible); + void updateZorder(int &topZorder); + + void fetchBuffers(); + + void copyBack(const QRegion ®ion, int dx, int dy, bool flush=false); + + static int platformWindowFormatToNativeFormat(const QSurfaceFormat &format); + + screen_context_t m_screenContext; + screen_window_t m_window; + QSize m_bufferSize; + QBBBuffer m_buffers[MAX_BUFFER_COUNT]; + int m_currentBufferIndex; + int m_previousBufferIndex; + QRegion m_previousDirty; + QRegion m_scrolled; + + QBBGLContext *m_platformOpenGLContext; + QBBScreen *m_screen; + QList m_childWindows; + QBBWindow *m_parentWindow; + bool m_visible; +}; + +QT_END_NAMESPACE + +#endif // QBBWINDOW_H diff --git a/src/plugins/platforms/platforms.pro b/src/plugins/platforms/platforms.pro index c2e6d8cea7..8f728a5fb0 100644 --- a/src/plugins/platforms/platforms.pro +++ b/src/plugins/platforms/platforms.pro @@ -11,3 +11,7 @@ mac { } win32: SUBDIRS += windows + +blackberry-armv7le-qcc { + SUBDIRS += blackberry +} -- cgit v1.2.3 From 44174332c996046a147c109769f28e4bee0f9a74 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 23 Feb 2012 17:27:53 +0200 Subject: Rename remaining references to QInputPanel Change-Id: I747d37d10c78af6ad00322d5bd8d29c6b343828c Reviewed-by: Lars Knoll --- src/corelib/tools/qlocale.qdoc | 4 ++-- src/gui/kernel/qplatforminputcontext_qpa.h | 2 +- src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h | 2 +- .../platforminputcontexts/maliit/qmaliitplatforminputcontext.h | 2 +- src/plugins/platforms/windows/qwindowsinputcontext.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc index 2fff58333d..3a386c17d6 100644 --- a/src/corelib/tools/qlocale.qdoc +++ b/src/corelib/tools/qlocale.qdoc @@ -89,7 +89,7 @@ pair; it does not use the system locale database. \note For the current keyboard input locale take a look at - QInputPanel::locale(). + QInputMethod::locale(). QLocale's data is based on Common Locale Data Repository v1.8.1. @@ -114,7 +114,7 @@ California, Berkeley and its contributors. \sa QString::arg(), QString::toInt(), QString::toDouble(), - QInputPanel::locale() + QInputMethod::locale() */ /*! diff --git a/src/gui/kernel/qplatforminputcontext_qpa.h b/src/gui/kernel/qplatforminputcontext_qpa.h index 77c3811d95..c7d823d662 100644 --- a/src/gui/kernel/qplatforminputcontext_qpa.h +++ b/src/gui/kernel/qplatforminputcontext_qpa.h @@ -64,7 +64,7 @@ public: virtual void reset(); virtual void commit(); virtual void update(Qt::InputMethodQueries); - virtual void invokeAction(QInputPanel::Action, int cursorPosition); + virtual void invokeAction(QInputMethod::Action, int cursorPosition); virtual bool filterEvent(const QEvent *event); virtual QRectF keyboardRect() const; void emitKeyboardRectChanged(); diff --git a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h index c5064663a1..ca8f492c5d 100644 --- a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h +++ b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h @@ -57,7 +57,7 @@ public: bool isValid() const; - void invokeAction(QInputPanel::Action a, int x); + void invokeAction(QInputMethod::Action a, int x); void reset(); void commit(); void update(Qt::InputMethodQueries); diff --git a/src/plugins/platforminputcontexts/maliit/qmaliitplatforminputcontext.h b/src/plugins/platforminputcontexts/maliit/qmaliitplatforminputcontext.h index 3760885641..a17abe7cbb 100644 --- a/src/plugins/platforminputcontexts/maliit/qmaliitplatforminputcontext.h +++ b/src/plugins/platforminputcontexts/maliit/qmaliitplatforminputcontext.h @@ -59,7 +59,7 @@ public: bool isValid() const; - void invokeAction(QInputPanel::Action action, int x); + void invokeAction(QInputMethod::Action action, int x); void reset(void); void update(Qt::InputMethodQueries); virtual QRectF keyboardRect() const; diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.h b/src/plugins/platforms/windows/qwindowsinputcontext.h index a33d24e2f6..610bad08dd 100644 --- a/src/plugins/platforms/windows/qwindowsinputcontext.h +++ b/src/plugins/platforms/windows/qwindowsinputcontext.h @@ -70,7 +70,7 @@ public: virtual void reset(); virtual void update(Qt::InputMethodQueries); - virtual void invokeAction(QInputPanel::Action, int cursorPosition); + virtual void invokeAction(QInputMethod::Action, int cursorPosition); static QWindowsInputContext *instance(); -- cgit v1.2.3 From c7a059e376bd0105ad470017a774715b112de8b4 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Tue, 28 Feb 2012 09:25:20 +0100 Subject: Compile SHA-2 code on systems without stdint.h stdint.h is a C99-ism, which isn't available everywhere. The sha.h header tells us we need 4 typedefs. Add these to qcryptographichash.cpp before including sha.h and comment out the stdint.h include in sha.h. Change-Id: I1ede9569fa7eaa84de3befeb3c58cc6a05aa522c Reviewed-by: Oliver Wolff Reviewed-by: Bradley T. Hughes --- src/3rdparty/rfc6234/sha.h | 3 ++- src/corelib/tools/qcryptographichash.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/3rdparty/rfc6234/sha.h b/src/3rdparty/rfc6234/sha.h index 1ffd688079..9c26f0253c 100644 --- a/src/3rdparty/rfc6234/sha.h +++ b/src/3rdparty/rfc6234/sha.h @@ -70,7 +70,8 @@ * */ -#include +// stdint.h include commented out by Nokia, it is not available on all platforms. +// #include /* * If you do not have the ISO standard stdint.h header file, then you * must typedef the following: diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 9c27af032f..31a0fdc5e6 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -47,6 +47,19 @@ #include "../../3rdparty/md4/md4.cpp" #include "../../3rdparty/sha1/sha1.cpp" +/* + These typedefs are needed by the RFC6234 code. Normally they would come + from from stdint.h, but since this header is not available on all platforms + (MSVC 2008, for example), we need to define them ourselves. +*/ +typedef QT_PREPEND_NAMESPACE(quint64) uint64_t; +typedef QT_PREPEND_NAMESPACE(quint32) uint32_t; +typedef QT_PREPEND_NAMESPACE(quint8) uint8_t; +typedef QT_PREPEND_NAMESPACE(qint16) int_least16_t; +// Header from rfc6234 with 1 modification: +// sha1.h - commented out '#include ' on line 74 +#include "../../3rdparty/rfc6234/sha.h" + /* These 2 functions replace macros of the same name in sha224-256.c and sha384-512.c. Originally, these macros relied on a global static 'addTemp' @@ -57,8 +70,6 @@ 2. static variables are not thread-safe, we do not want multiple threads computing a hash to corrupt one another */ -// Header from rfc6234 without modifications -#include "../../3rdparty/rfc6234/sha.h" static int SHA224_256AddLength(SHA256Context *context, unsigned int length); static int SHA384_512AddLength(SHA512Context *context, unsigned int length); -- cgit v1.2.3 From 018e78575c6f7f5a90b41274468a26b09b909443 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 27 Feb 2012 16:45:27 +0100 Subject: Make the CMake files work with directory overrides. This allows us to create correct CMake config files when Qt is configured with directories outside of the prefix (which Qt allows), and also allows us to use correct values when a 'longer' relative lib directory is used such as lib/x86_64-linux-gnu. Change-Id: I6f88255a23752dc5b84cb20ce13fdeeee9d5ad51 Reviewed-by: Oswald Buddenhagen Reviewed-by: Alexander Neundorf Reviewed-by: Stephen Kelly --- src/corelib/Qt5CoreConfigExtras.cmake.in | 29 +++++++++++++++++++++++------ src/widgets/Qt5WidgetsConfigExtras.cmake.in | 7 +++++-- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index 4873391f52..67598f4f70 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -1,12 +1,21 @@ get_filename_component(_qt5_corelib_install_prefix ${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR} ABSOLUTE) -# Required by default: -set(QT_QMAKE_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/qmake$$CMAKE_BIN_SUFFIX\") -set(QT_MOC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/moc$$CMAKE_BIN_SUFFIX\") -set(QT_RCC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/rcc$$CMAKE_BIN_SUFFIX\") +!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE) +set(QT_QMAKE_EXECUTABLE \"${_qt5_corelib_install_prefix}/$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\") +set(QT_MOC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\") +set(QT_RCC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\") +!!ELSE +set(QT_QMAKE_EXECUTABLE \"$${CMAKE_BIN_DIR}qmake$$CMAKE_BIN_SUFFIX\") +set(QT_MOC_EXECUTABLE \"$${CMAKE_BIN_DIR}moc$$CMAKE_BIN_SUFFIX\") +set(QT_RCC_EXECUTABLE \"$${CMAKE_BIN_DIR}rcc$$CMAKE_BIN_SUFFIX\") +!!ENDIF +!!IF isEmpty(CMAKE_DATA_DIR_IS_ABSOLUTE) list(APPEND Qt5Core_INCLUDE_DIRS \"${_qt5_corelib_install_prefix}/mkspecs/default\") +!!ELSE +list(APPEND Qt5Core_INCLUDE_DIRS \"$${CMAKE_DATA_DIR}mkspecs/default\") +!!ENDIF !!IF !isEmpty(CMAKE_ADD_FPIE_FLAGS) set(Qt5Core_EXECUTABLE_COMPILE_FLAGS "-fPIE") @@ -32,14 +41,22 @@ endif() !!IF !isEmpty(debug_type) set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(Qt5::WinMain PROPERTIES - IMPORTED_LOCATION_DEBUG "${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}" +!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) + IMPORTED_LOCATION_DEBUG "${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}" +!!ELSE + IMPORTED_LOCATION_DEBUG "$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_DEBUG}" +!!ENDIF ) !!ENDIF !!IF !isEmpty(release_type) set_property(TARGET Qt5::WinMain APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(Qt5::WinMain PROPERTIES - IMPORTED_LOCATION_RELEASE \"${_qt5_install_prefix}/$$CMAKE_LIB_DIR/$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\" +!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE) + IMPORTED_LOCATION_RELEASE \"${_qt5_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\" +!!ELSE + IMPORTED_LOCATION_RELEASE \"$${CMAKE_LIB_DIR}$${CMAKE_WINMAIN_FILE_LOCATION_RELEASE}\" +!!ENDIF ) !!ENDIF !!ENDIF diff --git a/src/widgets/Qt5WidgetsConfigExtras.cmake.in b/src/widgets/Qt5WidgetsConfigExtras.cmake.in index baf34b2fbc..93d3c6998a 100644 --- a/src/widgets/Qt5WidgetsConfigExtras.cmake.in +++ b/src/widgets/Qt5WidgetsConfigExtras.cmake.in @@ -1,5 +1,8 @@ get_filename_component(_qt5_widgets_install_prefix ${CMAKE_CURRENT_LIST_DIR}/$${CMAKE_RELATIVE_INSTALL_DIR} ABSOLUTE) -# Not Required by default: -set(QT_UIC_EXECUTABLE \"${_qt5_widgets_install_prefix}/$$CMAKE_BIN_DIR/uic$$CMAKE_BIN_SUFFIX\") +!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE) +set(QT_UIC_EXECUTABLE \"${_qt5_widgets_install_prefix}/$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\") +!!ELSE +set(QT_UIC_EXECUTABLE \"$${CMAKE_BIN_DIR}uic$$CMAKE_BIN_SUFFIX\") +!!ENDIF -- cgit v1.2.3