summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/accessible/qaccessible_win.cpp8
-rw-r--r--src/gui/dialogs/qcolordialog.cpp9
-rw-r--r--src/gui/dialogs/qcolordialog_mac.mm38
-rw-r--r--src/gui/dialogs/qdialog.cpp18
-rw-r--r--src/gui/dialogs/qdialog.h4
-rw-r--r--src/gui/dialogs/qdialog_p.h2
-rw-r--r--src/gui/dialogs/qerrormessage.cpp8
-rw-r--r--src/gui/dialogs/qfiledialog.cpp6
-rw-r--r--src/gui/dialogs/qfiledialog_mac.mm19
-rw-r--r--src/gui/dialogs/qfiledialog_win.cpp10
-rw-r--r--src/gui/dialogs/qfilesystemmodel_p.h18
-rw-r--r--src/gui/dialogs/qfontdialog.cpp4
-rw-r--r--src/gui/dialogs/qmessagebox.cpp23
-rw-r--r--src/gui/dialogs/qmessagebox.h2
-rw-r--r--src/gui/dialogs/qprintpreviewdialog.cpp142
-rw-r--r--src/gui/dialogs/qwizard.cpp14
-rw-r--r--src/gui/embedded/embedded.pri19
-rw-r--r--src/gui/embedded/qkbd_defaultmap_qws_p.h796
-rw-r--r--src/gui/embedded/qkbd_qws.cpp481
-rw-r--r--src/gui/embedded/qkbd_qws.h22
-rw-r--r--src/gui/embedded/qkbd_qws_p.h (renamed from src/gui/painting/qpaintengine_d3d_p.h)133
-rw-r--r--src/gui/embedded/qkbddriverfactory_qws.cpp14
-rw-r--r--src/gui/embedded/qkbdlinuxinput_qws.cpp241
-rw-r--r--src/gui/embedded/qkbdlinuxinput_qws.h (renamed from src/gui/embedded/qkbdusb_qws.h)24
-rw-r--r--src/gui/embedded/qkbdpc101_qws.cpp485
-rw-r--r--src/gui/embedded/qkbdsl5000_qws.cpp25
-rw-r--r--src/gui/embedded/qkbdsl5000_qws.h19
-rw-r--r--src/gui/embedded/qkbdtty_qws.cpp300
-rw-r--r--src/gui/embedded/qkbdtty_qws.h8
-rw-r--r--src/gui/embedded/qkbdum_qws.cpp9
-rw-r--r--src/gui/embedded/qkbdusb_qws.cpp401
-rw-r--r--src/gui/embedded/qscreen_qws.cpp8
-rw-r--r--src/gui/embedded/qwscommand_qws.cpp1
-rw-r--r--src/gui/embedded/qwssignalhandler.cpp6
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp579
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h4
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h28
-rw-r--r--src/gui/graphicsview/qgraphicslayoutitem.cpp134
-rw-r--r--src/gui/graphicsview/qgraphicslayoutitem_p.h8
-rw-r--r--src/gui/graphicsview/qgraphicsproxywidget.cpp9
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp149
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h6
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp194
-rw-r--r--src/gui/graphicsview/qgraphicsview_p.h9
-rw-r--r--src/gui/graphicsview/qgraphicswidget.cpp108
-rw-r--r--src/gui/graphicsview/qgraphicswidget_p.cpp258
-rw-r--r--src/gui/graphicsview/qgraphicswidget_p.h70
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp18
-rw-r--r--src/gui/gui.pro1
-rw-r--r--src/gui/image/image.pri1
-rw-r--r--src/gui/image/qicon.cpp2
-rw-r--r--src/gui/image/qimage.cpp8
-rw-r--r--src/gui/image/qnativeimage.cpp6
-rw-r--r--src/gui/image/qnativeimage_p.h2
-rw-r--r--src/gui/image/qpixmap.cpp66
-rw-r--r--src/gui/image/qpixmap.h10
-rw-r--r--src/gui/image/qpixmap_mac.cpp8
-rw-r--r--src/gui/image/qpixmap_mac_p.h1
-rw-r--r--src/gui/image/qpixmap_raster.cpp19
-rw-r--r--src/gui/image/qpixmap_raster_p.h8
-rw-r--r--src/gui/image/qpixmap_win.cpp12
-rw-r--r--src/gui/image/qpixmap_x11.cpp10
-rw-r--r--src/gui/image/qpixmap_x11_p.h1
-rw-r--r--src/gui/image/qpixmapcache.cpp367
-rw-r--r--src/gui/image/qpixmapcache.h27
-rw-r--r--src/gui/image/qpixmapcache_p.h (renamed from src/gui/embedded/qkbdpc101_qws.h)93
-rw-r--r--src/gui/image/qpixmapdata.cpp8
-rw-r--r--src/gui/image/qpixmapdata_p.h3
-rw-r--r--src/gui/inputmethod/qinputcontext_p.h4
-rw-r--r--src/gui/inputmethod/qmacinputcontext_mac.cpp20
-rw-r--r--src/gui/inputmethod/qmacinputcontext_p.h5
-rw-r--r--src/gui/inputmethod/qwininputcontext_p.h1
-rw-r--r--src/gui/inputmethod/qwininputcontext_win.cpp21
-rw-r--r--src/gui/inputmethod/qwsinputcontext_p.h1
-rw-r--r--src/gui/inputmethod/qwsinputcontext_qws.cpp11
-rw-r--r--src/gui/inputmethod/qximinputcontext_x11.cpp3
-rw-r--r--src/gui/itemviews/qabstractitemview.cpp32
-rw-r--r--src/gui/itemviews/qabstractitemview_p.h2
-rw-r--r--src/gui/itemviews/qdirmodel.cpp11
-rw-r--r--src/gui/itemviews/qfileiconprovider.cpp14
-rw-r--r--src/gui/itemviews/qheaderview.cpp39
-rw-r--r--src/gui/itemviews/qheaderview_p.h9
-rw-r--r--src/gui/itemviews/qlistview.cpp28
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp51
-rw-r--r--src/gui/itemviews/qtableview.cpp333
-rw-r--r--src/gui/itemviews/qtableview_p.h98
-rw-r--r--src/gui/itemviews/qtreeview.cpp46
-rw-r--r--src/gui/kernel/kernel.pri2
-rw-r--r--src/gui/kernel/qaction.cpp4
-rw-r--r--src/gui/kernel/qapplication.cpp35
-rw-r--r--src/gui/kernel/qapplication.h4
-rw-r--r--src/gui/kernel/qapplication_mac.mm13
-rw-r--r--src/gui/kernel/qapplication_p.h4
-rw-r--r--src/gui/kernel/qapplication_qws.cpp9
-rw-r--r--src/gui/kernel/qapplication_win.cpp106
-rw-r--r--src/gui/kernel/qapplication_x11.cpp26
-rw-r--r--src/gui/kernel/qclipboard.cpp24
-rw-r--r--src/gui/kernel/qclipboard_x11.cpp2
-rw-r--r--src/gui/kernel/qcocoaview_mac.mm14
-rw-r--r--src/gui/kernel/qcocoaview_mac_p.h1
-rw-r--r--src/gui/kernel/qcursor_win.cpp8
-rw-r--r--src/gui/kernel/qdesktopwidget_win.cpp12
-rw-r--r--src/gui/kernel/qdnd_x11.cpp24
-rw-r--r--src/gui/kernel/qevent.cpp11
-rw-r--r--src/gui/kernel/qevent_p.h4
-rw-r--r--src/gui/kernel/qformlayout.cpp6
-rw-r--r--src/gui/kernel/qkeymapper.cpp2
-rw-r--r--src/gui/kernel/qkeymapper_mac.cpp32
-rw-r--r--src/gui/kernel/qkeysequence.cpp112
-rw-r--r--src/gui/kernel/qkeysequence.h4
-rw-r--r--src/gui/kernel/qlayoutitem.cpp6
-rw-r--r--src/gui/kernel/qmime_mac.cpp119
-rw-r--r--src/gui/kernel/qshortcutmap.cpp6
-rw-r--r--src/gui/kernel/qt_x11_p.h4
-rw-r--r--src/gui/kernel/qwidget.cpp269
-rw-r--r--src/gui/kernel/qwidget.h5
-rw-r--r--src/gui/kernel/qwidget_mac.mm67
-rw-r--r--src/gui/kernel/qwidget_p.h531
-rw-r--r--src/gui/kernel/qwidget_qws.cpp17
-rw-r--r--src/gui/kernel/qwidget_win.cpp100
-rw-r--r--src/gui/kernel/qwidget_wince.cpp21
-rw-r--r--src/gui/kernel/qwidget_x11.cpp45
-rw-r--r--src/gui/kernel/qx11embed_x11.cpp19
-rw-r--r--src/gui/mac/images/leopard-unified-toolbar-on.pngbin0 -> 356 bytes
-rw-r--r--src/gui/mac/macresources.qrc (renamed from src/gui/mac/maccursors.qrc)3
-rw-r--r--src/gui/math3d/math3d.pri15
-rw-r--r--src/gui/math3d/qgenericmatrix.cpp251
-rw-r--r--src/gui/math3d/qgenericmatrix.h371
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp1670
-rw-r--r--src/gui/math3d/qmatrix4x4.h977
-rw-r--r--src/gui/math3d/qquaternion.cpp584
-rw-r--r--src/gui/math3d/qquaternion.h337
-rw-r--r--src/gui/math3d/qvector2d.cpp417
-rw-r--r--src/gui/math3d/qvector2d.h256
-rw-r--r--src/gui/math3d/qvector3d.cpp565
-rw-r--r--src/gui/math3d/qvector3d.h284
-rw-r--r--src/gui/math3d/qvector4d.cpp518
-rw-r--r--src/gui/math3d/qvector4d.h289
-rw-r--r--src/gui/painting/painting.pri10
-rw-r--r--src/gui/painting/qbezier.cpp24
-rw-r--r--src/gui/painting/qblendfunctions.cpp5
-rw-r--r--src/gui/painting/qcolor.cpp4
-rw-r--r--src/gui/painting/qcolor_p.cpp2
-rw-r--r--src/gui/painting/qcolormap_win.cpp2
-rw-r--r--src/gui/painting/qdrawhelper.cpp1010
-rw-r--r--src/gui/painting/qdrawutil.cpp297
-rw-r--r--src/gui/painting/qdrawutil.h38
-rw-r--r--src/gui/painting/qmatrix.cpp63
-rw-r--r--src/gui/painting/qmatrix.h20
-rw-r--r--src/gui/painting/qpaintengine_d3d.cpp4576
-rw-r--r--src/gui/painting/qpaintengine_d3d.fx608
-rw-r--r--src/gui/painting/qpaintengine_d3d.qrc5
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp40
-rw-r--r--src/gui/painting/qpainter.cpp24
-rw-r--r--src/gui/painting/qpainterpath.cpp66
-rw-r--r--src/gui/painting/qpainterpath.h12
-rw-r--r--src/gui/painting/qpainterpath_p.h2
-rw-r--r--src/gui/painting/qpathclipper.cpp36
-rw-r--r--src/gui/painting/qpolygon.cpp59
-rw-r--r--src/gui/painting/qpolygon.h13
-rw-r--r--src/gui/painting/qprinter.cpp14
-rw-r--r--src/gui/painting/qstroker.cpp12
-rw-r--r--src/gui/painting/qstroker_p.h2
-rw-r--r--src/gui/painting/qtessellator.cpp2
-rw-r--r--src/gui/painting/qtransform.cpp218
-rw-r--r--src/gui/painting/qtransform.h30
-rw-r--r--src/gui/painting/qwindowsurface_d3d.cpp169
-rw-r--r--src/gui/painting/qwindowsurface_raster.cpp12
-rw-r--r--src/gui/styles/gtksymbols.cpp224
-rw-r--r--src/gui/styles/qcleanlooksstyle.cpp55
-rw-r--r--src/gui/styles/qcommonstyle.cpp117
-rw-r--r--src/gui/styles/qmacstyle_mac.mm127
-rw-r--r--src/gui/styles/qmotifstyle.cpp4
-rw-r--r--src/gui/styles/qplastiquestyle.cpp7
-rw-r--r--src/gui/styles/qstyle.cpp4
-rw-r--r--src/gui/styles/qstyle.h3
-rw-r--r--src/gui/styles/qstylehelper.cpp353
-rw-r--r--src/gui/styles/qstylehelper_p.h (renamed from src/gui/painting/qwindowsurface_d3d_p.h)54
-rw-r--r--src/gui/styles/qstyleoption.cpp44
-rw-r--r--src/gui/styles/qstyleoption.h1
-rw-r--r--src/gui/styles/qstylesheetstyle.cpp246
-rw-r--r--src/gui/styles/qstylesheetstyle_p.h2
-rw-r--r--src/gui/styles/qwindowsmobilestyle.cpp8
-rw-r--r--src/gui/styles/qwindowsstyle.cpp4
-rw-r--r--src/gui/styles/qwindowsxpstyle.cpp14
-rw-r--r--src/gui/styles/styles.pri2
-rw-r--r--src/gui/text/qcssparser_p.h22
-rw-r--r--src/gui/text/qfontdatabase_qws.cpp5
-rw-r--r--src/gui/text/qfontdatabase_win.cpp10
-rw-r--r--src/gui/text/qfontengine_mac.mm110
-rw-r--r--src/gui/text/qfontengine_p.h3
-rw-r--r--src/gui/text/qfontengine_qpf.cpp12
-rw-r--r--src/gui/text/qfontengine_qws.cpp2
-rw-r--r--src/gui/text/qfontengine_win.cpp38
-rw-r--r--src/gui/text/qtextcursor.cpp25
-rw-r--r--src/gui/text/qtextdocument_p.cpp39
-rw-r--r--src/gui/text/qtextdocument_p.h3
-rw-r--r--src/gui/text/qtextengine.cpp4
-rw-r--r--src/gui/text/qtextengine_p.h2
-rw-r--r--src/gui/text/qtextodfwriter.cpp2
-rw-r--r--src/gui/util/qdesktopservices_mac.cpp2
-rw-r--r--src/gui/util/qsystemtrayicon.cpp10
-rw-r--r--src/gui/util/qsystemtrayicon_win.cpp10
-rw-r--r--src/gui/widgets/qabstractbutton.cpp21
-rw-r--r--src/gui/widgets/qabstractscrollarea.cpp7
-rw-r--r--src/gui/widgets/qabstractscrollarea_p.h2
-rw-r--r--src/gui/widgets/qabstractspinbox.cpp1
-rw-r--r--src/gui/widgets/qbuttongroup.cpp16
-rw-r--r--src/gui/widgets/qcombobox.cpp37
-rw-r--r--src/gui/widgets/qcombobox_p.h1
-rw-r--r--src/gui/widgets/qcommandlinkbutton.cpp9
-rw-r--r--src/gui/widgets/qdatetimeedit.cpp8
-rw-r--r--src/gui/widgets/qdockwidget.cpp2
-rw-r--r--src/gui/widgets/qframe_p.h2
-rw-r--r--src/gui/widgets/qgroupbox.cpp12
-rw-r--r--src/gui/widgets/qlabel.cpp22
-rw-r--r--src/gui/widgets/qlcdnumber.cpp12
-rw-r--r--src/gui/widgets/qlineedit.cpp4
-rw-r--r--src/gui/widgets/qmainwindowlayout_mac.mm4
-rw-r--r--src/gui/widgets/qmdisubwindow.cpp2
-rw-r--r--src/gui/widgets/qmenu.cpp2
-rw-r--r--src/gui/widgets/qmenu.h4
-rw-r--r--src/gui/widgets/qmenu_mac.mm142
-rw-r--r--src/gui/widgets/qmenu_p.h8
-rw-r--r--src/gui/widgets/qmenu_wince.cpp4
-rw-r--r--src/gui/widgets/qmenubar.cpp123
-rw-r--r--src/gui/widgets/qmenubar.h8
-rw-r--r--src/gui/widgets/qmenubar_p.h15
-rw-r--r--src/gui/widgets/qplaintextedit.cpp21
-rw-r--r--src/gui/widgets/qprintpreviewwidget.cpp44
-rw-r--r--src/gui/widgets/qslider.cpp10
-rw-r--r--src/gui/widgets/qsplitter.cpp12
-rw-r--r--src/gui/widgets/qsplitter_p.h9
-rw-r--r--src/gui/widgets/qtabbar.cpp7
-rw-r--r--src/gui/widgets/qtoolbar.cpp14
-rw-r--r--src/gui/widgets/qtoolbarlayout.cpp19
-rw-r--r--src/gui/widgets/qtoolbarlayout_p.h6
-rw-r--r--src/gui/widgets/qtoolbutton.cpp3
238 files changed, 13669 insertions, 10365 deletions
diff --git a/src/gui/accessible/qaccessible_win.cpp b/src/gui/accessible/qaccessible_win.cpp
index 99cc272..f287874 100644
--- a/src/gui/accessible/qaccessible_win.cpp
+++ b/src/gui/accessible/qaccessible_win.cpp
@@ -50,7 +50,7 @@
#include <winuser.h>
#if !defined(WINABLEAPI)
-# if defined(Q_OS_WINCE)
+# if defined(Q_WS_WINCE)
# include <bldver.h>
# endif
# include <winable.h>
@@ -61,7 +61,7 @@
#include <comdef.h>
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include "qguifunctions_wince.h"
#endif
@@ -239,7 +239,7 @@ void QAccessible::updateAccessibility(QObject *o, int who, Event reason)
typedef void (WINAPI *PtrNotifyWinEvent)(DWORD, HWND, LONG, LONG);
-#if defined(Q_OS_WINCE) // ### TODO: check for NotifyWinEvent in CE 6.0
+#if defined(Q_WS_WINCE) // ### TODO: check for NotifyWinEvent in CE 6.0
// There is no user32.lib nor NotifyWinEvent for CE
return;
#else
@@ -289,7 +289,7 @@ void QAccessible::updateAccessibility(QObject *o, int who, Event reason)
if (reason != MenuCommand) { // MenuCommand is faked
ptrNotifyWinEvent(reason, w->winId(), OBJID_CLIENT, who);
}
-#endif // Q_OS_WINCE
+#endif // Q_WS_WINCE
}
void QAccessible::setRootObject(QObject *o)
diff --git a/src/gui/dialogs/qcolordialog.cpp b/src/gui/dialogs/qcolordialog.cpp
index 3aa04f6..7e885da 100644
--- a/src/gui/dialogs/qcolordialog.cpp
+++ b/src/gui/dialogs/qcolordialog.cpp
@@ -1066,7 +1066,7 @@ QColorShower::QColorShower(QColorDialog *parent)
QGridLayout *gl = new QGridLayout(this);
gl->setMargin(gl->spacing());
lab = new QColorShowLabel(this);
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
lab->setMinimumWidth(60);
#else
lab->setMinimumWidth(20);
@@ -1369,7 +1369,7 @@ void QColorDialogPrivate::init(const QColor &initial)
leftLay = 0;
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
smallDisplay = true;
const int lumSpace = 20;
#else
@@ -1409,7 +1409,7 @@ void QColorDialogPrivate::init(const QColor &initial)
leftLay->addWidget(lblBasicColors);
leftLay->addWidget(standard);
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
leftLay->addStretch();
#endif
@@ -1578,10 +1578,11 @@ void QColorDialog::setCurrentColor(const QColor &color)
{
Q_D(QColorDialog);
d->setCurrentColor(color.rgb());
- d->selectColor(color.rgb());
+ d->selectColor(color);
d->setCurrentAlpha(color.alpha());
#ifdef Q_WS_MAC
+ d->setCurrentQColor(color);
if (d->delegate)
QColorDialogPrivate::setColor(d->delegate, color);
#endif
diff --git a/src/gui/dialogs/qcolordialog_mac.mm b/src/gui/dialogs/qcolordialog_mac.mm
index 2556265..9862c1c 100644
--- a/src/gui/dialogs/qcolordialog_mac.mm
+++ b/src/gui/dialogs/qcolordialog_mac.mm
@@ -234,16 +234,22 @@ QT_USE_NAMESPACE
CGFloat cyan, magenta, yellow, black, alpha;
[color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
mQtColor->setCmykF(cyan, magenta, yellow, black, alpha);
+ } else if (colorSpace == NSCalibratedRGBColorSpace || colorSpace == NSDeviceRGBColorSpace) {
+ CGFloat red, green, blue, alpha;
+ [color getRed:&red green:&green blue:&blue alpha:&alpha];
+ mQtColor->setRgbF(red, green, blue, alpha);
} else {
- NSColor *tmpColor;
- if (colorSpace == NSCalibratedRGBColorSpace || colorSpace == NSDeviceRGBColorSpace) {
- tmpColor = color;
+ NSColorSpace *colorSpace = [color colorSpace];
+ if ([colorSpace colorSpaceModel] == NSCMYKColorSpaceModel && [color numberOfComponents] == 5){
+ CGFloat components[5];
+ [color getComponents:components];
+ mQtColor->setCmykF(components[0], components[1], components[2], components[3], components[4]);
} else {
- tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
+ NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
+ CGFloat red, green, blue, alpha;
+ [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
+ mQtColor->setRgbF(red, green, blue, alpha);
}
- CGFloat red, green, blue, alpha;
- [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
- mQtColor->setRgbF(red, green, blue, alpha);
}
if (mPriv)
@@ -414,10 +420,20 @@ void QColorDialogPrivate::setColor(void *delegate, const QColor &color)
{
QMacCocoaAutoReleasePool pool;
QCocoaColorPanelDelegate *theDelegate = static_cast<QCocoaColorPanelDelegate *>(delegate);
- NSColor *nsColor = [NSColor colorWithCalibratedRed:color.red() / 255.0
- green:color.green() / 255.0
- blue:color.blue() / 255.0
- alpha:color.alpha() / 255.0];
+ NSColor *nsColor;
+ const QColor::Spec spec = color.spec();
+ if (spec == QColor::Cmyk) {
+ nsColor = [NSColor colorWithDeviceCyan:color.cyanF()
+ magenta:color.magentaF()
+ yellow:color.yellowF()
+ black:color.blackF()
+ alpha:color.alphaF()];
+ } else {
+ nsColor = [NSColor colorWithCalibratedRed:color.redF()
+ green:color.greenF()
+ blue:color.blueF()
+ alpha:color.alphaF()];
+ }
[[theDelegate colorPanel] setColor:nsColor];
}
diff --git a/src/gui/dialogs/qdialog.cpp b/src/gui/dialogs/qdialog.cpp
index 14d8162..b3f3c5b 100644
--- a/src/gui/dialogs/qdialog.cpp
+++ b/src/gui/dialogs/qdialog.cpp
@@ -55,7 +55,7 @@
#ifndef QT_NO_ACCESSIBILITY
#include "qaccessible.h"
#endif
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#include "qt_windows.h"
#include "qmenubar.h"
#include "qpointer.h"
@@ -251,7 +251,7 @@ QDialog::QDialog(QWidget *parent, Qt::WindowFlags f)
: QWidget(*new QDialogPrivate, parent,
f | QFlag((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : 0))
{
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (!qt_wince_is_smartphone())
setWindowFlags(windowFlags() | Qt::WindowOkButtonHint | QFlag(qt_wince_is_mobile() ? 0 : Qt::WindowCancelButtonHint));
#endif
@@ -280,7 +280,7 @@ QDialog::QDialog(QWidget *parent, const char *name, bool modal, Qt::WindowFlags
QDialog::QDialog(QDialogPrivate &dd, QWidget *parent, Qt::WindowFlags f)
: QWidget(dd, parent, f | QFlag((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : 0))
{
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (!qt_wince_is_smartphone())
setWindowFlags(windowFlags() | Qt::WindowOkButtonHint | QFlag(qt_wince_is_mobile() ? 0 : Qt::WindowCancelButtonHint));
#endif
@@ -364,8 +364,8 @@ void QDialogPrivate::resetModalitySetByOpen()
resetModalityTo = -1;
}
-#ifdef Q_OS_WINCE
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE
+#ifdef Q_WS_WINCE_WM
void QDialogPrivate::_q_doneAction()
{
//Done...
@@ -473,7 +473,7 @@ int QDialog::exec()
setResult(0);
//On Windows Mobile we create an empty menu to hide the current menu
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
#ifndef QT_NO_MENUBAR
QMenuBar *menuBar = 0;
if (!findChild<QMenuBar *>())
@@ -484,7 +484,7 @@ int QDialog::exec()
connect(doneAction, SIGNAL(triggered()), this, SLOT(_q_doneAction()));
}
#endif //QT_NO_MENUBAR
-#endif //Q_OS_WINCE_WM
+#endif //Q_WS_WINCE_WM
show();
@@ -505,12 +505,12 @@ int QDialog::exec()
int res = result();
if (deleteOnClose)
delete this;
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
#ifndef QT_NO_MENUBAR
else if (menuBar)
delete menuBar;
#endif //QT_NO_MENUBAR
-#endif //Q_OS_WINCE_WM
+#endif //Q_WS_WINCE_WM
return res;
}
diff --git a/src/gui/dialogs/qdialog.h b/src/gui/dialogs/qdialog.h
index ee1997a..bd86251 100644
--- a/src/gui/dialogs/qdialog.h
+++ b/src/gui/dialogs/qdialog.h
@@ -107,7 +107,7 @@ public Q_SLOTS:
protected:
QDialog(QDialogPrivate &, QWidget *parent, Qt::WindowFlags f = 0);
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
bool event(QEvent *e);
#endif
void keyPressEvent(QKeyEvent *);
@@ -124,7 +124,7 @@ private:
Q_DECLARE_PRIVATE(QDialog)
Q_DISABLE_COPY(QDialog)
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
Q_PRIVATE_SLOT(d_func(), void _q_doneAction())
#endif
};
diff --git a/src/gui/dialogs/qdialog_p.h b/src/gui/dialogs/qdialog_p.h
index 81a7b19..e4f551a 100644
--- a/src/gui/dialogs/qdialog_p.h
+++ b/src/gui/dialogs/qdialog_p.h
@@ -93,7 +93,7 @@ public:
void hideDefault();
void resetModalitySetByOpen();
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
void _q_doneAction();
#endif
diff --git a/src/gui/dialogs/qerrormessage.cpp b/src/gui/dialogs/qerrormessage.cpp
index f79c6b2..ca39d31 100644
--- a/src/gui/dialogs/qerrormessage.cpp
+++ b/src/gui/dialogs/qerrormessage.cpp
@@ -61,7 +61,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
extern bool qt_wince_is_high_dpi(); //defined in qguifunctions_wince.cpp
@@ -100,7 +100,7 @@ public:
QSize QErrorMessageTextView::minimumSizeHint() const
{
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qt_wince_is_mobile())
if (qt_wince_is_high_dpi())
return QSize(200, 200);
@@ -115,7 +115,7 @@ QSize QErrorMessageTextView::minimumSizeHint() const
QSize QErrorMessageTextView::sizeHint() const
{
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qt_wince_is_mobile())
if (qt_wince_is_high_dpi())
return QSize(400, 200);
@@ -240,7 +240,7 @@ QErrorMessage::QErrorMessage(QWidget * parent)
d->again->setChecked(true);
grid->addWidget(d->again, 1, 1, Qt::AlignTop);
d->ok = new QPushButton(this);
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
d->ok->setFixedSize(0,0);
#endif
connect(d->ok, SIGNAL(clicked()), this, SLOT(accept()));
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp
index eeb2743..903cd74 100644
--- a/src/gui/dialogs/qfiledialog.cpp
+++ b/src/gui/dialogs/qfiledialog.cpp
@@ -58,7 +58,7 @@
#include <qdebug.h>
#include <qapplication.h>
#include <qstylepainter.h>
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
#include "ui_qfiledialog.h"
#else
#include "ui_qfiledialog_wince.h"
@@ -1861,7 +1861,7 @@ QString QFileDialog::getExistingDirectory(QWidget *parent,
#if defined(Q_WS_WIN)
if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog) && (options & ShowDirsOnly)
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
&& qt_priv_ptr_valid
#endif
) {
@@ -2075,7 +2075,7 @@ void QFileDialogPrivate::init(const QString &directory, const QString &nameFilte
q->restoreState(settings.value(QLatin1String("filedialog")).toByteArray());
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
qFileDialogUi->lookInLabel->setVisible(false);
qFileDialogUi->fileNameLabel->setVisible(false);
qFileDialogUi->fileTypeLabel->setVisible(false);
diff --git a/src/gui/dialogs/qfiledialog_mac.mm b/src/gui/dialogs/qfiledialog_mac.mm
index 90af9fc..39a231b 100644
--- a/src/gui/dialogs/qfiledialog_mac.mm
+++ b/src/gui/dialogs/qfiledialog_mac.mm
@@ -911,8 +911,9 @@ void QFileDialogPrivate::createNavServicesDialog()
navOptions.windowTitle = QCFString::toCFStringRef(q->windowTitle());
- static const int w = 450, h = 350;
- navOptions.location.h = navOptions.location.v = -1;
+ navOptions.location.h = -1;
+ navOptions.location.v = -1;
+
QWidget *parent = q->parentWidget();
if (parent && parent->isVisible()) {
WindowClass wclass;
@@ -920,20 +921,6 @@ void QFileDialogPrivate::createNavServicesDialog()
parent = parent->window();
QString s = parent->windowTitle();
navOptions.clientName = QCFString::toCFStringRef(s);
- navOptions.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
- navOptions.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);
-
- QRect r = QApplication::desktop()->screenGeometry(
- QApplication::desktop()->screenNumber(parent));
- const int border = 10;
- if (navOptions.location.h + w > r.right())
- navOptions.location.h -= (navOptions.location.h + w) - r.right() + border;
- if (navOptions.location.v + h > r.bottom())
- navOptions.location.v -= (navOptions.location.v + h) - r.bottom() + border;
- if (navOptions.location.h < r.left())
- navOptions.location.h = r.left() + border;
- if (navOptions.location.v < r.top())
- navOptions.location.v = r.top() + border;
}
filterInfo.currentSelection = 0;
diff --git a/src/gui/dialogs/qfiledialog_win.cpp b/src/gui/dialogs/qfiledialog_win.cpp
index 8431488..6962674 100644
--- a/src/gui/dialogs/qfiledialog_win.cpp
+++ b/src/gui/dialogs/qfiledialog_win.cpp
@@ -60,7 +60,7 @@
#include <shlobj.h>
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include <commdlg.h>
# ifndef BFFM_SETSELECTION
# define BFFM_SETSELECTION (WM_USER + 102)
@@ -112,7 +112,7 @@ static void qt_win_resolve_libs()
triedResolve = true;
if (!(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)) {
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
QLibrary lib(QLatin1String("shell32"));
ptrSHBrowseForFolder = (PtrSHBrowseForFolder) lib.resolve("SHBrowseForFolderW");
ptrSHGetPathFromIDList = (PtrSHGetPathFromIDList) lib.resolve("SHGetPathFromIDListW");
@@ -186,7 +186,7 @@ static QString qt_win_selected_filter(const QString &filter, DWORD idx)
return qt_win_make_filters_list(filter).at((int)idx - 1);
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
// Static vars for OFNA funcs:
static QByteArray aInitDir;
static QByteArray aInitSel;
@@ -505,7 +505,7 @@ QString qt_win_get_save_file_name(const QFileDialogArgs &args,
}
qt_win_clean_up_OFNA(&ofn);
});
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
int semIndex = result.indexOf(QLatin1Char(';'));
if (semIndex >= 0)
result = result.left(semIndex);
@@ -700,7 +700,7 @@ QString qt_win_get_existing_directory(const QFileDialogArgs &args)
modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
modal_widget.setParent(parent, Qt::Window);
QApplicationPrivate::enterModal(&modal_widget);
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
QT_WA({
qt_win_resolve_libs();
QString initDir = QDir::toNativeSeparators(args.directory);
diff --git a/src/gui/dialogs/qfilesystemmodel_p.h b/src/gui/dialogs/qfilesystemmodel_p.h
index 0a1265a..61e8b4c 100644
--- a/src/gui/dialogs/qfilesystemmodel_p.h
+++ b/src/gui/dialogs/qfilesystemmodel_p.h
@@ -164,9 +164,12 @@ public:
QHash<QString, QFileSystemNode *>::const_iterator iterator;
for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) {
//On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/)
- if (!path.isEmpty())
- iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
- else
+ if (!path.isEmpty()) {
+ if (path.endsWith(QLatin1Char('/')))
+ iterator.value()->updateIcon(iconProvider, path + iterator.value()->fileName);
+ else
+ iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
+ } else
iterator.value()->updateIcon(iconProvider, iterator.value()->fileName);
}
}
@@ -177,9 +180,12 @@ public:
QHash<QString, QFileSystemNode *>::const_iterator iterator;
for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) {
//On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/)
- if (!path.isEmpty())
- iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
- else
+ if (!path.isEmpty()) {
+ if (path.endsWith(QLatin1Char('/')))
+ iterator.value()->retranslateStrings(iconProvider, path + iterator.value()->fileName);
+ else
+ iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
+ } else
iterator.value()->retranslateStrings(iconProvider, iterator.value()->fileName);
}
}
diff --git a/src/gui/dialogs/qfontdialog.cpp b/src/gui/dialogs/qfontdialog.cpp
index 4c5bf4f..d8a2c7c 100644
--- a/src/gui/dialogs/qfontdialog.cpp
+++ b/src/gui/dialogs/qfontdialog.cpp
@@ -311,11 +311,11 @@ void QFontDialogPrivate::init()
buttonBox->addButton(QDialogButtonBox::Cancel);
QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject()));
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
q->resize(180, 120);
#else
q->resize(500, 360);
-#endif // Q_OS_WINCE
+#endif // Q_WS_WINCE
sizeEdit->installEventFilter(q);
familyList->installEventFilter(q);
diff --git a/src/gui/dialogs/qmessagebox.cpp b/src/gui/dialogs/qmessagebox.cpp
index 5e59501..3b622b7 100644
--- a/src/gui/dialogs/qmessagebox.cpp
+++ b/src/gui/dialogs/qmessagebox.cpp
@@ -63,7 +63,7 @@
#include <QtGui/qfontmetrics.h>
#include <QtGui/qclipboard.h>
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
extern bool qt_wince_is_smartphone();//defined in qguifunctions_wince.cpp
extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wince.cpp
@@ -152,7 +152,7 @@ public:
int layoutMinimumWidth();
void retranslateStrings();
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void hideSpecial();
#endif
@@ -272,10 +272,7 @@ void QMessageBoxPrivate::updateSize()
return;
QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
-#ifdef Q_WS_QWS
- // the width of the screen, less the window border.
- int hardLimit = screenSize.width() - (q->frameGeometry().width() - q->geometry().width());
-#elif defined(Q_OS_WINCE)
+#if defined(Q_WS_QWS) || defined(Q_WS_WINCE)
// the width of the screen, less the window border.
int hardLimit = screenSize.width() - (q->frameGeometry().width() - q->geometry().width());
#else
@@ -290,11 +287,11 @@ void QMessageBoxPrivate::updateSize()
int softLimit = qMin(hardLimit, 500);
#else
// note: ideally on windows, hard and soft limits but it breaks compat
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
int softLimit = qMin(screenSize.width()/2, 500);
#else
int softLimit = qMin(screenSize.width() * 3 / 4, 500);
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
#endif
if (informativeLabel)
@@ -351,7 +348,7 @@ void QMessageBoxPrivate::updateSize()
}
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
/*!
\internal
Hides special buttons which are rather shown in the title bar
@@ -1213,7 +1210,7 @@ bool QMessageBox::event(QEvent *e)
case QEvent::LanguageChange:
d_func()->retranslateStrings();
break;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
case QEvent::OkRequest:
case QEvent::HelpRequest: {
QString bName =
@@ -1356,7 +1353,7 @@ void QMessageBox::keyPressEvent(QKeyEvent *e)
QDialog::keyPressEvent(e);
}
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
/*!
\reimp
*/
@@ -1425,7 +1422,7 @@ void QMessageBox::showEvent(QShowEvent *e)
Q_D(QMessageBox);
if (d->autoAddOkButton) {
addButton(Ok);
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
d->hideSpecial();
#endif
}
@@ -1733,7 +1730,7 @@ void QMessageBox::aboutQt(QWidget *parent, const QString &title)
QPixmap pm(QLatin1String(":/trolltech/qmessagebox/images/qtlogo-64.png"));
if (!pm.isNull())
msgBox->setIconPixmap(pm);
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
msgBox->setDefaultButton(msgBox->addButton(QMessageBox::Ok));
#endif
diff --git a/src/gui/dialogs/qmessagebox.h b/src/gui/dialogs/qmessagebox.h
index e1667d6..8d9b9fa 100644
--- a/src/gui/dialogs/qmessagebox.h
+++ b/src/gui/dialogs/qmessagebox.h
@@ -145,7 +145,7 @@ public:
QPushButton *addButton(StandardButton button);
void removeButton(QAbstractButton *button);
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void setVisible(bool visible);
#endif
diff --git a/src/gui/dialogs/qprintpreviewdialog.cpp b/src/gui/dialogs/qprintpreviewdialog.cpp
index c00bd14..3580fdc 100644
--- a/src/gui/dialogs/qprintpreviewdialog.cpp
+++ b/src/gui/dialogs/qprintpreviewdialog.cpp
@@ -54,6 +54,9 @@
#include <QtGui/qtoolbutton.h>
#include <QtGui/qvalidator.h>
#include <QtGui/qfiledialog.h>
+#include <QtGui/qmainwindow.h>
+#include <QtGui/qtoolbar.h>
+#include <QtGui/qformlayout.h>
#include <QtCore/QCoreApplication>
#include <math.h>
@@ -63,6 +66,13 @@
QT_BEGIN_NAMESPACE
namespace {
+class QPrintPreviewMainWindow : public QMainWindow
+{
+public:
+ QPrintPreviewMainWindow(QWidget *parent) : QMainWindow(parent) {}
+ QMenu *createPopupMenu() { return 0; }
+};
+
class ZoomFactorValidator : public QDoubleValidator
{
public:
@@ -197,7 +207,6 @@ public:
QActionGroup *printerGroup;
QAction *printAction;
QAction *pageSetupAction;
- QAction *closeAction;
QPointer<QObject> receiverToDisconnectOnClose;
QByteArray memberToDisconnectOnClose;
@@ -219,27 +228,12 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
QObject::connect(preview, SIGNAL(previewChanged()), q, SLOT(_q_previewChanged()));
setupActions();
- // Navigation
- QToolButton* nextPageButton = new QToolButton;
- nextPageButton->setDefaultAction(nextPageAction);
- QToolButton* prevPageButton = new QToolButton;
- prevPageButton->setDefaultAction(prevPageAction);
- QToolButton* firstPageButton = new QToolButton;
- firstPageButton->setDefaultAction(firstPageAction);
- QToolButton* lastPageButton = new QToolButton;
- lastPageButton->setDefaultAction(lastPageAction);
-
pageNumEdit = new LineEdit;
pageNumEdit->setAlignment(Qt::AlignRight);
- pageNumEdit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
+ pageNumEdit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
pageNumLabel = new QLabel;
QObject::connect(pageNumEdit, SIGNAL(editingFinished()), q, SLOT(_q_pageNumEdited()));
- QToolButton* fitWidthButton = new QToolButton;
- fitWidthButton->setDefaultAction(fitWidthAction);
- QToolButton* fitPageButton = new QToolButton;
- fitPageButton->setDefaultAction(fitPageAction);
-
zoomFactor = new QComboBox;
zoomFactor->setEditable(true);
zoomFactor->setMinimumContentsLength(7);
@@ -255,77 +249,66 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)),
q, SLOT(_q_zoomFactorChanged()));
- QToolButton* zoomInButton = new QToolButton;
- zoomInButton->setDefaultAction(zoomInAction);
+ QPrintPreviewMainWindow *mw = new QPrintPreviewMainWindow(q);
+ QToolBar *toolbar = new QToolBar(mw);
+ toolbar->addAction(fitWidthAction);
+ toolbar->addAction(fitPageAction);
+ toolbar->addSeparator();
+ toolbar->addWidget(zoomFactor);
+ toolbar->addAction(zoomOutAction);
+ toolbar->addAction(zoomInAction);
+ toolbar->addSeparator();
+ toolbar->addAction(portraitAction);
+ toolbar->addAction(landscapeAction);
+ toolbar->addSeparator();
+ toolbar->addAction(firstPageAction);
+ toolbar->addAction(prevPageAction);
+
+ // this is to ensure the label text and the editor text are
+ // aligned in all styles - the extra QVBoxLayout is a workaround
+ // for bug in QFormLayout
+ QWidget *pageEdit = new QWidget(toolbar);
+ QVBoxLayout *vboxLayout = new QVBoxLayout;
+ vboxLayout->setContentsMargins(0, 0, 0, 0);
+ QFormLayout *formLayout = new QFormLayout;
+ formLayout->setWidget(0, QFormLayout::LabelRole, pageNumEdit);
+ formLayout->setWidget(0, QFormLayout::FieldRole, pageNumLabel);
+ vboxLayout->addLayout(formLayout);
+ vboxLayout->setAlignment(Qt::AlignVCenter);
+ pageEdit->setLayout(vboxLayout);
+ toolbar->addWidget(pageEdit);
+
+ toolbar->addAction(nextPageAction);
+ toolbar->addAction(lastPageAction);
+ toolbar->addSeparator();
+ toolbar->addAction(singleModeAction);
+ toolbar->addAction(facingModeAction);
+ toolbar->addAction(overviewModeAction);
+ toolbar->addSeparator();
+ toolbar->addAction(pageSetupAction);
+ toolbar->addAction(printAction);
+
+ // Cannot use the actions' triggered signal here, since it doesn't autorepeat
+ QToolButton *zoomInButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomInAction));
+ QToolButton *zoomOutButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomOutAction));
zoomInButton->setAutoRepeat(true);
zoomInButton->setAutoRepeatInterval(200);
zoomInButton->setAutoRepeatDelay(200);
-
- QToolButton* zoomOutButton = new QToolButton;
- zoomOutButton->setDefaultAction(zoomOutAction);
zoomOutButton->setAutoRepeat(true);
zoomOutButton->setAutoRepeatInterval(200);
zoomOutButton->setAutoRepeatDelay(200);
-
- //Cannot use the actions' triggered signal here, since it doesnt autorepeat
QObject::connect(zoomInButton, SIGNAL(clicked()), q, SLOT(_q_zoomIn()));
QObject::connect(zoomOutButton, SIGNAL(clicked()), q, SLOT(_q_zoomOut()));
- QToolButton* portraitButton = new QToolButton;
- portraitButton->setDefaultAction(portraitAction);
- QToolButton* landscapeButton = new QToolButton;
- landscapeButton->setDefaultAction(landscapeAction);
-
- QToolButton* singleModeButton = new QToolButton;
- singleModeButton->setDefaultAction(singleModeAction);
- QToolButton* facingModeButton = new QToolButton;
- facingModeButton->setDefaultAction(facingModeAction);
- QToolButton* overviewModeButton = new QToolButton;
- overviewModeButton->setDefaultAction(overviewModeAction);
-
- QToolButton *printButton = new QToolButton;
- printButton->setDefaultAction(printAction);
- QToolButton *pageSetupButton = new QToolButton;
- pageSetupButton->setDefaultAction(pageSetupAction);
- QToolButton *closeButton = new QToolButton;
- closeButton->setDefaultAction(closeAction);
-
- QHBoxLayout* modeLayout = new QHBoxLayout;
- modeLayout->setSpacing(0);
- modeLayout->addWidget(singleModeButton);
- modeLayout->addWidget(facingModeButton);
- modeLayout->addWidget(overviewModeButton);
-
- QHBoxLayout *barLayout = new QHBoxLayout;
- barLayout->addWidget(fitWidthButton);
- barLayout->addWidget(fitPageButton);
- barLayout->addWidget(zoomFactor);
- barLayout->addWidget(zoomOutButton);
- barLayout->addWidget(zoomInButton);
- barLayout->addWidget(portraitButton);
- barLayout->addWidget(landscapeButton);
- barLayout->addStretch();
- barLayout->addWidget(firstPageButton);
- barLayout->addWidget(prevPageButton);
- barLayout->addWidget(pageNumEdit);
- barLayout->addWidget(pageNumLabel);
- barLayout->addWidget(nextPageButton);
- barLayout->addWidget(lastPageButton);
- barLayout->addStretch();
- barLayout->addLayout(modeLayout);
- barLayout->addStretch();
- barLayout->addWidget(pageSetupButton);
- barLayout->addWidget(printButton);
- barLayout->addWidget(closeButton);
-
- QWidget* buttonBar = new QWidget;
- buttonBar->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
- barLayout->setMargin(0);
- buttonBar->setLayout(barLayout);
+ mw->addToolBar(toolbar);
+ mw->setCentralWidget(preview);
+ // QMainWindows are always created as top levels, force it to be a
+ // plain widget
+ mw->setParent(q, Qt::Widget);
QVBoxLayout *topLayout = new QVBoxLayout;
- topLayout->addWidget(buttonBar);
- topLayout->addWidget(preview);
+ topLayout->addWidget(mw);
+ topLayout->setMargin(0);
q->setLayout(topLayout);
QString caption = QCoreApplication::translate("QPrintPreviewDialog", "Print Preview");
@@ -338,7 +321,8 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
|| printer->outputFormat() != QPrinter::NativeFormat
#endif
)
- pageSetupButton->setEnabled(false);
+ pageSetupAction->setEnabled(false);
+ preview->setFocus();
}
static inline void qt_setupActionIcon(QAction *action, const QLatin1String &name)
@@ -418,12 +402,10 @@ void QPrintPreviewDialogPrivate::setupActions()
printerGroup = new QActionGroup(q);
printAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Print"));
pageSetupAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Page setup"));
- closeAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Close"));
qt_setupActionIcon(printAction, QLatin1String("print"));
qt_setupActionIcon(pageSetupAction, QLatin1String("page-setup"));
QObject::connect(printAction, SIGNAL(triggered(bool)), q, SLOT(_q_print()));
QObject::connect(pageSetupAction, SIGNAL(triggered(bool)), q, SLOT(_q_pageSetup()));
- QObject::connect(closeAction, SIGNAL(triggered(bool)), q, SLOT(reject()));
// Initial state:
fitPageAction->setChecked(true);
diff --git a/src/gui/dialogs/qwizard.cpp b/src/gui/dialogs/qwizard.cpp
index 298f23f..b2ed983 100644
--- a/src/gui/dialogs/qwizard.cpp
+++ b/src/gui/dialogs/qwizard.cpp
@@ -69,7 +69,7 @@
#include "private/qdialog_p.h"
#include <qdebug.h>
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
#endif
@@ -1241,8 +1241,10 @@ void QWizardPrivate::updateMinMaxSizes(const QWizardLayoutInfo &info)
#endif
QSize minimumSize = mainLayout->totalMinimumSize() + QSize(0, extraHeight);
QSize maximumSize;
+ bool skipMaxSize = false;
#if defined(Q_WS_WIN)
- if (QSysInfo::WindowsVersion > QSysInfo::WV_Me) // ### See Tasks 164078 and 161660
+ if (QSysInfo::WindowsVersion <= QSysInfo::WV_Me) // ### See Tasks 164078 and 161660
+ skipMaxSize = true;
#endif
maximumSize = mainLayout->totalMaximumSize();
if (info.header && headerWidget->maximumWidth() != QWIDGETSIZE_MAX) {
@@ -1263,11 +1265,13 @@ void QWizardPrivate::updateMinMaxSizes(const QWizardLayoutInfo &info)
}
if (q->maximumWidth() == maximumWidth) {
maximumWidth = maximumSize.width();
- q->setMaximumWidth(maximumWidth);
+ if (!skipMaxSize)
+ q->setMaximumWidth(maximumWidth);
}
if (q->maximumHeight() == maximumHeight) {
maximumHeight = maximumSize.height();
- q->setMaximumHeight(maximumHeight);
+ if (!skipMaxSize)
+ q->setMaximumHeight(maximumHeight);
}
}
@@ -2120,7 +2124,7 @@ QWizard::QWizard(QWidget *parent, Qt::WindowFlags flags)
{
Q_D(QWizard);
d->init();
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (!qt_wince_is_mobile())
setWindowFlags(windowFlags() & ~Qt::WindowOkButtonHint);
#endif
diff --git a/src/gui/embedded/embedded.pri b/src/gui/embedded/embedded.pri
index 95c4132..4a9aa3f 100644
--- a/src/gui/embedded/embedded.pri
+++ b/src/gui/embedded/embedded.pri
@@ -89,6 +89,8 @@ embedded {
HEADERS += embedded/qscreendriverplugin_qws.h \
embedded/qscreendriverfactory_qws.h \
embedded/qkbd_qws.h \
+ embedded/qkbd_qws_p.h \
+ embedded/qkbd_defaultmap_qws_p.h \
embedded/qkbddriverplugin_qws.h \
embedded/qkbddriverfactory_qws.h \
embedded/qmouse_qws.h \
@@ -152,17 +154,11 @@ embedded {
contains( kbd-drivers, tty ) {
HEADERS +=embedded/qkbdtty_qws.h
SOURCES +=embedded/qkbdtty_qws.cpp
- !contains( kbd-drivers, pc101 ) {
- kbd-drivers += pc101
- }
}
- contains( kbd-drivers, usb ) {
- HEADERS +=embedded/qkbdusb_qws.h
- SOURCES +=embedded/qkbdusb_qws.cpp
- !contains( kbd-drivers, pc101 ) {
- kbd-drivers += pc101
- }
+ contains( kbd-drivers, linuxinput ) {
+ HEADERS +=embedded/qkbdlinuxinput_qws.h
+ SOURCES +=embedded/qkbdlinuxinput_qws.cpp
}
contains( kbd-drivers, um ) {
@@ -170,11 +166,6 @@ embedded {
SOURCES +=embedded/qkbdum_qws.cpp
}
- contains( kbd-drivers, pc101 ) {
- HEADERS +=embedded/qkbdpc101_qws.h
- SOURCES +=embedded/qkbdpc101_qws.cpp
- }
-
contains( kbd-drivers, yopy ) {
HEADERS +=embedded/qkbdyopy_qws.h
SOURCES +=embedded/qkbdyopy_qws.cpp
diff --git a/src/gui/embedded/qkbd_defaultmap_qws_p.h b/src/gui/embedded/qkbd_defaultmap_qws_p.h
new file mode 100644
index 0000000..0d6d77d
--- /dev/null
+++ b/src/gui/embedded/qkbd_defaultmap_qws_p.h
@@ -0,0 +1,796 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWSKEYBOARDHANDLER_DEFAULTMAP_H
+#define QWSKEYBOARDHANDLER_DEFAULTMAP_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+const QWSKeyboard::Mapping QWSKbPrivate::s_keymap_default[] = {
+ { 1, 0xffff, 0x01000000, 0x00, 0x00, 0x0000 },
+ { 2, 0x0031, 0x00000031, 0x00, 0x00, 0x0000 },
+ { 2, 0x0021, 0x00000021, 0x01, 0x00, 0x0000 },
+ { 3, 0x0032, 0x00000032, 0x00, 0x00, 0x0000 },
+ { 3, 0x0040, 0x00000040, 0x01, 0x00, 0x0000 },
+ { 3, 0x0040, 0x00000040, 0x02, 0x00, 0x0000 },
+ { 4, 0x0033, 0x00000033, 0x00, 0x00, 0x0000 },
+ { 4, 0x0023, 0x00000023, 0x01, 0x00, 0x0000 },
+ { 4, 0xffff, 0x01000000, 0x04, 0x00, 0x0000 },
+ { 5, 0x0034, 0x00000034, 0x00, 0x00, 0x0000 },
+ { 5, 0x0024, 0x00000024, 0x01, 0x00, 0x0000 },
+ { 5, 0x0024, 0x00000024, 0x02, 0x00, 0x0000 },
+ { 5, 0x005c, 0x0400005c, 0x04, 0x00, 0x0000 },
+ { 6, 0x0035, 0x00000035, 0x00, 0x00, 0x0000 },
+ { 6, 0x0025, 0x00000025, 0x01, 0x00, 0x0000 },
+ { 6, 0x005d, 0x0400005d, 0x04, 0x00, 0x0000 },
+ { 7, 0x0036, 0x00000036, 0x00, 0x00, 0x0000 },
+ { 7, 0x005e, 0x0000005e, 0x01, 0x00, 0x0000 },
+ { 7, 0x005e, 0x01001252, 0x02, 0x01, 0x0000 },
+ { 7, 0x005e, 0x0400005e, 0x04, 0x00, 0x0000 },
+ { 8, 0x0037, 0x00000037, 0x00, 0x00, 0x0000 },
+ { 8, 0x0026, 0x00000026, 0x01, 0x00, 0x0000 },
+ { 8, 0x007b, 0x0000007b, 0x02, 0x00, 0x0000 },
+ { 8, 0x005f, 0x0400005f, 0x04, 0x00, 0x0000 },
+ { 9, 0x0038, 0x00000038, 0x00, 0x00, 0x0000 },
+ { 9, 0x002a, 0x0000002a, 0x01, 0x00, 0x0000 },
+ { 9, 0x005b, 0x0000005b, 0x02, 0x00, 0x0000 },
+ { 9, 0xffff, 0x01000003, 0x04, 0x00, 0x0000 },
+ { 10, 0x0039, 0x00000039, 0x00, 0x00, 0x0000 },
+ { 10, 0x0028, 0x00000028, 0x01, 0x00, 0x0000 },
+ { 10, 0x005d, 0x0000005d, 0x02, 0x00, 0x0000 },
+ { 11, 0x0030, 0x00000030, 0x00, 0x00, 0x0000 },
+ { 11, 0x0029, 0x00000029, 0x01, 0x00, 0x0000 },
+ { 11, 0x007d, 0x0000007d, 0x02, 0x00, 0x0000 },
+ { 12, 0x002d, 0x0000002d, 0x00, 0x00, 0x0000 },
+ { 12, 0x005f, 0x0000005f, 0x01, 0x00, 0x0000 },
+ { 12, 0x005c, 0x0000005c, 0x02, 0x00, 0x0000 },
+ { 12, 0x005f, 0x0400005f, 0x04, 0x00, 0x0000 },
+ { 12, 0x005f, 0x0400005f, 0x05, 0x00, 0x0000 },
+ { 13, 0x003d, 0x0000003d, 0x00, 0x00, 0x0000 },
+ { 13, 0x002b, 0x0000002b, 0x01, 0x00, 0x0000 },
+ { 14, 0xffff, 0x01000003, 0x00, 0x00, 0x0000 },
+ { 14, 0xffff, 0x01000000, 0x0c, 0x08, 0x0300 },
+ { 15, 0xffff, 0x01000001, 0x00, 0x00, 0x0000 },
+ { 16, 0x0071, 0x00000051, 0x00, 0x00, 0x0000 },
+ { 16, 0x0051, 0x00000051, 0x01, 0x00, 0x0000 },
+ { 16, 0x0071, 0x00000051, 0x02, 0x00, 0x0000 },
+ { 16, 0x0051, 0x00000051, 0x03, 0x00, 0x0000 },
+ { 16, 0x0071, 0x04000051, 0x04, 0x00, 0x0000 },
+ { 16, 0x0071, 0x04000051, 0x05, 0x00, 0x0000 },
+ { 16, 0x0071, 0x04000051, 0x06, 0x00, 0x0000 },
+ { 16, 0x0071, 0x04000051, 0x07, 0x00, 0x0000 },
+ { 16, 0x0071, 0x08000051, 0x08, 0x00, 0x0000 },
+ { 16, 0x0071, 0x08000051, 0x09, 0x00, 0x0000 },
+ { 16, 0x0071, 0x08000051, 0x0a, 0x00, 0x0000 },
+ { 16, 0x0071, 0x08000051, 0x0b, 0x00, 0x0000 },
+ { 16, 0x0071, 0x0c000051, 0x0c, 0x00, 0x0000 },
+ { 16, 0x0071, 0x0c000051, 0x0d, 0x00, 0x0000 },
+ { 16, 0x0071, 0x0c000051, 0x0e, 0x00, 0x0000 },
+ { 16, 0x0071, 0x0c000051, 0x0f, 0x00, 0x0000 },
+ { 17, 0x0077, 0x00000057, 0x00, 0x00, 0x0000 },
+ { 17, 0x0057, 0x00000057, 0x01, 0x00, 0x0000 },
+ { 17, 0x0077, 0x00000057, 0x02, 0x00, 0x0000 },
+ { 17, 0x0057, 0x00000057, 0x03, 0x00, 0x0000 },
+ { 17, 0x0077, 0x04000057, 0x04, 0x00, 0x0000 },
+ { 17, 0x0077, 0x04000057, 0x05, 0x00, 0x0000 },
+ { 17, 0x0077, 0x04000057, 0x06, 0x00, 0x0000 },
+ { 17, 0x0077, 0x04000057, 0x07, 0x00, 0x0000 },
+ { 17, 0x0077, 0x08000057, 0x08, 0x00, 0x0000 },
+ { 17, 0x0077, 0x08000057, 0x09, 0x00, 0x0000 },
+ { 17, 0x0077, 0x08000057, 0x0a, 0x00, 0x0000 },
+ { 17, 0x0077, 0x08000057, 0x0b, 0x00, 0x0000 },
+ { 17, 0x0077, 0x0c000057, 0x0c, 0x00, 0x0000 },
+ { 17, 0x0077, 0x0c000057, 0x0d, 0x00, 0x0000 },
+ { 17, 0x0077, 0x0c000057, 0x0e, 0x00, 0x0000 },
+ { 17, 0x0077, 0x0c000057, 0x0f, 0x00, 0x0000 },
+ { 18, 0x0065, 0x00000045, 0x00, 0x00, 0x0000 },
+ { 18, 0x0045, 0x00000045, 0x01, 0x00, 0x0000 },
+ { 18, 0x0065, 0x00000045, 0x02, 0x00, 0x0000 },
+ { 18, 0x0045, 0x00000045, 0x03, 0x00, 0x0000 },
+ { 18, 0x0065, 0x04000045, 0x04, 0x00, 0x0000 },
+ { 18, 0x0065, 0x04000045, 0x05, 0x00, 0x0000 },
+ { 18, 0x0065, 0x04000045, 0x06, 0x00, 0x0000 },
+ { 18, 0x0065, 0x04000045, 0x07, 0x00, 0x0000 },
+ { 18, 0x0065, 0x08000045, 0x08, 0x00, 0x0000 },
+ { 18, 0x0065, 0x08000045, 0x09, 0x00, 0x0000 },
+ { 18, 0x0065, 0x08000045, 0x0a, 0x00, 0x0000 },
+ { 18, 0x0065, 0x08000045, 0x0b, 0x00, 0x0000 },
+ { 18, 0x0065, 0x0c000045, 0x0c, 0x00, 0x0000 },
+ { 18, 0x0065, 0x0c000045, 0x0d, 0x00, 0x0000 },
+ { 18, 0x0065, 0x0c000045, 0x0e, 0x00, 0x0000 },
+ { 18, 0x0065, 0x0c000045, 0x0f, 0x00, 0x0000 },
+ { 19, 0x0072, 0x00000052, 0x00, 0x00, 0x0000 },
+ { 19, 0x0052, 0x00000052, 0x01, 0x00, 0x0000 },
+ { 19, 0x0072, 0x00000052, 0x02, 0x00, 0x0000 },
+ { 19, 0x0052, 0x00000052, 0x03, 0x00, 0x0000 },
+ { 19, 0x0072, 0x04000052, 0x04, 0x00, 0x0000 },
+ { 19, 0x0072, 0x04000052, 0x05, 0x00, 0x0000 },
+ { 19, 0x0072, 0x04000052, 0x06, 0x00, 0x0000 },
+ { 19, 0x0072, 0x04000052, 0x07, 0x00, 0x0000 },
+ { 19, 0x0072, 0x08000052, 0x08, 0x00, 0x0000 },
+ { 19, 0x0072, 0x08000052, 0x09, 0x00, 0x0000 },
+ { 19, 0x0072, 0x08000052, 0x0a, 0x00, 0x0000 },
+ { 19, 0x0072, 0x08000052, 0x0b, 0x00, 0x0000 },
+ { 19, 0x0072, 0x0c000052, 0x0c, 0x00, 0x0000 },
+ { 19, 0x0072, 0x0c000052, 0x0d, 0x00, 0x0000 },
+ { 19, 0x0072, 0x0c000052, 0x0e, 0x00, 0x0000 },
+ { 19, 0x0072, 0x0c000052, 0x0f, 0x00, 0x0000 },
+ { 20, 0x0074, 0x00000054, 0x00, 0x00, 0x0000 },
+ { 20, 0x0054, 0x00000054, 0x01, 0x00, 0x0000 },
+ { 20, 0x0074, 0x00000054, 0x02, 0x00, 0x0000 },
+ { 20, 0x0054, 0x00000054, 0x03, 0x00, 0x0000 },
+ { 20, 0x0074, 0x04000054, 0x04, 0x00, 0x0000 },
+ { 20, 0x0074, 0x04000054, 0x05, 0x00, 0x0000 },
+ { 20, 0x0074, 0x04000054, 0x06, 0x00, 0x0000 },
+ { 20, 0x0074, 0x04000054, 0x07, 0x00, 0x0000 },
+ { 20, 0x0074, 0x08000054, 0x08, 0x00, 0x0000 },
+ { 20, 0x0074, 0x08000054, 0x09, 0x00, 0x0000 },
+ { 20, 0x0074, 0x08000054, 0x0a, 0x00, 0x0000 },
+ { 20, 0x0074, 0x08000054, 0x0b, 0x00, 0x0000 },
+ { 20, 0x0074, 0x0c000054, 0x0c, 0x00, 0x0000 },
+ { 20, 0x0074, 0x0c000054, 0x0d, 0x00, 0x0000 },
+ { 20, 0x0074, 0x0c000054, 0x0e, 0x00, 0x0000 },
+ { 20, 0x0074, 0x0c000054, 0x0f, 0x00, 0x0000 },
+ { 21, 0x0079, 0x00000059, 0x00, 0x00, 0x0000 },
+ { 21, 0x0059, 0x00000059, 0x01, 0x00, 0x0000 },
+ { 21, 0x0079, 0x00000059, 0x02, 0x00, 0x0000 },
+ { 21, 0x0059, 0x00000059, 0x03, 0x00, 0x0000 },
+ { 21, 0x0079, 0x04000059, 0x04, 0x00, 0x0000 },
+ { 21, 0x0079, 0x04000059, 0x05, 0x00, 0x0000 },
+ { 21, 0x0079, 0x04000059, 0x06, 0x00, 0x0000 },
+ { 21, 0x0079, 0x04000059, 0x07, 0x00, 0x0000 },
+ { 21, 0x0079, 0x08000059, 0x08, 0x00, 0x0000 },
+ { 21, 0x0079, 0x08000059, 0x09, 0x00, 0x0000 },
+ { 21, 0x0079, 0x08000059, 0x0a, 0x00, 0x0000 },
+ { 21, 0x0079, 0x08000059, 0x0b, 0x00, 0x0000 },
+ { 21, 0x0079, 0x0c000059, 0x0c, 0x00, 0x0000 },
+ { 21, 0x0079, 0x0c000059, 0x0d, 0x00, 0x0000 },
+ { 21, 0x0079, 0x0c000059, 0x0e, 0x00, 0x0000 },
+ { 21, 0x0079, 0x0c000059, 0x0f, 0x00, 0x0000 },
+ { 22, 0x0075, 0x00000055, 0x00, 0x00, 0x0000 },
+ { 22, 0x0055, 0x00000055, 0x01, 0x00, 0x0000 },
+ { 22, 0x0075, 0x00000055, 0x02, 0x00, 0x0000 },
+ { 22, 0x0055, 0x00000055, 0x03, 0x00, 0x0000 },
+ { 22, 0x0075, 0x04000055, 0x04, 0x00, 0x0000 },
+ { 22, 0x0075, 0x04000055, 0x05, 0x00, 0x0000 },
+ { 22, 0x0075, 0x04000055, 0x06, 0x00, 0x0000 },
+ { 22, 0x0075, 0x04000055, 0x07, 0x00, 0x0000 },
+ { 22, 0x0075, 0x08000055, 0x08, 0x00, 0x0000 },
+ { 22, 0x0075, 0x08000055, 0x09, 0x00, 0x0000 },
+ { 22, 0x0075, 0x08000055, 0x0a, 0x00, 0x0000 },
+ { 22, 0x0075, 0x08000055, 0x0b, 0x00, 0x0000 },
+ { 22, 0x0075, 0x0c000055, 0x0c, 0x00, 0x0000 },
+ { 22, 0x0075, 0x0c000055, 0x0d, 0x00, 0x0000 },
+ { 22, 0x0075, 0x0c000055, 0x0e, 0x00, 0x0000 },
+ { 22, 0x0075, 0x0c000055, 0x0f, 0x00, 0x0000 },
+ { 23, 0x0069, 0x00000049, 0x00, 0x00, 0x0000 },
+ { 23, 0x0049, 0x00000049, 0x01, 0x00, 0x0000 },
+ { 23, 0x0069, 0x00000049, 0x02, 0x00, 0x0000 },
+ { 23, 0x0049, 0x00000049, 0x03, 0x00, 0x0000 },
+ { 23, 0x0069, 0x04000049, 0x04, 0x00, 0x0000 },
+ { 23, 0x0069, 0x04000049, 0x05, 0x00, 0x0000 },
+ { 23, 0x0069, 0x04000049, 0x06, 0x00, 0x0000 },
+ { 23, 0x0069, 0x04000049, 0x07, 0x00, 0x0000 },
+ { 23, 0x0069, 0x08000049, 0x08, 0x00, 0x0000 },
+ { 23, 0x0069, 0x08000049, 0x09, 0x00, 0x0000 },
+ { 23, 0x0069, 0x08000049, 0x0a, 0x00, 0x0000 },
+ { 23, 0x0069, 0x08000049, 0x0b, 0x00, 0x0000 },
+ { 23, 0x0069, 0x0c000049, 0x0c, 0x00, 0x0000 },
+ { 23, 0x0069, 0x0c000049, 0x0d, 0x00, 0x0000 },
+ { 23, 0x0069, 0x0c000049, 0x0e, 0x00, 0x0000 },
+ { 23, 0x0069, 0x0c000049, 0x0f, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0000004f, 0x00, 0x00, 0x0000 },
+ { 24, 0x004f, 0x0000004f, 0x01, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0000004f, 0x02, 0x00, 0x0000 },
+ { 24, 0x004f, 0x0000004f, 0x03, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0400004f, 0x04, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0400004f, 0x05, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0400004f, 0x06, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0400004f, 0x07, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0800004f, 0x08, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0800004f, 0x09, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0800004f, 0x0a, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0800004f, 0x0b, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0c00004f, 0x0c, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0c00004f, 0x0d, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0c00004f, 0x0e, 0x00, 0x0000 },
+ { 24, 0x006f, 0x0c00004f, 0x0f, 0x00, 0x0000 },
+ { 25, 0x0070, 0x00000050, 0x00, 0x00, 0x0000 },
+ { 25, 0x0050, 0x00000050, 0x01, 0x00, 0x0000 },
+ { 25, 0x0070, 0x00000050, 0x02, 0x00, 0x0000 },
+ { 25, 0x0050, 0x00000050, 0x03, 0x00, 0x0000 },
+ { 25, 0x0070, 0x04000050, 0x04, 0x00, 0x0000 },
+ { 25, 0x0070, 0x04000050, 0x05, 0x00, 0x0000 },
+ { 25, 0x0070, 0x04000050, 0x06, 0x00, 0x0000 },
+ { 25, 0x0070, 0x04000050, 0x07, 0x00, 0x0000 },
+ { 25, 0x0070, 0x08000050, 0x08, 0x00, 0x0000 },
+ { 25, 0x0070, 0x08000050, 0x09, 0x00, 0x0000 },
+ { 25, 0x0070, 0x08000050, 0x0a, 0x00, 0x0000 },
+ { 25, 0x0070, 0x08000050, 0x0b, 0x00, 0x0000 },
+ { 25, 0x0070, 0x0c000050, 0x0c, 0x00, 0x0000 },
+ { 25, 0x0070, 0x0c000050, 0x0d, 0x00, 0x0000 },
+ { 25, 0x0070, 0x0c000050, 0x0e, 0x00, 0x0000 },
+ { 25, 0x0070, 0x0c000050, 0x0f, 0x00, 0x0000 },
+ { 26, 0x005b, 0x0000005b, 0x00, 0x00, 0x0000 },
+ { 26, 0x007b, 0x0000007b, 0x01, 0x00, 0x0000 },
+ { 26, 0xffff, 0x01000000, 0x04, 0x00, 0x0000 },
+ { 27, 0x005d, 0x0000005d, 0x00, 0x00, 0x0000 },
+ { 27, 0x007d, 0x0000007d, 0x01, 0x00, 0x0000 },
+ { 27, 0x007e, 0x0000007e, 0x02, 0x00, 0x0000 },
+ { 27, 0x005d, 0x0400005d, 0x04, 0x00, 0x0000 },
+ { 28, 0xffff, 0x01000004, 0x00, 0x00, 0x0000 },
+ { 28, 0x006d, 0x0c00004d, 0x08, 0x00, 0x0000 },
+ { 29, 0xffff, 0x01000021, 0x00, 0x04, 0x0004 },
+ { 30, 0x0061, 0x00000041, 0x00, 0x00, 0x0000 },
+ { 30, 0x0041, 0x00000041, 0x01, 0x00, 0x0000 },
+ { 30, 0x0061, 0x00000041, 0x02, 0x00, 0x0000 },
+ { 30, 0x0041, 0x00000041, 0x03, 0x00, 0x0000 },
+ { 30, 0x0061, 0x04000041, 0x04, 0x00, 0x0000 },
+ { 30, 0x0061, 0x04000041, 0x05, 0x00, 0x0000 },
+ { 30, 0x0061, 0x04000041, 0x06, 0x00, 0x0000 },
+ { 30, 0x0061, 0x04000041, 0x07, 0x00, 0x0000 },
+ { 30, 0x0061, 0x08000041, 0x08, 0x00, 0x0000 },
+ { 30, 0x0061, 0x08000041, 0x09, 0x00, 0x0000 },
+ { 30, 0x0061, 0x08000041, 0x0a, 0x00, 0x0000 },
+ { 30, 0x0061, 0x08000041, 0x0b, 0x00, 0x0000 },
+ { 30, 0x0061, 0x0c000041, 0x0c, 0x00, 0x0000 },
+ { 30, 0x0061, 0x0c000041, 0x0d, 0x00, 0x0000 },
+ { 30, 0x0061, 0x0c000041, 0x0e, 0x00, 0x0000 },
+ { 30, 0x0061, 0x0c000041, 0x0f, 0x00, 0x0000 },
+ { 31, 0x0073, 0x00000053, 0x00, 0x00, 0x0000 },
+ { 31, 0x0053, 0x00000053, 0x01, 0x00, 0x0000 },
+ { 31, 0x0073, 0x00000053, 0x02, 0x00, 0x0000 },
+ { 31, 0x0053, 0x00000053, 0x03, 0x00, 0x0000 },
+ { 31, 0x0073, 0x04000053, 0x04, 0x00, 0x0000 },
+ { 31, 0x0073, 0x04000053, 0x05, 0x00, 0x0000 },
+ { 31, 0x0073, 0x04000053, 0x06, 0x00, 0x0000 },
+ { 31, 0x0073, 0x04000053, 0x07, 0x00, 0x0000 },
+ { 31, 0x0073, 0x08000053, 0x08, 0x00, 0x0000 },
+ { 31, 0x0073, 0x08000053, 0x09, 0x00, 0x0000 },
+ { 31, 0x0073, 0x08000053, 0x0a, 0x00, 0x0000 },
+ { 31, 0x0073, 0x08000053, 0x0b, 0x00, 0x0000 },
+ { 31, 0x0073, 0x0c000053, 0x0c, 0x00, 0x0000 },
+ { 31, 0x0073, 0x0c000053, 0x0d, 0x00, 0x0000 },
+ { 31, 0x0073, 0x0c000053, 0x0e, 0x00, 0x0000 },
+ { 31, 0x0073, 0x0c000053, 0x0f, 0x00, 0x0000 },
+ { 32, 0x0064, 0x00000044, 0x00, 0x00, 0x0000 },
+ { 32, 0x0044, 0x00000044, 0x01, 0x00, 0x0000 },
+ { 32, 0x0064, 0x00000044, 0x02, 0x00, 0x0000 },
+ { 32, 0x0044, 0x00000044, 0x03, 0x00, 0x0000 },
+ { 32, 0x0064, 0x04000044, 0x04, 0x00, 0x0000 },
+ { 32, 0x0064, 0x04000044, 0x05, 0x00, 0x0000 },
+ { 32, 0x0064, 0x04000044, 0x06, 0x00, 0x0000 },
+ { 32, 0x0064, 0x04000044, 0x07, 0x00, 0x0000 },
+ { 32, 0x0064, 0x08000044, 0x08, 0x00, 0x0000 },
+ { 32, 0x0064, 0x08000044, 0x09, 0x00, 0x0000 },
+ { 32, 0x0064, 0x08000044, 0x0a, 0x00, 0x0000 },
+ { 32, 0x0064, 0x08000044, 0x0b, 0x00, 0x0000 },
+ { 32, 0x0064, 0x0c000044, 0x0c, 0x00, 0x0000 },
+ { 32, 0x0064, 0x0c000044, 0x0d, 0x00, 0x0000 },
+ { 32, 0x0064, 0x0c000044, 0x0e, 0x00, 0x0000 },
+ { 32, 0x0064, 0x0c000044, 0x0f, 0x00, 0x0000 },
+ { 33, 0x0066, 0x00000046, 0x00, 0x00, 0x0000 },
+ { 33, 0x0046, 0x00000046, 0x01, 0x00, 0x0000 },
+ { 33, 0x0066, 0x00000046, 0x02, 0x00, 0x0000 },
+ { 33, 0x0046, 0x00000046, 0x03, 0x00, 0x0000 },
+ { 33, 0x0066, 0x04000046, 0x04, 0x00, 0x0000 },
+ { 33, 0x0066, 0x04000046, 0x05, 0x00, 0x0000 },
+ { 33, 0x0066, 0x04000046, 0x06, 0x00, 0x0000 },
+ { 33, 0x0066, 0x04000046, 0x07, 0x00, 0x0000 },
+ { 33, 0x0066, 0x08000046, 0x08, 0x00, 0x0000 },
+ { 33, 0x0066, 0x08000046, 0x09, 0x00, 0x0000 },
+ { 33, 0x0066, 0x08000046, 0x0a, 0x00, 0x0000 },
+ { 33, 0x0066, 0x08000046, 0x0b, 0x00, 0x0000 },
+ { 33, 0x0066, 0x0c000046, 0x0c, 0x00, 0x0000 },
+ { 33, 0x0066, 0x0c000046, 0x0d, 0x00, 0x0000 },
+ { 33, 0x0066, 0x0c000046, 0x0e, 0x00, 0x0000 },
+ { 33, 0x0066, 0x0c000046, 0x0f, 0x00, 0x0000 },
+ { 34, 0x0067, 0x00000047, 0x00, 0x00, 0x0000 },
+ { 34, 0x0047, 0x00000047, 0x01, 0x00, 0x0000 },
+ { 34, 0x0067, 0x00000047, 0x02, 0x00, 0x0000 },
+ { 34, 0x0047, 0x00000047, 0x03, 0x00, 0x0000 },
+ { 34, 0x0067, 0x04000047, 0x04, 0x00, 0x0000 },
+ { 34, 0x0067, 0x04000047, 0x05, 0x00, 0x0000 },
+ { 34, 0x0067, 0x04000047, 0x06, 0x00, 0x0000 },
+ { 34, 0x0067, 0x04000047, 0x07, 0x00, 0x0000 },
+ { 34, 0x0067, 0x08000047, 0x08, 0x00, 0x0000 },
+ { 34, 0x0067, 0x08000047, 0x09, 0x00, 0x0000 },
+ { 34, 0x0067, 0x08000047, 0x0a, 0x00, 0x0000 },
+ { 34, 0x0067, 0x08000047, 0x0b, 0x00, 0x0000 },
+ { 34, 0x0067, 0x0c000047, 0x0c, 0x00, 0x0000 },
+ { 34, 0x0067, 0x0c000047, 0x0d, 0x00, 0x0000 },
+ { 34, 0x0067, 0x0c000047, 0x0e, 0x00, 0x0000 },
+ { 34, 0x0067, 0x0c000047, 0x0f, 0x00, 0x0000 },
+ { 35, 0x0068, 0x00000048, 0x00, 0x00, 0x0000 },
+ { 35, 0x0048, 0x00000048, 0x01, 0x00, 0x0000 },
+ { 35, 0x0068, 0x00000048, 0x02, 0x00, 0x0000 },
+ { 35, 0x0048, 0x00000048, 0x03, 0x00, 0x0000 },
+ { 35, 0x0068, 0x04000048, 0x04, 0x00, 0x0000 },
+ { 35, 0x0068, 0x04000048, 0x05, 0x00, 0x0000 },
+ { 35, 0x0068, 0x04000048, 0x06, 0x00, 0x0000 },
+ { 35, 0x0068, 0x04000048, 0x07, 0x00, 0x0000 },
+ { 35, 0x0068, 0x08000048, 0x08, 0x00, 0x0000 },
+ { 35, 0x0068, 0x08000048, 0x09, 0x00, 0x0000 },
+ { 35, 0x0068, 0x08000048, 0x0a, 0x00, 0x0000 },
+ { 35, 0x0068, 0x08000048, 0x0b, 0x00, 0x0000 },
+ { 35, 0x0068, 0x0c000048, 0x0c, 0x00, 0x0000 },
+ { 35, 0x0068, 0x0c000048, 0x0d, 0x00, 0x0000 },
+ { 35, 0x0068, 0x0c000048, 0x0e, 0x00, 0x0000 },
+ { 35, 0x0068, 0x0c000048, 0x0f, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0000004a, 0x00, 0x00, 0x0000 },
+ { 36, 0x004a, 0x0000004a, 0x01, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0000004a, 0x02, 0x00, 0x0000 },
+ { 36, 0x004a, 0x0000004a, 0x03, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0400004a, 0x04, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0400004a, 0x05, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0400004a, 0x06, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0400004a, 0x07, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0800004a, 0x08, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0800004a, 0x09, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0800004a, 0x0a, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0800004a, 0x0b, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0c00004a, 0x0c, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0c00004a, 0x0d, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0c00004a, 0x0e, 0x00, 0x0000 },
+ { 36, 0x006a, 0x0c00004a, 0x0f, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0000004b, 0x00, 0x00, 0x0000 },
+ { 37, 0x004b, 0x0000004b, 0x01, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0000004b, 0x02, 0x00, 0x0000 },
+ { 37, 0x004b, 0x0000004b, 0x03, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0400004b, 0x04, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0400004b, 0x05, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0400004b, 0x06, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0400004b, 0x07, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0800004b, 0x08, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0800004b, 0x09, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0800004b, 0x0a, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0800004b, 0x0b, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0c00004b, 0x0c, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0c00004b, 0x0d, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0c00004b, 0x0e, 0x00, 0x0000 },
+ { 37, 0x006b, 0x0c00004b, 0x0f, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0000004c, 0x00, 0x00, 0x0000 },
+ { 38, 0x004c, 0x0000004c, 0x01, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0000004c, 0x02, 0x00, 0x0000 },
+ { 38, 0x004c, 0x0000004c, 0x03, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0400004c, 0x04, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0400004c, 0x05, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0400004c, 0x06, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0400004c, 0x07, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0800004c, 0x08, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0800004c, 0x09, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0800004c, 0x0a, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0800004c, 0x0b, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0c00004c, 0x0c, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0c00004c, 0x0d, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0c00004c, 0x0e, 0x00, 0x0000 },
+ { 38, 0x006c, 0x0c00004c, 0x0f, 0x00, 0x0000 },
+ { 39, 0x003b, 0x0000003b, 0x00, 0x00, 0x0000 },
+ { 39, 0x003a, 0x0000003a, 0x01, 0x00, 0x0000 },
+ { 40, 0x0027, 0x00000027, 0x00, 0x00, 0x0000 },
+ { 40, 0x0022, 0x00000022, 0x01, 0x00, 0x0000 },
+ { 40, 0x0027, 0x01001251, 0x02, 0x01, 0x0000 },
+ { 40, 0x0022, 0x01001257, 0x03, 0x01, 0x0000 },
+ { 40, 0x0067, 0x04000047, 0x04, 0x00, 0x0000 },
+ { 41, 0x0060, 0x00000060, 0x00, 0x00, 0x0000 },
+ { 41, 0x007e, 0x0000007e, 0x01, 0x00, 0x0000 },
+ { 41, 0x0060, 0x01001250, 0x02, 0x01, 0x0000 },
+ { 41, 0x007e, 0x01001253, 0x03, 0x01, 0x0000 },
+ { 42, 0xffff, 0x01000020, 0x00, 0x04, 0x0001 },
+ { 43, 0x005c, 0x0000005c, 0x00, 0x00, 0x0000 },
+ { 43, 0x007c, 0x0000007c, 0x01, 0x00, 0x0000 },
+ { 43, 0x005c, 0x0400005c, 0x04, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0000005a, 0x00, 0x00, 0x0000 },
+ { 44, 0x005a, 0x0000005a, 0x01, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0000005a, 0x02, 0x00, 0x0000 },
+ { 44, 0x005a, 0x0000005a, 0x03, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0400005a, 0x04, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0400005a, 0x05, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0400005a, 0x06, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0400005a, 0x07, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0800005a, 0x08, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0800005a, 0x09, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0800005a, 0x0a, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0800005a, 0x0b, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0c00005a, 0x0c, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0c00005a, 0x0d, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0c00005a, 0x0e, 0x00, 0x0000 },
+ { 44, 0x007a, 0x0c00005a, 0x0f, 0x00, 0x0000 },
+ { 45, 0x0078, 0x00000058, 0x00, 0x00, 0x0000 },
+ { 45, 0x0058, 0x00000058, 0x01, 0x00, 0x0000 },
+ { 45, 0x0078, 0x00000058, 0x02, 0x00, 0x0000 },
+ { 45, 0x0058, 0x00000058, 0x03, 0x00, 0x0000 },
+ { 45, 0x0078, 0x04000058, 0x04, 0x00, 0x0000 },
+ { 45, 0x0078, 0x04000058, 0x05, 0x00, 0x0000 },
+ { 45, 0x0078, 0x04000058, 0x06, 0x00, 0x0000 },
+ { 45, 0x0078, 0x04000058, 0x07, 0x00, 0x0000 },
+ { 45, 0x0078, 0x08000058, 0x08, 0x00, 0x0000 },
+ { 45, 0x0078, 0x08000058, 0x09, 0x00, 0x0000 },
+ { 45, 0x0078, 0x08000058, 0x0a, 0x00, 0x0000 },
+ { 45, 0x0078, 0x08000058, 0x0b, 0x00, 0x0000 },
+ { 45, 0x0078, 0x0c000058, 0x0c, 0x00, 0x0000 },
+ { 45, 0x0078, 0x0c000058, 0x0d, 0x00, 0x0000 },
+ { 45, 0x0078, 0x0c000058, 0x0e, 0x00, 0x0000 },
+ { 45, 0x0078, 0x0c000058, 0x0f, 0x00, 0x0000 },
+ { 46, 0x0063, 0x00000043, 0x00, 0x00, 0x0000 },
+ { 46, 0x0043, 0x00000043, 0x01, 0x00, 0x0000 },
+ { 46, 0x0063, 0x00000043, 0x02, 0x00, 0x0000 },
+ { 46, 0x0043, 0x00000043, 0x03, 0x00, 0x0000 },
+ { 46, 0x0063, 0x04000043, 0x04, 0x00, 0x0000 },
+ { 46, 0x0063, 0x04000043, 0x05, 0x00, 0x0000 },
+ { 46, 0x0063, 0x04000043, 0x06, 0x00, 0x0000 },
+ { 46, 0x0063, 0x04000043, 0x07, 0x00, 0x0000 },
+ { 46, 0x0063, 0x08000043, 0x08, 0x00, 0x0000 },
+ { 46, 0x0063, 0x08000043, 0x09, 0x00, 0x0000 },
+ { 46, 0x0063, 0x08000043, 0x0a, 0x00, 0x0000 },
+ { 46, 0x0063, 0x08000043, 0x0b, 0x00, 0x0000 },
+ { 46, 0x0063, 0x0c000043, 0x0c, 0x00, 0x0000 },
+ { 46, 0x0063, 0x0c000043, 0x0d, 0x00, 0x0000 },
+ { 46, 0x0063, 0x0c000043, 0x0e, 0x00, 0x0000 },
+ { 46, 0x0063, 0x0c000043, 0x0f, 0x00, 0x0000 },
+ { 47, 0x0076, 0x00000056, 0x00, 0x00, 0x0000 },
+ { 47, 0x0056, 0x00000056, 0x01, 0x00, 0x0000 },
+ { 47, 0x0076, 0x00000056, 0x02, 0x00, 0x0000 },
+ { 47, 0x0056, 0x00000056, 0x03, 0x00, 0x0000 },
+ { 47, 0x0076, 0x04000056, 0x04, 0x00, 0x0000 },
+ { 47, 0x0076, 0x04000056, 0x05, 0x00, 0x0000 },
+ { 47, 0x0076, 0x04000056, 0x06, 0x00, 0x0000 },
+ { 47, 0x0076, 0x04000056, 0x07, 0x00, 0x0000 },
+ { 47, 0x0076, 0x08000056, 0x08, 0x00, 0x0000 },
+ { 47, 0x0076, 0x08000056, 0x09, 0x00, 0x0000 },
+ { 47, 0x0076, 0x08000056, 0x0a, 0x00, 0x0000 },
+ { 47, 0x0076, 0x08000056, 0x0b, 0x00, 0x0000 },
+ { 47, 0x0076, 0x0c000056, 0x0c, 0x00, 0x0000 },
+ { 47, 0x0076, 0x0c000056, 0x0d, 0x00, 0x0000 },
+ { 47, 0x0076, 0x0c000056, 0x0e, 0x00, 0x0000 },
+ { 47, 0x0076, 0x0c000056, 0x0f, 0x00, 0x0000 },
+ { 48, 0x0062, 0x00000042, 0x00, 0x00, 0x0000 },
+ { 48, 0x0042, 0x00000042, 0x01, 0x00, 0x0000 },
+ { 48, 0x0062, 0x00000042, 0x02, 0x00, 0x0000 },
+ { 48, 0x0042, 0x00000042, 0x03, 0x00, 0x0000 },
+ { 48, 0x0062, 0x04000042, 0x04, 0x00, 0x0000 },
+ { 48, 0x0062, 0x04000042, 0x05, 0x00, 0x0000 },
+ { 48, 0x0062, 0x04000042, 0x06, 0x00, 0x0000 },
+ { 48, 0x0062, 0x04000042, 0x07, 0x00, 0x0000 },
+ { 48, 0x0062, 0x08000042, 0x08, 0x00, 0x0000 },
+ { 48, 0x0062, 0x08000042, 0x09, 0x00, 0x0000 },
+ { 48, 0x0062, 0x08000042, 0x0a, 0x00, 0x0000 },
+ { 48, 0x0062, 0x08000042, 0x0b, 0x00, 0x0000 },
+ { 48, 0x0062, 0x0c000042, 0x0c, 0x00, 0x0000 },
+ { 48, 0x0062, 0x0c000042, 0x0d, 0x00, 0x0000 },
+ { 48, 0x0062, 0x0c000042, 0x0e, 0x00, 0x0000 },
+ { 48, 0x0062, 0x0c000042, 0x0f, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0000004e, 0x00, 0x00, 0x0000 },
+ { 49, 0x004e, 0x0000004e, 0x01, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0000004e, 0x02, 0x00, 0x0000 },
+ { 49, 0x004e, 0x0000004e, 0x03, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0400004e, 0x04, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0400004e, 0x05, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0400004e, 0x06, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0400004e, 0x07, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0800004e, 0x08, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0800004e, 0x09, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0800004e, 0x0a, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0800004e, 0x0b, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0c00004e, 0x0c, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0c00004e, 0x0d, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0c00004e, 0x0e, 0x00, 0x0000 },
+ { 49, 0x006e, 0x0c00004e, 0x0f, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0000004d, 0x00, 0x00, 0x0000 },
+ { 50, 0x004d, 0x0000004d, 0x01, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0000004d, 0x02, 0x00, 0x0000 },
+ { 50, 0x004d, 0x0000004d, 0x03, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0400004d, 0x04, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0400004d, 0x05, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0400004d, 0x06, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0400004d, 0x07, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0800004d, 0x08, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0800004d, 0x09, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0800004d, 0x0a, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0800004d, 0x0b, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0c00004d, 0x0c, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0c00004d, 0x0d, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0c00004d, 0x0e, 0x00, 0x0000 },
+ { 50, 0x006d, 0x0c00004d, 0x0f, 0x00, 0x0000 },
+ { 51, 0x002c, 0x0000002c, 0x00, 0x00, 0x0000 },
+ { 51, 0x003c, 0x0000003c, 0x01, 0x00, 0x0000 },
+ { 51, 0x002c, 0x0100125b, 0x02, 0x01, 0x0000 },
+ { 52, 0x002e, 0x0000002e, 0x00, 0x00, 0x0000 },
+ { 52, 0x003e, 0x0000003e, 0x01, 0x00, 0x0000 },
+ { 52, 0xffff, 0x01001120, 0x02, 0x00, 0x0000 },
+ { 53, 0x002f, 0x0000002f, 0x00, 0x00, 0x0000 },
+ { 53, 0x003f, 0x0000003f, 0x01, 0x00, 0x0000 },
+ { 53, 0xffff, 0x01000003, 0x04, 0x00, 0x0000 },
+ { 54, 0xffff, 0x01000020, 0x00, 0x04, 0x0001 },
+ { 55, 0x002a, 0x2000002a, 0x00, 0x00, 0x0000 },
+ { 56, 0xffff, 0x01000023, 0x00, 0x04, 0x0008 },
+ { 57, 0x0020, 0x00000020, 0x00, 0x00, 0x0000 },
+ { 58, 0xffff, 0x01000024, 0x00, 0x00, 0x0000 },
+ { 59, 0xffff, 0x01000030, 0x00, 0x00, 0x0000 },
+ { 59, 0xffff, 0x0100003c, 0x01, 0x00, 0x0000 },
+ { 59, 0xffff, 0x01000048, 0x04, 0x00, 0x0000 },
+ { 59, 0xffff, 0x01000000, 0x0c, 0x08, 0x0100 },
+ { 60, 0xffff, 0x01000031, 0x00, 0x00, 0x0000 },
+ { 60, 0xffff, 0x0100003d, 0x01, 0x00, 0x0000 },
+ { 60, 0xffff, 0x01000049, 0x04, 0x00, 0x0000 },
+ { 60, 0xffff, 0x01000000, 0x0c, 0x08, 0x0101 },
+ { 61, 0xffff, 0x01000032, 0x00, 0x00, 0x0000 },
+ { 61, 0xffff, 0x0100003e, 0x01, 0x00, 0x0000 },
+ { 61, 0xffff, 0x0100004a, 0x04, 0x00, 0x0000 },
+ { 61, 0xffff, 0x01000000, 0x0c, 0x08, 0x0102 },
+ { 62, 0xffff, 0x01000033, 0x00, 0x00, 0x0000 },
+ { 62, 0xffff, 0x0100003f, 0x01, 0x00, 0x0000 },
+ { 62, 0xffff, 0x0100004b, 0x04, 0x00, 0x0000 },
+ { 62, 0xffff, 0x01000000, 0x0c, 0x08, 0x0103 },
+ { 63, 0xffff, 0x01000034, 0x00, 0x00, 0x0000 },
+ { 63, 0xffff, 0x01000040, 0x01, 0x00, 0x0000 },
+ { 63, 0xffff, 0x0100004c, 0x04, 0x00, 0x0000 },
+ { 63, 0xffff, 0x01000000, 0x0c, 0x08, 0x0104 },
+ { 64, 0xffff, 0x01000035, 0x00, 0x00, 0x0000 },
+ { 64, 0xffff, 0x01000041, 0x01, 0x00, 0x0000 },
+ { 64, 0xffff, 0x0100004d, 0x04, 0x00, 0x0000 },
+ { 64, 0xffff, 0x01000000, 0x0c, 0x08, 0x0105 },
+ { 65, 0xffff, 0x01000036, 0x00, 0x00, 0x0000 },
+ { 65, 0xffff, 0x01000042, 0x01, 0x00, 0x0000 },
+ { 65, 0xffff, 0x0100004e, 0x04, 0x00, 0x0000 },
+ { 65, 0xffff, 0x01000000, 0x0c, 0x08, 0x0106 },
+ { 66, 0xffff, 0x01000037, 0x00, 0x00, 0x0000 },
+ { 66, 0xffff, 0x01000043, 0x01, 0x00, 0x0000 },
+ { 66, 0xffff, 0x0100004f, 0x04, 0x00, 0x0000 },
+ { 66, 0xffff, 0x01000000, 0x0c, 0x08, 0x0107 },
+ { 67, 0xffff, 0x01000038, 0x00, 0x00, 0x0000 },
+ { 67, 0xffff, 0x01000044, 0x01, 0x00, 0x0000 },
+ { 67, 0xffff, 0x01000050, 0x04, 0x00, 0x0000 },
+ { 67, 0xffff, 0x01000000, 0x0c, 0x08, 0x0108 },
+ { 68, 0xffff, 0x01000039, 0x00, 0x00, 0x0000 },
+ { 68, 0xffff, 0x01000045, 0x01, 0x00, 0x0000 },
+ { 68, 0xffff, 0x01000051, 0x04, 0x00, 0x0000 },
+ { 68, 0xffff, 0x01000000, 0x0c, 0x08, 0x0109 },
+ { 69, 0xffff, 0x01000025, 0x00, 0x00, 0x0000 },
+ { 70, 0xffff, 0x01000026, 0x00, 0x00, 0x0000 },
+ { 70, 0xffff, 0x01000026, 0x08, 0x00, 0x0000 },
+ { 71, 0x0037, 0x20000037, 0x00, 0x00, 0x0000 },
+ { 72, 0x0038, 0x20000038, 0x00, 0x00, 0x0000 },
+ { 73, 0x0039, 0x20000039, 0x00, 0x00, 0x0000 },
+ { 74, 0x002d, 0x2000002d, 0x00, 0x00, 0x0000 },
+ { 75, 0x0034, 0x20000034, 0x00, 0x00, 0x0000 },
+ { 76, 0x0035, 0x20000035, 0x00, 0x00, 0x0000 },
+ { 77, 0x0036, 0x20000036, 0x00, 0x00, 0x0000 },
+ { 78, 0x002b, 0x2000002b, 0x00, 0x00, 0x0000 },
+ { 79, 0x0031, 0x20000031, 0x00, 0x00, 0x0000 },
+ { 80, 0x0032, 0x20000032, 0x00, 0x00, 0x0000 },
+ { 81, 0x0033, 0x20000033, 0x00, 0x00, 0x0000 },
+ { 82, 0x0030, 0x20000030, 0x00, 0x00, 0x0000 },
+ { 83, 0x002e, 0x2000002e, 0x00, 0x00, 0x0000 },
+ { 83, 0xffff, 0x01000000, 0x06, 0x08, 0x0200 },
+ { 83, 0xffff, 0x01000000, 0x0c, 0x08, 0x0200 },
+ { 86, 0x003c, 0x0000003c, 0x00, 0x00, 0x0000 },
+ { 86, 0x003e, 0x0000003e, 0x01, 0x00, 0x0000 },
+ { 86, 0x007c, 0x0000007c, 0x02, 0x00, 0x0000 },
+ { 87, 0xffff, 0x0100003a, 0x00, 0x00, 0x0000 },
+ { 87, 0xffff, 0x01000046, 0x01, 0x00, 0x0000 },
+ { 87, 0xffff, 0x01000052, 0x04, 0x00, 0x0000 },
+ { 87, 0xffff, 0x01000000, 0x0c, 0x08, 0x010a },
+ { 88, 0xffff, 0x0100003b, 0x00, 0x00, 0x0000 },
+ { 88, 0xffff, 0x01000047, 0x01, 0x00, 0x0000 },
+ { 88, 0xffff, 0x01000000, 0x0c, 0x08, 0x010b },
+ { 96, 0xffff, 0x21000005, 0x00, 0x00, 0x0000 },
+ { 97, 0xffff, 0x01000021, 0x00, 0x04, 0x0004 },
+ { 98, 0x002f, 0x2000002f, 0x00, 0x00, 0x0000 },
+ { 99, 0x005c, 0x0400005c, 0x00, 0x00, 0x0000 },
+ { 100, 0xffff, 0x01001103, 0x00, 0x04, 0x0002 },
+ { 102, 0xffff, 0x01000010, 0x00, 0x00, 0x0000 },
+ { 103, 0xffff, 0x01000013, 0x00, 0x00, 0x0000 },
+ { 104, 0xffff, 0x01000016, 0x00, 0x00, 0x0000 },
+ { 105, 0xffff, 0x01000012, 0x00, 0x00, 0x0000 },
+ { 105, 0xffff, 0x01000000, 0x0c, 0x08, 0x0180 },
+ { 106, 0xffff, 0x01000014, 0x00, 0x00, 0x0000 },
+ { 106, 0xffff, 0x01000000, 0x0c, 0x08, 0x0181 },
+ { 107, 0xffff, 0x01000011, 0x00, 0x00, 0x0000 },
+ { 108, 0xffff, 0x01000015, 0x00, 0x00, 0x0000 },
+ { 109, 0xffff, 0x01000017, 0x00, 0x00, 0x0000 },
+ { 110, 0xffff, 0x01000006, 0x00, 0x00, 0x0000 },
+ { 111, 0xffff, 0x01000007, 0x00, 0x00, 0x0000 },
+ { 111, 0xffff, 0x01000000, 0x06, 0x08, 0x0200 },
+ { 111, 0xffff, 0x01000000, 0x0c, 0x08, 0x0200 },
+ { 119, 0xffff, 0x01000008, 0x00, 0x00, 0x0000 },
+};
+
+const QWSKeyboard::Composing QWSKbPrivate::s_keycompose_default[] = {
+ { 0x0060, 0x0041, 0x00c0 },
+ { 0x0060, 0x0061, 0x00e0 },
+ { 0x0027, 0x0041, 0x00c1 },
+ { 0x0027, 0x0061, 0x00e1 },
+ { 0x005e, 0x0041, 0x00c2 },
+ { 0x005e, 0x0061, 0x00e2 },
+ { 0x007e, 0x0041, 0x00c3 },
+ { 0x007e, 0x0061, 0x00e3 },
+ { 0x0022, 0x0041, 0x00c4 },
+ { 0x0022, 0x0061, 0x00e4 },
+ { 0x002d, 0x0061, 0x00aa },
+ { 0x002d, 0x0041, 0x00aa },
+ { 0x004f, 0x0041, 0x00c5 },
+ { 0x006f, 0x0061, 0x00e5 },
+ { 0x0030, 0x0041, 0x00c5 },
+ { 0x0030, 0x0061, 0x00e5 },
+ { 0x0041, 0x0041, 0x00c5 },
+ { 0x0061, 0x0061, 0x00e5 },
+ { 0x00b0, 0x0041, 0x00c5 },
+ { 0x00b0, 0x0061, 0x00e5 },
+ { 0x0041, 0x0045, 0x00c6 },
+ { 0x0061, 0x0065, 0x00e6 },
+ { 0x002c, 0x0043, 0x00c7 },
+ { 0x002c, 0x0063, 0x00e7 },
+ { 0x005e, 0x0043, 0x00c7 },
+ { 0x005e, 0x0063, 0x00e7 },
+ { 0x0060, 0x0045, 0x00c8 },
+ { 0x0060, 0x0065, 0x00e8 },
+ { 0x0027, 0x0045, 0x00c9 },
+ { 0x0027, 0x0065, 0x00e9 },
+ { 0x005e, 0x0045, 0x00ca },
+ { 0x005e, 0x0065, 0x00ea },
+ { 0x0022, 0x0045, 0x00cb },
+ { 0x0022, 0x0065, 0x00eb },
+ { 0x0060, 0x0049, 0x00cc },
+ { 0x0060, 0x0069, 0x00ec },
+ { 0x0027, 0x0049, 0x00cd },
+ { 0x0027, 0x0069, 0x00ed },
+ { 0x005e, 0x0049, 0x00ce },
+ { 0x005e, 0x0069, 0x00ee },
+ { 0x0022, 0x0049, 0x00cf },
+ { 0x0022, 0x0069, 0x00ef },
+ { 0x002d, 0x0044, 0x00d0 },
+ { 0x002d, 0x0064, 0x00f0 },
+ { 0x005e, 0x0044, 0x00d0 },
+ { 0x005e, 0x0064, 0x00f0 },
+ { 0x007e, 0x004e, 0x00d1 },
+ { 0x007e, 0x006e, 0x00f1 },
+ { 0x005e, 0x004e, 0x00d1 },
+ { 0x005e, 0x006e, 0x00f1 },
+ { 0x0060, 0x004f, 0x00d2 },
+ { 0x0060, 0x006f, 0x00f2 },
+ { 0x0027, 0x004f, 0x00d3 },
+ { 0x0027, 0x006f, 0x00f3 },
+ { 0x005e, 0x004f, 0x00d4 },
+ { 0x005e, 0x006f, 0x00f4 },
+ { 0x007e, 0x004f, 0x00d5 },
+ { 0x007e, 0x006f, 0x00f5 },
+ { 0x0022, 0x004f, 0x00d6 },
+ { 0x0022, 0x006f, 0x00f6 },
+ { 0x002f, 0x004f, 0x00d8 },
+ { 0x002f, 0x006f, 0x00f8 },
+ { 0x002d, 0x006f, 0x00ba },
+ { 0x002d, 0x004f, 0x00ba },
+ { 0x0060, 0x0055, 0x00d9 },
+ { 0x0060, 0x0075, 0x00f9 },
+ { 0x0027, 0x0055, 0x00da },
+ { 0x0027, 0x0075, 0x00fa },
+ { 0x005e, 0x0055, 0x00db },
+ { 0x005e, 0x0075, 0x00fb },
+ { 0x0022, 0x0055, 0x00dc },
+ { 0x0022, 0x0075, 0x00fc },
+ { 0x0027, 0x0059, 0x00dd },
+ { 0x0027, 0x0079, 0x00fd },
+ { 0x0054, 0x0048, 0x00de },
+ { 0x0074, 0x0068, 0x00fe },
+ { 0x0073, 0x0073, 0x00df },
+ { 0x0022, 0x0079, 0x00ff },
+ { 0x0073, 0x007a, 0x00df },
+ { 0x006e, 0x006e, 0x00f1 },
+ { 0x006e, 0x0068, 0x00f1 },
+ { 0x004e, 0x0059, 0x00d1 },
+ { 0x004e, 0x004e, 0x00d1 },
+ { 0x004e, 0x0048, 0x00d1 },
+ { 0x004e, 0x0079, 0x00d1 },
+ { 0x004e, 0x006e, 0x00d1 },
+ { 0x004e, 0x0068, 0x00d1 },
+ { 0x002d, 0x004c, 0x00a3 },
+ { 0x003c, 0x003c, 0x00ab },
+ { 0x003e, 0x003e, 0x00bb },
+ { 0x003f, 0x003f, 0x00bf },
+ { 0x005e, 0x003f, 0x00bf },
+ { 0x0021, 0x0021, 0x00a1 },
+ { 0x005e, 0x0021, 0x00a1 },
+ { 0x005e, 0x0031, 0x00b9 },
+ { 0x005e, 0x0032, 0x00b2 },
+ { 0x005e, 0x0033, 0x00b3 },
+ { 0x002b, 0x002d, 0x00b1 },
+ { 0x0063, 0x003d, 0x00a2 },
+ { 0x0063, 0x002f, 0x00a2 },
+ { 0x002f, 0x0063, 0x00a2 },
+ { 0x002d, 0x0063, 0x00a2 },
+ { 0x002d, 0x0043, 0x00a2 },
+ { 0x004c, 0x003d, 0x00a3 },
+ { 0x002d, 0x004c, 0x00a3 },
+ { 0x002d, 0x006c, 0x00a3 },
+ { 0x005e, 0x002a, 0x00d7 },
+ { 0x005e, 0x0078, 0x00d7 },
+ { 0x0078, 0x0078, 0x00d7 },
+ { 0x005e, 0x002e, 0x00b7 },
+ { 0x002e, 0x002e, 0x00b7 },
+ { 0x005e, 0x002f, 0x00f7 },
+ { 0x005e, 0x003a, 0x00f7 },
+ { 0x002d, 0x003a, 0x00f7 },
+ { 0x003a, 0x002d, 0x00f7 },
+ { 0x0059, 0x003d, 0x00a5 },
+ { 0x002d, 0x0059, 0x00a5 },
+ { 0x002d, 0x006c, 0x00a5 },
+ { 0x0028, 0x0063, 0x00a9 },
+ { 0x0022, 0x0063, 0x00a9 },
+ { 0x002d, 0x0061, 0x00aa },
+ { 0x002d, 0x0041, 0x00aa },
+ { 0x002d, 0x006f, 0x00ba },
+ { 0x002d, 0x004f, 0x00ba },
+ { 0x0028, 0x0072, 0x00ae },
+ { 0x0022, 0x0072, 0x00ae },
+ { 0x006d, 0x0075, 0x00b5 },
+ { 0x0031, 0x0034, 0x0152 },
+ { 0x0031, 0x0032, 0x0153 },
+ { 0x0033, 0x0034, 0x0178 },
+ { 0x0065, 0x003d, 0x20ac },
+ { 0x002d, 0x0065, 0x20ac },
+ { 0x002d, 0x0045, 0x20ac },
+ { 0x0076, 0x0053, 0x0160 },
+ { 0x005e, 0x0053, 0x0160 },
+ { 0x0076, 0x0073, 0x0161 },
+ { 0x005e, 0x0073, 0x0161 },
+ { 0x0076, 0x005a, 0x017d },
+ { 0x005e, 0x005a, 0x017d },
+ { 0x0076, 0x007a, 0x017e },
+ { 0x005e, 0x007a, 0x017e },
+ { 0x004f, 0x0045, 0x0152 },
+ { 0x004f, 0x0065, 0x0152 },
+ { 0x006f, 0x0065, 0x0153 },
+ { 0x0022, 0x0059, 0x0178 },
+ { 0x0069, 0x006a, 0x00ff },
+ { 0x0049, 0x004a, 0x0178 },
+};
+
+#endif
diff --git a/src/gui/embedded/qkbd_qws.cpp b/src/gui/embedded/qkbd_qws.cpp
index 8cf87db..dc92a01 100644
--- a/src/gui/embedded/qkbd_qws.cpp
+++ b/src/gui/embedded/qkbd_qws.cpp
@@ -40,56 +40,217 @@
****************************************************************************/
#include "qkbd_qws.h"
+#include "qkbd_qws_p.h"
#ifndef QT_NO_QWS_KEYBOARD
+#include <QFile>
+#include <QDataStream>
+#include <QStringList>
+
#include "qwindowsystem_qws.h"
#include "qscreen_qws.h"
#include "qtimer.h"
#include <stdlib.h>
+//#define QT_DEBUG_KEYMAP
+
+
QT_BEGIN_NAMESPACE
class QWSKbPrivate : public QObject
{
Q_OBJECT
public:
- QWSKbPrivate(QWSKeyboardHandler *h) {
- handler = h;
- arTimer = new QTimer(this);
- arTimer->setSingleShot(true);
- connect(arTimer, SIGNAL(timeout()), SLOT(autoRepeat()));
- repeatdelay = 400;
- repeatperiod = 80;
+ QWSKbPrivate(QWSKeyboardHandler *h, const QString &device)
+ : m_handler(h), m_modifiers(0), m_composing(0), m_dead_unicode(0xffff),
+ m_no_zap(false), m_do_compose(false),
+ m_keymap(0), m_keymap_size(0), m_keycompose(0), m_keycompose_size(0)
+ {
+ m_ar_timer = new QTimer(this);
+ m_ar_timer->setSingleShot(true);
+ connect(m_ar_timer, SIGNAL(timeout()), SLOT(autoRepeat()));
+ m_ar_delay = 400;
+ m_ar_period = 80;
+
+ memset(m_locks, 0, sizeof(m_locks));
+
+ QString keymap;
+ QStringList args = device.split(QLatin1Char(':'));
+ foreach (const QString &arg, args) {
+ if (arg.startsWith(QLatin1String("keymap=")))
+ keymap = arg.mid(7);
+ else if (arg == QLatin1String("disable-zap"))
+ m_no_zap = true;
+ else if (arg == QLatin1String("enable-compose"))
+ m_do_compose = true;
+ else if (arg.startsWith(QLatin1String("repeat-delay=")))
+ m_ar_delay = arg.mid(13).toInt();
+ else if (arg.startsWith(QLatin1String("repeat-rate=")))
+ m_ar_period = arg.mid(12).toInt();
+ }
+
+ if (keymap.isEmpty() || !loadKeymap(keymap))
+ unloadKeymap();
}
- void beginAutoRepeat(int uni, int code, Qt::KeyboardModifiers mod) {
- unicode = uni;
- keycode = code;
- modifier = mod;
- arTimer->start(repeatdelay);
+ ~QWSKbPrivate()
+ {
+ unloadKeymap();
}
- void endAutoRepeat() {
- arTimer->stop();
+
+ void beginAutoRepeat(int uni, int code, Qt::KeyboardModifiers mod)
+ {
+ m_ar_unicode = uni;
+ m_ar_keycode = code;
+ m_ar_modifier = mod;
+ m_ar_timer->start(m_ar_delay);
}
+ void endAutoRepeat()
+ {
+ m_ar_timer->stop();
+ }
+
+ static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
+ {
+ Qt::KeyboardModifiers qtmod = Qt::NoModifier;
+
+ if (mod & (QWSKeyboard::ModShift | QWSKeyboard::ModShiftL | QWSKeyboard::ModShiftR))
+ qtmod |= Qt::ShiftModifier;
+ if (mod & (QWSKeyboard::ModControl | QWSKeyboard::ModCtrlL | QWSKeyboard::ModCtrlR))
+ qtmod |= Qt::ControlModifier;
+ if (mod & QWSKeyboard::ModAlt)
+ qtmod |= Qt::AltModifier;
+
+ return qtmod;
+ }
+
+ void unloadKeymap();
+ bool loadKeymap(const QString &file);
+
private slots:
- void autoRepeat() {
- handler->processKeyEvent(unicode, keycode, modifier, false, true);
- handler->processKeyEvent(unicode, keycode, modifier, true, true);
- arTimer->start(repeatperiod);
+ void autoRepeat()
+ {
+ m_handler->processKeyEvent(m_ar_unicode, m_ar_keycode, m_ar_modifier, false, true);
+ m_handler->processKeyEvent(m_ar_unicode, m_ar_keycode, m_ar_modifier, true, true);
+ m_ar_timer->start(m_ar_period);
}
private:
- QWSKeyboardHandler *handler;
- int unicode;
- int keycode;
- Qt::KeyboardModifiers modifier;
- int repeatdelay;
- int repeatperiod;
- QTimer *arTimer;
+ QWSKeyboardHandler *m_handler;
+
+ // auto repeat simulation
+ int m_ar_unicode;
+ int m_ar_keycode;
+ Qt::KeyboardModifiers m_ar_modifier;
+ int m_ar_delay;
+ int m_ar_period;
+ QTimer *m_ar_timer;
+
+ // keymap handling
+ quint8 m_modifiers;
+ quint8 m_locks[3];
+ int m_composing;
+ quint16 m_dead_unicode;
+
+ bool m_no_zap;
+ bool m_do_compose;
+
+ const QWSKeyboard::Mapping *m_keymap;
+ int m_keymap_size;
+ const QWSKeyboard::Composing *m_keycompose;
+ int m_keycompose_size;
+
+ static const QWSKeyboard::Mapping s_keymap_default[];
+ static const QWSKeyboard::Composing s_keycompose_default[];
+
+ friend class QWSKeyboardHandler;
};
+// simple builtin US keymap
+#include "qkbd_defaultmap_qws_p.h"
+
+// the unloadKeymap() function needs to be AFTER the defaultmap include,
+// since the sizeof(s_keymap_default) wouldn't work otherwise.
+
+void QWSKbPrivate::unloadKeymap()
+{
+ if (m_keymap && m_keymap != s_keymap_default)
+ delete [] m_keymap;
+ if (m_keycompose && m_keycompose != s_keycompose_default)
+ delete [] m_keycompose;
+
+ m_keymap = s_keymap_default;
+ m_keymap_size = sizeof(s_keymap_default) / sizeof(s_keymap_default[0]);
+ m_keycompose = s_keycompose_default;
+ m_keycompose_size = sizeof(s_keycompose_default) / sizeof(s_keycompose_default[0]);
+
+ // reset state, so we could switch keymaps at runtime
+ m_modifiers = 0;
+ memset(m_locks, 0, sizeof(m_locks));
+ m_composing = 0;
+ m_dead_unicode = 0xffff;
+}
+
+bool QWSKbPrivate::loadKeymap(const QString &file)
+{
+ QFile f(file);
+
+ if (!f.open(QIODevice::ReadOnly)) {
+ qWarning("Could not open keymap file '%s'", qPrintable(file));
+ return false;
+ }
+
+ // .qmap files have a very simple structure:
+ // quint32 magic (QWSKeyboard::FileMagic)
+ // quint32 version (1)
+ // quint32 keymap_size (# of struct QWSKeyboard::Mappings)
+ // quint32 keycompose_size (# of struct QWSKeyboard::Composings)
+ // all QWSKeyboard::Mappings via QDataStream::operator(<<|>>)
+ // all QWSKeyboard::Composings via QDataStream::operator(<<|>>)
+
+ quint32 qmap_magic, qmap_version, qmap_keymap_size, qmap_keycompose_size;
+
+ QDataStream ds(&f);
+
+ ds >> qmap_magic >> qmap_version >> qmap_keymap_size >> qmap_keycompose_size;
+
+ if (ds.status() != QDataStream::Ok || qmap_magic != QWSKeyboard::FileMagic || qmap_version != 1 || qmap_keymap_size == 0) {
+ qWarning("'%s' is ot a valid.qmap keymap file.", qPrintable(file));
+ return false;
+ }
+
+ QWSKeyboard::Mapping *qmap_keymap = new QWSKeyboard::Mapping[qmap_keymap_size];
+ QWSKeyboard::Composing *qmap_keycompose = qmap_keycompose_size ? new QWSKeyboard::Composing[qmap_keycompose_size] : 0;
+
+ for (quint32 i = 0; i < qmap_keymap_size; ++i)
+ ds >> qmap_keymap[i];
+ for (quint32 i = 0; i < qmap_keycompose_size; ++i)
+ ds >> qmap_keycompose[i];
+
+ if (ds.status() != QDataStream::Ok) {
+ delete [] qmap_keymap;
+ delete [] qmap_keycompose;
+
+ qWarning("Keymap file '%s' can not be loaded.", qPrintable(file));
+ return false;
+ }
+
+ // unload currently active and clear state
+ unloadKeymap();
+
+ m_keymap = qmap_keymap;
+ m_keymap_size = qmap_keymap_size;
+ m_keycompose = qmap_keycompose;
+ m_keycompose_size = qmap_keycompose_size;
+
+ m_do_compose = true;
+
+ return true;
+}
+
+
/*!
\class QWSKeyboardHandler
\ingroup qws
@@ -132,18 +293,29 @@ private:
/*!
- Constructs a keyboard driver.
+ Constructs a keyboard driver. The \a device argument is passed by the
+ QWS_KEYBOARD environment variable.
Call the QWSServer::setKeyboardHandler() function to make the
newly created keyboard driver, the primary driver. Note that the
primary driver is controlled by the system, i.e., the system will
delete it upon exit.
*/
+QWSKeyboardHandler::QWSKeyboardHandler(const QString &device)
+{
+ d = new QWSKbPrivate(this, device);
+}
+
+/*!
+ \overload
+*/
QWSKeyboardHandler::QWSKeyboardHandler()
{
- d = new QWSKbPrivate(this);
+ d = new QWSKbPrivate(this, QString());
}
+
+
/*!
Destroys this keyboard driver.
@@ -172,7 +344,10 @@ QWSKeyboardHandler::~QWSKeyboardHandler()
event is caused by an auto-repeat mechanism and not an actual key
press.
- \sa beginAutoRepeat(), endAutoRepeat(), transformDirKey()
+ Note that this function does not handle key mapping. Please use
+ processKeycode() if you need that functionality.
+
+ \sa processKeycode(), beginAutoRepeat(), endAutoRepeat(), transformDirKey()
*/
void QWSKeyboardHandler::processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
bool isPress, bool autoRepeat)
@@ -241,6 +416,256 @@ void QWSKeyboardHandler::endAutoRepeat()
d->endAutoRepeat();
}
+/*!
+ \enum QWSKeyboardHandler::KeycodeAction
+
+ This enum describes the various special actions that actual
+ QWSKeyboardHandler implementations have to take care of.
+
+ \value None No further action required.
+
+ \value CapsLockOn Set the state of the Caps lock LED to on.
+ \value CapsLockOff Set the state of the Caps lock LED to off.
+ \value NumLockOn Set the state of the Num lock LED to on.
+ \value NumLockOff Set the state of the Num lock LED to off.
+ \value ScrollLockOn Set the state of the Scroll lock LED to on.
+ \value ScrollLockOff Set the state of the Scroll lock LED to off.
+
+ \value PreviousConsole Switch to the previous virtual console (by
+ default Ctrl+Alt+Left on Linux).
+ \value NextConsole Switch to the next virtual console (by default
+ Ctrl+Alt+Right on Linux).
+ \value SwitchConsoleFirst Switch to the first virtual console (0).
+ \value SwitchConsoleLast Switch to the last virtual console (255).
+ \value SwitchConsoleMask If the KeyAction value is between SwitchConsoleFirst
+ and SwitchConsoleLast, you can use this mask to get
+ the specific virtual console number to switch to.
+
+ \value Reboot Reboot the machine - this is ignored in both the TTY and
+ LinuxInput handlers though (by default Ctrl+Alt+Del on Linux).
+
+ \sa processKeycode()
+*/
+
+/*!
+ \fn QWSKeyboardHandler::KeycodeAction QWSKeyboardHandler::processKeycode(quint16 keycode, bool isPress, bool autoRepeat)
+
+ Maps \a keycode according to a keymap and sends that key event to the
+ \l{Qt for Embedded Linux} server application.
+
+ Please see the QWS_KEYBOARD documentation for a description on how to
+ create and use keymap files.
+
+ The key event is identified by its \a keycode value and the \a isPress
+ and \a autoRepeat parameters.
+
+ The \a keycode parameter is \bold NOT the Qt keycode value as defined by
+ the Qt::Key enum. This functions expects a standard Linux 16 bit kernel
+ keycode as it is used in the Linux Input Event sub-system. This
+ \a keycode is transformed to a Qt::Key code by using either a
+ compiled-in US keyboard layout or by dynamically loading a keymap at
+ startup which can be specified via the QWS_KEYBOARD environment
+ variable.
+
+ The \a isPress parameter is true if the event is a key press event and
+ \a autoRepeat is true if the event is caused by an auto-repeat mechanism
+ and not an actual key press.
+
+ The return value indicates if the actual QWSKeyboardHandler
+ implementation needs to take care of a special action, like console
+ switching or LED handling.
+
+ Standard Linux console keymaps can be found at the
+ \l {http://lct.sourceforege.net}{LCT project}
+
+ If standard Linux console keymaps are used, \a keycode must be one of the
+ standardized values defined in \c /usr/include/linux/input.h
+
+ \sa processKeyEvent(), KeycodeAction
+*/
+
+QWSKeyboardHandler::KeycodeAction QWSKeyboardHandler::processKeycode(quint16 keycode, bool pressed, bool autorepeat)
+{
+ KeycodeAction result = None;
+ bool first_press = pressed && !autorepeat;
+
+ const QWSKeyboard::Mapping *map_plain = 0;
+ const QWSKeyboard::Mapping *map_withmod = 0;
+
+ // get a specific and plain mapping for the keycode and the current modifiers
+ for (int i = 0; i < d->m_keymap_size && !(map_plain && map_withmod); ++i) {
+ const QWSKeyboard::Mapping *m = d->m_keymap + i;
+ if (m->keycode == keycode) {
+ if (m->modifiers == 0)
+ map_plain = m;
+
+ quint8 testmods = d->m_modifiers;
+ if (d->m_locks[0] /*CapsLock*/ && (m->flags & QWSKeyboard::IsLetter))
+ testmods ^= QWSKeyboard::ModShift;
+ if (m->modifiers == testmods)
+ map_withmod = m;
+ }
+ }
+
+#ifdef QT_DEBUG_KEYMAP
+ qWarning("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", \
+ keycode, d->m_modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, \
+ map_plain ? map_plain - d->m_keymap : -1, \
+ map_withmod ? map_withmod - d->m_keymap : -1, \
+ d->m_keymap_size);
+#endif
+
+ const QWSKeyboard::Mapping *it = map_withmod ? map_withmod : map_plain;
+
+ if (!it) {
+#ifdef QT_DEBUG_KEYMAP
+ // we couldn't even find a plain mapping
+ qWarning("Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, d->m_modifiers);
+#endif
+ return result;
+ }
+
+ bool skip = false;
+ quint16 unicode = it->unicode;
+ quint32 qtcode = it->qtcode;
+
+ if ((it->flags & QWSKeyboard::IsModifier) && it->special) {
+ // this is a modifier, i.e. Shift, Alt, ...
+ if (pressed)
+ d->m_modifiers |= quint8(it->special);
+ else
+ d->m_modifiers &= ~quint8(it->special);
+ } else if (qtcode >= Qt::Key_CapsLock && qtcode <= Qt::Key_ScrollLock) {
+ // (Caps|Num|Scroll)Lock
+ if (first_press) {
+ quint8 &lock = d->m_locks[qtcode - Qt::Key_CapsLock];
+ lock ^= 1;
+
+ switch (qtcode) {
+ case Qt::Key_CapsLock : result = lock ? CapsLockOn : CapsLockOff; break;
+ case Qt::Key_NumLock : result = lock ? NumLockOn : NumLockOff; break;
+ case Qt::Key_ScrollLock: result = lock ? ScrollLockOn : ScrollLockOff; break;
+ default : break;
+ }
+ }
+ } else if ((it->flags & QWSKeyboard::IsSystem) && it->special && first_press) {
+ switch (it->special) {
+ case QWSKeyboard::SystemReboot:
+ result = Reboot;
+ break;
+
+ case QWSKeyboard::SystemZap:
+ if (!d->m_no_zap)
+ qApp->quit();
+ break;
+
+ case QWSKeyboard::SystemConsolePrevious:
+ result = PreviousConsole;
+ break;
+
+ case QWSKeyboard::SystemConsoleNext:
+ result = NextConsole;
+ break;
+
+ default:
+ if (it->special >= QWSKeyboard::SystemConsoleFirst &&
+ it->special <= QWSKeyboard::SystemConsoleLast) {
+ result = KeycodeAction(SwitchConsoleFirst + ((it->special & QWSKeyboard::SystemConsoleMask) & SwitchConsoleMask));
+ }
+ break;
+ }
+
+ skip = true; // no need to tell QWS about it
+ } else if ((qtcode == Qt::Key_Multi_key) && d->m_do_compose) {
+ // the Compose key was pressed
+ if (first_press)
+ d->m_composing = 2;
+ skip = true;
+ } else if ((it->flags & QWSKeyboard::IsDead) && d->m_do_compose) {
+ // a Dead key was pressed
+ if (first_press && d->m_composing == 1 && d->m_dead_unicode == unicode) { // twice
+ d->m_composing = 0;
+ qtcode = Qt::Key_unknown; // otherwise it would be Qt::Key_Dead...
+ } else if (first_press && unicode != 0xffff) {
+ d->m_dead_unicode = unicode;
+ d->m_composing = 1;
+ skip = true;
+ } else {
+ skip = true;
+ }
+ }
+
+ if (!skip) {
+ // a normal key was pressed
+ const int modmask = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier;
+
+ // we couldn't find a specific mapping for the current modifiers,
+ // or that mapping didn't have special modifiers:
+ // so just report the plain mapping with additional modifiers.
+ if ((it == map_plain && it != map_withmod) ||
+ (map_withmod && !(map_withmod->qtcode & modmask))) {
+ qtcode |= QWSKbPrivate::toQtModifiers(d->m_modifiers);
+ }
+
+ if (d->m_composing == 2 && first_press && !(it->flags & QWSKeyboard::IsModifier)) {
+ // the last key press was the Compose key
+ if (unicode != 0xffff) {
+ int idx = 0;
+ // check if this code is in the compose table at all
+ for ( ; idx < d->m_keycompose_size; ++idx) {
+ if (d->m_keycompose[idx].first == unicode)
+ break;
+ }
+ if (idx < d->m_keycompose_size) {
+ // found it -> simulate a Dead key press
+ d->m_dead_unicode = unicode;
+ unicode = 0xffff;
+ d->m_composing = 1;
+ skip = true;
+ } else {
+ d->m_composing = 0;
+ }
+ } else {
+ d->m_composing = 0;
+ }
+ } else if (d->m_composing == 1 && first_press && !(it->flags & QWSKeyboard::IsModifier)) {
+ // the last key press was a Dead key
+ bool valid = false;
+ if (unicode != 0xffff) {
+ int idx = 0;
+ // check if this code is in the compose table at all
+ for ( ; idx < d->m_keycompose_size; ++idx) {
+ if (d->m_keycompose[idx].first == d->m_dead_unicode && d->m_keycompose[idx].second == unicode)
+ break;
+ }
+ if (idx < d->m_keycompose_size) {
+ quint16 composed = d->m_keycompose[idx].result;
+ if (composed != 0xffff) {
+ unicode = composed;
+ qtcode = Qt::Key_unknown;
+ valid = true;
+ }
+ }
+ }
+ if (!valid) {
+ unicode = d->m_dead_unicode;
+ qtcode = Qt::Key_unknown;
+ }
+ d->m_composing = 0;
+ }
+
+ if (!skip) {
+#ifdef QT_DEBUG_KEYMAP
+ qWarning("Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode & ~modmask, (qtcode & modmask));
+#endif
+
+ // send the result to the QWS server
+ processKeyEvent(unicode, qtcode & ~modmask, Qt::KeyboardModifiers(qtcode & modmask), pressed, autorepeat);
+ }
+ }
+ return result;
+}
+
QT_END_NAMESPACE
#include "qkbd_qws.moc"
diff --git a/src/gui/embedded/qkbd_qws.h b/src/gui/embedded/qkbd_qws.h
index 8809f0a..171adc0 100644
--- a/src/gui/embedded/qkbd_qws.h
+++ b/src/gui/embedded/qkbd_qws.h
@@ -58,11 +58,33 @@ class Q_GUI_EXPORT QWSKeyboardHandler
{
public:
QWSKeyboardHandler();
+ QWSKeyboardHandler(const QString &device);
virtual ~QWSKeyboardHandler();
virtual void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
bool isPress, bool autoRepeat);
+ enum KeycodeAction {
+ None = 0,
+
+ CapsLockOff = 0x01000000,
+ CapsLockOn = 0x01000001,
+ NumLockOff = 0x02000000,
+ NumLockOn = 0x02000001,
+ ScrollLockOff = 0x03000000,
+ ScrollLockOn = 0x03000001,
+
+ Reboot = 0x04000000,
+
+ PreviousConsole = 0x05000000,
+ NextConsole = 0x05000001,
+ SwitchConsoleFirst = 0x06000000,
+ SwitchConsoleLast = 0x0600007f,
+ SwitchConsoleMask = 0x0000007f,
+ };
+
+ KeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat);
+
protected:
int transformDirKey(int key);
void beginAutoRepeat(int uni, int code, Qt::KeyboardModifiers mod);
diff --git a/src/gui/painting/qpaintengine_d3d_p.h b/src/gui/embedded/qkbd_qws_p.h
index 8fa5cf6..3224da2 100644
--- a/src/gui/painting/qpaintengine_d3d_p.h
+++ b/src/gui/embedded/qkbd_qws_p.h
@@ -39,82 +39,91 @@
**
****************************************************************************/
-#ifndef QPAINTENGINE_D3D_P_H
-#define QPAINTENGINE_D3D_P_H
+#ifndef QWSKEYBOARD_P_H
+#define QWSKEYBOARD_P_H
//
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
-#include "QtGui/qpaintengine.h"
-#include <d3d9.h>
-
-QT_BEGIN_NAMESPACE
+#include <QDataStream>
+
+namespace QWSKeyboard {
+ const quint32 FileMagic = 0x514d4150; // 'QMAP'
+
+ struct Mapping {
+ quint16 keycode;
+ quint16 unicode;
+ quint32 qtcode;
+ quint8 modifiers;
+ quint8 flags;
+ quint16 special;
+
+ };
+
+ enum Flags {
+ IsDead = 0x01,
+ IsLetter = 0x02,
+ IsModifier = 0x04,
+ IsSystem = 0x08,
+ };
+
+ enum System {
+ SystemConsoleFirst = 0x0100,
+ SystemConsoleMask = 0x007f,
+ SystemConsoleLast = 0x017f,
+ SystemConsolePrevious = 0x0180,
+ SystemConsoleNext = 0x0181,
+ SystemReboot = 0x0200,
+ SystemZap = 0x0300,
+ };
+
+ struct Composing {
+ quint16 first;
+ quint16 second;
+ quint16 result;
+ };
+
+ enum Modifiers {
+ ModPlain = 0x00,
+ ModShift = 0x01,
+ ModAltGr = 0x02,
+ ModControl = 0x04,
+ ModAlt = 0x08,
+ ModShiftL = 0x10,
+ ModShiftR = 0x20,
+ ModCtrlL = 0x40,
+ ModCtrlR = 0x80,
+ // ModCapsShift = 0x100, // not supported!
+ };
+};
-class QDirect3DPaintEnginePrivate;
-class QDirect3DPaintEngine : public QPaintEngine
+inline QDataStream &operator>>(QDataStream &ds, QWSKeyboard::Mapping &m)
{
- Q_DECLARE_PRIVATE(QDirect3DPaintEngine)
-public:
- QDirect3DPaintEngine();
- ~QDirect3DPaintEngine();
- bool begin(QPaintDevice *device);
-
- void drawEllipse(const QRectF &rect);
- void drawEllipse(const QRect &rect);
-
- void drawImage(const QRectF &rectangle, const QImage &image, const QRectF &sr,
- Qt::ImageConversionFlags flags = Qt::AutoColor);
-
- void drawLines(const QLineF *lines, int lineCount);
- void drawLines(const QLine *lines, int lineCount);
-
- void drawPath(const QPainterPath &path);
-
- void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
-
- void drawPoints(const QPointF *points, int pointCount);
- void drawPoints(const QPoint *points, int pointCount);
-
- void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
- void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
-
- void drawRects(const QRectF *rects, int rectCount);
- void drawRects(const QRect * rects, int rectCount);
+ return ds >> m.keycode >> m.unicode >> m.qtcode >> m.modifiers >> m.flags >> m.special;
+}
- void drawTextItem(const QPointF &p, const QTextItem &textItem);
-
- void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &sr);
-
- bool end();
-
- Type type() const { return Direct3D; }
- void updateState(const QPaintEngineState &state);
-
- void cleanup();
-
- HDC getDC() const;
- void setFlushOnEnd(bool flushOnEnd);
- bool hasDirect3DSupport();
+inline QDataStream &operator<<(QDataStream &ds, const QWSKeyboard::Mapping &m)
+{
+ return ds << m.keycode << m.unicode << m.qtcode << m.modifiers << m.flags << m.special;
+}
-public:
- void scroll(QPaintDevice *pd, const RECT &srcrect, const RECT &destrect);
- LPDIRECT3DSWAPCHAIN9 swapChain(QPaintDevice *pd);
- void releaseSwapChain(QPaintDevice *pd);
+inline QDataStream &operator>>(QDataStream &ds, QWSKeyboard::Composing &c)
+{
+ return ds >> c.first >> c.second >> c.result;
+}
-private:
- Q_DISABLE_COPY(QDirect3DPaintEngine)
- friend class QPixmap;
- friend class QD3DGlyphCache;
-};
+inline QDataStream &operator<<(QDataStream &ds, const QWSKeyboard::Composing &c)
+{
+ return ds << c.first << c.second << c.result;
+}
-QT_END_NAMESPACE
-#endif
+#endif // QWSKEYBOARD_H
diff --git a/src/gui/embedded/qkbddriverfactory_qws.cpp b/src/gui/embedded/qkbddriverfactory_qws.cpp
index 1ade652..dbfac5c 100644
--- a/src/gui/embedded/qkbddriverfactory_qws.cpp
+++ b/src/gui/embedded/qkbddriverfactory_qws.cpp
@@ -45,7 +45,7 @@
#include "qapplication.h"
#include "qkbdtty_qws.h"
-#include "qkbdusb_qws.h"
+#include "qkbdlinuxinput_qws.h"
#include "qkbdum_qws.h"
#include "qkbdsl5000_qws.h"
#include "qkbdvfb_qws.h"
@@ -121,9 +121,11 @@ QWSKeyboardHandler *QKbdDriverFactory::create(const QString& key, const QString&
if (driver == QLatin1String("tty") || driver.isEmpty())
return new QWSTtyKeyboardHandler(device);
# endif
-# ifndef QT_NO_QWS_KBD_USB
- if (driver == QLatin1String("usb"))
- return new QWSUsbKeyboardHandler(device);
+# ifndef QT_NO_QWS_KBD_LINUXINPUT
+ if (driver == QLatin1String("linuxinput") || \
+ driver == QLatin1String("usb") || \
+ driver == QLatin1String("linuxis"))
+ return new QWSLinuxInputKeyboardHandler(device);
# endif
# ifndef QT_NO_QWS_KBD_UM
if (driver == QLatin1String("um") || driver == QLatin1String("qvfbkeyboard"))
@@ -168,8 +170,8 @@ QStringList QKbdDriverFactory::keys()
#ifndef QT_NO_QWS_KBD_TTY
list << QLatin1String("TTY");
#endif
-#ifndef QT_NO_QWS_KBD_USB
- list << QLatin1String("USB");
+#ifndef QT_NO_QWS_KBD_LINUXINPUT
+ list << QLatin1String("LinuxInput");
#endif
#ifndef QT_NO_QWS_KBD_UM
list << QLatin1String("UM");
diff --git a/src/gui/embedded/qkbdlinuxinput_qws.cpp b/src/gui/embedded/qkbdlinuxinput_qws.cpp
new file mode 100644
index 0000000..1ef2696
--- /dev/null
+++ b/src/gui/embedded/qkbdlinuxinput_qws.cpp
@@ -0,0 +1,241 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qkbdlinuxinput_qws.h"
+
+#ifndef QT_NO_QWS_KEYBOARD
+
+#include <QSocketNotifier>
+#include <QStringList>
+
+#include <qplatformdefs.h>
+
+#include <errno.h>
+#include <termios.h>
+
+#include <linux/kd.h>
+#include <linux/input.h>
+
+QT_BEGIN_NAMESPACE
+
+
+class QWSLinuxInputKbPrivate : public QObject
+{
+ Q_OBJECT
+public:
+ QWSLinuxInputKbPrivate(QWSLinuxInputKeyboardHandler *, const QString &);
+ ~QWSLinuxInputKbPrivate();
+
+private:
+ void switchLed(int, bool);
+
+private Q_SLOTS:
+ void readKeycode();
+
+private:
+ QWSLinuxInputKeyboardHandler *m_handler;
+ int m_fd;
+ int m_tty_fd;
+ struct termios m_tty_attr;
+};
+
+QWSLinuxInputKeyboardHandler::QWSLinuxInputKeyboardHandler(const QString &device)
+ : QWSKeyboardHandler(device)
+{
+ d = new QWSLinuxInputKbPrivate(this, device);
+}
+
+QWSLinuxInputKeyboardHandler::~QWSLinuxInputKeyboardHandler()
+{
+ delete d;
+}
+
+bool QWSLinuxInputKeyboardHandler::filterInputEvent(quint16 &, qint32 &)
+{
+ return false;
+}
+
+QWSLinuxInputKbPrivate::QWSLinuxInputKbPrivate(QWSLinuxInputKeyboardHandler *h, const QString &device)
+ : m_handler(h), m_fd(-1), m_tty_fd(-1)
+
+{
+ setObjectName(QLatin1String("LinuxInputSubsystem Keyboard Handler"));
+
+ QString dev = QLatin1String("/dev/input/event1");
+ int repeat_delay = -1;
+ int repeat_rate = -1;
+
+ QStringList args = device.split(QLatin1Char(':'));
+ foreach (const QString &arg, args) {
+ if (arg.startsWith(QLatin1String("repeat-delay=")))
+ repeat_delay = arg.mid(13).toInt();
+ else if (arg.startsWith(QLatin1String("repeat-rate=")))
+ repeat_rate = arg.mid(12).toInt();
+ else if (arg.startsWith(QLatin1String("/dev/")))
+ dev = arg;
+ }
+
+ m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDWR, 0);
+ if (m_fd >= 0) {
+ if (repeat_delay > 0 && repeat_rate > 0) {
+ int kbdrep[2] = { repeat_delay, repeat_rate };
+ ::ioctl(m_fd, EVIOCSREP, kbdrep);
+ }
+
+ QSocketNotifier *notifier;
+ notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
+ connect(notifier, SIGNAL(activated(int)), this, SLOT(readKeycode()));
+
+ // play nice in case we are started from a shell (e.g. for debugging)
+ m_tty_fd = isatty(0) ? 0 : -1;
+
+ if (m_tty_fd >= 0) {
+ // save tty config for restore.
+ tcgetattr(m_tty_fd, &m_tty_attr);
+
+ struct ::termios termdata;
+ tcgetattr(m_tty_fd, &termdata);
+
+ // setting this tranlation mode is also needed in INPUT mode to prevent
+ // the shell from also interpreting codes, if the process has a tty
+ // attached: e.g. Ctrl+C wouldn't copy, but kill the application.
+ ::ioctl(m_tty_fd, KDSKBMODE, K_MEDIUMRAW);
+
+ // set the tty layer to pass-through
+ termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ termdata.c_oflag = 0;
+ termdata.c_cflag = CREAD | CS8;
+ termdata.c_lflag = 0;
+ termdata.c_cc[VTIME]=0;
+ termdata.c_cc[VMIN]=1;
+ cfsetispeed(&termdata, 9600);
+ cfsetospeed(&termdata, 9600);
+ tcsetattr(m_tty_fd, TCSANOW, &termdata);
+ }
+ } else {
+ qWarning("Cannot open input device '%s': %s", qPrintable(dev), strerror(errno));
+ return;
+ }
+}
+
+QWSLinuxInputKbPrivate::~QWSLinuxInputKbPrivate()
+{
+ if (m_tty_fd >= 0) {
+ ::ioctl(m_tty_fd, KDSKBMODE, K_XLATE);
+ tcsetattr(m_tty_fd, TCSANOW, &m_tty_attr);
+ }
+ if (m_fd >= 0)
+ QT_CLOSE(m_fd);
+}
+
+void QWSLinuxInputKbPrivate::switchLed(int led, bool state)
+{
+ struct ::input_event led_ie;
+ ::gettimeofday(&led_ie.time, 0);
+ led_ie.type = EV_LED;
+ led_ie.code = led;
+ led_ie.value = state;
+
+ QT_WRITE(m_fd, &led_ie, sizeof(led_ie));
+}
+
+void QWSLinuxInputKbPrivate::readKeycode()
+{
+ struct ::input_event buffer[32];
+ int n = 0;
+
+ forever {
+ n = QT_READ(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n);
+
+ if (n == 0) {
+ qWarning("Got EOF from the input device.");
+ return;
+ } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) {
+ qWarning("Could not read from input device: %s", strerror(errno));
+ return;
+ } else if (n % sizeof(buffer[0]) == 0) {
+ break;
+ }
+ }
+
+ n /= sizeof(buffer[0]);
+
+ for (int i = 0; i < n; ++i) {
+ if (buffer[i].type != EV_KEY)
+ continue;
+
+ quint16 code = buffer[i].code;
+ qint32 value = buffer[i].value;
+
+ if (m_handler->filterInputEvent(code, value))
+ continue;
+
+ QWSKeyboardHandler::KeycodeAction ka;
+ ka = m_handler->processKeycode(code, value != 0, value == 2);
+
+ switch (ka) {
+ case QWSKeyboardHandler::CapsLockOn:
+ case QWSKeyboardHandler::CapsLockOff:
+ switchLed(LED_CAPSL, ka == QWSKeyboardHandler::CapsLockOn);
+ break;
+
+ case QWSKeyboardHandler::NumLockOn:
+ case QWSKeyboardHandler::NumLockOff:
+ switchLed(LED_NUML, ka == QWSKeyboardHandler::NumLockOn);
+ break;
+
+ case QWSKeyboardHandler::ScrollLockOn:
+ case QWSKeyboardHandler::ScrollLockOff:
+ switchLed(LED_SCROLLL, ka == QWSKeyboardHandler::ScrollLockOn);
+ break;
+
+ default:
+ // ignore console switching and reboot
+ break;
+ }
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "qkbdlinuxinput_qws.moc"
+
+#endif // QT_NO_QWS_KEYBOARD
diff --git a/src/gui/embedded/qkbdusb_qws.h b/src/gui/embedded/qkbdlinuxinput_qws.h
index 81d0103..5fa8214 100644
--- a/src/gui/embedded/qkbdusb_qws.h
+++ b/src/gui/embedded/qkbdlinuxinput_qws.h
@@ -39,10 +39,10 @@
**
****************************************************************************/
-#ifndef QKBDUSB_QWS_H
-#define QKBDUSB_QWS_H
+#ifndef QKBDLINUXINPUT_QWS_H
+#define QKBDLINUXINPUT_QWS_H
-#include <QtGui/qkbdpc101_qws.h>
+#include <QtGui/qkbd_qws.h>
QT_BEGIN_HEADER
@@ -52,21 +52,23 @@ QT_MODULE(Gui)
#ifndef QT_NO_QWS_KEYBOARD
-#ifndef QT_NO_QWS_KBD_USB
+#ifndef QT_NO_QWS_KBD_LINUXINPUT
-class QWSUsbKbPrivate;
+class QWSLinuxInputKbPrivate;
-class QWSUsbKeyboardHandler : public QWSPC101KeyboardHandler
+class QWSLinuxInputKeyboardHandler : public QWSKeyboardHandler
{
public:
- QWSUsbKeyboardHandler(const QString&);
- virtual ~QWSUsbKeyboardHandler();
+ QWSLinuxInputKeyboardHandler(const QString&);
+ virtual ~QWSLinuxInputKeyboardHandler();
+
+ virtual bool filterInputEvent(quint16 &input_code, qint32 &input_value);
private:
- QWSUsbKbPrivate *d;
+ QWSLinuxInputKbPrivate *d;
};
-#endif // QT_NO_QWS_KBD_USB
+#endif // QT_NO_QWS_KBD_LINUXINPUT
#endif // QT_NO_QWS_KEYBOARD
@@ -74,4 +76,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QKBDUSB_QWS_H
+#endif // QKBDLINUXINPUT_QWS_H
diff --git a/src/gui/embedded/qkbdpc101_qws.cpp b/src/gui/embedded/qkbdpc101_qws.cpp
deleted file mode 100644
index 3173645..0000000
--- a/src/gui/embedded/qkbdpc101_qws.cpp
+++ /dev/null
@@ -1,485 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qkbdpc101_qws.h"
-
-#ifndef QT_NO_QWS_KEYBOARD
-
-#include "qscreen_qws.h"
-#include "qwindowsystem_qws.h"
-#include "qnamespace.h"
-#include "qapplication.h"
-
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#ifdef Q_OS_LINUX
-#include <sys/kd.h>
-#include <sys/vt.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-static const QWSKeyMap pc101KeyM[] = {
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Escape, 27 , 27 , 0xffff },
- { Qt::Key_1, '1' , '!' , 0xffff },
- { Qt::Key_2, '2' , '@' , 0xffff },
- { Qt::Key_3, '3' , '#' , 0xffff },
- { Qt::Key_4, '4' , '$' , 0xffff },
- { Qt::Key_5, '5' , '%' , 0xffff },
- { Qt::Key_6, '6' , '^' , 0xffff },
- { Qt::Key_7, '7' , '&' , 0xffff },
- { Qt::Key_8, '8' , '*' , 0xffff },
- { Qt::Key_9, '9' , '(' , 0xffff }, // 10
- { Qt::Key_0, '0' , ')' , 0xffff },
- { Qt::Key_Minus, '-' , '_' , 0xffff },
- { Qt::Key_Equal, '=' , '+' , 0xffff },
- { Qt::Key_Backspace, 8 , 8 , 0xffff },
- { Qt::Key_Tab, 9 , 9 , 0xffff },
- { Qt::Key_Q, 'q' , 'Q' , 'Q'-64 },
- { Qt::Key_W, 'w' , 'W' , 'W'-64 },
- { Qt::Key_E, 'e' , 'E' , 'E'-64 },
- { Qt::Key_R, 'r' , 'R' , 'R'-64 },
- { Qt::Key_T, 't' , 'T' , 'T'-64 }, // 20
- { Qt::Key_Y, 'y' , 'Y' , 'Y'-64 },
- { Qt::Key_U, 'u' , 'U' , 'U'-64 },
- { Qt::Key_I, 'i' , 'I' , 'I'-64 },
- { Qt::Key_O, 'o' , 'O' , 'O'-64 },
- { Qt::Key_P, 'p' , 'P' , 'P'-64 },
- { Qt::Key_BraceLeft, '[' , '{' , 0xffff },
- { Qt::Key_BraceRight, ']' , '}' , 0xffff },
- { Qt::Key_Return, 13 , 13 , 0xffff },
- { Qt::Key_Control, 0xffff , 0xffff , 0xffff },
- { Qt::Key_A, 'a' , 'A' , 'A'-64 }, // 30
- { Qt::Key_S, 's' , 'S' , 'S'-64 },
- { Qt::Key_D, 'd' , 'D' , 'D'-64 },
- { Qt::Key_F, 'f' , 'F' , 'F'-64 },
- { Qt::Key_G, 'g' , 'G' , 'G'-64 },
- { Qt::Key_H, 'h' , 'H' , 'H'-64 },
- { Qt::Key_J, 'j' , 'J' , 'J'-64 },
- { Qt::Key_K, 'k' , 'K' , 'K'-64 },
- { Qt::Key_L, 'l' , 'L' , 'L'-64 },
- { Qt::Key_Semicolon, ';' , ':' , 0xffff },
- { Qt::Key_Apostrophe, '\'' , '"' , 0xffff }, // 40
- { Qt::Key_QuoteLeft, '`' , '~' , 0xffff },
- { Qt::Key_Shift, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Backslash, '\\' , '|' , 0xffff },
- { Qt::Key_Z, 'z' , 'Z' , 'Z'-64 },
- { Qt::Key_X, 'x' , 'X' , 'X'-64 },
- { Qt::Key_C, 'c' , 'C' , 'C'-64 },
- { Qt::Key_V, 'v' , 'V' , 'V'-64 },
- { Qt::Key_B, 'b' , 'B' , 'B'-64 },
- { Qt::Key_N, 'n' , 'N' , 'N'-64 },
- { Qt::Key_M, 'm' , 'M' , 'M'-64 }, // 50
- { Qt::Key_Comma, ',' , '<' , 0xffff },
- { Qt::Key_Period, '.' , '>' , 0xffff },
- { Qt::Key_Slash, '/' , '?' , 0xffff },
- { Qt::Key_Shift, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Asterisk, '*' , '*' , 0xffff },
- { Qt::Key_Alt, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Space, ' ' , ' ' , 0xffff },
- { Qt::Key_CapsLock, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F1, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F2, 0xffff , 0xffff , 0xffff }, // 60
- { Qt::Key_F3, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F4, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F5, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F6, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F7, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F8, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F9, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F10, 0xffff , 0xffff , 0xffff },
- { Qt::Key_NumLock, 0xffff , 0xffff , 0xffff },
- { Qt::Key_ScrollLock, 0xffff , 0xffff , 0xffff }, // 70
- { Qt::Key_7, '7' , '7' , 0xffff },
- { Qt::Key_8, '8' , '8' , 0xffff },
- { Qt::Key_9, '9' , '9' , 0xffff },
- { Qt::Key_Minus, '-' , '-' , 0xffff },
- { Qt::Key_4, '4' , '4' , 0xffff },
- { Qt::Key_5, '5' , '5' , 0xffff },
- { Qt::Key_6, '6' , '6' , 0xffff },
- { Qt::Key_Plus, '+' , '+' , 0xffff },
- { Qt::Key_1, '1' , '1' , 0xffff },
- { Qt::Key_2, '2' , '2' , 0xffff }, // 80
- { Qt::Key_3, '3' , '3' , 0xffff },
- { Qt::Key_0, '0' , '0' , 0xffff },
- { Qt::Key_Period, '.' , '.' , 0xffff },
- { Qt::Key_SysReq, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Less, '<' , '>' , 0xffff },
- { Qt::Key_F11, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F12, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff }, // 90
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Enter, 13 , 13 , 0xffff },
- { Qt::Key_Control, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Slash, '/' , '/' , 0xffff },
- { Qt::Key_SysReq, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Meta, 0xffff , 0xffff , 0xffff }, // 100
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff }, // break
- { Qt::Key_Home, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Up, 0xffff , 0xffff , 0xffff },
- { Qt::Key_PageUp, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Left, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Right, 0xffff , 0xffff , 0xffff },
- { Qt::Key_End, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Down, 0xffff , 0xffff , 0xffff },
- { Qt::Key_PageDown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Insert, 0xffff , 0xffff , 0xffff }, // 110
- { Qt::Key_Delete, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff }, // macro
- { Qt::Key_F13, 0xffff , 0xffff , 0xffff },
- { Qt::Key_F14, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Help, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff }, // do
- { Qt::Key_F17, 0xffff , 0xffff , 0xffff },
- { Qt::Key_Plus, '+' , '-' , 0xffff },
- { Qt::Key_Pause, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { Qt::Key_unknown, 0xffff , 0xffff , 0xffff },
- { 0, 0xffff , 0xffff , 0xffff }
-};
-
-static const int keyMSize = sizeof(pc101KeyM)/sizeof(QWSKeyMap)-1;
-
-//===========================================================================
-
-//
-// PC-101 type keyboards
-//
-
-/*!
- \class QWSPC101KeyboardHandler
- \ingroup qws
-
- \internal
-*/
-
-QWSPC101KeyboardHandler::QWSPC101KeyboardHandler(const QString&)
-{
- shift = false;
- alt = false;
- ctrl = false;
- extended = 0;
- prevuni = 0;
- prevkey = 0;
- caps = false;
-#if defined(QT_QWS_IPAQ)
- // iPAQ Action Key has ScanCode 0x60: 0x60|0x80 = 0xe0 == extended mode 1 !
- ipaq_return_pressed = false;
-#endif
-}
-
-QWSPC101KeyboardHandler::~QWSPC101KeyboardHandler()
-{
-}
-
-const QWSKeyMap *QWSPC101KeyboardHandler::keyMap() const
-{
- return pc101KeyM;
-}
-
-void QWSPC101KeyboardHandler::doKey(uchar code)
-{
-
- int keyCode = Qt::Key_unknown;
- bool release = false;
- int keypad = 0;
- bool softwareRepeat = false;
-
-#ifndef QT_QWS_USE_KEYCODES
- // extended?
- if (code == 224
-#if defined(QT_QWS_IPAQ)
- && !ipaq_return_pressed
-#endif
- ) {
- extended = 1;
- return;
- } else if (code == 225) {
- extended = 2;
- return;
- }
-#endif
-
- if (code & 0x80) {
- release = true;
- code &= 0x7f;
- }
-
-#ifndef QT_QWS_USE_KEYCODES
- if (extended == 1) {
- switch (code) {
- case 72:
- keyCode = Qt::Key_Up;
- break;
- case 75:
- keyCode = Qt::Key_Left;
- break;
- case 77:
- keyCode = Qt::Key_Right;
- break;
- case 80:
- keyCode = Qt::Key_Down;
- break;
- case 82:
- keyCode = Qt::Key_Insert;
- break;
- case 71:
- keyCode = Qt::Key_Home;
- break;
- case 73:
- keyCode = Qt::Key_PageUp;
- break;
- case 83:
- keyCode = Qt::Key_Delete;
- break;
- case 79:
- keyCode = Qt::Key_End;
- break;
- case 81:
- keyCode = Qt::Key_PageDown;
- break;
- case 28:
- keyCode = Qt::Key_Enter;
- break;
- case 53:
- keyCode = Qt::Key_Slash;
- break;
- case 0x1d:
- keyCode = Qt::Key_Control;
- break;
- case 0x2a:
- keyCode = Qt::Key_Print;
- break;
- case 0x38:
- keyCode = Qt::Key_Alt;
- break;
- case 0x5b:
- keyCode = Qt::Key_Super_L;
- break;
- case 0x5c:
- keyCode = Qt::Key_Super_R;
- break;
- case 0x5d:
- keyCode = Qt::Key_Menu;
- break;
-#if 0
- default:
- qDebug("extended1 code %x release %d", code, release);
- break;
-#endif
- }
- } else if (extended == 2) {
- switch (code) {
- case 0x1d:
- return;
- case 0x45:
- keyCode = Qt::Key_Pause;
- break;
- }
- } else
-#endif
- {
- if (code < keyMSize) {
- keyCode = pc101KeyM[code].key_code;
- }
-
-#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
- softwareRepeat = true;
-
- switch (code) {
- case 0x7a: case 0x7b: case 0x7c: case 0x7d:
- keyCode = code - 0x7a + Qt::Key_F9;
- softwareRepeat = false;
- break;
- case 0x79:
- keyCode = Qt::Key_SysReq;
- softwareRepeat = false;
- break;
- case 0x78:
-# ifdef QT_QWS_IPAQ
- keyCode = Qt::Key_F24; // record
-# else
- keyCode = Qt::Key_Escape;
-# endif
- softwareRepeat = false;
- break;
- case 0x60:
- keyCode = Qt::Key_Return;
-# ifdef QT_QWS_IPAQ
- ipaq_return_pressed = !release;
-# endif
- break;
- case 0x67:
- keyCode = Qt::Key_Right;
- break;
- case 0x69:
- keyCode = Qt::Key_Up;
- break;
- case 0x6a:
- keyCode = Qt::Key_Down;
- break;
- case 0x6c:
- keyCode = Qt::Key_Left;
- break;
- }
-
- if (qt_screen->isTransformed()
- && keyCode >= Qt::Key_Left && keyCode <= Qt::Key_Down)
- {
- keyCode = transformDirKey(keyCode);
- }
-#endif
- /*
- Translate shift+Qt::Key_Tab to Qt::Key_Backtab
- */
- if ((keyCode == Qt::Key_Tab) && shift)
- keyCode = Qt::Key_Backtab;
- }
-
-#ifndef QT_QWS_USE_KEYCODES
- /*
- Qt::Keypad consists of extended keys 53 and 28,
- and non-extended keys 55 and 71 through 83.
- */
- if ((extended == 1) ? (code == 53 || code == 28) :
- (code == 55 || (code >= 71 && code <= 83)))
-#else
- if (code == 55 || code >= 71 && code <= 83 || code == 96
- || code == 98 || code == 118)
-#endif
- {
- keypad = Qt::KeypadModifier;
- }
-
- // Ctrl-Alt-Backspace exits qws
- if (ctrl && alt && keyCode == Qt::Key_Backspace) {
- qApp->quit();
- }
-
- if (keyCode == Qt::Key_Alt) {
- alt = !release;
- } else if (keyCode == Qt::Key_Control) {
- ctrl = !release;
- } else if (keyCode == Qt::Key_Shift) {
- shift = !release;
- } else if (keyCode == Qt::Key_CapsLock && release) {
- caps = !caps;
-#if defined(Q_OS_LINUX)
- char leds;
- ioctl(0, KDGETLED, &leds);
- leds = leds & ~LED_CAP;
- if (caps) leds |= LED_CAP;
- ioctl(0, KDSETLED, leds);
-#endif
- }
- if (keyCode != Qt::Key_unknown) {
- bool bAlt = alt;
- bool bCtrl = ctrl;
- bool bShift = shift;
- int unicode = 0;
- if (code < keyMSize) {
- if (!extended) {
- bool bCaps = shift ||
- (caps ? QChar(keyMap()[code].unicode).isLetter() : false);
- if (bCtrl)
- unicode = keyMap()[code].ctrl_unicode ? keyMap()[code].ctrl_unicode : 0xffff;
- else if (bCaps)
- unicode = keyMap()[code].shift_unicode ? keyMap()[code].shift_unicode : 0xffff;
- else
- unicode = keyMap()[code].unicode ? keyMap()[code].unicode : 0xffff;
-#ifndef QT_QWS_USE_KEYCODES
- } else if (extended==1) {
- if (code == 53)
- unicode = '/';
-#endif
- }
- }
-
- modifiers = 0;
- if (bAlt) modifiers |= Qt::AltModifier;
- if (bCtrl) modifiers |= Qt::ControlModifier;
- if (bShift) modifiers |= Qt::ShiftModifier;
- if (keypad) modifiers |= Qt::KeypadModifier;
-
- // looks wrong -- WWA
- bool repeat = false;
- if (prevuni == unicode && prevkey == keyCode && !release)
- repeat = true;
-
- processKeyEvent(unicode, keyCode, modifiers, !release, repeat);
-
- if (!release) {
- prevuni = unicode;
- prevkey = keyCode;
- } else {
- prevkey = prevuni = 0;
- }
- }
-
- if (softwareRepeat && !release)
- beginAutoRepeat(prevuni, prevkey, modifiers);
- else
- endAutoRepeat();
-
- extended = 0;
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_QWS_KEYBOARD
diff --git a/src/gui/embedded/qkbdsl5000_qws.cpp b/src/gui/embedded/qkbdsl5000_qws.cpp
index bc412b6..1e8095e 100644
--- a/src/gui/embedded/qkbdsl5000_qws.cpp
+++ b/src/gui/embedded/qkbdsl5000_qws.cpp
@@ -195,6 +195,13 @@ static const int keyMSize = sizeof(sl5000KeyMap)/sizeof(QWSKeyMap)-1;
QWSSL5000KeyboardHandler::QWSSL5000KeyboardHandler(const QString &device)
: QWSTtyKeyboardHandler(device)
{
+ shift = false;
+ alt = false;
+ ctrl = false;
+ extended = 0;
+ prevuni = 0;
+ prevkey = 0;
+ caps = false;
meta = false;
fn = false;
numLock = false;
@@ -220,7 +227,7 @@ const QWSKeyMap *QWSSL5000KeyboardHandler::keyMap() const
return sl5000KeyMap;
}
-void QWSSL5000KeyboardHandler::doKey(uchar code)
+bool QWSSL5000KeyboardHandler::filterKeycode(char &code)
{
int keyCode = Qt::Key_unknown;
bool release = false;
@@ -239,19 +246,19 @@ void QWSSL5000KeyboardHandler::doKey(uchar code)
else if (code == 0x52) { unicode='Z'-'@'; scan=Qt::Key_Z; } // Undo
if (scan) {
processKeyEvent(unicode, scan, Qt::ControlModifier, !release, false);
- return;
+ return true;
}
}
if (code < keyMSize) {
- keyCode = keyMap()[code].key_code;
+ keyCode = keyMap()[int(code)].key_code;
}
bool repeatable = true;
if (release && (keyCode == Qt::Key_F34 || keyCode == Qt::Key_F35))
- return; // no release for power and light keys
- if (keyCode >= Qt::Key_F1 && keyCode <= Qt::Key_F35
+ return true; // no release for power and light keys
+ if ((keyCode >= Qt::Key_F1 && keyCode <= Qt::Key_F35)
|| keyCode == Qt::Key_Escape || keyCode == Qt::Key_Home
|| keyCode == Qt::Key_Shift || keyCode == Qt::Key_Meta)
repeatable = false;
@@ -318,11 +325,11 @@ void QWSSL5000KeyboardHandler::doKey(uchar code)
keyCode = Qt::Key_QuoteLeft;
unicode = '`';
} else if (bCtrl)
- unicode = keyMap()[code].ctrl_unicode ? keyMap()[code].ctrl_unicode : 0xffff;
+ unicode = keyMap()[int(code)].ctrl_unicode ? keyMap()[int(code)].ctrl_unicode : 0xffff;
else if (bCaps)
- unicode = keyMap()[code].shift_unicode ? keyMap()[code].shift_unicode : 0xffff;
+ unicode = keyMap()[int(code)].shift_unicode ? keyMap()[int(code)].shift_unicode : 0xffff;
else
- unicode = keyMap()[code].unicode ? keyMap()[code].unicode : 0xffff;
+ unicode = keyMap()[int(code)].unicode ? keyMap()[int(code)].unicode : 0xffff;
}
modifiers = 0;
@@ -349,6 +356,8 @@ void QWSSL5000KeyboardHandler::doKey(uchar code)
beginAutoRepeat(prevuni, prevkey, modifiers);
else
endAutoRepeat();
+
+ return true;
}
QT_END_NAMESPACE
diff --git a/src/gui/embedded/qkbdsl5000_qws.h b/src/gui/embedded/qkbdsl5000_qws.h
index 514d602..a96e038 100644
--- a/src/gui/embedded/qkbdsl5000_qws.h
+++ b/src/gui/embedded/qkbdsl5000_qws.h
@@ -52,7 +52,13 @@ QT_MODULE(Gui)
#ifndef QT_NO_QWS_KBD_SL5000
-class QWSSL5000KbPrivate;
+struct QWSKeyMap {
+ uint key_code;
+ ushort unicode;
+ ushort shift_unicode;
+ ushort ctrl_unicode;
+};
+
class QWSSL5000KeyboardHandler : public QWSTtyKeyboardHandler
{
@@ -60,14 +66,21 @@ public:
explicit QWSSL5000KeyboardHandler(const QString&);
virtual ~QWSSL5000KeyboardHandler();
- virtual void doKey(uchar scancode);
+ bool filterKeycode(char &keycode);
virtual const QWSKeyMap *keyMap() const;
private:
+ bool shift;
+ bool alt;
+ bool ctrl;
+ bool caps;
+ uint extended:2;
+ Qt::KeyboardModifiers modifiers;
+ int prevuni;
+ int prevkey;
bool meta;
bool fn;
bool numLock;
- QWSSL5000KbPrivate *d;
};
#endif // QT_NO_QWS_KBD_SL5000
diff --git a/src/gui/embedded/qkbdtty_qws.cpp b/src/gui/embedded/qkbdtty_qws.cpp
index b588e55..5c0dec8 100644
--- a/src/gui/embedded/qkbdtty_qws.cpp
+++ b/src/gui/embedded/qkbdtty_qws.cpp
@@ -43,64 +43,57 @@
#if !defined(QT_NO_QWS_KEYBOARD) && !defined(QT_NO_QWS_KBD_TTY)
-#include "qscreen_qws.h"
-
-#include "qwindowsystem_qws.h"
-#include "qapplication.h"
-#include "qsocketnotifier.h"
-#include "qnamespace.h"
-#include "qtimer.h"
-#include <private/qwssignalhandler_p.h>
-#include <private/qwindowsurface_qws_p.h>
-
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <signal.h>
-#include <termios.h>
+#include <QSocketNotifier>
+#include <QStringList>
-#include <qeventloop.h>
+#include <qplatformdefs.h>
-#ifdef Q_OS_LINUX
-#include <sys/kd.h>
-#include <sys/vt.h>
-#endif
+#include <errno.h>
+#include <termios.h>
-QT_BEGIN_NAMESPACE
+#if defined Q_OS_LINUX
+# include <linux/kd.h>
+# include <linux/vt.h> //TODO: move vt handling somewhere else (QLinuxFbScreen?)
-#define VTACQSIG SIGUSR1
-#define VTRELSIG SIGUSR2
+# include "qscreen_qws.h"
+# include "qwindowsystem_qws.h"
+# include "qapplication.h"
+# include "private/qwindowsurface_qws_p.h"
+# include "private/qwssignalhandler_p.h"
-static int vtQws = 0;
-static int kbdFD = -1;
+# define VTACQSIG SIGUSR1
+# define VTRELSIG SIGUSR2
+#endif
-//===========================================================================
-//
-// Tty keyboard
-//
+QT_BEGIN_NAMESPACE
class QWSTtyKbPrivate : public QObject
{
Q_OBJECT
public:
- QWSTtyKbPrivate(QWSPC101KeyboardHandler *, const QString &device);
+ QWSTtyKbPrivate(QWSTtyKeyboardHandler *handler, const QString &device);
~QWSTtyKbPrivate();
-private slots:
- void readKeyboardData();
- void handleTtySwitch(int);
+private:
+ void switchLed(char, bool);
+ void switchConsole(int vt);
+
+private Q_SLOTS:
+ void readKeycode();
+ void handleConsoleSwitch(int sig);
private:
- QWSPC101KeyboardHandler *handler;
- struct termios origTermData;
+ QWSTtyKeyboardHandler *m_handler;
+ int m_tty_fd;
+ struct termios m_tty_attr;
+ char m_last_keycode;
+ int m_vt_qws;
};
+
QWSTtyKeyboardHandler::QWSTtyKeyboardHandler(const QString &device)
- : QWSPC101KeyboardHandler(device)
+ : QWSKeyboardHandler(device)
{
d = new QWSTtyKbPrivate(this, device);
}
@@ -110,59 +103,63 @@ QWSTtyKeyboardHandler::~QWSTtyKeyboardHandler()
delete d;
}
-void QWSTtyKeyboardHandler::processKeyEvent(int unicode, int keycode,
- Qt::KeyboardModifiers modifiers, bool isPress,
- bool autoRepeat)
+bool QWSTtyKeyboardHandler::filterKeycode(char &)
{
-#if defined(Q_OS_LINUX)
- // Virtual console switching
- int term = 0;
- bool ctrl = modifiers & Qt::ControlModifier;
- bool alt = modifiers & Qt::AltModifier;
- if (ctrl && alt && keycode >= Qt::Key_F1 && keycode <= Qt::Key_F10)
- term = keycode - Qt::Key_F1 + 1;
- else if (ctrl && alt && keycode == Qt::Key_Left)
- term = qMax(vtQws - 1, 1);
- else if (ctrl && alt && keycode == Qt::Key_Right)
- term = qMin(vtQws + 1, 10);
- if (term && isPress) {
- ioctl(kbdFD, VT_ACTIVATE, term);
- return;
- }
-#endif
-
- QWSPC101KeyboardHandler::processKeyEvent(unicode, keycode, modifiers,
- isPress, autoRepeat);
+ return false;
}
-
-QWSTtyKbPrivate::QWSTtyKbPrivate(QWSPC101KeyboardHandler *h, const QString &device) : handler(h)
+QWSTtyKbPrivate::QWSTtyKbPrivate(QWSTtyKeyboardHandler *h, const QString &device)
+ : m_handler(h), m_tty_fd(-1), m_last_keycode(0), m_vt_qws(0)
{
- kbdFD = ::open(device.isEmpty()?"/dev/tty0":device.toLatin1().constData(), O_RDWR|O_NDELAY, 0);
+ setObjectName(QLatin1String("TTY Keyboard Handler"));
#ifndef QT_NO_QWS_SIGNALHANDLER
QWSSignalHandler::instance()->addObject(this);
#endif
- if (kbdFD >= 0) {
+ QString dev = QLatin1String("/dev/tty0");
+ int repeat_delay = -1;
+ int repeat_rate = -1;
+
+ QStringList args = device.split(QLatin1Char(':'));
+ foreach (const QString &arg, args) {
+ if (arg.startsWith(QLatin1String("repeat-delay=")))
+ repeat_delay = arg.mid(13).toInt();
+ else if (arg.startsWith(QLatin1String("repeat-rate=")))
+ repeat_rate = arg.mid(12).toInt();
+ else if (arg.startsWith(QLatin1String("/dev/")))
+ dev = arg;
+ }
+
+ m_tty_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDWR, 0);
+ if (m_tty_fd >= 0) {
+ if (repeat_delay > 0 && repeat_rate > 0) {
+#if defined(Q_OS_LINUX)
+ struct ::kbd_repeat kbdrep = { repeat_delay, repeat_rate };
+ ::ioctl(m_tty_fd, KDKBDREP, &kbdrep);
+#endif
+ }
+
QSocketNotifier *notifier;
- notifier = new QSocketNotifier(kbdFD, QSocketNotifier::Read, this);
- connect(notifier, SIGNAL(activated(int)),this,
- SLOT(readKeyboardData()));
+ notifier = new QSocketNotifier(m_tty_fd, QSocketNotifier::Read, this);
+ connect(notifier, SIGNAL(activated(int)), this, SLOT(readKeycode()));
- // save for restore.
- tcgetattr(kbdFD, &origTermData);
+ // save tty config for restore.
+ tcgetattr(m_tty_fd, &m_tty_attr);
- struct termios termdata;
- tcgetattr(kbdFD, &termdata);
+ struct ::termios termdata;
+ tcgetattr(m_tty_fd, &termdata);
#if defined(Q_OS_LINUX)
-# ifdef QT_QWS_USE_KEYCODES
- ioctl(kbdFD, KDSKBMODE, K_MEDIUMRAW);
-# else
- ioctl(kbdFD, KDSKBMODE, K_RAW);
-# endif
+ // PLEASE NOTE:
+ // The tty keycode interface can only report keycodes 0x01 .. 0x7f
+ // KEY_MAX is however defined to 0x1ff. In practice this is sufficient
+ // for a PC style keyboard though.
+ // we don't support K_RAW anymore - if you need, you habe to add a
+ // scan- to keycode converter.
+ ::ioctl(m_tty_fd, KDSKBMODE, K_MEDIUMRAW);
#endif
+ // set the tty layer to pass-through
termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
termdata.c_oflag = 0;
termdata.c_cflag = CREAD | CS8;
@@ -171,50 +168,145 @@ QWSTtyKbPrivate::QWSTtyKbPrivate(QWSPC101KeyboardHandler *h, const QString &devi
termdata.c_cc[VMIN]=1;
cfsetispeed(&termdata, 9600);
cfsetospeed(&termdata, 9600);
- tcsetattr(kbdFD, TCSANOW, &termdata);
+ tcsetattr(m_tty_fd, TCSANOW, &termdata);
#if defined(Q_OS_LINUX)
-
- connect(QApplication::instance(), SIGNAL(unixSignal(int)), this, SLOT(handleTtySwitch(int)));
+ // VT switching is handled via unix signals
+ connect(QApplication::instance(), SIGNAL(unixSignal(int)), this, SLOT(handleConsoleSwitch(int)));
QApplication::instance()->watchUnixSignal(VTACQSIG, true);
QApplication::instance()->watchUnixSignal(VTRELSIG, true);
- struct vt_mode vtMode;
- ioctl(kbdFD, VT_GETMODE, &vtMode);
+ struct ::vt_mode vtMode;
+ if (::ioctl(m_tty_fd, VT_GETMODE, &vtMode) == 0) {
+ vtMode.mode = VT_PROCESS;
+ vtMode.relsig = VTRELSIG;
+ vtMode.acqsig = VTACQSIG;
- // let us control VT switching
- vtMode.mode = VT_PROCESS;
- vtMode.relsig = VTRELSIG;
- vtMode.acqsig = VTACQSIG;
- ioctl(kbdFD, VT_SETMODE, &vtMode);
+ if (::ioctl(m_tty_fd, VT_SETMODE, &vtMode) == 0) {
+ struct ::vt_stat vtStat;
+ ::memset(&vtStat, 0, sizeof(vtStat));
- struct vt_stat vtStat;
- ioctl(kbdFD, VT_GETSTATE, &vtStat);
- vtQws = vtStat.v_active;
+ if (::ioctl(m_tty_fd, VT_GETSTATE, &vtStat) == 0 ) {
+ m_vt_qws = vtStat.v_active;
+ }
+ }
+ }
+
+ if (!m_vt_qws)
+ qWarning("Could not initialize virtual console switching");
#endif
} else {
- qCritical("Cannot open keyboard: %s", strerror(errno));
+ qWarning("Cannot open input device '%s': %s", qPrintable(dev), strerror(errno));
+ return;
}
}
QWSTtyKbPrivate::~QWSTtyKbPrivate()
{
- if (kbdFD >= 0) {
+ if (m_tty_fd >= 0) {
#if defined(Q_OS_LINUX)
- ioctl(kbdFD, KDSKBMODE, K_XLATE);
+ ::ioctl(m_tty_fd, KDSKBMODE, K_XLATE);
#endif
- tcsetattr(kbdFD, TCSANOW, &origTermData);
- ::close(kbdFD);
- kbdFD = -1;
+ tcsetattr(m_tty_fd, TCSANOW, &m_tty_attr);
}
}
-void QWSTtyKbPrivate::handleTtySwitch(int sig)
+
+
+void QWSTtyKbPrivate::switchLed(char led, bool state)
{
#if defined(Q_OS_LINUX)
+ char ledstate;
+
+ ::ioctl(m_tty_fd, KDGETLED, &ledstate);
+ if (state)
+ ledstate |= led;
+ else
+ ledstate &= ~led;
+ ::ioctl(m_tty_fd, KDSETLED, ledstate);
+#endif
+}
+
+void QWSTtyKbPrivate::readKeycode()
+{
+ char buffer[32];
+ int n = 0;
+
+ forever {
+ n = QT_READ(m_tty_fd, buffer + n, 32 - n);
+
+ if (n == 0) {
+ qWarning("Got EOF from the input device.");
+ return;
+ } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) {
+ qWarning("Could not read from input device: %s", strerror(errno));
+ return;
+ } else {
+ break;
+ }
+ }
+
+ for (int i = 0; i < n; ++i) {
+ if (m_handler->filterKeycode(buffer[i]))
+ continue;
+
+ QWSKeyboardHandler::KeycodeAction ka;
+ ka = m_handler->processKeycode(buffer[i] & 0x7f, (buffer[i] & 0x80) == 0x00, buffer[i] == m_last_keycode);
+ m_last_keycode = buffer[i];
+
+ switch (ka) {
+ case QWSKeyboardHandler::CapsLockOn:
+ case QWSKeyboardHandler::CapsLockOff:
+ switchLed(LED_CAP, ka == QWSKeyboardHandler::CapsLockOn);
+ break;
+
+ case QWSKeyboardHandler::NumLockOn:
+ case QWSKeyboardHandler::NumLockOff:
+ switchLed(LED_NUM, ka == QWSKeyboardHandler::NumLockOn);
+ break;
+
+ case QWSKeyboardHandler::ScrollLockOn:
+ case QWSKeyboardHandler::ScrollLockOff:
+ switchLed(LED_SCR, ka == QWSKeyboardHandler::ScrollLockOn);
+ break;
+
+ case QWSKeyboardHandler::PreviousConsole:
+ switchConsole(qBound(1, m_vt_qws - 1, 10));
+ break;
+
+ case QWSKeyboardHandler::NextConsole:
+ switchConsole(qBound(1, m_vt_qws + 1, 10));
+ break;
+
+ default:
+ if (ka >= QWSKeyboardHandler::SwitchConsoleFirst &&
+ ka <= QWSKeyboardHandler::SwitchConsoleLast) {
+ switchConsole(1 + (ka & QWSKeyboardHandler::SwitchConsoleMask));
+ }
+ //ignore reboot
+ break;
+ }
+ }
+}
+
+
+void QWSTtyKbPrivate::switchConsole(int vt)
+{
+#if defined(Q_OS_LINUX)
+ if (m_vt_qws && vt && (m_tty_fd >= 0 ))
+ ::ioctl(m_tty_fd, VT_ACTIVATE, vt);
+#endif
+}
+
+void QWSTtyKbPrivate::handleConsoleSwitch(int sig)
+{
+#if defined(Q_OS_LINUX)
+ // received a notification from the kernel that the current VT is
+ // changing: either enable or disable QWS painting accordingly.
+
if (sig == VTACQSIG) {
- if (ioctl(kbdFD, VT_RELDISP, VT_ACKACQ) == 0) {
+ if (::ioctl(m_tty_fd, VT_RELDISP, VT_ACKACQ) == 0) {
qwsServer->enablePainting(true);
qt_screen->restore();
qwsServer->resumeMouse();
@@ -236,9 +328,9 @@ void QWSTtyKbPrivate::handleTtySwitch(int sig)
}
if (!allWindowsHidden) {
- ioctl(kbdFD, VT_RELDISP, 0); // abort console switch
+ ::ioctl(m_tty_fd, VT_RELDISP, 0); // abort console switch
qwsServer->enablePainting(true);
- } else if (ioctl(kbdFD, VT_RELDISP, 1) == 0) {
+ } else if (::ioctl(m_tty_fd, VT_RELDISP, 1) == 0) {
qt_screen->save();
qwsServer->suspendMouse();
} else {
@@ -248,14 +340,6 @@ void QWSTtyKbPrivate::handleTtySwitch(int sig)
#endif
}
-void QWSTtyKbPrivate::readKeyboardData()
-{
- unsigned char buf[81];
- int n = read(kbdFD, buf, 80);
- for (int loop = 0; loop < n; loop++)
- handler->doKey(buf[loop]);
-}
-
QT_END_NAMESPACE
#include "qkbdtty_qws.moc"
diff --git a/src/gui/embedded/qkbdtty_qws.h b/src/gui/embedded/qkbdtty_qws.h
index 4f93d6c..fc3eaa1 100644
--- a/src/gui/embedded/qkbdtty_qws.h
+++ b/src/gui/embedded/qkbdtty_qws.h
@@ -42,7 +42,7 @@
#ifndef QKBDTTY_QWS_H
#define QKBDTTY_QWS_H
-#include <QtGui/qkbdpc101_qws.h>
+#include <QtGui/qkbd_qws.h>
QT_BEGIN_HEADER
@@ -56,15 +56,13 @@ QT_MODULE(Gui)
class QWSTtyKbPrivate;
-class QWSTtyKeyboardHandler : public QWSPC101KeyboardHandler
+class QWSTtyKeyboardHandler : public QWSKeyboardHandler
{
public:
explicit QWSTtyKeyboardHandler(const QString&);
virtual ~QWSTtyKeyboardHandler();
-protected:
- virtual void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
- bool isPress, bool autoRepeat);
+ virtual bool filterKeycode(char &code);
private:
QWSTtyKbPrivate *d;
diff --git a/src/gui/embedded/qkbdum_qws.cpp b/src/gui/embedded/qkbdum_qws.cpp
index d525c66..fa05d6c 100644
--- a/src/gui/embedded/qkbdum_qws.cpp
+++ b/src/gui/embedded/qkbdum_qws.cpp
@@ -54,6 +54,7 @@
#include <qstring.h>
#include <qwindowsystem_qws.h>
#include <qsocketnotifier.h>
+#include "qplatformdefs.h"
QT_BEGIN_NAMESPACE
@@ -81,13 +82,13 @@ QWSUmKeyboardHandlerPrivate::QWSUmKeyboardHandlerPrivate(const QString &device)
{
kbdBuffer = new unsigned char [kbdBufferLen];
- if ((kbdFD = open((const char *)device.toLocal8Bit(), O_RDONLY | O_NDELAY)) < 0) {
+ if ((kbdFD = QT_OPEN((const char *)device.toLocal8Bit(), O_RDONLY | O_NDELAY, 0)) < 0) {
qDebug("Cannot open %s (%s)", (const char *)device.toLocal8Bit(),
strerror(errno));
} else {
// Clear pending input
char buf[2];
- while (read(kbdFD, buf, 1) > 0) { }
+ while (QT_READ(kbdFD, buf, 1) > 0) { }
notifier = new QSocketNotifier(kbdFD, QSocketNotifier::Read, this);
connect(notifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData()));
@@ -97,7 +98,7 @@ QWSUmKeyboardHandlerPrivate::QWSUmKeyboardHandlerPrivate(const QString &device)
QWSUmKeyboardHandlerPrivate::~QWSUmKeyboardHandlerPrivate()
{
if (kbdFD >= 0)
- close(kbdFD);
+ QT_CLOSE(kbdFD);
delete [] kbdBuffer;
}
@@ -106,7 +107,7 @@ void QWSUmKeyboardHandlerPrivate::readKeyboardData()
{
int n;
do {
- n = read(kbdFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx);
+ n = QT_READ(kbdFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx);
if (n > 0)
kbdIdx += n;
} while (n > 0);
diff --git a/src/gui/embedded/qkbdusb_qws.cpp b/src/gui/embedded/qkbdusb_qws.cpp
deleted file mode 100644
index e35ac55..0000000
--- a/src/gui/embedded/qkbdusb_qws.cpp
+++ /dev/null
@@ -1,401 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qkbdusb_qws.h"
-
-#ifndef QT_NO_QWS_KEYBOARD
-
-#include "qscreen_qws.h"
-
-#include "qwindowsystem_qws.h"
-#include "qapplication.h"
-#include "qsocketnotifier.h"
-#include "qnamespace.h"
-#include "qtimer.h"
-
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <linux/input.h>
-
-#ifdef Q_OS_LINUX
-#include <sys/kd.h>
-#include <sys/vt.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/* USB driver */
-
-
-class QWSUsbKbPrivate : public QObject
-{
- Q_OBJECT
-public:
- QWSUsbKbPrivate(QWSPC101KeyboardHandler *, const QString &);
- ~QWSUsbKbPrivate();
-
-private slots:
- void readKeyboardData();
-
-private:
- QWSPC101KeyboardHandler *handler;
- int fd;
-#ifdef QT_QWS_ZYLONITE
- bool shift;
-#endif
-};
-
-QWSUsbKeyboardHandler::QWSUsbKeyboardHandler(const QString &device)
- : QWSPC101KeyboardHandler(device)
-{
- d = new QWSUsbKbPrivate(this, device);
-}
-
-QWSUsbKeyboardHandler::~QWSUsbKeyboardHandler()
-{
- delete d;
-}
-
-QWSUsbKbPrivate::QWSUsbKbPrivate(QWSPC101KeyboardHandler *h, const QString &device) : handler(h)
-{
-#ifdef QT_QWS_ZYLONITE
- shift = FALSE;
-#endif
- fd = ::open(device.isEmpty()?"/dev/input/event1":device.toLocal8Bit(),O_RDONLY, 0);
- if (fd >= 0) {
- QSocketNotifier *notifier;
- notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
- connect(notifier, SIGNAL(activated(int)),this,
- SLOT(readKeyboardData()));
- }
-}
-
-QWSUsbKbPrivate::~QWSUsbKbPrivate()
-{
- ::close(fd);
-}
-
-void QWSUsbKbPrivate::readKeyboardData()
-{
- input_event event;
- if (read(fd, &event, sizeof(input_event)) != sizeof(input_event))
- return;
-
- if (event.type != EV_KEY)
- return;
-
-#ifdef QT_QWS_ZYLONITE
- qDebug("keypressed: code=%03d (%s)\n",event.code,((event.value)!=0) ? "Down":"Up");
- int modifiers=0;
- int unicode=0xffff;
- int key_code=0;
-
- switch(event.code)
- {
- case 0xA2:
- key_code = ((!shift) ? Qt::Key_0 : Qt::Key_Plus );
- unicode = ((!shift) ? 0x30 : 0x2B );
- break;
- case 0x70:
- key_code = ((!shift) ? Qt::Key_1 : Qt::Key_At );
- unicode = ((!shift) ? 0x31 : 0x40 );
- break;
- case 0x72:
- key_code = ((!shift) ? Qt::Key_2 : Qt::Key_Ampersand );
- unicode = ((!shift) ? 0x32 : 0x26 );
- break;
- case 0x74:
- key_code = ((!shift) ? Qt::Key_3 : Qt::Key_At );
- unicode = ((!shift) ? 0x33 : 0x3F );
- break;
- case 0x80:
- key_code = ((!shift) ? Qt::Key_4 : Qt::Key_Minus );
- unicode = ((!shift) ? 0x34 : 0x2D );
- break;
- case 0x82:
- key_code = ((!shift) ? Qt::Key_5 : Qt::Key_Apostrophe);
- unicode = ((!shift) ? 0x35 : 0x27 );
- break;
- case 0x84:
- key_code = ((!shift) ? Qt::Key_6 : Qt::Key_Slash );
- unicode = ((!shift) ? 0x36 : 0x5C );
- break;
- case 0x90:
- key_code = ((!shift) ? Qt::Key_7 : Qt::Key_Colon );
- unicode = ((!shift) ? 0x37 : 0x3A );
- break;
- case 0x92:
- key_code = ((!shift) ? Qt::Key_8 : Qt::Key_Semicolon );
- unicode = ((!shift) ? 0x38 : 0x3B );
- break;
- case 0x94:
- key_code = ((!shift) ? Qt::Key_9 : Qt::Key_QuoteDbl );
- unicode = ((!shift) ? 0x39 : 0x22 );
- break;
- case 0x0:
- key_code = Qt::Key_A;
- unicode = ((!shift) ? 0x61 : 0x41 );
- break;
- case 0x10:
- key_code = Qt::Key_B;
- unicode = ((!shift) ? 0x62 : 0x42 );
- break;
- case 0x20:
- key_code = Qt::Key_C;
- unicode = ((!shift) ? 0x63 : 0x43 );
- break;
- case 0x30:
- key_code = Qt::Key_D;
- unicode = ((!shift) ? 0x64 : 0x44 );
- break;
- case 0x40:
- key_code = Qt::Key_E;
- unicode = ((!shift) ? 0x65 : 0x45 );
- break;
- case 0x50:
- key_code = Qt::Key_F;
- unicode = ((!shift) ? 0x66 : 0x46 );
- break;
- case 0x01:
- key_code = Qt::Key_G;
- unicode = ((!shift) ? 0x67 : 0x47 );
- break;
- case 0x11:
- key_code = Qt::Key_H;
- unicode = ((!shift) ? 0x68 : 0x48 );
- break;
- case 0x21:
- key_code = Qt::Key_I;
- unicode = ((!shift) ? 0x69 : 0x49 );
- break;
- case 0x31:
- key_code = Qt::Key_J;
- unicode = ((!shift) ? 0x6A : 0x4A );
- break;
- case 0x41:
- key_code = Qt::Key_K;
- unicode = ((!shift) ? 0x6B : 0x4B );
- break;
- case 0x51:
- key_code = Qt::Key_L;
- unicode = ((!shift) ? 0x6C : 0x4C );
- break;
- case 0x02:
- key_code = Qt::Key_M;
- unicode = ((!shift) ? 0x6D : 0x4D );
- break;
- case 0x12:
- key_code = Qt::Key_N;
- unicode = ((!shift) ? 0x6E : 0x4E );
- break;
- case 0x22:
- key_code = Qt::Key_O;
- unicode = ((!shift) ? 0x6F : 0x4F );
- break;
- case 0x32:
- key_code = Qt::Key_P;
- unicode = ((!shift) ? 0x70 : 0x50 );
- break;
- case 0x42:
- key_code = Qt::Key_Q;
- unicode = ((!shift) ? 0x71 : 0x51 );
- break;
- case 0x52:
- key_code = Qt::Key_R;
- unicode = ((!shift) ? 0x72 : 0x52 );
- break;
- case 0x03:
- key_code = Qt::Key_S;
- unicode = ((!shift) ? 0x73 : 0x53 );
- break;
- case 0x13:
- key_code = Qt::Key_T;
- unicode = ((!shift) ? 0x74 : 0x54 );
- break;
- case 0x23:
- key_code = Qt::Key_U;
- unicode = ((!shift) ? 0x75 : 0x55 );
- break;
- case 0x33:
- key_code = Qt::Key_V;
- unicode = ((!shift) ? 0x76 : 0x56 );
- break;
- case 0x43:
- key_code = Qt::Key_W;
- unicode = ((!shift) ? 0x77 : 0x57 );
- break;
- case 0x53:
- key_code = Qt::Key_X;
- unicode = ((!shift) ? 0x78 : 0x58 );
- break;
- case 0x24:
- key_code = Qt::Key_Y;
- unicode = ((!shift) ? 0x79 : 0x59 );
- break;
- case 0x34:
- key_code = Qt::Key_Z;
- unicode = ((!shift) ? 0x7A : 0x5A );
- break;
- case 0xA4:
- key_code = ((!shift) ? Qt::Key_NumberSign : Qt::Key_Period);
- unicode = ((!shift) ? 0x23 : 0x2E );
- break;
- case 0xA0:
- key_code = ((!shift) ? Qt::Key_Asterisk : Qt::Key_NumberSign );
- unicode = ((!shift) ? 0x2A : 0x2C );
- break;
- case 0x25:
- key_code = Qt::Key_Space;
- unicode = 0x20;
- break;
- case 0x06:
- key_code = Qt::Key_Up;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x16:
- key_code = Qt::Key_Down;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x26:
- key_code = Qt::Key_Left;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x36:
- key_code = Qt::Key_Right;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x46:
- key_code = Qt::Key_Select;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x61:
- key_code = Qt::Key_No;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x60:
- key_code = Qt::Key_Call;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x55:
- key_code = Qt::Key_Hangup;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x62:
- key_code = Qt::Key_Context1;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x63:
- key_code = Qt::Key_No;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x05:
- key_code = Qt::Key_Home;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x15:
- key_code = Qt::Key_Shift;
- unicode = 0xffff; modifiers |= Qt::ShiftModifier;
- if(event.value==0) break;
- if(shift) {
- shift = FALSE;
- qWarning("Caps Off!");
- } else {
- shift = TRUE;
- qWarning("Caps On!");
- }
- break;
- case 0x1C:
- key_code = ((!shift) ? Qt::Key_Back : Qt::Key_Enter );
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x19:
- key_code = Qt::Key_Context2;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x1A:
- key_code = Qt::Key_Context3;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- case 0x1B:
- key_code = Qt::Key_Context4;
- unicode = 0xffff; modifiers |= Qt::KeypadModifier;
- break;
- }
- if(shift) modifiers |= Qt::ShiftModifier;
- handler->processKeyEvent(unicode, key_code, (Qt::KeyboardModifiers)modifiers, event.value!=0, false);
-#else
-
- int key=event.code;
-#ifndef QT_QWS_USE_KEYCODES
- // Handle SOME keys, otherwise it's useless.
-
- if(key==103) {
- handler->processKeyEvent(0, Qt::Key_Up, 0, event.value!=0, false);
- } else if(key==106) {
- handler->processKeyEvent(0, Qt::Key_Right, 0, event.value!=0, false );
- } else if(key==108) {
- handler->processKeyEvent(0, Qt::Key_Down, 0, event.value!=0, false);
- } else if(key==105) {
- handler->processKeyEvent(0, Qt::Key_Left, 0, event.value!=0, false);
- } else
-
-#endif
-
- {
- if(event.value == 0) {
- key=key | 0x80;
- }
- handler->doKey(key);
- }
-#endif
-}
-
-QT_END_NAMESPACE
-
-#include "qkbdusb_qws.moc"
-
-#endif // QT_NO_QWS_KEYBOARD
diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp
index 6741f2c..ff48403 100644
--- a/src/gui/embedded/qscreen_qws.cpp
+++ b/src/gui/embedded/qscreen_qws.cpp
@@ -198,10 +198,12 @@ void QScreenCursor::set(const QImage &image, int hotx, int hoty)
*/
void QScreenCursor::move(int x, int y)
{
- const QRegion r = boundingRect();
+ QRegion r = boundingRect();
pos = QPoint(x,y);
- if (enable && !hwaccel)
- qt_screen->exposeRegion(r | boundingRect(), 0);
+ if (enable && !hwaccel) {
+ r |= boundingRect();
+ qt_screen->exposeRegion(r, 0);
+ }
}
diff --git a/src/gui/embedded/qwscommand_qws.cpp b/src/gui/embedded/qwscommand_qws.cpp
index 88e33a3..b0fd78b 100644
--- a/src/gui/embedded/qwscommand_qws.cpp
+++ b/src/gui/embedded/qwscommand_qws.cpp
@@ -43,7 +43,6 @@
#include "qtransportauth_qws.h"
#include "qtransportauth_qws_p.h"
-#include <sys/uio.h>
#include <unistd.h>
// #define QWSCOMMAND_DEBUG 1 // Uncomment to debug client/server communication
diff --git a/src/gui/embedded/qwssignalhandler.cpp b/src/gui/embedded/qwssignalhandler.cpp
index 0946fb6..e85bd36 100644
--- a/src/gui/embedded/qwssignalhandler.cpp
+++ b/src/gui/embedded/qwssignalhandler.cpp
@@ -44,8 +44,10 @@
#ifndef QT_NO_QWS_SIGNALHANDLER
#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
+#ifndef QT_NO_QWS_MULTIPROCESS
+# include <sys/ipc.h>
+# include <sys/sem.h>
+#endif
#include <signal.h>
QT_BEGIN_NAMESPACE
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 4908296..72b832a 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -274,6 +274,15 @@
this flag, the child will be stacked behind it. This flag is useful for
drop shadow effects and for decoration objects that follow the parent
item's geometry without drawing on top of it.
+
+ \value ItemUsesExtendedStyleOption The item makes use of either
+ QStyleOptionGraphicsItem::exposedRect or QStyleOptionGraphicsItem::matrix.
+ By default, the exposedRect is initialized to the item's boundingRect and
+ the matrix is untransformed. Enable this flag for more fine-grained values.
+ Note that QStyleOptionGraphicsItem::levelOfDetail is unaffected by this flag
+ and is always initialized to 1.
+ Use QStyleOptionGraphicsItem::levelOfDetailFromTransform for a more
+ fine-grained value.
*/
/*!
@@ -522,6 +531,11 @@
#include <private/qtextdocumentlayout_p.h>
#include <private/qtextengine_p.h>
+#ifdef Q_WS_X11
+#include <private/qt_x11_p.h>
+#include <private/qpixmap_x11_p.h>
+#endif
+
#include <math.h>
QT_BEGIN_NAMESPACE
@@ -559,29 +573,6 @@ Q_GLOBAL_STATIC(QGraphicsItemCustomDataStore, qt_dataStore)
/*!
\internal
- Removes the first instance of \a child from \a children. This is a
- heuristic approach that assumes that it's common to remove items from the
- start or end of the list.
-*/
-static void qt_graphicsitem_removeChild(QGraphicsItem *child, QList<QGraphicsItem *> *children)
-{
- const int n = children->size();
- for (int i = 0; i < (n + 1) / 2; ++i) {
- if (children->at(i) == child) {
- children->removeAt(i);
- return;
- }
- int j = n - i - 1;
- if (children->at(j) == child) {
- children->removeAt(j);
- return;
- }
- }
-}
-
-/*!
- \internal
-
Returns a QPainterPath of \a path when stroked with the \a pen.
Ignoring dash pattern.
*/
@@ -781,11 +772,213 @@ QVariant QGraphicsItemPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query
/*!
\internal
+ If \a deleting is true, then this item is being deleted, and \a parent is
+ null. Make sure not to trigger any pure virtual function calls (e.g.,
+ prepareGeometryChange).
+*/
+void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, bool deleting)
+{
+ Q_Q(QGraphicsItem);
+ if (newParent == q) {
+ qWarning("QGraphicsItem::setParentItem: cannot assign %p as a parent of itself", this);
+ return;
+ }
+ if (newParent == parent)
+ return;
+
+ const QVariant newParentVariant(q->itemChange(QGraphicsItem::ItemParentChange,
+ qVariantFromValue<QGraphicsItem *>(newParent)));
+ newParent = qVariantValue<QGraphicsItem *>(newParentVariant);
+ if (newParent == parent)
+ return;
+
+ if (QGraphicsWidget *w = isWidget ? static_cast<QGraphicsWidget *>(q) : q->parentWidget()) {
+ // Update the child focus chain; when reparenting a widget that has a
+ // focus child, ensure that that focus child clears its focus child
+ // chain from our parents before it's reparented.
+ if (QGraphicsWidget *focusChild = w->focusWidget())
+ focusChild->clearFocus();
+ }
+
+ // We anticipate geometry changes. If the item is deleted, it will be
+ // removed from the index at a later stage, and the whole scene will be
+ // updated.
+ if (!deleting)
+ q_ptr->prepareGeometryChange();
+
+ const QVariant thisPointerVariant(qVariantFromValue<QGraphicsItem *>(q));
+ if (parent) {
+ // Remove from current parent
+ parent->d_ptr->removeChild(q);
+ parent->itemChange(QGraphicsItem::ItemChildRemovedChange, thisPointerVariant);
+ }
+
+ // Update toplevelitem list. If this item is being deleted, its parent
+ // will be 0 but we don't want to register/unregister it in the TLI list.
+ if (scene && !deleting) {
+ if (parent && !newParent) {
+ scene->d_func()->registerTopLevelItem(q);
+ } else if (!parent && newParent) {
+ scene->d_func()->unregisterTopLevelItem(q);
+ }
+ }
+
+ if ((parent = newParent)) {
+ bool implicitUpdate = false;
+ if (parent->d_func()->scene && parent->d_func()->scene != scene) {
+ // Move this item to its new parent's scene
+ parent->d_func()->scene->addItem(q);
+ implicitUpdate = true;
+ } else if (!parent->d_func()->scene && scene) {
+ // Remove this item from its former scene
+ scene->removeItem(q);
+ }
+
+ parent->d_ptr->addChild(q);
+ parent->itemChange(QGraphicsItem::ItemChildAddedChange, thisPointerVariant);
+ if (!implicitUpdate)
+ updateHelper(QRectF(), false, true);
+
+ // Inherit ancestor flags from the new parent.
+ updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
+ updateAncestorFlag(QGraphicsItem::ItemClipsChildrenToShape);
+ updateAncestorFlag(QGraphicsItem::ItemIgnoresTransformations);
+
+ // Update item visible / enabled.
+ if (parent->isVisible() != visible) {
+ if (!parent->isVisible() || !explicitlyHidden)
+ setVisibleHelper(parent->isVisible(), /* explicit = */ false, /* update = */ !implicitUpdate);
+ }
+ if (parent->isEnabled() != enabled) {
+ if (!parent->isEnabled() || !explicitlyDisabled)
+ setEnabledHelper(parent->isEnabled(), /* explicit = */ false, /* update = */ !implicitUpdate);
+ }
+
+ } else {
+ // Inherit ancestor flags from the new parent.
+ updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
+ updateAncestorFlag(QGraphicsItem::ItemClipsChildrenToShape);
+ updateAncestorFlag(QGraphicsItem::ItemIgnoresTransformations);
+
+ if (!deleting) {
+ // Update item visible / enabled.
+ if (!visible && !explicitlyHidden)
+ setVisibleHelper(true, /* explicit = */ false);
+ if (!enabled && !explicitlyDisabled)
+ setEnabledHelper(true, /* explicit = */ false);
+
+ // If the item is being deleted, the whole scene will be updated.
+ updateHelper(QRectF(), false, true);
+ }
+ }
+
+ if (scene) {
+ // Invalidate any sort caching; arrival of a new item means we need to
+ // resort.
+ scene->d_func()->invalidateSortCache();
+ }
+
+ // Resolve opacity.
+ updateEffectiveOpacity();
+
+ // Resolve depth.
+ resolveDepth(parent ? parent->d_ptr->depth : -1);
+
+ // Invalidate transform cache.
+ invalidateSceneTransformCache();
+
+ // Deliver post-change notification
+ q->itemChange(QGraphicsItem::ItemParentHasChanged, newParentVariant);
+}
+
+/*!
+ \internal
+
+ Returns the bounding rect of this item's children (excluding itself).
+*/
+void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rect)
+{
+ for (int i = 0; i < children.size(); ++i) {
+ QGraphicsItem *child = children.at(i);
+ QGraphicsItemPrivate *childd = child->d_ptr;
+ bool hasX = childd->hasTransform;
+ bool hasPos = !childd->pos.isNull();
+ if (hasPos || hasX) {
+ QTransform matrix;
+ if (hasX)
+ matrix = child->transform();
+ if (hasPos) {
+ const QPointF &p = childd->pos;
+ matrix *= QTransform::fromTranslate(p.x(), p.y());
+ }
+ matrix *= *x;
+ *rect |= matrix.mapRect(child->boundingRect());
+ if (!childd->children.isEmpty())
+ childd->childrenBoundingRectHelper(&matrix, rect);
+ } else {
+ *rect |= x->mapRect(child->boundingRect());
+ if (!childd->children.isEmpty())
+ childd->childrenBoundingRectHelper(x, rect);
+ }
+ }
+}
+
+void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform,
+ const QRegion &exposedRegion, bool allItems) const
+{
+ Q_ASSERT(option);
+ Q_Q(const QGraphicsItem);
+
+ // Initialize standard QStyleOption values.
+ const QRectF brect = q->boundingRect();
+ option->state = QStyle::State_None;
+ option->rect = brect.toRect();
+ option->levelOfDetail = 1;
+ option->exposedRect = brect;
+ if (selected)
+ option->state |= QStyle::State_Selected;
+ if (enabled)
+ option->state |= QStyle::State_Enabled;
+ if (q->hasFocus())
+ option->state |= QStyle::State_HasFocus;
+ if (scene) {
+ if (scene->d_func()->hoverItems.contains(q_ptr))
+ option->state |= QStyle::State_MouseOver;
+ if (q == scene->mouseGrabberItem())
+ option->state |= QStyle::State_Sunken;
+ }
+
+ if (!(flags & QGraphicsItem::ItemUsesExtendedStyleOption))
+ return;
+
+ // Initialize QStyleOptionGraphicsItem specific values (matrix, exposedRect).
+
+ const QTransform itemToViewportTransform = q->deviceTransform(worldTransform);
+ option->matrix = itemToViewportTransform.toAffine(); //### discards perspective
+
+ if (!allItems) {
+ // Determine the item's exposed area
+ option->exposedRect = QRectF();
+ const QTransform reverseMap = itemToViewportTransform.inverted();
+ const QVector<QRect> exposedRects(exposedRegion.rects());
+ for (int i = 0; i < exposedRects.size(); ++i) {
+ option->exposedRect |= reverseMap.mapRect(exposedRects.at(i));
+ if (option->exposedRect.contains(brect))
+ break;
+ }
+ option->exposedRect &= brect;
+ }
+}
+
+/*!
+ \internal
+
Empty all cached pixmaps from the pixmap cache.
*/
void QGraphicsItemCache::purge()
{
QPixmapCache::remove(key);
+ key = QPixmapCache::Key();
QMutableMapIterator<QPaintDevice *, DeviceData> it(deviceData);
while (it.hasNext()) {
DeviceData &data = it.next().value();
@@ -853,24 +1046,17 @@ QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent,
*/
QGraphicsItem::~QGraphicsItem()
{
+ if (d_ptr->scene && !d_ptr->parent)
+ d_ptr->scene->d_func()->unregisterTopLevelItem(this);
+
clearFocus();
- d_ptr->removeExtraItemCache();
- QVariant variant;
- foreach (QGraphicsItem *child, d_ptr->children) {
- if (QGraphicsItem *parent = child->parentItem()) {
- qVariantSetValue<QGraphicsItem *>(variant, child);
- parent->itemChange(ItemChildRemovedChange, variant);
- }
- delete child;
- }
- d_ptr->children.clear();
+ d_ptr->removeExtraItemCache();
+ QList<QGraphicsItem *> oldChildren = d_ptr->children;
+ qDeleteAll(oldChildren);
+ Q_ASSERT(d_ptr->children.isEmpty());
- if (QGraphicsItem *parent = parentItem()) {
- qVariantSetValue<QGraphicsItem *>(variant, this);
- parent->itemChange(ItemChildRemovedChange, variant);
- qt_graphicsitem_removeChild(this, &parent->d_func()->children);
- }
+ d_ptr->setParentItemHelper(0, /* deleting = */ true);
if (d_ptr->scene)
d_ptr->scene->d_func()->_q_removeItemLater(this);
@@ -1015,98 +1201,7 @@ QGraphicsWidget *QGraphicsItem::window() const
*/
void QGraphicsItem::setParentItem(QGraphicsItem *parent)
{
- if (parent == this) {
- qWarning("QGraphicsItem::setParentItem: cannot assign %p as a parent of itself", this);
- return;
- }
- if (parent == d_ptr->parent)
- return;
- const QVariant newParentVariant(itemChange(ItemParentChange, qVariantFromValue<QGraphicsItem *>(parent)));
- parent = qVariantValue<QGraphicsItem *>(newParentVariant);
- if (parent == d_ptr->parent)
- return;
-
- if (QGraphicsWidget *w = d_ptr->isWidget ? static_cast<QGraphicsWidget *>(this) : parentWidget()) {
- // Update the child focus chain; when reparenting a widget that has a
- // focus child, ensure that that focus child clears its focus child
- // chain from our parents before it's reparented.
- if (QGraphicsWidget *focusChild = w->focusWidget())
- focusChild->clearFocus();
- }
-
- // We anticipate geometry changes
- prepareGeometryChange();
-
- const QVariant thisPointerVariant(qVariantFromValue<QGraphicsItem *>(this));
- if (d_ptr->parent) {
- // Remove from current parent
- qt_graphicsitem_removeChild(this, &d_ptr->parent->d_func()->children);
- d_ptr->parent->itemChange(ItemChildRemovedChange, thisPointerVariant);
- }
-
- if ((d_ptr->parent = parent)) {
- bool implicitUpdate = false;
- if (parent->d_func()->scene && parent->d_func()->scene != d_ptr->scene) {
- // Move this item to its new parent's scene
- parent->d_func()->scene->addItem(this);
- implicitUpdate = true;
- } else if (!parent->d_func()->scene && d_ptr->scene) {
- // Remove this item from its former scene
- d_ptr->scene->removeItem(this);
- }
-
- d_ptr->parent->d_func()->children << this;
- d_ptr->parent->itemChange(ItemChildAddedChange, thisPointerVariant);
- if (!implicitUpdate)
- d_ptr->updateHelper(QRectF(), false, true);
-
- // Inherit ancestor flags from the new parent.
- d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
- d_ptr->updateAncestorFlag(ItemClipsChildrenToShape);
- d_ptr->updateAncestorFlag(ItemIgnoresTransformations);
-
- // Update item visible / enabled.
- if (d_ptr->parent->isVisible() != d_ptr->visible) {
- if (!d_ptr->parent->isVisible() || !d_ptr->explicitlyHidden)
- d_ptr->setVisibleHelper(d_ptr->parent->isVisible(), /* explicit = */ false, /* update = */ !implicitUpdate);
- }
- if (d_ptr->parent->isEnabled() != d_ptr->enabled) {
- if (!d_ptr->parent->isEnabled() || !d_ptr->explicitlyDisabled)
- d_ptr->setEnabledHelper(d_ptr->parent->isEnabled(), /* explicit = */ false, /* update = */ !implicitUpdate);
- }
-
- } else {
- // Inherit ancestor flags from the new parent.
- d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
- d_ptr->updateAncestorFlag(ItemClipsChildrenToShape);
- d_ptr->updateAncestorFlag(ItemIgnoresTransformations);
-
- // Update item visible / enabled.
- if (!d_ptr->visible && !d_ptr->explicitlyHidden)
- d_ptr->setVisibleHelper(true, /* explicit = */ false);
- if (!d_ptr->enabled && !d_ptr->explicitlyDisabled)
- d_ptr->setEnabledHelper(true, /* explicit = */ false);
-
- d_ptr->updateHelper(QRectF(), false, true);
- }
-
- if (d_ptr->scene) {
- // Invalidate any sort caching; arrival of a new item means we need to
- // resort.
- d_ptr->scene->d_func()->invalidateSortCache();
- }
-
- // Resolve opacity.
- d_ptr->updateEffectiveOpacity();
-
- // Resolve depth.
- d_ptr->resolveDepth(parent ? parent->d_ptr->depth : -1);
-
- // Invalidate transform cache.
- d_ptr->invalidateSceneTransformCache();
-
- // Deliver post-change notification
- itemChange(QGraphicsItem::ItemParentHasChanged, newParentVariant);
+ d_ptr->setParentItemHelper(parent, /* deleting = */ false);
}
/*!
@@ -1332,12 +1427,6 @@ void QGraphicsItem::setCacheMode(CacheMode mode, const QSize &logicalCacheSize)
cache->purge();
if (mode == ItemCoordinateCache) {
- if (cache->key.isEmpty()) {
- // Generate new simple pixmap cache key.
- QString tmp;
- tmp.sprintf("qgv-%p", this);
- cache->key = tmp;
- }
if (lastMode == mode && cache->fixedSize == logicalCacheSize)
noVisualChange = true;
cache->fixedSize = logicalCacheSize;
@@ -1415,7 +1504,9 @@ void QGraphicsItem::setCursor(const QCursor &cursor)
d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qVariantValue<QCursor>(cursorVariant));
d_ptr->hasCursor = 1;
if (d_ptr->scene) {
+ d_ptr->scene->d_func()->allItemsUseDefaultCursor = false;
foreach (QGraphicsView *view, d_ptr->scene->views()) {
+ view->viewport()->setMouseTracking(true);
// Note: Some of this logic is duplicated in QGraphicsView's mouse events.
if (view->underMouse()) {
foreach (QGraphicsItem *itemUnderCursor, view->items(view->mapFromGlobal(QCursor::pos()))) {
@@ -1898,11 +1989,11 @@ void QGraphicsItem::setOpacity(qreal opacity)
newOpacity = qBound<qreal>(0.0, newOpacity, 1.0);
// No change? Done.
- if (qFuzzyCompare(newOpacity, this->opacity()))
+ if (qFuzzyIsNull(newOpacity - this->opacity()))
return;
// Assign local opacity.
- if (qFuzzyCompare(newOpacity, qreal(1.0))) {
+ if (qFuzzyIsNull(newOpacity - 1)) {
// Opaque, unset opacity.
d_ptr->hasOpacity = 0;
d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraOpacity);
@@ -2047,7 +2138,13 @@ bool QGraphicsItem::acceptsHoverEvents() const
*/
void QGraphicsItem::setAcceptHoverEvents(bool enabled)
{
+ if (d_ptr->acceptsHover == quint32(enabled))
+ return;
d_ptr->acceptsHover = quint32(enabled);
+ if (d_ptr->acceptsHover && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreHoverEvents) {
+ d_ptr->scene->d_func()->allItemsIgnoreHoverEvents = false;
+ d_ptr->scene->d_func()->enableMouseTrackingOnViews();
+ }
}
/*!
@@ -2057,7 +2154,7 @@ void QGraphicsItem::setAcceptHoverEvents(bool enabled)
*/
void QGraphicsItem::setAcceptsHoverEvents(bool enabled)
{
- d_ptr->acceptsHover = quint32(enabled);
+ setAcceptHoverEvents(enabled);
}
/*!
@@ -2945,11 +3042,11 @@ qreal QGraphicsItem::zValue() const
/*!
Sets the Z-value, or the elevation, of the item, to \a z. The elevation
decides the stacking order of sibling (neighboring) items. An item of high
- Z-value will be drawn on top of an item with a lower Z-value if they
- share the same parent item. In addition, children of an item will always be drawn
- on top of the parent, regardless of the child's Z-value. Sibling items
- that share the same Z-value will be drawn in an undefined order, although
- the order will stay the same for as long as the items live.
+ Z-value will be drawn on top of an item with a lower Z-value if they share
+ the same parent item. In addition, children of an item will always be
+ drawn on top of the parent, regardless of the child's Z-value. Sibling
+ items that share the same Z-value will be drawn in order of insertion; the
+ last inserted child is stacked above previous children.
\img graphicsview-zorder.png
@@ -2977,7 +3074,7 @@ void QGraphicsItem::setZValue(qreal z)
qreal newZ = qreal(newZVariant.toDouble());
if (newZ == d_ptr->z)
return;
- d_ptr->z = z;
+ d_ptr->z = newZ;
d_ptr->fullUpdateHelper();
if (d_ptr->scene) {
@@ -3009,13 +3106,8 @@ void QGraphicsItem::setZValue(qreal z)
QRectF QGraphicsItem::childrenBoundingRect() const
{
QRectF childRect;
- foreach (QGraphicsItem *child, children()) {
- QPointF childPos = child->pos();
- QTransform matrix = child->transform();
- if (!childPos.isNull())
- matrix *= QTransform::fromTranslate(childPos.x(), childPos.y());
- childRect |= matrix.mapRect(child->boundingRect() | child->childrenBoundingRect());
- }
+ QTransform x;
+ d_ptr->childrenBoundingRectHelper(&x, &childRect);
return childRect;
}
@@ -3630,7 +3722,7 @@ void QGraphicsItem::setBoundingRegionGranularity(qreal granularity)
All painting is done in local coordinates.
- \sa setCacheMode(), QPen::width(), {Item Coordinates}
+ \sa setCacheMode(), QPen::width(), {Item Coordinates}, ItemUsesExtendedStyleOption
*/
/*!
@@ -3721,7 +3813,7 @@ void QGraphicsItemPrivate::fullUpdateHelper(bool childrenOnly, bool maybeDirtyCl
dirtyChildren = 1;
}
-static inline bool qt_allChildrenCombineOpacity(QGraphicsItem *parent)
+static inline bool allChildrenCombineOpacityHelper(QGraphicsItem *parent)
{
Q_ASSERT(parent);
if (parent->flags() & QGraphicsItem::ItemDoesntPropagateOpacityToChildren)
@@ -3740,11 +3832,11 @@ void QGraphicsItemPrivate::updateEffectiveOpacity()
Q_Q(QGraphicsItem);
if (parent) {
resolveEffectiveOpacity(parent->effectiveOpacity());
- parent->d_ptr->allChildrenCombineOpacity = qt_allChildrenCombineOpacity(parent);
+ parent->d_ptr->allChildrenCombineOpacity = allChildrenCombineOpacityHelper(parent);
} else {
resolveEffectiveOpacity(1.0);
}
- allChildrenCombineOpacity = qt_allChildrenCombineOpacity(q);
+ allChildrenCombineOpacity = allChildrenCombineOpacityHelper(q);
}
/*!
@@ -3771,7 +3863,7 @@ void QGraphicsItemPrivate::resolveEffectiveOpacity(qreal parentEffectiveOpacity)
}
// Set this item's resolved opacity.
- if (qFuzzyCompare(myEffectiveOpacity, qreal(1.0))) {
+ if (qFuzzyIsNull(myEffectiveOpacity - 1)) {
// Opaque, unset effective opacity.
hasEffectiveOpacity = 0;
unsetExtra(ExtraEffectiveOpacity);
@@ -3810,6 +3902,41 @@ void QGraphicsItemPrivate::invalidateSceneTransformCache()
children.at(i)->d_ptr->invalidateSceneTransformCache();
}
+/*!
+ \internal
+*/
+void QGraphicsItemPrivate::addChild(QGraphicsItem *child)
+{
+ child->d_ptr->siblingIndex = children.size();
+ children.append(child);
+}
+
+/*!
+ \internal
+*/
+void QGraphicsItemPrivate::removeChild(QGraphicsItem *child)
+{
+ int idx = child->d_ptr->siblingIndex;
+ int size = children.size();
+ for (int i = idx; i < size - 1; ++i) {
+ QGraphicsItem *p = children[i + 1];
+ children[i] = p;
+ p->d_ptr->siblingIndex = i;
+ }
+ children.removeLast();
+}
+
+/*!
+ \internal
+*/
+QGraphicsItemCache *QGraphicsItemPrivate::maybeExtraItemCache() const
+{
+ return (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData));
+}
+
+/*!
+ \internal
+*/
QGraphicsItemCache *QGraphicsItemPrivate::extraItemCache() const
{
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData));
@@ -3821,6 +3948,9 @@ QGraphicsItemCache *QGraphicsItemPrivate::extraItemCache() const
return c;
}
+/*!
+ \internal
+*/
void QGraphicsItemPrivate::removeExtraItemCache()
{
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData));
@@ -3976,11 +4106,13 @@ void QGraphicsItem::update(const QRectF &rect)
}
// Invalidate cache.
- if (rect.isNull()) {
- cache->allExposed = true;
- cache->exposed.clear();
- } else {
- cache->exposed.append(rect);
+ if (!cache->allExposed) {
+ if (rect.isNull()) {
+ cache->allExposed = true;
+ cache->exposed.clear();
+ } else {
+ cache->exposed.append(rect);
+ }
}
// Only invalidate cache; item is already dirty.
if (d_ptr->dirty)
@@ -3995,6 +4127,45 @@ void QGraphicsItem::update(const QRectF &rect)
d_ptr->scene->itemUpdated(this, rect);
}
+/*!
+ \internal
+
+ Scrolls \a rect in \a pix by \a dx, \a dy.
+
+ ### This can be done much more efficiently by using XCopyArea on X11 with
+ the same dst and src, and through moving pixels in the raster engine. It
+ can probably also be done much better on the other paint engines.
+*/
+void _q_scrollPixmap(QPixmap *pix, const QRect &rect, int dx, int dy)
+{
+#if 0
+ QPainter painter(pix);
+ painter.setClipRect(rect);
+ painter.drawPixmap(rect.translated(dx, dy), *pix, rect);
+ painter.end();
+#elif defined Q_WS_X11
+ GC gc = XCreateGC(X11->display, pix->handle(), 0, 0);
+
+ XRectangle xrect;
+ xrect.x = rect.x();
+ xrect.y = rect.y();
+ xrect.width = rect.width();
+ xrect.height = rect.height();
+ XSetClipRectangles(X11->display, gc, 0, 0, &xrect, 1, YXBanded);
+
+ XCopyArea(X11->display, pix->handle(), pix->handle(), gc,
+ rect.x(), rect.y(), rect.width(), rect.height(),
+ rect.x()+dx, rect.y()+dy);
+ XFreeGC(X11->display, gc);
+#else
+ QPixmap newPix = *pix;
+ QPainter painter(&newPix);
+ painter.setClipRect(rect);
+ painter.drawPixmap(rect.translated(dx, dy), *pix, rect);
+ painter.end();
+ *pix = newPix;
+#endif
+}
/*!
\since 4.4
@@ -4023,11 +4194,45 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)
if (!d->scene)
return;
if (d->cacheMode != NoCache) {
- // ### This is very slow, and can be done much better. If the cache is
- // local and matches the below criteria for rotation and scaling, we
- // can easily scroll. And if the cache is in device coordinates, we
- // can scroll both the viewport and the cache.
- update(rect);
+ QGraphicsItemCache *c;
+ bool scrollCache = qFuzzyIsNull(dx - int(dx)) && qFuzzyIsNull(dy - int(dy))
+ && (c = (QGraphicsItemCache *)qVariantValue<void *>(d_ptr->extra(QGraphicsItemPrivate::ExtraCacheData)))
+ && (d->cacheMode == ItemCoordinateCache && !c->fixedSize.isValid());
+ if (scrollCache) {
+ QPixmap pix;
+ if (QPixmapCache::find(c->key, &pix)) {
+ // Adjust with 2 pixel margin. Notice the loss of precision
+ // when converting to QRect.
+ int adjust = 2;
+ QRectF br = boundingRect().adjusted(-adjust, -adjust, adjust, adjust);
+ QRect irect = rect.toRect().translated(-br.x(), -br.y());
+
+ _q_scrollPixmap(&pix, irect, dx, dy);
+
+ QPixmapCache::replace(c->key, pix);
+
+ // Translate the existing expose.
+ foreach (QRectF exposedRect, c->exposed)
+ c->exposed += exposedRect.translated(dx, dy) & rect;
+
+ // Calculate exposure.
+ QRegion exposed;
+ QRect r = rect.toRect();
+ exposed += r;
+ exposed -= r.translated(dx, dy);
+ foreach (QRect rect, exposed.rects())
+ update(rect);
+ d_ptr->updateHelper();
+ } else {
+ update(rect);
+ }
+ } else {
+ // ### This is very slow, and can be done much better. If the cache is
+ // local and matches the below criteria for rotation and scaling, we
+ // can easily scroll. And if the cache is in device coordinates, we
+ // can scroll both the viewport and the cache.
+ update(rect);
+ }
return;
}
@@ -4184,7 +4389,9 @@ QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPointF &point
*/
QPointF QGraphicsItem::mapToParent(const QPointF &point) const
{
- return d_ptr->pos + (d_ptr->hasTransform ? transform().map(point) : point);
+ if (!d_ptr->hasTransform)
+ return point + d_ptr->pos;
+ return transform().map(point) + d_ptr->pos;
}
/*!
@@ -4249,9 +4456,9 @@ QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QRectF &rect
*/
QPolygonF QGraphicsItem::mapToParent(const QRectF &rect) const
{
- QPolygonF p = !d_ptr->hasTransform ? rect : transform().map(rect);
- p.translate(d_ptr->pos);
- return p;
+ if (!d_ptr->hasTransform)
+ return rect.translated(d_ptr->pos);
+ return transform().map(rect).translated(d_ptr->pos);
}
/*!
@@ -4450,9 +4657,9 @@ QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPolygonF &p
*/
QPolygonF QGraphicsItem::mapToParent(const QPolygonF &polygon) const
{
- QPolygonF p = !d_ptr->hasTransform ? polygon : transform().map(polygon);
- p.translate(d_ptr->pos);
- return p;
+ if (!d_ptr->hasTransform)
+ return polygon.translated(d_ptr->pos);
+ return transform().map(polygon).translated(d_ptr->pos);
}
/*!
@@ -4494,10 +4701,9 @@ QPainterPath QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPainterP
*/
QPainterPath QGraphicsItem::mapToParent(const QPainterPath &path) const
{
- QTransform x = QTransform::fromTranslate(d_ptr->pos.x(), d_ptr->pos.y());
- if (d_ptr->hasTransform)
- x = transform() * x;
- return x.map(path);
+ if (!d_ptr->hasTransform)
+ return path.translated(d_ptr->pos);
+ return transform().map(path).translated(d_ptr->pos);
}
/*!
@@ -4712,9 +4918,9 @@ QPainterPath QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPainte
*/
QPainterPath QGraphicsItem::mapFromParent(const QPainterPath &path) const
{
- if (d_ptr->parent)
- return d_ptr->parent->itemTransform(this).map(path);
- return mapFromScene(path);
+ QPainterPath p(path);
+ p.translate(-d_ptr->pos);
+ return d_ptr->hasTransform ? transform().inverted().map(p) : p;
}
/*!
@@ -5753,7 +5959,7 @@ static void qt_graphicsItem_highlightSelected(
QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
{
const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
- if (qFuzzyCompare(qMax(murect.width(), murect.height()) + 1, 1))
+ if (qFuzzyIsNull(qMax(murect.width(), murect.height())))
return;
const QRectF mbrect = painter->transform().mapRect(item->boundingRect());
@@ -7480,9 +7686,7 @@ void QGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
painter->setRenderHint(QPainter::SmoothPixmapTransform,
(d->transformationMode == Qt::SmoothTransformation));
- QRectF exposed = option->exposedRect.adjusted(-1, -1, 1, 1);
- exposed &= QRectF(d->offset.x(), d->offset.y(), d->pixmap.width(), d->pixmap.height());
- painter->drawPixmap(exposed, d->pixmap, exposed.translated(-d->offset));
+ painter->drawPixmap(d->offset, d->pixmap);
if (option->state & QStyle::State_Selected)
qt_graphicsItem_highlightSelected(this, painter, option);
@@ -7648,6 +7852,7 @@ QGraphicsTextItem::QGraphicsTextItem(const QString &text, QGraphicsItem *parent
setPlainText(text);
setAcceptDrops(true);
setAcceptHoverEvents(true);
+ setFlags(ItemUsesExtendedStyleOption);
}
/*!
@@ -7667,6 +7872,7 @@ QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem *parent
dd->qq = this;
setAcceptDrops(true);
setAcceptHoverEvents(true);
+ setFlag(ItemUsesExtendedStyleOption);
}
/*!
@@ -9012,6 +9218,9 @@ QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag)
case QGraphicsItem::ItemStacksBehindParent:
str = "ItemStacksBehindParent";
break;
+ case QGraphicsItem::ItemUsesExtendedStyleOption:
+ str = "ItemUsesExtendedStyleOption";
+ break;
}
debug << str;
return debug;
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index b98882d..0a0179e 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -94,7 +94,9 @@ public:
ItemIgnoresTransformations = 0x20,
ItemIgnoresParentOpacity = 0x40,
ItemDoesntPropagateOpacityToChildren = 0x80,
- ItemStacksBehindParent = 0x100
+ ItemStacksBehindParent = 0x100,
+ ItemUsesExtendedStyleOption = 0x200
+ // NB! Don't forget to increase the d_ptr->flags bit field by 1 when adding a new flag.
};
Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index 9ce1bbf..820ef04 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -54,6 +54,7 @@
//
#include "qgraphicsitem.h"
+#include "qpixmapcache.h"
#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
@@ -69,13 +70,14 @@ public:
// ItemCoordinateCache only
QRect boundingRect;
QSize fixedSize;
- QString key;
+ QPixmapCache::Key key;
// DeviceCoordinateCache only
struct DeviceData {
+ DeviceData() {}
QTransform lastTransform;
QPoint cacheIndent;
- QString key;
+ QPixmapCache::Key key;
};
QMap<QPaintDevice *, DeviceData> deviceData;
@@ -113,6 +115,7 @@ public:
: z(0),
scene(0),
parent(0),
+ siblingIndex(-1),
index(-1),
depth(0),
acceptedMouseButtons(0x1f),
@@ -131,7 +134,6 @@ public:
ancestorFlags(0),
cacheMode(0),
hasBoundingRegionGranularity(0),
- flags(0),
hasOpacity(0),
hasEffectiveOpacity(0),
isWidget(0),
@@ -141,6 +143,7 @@ public:
dirtyClipPath(1),
emptyClipPath(0),
inSetPosHelper(0),
+ flags(0),
allChildrenCombineOpacity(1),
globalStackingOrder(-1),
sceneTransformIndex(-1),
@@ -173,6 +176,12 @@ public:
void resolveEffectiveOpacity(qreal effectiveParentOpacity);
void resolveDepth(int parentDepth);
void invalidateSceneTransformCache();
+ void addChild(QGraphicsItem *child);
+ void removeChild(QGraphicsItem *child);
+ void setParentItemHelper(QGraphicsItem *parent, bool deleting);
+ void childrenBoundingRectHelper(QTransform *x, QRectF *rect);
+ void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform,
+ const QRegion &exposedRegion, bool allItems = false) const;
virtual void resolveFont(uint inheritedMask)
{
@@ -238,6 +247,7 @@ public:
};
QList<ExtraStruct> extras;
+ QGraphicsItemCache *maybeExtraItemCache() const;
QGraphicsItemCache *extraItemCache() const;
void removeExtraItemCache();
@@ -263,7 +273,7 @@ public:
void updateCachedClipPathFromSetPosHelper(const QPointF &newPos);
inline bool isFullyTransparent() const
- { return hasEffectiveOpacity && qFuzzyCompare(q_func()->effectiveOpacity() + 1, qreal(1.0)); }
+ { return hasEffectiveOpacity && qFuzzyIsNull(q_func()->effectiveOpacity()); }
inline bool childrenCombineOpacity() const
{ return allChildrenCombineOpacity || children.isEmpty(); }
@@ -287,10 +297,11 @@ public:
QGraphicsScene *scene;
QGraphicsItem *parent;
QList<QGraphicsItem *> children;
+ int siblingIndex;
int index;
int depth;
- // Packed 32 bytes
+ // Packed 32 bits
quint32 acceptedMouseButtons : 5;
quint32 visible : 1;
quint32 explicitlyHidden : 1;
@@ -307,9 +318,6 @@ public:
quint32 ancestorFlags : 3;
quint32 cacheMode : 2;
quint32 hasBoundingRegionGranularity : 1;
- quint32 flags : 9;
-
- // New 32 bytes
quint32 hasOpacity : 1;
quint32 hasEffectiveOpacity : 1;
quint32 isWidget : 1;
@@ -319,7 +327,11 @@ public:
quint32 dirtyClipPath : 1;
quint32 emptyClipPath : 1;
quint32 inSetPosHelper : 1;
+
+ // New 32 bits
+ quint32 flags : 10;
quint32 allChildrenCombineOpacity : 1;
+ quint32 padding : 21; // feel free to use
// Optional stacking order
int globalStackingOrder;
diff --git a/src/gui/graphicsview/qgraphicslayoutitem.cpp b/src/gui/graphicsview/qgraphicslayoutitem.cpp
index eaa97ff..e058292 100644
--- a/src/gui/graphicsview/qgraphicslayoutitem.cpp
+++ b/src/gui/graphicsview/qgraphicslayoutitem.cpp
@@ -108,13 +108,22 @@ static void normalizeHints(qreal &minimum, qreal &preferred, qreal &maximum, qre
\internal
*/
QGraphicsLayoutItemPrivate::QGraphicsLayoutItemPrivate(QGraphicsLayoutItem *par, bool layout)
- : parent(par), isLayout(layout), ownedByLayout(false), graphicsItem(0)
+ : parent(par), userSizeHints(0), isLayout(layout), ownedByLayout(false), graphicsItem(0)
{
}
/*!
\internal
*/
+QGraphicsLayoutItemPrivate::~QGraphicsLayoutItemPrivate()
+{
+ // Remove any lazily allocated data
+ delete[] userSizeHints;
+}
+
+/*!
+ \internal
+*/
void QGraphicsLayoutItemPrivate::init()
{
sizeHintCacheDirty = true;
@@ -132,7 +141,8 @@ QSizeF *QGraphicsLayoutItemPrivate::effectiveSizeHints(const QSizeF &constraint)
for (int i = 0; i < Qt::NSizeHints; ++i) {
cachedSizeHints[i] = constraint;
- combineSize(cachedSizeHints[i], userSizeHints[i]);
+ if (userSizeHints)
+ combineSize(cachedSizeHints[i], userSizeHints[i]);
}
QSizeF &minS = cachedSizeHints[Qt::MinimumSize];
@@ -198,6 +208,58 @@ QGraphicsItem *QGraphicsLayoutItemPrivate::parentItem() const
}
/*!
+ \internal
+
+ Ensures that userSizeHints is allocated.
+ This function must be called before any dereferencing.
+*/
+void QGraphicsLayoutItemPrivate::ensureUserSizeHints()
+{
+ if (!userSizeHints)
+ userSizeHints = new QSizeF[Qt::NSizeHints];
+}
+
+/*!
+ \internal
+
+ Sets the user size hint \a which to \a size. Use an invalid size to unset the size hint.
+ */
+void QGraphicsLayoutItemPrivate::setSize(Qt::SizeHint which, const QSizeF &size)
+{
+ Q_Q(QGraphicsLayoutItem);
+
+ if (userSizeHints) {
+ if (size == userSizeHints[which])
+ return;
+ } else if (!size.isValid()) {
+ return;
+ }
+
+ ensureUserSizeHints();
+ userSizeHints[which] = size;
+ q->updateGeometry();
+}
+
+/*!
+ \internal
+
+ Sets the width of the user size hint \a which to \a width.
+ */
+void QGraphicsLayoutItemPrivate::setSizeComponent(
+ Qt::SizeHint which, SizeComponent component, qreal value)
+{
+ Q_Q(QGraphicsLayoutItem);
+ ensureUserSizeHints();
+ qreal &userValue = (component == Width)
+ ? userSizeHints[which].rwidth()
+ : userSizeHints[which].rheight();
+ if (value == userValue)
+ return;
+ userValue = value;
+ q->updateGeometry();
+}
+
+/*!
\class QGraphicsLayoutItem
\brief The QGraphicsLayoutItem class can be inherited to allow your custom
items to be managed by layouts.
@@ -381,12 +443,7 @@ QSizePolicy QGraphicsLayoutItem::sizePolicy() const
*/
void QGraphicsLayoutItem::setMinimumSize(const QSizeF &size)
{
- Q_D(QGraphicsLayoutItem);
- if (size == d->userSizeHints[Qt::MinimumSize])
- return;
-
- d->userSizeHints[Qt::MinimumSize] = size;
- updateGeometry();
+ d_ptr->setSize(Qt::MinimumSize, size);
}
/*!
@@ -416,12 +473,7 @@ QSizeF QGraphicsLayoutItem::minimumSize() const
*/
void QGraphicsLayoutItem::setMinimumWidth(qreal width)
{
- Q_D(QGraphicsLayoutItem);
- qreal &userSizeHint = d->userSizeHints[Qt::MinimumSize].rwidth();
- if (width == userSizeHint)
- return;
- userSizeHint = width;
- updateGeometry();
+ d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Width, width);
}
/*!
@@ -431,12 +483,7 @@ void QGraphicsLayoutItem::setMinimumWidth(qreal width)
*/
void QGraphicsLayoutItem::setMinimumHeight(qreal height)
{
- Q_D(QGraphicsLayoutItem);
- qreal &userSizeHint = d->userSizeHints[Qt::MinimumSize].rheight();
- if (height == userSizeHint)
- return;
- userSizeHint = height;
- updateGeometry();
+ d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Height, height);
}
@@ -450,12 +497,7 @@ void QGraphicsLayoutItem::setMinimumHeight(qreal height)
*/
void QGraphicsLayoutItem::setPreferredSize(const QSizeF &size)
{
- Q_D(QGraphicsLayoutItem);
- if (size == d->userSizeHints[Qt::PreferredSize])
- return;
-
- d->userSizeHints[Qt::PreferredSize] = size;
- updateGeometry();
+ d_ptr->setSize(Qt::PreferredSize, size);
}
/*!
@@ -485,12 +527,7 @@ QSizeF QGraphicsLayoutItem::preferredSize() const
*/
void QGraphicsLayoutItem::setPreferredHeight(qreal height)
{
- Q_D(QGraphicsLayoutItem);
- qreal &userSizeHint = d->userSizeHints[Qt::PreferredSize].rheight();
- if (height == userSizeHint)
- return;
- userSizeHint = height;
- updateGeometry();
+ d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Height, height);
}
/*!
@@ -500,12 +537,7 @@ void QGraphicsLayoutItem::setPreferredHeight(qreal height)
*/
void QGraphicsLayoutItem::setPreferredWidth(qreal width)
{
- Q_D(QGraphicsLayoutItem);
- qreal &userSizeHint = d->userSizeHints[Qt::PreferredSize].rwidth();
- if (width == userSizeHint)
- return;
- userSizeHint = width;
- updateGeometry();
+ d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Width, width);
}
/*!
@@ -519,12 +551,7 @@ void QGraphicsLayoutItem::setPreferredWidth(qreal width)
*/
void QGraphicsLayoutItem::setMaximumSize(const QSizeF &size)
{
- Q_D(QGraphicsLayoutItem);
- if (size == d->userSizeHints[Qt::MaximumSize])
- return;
-
- d->userSizeHints[Qt::MaximumSize] = size;
- updateGeometry();
+ d_ptr->setSize(Qt::MaximumSize, size);
}
/*!
@@ -554,12 +581,7 @@ QSizeF QGraphicsLayoutItem::maximumSize() const
*/
void QGraphicsLayoutItem::setMaximumWidth(qreal width)
{
- Q_D(QGraphicsLayoutItem);
- qreal &userSizeHint = d->userSizeHints[Qt::MaximumSize].rwidth();
- if (width == userSizeHint)
- return;
- userSizeHint = width;
- updateGeometry();
+ d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Width, width);
}
/*!
@@ -569,12 +591,7 @@ void QGraphicsLayoutItem::setMaximumWidth(qreal width)
*/
void QGraphicsLayoutItem::setMaximumHeight(qreal height)
{
- Q_D(QGraphicsLayoutItem);
- qreal &userSizeHint = d->userSizeHints[Qt::MaximumSize].rheight();
- if (height == userSizeHint)
- return;
- userSizeHint = height;
- updateGeometry();
+ d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Height, height);
}
/*!
@@ -732,6 +749,11 @@ QRectF QGraphicsLayoutItem::contentsRect() const
*/
QSizeF QGraphicsLayoutItem::effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
+ Q_D(const QGraphicsLayoutItem);
+
+ if (!d->userSizeHints && constraint.isValid())
+ return constraint;
+
// ### should respect size policy???
return d_ptr->effectiveSizeHints(constraint)[which];
}
diff --git a/src/gui/graphicsview/qgraphicslayoutitem_p.h b/src/gui/graphicsview/qgraphicslayoutitem_p.h
index fab0f39..dc044e6 100644
--- a/src/gui/graphicsview/qgraphicslayoutitem_p.h
+++ b/src/gui/graphicsview/qgraphicslayoutitem_p.h
@@ -63,16 +63,20 @@ class Q_AUTOTEST_EXPORT QGraphicsLayoutItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsLayoutItem)
public:
- virtual ~QGraphicsLayoutItemPrivate() {}
+ virtual ~QGraphicsLayoutItemPrivate();
QGraphicsLayoutItemPrivate(QGraphicsLayoutItem *parent, bool isLayout);
void init();
QSizeF *effectiveSizeHints(const QSizeF &constraint) const;
QGraphicsItem *parentItem() const;
+ void ensureUserSizeHints();
+ void setSize(Qt::SizeHint which, const QSizeF &size);
+ enum SizeComponent { Width, Height };
+ void setSizeComponent(Qt::SizeHint which, SizeComponent component, qreal value);
QSizePolicy sizePolicy;
QGraphicsLayoutItem *parent;
- QSizeF userSizeHints[Qt::NSizeHints];
+ QSizeF *userSizeHints;
mutable QSizeF cachedSizeHints[Qt::NSizeHints];
mutable QSizeF cachedConstraint;
diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp
index e660879..01b7593 100644
--- a/src/gui/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp
@@ -460,7 +460,7 @@ void QGraphicsProxyWidgetPrivate::embedSubWindow(QWidget *subWin)
{
QWExtra *extra;
if (!((extra = subWin->d_func()->extra) && extra->proxyWidget)) {
- QGraphicsProxyWidget *subProxy = new QGraphicsProxyWidget(q_func());
+ QGraphicsProxyWidget *subProxy = new QGraphicsProxyWidget(q_func(), subWin->windowFlags());
subProxy->d_func()->setWidget_helper(subWin, false);
}
}
@@ -544,6 +544,9 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget()
hidden or disabled after embedding is complete. The class documentation
has a full overview over the shared state.
+ QGraphicsProxyWidget's window flags determine whether the widget, after
+ embedding, will be given window decorations or not.
+
After this function returns, QGraphicsProxyWidget will keep its state
synchronized with that of \a widget whenever possible.
@@ -661,10 +664,6 @@ void QGraphicsProxyWidgetPrivate::setWidget_helper(QWidget *newWidget, bool auto
if (newWidget->testAttribute(Qt::WA_SetCursor))
q->setCursor(widget->cursor());
#endif
- Qt::WFlags flags = newWidget->windowFlags();
- if (newWidget->windowType() == Qt::Window)
- flags &= ~Qt::Window;
- q->setWindowFlags(flags);
q->setEnabled(newWidget->isEnabled());
q->setVisible(newWidget->isVisible());
q->setLayoutDirection(newWidget->layoutDirection());
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index b89e352..1fbda85 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -351,6 +351,8 @@ QGraphicsScenePrivate::QGraphicsScenePrivate()
dragDropItem(0),
enterWidget(0),
lastDropAction(Qt::IgnoreAction),
+ allItemsIgnoreHoverEvents(true),
+ allItemsUseDefaultCursor(true),
painterStateProtection(true),
sortCacheEnabled(false),
updatingSortCache(false),
@@ -622,6 +624,30 @@ void QGraphicsScenePrivate::_q_emitUpdated()
/*!
\internal
+*/
+void QGraphicsScenePrivate::registerTopLevelItem(QGraphicsItem *item)
+{
+ item->d_ptr->siblingIndex = topLevelItems.size();
+ topLevelItems.append(item);
+}
+
+/*!
+ \internal
+*/
+void QGraphicsScenePrivate::unregisterTopLevelItem(QGraphicsItem *item)
+{
+ int idx = item->d_ptr->siblingIndex;
+ int size = topLevelItems.size();
+ for (int i = idx; i < size - 1; ++i) {
+ QGraphicsItem *p = topLevelItems[i + 1];
+ topLevelItems[i] = p;
+ p->d_ptr->siblingIndex = i;
+ }
+ topLevelItems.removeLast();
+}
+
+/*!
+ \internal
Updates all items in the pending update list. At this point, the list is
unlikely to contain partially constructed items.
@@ -756,10 +782,6 @@ void QGraphicsScenePrivate::_q_removeItemLater(QGraphicsItem *item)
freeSceneTransformSlots.append(transformIndex);
}
- // Remove all children recursively.
- foreach (QGraphicsItem *child, item->children())
- _q_removeItemLater(child);
-
// Reset the mouse grabber
if (mouseGrabberItems.contains(item))
ungrabMouse(item, /* item is dying */ true);
@@ -880,11 +902,18 @@ void QGraphicsScenePrivate::grabMouse(QGraphicsItem *item, bool implicit)
{
// Append to list of mouse grabber items, and send a mouse grab event.
if (mouseGrabberItems.contains(item)) {
- if (mouseGrabberItems.last() == item)
- qWarning("QGraphicsItem::grabMouse: already a mouse grabber");
- else
+ if (mouseGrabberItems.last() == item) {
+ Q_ASSERT(!implicit);
+ if (!lastMouseGrabberItemHasImplicitMouseGrab) {
+ qWarning("QGraphicsItem::grabMouse: already a mouse grabber");
+ } else {
+ // Upgrade to an explicit mouse grab
+ lastMouseGrabberItemHasImplicitMouseGrab = false;
+ }
+ } else {
qWarning("QGraphicsItem::grabMouse: already blocked by mouse grabber: %p",
mouseGrabberItems.last());
+ }
return;
}
@@ -1036,6 +1065,12 @@ void QGraphicsScenePrivate::clearKeyboardGrabber()
ungrabKeyboard(keyboardGrabberItems.first());
}
+void QGraphicsScenePrivate::enableMouseTrackingOnViews()
+{
+ foreach (QGraphicsView *view, views)
+ view->viewport()->setMouseTracking(true);
+}
+
/*!
Returns all items for the screen position in \a event.
*/
@@ -1294,7 +1329,8 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
// check if the item we are sending to are disabled (before we send the event)
bool disabled = !item->isEnabled();
bool isWindow = item->isWindow();
- if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick && item != lastMouseGrabberItem) {
+ if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick
+ && item != lastMouseGrabberItem && lastMouseGrabberItem) {
// If this item is different from the item that received the last
// mouse event, and mouseEvent is a doubleclick event, then the
// event is converted to a press. Known limitation:
@@ -1831,7 +1867,7 @@ inline bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item
if (f1 != f2) return f2;
qreal z1 = d1->z;
qreal z2 = d2->z;
- return z1 != z2 ? z1 > z2 : item1 > item2;
+ return z1 != z2 ? z1 > z2 : d1->siblingIndex > d2->siblingIndex;
}
/*!
@@ -2211,8 +2247,6 @@ void QGraphicsScene::setSceneRect(const QRectF &rect)
void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRectF &source,
Qt::AspectRatioMode aspectRatioMode)
{
- Q_D(QGraphicsScene);
-
// Default source rect = scene rect
QRectF sourceRect = source;
if (sourceRect.isNull())
@@ -2269,36 +2303,8 @@ void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRect
// Generate the style options
QStyleOptionGraphicsItem *styleOptionArray = new QStyleOptionGraphicsItem[numItems];
- for (int i = 0; i < numItems; ++i) {
- QGraphicsItem *item = itemArray[i];
-
- QStyleOptionGraphicsItem option;
- option.state = QStyle::State_None;
- option.rect = item->boundingRect().toRect();
- if (item->isSelected())
- option.state |= QStyle::State_Selected;
- if (item->isEnabled())
- option.state |= QStyle::State_Enabled;
- if (item->hasFocus())
- option.state |= QStyle::State_HasFocus;
- if (d->hoverItems.contains(item))
- option.state |= QStyle::State_MouseOver;
- if (item == mouseGrabberItem())
- option.state |= QStyle::State_Sunken;
-
- // Calculate a simple level-of-detail metric.
- // ### almost identical code in QGraphicsView::paintEvent()
- // and QGraphicsView::render() - consider refactoring
- QTransform itemToDeviceTransform = item->deviceTransform(painterTransform);
-
- option.levelOfDetail = qSqrt(itemToDeviceTransform.map(v1).length() * itemToDeviceTransform.map(v2).length());
- option.matrix = itemToDeviceTransform.toAffine(); //### discards perspective
-
- option.exposedRect = item->boundingRect();
- option.exposedRect &= itemToDeviceTransform.inverted().mapRect(targetRect);
-
- styleOptionArray[i] = option;
- }
+ for (int i = 0; i < numItems; ++i)
+ itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterTransform, targetRect.toRect());
// Render the scene.
drawBackground(painter, sourceRect);
@@ -2742,12 +2748,13 @@ void QGraphicsScene::clear()
}
d->unindexedItems.clear();
qDeleteAll(unindexedParents);
-
d->indexedItems.clear();
d->freeItemIndexes.clear();
d->lastItemCount = 0;
d->bspTree.clear();
d->largestUntransformableItem = QRectF();
+ d->allItemsIgnoreHoverEvents = true;
+ d->allItemsUseDefaultCursor = true;
}
/*!
@@ -2851,7 +2858,6 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
qWarning("QGraphicsScene::addItem: item has already been added to this scene");
return;
}
-
// Remove this item from its existing scene
if (QGraphicsScene *oldScene = item->scene())
oldScene->removeItem(item);
@@ -2892,6 +2898,10 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
item->d_func()->index = -1;
d->startIndexTimer();
+ // Add to list of toplevels if this item is a toplevel.
+ if (!item->d_ptr->parent)
+ d->registerTopLevelItem(item);
+
// Update the scene's sort cache settings.
item->d_ptr->globalStackingOrder = -1;
d->invalidateSortCache();
@@ -2909,6 +2919,17 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
++d->selectionChanging;
int oldSelectedItemSize = d->selectedItems.size();
+ // Enable mouse tracking if the item accepts hover events or has a cursor set.
+ if (d->allItemsIgnoreHoverEvents && d->itemAcceptsHoverEvents_helper(item)) {
+ d->allItemsIgnoreHoverEvents = false;
+ d->enableMouseTrackingOnViews();
+ }
+ if (d->allItemsUseDefaultCursor && item->hasCursor()) {
+ d->allItemsUseDefaultCursor = false;
+ if (d->allItemsIgnoreHoverEvents) // already enabled otherwise
+ d->enableMouseTrackingOnViews();
+ }
+
// Update selection lists
if (item->isSelected())
d->selectedItems << item;
@@ -3244,13 +3265,15 @@ void QGraphicsScene::removeItem(QGraphicsItem *item)
// Set the item's scene ptr to 0.
item->d_func()->scene = 0;
- // Detach the item from its parent.
+ // Remove from parent, or unregister from toplevels.
if (QGraphicsItem *parentItem = item->parentItem()) {
if (parentItem->scene()) {
Q_ASSERT_X(parentItem->scene() == this, "QGraphicsScene::removeItem",
"Parent item's scene is different from this item's scene");
item->setParentItem(0);
}
+ } else {
+ d->unregisterTopLevelItem(item);
}
// Remove from our item lists.
@@ -4209,6 +4232,9 @@ bool QGraphicsScenePrivate::itemAcceptsHoverEvents_helper(const QGraphicsItem *i
*/
bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent)
{
+ if (allItemsIgnoreHoverEvents)
+ return false;
+
// Find the first item that accepts hover events, reusing earlier
// calculated data is possible.
if (cachedItemsUnderMouse.isEmpty()) {
@@ -4608,7 +4634,7 @@ static void _q_paintItem(QGraphicsItem *item, QPainter *painter,
? proxy->widget()->windowOpacity() : 1.0;
const qreal oldPainterOpacity = painter->opacity();
- if (qFuzzyCompare(windowOpacity + 1, qreal(1.0)))
+ if (qFuzzyIsNull(windowOpacity))
return;
// Set new painter opacity.
if (windowOpacity < 1.0)
@@ -4717,8 +4743,9 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
return;
// Fetch the off-screen transparent buffer and exposed area info.
- QString pixmapKey;
+ QPixmapCache::Key pixmapKey;
QPixmap pix;
+ bool pixmapFound;
QGraphicsItemCache *itemCache = itemd->extraItemCache();
if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
if (itemCache->boundingRect != brect.toRect()) {
@@ -4728,17 +4755,14 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
}
pixmapKey = itemCache->key;
} else {
- if ((pixmapKey = itemCache->deviceData.value(widget).key).isEmpty()) {
- pixmapKey.sprintf("qgv-%p-%p", item, widget);
- QGraphicsItemCache::DeviceData data;
- data.key = pixmapKey;
- itemCache->deviceData.insert(widget, data);
- }
+ pixmapKey = itemCache->deviceData.value(widget).key;
}
// Find pixmap in cache.
if (!itemCache->allExposed)
- QPixmapCache::find(pixmapKey, pix);
+ pixmapFound = QPixmapCache::find(pixmapKey, &pix);
+ else
+ pixmapFound = false;
// Render using item coordinate cache mode.
if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
@@ -4791,8 +4815,12 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
_q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(),
&cacheOption, painterStateProtection);
- // Reinsert this pixmap into the cache.
- QPixmapCache::insert(pixmapKey, pix);
+ if (!pixmapFound) {
+ // insert this pixmap into the cache.
+ itemCache->key = QPixmapCache::insert(pix);
+ } else {
+ QPixmapCache::replace(pixmapKey, pix);
+ }
// Reset expose data.
itemCache->allExposed = false;
@@ -4959,8 +4987,13 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
}
if (pixModified) {
- // Reinsert this pixmap into the cache
- QPixmapCache::insert(pixmapKey, pix);
+ if (!pixmapFound) {
+ // Insert this pixmap into the cache.
+ deviceData->key = QPixmapCache::insert(pix);
+ } else {
+ //otherwise we replace the pixmap in the cache
+ QPixmapCache::replace(pixmapKey, pix);
+ }
}
// Redraw the exposed area using an untransformed painter. This
@@ -5242,7 +5275,7 @@ void QGraphicsScene::itemUpdated(QGraphicsItem *item, const QRectF &rect)
// Deliver the actual update.
if (!d->updateAll) {
if (d->views.isEmpty() || ((d->connectedSignals & d->changedSignalMask) && !item->d_ptr->itemIsUntransformable()
- && qFuzzyCompare(item->boundingRegionGranularity(), qreal(0.0)))) {
+ && qFuzzyIsNull(item->boundingRegionGranularity()))) {
// This block of code is kept for compatibility. Since 4.5, by default
// QGraphicsView does not connect the signal and we use the below
// method of delivering updates.
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index befbbd8..9ace725 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -113,7 +113,10 @@ public:
QList<QGraphicsItem *> dirtyItems;
QList<QGraphicsItem *> pendingUpdateItems;
QList<QGraphicsItem *> unpolishedItems;
+ QList<QGraphicsItem *> topLevelItems;
QMap<QGraphicsItem *, QPointF> movingItemsInitialPositions;
+ void registerTopLevelItem(QGraphicsItem *item);
+ void unregisterTopLevelItem(QGraphicsItem *item);
void _q_updateLater();
void _q_polishItems();
@@ -165,6 +168,9 @@ public:
Qt::DropAction lastDropAction;
QList<QGraphicsItem *> cachedItemsUnderMouse;
QList<QGraphicsItem *> hoverItems;
+ bool allItemsIgnoreHoverEvents;
+ bool allItemsUseDefaultCursor;
+ void enableMouseTrackingOnViews();
QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownPos;
QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownScenePos;
QMap<Qt::MouseButton, QPoint> mouseGrabberButtonDownScreenPos;
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index a795fb4..396618c 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -614,6 +614,16 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
}
#ifndef QT_NO_CURSOR
+ // If all the items ignore hover events, we don't look-up any items
+ // in QGraphicsScenePrivate::dispatchHoverEvent, hence the
+ // cachedItemsUnderMouse list will be empty. We therefore do the look-up
+ // for cursor items here if not all items use the default cursor.
+ if (scene->d_func()->allItemsIgnoreHoverEvents && !scene->d_func()->allItemsUseDefaultCursor
+ && scene->d_func()->cachedItemsUnderMouse.isEmpty()) {
+ scene->d_func()->cachedItemsUnderMouse = scene->d_func()->itemsAtPosition(mouseEvent.screenPos(),
+ mouseEvent.scenePos(),
+ mouseEvent.widget());
+ }
// Find the topmost item under the mouse with a cursor.
foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) {
if (item->hasCursor()) {
@@ -1061,7 +1071,7 @@ QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedReg
// Step 1) If all items are contained within the expose region, then
// return a list of all visible items.
- const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 2, 2))
+ const QRectF exposedRegionSceneBounds = q->mapToScene(exposedRegion.boundingRect().adjusted(-1, -1, 1, 1))
.boundingRect();
if (exposedRegionSceneBounds.contains(scene->d_func()->growingItemsBoundingRect)) {
Q_ASSERT(allItems);
@@ -1117,69 +1127,6 @@ QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedReg
return itemsInArea(exposedPath, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder);
}
-void QGraphicsViewPrivate::generateStyleOptions(const QList<QGraphicsItem *> &itemList,
- QGraphicsItem **itemArray,
- QStyleOptionGraphicsItem *styleOptionArray,
- const QTransform &worldTransform,
- bool allItems,
- const QRegion &exposedRegion) const
-{
- // Two unit vectors.
- QLineF v1(0, 0, 1, 0);
- QLineF v2(0, 0, 0, 1);
- QTransform itemToViewportTransform;
- QRectF brect;
- QTransform reverseMap;
-
- for (int i = 0; i < itemList.size(); ++i) {
- QGraphicsItem *item = itemArray[i] = itemList[i];
-
- QStyleOptionGraphicsItem &option = styleOptionArray[i];
- brect = item->boundingRect();
- option.state = QStyle::State_None;
- option.rect = brect.toRect();
- option.exposedRect = QRectF();
- if (item->d_ptr->selected)
- option.state |= QStyle::State_Selected;
- if (item->d_ptr->enabled)
- option.state |= QStyle::State_Enabled;
- if (item->hasFocus())
- option.state |= QStyle::State_HasFocus;
- if (scene->d_func()->hoverItems.contains(item))
- option.state |= QStyle::State_MouseOver;
- if (item == scene->mouseGrabberItem())
- option.state |= QStyle::State_Sunken;
-
- // Calculate a simple level-of-detail metric.
- // ### almost identical code in QGraphicsScene::render()
- // and QGraphicsView::render() - consider refactoring
- itemToViewportTransform = item->deviceTransform(worldTransform);
-
- if (itemToViewportTransform.type() <= QTransform::TxTranslate) {
- // Translation and rotation only? The LOD is 1.
- option.levelOfDetail = 1;
- } else {
- // LOD is the transformed area of a 1x1 rectangle.
- option.levelOfDetail = qSqrt(itemToViewportTransform.map(v1).length() * itemToViewportTransform.map(v2).length());
- }
- option.matrix = itemToViewportTransform.toAffine(); //### discards perspective
-
- if (!allItems) {
- // Determine the item's exposed area
- reverseMap = itemToViewportTransform.inverted();
- foreach (const QRect &rect, exposedRegion.rects()) {
- option.exposedRect |= reverseMap.mapRect(QRectF(rect.adjusted(-1, -1, 1, 1)));
- if (option.exposedRect.contains(brect))
- break;
- }
- option.exposedRect &= brect;
- } else {
- // The whole item is exposed
- option.exposedRect = brect;
- }
- }
-}
-
/*!
Constructs a QGraphicsView. \a parent is passed to QWidget's constructor.
*/
@@ -1689,6 +1636,12 @@ void QGraphicsView::setScene(QGraphicsScene *scene)
d->recalculateContentSize();
d->lastCenterPoint = sceneRect().center();
d->keepLastCenterPoint = true;
+ // We are only interested in mouse tracking if items accept
+ // hover events or use non-default cursors.
+ if (!d->scene->d_func()->allItemsIgnoreHoverEvents
+ || !d->scene->d_func()->allItemsUseDefaultCursor) {
+ d->viewport->setMouseTracking(true);
+ }
} else {
d->recalculateContentSize();
}
@@ -2130,40 +2083,10 @@ void QGraphicsView::render(QPainter *painter, const QRectF &target, const QRect
.scale(xratio, yratio)
.translate(-sourceRect.left(), -sourceRect.top());
- // Two unit vectors.
- QLineF v1(0, 0, 1, 0);
- QLineF v2(0, 0, 0, 1);
-
// Generate the style options
QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
- QStyleOptionGraphicsItem* option = styleOptionArray;
- for (int i = 0; i < numItems; ++i, ++option) {
- QGraphicsItem *item = itemArray[i];
-
- option->state = QStyle::State_None;
- option->rect = item->boundingRect().toRect();
- if (item->isSelected())
- option->state |= QStyle::State_Selected;
- if (item->isEnabled())
- option->state |= QStyle::State_Enabled;
- if (item->hasFocus())
- option->state |= QStyle::State_HasFocus;
- if (d->scene->d_func()->hoverItems.contains(item))
- option->state |= QStyle::State_MouseOver;
- if (item == d->scene->mouseGrabberItem())
- option->state |= QStyle::State_Sunken;
-
- // Calculate a simple level-of-detail metric.
- // ### almost identical code in QGraphicsScene::render()
- // and QGraphicsView::paintEvent() - consider refactoring
- QTransform itemToViewportTransform = item->deviceTransform(painterMatrix);
-
- option->levelOfDetail = qSqrt(itemToViewportTransform.map(v1).length() * itemToViewportTransform.map(v2).length());
- option->matrix = itemToViewportTransform.toAffine();
-
- option->exposedRect = item->boundingRect();
- option->exposedRect &= itemToViewportTransform.inverted().mapRect(targetRect);
- }
+ for (int i = 0; i < numItems; ++i)
+ itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterMatrix, targetRect.toRect());
painter->save();
@@ -2289,7 +2212,7 @@ QList<QGraphicsItem *> QGraphicsView::items(const QPoint &pos) const
QTransform xinv = viewportTransform().inverted();
return d->scene->items(xinv.mapRect(QRectF(pos.x(), pos.y(), 1, 1)));
}
- return d->scene->items(mapToScene(pos.x(), pos.y(), 2, 2));
+ return d->scene->items(mapToScene(pos.x(), pos.y(), 1, 1));
}
QPainterPath path;
@@ -2451,10 +2374,11 @@ QPolygonF QGraphicsView::mapToScene(const QRect &rect) const
return QPolygonF();
QPointF scrollOffset(d->horizontalScroll(), d->verticalScroll());
- QPointF tl = scrollOffset + rect.topLeft();
- QPointF tr = scrollOffset + rect.topRight();
- QPointF br = scrollOffset + rect.bottomRight();
- QPointF bl = scrollOffset + rect.bottomLeft();
+ QRect r = rect.adjusted(0, 0, 1, 1);
+ QPointF tl = scrollOffset + r.topLeft();
+ QPointF tr = scrollOffset + r.topRight();
+ QPointF br = scrollOffset + r.bottomRight();
+ QPointF bl = scrollOffset + r.bottomLeft();
QPolygonF poly;
poly.resize(4);
@@ -2784,9 +2708,7 @@ void QGraphicsView::setupViewport(QWidget *widget)
const bool isGLWidget = widget->inherits("QGLWidget");
- d->accelerateScrolling = !(isGLWidget
- || widget->testAttribute(Qt::WA_MSWindowsUseDirect3D)
- || qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault));
+ d->accelerateScrolling = !(isGLWidget);
widget->setFocusPolicy(Qt::StrongFocus);
@@ -2795,7 +2717,12 @@ void QGraphicsView::setupViewport(QWidget *widget)
widget->setAutoFillBackground(true);
}
- widget->setMouseTracking(true);
+ // We are only interested in mouse tracking if items
+ // accept hover events or use non-default cursors.
+ if (d->scene && (!d->scene->d_func()->allItemsIgnoreHoverEvents
+ || !d->scene->d_func()->allItemsUseDefaultCursor)) {
+ widget->setMouseTracking(true);
+ }
widget->setAcceptDrops(acceptDrops());
}
@@ -3442,7 +3369,7 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
exposedRegion = viewport()->rect();
else if (d->viewportUpdateMode == BoundingRectViewportUpdate)
exposedRegion = event->rect();
- QRectF exposedSceneRect = mapToScene(exposedRegion.boundingRect().adjusted(0, 0, 1, 1)).boundingRect();
+ QRectF exposedSceneRect = mapToScene(exposedRegion.boundingRect()).boundingRect();
// Set up the painter
QPainter painter(viewport());
@@ -3496,6 +3423,7 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
QPainter backgroundPainter(&d->backgroundPixmap);
backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
backgroundPainter.setTransform(viewportTransform());
+ backgroundPainter.setCompositionMode(QPainter::CompositionMode_Source);
drawBackground(&backgroundPainter, exposedSceneRect);
d->backgroundPixmapExposed = QRegion();
}
@@ -3517,15 +3445,17 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
int backgroundTime = stopWatch.elapsed() - exposedTime;
#endif
- // Generate the style options
- QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
- QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(itemList.size());
-
- d->generateStyleOptions(itemList, itemArray, styleOptionArray, viewTransform,
- allItems, exposedRegion);
-
- // Items
- drawItems(&painter, itemList.size(), itemArray, styleOptionArray);
+ if (!itemList.isEmpty()) {
+ // Generate the style options.
+ const int numItems = itemList.size();
+ QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
+ QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
+ for (int i = 0; i < numItems; ++i)
+ itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], viewTransform, exposedRegion, allItems);
+ // Draw the items.
+ drawItems(&painter, numItems, itemArray, styleOptionArray);
+ d->freeStyleOptionsArray(styleOptionArray);
+ }
#ifdef QGRAPHICSVIEW_DEBUG
int itemsTime = stopWatch.elapsed() - exposedTime - backgroundTime;
@@ -3534,9 +3464,6 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
// Foreground
drawForeground(&painter, exposedSceneRect);
- delete [] itemArray;
- d->freeStyleOptionsArray(styleOptionArray);
-
#ifdef QGRAPHICSVIEW_DEBUG
int foregroundTime = stopWatch.elapsed() - exposedTime - backgroundTime - itemsTime;
#endif
@@ -3648,31 +3575,14 @@ void QGraphicsView::scrollContentsBy(int dx, int dy)
&& X11->use_xrender
#endif
) {
- // Invalidate the background pixmap
- d->backgroundPixmapExposed.translate(dx, 0);
- if (dx > 0) {
- d->backgroundPixmapExposed += QRect(0, 0, dx, viewport()->height());
- } else if (dx < 0) {
- d->backgroundPixmapExposed += QRect(viewport()->width() + dx, 0,
- -dx, viewport()->height());
- }
- d->backgroundPixmapExposed.translate(0, dy);
- if (dy > 0) {
- d->backgroundPixmapExposed += QRect(0, 0, viewport()->width(), dy);
- } else if (dy < 0) {
- d->backgroundPixmapExposed += QRect(0, viewport()->height() + dy,
- viewport()->width(), -dy);
- }
-
// Scroll the background pixmap
- if (!d->backgroundPixmap.isNull()) {
- QPixmap tmp = d->backgroundPixmap.copy();
- QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());
- if (!bgBrush.isOpaque())
- d->backgroundPixmap.fill(Qt::transparent);
- QPainter painter(&d->backgroundPixmap);
- painter.drawPixmap(dx, dy, tmp);
- }
+ QRegion exposed;
+ if (!d->backgroundPixmap.isNull())
+ d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed);
+
+ // Invalidate the background pixmap
+ d->backgroundPixmapExposed.translate(dx, dy);
+ d->backgroundPixmapExposed += exposed;
}
// Always replay on scroll.
diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h
index a76279e..c18f85d 100644
--- a/src/gui/graphicsview/qgraphicsview_p.h
+++ b/src/gui/graphicsview/qgraphicsview_p.h
@@ -63,7 +63,7 @@
QT_BEGIN_NAMESPACE
-class Q_GUI_EXPORT QGraphicsViewPrivate : public QAbstractScrollAreaPrivate
+class QGraphicsViewPrivate : public QAbstractScrollAreaPrivate
{
Q_DECLARE_PUBLIC(QGraphicsView)
public:
@@ -174,13 +174,6 @@ public:
bool updateSceneSlotReimplementedChecked;
QList<QGraphicsItem *> findItems(const QRegion &exposedRegion, bool *allItems) const;
-
- void generateStyleOptions(const QList<QGraphicsItem *> &itemList,
- QGraphicsItem **itemArray,
- QStyleOptionGraphicsItem *styleOptionArray,
- const QTransform &worldTransform,
- bool allItems,
- const QRegion &exposedRegion) const;
};
QT_END_NAMESPACE
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp
index 7f02fb9..702e0b6 100644
--- a/src/gui/graphicsview/qgraphicswidget.cpp
+++ b/src/gui/graphicsview/qgraphicswidget.cpp
@@ -459,17 +459,19 @@ void QGraphicsWidget::setContentsMargins(qreal left, qreal top, qreal right, qre
{
Q_D(QGraphicsWidget);
- if (left == d->leftMargin
- && top == d->topMargin
- && right == d->rightMargin
- && bottom == d->bottomMargin) {
+ if (!d->margins && left == 0 && top == 0 && right == 0 && bottom == 0)
+ return;
+ d->ensureMargins();
+ if (left == d->margins[d->Left]
+ && top == d->margins[d->Top]
+ && right == d->margins[d->Right]
+ && bottom == d->margins[d->Bottom])
return;
- }
- d->leftMargin = left;
- d->topMargin = top;
- d->rightMargin = right;
- d->bottomMargin = bottom;
+ d->margins[d->Left] = left;
+ d->margins[d->Top] = top;
+ d->margins[d->Right] = right;
+ d->margins[d->Bottom] = bottom;
if (QGraphicsLayout *l = d->layout)
l->invalidate();
@@ -490,14 +492,16 @@ void QGraphicsWidget::setContentsMargins(qreal left, qreal top, qreal right, qre
void QGraphicsWidget::getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
{
Q_D(const QGraphicsWidget);
+ if (left || top || right || bottom)
+ d->ensureMargins();
if (left)
- *left = d->leftMargin;
+ *left = d->margins[d->Left];
if (top)
- *top = d->topMargin;
+ *top = d->margins[d->Top];
if (right)
- *right = d->rightMargin;
+ *right = d->margins[d->Right];
if (bottom)
- *bottom = d->bottomMargin;
+ *bottom = d->margins[d->Bottom];
}
/*!
@@ -513,16 +517,23 @@ void QGraphicsWidget::getContentsMargins(qreal *left, qreal *top, qreal *right,
void QGraphicsWidget::setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom)
{
Q_D(QGraphicsWidget);
- bool unchanged = left == d->leftWindowFrameMargin && top == d->topWindowFrameMargin
- && right == d->rightWindowFrameMargin && bottom == d->bottomWindowFrameMargin;
+
+ if (!d->windowFrameMargins && left == 0 && top == 0 && right == 0 && bottom == 0)
+ return;
+ d->ensureWindowFrameMargins();
+ bool unchanged =
+ d->windowFrameMargins[d->Left] == left
+ && d->windowFrameMargins[d->Top] == top
+ && d->windowFrameMargins[d->Right] == right
+ && d->windowFrameMargins[d->Bottom] == bottom;
if (d->setWindowFrameMargins && unchanged)
return;
if (!unchanged)
prepareGeometryChange();
- d->leftWindowFrameMargin = left;
- d->topWindowFrameMargin = top;
- d->rightWindowFrameMargin = right;
- d->bottomWindowFrameMargin = bottom;
+ d->windowFrameMargins[d->Left] = left;
+ d->windowFrameMargins[d->Top] = top;
+ d->windowFrameMargins[d->Right] = right;
+ d->windowFrameMargins[d->Bottom] = bottom;
d->setWindowFrameMargins = true;
}
@@ -536,14 +547,16 @@ void QGraphicsWidget::setWindowFrameMargins(qreal left, qreal top, qreal right,
void QGraphicsWidget::getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
{
Q_D(const QGraphicsWidget);
+ if (left || top || right || bottom)
+ d->ensureWindowFrameMargins();
if (left)
- *left = d->leftWindowFrameMargin;
+ *left = d->windowFrameMargins[d->Left];
if (top)
- *top = d->topWindowFrameMargin;
+ *top = d->windowFrameMargins[d->Top];
if (right)
- *right = d->rightWindowFrameMargin;
+ *right = d->windowFrameMargins[d->Right];
if (bottom)
- *bottom = d->bottomWindowFrameMargin;
+ *bottom = d->windowFrameMargins[d->Bottom];
}
/*!
@@ -577,8 +590,10 @@ void QGraphicsWidget::unsetWindowFrameMargins()
QRectF QGraphicsWidget::windowFrameGeometry() const
{
Q_D(const QGraphicsWidget);
- return geometry().adjusted(-d->leftWindowFrameMargin, -d->topWindowFrameMargin,
- d->rightWindowFrameMargin, d->bottomWindowFrameMargin);
+ return d->windowFrameMargins
+ ? geometry().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
+ d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
+ : geometry();
}
/*!
@@ -589,8 +604,10 @@ QRectF QGraphicsWidget::windowFrameGeometry() const
QRectF QGraphicsWidget::windowFrameRect() const
{
Q_D(const QGraphicsWidget);
- return rect().adjusted(-d->leftWindowFrameMargin, -d->topWindowFrameMargin,
- d->rightWindowFrameMargin, d->bottomWindowFrameMargin);
+ return d->windowFrameMargins
+ ? rect().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
+ d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
+ : rect();
}
/*!
@@ -699,7 +716,10 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
QSizeF sh;
if (d->layout) {
sh = d->layout->effectiveSizeHint(which, constraint);
- sh += QSizeF(d->leftMargin + d->rightMargin, d->topMargin + d->bottomMargin);
+ if (d->margins) {
+ sh += QSizeF(d->margins[d->Left] + d->margins[d->Right],
+ d->margins[d->Top] + d->margins[d->Bottom]);
+ }
} else {
switch (which) {
case Qt::MinimumSize:
@@ -1039,10 +1059,6 @@ QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &
break;
}
case ItemParentHasChanged: {
- // reset window type on parent change in order to automagically remove decorations etc.
- Qt::WindowFlags wflags = d->windowFlags & ~Qt::WindowType_Mask;
- d->adjustWindowFlags(&wflags);
- setWindowFlags(wflags);
// Deliver ParentChange.
QEvent event(QEvent::ParentChange);
QApplication::sendEvent(this, &event);
@@ -1131,7 +1147,8 @@ bool QGraphicsWidget::windowFrameEvent(QEvent *event)
d->windowFrameMousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
break;
case QEvent::GraphicsSceneMouseMove:
- if (d->grabbedSection != Qt::NoSection) {
+ d->ensureWindowData();
+ if (d->windowData->grabbedSection != Qt::NoSection) {
d->windowFrameMouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
event->accept();
}
@@ -1186,7 +1203,8 @@ Qt::WindowFrameSection QGraphicsWidget::windowFrameSectionAt(const QPointF &pos)
const qreal cornerMargin = 20;
//### Not sure of this one, it should be the same value for all edges.
- const qreal windowFrameWidth = d->leftWindowFrameMargin;
+ const qreal windowFrameWidth = d->windowFrameMargins
+ ? d->windowFrameMargins[d->Left] : 0;
Qt::WindowFrameSection s = Qt::NoSection;
if (x <= left + cornerMargin) {
@@ -1212,7 +1230,8 @@ Qt::WindowFrameSection QGraphicsWidget::windowFrameSectionAt(const QPointF &pos)
}
if (s == Qt::NoSection) {
QRectF r1 = r;
- r1.setHeight(d->topWindowFrameMargin);
+ r1.setHeight(d->windowFrameMargins
+ ? d->windowFrameMargins[d->Top] : 0);
if (r1.contains(pos))
s = Qt::TitleBarArea;
}
@@ -1320,7 +1339,8 @@ bool QGraphicsWidget::event(QEvent *event)
case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMouseRelease:
case QEvent::GraphicsSceneMouseDoubleClick:
- if (d->hasDecoration() && d->grabbedSection != Qt::NoSection)
+ d->ensureWindowData();
+ if (d->hasDecoration() && d->windowData->grabbedSection != Qt::NoSection)
return windowFrameEvent(event);
break;
case QEvent::GraphicsSceneHoverEnter:
@@ -1623,6 +1643,7 @@ void QGraphicsWidget::setWindowFlags(Qt::WindowFlags wFlags)
return;
bool wasPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
+ d->adjustWindowFlags(&wFlags);
d->windowFlags = wFlags;
if (!d->setWindowFrameMargins)
unsetWindowFrameMargins();
@@ -1635,6 +1656,11 @@ void QGraphicsWidget::setWindowFlags(Qt::WindowFlags wFlags)
else
d->scene->d_func()->addPopup(this);
}
+
+ if (d->scene && d->scene->d_func()->allItemsIgnoreHoverEvents && d->hasDecoration()) {
+ d->scene->d_func()->allItemsIgnoreHoverEvents = false;
+ d->scene->d_func()->enableMouseTrackingOnViews();
+ }
}
/*!
@@ -1667,12 +1693,13 @@ bool QGraphicsWidget::isActiveWindow() const
void QGraphicsWidget::setWindowTitle(const QString &title)
{
Q_D(QGraphicsWidget);
- d->windowTitle = title;
+ d->ensureWindowData();
+ d->windowData->windowTitle = title;
}
QString QGraphicsWidget::windowTitle() const
{
Q_D(const QGraphicsWidget);
- return d->windowTitle;
+ return d->windowData ? d->windowData->windowTitle : QString();
}
/*!
@@ -2108,11 +2135,12 @@ void QGraphicsWidget::paintWindowFrame(QPainter *painter, const QStyleOptionGrap
QStyleOptionTitleBar bar;
bar.QStyleOption::operator=(*option);
d->initStyleOptionTitleBar(&bar); // this clear flags in bar.state
- if (d->buttonMouseOver)
+ d->ensureWindowData();
+ if (d->windowData->buttonMouseOver)
bar.state |= QStyle::State_MouseOver;
else
bar.state &= ~QStyle::State_MouseOver;
- if (d->buttonSunken)
+ if (d->windowData->buttonSunken)
bar.state |= QStyle::State_Sunken;
else
bar.state &= ~QStyle::State_Sunken;
diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp
index 789f8da..a435758 100644
--- a/src/gui/graphicsview/qgraphicswidget_p.cpp
+++ b/src/gui/graphicsview/qgraphicswidget_p.cpp
@@ -66,16 +66,17 @@ void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFl
isWidget = 1; // QGraphicsItem::isWidget() returns true.
focusNext = focusPrev = q;
focusPolicy = Qt::NoFocus;
+
+ adjustWindowFlags(&wFlags);
+ windowFlags = wFlags;
+
q->setParentItem(parentItem);
q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType));
q->setGraphicsItem(q);
resolveLayoutDirection();
-
- if (!parentItem)
- adjustWindowFlags(&wFlags);
- windowFlags = wFlags;
q->unsetWindowFrameMargins();
+ q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
}
qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const
{
@@ -89,56 +90,57 @@ qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options
return (qreal)height;
}
-void QGraphicsWidgetPrivate::getLayoutItemMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
+/*!
+ \internal
+*/
+QGraphicsWidgetPrivate::~QGraphicsWidgetPrivate()
{
- if (left)
- *left = leftLayoutItemMargin;
- if (top)
- *top = topLayoutItemMargin;
- if (right)
- *right = rightLayoutItemMargin;
- if (bottom)
- *bottom = bottomLayoutItemMargin;
+ // Remove any lazily allocated data
+ delete[] margins;
+ delete[] windowFrameMargins;
+ delete windowData;
}
-void QGraphicsWidgetPrivate::setLayoutItemMargins(qreal left, qreal top, qreal right, qreal bottom)
-{
- if (leftLayoutItemMargin == left
- && topLayoutItemMargin == top
- && rightLayoutItemMargin == right
- && bottomLayoutItemMargin == bottom)
- return;
+/*!
+ \internal
- Q_Q(QGraphicsWidget);
- leftLayoutItemMargin = left;
- topLayoutItemMargin = top;
- rightLayoutItemMargin = right;
- bottomLayoutItemMargin = bottom;
- q->updateGeometry();
+ Ensures that margins is allocated.
+ This function must be called before any dereferencing.
+*/
+void QGraphicsWidgetPrivate::ensureMargins() const
+{
+ if (!margins) {
+ margins = new qreal[4];
+ for (int i = 0; i < 4; ++i)
+ margins[i] = 0;
+ }
}
-void QGraphicsWidgetPrivate::setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt)
+/*!
+ \internal
+
+ Ensures that windowFrameMargins is allocated.
+ This function must be called before any dereferencing.
+*/
+void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const
{
- Q_Q(QGraphicsWidget);
- QStyleOption myOpt;
- if (!opt) {
- q->initStyleOption(&myOpt);
- myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary
- opt = &myOpt;
+ if (!windowFrameMargins) {
+ windowFrameMargins = new qreal[4];
+ for (int i = 0; i < 4; ++i)
+ windowFrameMargins[i] = 0;
}
+}
- QRect liRect = q->style()->subElementRect(element, opt, /* q */ 0);
- if (liRect.isValid()) {
- leftLayoutItemMargin = (opt->rect.left() - liRect.left());
- topLayoutItemMargin = (opt->rect.top() - liRect.top());
- rightLayoutItemMargin = (liRect.right() - opt->rect.right());
- bottomLayoutItemMargin = (liRect.bottom() - opt->rect.bottom());
- } else {
- leftLayoutItemMargin = 0;
- topLayoutItemMargin = 0;
- rightLayoutItemMargin = 0;
- bottomLayoutItemMargin = 0;
- }
+/*!
+ \internal
+
+ Ensures that windowData is allocated.
+ This function must be called before any dereferencing.
+*/
+void QGraphicsWidgetPrivate::ensureWindowData()
+{
+ if (!windowData)
+ windowData = new WindowData;
}
void QGraphicsWidgetPrivate::setPalette_helper(const QPalette &palette)
@@ -297,11 +299,12 @@ QFont QGraphicsWidgetPrivate::naturalWidgetFont() const
void QGraphicsWidgetPrivate::initStyleOptionTitleBar(QStyleOptionTitleBar *option)
{
Q_Q(QGraphicsWidget);
+ ensureWindowData();
q->initStyleOption(option);
option->rect.setHeight(titleBarHeight(*option));
option->titleBarFlags = windowFlags;
option->subControls = QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarSysMenu;
- option->activeSubControls = hoveredSubControl;
+ option->activeSubControls = windowData->hoveredSubControl;
bool isActive = q->isActiveWindow();
if (isActive) {
option->state |= QStyle::State_Active;
@@ -313,7 +316,8 @@ void QGraphicsWidgetPrivate::initStyleOptionTitleBar(QStyleOptionTitleBar *optio
}
QFont windowTitleFont = QApplication::font("QWorkspaceTitleBar");
QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, 0);
- option->text = QFontMetrics(windowTitleFont).elidedText(windowTitle, Qt::ElideRight, textRect.width());
+ option->text = QFontMetrics(windowTitleFont).elidedText(
+ windowData->windowTitle, Qt::ElideRight, textRect.width());
}
void QGraphicsWidgetPrivate::adjustWindowFlags(Qt::WindowFlags *flags)
@@ -341,9 +345,10 @@ void QGraphicsWidgetPrivate::adjustWindowFlags(Qt::WindowFlags *flags)
void QGraphicsWidgetPrivate::windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_Q(QGraphicsWidget);
- if (grabbedSection != Qt::NoSection) {
- if (grabbedSection == Qt::TitleBarArea) {
- buttonSunken = false;
+ ensureWindowData();
+ if (windowData->grabbedSection != Qt::NoSection) {
+ if (windowData->grabbedSection == Qt::TitleBarArea) {
+ windowData->buttonSunken = false;
QStyleOptionTitleBar bar;
initStyleOptionTitleBar(&bar);
// make sure that the coordinates (rect and pos) we send to the style are positive.
@@ -351,8 +356,10 @@ void QGraphicsWidgetPrivate::windowFrameMouseReleaseEvent(QGraphicsSceneMouseEve
bar.rect.moveTo(0,0);
bar.rect.setHeight(q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &bar));
QPointF pos = event->pos();
- pos.rx() += leftWindowFrameMargin;
- pos.ry() += topWindowFrameMargin;
+ if (windowFrameMargins) {
+ pos.rx() += windowFrameMargins[Left];
+ pos.ry() += windowFrameMargins[Top];
+ }
bar.subControls = QStyle::SC_TitleBarCloseButton;
if (q->style()->subControlRect(QStyle::CC_TitleBar, &bar,
QStyle::SC_TitleBarCloseButton,
@@ -361,7 +368,7 @@ void QGraphicsWidgetPrivate::windowFrameMouseReleaseEvent(QGraphicsSceneMouseEve
}
}
if (!(static_cast<QGraphicsSceneMouseEvent *>(event)->buttons()))
- grabbedSection = Qt::NoSection;
+ windowData->grabbedSection = Qt::NoSection;
event->accept();
}
}
@@ -372,35 +379,16 @@ void QGraphicsWidgetPrivate::windowFrameMousePressEvent(QGraphicsSceneMouseEvent
if (event->button() != Qt::LeftButton)
return;
- startGeometry = q->geometry();
- grabbedSection = q->windowFrameSectionAt(event->pos());
- switch (grabbedSection) {
- case Qt::LeftSection:
- case Qt::TopLeftSection:
- mouseDelta = event->pos() - q->rect().topLeft();
- break;
- case Qt::TopSection:
- case Qt::TopRightSection:
- mouseDelta = event->pos() - q->rect().topRight();
- break;
- case Qt::RightSection:
- case Qt::BottomRightSection:
- mouseDelta = event->pos() - q->rect().bottomRight();
- break;
- case Qt::BottomSection:
- case Qt::BottomLeftSection:
- mouseDelta = event->pos() - q->rect().bottomLeft();
- break;
- case Qt::TitleBarArea:
- if (hoveredSubControl == QStyle::SC_TitleBarCloseButton) {
- buttonSunken = true;
- q->update();
- }
- break;
- case Qt::NoSection:
- break;
+ ensureWindowData();
+ windowData->startGeometry = q->geometry();
+ windowData->grabbedSection = q->windowFrameSectionAt(event->pos());
+ ensureWindowData();
+ if (windowData->grabbedSection == Qt::TitleBarArea
+ && windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton) {
+ windowData->buttonSunken = true;
+ q->update();
}
- event->setAccepted(grabbedSection != Qt::NoSection);
+ event->setAccepted(windowData->grabbedSection != Qt::NoSection);
}
static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry,
@@ -455,7 +443,8 @@ static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry,
void QGraphicsWidgetPrivate::windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_Q(QGraphicsWidget);
- if (!(event->buttons() & Qt::LeftButton) || hoveredSubControl != QStyle::SC_TitleBarLabel)
+ ensureWindowData();
+ if (!(event->buttons() & Qt::LeftButton) || windowData->hoveredSubControl != QStyle::SC_TitleBarLabel)
return;
QLineF delta(q->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)), event->pos());
@@ -464,49 +453,56 @@ void QGraphicsWidgetPrivate::windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent
QLineF parentYDelta(q->mapToParent(QPointF(0, delta.p1().y())), q->mapToParent(QPointF(0, delta.p2().y())));
QRectF newGeometry;
- switch (grabbedSection) {
+ switch (windowData->grabbedSection) {
case Qt::LeftSection:
- newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()),
- startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
+ newGeometry = QRectF(windowData->startGeometry.topLeft()
+ + QPointF(parentXDelta.dx(), parentXDelta.dy()),
+ windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
break;
case Qt::TopLeftSection:
- newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()),
- startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
+ newGeometry = QRectF(windowData->startGeometry.topLeft()
+ + QPointF(parentDelta.dx(), parentDelta.dy()),
+ windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
break;
case Qt::TopSection:
- newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()),
- startGeometry.size() - QSizeF(0, delta.dy()));
+ newGeometry = QRectF(windowData->startGeometry.topLeft()
+ + QPointF(parentYDelta.dx(), parentYDelta.dy()),
+ windowData->startGeometry.size() - QSizeF(0, delta.dy()));
break;
case Qt::TopRightSection:
- newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()),
- startGeometry.size() - QSizeF(-delta.dx(), delta.dy()));
+ newGeometry = QRectF(windowData->startGeometry.topLeft()
+ + QPointF(parentYDelta.dx(), parentYDelta.dy()),
+ windowData->startGeometry.size() - QSizeF(-delta.dx(), delta.dy()));
break;
case Qt::RightSection:
- newGeometry = QRectF(startGeometry.topLeft(),
- startGeometry.size() + QSizeF(delta.dx(), 0));
+ newGeometry = QRectF(windowData->startGeometry.topLeft(),
+ windowData->startGeometry.size() + QSizeF(delta.dx(), 0));
break;
case Qt::BottomRightSection:
- newGeometry = QRectF(startGeometry.topLeft(),
- startGeometry.size() + QSizeF(delta.dx(), delta.dy()));
+ newGeometry = QRectF(windowData->startGeometry.topLeft(),
+ windowData->startGeometry.size() + QSizeF(delta.dx(), delta.dy()));
break;
case Qt::BottomSection:
- newGeometry = QRectF(startGeometry.topLeft(),
- startGeometry.size() + QSizeF(0, delta.dy()));
+ newGeometry = QRectF(windowData->startGeometry.topLeft(),
+ windowData->startGeometry.size() + QSizeF(0, delta.dy()));
break;
case Qt::BottomLeftSection:
- newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()),
- startGeometry.size() - QSizeF(delta.dx(), -delta.dy()));
+ newGeometry = QRectF(windowData->startGeometry.topLeft()
+ + QPointF(parentXDelta.dx(), parentXDelta.dy()),
+ windowData->startGeometry.size() - QSizeF(delta.dx(), -delta.dy()));
break;
case Qt::TitleBarArea:
- newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()),
- startGeometry.size());
+ newGeometry = QRectF(windowData->startGeometry.topLeft()
+ + QPointF(parentDelta.dx(), parentDelta.dy()),
+ windowData->startGeometry.size());
break;
case Qt::NoSection:
break;
}
- if (grabbedSection != Qt::NoSection) {
- _q_boundGeometryToSizeConstraints(startGeometry, &newGeometry, grabbedSection,
+ if (windowData->grabbedSection != Qt::NoSection) {
+ _q_boundGeometryToSizeConstraints(windowData->startGeometry, &newGeometry,
+ windowData->grabbedSection,
q->effectiveSizeHint(Qt::MinimumSize),
q->effectiveSizeHint(Qt::MaximumSize));
q->setGeometry(newGeometry);
@@ -519,21 +515,25 @@ void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent
if (!hasDecoration())
return;
+ ensureWindowData();
+
if (q->rect().contains(event->pos())) {
- if (buttonMouseOver || hoveredSubControl != QStyle::SC_None)
+ if (windowData->buttonMouseOver || windowData->hoveredSubControl != QStyle::SC_None)
windowFrameHoverLeaveEvent(event);
return;
}
- bool wasMouseOver = buttonMouseOver;
- QRect oldButtonRect = buttonRect;
- buttonRect = QRect();
- buttonMouseOver = false;
+ bool wasMouseOver = windowData->buttonMouseOver;
+ QRect oldButtonRect = windowData->buttonRect;
+ windowData->buttonRect = QRect();
+ windowData->buttonMouseOver = false;
QPointF pos = event->pos();
QStyleOptionTitleBar bar;
// make sure that the coordinates (rect and pos) we send to the style are positive.
- pos.rx() += leftWindowFrameMargin;
- pos.ry() += topWindowFrameMargin;
+ if (windowFrameMargins) {
+ pos.rx() += windowFrameMargins[Left];
+ pos.ry() += windowFrameMargins[Top];
+ }
initStyleOptionTitleBar(&bar);
bar.rect = q->windowFrameRect().toRect();
bar.rect.moveTo(0,0);
@@ -559,14 +559,17 @@ void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent
cursorShape = Qt::SizeVerCursor;
break;
case Qt::TitleBarArea:
- buttonRect = q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0);
+ windowData->buttonRect = q->style()->subControlRect(
+ QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0);
#ifdef Q_WS_MAC
// On mac we should hover if we are in the 'area' of the buttons
- buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0);
- buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0);
+ windowData->buttonRect |= q->style()->subControlRect(
+ QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0);
+ windowData->buttonRect |= q->style()->subControlRect(
+ QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0);
#endif
- if (buttonRect.contains(pos.toPoint()))
- buttonMouseOver = true;
+ if (windowData->buttonRect.contains(pos.toPoint()))
+ windowData->buttonMouseOver = true;
event->ignore();
break;
default:
@@ -578,15 +581,15 @@ void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent
q->setCursor(cursorShape);
#endif
// update buttons if we hover over them
- hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);
- if (hoveredSubControl != QStyle::SC_TitleBarCloseButton)
- hoveredSubControl = QStyle::SC_TitleBarLabel;
+ windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);
+ if (windowData->hoveredSubControl != QStyle::SC_TitleBarCloseButton)
+ windowData->hoveredSubControl = QStyle::SC_TitleBarLabel;
- if (buttonMouseOver != wasMouseOver) {
+ if (windowData->buttonMouseOver != wasMouseOver) {
if (!oldButtonRect.isNull())
q->update(QRectF(oldButtonRect).translated(q->windowFrameRect().topLeft()));
- if (!buttonRect.isNull())
- q->update(QRectF(buttonRect).translated(q->windowFrameRect().topLeft()));
+ if (!windowData->buttonRect.isNull())
+ q->update(QRectF(windowData->buttonRect).translated(q->windowFrameRect().topLeft()));
}
}
@@ -600,16 +603,19 @@ void QGraphicsWidgetPrivate::windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent
q->unsetCursor();
#endif
+ ensureWindowData();
+
bool needsUpdate = false;
- if (hoveredSubControl == QStyle::SC_TitleBarCloseButton || buttonMouseOver)
+ if (windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton
+ || windowData->buttonMouseOver)
needsUpdate = true;
// update the hover state (of buttons etc...)
- hoveredSubControl = QStyle::SC_None;
- buttonMouseOver = false;
- buttonRect = QRect();
+ windowData->hoveredSubControl = QStyle::SC_None;
+ windowData->buttonMouseOver = false;
+ windowData->buttonRect = QRect();
if (needsUpdate)
- q->update(buttonRect);
+ q->update(windowData->buttonRect);
}
}
diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h
index 53eaa31..f4cdeca 100644
--- a/src/gui/graphicsview/qgraphicswidget_p.h
+++ b/src/gui/graphicsview/qgraphicswidget_p.h
@@ -68,19 +68,12 @@ class QStyleOptionTitleBar;
#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
-class Q_GUI_EXPORT QGraphicsWidgetPrivate : public QGraphicsItemPrivate
+class QGraphicsWidgetPrivate : public QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsWidget)
public:
QGraphicsWidgetPrivate()
- : leftMargin(0),
- topMargin(0),
- rightMargin(0),
- bottomMargin(0),
- leftLayoutItemMargin(0),
- topLayoutItemMargin(0),
- rightLayoutItemMargin(0),
- bottomLayoutItemMargin(0),
+ : margins(0),
layout(0),
inheritedPaletteResolveMask(0),
inheritedFontResolveMask(0),
@@ -92,40 +85,23 @@ public:
focusPrev(0),
focusChild(0),
windowFlags(0),
- hoveredSubControl(QStyle::SC_None),
- grabbedSection(Qt::NoSection),
- buttonMouseOver(false),
- buttonSunken(false),
+ windowData(0),
setWindowFrameMargins(false),
- leftWindowFrameMargin(0),
- topWindowFrameMargin(0),
- rightWindowFrameMargin(0),
- bottomWindowFrameMargin(0)
+ windowFrameMargins(0)
{ }
+ virtual ~QGraphicsWidgetPrivate();
void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags);
qreal titleBarHeight(const QStyleOptionTitleBar &options) const;
// Margins
- qreal leftMargin;
- qreal topMargin;
- qreal rightMargin;
- qreal bottomMargin;
- QRectF contentsRect;
-
- // Layout item margins
- void getLayoutItemMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
- void setLayoutItemMargins(qreal left, qreal top, qreal right, qreal bottom);
- void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
+ enum {Left, Top, Right, Bottom};
+ mutable qreal *margins;
+ void ensureMargins() const;
void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *newScene = 0);
void setLayout_helper(QGraphicsLayout *l);
- qreal leftLayoutItemMargin;
- qreal topLayoutItemMargin;
- qreal rightLayoutItemMargin;
- qreal bottomLayoutItemMargin;
-
// Layouts
QGraphicsLayout *layout;
void setLayoutDirection_helper(Qt::LayoutDirection direction);
@@ -208,20 +184,26 @@ public:
// Windows
Qt::WindowFlags windowFlags;
- QString windowTitle;
- QStyle::SubControl hoveredSubControl;
- Qt::WindowFrameSection grabbedSection;
- uint buttonMouseOver : 1;
- uint buttonSunken : 1;
- QPointF mouseDelta; // to compensate for small error when interactively resizing
- QRectF startGeometry;
- QRect buttonRect;
+ struct WindowData {
+ QString windowTitle;
+ QStyle::SubControl hoveredSubControl;
+ Qt::WindowFrameSection grabbedSection;
+ uint buttonMouseOver : 1;
+ uint buttonSunken : 1;
+ QRectF startGeometry;
+ QRect buttonRect;
+ WindowData()
+ : hoveredSubControl(QStyle::SC_None)
+ , grabbedSection(Qt::NoSection)
+ , buttonMouseOver(false)
+ , buttonSunken(false)
+ {}
+ } *windowData;
+ void ensureWindowData();
bool setWindowFrameMargins;
- qreal leftWindowFrameMargin;
- qreal topWindowFrameMargin;
- qreal rightWindowFrameMargin;
- qreal bottomWindowFrameMargin;
+ mutable qreal *windowFrameMargins;
+ void ensureWindowFrameMargins() const;
#ifndef QT_NO_ACTION
QList<QAction *> actions;
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index dc5ca21..c150b0e 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -275,7 +275,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz
if (hasIgnoreFlag) {
factors[i] = (stretch < 0) ? 1.0 : 0.0;
} else {
- factors[i] = (stretch < 0) ? sizes[i] : 0.0;
+ factors[i] = (stretch < 0) ? sizes[i] : 0.0;
}
} else if (stretch == sumStretches) {
factors[i] = 1.0;
@@ -615,7 +615,7 @@ QRectF QGridLayoutItem::geometryWithin(qreal x, qreal y, qreal width, qreal heig
QSizeF size = effectiveMaxSize().boundedTo(QSizeF(cellWidth, cellHeight));
width = size.width();
height = size.height();
-
+
Qt::Alignment align = q_engine->effectiveAlignment(this);
switch (align & Qt::AlignHorizontal_Mask) {
case Qt::AlignHCenter:
@@ -717,7 +717,7 @@ void QGridLayoutItem::dump(int indent) const
void QGridLayoutRowInfo::insertOrRemoveRows(int row, int delta)
{
count += delta;
-
+
insertOrRemoveItems(stretches, row, delta);
insertOrRemoveItems(spacings, row, delta);
insertOrRemoveItems(alignments, row, delta);
@@ -1076,7 +1076,7 @@ QSizeF QGridLayoutEngine::sizeHint(const QLayoutStyleInfo &styleInfo, Qt::SizeHi
break;
}
return QSizeF();
-}
+}
QSizePolicy::ControlTypes QGridLayoutEngine::controlTypes(LayoutSide side) const
{
@@ -1150,16 +1150,16 @@ void QGridLayoutEngine::dump(int indent) const
q_rowData.dump(indent + 2);
qDebug("%*s Geometries output", indent, "");
+ QVector<qreal> *cellPos = &q_yy;
for (int pass = 0; pass < 2; ++pass) {
- QVector<qreal> &cellPos = q_yy;
QString message;
- for (i = 0; i < cellPos.count(); ++i) {
+ for (i = 0; i < cellPos->count(); ++i) {
message += QLatin1String((message.isEmpty() ? "[" : ", "));
- message += QString::number(cellPos.at(i));
+ message += QString::number(cellPos->at(i));
}
message += QLatin1String("]");
qDebug("%*s %s %s", indent, "", (pass == 0 ? "rows:" : "columns:"), qPrintable(message));
- cellPos = q_xx;
+ cellPos = &q_xx;
}
}
#endif
@@ -1538,5 +1538,5 @@ void QGridLayoutEngine::ensureGeometries(const QLayoutStyleInfo &styleInfo,
}
QT_END_NAMESPACE
-
+
#endif //QT_NO_GRAPHICSVIEW
diff --git a/src/gui/gui.pro b/src/gui/gui.pro
index f224e67..1aa6558 100644
--- a/src/gui/gui.pro
+++ b/src/gui/gui.pro
@@ -31,6 +31,7 @@ include(itemviews/itemviews.pri)
include(inputmethod/inputmethod.pri)
include(graphicsview/graphicsview.pri)
include(util/util.pri)
+include(math3d/math3d.pri)
embedded: QT += network
diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri
index ca52974..bf348af 100644
--- a/src/gui/image/image.pri
+++ b/src/gui/image/image.pri
@@ -22,6 +22,7 @@ HEADERS += \
image/qpixmap.h \
image/qpixmap_raster_p.h \
image/qpixmapcache.h \
+ image/qpixmapcache_p.h \
image/qpixmapdata_p.h \
image/qpixmapdatafactory_p.h \
image/qpixmapfilter_p.h
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 53430ab..b2b8c13 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -304,6 +304,8 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
QString key = QLatin1String("$qt_icon_")
+ QString::number(pm.cacheKey())
+ QString::number(pe->mode)
+ + QString::number(qApp->palette().cacheKey())
+ + QLatin1Char('_')
+ QString::number(actualSize.width())
+ QLatin1Char('_')
+ QString::number(actualSize.height())
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index c7a20db..14e8b8f 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -1691,8 +1691,12 @@ void QImage::setColorTable(const QVector<QRgb> colors)
d->colortable = colors;
d->has_alpha_clut = false;
- for (int i = 0; i < d->colortable.size(); ++i)
- d->has_alpha_clut |= (qAlpha(d->colortable.at(i)) != 255);
+ for (int i = 0; i < d->colortable.size(); ++i) {
+ if (qAlpha(d->colortable.at(i)) != 255) {
+ d->has_alpha_clut = true;
+ break;
+ }
+ }
}
/*!
diff --git a/src/gui/image/qnativeimage.cpp b/src/gui/image/qnativeimage.cpp
index 33e565c..dc01fe4 100644
--- a/src/gui/image/qnativeimage.cpp
+++ b/src/gui/image/qnativeimage.cpp
@@ -65,7 +65,7 @@ typedef struct {
QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool isTextBuffer, QWidget *)
{
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
Q_UNUSED(isTextBuffer);
#endif
BITMAPINFO_MASK bmi;
@@ -78,7 +78,7 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool is
if (format == QImage::Format_RGB16) {
bmi.bmiHeader.biBitCount = 16;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (isTextBuffer) {
bmi.bmiHeader.biCompression = BI_RGB;
bmi.redMask = 0;
@@ -116,7 +116,7 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format, bool is
Q_ASSERT(image.paintEngine()->type() == QPaintEngine::Raster);
static_cast<QRasterPaintEngine *>(image.paintEngine())->setDC(hdc);
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
GdiFlush();
#endif
}
diff --git a/src/gui/image/qnativeimage_p.h b/src/gui/image/qnativeimage_p.h
index 860485a..6402af2 100644
--- a/src/gui/image/qnativeimage_p.h
+++ b/src/gui/image/qnativeimage_p.h
@@ -70,7 +70,7 @@ QT_BEGIN_NAMESPACE
class QWidget;
-class Q_GUI_EXPORT QNativeImage
+class QNativeImage
{
public:
QNativeImage(int width, int height, QImage::Format format, bool isTextBuffer = false, QWidget *widget = 0);
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index efb8260..5568c0d 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -379,6 +379,56 @@ QPixmap QPixmap::copy(const QRect &rect) const
}
/*!
+ \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed)
+
+ This convenience function is equivalent to calling QPixmap::scroll(\a dx,
+ \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed).
+
+ \sa QWidget::scroll(), QGraphicsItem::scroll()
+*/
+
+/*!
+ Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed
+ region is left unchanged. You can optionally pass a pointer to an empty
+ QRegion to get the region that is \a exposed by the scroll operation.
+
+ \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 2
+
+ You cannot scroll while there is an active painter on the pixmap.
+
+ \sa QWidget::scroll(), QGraphicsItem::scroll()
+*/
+void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed)
+{
+ if (isNull() || (dx == 0 && dy == 0))
+ return;
+ QRect dest = rect & this->rect();
+ QRect src = dest.translated(-dx, -dy) & dest;
+ if (src.isEmpty()) {
+ if (exposed)
+ *exposed += dest;
+ return;
+ }
+
+ detach();
+
+ if (!data->scroll(dx, dy, src)) {
+ // Fallback
+ QPixmap pix = *this;
+ QPainter painter(&pix);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.drawPixmap(src.translated(dx, dy), *this, src);
+ painter.end();
+ *this = pix;
+ }
+
+ if (exposed) {
+ *exposed += dest;
+ *exposed -= src.translated(dx, dy);
+ }
+}
+
+/*!
Assigns the given \a pixmap to this pixmap and returns a reference
to this pixmap.
@@ -1309,14 +1359,6 @@ bool QPixmap::isDetached() const
void QPixmap::deref()
{
if (data && !data->ref.deref()) { // Destroy image if last ref
-#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
- if (data->classId() == QPixmapData::RasterClass) {
- QRasterPixmapData *rData = static_cast<QRasterPixmapData*>(data);
- if (rData->texture)
- rData->texture->Release();
- rData->texture = 0;
- }
-#endif
if (data->is_cached && qt_pixmap_cleanup_hook_64)
qt_pixmap_cleanup_hook_64(cacheKey());
delete data;
@@ -1853,7 +1895,7 @@ int QPixmap::defaultDepth()
return QScreen::instance()->depth();
#elif defined(Q_WS_X11)
return QX11Info::appDepth();
-#elif defined(Q_OS_WINCE)
+#elif defined(Q_WS_WINCE)
return QColormap::instance().depth();
#elif defined(Q_WS_WIN)
return 32; // XXX
@@ -1888,12 +1930,6 @@ void QPixmap::detach()
if (id == QPixmapData::RasterClass) {
QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data);
rasterData->image.detach();
-#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
- if (rasterData->texture) {
- rasterData->texture->Release();
- rasterData->texture = 0;
- }
-#endif
}
if (data->is_cached && qt_pixmap_cleanup_hook_64 && data->ref == 1)
diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h
index 1863273..a5609e4 100644
--- a/src/gui/image/qpixmap.h
+++ b/src/gui/image/qpixmap.h
@@ -155,6 +155,9 @@ public:
inline QPixmap copy(int x, int y, int width, int height) const;
QPixmap copy(const QRect &rect = QRect()) const;
+ inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = 0);
+ void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = 0);
+
int serialNumber() const;
qint64 cacheKey() const;
@@ -251,8 +254,6 @@ private:
friend class QWidgetPrivate;
friend class QRasterPaintEngine;
friend class QRasterBuffer;
- friend class QDirect3DPaintEngine;
- friend class QDirect3DPaintEnginePrivate;
friend class QDetachedPixmap;
#if !defined(QT_NO_DATASTREAM)
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
@@ -274,6 +275,11 @@ inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
return copy(QRect(ax, ay, awidth, aheight));
}
+inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
+{
+ scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
+}
+
inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
Qt::ImageConversionFlags flags)
{
diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp
index 26d9618..973cd78 100644
--- a/src/gui/image/qpixmap_mac.cpp
+++ b/src/gui/image/qpixmap_mac.cpp
@@ -1290,6 +1290,14 @@ void QMacPixmapData::copy(const QPixmapData *data, const QRect &rect)
has_mask = macData->has_mask;
}
+bool QMacPixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ Q_UNUSED(dx);
+ Q_UNUSED(dy);
+ Q_UNUSED(rect);
+ return false;
+}
+
/*!
\since 4.2
diff --git a/src/gui/image/qpixmap_mac_p.h b/src/gui/image/qpixmap_mac_p.h
index 75525c4..2b22e6b 100644
--- a/src/gui/image/qpixmap_mac_p.h
+++ b/src/gui/image/qpixmap_mac_p.h
@@ -68,6 +68,7 @@ public:
void resize(int width, int height);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
+ bool scroll(int dx, int dy, const QRect &rect);
int metric(QPaintDevice::PaintDeviceMetric metric) const;
void fill(const QColor &color);
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index 7dfab70..b5556cd 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -50,12 +50,6 @@
#include <private/qwidget_p.h>
#include <private/qdrawhelper_p.h>
-#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
-#include <private/qpaintengine_d3d_p.h>
-#include <d3d9.h>
-extern QDirect3DPaintEngine *qt_d3dEngine();
-#endif
-
QT_BEGIN_NAMESPACE
const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
@@ -63,9 +57,6 @@ const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
QRasterPixmapData::QRasterPixmapData(PixelType type)
: QPixmapData(type, RasterClass)
-#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
- , texture(0)
-#endif
{
}
@@ -181,6 +172,16 @@ void QRasterPixmapData::fromImage(const QImage &sourceImage,
setSerialNumber(image.serialNumber());
}
+// from qwindowsurface.cpp
+extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
+
+bool QRasterPixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ if (!image.isNull())
+ qt_scrollRectInImage(image, rect, QPoint(dx, dy));
+ return true;
+}
+
void QRasterPixmapData::fill(const QColor &color)
{
uint pixel;
diff --git a/src/gui/image/qpixmap_raster_p.h b/src/gui/image/qpixmap_raster_p.h
index 095f378..9d3bf72 100644
--- a/src/gui/image/qpixmap_raster_p.h
+++ b/src/gui/image/qpixmap_raster_p.h
@@ -58,9 +58,6 @@
#ifdef Q_WS_WIN
# include "qt_windows.h"
-# ifndef QT_NO_DIRECT3D
-# include <d3d9.h>
-# endif
#endif
QT_BEGIN_NAMESPACE
@@ -75,6 +72,7 @@ public:
void fromFile(const QString &filename, Qt::ImageConversionFlags flags);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
+ bool scroll(int dx, int dy, const QRect &rect);
void fill(const QColor &color);
void setMask(const QBitmap &mask);
bool hasAlphaChannel() const;
@@ -87,10 +85,6 @@ protected:
int metric(QPaintDevice::PaintDeviceMetric metric) const;
private:
-#if defined(Q_WS_WIN) && !defined(QT_NO_DIRECT3D)
- friend class QDirect3DPaintEnginePrivate;
- IDirect3DTexture9 *texture;
-#endif
friend class QPixmap;
friend class QBitmap;
friend class QDetachedPixmap;
diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp
index cbe9004..d4ebef7 100644
--- a/src/gui/image/qpixmap_win.cpp
+++ b/src/gui/image/qpixmap_win.cpp
@@ -59,7 +59,7 @@
#include "qdebug.h"
#include "qt_windows.h"
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#include <winbase.h>
#include "qguifunctions_wince.h"
extern bool qt_wince_is_high_dpi();
@@ -80,7 +80,7 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h )
if (w < 0) w = r.right - r.left;
if (h < 0) h = r.bottom - r.top;
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
if (qt_wince_is_pocket_pc()) {
QWidget *widget = QWidget::find(winId);
if (qobject_cast<QDesktopWidget *>(widget)) {
@@ -101,7 +101,7 @@ QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h )
// copy data
HDC window_dc = GetDC(winId);
BitBlt(bitmap_dc, 0, 0, w, h, window_dc, x, y, SRCCOPY
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
| CAPTUREBLT
#endif
);
@@ -288,7 +288,7 @@ QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
}
#ifdef Q_WS_WIN
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
{
@@ -392,7 +392,7 @@ QPixmap convertHIconToPixmap( const HICON icon)
DeleteDC(hdc);
return QPixmap::fromImage(image);
}
-#else //ifndef Q_OS_WINCE
+#else //ifndef Q_WS_WINCE
QPixmap convertHIconToPixmap( const HICON icon, bool large)
{
HDC screenDevice = GetDC(0);
@@ -457,7 +457,7 @@ QPixmap convertHIconToPixmap( const HICON icon, bool large)
DeleteDC(hdc);
return QPixmap::fromImage(image);
}
-#endif //ifndef Q_OS_WINCE
+#endif //ifndef Q_WS_WINCE
QPixmap loadIconFromShell32( int resourceId, int size )
{
diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp
index 38916c7..d9c10db 100644
--- a/src/gui/image/qpixmap_x11.cpp
+++ b/src/gui/image/qpixmap_x11.cpp
@@ -2205,6 +2205,16 @@ void QX11PixmapData::copy(const QPixmapData *data, const QRect &rect)
}
}
+bool QX11PixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ GC gc = XCreateGC(X11->display, hd, 0, 0);
+ XCopyArea(X11->display, hd, hd, gc,
+ rect.left(), rect.top(), rect.width(), rect.height(),
+ rect.left() + dx, rect.top() + dy);
+ XFreeGC(X11->display, gc);
+ return true;
+}
+
#if !defined(QT_NO_XRENDER)
void QX11PixmapData::convertToARGB32(bool preserveContents)
{
diff --git a/src/gui/image/qpixmap_x11_p.h b/src/gui/image/qpixmap_x11_p.h
index 980b10e..c526402 100644
--- a/src/gui/image/qpixmap_x11_p.h
+++ b/src/gui/image/qpixmap_x11_p.h
@@ -74,6 +74,7 @@ public:
void resize(int width, int height);
void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
void copy(const QPixmapData *data, const QRect &rect);
+ bool scroll(int dx, int dy, const QRect &rect);
void fill(const QColor &color);
QBitmap mask() const;
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 458d6b9..810ce65 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -40,13 +40,9 @@
****************************************************************************/
#include "qpixmapcache.h"
-#include "qcache.h"
#include "qobject.h"
#include "qdebug.h"
-
-#include "qpaintengine.h"
-#include <private/qimage_p.h>
-#include <private/qpixmap_raster_p.h>
+#include "qpixmapcache_p.h"
QT_BEGIN_NAMESPACE
@@ -68,15 +64,17 @@ QT_BEGIN_NAMESPACE
access the global pixmap cache. It creates an internal QCache
object for caching the pixmaps.
- The cache associates a pixmap with a string (key). If two pixmaps
- are inserted into the cache using equal keys, then the last pixmap
- will hide the first pixmap. The QHash and QCache classes do
+ The cache associates a pixmap with a string as a key or with a QPixmapCache::Key.
+ The QPixmapCache::Key is faster than using strings as key.
+ If two pixmaps are inserted into the cache using equal keys, then the
+ last pixmap will hide the first pixmap. The QHash and QCache classes do
exactly the same.
The cache becomes full when the total size of all pixmaps in the
- cache exceeds cacheLimit(). The initial cache limit is 1024 KB (1
- MB); it is changed with setCacheLimit(). A pixmap takes roughly
- (\e{width} * \e{height} * \e{depth})/8 bytes of memory.
+ cache exceeds cacheLimit(). The initial cache limit is
+ 2048 KB(2 MB) for Embedded, 10240 KB (10
+ MB) for Desktops; it is changed with setCacheLimit().
+ A pixmap takes roughly (\e{width} * \e{height} * \e{depth})/8 bytes of memory.
The \e{Qt Quarterly} article
\l{http://doc.trolltech.com/qq/qq12-qpixmapcache.html}{Optimizing
@@ -86,58 +84,123 @@ QT_BEGIN_NAMESPACE
\sa QCache, QPixmap
*/
-#if defined(Q_WS_QWS) || defined(Q_OS_WINCE)
+#if defined(Q_WS_QWS) || defined(Q_WS_WINCE)
static int cache_limit = 2048; // 2048 KB cache limit for embedded
#else
static int cache_limit = 10240; // 10 MB cache limit for desktop
#endif
-// XXX: hw: is this a general concept we need to abstract?
-class QDetachedPixmap : public QPixmap
+/*!
+ Constructs an empty Key object.
+*/
+QPixmapCache::Key::Key() : d(0)
{
-public:
- QDetachedPixmap(const QPixmap &pix) : QPixmap(pix)
- {
- if (data && data->classId() == QPixmapData::RasterClass) {
- QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data);
- if (!d->image.isNull() && d->image.d->paintEngine
- && !d->image.d->paintEngine->isActive())
- {
- delete d->image.d->paintEngine;
- d->image.d->paintEngine = 0;
- }
- }
+}
+
+/*!
+ \internal
+ Constructs a copy of \a other.
+*/
+QPixmapCache::Key::Key(const Key &other)
+{
+ if (other.d)
+ ++(other.d->ref);
+ d = other.d;
+}
+
+/*!
+ Destructor; called immediately before the object is deleted.
+*/
+QPixmapCache::Key::~Key()
+{
+ if (d && --(d->ref) == 0)
+ delete d;
+}
+
+/*!
+ \internal
+
+ Returns true if this key is the same as the given \a key.
+*/
+bool QPixmapCache::Key::operator ==(const Key &key) const
+{
+ return (d == key.d);
+}
+
+/*!
+ \internal
+*/
+QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other)
+{
+ if (d != other.d) {
+ if (other.d)
+ ++(other.d->ref);
+ if (d && --(d->ref) == 0)
+ delete d;
+ d = other.d;
}
-};
+ return *this;
+}
-class QPMCache : public QObject, public QCache<qint64, QDetachedPixmap>
+class QPMCache : public QObject, public QCache<QPixmapCache::Key, QDetachedPixmap>
{
Q_OBJECT
public:
- QPMCache()
- : QObject(0),
- QCache<qint64, QDetachedPixmap>(cache_limit * 1024),
- theid(0), ps(0), t(false) { }
- ~QPMCache() { }
+ QPMCache();
+ ~QPMCache();
void timerEvent(QTimerEvent *);
bool insert(const QString& key, const QPixmap &pixmap, int cost);
+ QPixmapCache::Key insert(const QPixmap &pixmap, int cost);
+ bool replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost);
bool remove(const QString &key);
+ bool remove(const QPixmapCache::Key &key);
+
+ void resizeKeyArray(int size);
+ QPixmapCache::Key createKey();
+ void releaseKey(const QPixmapCache::Key &key);
+ void clear();
QPixmap *object(const QString &key) const;
+ QPixmap *object(const QPixmapCache::Key &key) const;
+
+ static inline QPixmapCache::KeyData *get(const QPixmapCache::Key &key)
+ {return key.d;}
+
+ static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);
private:
- QHash<QString, qint64> cacheKeys;
+ int *keyArray;
int theid;
int ps;
+ int keyArraySize;
+ int freeKey;
+ QHash<QString, QPixmapCache::Key> cacheKeys;
bool t;
};
+
QT_BEGIN_INCLUDE_NAMESPACE
#include "qpixmapcache.moc"
QT_END_INCLUDE_NAMESPACE
+static uint qHash(const QPixmapCache::Key &k)
+{
+ return qHash(QPMCache::get(k)->key);
+}
+
+QPMCache::QPMCache()
+ : QObject(0),
+ QCache<QPixmapCache::Key, QDetachedPixmap>(cache_limit * 1024),
+ keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)
+{
+}
+QPMCache::~QPMCache()
+{
+ free(keyArray);
+}
+
/*
- This is supposed to cut the cache size down by about 80-90% in a
+ This is supposed to cut the cache size down by about 25% in a
minute once the application becomes idle, to let any inserted pixmap
remain in the cache for some time before it becomes a candidate for
cleaning-up, and to not cut down the size of the cache while the
@@ -146,23 +209,28 @@ QT_END_INCLUDE_NAMESPACE
When the last pixmap has been deleted from the cache, kill the
timer so Qt won't keep the CPU from going into sleep mode.
*/
-
void QPMCache::timerEvent(QTimerEvent *)
{
int mc = maxCost();
bool nt = totalCost() == ps;
+ QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QDetachedPixmap>::keys();
setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
setMaxCost(mc);
ps = totalCost();
- QHash<QString, qint64>::iterator it = cacheKeys.begin();
+ QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();
while (it != cacheKeys.end()) {
if (!contains(it.value())) {
+ releaseKey(it.value());
it = cacheKeys.erase(it);
} else {
++it;
}
}
+ for (int i = 0; i < keys.size(); ++i) {
+ if (!contains(keys.at(i)))
+ releaseKey(keys.at(i));
+ }
if (!size()) {
killTimer(theid);
@@ -176,38 +244,154 @@ void QPMCache::timerEvent(QTimerEvent *)
QPixmap *QPMCache::object(const QString &key) const
{
- return QCache<qint64, QDetachedPixmap>::object(cacheKeys.value(key, -1));
+ QPixmapCache::Key cacheKey = cacheKeys.value(key);
+ if (!cacheKey.d || !cacheKey.d->isValid) {
+ const_cast<QPMCache *>(this)->cacheKeys.remove(key);
+ return 0;
+ }
+ QPixmap *ptr = QCache<QPixmapCache::Key, QDetachedPixmap>::object(cacheKey);
+ //We didn't find the pixmap in the cache, the key is not valid anymore
+ if (!ptr) {
+ const_cast<QPMCache *>(this)->cacheKeys.remove(key);
+ const_cast<QPMCache *>(this)->releaseKey(cacheKey);
+ }
+ return ptr;
}
+QPixmap *QPMCache::object(const QPixmapCache::Key &key) const
+{
+ Q_ASSERT(key.d->isValid);
+ QPixmap *ptr = QCache<QPixmapCache::Key, QDetachedPixmap>::object(key);
+ //We didn't find the pixmap in the cache, the key is not valid anymore
+ if (!ptr)
+ const_cast<QPMCache *>(this)->releaseKey(key);
+ return ptr;
+}
bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)
{
- qint64 cacheKey = pixmap.cacheKey();
- if (QCache<qint64, QDetachedPixmap>::object(cacheKey)) {
+ QPixmapCache::Key cacheKey;
+ QPixmapCache::Key oldCacheKey = cacheKeys.value(key);
+ //If for the same key we add already a pixmap we should delete it
+ if (oldCacheKey.d) {
+ QCache<QPixmapCache::Key, QDetachedPixmap>::remove(oldCacheKey);
+ cacheKey = oldCacheKey;
+ } else {
+ cacheKey = createKey();
+ }
+
+ bool success = QCache<QPixmapCache::Key, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
+ if (success) {
cacheKeys.insert(key, cacheKey);
- return true;
+ if (!theid) {
+ theid = startTimer(30000);
+ t = false;
+ }
+ } else {
+ //Insertion failed we released the new allocated key
+ releaseKey(cacheKey);
}
- qint64 oldCacheKey = cacheKeys.value(key, -1);
- //If for the same key we add already a pixmap we should delete it
- if (oldCacheKey != -1)
- QCache<qint64, QDetachedPixmap>::remove(oldCacheKey);
+ return success;
+}
- bool success = QCache<qint64, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
+QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)
+{
+ QPixmapCache::Key cacheKey = createKey();
+ bool success = QCache<QPixmapCache::Key, QDetachedPixmap>::insert(cacheKey, new QDetachedPixmap(pixmap), cost);
if (success) {
- cacheKeys.insert(key, cacheKey);
if (!theid) {
theid = startTimer(30000);
t = false;
}
+ } else {
+ //Insertion failed we released the key and return an invalid one
+ releaseKey(cacheKey);
+ }
+ return cacheKey;
+}
+
+bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost)
+{
+ Q_ASSERT(key.d->isValid);
+ //If for the same key we add already a pixmap we should delete it
+ QCache<QPixmapCache::Key, QDetachedPixmap>::remove(key);
+
+ bool success = QCache<QPixmapCache::Key, QDetachedPixmap>::insert(key, new QDetachedPixmap(pixmap), cost);
+ if (success && !theid) {
+ theid = startTimer(30000);
+ t = false;
}
return success;
}
bool QPMCache::remove(const QString &key)
{
- qint64 cacheKey = cacheKeys.value(key, -1);
+ QPixmapCache::Key cacheKey = cacheKeys.value(key);
+ //The key was not in the cache
+ if (!cacheKey.d)
+ return false;
cacheKeys.remove(key);
- return QCache<qint64, QDetachedPixmap>::remove(cacheKey);
+ releaseKey(cacheKey);
+ return QCache<QPixmapCache::Key, QDetachedPixmap>::remove(cacheKey);
+}
+
+bool QPMCache::remove(const QPixmapCache::Key &key)
+{
+ releaseKey(key);
+ return QCache<QPixmapCache::Key, QDetachedPixmap>::remove(key);
+}
+
+void QPMCache::resizeKeyArray(int size)
+{
+ if (size <= keyArraySize || size == 0)
+ return;
+ keyArray = reinterpret_cast<int *>(realloc(keyArray, size * sizeof(int)));
+ for (int i = keyArraySize; i != size; ++i)
+ keyArray[i] = i + 1;
+ keyArraySize = size;
+}
+
+QPixmapCache::Key QPMCache::createKey()
+{
+ if (freeKey == keyArraySize)
+ resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
+ int id = freeKey;
+ freeKey = keyArray[id];
+ QPixmapCache::Key key;
+ QPixmapCache::KeyData *d = QPMCache::getKeyData(&key);
+ d->key = ++id;
+ return key;
+}
+
+void QPMCache::releaseKey(const QPixmapCache::Key &key)
+{
+ if (key.d->key > keyArraySize || key.d->key <= 0)
+ return;
+ key.d->key--;
+ keyArray[key.d->key] = freeKey;
+ freeKey = key.d->key;
+ key.d->isValid = false;
+ key.d->key = 0;
+}
+
+void QPMCache::clear()
+{
+ free(keyArray);
+ keyArray = 0;
+ freeKey = 0;
+ keyArraySize = 0;
+ //Mark all keys as invalid
+ QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QDetachedPixmap>::keys();
+ for (int i = 0; i < keys.size(); ++i)
+ keys.at(i).d->isValid = false;
+ QCache<QPixmapCache::Key, QDetachedPixmap>::clear();
+}
+
+QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key)
+{
+ if (!key->d)
+ key->d = new QPixmapCache::KeyData;
+ return key->d;
}
Q_GLOBAL_STATIC(QPMCache, pm_cache)
@@ -222,7 +406,7 @@ Q_GLOBAL_STATIC(QPMCache, pm_cache)
\warning If valid, you should copy the pixmap immediately (this is
fast). Subsequent insertions into the cache could cause the
pointer to become invalid. For this reason, we recommend you use
- find(const QString&, QPixmap&) instead.
+ bool find(const QString&, QPixmap*) instead.
Example:
\snippet doc/src/snippets/code/src_gui_image_qpixmapcache.cpp 0
@@ -235,6 +419,17 @@ QPixmap *QPixmapCache::find(const QString &key)
/*!
+ \obsolete
+
+ Use bool find(const QString&, QPixmap*) instead.
+*/
+
+bool QPixmapCache::find(const QString &key, QPixmap& pixmap)
+{
+ return find(key, &pixmap);
+}
+
+/*!
Looks for a cached pixmap associated with the \a key in the cache.
If the pixmap is found, the function sets \a pm to that pixmap and
returns true; otherwise it leaves \a pm alone and returns false.
@@ -243,14 +438,31 @@ QPixmap *QPixmapCache::find(const QString &key)
\snippet doc/src/snippets/code/src_gui_image_qpixmapcache.cpp 1
*/
-bool QPixmapCache::find(const QString &key, QPixmap& pm)
+bool QPixmapCache::find(const QString &key, QPixmap* pixmap)
{
QPixmap *ptr = pm_cache()->object(key);
- if (ptr)
- pm = *ptr;
+ if (ptr && pixmap)
+ *pixmap = *ptr;
return ptr != 0;
}
+/*!
+ Looks for a cached pixmap associated with the \a key in the cache.
+ If the pixmap is found, the function sets \a pm to that pixmap and
+ returns true; otherwise it leaves \a pm alone and returns false. If
+ the pixmap is not found, it means that the \a key is not valid anymore,
+ so it will be released for the next insertion.
+*/
+bool QPixmapCache::find(const Key &key, QPixmap* pixmap)
+{
+ //The key is not valid anymore, a flush happened before probably
+ if (!key.d || !key.d->isValid)
+ return false;
+ QPixmap *ptr = pm_cache()->object(key);
+ if (ptr && pixmap)
+ *pixmap = *ptr;
+ return ptr != 0;
+}
/*!
Inserts a copy of the pixmap \a pm associated with the \a key into
@@ -272,9 +484,43 @@ bool QPixmapCache::find(const QString &key, QPixmap& pm)
\sa setCacheLimit()
*/
-bool QPixmapCache::insert(const QString &key, const QPixmap &pm)
+bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
+{
+ return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
+}
+
+/*!
+ Inserts a copy of the pixmap \a pm into
+ the cache and return you the key. The key is always greater than 0.
+ If the key is equals 0 then the insertion failed.
+
+ When a pixmap is inserted and the cache is about to exceed its
+ limit, it removes pixmaps until there is enough room for the
+ pixmap to be inserted.
+
+ The oldest pixmaps (least recently accessed in the cache) are
+ deleted when more space is needed.
+
+ \sa setCacheLimit(), replace()
+*/
+QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
+{
+ return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
+}
+
+/*!
+ Replace the pixmap associated to the \a key into
+ the cache. It return true if the pixmap \a pm has been correctly
+ inserted into the cache false otherwise.
+
+ \sa setCacheLimit(), insert()
+*/
+bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)
{
- return pm_cache()->insert(key, pm, pm.width() * pm.height() * pm.depth() / 8);
+ //The key is not valid anymore, a flush happened before probably
+ if (!key.d || !key.d->isValid)
+ return false;
+ return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
}
/*!
@@ -314,6 +560,17 @@ void QPixmapCache::remove(const QString &key)
pm_cache()->remove(key);
}
+/*!
+ Removes the pixmap associated with \a key from the cache and release
+ the key for a future insertion.
+*/
+void QPixmapCache::remove(const Key &key)
+{
+ //The key is not valid anymore, a flush happened before probably
+ if (!key.d || !key.d->isValid)
+ return;
+ pm_cache()->remove(key);
+}
/*!
Removes all pixmaps from the cache.
diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h
index 2750a88..ae64310 100644
--- a/src/gui/image/qpixmapcache.h
+++ b/src/gui/image/qpixmapcache.h
@@ -53,12 +53,35 @@ QT_MODULE(Gui)
class Q_GUI_EXPORT QPixmapCache
{
public:
+ class KeyData;
+ class Key
+ {
+ public:
+ Key();
+ Key(const Key &other);
+ ~Key();
+ bool operator ==(const Key &key) const;
+ inline bool operator !=(const Key &key) const
+ { return !operator==(key); }
+ Key &operator =(const Key &other);
+
+ private:
+ KeyData *d;
+ friend class QPMCache;
+ friend class QPixmapCache;
+ };
+
static int cacheLimit();
static void setCacheLimit(int);
static QPixmap *find(const QString &key);
- static bool find(const QString &key, QPixmap&);
- static bool insert(const QString &key, const QPixmap&);
+ static bool find(const QString &key, QPixmap &pixmap);
+ static bool find(const QString &key, QPixmap *pixmap);
+ static bool find(const Key &key, QPixmap *pixmap);
+ static bool insert(const QString &key, const QPixmap &pixmap);
+ static Key insert(const QPixmap &pixmap);
+ static bool replace(const Key &key, const QPixmap &pixmap);
static void remove(const QString &key);
+ static void remove(const Key &key);
static void clear();
};
diff --git a/src/gui/embedded/qkbdpc101_qws.h b/src/gui/image/qpixmapcache_p.h
index f9f0104..66b30d2 100644
--- a/src/gui/embedded/qkbdpc101_qws.h
+++ b/src/gui/image/qpixmapcache_p.h
@@ -39,57 +39,54 @@
**
****************************************************************************/
-#ifndef QKBDPC101_QWS_H
-#define QKBDPC101_QWS_H
-
-#include <QtGui/qkbd_qws.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
-
-#ifndef QT_NO_QWS_KEYBOARD
-
-#ifndef QT_NO_QWS_KBD_PC101
-
-struct QWSKeyMap {
- uint key_code;
- ushort unicode;
- ushort shift_unicode;
- ushort ctrl_unicode;
+#ifndef QPIXMAPCACHE_P_H
+#define QPIXMAPCACHE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. This header
+// file may change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpixmapcache.h"
+#include "qpaintengine.h"
+#include <private/qimage_p.h>
+#include <private/qpixmap_raster_p.h>
+#include "qcache.h"
+
+class QPixmapCache::KeyData
+{
+public:
+ KeyData() : isValid(true), key(0), ref(1) {}
+ KeyData(const KeyData &other)
+ : isValid(other.isValid), key(other.key), ref(1) {}
+ ~KeyData() {}
+
+ bool isValid;
+ int key;
+ int ref;
};
-class QWSPC101KeyboardHandler : public QWSKeyboardHandler
+// XXX: hw: is this a general concept we need to abstract?
+class QDetachedPixmap : public QPixmap
{
public:
- explicit QWSPC101KeyboardHandler(const QString&);
- virtual ~QWSPC101KeyboardHandler();
-
- virtual void doKey(uchar scancode);
- virtual const QWSKeyMap *keyMap() const;
-
-protected:
- bool shift;
- bool alt;
- bool ctrl;
- bool caps;
-#if defined(QT_QWS_IPAQ)
- uint ipaq_return_pressed:1;
-#endif
- uint extended:2;
- Qt::KeyboardModifiers modifiers;
- int prevuni;
- int prevkey;
+ QDetachedPixmap(const QPixmap &pix) : QPixmap(pix)
+ {
+ if (data && data->classId() == QPixmapData::RasterClass) {
+ QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data);
+ if (!d->image.isNull() && d->image.d->paintEngine
+ && !d->image.d->paintEngine->isActive())
+ {
+ delete d->image.d->paintEngine;
+ d->image.d->paintEngine = 0;
+ }
+ }
+ }
};
-#endif // QT_NO_QWS_KBD_PC101
-
-#endif // QT_NO_QWS_KEYBOARD
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QKBDPC101_QWS_H
+#endif // QPIXMAPCACHE_P_H
diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp
index 3d88f4b..245a866 100644
--- a/src/gui/image/qpixmapdata.cpp
+++ b/src/gui/image/qpixmapdata.cpp
@@ -73,6 +73,14 @@ void QPixmapData::copy(const QPixmapData *data, const QRect &rect)
fromImage(data->toImage().copy(rect), Qt::AutoColor);
}
+bool QPixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ Q_UNUSED(dx);
+ Q_UNUSED(dy);
+ Q_UNUSED(rect);
+ return false;
+}
+
void QPixmapData::setMask(const QBitmap &mask)
{
if (mask.size().isEmpty()) {
diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h
index 7296426..27bc70d 100644
--- a/src/gui/image/qpixmapdata_p.h
+++ b/src/gui/image/qpixmapdata_p.h
@@ -78,6 +78,7 @@ public:
virtual void fromFile(const QString &filename, const char *format,
Qt::ImageConversionFlags flags);
virtual void copy(const QPixmapData *data, const QRect &rect);
+ virtual bool scroll(int dx, int dy, const QRect &rect);
virtual int metric(QPaintDevice::PaintDeviceMetric metric) const = 0;
virtual void fill(const QColor &color) = 0;
@@ -121,7 +122,7 @@ private:
};
#ifdef Q_WS_WIN
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
QPixmap convertHIconToPixmap( const HICON icon);
#else
QPixmap convertHIconToPixmap( const HICON icon, bool large = false);
diff --git a/src/gui/inputmethod/qinputcontext_p.h b/src/gui/inputmethod/qinputcontext_p.h
index 8c1b8de..a5e3d91 100644
--- a/src/gui/inputmethod/qinputcontext_p.h
+++ b/src/gui/inputmethod/qinputcontext_p.h
@@ -84,10 +84,6 @@ public:
{}
QWidget *focusWidget;
-
-#if defined(Q_WS_WIN) || defined(Q_WS_QWS)
- static void updateImeStatus(QWidget *w, bool hasFocus);
-#endif
};
QT_END_NAMESPACE
diff --git a/src/gui/inputmethod/qmacinputcontext_mac.cpp b/src/gui/inputmethod/qmacinputcontext_mac.cpp
index f0e7ea9..86385fa 100644
--- a/src/gui/inputmethod/qmacinputcontext_mac.cpp
+++ b/src/gui/inputmethod/qmacinputcontext_mac.cpp
@@ -45,6 +45,7 @@
#include "qtextformat.h"
#include <qdebug.h>
#include <private/qapplication_p.h>
+#include <private/qkeymapper_p.h>
QT_BEGIN_NAMESPACE
@@ -63,7 +64,8 @@ static QTextFormat qt_mac_compose_format()
}
QMacInputContext::QMacInputContext(QObject *parent)
- : QInputContext(parent), composing(false), recursionGuard(false), textDocument(0)
+ : QInputContext(parent), composing(false), recursionGuard(false), textDocument(0),
+ keydownEvent(0)
{
// createTextDocument();
}
@@ -183,6 +185,16 @@ QMacInputContext::cleanup()
#endif
}
+void QMacInputContext::setLastKeydownEvent(EventRef event)
+{
+ EventRef tmpEvent = keydownEvent;
+ keydownEvent = event;
+ if (keydownEvent)
+ RetainEvent(keydownEvent);
+ if (tmpEvent)
+ ReleaseEvent(tmpEvent);
+}
+
OSStatus
QMacInputContext::globalEventProcessor(EventHandlerCallRef, EventRef event, void *)
{
@@ -335,6 +347,12 @@ QMacInputContext::globalEventProcessor(EventHandlerCallRef, EventRef event, void
GetEventParameter(key_ev, kEventParamKeyMacCharCodes, typeChar, 0, sizeof(chr), 0, &chr);
if(!chr || chr >= 128 || (text.length() > 0 && (text.length() > 1 || text.at(0) != QLatin1Char(chr))))
handled_event = !widget->testAttribute(Qt::WA_InputMethodEnabled);
+ QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext());
+ if (context && context->lastKeydownEvent()) {
+ qt_keymapper_private()->translateKeyEvent(widget, 0, context->lastKeydownEvent(),
+ 0, false);
+ context->setLastKeydownEvent(0);
+ }
}
break; }
default:
diff --git a/src/gui/inputmethod/qmacinputcontext_p.h b/src/gui/inputmethod/qmacinputcontext_p.h
index f708040..c3f245a 100644
--- a/src/gui/inputmethod/qmacinputcontext_p.h
+++ b/src/gui/inputmethod/qmacinputcontext_p.h
@@ -78,6 +78,10 @@ public:
static OSStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *);
static void initialize();
static void cleanup();
+
+ EventRef lastKeydownEvent() { return keydownEvent; }
+ void setLastKeydownEvent(EventRef);
+
protected:
void mouseHandler(int pos, QMouseEvent *);
private:
@@ -85,6 +89,7 @@ private:
bool recursionGuard;
TSMDocumentID textDocument;
QString currentText;
+ EventRef keydownEvent;
};
QT_END_NAMESPACE
diff --git a/src/gui/inputmethod/qwininputcontext_p.h b/src/gui/inputmethod/qwininputcontext_p.h
index 38d7e32..c6ad19e 100644
--- a/src/gui/inputmethod/qwininputcontext_p.h
+++ b/src/gui/inputmethod/qwininputcontext_p.h
@@ -83,6 +83,7 @@ public:
static void TranslateMessage(const MSG *msg);
static LRESULT DefWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+ static void updateImeStatus(QWidget *w, bool hasFocus);
static void enablePopupChild(QWidget *w, bool e);
static void enable(QWidget *w, bool e);
diff --git a/src/gui/inputmethod/qwininputcontext_win.cpp b/src/gui/inputmethod/qwininputcontext_win.cpp
index e3e8aa4..dd966d5 100644
--- a/src/gui/inputmethod/qwininputcontext_win.cpp
+++ b/src/gui/inputmethod/qwininputcontext_win.cpp
@@ -59,7 +59,7 @@
#include "qdebug.h"
#endif
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
extern void qt_wince_show_SIP(bool show); // defined in qguifunctions_wince.cpp
#endif
@@ -237,7 +237,7 @@ QWinInputContext::QWinInputContext(QObject *parent)
aimmpump->Start();
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
QSysInfo::WinVersion ver = QSysInfo::windowsVersion();
if (ver & QSysInfo::WV_NT_based && ver >= QSysInfo::WV_VISTA) {
// Since the IsValidLanguageGroup/IsValidLocale functions always return true on
@@ -349,7 +349,7 @@ static LONG getCompositionString(HIMC himc, DWORD dwIndex, LPVOID lpbuf, DWORD d
if(QSysInfo::WindowsVersion != QSysInfo::WV_95) {
len = ImmGetCompositionStringW(himc, dwIndex, lpbuf, dBufLen);
}
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
else {
len = ImmGetCompositionStringA(himc, dwIndex, lpbuf, dBufLen);
if (unicode)
@@ -738,7 +738,7 @@ inline void enableIme(QWidget *w, bool value)
// enable ime
if (defaultContext)
ImmAssociateContext(w->effectiveWinId(), defaultContext);
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qApp->autoSipEnabled())
qt_wince_show_SIP(true);
#endif
@@ -747,7 +747,7 @@ inline void enableIme(QWidget *w, bool value)
HIMC oldimc = ImmAssociateContext(w->effectiveWinId(), 0);
if (!defaultContext)
defaultContext = oldimc;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qApp->autoSipEnabled())
qt_wince_show_SIP(false);
#endif
@@ -755,7 +755,7 @@ inline void enableIme(QWidget *w, bool value)
}
-void QInputContextPrivate::updateImeStatus(QWidget *w, bool hasFocus)
+void QWinInputContext::updateImeStatus(QWidget *w, bool hasFocus)
{
if (!w)
return;
@@ -824,6 +824,15 @@ void QWinInputContext::enable(QWidget *w, bool e)
void QWinInputContext::setFocusWidget(QWidget *w)
{
+ QWidget *oldFocus = focusWidget();
+ if (oldFocus == w)
+ return;
+ if (w) {
+ QWinInputContext::updateImeStatus(w, true);
+ } else {
+ if (oldFocus)
+ QWinInputContext::updateImeStatus(oldFocus , false);
+ }
QInputContext::setFocusWidget(w);
update();
}
diff --git a/src/gui/inputmethod/qwsinputcontext_p.h b/src/gui/inputmethod/qwsinputcontext_p.h
index 20811da..835cb3f 100644
--- a/src/gui/inputmethod/qwsinputcontext_p.h
+++ b/src/gui/inputmethod/qwsinputcontext_p.h
@@ -87,6 +87,7 @@ public:
static bool translateIMEvent(QWidget *w, const QWSIMEvent *e);
static bool translateIMQueryEvent(QWidget *w, const QWSIMQueryEvent *e);
static bool translateIMInitEvent(const QWSIMInitEvent *e);
+ static void updateImeStatus(QWidget *w, bool hasFocus);
};
QT_END_NAMESPACE
diff --git a/src/gui/inputmethod/qwsinputcontext_qws.cpp b/src/gui/inputmethod/qwsinputcontext_qws.cpp
index 46ac13d..6180c48 100644
--- a/src/gui/inputmethod/qwsinputcontext_qws.cpp
+++ b/src/gui/inputmethod/qwsinputcontext_qws.cpp
@@ -73,10 +73,17 @@ void QWSInputContext::reset()
void QWSInputContext::setFocusWidget( QWidget *w )
{
- QWidget *oldFocus = focusWidget();
+ QWidget *oldFocus = focusWidget();
if (oldFocus == w)
return;
+ if (w) {
+ QWSInputContext::updateImeStatus(w, true);
+ } else {
+ if (oldFocus)
+ QWSInputContext::updateImeStatus(oldFocus, false);
+ }
+
if (oldFocus) {
QWidget *tlw = oldFocus->window();
int winid = tlw->internalWinId();
@@ -224,7 +231,7 @@ bool QWSInputContext::translateIMEvent(QWidget *w, const QWSIMEvent *e)
Q_GUI_EXPORT void (*qt_qws_inputMethodStatusChanged)(QWidget*) = 0;
-void QInputContextPrivate::updateImeStatus(QWidget *w, bool hasFocus)
+void QWSInputContext::updateImeStatus(QWidget *w, bool hasFocus)
{
Q_UNUSED(hasFocus);
diff --git a/src/gui/inputmethod/qximinputcontext_x11.cpp b/src/gui/inputmethod/qximinputcontext_x11.cpp
index c320fb4..b43a134 100644
--- a/src/gui/inputmethod/qximinputcontext_x11.cpp
+++ b/src/gui/inputmethod/qximinputcontext_x11.cpp
@@ -438,7 +438,8 @@ void QXIMInputContext::create_xim()
// server (like SCIM) has been launched without
// requiring the user to manually switch focus.
if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled)
- && focusWidget->testAttribute(Qt::WA_WState_Created))
+ && focusWidget->testAttribute(Qt::WA_WState_Created)
+ && focusWidget->isEnabled())
setFocusWidget(focusWidget);
}
// following code fragment is not required for immodule
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp
index 83e05b4..90c38ca 100644
--- a/src/gui/itemviews/qabstractitemview.cpp
+++ b/src/gui/itemviews/qabstractitemview.cpp
@@ -1426,10 +1426,10 @@ bool QAbstractItemView::viewportEvent(QEvent *event)
case QEvent::HoverEnter: {
QHoverEvent *he = static_cast<QHoverEvent*>(event);
d->hover = indexAt(he->pos());
- d->viewport->update(visualRect(d->hover));
+ update(d->hover);
break; }
case QEvent::HoverLeave: {
- d->viewport->update(visualRect(d->hover)); // update old
+ update(d->hover); // update old
d->hover = QModelIndex();
break; }
case QEvent::HoverMove: {
@@ -1642,7 +1642,7 @@ void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event)
if (d->isIndexValid(index)
&& d->isIndexEnabled(index)
&& d->sendDelegateEvent(index, event))
- d->viewport->update(visualRect(index));
+ update(index);
return;
}
@@ -2165,11 +2165,12 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
}
#endif
bool modified = (event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier));
- if (!event->text().isEmpty() && !modified) {
- if (!edit(currentIndex(), AnyKeyPressed, event))
- keyboardSearch(event->text());
+ if (!event->text().isEmpty() && !modified && !edit(currentIndex(), AnyKeyPressed, event)) {
+ keyboardSearch(event->text());
+ event->accept();
+ } else {
+ event->ignore();
}
- event->ignore();
break; }
}
}
@@ -2325,7 +2326,7 @@ bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEve
}
if (d->sendDelegateEvent(index, event)) {
- d->viewport->update(visualRect(index));
+ update(index);
return true;
}
@@ -2844,9 +2845,9 @@ void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget
d->persistent.insert(widget);
d->addEditor(index, widget, true);
widget->show();
+ dataChanged(index, index); // update the geometry
if (!d->delayedPendingLayout)
widget->setGeometry(visualRect(index));
- dataChanged(index, index); // update the geometry
}
}
@@ -2926,7 +2927,7 @@ void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelInde
}
if (isVisible() && !d->delayedPendingLayout) {
// otherwise the items will be update later anyway
- d->viewport->update(visualRect(topLeft));
+ update(topLeft);
}
return;
}
@@ -3131,9 +3132,7 @@ void QAbstractItemView::selectionChanged(const QItemSelection &selected,
{
Q_D(QAbstractItemView);
if (isVisible() && updatesEnabled()) {
- d->setDirtyRegion(visualRegionForSelection(deselected));
- d->setDirtyRegion(visualRegionForSelection(selected));
- d->updateDirtyRegion();
+ d->viewport->update(visualRegionForSelection(deselected) | visualRegionForSelection(selected));
}
}
@@ -3161,16 +3160,15 @@ void QAbstractItemView::currentChanged(const QModelIndex &current, const QModelI
closeEditor(editor, QAbstractItemDelegate::NoHint);
}
if (isVisible()) {
- d->setDirtyRegion(visualRect(previous));
- d->updateDirtyRegion();
+ update(previous);
}
}
+
if (current.isValid() && !d->autoScrollTimer.isActive()) {
if (isVisible()) {
if (d->autoScroll)
scrollTo(current);
- d->setDirtyRegion(visualRect(current));
- d->updateDirtyRegion();
+ update(current);
edit(current, CurrentChanged, 0);
if (current.row() == (d->model->rowCount(d->root) - 1))
d->_q_fetchMore();
diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h
index 16bd1ab..139d0b7 100644
--- a/src/gui/itemviews/qabstractitemview_p.h
+++ b/src/gui/itemviews/qabstractitemview_p.h
@@ -99,7 +99,7 @@ public:
QVariant data(const QModelIndex &, int) const { return QVariant(); }
};
-class Q_GUI_EXPORT QAbstractItemViewPrivate : public QAbstractScrollAreaPrivate
+class QAbstractItemViewPrivate : public QAbstractScrollAreaPrivate
{
Q_DECLARE_PUBLIC(QAbstractItemView)
diff --git a/src/gui/itemviews/qdirmodel.cpp b/src/gui/itemviews/qdirmodel.cpp
index 7da7c7a..65e3032 100644
--- a/src/gui/itemviews/qdirmodel.cpp
+++ b/src/gui/itemviews/qdirmodel.cpp
@@ -44,6 +44,7 @@
#ifndef QT_NO_DIRMODEL
#include <qstack.h>
#include <qfile.h>
+#include <qfilesystemmodel.h>
#include <qurl.h>
#include <qmime.h>
#include <qpair.h>
@@ -1335,14 +1336,14 @@ QString QDirModelPrivate::size(const QModelIndex &index) const
const quint64 tb = 1024 * gb;
quint64 bytes = n->info.size();
if (bytes >= tb)
- return QLocale().toString(bytes / tb) + QString::fromLatin1(" TB");
+ return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3));
if (bytes >= gb)
- return QLocale().toString(bytes / gb) + QString::fromLatin1(" GB");
+ return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2));
if (bytes >= mb)
- return QLocale().toString(bytes / mb) + QString::fromLatin1(" MB");
+ return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1));
if (bytes >= kb)
- return QLocale().toString(bytes / kb) + QString::fromLatin1(" KB");
- return QLocale().toString(bytes) + QString::fromLatin1(" bytes");
+ return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb));
+ return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes));
}
QString QDirModelPrivate::type(const QModelIndex &index) const
diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp
index ac62551..054f4cf 100644
--- a/src/gui/itemviews/qfileiconprovider.cpp
+++ b/src/gui/itemviews/qfileiconprovider.cpp
@@ -356,7 +356,7 @@ QIcon QFileIconProvider::icon(const QFileInfo &info) const
return icon;
#endif
if (info.isRoot())
-#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined (Q_WS_WIN) && !defined(Q_WS_WINCE)
{
uint type = DRIVE_UNKNOWN;
QT_WA({ type = GetDriveTypeW((wchar_t *)info.absoluteFilePath().utf16()); },
@@ -416,26 +416,22 @@ QString QFileIconProvider::type(const QFileInfo &info) const
}
if (info.isDir())
- return QApplication::translate("QFileDialog",
#ifdef Q_WS_WIN
- "File Folder", "Match Windows Explorer"
+ return QApplication::translate("QFileDialog", "File Folder", "Match Windows Explorer");
#else
- "Folder", "All other platforms"
+ return QApplication::translate("QFileDialog", "Folder", "All other platforms");
#endif
- );
// Windows - "File Folder"
// OS X - "Folder"
// Konqueror - "Folder"
// Nautilus - "folder"
if (info.isSymLink())
- return QApplication::translate("QFileDialog",
#ifdef Q_OS_MAC
- "Alias", "Mac OS X Finder"
+ return QApplication::translate("QFileDialog", "Alias", "Mac OS X Finder");
#else
- "Shortcut", "All other platforms"
+ return QApplication::translate("QFileDialog", "Shortcut", "All other platforms");
#endif
- );
// OS X - "Alias"
// Windows - "Shortcut"
// Konqueror - "Folder" or "TXT File" i.e. what it is pointing to
diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp
index dc63b25..6238df5 100644
--- a/src/gui/itemviews/qheaderview.cpp
+++ b/src/gui/itemviews/qheaderview.cpp
@@ -1195,7 +1195,7 @@ QHeaderView::ResizeMode QHeaderView::resizeMode(int logicalIndex) const
Q_D(const QHeaderView);
int visual = visualIndex(logicalIndex);
Q_ASSERT(visual != -1);
- return d->visualIndexResizeMode(visual);
+ return d->headerSectionResizeMode(visual);
}
/*!
@@ -1234,7 +1234,7 @@ void QHeaderView::setSortIndicatorShown(bool show)
if (sortIndicatorSection() < 0 || sortIndicatorSection() > count())
return;
- if (d->visualIndexResizeMode(sortIndicatorSection()) == ResizeToContents)
+ if (d->headerSectionResizeMode(sortIndicatorSection()) == ResizeToContents)
resizeSections();
d->viewport->update();
@@ -1967,20 +1967,19 @@ void QHeaderView::currentChanged(const QModelIndex &current, const QModelIndex &
if (d->orientation == Qt::Horizontal && current.column() != old.column()) {
if (old.isValid() && old.parent() == d->root)
- d->setDirtyRegion(QRect(sectionViewportPosition(old.column()), 0,
+ d->viewport->update(QRect(sectionViewportPosition(old.column()), 0,
sectionSize(old.column()), d->viewport->height()));
if (current.isValid() && current.parent() == d->root)
- d->setDirtyRegion(QRect(sectionViewportPosition(current.column()), 0,
+ d->viewport->update(QRect(sectionViewportPosition(current.column()), 0,
sectionSize(current.column()), d->viewport->height()));
} else if (d->orientation == Qt::Vertical && current.row() != old.row()) {
if (old.isValid() && old.parent() == d->root)
- d->setDirtyRegion(QRect(0, sectionViewportPosition(old.row()),
+ d->viewport->update(QRect(0, sectionViewportPosition(old.row()),
d->viewport->width(), sectionSize(old.row())));
if (current.isValid() && current.parent() == d->root)
- d->setDirtyRegion(QRect(0, sectionViewportPosition(current.row()),
+ d->viewport->update(QRect(0, sectionViewportPosition(current.row()),
d->viewport->width(), sectionSize(current.row())));
}
- d->updateDirtyRegion();
}
@@ -2934,22 +2933,25 @@ int QHeaderViewPrivate::lastVisibleVisualIndex() const
void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool useGlobalMode)
{
Q_Q(QHeaderView);
+ //stop the timer in case it is delayed
+ delayedResize.stop();
executePostedLayout();
if (sectionCount == 0)
return;
+
+ if (resizeRecursionBlock)
+ return;
+ resizeRecursionBlock = true;
+
invalidateCachedSizeHint();
+ const int lastVisibleSection = lastVisibleVisualIndex();
+
// find stretchLastSection if we have it
int stretchSection = -1;
- if (stretchLastSection && !useGlobalMode) {
- for (int i = sectionCount - 1; i >= 0; --i) {
- if (!isVisualIndexHidden(i)) {
- stretchSection = i;
- break;
- }
- }
- }
+ if (stretchLastSection && !useGlobalMode)
+ stretchSection = lastVisibleVisualIndex();
// count up the number of strected sections and how much space left for them
int lengthToStrech = (orientation == Qt::Horizontal ? viewport->width() : viewport->height());
@@ -2963,7 +2965,7 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool
if (useGlobalMode && (i != stretchSection))
resizeMode = globalMode;
else
- resizeMode = (i == stretchSection ? QHeaderView::Stretch : visualIndexResizeMode(i));
+ resizeMode = (i == stretchSection ? QHeaderView::Stretch : headerSectionResizeMode(i));
if (resizeMode == QHeaderView::Stretch) {
++numberOfStretchedSections;
@@ -2995,7 +2997,6 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool
int spanStartSection = 0;
int previousSectionLength = 0;
- const int lastVisibleSection = lastVisibleVisualIndex();
QHeaderView::ResizeMode previousSectionResizeMode = QHeaderView::Interactive;
@@ -3014,7 +3015,7 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool
else
resizeMode = (i == stretchSection
? QHeaderView::Stretch
- : visualIndexResizeMode(i));
+ : newSectionResizeMode);
if (resizeMode == QHeaderView::Stretch && stretchSectionLength != -1) {
if (i == lastVisibleSection)
newSectionLength = qMax(stretchSectionLength, lastSectionSize);
@@ -3051,7 +3052,7 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool
(sectionCount - spanStartSection) * previousSectionLength,
previousSectionResizeMode);
//Q_ASSERT(headerLength() == length);
-
+ resizeRecursionBlock = false;
viewport->update();
}
diff --git a/src/gui/itemviews/qheaderview_p.h b/src/gui/itemviews/qheaderview_p.h
index 2889f08..cfb1c3e 100644
--- a/src/gui/itemviews/qheaderview_p.h
+++ b/src/gui/itemviews/qheaderview_p.h
@@ -90,6 +90,7 @@ public:
highlightSelected(false),
stretchLastSection(false),
cascadingResizing(false),
+ resizeRecursionBlock(false),
stretchSections(0),
contentsSections(0),
minimumSectionSize(-1),
@@ -169,10 +170,6 @@ public:
if (!sectionHidden.isEmpty()) sectionHidden.setBit(visual, hidden);
}
- inline QHeaderView::ResizeMode visualIndexResizeMode(int visual) const {
- return headerSectionResizeMode(visual);
- }
-
inline bool hasAutoResizeSections() const {
return stretchSections || stretchLastSection || contentsSections;
}
@@ -210,7 +207,7 @@ public:
}
inline bool sectionIsCascadable(int visual) const {
- return visualIndexResizeMode(visual) == QHeaderView::Interactive;
+ return headerSectionResizeMode(visual) == QHeaderView::Interactive;
}
inline int modelSectionCount() const {
@@ -230,7 +227,6 @@ public:
inline void executePostedResize() const {
if (delayedResize.isActive() && state == NoState) {
- delayedResize.stop();
const_cast<QHeaderView*>(q_func())->resizeSections();
}
}
@@ -274,6 +270,7 @@ public:
bool highlightSelected;
bool stretchLastSection;
bool cascadingResizing;
+ bool resizeRecursionBlock;
int stretchSections;
int contentsSections;
int defaultSectionSize;
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp
index 48f53a0..1071c1d 100644
--- a/src/gui/itemviews/qlistview.cpp
+++ b/src/gui/itemviews/qlistview.cpp
@@ -588,7 +588,7 @@ void QListView::scrollTo(const QModelIndex &index, ScrollHint hint)
const QRect rect = visualRect(index);
if (hint == EnsureVisible && d->viewport->rect().contains(rect)) {
- d->setDirtyRegion(rect);
+ d->viewport->update(rect);
return;
}
@@ -755,7 +755,7 @@ void QListView::scrollContentsBy(int dx, int dy)
// update the dragged items
if (d->viewMode == IconMode) // ### move to dynamic class
if (!d->dynamicListView->draggedItems.isEmpty())
- d->setDirtyRegion(d->dynamicListView->draggedItemsRect().translated(dx, dy));
+ d->viewport->update(d->dynamicListView->draggedItemsRect().translated(dx, dy));
}
/*!
@@ -835,7 +835,7 @@ void QListView::mouseMoveEvent(QMouseEvent *e)
&& d->selectionMode != NoSelection) {
QRect rect(d->pressedPosition, e->pos() + QPoint(horizontalOffset(), verticalOffset()));
rect = rect.normalized();
- d->setDirtyRegion(d->mapToViewport(rect.united(d->elasticBand), d->viewMode == QListView::ListMode));
+ d->viewport->update(d->mapToViewport(rect.united(d->elasticBand), d->viewMode == QListView::ListMode));
d->elasticBand = rect;
}
}
@@ -849,7 +849,7 @@ void QListView::mouseReleaseEvent(QMouseEvent *e)
QAbstractItemView::mouseReleaseEvent(e);
// #### move this implementation into a dynamic class
if (d->showElasticBand && d->elasticBand.isValid()) {
- d->setDirtyRegion(d->mapToViewport(d->elasticBand, d->viewMode == QListView::ListMode));
+ d->viewport->update(d->mapToViewport(d->elasticBand, d->viewMode == QListView::ListMode));
d->elasticBand = QRect();
}
}
@@ -914,11 +914,11 @@ void QListView::dragMoveEvent(QDragMoveEvent *e)
if (d->canDecode(e)) {
// get old dragged items rect
QRect itemsRect = d->dynamicListView->itemsRect(d->dynamicListView->draggedItems);
- d->setDirtyRegion(itemsRect.translated(d->dynamicListView->draggedItemsDelta()));
+ d->viewport->update(itemsRect.translated(d->dynamicListView->draggedItemsDelta()));
// update position
d->dynamicListView->draggedItemsPos = e->pos();
// get new items rect
- d->setDirtyRegion(itemsRect.translated(d->dynamicListView->draggedItemsDelta()));
+ d->viewport->update(itemsRect.translated(d->dynamicListView->draggedItemsDelta()));
// set the item under the cursor to current
QModelIndex index;
if (d->movement == Snap) {
@@ -1007,12 +1007,12 @@ void QListView::internalDrop(QDropEvent *event)
for (int i = 0; i < indexes.count(); ++i) {
QModelIndex index = indexes.at(i);
QRect rect = rectForIndex(index);
- d->setDirtyRegion(d->mapToViewport(rect, d->viewMode == QListView::ListMode));
+ d->viewport->update(d->mapToViewport(rect, d->viewMode == QListView::ListMode));
QPoint dest = rect.topLeft() + delta;
if (isRightToLeft())
dest.setX(d->flipX(dest.x()) - rect.width());
d->dynamicListView->moveItem(index.row(), dest);
- d->setDirtyRegion(visualRect(index));
+ update(index);
}
stopAutoScroll();
d->dynamicListView->draggedItems.clear();
@@ -1455,9 +1455,9 @@ void QListView::setPositionForIndex(const QPoint &position, const QModelIndex &i
if (index.row() >= d->dynamicListView->items.count())
return;
const QSize oldContents = d->contentsSize();
- d->setDirtyRegion(visualRect(index)); // update old position
+ update(index); // update old position
d->dynamicListView->moveItem(index.row(), position);
- d->setDirtyRegion(visualRect(index)); // update new position
+ update(index); // update new position
if (d->contentsSize() != oldContents)
updateGeometries(); // update the scroll bars
@@ -1608,6 +1608,10 @@ QRegion QListView::visualRegionForSelection(const QItemSelection &selection) con
if (!selection.at(i).isValid())
continue;
QModelIndex parent = selection.at(i).topLeft().parent();
+ //we only display the children of the root in a listview
+ //we're not interested in the other model indexes
+ if (parent != d->root)
+ continue;
int t = selection.at(i).topLeft().row();
int b = selection.at(i).bottomRight().row();
if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items
@@ -1616,8 +1620,8 @@ QRegion QListView::visualRegionForSelection(const QItemSelection &selection) con
} else { // in static mode, we can optimize a bit
while (t <= b && d->isHidden(t)) ++t;
while (b >= t && d->isHidden(b)) --b;
- const QModelIndex top = d->model->index(t, c, d->root);
- const QModelIndex bottom = d->model->index(b, c, d->root);
+ const QModelIndex top = d->model->index(t, c, parent);
+ const QModelIndex bottom = d->model->index(b, c, parent);
QRect rect(visualRect(top).topLeft(),
visualRect(bottom).bottomRight());
selectionRegion += QRegion(rect);
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index 43feda8..56925b8 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -56,6 +56,15 @@ QT_BEGIN_NAMESPACE
typedef QList<QPair<QModelIndex, QPersistentModelIndex> > QModelIndexPairList;
+static inline QSet<int> qVectorToSet(const QVector<int> &vector)
+{
+ QSet<int> set;
+ set.reserve(vector.size());
+ for(int i=0; i < vector.size(); ++i)
+ set << vector.at(i);
+ return set;
+}
+
class QSortFilterProxyModelLessThan
{
public:
@@ -224,8 +233,8 @@ public:
QModelIndexPairList store_persistent_indexes();
void update_persistent_indexes(const QModelIndexPairList &source_indexes);
- void filter_changed();
- void handle_filter_changed(
+ void filter_changed(const QModelIndex &source_parent = QModelIndex());
+ QSet<int> handle_filter_changed(
QVector<int> &source_to_proxy, QVector<int> &proxy_to_source,
const QModelIndex &source_parent, Qt::Orientation orient);
@@ -937,27 +946,39 @@ void QSortFilterProxyModelPrivate::update_persistent_indexes(
q->changePersistentIndexList(from, to);
}
+
/*!
\internal
Updates the proxy model (adds/removes rows) based on the
new filter.
*/
-void QSortFilterProxyModelPrivate::filter_changed()
+void QSortFilterProxyModelPrivate::filter_changed(const QModelIndex &source_parent)
{
- QMap<QModelIndex, Mapping *>::const_iterator it;
- for (it = source_index_mapping.constBegin(); it != source_index_mapping.constEnd(); ++it) {
- QModelIndex source_parent = it.key();
- Mapping *m = it.value();
- handle_filter_changed(m->proxy_rows, m->source_rows, source_parent, Qt::Vertical);
- handle_filter_changed(m->proxy_columns, m->source_columns, source_parent, Qt::Horizontal);
+ IndexMap::const_iterator it = source_index_mapping.constFind(source_parent);
+ if (it == source_index_mapping.constEnd())
+ return;
+ Mapping *m = it.value();
+ QSet<int> rows_removed = handle_filter_changed(m->proxy_rows, m->source_rows, source_parent, Qt::Vertical);
+ QSet<int> columns_removed = handle_filter_changed(m->proxy_columns, m->source_columns, source_parent, Qt::Horizontal);
+ QVector<QModelIndex>::iterator it2 = m->mapped_children.end();
+ while (it2 != m->mapped_children.begin()) {
+ --it2;
+ const QModelIndex source_child_index = *it2;
+ if (rows_removed.contains(source_child_index.row()) || columns_removed.contains(source_child_index.column())) {
+ it2 = m->mapped_children.erase(it2);
+ remove_from_mapping(source_child_index);
+ } else {
+ filter_changed(source_child_index);
+ }
}
}
/*!
\internal
+ returns the removed items indexes
*/
-void QSortFilterProxyModelPrivate::handle_filter_changed(
+QSet<int> QSortFilterProxyModelPrivate::handle_filter_changed(
QVector<int> &source_to_proxy, QVector<int> &proxy_to_source,
const QModelIndex &source_parent, Qt::Orientation orient)
{
@@ -994,6 +1015,7 @@ void QSortFilterProxyModelPrivate::handle_filter_changed(
insert_source_items(source_to_proxy, proxy_to_source,
source_items_insert, source_parent, orient);
}
+ return qVectorToSet(source_items_remove);
}
void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &source_top_left,
@@ -1044,15 +1066,14 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc
if (!source_rows_remove.isEmpty()) {
remove_source_items(m->proxy_rows, m->source_rows,
source_rows_remove, source_parent, Qt::Vertical);
- QSet<int> source_rows_remove_set = source_rows_remove.toList().toSet();
- QVector<QModelIndex>::iterator it = m->mapped_children.begin();
- while (it != m->mapped_children.end()) {
+ QSet<int> source_rows_remove_set = qVectorToSet(source_rows_remove);
+ QVector<QModelIndex>::iterator it = m->mapped_children.end();
+ while (it != m->mapped_children.begin()) {
+ --it;
const QModelIndex source_child_index = *it;
if (source_rows_remove_set.contains(source_child_index.row())) {
it = m->mapped_children.erase(it);
remove_from_mapping(source_child_index);
- } else {
- ++it;
}
}
}
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp
index 2902768..757ecf2 100644
--- a/src/gui/itemviews/qtableview.cpp
+++ b/src/gui/itemviews/qtableview.cpp
@@ -59,6 +59,138 @@
QT_BEGIN_NAMESPACE
+/** \internal
+ Add a span to the collection. the collection takes the ownership.
+ */
+void QSpanCollection::addSpan(QSpanCollection::Span *span)
+{
+ spans.append(span);
+ Index::iterator it_y = index.lowerBound(-span->top());
+ if (it_y == index.end() || it_y.key() != -span->top()) {
+ //there is no spans that starts with the row in the index, so create a sublist for it.
+ SubIndex sub_index;
+ if (it_y != index.end()) {
+ //the previouslist is the list of spans that sarts _before_ the row of the span.
+ // and which may intersect this row.
+ const SubIndex previousList = it_y.value();
+ foreach(Span *s, previousList) {
+ //If a subspans intersect the row, we need to split it into subspans
+ if(s->bottom() >= span->top())
+ sub_index.insert(-s->left(), s);
+ }
+ }
+ it_y = index.insert(-span->top(), sub_index);
+ //we will insert span to *it_y in the later loop
+ }
+
+ //insert the span as supspan in all the lists that intesects the span
+ while(-it_y.key() <= span->bottom()) {
+ (*it_y).insert(-span->left(), span);
+ if(it_y == index.begin())
+ break;
+ --it_y;
+ }
+}
+
+
+/** \internal
+* Has to be called after the height and width of a span is changed.
+*
+* old_height is the height before the change
+*
+* if the size of the span is now 0x0 the span will be deleted.
+*/
+void QSpanCollection::updateSpan(QSpanCollection::Span *span, int old_height)
+{
+ if (old_height < span->height()) {
+ //add the span as subspan in all the lists that intersect the new covered columns
+ Index::iterator it_y = index.lowerBound(-(span->top() + old_height - 1));
+ Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list
+ while (-it_y.key() <= span->bottom()) {
+ (*it_y).insert(-span->left(), span);
+ if(it_y == index.begin())
+ break;
+ --it_y;
+ }
+ } else if (old_height > span->height()) {
+ //remove the span from all the subspans lists that intersect the columns not covered anymore
+ Index::iterator it_y = index.lowerBound(-span->bottom());
+ Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list
+ while (-it_y.key() <= span->top() + old_height -1) {
+ if(-it_y.key() != span->bottom()) {
+ (*it_y).remove(-span->left());
+ if (it_y->isEmpty()) {
+ it_y = index.erase(it_y) - 1;
+ }
+ }
+ if(it_y == index.begin())
+ break;
+ --it_y;
+ }
+ }
+
+ if (span->width() == 0 && span->height() == 0) {
+ spans.removeOne(span);
+ delete span;
+ }
+}
+
+/** \internal
+ * \return a spans that spans over cell x,y (column,row) or 0 if there is none.
+ */
+QSpanCollection::Span *QSpanCollection::spanAt(int x, int y) const
+{
+ Index::const_iterator it_y = index.lowerBound(-y);
+ if (it_y == index.end())
+ return 0;
+ SubIndex::const_iterator it_x = (*it_y).lowerBound(-x);
+ if (it_x == (*it_y).end())
+ return 0;
+ Span *span = *it_x;
+ if (span->right() >= x && span->bottom() >= y)
+ return span;
+ return 0;
+}
+
+
+/** \internal
+* remove and deletes all spans inside the collection
+*/
+void QSpanCollection::clear()
+{
+ qDeleteAll(spans);
+ index.clear();
+ spans.clear();
+}
+
+/** \internal
+ * return a list to all the spans that spans over cells in the given rectangle
+ */
+QList<QSpanCollection::Span *> QSpanCollection::spansInRect(int x, int y, int w, int h) const
+{
+ QSet<Span *> list;
+ Index::const_iterator it_y = index.lowerBound(-y);
+ if(it_y == index.end())
+ --it_y;
+ while(-it_y.key() <= y + h) {
+ SubIndex::const_iterator it_x = (*it_y).lowerBound(-x);
+ if (it_x == (*it_y).end())
+ --it_x;
+ while(-it_x.key() <= x + w) {
+ Span *s = *it_x;
+ if (s->bottom() >= y && s->right() >= x)
+ list << s;
+ if (it_x == (*it_y).begin())
+ break;
+ --it_x;
+ }
+ if(it_y == index.begin())
+ break;
+ --it_y;
+ }
+ return list.toList();
+}
+
class QTableCornerButton : public QAbstractButton
{
Q_OBJECT
@@ -149,35 +281,40 @@ void QTableViewPrivate::trimHiddenSelections(QItemSelectionRange *range) const
*/
void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan)
{
- if (row < 0 || column < 0 || rowSpan < 0 || columnSpan < 0)
+ if (row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0) {
+ qWarning() << "QTableView::setSpan: invalid span given: (" << row << "," << column << "," << rowSpan << "," << columnSpan << ")";
return;
- Span sp(row, column, rowSpan, columnSpan);
- QList<Span>::iterator it;
- for (it = spans.begin(); it != spans.end(); ++it) {
- if (((*it).top() == sp.top()) && ((*it).left() == sp.left())) {
- if ((sp.height() == 1) && (sp.width() == 1))
- spans.erase(it); // "Implicit" span (1, 1), no need to store it
- else
- *it = sp; // Replace
+ }
+ QSpanCollection::Span *sp = spans.spanAt(column, row);
+ if (sp) {
+ if (sp->top() != row || sp->left() != column) {
+ qWarning() << "QTableView::setSpan: span cannot overlap";
return;
}
+ if (rowSpan == 1 && columnSpan == 1) {
+ rowSpan = columnSpan = 0;
+ }
+ const int old_height = sp->height();
+ sp->m_bottom = row + rowSpan - 1;
+ sp->m_right = column + columnSpan - 1;
+ spans.updateSpan(sp, old_height);
+ return;
}
- spans.append(sp);
+ sp = new QSpanCollection::Span(row, column, rowSpan, columnSpan);
+ spans.addSpan(sp);
}
/*!
\internal
Gets the span information for the cell at (\a row, \a column).
*/
-QTableViewPrivate::Span QTableViewPrivate::span(int row, int column) const
+QSpanCollection::Span QTableViewPrivate::span(int row, int column) const
{
- QList<Span>::const_iterator it;
- for (it = spans.constBegin(); it != spans.constEnd(); ++it) {
- Span span = *it;
- if (isInSpan(row, column, span))
- return span;
- }
- return Span(row, column, 1, 1);
+ QSpanCollection::Span *sp = spans.spanAt(column, row);
+ if (sp)
+ return *sp;
+
+ return QSpanCollection::Span(row, column, 1, 1);
}
/*!
@@ -233,67 +370,9 @@ bool QTableViewPrivate::spanContainsSection(const QHeaderView *header, int logic
/*!
\internal
- Returns true if one or more spans intersect column \a column.
-*/
-bool QTableViewPrivate::spansIntersectColumn(int column) const
-{
- QList<Span>::const_iterator it;
- for (it = spans.constBegin(); it != spans.constEnd(); ++it) {
- Span span = *it;
- if (spanContainsColumn(column, span.left(), span.width()))
- return true;
- }
- return false;
-}
-
-/*!
- \internal
- Returns true if one or more spans intersect row \a row.
-*/
-bool QTableViewPrivate::spansIntersectRow(int row) const
-{
- QList<Span>::const_iterator it;
- for (it = spans.constBegin(); it != spans.constEnd(); ++it) {
- Span span = *it;
- if (spanContainsRow(row, span.top(), span.height()))
- return true;
- }
- return false;
-}
-
-/*!
- \internal
- Returns true if one or more spans intersect one or more columns.
-*/
-bool QTableViewPrivate::spansIntersectColumns(const QList<int> &columns) const
-{
- QList<int>::const_iterator it;
- for (it = columns.constBegin(); it != columns.constEnd(); ++it) {
- if (spansIntersectColumn(*it))
- return true;
- }
- return false;
-}
-
-/*!
- \internal
- Returns true if one or more spans intersect one or more rows.
-*/
-bool QTableViewPrivate::spansIntersectRows(const QList<int> &rows) const
-{
- QList<int>::const_iterator it;
- for (it = rows.constBegin(); it != rows.constEnd(); ++it) {
- if (spansIntersectRow(*it))
- return true;
- }
- return false;
-}
-
-/*!
- \internal
Returns the visual rect for the given \a span.
*/
-QRect QTableViewPrivate::visualSpanRect(const Span &span) const
+QRect QTableViewPrivate::visualSpanRect(const QSpanCollection::Span &span) const
{
Q_Q(const QTableView);
// vertical
@@ -319,42 +398,54 @@ QRect QTableViewPrivate::visualSpanRect(const Span &span) const
preparation for the main drawing loop.
\a drawn is a QBitArray of visualRowCountxvisualCoulumnCount which say if particular cell has been drawn
*/
-void QTableViewPrivate::drawAndClipSpans(const QRect &area, QPainter *painter,
+void QTableViewPrivate::drawAndClipSpans(const QRegion &area, QPainter *painter,
const QStyleOptionViewItemV4 &option, QBitArray *drawn,
int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn)
{
bool alternateBase = false;
QRegion region = viewport->rect();
- QList<Span>::const_iterator it;
- for (it = spans.constBegin(); it != spans.constEnd(); ++it) {
- Span span = *it;
+ QList<QSpanCollection::Span *> visibleSpans;
+ bool sectionMoved = verticalHeader->sectionsMoved() || horizontalHeader->sectionsMoved();
+
+ if (!sectionMoved) {
+ visibleSpans = spans.spansInRect(logicalColumn(firstVisualColumn), logicalRow(firstVisualRow),
+ lastVisualColumn - firstVisualColumn + 1, lastVisualRow - firstVisualRow + 1);
+ } else {
+ QSet<QSpanCollection::Span *> set;
+ for(int x = firstVisualColumn; x <= lastVisualColumn; x++)
+ for(int y = firstVisualRow; y <= lastVisualRow; y++)
+ set.insert(spans.spanAt(x,y));
+ set.remove(0);
+ visibleSpans = set.toList();
+ }
- int row = span.top();
- int col = span.left();
+ foreach (QSpanCollection::Span *span, visibleSpans) {
+ int row = span->top();
+ int col = span->left();
if (isHidden(row, col))
continue;
QModelIndex index = model->index(row, col, root);
if (!index.isValid())
continue;
- QRect rect = visualSpanRect(span);
+ QRect rect = visualSpanRect(*span);
rect.translate(scrollDelayOffset);
- if (!rect.intersects(area))
+ if (!area.intersects(rect))
continue;
QStyleOptionViewItemV4 opt = option;
opt.rect = rect;
- alternateBase = alternatingColors && (span.top() & 1);
+ alternateBase = alternatingColors && (span->top() & 1);
if (alternateBase)
opt.features |= QStyleOptionViewItemV2::Alternate;
else
opt.features &= ~QStyleOptionViewItemV2::Alternate;
drawCell(painter, opt, index);
region -= rect;
- for (int r = span.top(); r <= span.bottom(); ++r) {
+ for (int r = span->top(); r <= span->bottom(); ++r) {
const int vr = visualRow(r);
if (vr < firstVisualRow || vr > lastVisualRow)
continue;
- for (int c = span.left(); c <= span.right(); ++c) {
+ for (int c = span->left(); c <= span->right(); ++c) {
const int vc = visualColumn(c);
if (vc < firstVisualColumn || vc > lastVisualColumn)
continue;
@@ -753,7 +844,8 @@ void QTableView::paintEvent(QPaintEvent *event)
uint x = horizontalHeader->length() - horizontalHeader->offset() - (rightToLeft ? 0 : 1);
uint y = verticalHeader->length() - verticalHeader->offset() - 1;
- QVector<QRect> rects = event->region().rects();
+ const QRegion region = event->region().translated(offset);
+ const QVector<QRect> rects = region.rects();
//firstVisualRow is the visual index of the first visible row. lastVisualRow is the visual index of the last visible Row.
//same goes for ...VisualColumn
@@ -773,9 +865,13 @@ void QTableView::paintEvent(QPaintEvent *event)
QBitArray drawn((lastVisualRow - firstVisualRow + 1) * (lastVisualColumn - firstVisualColumn + 1));
+ if (d->hasSpans()) {
+ d->drawAndClipSpans(region, &painter, option, &drawn,
+ firstVisualRow, lastVisualRow, firstVisualColumn, lastVisualColumn);
+ }
+
for (int i = 0; i < rects.size(); ++i) {
QRect dirtyArea = rects.at(i);
- dirtyArea.translate(offset);
dirtyArea.setBottom(qMin(dirtyArea.bottom(), int(y)));
if (rightToLeft) {
dirtyArea.setLeft(qMax(dirtyArea.left(), d->viewport->width() - int(x)));
@@ -783,10 +879,6 @@ void QTableView::paintEvent(QPaintEvent *event)
dirtyArea.setRight(qMin(dirtyArea.right(), int(x)));
}
- if (d->hasSpans())
- d->drawAndClipSpans(dirtyArea, &painter, option, &drawn,
- firstVisualRow, lastVisualRow, firstVisualColumn, lastVisualColumn);
-
// get the horizontal start and end visual sections
int left = horizontalHeader->visualIndexAt(dirtyArea.left());
int right = horizontalHeader->visualIndexAt(dirtyArea.right());
@@ -913,7 +1005,7 @@ QModelIndex QTableView::indexAt(const QPoint &pos) const
int c = columnAt(pos.x());
if (r >= 0 && c >= 0) {
if (d->hasSpans()) {
- QTableViewPrivate::Span span = d->span(r, c);
+ QSpanCollection::Span span = d->span(r, c);
r = span.top();
c = span.left();
}
@@ -1011,14 +1103,14 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
--visualRow;
if (d->hasSpans()) {
int row = d->logicalRow(visualRow);
- QTableViewPrivate::Span span = d->span(row, current.column());
+ QSpanCollection::Span span = d->span(row, current.column());
visualRow = d->visualRow(span.top());
visualColumn = d->visualColumn(span.left());
}
break;
case MoveDown:
if (d->hasSpans()) {
- QTableViewPrivate::Span span = d->span(current.row(), current.column());
+ QSpanCollection::Span span = d->span(current.row(), current.column());
visualRow = d->visualRow(d->rowSpanEndLogical(span.top(), span.height()));
}
#ifdef QT_KEYPAD_NAVIGATION
@@ -1030,7 +1122,7 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
++visualRow;
if (d->hasSpans()) {
int row = d->logicalRow(visualRow);
- QTableViewPrivate::Span span = d->span(row, current.column());
+ QSpanCollection::Span span = d->span(row, current.column());
visualColumn = d->visualColumn(span.left());
}
break;
@@ -1058,7 +1150,7 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
--visualColumn;
if (d->hasSpans()) {
int column = d->logicalColumn(visualColumn);
- QTableViewPrivate::Span span = d->span(current.row(), column);
+ QSpanCollection::Span span = d->span(current.row(), column);
visualRow = d->visualRow(span.top());
visualColumn = d->visualColumn(span.left());
}
@@ -1078,7 +1170,7 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
} // else MoveRight
case MoveRight:
if (d->hasSpans()) {
- QTableViewPrivate::Span span = d->span(current.row(), current.column());
+ QSpanCollection::Span span = d->span(current.row(), current.column());
visualColumn = d->visualColumn(d->columnSpanEndLogical(span.left(), span.width()));
}
++visualColumn;
@@ -1086,7 +1178,7 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi
++visualColumn;
if (d->hasSpans()) {
int column = d->logicalColumn(visualColumn);
- QTableViewPrivate::Span span = d->span(current.row(), column);
+ QSpanCollection::Span span = d->span(current.row(), column);
visualRow = d->visualRow(span.top());
}
break;
@@ -1161,9 +1253,8 @@ void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionF
int right = qMax(d->visualColumn(tl.column()), d->visualColumn(br.column()));
do {
expanded = false;
- QList<QTableViewPrivate::Span>::const_iterator it;
- for (it = d->spans.constBegin(); it != d->spans.constEnd(); ++it) {
- QTableViewPrivate::Span span = *it;
+ foreach (QSpanCollection::Span *it, d->spans.spans) {
+ const QSpanCollection::Span &span = *it;
int t = d->visualRow(span.top());
int l = d->visualColumn(span.left());
int b = d->visualRow(d->rowSpanEndLogical(span.top(), span.height()));
@@ -1253,7 +1344,7 @@ QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) co
bool verticalMoved = verticalHeader()->sectionsMoved();
bool horizontalMoved = horizontalHeader()->sectionsMoved();
- if ((verticalMoved && horizontalMoved) || d->hasSpans()) {
+ if ((verticalMoved && horizontalMoved) || (d->hasSpans() && (verticalMoved || horizontalMoved))) {
for (int i = 0; i < selection.count(); ++i) {
QItemSelectionRange range = selection.at(i);
if (range.parent() != d->root || !range.isValid())
@@ -1296,9 +1387,19 @@ QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) co
if (range.parent() != d->root || !range.isValid())
continue;
d->trimHiddenSelections(&range);
- QRect tl = visualRect(range.topLeft());
- QRect br = visualRect(range.bottomRight());
- selectionRegion += QRegion(tl|br);
+
+ const int rtop = rowViewportPosition(range.top());
+ const int rbottom = rowViewportPosition(range.bottom()) + rowHeight(range.bottom());
+ const int rleft = columnViewportPosition(range.left());
+ const int rright = columnViewportPosition(range.right()) + columnWidth(range.right());
+ selectionRegion += QRect(QPoint(rleft, rtop), QPoint(rright, rbottom));
+ if (d->hasSpans()) {
+ foreach (QSpanCollection::Span *s,
+ d->spans.spansInRect(range.left(), range.top(), range.width(), range.height())) {
+ if (range.contains(s->top(), s->left(), range.parent()))
+ selectionRegion += d->visualSpanRect(*s);
+ }
+ }
}
}
@@ -1874,7 +1975,7 @@ QRect QTableView::visualRect(const QModelIndex &index) const
d->executePostedLayout();
if (d->hasSpans()) {
- QTableViewPrivate::Span span = d->span(index.row(), index.column());
+ QSpanCollection::Span span = d->span(index.row(), index.column());
return d->visualSpanRect(span);
}
@@ -1903,7 +2004,7 @@ void QTableView::scrollTo(const QModelIndex &index, ScrollHint hint)
|| isIndexHidden(index))
return;
- QTableViewPrivate::Span span;
+ QSpanCollection::Span span;
if (d->hasSpans())
span = d->span(index.row(), index.column());
@@ -2010,7 +2111,7 @@ void QTableView::scrollTo(const QModelIndex &index, ScrollHint hint)
}
}
- d->setDirtyRegion(visualRect(index));
+ update(index);
}
/*!
@@ -2058,7 +2159,7 @@ void QTableView::timerEvent(QTimerEvent *event)
QRect rect;
int viewportHeight = d->viewport->height();
int viewportWidth = d->viewport->width();
- if (d->hasSpans() && d->spansIntersectColumns(d->columnsToUpdate)) {
+ if (d->hasSpans()) {
rect = QRect(0, 0, viewportWidth, viewportHeight);
} else {
for (int i = d->columnsToUpdate.size()-1; i >= 0; --i) {
@@ -2083,7 +2184,7 @@ void QTableView::timerEvent(QTimerEvent *event)
int viewportHeight = d->viewport->height();
int viewportWidth = d->viewport->width();
int top;
- if (d->hasSpans() && d->spansIntersectRows(d->rowsToUpdate)) {
+ if (d->hasSpans()) {
top = 0;
} else {
top = viewportHeight;
@@ -2114,7 +2215,7 @@ void QTableView::rowMoved(int, int oldIndex, int newIndex)
updateGeometries();
int logicalOldIndex = d->verticalHeader->logicalIndex(oldIndex);
int logicalNewIndex = d->verticalHeader->logicalIndex(newIndex);
- if (d->hasSpans() && (d->spansIntersectRow(logicalOldIndex) || d->spansIntersectRow(logicalNewIndex))) {
+ if (d->hasSpans()) {
d->viewport->update();
} else {
int oldTop = rowViewportPosition(logicalOldIndex);
@@ -2142,7 +2243,7 @@ void QTableView::columnMoved(int, int oldIndex, int newIndex)
updateGeometries();
int logicalOldIndex = d->horizontalHeader->logicalIndex(oldIndex);
int logicalNewIndex = d->horizontalHeader->logicalIndex(newIndex);
- if (d->hasSpans() && (d->spansIntersectColumn(logicalOldIndex) || d->spansIntersectColumn(logicalNewIndex))) {
+ if (d->hasSpans()) {
d->viewport->update();
} else {
int oldLeft = columnViewportPosition(logicalOldIndex);
@@ -2325,7 +2426,7 @@ bool QTableView::isIndexHidden(const QModelIndex &index) const
if (isRowHidden(index.row()) || isColumnHidden(index.column()))
return true;
if (d->hasSpans()) {
- QTableViewPrivate::Span span = d->span(index.row(), index.column());
+ QSpanCollection::Span span = d->span(index.row(), index.column());
return !((span.top() == index.row()) && (span.left() == index.column()));
}
return false;
diff --git a/src/gui/itemviews/qtableview_p.h b/src/gui/itemviews/qtableview_p.h
index b08eabd..3f3dd36 100644
--- a/src/gui/itemviews/qtableview_p.h
+++ b/src/gui/itemviews/qtableview_p.h
@@ -53,12 +53,69 @@
// We mean it.
//
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QSet>
+#include <QtCore/QDebug>
#include "private/qabstractitemview_p.h"
#ifndef QT_NO_TABLEVIEW
QT_BEGIN_NAMESPACE
+/** \internal
+*
+* This is a list of span with a binary index to look up quickly a span at a certain index.
+*
+* The index is a map of map.
+* spans are mentaly divided into sub spans so that the start of any subspans doesn't overlap
+* with any other subspans. There is no real representation of the subspans.
+* The key of the first map is the row where the subspan starts, the value of the first map is
+* a list (map) of all subspans that starts at the same row. It is indexed with its row
+*/
+class QSpanCollection
+{
+public:
+ struct Span
+ {
+ int m_top;
+ int m_left;
+ int m_bottom;
+ int m_right;
+ Span()
+ : m_top(-1), m_left(-1), m_bottom(-1), m_right(-1) { }
+ Span(int row, int column, int rowCount, int columnCount)
+ : m_top(row), m_left(column), m_bottom(row+rowCount-1), m_right(column+columnCount-1) { }
+ inline int top() const { return m_top; }
+ inline int left() const { return m_left; }
+ inline int bottom() const { return m_bottom; }
+ inline int right() const { return m_right; }
+ inline int height() const { return m_bottom - m_top + 1; }
+ inline int width() const { return m_right - m_left + 1; }
+ };
+
+ ~QSpanCollection()
+ {
+ qDeleteAll(spans);
+ }
+
+ void addSpan(Span *span);
+ void updateSpan(Span *span, int old_height);
+ Span *spanAt(int x, int y) const;
+ void clear();
+ QList<Span *> spansInRect(int x, int y, int w, int h) const;
+
+ QList<Span *> spans; //lists of all spans
+private:
+ //the indexes are negative so the QMap::lowerBound do what i need.
+ typedef QMap<int, Span *> SubIndex;
+ typedef QMap<int, SubIndex> Index;
+ Index index;
+};
+
+Q_DECLARE_TYPEINFO ( QSpanCollection::Span, Q_MOVABLE_TYPE);
+
+
class QTableViewPrivate : public QAbstractItemViewPrivate
{
Q_DECLARE_PUBLIC(QTableView)
@@ -98,11 +155,7 @@ public:
int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const;
int sectionSpanSize(const QHeaderView *header, int logical, int span) const;
bool spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const;
- bool spansIntersectColumn(int column) const;
- bool spansIntersectRow(int row) const;
- bool spansIntersectColumns(const QList<int> &columns) const;
- bool spansIntersectRows(const QList<int> &rows) const;
- void drawAndClipSpans(const QRect &area, QPainter *painter,
+ void drawAndClipSpans(const QRegion &area, QPainter *painter,
const QStyleOptionViewItemV4 &option, QBitArray *drawn,
int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn);
void drawCell(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index);
@@ -121,27 +174,10 @@ public:
bool sortingEnabled;
bool geometryRecursionBlock;
- struct Span
- {
- int m_top;
- int m_left;
- int m_bottom;
- int m_right;
- Span()
- : m_top(-1), m_left(-1), m_bottom(-1), m_right(-1) { }
- Span(int row, int column, int rowCount, int columnCount)
- : m_top(row), m_left(column), m_bottom(row+rowCount-1), m_right(column+columnCount-1) { }
- inline int top() const { return m_top; }
- inline int left() const { return m_left; }
- inline int bottom() const { return m_bottom; }
- inline int right() const { return m_right; }
- inline int height() const { return m_bottom - m_top + 1; }
- inline int width() const { return m_right - m_left + 1; }
- };
- QList<Span> spans;
+ QSpanCollection spans;
void setSpan(int row, int column, int rowSpan, int columnSpan);
- Span span(int row, int column) const;
+ QSpanCollection::Span span(int row, int column) const;
inline int rowSpan(int row, int column) const {
return span(row, column).height();
}
@@ -149,17 +185,7 @@ public:
return span(row, column).width();
}
inline bool hasSpans() const {
- return !spans.isEmpty();
- }
- inline bool spanContainsRow(int row, int spanRow, int span) const {
- return spanContainsSection(verticalHeader, row, spanRow, span);
- }
- inline bool spanContainsColumn(int column, int spanColumn, int span) const {
- return spanContainsSection(horizontalHeader, column, spanColumn, span);
- }
- inline bool isInSpan(int row, int column, const Span &span) const {
- return spanContainsRow(row, span.top(), span.height())
- && spanContainsColumn(column, span.left(), span.width());
+ return !spans.spans.isEmpty();
}
inline int rowSpanHeight(int row, int span) const {
return sectionSpanSize(verticalHeader, row, span);
@@ -194,7 +220,7 @@ public:
return isColumnHidden(c) || !isCellEnabled(r, c);
}
- QRect visualSpanRect(const Span &span) const;
+ QRect visualSpanRect(const QSpanCollection::Span &span) const;
void _q_selectRow(int row);
void _q_selectColumn(int column);
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index 62c1277..d742698 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -680,10 +680,9 @@ void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto
// refresh the height cache here; we don't really lose anything by getting the size hint,
// since QAbstractItemView::dataChanged() will get the visualRect for the items anyway
- QModelIndex top = topLeft.sibling(topLeft.row(), 0);
- int topViewIndex = d->viewIndex(top);
+ int topViewIndex = d->viewIndex(topLeft);
if (topViewIndex == 0)
- d->defaultItemHeight = indexRowSizeHint(top);
+ d->defaultItemHeight = indexRowSizeHint(topLeft);
bool sizeChanged = false;
if (topViewIndex != -1) {
if (topLeft == bottomRight) {
@@ -691,8 +690,7 @@ void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto
d->invalidateHeightCache(topViewIndex);
sizeChanged = (oldHeight != d->itemHeight(topViewIndex));
} else {
- QModelIndex bottom = bottomRight.sibling(bottomRight.row(), 0);
- int bottomViewIndex = d->viewIndex(bottom);
+ int bottomViewIndex = d->viewIndex(bottomRight);
for (int i = topViewIndex; i <= bottomViewIndex; ++i) {
int oldHeight = d->itemHeight(i);
d->invalidateHeightCache(i);
@@ -1140,7 +1138,7 @@ void QTreeView::scrollTo(const QModelIndex &index, ScrollHint hint)
if (rect.isEmpty()) {
// nothing to do
} else if (hint == EnsureVisible && area.contains(rect)) {
- d->setDirtyRegion(rect);
+ d->viewport->update(rect);
// nothing to do
} else {
bool above = (hint == EnsureVisible
@@ -1546,7 +1544,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
? logicalIndexBeforeLeft
: logicalIndices.at(currentLogicalSection - 1);
if (columnCount == 1 || (nextLogicalSection == 0 && prevLogicalSection == -1)
- || (headerSection == 0 && nextLogicalSection == -1))
+ || (headerSection == 0 && nextLogicalSection == -1) || spanning)
opt.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
else if (headerSection == 0 || (nextLogicalSection != 0 && prevLogicalSection == -1))
opt.viewItemPosition = QStyleOptionViewItemV4::Beginning;
@@ -1815,10 +1813,10 @@ void QTreeView::mouseDoubleClickEvent(QMouseEvent *event)
if (i == -1)
return; // user clicked outside the items
- const QModelIndex &index = d->viewItems.at(i).index;
+ const QPersistentModelIndex firstColumnIndex = d->viewItems.at(i).index;
int column = d->header->logicalIndexAt(event->x());
- QPersistentModelIndex persistent = index.sibling(index.row(), column);
+ QPersistentModelIndex persistent = firstColumnIndex.sibling(firstColumnIndex.row(), column);
if (d->pressedIndex != persistent) {
mousePressEvent(event);
@@ -1841,10 +1839,10 @@ void QTreeView::mouseDoubleClickEvent(QMouseEvent *event)
if (d->itemsExpandable
&& d->expandsOnDoubleClick
&& d->hasVisibleChildren(persistent)) {
- if (!((i < d->viewItems.count()) && (d->viewItems.at(i).index == persistent))) {
+ if (!((i < d->viewItems.count()) && (d->viewItems.at(i).index == firstColumnIndex))) {
// find the new index of the item
for (i = 0; i < d->viewItems.count(); ++i) {
- if (d->viewItems.at(i).index == persistent)
+ if (d->viewItems.at(i).index == firstColumnIndex)
break;
}
if (i == d->viewItems.count())
@@ -2422,14 +2420,10 @@ void QTreeView::rowsInserted(const QModelIndex &parent, int start, int end)
? d->viewItems.count()
: d->viewItems.at(parentItem).total) - 1;
- int firstColumn = 0;
- while (isColumnHidden(firstColumn) && firstColumn < header()->count() - 1)
- ++firstColumn;
-
const int delta = end - start + 1;
QVector<QTreeViewItem> insertedItems(delta);
for (int i = 0; i < delta; ++i) {
- insertedItems[i].index = d->model->index(i + start, firstColumn, parent);
+ insertedItems[i].index = d->model->index(i + start, 0, parent);
insertedItems[i].level = childLevel;
}
if (d->viewItems.isEmpty())
@@ -2612,7 +2606,7 @@ void QTreeView::expandAll()
d->viewItems[i].expanded = true;
d->layout(i);
QModelIndex idx = d->viewItems.at(i).index;
- d->expandedIndexes.insert(idx.sibling(idx.row(), 0));
+ d->expandedIndexes.insert(idx);
}
updateGeometries();
d->viewport->update();
@@ -3092,10 +3086,6 @@ void QTreeViewPrivate::layout(int i)
Q_Q(QTreeView);
QModelIndex current;
QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i);
- // modelIndex() will return an index that don't have a parent if column 0 is hidden,
- // so we must make sure that parent points to the actual parent that has children.
- if (parent != root)
- parent = model->index(parent.row(), 0, parent.parent());
if (i>=0 && !parent.isValid()) {
//modelIndex() should never return something invalid for the real items.
@@ -3130,13 +3120,9 @@ void QTreeViewPrivate::layout(int i)
int last = 0;
int children = 0;
- int firstColumn = 0;
- while (header->isSectionHidden(firstColumn) && firstColumn < header->count())
- ++firstColumn;
-
for (int j = first; j < first + count; ++j) {
- current = model->index(j - first, firstColumn, parent);
- if (isRowHidden(current.sibling(current.row(), 0))) {
+ current = model->index(j - first, 0, parent);
+ if (isRowHidden(current)) {
++hidden;
last = j - hidden + children;
} else {
@@ -3319,15 +3305,11 @@ int QTreeViewPrivate::itemAtCoordinate(int coordinate) const
int QTreeViewPrivate::viewIndex(const QModelIndex &_index) const
{
- Q_Q(const QTreeView);
if (!_index.isValid() || viewItems.isEmpty())
return -1;
const int totalCount = viewItems.count();
- int firstColumn = 0;
- while (q->isColumnHidden(firstColumn) && firstColumn < header->count())
- ++firstColumn;
- const QModelIndex index = _index.sibling(_index.row(), firstColumn);
+ const QModelIndex index = _index.sibling(_index.row(), 0);
// A quick check near the last item to see if we are just incrementing
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
index cb2b014..a1b982a 100644
--- a/src/gui/kernel/kernel.pri
+++ b/src/gui/kernel/kernel.pri
@@ -193,7 +193,7 @@ embedded {
MENU_NIB.path = Resources
MENU_NIB.version = Versions
QMAKE_BUNDLE_DATA += MENU_NIB
- RESOURCES += mac/maccursors.qrc
+ RESOURCES += mac/macresources.qrc
LIBS += -framework AppKit
}
diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp
index abb17d7..b2afbd0 100644
--- a/src/gui/kernel/qaction.cpp
+++ b/src/gui/kernel/qaction.cpp
@@ -1151,6 +1151,8 @@ void QAction::activate(ActionEvent event)
// the checked action of an exclusive group cannot be unchecked
if (d->checked && (d->group && d->group->isExclusive()
&& d->group->checkedAction() == this)) {
+ if (guard)
+ emit triggered(true);
QMetaObject::removeGuard(&guard);
return;
}
@@ -1368,7 +1370,7 @@ QAction::MenuRole QAction::menuRole() const
void QAction::setIconVisibleInMenu(bool visible)
{
Q_D(QAction);
- if (visible != (bool)d->iconVisibleInMenu) {
+ if (d->iconVisibleInMenu == -1 || visible != bool(d->iconVisibleInMenu)) {
int oldValue = d->iconVisibleInMenu;
d->iconVisibleInMenu = visible;
// Only send data changed if we really need to.
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index 4cf0ad7..824d6f1 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -89,7 +89,7 @@
#include "qapplication.h"
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include "qdatetime.h"
#include "qguifunctions_wince.h"
extern bool qt_wince_is_smartphone(); //qguifunctions_wince.cpp
@@ -101,15 +101,12 @@ extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp
static void initResources()
{
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
Q_INIT_RESOURCE(qstyle_wince);
#else
Q_INIT_RESOURCE(qstyle);
#endif
-#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
- Q_INIT_RESOURCE(qpaintengine_d3d);
-#endif
Q_INIT_RESOURCE(qmessagebox);
#if !defined(QT_NO_PRINTDIALOG)
Q_INIT_RESOURCE(qprintdialog);
@@ -130,7 +127,7 @@ QInputContext *QApplicationPrivate::inputContext;
bool QApplicationPrivate::quitOnLastWindowClosed = true;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
int QApplicationPrivate::autoMaximizeThreshold = -1;
bool QApplicationPrivate::autoSipEnabled = false;
#endif
@@ -442,7 +439,7 @@ bool QApplicationPrivate::fade_tooltip = false;
bool QApplicationPrivate::animate_toolbox = false;
bool QApplicationPrivate::widgetCount = false;
QString* QApplicationPrivate::styleOverride = 0;
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
bool QApplicationPrivate::inSizeMove = false;
#endif
#ifdef QT_KEYPAD_NAVIGATION
@@ -620,13 +617,6 @@ void QApplicationPrivate::process_cmdline()
and QPixmaps. Available options are \c{raster} and \c{opengl}.
\endlist
- The Windows version of Qt supports an additional command line option, if
- Direct3D support has been compiled into Qt:
- \list
- \o -direct3d will make the Direct3D paint engine the default widget
- paint engine in Qt. \bold {This functionality is experimental.}
- \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).
@@ -866,7 +856,7 @@ void QApplicationPrivate::initialize()
q->setAttribute(Qt::AA_NativeWindows);
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#ifdef QT_AUTO_MAXIMIZE_THRESHOLD
autoMaximizeThreshold = QT_AUTO_MAXIMIZE_THRESHOLD;
#else
@@ -875,7 +865,7 @@ void QApplicationPrivate::initialize()
else
autoMaximizeThreshold = -1;
#endif //QT_AUTO_MAXIMIZE_THRESHOLD
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
// Set up which span functions should be used in raster engine...
qInitDrawhelperAsm();
@@ -1227,7 +1217,7 @@ bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventLis
the WA_InputMethodEnabled attribute set.
*/
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void QApplication::setAutoMaximizeThreshold(const int threshold)
{
QApplicationPrivate::autoMaximizeThreshold = threshold;
@@ -1302,7 +1292,7 @@ QStyle *QApplication::style()
delete QApplicationPrivate::styleOverride;
QApplicationPrivate::styleOverride = 0;
} else {
-#if defined(Q_WS_WIN) && defined(Q_OS_WINCE)
+#if defined(Q_WS_WIN) && defined(Q_WS_WINCE)
if (qt_wince_is_smartphone() || qt_wince_is_pocket_pc())
style = QLatin1String("WindowsMobile");
else
@@ -2089,8 +2079,9 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
if(focus && QApplicationPrivate::focus_widget == focus) {
if (focus->testAttribute(Qt::WA_InputMethodEnabled)) {
QInputContext *qic = focus->inputContext();
- if (qic && focus_widget->testAttribute(Qt::WA_WState_Created))
- qic->setFocusWidget( focus_widget );
+ if (qic && focus->testAttribute(Qt::WA_WState_Created)
+ && focus->isEnabled())
+ qic->setFocusWidget(focus);
}
QFocusEvent in(QEvent::FocusIn, reason);
QPointer<QWidget> that = focus;
@@ -3496,7 +3487,7 @@ void QApplication::changeOverrideCursor(const QCursor &cursor)
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(). As a
special case, modal widgets like QMessageBox can be used before calling
exec(), because modal widgets call exec() to start a local event loop.
@@ -4034,7 +4025,7 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e)
if (receiver->isWidgetType()) {
QWidget *widget = static_cast<QWidget *>(receiver);
-#if !defined(Q_OS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR))
+#if !defined(Q_WS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR))
// toggle HasMouse widget state on enter and leave
if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) &&
(!qApp->activePopupWidget() || qApp->activePopupWidget() == widget->window()))
diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h
index 1d6941d..2baf6dc 100644
--- a/src/gui/kernel/qapplication.h
+++ b/src/gui/kernel/qapplication.h
@@ -102,7 +102,7 @@ class Q_GUI_EXPORT QApplication : public QCoreApplication
#ifndef QT_NO_STYLE_STYLESHEET
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
Q_PROPERTY(int autoMaximizeThreshold READ autoMaximizeThreshold WRITE setAutoMaximizeThreshold)
Q_PROPERTY(bool autoSipEnabled READ autoSipEnabled WRITE setAutoSipEnabled)
#endif
@@ -281,7 +281,7 @@ public Q_SLOTS:
#ifndef QT_NO_STYLE_STYLESHEET
void setStyleSheet(const QString& sheet);
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void setAutoMaximizeThreshold(const int threshold);
int autoMaximizeThreshold() const;
void setAutoSipEnabled(const bool enabled);
diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm
index 69302ec..d5fa9ea 100644
--- a/src/gui/kernel/qapplication_mac.mm
+++ b/src/gui/kernel/qapplication_mac.mm
@@ -1196,10 +1196,6 @@ void qt_init(QApplicationPrivate *priv, int)
[qtMenuLoader release];
}
#endif
- if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
- extern void qt_mac_set_native_menubar(bool);
- qt_mac_set_native_menubar(false);
- }
// Register for Carbon tablet proximity events on the event monitor target.
// This means that we should receive proximity events even when we aren't the active application.
if (!tablet_proximity_handler) {
@@ -1642,15 +1638,6 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event
bool inNonClientArea = false;
GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0,
sizeof(where), 0, &where);
- if(ekind == kEventMouseMoved && qt_mac_app_fullscreen &&
- QApplication::desktop()->screenNumber(QPoint(where.h, where.v)) ==
- QApplication::desktop()->primaryScreen()) {
- if(where.v <= 0)
- ShowMenuBar();
- else if(qt_mac_window_at(where.h, where.v, 0) != inMenuBar)
- HideMenuBar();
- }
-
#if defined(DEBUG_MOUSE_MAPS)
const char *edesc = 0;
switch(ekind) {
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index 7487f0a..7e97418 100644
--- a/src/gui/kernel/qapplication_p.h
+++ b/src/gui/kernel/qapplication_p.h
@@ -219,7 +219,7 @@ public:
#endif
static bool quitOnLastWindowClosed;
static void emitLastWindowClosed();
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
static int autoMaximizeThreshold;
static bool autoSipEnabled;
#endif
@@ -358,7 +358,7 @@ public:
#ifdef Q_WS_MAC
static bool native_modal_dialog_active;
#endif
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
static bool inSizeMove;
#endif
diff --git a/src/gui/kernel/qapplication_qws.cpp b/src/gui/kernel/qapplication_qws.cpp
index 018440f..1125610 100644
--- a/src/gui/kernel/qapplication_qws.cpp
+++ b/src/gui/kernel/qapplication_qws.cpp
@@ -195,14 +195,14 @@ QString qws_dataDir()
if (!result.isEmpty())
return result;
QByteArray dataDir = QString(QLatin1String("/tmp/qtembedded-%1")).arg(qws_display_id).toLocal8Bit();
- if (mkdir(dataDir, 0700)) {
+ if (QT_MKDIR(dataDir, 0700)) {
if (errno != EEXIST) {
qFatal("Cannot create Qt for Embedded Linux data directory: %s", dataDir.constData());
}
}
- struct stat buf;
- if (lstat(dataDir, &buf))
+ QT_STATBUF buf;
+ if (QT_LSTAT(dataDir, &buf))
qFatal("stat failed for Qt for Embedded Linux data directory: %s", dataDir.constData());
if (!S_ISDIR(buf.st_mode))
@@ -2280,7 +2280,8 @@ void qt_init(QApplicationPrivate *priv, int type)
qt_appType = QApplication::Type(type);
qws_single_process = true;
QWSServer::startup(flags);
- setenv("QWS_DISPLAY", qws_display_spec.constData(), 0);
+ if (!display) // if not already set
+ qputenv("QWS_DISPLAY", qws_display_spec);
}
if(qt_is_gui_used) {
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index f14ad6f..6237657 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include "qguifunctions_wince.h"
#include "qmenubar.h"
extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
@@ -48,7 +48,7 @@ extern bool qt_wince_is_smartphone(); //defined in qguifunctions_wince.c
extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wince.cpp
extern void qt_wince_hide_taskbar(HWND hwnd); //defined in qguifunctions_wince.cpp
#endif
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
#include <windowsm.h>
#include <tpcshell.h>
#endif
@@ -106,7 +106,7 @@ extern void qt_wince_hide_taskbar(HWND hwnd); //defined in qguifunctions_wince.c
#include <winuser.h>
#if !defined(WINABLEAPI)
-# if defined(Q_OS_WINCE)
+# if defined(Q_WS_WINCE)
# include <bldver.h>
# endif
# include <winable.h>
@@ -155,7 +155,7 @@ static PtrFlashWindowEx pFlashWindowEx = 0;
QT_BEGIN_NAMESPACE
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#ifndef SHRG_RETURNCMD
struct SHRGINFO {
DWORD cbSize;
@@ -266,7 +266,7 @@ Q_CORE_EXPORT bool winPostMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
#define MK_XBUTTON2 0x0040
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#define GET_KEYSTATE_WPARAM(wParam) (LOWORD(wParam))
#endif
@@ -497,7 +497,7 @@ static void qt_set_windows_color_resources()
pal.setColor(QPalette::HighlightedText,
QColor(qt_colorref2qrgb(GetSysColor(COLOR_HIGHLIGHTTEXT))));
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
// ### hardcoded until I find out how to get it from the system settings.
pal.setColor(QPalette::LinkVisited, pal.highlight().color().dark(150));
pal.setColor(QPalette::Link, pal.highlight().color().light(130));
@@ -573,7 +573,7 @@ static void qt_set_windows_color_resources()
static void qt_set_windows_font_resources()
{
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
QFont menuFont;
QFont messageFont;
QFont statusFont;
@@ -625,7 +625,7 @@ static void qt_set_windows_font_resources()
smallerFont.setPointSize(systemFont.pointSize()-1);
QApplication::setFont(smallerFont, "QTabBar");
}
-#endif// Q_OS_WINCE
+#endif// Q_WS_WINCE
}
static void qt_win_read_cleartype_settings()
@@ -745,9 +745,6 @@ void qt_init(QApplicationPrivate *priv, int)
appNoGrab = !appNoGrab;
else
#endif // QT_DEBUG
- if (qstrcmp(argv[i], "-direct3d") == 0)
- QApplication::setAttribute(Qt::AA_MSWindowsUseDirect3DByDefault);
- else
argv[j++] = argv[i];
}
if(j < priv->argc) {
@@ -756,7 +753,7 @@ void qt_init(QApplicationPrivate *priv, int)
}
// Get the application name/instance if qWinMain() was not invoked
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
// No message boxes but important ones
SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
#endif
@@ -769,7 +766,7 @@ void qt_init(QApplicationPrivate *priv, int)
});
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
// Initialize OLE/COM
// S_OK means success and S_FALSE means that it has already
// been initialized
@@ -781,7 +778,7 @@ void qt_init(QApplicationPrivate *priv, int)
#endif
// Misc. initialization
-#if defined(QT_DEBUG) && !defined(Q_OS_WINCE)
+#if defined(QT_DEBUG) && !defined(Q_WS_WINCE)
GdiSetBatchLimit(1);
#endif
@@ -795,7 +792,7 @@ void qt_init(QApplicationPrivate *priv, int)
#endif
qApp->setObjectName(QLatin1String(theAppName));
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
// default font
HFONT hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
QFont f(QLatin1String("MS Sans Serif"),8);
@@ -815,7 +812,7 @@ void qt_init(QApplicationPrivate *priv, int)
&& f.family() == QLatin1String("MS Shell Dlg"))
f.setFamily(QLatin1String("MS Shell Dlg 2"));
QApplicationPrivate::setSystemFont(f);
-#else //Q_OS_WINCE
+#else //Q_WS_WINCE
LOGFONT lf;
HGDIOBJ stockFont = GetStockObject(SYSTEM_FONT);
int result = 0;
@@ -823,7 +820,7 @@ void qt_init(QApplicationPrivate *priv, int)
QFont font = qt_LOGFONTtoQFont(lf, true);
if (result)
QApplicationPrivate::setSystemFont(font);
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
// QFont::locale_init(); ### Uncomment when it does something on Windows
@@ -880,7 +877,7 @@ void qt_cleanup()
delete QApplicationPrivate::inputContext;
QApplicationPrivate::inputContext = 0;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
// Deinitialize OLE/COM
OleUninitialize();
#endif
@@ -928,7 +925,7 @@ const QString qt_reg_winclass(QWidget *w) // register window class
if (flags & Qt::MSWindowsOwnDC) {
cname = QLatin1String("QWidgetOwnDC");
style = CS_DBLCLKS;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
style |= CS_OWNDC;
#endif
icon = true;
@@ -943,14 +940,14 @@ const QString qt_reg_winclass(QWidget *w) // register window class
} else {
cname = QLatin1String("QTool");
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
style |= CS_SAVEBITS;
#endif
icon = false;
} else if (type == Qt::Popup) {
cname = QLatin1String("QPopup");
style = CS_DBLCLKS;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
style |= CS_SAVEBITS;
#endif
if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
@@ -963,7 +960,7 @@ const QString qt_reg_winclass(QWidget *w) // register window class
icon = true;
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
// force CS_OWNDC when the GL graphics system is
// used as the default renderer
if (qt_win_owndc_required)
@@ -1008,7 +1005,7 @@ const QString qt_reg_winclass(QWidget *w) // register window class
return cname;
ATOM atom;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
HBRUSH bgBrush = (HBRUSH)GetSysColorBrush(COLOR_WINDOW);
QT_WA({
WNDCLASS wc;
@@ -1381,7 +1378,7 @@ void QApplication::winFocus(QWidget *widget, bool gotFocus)
&& (QApplicationPrivate::active_window->windowType() == Qt::Dialog)) {
// raise the entire application, not just the dialog
QWidget* mw = QApplicationPrivate::active_window;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
while(mw->parentWidget() && (mw->windowType() == Qt::Dialog))
mw = mw->parentWidget()->window();
if (mw->testAttribute(Qt::WA_WState_Created) && mw != QApplicationPrivate::active_window)
@@ -1432,7 +1429,7 @@ static bool qt_is_translatable_mouse_event(UINT message)
message >= WM_XBUTTONDOWN && message <= WM_XBUTTONDBLCLK)
&& message != WM_MOUSEWHEEL
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
|| message >= WM_NCMOUSEMOVE && message <= WM_NCMBUTTONDBLCLK
#endif
;
@@ -1472,7 +1469,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
msg.pt.y = GET_Y_LPARAM(lParam);
// If it's a non-client-area message the coords are screen coords, otherwise they are
// client coords.
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
if (message < WM_NCMOUSEMOVE || message > WM_NCMBUTTONDBLCLK)
#endif
ClientToScreen(msg.hwnd, &msg.pt);
@@ -1502,7 +1499,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
if (imeParentWnd && QApplication::activePopupWidget()
&& (message == WM_MBUTTONDOWN || message == WM_XBUTTONDOWN
|| message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
|| message == WM_NCMBUTTONDOWN || message == WM_NCLBUTTONDOWN
|| message == WM_NCRBUTTONDOWN)) {
#else
@@ -1512,7 +1509,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
}
switch (message) {
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
case WM_QUERYENDSESSION: {
if (sm_smActive) // bogus message from windows
RETURN(true);
@@ -1563,7 +1560,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
#endif
case WM_SETTINGCHANGE:
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
// CE SIP hide/show
if (wParam == SPI_SETSIPINFO) {
QResizeEvent re(QSize(0, 0), QSize(0, 0)); // Calculated by QDesktopWidget
@@ -1665,7 +1662,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
if (!qt_tabletChokeMouse) {
result = widget->translateMouseEvent(msg); // mouse event
-#if defined(Q_OS_WINCE) && !defined(QT_NO_CONTEXTMENU)
+#if defined(Q_WS_WINCE) && !defined(QT_NO_CONTEXTMENU)
if (message == WM_LBUTTONDOWN && widget != qApp->activePopupWidget()) {
QWidget* alienWidget = widget;
if ((alienWidget != qApp->activePopupWidget()) && (alienWidget->contextMenuPolicy() != Qt::PreventContextMenu)) {
@@ -1908,7 +1905,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
}
break;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
case WM_NCHITTEST:
if (widget->isWindow()) {
QPoint pos = widget->mapFromGlobal(QPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
@@ -1927,7 +1924,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
#endif
case WM_SYSCOMMAND: {
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
bool window_state_change = false;
Qt::WindowStates oldstate = Qt::WindowStates(widget->dataPtr()->window_state);
// MSDN:In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are
@@ -1955,7 +1952,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
QHideEvent e;
qt_sendSpontaneousEvent(widget, &e);
widget->hideChildren(true);
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
const QString title = widget->windowIconText();
if (!title.isEmpty())
widget->setWindowTitle_helper(title);
@@ -1978,7 +1975,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
widget->showChildren(true);
QShowEvent e;
qt_sendSpontaneousEvent(widget, &e);
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
const QString title = widget->windowTitle();
if (!title.isEmpty())
widget->setWindowTitle_helper(title);
@@ -2028,7 +2025,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
result = widget->translatePaintEvent(msg);
break;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
case WM_ENTERSIZEMOVE:
autoCaptureWnd = hwnd;
QApplicationPrivate::inSizeMove = true;
@@ -2085,7 +2082,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
// where it got it from; it would simply get a 0 value as the old focus widget.
if (!(widget->windowState() & Qt::WindowMinimized)) {
// Ignore the activate message send by WindowsXP to a minimized window
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
if (widget->windowState() & Qt::WindowFullScreen)
qt_wince_hide_taskbar(widget->winId());
#endif
@@ -2112,7 +2109,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
}
break;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
case WM_MOUSEACTIVATE:
if (widget->window()->windowType() == Qt::Tool) {
QWidget *w = widget;
@@ -2201,7 +2198,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
result = false;
break;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
case WM_WINDOWPOSCHANGING:
{
result = false;
@@ -2317,7 +2314,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
break;
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
case WM_CHANGECBCHAIN:
case WM_DRAWCLIPBOARD:
#endif
@@ -2424,7 +2421,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
#endif // QT_NO_TABLETEVENT
}
break;
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
case WM_SETFOCUS: {
HIMC hC;
hC = ImmGetContext(hwnd);
@@ -2470,7 +2467,7 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
widget->update();
break;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
case WM_INPUTLANGCHANGE: {
char info[7];
if (!GetLocaleInfoA(MAKELCID(lParam, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, info, 6)) {
@@ -2668,19 +2665,19 @@ bool qt_try_modal(QWidget *widget, MSG *msg, int& ret)
int type = msg->message;
bool block_event = false;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
if (type != WM_NCHITTEST)
#endif
if ((type >= WM_MOUSEFIRST && type <= WM_MOUSELAST) ||
type == WM_MOUSEWHEEL || type == (int)WM95_MOUSEWHEEL ||
type == WM_MOUSELEAVE ||
(type >= WM_KEYFIRST && type <= WM_KEYLAST)
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
|| type == WM_NCMOUSEMOVE
#endif
) {
if (type == WM_MOUSEMOVE
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
|| type == WM_NCMOUSEMOVE
#endif
) {
@@ -2698,7 +2695,7 @@ bool qt_try_modal(QWidget *widget, MSG *msg, int& ret)
} else if (type == WM_CLOSE) {
block_event = true;
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
else if (type == WM_MOUSEACTIVATE || type == WM_NCLBUTTONDOWN){
if (!top->isActiveWindow()) {
top->activateWindow();
@@ -2856,7 +2853,7 @@ static const ushort mouseTbl[] = {
WM_XBUTTONUP, QEvent::MouseButtonRelease, Qt::XButton1,
WM_XBUTTONDBLCLK, QEvent::MouseButtonDblClick, Qt::XButton1,
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
WM_NCMOUSEMOVE, QEvent::NonClientAreaMouseMove, 0,
WM_NCLBUTTONDOWN, QEvent::NonClientAreaMouseButtonPress, Qt::LeftButton,
WM_NCLBUTTONUP, QEvent::NonClientAreaMouseButtonRelease, Qt::LeftButton,
@@ -3173,10 +3170,7 @@ bool QETWidget::translateMouseEvent(const MSG &msg)
if (popupButtonFocus) {
target = popupButtonFocus;
} else if (popupChild) {
- // forward mouse events to the popup child. mouse move events
- // are only forwarded to popup children that enable mouse tracking.
- if (type != QEvent::MouseMove || popupChild->hasMouseTracking())
- target = popupChild;
+ target = popupChild;
}
pos = target->mapFromGlobal(globalPos);
@@ -3658,7 +3652,7 @@ bool QETWidget::translateConfigEvent(const MSG &msg)
WORD b = HIWORD(msg.lParam);
QSize oldSize = size();
QSize newSize(a, b);
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
if (isFullScreen() && (oldSize.width() == newSize.height()) && (oldSize.height() == newSize.width()))
qt_wince_hide_taskbar(internalWinId());
#endif
@@ -3670,7 +3664,7 @@ bool QETWidget::translateConfigEvent(const MSG &msg)
// Capture SIZE_MINIMIZED without preceding WM_SYSCOMMAND
// (like Windows+M)
if (msg.wParam == SIZE_MINIMIZED && !isMinimized()) {
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
const QString title = windowIconText();
if (!title.isEmpty())
d_func()->setWindowTitle_helper(title);
@@ -3682,7 +3676,7 @@ bool QETWidget::translateConfigEvent(const MSG &msg)
hideChildren(true);
}
} else if (msg.wParam != SIZE_MINIMIZED && isMinimized()) {
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
const QString title = windowTitle();
if (!title.isEmpty())
d_func()->setWindowTitle_helper(title);
@@ -3728,7 +3722,7 @@ bool QETWidget::translateConfigEvent(const MSG &msg)
QPoint oldPos = geometry().topLeft();
QPoint newCPos(a, b);
// Ignore silly Windows move event to wild pos after iconify.
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
if (!IsIconic(internalWinId()) && newCPos != oldPos) {
#endif
cr.moveTopLeft(newCPos);
@@ -3740,7 +3734,7 @@ bool QETWidget::translateConfigEvent(const MSG &msg)
QMoveEvent * e = new QMoveEvent(newCPos, oldPos);
QApplication::postEvent(this, e);
}
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
}
#endif
}
@@ -3782,7 +3776,7 @@ int QApplication::cursorFlashTime()
void QApplication::setDoubleClickInterval(int ms)
{
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
SetDoubleClickTime(ms);
#endif
QApplicationPrivate::mouse_double_click_time = ms;
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index a3c9406..90376b3 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -294,6 +294,10 @@ static const char * x11_atomnames = {
// XEMBED
"_XEMBED\0"
"_XEMBED_INFO\0"
+
+ "Wacom Stylus\0"
+ "Wacom Cursor\0"
+ "Wacom Eraser\0"
};
Q_GUI_EXPORT QX11Data *qt_x11Data = 0;
@@ -1579,6 +1583,7 @@ static PtrWacomConfigOpenDevice ptrWacomConfigOpenDevice = 0;
static PtrWacomConfigGetRawParam ptrWacomConfigGetRawParam = 0;
static PtrWacomConfigCloseDevice ptrWacomConfigCloseDevice = 0;
static PtrWacomConfigTerm ptrWacomConfigTerm = 0;
+Q_GLOBAL_STATIC(QByteArray, wacomDeviceName)
#endif
#endif
@@ -2356,13 +2361,6 @@ void qt_init(QApplicationPrivate *priv, int,
XAxisInfoPtr a;
XDevice *dev = 0;
-#if !defined(Q_OS_IRIX)
- // XFree86 divides a stylus and eraser into 2 devices, so we must do for both...
- const QString XFREENAMESTYLUS = QLatin1String("stylus");
- const QString XFREENAMEPEN = QLatin1String("pen");
- const QString XFREENAMEERASER = QLatin1String("eraser");
-#endif
-
if (X11->ptrXListInputDevices) {
devices = X11->ptrXListInputDevices(X11->display, &ndev);
if (!devices)
@@ -2377,18 +2375,19 @@ void qt_init(QApplicationPrivate *priv, int,
gotStylus = false;
gotEraser = false;
- QString devName = QString::fromLocal8Bit(devs->name).toLower();
#if defined(Q_OS_IRIX)
+ QString devName = QString::fromLocal8Bit(devs->name).toLower();
if (devName == QLatin1String(WACOM_NAME)) {
deviceType = QTabletEvent::Stylus;
gotStylus = true;
}
#else
- if (devName.startsWith(XFREENAMEPEN)
- || devName.startsWith(XFREENAMESTYLUS)) {
+ if (devs->type == ATOM(XWacomStylus)) {
deviceType = QTabletEvent::Stylus;
+ if (wacomDeviceName()->isEmpty())
+ wacomDeviceName()->append(devs->name);
gotStylus = true;
- } else if (devName.startsWith(XFREENAMEERASER)) {
+ } else if (devs->type == ATOM(XWacomEraser)) {
deviceType = QTabletEvent::XFreeEraser;
gotEraser = true;
}
@@ -2979,7 +2978,7 @@ QWidget *QApplication::topLevelAt(const QPoint &p)
void QApplication::syncX()
{
if (X11->display)
- XSync(X11->display, False); // don't discard events
+ XSync(X11->display, False); // don't discard events
}
@@ -4484,8 +4483,7 @@ void fetchWacomToolId(int &deviceType, qint64 &serialId)
WACOMCONFIG *config = ptrWacomConfigInit(X11->display, 0);
if (config == 0)
return;
- const char *name = "stylus"; // TODO get this from the X config instead (users may have called it differently)
- WACOMDEVICE *device = ptrWacomConfigOpenDevice (config, name);
+ WACOMDEVICE *device = ptrWacomConfigOpenDevice (config, wacomDeviceName()->constData());
if (device == 0)
return;
unsigned keys[1];
diff --git a/src/gui/kernel/qclipboard.cpp b/src/gui/kernel/qclipboard.cpp
index 917b5d5..6daf433 100644
--- a/src/gui/kernel/qclipboard.cpp
+++ b/src/gui/kernel/qclipboard.cpp
@@ -50,6 +50,7 @@
#include "qvariant.h"
#include "qbuffer.h"
#include "qimage.h"
+#include "qtextcodec.h"
QT_BEGIN_NAMESPACE
@@ -276,11 +277,12 @@ QClipboard::~QClipboard()
*/
QString QClipboard::text(QString &subtype, Mode mode) const
{
- const QMimeData *data = mimeData(mode);
+ const QMimeData *const data = mimeData(mode);
if (!data)
return QString();
+
+ const QStringList formats = data->formats();
if (subtype.isEmpty()) {
- QStringList formats = data->formats();
if (formats.contains(QLatin1String("text/plain")))
subtype = QLatin1String("plain");
else {
@@ -289,13 +291,21 @@ QString QClipboard::text(QString &subtype, Mode mode) const
subtype = formats.at(i).mid(5);
break;
}
+ if (subtype.isEmpty())
+ return QString();
}
- }
- if (subtype.isEmpty())
+ } else if (!formats.contains(QLatin1String("text/") + subtype)) {
return QString();
- if (subtype == QLatin1String("plain"))
- return data->text();
- return QString::fromUtf8(data->data(QLatin1String("text/") + subtype));
+ }
+
+ const QByteArray rawData = data->data(QLatin1String("text/") + subtype);
+
+ QTextCodec* codec = QTextCodec::codecForMib(106); // utf-8 is default
+ if (subtype == QLatin1String("html"))
+ codec = QTextCodec::codecForHtml(rawData, codec);
+ else
+ codec = QTextCodec::codecForUtfText(rawData, codec);
+ return codec->toUnicode(rawData);
}
/*!
diff --git a/src/gui/kernel/qclipboard_x11.cpp b/src/gui/kernel/qclipboard_x11.cpp
index 089cc43..d7eb111 100644
--- a/src/gui/kernel/qclipboard_x11.cpp
+++ b/src/gui/kernel/qclipboard_x11.cpp
@@ -786,7 +786,7 @@ static Atom send_selection(QClipboardData *d, Atom target, Window window, Atom p
QByteArray data;
QByteArray fmt = X11->xdndAtomToString(target);
- if (fmt.isEmpty() || !QInternalMimeData::hasFormatHelper(QString::fromAscii(fmt), d->source())) { // Not a MIME type we have
+ if (fmt.isEmpty()) { // Not a MIME type we have
DEBUG("QClipboard: send_selection(): converting to type '%s' is not supported", fmt.data());
return XNone;
}
diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm
index 4ceae3f..1cbc960 100644
--- a/src/gui/kernel/qcocoaview_mac.mm
+++ b/src/gui/kernel/qcocoaview_mac.mm
@@ -196,6 +196,7 @@ extern "C" {
if (self) {
[self finishInitWithQWidget:widget widgetPrivate:widgetprivate];
}
+ composingText = new QString();
composing = false;
sendKeyEvents = true;
currentCustomTypes = 0;
@@ -419,6 +420,7 @@ extern "C" {
- (void)dealloc
{
+ delete composingText;
[[NSNotificationCenter defaultCenter] removeObserver:self];
delete currentCustomTypes;
[self unregisterDraggedTypes];
@@ -997,7 +999,7 @@ extern "C" {
- (void) insertText:(id)aString
{
- if (composing) {
+ if ([aString length]) {
// Send the commit string to the widget.
QString commitText;
if ([aString isKindOfClass:[NSAttributedString class]]) {
@@ -1011,6 +1013,7 @@ extern "C" {
e.setCommitString(commitText);
qt_sendSpontaneousEvent(qwidget, &e);
}
+ composingText->clear();
}
- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange
@@ -1064,12 +1067,21 @@ extern "C" {
attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
0, composingLength, format);
}
+ *composingText = qtText;
QInputMethodEvent e(qtText, attrs);
qt_sendSpontaneousEvent(qwidget, &e);
+ if (!composingLength)
+ composing = false;
}
- (void) unmarkText
{
+ if (composing) {
+ QInputMethodEvent e;
+ e.setCommitString(*composingText);
+ qt_sendSpontaneousEvent(qwidget, &e);
+ }
+ composingText->clear();
composing = false;
}
diff --git a/src/gui/kernel/qcocoaview_mac_p.h b/src/gui/kernel/qcocoaview_mac_p.h
index 983c762..1d4e3e4 100644
--- a/src/gui/kernel/qcocoaview_mac_p.h
+++ b/src/gui/kernel/qcocoaview_mac_p.h
@@ -83,6 +83,7 @@ Q_GUI_EXPORT
bool composing;
int composingLength;
bool sendKeyEvents;
+ QString *composingText;
QStringList *currentCustomTypes;
}
- (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate;
diff --git a/src/gui/kernel/qcursor_win.cpp b/src/gui/kernel/qcursor_win.cpp
index 85d5a11..a475882 100644
--- a/src/gui/kernel/qcursor_win.cpp
+++ b/src/gui/kernel/qcursor_win.cpp
@@ -66,7 +66,7 @@ QCursorData::~QCursorData()
{
delete bm;
delete bmm;
-#if !defined(Q_OS_WINCE) || defined(GWES_ICONCURS)
+#if !defined(Q_WS_WINCE) || defined(GWES_ICONCURS)
if (hcurs)
DestroyCursor(hcurs);
#endif
@@ -129,7 +129,7 @@ extern HBITMAP qt_createIconMask(const QBitmap &bitmap);
static HCURSOR create32BitCursor(const QPixmap &pixmap, int hx, int hy)
{
HCURSOR cur = 0;
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
QBitmap mask = pixmap.mask();
if (mask.isNull()) {
mask = QBitmap(pixmap.size());
@@ -407,7 +407,7 @@ void QCursorData::update()
}
int n = qMax(1, bbits.width() / 8);
int h = bbits.height();
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
uchar* xBits = new uchar[h * n];
uchar* xMask = new uchar[h * n];
int x = 0;
@@ -430,7 +430,7 @@ void QCursorData::update()
xBits, xMask);
delete [] xBits;
delete [] xMask;
-#elif defined(GWES_ICONCURS) // Q_OS_WINCE
+#elif defined(GWES_ICONCURS) // Q_WS_WINCE
// Windows CE only supports fixed cursor size.
int sysW = GetSystemMetrics(SM_CXCURSOR);
int sysH = GetSystemMetrics(SM_CYCURSOR);
diff --git a/src/gui/kernel/qdesktopwidget_win.cpp b/src/gui/kernel/qdesktopwidget_win.cpp
index 725e985..b9e2e1e 100644
--- a/src/gui/kernel/qdesktopwidget_win.cpp
+++ b/src/gui/kernel/qdesktopwidget_win.cpp
@@ -45,7 +45,7 @@
#include "qlibrary.h"
#include <qvector.h>
#include <limits.h>
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include <sipapi.h>
#endif
#include "qwidget_p.h"
@@ -92,7 +92,7 @@ QVector<QRect> *QDesktopWidgetPrivate::rects = 0;
QVector<QRect> *QDesktopWidgetPrivate::workrects = 0;
static int screen_number = 0;
int QDesktopWidgetPrivate::refcount = 0;
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
// Use SIP information, if available
// SipGetInfo is not supported by SSDK (no definition!).
static inline void qt_get_sip_info(QRect &rect)
@@ -208,7 +208,7 @@ void QDesktopWidgetPrivate::init(QDesktopWidget *that)
SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
QRect qr = QRect(QPoint(r.left, r.top), QPoint(r.right - 1, r.bottom - 1));
-#if defined(Q_OS_WINCE_WM)
+#if defined(Q_WS_WINCE_WM)
qt_get_sip_info(qr);
#endif
@@ -222,7 +222,7 @@ void QDesktopWidgetPrivate::init(QDesktopWidget *that)
enumDisplayMonitors(0, 0, enumCallback, 0);
enumDisplayMonitors = 0;
getMonitorInfo = 0;
-#endif // Q_OS_WINCE
+#endif // Q_WS_WINCE
}
QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
@@ -303,7 +303,7 @@ QWidget *QDesktopWidget::screen(int /* screen */)
const QRect QDesktopWidget::availableGeometry(int screen) const
{
Q_D(const QDesktopWidget);
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
for(int i=0; i < d->workrects->size(); ++i)
qt_get_sip_info((*d->workrects)[i]);
#endif
@@ -385,7 +385,7 @@ void QDesktopWidget::resizeEvent(QResizeEvent *)
QDesktopWidgetPrivate::cleanup();
QDesktopWidgetPrivate::init(this);
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
for(int i=0; i < d->workrects->size(); ++i)
qt_get_sip_info((*d->workrects)[i]);
#endif
diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp
index 4c9c73c..9b2305d 100644
--- a/src/gui/kernel/qdnd_x11.cpp
+++ b/src/gui/kernel/qdnd_x11.cpp
@@ -542,6 +542,8 @@ bool QX11Data::xdndMimeDataForAtom(Atom a, QMimeData *mimeData, QByteArray *data
dm->xdndMimeTransferedPixmapIndex =
(dm->xdndMimeTransferedPixmapIndex + 1) % 2;
}
+ } else {
+ DEBUG("QClipboard: xdndMimeDataForAtom(): converting to type '%s' is not supported", qPrintable(atomName));
}
}
return data;
@@ -622,28 +624,12 @@ QVariant QX11Data::xdndMimeConvertToFormat(Atom a, const QByteArray &data, const
if (format == QLatin1String("image/ppm")) {
if (a == XA_PIXMAP && data.size() == sizeof(Pixmap)) {
Pixmap xpm = *((Pixmap*)data.data());
- Display *dpy = display;
- Window r;
- int x,y;
- uint w,h,bw,d;
if (!xpm)
return QByteArray();
- XGetGeometry(dpy,xpm, &r,&x,&y,&w,&h,&bw,&d);
+ QPixmap qpm = QPixmap::fromX11Pixmap(xpm);
QImageWriter imageWriter;
- GC gc = XCreateGC(dpy, xpm, 0, 0);
- QImage imageToWrite;
- if (d == 1) {
- QBitmap qbm(w,h);
- XCopyArea(dpy,xpm,qbm.handle(),gc,0,0,w,h,0,0);
- imageWriter.setFormat("PBMRAW");
- imageToWrite = qbm.toImage();
- } else {
- QPixmap qpm(w,h);
- XCopyArea(dpy,xpm,qpm.handle(),gc,0,0,w,h,0,0);
- imageWriter.setFormat("PPMRAW");
- imageToWrite = qpm.toImage();
- }
- XFreeGC(dpy,gc);
+ imageWriter.setFormat("PPMRAW");
+ QImage imageToWrite = qpm.toImage();
QBuffer buf;
buf.open(QIODevice::WriteOnly);
imageWriter.setDevice(&buf);
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 2aed287..0ab4423 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -861,6 +861,17 @@ bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference
uint platform = QApplicationPrivate::currentPlatform();
+#ifdef Q_WS_MAC
+ if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ uint oldSearchKey = searchkey;
+ searchkey &= ~(Qt::ControlModifier | Qt::MetaModifier);
+ if (oldSearchKey & Qt::ControlModifier)
+ searchkey |= Qt::MetaModifier;
+ if (oldSearchKey & Qt::MetaModifier)
+ searchkey |= Qt::ControlModifier;
+ }
+#endif
+
uint N = QKeySequencePrivate::numberOfKeyBindings;
int first = 0;
int last = N - 1;
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index cc94aad..8e762d6 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
//
// ### Qt 5: remove
-class Q_GUI_EXPORT QKeyEventEx : public QKeyEvent
+class QKeyEventEx : public QKeyEvent
{
public:
QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
@@ -76,7 +76,7 @@ protected:
};
// ### Qt 5: remove
-class Q_GUI_EXPORT QMouseEventEx : public QMouseEvent
+class QMouseEventEx : public QMouseEvent
{
public:
QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos,
diff --git a/src/gui/kernel/qformlayout.cpp b/src/gui/kernel/qformlayout.cpp
index e2d6108..a665c89 100644
--- a/src/gui/kernel/qformlayout.cpp
+++ b/src/gui/kernel/qformlayout.cpp
@@ -689,12 +689,16 @@ void QFormLayoutPrivate::setupVerticalLayoutData(int width)
// are split.
maxLabelWidth = 0;
if (!wrapAllRows) {
+ int maxFieldMinWidth = 0; //the maximum minimum size of the field
for (int i = 0; i < rr; ++i) {
const QFormLayoutItem *label = m_matrix(i, 0);
const QFormLayoutItem *field = m_matrix(i, 1);
- if (label && (label->sizeHint.width() + (field ? field->minSize.width() : 0) <= width))
+ if (label && field && label->sideBySide)
maxLabelWidth = qMax(maxLabelWidth, label->sizeHint.width());
+ if (field)
+ maxFieldMinWidth = qMax(maxFieldMinWidth, field->minSize.width() + field->sbsHSpace);
}
+ maxLabelWidth = qMin(maxLabelWidth, width - maxFieldMinWidth);
} else {
maxLabelWidth = width;
}
diff --git a/src/gui/kernel/qkeymapper.cpp b/src/gui/kernel/qkeymapper.cpp
index 535d009..503a33b 100644
--- a/src/gui/kernel/qkeymapper.cpp
+++ b/src/gui/kernel/qkeymapper.cpp
@@ -116,6 +116,4 @@ QKeyMapperPrivate *qt_keymapper_private()
return QKeyMapper::instance()->d_func();
}
-Q_GUI_EXPORT QList<int> qt_keymapper_possibleKeys(QKeyEvent *e) { return QKeyMapper::instance()->possibleKeys(e); }
-
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qkeymapper_mac.cpp b/src/gui/kernel/qkeymapper_mac.cpp
index 1a0fb08..01b2c13 100644
--- a/src/gui/kernel/qkeymapper_mac.cpp
+++ b/src/gui/kernel/qkeymapper_mac.cpp
@@ -48,6 +48,7 @@
#include <qinputcontext.h>
#include <private/qkeymapper_p.h>
#include <private/qapplication_p.h>
+#include <private/qmacinputcontext_p.h>
QT_BEGIN_NAMESPACE
@@ -160,6 +161,14 @@ Qt::KeyboardModifiers qt_mac_get_modifiers(int keys)
ret |= Qt::KeyboardModifier(qt_mac_modifier_symbols[i].qt_code);
}
}
+ if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ Qt::KeyboardModifiers oldModifiers = ret;
+ ret &= ~(Qt::MetaModifier | Qt::ControlModifier);
+ if (oldModifiers & Qt::ControlModifier)
+ ret |= Qt::MetaModifier;
+ if (oldModifiers & Qt::MetaModifier)
+ ret |= Qt::ControlModifier;
+ }
return ret;
}
static int qt_mac_get_mac_modifiers(Qt::KeyboardModifiers keys)
@@ -176,6 +185,15 @@ static int qt_mac_get_mac_modifiers(Qt::KeyboardModifiers keys)
ret |= qt_mac_modifier_symbols[i].mac_code;
}
}
+
+ if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ int oldModifiers = ret;
+ ret &= ~(controlKeyBit | cmdKeyBit);
+ if (oldModifiers & controlKeyBit)
+ ret |= cmdKeyBit;
+ if (oldModifiers & cmdKeyBit)
+ ret |= controlKeyBit;
+ }
return ret;
}
void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object)
@@ -480,7 +498,8 @@ static bool translateKeyEventInternal(EventHandlerCallRef er, EventRef keyEvent,
#ifdef QT_MAC_USE_COCOA
if (outHandled) {
qt_mac_eat_unicode_key = false;
- CallNextEventHandler(er, keyEvent);
+ if (er)
+ CallNextEventHandler(er, keyEvent);
*outHandled = qt_mac_eat_unicode_key;
}
#endif
@@ -692,8 +711,14 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e
return true;
}
- if (qApp->inputContext() && qApp->inputContext()->isComposing())
+ if (qApp->inputContext() && qApp->inputContext()->isComposing()) {
+ if (ekind == kEventRawKeyDown) {
+ QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext());
+ if (context)
+ context->setLastKeydownEvent(event);
+ }
return false;
+ }
//get modifiers
Qt::KeyboardModifiers modifiers;
int qtKey;
@@ -721,7 +746,8 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e
//is it of use to text services? If so we won't bother
//with a QKeyEvent.
qt_mac_eat_unicode_key = false;
- CallNextEventHandler(er, event);
+ if (er)
+ CallNextEventHandler(er, event);
extern bool qt_mac_menubar_is_open();
if (qt_mac_eat_unicode_key || qt_mac_menubar_is_open()) {
return true;
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index 352d26a..d1cb572 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -105,20 +105,39 @@ static bool operator<(int key, const MacSpecialKey &entry)
static const MacSpecialKey * const MacSpecialKeyEntriesEnd = entries + NumEntries;
-static QChar macSymbolForQtKey(int key)
+QChar qt_macSymbolForQtKey(int key)
{
const MacSpecialKey *i = qBinaryFind(entries, MacSpecialKeyEntriesEnd, key);
if (i == MacSpecialKeyEntriesEnd)
return QChar();
- return QChar(i->macSymbol);
+ ushort macSymbol = i->macSymbol;
+ if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)
+ && (macSymbol == kControlUnicode || macSymbol == kCommandUnicode)) {
+ if (macSymbol == kControlUnicode)
+ macSymbol = kCommandUnicode;
+ else
+ macSymbol = kControlUnicode;
+ }
+
+ return QChar(macSymbol);
}
static int qtkeyForMacSymbol(const QChar ch)
{
+ const ushort unicode = ch.unicode();
for (int i = 0; i < NumEntries; ++i) {
const MacSpecialKey &entry = entries[i];
- if (entry.macSymbol == ch.unicode())
- return entry.key;
+ if (entry.macSymbol == unicode) {
+ int key = entry.key;
+ if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)
+ && (unicode == kControlUnicode || unicode == kCommandUnicode)) {
+ if (unicode == kControlUnicode)
+ key = Qt::Key_Control;
+ else
+ key = Qt::Key_Meta;
+ }
+ return key;
+ }
}
return -1;
}
@@ -213,12 +232,14 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
\row \i Open \i Ctrl+O \i Ctrl+O \i Ctrl+O \i Ctrl+O
\row \i Close \i Ctrl+F4, Ctrl+W \i Ctrl+W, Ctrl+F4 \i Ctrl+W \i Ctrl+W
\row \i Save \i Ctrl+S \i Ctrl+S \i Ctrl+S \i Ctrl+S
+ \row \i Quit \i \i Ctrl+Q \i Qtrl+Q \i Qtrl+Q
\row \i SaveAs \i \i Ctrl+Shift+S \i \i Ctrl+Shift+S
\row \i New \i Ctrl+N \i Ctrl+N \i Ctrl+N \i Ctrl+N
\row \i Delete \i Del \i Del, Meta+D \i Del, Ctrl+D \i Del, Ctrl+D
\row \i Cut \i Ctrl+X, Shift+Del \i Ctrl+X \i Ctrl+X, F20, Shift+Del \i Ctrl+X, F20, Shift+Del
\row \i Copy \i Ctrl+C, Ctrl+Ins \i Ctrl+C \i Ctrl+C, F16, Ctrl+Ins \i Ctrl+C, F16, Ctrl+Ins
\row \i Paste \i Ctrl+V, Shift+Ins \i Ctrl+V \i Ctrl+V, F18, Shift+Ins \i Ctrl+V, F18, Shift+Ins
+ \row \i Preferences \i \i Ctrl+, \i \i
\row \i Undo \i Ctrl+Z, Alt+Backspace \i Ctrl+Z \i Ctrl+Z, F14 \i Ctrl+Z, F14
\row \i Redo \i Ctrl+Y, Shift+Ctrl+Z, Alt+Shift+Backspace \i Ctrl+Shift+Z, Ctrl+Y \i Ctrl+Shift+Z \i Ctrl+Shift+Z
\row \i Back \i Alt+Left, Backspace \i Ctrl+[ \i Alt+Left \i Alt+Left
@@ -521,6 +542,7 @@ const QKeyBinding QKeySequencePrivate::keyBindings[] = {
{QKeySequence::FindPrevious, 1, Qt::SHIFT | Qt::Key_F3, QApplicationPrivate::KB_Win},
{QKeySequence::ZoomIn, 1, Qt::CTRL | Qt::Key_Plus, QApplicationPrivate::KB_All},
{QKeySequence::NextChild, 0, Qt::CTRL | Qt::Key_Comma, QApplicationPrivate::KB_KDE},
+ {QKeySequence::Preferences, 0, Qt::CTRL | Qt::Key_Comma, QApplicationPrivate::KB_Mac},
{QKeySequence::ZoomOut, 1, Qt::CTRL | Qt::Key_Minus, QApplicationPrivate::KB_All},
{QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::Key_Period, QApplicationPrivate::KB_KDE},
{QKeySequence::HelpContents, 1, Qt::CTRL | Qt::Key_Question, QApplicationPrivate::KB_Mac},
@@ -538,6 +560,7 @@ const QKeyBinding QKeySequencePrivate::keyBindings[] = {
{QKeySequence::New, 1, Qt::CTRL | Qt::Key_N, QApplicationPrivate::KB_All},
{QKeySequence::Open, 1, Qt::CTRL | Qt::Key_O, QApplicationPrivate::KB_All},
{QKeySequence::Print, 1, Qt::CTRL | Qt::Key_P, QApplicationPrivate::KB_All},
+ {QKeySequence::Quit, 0, Qt::CTRL | Qt::Key_Q, QApplicationPrivate::KB_Gnome | QApplicationPrivate::KB_KDE | QApplicationPrivate::KB_Mac},
{QKeySequence::Refresh, 1, Qt::CTRL | Qt::Key_R, QApplicationPrivate::KB_Gnome | QApplicationPrivate::KB_Mac},
{QKeySequence::Replace, 0, Qt::CTRL | Qt::Key_R, QApplicationPrivate::KB_KDE},
{QKeySequence::Save, 1, Qt::CTRL | Qt::Key_S, QApplicationPrivate::KB_All},
@@ -671,12 +694,14 @@ const uint QKeySequencePrivate::numberOfKeyBindings = sizeof(QKeySequencePrivate
\value NextChild Navigate to next tab or child window.
\value Open Open document.
\value Paste Paste.
+ \value Preferences Open the preferences dialog.
\value PreviousChild Navigate to previous tab or child window.
\value Print Print document.
+ \value Quit Quit the application.
\value Redo Redo.
\value Refresh Refresh or reload current document.
\value Replace Find and replace.
- \value SaveAs Save document after prompting the user for a file name.
+ \value SaveAs Save document after prompting the user for a file name.
\value Save Save document.
\value SelectAll Select all text.
\value SelectEndOfBlock Extend selection to the end of a text block. This shortcut is only used on OS X.
@@ -782,6 +807,21 @@ QKeySequence::QKeySequence(const QKeySequence& keysequence)
d->ref.ref();
}
+#ifdef Q_WS_MAC
+static inline int maybeSwapShortcut(int shortcut)
+{
+ if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ uint oldshortcut = shortcut;
+ shortcut &= ~(Qt::CTRL | Qt::META);
+ if (oldshortcut & Qt::CTRL)
+ shortcut |= Qt::META;
+ if (oldshortcut & Qt::META)
+ shortcut |= Qt::CTRL;
+ }
+ return shortcut;
+}
+#endif
+
/*!
\since 4.2
@@ -798,10 +838,16 @@ QList<QKeySequence> QKeySequence::keyBindings(StandardKey key)
for (uint i = 0; i < QKeySequencePrivate::numberOfKeyBindings ; ++i) {
QKeyBinding keyBinding = QKeySequencePrivate::keyBindings[i];
if (keyBinding.standardKey == key && (keyBinding.platform & platform)) {
- if (keyBinding.priority > 0)
- list.prepend(QKeySequence(QKeySequencePrivate::keyBindings[i].shortcut));
- else
- list.append(QKeySequence(QKeySequencePrivate::keyBindings[i].shortcut));
+ uint shortcut =
+#ifdef Q_WS_MAC
+ maybeSwapShortcut(QKeySequencePrivate::keyBindings[i].shortcut);
+#else
+ QKeySequencePrivate::keyBindings[i].shortcut;
+#endif
+ if (keyBinding.priority > 0)
+ list.prepend(QKeySequence(shortcut));
+ else
+ list.append(QKeySequence(shortcut));
}
}
return list;
@@ -969,9 +1015,16 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
gmodifs = globalModifs();
if (gmodifs->isEmpty()) {
#ifdef Q_WS_MAC
- *gmodifs << QModifKeyName(Qt::CTRL, QChar(kCommandUnicode));
+ const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
+ if (dontSwap)
+ *gmodifs << QModifKeyName(Qt::META, QChar(kCommandUnicode));
+ else
+ *gmodifs << QModifKeyName(Qt::CTRL, QChar(kCommandUnicode));
*gmodifs << QModifKeyName(Qt::ALT, QChar(kOptionUnicode));
- *gmodifs << QModifKeyName(Qt::META, QChar(kControlUnicode));
+ if (dontSwap)
+ *gmodifs << QModifKeyName(Qt::CTRL, QChar(kControlUnicode));
+ else
+ *gmodifs << QModifKeyName(Qt::META, QChar(kControlUnicode));
*gmodifs << QModifKeyName(Qt::SHIFT, QChar(kShiftUnicode));
#endif
*gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
@@ -1069,8 +1122,6 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
if (found)
break;
}
-#ifdef Q_WS_MAC
-#endif
}
return ret;
}
@@ -1099,15 +1150,30 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
QString s;
#if defined(Q_WS_MAC)
if (nativeText) {
- // On MAC the order is Meta, Alt, Shift, Control.
- if ((key & Qt::META) == Qt::META)
- s += macSymbolForQtKey(Qt::Key_Meta);
- if ((key & Qt::ALT) == Qt::ALT)
- s += macSymbolForQtKey(Qt::Key_Alt);
- if ((key & Qt::SHIFT) == Qt::SHIFT)
- s += macSymbolForQtKey(Qt::Key_Shift);
- if ((key & Qt::CTRL) == Qt::CTRL)
- s += macSymbolForQtKey(Qt::Key_Control);
+ // On Mac OS X the order (by default) is Meta, Alt, Shift, Control.
+ // If the AA_MacDontSwapCtrlAndMeta is enabled, then the order
+ // is Ctrl, Alt, Shift, Meta. The macSymbolForQtKey does this swap
+ // for us, which means that we have to adjust our order here.
+ // The upshot is a lot more infrastructure to keep the number of
+ // if tests down and the code relatively clean.
+ static const int ModifierOrder[] = { Qt::META, Qt::ALT, Qt::SHIFT, Qt::CTRL, 0 };
+ static const int QtKeyOrder[] = { Qt::Key_Meta, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Control, 0 };
+ static const int DontSwapModifierOrder[] = { Qt::CTRL, Qt::ALT, Qt::SHIFT, Qt::META, 0 };
+ static const int DontSwapQtKeyOrder[] = { Qt::Key_Control, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Meta, 0 };
+ const int *modifierOrder;
+ const int *qtkeyOrder;
+ if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ modifierOrder = DontSwapModifierOrder;
+ qtkeyOrder = DontSwapQtKeyOrder;
+ } else {
+ modifierOrder = ModifierOrder;
+ qtkeyOrder = QtKeyOrder;
+ }
+
+ for (int i = 0; modifierOrder[i] != 0; ++i) {
+ if (key & modifierOrder[i])
+ s += qt_macSymbolForQtKey(qtkeyOrder[i]);
+ }
} else
#endif
{
@@ -1140,7 +1206,7 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
int i=0;
#if defined(Q_WS_MAC)
if (nativeText) {
- QChar ch = macSymbolForQtKey(key);
+ QChar ch = qt_macSymbolForQtKey(key);
if (!ch.isNull())
p = ch;
else
diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h
index 1c4776f..f78e34a 100644
--- a/src/gui/kernel/qkeysequence.h
+++ b/src/gui/kernel/qkeysequence.h
@@ -136,7 +136,9 @@ public:
DeleteEndOfLine,
InsertParagraphSeparator,
InsertLineSeparator,
- SaveAs
+ SaveAs,
+ Preferences,
+ Quit
};
QKeySequence();
diff --git a/src/gui/kernel/qlayoutitem.cpp b/src/gui/kernel/qlayoutitem.cpp
index 0fd73b8..c70ab2d 100644
--- a/src/gui/kernel/qlayoutitem.cpp
+++ b/src/gui/kernel/qlayoutitem.cpp
@@ -54,7 +54,8 @@ QT_BEGIN_NAMESPACE
inline static QRect fromLayoutItemRect(QWidgetPrivate *priv, const QRect &rect)
{
- return priv->fromOrToLayoutItemRect(rect, -1);
+ return rect.adjusted(priv->leftLayoutItemMargin, priv->topLayoutItemMargin,
+ -priv->rightLayoutItemMargin, -priv->bottomLayoutItemMargin);
}
inline static QSize fromLayoutItemSize(QWidgetPrivate *priv, const QSize &size)
@@ -64,7 +65,8 @@ inline static QSize fromLayoutItemSize(QWidgetPrivate *priv, const QSize &size)
inline static QRect toLayoutItemRect(QWidgetPrivate *priv, const QRect &rect)
{
- return priv->fromOrToLayoutItemRect(rect, +1);
+ return rect.adjusted(-priv->leftLayoutItemMargin, -priv->topLayoutItemMargin,
+ priv->rightLayoutItemMargin, priv->bottomLayoutItemMargin);
}
inline static QSize toLayoutItemSize(QWidgetPrivate *priv, const QSize &size)
diff --git a/src/gui/kernel/qmime_mac.cpp b/src/gui/kernel/qmime_mac.cpp
index cf1d747..b2eeb5c 100644
--- a/src/gui/kernel/qmime_mac.cpp
+++ b/src/gui/kernel/qmime_mac.cpp
@@ -127,32 +127,44 @@ CFStringRef qt_mac_mime_typeUTI = CFSTR("com.pasteboard.trolltech.marker");
/*!
\class QMacPasteboardMime
- \brief The QMacPasteboardMime class maps open-standard MIME to Mac flavors.
+ \brief The QMacPasteboardMime class converts between a MIME type and a
+ \l{http://developer.apple.com/macosx/uniformtypeidentifiers.html}{Uniform
+ Type Identifier (UTI)} format.
\since 4.2
\ingroup io
\ingroup draganddrop
\ingroup misc
- Qt's drag and drop support and clipboard facilities use the MIME
- standard. On X11, this maps trivially to the Xdnd protocol, but on
- Mac although some applications use MIME types to describe clipboard
- formats, others use arbitrary non-standardized naming conventions,
- or unnamed built-in Mac formats.
+ Qt's drag and drop and clipboard facilities use the MIME
+ standard. On X11, this maps trivially to the Xdnd protocol. On
+ Mac, although some applications use MIME to describe clipboard
+ contents, it is more common to use Apple's UTI format.
- By instantiating subclasses of QMacPasteboardMime that provide conversions
- between Mac flavors and MIME formats, you can convert proprietary
- clipboard formats to MIME formats.
+ QMacPasteboardMime's role is to bridge the gap between MIME and UTI;
+ By subclasses this class, one can extend Qt's drag and drop
+ and clipboard handling to convert to and from unsupported, or proprietary, UTI formats.
- Qt has predefined support for the following Mac flavors:
+ A subclass of QMacPasteboardMime will automatically be registered, and active, upon instantiation.
+
+ Qt has predefined support for the following UTIs:
\list
- \i kScrapFlavorTypeUnicode - converted to "text/plain;charset=ISO-10646-UCS-2"
- \i kScrapFlavorTypeText - converted to "text/plain;charset=system" or "text/plain"
- \i kScrapFlavorTypePicture - converted to "application/x-qt-image"
- \i typeFileURL - converted to "text/uri-list"
+ \i public.utf8-plain-text - converts to "text/plain"
+ \i public.utf16-plain-text - converts to "text/plain"
+ \i public.html - converts to "text/html"
+ \i public.url - converts to "text/uri-list"
+ \i public.file-url - converts to "text/uri-list"
+ \i public.tiff - converts to "application/x-qt-image"
+ \i com.apple.traditional-mac-plain-text - converts to "text/plain"
+ \i com.apple.pict - converts to "application/x-qt-image"
\endlist
- You can check if a MIME type is convertible using canConvert() and
- can perform conversions with convertToMime() and convertFromMime().
+ When working with MIME data, Qt will interate through all instances of QMacPasteboardMime to
+ find an instance that can convert to, or from, a specific MIME type. It will do this by calling
+ canConvert() on each instance, starting with (and choosing) the last created instance first.
+ The actual conversions will be done by using convertToMime() and convertFromMime().
+
+ \note The API uses the term "flavor" in some cases. This is for backwards
+ compatibility reasons, and should now be understood as UTIs.
*/
/*! \enum QMacPasteboardMime::QMacPasteboardMimeType
@@ -841,6 +853,80 @@ QList<QByteArray> QMacPasteboardMimeFileUri::convertFromMime(const QString &mime
return ret;
}
+class QMacPasteboardMimeUrl : public QMacPasteboardMime {
+public:
+ QMacPasteboardMimeUrl() : QMacPasteboardMime(MIME_ALL) { }
+ QString convertorName();
+
+ QString flavorFor(const QString &mime);
+ QString mimeFor(QString flav);
+ bool canConvert(const QString &mime, QString flav);
+ QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
+ QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
+};
+
+QString QMacPasteboardMimeUrl::convertorName()
+{
+ return QLatin1String("URL");
+}
+
+QString QMacPasteboardMimeUrl::flavorFor(const QString &mime)
+{
+ if(mime.startsWith(QLatin1String("text/uri-list")))
+ return QLatin1String("public.url");
+ return QString();
+}
+
+QString QMacPasteboardMimeUrl::mimeFor(QString flav)
+{
+ if(flav == QLatin1String("public.url"))
+ return QLatin1String("text/uri-list");
+ return QString();
+}
+
+bool QMacPasteboardMimeUrl::canConvert(const QString &mime, QString flav)
+{
+ return flav == QLatin1String("public.url")
+ && mime == QLatin1String("text/uri-list");
+}
+
+QVariant QMacPasteboardMimeUrl::convertToMime(const QString &mime, QList<QByteArray> data, QString flav)
+{
+ if(!canConvert(mime, flav))
+ return QVariant();
+
+ QList<QVariant> ret;
+ for (int i=0; i<data.size(); ++i) {
+ QUrl url = QUrl::fromEncoded(data.at(i));
+ if (url.host().toLower() == QLatin1String("localhost"))
+ url.setHost(QString());
+ url.setPath(url.path().normalized(QString::NormalizationForm_C));
+ ret.append(url);
+ }
+ return QVariant(ret);
+}
+
+QList<QByteArray> QMacPasteboardMimeUrl::convertFromMime(const QString &mime, QVariant data, QString flav)
+{
+ QList<QByteArray> ret;
+ if (!canConvert(mime, flav))
+ return ret;
+
+ QList<QVariant> urls = data.toList();
+ for(int i=0; i<urls.size(); ++i) {
+ QUrl url = urls.at(i).toUrl();
+ if (url.scheme().isEmpty())
+ url.setScheme(QLatin1String("file"));
+ if (url.scheme().toLower() == QLatin1String("file")) {
+ if (url.host().isEmpty())
+ url.setHost(QLatin1String("localhost"));
+ url.setPath(url.path().normalized(QString::NormalizationForm_D));
+ }
+ ret.append(url.toEncoded());
+ }
+ return ret;
+}
+
#ifdef QT3_SUPPORT
class QMacPasteboardMimeQt3Any : public QMacPasteboardMime {
private:
@@ -1043,6 +1129,7 @@ void QMacPasteboardMime::initialize()
new QMacPasteboardMimePlainText;
new QMacPasteboardMimeHTMLText;
new QMacPasteboardMimeFileUri;
+ new QMacPasteboardMimeUrl;
new QMacPasteboardMimeTypeName;
//make sure our "non-standard" types are always last! --Sam
new QMacPasteboardMimeAny;
diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp
index 86894b4..f998bb2 100644
--- a/src/gui/kernel/qshortcutmap.cpp
+++ b/src/gui/kernel/qshortcutmap.cpp
@@ -61,8 +61,6 @@
QT_BEGIN_NAMESPACE
-extern bool qt_mac_no_native_menubar; // qmenu_mac.cpp
-
// To enable verbose output uncomment below
//#define DEBUG_QSHORTCUTMAP
@@ -660,7 +658,7 @@ bool QShortcutMap::correctWidgetContext(Qt::ShortcutContext context, QWidget *w,
{
bool visible = w->isVisible();
#ifdef Q_WS_MAC
- if (!qt_mac_no_native_menubar && qobject_cast<QMenuBar *>(w))
+ if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
visible = true;
#endif
@@ -723,7 +721,7 @@ bool QShortcutMap::correctGraphicsWidgetContext(Qt::ShortcutContext context, QGr
{
bool visible = w->isVisible();
#ifdef Q_WS_MAC
- if (!qt_mac_no_native_menubar && qobject_cast<QMenuBar *>(w))
+ if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
visible = true;
#endif
diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h
index 563b7e9..b9ace9d 100644
--- a/src/gui/kernel/qt_x11_p.h
+++ b/src/gui/kernel/qt_x11_p.h
@@ -652,6 +652,10 @@ struct QX11Data
_XEMBED,
_XEMBED_INFO,
+ XWacomStylus,
+ XWacomCursor,
+ XWacomEraser,
+
NPredefinedAtoms,
_QT_SETTINGS_TIMESTAMP = NPredefinedAtoms,
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index d911b48..ab529fe 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -167,39 +167,48 @@ static inline bool bypassGraphicsProxyWidget(QWidget *p)
extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp
extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp
-QWidgetPrivate::QWidgetPrivate(int version) :
- QObjectPrivate(version), extra(0), focus_child(0)
- ,layout(0), widgetItem(0)
- ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0)
- ,leftLayoutItemMargin(0), topLayoutItemMargin(0), rightLayoutItemMargin(0)
- ,bottomLayoutItemMargin(0)
- ,fg_role(QPalette::NoRole)
- ,bg_role(QPalette::NoRole)
- ,hd(0)
- ,dirty(0)
- ,needsFlush(0)
- ,dirtyOpaqueChildren(1)
- ,isOpaque(0)
- ,inDirtyList(0)
- ,isScrolled(0)
- ,isMoved(0)
- ,usesDoubleBufferedGLContext(0)
-#ifdef Q_WS_WIN
- ,noPaintOnScreen(0)
-#endif
- ,inheritedFontResolveMask(0)
- ,inheritedPaletteResolveMask(0)
+QWidgetPrivate::QWidgetPrivate(int version)
+ : QObjectPrivate(version)
+ , extra(0)
+ , focus_next(0)
+ , focus_prev(0)
+ , focus_child(0)
+ , layout(0)
+ , needsFlush(0)
+ , redirectDev(0)
+ , widgetItem(0)
+ , extraPaintEngine(0)
+ , polished(0)
+ , inheritedFontResolveMask(0)
+ , inheritedPaletteResolveMask(0)
+ , leftmargin(0)
+ , topmargin(0)
+ , rightmargin(0)
+ , bottommargin(0)
+ , leftLayoutItemMargin(0)
+ , topLayoutItemMargin(0)
+ , rightLayoutItemMargin(0)
+ , bottomLayoutItemMargin(0)
+ , hd(0)
+ , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
+ , fg_role(QPalette::NoRole)
+ , bg_role(QPalette::NoRole)
+ , dirtyOpaqueChildren(1)
+ , isOpaque(0)
+ , inDirtyList(0)
+ , isScrolled(0)
+ , isMoved(0)
+ , usesDoubleBufferedGLContext(0)
#if defined(Q_WS_X11)
- ,picture(0)
-#endif
-#ifdef Q_WS_MAC
- ,needWindowChange(0)
- ,isGLWidget(0)
+ , picture(0)
+#elif defined(Q_WS_WIN)
+ , noPaintOnScreen(0)
+#elif defined(Q_WS_MAC)
+ , needWindowChange(0)
+ , isGLWidget(0)
+ , window_event(0)
+ , qd_hd(0)
#endif
- ,polished(0)
-
- , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
- , redirectDev(0)
{
if (!qApp) {
qFatal("QWidget: Must construct a QApplication before a QPaintDevice");
@@ -1027,7 +1036,7 @@ void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w)
if (customize)
; // don't modify window flags if the user explicitely set them.
else if (type == Qt::Dialog || type == Qt::Sheet)
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint;
#else
flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
@@ -1094,7 +1103,7 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
if (f & Qt::MSWindowsOwnDC)
q->setAttribute(Qt::WA_NativeWindow);
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
data.window_state_internal = 0;
#endif
@@ -1345,7 +1354,7 @@ QWidget::~QWidget()
d->setDirtyOpaqueRegion();
if (isWindow() && isVisible() && internalWinId())
- hide();
+ d->close_helper(QWidgetPrivate::CloseNoEvent);
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
else if (!internalWinId() && isVisible())
qApp->d_func()->sendSyntheticEnterLeave(this);
@@ -1412,36 +1421,26 @@ void QWidgetPrivate::createTLExtra()
createExtra();
if (!extra->topextra) {
QTLWExtra* x = extra->topextra = new QTLWExtra;
+ x->icon = 0;
+ x->iconPixmap = 0;
+ x->backingStore = 0;
x->windowSurface = 0;
+ x->sharedPainter = 0;
+ x->incw = x->inch = 0;
+ x->basew = x->baseh = 0;
+ x->frameStrut.setCoords(0, 0, 0, 0);
+ x->normalGeometry = QRect(0,0,-1,-1);
+ x->savedFlags = 0;
x->opacity = 255;
x->posFromMove = false;
x->sizeAdjusted = false;
x->inTopLevelResize = false;
x->inRepaint = false;
- x->backingStore = 0;
- x->icon = 0;
- x->iconPixmap = 0;
- x->frameStrut.setCoords(0, 0, 0, 0);
- x->incw = x->inch = 0;
- x->basew = x->baseh = 0;
- x->normalGeometry = QRect(0,0,-1,-1);
-#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC)
x->embedded = 0;
-#endif
-#if defined(Q_WS_X11)
- x->parentWinId = 0;
- x->spont_unmapped = 0;
- x->dnd = 0;
-#endif
- x->savedFlags = 0;
-#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
- x->qwsManager = 0;
-#endif
- x->sharedPainter = 0;
createTLSysExtra();
#ifdef QWIDGET_EXTRA_DEBUG
- static int count = 0;
- qDebug() << "tlextra" << ++count;
+ static int count = 0;
+ qDebug() << "tlextra" << ++count;
#endif
}
}
@@ -1455,27 +1454,28 @@ void QWidgetPrivate::createExtra()
{
if (!extra) { // if not exists
extra = new QWExtra;
- extra->minw = extra->minh = 0;
- extra->maxw = extra->maxh = QWIDGETSIZE_MAX;
+ extra->glContext = 0;
+ extra->topextra = 0;
+ extra->proxyWidget = 0;
+#ifndef QT_NO_CURSOR
+ extra->curs = 0;
+#endif
+ extra->minw = 0;
+ extra->minh = 0;
+ extra->maxw = QWIDGETSIZE_MAX;
+ extra->maxh = QWIDGETSIZE_MAX;
+ extra->customDpiX = 0;
+ extra->customDpiY = 0;
extra->explicitMinSize = 0;
extra->explicitMaxSize = 0;
extra->autoFillBackground = 0;
extra->nativeChildrenForced = 0;
extra->inRenderWithPainter = 0;
extra->hasMask = 0;
-#ifndef QT_NO_CURSOR
- extra->curs = 0;
-#endif
- extra->style = 0;
- extra->topextra = 0;
- extra->proxyWidget = 0;
- extra->glContext = 0;
- extra->customDpiX = 0;
- extra->customDpiY = 0;
createSysExtra();
#ifdef QWIDGET_EXTRA_DEBUG
- static int count = 0;
- qDebug() << "extra" << ++count;
+ static int count = 0;
+ qDebug() << "extra" << ++count;
#endif
}
}
@@ -1516,45 +1516,6 @@ void QWidgetPrivate::deleteExtra()
}
/*
- Returns true if the background is inherited; otherwise returns
- false.
-
- Mainly used in the paintOnScreen case.
-*/
-
-bool QWidgetPrivate::isBackgroundInherited() const
-{
- Q_Q(const QWidget);
-
- // windows do not inherit their background
- if (q->isWindow() || q->windowType() == Qt::SubWindow)
- return false;
-
- if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent))
- return false;
-
- const QPalette &pal = q->palette();
- QPalette::ColorRole bg = q->backgroundRole();
- QBrush brush = pal.brush(bg);
-
- // non opaque brushes leaves us no choice, we must inherit
- if (!q->autoFillBackground() || !brush.isOpaque())
- return true;
-
- if (brush.style() == Qt::SolidPattern) {
- // the background is just a solid color. If there is no
- // propagated contents, then we claim as performance
- // optimization that it was not inheritet. This is the normal
- // case in standard Windows or Motif style.
- const QWidget *w = q->parentWidget();
- if (!w->d_func()->isBackgroundInherited())
- return false;
- }
-
- return true;
-}
-
-/*
Returns true if there are widgets above this which overlap with
\a rect, which is in parent's coordinate system (same as crect).
*/
@@ -1900,24 +1861,6 @@ void QWidgetPrivate::clipToEffectiveMask(QRegion &region) const
}
}
-bool QWidgetPrivate::hasBackground() const
-{
- Q_Q(const QWidget);
- if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_PaintOnScreen))
- return true;
- if (q->testAttribute(Qt::WA_PaintOnScreen))
- return true;
- if (!q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
- const QPalette &pal = q->palette();
- QPalette::ColorRole bg = q->backgroundRole();
- QBrush bgBrush = pal.brush(bg);
- return (bgBrush.style() != Qt::NoBrush &&
- ((q->isWindow() || q->windowType() == Qt::SubWindow)
- || (QPalette::ColorRole(bg_role) != QPalette::NoRole || (pal.resolve() & (1<<bg)))));
- }
- return false;
-}
-
bool QWidgetPrivate::paintOnScreen() const
{
#if defined(Q_WS_QWS)
@@ -2956,10 +2899,15 @@ void QWidgetPrivate::setEnabled_helper(bool enable)
#if defined(Q_WS_MAC)
setEnabled_helper_sys(enable);
#endif
-#if defined (Q_WS_WIN)
- if (q->hasFocus())
- QInputContextPrivate::updateImeStatus(q, true);
-#endif
+ if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
+ QInputContext *qic = inputContext();
+ if (enable) {
+ qic->setFocusWidget(q);
+ } else {
+ qic->reset();
+ qic->setFocusWidget(0);
+ }
+ }
QEvent e(QEvent::EnabledChange);
QApplication::sendEvent(q, &e);
#ifdef QT3_SUPPORT
@@ -4196,7 +4144,7 @@ const QPalette &QWidget::palette() const
if (!isEnabled()) {
data->pal.setCurrentColorGroup(QPalette::Disabled);
} else if ((!isVisible() || isActiveWindow())
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+#if defined(Q_OS_WIN) && !defined(Q_WS_WINCE)
&& !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this))
#endif
) {
@@ -4784,7 +4732,7 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset,
}
const qreal opacity = painter->opacity();
- if (qFuzzyCompare(opacity + 1, qreal(1.0)))
+ if (qFuzzyIsNull(opacity))
return; // Fully transparent.
Q_D(QWidget);
@@ -5894,6 +5842,8 @@ QWidget *QWidget::focusWidget() const
/*!
Returns the next widget in this widget's focus chain.
+
+ \sa previousInFocusChain
*/
QWidget *QWidget::nextInFocusChain() const
{
@@ -5901,6 +5851,18 @@ QWidget *QWidget::nextInFocusChain() const
}
/*!
+ Returns the previous widget in this widget's focus chain.
+
+ \sa nextInFocusChain
+
+ \since 4.6
+*/
+QWidget *QWidget::previousInFocusChain() const
+{
+ return const_cast<QWidget *>(d_func()->focus_prev);
+}
+
+/*!
\property QWidget::isActiveWindow
\brief whether this widget's window is the active window
@@ -6138,14 +6100,6 @@ int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r)
return dx + dy;
}
-QRect QWidgetPrivate::fromOrToLayoutItemRect(const QRect &rect, int sign) const
-{
- QRect r = rect;
- r.adjust(-sign * leftLayoutItemMargin, -sign * topLayoutItemMargin,
- +sign * rightLayoutItemMargin, +sign * bottomLayoutItemMargin);
- return r;
-}
-
/*!
\property QWidget::frameSize
\brief the size of the widget including any window frame
@@ -7319,7 +7273,7 @@ QSize QWidgetPrivate::adjustedSize() const
#else // all others
QRect screen = QApplication::desktop()->screenGeometry(q->pos());
#endif
-#if defined (Q_OS_WINCE)
+#if defined (Q_WS_WINCE)
s.setWidth(qMin(s.width(), screen.width()));
s.setHeight(qMin(s.height(), screen.height()));
#else
@@ -7627,16 +7581,10 @@ bool QWidget::event(QEvent *event)
}
break;
case QEvent::FocusIn:
-#if defined(Q_WS_WIN)
- QInputContextPrivate::updateImeStatus(this, true);
-#endif
focusInEvent((QFocusEvent*)event);
break;
case QEvent::FocusOut:
-#if defined(Q_WS_WIN)
- QInputContextPrivate::updateImeStatus(this, false);
-#endif
focusOutEvent((QFocusEvent*)event);
break;
@@ -9792,27 +9740,6 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
QEvent e(QEvent::MouseTrackingChange);
QApplication::sendEvent(this, &e);
break; }
-#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
- case Qt::WA_MSWindowsUseDirect3D:
- if (!qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault)) {
- if (on) {
- if (!d->extra)
- d->createExtra();
- d->extra->had_auto_fill_bg = d->extra->autoFillBackground;
- d->extra->had_no_system_bg = testAttribute(Qt::WA_NoSystemBackground);
- d->extra->had_paint_on_screen = testAttribute(Qt::WA_PaintOnScreen);
- // enforce the opaque widget state D3D needs
- d->extra->autoFillBackground = true;
- setAttribute(Qt::WA_PaintOnScreen);
- setAttribute(Qt::WA_NoSystemBackground);
- } else if (d->extra) {
- d->extra->autoFillBackground = d->extra->had_auto_fill_bg;
- setAttribute(Qt::WA_PaintOnScreen, d->extra->had_paint_on_screen);
- setAttribute(Qt::WA_NoSystemBackground, d->extra->had_no_system_bg);
- }
- }
- break;
-#endif
case Qt::WA_NativeWindow: {
QInputContext *ic = 0;
if (on && !internalWinId() && testAttribute(Qt::WA_InputMethodEnabled) && hasFocus()) {
@@ -9824,7 +9751,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
parentWidget()->d_func()->enforceNativeChildren();
if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created))
d->createWinId();
- if (ic)
+ if (ic && isEnabled())
ic->setFocusWidget(this);
break;
}
@@ -9855,10 +9782,6 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
#endif
break;
case Qt::WA_InputMethodEnabled: {
-#if defined(Q_WS_WIN) || (defined(Q_WS_QWS) && !defined(QT_NO_QWS_INPUTMETHODS))
- if (hasFocus())
- QInputContextPrivate::updateImeStatus(this, true);
-#endif
QInputContext *ic = d->ic;
if (!ic) {
// implicitly create input context only if we have a focus
@@ -9866,7 +9789,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
ic = d->inputContext();
}
if (ic) {
- if (on && hasFocus() && ic->focusWidget() != this) {
+ if (on && hasFocus() && ic->focusWidget() != this && isEnabled()) {
ic->setFocusWidget(this);
} else if (!on && ic->focusWidget() == this) {
ic->reset();
diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h
index f54ebf9..6703d26 100644
--- a/src/gui/kernel/qwidget.h
+++ b/src/gui/kernel/qwidget.h
@@ -130,7 +130,7 @@ public:
int alloc_region_index;
// int alloc_region_revision;
#endif
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
uint window_state_internal : 4;
#endif
QRect wrect;
@@ -469,7 +469,7 @@ public Q_SLOTS:
virtual void setVisible(bool visible);
inline void setHidden(bool hidden) { setVisible(!hidden); }
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
inline void show() { setVisible(true); }
#else
void show();
@@ -539,6 +539,7 @@ public:
QWidget *focusWidget() const;
QWidget *nextInFocusChain() const;
+ QWidget *previousInFocusChain() const;
// drag and drop
bool acceptDrops() const;
diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm
index f863428..8243f32 100644
--- a/src/gui/kernel/qwidget_mac.mm
+++ b/src/gui/kernel/qwidget_mac.mm
@@ -390,21 +390,15 @@ QWidget *qt_mac_find_window(OSWindowRef window)
inline static void qt_mac_set_fullscreen_mode(bool b)
{
- extern bool qt_mac_app_fullscreen; //qapplication_mac.cpp
+ extern bool qt_mac_app_fullscreen; //qapplication_mac.mm
if(qt_mac_app_fullscreen == b)
return;
qt_mac_app_fullscreen = b;
-#if QT_MAC_USE_COCOA
- if(b)
- SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
- else
+ if (b) {
+ SetSystemUIMode(kUIModeAllSuppressed, 0);
+ } else {
SetSystemUIMode(kUIModeNormal, 0);
-#else
- if(b)
- HideMenuBar();
- else
- ShowMenuBar();
-#endif
+ }
}
Q_GUI_EXPORT OSViewRef qt_mac_nativeview_for(const QWidget *w)
@@ -734,6 +728,7 @@ static OSWindowRef qt_mac_create_window(QWidget *, WindowClass wclass, WindowAtt
static EventTypeSpec window_events[] = {
{ kEventClassWindow, kEventWindowClose },
{ kEventClassWindow, kEventWindowExpanded },
+ { kEventClassWindow, kEventWindowHidden },
{ kEventClassWindow, kEventWindowZoomed },
{ kEventClassWindow, kEventWindowCollapsed },
{ kEventClassWindow, kEventWindowToolbarSwitchMode },
@@ -993,6 +988,19 @@ OSStatus QWidgetPrivate::qt_window_event(EventHandlerCallRef er, EventRef event,
}
}
}
+ } else if (ekind == kEventWindowHidden) {
+ // Make sure that we also hide any visible sheets on our window.
+ // Cocoa does the right thing for us.
+ const QObjectList children = widget->children();
+ const int childCount = children.count();
+ for (int i = 0; i < childCount; ++i) {
+ QObject *obj = children.at(i);
+ if (obj->isWidgetType()) {
+ QWidget *widget = static_cast<QWidget *>(obj);
+ if (qt_mac_is_macsheet(widget) && widget->isVisible())
+ widget->hide();
+ }
+ }
} else {
handled_event = false;
}
@@ -1595,24 +1603,6 @@ bool QWidgetPrivate::qt_create_root_win()
return true;
}
-bool QWidgetPrivate::qt_recreate_root_win()
-{
- if(!qt_root_win) //sanity check
- return false;
- //store old
- OSWindowRef old_root_win = qt_root_win;
- //recreate
- qt_root_win = 0;
- qt_create_root_win();
- //cleanup old window
-#ifdef QT_MAC_USE_COCOA
- [old_root_win release];
-#else
- CFRelease(old_root_win);
-#endif
- return true;
-}
-
bool QWidgetPrivate::qt_widget_rgn(QWidget *widget, short wcode, RgnHandle rgn, bool force = false)
{
bool ret = false;
@@ -4434,11 +4424,13 @@ void QWidgetPrivate::deleteSysExtra()
void QWidgetPrivate::createTLSysExtra()
{
+ extra->topextra->resizer = 0;
+ extra->topextra->isSetGeometry = 0;
+ extra->topextra->isMove = 0;
+ extra->topextra->wattr = 0;
extra->topextra->wclass = 0;
extra->topextra->group = 0;
extra->topextra->windowIcon = 0;
- extra->topextra->resizer = 0;
- extra->topextra->isSetGeometry = 0;
extra->topextra->savedWindowAttributesFromMaximized = 0;
}
@@ -4513,14 +4505,6 @@ void QWidgetPrivate::setMask_sys(const QRegion &region)
#endif
}
-extern "C" {
- typedef struct CGSConnection *CGSConnectionRef;
- typedef struct CGSWindow *CGSWindowRef;
- extern OSStatus CGSSetWindowAlpha(CGSConnectionRef, CGSWindowRef, float);
- extern CGSWindowRef GetNativeWindowFromWindowRef(WindowRef);
- extern CGSConnectionRef _CGSDefaultConnection();
-}
-
void QWidgetPrivate::setWindowOpacity_sys(qreal level)
{
Q_Q(QWidget);
@@ -4533,12 +4517,11 @@ void QWidgetPrivate::setWindowOpacity_sys(qreal level)
if (!q->testAttribute(Qt::WA_WState_Created))
return;
-#if QT_MAC_USE_COCOA
OSWindowRef oswindow = qt_mac_window_for(q);
+#if QT_MAC_USE_COCOA
[oswindow setAlphaValue:level];
#else
- CGSSetWindowAlpha(_CGSDefaultConnection(),
- GetNativeWindowFromWindowRef(qt_mac_window_for(q)), level);
+ SetWindowAlpha(oswindow, level);
#endif
}
diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h
index 2461820..bf4f091 100644
--- a/src/gui/kernel/qwidget_p.h
+++ b/src/gui/kernel/qwidget_p.h
@@ -99,93 +99,92 @@ class QWidgetItemV2;
class QStyle;
struct QTLWExtra {
+ // *************************** Cross-platform variables *****************************
+
+ // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
+ QIcon *icon; // widget icon
+ QPixmap *iconPixmap;
+ QWidgetBackingStore *backingStore;
+ QWindowSurface *windowSurface;
+ QPainter *sharedPainter;
+
+ // Implicit pointers (shared_null).
QString caption; // widget caption
QString iconText; // widget icon text
QString role; // widget role
QString filePath; // widget file path
- QIcon *icon; // widget icon
- QPixmap *iconPixmap;
+
+ // Other variables.
short incw, inch; // size increments
+ short basew, baseh; // base sizes
// frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
QRect frameStrut;
+ QRect normalGeometry; // used by showMin/maximized/FullScreen
+ Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
+
+ // *************************** Cross-platform bit fields ****************************
uint opacity : 8;
uint posFromMove : 1;
uint sizeAdjusted : 1;
uint inTopLevelResize : 1;
uint inRepaint : 1;
- QWidgetBackingStore *backingStore;
-#if defined(Q_WS_WIN)
- ulong savedFlags; // Save window flags while showing fullscreen
- uint embedded : 1; // window is embedded in another application
-#else
- Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
-#endif
- short basew, baseh; // base sizes
-#if defined(Q_WS_X11)
- WId parentWinId; // parent window Id (valid after reparenting)
- uint embedded : 1; // window is embedded in another Qt application
+ uint embedded : 1;
+
+ // *************************** Platform specific values (bit fields first) **********
+#if defined(Q_WS_X11) // <----------------------------------------------------------- X11
uint spont_unmapped: 1; // window was spontaneously unmapped
uint dnd : 1; // DND properties installed
uint validWMState : 1; // is WM_STATE valid?
uint waitingForMapNotify : 1; // show() has been called, haven't got the MapNotify yet
+ WId parentWinId; // parent window Id (valid after reparenting)
WId userTimeWindow; // window id that contains user-time timestamp when WM supports a _NET_WM_USER_TIME_WINDOW atom
QPoint fullScreenOffset;
-#endif
-#if defined(Q_WS_MAC)
+#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
+ HICON winIconBig; // internal big Windows icon
+ HICON winIconSmall; // internal small Windows icon
+#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
+ uint resizer : 4;
+ uint isSetGeometry : 1;
+ uint isMove : 1;
quint32 wattr;
quint32 wclass;
WindowGroupRef group;
IconRef windowIcon; // the current window icon, if set with setWindowIcon_sys.
quint32 savedWindowAttributesFromMaximized; // Saved attributes from when the calling updateMaximizeButton_sys()
- uint resizer : 4;
- uint isSetGeometry : 1;
- uint isMove : 1;
- uint embedded : 1;
-#endif
-#if defined(Q_WS_QWS) && !defined (QT_NO_QWS_MANAGER)
+#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
+#ifndef QT_NO_QWS_MANAGER
QWSManager *qwsManager;
#endif
-#if defined(Q_WS_WIN)
- HICON winIconBig; // internal big Windows icon
- HICON winIconSmall; // internal small Windows icon
#endif
- QRect normalGeometry; // used by showMin/maximized/FullScreen
- QWindowSurface *windowSurface;
- QPainter *sharedPainter;
};
struct QWExtra {
- qint32 minw, minh; // minimum size
- qint32 maxw, maxh; // maximum size
- QPointer<QWidget> focus_proxy;
-#ifndef QT_NO_CURSOR
- QCursor *curs;
-#endif
+ // *************************** Cross-platform variables *****************************
+
+ // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
+ void *glContext; // if the widget is hijacked by QGLWindowSurface
QTLWExtra *topextra; // only useful for TLWs
QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
- void *glContext; // if the widget is hijacked by QGLWindowSurface
-#if defined(Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP)
- QOleDropTarget *dropTarget; // drop target
- QList<QPointer<QWidget> > oleDropWidgets;
-#endif
-#if defined(Q_WS_X11)
- WId xDndProxy; // XDND forwarding to embedded windows
+#ifndef QT_NO_CURSOR
+ QCursor *curs;
#endif
+ QPointer<QStyle> style;
+ QPointer<QWidget> focus_proxy;
+
+ // Implicit pointers (shared_empty/shared_null).
QRegion mask; // widget mask
+ QString styleSheet;
+
+ // Other variables.
+ qint32 minw;
+ qint32 minh; // minimum size
+ qint32 maxw;
+ qint32 maxh; // maximum size
+ quint16 customDpiX;
+ quint16 customDpiY;
QSize staticContentsSize;
-//bit flags at the end to improve packing
-#if defined(Q_WS_WIN)
- uint shown_mode : 8; // widget show mode
-#ifndef QT_NO_DIRECT3D
- uint had_paint_on_screen : 1;
- uint had_no_system_bg : 1;
- uint had_auto_fill_bg : 1;
-#endif
-#endif
-#if defined(Q_WS_X11)
- uint compress_events : 1;
-#endif
+ // *************************** Cross-platform bit fields ****************************
uint explicitMinSize : 2;
uint explicitMaxSize : 2;
uint autoFillBackground : 1;
@@ -193,16 +192,22 @@ struct QWExtra {
uint inRenderWithPainter : 1;
uint hasMask : 1;
- QPointer<QStyle> style;
- QString styleSheet;
-
- quint16 customDpiX;
- quint16 customDpiY;
-#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
+ // *************************** Platform specific values (bit fields first) **********
+#if defined(Q_WS_WIN) // <----------------------------------------------------------- WIN
+#ifndef QT_NO_DRAGANDDROP
+ QOleDropTarget *dropTarget; // drop target
+ QList<QPointer<QWidget> > oleDropWidgets;
+#endif
+#elif defined(Q_WS_X11) // <--------------------------------------------------------- X11
+ uint compress_events : 1;
+ WId xDndProxy; // XDND forwarding to embedded windows
+#elif defined(Q_WS_MAC) // <------------------------------------------------------ MAC
+#ifdef QT_MAC_USE_COCOA
// Cocoa Mask stuff
QImage maskBits;
CGImageRef imageMask;
#endif
+#endif
};
class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate
@@ -210,6 +215,24 @@ class Q_GUI_EXPORT QWidgetPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QWidget)
public:
+ // *************************** Cross-platform ***************************************
+ enum DrawWidgetFlags {
+ DrawAsRoot = 0x01,
+ DrawPaintOnScreen = 0x02,
+ DrawRecursive = 0x04,
+ DrawInvisible = 0x08,
+ DontSubtractOpaqueChildren = 0x10,
+ DontSetCompositionMode = 0x20,
+ DontDrawOpaqueChildren = 0x40
+ };
+
+ enum CloseMode {
+ CloseNoEvent,
+ CloseWithEvent,
+ CloseWithSpontaneousEvent
+ };
+
+ // Functions.
explicit QWidgetPrivate(int version = QObjectPrivateVersion);
~QWidgetPrivate();
@@ -219,10 +242,6 @@ public:
QPainter *sharedPainter() const;
void setSharedPainter(QPainter *painter);
QWidgetBackingStore *maybeBackingStore() const;
-#ifdef Q_WS_QWS
- void setMaxWindowState_helper();
- void setFullScreenSize_helper();
-#endif
void init(QWidget *desktopWidget, Qt::WindowFlags f);
void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
void createRecursively();
@@ -243,24 +262,6 @@ public:
QPalette naturalWidgetPalette(uint inheritedMask) const;
void setMask_sys(const QRegion &);
-#ifdef Q_WS_WIN
- bool shouldShowMaximizeButton();
- void winUpdateIsOpaque();
-#endif
-
-#ifdef Q_WS_MAC
- void macUpdateSizeAttribute();
- void macUpdateHideOnSuspend();
- void macUpdateOpaqueSizeGrip();
- void macUpdateIgnoreMouseEvents();
- void macUpdateMetalAttribute();
- void macUpdateIsOpaque();
- void setEnabled_helper_sys(bool enable);
- bool isRealWindow() const;
- void adjustWithinMaxAndMinSize(int &w, int &h);
- void applyMaxAndMinSizeOnWindow();
-#endif
-
void raise_sys();
void lower_sys();
void stackUnder_sys(QWidget *);
@@ -285,20 +286,9 @@ public:
void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack = false);
void inheritStyle();
- bool isBackgroundInherited() const;
-
void setUpdatesEnabled_helper(bool );
void paintBackground(QPainter *, const QRegion &, const QPoint & = QPoint(), int flags = DrawAsRoot) const;
- enum DrawWidgetFlags {
- DrawAsRoot = 0x01,
- DrawPaintOnScreen = 0x02,
- DrawRecursive = 0x04,
- DrawInvisible = 0x08,
- DontSubtractOpaqueChildren = 0x10,
- DontSetCompositionMode = 0x20,
- DontDrawOpaqueChildren = 0x40
- };
bool isAboutToShow() const;
QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
@@ -321,10 +311,6 @@ public:
QWindowSurface *createDefaultWindowSurface();
QWindowSurface *createDefaultWindowSurface_sys();
void repaint_sys(const QRegion &rgn);
-#ifdef Q_WS_MAC
- void update_sys(const QRect &rect);
- void update_sys(const QRegion &rgn);
-#endif
QRect clipRect() const;
QRegion clipRegion() const;
@@ -335,42 +321,20 @@ public:
void updateIsOpaque();
void setOpaque(bool opaque);
void updateIsTranslucent();
- bool hasBackground() const;
bool paintOnScreen() const;
QRegion getOpaqueRegion() const;
const QRegion &getOpaqueChildren() const;
void setDirtyOpaqueRegion();
- QRegion opaqueChildren;
-
- enum CloseMode {
- CloseNoEvent,
- CloseWithEvent,
- CloseWithSpontaneousEvent
- };
bool close_helper(CloseMode mode);
- bool compositeEvent(QEvent *e);
void setWindowIcon_helper();
void setWindowIcon_sys(bool forceReset = false);
void setWindowOpacity_sys(qreal opacity);
-
void adjustQuitOnCloseAttribute();
-#if defined(Q_WS_X11)
- void setWindowRole();
- void sendStartupMessage(const char *message) const;
- void setNetWmWindowTypes();
- void x11UpdateIsOpaque();
-#endif
-
-#if defined (Q_WS_WIN)
- void reparentChildren();
-#endif
-
void scrollChildren(int dx, int dy);
-
void moveRect(const QRect &, int dx, int dy);
void scrollRect(const QRect &, int dx, int dy);
void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
@@ -384,7 +348,6 @@ public:
void reparentFocusWidgets(QWidget *oldtlw);
static int pointToRect(const QPoint &p, const QRect &r);
- QRect fromOrToLayoutItemRect(const QRect &rect, int sign) const;
void setWinId(WId);
void showChildren(bool spontaneous);
@@ -394,9 +357,6 @@ public:
void scroll_sys(int dx, int dy, const QRect &r);
void deactivateWidgetCleanup();
void setGeometry_sys(int, int, int, int, bool);
-#ifdef Q_WS_MAC
- void setGeometry_sys_helper(int, int, int, int, bool);
-#endif
void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
void activateChildLayoutsRecursively();
void show_recursive();
@@ -408,10 +368,6 @@ public:
void setEnabled_helper(bool);
void registerDropSite(bool);
-#if defined(Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP)
- QOleDropTarget *registerOleDnd(QWidget *widget);
- void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
-#endif
static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
void updateFrameStrut();
@@ -421,32 +377,11 @@ public:
void setWindowIconText_helper(const QString &cap);
void setWindowTitle_sys(const QString &cap);
-#ifdef Q_OS_WIN
- void grabMouseWhileInWindow();
-#endif
-
#ifndef QT_NO_CURSOR
void setCursor_sys(const QCursor &cursor);
void unsetCursor_sys();
#endif
-#ifdef Q_WS_MAC
- void setWindowModified_sys(bool b);
- void updateMaximizeButton_sys();
- void setWindowFilePath_sys(const QString &filePath);
- void createWindow_sys();
- void recreateMacWindow();
-#ifndef QT_MAC_USE_COCOA
- void initWindowPtr();
- void finishCreateWindow_sys_Carbon(OSWindowRef windowRef);
-#else
- void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
- void syncCocoaMask();
- void finishCocoaMaskSetup();
-#endif
- void determineWindowClass();
- void transferChildren();
-#endif
void setWindowTitle_helper(const QString &cap);
void setWindowFilePath_helper(const QString &filePath);
@@ -462,59 +397,89 @@ public:
QInputContext *inputContext() const;
-#if defined(Q_WS_QWS)
- void moveSurface(QWindowSurface *surface, const QPoint &offset);
+ void setModal_sys();
- QRegion localRequestedRegion() const;
- QRegion localAllocatedRegion() const;
+ inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
+ {
+ Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
+ redirectDev = replacement;
+ redirectOffset = offset;
+ }
- void blitToScreen(const QRegion &globalrgn);
-#ifndef QT_NO_CURSOR
- void updateCursor() const;
-#endif
+ inline QPaintDevice *redirected(QPoint *offset) const
+ {
+ if (offset)
+ *offset = redirectDev ? redirectOffset : QPoint();
+ return redirectDev;
+ }
- QScreen* getScreen() const;
+ inline void restoreRedirected()
+ { redirectDev = 0; }
- friend class QWSManager;
- friend class QWSManagerPrivate;
- friend class QDecoration;
-#endif
+ inline void enforceNativeChildren()
+ {
+ if (!extra)
+ createExtra();
- static int instanceCounter; // Current number of widget instances
- static int maxInstances; // Maximum number of widget instances
+ if (extra->nativeChildrenForced)
+ return;
+ extra->nativeChildrenForced = 1;
-#ifdef QT_KEYPAD_NAVIGATION
- static QPointer<QWidget> editingWidget;
-#endif
+ for (int i = 0; i < children.size(); ++i) {
+ if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
+ child->setAttribute(Qt::WA_NativeWindow);
+ }
+ }
- QWidgetData data;
+ inline bool nativeChildrenForced() const
+ {
+ return extra ? extra->nativeChildrenForced : false;
+ }
+ QSize adjustedSize() const;
+
+#ifndef Q_WS_QWS // Almost cross-platform :-)
+ void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
+
+ inline QPoint mapToWS(const QPoint &p) const
+ { return p - data.wrect.topLeft(); }
+
+ inline QPoint mapFromWS(const QPoint &p) const
+ { return p + data.wrect.topLeft(); }
+
+ inline QRect mapToWS(const QRect &r) const
+ { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
+
+ inline QRect mapFromWS(const QRect &r) const
+ { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
+#endif
+
+ // Variables.
+ // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
QWExtra *extra;
QWidget *focus_next;
QWidget *focus_prev;
QWidget *focus_child;
-#ifndef QT_NO_ACTION
- QList<QAction*> actions;
-#endif
QLayout *layout;
+ QRegion *needsFlush;
+ QPaintDevice *redirectDev;
QWidgetItemV2 *widgetItem;
-#if !defined(QT_NO_IM)
- QPointer<QInputContext> ic;
-#endif
+ QPaintEngine *extraPaintEngine;
+ mutable const QMetaObject *polished;
// All widgets are initially added into the uncreatedWidgets set. Once
// they receive a window id they are removed and added to the mapper
static QWidgetMapper *mapper;
static QWidgetSet *uncreatedWidgets;
+#if !defined(QT_NO_IM)
+ QPointer<QInputContext> ic;
+#endif
+#ifdef QT_KEYPAD_NAVIGATION
+ static QPointer<QWidget> editingWidget;
+#endif
- short leftmargin, topmargin, rightmargin, bottommargin;
-
- signed char leftLayoutItemMargin;
- signed char topLayoutItemMargin;
- signed char rightLayoutItemMargin;
- signed char bottomLayoutItemMargin;
-
- // ### TODO: reorganize private/extra/topextra to save memory
- QPointer<QWidget> compositeChildGrab;
+ // Implicit pointers (shared_null/shared_empty).
+ QRegion opaqueChildren;
+ QRegion dirty;
#ifndef QT_NO_TOOLTIP
QString toolTip;
#endif
@@ -524,14 +489,37 @@ public:
#ifndef QT_NO_WHATSTHIS
QString whatsThis;
#endif
- QString accessibleName, accessibleDescription;
+#ifndef QT_NO_ACCESSIBILITY
+ QString accessibleName;
+ QString accessibleDescription;
+#endif
+
+ // Other variables.
+ uint inheritedFontResolveMask;
+ uint inheritedPaletteResolveMask;
+ short leftmargin;
+ short topmargin;
+ short rightmargin;
+ short bottommargin;
+ signed char leftLayoutItemMargin;
+ signed char topLayoutItemMargin;
+ signed char rightLayoutItemMargin;
+ signed char bottomLayoutItemMargin;
+ static int instanceCounter; // Current number of widget instances
+ static int maxInstances; // Maximum number of widget instances
+ Qt::HANDLE hd;
+ QWidgetData data;
+ QSizePolicy size_policy;
+ QLocale locale;
+ QPoint redirectOffset;
+#ifndef QT_NO_ACTION
+ QList<QAction*> actions;
+#endif
+ // Bit fields.
+ uint high_attributes[3]; // the low ones are in QWidget::widget_attributes
QPalette::ColorRole fg_role : 8;
QPalette::ColorRole bg_role : 8;
- uint high_attributes[3]; // the low ones are in QWidget::widget_attributes
- Qt::HANDLE hd;
- QRegion dirty;
- QRegion *needsFlush;
uint dirtyOpaqueChildren : 1;
uint isOpaque : 1;
uint inDirtyList : 1;
@@ -539,35 +527,33 @@ public:
uint isMoved : 1;
uint usesDoubleBufferedGLContext : 1;
-#ifdef Q_WS_WIN
- uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
-#endif
-
- uint inheritedFontResolveMask;
- uint inheritedPaletteResolveMask;
-#if defined(Q_WS_X11)
+ // *************************** Platform specific ************************************
+#if defined(Q_WS_X11) // <----------------------------------------------------------- X11
QX11Info xinfo;
Qt::HANDLE picture;
+ static QWidget *mouseGrabber;
+ static QWidget *keyboardGrabber;
+
+ void setWindowRole();
+ void sendStartupMessage(const char *message) const;
+ void setNetWmWindowTypes();
+ void x11UpdateIsOpaque();
+ bool isBackgroundInherited() const;
+#elif defined(Q_WS_WIN) // <--------------------------------------------------------- WIN
+ uint noPaintOnScreen : 1; // see qwidget_win.cpp ::paintEngine()
+
+ bool shouldShowMaximizeButton();
+ void winUpdateIsOpaque();
+ void reparentChildren();
+#ifndef QT_NO_DRAGANDDROP
+ QOleDropTarget *registerOleDnd(QWidget *widget);
+ void unregisterOleDnd(QWidget *widget, QOleDropTarget *target);
#endif
-#if defined(Q_WS_MAC)
- enum PaintChildrenOPs {
- PC_None = 0x00,
- PC_Now = 0x01,
- PC_NoPaint = 0x04,
- PC_Later = 0x10
- };
- EventHandlerRef window_event;
- bool qt_mac_dnd_event(uint, DragRef);
- void toggleDrawers(bool);
- //mac event functions
- static bool qt_create_root_win();
- static void qt_clean_root_win();
- static bool qt_recreate_root_win();
- static bool qt_mac_update_sizer(QWidget *, int up = 0);
- static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
- static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
- static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
- static bool qt_widget_shape(QWidget *, short, HIMutableShapeRef, bool);
+ void grabMouseWhileInWindow();
+#elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC
+ // This is new stuff
+ uint needWindowChange : 1;
+ uint isGLWidget : 1;
// Each wiget keeps a list of all its child and grandchild OpenGL widgets.
// This list is used to update the gl context whenever a parent and a granparent
@@ -580,95 +566,70 @@ public:
QWidget * widget;
QWidget * lastUpdateWidget;
};
- QList<GlWidgetInfo> glWidgets;
// dirtyOnWidget contains the areas in the widget that needs to be repained,
// in the same way as dirtyOnScreen does for the window. Areas are added in
// dirtyWidget_sys and cleared in the paint event. In scroll_sys we then use
// this information repaint invalid areas when widgets are scrolled.
QRegion dirtyOnWidget;
+ EventHandlerRef window_event;
+ QList<GlWidgetInfo> glWidgets;
//these are here just for code compat (HIViews)
Qt::HANDLE qd_hd;
- // This is new stuff
- uint needWindowChange : 1;
- uint isGLWidget : 1;
-#endif
-
-#if defined(Q_WS_X11) || defined (Q_WS_WIN) || defined(Q_WS_MAC)
-#ifdef Q_WS_MAC
- void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
+ void macUpdateSizeAttribute();
+ void macUpdateHideOnSuspend();
+ void macUpdateOpaqueSizeGrip();
+ void macUpdateIgnoreMouseEvents();
+ void macUpdateMetalAttribute();
+ void macUpdateIsOpaque();
+ void setEnabled_helper_sys(bool enable);
+ bool isRealWindow() const;
+ void adjustWithinMaxAndMinSize(int &w, int &h);
+ void applyMaxAndMinSizeOnWindow();
+ void update_sys(const QRect &rect);
+ void update_sys(const QRegion &rgn);
+ void setGeometry_sys_helper(int, int, int, int, bool);
+ void setWindowModified_sys(bool b);
+ void updateMaximizeButton_sys();
+ void setWindowFilePath_sys(const QString &filePath);
+ void createWindow_sys();
+ void recreateMacWindow();
+#ifndef QT_MAC_USE_COCOA
+ void initWindowPtr();
+ void finishCreateWindow_sys_Carbon(OSWindowRef windowRef);
#else
- void setWSGeometry(bool dontShow=false);
+ void finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ windowRef);
+ void syncCocoaMask();
+ void finishCocoaMaskSetup();
#endif
+ void determineWindowClass();
+ void transferChildren();
+ bool qt_mac_dnd_event(uint, DragRef);
+ void toggleDrawers(bool);
+ //mac event functions
+ static bool qt_create_root_win();
+ static void qt_clean_root_win();
+ static bool qt_mac_update_sizer(QWidget *, int up = 0);
+ static OSStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
+ static OSStatus qt_widget_event(EventHandlerCallRef er, EventRef event, void *);
+ static bool qt_widget_rgn(QWidget *, short, RgnHandle, bool);
+#elif defined(Q_WS_QWS) // <--------------------------------------------------------- QWS
+ void setMaxWindowState_helper();
+ void setFullScreenSize_helper();
+ void moveSurface(QWindowSurface *surface, const QPoint &offset);
+ QRegion localRequestedRegion() const;
+ QRegion localAllocatedRegion() const;
- inline QPoint mapToWS(const QPoint &p) const
- { return p - data.wrect.topLeft(); }
-
- inline QPoint mapFromWS(const QPoint &p) const
- { return p + data.wrect.topLeft(); }
-
- inline QRect mapToWS(const QRect &r) const
- { QRect rr(r); rr.translate(-data.wrect.topLeft()); return rr; }
-
- inline QRect mapFromWS(const QRect &r) const
- { QRect rr(r); rr.translate(data.wrect.topLeft()); return rr; }
+ friend class QWSManager;
+ friend class QWSManagerPrivate;
+ friend class QDecoration;
+#ifndef QT_NO_CURSOR
+ void updateCursor() const;
#endif
-
- QPaintEngine *extraPaintEngine;
-
- mutable const QMetaObject *polished;
-
- void setModal_sys();
- QSizePolicy size_policy;
- QLocale locale;
-
-#ifdef Q_WS_X11
- static QWidget *mouseGrabber;
- static QWidget *keyboardGrabber;
+ QScreen* getScreen() const;
#endif
- QPaintDevice *redirectDev;
- QPoint redirectOffset;
-
- inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
- {
- Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
- redirectDev = replacement;
- redirectOffset = offset;
- }
-
- inline QPaintDevice *redirected(QPoint *offset) const
- {
- if (offset)
- *offset = redirectDev ? redirectOffset : QPoint();
- return redirectDev;
- }
-
- inline void restoreRedirected()
- { redirectDev = 0; }
-
- inline void enforceNativeChildren()
- {
- if (!extra)
- createExtra();
-
- if (extra->nativeChildrenForced)
- return;
- extra->nativeChildrenForced = 1;
-
- for (int i = 0; i < children.size(); ++i) {
- if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
- child->setAttribute(Qt::WA_NativeWindow);
- }
- }
-
- inline bool nativeChildrenForced() const
- {
- return extra ? extra->nativeChildrenForced : false;
- }
-
- QSize adjustedSize() const;
};
inline QWExtra *QWidgetPrivate::extraData() const
diff --git a/src/gui/kernel/qwidget_qws.cpp b/src/gui/kernel/qwidget_qws.cpp
index 1445f57..94bdb85 100644
--- a/src/gui/kernel/qwidget_qws.cpp
+++ b/src/gui/kernel/qwidget_qws.cpp
@@ -565,20 +565,6 @@ void QWidget::activateWindow()
}
}
-/*
- Should we require that q is a toplevel window ???
-
- Used by QWSManager
- */
-void QWidgetPrivate::blitToScreen(const QRegion &globalrgn)
-{
- Q_Q(QWidget);
- QWidget *win = q->window();
- QBrush bgBrush = win->palette().brush(win->backgroundRole());
- bool opaque = bgBrush.style() == Qt::NoBrush || bgBrush.isOpaque();
- QWidget::qwsDisplay()->repaintRegion(win->data->winid, win->windowFlags(), opaque, globalrgn);
-}
-
void QWidgetPrivate::show_sys()
{
Q_Q(QWidget);
@@ -1037,6 +1023,9 @@ void QWidgetPrivate::deleteSysExtra()
void QWidgetPrivate::createTLSysExtra()
{
+#ifndef QT_NO_QWS_MANAGER
+ extra->topextra->qwsManager = 0;
+#endif
}
void QWidgetPrivate::deleteTLSysExtra()
diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp
index ffbb341..0f341fd 100644
--- a/src/gui/kernel/qwidget_win.cpp
+++ b/src/gui/kernel/qwidget_win.cpp
@@ -56,19 +56,13 @@
#include "private/qbackingstore_p.h"
#include "private/qwindowsurface_raster_p.h"
-#ifndef QT_NO_DIRECT3D
-#include "private/qpaintengine_d3d_p.h"
-#include "private/qwindowsurface_d3d_p.h"
-#endif
-
-
#include <qdebug.h>
#include <private/qapplication_p.h>
#include <private/qwininputcontext_p.h>
#include <private/qpaintengine_raster_p.h>
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#include "qguifunctions_wince.h"
QT_USE_NAMESPACE
extern void qt_wince_maximize(QWidget *widget); //defined in qguifunctions_wince.cpp
@@ -257,7 +251,7 @@ extern "C" LRESULT CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM);
QWidget member functions
*****************************************************************************/
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
{
Q_Q(QWidget);
@@ -546,7 +540,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
}
}
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
@@ -574,7 +568,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
if (destroyWindow && !(windowType() == Qt::Desktop) && internalWinId()) {
DestroyWindow(internalWinId());
}
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (destroyWindow && (windowType() == Qt::Desktop) && !GetDesktopWindow()) {
DestroyWindow(internalWinId());
}
@@ -681,7 +675,7 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
}
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
// Show borderless toplevel windows in tasklist & NavBar
if (!parent) {
QString txt = q->windowTitle().isEmpty()?qAppName():q->windowTitle();
@@ -877,12 +871,12 @@ QCursor *qt_grab_cursor()
}
// The procedure does nothing, but is required for mousegrabbing to work
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
LRESULT CALLBACK qJournalRecordProc(int nCode, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(journalRec, nCode, wParam, lParam);
}
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
/* Works only as long as pointer is inside the application's window,
which is good enough for QDockWidget.
@@ -905,7 +899,7 @@ void QWidgetPrivate::grabMouseWhileInWindow()
}
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
void QWidget::grabMouse()
{
if (!qt_nograb()) {
@@ -982,7 +976,7 @@ void QWidget::activateWindow()
SetForegroundWindow(window()->internalWinId());
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
void QWidget::setWindowState(Qt::WindowStates newstate)
{
Q_D(QWidget);
@@ -1031,13 +1025,13 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
if (newstate & Qt::WindowFullScreen) {
if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized))
d->topData()->normalGeometry = geometry();
- d->topData()->savedFlags = GetWindowLongA(internalWinId(), GWL_STYLE);
+ d->topData()->savedFlags = Qt::WindowFlags(GetWindowLongA(internalWinId(), GWL_STYLE));
#ifndef Q_FLATTEN_EXPOSE
UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP;
#else
UINT style = WS_POPUP;
#endif
- if (d->topData()->savedFlags & WS_SYSMENU)
+ if (ulong(d->topData()->savedFlags) & WS_SYSMENU)
style |= WS_SYSMENU;
if (isVisible())
style |= WS_VISIBLE;
@@ -1084,7 +1078,7 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
QWindowStateChangeEvent e(oldstate);
QApplication::sendEvent(this, &e);
}
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
/*
@@ -1097,7 +1091,7 @@ void QWidgetPrivate::hide_sys()
Q_Q(QWidget);
deactivateWidgetCleanup();
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (!qt_wince_is_mobile() && q->isFullScreen()) {
HWND handle = FindWindow(L"HHTaskBar", L"");
if (handle) {
@@ -1126,7 +1120,7 @@ void QWidgetPrivate::hide_sys()
\internal
Platform-specific part of QWidget::show().
*/
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
void QWidgetPrivate::show_sys()
{
Q_Q(QWidget);
@@ -1194,7 +1188,7 @@ void QWidgetPrivate::show_sys()
invalidateBuffer(q->rect());
}
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
void QWidgetPrivate::setFocus_sys()
{
@@ -1240,7 +1234,7 @@ void QWidgetPrivate::stackUnder_sys(QWidget* w)
(In all comments below: s/X/Windows/g)
*/
-void QWidgetPrivate::setWSGeometry(bool dontShow)
+void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &)
{
Q_Q(QWidget);
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
@@ -1452,7 +1446,7 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
show_sys();
} else if (!q->testAttribute(Qt::WA_DontShowOnScreen)) {
q->setAttribute(Qt::WA_OutsideWSRange, false);
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
// If the window is hidden and in maximized state or minimized, instead of moving the
// window, set the normal position of the window.
WINDOWPLACEMENT wndpl;
@@ -1571,7 +1565,7 @@ bool QWidgetPrivate::shouldShowMaximizeButton()
void QWidgetPrivate::winUpdateIsOpaque()
{
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
Q_Q(QWidget);
if (!q->isWindow() || !q->testAttribute(Qt::WA_TranslucentBackground))
@@ -1592,7 +1586,7 @@ void QWidgetPrivate::winUpdateIsOpaque()
void QWidgetPrivate::setConstraints_sys()
{
-#ifndef Q_OS_WINCE_WM
+#ifndef Q_WS_WINCE_WM
Q_Q(QWidget);
if (q->isWindow() && q->testAttribute(Qt::WA_WState_Created)) {
int style = GetWindowLongA(q->internalWinId(), GWL_STYLE);
@@ -1710,28 +1704,24 @@ int QWidget::metric(PaintDeviceMetric m) const
return val;
}
-#ifndef Q_OS_WINCE
void QWidgetPrivate::createSysExtra()
{
#ifndef QT_NO_DRAGANDDROP
extra->dropTarget = 0;
#endif
-#ifndef QT_NO_DIRECT3D
- extra->had_auto_fill_bg = 0;
- extra->had_paint_on_screen = 0;
- extra->had_no_system_bg = 0;
-#endif
}
+#ifndef Q_WS_WINCE
void QWidgetPrivate::deleteSysExtra()
{
}
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
void QWidgetPrivate::createTLSysExtra()
{
- extra->topextra->winIconSmall = 0;
+ extra->topextra->savedFlags = 0;
extra->topextra->winIconBig = 0;
+ extra->topextra->winIconSmall = 0;
}
void QWidgetPrivate::deleteTLSysExtra()
@@ -1877,7 +1867,7 @@ void QWidgetPrivate::updateFrameStrut()
GetWindowLongA(q->internalWinId(), GWL_EXSTYLE));
uint style = QT_WA_INLINE(GetWindowLongW(q->internalWinId(), GWL_STYLE),
GetWindowLongA(q->internalWinId(), GWL_STYLE));
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
if (AdjustWindowRectEx(&rect, style & ~(WS_OVERLAPPED), FALSE, exstyle)) {
#else
if (AdjustWindowRectEx(&rect, style, FALSE, exstyle)) {
@@ -1887,7 +1877,7 @@ void QWidgetPrivate::updateFrameStrut()
}
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
void QWidgetPrivate::setWindowOpacity_sys(qreal level)
{
Q_Q(QWidget);
@@ -1922,7 +1912,7 @@ void QWidgetPrivate::setWindowOpacity_sys(qreal level)
}
(*ptrSetLayeredWindowAttributes)(q->internalWinId(), 0, (int)(level * 255), Q_LWA_ALPHA);
}
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
// class QGlobalRasterPaintEngine: public QRasterPaintEngine
// {
@@ -1931,22 +1921,6 @@ void QWidgetPrivate::setWindowOpacity_sys(qreal level)
// };
// Q_GLOBAL_STATIC(QGlobalRasterPaintEngine, globalRasterPaintEngine)
-#ifndef QT_NO_DIRECT3D
-static void cleanup_d3d_engine();
-Q_GLOBAL_STATIC_WITH_INITIALIZER(QDirect3DPaintEngine, _qt_d3dEngine,
- {
- qAddPostRoutine(cleanup_d3d_engine);
- })
-static void cleanup_d3d_engine()
-{
- _qt_d3dEngine()->cleanup();
-}
-QDirect3DPaintEngine* qt_d3dEngine()
-{
- return _qt_d3dEngine();
-}
-#endif
-
#ifndef QT_NO_DIRECTDRAW
static uchar *qt_primary_surface_bits;
@@ -2059,19 +2033,6 @@ void qt_win_initialize_directdraw() { }
QPaintEngine *QWidget::paintEngine() const
{
-#ifndef QT_NO_DIRECT3D
- if ((qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault)
- || testAttribute(Qt::WA_MSWindowsUseDirect3D))
- && qt_d3dEngine()->hasDirect3DSupport())
- {
- QDirect3DPaintEngine *engine = qt_d3dEngine();
- if (qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault))
- engine->setFlushOnEnd(false);
- else
- engine->setFlushOnEnd(true);
- return engine;
- }
-#endif
#ifndef QT_NO_DIRECTDRAW
QOnScreenRasterPaintEngine *pe = onScreenPaintEngine();
pe->widget = this;
@@ -2100,13 +2061,6 @@ QPaintEngine *QWidget::paintEngine() const
QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys()
{
Q_Q(QWidget);
-#ifndef QT_NO_DIRECT3D
- extern QDirect3DPaintEngine *qt_d3dEngine();
- if (qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault) && (q->windowOpacity() == 1.0f)
- && qt_d3dEngine()->hasDirect3DSupport()) {
- return new QD3DWindowSurface(q);
- }
-#endif
return new QRasterWindowSurface(q);
}
@@ -2119,6 +2073,6 @@ void QWidgetPrivate::setModal_sys()
QT_END_NAMESPACE
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
# include "qwidget_wince.cpp"
#endif
diff --git a/src/gui/kernel/qwidget_wince.cpp b/src/gui/kernel/qwidget_wince.cpp
index bb9681e..435fd31 100644
--- a/src/gui/kernel/qwidget_wince.cpp
+++ b/src/gui/kernel/qwidget_wince.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include "qguifunctions_wince.h"
@@ -211,7 +211,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
style |= WS_SYSMENU;
if (flags & Qt::WindowContextHelpButtonHint)
exsty |= WS_EX_CONTEXTHELP;
-#ifndef Q_OS_WINCE_WM
+#ifndef Q_WS_WINCE_WM
if (flags & Qt::WindowMinimizeButtonHint)
style |= WS_MINIMIZEBOX;
if (shouldShowMaximizeButton())
@@ -414,7 +414,7 @@ void QWidgetPrivate::show_sys() {
int sm = SW_SHOW;
bool fakedMaximize = false;
if (q->isWindow()) {
-#ifndef Q_OS_WINCE_WM
+#ifndef Q_WS_WINCE_WM
if (q->isMinimized()) {
sm = SW_SHOWMINIMIZED;
} else if (q->isMaximized()) {
@@ -450,7 +450,7 @@ void QWidgetPrivate::show_sys() {
if (q->isMaximized() && q->isWindow())
qt_wince_maximize(q);
-#ifndef Q_OS_WINCE_WM
+#ifndef Q_WS_WINCE_WM
if (!qt_wince_is_mobile() && q->isFullScreen()) {
HWND handle = FindWindow(L"HHTaskBar", L"");
if (handle) {
@@ -535,7 +535,7 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
if (newstate & Qt::WindowFullScreen) {
if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized))
d->topData()->normalGeometry = geometry();
- d->topData()->savedFlags = GetWindowLongA(internalWinId(), GWL_STYLE);
+ d->topData()->savedFlags = (Qt::WindowFlags) GetWindowLongA(internalWinId(), GWL_STYLE);
UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP;
if (isVisible())
style |= WS_VISIBLE;
@@ -583,7 +583,7 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
}
if ((newstate & Qt::WindowMaximized) && !(newstate & Qt::WindowFullScreen)) {
QRect r = d->topData()->normalGeometry;
-#ifdef Q_OS_WINCE_WM
+#ifdef Q_WS_WINCE_WM
if (!inherits("QDialog") && !inherits("QMdiArea") && !isVisible()) {
d->data.crect.setRect(0, 0, -1, -1);
}
@@ -598,13 +598,6 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
QApplication::sendEvent(this, &e);
}
-
-void QWidgetPrivate::createSysExtra() {
-#ifndef QT_NO_DRAGANDDROP
- extra->dropTarget = 0;
-#endif
-}
-
void QWidgetPrivate::deleteSysExtra()
{
Q_Q(QWidget);
@@ -704,4 +697,4 @@ void QWidget::show()
QT_END_NAMESPACE
-#endif Q_OS_WINCE
+#endif // Q_WS_WINCE
diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp
index 6202b35..b35740a 100644
--- a/src/gui/kernel/qwidget_x11.cpp
+++ b/src/gui/kernel/qwidget_x11.cpp
@@ -906,6 +906,44 @@ void QWidgetPrivate::x11UpdateIsOpaque()
#endif
}
+/*
+ Returns true if the background is inherited; otherwise returns
+ false.
+
+ Mainly used in the paintOnScreen case.
+*/
+bool QWidgetPrivate::isBackgroundInherited() const
+{
+ Q_Q(const QWidget);
+
+ // windows do not inherit their background
+ if (q->isWindow() || q->windowType() == Qt::SubWindow)
+ return false;
+
+ if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent))
+ return false;
+
+ const QPalette &pal = q->palette();
+ QPalette::ColorRole bg = q->backgroundRole();
+ QBrush brush = pal.brush(bg);
+
+ // non opaque brushes leaves us no choice, we must inherit
+ if (!q->autoFillBackground() || !brush.isOpaque())
+ return true;
+
+ if (brush.style() == Qt::SolidPattern) {
+ // the background is just a solid color. If there is no
+ // propagated contents, then we claim as performance
+ // optimization that it was not inheritet. This is the normal
+ // case in standard Windows or Motif style.
+ const QWidget *w = q->parentWidget();
+ if (!w->d_func()->isBackgroundInherited())
+ return false;
+ }
+
+ return true;
+}
+
void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
{
Q_D(QWidget);
@@ -2152,7 +2190,7 @@ static void do_size_hints(QWidget* widget, QWExtra *x)
parentWRect is the geometry of the parent's X rect, measured in
parent's coord sys
*/
-void QWidgetPrivate::setWSGeometry(bool dontShow)
+void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &)
{
Q_Q(QWidget);
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
@@ -2610,8 +2648,8 @@ int QWidget::metric(PaintDeviceMetric m) const
void QWidgetPrivate::createSysExtra()
{
- extra->xDndProxy = 0;
extra->compress_events = true;
+ extra->xDndProxy = 0;
}
void QWidgetPrivate::deleteSysExtra()
@@ -2620,8 +2658,11 @@ void QWidgetPrivate::deleteSysExtra()
void QWidgetPrivate::createTLSysExtra()
{
+ extra->topextra->spont_unmapped = 0;
+ extra->topextra->dnd = 0;
extra->topextra->validWMState = 0;
extra->topextra->waitingForMapNotify = 0;
+ extra->topextra->parentWinId = 0;
extra->topextra->userTimeWindow = 0;
}
diff --git a/src/gui/kernel/qx11embed_x11.cpp b/src/gui/kernel/qx11embed_x11.cpp
index 6329135..ae93efe 100644
--- a/src/gui/kernel/qx11embed_x11.cpp
+++ b/src/gui/kernel/qx11embed_x11.cpp
@@ -1297,9 +1297,6 @@ bool QX11EmbedContainer::eventFilter(QObject *o, QEvent *event)
// focus is set to our focus proxy. We want to intercept all
// keypresses.
if (o == window() && d->client) {
- if (!d->isEmbedded() && d->activeContainer == this)
- d->moveInputToProxy();
-
if (d->clientIsXEmbed) {
sendXEmbedMessage(d->client, x11Info().display(), XEMBED_WINDOW_ACTIVATE);
} else {
@@ -1307,6 +1304,8 @@ bool QX11EmbedContainer::eventFilter(QObject *o, QEvent *event)
if (hasFocus())
XSetInputFocus(x11Info().display(), d->client, XRevertToParent, x11Time());
}
+ if (!d->isEmbedded())
+ d->moveInputToProxy();
}
break;
case QEvent::WindowDeactivate:
@@ -1729,10 +1728,10 @@ void QX11EmbedContainerPrivate::acceptClient(WId window)
checkGrab();
if (q->hasFocus()) {
XSetInputFocus(q->x11Info().display(), client, XRevertToParent, x11Time());
- } else {
- if (!isEmbedded())
- moveInputToProxy();
}
+ } else {
+ if (!isEmbedded())
+ moveInputToProxy();
}
emit q->clientIsEmbedded();
@@ -1749,11 +1748,9 @@ void QX11EmbedContainerPrivate::acceptClient(WId window)
void QX11EmbedContainerPrivate::moveInputToProxy()
{
Q_Q(QX11EmbedContainer);
- WId focus;
- int revert_to;
- XGetInputFocus(q->x11Info().display(), &focus, &revert_to);
- if (focus != focusProxy->internalWinId())
- XSetInputFocus(q->x11Info().display(), focusProxy->internalWinId(), XRevertToParent, x11Time());
+ // Following Owen Taylor's advice from the XEmbed specification to
+ // always use CurrentTime when no explicit user action is involved.
+ XSetInputFocus(q->x11Info().display(), focusProxy->internalWinId(), XRevertToParent, CurrentTime);
}
/*! \internal
diff --git a/src/gui/mac/images/leopard-unified-toolbar-on.png b/src/gui/mac/images/leopard-unified-toolbar-on.png
new file mode 100644
index 0000000..6716597
--- /dev/null
+++ b/src/gui/mac/images/leopard-unified-toolbar-on.png
Binary files differ
diff --git a/src/gui/mac/maccursors.qrc b/src/gui/mac/macresources.qrc
index d80a63b..9696002 100644
--- a/src/gui/mac/maccursors.qrc
+++ b/src/gui/mac/macresources.qrc
@@ -6,4 +6,7 @@
<file>images/waitcursor.png</file>
<file>images/pluscursor.png</file>
</qresource>
+<qresource prefix="/trolltech/mac/style">
+<file>images/leopard-unified-toolbar-on.png</file>
+</qresource>
</RCC>
diff --git a/src/gui/math3d/math3d.pri b/src/gui/math3d/math3d.pri
new file mode 100644
index 0000000..e4dd53a
--- /dev/null
+++ b/src/gui/math3d/math3d.pri
@@ -0,0 +1,15 @@
+HEADERS += \
+ math3d/qgenericmatrix.h \
+ math3d/qmatrix4x4.h \
+ math3d/qquaternion.h \
+ math3d/qvector2d.h \
+ math3d/qvector3d.h \
+ math3d/qvector4d.h
+
+SOURCES += \
+ math3d/qgenericmatrix.cpp \
+ math3d/qmatrix4x4.cpp \
+ math3d/qquaternion.cpp \
+ math3d/qvector2d.cpp \
+ math3d/qvector3d.cpp \
+ math3d/qvector4d.cpp
diff --git a/src/gui/math3d/qgenericmatrix.cpp b/src/gui/math3d/qgenericmatrix.cpp
new file mode 100644
index 0000000..a77ca42
--- /dev/null
+++ b/src/gui/math3d/qgenericmatrix.cpp
@@ -0,0 +1,251 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgenericmatrix.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QGenericMatrix
+ \brief The QGenericMatrix class is a template class that represents a NxM transformation matrix with N columns and M rows.
+ \since 4.6
+
+ The QGenericMatrix template has four parameters:
+
+ \table
+ \row \i N \i Number of columns.
+ \row \i M \i Number of rows.
+ \row \i T \i Element type that is visible to users of the class.
+ \row \i InnerT \i Element type that is used inside the class.
+ \endtable
+
+ Normally T and InnerT are the same type; e.g. float or double.
+ But they can be different if the user wants to store elements
+ internally in a fixed-point format for the underlying hardware.
+
+ \sa QMatrix4x4, QFixedPt
+*/
+
+/*!
+ \fn QGenericMatrix::QGenericMatrix()
+
+ Constructs a NxM identity matrix.
+*/
+
+/*!
+ \fn QGenericMatrix::QGenericMatrix(const QGenericMatrix<N, M, T, InnerT>& other)
+
+ Constructs a copy of \a other.
+*/
+
+/*!
+ \fn QGenericMatrix::QGenericMatrix(const T *values)
+
+ Constructs a matrix from the given N * M floating-point \a values.
+ The contents of the array \a values is assumed to be in
+ row-major order.
+
+ \sa toValueArray()
+*/
+
+/*!
+ \fn T QGenericMatrix::operator()(int row, int column) const
+
+ Returns the element at position (\a row, \a column) in this matrix.
+*/
+
+/*!
+ \fn InnerT& QGenericMatrix::operator()(int row, int column)
+
+ Returns a reference to the element at position (\a row, \a column)
+ in this matrix so that the element can be assigned to.
+*/
+
+/*!
+ \fn bool QGenericMatrix::isIdentity() const
+
+ Returns true if this matrix is the identity; false otherwise.
+
+ \sa setIdentity()
+*/
+
+/*!
+ \fn void QGenericMatrix::setIdentity()
+
+ Sets this matrix to the identity.
+
+ \sa isIdentity()
+*/
+
+/*!
+ \fn void QGenericMatrix::fill(qreal value)
+
+ Fills all elements of this matrix with \a value.
+*/
+
+/*!
+ \fn QGenericMatrix<M, N> QGenericMatrix::transposed() const
+
+ Returns this matrix, transposed about its diagonal.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT>& QGenericMatrix::operator+=(const QGenericMatrix<N, M, T, InnerT>& other)
+
+ Adds the contents of \a other to this matrix.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT>& QGenericMatrix::operator-=(const QGenericMatrix<N, M, T, InnerT>& other)
+
+ Subtracts the contents of \a other from this matrix.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT>& QGenericMatrix::operator*=(T factor)
+
+ Multiplies all elements of this matrix by \a factor.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT>& QGenericMatrix::operator/=(T divisor)
+
+ Divides all elements of this matrix by \a divisor.
+*/
+
+/*!
+ \fn bool QGenericMatrix::operator==(const QGenericMatrix<N, M, T, InnerT>& other) const
+
+ Returns true if this matrix is identical to \a other; false otherwise.
+*/
+
+/*!
+ \fn bool QGenericMatrix::operator!=(const QGenericMatrix<N, M, T, InnerT>& other) const
+
+ Returns true if this matrix is not identical to \a other; false otherwise.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT> operator+(const QGenericMatrix<N, M, T, InnerT>& m1, const QGenericMatrix<N, M, T, InnerT>& m2)
+ \relates QGenericMatrix
+
+ Returns the sum of \a m1 and \a m2.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT> operator-(const QGenericMatrix<N, M, T, InnerT>& m1, const QGenericMatrix<N, M, T, InnerT>& m2)
+ \relates QGenericMatrix
+
+ Returns the difference of \a m1 and \a m2.
+*/
+
+/*!
+ \fn QGenericMatrix<M1, M2, T, InnerT> operator*(const QGenericMatrix<N, M2, T, InnerT>& m1, const QGenericMatrix<M1, N, T, InnerT>& m2)
+ \relates QGenericMatrix
+
+ Returns the product of the NxM2 matrix \a m1 and the M1xN matrix \a m2
+ to produce a M1xM2 matrix result.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT> operator-(const QGenericMatrix<N, M, T, InnerT>& matrix)
+ \overload
+ \relates QGenericMatrix
+
+ Returns the negation of \a matrix.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT> operator*(T factor, const QGenericMatrix<N, M, T, InnerT>& matrix)
+ \relates QGenericMatrix
+
+ Returns the result of multiplying all elements of \a matrix by \a factor.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT> operator*(const QGenericMatrix<N, M, T, InnerT>& matrix, T factor)
+ \relates QGenericMatrix
+
+ Returns the result of multiplying all elements of \a matrix by \a factor.
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, T, InnerT> operator/(const QGenericMatrix<N, M, T, InnerT>& matrix, T divisor)
+ \relates QGenericMatrix
+
+ Returns the result of dividing all elements of \a matrix by \a divisor.
+*/
+
+/*!
+ \fn void QGenericMatrix::toValueArray(T *values)
+
+ Retrieves the N * M items in this matrix and writes them to \a values
+ in row-major order.
+*/
+
+/*!
+ \fn InnerT *QGenericMatrix::data()
+
+ Returns a pointer to the raw data of this matrix. This is intended
+ for use with raw GL functions.
+
+ \sa constData()
+*/
+
+/*!
+ \fn const InnerT *QGenericMatrix::data() const
+
+ Returns a constant pointer to the raw data of this matrix.
+ This is intended for use with raw GL functions.
+
+ \sa constData()
+*/
+
+/*!
+ \fn const InnerT *QGenericMatrix::constData() const
+
+ Returns a constant pointer to the raw data of this matrix.
+ This is intended for use with raw GL functions.
+
+ \sa data()
+*/
+
+QT_END_NAMESPACE
diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h
new file mode 100644
index 0000000..d0b22de
--- /dev/null
+++ b/src/gui/math3d/qgenericmatrix.h
@@ -0,0 +1,371 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGENERICMATRIX_H
+#define QGENERICMATRIX_H
+
+#include <QtCore/qmetatype.h>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+template <int N, int M, typename T, typename InnerT = T>
+class QGenericMatrix
+{
+public:
+ QGenericMatrix();
+ QGenericMatrix(const QGenericMatrix<N, M, T, InnerT>& other);
+ explicit QGenericMatrix(const T *values);
+
+ T operator()(int row, int column) const;
+ InnerT& operator()(int row, int column);
+
+ bool isIdentity() const;
+ void setIdentity();
+
+ void fill(qreal value);
+
+ QGenericMatrix<M, N, T, InnerT> transposed() const;
+
+ QGenericMatrix<N, M, T, InnerT>& operator+=(const QGenericMatrix<N, M, T, InnerT>& other);
+ QGenericMatrix<N, M, T, InnerT>& operator-=(const QGenericMatrix<N, M, T, InnerT>& other);
+ QGenericMatrix<N, M, T, InnerT>& operator*=(T factor);
+ QGenericMatrix<N, M, T, InnerT>& operator/=(T divisor);
+ bool operator==(const QGenericMatrix<N, M, T, InnerT>& other) const;
+ bool operator!=(const QGenericMatrix<N, M, T, InnerT>& other) const;
+
+ void toValueArray(T *values);
+
+ InnerT *data() { return m[0]; }
+ const InnerT *data() const { return m[0]; }
+ const InnerT *constData() const { return m[0]; }
+
+#if !defined(Q_NO_TEMPLATE_FRIENDS)
+ template<int NN, int MM, typename TT, typename ITT>
+ friend QGenericMatrix<NN, MM, TT, ITT> operator+(const QGenericMatrix<NN, MM, TT, ITT>& m1, const QGenericMatrix<NN, MM, TT, ITT>& m2);
+ template<int NN, int MM, typename TT, typename ITT>
+ friend QGenericMatrix<NN, MM, TT, ITT> operator-(const QGenericMatrix<NN, MM, TT, ITT>& m1, const QGenericMatrix<NN, MM, TT, ITT>& m2);
+ template<int NN, int M1, int M2, typename TT, typename ITT>
+ friend QGenericMatrix<M1, M2, TT, ITT> operator*(const QGenericMatrix<NN, M2, TT, ITT>& m1, const QGenericMatrix<M1, NN, TT, ITT>& m2);
+ template<int NN, int MM, typename TT, typename ITT>
+ friend QGenericMatrix<NN, MM, TT, ITT> operator-(const QGenericMatrix<NN, MM, TT, ITT>& matrix);
+ template<int NN, int MM, typename TT, typename ITT>
+ friend QGenericMatrix<NN, MM, TT, ITT> operator*(TT factor, const QGenericMatrix<NN, MM, TT, ITT>& matrix);
+ template<int NN, int MM, typename TT, typename ITT>
+ friend QGenericMatrix<NN, MM, TT, ITT> operator*(const QGenericMatrix<NN, MM, TT, ITT>& matrix, TT factor);
+ template<int NN, int MM, typename TT, typename ITT>
+ friend QGenericMatrix<NN, MM, TT, ITT> operator/(const QGenericMatrix<NN, MM, TT, ITT>& matrix, TT divisor);
+
+private:
+#endif
+ InnerT m[N][M]; // Column-major order to match OpenGL.
+
+ QGenericMatrix(int) {} // Construct without initializing identity matrix.
+
+#if !defined(Q_NO_TEMPLATE_FRIENDS)
+ template <int NN, int MM, typename TT, typename ITT>
+ friend class QGenericMatrix;
+#endif
+};
+
+template <int N, int M, typename T, typename InnerT>
+Q_INLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT>::QGenericMatrix()
+{
+ setIdentity();
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_INLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT>::QGenericMatrix(const QGenericMatrix<N, M, T, InnerT>& other)
+{
+ qMemCopy(m, other.m, sizeof(m));
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT>::QGenericMatrix(const T *values)
+{
+ for (int col = 0; col < N; ++col)
+ for (int row = 0; row < M; ++row)
+ m[col][row] = values[row * N + col];
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_INLINE_TEMPLATE T QGenericMatrix<N, M, T, InnerT>::operator()(int row, int column) const
+{
+ Q_ASSERT(row >= 0 && row < M && column >= 0 && column < N);
+ return T(m[column][row]);
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_INLINE_TEMPLATE InnerT& QGenericMatrix<N, M, T, InnerT>::operator()(int row, int column)
+{
+ Q_ASSERT(row >= 0 && row < M && column >= 0 && column < N);
+ return m[column][row];
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE bool QGenericMatrix<N, M, T, InnerT>::isIdentity() const
+{
+ for (int col = 0; col < N; ++col) {
+ for (int row = 0; row < M; ++row) {
+ if (row == col) {
+ if (m[col][row] != 1.0f)
+ return false;
+ } else {
+ if (m[col][row] != 0.0f)
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T, InnerT>::setIdentity()
+{
+ for (int col = 0; col < N; ++col) {
+ for (int row = 0; row < M; ++row) {
+ if (row == col)
+ m[col][row] = 1.0f;
+ else
+ m[col][row] = 0.0f;
+ }
+ }
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T, InnerT>::fill(qreal value)
+{
+ for (int col = 0; col < N; ++col)
+ for (int row = 0; row < M; ++row)
+ m[col][row] = value;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<M, N, T, InnerT> QGenericMatrix<N, M, T, InnerT>::transposed() const
+{
+ QGenericMatrix<M, N, T, InnerT> result(1);
+ for (int row = 0; row < M; ++row)
+ for (int col = 0; col < N; ++col)
+ result.m[row][col] = m[col][row];
+ return result;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT>& QGenericMatrix<N, M, T, InnerT>::operator+=(const QGenericMatrix<N, M, T, InnerT>& other)
+{
+ for (int index = 0; index < N * M; ++index)
+ m[0][index] += other.m[0][index];
+ return *this;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT>& QGenericMatrix<N, M, T, InnerT>::operator-=(const QGenericMatrix<N, M, T, InnerT>& other)
+{
+ for (int index = 0; index < N * M; ++index)
+ m[0][index] -= other.m[0][index];
+ return *this;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT>& QGenericMatrix<N, M, T, InnerT>::operator*=(T factor)
+{
+ InnerT f(factor);
+ for (int index = 0; index < N * M; ++index)
+ m[0][index] *= f;
+ return *this;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE bool QGenericMatrix<N, M, T, InnerT>::operator==(const QGenericMatrix<N, M, T, InnerT>& other) const
+{
+ for (int index = 0; index < N * M; ++index) {
+ if (m[0][index] != other.m[0][index])
+ return false;
+ }
+ return true;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE bool QGenericMatrix<N, M, T, InnerT>::operator!=(const QGenericMatrix<N, M, T, InnerT>& other) const
+{
+ for (int index = 0; index < N * M; ++index) {
+ if (m[0][index] != other.m[0][index])
+ return true;
+ }
+ return false;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT>& QGenericMatrix<N, M, T, InnerT>::operator/=(T divisor)
+{
+ InnerT d(divisor);
+ for (int index = 0; index < N * M; ++index)
+ m[0][index] /= d;
+ return *this;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT> operator+(const QGenericMatrix<N, M, T, InnerT>& m1, const QGenericMatrix<N, M, T, InnerT>& m2)
+{
+ QGenericMatrix<N, M, T, InnerT> result(1);
+ for (int index = 0; index < N * M; ++index)
+ result.m[0][index] = m1.m[0][index] + m2.m[0][index];
+ return result;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT> operator-(const QGenericMatrix<N, M, T, InnerT>& m1, const QGenericMatrix<N, M, T, InnerT>& m2)
+{
+ QGenericMatrix<N, M, T, InnerT> result(1);
+ for (int index = 0; index < N * M; ++index)
+ result.m[0][index] = m1.m[0][index] - m2.m[0][index];
+ return result;
+}
+
+template <int N, int M1, int M2, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<M1, M2, T, InnerT> operator*(const QGenericMatrix<N, M2, T, InnerT>& m1, const QGenericMatrix<M1, N, T, InnerT>& m2)
+{
+ QGenericMatrix<M1, M2, T, InnerT> result(1);
+ for (int row = 0; row < M2; ++row) {
+ for (int col = 0; col < M1; ++col) {
+ InnerT sum(0.0f);
+ for (int j = 0; j < N; ++j)
+ sum += m1.m[j][row] * m2.m[col][j];
+ result.m[col][row] = sum;
+ }
+ }
+ return result;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT> operator-(const QGenericMatrix<N, M, T, InnerT>& matrix)
+{
+ QGenericMatrix<N, M, T, InnerT> result(1);
+ for (int index = 0; index < N * M; ++index)
+ result.m[0][index] = -matrix.m[0][index];
+ return result;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT> operator*(T factor, const QGenericMatrix<N, M, T, InnerT>& matrix)
+{
+ InnerT f(factor);
+ QGenericMatrix<N, M, T, InnerT> result(1);
+ for (int index = 0; index < N * M; ++index)
+ result.m[0][index] = matrix.m[0][index] * f;
+ return result;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT> operator*(const QGenericMatrix<N, M, T, InnerT>& matrix, T factor)
+{
+ InnerT f(factor);
+ QGenericMatrix<N, M, T, InnerT> result(1);
+ for (int index = 0; index < N * M; ++index)
+ result.m[0][index] = matrix.m[0][index] * f;
+ return result;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T, InnerT> operator/(const QGenericMatrix<N, M, T, InnerT>& matrix, T divisor)
+{
+ InnerT d(divisor);
+ QGenericMatrix<N, M, T, InnerT> result(1);
+ for (int index = 0; index < N * M; ++index)
+ result.m[0][index] = matrix.m[0][index] / d;
+ return result;
+}
+
+template <int N, int M, typename T, typename InnerT>
+Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T, InnerT>::toValueArray(T *values)
+{
+ for (int col = 0; col < N; ++col)
+ for (int row = 0; row < M; ++row)
+ values[row * N + col] = T(m[col][row]);
+}
+
+// Define aliases for the useful variants of QGenericMatrix.
+typedef QGenericMatrix<2, 2, qreal, float> QMatrix2x2;
+typedef QGenericMatrix<2, 3, qreal, float> QMatrix2x3;
+typedef QGenericMatrix<2, 4, qreal, float> QMatrix2x4;
+typedef QGenericMatrix<3, 2, qreal, float> QMatrix3x2;
+typedef QGenericMatrix<3, 3, qreal, float> QMatrix3x3;
+typedef QGenericMatrix<3, 4, qreal, float> QMatrix3x4;
+typedef QGenericMatrix<4, 2, qreal, float> QMatrix4x2;
+typedef QGenericMatrix<4, 3, qreal, float> QMatrix4x3;
+
+#ifndef QT_NO_DEBUG_STREAM
+
+template <int N, int M, typename T, typename InnerT>
+QDebug operator<<(QDebug dbg, const QGenericMatrix<N, M, T, InnerT> &m)
+{
+ dbg.nospace() << "QGenericMatrix<" << N << ", " << M
+ << ", " << QTypeInfo<T>::name() << ", " << QTypeInfo<InnerT>::name()
+ << ">(" << endl << qSetFieldWidth(10);
+ for (int row = 0; row < M; ++row) {
+ for (int col = 0; col < N; ++col)
+ dbg << m(row, col);
+ dbg << endl;
+ }
+ dbg << qSetFieldWidth(0) << ')';
+ return dbg.space();
+}
+
+#endif
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QMatrix2x2)
+Q_DECLARE_METATYPE(QMatrix2x3)
+Q_DECLARE_METATYPE(QMatrix2x4)
+Q_DECLARE_METATYPE(QMatrix3x2)
+Q_DECLARE_METATYPE(QMatrix3x3)
+Q_DECLARE_METATYPE(QMatrix3x4)
+Q_DECLARE_METATYPE(QMatrix4x2)
+Q_DECLARE_METATYPE(QMatrix4x3)
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
new file mode 100644
index 0000000..a8dabf3
--- /dev/null
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -0,0 +1,1670 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmatrix4x4.h"
+#include <QtCore/qmath.h>
+#include <QtGui/qmatrix.h>
+#include <QtGui/qtransform.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_MATRIX4X4
+
+/*!
+ \class QMatrix4x4
+ \brief The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
+ \since 4.6
+
+ The matrix elements are stored internally using the most efficient
+ numeric representation for the underlying hardware: floating-point
+ or fixed-point.
+
+ \sa QVector3D, QGenericMatrix
+*/
+
+/*!
+ \fn QMatrix4x4::QMatrix4x4()
+
+ Constructs an identity matrix.
+*/
+
+/*!
+ Constructs a matrix from the given 16 floating-point \a values.
+ The contents of the array \a values is assumed to be in
+ row-major order.
+
+ If the matrix has a special type (identity, translate, scale, etc),
+ the programmer should follow this constructor with a call to
+ inferSpecialType() if they wish QMatrix4x4 to optimize further
+ calls to translate(), scale(), etc.
+
+ \sa toValueArray(), inferSpecialType()
+*/
+QMatrix4x4::QMatrix4x4(const qreal *values)
+{
+ for (int row = 0; row < 4; ++row)
+ for (int col = 0; col < 4; ++col)
+ m[col][row] = values[row * 4 + col];
+ flagBits = General;
+}
+
+/*!
+ \fn QMatrix4x4::QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14, qreal m21, qreal m22, qreal m23, qreal m24, qreal m31, qreal m32, qreal m33, qreal m34, qreal m41, qreal m42, qreal m43, qreal m44)
+
+ Constructs a matrix from the 16 elements \a m11, \a m12, \a m13, \a m14,
+ \a m21, \a m22, \a m23, \a m24, \a m31, \a m32, \a m33, \a m34,
+ \a m41, \a m42, \a m43, and \a m44. The elements are specified in
+ row-major order.
+
+ If the matrix has a special type (identity, translate, scale, etc),
+ the programmer should follow this constructor with a call to
+ inferSpecialType() if they wish QMatrix4x4 to optimize further
+ calls to translate(), scale(), etc.
+
+ \sa inferSpecialType()
+*/
+
+#if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC)
+
+/*!
+ \fn QMatrix4x4::QMatrix4x4(const QGenericMatrix<N, M, qreal, float>& matrix)
+
+ Constructs a 4x4 matrix from the left-most 4 columns and top-most
+ 4 rows of \a matrix. If \a matrix has less than 4 columns or rows,
+ the remaining elements are filled with elements from the identity
+ matrix.
+
+ \sa toGenericMatrix(), qGenericMatrixToMatrix4x4()
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, qreal, float> QMatrix4x4::toGenericMatrix() const
+
+ Constructs a NxM generic matrix from the left-most N columns and
+ top-most M rows of this 4x4 matrix. If N or M is greater than 4,
+ then the remaining elements are filled with elements from the
+ identity matrix.
+
+ \sa qGenericMatrixFromMatrix4x4()
+*/
+
+#endif
+
+/*!
+ \fn QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, qreal, float>& matrix)
+ \relates QMatrix4x4
+
+ Returns a 4x4 matrix constructed from the left-most 4 columns and
+ top-most 4 rows of \a matrix. If \a matrix has less than 4 columns
+ or rows, the remaining elements are filled with elements from the
+ identity matrix.
+
+ \sa qGenericMatrixFromMatrix4x4()
+*/
+
+/*!
+ \fn QGenericMatrix<N, M, qreal, float> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)
+ \relates QMatrix4x4
+
+ Returns a NxM generic matrix constructed from the left-most N columns
+ and top-most M rows of \a matrix. If N or M is greater than 4,
+ then the remaining elements are filled with elements from the
+ identity matrix.
+
+ \sa qGenericMatrixToMatrix4x4(), QMatrix4x4::toGenericMatrix()
+*/
+
+/*!
+ \internal
+*/
+QMatrix4x4::QMatrix4x4(const float *values, int cols, int rows)
+{
+ for (int col = 0; col < 4; ++col) {
+ for (int row = 0; row < 4; ++row) {
+ if (col < cols && row < rows)
+ m[col][row] = values[col * rows + row];
+ else if (col == row)
+ m[col][row] = 1.0f;
+ else
+ m[col][row] = 0.0f;
+ }
+ }
+ flagBits = General;
+}
+
+/*!
+ Constructs a 4x4 matrix from a conventional Qt 2D affine
+ transformation \a matrix.
+
+ If \a matrix has a special type (identity, translate, scale, etc),
+ the programmer should follow this constructor with a call to
+ inferSpecialType() if they wish QMatrix4x4 to optimize further
+ calls to translate(), scale(), etc.
+
+ \sa toAffine(), inferSpecialType()
+*/
+QMatrix4x4::QMatrix4x4(const QMatrix& matrix)
+{
+ m[0][0] = matrix.m11();
+ m[0][1] = matrix.m12();
+ m[0][2] = 0.0f;
+ m[0][3] = 0.0f;
+ m[1][0] = matrix.m21();
+ m[1][1] = matrix.m22();
+ m[1][2] = 0.0f;
+ m[1][3] = 0.0f;
+ m[2][0] = 0.0f;
+ m[2][1] = 0.0f;
+ m[2][2] = 1.0f;
+ m[2][3] = 0.0f;
+ m[3][0] = matrix.dx();
+ m[3][1] = matrix.dy();
+ m[3][2] = 0.0f;
+ m[3][3] = 1.0f;
+ flagBits = General;
+}
+
+/*!
+ Constructs a 4x4 matrix from the conventional Qt 2D
+ transformation matrix \a transform.
+
+ If \a transform has a special type (identity, translate, scale, etc),
+ the programmer should follow this constructor with a call to
+ inferSpecialType() if they wish QMatrix4x4 to optimize further
+ calls to translate(), scale(), etc.
+
+ \sa toTransform(), inferSpecialType()
+*/
+QMatrix4x4::QMatrix4x4(const QTransform& transform)
+{
+ m[0][0] = transform.m11();
+ m[0][1] = transform.m12();
+ m[0][2] = 0.0f;
+ m[0][3] = transform.m13();
+ m[1][0] = transform.m21();
+ m[1][1] = transform.m22();
+ m[1][2] = 0.0f;
+ m[1][3] = transform.m23();
+ m[2][0] = 0.0f;
+ m[2][1] = 0.0f;
+ m[2][2] = 1.0f;
+ m[2][3] = 0.0f;
+ m[3][0] = transform.dx();
+ m[3][1] = transform.dy();
+ m[3][2] = 0.0f;
+ m[3][3] = transform.m33();
+ flagBits = General;
+}
+
+/*!
+ \fn qreal QMatrix4x4::operator()(int row, int column) const
+
+ Returns the element at position (\a row, \a column) in this matrix.
+
+ \sa column(), row()
+*/
+
+/*!
+ \fn float& QMatrix4x4::operator()(int row, int column)
+
+ Returns a reference to the element at position (\a row, \a column)
+ in this matrix so that the element can be assigned to.
+
+ \sa inferSpecialType(), setColumn(), setRow()
+*/
+
+/*!
+ \fn QVector4D QMatrix4x4::column(int index) const
+
+ Returns the elements of column \a index as a 4D vector.
+
+ \sa setColumn(), row()
+*/
+
+/*!
+ \fn void QMatrix4x4::setColumn(int index, const QVector4D& value)
+
+ Sets the elements of column \a index to the components of \a value.
+
+ \sa column(), setRow()
+*/
+
+/*!
+ \fn QVector4D QMatrix4x4::row(int index) const
+
+ Returns the elements of row \a index as a 4D vector.
+
+ \sa setRow(), column()
+*/
+
+/*!
+ \fn void QMatrix4x4::setRow(int index, const QVector4D& value)
+
+ Sets the elements of row \a index to the components of \a value.
+
+ \sa row(), setColumn()
+*/
+
+/*!
+ \fn bool QMatrix4x4::isIdentity() const
+
+ Returns true if this matrix is the identity; false otherwise.
+
+ \sa setIdentity()
+*/
+
+/*!
+ \fn void QMatrix4x4::setIdentity()
+
+ Sets this matrix to the identity.
+
+ \sa isIdentity()
+*/
+
+/*!
+ \fn void QMatrix4x4::fill(qreal value)
+
+ Fills all elements of this matrx with \a value.
+*/
+
+// The 4x4 matrix inverse algorithm is based on that described at:
+// http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q24
+// Some optimization has been done to avoid making copies of 3x3
+// sub-matrices, to do calculations in fixed-point where required,
+// and to unroll the loops.
+
+// Calculate the determinant of a 3x3 sub-matrix.
+// | A B C |
+// M = | D E F | det(M) = A * (EI - HF) - B * (DI - GF) + C * (DH - GE)
+// | G H I |
+static inline float matrixDet3
+ (const float m[4][4], int col0, int col1, int col2,
+ int row0, int row1, int row2)
+{
+ return m[col0][row0] *
+ (m[col1][row1] * m[col2][row2] -
+ m[col1][row2] * m[col2][row1]) -
+ m[col1][row0] *
+ (m[col0][row1] * m[col2][row2] -
+ m[col0][row2] * m[col2][row1]) +
+ m[col2][row0] *
+ (m[col0][row1] * m[col1][row2] -
+ m[col0][row2] * m[col1][row1]);
+}
+
+// Calculate the determinant of a 4x4 matrix.
+static inline float matrixDet4(const float m[4][4])
+{
+ float det;
+ det = m[0][0] * matrixDet3(m, 1, 2, 3, 1, 2, 3);
+ det -= m[1][0] * matrixDet3(m, 0, 2, 3, 1, 2, 3);
+ det += m[2][0] * matrixDet3(m, 0, 1, 3, 1, 2, 3);
+ det -= m[3][0] * matrixDet3(m, 0, 1, 2, 1, 2, 3);
+ return det;
+}
+
+/*!
+ Returns the determinant of this matrix.
+*/
+qreal QMatrix4x4::determinant() const
+{
+ return qreal(matrixDet4(m));
+}
+
+/*!
+ Returns the inverse of this matrix. Returns the identity if
+ this matrix cannot be inverted; i.e. determinant() is zero.
+ If \a invertible is not null, then true will be written to
+ that location if the matrix can be inverted; false otherwise.
+
+ If the matrix is recognized as the identity or an orthonormal
+ matrix, then this function will quickly invert the matrix
+ using optimized routines.
+
+ \sa determinant(), normalMatrix()
+*/
+QMatrix4x4 QMatrix4x4::inverted(bool *invertible) const
+{
+ // Handle some of the easy cases first.
+ if (flagBits == Identity) {
+ if (invertible)
+ *invertible = true;
+ return QMatrix4x4();
+ } else if (flagBits == Translation) {
+ QMatrix4x4 inv;
+ inv.m[3][0] = -m[3][0];
+ inv.m[3][1] = -m[3][1];
+ inv.m[3][2] = -m[3][2];
+ inv.flagBits = Translation;
+ if (invertible)
+ *invertible = true;
+ return inv;
+ } else if (flagBits == Rotation || flagBits == (Rotation | Translation)) {
+ if (invertible)
+ *invertible = true;
+ return orthonormalInverse();
+ }
+
+ QMatrix4x4 inv(1); // The "1" says to not load the identity.
+
+ float det = matrixDet4(m);
+ if (det == 0.0f) {
+ if (invertible)
+ *invertible = false;
+ return QMatrix4x4();
+ }
+ det = 1.0f / det;
+
+ inv.m[0][0] = matrixDet3(m, 1, 2, 3, 1, 2, 3) * det;
+ inv.m[0][1] = -matrixDet3(m, 0, 2, 3, 1, 2, 3) * det;
+ inv.m[0][2] = matrixDet3(m, 0, 1, 3, 1, 2, 3) * det;
+ inv.m[0][3] = -matrixDet3(m, 0, 1, 2, 1, 2, 3) * det;
+ inv.m[1][0] = -matrixDet3(m, 1, 2, 3, 0, 2, 3) * det;
+ inv.m[1][1] = matrixDet3(m, 0, 2, 3, 0, 2, 3) * det;
+ inv.m[1][2] = -matrixDet3(m, 0, 1, 3, 0, 2, 3) * det;
+ inv.m[1][3] = matrixDet3(m, 0, 1, 2, 0, 2, 3) * det;
+ inv.m[2][0] = matrixDet3(m, 1, 2, 3, 0, 1, 3) * det;
+ inv.m[2][1] = -matrixDet3(m, 0, 2, 3, 0, 1, 3) * det;
+ inv.m[2][2] = matrixDet3(m, 0, 1, 3, 0, 1, 3) * det;
+ inv.m[2][3] = -matrixDet3(m, 0, 1, 2, 0, 1, 3) * det;
+ inv.m[3][0] = -matrixDet3(m, 1, 2, 3, 0, 1, 2) * det;
+ inv.m[3][1] = matrixDet3(m, 0, 2, 3, 0, 1, 2) * det;
+ inv.m[3][2] = -matrixDet3(m, 0, 1, 3, 0, 1, 2) * det;
+ inv.m[3][3] = matrixDet3(m, 0, 1, 2, 0, 1, 2) * det;
+
+ if (invertible)
+ *invertible = true;
+ return inv;
+}
+
+/*!
+ Returns the normal matrix corresponding to this 4x4 transformation.
+ The normal matrix is the transpose of the inverse of the top-left
+ 3x3 part of this 4x4 matrix. If the 3x3 sub-matrix is not invertible,
+ this function returns the identity.
+
+ \sa inverted()
+*/
+QMatrix3x3 QMatrix4x4::normalMatrix() const
+{
+ QMatrix3x3 inv;
+
+ // Handle the simple cases first.
+ if (flagBits == Identity || flagBits == Translation) {
+ return inv;
+ } else if (flagBits == Scale || flagBits == (Translation | Scale)) {
+ if (m[0][0] == 0.0f || m[1][1] == 0.0f || m[2][2] == 0.0f)
+ return inv;
+ inv.data()[0] = 1.0f / m[0][0];
+ inv.data()[4] = 1.0f / m[1][1];
+ inv.data()[8] = 1.0f / m[2][2];
+ return inv;
+ }
+
+ float det = matrixDet3(m, 0, 1, 2, 0, 1, 2);
+ if (det == 0.0f)
+ return inv;
+ det = 1.0f / det;
+
+ float *invm = inv.data();
+
+ // Invert and transpose in a single step.
+ invm[0 + 0 * 3] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * det;
+ invm[1 + 0 * 3] = -(m[1][0] * m[2][2] - m[1][2] * m[2][0]) * det;
+ invm[2 + 0 * 3] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) * det;
+ invm[0 + 1 * 3] = -(m[0][1] * m[2][2] - m[2][1] * m[0][2]) * det;
+ invm[1 + 1 * 3] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * det;
+ invm[2 + 1 * 3] = -(m[0][0] * m[2][1] - m[0][1] * m[2][0]) * det;
+ invm[0 + 2 * 3] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * det;
+ invm[1 + 2 * 3] = -(m[0][0] * m[1][2] - m[0][2] * m[1][0]) * det;
+ invm[2 + 2 * 3] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * det;
+
+ return inv;
+}
+
+/*!
+ Returns this matrix, transposed about its diagonal.
+*/
+QMatrix4x4 QMatrix4x4::transposed() const
+{
+ QMatrix4x4 result(1); // The "1" says to not load the identity.
+ for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col) {
+ result.m[col][row] = m[row][col];
+ }
+ }
+ return result;
+}
+
+/*!
+ \fn QMatrix4x4& QMatrix4x4::operator+=(const QMatrix4x4& other)
+
+ Adds the contents of \a other to this matrix.
+*/
+
+/*!
+ \fn QMatrix4x4& QMatrix4x4::operator-=(const QMatrix4x4& other)
+
+ Subtracts the contents of \a other from this matrix.
+*/
+
+/*!
+ \fn QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other)
+
+ Multiplies the contents of \a other by this matrix.
+*/
+
+/*!
+ \fn QMatrix4x4& QMatrix4x4::operator*=(qreal factor)
+ \overload
+
+ Multiplies all elements of this matrix by \a factor.
+*/
+
+/*!
+ \overload
+
+ Divides all elements of this matrix by \a divisor.
+*/
+QMatrix4x4& QMatrix4x4::operator/=(qreal divisor)
+{
+ m[0][0] /= divisor;
+ m[0][1] /= divisor;
+ m[0][2] /= divisor;
+ m[0][3] /= divisor;
+ m[1][0] /= divisor;
+ m[1][1] /= divisor;
+ m[1][2] /= divisor;
+ m[1][3] /= divisor;
+ m[2][0] /= divisor;
+ m[2][1] /= divisor;
+ m[2][2] /= divisor;
+ m[2][3] /= divisor;
+ m[3][0] /= divisor;
+ m[3][1] /= divisor;
+ m[3][2] /= divisor;
+ m[3][3] /= divisor;
+ flagBits = General;
+ return *this;
+}
+
+/*!
+ \fn bool QMatrix4x4::operator==(const QMatrix4x4& other) const
+
+ Returns true if this matrix is identical to \a other; false otherwise.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool QMatrix4x4::operator!=(const QMatrix4x4& other) const
+
+ Returns true if this matrix is not identical to \a other; false otherwise.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)
+ \relates QMatrix4x4
+
+ Returns the sum of \a m1 and \a m2.
+*/
+
+/*!
+ \fn QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)
+ \relates QMatrix4x4
+
+ Returns the difference of \a m1 and \a m2.
+*/
+
+/*!
+ \fn QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
+ \relates QMatrix4x4
+
+ Returns the product of \a m1 and \a m2.
+*/
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \fn QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a vector according to \a matrix,
+ with the matrix applied post-vector.
+*/
+
+/*!
+ \fn QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a vector according to \a matrix,
+ with the matrix applied pre-vector.
+*/
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \fn QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a vector according to \a matrix,
+ with the matrix applied post-vector.
+*/
+
+/*!
+ \fn QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a vector according to \a matrix,
+ with the matrix applied pre-vector.
+*/
+
+#endif
+
+/*!
+ \fn QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a point according to \a matrix,
+ with the matrix applied post-point.
+*/
+
+/*!
+ \fn QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a point according to \a matrix,
+ with the matrix applied post-point.
+*/
+
+/*!
+ \fn QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a point according to \a matrix,
+ with the matrix applied pre-point.
+*/
+
+/*!
+ \fn QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
+ \relates QMatrix4x4
+
+ Returns the result of transforming \a point according to \a matrix,
+ with the matrix applied pre-point.
+*/
+
+/*!
+ \fn QMatrix4x4 operator-(const QMatrix4x4& matrix)
+ \overload
+ \relates QMatrix4x4
+
+ Returns the negation of \a matrix.
+*/
+
+/*!
+ \fn QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix)
+ \relates QMatrix4x4
+
+ Returns the result of multiplying all elements of \a matrix by \a factor.
+*/
+
+/*!
+ \fn QMatrix4x4 operator*(const QMatrix4x4& matrix, qreal factor)
+ \relates QMatrix4x4
+
+ Returns the result of multiplying all elements of \a matrix by \a factor.
+*/
+
+/*!
+ \relates QMatrix4x4
+
+ Returns the result of dividing all elements of \a matrix by \a divisor.
+*/
+QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor)
+{
+ QMatrix4x4 m(1); // The "1" says to not load the identity.
+ m.m[0][0] = matrix.m[0][0] / divisor;
+ m.m[0][1] = matrix.m[0][1] / divisor;
+ m.m[0][2] = matrix.m[0][2] / divisor;
+ m.m[0][3] = matrix.m[0][3] / divisor;
+ m.m[1][0] = matrix.m[1][0] / divisor;
+ m.m[1][1] = matrix.m[1][1] / divisor;
+ m.m[1][2] = matrix.m[1][2] / divisor;
+ m.m[1][3] = matrix.m[1][3] / divisor;
+ m.m[2][0] = matrix.m[2][0] / divisor;
+ m.m[2][1] = matrix.m[2][1] / divisor;
+ m.m[2][2] = matrix.m[2][2] / divisor;
+ m.m[2][3] = matrix.m[2][3] / divisor;
+ m.m[3][0] = matrix.m[3][0] / divisor;
+ m.m[3][1] = matrix.m[3][1] / divisor;
+ m.m[3][2] = matrix.m[3][2] / divisor;
+ m.m[3][3] = matrix.m[3][3] / divisor;
+ return m;
+}
+
+/*!
+ \fn bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2)
+ \relates QMatrix4x4
+
+ Returns true if \a m1 and \a m2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Multiplies this matrix by another that scales coordinates by
+ the components of \a vector. Returns this matrix.
+
+ \sa translate(), rotate()
+*/
+QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector)
+{
+ float vx = vector.xp;
+ float vy = vector.yp;
+ float vz = vector.zp;
+ if (flagBits == Identity) {
+ m[0][0] = vx;
+ m[1][1] = vy;
+ m[2][2] = vz;
+ flagBits = Scale;
+ } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
+ m[0][0] *= vx;
+ m[1][1] *= vy;
+ m[2][2] *= vz;
+ } else if (flagBits == Translation) {
+ m[0][0] = vx;
+ m[1][1] = vy;
+ m[2][2] = vz;
+ flagBits |= Scale;
+ } else {
+ m[0][0] *= vx;
+ m[0][1] *= vx;
+ m[0][2] *= vx;
+ m[0][3] *= vx;
+ m[1][0] *= vy;
+ m[1][1] *= vy;
+ m[1][2] *= vy;
+ m[1][3] *= vy;
+ m[2][0] *= vz;
+ m[2][1] *= vz;
+ m[2][2] *= vz;
+ m[2][3] *= vz;
+ flagBits = General;
+ }
+ return *this;
+}
+#endif
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that scales coordinates by the
+ components \a x, \a y, and \a z. Returns this matrix.
+
+ \sa translate(), rotate()
+*/
+QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y, qreal z)
+{
+ float vx(x);
+ float vy(y);
+ float vz(z);
+ if (flagBits == Identity) {
+ m[0][0] = vx;
+ m[1][1] = vy;
+ m[2][2] = vz;
+ flagBits = Scale;
+ } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
+ m[0][0] *= vx;
+ m[1][1] *= vy;
+ m[2][2] *= vz;
+ } else if (flagBits == Translation) {
+ m[0][0] = vx;
+ m[1][1] = vy;
+ m[2][2] = vz;
+ flagBits |= Scale;
+ } else {
+ m[0][0] *= vx;
+ m[0][1] *= vx;
+ m[0][2] *= vx;
+ m[0][3] *= vx;
+ m[1][0] *= vy;
+ m[1][1] *= vy;
+ m[1][2] *= vy;
+ m[1][3] *= vy;
+ m[2][0] *= vz;
+ m[2][1] *= vz;
+ m[2][2] *= vz;
+ m[2][3] *= vz;
+ flagBits = General;
+ }
+ return *this;
+}
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that scales coordinates by the
+ given \a factor. Returns this matrix.
+
+ \sa translate(), rotate()
+*/
+QMatrix4x4& QMatrix4x4::scale(qreal factor)
+{
+ if (flagBits == Identity) {
+ m[0][0] = factor;
+ m[1][1] = factor;
+ m[2][2] = factor;
+ flagBits = Scale;
+ } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
+ m[0][0] *= factor;
+ m[1][1] *= factor;
+ m[2][2] *= factor;
+ } else if (flagBits == Translation) {
+ m[0][0] = factor;
+ m[1][1] = factor;
+ m[2][2] = factor;
+ flagBits |= Scale;
+ } else {
+ m[0][0] *= factor;
+ m[0][1] *= factor;
+ m[0][2] *= factor;
+ m[0][3] *= factor;
+ m[1][0] *= factor;
+ m[1][1] *= factor;
+ m[1][2] *= factor;
+ m[1][3] *= factor;
+ m[2][0] *= factor;
+ m[2][1] *= factor;
+ m[2][2] *= factor;
+ m[2][3] *= factor;
+ flagBits = General;
+ }
+ return *this;
+}
+
+#ifndef QT_NO_VECTOR3D
+/*!
+ Multiplies this matrix by another that translates coordinates by
+ the components of \a vector. Returns this matrix.
+
+ \sa scale(), rotate()
+*/
+QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector)
+{
+ float vx = vector.xp;
+ float vy = vector.yp;
+ float vz = vector.zp;
+ if (flagBits == Identity) {
+ m[3][0] = vx;
+ m[3][1] = vy;
+ m[3][2] = vz;
+ flagBits = Translation;
+ } else if (flagBits == Translation) {
+ m[3][0] += vx;
+ m[3][1] += vy;
+ m[3][2] += vz;
+ } else if (flagBits == Scale) {
+ m[3][0] = m[0][0] * vx;
+ m[3][1] = m[1][1] * vy;
+ m[3][2] = m[2][2] * vz;
+ flagBits |= Translation;
+ } else if (flagBits == (Scale | Translation)) {
+ m[3][0] += m[0][0] * vx;
+ m[3][1] += m[1][1] * vy;
+ m[3][2] += m[2][2] * vz;
+ } else {
+ m[3][0] += m[0][0] * vx + m[1][0] * vy + m[2][0] * vz;
+ m[3][1] += m[0][1] * vx + m[1][1] * vy + m[2][1] * vz;
+ m[3][2] += m[0][2] * vx + m[1][2] * vy + m[2][2] * vz;
+ m[3][3] += m[0][3] * vx + m[1][3] * vy + m[2][3] * vz;
+ if (flagBits == Rotation)
+ flagBits |= Translation;
+ else if (flagBits != (Rotation | Translation))
+ flagBits = General;
+ }
+ return *this;
+}
+
+#endif
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that translates coordinates
+ by the components \a x, \a y, and \a z. Returns this matrix.
+
+ \sa scale(), rotate()
+*/
+QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y, qreal z)
+{
+ float vx(x);
+ float vy(y);
+ float vz(z);
+ if (flagBits == Identity) {
+ m[3][0] = vx;
+ m[3][1] = vy;
+ m[3][2] = vz;
+ flagBits = Translation;
+ } else if (flagBits == Translation) {
+ m[3][0] += vx;
+ m[3][1] += vy;
+ m[3][2] += vz;
+ } else if (flagBits == Scale) {
+ m[3][0] = m[0][0] * vx;
+ m[3][1] = m[1][1] * vy;
+ m[3][2] = m[2][2] * vz;
+ flagBits |= Translation;
+ } else if (flagBits == (Scale | Translation)) {
+ m[3][0] += m[0][0] * vx;
+ m[3][1] += m[1][1] * vy;
+ m[3][2] += m[2][2] * vz;
+ } else {
+ m[3][0] += m[0][0] * vx + m[1][0] * vy + m[2][0] * vz;
+ m[3][1] += m[0][1] * vx + m[1][1] * vy + m[2][1] * vz;
+ m[3][2] += m[0][2] * vx + m[1][2] * vy + m[2][2] * vz;
+ m[3][3] += m[0][3] * vx + m[1][3] * vy + m[2][3] * vz;
+ if (flagBits == Rotation)
+ flagBits |= Translation;
+ else if (flagBits != (Rotation | Translation))
+ flagBits = General;
+ }
+ return *this;
+}
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Multiples this matrix by another that rotates coordinates through
+ \a angle degrees about \a vector. Returns this matrix.
+
+ \sa scale(), translate()
+*/
+QMatrix4x4& QMatrix4x4::rotate(qreal angle, const QVector3D& vector)
+{
+ return rotate(angle, vector.x(), vector.y(), vector.z());
+}
+
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that rotates coordinates through
+ \a angle degrees about the vector (\a x, \a y, \a z). Returns this matrix.
+
+ \sa scale(), translate()
+*/
+QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z)
+{
+ QMatrix4x4 m(1); // The "1" says to not load the identity.
+ qreal a = angle * M_PI / 180.0f;
+ qreal c = qCos(a);
+ qreal s = qSin(a);
+ qreal ic;
+ bool quick = false;
+ if (x == 0.0f) {
+ if (y == 0.0f) {
+ if (z != 0.0f) {
+ // Rotate around the Z axis.
+ m.setIdentity();
+ m.m[0][0] = c;
+ m.m[1][1] = c;
+ if (z < 0.0f) {
+ m.m[1][0] = s;
+ m.m[0][1] = -s;
+ } else {
+ m.m[1][0] = -s;
+ m.m[0][1] = s;
+ }
+ m.flagBits = General;
+ quick = true;
+ }
+ } else if (z == 0.0f) {
+ // Rotate around the Y axis.
+ m.setIdentity();
+ m.m[0][0] = c;
+ m.m[2][2] = c;
+ if (y < 0.0f) {
+ m.m[2][0] = -s;
+ m.m[0][2] = s;
+ } else {
+ m.m[2][0] = s;
+ m.m[0][2] = -s;
+ }
+ m.flagBits = General;
+ quick = true;
+ }
+ } else if (y == 0.0f && z == 0.0f) {
+ // Rotate around the X axis.
+ m.setIdentity();
+ m.m[1][1] = c;
+ m.m[2][2] = c;
+ if (x < 0.0f) {
+ m.m[2][1] = s;
+ m.m[1][2] = -s;
+ } else {
+ m.m[2][1] = -s;
+ m.m[1][2] = s;
+ }
+ m.flagBits = General;
+ quick = true;
+ }
+ if (!quick) {
+ qreal len = x * x + y * y + z * z;
+ if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) {
+ len = qSqrt(len);
+ x /= len;
+ y /= len;
+ z /= len;
+ }
+ ic = 1.0f - c;
+ m.m[0][0] = x * x * ic + c;
+ m.m[1][0] = x * y * ic - z * s;
+ m.m[2][0] = x * z * ic + y * s;
+ m.m[3][0] = 0.0f;
+ m.m[0][1] = y * x * ic + z * s;
+ m.m[1][1] = y * y * ic + c;
+ m.m[2][1] = y * z * ic - x * s;
+ m.m[3][1] = 0.0f;
+ m.m[0][2] = x * z * ic - y * s;
+ m.m[1][2] = y * z * ic + x * s;
+ m.m[2][2] = z * z * ic + c;
+ m.m[3][2] = 0.0f;
+ m.m[0][3] = 0.0f;
+ m.m[1][3] = 0.0f;
+ m.m[2][3] = 0.0f;
+ m.m[3][3] = 1.0f;
+ }
+ int flags = flagBits;
+ *this *= m;
+ if (flags != Identity)
+ flagBits = flags | Rotation;
+ else
+ flagBits = Rotation;
+ return *this;
+}
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ Multiples this matrix by another that rotates coordinates according
+ to a specified \a quaternion. The \a quaternion is assumed to have
+ been normalized. Returns this matrix.
+
+ \sa scale(), translate(), QQuaternion
+*/
+QMatrix4x4& QMatrix4x4::rotate(const QQuaternion& quaternion)
+{
+ // Algorithm from:
+ // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54
+ QMatrix4x4 m(1);
+ float xx = quaternion.xp * quaternion.xp;
+ float xy = quaternion.xp * quaternion.yp;
+ float xz = quaternion.xp * quaternion.zp;
+ float xw = quaternion.xp * quaternion.wp;
+ float yy = quaternion.yp * quaternion.yp;
+ float yz = quaternion.yp * quaternion.zp;
+ float yw = quaternion.yp * quaternion.wp;
+ float zz = quaternion.zp * quaternion.zp;
+ float zw = quaternion.zp * quaternion.wp;
+ m.m[0][0] = 1.0f - 2 * (yy + zz);
+ m.m[1][0] = 2 * (xy - zw);
+ m.m[2][0] = 2 * (xz + yw);
+ m.m[3][0] = 0.0f;
+ m.m[0][1] = 2 * (xy + zw);
+ m.m[1][1] = 1.0f - 2 * (xx + zz);
+ m.m[2][1] = 2 * (yz - xw);
+ m.m[3][1] = 0.0f;
+ m.m[0][2] = 2 * (xz - yw);
+ m.m[1][2] = 2 * (yz + xw);
+ m.m[2][2] = 1.0f - 2 * (xx + yy);
+ m.m[3][2] = 0.0f;
+ m.m[0][3] = 0.0f;
+ m.m[1][3] = 0.0f;
+ m.m[2][3] = 0.0f;
+ m.m[3][3] = 1.0f;
+ int flags = flagBits;
+ *this *= m;
+ if (flags != Identity)
+ flagBits = flags | Rotation;
+ else
+ flagBits = Rotation;
+ return *this;
+}
+
+#endif
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that applies an orthographic
+ projection for a window with boundaries specified by \a rect.
+ The near and far clipping planes will be -1 and 1 respectively.
+ Returns this matrix.
+
+ \sa frustum(), perspective()
+*/
+QMatrix4x4& QMatrix4x4::ortho(const QRect& rect)
+{
+ // Note: rect.right() and rect.bottom() subtract 1 in QRect,
+ // which gives the location of a pixel within the rectangle,
+ // instead of the extent of the rectangle. We want the extent.
+ // QRectF expresses the extent properly.
+ return ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), -1.0f, 1.0f);
+}
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that applies an orthographic
+ projection for a window with boundaries specified by \a rect.
+ The near and far clipping planes will be -1 and 1 respectively.
+ Returns this matrix.
+
+ \sa frustum(), perspective()
+*/
+QMatrix4x4& QMatrix4x4::ortho(const QRectF& rect)
+{
+ return ortho(rect.left(), rect.right(), rect.bottom(), rect.top(), -1.0f, 1.0f);
+}
+
+/*!
+ Multiplies this matrix by another that applies an orthographic
+ projection for a window with lower-left corner (\a left, \a bottom),
+ upper-right corner (\a right, \a top), and the specified \a nearPlane
+ and \a farPlane clipping planes. Returns this matrix.
+
+ \sa frustum(), perspective()
+*/
+QMatrix4x4& QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane)
+{
+ // Bail out if the projection volume is zero-sized.
+ if (left == right || bottom == top || nearPlane == farPlane)
+ return *this;
+
+ // Construct the projection.
+ qreal width = right - left;
+ qreal invheight = top - bottom;
+ qreal clip = farPlane - nearPlane;
+#ifndef QT_NO_VECTOR3D
+ if (clip == 2.0f && (nearPlane + farPlane) == 0.0f) {
+ // We can express this projection as a translate and scale
+ // which will be more efficient to modify with further
+ // transformations than producing a "General" matrix.
+ translate(QVector3D
+ (-(left + right) / width,
+ -(top + bottom) / invheight,
+ 0.0f, 1));
+ scale(QVector3D
+ (2.0f / width,
+ 2.0f / invheight,
+ -1.0f, 1));
+ return *this;
+ }
+#endif
+ QMatrix4x4 m(1);
+ m.m[0][0] = 2.0f / width;
+ m.m[1][0] = 0.0f;
+ m.m[2][0] = 0.0f;
+ m.m[3][0] = -(left + right) / width;
+ m.m[0][1] = 0.0f;
+ m.m[1][1] = 2.0f / invheight;
+ m.m[2][1] = 0.0f;
+ m.m[3][1] = -(top + bottom) / invheight;
+ m.m[0][2] = 0.0f;
+ m.m[1][2] = 0.0f;
+ m.m[2][2] = -2.0f / clip;
+ m.m[3][2] = -(nearPlane + farPlane) / clip;
+ m.m[0][3] = 0.0f;
+ m.m[1][3] = 0.0f;
+ m.m[2][3] = 0.0f;
+ m.m[3][3] = 1.0f;
+
+ // Apply the projection.
+ *this *= m;
+ return *this;
+}
+
+/*!
+ Multiplies this matrix by another that applies a perspective
+ frustum projection for a window with lower-left corner (\a left, \a bottom),
+ upper-right corner (\a right, \a top), and the specified \a nearPlane
+ and \a farPlane clipping planes. Returns this matrix.
+
+ \sa ortho(), perspective()
+*/
+QMatrix4x4& QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane)
+{
+ // Bail out if the projection volume is zero-sized.
+ if (left == right || bottom == top || nearPlane == farPlane)
+ return *this;
+
+ // Construct the projection.
+ QMatrix4x4 m(1);
+ qreal width = right - left;
+ qreal invheight = top - bottom;
+ qreal clip = farPlane - nearPlane;
+ m.m[0][0] = 2.0f * nearPlane / width;
+ m.m[1][0] = 0.0f;
+ m.m[2][0] = (left + right) / width;
+ m.m[3][0] = 0.0f;
+ m.m[0][1] = 0.0f;
+ m.m[1][1] = 2.0f * nearPlane / invheight;
+ m.m[2][1] = (top + bottom) / invheight;
+ m.m[3][1] = 0.0f;
+ m.m[0][2] = 0.0f;
+ m.m[1][2] = 0.0f;
+ m.m[2][2] = -(nearPlane + farPlane) / clip;
+ m.m[3][2] = -2.0f * nearPlane * farPlane / clip;
+ m.m[0][3] = 0.0f;
+ m.m[1][3] = 0.0f;
+ m.m[2][3] = -1.0f;
+ m.m[3][3] = 0.0f;
+
+ // Apply the projection.
+ *this *= m;
+ return *this;
+}
+
+/*!
+ Multiplies this matrix by another that applies a perspective
+ projection. The field of view will be \a angle degrees within
+ a window with a given \a aspect ratio. The projection will
+ have the specified \a nearPlane and \a farPlane clipping planes.
+ Returns this matrix.
+
+ \sa ortho(), frustum()
+*/
+QMatrix4x4& QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane)
+{
+ // Bail out if the projection volume is zero-sized.
+ if (nearPlane == farPlane || aspect == 0.0f)
+ return *this;
+
+ // Construct the projection.
+ QMatrix4x4 m(1);
+ qreal radians = (angle / 2.0f) * M_PI / 180.0f;
+ qreal sine = qSin(radians);
+ if (sine == 0.0f)
+ return *this;
+ qreal cotan = qCos(radians) / sine;
+ qreal clip = farPlane - nearPlane;
+ m.m[0][0] = cotan / aspect;
+ m.m[1][0] = 0.0f;
+ m.m[2][0] = 0.0f;
+ m.m[3][0] = 0.0f;
+ m.m[0][1] = 0.0f;
+ m.m[1][1] = cotan;
+ m.m[2][1] = 0.0f;
+ m.m[3][1] = 0.0f;
+ m.m[0][2] = 0.0f;
+ m.m[1][2] = 0.0f;
+ m.m[2][2] = -(nearPlane + farPlane) / clip;
+ m.m[3][2] = -(2.0f * nearPlane * farPlane) / clip;
+ m.m[0][3] = 0.0f;
+ m.m[1][3] = 0.0f;
+ m.m[2][3] = -1.0f;
+ m.m[3][3] = 0.0f;
+
+ // Apply the projection.
+ *this *= m;
+ return *this;
+}
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Multiplies this matrix by another that applies an \a eye position
+ transformation. The \a center value indicates the center of the
+ view that the \a eye is looking at. The \a up value indicates
+ which direction should be considered up with respect to the \a eye.
+ Returns this matrix.
+*/
+QMatrix4x4& QMatrix4x4::lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up)
+{
+ QVector3D forward = (center - eye).normalized();
+ QVector3D side = QVector3D::crossProduct(forward, up).normalized();
+ QVector3D upVector = QVector3D::crossProduct(side, forward);
+
+ QMatrix4x4 m(1);
+
+ m.m[0][0] = side.xp;
+ m.m[1][0] = side.yp;
+ m.m[2][0] = side.zp;
+ m.m[3][0] = 0.0f;
+ m.m[0][1] = upVector.xp;
+ m.m[1][1] = upVector.yp;
+ m.m[2][1] = upVector.zp;
+ m.m[3][1] = 0.0f;
+ m.m[0][2] = -forward.xp;
+ m.m[1][2] = -forward.yp;
+ m.m[2][2] = -forward.zp;
+ m.m[3][2] = 0.0f;
+ m.m[0][3] = 0.0f;
+ m.m[1][3] = 0.0f;
+ m.m[2][3] = 0.0f;
+ m.m[3][3] = 1.0f;
+
+ *this *= m;
+ return translate(-eye);
+}
+
+#endif
+
+/*!
+ Flips between right-handed and left-handed coordinate systems
+ by multiplying the y and z co-ordinates by -1. This is normally
+ used to create a left-handed orthographic view without scaling
+ the viewport as ortho() does. Returns this matrix.
+
+ \sa ortho()
+*/
+QMatrix4x4& QMatrix4x4::flipCoordinates()
+{
+ if (flagBits == Scale || flagBits == (Scale | Translation)) {
+ m[1][1] = -m[1][1];
+ m[2][2] = -m[2][2];
+ } else if (flagBits == Translation) {
+ m[1][1] = -m[1][1];
+ m[2][2] = -m[2][2];
+ flagBits |= Scale;
+ } else if (flagBits == Identity) {
+ m[1][1] = -1.0f;
+ m[2][2] = -1.0f;
+ flagBits = Scale;
+ } else {
+ m[1][0] = -m[1][0];
+ m[1][1] = -m[1][1];
+ m[1][2] = -m[1][2];
+ m[1][3] = -m[1][3];
+ m[2][0] = -m[2][0];
+ m[2][1] = -m[2][1];
+ m[2][2] = -m[2][2];
+ m[2][3] = -m[2][3];
+ flagBits = General;
+ }
+ return *this;
+}
+
+/*!
+ Retrieves the 16 items in this matrix and writes them to \a values
+ in row-major order.
+*/
+void QMatrix4x4::toValueArray(qreal *values) const
+{
+ for (int row = 0; row < 4; ++row)
+ for (int col = 0; col < 4; ++col)
+ values[row * 4 + col] = qreal(m[col][row]);
+}
+
+/*!
+ Returns the conventional Qt 2D affine transformation matrix that
+ corresponds to this matrix. It is assumed that this matrix
+ only contains 2D affine transformation elements.
+
+ \sa toTransform()
+*/
+QMatrix QMatrix4x4::toAffine() const
+{
+ return QMatrix(qreal(m[0][0]), qreal(m[0][1]),
+ qreal(m[1][0]), qreal(m[1][1]),
+ qreal(m[3][0]), qreal(m[3][1]));
+}
+
+/*!
+ Returns the conventional Qt 2D transformation matrix that
+ corresponds to this matrix. It is assumed that this matrix
+ only contains 2D transformation elements.
+
+ \sa toAffine()
+*/
+QTransform QMatrix4x4::toTransform() const
+{
+ return QTransform(qreal(m[0][0]), qreal(m[0][1]), qreal(m[0][3]),
+ qreal(m[1][0]), qreal(m[1][1]), qreal(m[1][3]),
+ qreal(m[3][0]), qreal(m[3][1]), qreal(m[3][3]));
+}
+
+/*!
+ \fn QPoint QMatrix4x4::map(const QPoint& point) const
+
+ Maps \a point by multiplying this matrix by \a point.
+
+ \sa mapRect()
+*/
+
+/*!
+ \fn QPointF QMatrix4x4::map(const QPointF& point) const
+
+ Maps \a point by multiplying this matrix by \a point.
+
+ \sa mapRect()
+*/
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \fn QVector3D QMatrix4x4::map(const QVector3D& point) const
+
+ Maps \a point by multiplying this matrix by \a point.
+
+ \sa mapRect()
+*/
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \fn QVector4D QMatrix4x4::map(const QVector4D& point) const;
+
+ Maps \a point by multiplying this matrix by \a point.
+
+ \sa mapRect()
+*/
+
+#endif
+
+/*!
+ \fn QRect QMatrix4x4::mapRect(const QRect& rect) const
+
+ Maps \a rect by multiplying this matrix by the corners
+ of \a rect and then forming a new rectangle from the results.
+ The returned rectangle will be an ordinary 2D rectangle
+ with sides parallel to the horizontal and vertical axes.
+
+ \sa map()
+*/
+
+/*!
+ \fn QRectF QMatrix4x4::mapRect(const QRectF& rect) const
+
+ Maps \a rect by multiplying this matrix by the corners
+ of \a rect and then forming a new rectangle from the results.
+ The returned rectangle will be an ordinary 2D rectangle
+ with sides parallel to the horizontal and vertical axes.
+
+ \sa map()
+*/
+
+/*!
+ \fn float *QMatrix4x4::data()
+
+ Returns a pointer to the raw data of this matrix. This is intended
+ for use with raw GL functions.
+
+ \sa constData(), inferSpecialType()
+*/
+
+/*!
+ \fn const float *QMatrix4x4::data() const
+
+ Returns a constant pointer to the raw data of this matrix.
+ This is intended for use with raw GL functions.
+
+ \sa constData()
+*/
+
+/*!
+ \fn const float *QMatrix4x4::constData() const
+
+ Returns a constant pointer to the raw data of this matrix.
+ This is intended for use with raw GL functions.
+
+ \sa data()
+*/
+
+// Helper routine for inverting orthonormal matrices that consist
+// of just rotations and translations.
+QMatrix4x4 QMatrix4x4::orthonormalInverse() const
+{
+ QMatrix4x4 result(1); // The '1' says not to load identity
+
+ result.m[0][0] = m[0][0];
+ result.m[1][0] = m[0][1];
+ result.m[2][0] = m[0][2];
+
+ result.m[0][1] = m[1][0];
+ result.m[1][1] = m[1][1];
+ result.m[2][1] = m[1][2];
+
+ result.m[0][2] = m[2][0];
+ result.m[1][2] = m[2][1];
+ result.m[2][2] = m[2][2];
+
+ result.m[0][3] = 0.0f;
+ result.m[1][3] = 0.0f;
+ result.m[2][3] = 0.0f;
+
+ result.m[3][0] = -(result.m[0][0] * m[3][0] + result.m[1][0] * m[3][1] + result.m[2][0] * m[3][2]);
+ result.m[3][1] = -(result.m[0][1] * m[3][0] + result.m[1][1] * m[3][1] + result.m[2][1] * m[3][2]);
+ result.m[3][2] = -(result.m[0][2] * m[3][0] + result.m[1][2] * m[3][1] + result.m[2][2] * m[3][2]);
+ result.m[3][3] = 1.0f;
+
+ return result;
+}
+
+#ifndef QT_NO_VECTOR3D
+/*!
+ Decomposes the current rotation matrix into an \a axis of rotation plus
+ an \a angle. The result can be used to construct an equivalent rotation
+ matrix using glRotate(). It is assumed that the homogenous coordinate
+ is 1.0. The returned vector is guaranteed to be normalized.
+
+ \code
+ qreal angle;
+ QVector3D axis;
+
+ matrix.extractAxisAngle(angle, axis);
+ glRotate(angle, axis[0], axis[1], axis[2]);
+ \endcode
+
+ \sa rotate()
+*/
+void QMatrix4x4::extractAxisRotation(qreal &angle, QVector3D &axis) const
+{
+ // Orientation is dependent on the upper 3x3 matrix; subtract the
+ // homogeneous scaling element from the trace of the 4x4 matrix
+ float tr = m[0][0] + m[1][1] + m[2][2];
+ qreal cosa = qreal(0.5f * (tr - 1.0f));
+ angle = acos(cosa) * 180.0f / M_PI;
+
+ // Any axis will work if r is zero (means no rotation)
+ if (qFuzzyIsNull(angle)) {
+ axis.setX(1.0f);
+ axis.setY(0.0f);
+ axis.setZ(0.0f);
+ return;
+ }
+
+ if (angle < 180.0f) {
+ axis.xp = m[1][2] - m[2][1];
+ axis.yp = m[2][0] - m[0][2];
+ axis.zp = m[0][1] - m[1][0];
+ axis.normalize();
+ return;
+ }
+
+ // rads == PI
+ float tmp;
+
+ // r00 is maximum
+ if ((m[0][0] >= m[2][2]) && (m[0][0] >= m[1][1])) {
+ axis.xp = 0.5f * qSqrt(m[0][0] - m[1][1] - m[2][2] + 1.0f);
+ tmp = 0.5f / axis.x();
+ axis.yp = m[1][0] * tmp;
+ axis.zp = m[2][0] * tmp;
+ }
+
+ // r11 is maximum
+ if ((m[1][1] >= m[2][2]) && (m[1][1] >= m[0][0])) {
+ axis.yp = 0.5f * qSqrt(m[1][1] - m[0][0] - m[2][2] + 1.0f);
+ tmp = 0.5f / axis.y();
+ axis.xp = tmp * m[1][0];
+ axis.zp = tmp * m[2][1];
+ }
+
+ // r22 is maximum
+ if ((m[2][2] >= m[1][1]) && (m[2][2] >= m[0][0])) {
+ axis.zp = 0.5f * qSqrt(m[2][2] - m[0][0] - m[1][1] + 1.0f);
+ tmp = 0.5f / axis.z();
+ axis.xp = m[2][0]*tmp;
+ axis.yp = m[2][1]*tmp;
+ }
+}
+
+/*!
+ If this is an orthonormal transformation matrix (e.g. only rotations and
+ translations have been applied to the matrix, no scaling, or shearing)
+ then the world translational component can be obtained by calling this function.
+
+ This is most useful for camera matrices, where the negation of this vector
+ is effectively the camera world coordinates.
+*/
+QVector3D QMatrix4x4::extractTranslation() const
+{
+ return QVector3D
+ (m[0][0] * m[3][0] + m[0][1] * m[3][1] + m[0][2] * m[3][2],
+ m[1][0] * m[3][0] + m[1][1] * m[3][1] + m[1][2] * m[3][2],
+ m[2][0] * m[3][0] + m[2][1] * m[3][1] + m[2][2] * m[3][2], 1);
+}
+#endif
+
+/*!
+ Infers the special type of this matrix from its current elements.
+
+ Some operations such as translate(), scale(), and rotate() can be
+ performed more efficiently if the matrix being modified is already
+ known to be the identity, a previous translate(), a previous
+ scale(), etc.
+
+ Normally the QMatrix4x4 class keeps track of this special type internally
+ as operations are performed. However, if the matrix is modified
+ directly with operator()() or data(), then QMatrix4x4 will lose track of
+ the special type and will revert to the safest but least efficient
+ operations thereafter.
+
+ By calling inferSpecialType() after directly modifying the matrix,
+ the programmer can force QMatrix4x4 to recover the special type if
+ the elements appear to conform to one of the known optimized types.
+
+ \sa operator()(), data(), translate()
+*/
+void QMatrix4x4::inferSpecialType()
+{
+ // If the last element is not 1, then it can never be special.
+ if (m[3][3] != 1.0f) {
+ flagBits = General;
+ return;
+ }
+
+ // If the upper three elements m12, m13, and m21 are not all zero,
+ // or the lower elements below the diagonal are not all zero, then
+ // the matrix can never be special.
+ if (m[1][0] != 0.0f || m[2][0] != 0.0f || m[2][1] != 0.0f) {
+ flagBits = General;
+ return;
+ }
+ if (m[0][1] != 0.0f || m[0][2] != 0.0f || m[0][3] != 0.0f ||
+ m[1][2] != 0.0f || m[1][3] != 0.0f || m[2][3] != 0.0f) {
+ flagBits = General;
+ return;
+ }
+
+ // Determine what we have in the remaining regions of the matrix.
+ bool identityAlongDiagonal
+ = (m[0][0] == 1.0f && m[1][1] == 1.0f && m[2][2] == 1.0f);
+ bool translationPresent
+ = (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f);
+
+ // Now determine the special matrix type.
+ if (translationPresent && identityAlongDiagonal)
+ flagBits = Translation;
+ else if (translationPresent)
+ flagBits = (Translation | Scale);
+ else if (identityAlongDiagonal)
+ flagBits = Identity;
+ else
+ flagBits = Scale;
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, const QMatrix4x4 &m)
+{
+ // Create a string that represents the matrix type.
+ QByteArray bits;
+ if ((m.flagBits & QMatrix4x4::Identity) != 0)
+ bits += "Identity,";
+ if ((m.flagBits & QMatrix4x4::General) != 0)
+ bits += "General,";
+ if ((m.flagBits & QMatrix4x4::Translation) != 0)
+ bits += "Translation,";
+ if ((m.flagBits & QMatrix4x4::Scale) != 0)
+ bits += "Scale,";
+ if ((m.flagBits & QMatrix4x4::Rotation) != 0)
+ bits += "Rotation,";
+ if (bits.size() > 0)
+ bits = bits.left(bits.size() - 1);
+
+ // Output in row-major order because it is more human-readable.
+ dbg.nospace() << "QMatrix4x4(type:" << bits.constData() << endl
+ << qSetFieldWidth(10)
+ << m(0, 0) << m(0, 1) << m(0, 2) << m(0, 3) << endl
+ << m(1, 0) << m(1, 1) << m(1, 2) << m(1, 3) << endl
+ << m(2, 0) << m(2, 1) << m(2, 2) << m(2, 3) << endl
+ << m(3, 0) << m(3, 1) << m(3, 2) << m(3, 3) << endl
+ << qSetFieldWidth(0) << ')';
+ return dbg.space();
+}
+
+#endif
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
new file mode 100644
index 0000000..2b485c1
--- /dev/null
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -0,0 +1,977 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMATRIX4X4_H
+#define QMATRIX4X4_H
+
+#include <QtGui/qvector3d.h>
+#include <QtGui/qvector4d.h>
+#include <QtGui/qquaternion.h>
+#include <QtGui/qgenericmatrix.h>
+#include <QtCore/qrect.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_MATRIX4X4
+
+class QMatrix;
+class QTransform;
+
+class Q_GUI_EXPORT QMatrix4x4
+{
+public:
+ inline QMatrix4x4() { setIdentity(); }
+ explicit QMatrix4x4(const qreal *values);
+ inline QMatrix4x4(qreal m11, qreal m12, qreal m13, qreal m14,
+ qreal m21, qreal m22, qreal m23, qreal m24,
+ qreal m31, qreal m32, qreal m33, qreal m34,
+ qreal m41, qreal m42, qreal m43, qreal m44);
+#if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC)
+ template <int N, int M>
+ explicit QMatrix4x4(const QGenericMatrix<N, M, qreal, float>& matrix);
+#endif
+ QMatrix4x4(const float *values, int cols, int rows);
+ QMatrix4x4(const QTransform& transform);
+ QMatrix4x4(const QMatrix& matrix);
+
+ inline qreal operator()(int row, int column) const;
+ inline float& operator()(int row, int column);
+
+ inline QVector4D column(int index) const;
+ inline void setColumn(int index, const QVector4D& value);
+
+ inline QVector4D row(int index) const;
+ inline void setRow(int index, const QVector4D& value);
+
+ inline bool isIdentity() const;
+ inline void setIdentity();
+
+ inline void fill(qreal value);
+
+ qreal determinant() const;
+ QMatrix4x4 inverted(bool *invertible = 0) const;
+ QMatrix4x4 transposed() const;
+ QMatrix3x3 normalMatrix() const;
+
+ inline QMatrix4x4& operator+=(const QMatrix4x4& other);
+ inline QMatrix4x4& operator-=(const QMatrix4x4& other);
+ inline QMatrix4x4& operator*=(const QMatrix4x4& other);
+ inline QMatrix4x4& operator*=(qreal factor);
+ QMatrix4x4& operator/=(qreal divisor);
+ inline bool operator==(const QMatrix4x4& other) const;
+ inline bool operator!=(const QMatrix4x4& other) const;
+
+ friend QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2);
+ friend QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2);
+ friend QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2);
+#ifndef QT_NO_VECTOR3D
+ friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
+ friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
+#endif
+#ifndef QT_NO_VECTOR4D
+ friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
+ friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
+#endif
+ friend QPoint operator*(const QPoint& point, const QMatrix4x4& matrix);
+ friend QPointF operator*(const QPointF& point, const QMatrix4x4& matrix);
+ friend QMatrix4x4 operator-(const QMatrix4x4& matrix);
+ friend QPoint operator*(const QMatrix4x4& matrix, const QPoint& point);
+ friend QPointF operator*(const QMatrix4x4& matrix, const QPointF& point);
+ friend QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix);
+ friend QMatrix4x4 operator*(const QMatrix4x4& matrix, qreal factor);
+ friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor);
+
+ friend inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2);
+
+#ifndef QT_NO_VECTOR3D
+ QMatrix4x4& scale(const QVector3D& vector);
+ QMatrix4x4& translate(const QVector3D& vector);
+ QMatrix4x4& rotate(qreal angle, const QVector3D& vector);
+#endif
+ QMatrix4x4& scale(qreal x, qreal y, qreal z = 1.0f);
+ QMatrix4x4& scale(qreal factor);
+ QMatrix4x4& translate(qreal x, qreal y, qreal z = 0.0f);
+ QMatrix4x4& rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f);
+#ifndef QT_NO_QUATERNION
+ QMatrix4x4& rotate(const QQuaternion& quaternion);
+#endif
+
+#ifndef QT_NO_VECTOR3D
+ void extractAxisRotation(qreal &angle, QVector3D &axis) const;
+ QVector3D extractTranslation() const;
+#endif
+
+ QMatrix4x4& ortho(const QRect& rect);
+ QMatrix4x4& ortho(const QRectF& rect);
+ QMatrix4x4& ortho(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
+ QMatrix4x4& frustum(qreal left, qreal right, qreal bottom, qreal top, qreal nearPlane, qreal farPlane);
+ QMatrix4x4& perspective(qreal angle, qreal aspect, qreal nearPlane, qreal farPlane);
+#ifndef QT_NO_VECTOR3D
+ QMatrix4x4& lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up);
+#endif
+ QMatrix4x4& flipCoordinates();
+
+ void toValueArray(qreal *values) const;
+
+ QMatrix toAffine() const;
+ QTransform toTransform() const;
+
+ QPoint map(const QPoint& point) const;
+ QPointF map(const QPointF& point) const;
+#ifndef QT_NO_VECTOR3D
+ QVector3D map(const QVector3D& point) const;
+#endif
+#ifndef QT_NO_VECTOR4D
+ QVector4D map(const QVector4D& point) const;
+#endif
+ QRect mapRect(const QRect& rect) const;
+ QRectF mapRect(const QRectF& rect) const;
+
+#if !defined(QT_NO_MEMBER_TEMPLATES) || defined(Q_QDOC)
+ template <int N, int M>
+ QGenericMatrix<N, M, qreal, float> toGenericMatrix() const;
+#endif
+
+ inline float *data();
+ inline const float *data() const { return m[0]; }
+ inline const float *constData() const { return m[0]; }
+
+ void inferSpecialType();
+
+#ifndef QT_NO_DEBUG_STREAM
+ friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
+#endif
+
+private:
+ float m[4][4]; // Column-major order to match OpenGL.
+ int flagBits; // Flag bits from the enum below.
+
+ enum {
+ Identity = 0x0001, // Identity matrix
+ General = 0x0002, // General matrix, unknown contents
+ Translation = 0x0004, // Contains a simple translation
+ Scale = 0x0008, // Contains a simple scale
+ Rotation = 0x0010 // Contains a simple rotation
+ };
+
+ // Construct without initializing identity matrix.
+ QMatrix4x4(int) { flagBits = General; }
+
+ QMatrix4x4 orthonormalInverse() const;
+};
+
+inline QMatrix4x4::QMatrix4x4
+ (qreal m11, qreal m12, qreal m13, qreal m14,
+ qreal m21, qreal m22, qreal m23, qreal m24,
+ qreal m31, qreal m32, qreal m33, qreal m34,
+ qreal m41, qreal m42, qreal m43, qreal m44)
+{
+ m[0][0] = m11; m[0][1] = m21; m[0][2] = m31; m[0][3] = m41;
+ m[1][0] = m12; m[1][1] = m22; m[1][2] = m32; m[1][3] = m42;
+ m[2][0] = m13; m[2][1] = m23; m[2][2] = m33; m[2][3] = m43;
+ m[3][0] = m14; m[3][1] = m24; m[3][2] = m34; m[3][3] = m44;
+ flagBits = General;
+}
+
+#if !defined(QT_NO_MEMBER_TEMPLATES)
+
+template <int N, int M>
+Q_INLINE_TEMPLATE QMatrix4x4::QMatrix4x4
+ (const QGenericMatrix<N, M, qreal, float>& matrix)
+{
+ const float *values = matrix.constData();
+ for (int col = 0; col < 4; ++col) {
+ for (int row = 0; row < 4; ++row) {
+ if (col < N && row < M)
+ m[col][row] = values[col * M + row];
+ else if (col == row)
+ m[col][row] = 1.0f;
+ else
+ m[col][row] = 0.0f;
+ }
+ }
+ flagBits = General;
+}
+
+template <int N, int M>
+QGenericMatrix<N, M, qreal, float> QMatrix4x4::toGenericMatrix() const
+{
+ QGenericMatrix<N, M, qreal, float> result;
+ float *values = result.data();
+ for (int col = 0; col < N; ++col) {
+ for (int row = 0; row < M; ++row) {
+ if (col < 4 && row < 4)
+ values[col * M + row] = m[col][row];
+ else if (col == row)
+ values[col * M + row] = 1.0f;
+ else
+ values[col * M + row] = 0.0f;
+ }
+ }
+ return result;
+}
+
+#endif
+
+inline qreal QMatrix4x4::operator()(int row, int column) const
+{
+ Q_ASSERT(row >= 0 && row < 4 && column >= 0 && column < 4);
+ return qreal(m[column][row]);
+}
+
+inline float& QMatrix4x4::operator()(int row, int column)
+{
+ Q_ASSERT(row >= 0 && row < 4 && column >= 0 && column < 4);
+ flagBits = General;
+ return m[column][row];
+}
+
+inline QVector4D QMatrix4x4::column(int index) const
+{
+ Q_ASSERT(index >= 0 && index < 4);
+ return QVector4D(m[index][0], m[index][1], m[index][2], m[index][3], 1);
+}
+
+inline void QMatrix4x4::setColumn(int index, const QVector4D& value)
+{
+ Q_ASSERT(index >= 0 && index < 4);
+ m[index][0] = value.xp;
+ m[index][1] = value.yp;
+ m[index][2] = value.zp;
+ m[index][3] = value.wp;
+ flagBits = General;
+}
+
+inline QVector4D QMatrix4x4::row(int index) const
+{
+ Q_ASSERT(index >= 0 && index < 4);
+ return QVector4D(m[0][index], m[1][index], m[2][index], m[3][index], 1);
+}
+
+inline void QMatrix4x4::setRow(int index, const QVector4D& value)
+{
+ Q_ASSERT(index >= 0 && index < 4);
+ m[0][index] = value.xp;
+ m[1][index] = value.yp;
+ m[2][index] = value.zp;
+ m[3][index] = value.wp;
+ flagBits = General;
+}
+
+Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor);
+
+inline bool QMatrix4x4::isIdentity() const
+{
+ if (flagBits == Identity)
+ return true;
+ if (m[0][0] != 1.0f || m[0][1] != 0.0f || m[0][2] != 0.0f)
+ return false;
+ if (m[0][3] != 0.0f || m[1][0] != 0.0f || m[1][1] != 1.0f)
+ return false;
+ if (m[1][2] != 0.0f || m[1][3] != 0.0f || m[2][0] != 0.0f)
+ return false;
+ if (m[2][1] != 0.0f || m[2][2] != 1.0f || m[2][3] != 0.0f)
+ return false;
+ if (m[3][0] != 0.0f || m[3][1] != 0.0f || m[3][2] != 0.0f)
+ return false;
+ return (m[3][3] == 1.0f);
+}
+
+inline void QMatrix4x4::setIdentity()
+{
+ m[0][0] = 1.0f;
+ m[0][1] = 0.0f;
+ m[0][2] = 0.0f;
+ m[0][3] = 0.0f;
+ m[1][0] = 0.0f;
+ m[1][1] = 1.0f;
+ m[1][2] = 0.0f;
+ m[1][3] = 0.0f;
+ m[2][0] = 0.0f;
+ m[2][1] = 0.0f;
+ m[2][2] = 1.0f;
+ m[2][3] = 0.0f;
+ m[3][0] = 0.0f;
+ m[3][1] = 0.0f;
+ m[3][2] = 0.0f;
+ m[3][3] = 1.0f;
+ flagBits = Identity;
+}
+
+inline void QMatrix4x4::fill(qreal value)
+{
+ m[0][0] = value;
+ m[0][1] = value;
+ m[0][2] = value;
+ m[0][3] = value;
+ m[1][0] = value;
+ m[1][1] = value;
+ m[1][2] = value;
+ m[1][3] = value;
+ m[2][0] = value;
+ m[2][1] = value;
+ m[2][2] = value;
+ m[2][3] = value;
+ m[3][0] = value;
+ m[3][1] = value;
+ m[3][2] = value;
+ m[3][3] = value;
+ flagBits = General;
+}
+
+inline QMatrix4x4& QMatrix4x4::operator+=(const QMatrix4x4& other)
+{
+ m[0][0] += other.m[0][0];
+ m[0][1] += other.m[0][1];
+ m[0][2] += other.m[0][2];
+ m[0][3] += other.m[0][3];
+ m[1][0] += other.m[1][0];
+ m[1][1] += other.m[1][1];
+ m[1][2] += other.m[1][2];
+ m[1][3] += other.m[1][3];
+ m[2][0] += other.m[2][0];
+ m[2][1] += other.m[2][1];
+ m[2][2] += other.m[2][2];
+ m[2][3] += other.m[2][3];
+ m[3][0] += other.m[3][0];
+ m[3][1] += other.m[3][1];
+ m[3][2] += other.m[3][2];
+ m[3][3] += other.m[3][3];
+ flagBits = General;
+ return *this;
+}
+
+inline QMatrix4x4& QMatrix4x4::operator-=(const QMatrix4x4& other)
+{
+ m[0][0] -= other.m[0][0];
+ m[0][1] -= other.m[0][1];
+ m[0][2] -= other.m[0][2];
+ m[0][3] -= other.m[0][3];
+ m[1][0] -= other.m[1][0];
+ m[1][1] -= other.m[1][1];
+ m[1][2] -= other.m[1][2];
+ m[1][3] -= other.m[1][3];
+ m[2][0] -= other.m[2][0];
+ m[2][1] -= other.m[2][1];
+ m[2][2] -= other.m[2][2];
+ m[2][3] -= other.m[2][3];
+ m[3][0] -= other.m[3][0];
+ m[3][1] -= other.m[3][1];
+ m[3][2] -= other.m[3][2];
+ m[3][3] -= other.m[3][3];
+ flagBits = General;
+ return *this;
+}
+
+inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other)
+{
+ if (flagBits == Identity) {
+ *this = other;
+ return *this;
+ } else if (other.flagBits == Identity) {
+ return *this;
+ } else {
+ *this = *this * other;
+ return *this;
+ }
+}
+
+inline QMatrix4x4& QMatrix4x4::operator*=(qreal factor)
+{
+ m[0][0] *= factor;
+ m[0][1] *= factor;
+ m[0][2] *= factor;
+ m[0][3] *= factor;
+ m[1][0] *= factor;
+ m[1][1] *= factor;
+ m[1][2] *= factor;
+ m[1][3] *= factor;
+ m[2][0] *= factor;
+ m[2][1] *= factor;
+ m[2][2] *= factor;
+ m[2][3] *= factor;
+ m[3][0] *= factor;
+ m[3][1] *= factor;
+ m[3][2] *= factor;
+ m[3][3] *= factor;
+ flagBits = General;
+ return *this;
+}
+
+inline bool QMatrix4x4::operator==(const QMatrix4x4& other) const
+{
+ return m[0][0] == other.m[0][0] &&
+ m[0][1] == other.m[0][1] &&
+ m[0][2] == other.m[0][2] &&
+ m[0][3] == other.m[0][3] &&
+ m[1][0] == other.m[1][0] &&
+ m[1][1] == other.m[1][1] &&
+ m[1][2] == other.m[1][2] &&
+ m[1][3] == other.m[1][3] &&
+ m[2][0] == other.m[2][0] &&
+ m[2][1] == other.m[2][1] &&
+ m[2][2] == other.m[2][2] &&
+ m[2][3] == other.m[2][3] &&
+ m[3][0] == other.m[3][0] &&
+ m[3][1] == other.m[3][1] &&
+ m[3][2] == other.m[3][2] &&
+ m[3][3] == other.m[3][3];
+}
+
+inline bool QMatrix4x4::operator!=(const QMatrix4x4& other) const
+{
+ return m[0][0] != other.m[0][0] ||
+ m[0][1] != other.m[0][1] ||
+ m[0][2] != other.m[0][2] ||
+ m[0][3] != other.m[0][3] ||
+ m[1][0] != other.m[1][0] ||
+ m[1][1] != other.m[1][1] ||
+ m[1][2] != other.m[1][2] ||
+ m[1][3] != other.m[1][3] ||
+ m[2][0] != other.m[2][0] ||
+ m[2][1] != other.m[2][1] ||
+ m[2][2] != other.m[2][2] ||
+ m[2][3] != other.m[2][3] ||
+ m[3][0] != other.m[3][0] ||
+ m[3][1] != other.m[3][1] ||
+ m[3][2] != other.m[3][2] ||
+ m[3][3] != other.m[3][3];
+}
+
+inline QMatrix4x4 operator+(const QMatrix4x4& m1, const QMatrix4x4& m2)
+{
+ QMatrix4x4 m(1);
+ m.m[0][0] = m1.m[0][0] + m2.m[0][0];
+ m.m[0][1] = m1.m[0][1] + m2.m[0][1];
+ m.m[0][2] = m1.m[0][2] + m2.m[0][2];
+ m.m[0][3] = m1.m[0][3] + m2.m[0][3];
+ m.m[1][0] = m1.m[1][0] + m2.m[1][0];
+ m.m[1][1] = m1.m[1][1] + m2.m[1][1];
+ m.m[1][2] = m1.m[1][2] + m2.m[1][2];
+ m.m[1][3] = m1.m[1][3] + m2.m[1][3];
+ m.m[2][0] = m1.m[2][0] + m2.m[2][0];
+ m.m[2][1] = m1.m[2][1] + m2.m[2][1];
+ m.m[2][2] = m1.m[2][2] + m2.m[2][2];
+ m.m[2][3] = m1.m[2][3] + m2.m[2][3];
+ m.m[3][0] = m1.m[3][0] + m2.m[3][0];
+ m.m[3][1] = m1.m[3][1] + m2.m[3][1];
+ m.m[3][2] = m1.m[3][2] + m2.m[3][2];
+ m.m[3][3] = m1.m[3][3] + m2.m[3][3];
+ return m;
+}
+
+inline QMatrix4x4 operator-(const QMatrix4x4& m1, const QMatrix4x4& m2)
+{
+ QMatrix4x4 m(1);
+ m.m[0][0] = m1.m[0][0] - m2.m[0][0];
+ m.m[0][1] = m1.m[0][1] - m2.m[0][1];
+ m.m[0][2] = m1.m[0][2] - m2.m[0][2];
+ m.m[0][3] = m1.m[0][3] - m2.m[0][3];
+ m.m[1][0] = m1.m[1][0] - m2.m[1][0];
+ m.m[1][1] = m1.m[1][1] - m2.m[1][1];
+ m.m[1][2] = m1.m[1][2] - m2.m[1][2];
+ m.m[1][3] = m1.m[1][3] - m2.m[1][3];
+ m.m[2][0] = m1.m[2][0] - m2.m[2][0];
+ m.m[2][1] = m1.m[2][1] - m2.m[2][1];
+ m.m[2][2] = m1.m[2][2] - m2.m[2][2];
+ m.m[2][3] = m1.m[2][3] - m2.m[2][3];
+ m.m[3][0] = m1.m[3][0] - m2.m[3][0];
+ m.m[3][1] = m1.m[3][1] - m2.m[3][1];
+ m.m[3][2] = m1.m[3][2] - m2.m[3][2];
+ m.m[3][3] = m1.m[3][3] - m2.m[3][3];
+ return m;
+}
+
+inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
+{
+ if (m1.flagBits == QMatrix4x4::Identity)
+ return m2;
+ else if (m2.flagBits == QMatrix4x4::Identity)
+ return m1;
+
+ QMatrix4x4 m(1);
+ m.m[0][0] = m1.m[0][0] * m2.m[0][0] +
+ m1.m[1][0] * m2.m[0][1] +
+ m1.m[2][0] * m2.m[0][2] +
+ m1.m[3][0] * m2.m[0][3];
+ m.m[0][1] = m1.m[0][1] * m2.m[0][0] +
+ m1.m[1][1] * m2.m[0][1] +
+ m1.m[2][1] * m2.m[0][2] +
+ m1.m[3][1] * m2.m[0][3];
+ m.m[0][2] = m1.m[0][2] * m2.m[0][0] +
+ m1.m[1][2] * m2.m[0][1] +
+ m1.m[2][2] * m2.m[0][2] +
+ m1.m[3][2] * m2.m[0][3];
+ m.m[0][3] = m1.m[0][3] * m2.m[0][0] +
+ m1.m[1][3] * m2.m[0][1] +
+ m1.m[2][3] * m2.m[0][2] +
+ m1.m[3][3] * m2.m[0][3];
+ m.m[1][0] = m1.m[0][0] * m2.m[1][0] +
+ m1.m[1][0] * m2.m[1][1] +
+ m1.m[2][0] * m2.m[1][2] +
+ m1.m[3][0] * m2.m[1][3];
+ m.m[1][1] = m1.m[0][1] * m2.m[1][0] +
+ m1.m[1][1] * m2.m[1][1] +
+ m1.m[2][1] * m2.m[1][2] +
+ m1.m[3][1] * m2.m[1][3];
+ m.m[1][2] = m1.m[0][2] * m2.m[1][0] +
+ m1.m[1][2] * m2.m[1][1] +
+ m1.m[2][2] * m2.m[1][2] +
+ m1.m[3][2] * m2.m[1][3];
+ m.m[1][3] = m1.m[0][3] * m2.m[1][0] +
+ m1.m[1][3] * m2.m[1][1] +
+ m1.m[2][3] * m2.m[1][2] +
+ m1.m[3][3] * m2.m[1][3];
+ m.m[2][0] = m1.m[0][0] * m2.m[2][0] +
+ m1.m[1][0] * m2.m[2][1] +
+ m1.m[2][0] * m2.m[2][2] +
+ m1.m[3][0] * m2.m[2][3];
+ m.m[2][1] = m1.m[0][1] * m2.m[2][0] +
+ m1.m[1][1] * m2.m[2][1] +
+ m1.m[2][1] * m2.m[2][2] +
+ m1.m[3][1] * m2.m[2][3];
+ m.m[2][2] = m1.m[0][2] * m2.m[2][0] +
+ m1.m[1][2] * m2.m[2][1] +
+ m1.m[2][2] * m2.m[2][2] +
+ m1.m[3][2] * m2.m[2][3];
+ m.m[2][3] = m1.m[0][3] * m2.m[2][0] +
+ m1.m[1][3] * m2.m[2][1] +
+ m1.m[2][3] * m2.m[2][2] +
+ m1.m[3][3] * m2.m[2][3];
+ m.m[3][0] = m1.m[0][0] * m2.m[3][0] +
+ m1.m[1][0] * m2.m[3][1] +
+ m1.m[2][0] * m2.m[3][2] +
+ m1.m[3][0] * m2.m[3][3];
+ m.m[3][1] = m1.m[0][1] * m2.m[3][0] +
+ m1.m[1][1] * m2.m[3][1] +
+ m1.m[2][1] * m2.m[3][2] +
+ m1.m[3][1] * m2.m[3][3];
+ m.m[3][2] = m1.m[0][2] * m2.m[3][0] +
+ m1.m[1][2] * m2.m[3][1] +
+ m1.m[2][2] * m2.m[3][2] +
+ m1.m[3][2] * m2.m[3][3];
+ m.m[3][3] = m1.m[0][3] * m2.m[3][0] +
+ m1.m[1][3] * m2.m[3][1] +
+ m1.m[2][3] * m2.m[3][2] +
+ m1.m[3][3] * m2.m[3][3];
+ return m;
+}
+
+#ifndef QT_NO_VECTOR3D
+
+inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
+{
+ float x, y, z, w;
+ x = vector.xp * matrix.m[0][0] +
+ vector.yp * matrix.m[0][1] +
+ vector.zp * matrix.m[0][2] +
+ matrix.m[0][3];
+ y = vector.xp * matrix.m[1][0] +
+ vector.yp * matrix.m[1][1] +
+ vector.zp * matrix.m[1][2] +
+ matrix.m[1][3];
+ z = vector.xp * matrix.m[2][0] +
+ vector.yp * matrix.m[2][1] +
+ vector.zp * matrix.m[2][2] +
+ matrix.m[2][3];
+ w = vector.xp * matrix.m[3][0] +
+ vector.yp * matrix.m[3][1] +
+ vector.zp * matrix.m[3][2] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QVector3D(x, y, z, 1);
+ else
+ return QVector3D(x / w, y / w, z / w, 1);
+}
+
+inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
+{
+ float x, y, z, w;
+ x = vector.xp * matrix.m[0][0] +
+ vector.yp * matrix.m[1][0] +
+ vector.zp * matrix.m[2][0] +
+ matrix.m[3][0];
+ y = vector.xp * matrix.m[0][1] +
+ vector.yp * matrix.m[1][1] +
+ vector.zp * matrix.m[2][1] +
+ matrix.m[3][1];
+ z = vector.xp * matrix.m[0][2] +
+ vector.yp * matrix.m[1][2] +
+ vector.zp * matrix.m[2][2] +
+ matrix.m[3][2];
+ w = vector.xp * matrix.m[0][3] +
+ vector.yp * matrix.m[1][3] +
+ vector.zp * matrix.m[2][3] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QVector3D(x, y, z, 1);
+ else
+ return QVector3D(x / w, y / w, z / w, 1);
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+inline QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix)
+{
+ float x, y, z, w;
+ x = vector.xp * matrix.m[0][0] +
+ vector.yp * matrix.m[0][1] +
+ vector.zp * matrix.m[0][2] +
+ vector.wp * matrix.m[0][3];
+ y = vector.xp * matrix.m[1][0] +
+ vector.yp * matrix.m[1][1] +
+ vector.zp * matrix.m[1][2] +
+ vector.wp * matrix.m[1][3];
+ z = vector.xp * matrix.m[2][0] +
+ vector.yp * matrix.m[2][1] +
+ vector.zp * matrix.m[2][2] +
+ vector.wp * matrix.m[2][3];
+ w = vector.xp * matrix.m[3][0] +
+ vector.yp * matrix.m[3][1] +
+ vector.zp * matrix.m[3][2] +
+ vector.wp * matrix.m[3][3];
+ return QVector4D(x, y, z, w, 1);
+}
+
+inline QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector)
+{
+ float x, y, z, w;
+ x = vector.xp * matrix.m[0][0] +
+ vector.yp * matrix.m[1][0] +
+ vector.zp * matrix.m[2][0] +
+ vector.wp * matrix.m[3][0];
+ y = vector.xp * matrix.m[0][1] +
+ vector.yp * matrix.m[1][1] +
+ vector.zp * matrix.m[2][1] +
+ vector.wp * matrix.m[3][1];
+ z = vector.xp * matrix.m[0][2] +
+ vector.yp * matrix.m[1][2] +
+ vector.zp * matrix.m[2][2] +
+ vector.wp * matrix.m[3][2];
+ w = vector.xp * matrix.m[0][3] +
+ vector.yp * matrix.m[1][3] +
+ vector.zp * matrix.m[2][3] +
+ vector.wp * matrix.m[3][3];
+ return QVector4D(x, y, z, w, 1);
+}
+
+#endif
+
+inline QPoint operator*(const QPoint& point, const QMatrix4x4& matrix)
+{
+ float xin, yin;
+ float x, y, w;
+ xin = point.x();
+ yin = point.y();
+ x = xin * matrix.m[0][0] +
+ yin * matrix.m[0][1] +
+ matrix.m[0][3];
+ y = xin * matrix.m[1][0] +
+ yin * matrix.m[1][1] +
+ matrix.m[1][3];
+ w = xin * matrix.m[3][0] +
+ yin * matrix.m[3][1] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QPoint(qRound(x), qRound(y));
+ else
+ return QPoint(qRound(x / w), qRound(y / w));
+}
+
+inline QPointF operator*(const QPointF& point, const QMatrix4x4& matrix)
+{
+ float xin, yin;
+ float x, y, w;
+ xin = point.x();
+ yin = point.y();
+ x = xin * matrix.m[0][0] +
+ yin * matrix.m[0][1] +
+ matrix.m[0][3];
+ y = xin * matrix.m[1][0] +
+ yin * matrix.m[1][1] +
+ matrix.m[1][3];
+ w = xin * matrix.m[3][0] +
+ yin * matrix.m[3][1] +
+ matrix.m[3][3];
+ if (w == 1.0f) {
+ return QPointF(qreal(x), qreal(y));
+ } else {
+ return QPointF(qreal(x / w), qreal(y / w));
+ }
+}
+
+inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
+{
+ float xin, yin;
+ float x, y, w;
+ xin = point.x();
+ yin = point.y();
+ x = xin * matrix.m[0][0] +
+ yin * matrix.m[1][0] +
+ matrix.m[3][0];
+ y = xin * matrix.m[0][1] +
+ yin * matrix.m[1][1] +
+ matrix.m[3][1];
+ w = xin * matrix.m[0][3] +
+ yin * matrix.m[1][3] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QPoint(qRound(x), qRound(y));
+ else
+ return QPoint(qRound(x / w), qRound(y / w));
+}
+
+inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
+{
+ float xin, yin;
+ float x, y, w;
+ xin = point.x();
+ yin = point.y();
+ x = xin * matrix.m[0][0] +
+ yin * matrix.m[1][0] +
+ matrix.m[3][0];
+ y = xin * matrix.m[0][1] +
+ yin * matrix.m[1][1] +
+ matrix.m[3][1];
+ w = xin * matrix.m[0][3] +
+ yin * matrix.m[1][3] +
+ matrix.m[3][3];
+ if (w == 1.0f) {
+ return QPointF(qreal(x), qreal(y));
+ } else {
+ return QPointF(qreal(x / w), qreal(y / w));
+ }
+}
+
+inline QMatrix4x4 operator-(const QMatrix4x4& matrix)
+{
+ QMatrix4x4 m(1);
+ m.m[0][0] = -matrix.m[0][0];
+ m.m[0][1] = -matrix.m[0][1];
+ m.m[0][2] = -matrix.m[0][2];
+ m.m[0][3] = -matrix.m[0][3];
+ m.m[1][0] = -matrix.m[1][0];
+ m.m[1][1] = -matrix.m[1][1];
+ m.m[1][2] = -matrix.m[1][2];
+ m.m[1][3] = -matrix.m[1][3];
+ m.m[2][0] = -matrix.m[2][0];
+ m.m[2][1] = -matrix.m[2][1];
+ m.m[2][2] = -matrix.m[2][2];
+ m.m[2][3] = -matrix.m[2][3];
+ m.m[3][0] = -matrix.m[3][0];
+ m.m[3][1] = -matrix.m[3][1];
+ m.m[3][2] = -matrix.m[3][2];
+ m.m[3][3] = -matrix.m[3][3];
+ return m;
+}
+
+inline QMatrix4x4 operator*(qreal factor, const QMatrix4x4& matrix)
+{
+ QMatrix4x4 m(1);
+ m.m[0][0] = matrix.m[0][0] * factor;
+ m.m[0][1] = matrix.m[0][1] * factor;
+ m.m[0][2] = matrix.m[0][2] * factor;
+ m.m[0][3] = matrix.m[0][3] * factor;
+ m.m[1][0] = matrix.m[1][0] * factor;
+ m.m[1][1] = matrix.m[1][1] * factor;
+ m.m[1][2] = matrix.m[1][2] * factor;
+ m.m[1][3] = matrix.m[1][3] * factor;
+ m.m[2][0] = matrix.m[2][0] * factor;
+ m.m[2][1] = matrix.m[2][1] * factor;
+ m.m[2][2] = matrix.m[2][2] * factor;
+ m.m[2][3] = matrix.m[2][3] * factor;
+ m.m[3][0] = matrix.m[3][0] * factor;
+ m.m[3][1] = matrix.m[3][1] * factor;
+ m.m[3][2] = matrix.m[3][2] * factor;
+ m.m[3][3] = matrix.m[3][3] * factor;
+ return m;
+}
+
+inline QMatrix4x4 operator*(const QMatrix4x4& matrix, qreal factor)
+{
+ QMatrix4x4 m(1);
+ m.m[0][0] = matrix.m[0][0] * factor;
+ m.m[0][1] = matrix.m[0][1] * factor;
+ m.m[0][2] = matrix.m[0][2] * factor;
+ m.m[0][3] = matrix.m[0][3] * factor;
+ m.m[1][0] = matrix.m[1][0] * factor;
+ m.m[1][1] = matrix.m[1][1] * factor;
+ m.m[1][2] = matrix.m[1][2] * factor;
+ m.m[1][3] = matrix.m[1][3] * factor;
+ m.m[2][0] = matrix.m[2][0] * factor;
+ m.m[2][1] = matrix.m[2][1] * factor;
+ m.m[2][2] = matrix.m[2][2] * factor;
+ m.m[2][3] = matrix.m[2][3] * factor;
+ m.m[3][0] = matrix.m[3][0] * factor;
+ m.m[3][1] = matrix.m[3][1] * factor;
+ m.m[3][2] = matrix.m[3][2] * factor;
+ m.m[3][3] = matrix.m[3][3] * factor;
+ return m;
+}
+
+inline bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2)
+{
+ return qFuzzyCompare(m1.m[0][0], m2.m[0][0]) &&
+ qFuzzyCompare(m1.m[0][1], m2.m[0][1]) &&
+ qFuzzyCompare(m1.m[0][2], m2.m[0][2]) &&
+ qFuzzyCompare(m1.m[0][3], m2.m[0][3]) &&
+ qFuzzyCompare(m1.m[1][0], m2.m[1][0]) &&
+ qFuzzyCompare(m1.m[1][1], m2.m[1][1]) &&
+ qFuzzyCompare(m1.m[1][2], m2.m[1][2]) &&
+ qFuzzyCompare(m1.m[1][3], m2.m[1][3]) &&
+ qFuzzyCompare(m1.m[2][0], m2.m[2][0]) &&
+ qFuzzyCompare(m1.m[2][1], m2.m[2][1]) &&
+ qFuzzyCompare(m1.m[2][2], m2.m[2][2]) &&
+ qFuzzyCompare(m1.m[2][3], m2.m[2][3]) &&
+ qFuzzyCompare(m1.m[3][0], m2.m[3][0]) &&
+ qFuzzyCompare(m1.m[3][1], m2.m[3][1]) &&
+ qFuzzyCompare(m1.m[3][2], m2.m[3][2]) &&
+ qFuzzyCompare(m1.m[3][3], m2.m[3][3]);
+}
+
+inline QPoint QMatrix4x4::map(const QPoint& point) const
+{
+ return *this * point;
+}
+
+inline QPointF QMatrix4x4::map(const QPointF& point) const
+{
+ return *this * point;
+}
+
+#ifndef QT_NO_VECTOR3D
+
+inline QVector3D QMatrix4x4::map(const QVector3D& point) const
+{
+ return *this * point;
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+inline QVector4D QMatrix4x4::map(const QVector4D& point) const
+{
+ return *this * point;
+}
+
+#endif
+
+inline QRect QMatrix4x4::mapRect(const QRect& rect) const
+{
+ QPoint tl = map(rect.topLeft()); QPoint tr = map(rect.topRight());
+ QPoint bl = map(rect.bottomLeft()); QPoint br = map(rect.bottomRight());
+
+ int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
+ int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
+ int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
+ int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+
+ return QRect(QPoint(xmin, ymin), QPoint(xmax, ymax));
+}
+
+inline QRectF QMatrix4x4::mapRect(const QRectF& rect) const
+{
+ QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
+ QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());
+
+ qreal xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
+ qreal xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
+ qreal ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
+ qreal ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+
+ return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+}
+
+inline float *QMatrix4x4::data()
+{
+ // We have to assume that the caller will modify the matrix elements,
+ // so we flip it over to "General" mode.
+ flagBits = General;
+ return m[0];
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
+#endif
+
+template <int N, int M>
+QMatrix4x4 qGenericMatrixToMatrix4x4(const QGenericMatrix<N, M, qreal, float>& matrix)
+{
+ return QMatrix4x4(matrix.constData(), N, M);
+}
+
+template <int N, int M>
+QGenericMatrix<N, M, qreal, float> qGenericMatrixFromMatrix4x4(const QMatrix4x4& matrix)
+{
+ QGenericMatrix<N, M, qreal, float> result;
+ const float *m = matrix.constData();
+ float *values = result.data();
+ for (int col = 0; col < N; ++col) {
+ for (int row = 0; row < M; ++row) {
+ if (col < 4 && row < 4)
+ values[col * M + row] = m[col * 4 + row];
+ else if (col == row)
+ values[col * M + row] = 1.0f;
+ else
+ values[col * M + row] = 0.0f;
+ }
+ }
+ return result;
+}
+
+#endif
+
+QT_END_NAMESPACE
+
+#ifndef QT_NO_MATRIX4X4
+Q_DECLARE_METATYPE(QMatrix4x4)
+#endif
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
new file mode 100644
index 0000000..96659ea
--- /dev/null
+++ b/src/gui/math3d/qquaternion.cpp
@@ -0,0 +1,584 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquaternion.h"
+#include <QtCore/qmath.h>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_QUATERNION
+
+/*!
+ \class QQuaternion
+ \brief The QQuaternion class represents a quaternion consisting of a vector and scalar.
+ \since 4.6
+
+ Quaternions are used to represent rotations in 3D space, and
+ consist of a 3D rotation axis specified by the x, y, and z
+ coordinates, and a scalar representing the rotation angle.
+
+ The components of a quaternion are stored internally using the most
+ efficient representation for the GL rendering engine, which will be
+ either floating-point or fixed-point.
+*/
+
+/*!
+ \fn QQuaternion::QQuaternion()
+
+ Constructs an identity quaternion, i.e. with coordinates (1, 0, 0, 0).
+*/
+
+/*!
+ \fn QQuaternion::QQuaternion(qreal scalar, qreal xpos, qreal ypos, qreal zpos)
+
+ Constructs a quaternion with the vector (\a xpos, \a ypos, \a zpos)
+ and \a scalar.
+*/
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \fn QQuaternion::QQuaternion(qreal scalar, const QVector3D& vector)
+
+ Constructs a quaternion vector from the specified \a vector and
+ \a scalar.
+
+ \sa vector(), scalar()
+*/
+
+/*!
+ \fn QVector3D QQuaternion::vector() const
+
+ Returns the vector component of this quaternion.
+
+ \sa setVector(), scalar()
+*/
+
+/*!
+ \fn void QQuaternion::setVector(const QVector3D& vector)
+
+ Sets the vector component of this quaternion to \a vector.
+
+ \sa vector(), setScalar()
+*/
+
+#endif
+
+/*!
+ \fn void QQuaternion::setVector(qreal x, qreal y, qreal z)
+
+ Sets the vector component of this quaternion to (\a x, \a y, \a z).
+
+ \sa vector(), setScalar()
+*/
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \fn QQuaternion::QQuaternion(const QVector4D& vector)
+
+ Constructs a quaternion from the components of \a vector.
+*/
+
+/*!
+ \fn QVector4D QQuaternion::toVector4D() const
+
+ Returns this quaternion as a 4D vector.
+*/
+
+#endif
+
+/*!
+ \fn bool QQuaternion::isNull() const
+
+ Returns true if the x, y, z, and scalar components of this
+ quaternion are set to 0.0; otherwise returns false.
+*/
+
+/*!
+ \fn bool QQuaternion::isIdentity() const
+
+ Returns true if the x, y, and z components of this
+ quaternion are set to 0.0, and the scalar component is set
+ to 1.0; otherwise returns false.
+*/
+
+/*!
+ \fn qreal QQuaternion::x() const
+
+ Returns the x coordinate of this quaternion's vector.
+
+ \sa setX(), y(), z(), scalar()
+*/
+
+/*!
+ \fn qreal QQuaternion::y() const
+
+ Returns the y coordinate of this quaternion's vector.
+
+ \sa setY(), x(), z(), scalar()
+*/
+
+/*!
+ \fn qreal QQuaternion::z() const
+
+ Returns the z coordinate of this quaternion's vector.
+
+ \sa setZ(), x(), y(), scalar()
+*/
+
+/*!
+ \fn qreal QQuaternion::scalar() const
+
+ Returns the scalar component of this quaternion.
+
+ \sa setScalar(), x(), y(), z()
+*/
+
+/*!
+ \fn void QQuaternion::setX(qreal x)
+
+ Sets the x coordinate of this quaternion's vector to the given
+ \a x coordinate.
+
+ \sa x(), setY(), setZ(), setScalar()
+*/
+
+/*!
+ \fn void QQuaternion::setY(qreal y)
+
+ Sets the y coordinate of this quaternion's vector to the given
+ \a y coordinate.
+
+ \sa y(), setX(), setZ(), setScalar()
+*/
+
+/*!
+ \fn void QQuaternion::setZ(qreal z)
+
+ Sets the z coordinate of this quaternion's vector to the given
+ \a z coordinate.
+
+ \sa z(), setX(), setY(), setScalar()
+*/
+
+/*!
+ \fn void QQuaternion::setScalar(qreal scalar)
+
+ Sets the scalar component of this quaternion to \a scalar.
+
+ \sa scalar(), setX(), setY(), setZ()
+*/
+
+/*!
+ Returns the length of the quaternion. This is also called the "norm".
+
+ \sa lengthSquared(), normalized()
+*/
+qreal QQuaternion::length() const
+{
+ return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
+}
+
+/*!
+ Returns the squared length of the quaternion.
+
+ \sa length()
+*/
+qreal QQuaternion::lengthSquared() const
+{
+ return xp * xp + yp * yp + zp * zp + wp * wp;
+}
+
+/*!
+ Returns the normalized unit form of this quaternion.
+
+ If this quaternion is null, then a null quaternion is returned.
+ If the length of the quaternion is very close to 1, then the quaternion
+ will be returned as-is. Otherwise the normalized form of the
+ quaternion of length 1 will be returned.
+
+ \sa length(), normalize()
+*/
+QQuaternion QQuaternion::normalized() const
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f))
+ return *this;
+ else if (!qFuzzyIsNull(len))
+ return *this / qSqrt(len);
+ else
+ return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
+}
+
+/*!
+ Normalizes the currect quaternion in place. Nothing happens if this
+ is a null quaternion or the length of the quaternion is very close to 1.
+
+ \sa length(), normalized()
+*/
+void QQuaternion::normalize()
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ return;
+
+ len = qSqrt(len);
+
+ xp /= len;
+ yp /= len;
+ zp /= len;
+ wp /= len;
+}
+
+/*!
+ \fn QQuaternion QQuaternion::conjugate() const
+
+ Returns the conjugate of this quaternion, which is
+ (-x, -y, -z, scalar).
+*/
+
+/*!
+ Rotates \a vector with this quaternion to produce a new vector
+ in 3D space. The following code:
+
+ \code
+ QVector3D result = q.rotateVector(vector);
+ \endcode
+
+ is equivalent to the following:
+
+ \code
+ QVector3D result = (q * QQuaternion(0, vector) * q.conjugate()).vector();
+ \endcode
+*/
+QVector3D QQuaternion::rotateVector(const QVector3D& vector) const
+{
+ return (*this * QQuaternion(0, vector) * conjugate()).vector();
+}
+
+/*!
+ \fn QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion)
+
+ Adds the given \a quaternion to this quaternion and returns a reference to
+ this quaternion.
+
+ \sa operator-=()
+*/
+
+/*!
+ \fn QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion)
+
+ Subtracts the given \a quaternion from this quaternion and returns a
+ reference to this quaternion.
+
+ \sa operator+=()
+*/
+
+/*!
+ \fn QQuaternion &QQuaternion::operator*=(qreal factor)
+
+ Multiplies this quaternion's components by the given \a factor, and
+ returns a reference to this quaternion.
+
+ \sa operator/=()
+*/
+
+/*!
+ \fn QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion)
+
+ Multiplies this quaternion by \a quaternion and returns a reference
+ to this quaternion.
+*/
+
+/*!
+ \fn QQuaternion &QQuaternion::operator/=(qreal divisor)
+
+ Divides this quaternion's components by the given \a divisor, and
+ returns a reference to this quaternion.
+
+ \sa operator*=()
+*/
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Creates a normalized quaternion that corresponds to rotating through
+ \a angle degrees about the specified 3D \a axis.
+*/
+QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle)
+{
+ // Algorithm from:
+ // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56
+ // We normalize the result just in case the values are close
+ // to zero, as suggested in the above FAQ.
+ qreal a = (angle / 2.0f) * M_PI / 180.0f;
+ qreal s = qSin(a);
+ qreal c = qCos(a);
+ QVector3D ax = axis.normalized();
+ return QQuaternion(c, ax.xp * s, ax.yp * s, ax.zp * s, 1).normalized();
+}
+
+#endif
+
+/*!
+ Creates a normalized quaternion that corresponds to rotating through
+ \a angle degrees about the 3D axis (\a x, \a y, \a z).
+*/
+QQuaternion QQuaternion::fromAxisAndAngle
+ (qreal x, qreal y, qreal z, qreal angle)
+{
+ float xp = x;
+ float yp = y;
+ float zp = z;
+ qreal length = qSqrt(xp * xp + yp * yp + zp * zp);
+ if (!qIsNull(length)) {
+ xp /= length;
+ yp /= length;
+ zp /= length;
+ }
+ qreal a = (angle / 2.0f) * M_PI / 180.0f;
+ qreal s = qSin(a);
+ qreal c = qCos(a);
+ return QQuaternion(c, xp * s, yp * s, zp * s, 1).normalized();
+}
+
+/*!
+ \fn bool operator==(const QQuaternion &q1, const QQuaternion &q2)
+ \relates QQuaternion
+
+ Returns true if \a q1 is equal to \a q2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool operator!=(const QQuaternion &q1, const QQuaternion &q2)
+ \relates QQuaternion
+
+ Returns true if \a q1 is not equal to \a q2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2)
+ \relates QQuaternion
+
+ Returns a QQuaternion object that is the sum of the given quaternions,
+ \a q1 and \a q2; each component is added separately.
+
+ \sa QQuaternion::operator+=()
+*/
+
+/*!
+ \fn const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2)
+ \relates QQuaternion
+
+ Returns a QQuaternion object that is formed by subtracting
+ \a q2 from \a q1; each component is subtracted separately.
+
+ \sa QQuaternion::operator-=()
+*/
+
+/*!
+ \fn const QQuaternion operator*(qreal factor, const QQuaternion &quaternion)
+ \relates QQuaternion
+
+ Returns a copy of the given \a quaternion, multiplied by the
+ given \a factor.
+
+ \sa QQuaternion::operator*=()
+*/
+
+/*!
+ \fn const QQuaternion operator*(const QQuaternion &quaternion, qreal factor)
+ \relates QQuaternion
+
+ Returns a copy of the given \a quaternion, multiplied by the
+ given \a factor.
+
+ \sa QQuaternion::operator*=()
+*/
+
+/*!
+ \fn const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2)
+ \relates QQuaternion
+
+ Multiplies \a q1 and \a q2 using quaternion multiplication.
+ The result corresponds to applying both of the rotations specified
+ by \a q1 and \a q2.
+
+ \sa QQuaternion::operator*=()
+*/
+
+/*!
+ \fn const QQuaternion operator-(const QQuaternion &quaternion)
+ \relates QQuaternion
+ \overload
+
+ Returns a QQuaternion object that is formed by changing the sign of
+ all three components of the given \a quaternion.
+
+ Equivalent to \c {QQuaternion(0,0,0,0) - quaternion}.
+*/
+
+/*!
+ \fn const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor)
+ \relates QQuaternion
+
+ Returns the QQuaternion object formed by dividing all components of
+ the given \a quaternion by the given \a divisor.
+
+ \sa QQuaternion::operator/=()
+*/
+
+/*!
+ \fn bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2)
+ \relates QQuaternion
+
+ Returns true if \a q1 and \a q2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+
+/*!
+ Interpolates along the shortest spherical path between the
+ rotational positions \a q1 and \a q2. The value \a t should
+ be between 0 and 1, indicating the spherical distance to travel
+ between \a q1 and \a q2.
+
+ If \a t is less than or equal to 0, then \a q1 will be returned.
+ If \a t is greater than or equal to 1, then \a q2 will be returned.
+
+ \sa nlerp()
+*/
+QQuaternion QQuaternion::slerp
+ (const QQuaternion& q1, const QQuaternion& q2, qreal t)
+{
+ // Handle the easy cases first.
+ if (t <= 0.0f)
+ return q1;
+ else if (t >= 1.0f)
+ return q2;
+
+ // Determine the angle between the two quaternions.
+ QQuaternion q2b;
+ qreal dot;
+ dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
+ if (dot >= 0.0f) {
+ q2b = q2;
+ } else {
+ q2b = -q2;
+ dot = -dot;
+ }
+
+ // Get the scale factors. If they are too small,
+ // then revert to simple linear interpolation.
+ qreal factor1 = 1.0f - t;
+ qreal factor2 = t;
+ if ((1.0f - dot) > 0.0000001) {
+ qreal angle = qreal(qAcos(dot));
+ qreal sinOfAngle = qreal(qSin(angle));
+ if (sinOfAngle > 0.0000001) {
+ factor1 = qreal(qSin((1.0f - t) * angle)) / sinOfAngle;
+ factor2 = qreal(qSin(t * angle)) / sinOfAngle;
+ }
+ }
+
+ // Construct the result quaternion.
+ return q1 * factor1 + q2b * factor2;
+}
+
+/*!
+ Interpolates along the shortest linear path between the rotational
+ positions \a q1 and \a q2. The value \a t should be between 0 and 1,
+ indicating the distance to travel between \a q1 and \a q2.
+ The result will be normalized().
+
+ If \a t is less than or equal to 0, then \a q1 will be returned.
+ If \a t is greater than or equal to 1, then \a q2 will be returned.
+
+ The nlerp() function is typically faster than slerp() and will
+ give approximate results to spherical interpolation that are
+ good enough for some applications.
+
+ \sa slerp()
+*/
+QQuaternion QQuaternion::nlerp
+ (const QQuaternion& q1, const QQuaternion& q2, qreal t)
+{
+ // Handle the easy cases first.
+ if (t <= 0.0f)
+ return q1;
+ else if (t >= 1.0f)
+ return q2;
+
+ // Determine the angle between the two quaternions.
+ QQuaternion q2b;
+ qreal dot;
+ dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
+ if (dot >= 0.0f)
+ q2b = q2;
+ else
+ q2b = -q2;
+
+ // Perform the linear interpolation.
+ return (q1 * (1.0f - t) + q2b * t).normalized();
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, const QQuaternion &q)
+{
+ dbg.nospace() << "QQuaternion(scalar:" << q.scalar()
+ << ", vector:(" << q.x() << ", "
+ << q.y() << ", " << q.z() << "))";
+ return dbg.space();
+}
+
+#endif
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h
new file mode 100644
index 0000000..c05c641
--- /dev/null
+++ b/src/gui/math3d/qquaternion.h
@@ -0,0 +1,337 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUATERNION_H
+#define QQUATERNION_H
+
+#include <QtGui/qvector3d.h>
+#include <QtGui/qvector4d.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_QUATERNION
+
+class QMatrix4x4;
+
+class Q_GUI_EXPORT QQuaternion
+{
+public:
+ QQuaternion();
+ QQuaternion(qreal scalar, qreal xpos, qreal ypos, qreal zpos);
+#ifndef QT_NO_VECTOR3D
+ QQuaternion(qreal scalar, const QVector3D& vector);
+#endif
+#ifndef QT_NO_VECTOR4D
+ explicit QQuaternion(const QVector4D& vector);
+#endif
+
+ bool isNull() const;
+ bool isIdentity() const;
+
+#ifndef QT_NO_VECTOR3D
+ QVector3D vector() const;
+ void setVector(const QVector3D& vector);
+#endif
+ void setVector(qreal x, qreal y, qreal z);
+
+ qreal x() const;
+ qreal y() const;
+ qreal z() const;
+ qreal scalar() const;
+
+ void setX(qreal x);
+ void setY(qreal y);
+ void setZ(qreal z);
+ void setScalar(qreal scalar);
+
+ qreal length() const;
+ qreal lengthSquared() const;
+
+ QQuaternion normalized() const;
+ void normalize();
+
+ QQuaternion conjugate() const;
+
+ QVector3D rotateVector(const QVector3D& vector) const;
+
+ QQuaternion &operator+=(const QQuaternion &quaternion);
+ QQuaternion &operator-=(const QQuaternion &quaternion);
+ QQuaternion &operator*=(qreal factor);
+ QQuaternion &operator*=(const QQuaternion &quaternion);
+ QQuaternion &operator/=(qreal divisor);
+
+ friend inline bool operator==(const QQuaternion &q1, const QQuaternion &q2);
+ friend inline bool operator!=(const QQuaternion &q1, const QQuaternion &q2);
+ friend inline const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2);
+ friend inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2);
+ friend inline const QQuaternion operator*(qreal factor, const QQuaternion &quaternion);
+ friend inline const QQuaternion operator*(const QQuaternion &quaternion, qreal factor);
+ friend inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2);
+ friend inline const QQuaternion operator-(const QQuaternion &quaternion);
+ friend inline const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor);
+
+ friend inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2);
+
+#ifndef QT_NO_VECTOR4D
+ QVector4D toVector4D() const;
+#endif
+
+#ifndef QT_NO_VECTOR3D
+ static QQuaternion fromAxisAndAngle(const QVector3D& axis, qreal angle);
+#endif
+ static QQuaternion fromAxisAndAngle
+ (qreal x, qreal y, qreal z, qreal angle);
+
+ static QQuaternion slerp
+ (const QQuaternion& q1, const QQuaternion& q2, qreal t);
+ static QQuaternion nlerp
+ (const QQuaternion& q1, const QQuaternion& q2, qreal t);
+
+private:
+ float wp, xp, yp, zp;
+
+ friend class QMatrix4x4;
+
+ QQuaternion(float scalar, float xpos, float ypos, float zpos, int dummy);
+};
+
+inline QQuaternion::QQuaternion() : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {}
+
+inline QQuaternion::QQuaternion(qreal scalar, qreal xpos, qreal ypos, qreal zpos) : wp(scalar), xp(xpos), yp(ypos), zp(zpos) {}
+
+
+inline QQuaternion::QQuaternion(float scalar, float xpos, float ypos, float zpos, int) : wp(scalar), xp(xpos), yp(ypos), zp(zpos) {}
+
+inline bool QQuaternion::isNull() const
+{
+ return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && qIsNull(wp);
+}
+
+inline bool QQuaternion::isIdentity() const
+{
+ return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && wp == 1.0f;
+}
+
+inline qreal QQuaternion::x() const { return qreal(xp); }
+inline qreal QQuaternion::y() const { return qreal(yp); }
+inline qreal QQuaternion::z() const { return qreal(zp); }
+inline qreal QQuaternion::scalar() const { return qreal(wp); }
+
+inline void QQuaternion::setX(qreal x) { xp = x; }
+inline void QQuaternion::setY(qreal y) { yp = y; }
+inline void QQuaternion::setZ(qreal z) { zp = z; }
+inline void QQuaternion::setScalar(qreal scalar) { wp = scalar; }
+
+inline QQuaternion QQuaternion::conjugate() const
+{
+ return QQuaternion(wp, -xp, -yp, -zp, 1);
+}
+
+inline QQuaternion &QQuaternion::operator+=(const QQuaternion &quaternion)
+{
+ xp += quaternion.xp;
+ yp += quaternion.yp;
+ zp += quaternion.zp;
+ wp += quaternion.wp;
+ return *this;
+}
+
+inline QQuaternion &QQuaternion::operator-=(const QQuaternion &quaternion)
+{
+ xp -= quaternion.xp;
+ yp -= quaternion.yp;
+ zp -= quaternion.zp;
+ wp -= quaternion.wp;
+ return *this;
+}
+
+inline QQuaternion &QQuaternion::operator*=(qreal factor)
+{
+ xp *= factor;
+ yp *= factor;
+ zp *= factor;
+ wp *= factor;
+ return *this;
+}
+
+inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2)
+{
+ // Algorithm from:
+ // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q53
+ float x = q1.wp * q2.xp +
+ q1.xp * q2.wp +
+ q1.yp * q2.zp -
+ q1.zp * q2.yp;
+ float y = q1.wp * q2.yp +
+ q1.yp * q2.wp +
+ q1.zp * q2.xp -
+ q1.xp * q2.zp;
+ float z = q1.wp * q2.zp +
+ q1.zp * q2.wp +
+ q1.xp * q2.yp -
+ q1.yp * q2.xp;
+ float w = q1.wp * q2.wp -
+ q1.xp * q2.xp -
+ q1.yp * q2.yp -
+ q1.zp * q2.zp;
+ return QQuaternion(w, x, y, z, 1);
+}
+
+inline QQuaternion &QQuaternion::operator*=(const QQuaternion &quaternion)
+{
+ *this = *this * quaternion;
+ return *this;
+}
+
+inline QQuaternion &QQuaternion::operator/=(qreal divisor)
+{
+ xp /= divisor;
+ yp /= divisor;
+ zp /= divisor;
+ wp /= divisor;
+ return *this;
+}
+
+inline bool operator==(const QQuaternion &q1, const QQuaternion &q2)
+{
+ return q1.xp == q2.xp && q1.yp == q2.yp && q1.zp == q2.zp && q1.wp == q2.wp;
+}
+
+inline bool operator!=(const QQuaternion &q1, const QQuaternion &q2)
+{
+ return q1.xp != q2.xp || q1.yp != q2.yp || q1.zp != q2.zp || q1.wp != q2.wp;
+}
+
+inline const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2)
+{
+ return QQuaternion(q1.wp + q2.wp, q1.xp + q2.xp, q1.yp + q2.yp, q1.zp + q2.zp, 1);
+}
+
+inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2)
+{
+ return QQuaternion(q1.wp - q2.wp, q1.xp - q2.xp, q1.yp - q2.yp, q1.zp - q2.zp, 1);
+}
+
+inline const QQuaternion operator*(qreal factor, const QQuaternion &quaternion)
+{
+ return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor, 1);
+}
+
+inline const QQuaternion operator*(const QQuaternion &quaternion, qreal factor)
+{
+ return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor, 1);
+}
+
+inline const QQuaternion operator-(const QQuaternion &quaternion)
+{
+ return QQuaternion(-quaternion.wp, -quaternion.xp, -quaternion.yp, -quaternion.zp, 1);
+}
+
+inline const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor)
+{
+ return QQuaternion(quaternion.wp / divisor, quaternion.xp / divisor, quaternion.yp / divisor, quaternion.zp / divisor, 1);
+}
+
+inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2)
+{
+ return qFuzzyCompare(q1.xp, q2.xp) &&
+ qFuzzyCompare(q1.yp, q2.yp) &&
+ qFuzzyCompare(q1.zp, q2.zp) &&
+ qFuzzyCompare(q1.wp, q2.wp);
+}
+
+#ifndef QT_NO_VECTOR3D
+
+inline QQuaternion::QQuaternion(qreal scalar, const QVector3D& vector)
+ : wp(scalar), xp(vector.xp), yp(vector.yp), zp(vector.zp) {}
+
+inline void QQuaternion::setVector(const QVector3D& vector)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = vector.zp;
+}
+
+inline QVector3D QQuaternion::vector() const
+{
+ return QVector3D(xp, yp, zp, 1);
+}
+
+#endif
+
+inline void QQuaternion::setVector(qreal x, qreal y, qreal z)
+{
+ xp = x;
+ yp = y;
+ zp = z;
+}
+
+#ifndef QT_NO_VECTOR4D
+
+inline QQuaternion::QQuaternion(const QVector4D& vector)
+ : wp(vector.wp), xp(vector.xp), yp(vector.yp), zp(vector.zp) {}
+
+inline QVector4D QQuaternion::toVector4D() const
+{
+ return QVector4D(xp, yp, zp, wp, 1);
+}
+
+#endif
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QQuaternion &q);
+#endif
+
+#endif
+
+QT_END_NAMESPACE
+
+#ifndef QT_NO_QUATERNION
+Q_DECLARE_METATYPE(QQuaternion)
+#endif
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp
new file mode 100644
index 0000000..c3aaa42
--- /dev/null
+++ b/src/gui/math3d/qvector2d.cpp
@@ -0,0 +1,417 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qvector2d.h"
+#include "qvector3d.h"
+#include "qvector4d.h"
+#include <QtCore/qdebug.h>
+#include <QtCore/qmath.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ \class QVector2D
+ \brief The QVector2D class represents a vector or vertex in 2D space.
+ \since 4.6
+
+ The QVector2D class can also be used to represent vertices in 2D space.
+ We therefore do not need to provide a separate vertex class.
+
+ The coordinates are stored internally using the most efficient
+ representation for the GL rendering engine, which will be either
+ floating-point or fixed-point.
+*/
+
+/*!
+ \fn QVector2D::QVector2D()
+
+ Constructs a null vector, i.e. with coordinates (0, 0, 0).
+*/
+
+/*!
+ \fn QVector2D::QVector2D(qreal xpos, qreal ypos)
+
+ Constructs a vector with coordinates (\a xpos, \a ypos).
+*/
+
+/*!
+ \fn QVector2D::QVector2D(const QPoint& point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point.
+*/
+
+/*!
+ \fn QVector2D::QVector2D(const QPointF& point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point.
+*/
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Constructs a vector with x and y coordinates from a 3D \a vector.
+ The z coordinate of \a vector is dropped.
+
+ \sa toVector3D()
+*/
+QVector2D::QVector2D(const QVector3D& vector)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ Constructs a vector with x and y coordinates from a 3D \a vector.
+ The z and w coordinates of \a vector are dropped.
+
+ \sa toVector4D()
+*/
+QVector2D::QVector2D(const QVector4D& vector)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+}
+
+#endif
+
+/*!
+ \fn bool QVector2D::isNull() const
+
+ Returns true if the x and y coordinates are set to 0.0,
+ otherwise returns false.
+*/
+
+/*!
+ \fn qreal QVector2D::x() const
+
+ Returns the x coordinate of this point.
+
+ \sa setX(), y()
+*/
+
+/*!
+ \fn qreal QVector2D::y() const
+
+ Returns the y coordinate of this point.
+
+ \sa setY(), x()
+*/
+
+/*!
+ \fn void QVector2D::setX(qreal x)
+
+ Sets the x coordinate of this point to the given \a x coordinate.
+
+ \sa x(), setY()
+*/
+
+/*!
+ \fn void QVector2D::setY(qreal y)
+
+ Sets the y coordinate of this point to the given \a y coordinate.
+
+ \sa y(), setX()
+*/
+
+/*!
+ Returns the length of the vector from the origin.
+
+ \sa lengthSquared(), normalized()
+*/
+qreal QVector2D::length() const
+{
+ return qSqrt(xp * xp + yp * yp);
+}
+
+/*!
+ Returns the squared length of the vector from the origin.
+ This is equivalent to the dot product of the vector with itself.
+
+ \sa length(), dotProduct()
+*/
+qreal QVector2D::lengthSquared() const
+{
+ return xp * xp + yp * yp;
+}
+
+/*!
+ Returns the normalized unit vector form of this vector.
+
+ If this vector is null, then a null vector is returned. If the length
+ of the vector is very close to 1, then the vector will be returned as-is.
+ Otherwise the normalized form of the vector of length 1 will be returned.
+
+ \sa length(), normalize()
+*/
+QVector2D QVector2D::normalized() const
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f))
+ return *this;
+ else if (!qFuzzyIsNull(len))
+ return *this / qSqrt(len);
+ else
+ return QVector2D();
+}
+
+/*!
+ Normalizes the currect vector in place. Nothing happens if this
+ vector is a null vector or the length of the vector is very close to 1.
+
+ \sa length(), normalized()
+*/
+void QVector2D::normalize()
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ return;
+
+ len = qSqrt(len);
+
+ xp /= len;
+ yp /= len;
+}
+
+/*!
+ \fn QVector2D &QVector2D::operator+=(const QVector2D &vector)
+
+ Adds the given \a vector to this vector and returns a reference to
+ this vector.
+
+ \sa operator-=()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator-=(const QVector2D &vector)
+
+ Subtracts the given \a vector from this vector and returns a reference to
+ this vector.
+
+ \sa operator+=()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator*=(qreal factor)
+
+ Multiplies this vector's coordinates by the given \a factor, and
+ returns a reference to this vector.
+
+ \sa operator/=()
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator*=(const QVector2D &vector)
+
+ Multiplies the components of this vector by the corresponding
+ components in \a vector.
+*/
+
+/*!
+ \fn QVector2D &QVector2D::operator/=(qreal divisor)
+
+ Divides this vector's coordinates by the given \a divisor, and
+ returns a reference to this vector.
+
+ \sa operator*=()
+*/
+
+/*!
+ Returns the dot product of \a v1 and \a v2.
+*/
+qreal QVector2D::dotProduct(const QVector2D& v1, const QVector2D& v2)
+{
+ return v1.xp * v2.xp + v1.yp * v2.yp;
+}
+
+/*!
+ \fn bool operator==(const QVector2D &v1, const QVector2D &v2)
+ \relates QVector2D
+
+ Returns true if \a v1 is equal to \a v2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool operator!=(const QVector2D &v1, const QVector2D &v2)
+ \relates QVector2D
+
+ Returns true if \a v1 is not equal to \a v2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn const QVector2D operator+(const QVector2D &v1, const QVector2D &v2)
+ \relates QVector2D
+
+ Returns a QVector2D object that is the sum of the given vectors, \a v1
+ and \a v2; each component is added separately.
+
+ \sa QVector2D::operator+=()
+*/
+
+/*!
+ \fn const QVector2D operator-(const QVector2D &v1, const QVector2D &v2)
+ \relates QVector2D
+
+ Returns a QVector2D object that is formed by subtracting \a v2 from \a v1;
+ each component is subtracted separately.
+
+ \sa QVector2D::operator-=()
+*/
+
+/*!
+ \fn const QVector2D operator*(qreal factor, const QVector2D &vector)
+ \relates QVector2D
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector2D::operator*=()
+*/
+
+/*!
+ \fn const QVector2D operator*(const QVector2D &vector, qreal factor)
+ \relates QVector2D
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector2D::operator*=()
+*/
+
+/*!
+ \fn const QVector2D operator*(const QVector2D &v1, const QVector2D &v2)
+ \relates QVector2D
+
+ Multiplies the components of \a v1 by the corresponding
+ components in \a v2.
+*/
+
+/*!
+ \fn const QVector2D operator-(const QVector2D &vector)
+ \relates QVector2D
+ \overload
+
+ Returns a QVector2D object that is formed by changing the sign of
+ the components of the given \a vector.
+
+ Equivalent to \c {QVector2D(0,0) - vector}.
+*/
+
+/*!
+ \fn const QVector2D operator/(const QVector2D &vector, qreal divisor)
+ \relates QVector2D
+
+ Returns the QVector2D object formed by dividing all three components of
+ the given \a vector by the given \a divisor.
+
+ \sa QVector2D::operator/=()
+*/
+
+/*!
+ \fn bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2)
+ \relates QVector2D
+
+ Returns true if \a v1 and \a v2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Returns the 3D form of this 2D vector, with the z coordinate set to zero.
+
+ \sa toVector4D(), toPoint()
+*/
+QVector3D QVector2D::toVector3D() const
+{
+ return QVector3D(xp, yp, 0.0f, 1);
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
+
+ \sa toVector3D(), toPoint()
+*/
+QVector4D QVector2D::toVector4D() const
+{
+ return QVector4D(xp, yp, 0.0f, 0.0f, 1);
+}
+
+#endif
+
+/*!
+ \fn QPoint QVector2D::toPoint() const
+
+ Returns the QPoint form of this 2D vector.
+
+ \sa toPointF(), toVector3D()
+*/
+
+/*!
+ \fn QPointF QVector2D::toPointF() const
+
+ Returns the QPointF form of this 2D vector.
+
+ \sa toPoint(), toVector3D()
+*/
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, const QVector2D &vector)
+{
+ dbg.nospace() << "QVector2D(" << vector.x() << ", " << vector.y() << ')';
+ return dbg.space();
+}
+
+#endif
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h
new file mode 100644
index 0000000..b027df4
--- /dev/null
+++ b/src/gui/math3d/qvector2d.h
@@ -0,0 +1,256 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QVECTOR2D_H
+#define QVECTOR2D_H
+
+#include <QtCore/qpoint.h>
+#include <QtCore/qmetatype.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QVector3D;
+class QVector4D;
+
+#ifndef QT_NO_VECTOR2D
+
+class Q_GUI_EXPORT QVector2D
+{
+public:
+ QVector2D();
+ QVector2D(qreal xpos, qreal ypos);
+ explicit QVector2D(const QPoint& point);
+ explicit QVector2D(const QPointF& point);
+#ifndef QT_NO_VECTOR3D
+ explicit QVector2D(const QVector3D& vector);
+#endif
+#ifndef QT_NO_VECTOR4D
+ explicit QVector2D(const QVector4D& vector);
+#endif
+
+ bool isNull() const;
+
+ qreal x() const;
+ qreal y() const;
+
+ void setX(qreal x);
+ void setY(qreal y);
+
+ qreal length() const;
+ qreal lengthSquared() const;
+
+ QVector2D normalized() const;
+ void normalize();
+
+ QVector2D &operator+=(const QVector2D &vector);
+ QVector2D &operator-=(const QVector2D &vector);
+ QVector2D &operator*=(qreal factor);
+ QVector2D &operator*=(const QVector2D &vector);
+ QVector2D &operator/=(qreal divisor);
+
+ static qreal dotProduct(const QVector2D& v1, const QVector2D& v2);
+
+ friend inline bool operator==(const QVector2D &v1, const QVector2D &v2);
+ friend inline bool operator!=(const QVector2D &v1, const QVector2D &v2);
+ friend inline const QVector2D operator+(const QVector2D &v1, const QVector2D &v2);
+ friend inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2);
+ friend inline const QVector2D operator*(qreal factor, const QVector2D &vector);
+ friend inline const QVector2D operator*(const QVector2D &vector, qreal factor);
+ friend inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2);
+ friend inline const QVector2D operator-(const QVector2D &vector);
+ friend inline const QVector2D operator/(const QVector2D &vector, qreal divisor);
+
+ friend inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2);
+
+#ifndef QT_NO_VECTOR3D
+ QVector3D toVector3D() const;
+#endif
+#ifndef QT_NO_VECTOR4D
+ QVector4D toVector4D() const;
+#endif
+
+ QPoint toPoint() const;
+ QPointF toPointF() const;
+
+private:
+ float xp, yp;
+
+ QVector2D(float xpos, float ypos, int dummy);
+
+ friend class QVector3D;
+ friend class QVector4D;
+};
+
+inline QVector2D::QVector2D() : xp(0.0f), yp(0.0f) {}
+
+inline QVector2D::QVector2D(float xpos, float ypos, int) : xp(xpos), yp(ypos) {}
+
+inline QVector2D::QVector2D(qreal xpos, qreal ypos) : xp(xpos), yp(ypos) {}
+
+inline QVector2D::QVector2D(const QPoint& point) : xp(point.x()), yp(point.y()) {}
+
+inline QVector2D::QVector2D(const QPointF& point) : xp(point.x()), yp(point.y()) {}
+
+inline bool QVector2D::isNull() const
+{
+ return qIsNull(xp) && qIsNull(yp);
+}
+
+inline qreal QVector2D::x() const { return qreal(xp); }
+inline qreal QVector2D::y() const { return qreal(yp); }
+
+inline void QVector2D::setX(qreal x) { xp = x; }
+inline void QVector2D::setY(qreal y) { yp = y; }
+
+inline QVector2D &QVector2D::operator+=(const QVector2D &vector)
+{
+ xp += vector.xp;
+ yp += vector.yp;
+ return *this;
+}
+
+inline QVector2D &QVector2D::operator-=(const QVector2D &vector)
+{
+ xp -= vector.xp;
+ yp -= vector.yp;
+ return *this;
+}
+
+inline QVector2D &QVector2D::operator*=(qreal factor)
+{
+ xp *= factor;
+ yp *= factor;
+ return *this;
+}
+
+inline QVector2D &QVector2D::operator*=(const QVector2D &vector)
+{
+ xp *= vector.xp;
+ yp *= vector.yp;
+ return *this;
+}
+
+inline QVector2D &QVector2D::operator/=(qreal divisor)
+{
+ xp /= divisor;
+ yp /= divisor;
+ return *this;
+}
+
+inline bool operator==(const QVector2D &v1, const QVector2D &v2)
+{
+ return v1.xp == v2.xp && v1.yp == v2.yp;
+}
+
+inline bool operator!=(const QVector2D &v1, const QVector2D &v2)
+{
+ return v1.xp != v2.xp || v1.yp != v2.yp;
+}
+
+inline const QVector2D operator+(const QVector2D &v1, const QVector2D &v2)
+{
+ return QVector2D(v1.xp + v2.xp, v1.yp + v2.yp, 1);
+}
+
+inline const QVector2D operator-(const QVector2D &v1, const QVector2D &v2)
+{
+ return QVector2D(v1.xp - v2.xp, v1.yp - v2.yp, 1);
+}
+
+inline const QVector2D operator*(qreal factor, const QVector2D &vector)
+{
+ return QVector2D(vector.xp * factor, vector.yp * factor, 1);
+}
+
+inline const QVector2D operator*(const QVector2D &vector, qreal factor)
+{
+ return QVector2D(vector.xp * factor, vector.yp * factor, 1);
+}
+
+inline const QVector2D operator*(const QVector2D &v1, const QVector2D &v2)
+{
+ return QVector2D(v1.xp * v2.xp, v1.yp * v2.yp, 1);
+}
+
+inline const QVector2D operator-(const QVector2D &vector)
+{
+ return QVector2D(-vector.xp, -vector.yp, 1);
+}
+
+inline const QVector2D operator/(const QVector2D &vector, qreal divisor)
+{
+ return QVector2D(vector.xp / divisor, vector.yp / divisor, 1);
+}
+
+inline bool qFuzzyCompare(const QVector2D& v1, const QVector2D& v2)
+{
+ return qFuzzyCompare(v1.xp, v2.xp) && qFuzzyCompare(v1.yp, v2.yp);
+}
+
+inline QPoint QVector2D::toPoint() const
+{
+ return QPoint(qRound(xp), qRound(yp));
+}
+
+inline QPointF QVector2D::toPointF() const
+{
+ return QPointF(qreal(xp), qreal(yp));
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector2D &vector);
+#endif
+
+#endif
+
+QT_END_NAMESPACE
+
+#ifndef QT_NO_VECTOR2D
+Q_DECLARE_METATYPE(QVector2D)
+#endif
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp
new file mode 100644
index 0000000..c83cd60
--- /dev/null
+++ b/src/gui/math3d/qvector3d.cpp
@@ -0,0 +1,565 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qvector3d.h"
+#include "qvector2d.h"
+#include "qvector4d.h"
+#include <QtCore/qmath.h>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ \class QVector3D
+ \brief The QVector3D class represents a vector or vertex in 3D space.
+ \since 4.6
+
+ Vectors are one of the main building blocks of 3D representation and
+ drawing. They consist of three coordinates, traditionally called
+ x, y, and z.
+
+ The QVector3D class can also be used to represent vertices in 3D space.
+ We therefore do not need to provide a separate vertex class.
+
+ The coordinates are stored internally using the most efficient
+ representation for the GL rendering engine, which will be either
+ floating-point or fixed-point.
+*/
+
+/*!
+ \fn QVector3D::QVector3D()
+
+ Constructs a null vector, i.e. with coordinates (0, 0, 0).
+*/
+
+/*!
+ \fn QVector3D::QVector3D(qreal xpos, qreal ypos, qreal zpos)
+
+ Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos).
+*/
+
+/*!
+ \fn QVector3D::QVector3D(const QPoint& point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and a
+ z coordinate of 0.
+*/
+
+/*!
+ \fn QVector3D::QVector3D(const QPointF& point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and a
+ z coordinate of 0.
+*/
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ Constructs a 3D vector from the specified 2D \a vector. The z
+ coordinate is set to zero.
+
+ \sa toVector2D()
+*/
+QVector3D::QVector3D(const QVector2D& vector)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = 0.0f;
+}
+
+/*!
+ Constructs a 3D vector from the specified 2D \a vector. The z
+ coordinate is set to \a zpos.
+
+ \sa toVector2D()
+*/
+QVector3D::QVector3D(const QVector2D& vector, qreal zpos)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = zpos;
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ Constructs a 3D vector from the specified 4D \a vector. The w
+ coordinate is dropped.
+
+ \sa toVector4D()
+*/
+QVector3D::QVector3D(const QVector4D& vector)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = vector.zp;
+}
+
+#endif
+
+/*!
+ \fn bool QVector3D::isNull() const
+
+ Returns true if the x, y, and z coordinates are set to 0.0,
+ otherwise returns false.
+*/
+
+/*!
+ \fn qreal QVector3D::x() const
+
+ Returns the x coordinate of this point.
+
+ \sa setX(), y(), z()
+*/
+
+/*!
+ \fn qreal QVector3D::y() const
+
+ Returns the y coordinate of this point.
+
+ \sa setY(), x(), z()
+*/
+
+/*!
+ \fn qreal QVector3D::z() const
+
+ Returns the z coordinate of this point.
+
+ \sa setZ(), x(), y()
+*/
+
+/*!
+ \fn void QVector3D::setX(qreal x)
+
+ Sets the x coordinate of this point to the given \a x coordinate.
+
+ \sa x(), setY(), setZ()
+*/
+
+/*!
+ \fn void QVector3D::setY(qreal y)
+
+ Sets the y coordinate of this point to the given \a y coordinate.
+
+ \sa y(), setX(), setZ()
+*/
+
+/*!
+ \fn void QVector3D::setZ(qreal z)
+
+ Sets the z coordinate of this point to the given \a z coordinate.
+
+ \sa z(), setX(), setY()
+*/
+
+/*!
+ Returns the normalized unit vector form of this vector.
+
+ If this vector is null, then a null vector is returned. If the length
+ of the vector is very close to 1, then the vector will be returned as-is.
+ Otherwise the normalized form of the vector of length 1 will be returned.
+
+ \sa length(), normalize()
+*/
+QVector3D QVector3D::normalized() const
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f))
+ return *this;
+ else if (!qFuzzyIsNull(len))
+ return *this / qSqrt(len);
+ else
+ return QVector3D();
+}
+
+/*!
+ Normalizes the currect vector in place. Nothing happens if this
+ vector is a null vector or the length of the vector is very close to 1.
+
+ \sa length(), normalized()
+*/
+void QVector3D::normalize()
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ return;
+
+ len = qSqrt(len);
+
+ xp /= len;
+ yp /= len;
+ zp /= len;
+}
+
+/*!
+ \fn QVector3D &QVector3D::operator+=(const QVector3D &vector)
+
+ Adds the given \a vector to this vector and returns a reference to
+ this vector.
+
+ \sa operator-=()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator-=(const QVector3D &vector)
+
+ Subtracts the given \a vector from this vector and returns a reference to
+ this vector.
+
+ \sa operator+=()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator*=(qreal factor)
+
+ Multiplies this vector's coordinates by the given \a factor, and
+ returns a reference to this vector.
+
+ \sa operator/=()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator*=(const QVector3D& vector)
+ \overload
+
+ Multiplies the components of this vector by the corresponding
+ components in \a vector.
+
+ Note: this is not the same as the crossProduct() of this
+ vector and \a vector.
+
+ \sa crossProduct()
+*/
+
+/*!
+ \fn QVector3D &QVector3D::operator/=(qreal divisor)
+
+ Divides this vector's coordinates by the given \a divisor, and
+ returns a reference to this vector.
+
+ \sa operator*=()
+*/
+
+/*!
+ Returns the dot product of \a v1 and \a v2.
+*/
+qreal QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2)
+{
+ return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp;
+}
+
+/*!
+ Returns the cross-product of vectors \a v1 and \a v2, which corresponds
+ to the normal vector of a plane defined by \a v1 and \a v2.
+
+ \sa normal()
+*/
+QVector3D QVector3D::crossProduct(const QVector3D& v1, const QVector3D& v2)
+{
+ return QVector3D(v1.yp * v2.zp - v1.zp * v2.yp,
+ v1.zp * v2.xp - v1.xp * v2.zp,
+ v1.xp * v2.yp - v1.yp * v2.xp, 1);
+}
+
+/*!
+ Returns the normal vector of a plane defined by vectors \a v1 and \a v2,
+ normalized to be a unit vector.
+
+ Use crossProduct() to compute the cross-product of \a v1 and \a v2 if you
+ do not need the result to be normalized to a unit vector.
+
+ \sa crossProduct(), distanceToPlane()
+*/
+QVector3D QVector3D::normal(const QVector3D& v1, const QVector3D& v2)
+{
+ return crossProduct(v1, v2).normalized();
+}
+
+/*!
+ \overload
+
+ Returns the normal vector of a plane defined by vectors
+ \a v2 - \a v1 and \a v3 - \a v1, normalized to be a unit vector.
+
+ Use crossProduct() to compute the cross-product of \a v2 - \a v1 and
+ \a v3 - \a v1 if you do not need the result to be normalized to a
+ unit vector.
+
+ \sa crossProduct(), distanceToPlane()
+*/
+QVector3D QVector3D::normal
+ (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3)
+{
+ return crossProduct((v2 - v1), (v3 - v1)).normalized();
+}
+
+/*!
+ Returns the distance from this vertex to a plane defined by
+ the vertex \a plane and a \a normal unit vector. The \a normal
+ parameter is assumed to have been normalized to a unit vector.
+
+ The return value will be negative if the vertex is below the plane,
+ or zero if it is on the plane.
+
+ \sa normal(), distanceToLine()
+*/
+qreal QVector3D::distanceToPlane
+ (const QVector3D& plane, const QVector3D& normal) const
+{
+ return dotProduct(*this - plane, normal);
+}
+
+/*!
+ \overload
+
+ Returns the distance from this vertex a plane defined by
+ the vertices \a plane1, \a plane2 and \a plane3.
+
+ The return value will be negative if the vertex is below the plane,
+ or zero if it is on the plane.
+
+ The two vectors that define the plane are \a plane2 - \a plane1
+ and \a plane3 - \a plane1.
+
+ \sa normal(), distanceToLine()
+*/
+qreal QVector3D::distanceToPlane
+ (const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const
+{
+ QVector3D n = normal(plane2 - plane1, plane3 - plane1);
+ return dotProduct(*this - plane1, n);
+}
+
+/*!
+ Returns the distance that this vertex is from a line defined
+ by \a point and the unit vector \a direction.
+
+ If \a direction is a null vector, then it does not define a line.
+ In that case, the distance from \a point to this vertex is returned.
+
+ \sa distanceToPlane()
+*/
+qreal QVector3D::distanceToLine
+ (const QVector3D& point, const QVector3D& direction) const
+{
+ if (direction.isNull())
+ return (*this - point).length();
+ QVector3D p = point + dotProduct(*this - point, direction) * direction;
+ return (*this - p).length();
+}
+
+/*!
+ \fn bool operator==(const QVector3D &v1, const QVector3D &v2)
+ \relates QVector3D
+
+ Returns true if \a v1 is equal to \a v2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool operator!=(const QVector3D &v1, const QVector3D &v2)
+ \relates QVector3D
+
+ Returns true if \a v1 is not equal to \a v2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn const QVector3D operator+(const QVector3D &v1, const QVector3D &v2)
+ \relates QVector3D
+
+ Returns a QVector3D object that is the sum of the given vectors, \a v1
+ and \a v2; each component is added separately.
+
+ \sa QVector3D::operator+=()
+*/
+
+/*!
+ \fn const QVector3D operator-(const QVector3D &v1, const QVector3D &v2)
+ \relates QVector3D
+
+ Returns a QVector3D object that is formed by subtracting \a v2 from \a v1;
+ each component is subtracted separately.
+
+ \sa QVector3D::operator-=()
+*/
+
+/*!
+ \fn const QVector3D operator*(qreal factor, const QVector3D &vector)
+ \relates QVector3D
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector3D::operator*=()
+*/
+
+/*!
+ \fn const QVector3D operator*(const QVector3D &vector, qreal factor)
+ \relates QVector3D
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector3D::operator*=()
+*/
+
+/*!
+ \fn const QVector3D operator*(const QVector3D &v1, const QVector3D& v2)
+ \relates QVector3D
+
+ Multiplies the components of \a v1 by the corresponding components in \a v2.
+
+ Note: this is not the same as the crossProduct() of \a v1 and \a v2.
+
+ \sa QVector3D::crossProduct()
+*/
+
+/*!
+ \fn const QVector3D operator-(const QVector3D &vector)
+ \relates QVector3D
+ \overload
+
+ Returns a QVector3D object that is formed by changing the sign of
+ all three components of the given \a vector.
+
+ Equivalent to \c {QVector3D(0,0,0) - vector}.
+*/
+
+/*!
+ \fn const QVector3D operator/(const QVector3D &vector, qreal divisor)
+ \relates QVector3D
+
+ Returns the QVector3D object formed by dividing all three components of
+ the given \a vector by the given \a divisor.
+
+ \sa QVector3D::operator/=()
+*/
+
+/*!
+ \fn bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2)
+ \relates QVector3D
+
+ Returns true if \a v1 and \a v2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ Returns the 2D vector form of this 3D vector, dropping the z coordinate.
+
+ \sa toVector4D(), toPoint()
+*/
+QVector2D QVector3D::toVector2D() const
+{
+ return QVector2D(xp, yp, 1);
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ Returns the 4D form of this 3D vector, with the w coordinate set to zero.
+
+ \sa toVector2D(), toPoint()
+*/
+QVector4D QVector3D::toVector4D() const
+{
+ return QVector4D(xp, yp, zp, 0.0f, 1);
+}
+
+#endif
+
+/*!
+ \fn QPoint QVector3D::toPoint() const
+
+ Returns the QPoint form of this 3D vector.
+
+ \sa toPointF(), toVector2D()
+*/
+
+/*!
+ \fn QPointF QVector3D::toPointF() const
+
+ Returns the QPointF form of this 3D vector.
+
+ \sa toPoint(), toVector2D()
+*/
+
+/*!
+ Returns the length of the vector from the origin.
+
+ \sa lengthSquared(), normalized()
+*/
+qreal QVector3D::length() const
+{
+ return qSqrt(xp * xp + yp * yp + zp * zp);
+}
+
+/*!
+ Returns the squared length of the vector from the origin.
+ This is equivalent to the dot product of the vector with itself.
+
+ \sa length(), dotProduct()
+*/
+qreal QVector3D::lengthSquared() const
+{
+ return xp * xp + yp * yp + zp * zp;
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, const QVector3D &vector)
+{
+ dbg.nospace() << "QVector3D("
+ << vector.x() << ", " << vector.y() << ", " << vector.z() << ')';
+ return dbg.space();
+}
+
+#endif
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h
new file mode 100644
index 0000000..02873f2
--- /dev/null
+++ b/src/gui/math3d/qvector3d.h
@@ -0,0 +1,284 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QVECTOR3D_H
+#define QVECTOR3D_H
+
+#include <QtCore/qpoint.h>
+#include <QtCore/qmetatype.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QMatrix4x4;
+class QVector2D;
+class QVector4D;
+class QQuaternion;
+
+#ifndef QT_NO_VECTOR3D
+
+class Q_GUI_EXPORT QVector3D
+{
+public:
+ QVector3D();
+ QVector3D(qreal xpos, qreal ypos, qreal zpos);
+ explicit QVector3D(const QPoint& point);
+ explicit QVector3D(const QPointF& point);
+#ifndef QT_NO_VECTOR2D
+ QVector3D(const QVector2D& vector);
+ QVector3D(const QVector2D& vector, qreal zpos);
+#endif
+#ifndef QT_NO_VECTOR4D
+ explicit QVector3D(const QVector4D& vector);
+#endif
+
+ bool isNull() const;
+
+ qreal x() const;
+ qreal y() const;
+ qreal z() const;
+
+ void setX(qreal x);
+ void setY(qreal y);
+ void setZ(qreal z);
+
+ qreal length() const;
+ qreal lengthSquared() const;
+
+ QVector3D normalized() const;
+ void normalize();
+
+ QVector3D &operator+=(const QVector3D &vector);
+ QVector3D &operator-=(const QVector3D &vector);
+ QVector3D &operator*=(qreal factor);
+ QVector3D &operator*=(const QVector3D& vector);
+ QVector3D &operator/=(qreal divisor);
+
+ static qreal dotProduct(const QVector3D& v1, const QVector3D& v2);
+ static QVector3D crossProduct(const QVector3D& v1, const QVector3D& v2);
+ static QVector3D normal(const QVector3D& v1, const QVector3D& v2);
+ static QVector3D normal
+ (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3);
+
+ qreal distanceToPlane(const QVector3D& plane, const QVector3D& normal) const;
+ qreal distanceToPlane(const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const;
+ qreal distanceToLine(const QVector3D& point, const QVector3D& direction) const;
+
+ friend inline bool operator==(const QVector3D &v1, const QVector3D &v2);
+ friend inline bool operator!=(const QVector3D &v1, const QVector3D &v2);
+ friend inline const QVector3D operator+(const QVector3D &v1, const QVector3D &v2);
+ friend inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2);
+ friend inline const QVector3D operator*(qreal factor, const QVector3D &vector);
+ friend inline const QVector3D operator*(const QVector3D &vector, qreal factor);
+ friend const QVector3D operator*(const QVector3D &v1, const QVector3D& v2);
+ friend inline const QVector3D operator-(const QVector3D &vector);
+ friend inline const QVector3D operator/(const QVector3D &vector, qreal divisor);
+
+ friend inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2);
+
+#ifndef QT_NO_VECTOR2D
+ QVector2D toVector2D() const;
+#endif
+#ifndef QT_NO_VECTOR4D
+ QVector4D toVector4D() const;
+#endif
+
+ QPoint toPoint() const;
+ QPointF toPointF() const;
+
+private:
+ float xp, yp, zp;
+
+ QVector3D(float xpos, float ypos, float zpos, int dummy);
+
+ friend class QVector2D;
+ friend class QVector4D;
+ friend class QQuaternion;
+ friend class QMatrix4x4;
+#ifndef QT_NO_MATRIX4X4
+ friend QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix);
+ friend QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector);
+#endif
+};
+
+inline QVector3D::QVector3D() : xp(0.0f), yp(0.0f), zp(0.0f) {}
+
+inline QVector3D::QVector3D(qreal xpos, qreal ypos, qreal zpos) : xp(xpos), yp(ypos), zp(zpos) {}
+
+inline QVector3D::QVector3D(float xpos, float ypos, float zpos, int) : xp(xpos), yp(ypos), zp(zpos) {}
+
+inline QVector3D::QVector3D(const QPoint& point) : xp(point.x()), yp(point.y()), zp(0.0f) {}
+
+inline QVector3D::QVector3D(const QPointF& point) : xp(point.x()), yp(point.y()), zp(0.0f) {}
+
+inline bool QVector3D::isNull() const
+{
+ return qIsNull(xp) && qIsNull(yp) && qIsNull(zp);
+}
+
+inline qreal QVector3D::x() const { return qreal(xp); }
+inline qreal QVector3D::y() const { return qreal(yp); }
+inline qreal QVector3D::z() const { return qreal(zp); }
+
+inline void QVector3D::setX(qreal x) { xp = x; }
+inline void QVector3D::setY(qreal y) { yp = y; }
+inline void QVector3D::setZ(qreal z) { zp = z; }
+
+inline QVector3D &QVector3D::operator+=(const QVector3D &vector)
+{
+ xp += vector.xp;
+ yp += vector.yp;
+ zp += vector.zp;
+ return *this;
+}
+
+inline QVector3D &QVector3D::operator-=(const QVector3D &vector)
+{
+ xp -= vector.xp;
+ yp -= vector.yp;
+ zp -= vector.zp;
+ return *this;
+}
+
+inline QVector3D &QVector3D::operator*=(qreal factor)
+{
+ xp *= factor;
+ yp *= factor;
+ zp *= factor;
+ return *this;
+}
+
+inline QVector3D &QVector3D::operator*=(const QVector3D& vector)
+{
+ xp *= vector.xp;
+ yp *= vector.yp;
+ zp *= vector.zp;
+ return *this;
+}
+
+inline QVector3D &QVector3D::operator/=(qreal divisor)
+{
+ xp /= divisor;
+ yp /= divisor;
+ zp /= divisor;
+ return *this;
+}
+
+inline bool operator==(const QVector3D &v1, const QVector3D &v2)
+{
+ return v1.xp == v2.xp && v1.yp == v2.yp && v1.zp == v2.zp;
+}
+
+inline bool operator!=(const QVector3D &v1, const QVector3D &v2)
+{
+ return v1.xp != v2.xp || v1.yp != v2.yp || v1.zp != v2.zp;
+}
+
+inline const QVector3D operator+(const QVector3D &v1, const QVector3D &v2)
+{
+ return QVector3D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp, 1);
+}
+
+inline const QVector3D operator-(const QVector3D &v1, const QVector3D &v2)
+{
+ return QVector3D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp, 1);
+}
+
+inline const QVector3D operator*(qreal factor, const QVector3D &vector)
+{
+ return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor, 1);
+}
+
+inline const QVector3D operator*(const QVector3D &vector, qreal factor)
+{
+ return QVector3D(vector.xp * factor, vector.yp * factor, vector.zp * factor, 1);
+}
+
+inline const QVector3D operator*(const QVector3D &v1, const QVector3D& v2)
+{
+ return QVector3D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp, 1);
+}
+
+inline const QVector3D operator-(const QVector3D &vector)
+{
+ return QVector3D(-vector.xp, -vector.yp, -vector.zp, 1);
+}
+
+inline const QVector3D operator/(const QVector3D &vector, qreal divisor)
+{
+ return QVector3D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, 1);
+}
+
+inline bool qFuzzyCompare(const QVector3D& v1, const QVector3D& v2)
+{
+ return qFuzzyCompare(v1.xp, v2.xp) &&
+ qFuzzyCompare(v1.yp, v2.yp) &&
+ qFuzzyCompare(v1.zp, v2.zp);
+}
+
+inline QPoint QVector3D::toPoint() const
+{
+ return QPoint(qRound(xp), qRound(yp));
+}
+
+inline QPointF QVector3D::toPointF() const
+{
+ return QPointF(qreal(xp), qreal(yp));
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector3D &vector);
+#endif
+
+#endif
+
+QT_END_NAMESPACE
+
+#ifndef QT_NO_VECTOR3D
+Q_DECLARE_METATYPE(QVector3D)
+#endif
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp
new file mode 100644
index 0000000..010fa53
--- /dev/null
+++ b/src/gui/math3d/qvector4d.cpp
@@ -0,0 +1,518 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qvector4d.h"
+#include "qvector3d.h"
+#include "qvector2d.h"
+#include <QtCore/qdebug.h>
+#include <QtCore/qmath.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_VECTOR4D
+
+/*!
+ \class QVector4D
+ \brief The QVector4D class represents a vector or vertex in 4D space.
+ \since 4.6
+
+ The QVector4D class can also be used to represent vertices in 4D space.
+ We therefore do not need to provide a separate vertex class.
+
+ The coordinates are stored internally using the most efficient
+ representation for the GL rendering engine, which will be either
+ floating-point or fixed-point.
+
+ \sa QQuaternion, QVector2D, QVector3D
+*/
+
+/*!
+ \fn QVector4D::QVector4D()
+
+ Constructs a null vector, i.e. with coordinates (0, 0, 0, 0).
+*/
+
+/*!
+ \fn QVector4D::QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos)
+
+ Constructs a vector with coordinates (\a xpos, \a ypos, \a zpos, \a wpos).
+*/
+
+/*!
+ \fn QVector4D::QVector4D(const QPoint& point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and
+ z and w coordinates of 0.
+*/
+
+/*!
+ \fn QVector4D::QVector4D(const QPointF& point)
+
+ Constructs a vector with x and y coordinates from a 2D \a point, and
+ z and w coordinates of 0.
+*/
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ Constructs a 4D vector from the specified 2D \a vector. The z
+ and w coordinates are set to zero.
+
+ \sa toVector2D()
+*/
+QVector4D::QVector4D(const QVector2D& vector)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = 0.0f;
+ wp = 0.0f;
+}
+
+/*!
+ Constructs a 4D vector from the specified 2D \a vector. The z
+ and w coordinates are set to \a zpos and \a wpos respectively.
+
+ \sa toVector2D()
+*/
+QVector4D::QVector4D(const QVector2D& vector, qreal zpos, qreal wpos)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = zpos;
+ wp = wpos;
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Constructs a 4D vector from the specified 3D \a vector. The w
+ coordinate is set to zero.
+
+ \sa toVector3D()
+*/
+QVector4D::QVector4D(const QVector3D& vector)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = vector.zp;
+ wp = 0.0f;
+}
+
+/*!
+ Constructs a 4D vector from the specified 3D \a vector. The w
+ coordinate is set to \a wpos.
+
+ \sa toVector3D()
+*/
+QVector4D::QVector4D(const QVector3D& vector, qreal wpos)
+{
+ xp = vector.xp;
+ yp = vector.yp;
+ zp = vector.zp;
+ wp = wpos;
+}
+
+#endif
+
+/*!
+ \fn bool QVector4D::isNull() const
+
+ Returns true if the x, y, z, and w coordinates are set to 0.0,
+ otherwise returns false.
+*/
+
+/*!
+ \fn qreal QVector4D::x() const
+
+ Returns the x coordinate of this point.
+
+ \sa setX(), y(), z(), w()
+*/
+
+/*!
+ \fn qreal QVector4D::y() const
+
+ Returns the y coordinate of this point.
+
+ \sa setY(), x(), z(), w()
+*/
+
+/*!
+ \fn qreal QVector4D::z() const
+
+ Returns the z coordinate of this point.
+
+ \sa setZ(), x(), y(), w()
+*/
+
+/*!
+ \fn qreal QVector4D::w() const
+
+ Returns the w coordinate of this point.
+
+ \sa setW(), x(), y(), z()
+*/
+
+/*!
+ \fn void QVector4D::setX(qreal x)
+
+ Sets the x coordinate of this point to the given \a x coordinate.
+
+ \sa x(), setY(), setZ(), setW()
+*/
+
+/*!
+ \fn void QVector4D::setY(qreal y)
+
+ Sets the y coordinate of this point to the given \a y coordinate.
+
+ \sa y(), setX(), setZ(), setW()
+*/
+
+/*!
+ \fn void QVector4D::setZ(qreal z)
+
+ Sets the z coordinate of this point to the given \a z coordinate.
+
+ \sa z(), setX(), setY(), setW()
+*/
+
+/*!
+ \fn void QVector4D::setW(qreal w)
+
+ Sets the w coordinate of this point to the given \a w coordinate.
+
+ \sa w(), setX(), setY(), setZ()
+*/
+
+/*!
+ Returns the length of the vector from the origin.
+
+ \sa lengthSquared(), normalized()
+*/
+qreal QVector4D::length() const
+{
+ return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
+}
+
+/*!
+ Returns the squared length of the vector from the origin.
+ This is equivalent to the dot product of the vector with itself.
+
+ \sa length(), dotProduct()
+*/
+qreal QVector4D::lengthSquared() const
+{
+ return xp * xp + yp * yp + zp * zp + wp * wp;
+}
+
+/*!
+ Returns the normalized unit vector form of this vector.
+
+ If this vector is null, then a null vector is returned. If the length
+ of the vector is very close to 1, then the vector will be returned as-is.
+ Otherwise the normalized form of the vector of length 1 will be returned.
+
+ \sa length(), normalize()
+*/
+QVector4D QVector4D::normalized() const
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f))
+ return *this;
+ else if (!qFuzzyIsNull(len))
+ return *this / qSqrt(len);
+ else
+ return QVector4D();
+}
+
+/*!
+ Normalizes the currect vector in place. Nothing happens if this
+ vector is a null vector or the length of the vector is very close to 1.
+
+ \sa length(), normalized()
+*/
+void QVector4D::normalize()
+{
+ qreal len = lengthSquared();
+ if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
+ return;
+
+ len = qSqrt(len);
+
+ xp /= len;
+ yp /= len;
+ zp /= len;
+ wp /= len;
+}
+
+/*!
+ \fn QVector4D &QVector4D::operator+=(const QVector4D &vector)
+
+ Adds the given \a vector to this vector and returns a reference to
+ this vector.
+
+ \sa operator-=()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator-=(const QVector4D &vector)
+
+ Subtracts the given \a vector from this vector and returns a reference to
+ this vector.
+
+ \sa operator+=()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator*=(qreal factor)
+
+ Multiplies this vector's coordinates by the given \a factor, and
+ returns a reference to this vector.
+
+ \sa operator/=()
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator*=(const QVector4D &vector)
+
+ Multiplies the components of this vector by the corresponding
+ components in \a vector.
+*/
+
+/*!
+ \fn QVector4D &QVector4D::operator/=(qreal divisor)
+
+ Divides this vector's coordinates by the given \a divisor, and
+ returns a reference to this vector.
+
+ \sa operator*=()
+*/
+
+/*!
+ Returns the dot product of \a v1 and \a v2.
+*/
+qreal QVector4D::dotProduct(const QVector4D& v1, const QVector4D& v2)
+{
+ return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp + v1.wp * v2.wp;
+}
+
+/*!
+ \fn bool operator==(const QVector4D &v1, const QVector4D &v2)
+ \relates QVector4D
+
+ Returns true if \a v1 is equal to \a v2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn bool operator!=(const QVector4D &v1, const QVector4D &v2)
+ \relates QVector4D
+
+ Returns true if \a v1 is not equal to \a v2; otherwise returns false.
+ This operator uses an exact floating-point comparison.
+*/
+
+/*!
+ \fn const QVector4D operator+(const QVector4D &v1, const QVector4D &v2)
+ \relates QVector4D
+
+ Returns a QVector4D object that is the sum of the given vectors, \a v1
+ and \a v2; each component is added separately.
+
+ \sa QVector4D::operator+=()
+*/
+
+/*!
+ \fn const QVector4D operator-(const QVector4D &v1, const QVector4D &v2)
+ \relates QVector4D
+
+ Returns a QVector4D object that is formed by subtracting \a v2 from \a v1;
+ each component is subtracted separately.
+
+ \sa QVector4D::operator-=()
+*/
+
+/*!
+ \fn const QVector4D operator*(qreal factor, const QVector4D &vector)
+ \relates QVector4D
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector4D::operator*=()
+*/
+
+/*!
+ \fn const QVector4D operator*(const QVector4D &vector, qreal factor)
+ \relates QVector4D
+
+ Returns a copy of the given \a vector, multiplied by the given \a factor.
+
+ \sa QVector4D::operator*=()
+*/
+
+/*!
+ \fn const QVector4D operator*(const QVector4D &v1, const QVector4D& v2)
+ \relates QVector4D
+
+ Returns the vector consisting of the multiplication of the
+ components from \a v1 and \a v2.
+
+ \sa QVector4D::operator*=()
+*/
+
+/*!
+ \fn const QVector4D operator-(const QVector4D &vector)
+ \relates QVector4D
+ \overload
+
+ Returns a QVector4D object that is formed by changing the sign of
+ all three components of the given \a vector.
+
+ Equivalent to \c {QVector4D(0,0,0,0) - vector}.
+*/
+
+/*!
+ \fn const QVector4D operator/(const QVector4D &vector, qreal divisor)
+ \relates QVector4D
+
+ Returns the QVector4D object formed by dividing all four components of
+ the given \a vector by the given \a divisor.
+
+ \sa QVector4D::operator/=()
+*/
+
+/*!
+ \fn bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2)
+ \relates QVector4D
+
+ Returns true if \a v1 and \a v2 are equal, allowing for a small
+ fuzziness factor for floating-point comparisons; false otherwise.
+*/
+
+#ifndef QT_NO_VECTOR2D
+
+/*!
+ Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
+
+ \sa toVector2DAffine(), toVector3D(), toPoint()
+*/
+QVector2D QVector4D::toVector2D() const
+{
+ return QVector2D(xp, yp, 1);
+}
+
+/*!
+ Returns the 2D vector form of this 4D vector, dividing the x and y
+ coordinates by the w coordinate and dropping the z coordinate.
+ Returns a null vector if w is zero.
+
+ \sa toVector2D(), toVector3DAffine(), toPoint()
+*/
+QVector2D QVector4D::toVector2DAffine() const
+{
+ if (qIsNull(wp))
+ return QVector2D();
+ return QVector2D(xp / wp, yp / wp, 1);
+}
+
+#endif
+
+#ifndef QT_NO_VECTOR3D
+
+/*!
+ Returns the 3D vector form of this 4D vector, dropping the w coordinate.
+
+ \sa toVector3DAffine(), toVector2D(), toPoint()
+*/
+QVector3D QVector4D::toVector3D() const
+{
+ return QVector3D(xp, yp, zp, 1);
+}
+
+/*!
+ Returns the 3D vector form of this 4D vector, dividing the x, y, and
+ z coordinates by the w coordinate. Returns a null vector if w is zero.
+
+ \sa toVector3D(), toVector2DAffine(), toPoint()
+*/
+QVector3D QVector4D::toVector3DAffine() const
+{
+ if (qIsNull(wp))
+ return QVector3D();
+ return QVector3D(xp / wp, yp / wp, zp / wp, 1);
+}
+
+#endif
+
+/*!
+ \fn QPoint QVector4D::toPoint() const
+
+ Returns the QPoint form of this 4D vector.
+
+ \sa toPointF(), toVector2D()
+*/
+
+/*!
+ \fn QPointF QVector4D::toPointF() const
+
+ Returns the QPointF form of this 4D vector.
+
+ \sa toPoint(), toVector2D()
+*/
+
+#ifndef QT_NO_DEBUG_STREAM
+
+QDebug operator<<(QDebug dbg, const QVector4D &vector)
+{
+ dbg.nospace() << "QVector4D("
+ << vector.x() << ", " << vector.y() << ", "
+ << vector.z() << ", " << vector.w() << ')';
+ return dbg.space();
+}
+
+#endif
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h
new file mode 100644
index 0000000..8e673f3
--- /dev/null
+++ b/src/gui/math3d/qvector4d.h
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QVECTOR4D_H
+#define QVECTOR4D_H
+
+#include <QtCore/qpoint.h>
+#include <QtCore/qmetatype.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QMatrix4x4;
+class QVector2D;
+class QVector3D;
+class QQuaternion;
+
+#ifndef QT_NO_VECTOR4D
+
+class Q_GUI_EXPORT QVector4D
+{
+public:
+ QVector4D();
+ QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos);
+ explicit QVector4D(const QPoint& point);
+ explicit QVector4D(const QPointF& point);
+#ifndef QT_NO_VECTOR2D
+ QVector4D(const QVector2D& vector);
+ QVector4D(const QVector2D& vector, qreal zpos, qreal wpos);
+#endif
+#ifndef QT_NO_VECTOR3D
+ QVector4D(const QVector3D& vector);
+ QVector4D(const QVector3D& vector, qreal wpos);
+#endif
+
+ bool isNull() const;
+
+ qreal x() const;
+ qreal y() const;
+ qreal z() const;
+ qreal w() const;
+
+ void setX(qreal x);
+ void setY(qreal y);
+ void setZ(qreal z);
+ void setW(qreal w);
+
+ qreal length() const;
+ qreal lengthSquared() const;
+
+ QVector4D normalized() const;
+ void normalize();
+
+ QVector4D &operator+=(const QVector4D &vector);
+ QVector4D &operator-=(const QVector4D &vector);
+ QVector4D &operator*=(qreal factor);
+ QVector4D &operator*=(const QVector4D &vector);
+ QVector4D &operator/=(qreal divisor);
+
+ static qreal dotProduct(const QVector4D& v1, const QVector4D& v2);
+
+ friend inline bool operator==(const QVector4D &v1, const QVector4D &v2);
+ friend inline bool operator!=(const QVector4D &v1, const QVector4D &v2);
+ friend inline const QVector4D operator+(const QVector4D &v1, const QVector4D &v2);
+ friend inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2);
+ friend inline const QVector4D operator*(qreal factor, const QVector4D &vector);
+ friend inline const QVector4D operator*(const QVector4D &vector, qreal factor);
+ friend inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2);
+ friend inline const QVector4D operator-(const QVector4D &vector);
+ friend inline const QVector4D operator/(const QVector4D &vector, qreal divisor);
+
+ friend inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2);
+
+#ifndef QT_NO_VECTOR2D
+ QVector2D toVector2D() const;
+ QVector2D toVector2DAffine() const;
+#endif
+#ifndef QT_NO_VECTOR3D
+ QVector3D toVector3D() const;
+ QVector3D toVector3DAffine() const;
+#endif
+
+ QPoint toPoint() const;
+ QPointF toPointF() const;
+
+private:
+ float xp, yp, zp, wp;
+
+ QVector4D(float xpos, float ypos, float zpos, float wpos, int dummy);
+
+ friend class QVector2D;
+ friend class QVector3D;
+ friend class QQuaternion;
+ friend class QMatrix4x4;
+#ifndef QT_NO_MATRIX4X4
+ friend QVector4D operator*(const QVector4D& vector, const QMatrix4x4& matrix);
+ friend QVector4D operator*(const QMatrix4x4& matrix, const QVector4D& vector);
+#endif
+};
+
+inline QVector4D::QVector4D() : xp(0.0f), yp(0.0f), zp(0.0f), wp(0.0f) {}
+
+inline QVector4D::QVector4D(qreal xpos, qreal ypos, qreal zpos, qreal wpos) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {}
+
+inline QVector4D::QVector4D(float xpos, float ypos, float zpos, float wpos, int) : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {}
+
+inline QVector4D::QVector4D(const QPoint& point) : xp(point.x()), yp(point.y()), zp(0.0f), wp(0.0f) {}
+
+inline QVector4D::QVector4D(const QPointF& point) : xp(point.x()), yp(point.y()), zp(0.0f), wp(0.0f) {}
+
+inline bool QVector4D::isNull() const
+{
+ return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && qIsNull(wp);
+}
+
+inline qreal QVector4D::x() const { return qreal(xp); }
+inline qreal QVector4D::y() const { return qreal(yp); }
+inline qreal QVector4D::z() const { return qreal(zp); }
+inline qreal QVector4D::w() const { return qreal(wp); }
+
+inline void QVector4D::setX(qreal x) { xp = x; }
+inline void QVector4D::setY(qreal y) { yp = y; }
+inline void QVector4D::setZ(qreal z) { zp = z; }
+inline void QVector4D::setW(qreal w) { wp = w; }
+
+inline QVector4D &QVector4D::operator+=(const QVector4D &vector)
+{
+ xp += vector.xp;
+ yp += vector.yp;
+ zp += vector.zp;
+ wp += vector.wp;
+ return *this;
+}
+
+inline QVector4D &QVector4D::operator-=(const QVector4D &vector)
+{
+ xp -= vector.xp;
+ yp -= vector.yp;
+ zp -= vector.zp;
+ wp -= vector.wp;
+ return *this;
+}
+
+inline QVector4D &QVector4D::operator*=(qreal factor)
+{
+ xp *= factor;
+ yp *= factor;
+ zp *= factor;
+ wp *= factor;
+ return *this;
+}
+
+inline QVector4D &QVector4D::operator*=(const QVector4D &vector)
+{
+ xp *= vector.xp;
+ yp *= vector.yp;
+ zp *= vector.zp;
+ wp *= vector.wp;
+ return *this;
+}
+
+inline QVector4D &QVector4D::operator/=(qreal divisor)
+{
+ xp /= divisor;
+ yp /= divisor;
+ zp /= divisor;
+ wp /= divisor;
+ return *this;
+}
+
+inline bool operator==(const QVector4D &v1, const QVector4D &v2)
+{
+ return v1.xp == v2.xp && v1.yp == v2.yp && v1.zp == v2.zp && v1.wp == v2.wp;
+}
+
+inline bool operator!=(const QVector4D &v1, const QVector4D &v2)
+{
+ return v1.xp != v2.xp || v1.yp != v2.yp || v1.zp != v2.zp || v1.wp != v2.wp;
+}
+
+inline const QVector4D operator+(const QVector4D &v1, const QVector4D &v2)
+{
+ return QVector4D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp, v1.wp + v2.wp, 1);
+}
+
+inline const QVector4D operator-(const QVector4D &v1, const QVector4D &v2)
+{
+ return QVector4D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp, v1.wp - v2.wp, 1);
+}
+
+inline const QVector4D operator*(qreal factor, const QVector4D &vector)
+{
+ return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1);
+}
+
+inline const QVector4D operator*(const QVector4D &vector, qreal factor)
+{
+ return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1);
+}
+
+inline const QVector4D operator*(const QVector4D &v1, const QVector4D& v2)
+{
+ return QVector4D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp, v1.wp * v2.wp, 1);
+}
+
+inline const QVector4D operator-(const QVector4D &vector)
+{
+ return QVector4D(-vector.xp, -vector.yp, -vector.zp, -vector.wp, 1);
+}
+
+inline const QVector4D operator/(const QVector4D &vector, qreal divisor)
+{
+ return QVector4D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, vector.wp / divisor, 1);
+}
+
+inline bool qFuzzyCompare(const QVector4D& v1, const QVector4D& v2)
+{
+ return qFuzzyCompare(v1.xp, v2.xp) &&
+ qFuzzyCompare(v1.yp, v2.yp) &&
+ qFuzzyCompare(v1.zp, v2.zp) &&
+ qFuzzyCompare(v1.wp, v2.wp);
+}
+
+inline QPoint QVector4D::toPoint() const
+{
+ return QPoint(qRound(xp), qRound(yp));
+}
+
+inline QPointF QVector4D::toPointF() const
+{
+ return QPointF(qreal(xp), qreal(yp));
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QVector4D &vector);
+#endif
+
+#endif
+
+QT_END_NAMESPACE
+
+#ifndef QT_NO_VECTOR4D
+Q_DECLARE_METATYPE(QVector4D)
+#endif
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri
index 528559c..34d1779 100644
--- a/src/gui/painting/painting.pri
+++ b/src/gui/painting/painting.pri
@@ -103,12 +103,6 @@ win32 {
painting/qprinterinfo_win.cpp \
painting/qregion_win.cpp
!win32-borland:!wince*:LIBS += -lmsimg32
- contains(QT_CONFIG, direct3d) {
- HEADERS += painting/qpaintengine_d3d_p.h
- SOURCES += painting/qpaintengine_d3d.cpp
- RESOURCES += painting/qpaintengine_d3d.qrc
- LIBS += -ldxguid
- }
}
embedded {
@@ -362,8 +356,4 @@ embedded {
SOURCES += painting/qwindowsurface_qws.cpp
}
-win32:contains(QT_CONFIG, direct3d) {
- HEADERS += painting/qwindowsurface_d3d_p.h
- SOURCES += painting/qwindowsurface_d3d.cpp
-}
diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp
index 8317dd8..7ed521e 100644
--- a/src/gui/painting/qbezier.cpp
+++ b/src/gui/painting/qbezier.cpp
@@ -127,13 +127,13 @@ static inline void flattenBezierWithoutInflections(QBezier &bez,
qreal dy = bez.y2 - bez.y1;
qreal normalized = qSqrt(dx * dx + dy * dy);
- if (qFuzzyCompare(normalized + 1, 1))
+ if (qFuzzyIsNull(normalized))
break;
qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2));
qreal t = qSqrt(4. / 3. * normalized * flatness / d);
- if (t > 1 || qFuzzyCompare(t, (qreal)1.))
+ if (t > 1 || qFuzzyIsNull(t - (qreal)1.))
break;
bez.parameterSplitLeft(t, &left);
p->append(bez.pt1());
@@ -144,19 +144,19 @@ static inline void flattenBezierWithoutInflections(QBezier &bez,
static inline int quadraticRoots(qreal a, qreal b, qreal c,
qreal *x1, qreal *x2)
{
- if (qFuzzyCompare(a + 1, 1)) {
- if (qFuzzyCompare(b + 1, 1))
+ if (qFuzzyIsNull(a)) {
+ if (qFuzzyIsNull(b))
return 0;
*x1 = *x2 = (-c / b);
return 1;
} else {
const qreal det = b * b - 4 * a * c;
- if (qFuzzyCompare(det + 1, 1)) {
+ if (qFuzzyIsNull(det)) {
*x1 = *x2 = -b / (2 * a);
return 1;
}
if (det > 0) {
- if (qFuzzyCompare(b + 1, 1)) {
+ if (qFuzzyIsNull(b)) {
*x2 = qSqrt(-c / a);
*x1 = -(*x2);
return 2;
@@ -187,7 +187,7 @@ static inline bool findInflections(qreal a, qreal b, qreal c,
*t1 = r2;
*t2 = r1;
}
- if (!qFuzzyCompare(a + 1, 1))
+ if (!qFuzzyIsNull(a))
*tCups = 0.5 * (-b / a);
else
*tCups = 2;
@@ -243,7 +243,7 @@ void QBezier::addToPolygonMixed(QPolygonF *polygon) const
qreal b = 6 * (ay * cx - ax * cy);
qreal c = 2 * (by * cx - bx * cy);
- if ((qFuzzyCompare(a + 1, 1) && qFuzzyCompare(b + 1, 1)) ||
+ if ((qFuzzyIsNull(a) && qFuzzyIsNull(b)) ||
(b * b - 4 * a *c) < 0) {
QBezier bez(*this);
flattenBezierWithoutInflections(bez, polygon);
@@ -447,7 +447,7 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr
qreal r = 1.0 + prev_normal.x() * next_normal.x()
+ prev_normal.y() * next_normal.y();
- if (qFuzzyCompare(r + 1, 1)) {
+ if (qFuzzyIsNull(r)) {
points_shifted[i] = points[i] + offset * prev_normal;
} else {
qreal k = offset / r;
@@ -477,12 +477,12 @@ static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2);
qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y());
- if (qFuzzyCompare(dist + 1, 1))
+ if (qFuzzyIsNull(dist))
return false;
normals[0] /= dist;
normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4);
dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y());
- if (qFuzzyCompare(dist + 1, 1))
+ if (qFuzzyIsNull(dist))
return false;
normals[2] /= dist;
@@ -1022,7 +1022,7 @@ int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const
QList<qreal> result;
- if (qFuzzyCompare(reciprocal + 1, 1)) {
+ if (qFuzzyIsNull(reciprocal)) {
t0 = -b / (2 * a);
return 1;
} else if (reciprocal > 0) {
diff --git a/src/gui/painting/qblendfunctions.cpp b/src/gui/painting/qblendfunctions.cpp
index 93f11e1..8f4a2bf 100644
--- a/src/gui/painting/qblendfunctions.cpp
+++ b/src/gui/painting/qblendfunctions.cpp
@@ -513,11 +513,10 @@ static void qt_blend_argb32_on_argb32(uchar *destPixels, int dbpl,
for (int y=0; y<h; ++y) {
for (int x=0; x<w; ++x) {
uint s = src[x];
- if ((s & 0xff000000) == 0xff000000)
+ if (s >= 0xff000000)
dst[x] = s;
- else {
+ else if (s != 0)
dst[x] = s + BYTE_MUL(dst[x], qAlpha(~s));
- }
}
dst = (quint32 *)(((uchar *) dst) + dbpl);
src = (const quint32 *)(((const uchar *) src) + sbpl);
diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp
index 1723a19..534a425 100644
--- a/src/gui/painting/qcolor.cpp
+++ b/src/gui/painting/qcolor.cpp
@@ -1387,7 +1387,7 @@ QColor QColor::toHsv() const
const qreal min = Q_MIN_3(r, g, b);
const qreal delta = max - min;
color.ct.ahsv.value = qRound(max * USHRT_MAX);
- if (qFuzzyCompare(delta + 1, 1)) {
+ if (qFuzzyIsNull(delta)) {
// achromatic case, hue is undefined
color.ct.ahsv.hue = USHRT_MAX;
color.ct.ahsv.saturation = 0;
@@ -1441,7 +1441,7 @@ QColor QColor::toCmyk() const
// cmy -> cmyk
const qreal k = qMin(c, qMin(m, y));
- if (!qFuzzyCompare(k,1)) {
+ if (!qFuzzyIsNull(k - 1)) {
c = (c - k) / (1.0 - k);
m = (m - k) / (1.0 - k);
y = (y - k) / (1.0 - k);
diff --git a/src/gui/painting/qcolor_p.cpp b/src/gui/painting/qcolor_p.cpp
index 5bdbee4..fb6d10c 100644
--- a/src/gui/painting/qcolor_p.cpp
+++ b/src/gui/painting/qcolor_p.cpp
@@ -49,7 +49,7 @@
#include "qrgb.h"
#include "qstringlist.h"
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#include "qguifunctions_wince.h"
#endif
QT_BEGIN_NAMESPACE
diff --git a/src/gui/painting/qcolormap_win.cpp b/src/gui/painting/qcolormap_win.cpp
index 7d36582..9ca2521 100644
--- a/src/gui/painting/qcolormap_win.cpp
+++ b/src/gui/painting/qcolormap_win.cpp
@@ -44,7 +44,7 @@
#include "qvector.h"
#include "qt_windows.h"
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#include "qguifunctions_wince.h"
#endif
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index 9f2831d..fdd0c21 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -157,46 +157,9 @@ static uint * QT_FASTCALL destFetchRGB16(uint *buffer, QRasterBuffer *rasterBuff
return buffer;
}
-#if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
-template <typename EnumType, int value>
-class QEnumToType
-{
-public:
- inline EnumType operator()() const
- {
- return EnumType(value);
- }
-};
-template <QImage::Format format>
-class QImageFormatToType
-{
-public:
- inline QImage::Format operator()() const
- {
- return format;
- }
-};
-// Would have used QEnumToType instead of creating a specialized version for QImageFormatToType,
-// but that causes internal compiler error on VC6
-#define Q_TEMPLATE_IMAGEFORMAT_FIX(format) , const QImageFormatToType<format> &imageFormatType
-#define Q_TEMPLATE_IMAGEFORMAT_CALL(format) , QImageFormatToType<format>()
-#define Q_TEMPLATE_ENUM_FIX(Type, Value) , const QEnumToType<Type, Value> &enumTemplateType
-#define Q_TEMPLATE_ENUM_CALL(Type, Value) , QEnumToType<Type, Value>()
-#define Q_TEMPLATE_FIX(Type) , const QTypeInfo<Type> &templateType
-#define Q_TEMPLATE_CALL(Type) , QTypeInfo<Type>()
-#else
-#define Q_TEMPLATE_IMAGEFORMAT_FIX(format)
-#define Q_TEMPLATE_IMAGEFORMAT_CALL(format)
-#define Q_TEMPLATE_ENUM_FIX(Type, Value)
-#define Q_TEMPLATE_ENUM_CALL(Type, Value)
-#define Q_TEMPLATE_FIX(Type)
-#define Q_TEMPLATE_CALL(Type)
-#endif
-
template <class DST>
Q_STATIC_TEMPLATE_FUNCTION uint * QT_FASTCALL destFetch(uint *buffer, QRasterBuffer *rasterBuffer,
- int x, int y, int length
- Q_TEMPLATE_FIX(DST))
+ int x, int y, int length)
{
const DST *src = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x;
quint32 *dest = reinterpret_cast<quint32*>(buffer);
@@ -205,28 +168,7 @@ Q_STATIC_TEMPLATE_FUNCTION uint * QT_FASTCALL destFetch(uint *buffer, QRasterBuf
return buffer;
}
-#if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
-#define DEST_FETCH_DECL(DST) \
- static uint * QT_FASTCALL destFetch_##DST(uint *buffer, \
- QRasterBuffer *rasterBuffer, \
- int x, int y, int length) \
- { \
- return destFetch<DST>(buffer, rasterBuffer, x, y, length Q_TEMPLATE_CALL(DST)); \
- }
-
-DEST_FETCH_DECL(qargb8565)
-DEST_FETCH_DECL(qrgb666)
-DEST_FETCH_DECL(qargb6666)
-DEST_FETCH_DECL(qrgb555)
-DEST_FETCH_DECL(qrgb888)
-DEST_FETCH_DECL(qargb8555)
-DEST_FETCH_DECL(qrgb444)
-DEST_FETCH_DECL(qargb4444)
-#undef DEST_FETCH_DECL
-# define SPANFUNC_POINTER_DESTFETCH(Arg) destFetch_##Arg
-#else // !VC6 && !VC2002
# define SPANFUNC_POINTER_DESTFETCH(Arg) destFetch<Arg>
-#endif
static const DestFetchProc destFetchProc[QImage::NImageFormats] =
{
@@ -366,8 +308,7 @@ static void QT_FASTCALL destStoreRGB16(QRasterBuffer *rasterBuffer, int x, int y
template <class DST>
Q_STATIC_TEMPLATE_FUNCTION void QT_FASTCALL destStore(QRasterBuffer *rasterBuffer,
int x, int y,
- const uint *buffer, int length
- Q_TEMPLATE_FIX(DST))
+ const uint *buffer, int length)
{
DST *dest = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x;
const quint32p *src = reinterpret_cast<const quint32p*>(buffer);
@@ -375,28 +316,7 @@ Q_STATIC_TEMPLATE_FUNCTION void QT_FASTCALL destStore(QRasterBuffer *rasterBuffe
*dest++ = DST(*src++);
}
-#if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
-# define DEST_STORE_DECL(DST) \
- static void QT_FASTCALL destStore_##DST(QRasterBuffer *rasterBuffer, \
- int x, int y, \
- const uint *buffer, int length) \
- { \
- destStore<DST>(rasterBuffer, x, y, buffer, length Q_TEMPLATE_CALL(DST)); \
- }
-
-DEST_STORE_DECL(qargb8565)
-DEST_STORE_DECL(qrgb555)
-DEST_STORE_DECL(qrgb666)
-DEST_STORE_DECL(qargb6666)
-DEST_STORE_DECL(qargb8555)
-DEST_STORE_DECL(qrgb888)
-DEST_STORE_DECL(qrgb444)
-DEST_STORE_DECL(qargb4444)
-# undef DEST_FETCH_DECL
-# define SPANFUNC_POINTER_DESTSTORE(DEST) destStore_##DEST
-#else // !VC6 && !VC2002
# define SPANFUNC_POINTER_DESTSTORE(DEST) destStore<DEST>
-#endif
static const DestStoreProc destStoreProc[QImage::NImageFormats] =
{
@@ -425,10 +345,8 @@ static const DestStoreProc destStoreProc[QImage::NImageFormats] =
We need 5 fetch methods per surface type:
untransformed
- transformed
- transformed tiled
- transformed bilinear
- transformed bilinear tiled
+ transformed (tiled and not tiled)
+ transformed bilinear (tiled and not tiled)
We don't need bounds checks for untransformed, but we need them for the other ones.
@@ -436,14 +354,12 @@ static const DestStoreProc destStoreProc[QImage::NImageFormats] =
*/
template <QImage::Format format>
-Q_STATIC_TEMPLATE_FUNCTION uint QT_FASTCALL qt_fetchPixel(const uchar *scanLine, int x, const QVector<QRgb> *rgb
- Q_TEMPLATE_IMAGEFORMAT_FIX(format));
+Q_STATIC_TEMPLATE_FUNCTION uint QT_FASTCALL qt_fetchPixel(const uchar *scanLine, int x, const QVector<QRgb> *rgb);
template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_Mono>(const uchar *scanLine,
- int x, const QVector<QRgb> *rgb
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_Mono))
+ int x, const QVector<QRgb> *rgb)
{
bool pixel = scanLine[x>>3] & (0x80 >> (x & 7));
if (rgb) return PREMUL(rgb->at(pixel ? 1 : 0));
@@ -453,8 +369,7 @@ uint QT_FASTCALL qt_fetchPixel<QImage::Format_Mono>(const uchar *scanLine,
template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_MonoLSB>(const uchar *scanLine,
- int x, const QVector<QRgb> *rgb
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_MonoLSB))
+ int x, const QVector<QRgb> *rgb)
{
bool pixel = scanLine[x>>3] & (0x1 << (x & 7));
if (rgb) return PREMUL(rgb->at(pixel ? 1 : 0));
@@ -464,8 +379,7 @@ uint QT_FASTCALL qt_fetchPixel<QImage::Format_MonoLSB>(const uchar *scanLine,
template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_Indexed8>(const uchar *scanLine,
- int x, const QVector<QRgb> *rgb
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_Indexed8))
+ int x, const QVector<QRgb> *rgb)
{
return PREMUL(rgb->at(scanLine[x]));
}
@@ -473,8 +387,7 @@ uint QT_FASTCALL qt_fetchPixel<QImage::Format_Indexed8>(const uchar *scanLine,
template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32>(const uchar *scanLine,
- int x, const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB32))
+ int x, const QVector<QRgb> *)
{
return PREMUL(((const uint *)scanLine)[x]);
}
@@ -482,8 +395,7 @@ uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32>(const uchar *scanLine,
template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32_Premultiplied>(const uchar *scanLine,
- int x, const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB32_Premultiplied))
+ int x, const QVector<QRgb> *)
{
return ((const uint *)scanLine)[x];
}
@@ -491,8 +403,7 @@ uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32_Premultiplied>(const uchar
template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB16>(const uchar *scanLine,
- int x, const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB16))
+ int x, const QVector<QRgb> *)
{
return qConvertRgb16To32(((const ushort *)scanLine)[x]);
}
@@ -501,8 +412,7 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB8565_Premultiplied>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB8565_Premultiplied))
+ const QVector<QRgb> *)
{
const qargb8565 color = reinterpret_cast<const qargb8565*>(scanLine)[x];
return qt_colorConvert<quint32, qargb8565>(color, 0);
@@ -512,8 +422,7 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB666>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB666))
+ const QVector<QRgb> *)
{
const qrgb666 color = reinterpret_cast<const qrgb666*>(scanLine)[x];
return qt_colorConvert<quint32, qrgb666>(color, 0);
@@ -523,8 +432,7 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB6666_Premultiplied>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB6666_Premultiplied))
+ const QVector<QRgb> *)
{
const qargb6666 color = reinterpret_cast<const qargb6666*>(scanLine)[x];
return qt_colorConvert<quint32, qargb6666>(color, 0);
@@ -534,8 +442,7 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB555>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB555))
+ const QVector<QRgb> *)
{
const qrgb555 color = reinterpret_cast<const qrgb555*>(scanLine)[x];
return qt_colorConvert<quint32, qrgb555>(color, 0);
@@ -545,8 +452,7 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB8555_Premultiplied>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB8555_Premultiplied))
+ const QVector<QRgb> *)
{
const qargb8555 color = reinterpret_cast<const qargb8555*>(scanLine)[x];
return qt_colorConvert<quint32, qargb8555>(color, 0);
@@ -556,8 +462,7 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB888>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB888))
+ const QVector<QRgb> *)
{
const qrgb888 color = reinterpret_cast<const qrgb888*>(scanLine)[x];
return qt_colorConvert<quint32, qrgb888>(color, 0);
@@ -567,8 +472,7 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB444>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB444))
+ const QVector<QRgb> *)
{
const qrgb444 color = reinterpret_cast<const qrgb444*>(scanLine)[x];
return qt_colorConvert<quint32, qrgb444>(color, 0);
@@ -578,47 +482,24 @@ template<>
Q_STATIC_TEMPLATE_SPECIALIZATION
uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB4444_Premultiplied>(const uchar *scanLine,
int x,
- const QVector<QRgb> *
- Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB4444_Premultiplied))
+ const QVector<QRgb> *)
{
const qargb4444 color = reinterpret_cast<const qargb4444*>(scanLine)[x];
return qt_colorConvert<quint32, qargb4444>(color, 0);
}
-typedef uint (QT_FASTCALL *FetchPixelProc)(const uchar *scanLine, int x, const QVector<QRgb> *);
-
-#if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
-
-// explicit template instantiations needed to compile with VC6 and VC2002
-
-#define SPANFUNC_INSTANTIATION_FETCHPIXEL(Arg) \
- static inline uint fetchPixel_##Arg(const uchar * scanLine, int x, const QVector<QRgb> * rgb) \
-{ \
- return qt_fetchPixel<QImage::Arg>(scanLine, x, rgb Q_TEMPLATE_IMAGEFORMAT_CALL(QImage::Arg)); \
+template<>
+Q_STATIC_TEMPLATE_SPECIALIZATION
+uint QT_FASTCALL qt_fetchPixel<QImage::Format_Invalid>(const uchar *,
+ int ,
+ const QVector<QRgb> *)
+{
+ return 0;
}
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_Mono);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_MonoLSB);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_Indexed8);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB32_Premultiplied);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB32);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB16);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB8565_Premultiplied);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB666);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB6666_Premultiplied);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB555);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB8555_Premultiplied);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB888);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB444);
-SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB4444_Premultiplied);
-
-#undef SPANFUNC_INSTANTIATION_FETCHPIXEL
-
-#define SPANFUNC_POINTER_FETCHPIXEL(Arg) fetchPixel_##Arg
+typedef uint (QT_FASTCALL *FetchPixelProc)(const uchar *scanLine, int x, const QVector<QRgb> *);
-#else // !VC6 && !VC2002
-# define SPANFUNC_POINTER_FETCHPIXEL(Arg) qt_fetchPixel<QImage::Arg>
-#endif
+#define SPANFUNC_POINTER_FETCHPIXEL(Arg) qt_fetchPixel<QImage::Arg>
static const FetchPixelProc fetchPixelProc[QImage::NImageFormats] =
@@ -653,11 +534,11 @@ enum TextureBlendType {
template <QImage::Format format>
Q_STATIC_TEMPLATE_FUNCTION const uint * QT_FASTCALL qt_fetchUntransformed(uint *buffer, const Operator *, const QSpanData *data,
- int y, int x, int length Q_TEMPLATE_IMAGEFORMAT_FIX(format))
+ int y, int x, int length)
{
const uchar *scanLine = data->texture.scanLine(y);
for (int i = 0; i < length; ++i)
- buffer[i] = qt_fetchPixel<format>(scanLine, x + i, data->texture.colorTable Q_TEMPLATE_IMAGEFORMAT_CALL(format));
+ buffer[i] = qt_fetchPixel<format>(scanLine, x + i, data->texture.colorTable);
return buffer;
}
@@ -665,13 +546,15 @@ template <>
Q_STATIC_TEMPLATE_SPECIALIZATION const uint * QT_FASTCALL
qt_fetchUntransformed<QImage::Format_ARGB32_Premultiplied>(uint *, const Operator *,
const QSpanData *data,
- int y, int x, int Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB32_Premultiplied))
+ int y, int x, int)
{
const uchar *scanLine = data->texture.scanLine(y);
return ((const uint *)scanLine) + x;
}
-static const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *, const QSpanData *data,
+template<TextureBlendType blendType> /* either BlendTransformed or BlendTransformedTiled */
+Q_STATIC_TEMPLATE_FUNCTION
+const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *, const QSpanData *data,
int y, int x, int length)
{
FetchPixelProc fetch = fetchPixelProc[data->texture.format];
@@ -698,84 +581,23 @@ static const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *,
int px = fx >> 16;
int py = fy >> 16;
- bool out = (px < 0) || (px >= image_width)
- || (py < 0) || (py >= image_height);
+ if (blendType == BlendTransformedTiled) {
+ px %= image_width;
+ py %= image_height;
+ if (px < 0) px += image_width;
+ if (py < 0) py += image_height;
- const uchar *scanLine = data->texture.scanLine(py);
- *b = out ? uint(0) : fetch(scanLine, px, data->texture.colorTable);
- fx += fdx;
- fy += fdy;
- ++b;
- }
- } else {
- const qreal fdx = data->m11;
- const qreal fdy = data->m12;
- const qreal fdw = data->m13;
-
- qreal fx = data->m21 * cy + data->m11 * cx + data->dx;
- qreal fy = data->m22 * cy + data->m12 * cx + data->dy;
- qreal fw = data->m23 * cy + data->m13 * cx + data->m33;
-
- while (b < end) {
- const qreal iw = fw == 0 ? 1 : 1 / fw;
- const qreal tx = fx * iw;
- const qreal ty = fy * iw;
- const int px = int(tx) - (tx < 0);
- const int py = int(ty) - (ty < 0);
-
- bool out = (px < 0) || (px >= image_width)
- || (py < 0) || (py >= image_height);
-
- const uchar *scanLine = data->texture.scanLine(py);
- *b = out ? uint(0) : fetch(scanLine, px, data->texture.colorTable);
- fx += fdx;
- fy += fdy;
- fw += fdw;
- //force increment to avoid /0
- if (!fw) {
- fw += fdw;
+ const uchar *scanLine = data->texture.scanLine(py);
+ *b = fetch(scanLine, px, data->texture.colorTable);
+ } else {
+ if ((px < 0) || (px >= image_width)
+ || (py < 0) || (py >= image_height)) {
+ *b = uint(0);
+ } else {
+ const uchar *scanLine = data->texture.scanLine(py);
+ *b = fetch(scanLine, px, data->texture.colorTable);
+ }
}
- ++b;
- }
- }
-
- return buffer;
-}
-
-static const uint * QT_FASTCALL fetchTransformedTiled(uint *buffer, const Operator *, const QSpanData *data,
- int y, int x, int length)
-{
- FetchPixelProc fetch = fetchPixelProc[data->texture.format];
-
- int image_width = data->texture.width;
- int image_height = data->texture.height;
-
- const qreal cx = x + 0.5;
- const qreal cy = y + 0.5;
-
- const uint *end = buffer + length;
- uint *b = buffer;
- if (data->fast_matrix) {
- // The increment pr x in the scanline
- int fdx = (int)(data->m11 * fixed_scale);
- int fdy = (int)(data->m12 * fixed_scale);
-
- int fx = int((data->m21 * cy
- + data->m11 * cx + data->dx) * fixed_scale);
- int fy = int((data->m22 * cy
- + data->m12 * cx + data->dy) * fixed_scale);
-
- while (b < end) {
- int px = fx >> 16;
- int py = fy >> 16;
-
- px %= image_width;
- py %= image_height;
- if (px < 0) px += image_width;
- if (py < 0) py += image_height;
-
- const uchar *scanLine = data->texture.scanLine(py);
- *b = fetch(scanLine, px, data->texture.colorTable);
fx += fdx;
fy += fdy;
++b;
@@ -796,13 +618,23 @@ static const uint * QT_FASTCALL fetchTransformedTiled(uint *buffer, const Operat
int px = int(tx) - (tx < 0);
int py = int(ty) - (ty < 0);
- px %= image_width;
- py %= image_height;
- if (px < 0) px += image_width;
- if (py < 0) py += image_height;
+ if (blendType == BlendTransformedTiled) {
+ px %= image_width;
+ py %= image_height;
+ if (px < 0) px += image_width;
+ if (py < 0) py += image_height;
- const uchar *scanLine = data->texture.scanLine(py);
- *b = fetch(scanLine, px, data->texture.colorTable);
+ const uchar *scanLine = data->texture.scanLine(py);
+ *b = fetch(scanLine, px, data->texture.colorTable);
+ } else {
+ if ((px < 0) || (px >= image_width)
+ || (py < 0) || (py >= image_height)) {
+ *b = uint(0);
+ } else {
+ const uchar *scanLine = data->texture.scanLine(py);
+ *b = fetch(scanLine, px, data->texture.colorTable);
+ }
+ }
fx += fdx;
fy += fdy;
fw += fdw;
@@ -817,10 +649,12 @@ static const uint * QT_FASTCALL fetchTransformedTiled(uint *buffer, const Operat
return buffer;
}
-static const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator *, const QSpanData *data,
- int y, int x, int length)
+template<TextureBlendType blendType, QImage::Format format> /* blendType = BlendTransformedBilinear or BlendTransformedBilinearTiled */
+Q_STATIC_TEMPLATE_FUNCTION
+const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator *, const QSpanData *data,
+ int y, int x, int length)
{
- FetchPixelProc fetch = fetchPixelProc[data->texture.format];
+ FetchPixelProc fetch = (format != QImage::Format_Invalid) ? FetchPixelProc(qt_fetchPixel<format>) : fetchPixelProc[data->texture.format];
int image_width = data->texture.width;
int image_height = data->texture.height;
@@ -853,130 +687,27 @@ static const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Ope
int idistx = 256 - distx;
int idisty = 256 - disty;
- x1 = qBound(0, x1, image_width - 1);
- x2 = qBound(0, x2, image_width - 1);
- y1 = qBound(0, y1, image_height - 1);
- y2 = qBound(0, y2, image_height - 1);
-
- const uchar *s1 = data->texture.scanLine(y1);
- const uchar *s2 = data->texture.scanLine(y2);
-
- uint tl = fetch(s1, x1, data->texture.colorTable);
- uint tr = fetch(s1, x2, data->texture.colorTable);
- uint bl = fetch(s2, x1, data->texture.colorTable);
- uint br = fetch(s2, x2, data->texture.colorTable);
-
- uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
- uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
- *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
-
- fx += fdx;
- fy += fdy;
- ++b;
- }
- } else {
- const qreal fdx = data->m11;
- const qreal fdy = data->m12;
- const qreal fdw = data->m13;
-
- qreal fx = data->m21 * cy + data->m11 * cx + data->dx;
- qreal fy = data->m22 * cy + data->m12 * cx + data->dy;
- qreal fw = data->m23 * cy + data->m13 * cx + data->m33;
-
- while (b < end) {
- const qreal iw = fw == 0 ? 1 : 1 / fw;
- const qreal px = fx * iw - 0.5;
- const qreal py = fy * iw - 0.5;
-
- int x1 = int(px) - (px < 0);
- int x2 = x1 + 1;
- int y1 = int(py) - (py < 0);
- int y2 = y1 + 1;
-
- int distx = int((px - x1) * 256);
- int disty = int((py - y1) * 256);
- int idistx = 256 - distx;
- int idisty = 256 - disty;
-
- x1 = qBound(0, x1, image_width - 1);
- x2 = qBound(0, x2, image_width - 1);
- y1 = qBound(0, y1, image_height - 1);
- y2 = qBound(0, y2, image_height - 1);
-
- const uchar *s1 = data->texture.scanLine(y1);
- const uchar *s2 = data->texture.scanLine(y2);
-
- uint tl = fetch(s1, x1, data->texture.colorTable);
- uint tr = fetch(s1, x2, data->texture.colorTable);
- uint bl = fetch(s2, x1, data->texture.colorTable);
- uint br = fetch(s2, x2, data->texture.colorTable);
-
- uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
- uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
- *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
-
- fx += fdx;
- fy += fdy;
- fw += fdw;
- //force increment to avoid /0
- if (!fw) {
- fw += fdw;
+ if (blendType == BlendTransformedBilinearTiled) {
+ x1 %= image_width;
+ x2 %= image_width;
+ y1 %= image_height;
+ y2 %= image_height;
+
+ if (x1 < 0) x1 += image_width;
+ if (x2 < 0) x2 += image_width;
+ if (y1 < 0) y1 += image_height;
+ if (y2 < 0) y2 += image_height;
+
+ Q_ASSERT(x1 >= 0 && x1 < image_width);
+ Q_ASSERT(x2 >= 0 && x2 < image_width);
+ Q_ASSERT(y1 >= 0 && y1 < image_height);
+ Q_ASSERT(y2 >= 0 && y2 < image_height);
+ } else {
+ x1 = qBound(0, x1, image_width - 1);
+ x2 = qBound(0, x2, image_width - 1);
+ y1 = qBound(0, y1, image_height - 1);
+ y2 = qBound(0, y2, image_height - 1);
}
- ++b;
- }
- }
-
- return buffer;
-}
-
-static const uint * QT_FASTCALL fetchTransformedBilinearTiled(uint *buffer, const Operator *, const QSpanData *data,
- int y, int x, int length)
-{
- FetchPixelProc fetch = fetchPixelProc[data->texture.format];
-
- int image_width = data->texture.width;
- int image_height = data->texture.height;
-
- const qreal cx = x + 0.5;
- const qreal cy = y + 0.5;
-
- const uint *end = buffer + length;
- uint *b = buffer;
- if (data->fast_matrix) {
- // The increment pr x in the scanline
- int fdx = (int)(data->m11 * fixed_scale);
- int fdy = (int)(data->m12 * fixed_scale);
-
- int fx = int((data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale);
- int fy = int((data->m22 * cy + data->m12 * cx + data->dy) * fixed_scale);
-
- fx -= half_point;
- fy -= half_point;
- while (b < end) {
- int x1 = (fx >> 16);
- int x2 = x1 + 1;
- int y1 = (fy >> 16);
- int y2 = y1 + 1;
-
- int distx = ((fx - (x1 << 16)) >> 8);
- int disty = ((fy - (y1 << 16)) >> 8);
- int idistx = 256 - distx;
- int idisty = 256 - disty;
-
- x1 %= image_width;
- x2 %= image_width;
- y1 %= image_height;
- y2 %= image_height;
-
- if (x1 < 0) x1 += image_width;
- if (x2 < 0) x2 += image_width;
- if (y1 < 0) y1 += image_height;
- if (y2 < 0) y2 += image_height;
-
- Q_ASSERT(x1 >= 0 && x1 < image_width);
- Q_ASSERT(x2 >= 0 && x2 < image_width);
- Q_ASSERT(y1 >= 0 && y1 < image_height);
- Q_ASSERT(y2 >= 0 && y2 < image_height);
const uchar *s1 = data->texture.scanLine(y1);
const uchar *s2 = data->texture.scanLine(y2);
@@ -1018,20 +749,27 @@ static const uint * QT_FASTCALL fetchTransformedBilinearTiled(uint *buffer, cons
int idistx = 256 - distx;
int idisty = 256 - disty;
- x1 %= image_width;
- x2 %= image_width;
- y1 %= image_height;
- y2 %= image_height;
-
- if (x1 < 0) x1 += image_width;
- if (x2 < 0) x2 += image_width;
- if (y1 < 0) y1 += image_height;
- if (y2 < 0) y2 += image_height;
-
- Q_ASSERT(x1 >= 0 && x1 < image_width);
- Q_ASSERT(x2 >= 0 && x2 < image_width);
- Q_ASSERT(y1 >= 0 && y1 < image_height);
- Q_ASSERT(y2 >= 0 && y2 < image_height);
+ if (blendType == BlendTransformedBilinearTiled) {
+ x1 %= image_width;
+ x2 %= image_width;
+ y1 %= image_height;
+ y2 %= image_height;
+
+ if (x1 < 0) x1 += image_width;
+ if (x2 < 0) x2 += image_width;
+ if (y1 < 0) y1 += image_height;
+ if (y2 < 0) y2 += image_height;
+
+ Q_ASSERT(x1 >= 0 && x1 < image_width);
+ Q_ASSERT(x2 >= 0 && x2 < image_width);
+ Q_ASSERT(y1 >= 0 && y1 < image_height);
+ Q_ASSERT(y2 >= 0 && y2 < image_height);
+ } else {
+ x1 = qBound(0, x1, image_width - 1);
+ x2 = qBound(0, x2, image_width - 1);
+ y1 = qBound(0, y1, image_height - 1);
+ y2 = qBound(0, y2, image_height - 1);
+ }
const uchar *s1 = data->texture.scanLine(y1);
const uchar *s2 = data->texture.scanLine(y2);
@@ -1059,39 +797,7 @@ static const uint * QT_FASTCALL fetchTransformedBilinearTiled(uint *buffer, cons
return buffer;
}
-#if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
-
-// explicit template instantiations needed to compile with VC6 and VC2002
-
-#define SPANFUNC_POINTER_FETCHUNTRANSFORMED(Arg) \
- const uint *qt_fetchUntransformed_##Arg(uint *buffer, const Operator *op, const QSpanData *data, \
- int y, int x, int length) \
-{ \
- return qt_fetchUntransformed<QImage::Arg>(buffer, op, data, y, x, length Q_TEMPLATE_IMAGEFORMAT_CALL(QImage::Arg)); \
-}
-
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_Mono);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_MonoLSB);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_Indexed8);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB32_Premultiplied);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB32);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB16);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB8565_Premultiplied);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB666);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB6666_Premultiplied);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB555);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB8555_Premultiplied);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB888);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB444);
-SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB4444_Premultiplied);
-
-#undef SPANFUNC_POINTER_FETCHUNTRANSFORMED
-
-#define SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Arg) qt_fetchUntransformed_##Arg
-
-#else // !VC6 && !VC2002
-# define SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Arg) qt_fetchUntransformed<QImage::Arg>
-#endif
+#define SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Arg) qt_fetchUntransformed<QImage::Arg>
static const SourceFetchProc sourceFetch[NBlendTypes][QImage::NImageFormats] = {
// Untransformed
@@ -1135,75 +841,75 @@ static const SourceFetchProc sourceFetch[NBlendTypes][QImage::NImageFormats] = {
// Transformed
{
0, // Invalid
- fetchTransformed, // Mono
- fetchTransformed, // MonoLsb
- fetchTransformed, // Indexed8
- fetchTransformed, // RGB32
- fetchTransformed, // ARGB32
- fetchTransformed, // ARGB32_Premultiplied
- fetchTransformed, // RGB16
- fetchTransformed, // ARGB8565_Premultiplied
- fetchTransformed, // RGB666
- fetchTransformed, // ARGB6666_Premultiplied
- fetchTransformed, // RGB555
- fetchTransformed, // ARGB8555_Premultiplied
- fetchTransformed, // RGB888
- fetchTransformed, // RGB444
- fetchTransformed, // ARGB4444_Premultiplied
+ fetchTransformed<BlendTransformed>, // Mono
+ fetchTransformed<BlendTransformed>, // MonoLsb
+ fetchTransformed<BlendTransformed>, // Indexed8
+ fetchTransformed<BlendTransformed>, // RGB32
+ fetchTransformed<BlendTransformed>, // ARGB32
+ fetchTransformed<BlendTransformed>, // ARGB32_Premultiplied
+ fetchTransformed<BlendTransformed>, // RGB16
+ fetchTransformed<BlendTransformed>, // ARGB8565_Premultiplied
+ fetchTransformed<BlendTransformed>, // RGB666
+ fetchTransformed<BlendTransformed>, // ARGB6666_Premultiplied
+ fetchTransformed<BlendTransformed>, // RGB555
+ fetchTransformed<BlendTransformed>, // ARGB8555_Premultiplied
+ fetchTransformed<BlendTransformed>, // RGB888
+ fetchTransformed<BlendTransformed>, // RGB444
+ fetchTransformed<BlendTransformed>, // ARGB4444_Premultiplied
},
{
0, // TransformedTiled
- fetchTransformedTiled, // Mono
- fetchTransformedTiled, // MonoLsb
- fetchTransformedTiled, // Indexed8
- fetchTransformedTiled, // RGB32
- fetchTransformedTiled, // ARGB32
- fetchTransformedTiled, // ARGB32_Premultiplied
- fetchTransformedTiled, // RGB16
- fetchTransformedTiled, // ARGB8565_Premultiplied
- fetchTransformedTiled, // RGB666
- fetchTransformedTiled, // ARGB6666_Premultiplied
- fetchTransformedTiled, // RGB555
- fetchTransformedTiled, // ARGB8555_Premultiplied
- fetchTransformedTiled, // RGB888
- fetchTransformedTiled, // RGB444
- fetchTransformedTiled, // ARGB4444_Premultiplied
+ fetchTransformed<BlendTransformedTiled>, // Mono
+ fetchTransformed<BlendTransformedTiled>, // MonoLsb
+ fetchTransformed<BlendTransformedTiled>, // Indexed8
+ fetchTransformed<BlendTransformedTiled>, // RGB32
+ fetchTransformed<BlendTransformedTiled>, // ARGB32
+ fetchTransformed<BlendTransformedTiled>, // ARGB32_Premultiplied
+ fetchTransformed<BlendTransformedTiled>, // RGB16
+ fetchTransformed<BlendTransformedTiled>, // ARGB8565_Premultiplied
+ fetchTransformed<BlendTransformedTiled>, // RGB666
+ fetchTransformed<BlendTransformedTiled>, // ARGB6666_Premultiplied
+ fetchTransformed<BlendTransformedTiled>, // RGB555
+ fetchTransformed<BlendTransformedTiled>, // ARGB8555_Premultiplied
+ fetchTransformed<BlendTransformedTiled>, // RGB888
+ fetchTransformed<BlendTransformedTiled>, // RGB444
+ fetchTransformed<BlendTransformedTiled>, // ARGB4444_Premultiplied
},
{
0, // Bilinear
- fetchTransformedBilinear, // Mono
- fetchTransformedBilinear, // MonoLsb
- fetchTransformedBilinear, // Indexed8
- fetchTransformedBilinear, // RGB32
- fetchTransformedBilinear, // ARGB32
- fetchTransformedBilinear, // ARGB32_Premultiplied
- fetchTransformedBilinear, // RGB16
- fetchTransformedBilinear, // ARGB8565_Premultiplied
- fetchTransformedBilinear, // RGB666
- fetchTransformedBilinear, // ARGB6666_Premultiplied
- fetchTransformedBilinear, // RGB555
- fetchTransformedBilinear, // ARGB8555_Premultiplied
- fetchTransformedBilinear, // RGB888
- fetchTransformedBilinear, // RGB444
- fetchTransformedBilinear // ARGB4444_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // Mono
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // MonoLsb
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // Indexed8
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32_Premultiplied>, // RGB32
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32>, // ARGB32
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32_Premultiplied>, // ARGB32_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB16
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // ARGB8565_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB666
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // ARGB6666_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB555
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // ARGB8555_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB888
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>, // RGB444
+ fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid> // ARGB4444_Premultiplied
},
{
0, // BilinearTiled
- fetchTransformedBilinearTiled, // Mono
- fetchTransformedBilinearTiled, // MonoLsb
- fetchTransformedBilinearTiled, // Indexed8
- fetchTransformedBilinearTiled, // RGB32
- fetchTransformedBilinearTiled, // ARGB32
- fetchTransformedBilinearTiled, // ARGB32_Premultiplied
- fetchTransformedBilinearTiled, // RGB16
- fetchTransformedBilinearTiled, // ARGB8565_Premultiplied
- fetchTransformedBilinearTiled, // RGB666
- fetchTransformedBilinearTiled, // ARGB6666_Premultiplied
- fetchTransformedBilinearTiled, // RGB555
- fetchTransformedBilinearTiled, // ARGB8555_Premultiplied
- fetchTransformedBilinearTiled, // RGB888
- fetchTransformedBilinearTiled, // RGB444
- fetchTransformedBilinearTiled // ARGB4444_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // Mono
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // MonoLsb
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // Indexed8
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32_Premultiplied>, // RGB32
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32>, // ARGB32
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32_Premultiplied>, // ARGB32_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB16
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // ARGB8565_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB666
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // ARGB6666_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB555
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // ARGB8555_Premultiplied
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB888
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>, // RGB444
+ fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid> // ARGB4444_Premultiplied
},
};
@@ -3219,8 +2925,7 @@ static void blend_color_argb(int count, const QSpan *spans, void *userData)
}
template <class T>
-Q_STATIC_TEMPLATE_FUNCTION void blendColor(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_FIX(T))
+Q_STATIC_TEMPLATE_FUNCTION void blendColor(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
Operator op = getOperator(data, spans, count);
@@ -3266,28 +2971,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendColor(int count, const QSpan *spans, void *
blend_color_generic(count, spans, userData);
}
-#if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
-#define BLEND_COLOR_DECL(DST) \
- static void blendColor_##DST(int count, \
- const QSpan *spans, \
- void *userData) \
- { \
- blendColor<DST>(count, spans, userData Q_TEMPLATE_CALL(DST)); \
- }
-
-BLEND_COLOR_DECL(qargb8565)
-BLEND_COLOR_DECL(qrgb666)
-BLEND_COLOR_DECL(qargb6666)
-BLEND_COLOR_DECL(qrgb555)
-BLEND_COLOR_DECL(qargb8555)
-BLEND_COLOR_DECL(qrgb888)
-BLEND_COLOR_DECL(qrgb444)
-BLEND_COLOR_DECL(qargb4444)
-#undef DEST_FETCH_DECL
-#define SPANFUNC_POINTER_BLENDCOLOR(DST) blendColor_##DST
-#else // !VC6 && !VC2002
-# define SPANFUNC_POINTER_BLENDCOLOR(DST) blendColor<DST>
-#endif
+#define SPANFUNC_POINTER_BLENDCOLOR(DST) blendColor<DST>
static void blend_color_rgb16(int count, const QSpan *spans, void *userData)
{
@@ -3365,45 +3049,117 @@ static void blend_color_rgb16(int count, const QSpan *spans, void *userData)
blend_color_generic(count, spans, userData);
}
-template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_src_generic(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+template <typename T>
+void handleSpans(int count, const QSpan *spans, const QSpanData *data, T &handler)
{
- QSpanData *data = reinterpret_cast<QSpanData *>(userData);
-
- uint buffer[buffer_size];
- uint src_buffer[buffer_size];
- Operator op = getOperator(data, spans, count);
-
uint const_alpha = 256;
if (data->type == QSpanData::Texture)
const_alpha = data->texture.const_alpha;
- while (count--) {
+ int coverage = 0;
+ while (count) {
int x = spans->x;
- int length = spans->len;
- const int coverage = (spans->coverage * const_alpha) >> 8;
+ const int y = spans->y;
+ int right = x + spans->len;
+
+ // compute length of adjacent spans
+ for (int i = 1; i < count && spans[i].y == y && spans[i].x == right; ++i)
+ right += spans[i].len;
+ int length = right - x;
+
while (length) {
int l = qMin(buffer_size, length);
- const uint *src = op.src_fetch(src_buffer, &op, data, spans->y, x, l);
- if (spanMethod == RegularSpans) {
- uint *dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, spans->y, l) : buffer;
- op.func(dest, src, l, coverage);
- if (op.dest_store)
- op.dest_store(data->rasterBuffer, x, spans->y, dest, l);
- } else {
- drawBufferSpan(data, src, l, x, spans->y, l, coverage);
- }
- x += l;
length -= l;
+
+ int process_length = l;
+ int process_x = x;
+
+ const uint *src = handler.fetch(process_x, y, process_length);
+ int offset = 0;
+ while (l > 0) {
+ if (x == spans->x) // new span?
+ coverage = (spans->coverage * const_alpha) >> 8;
+
+ int right = spans->x + spans->len;
+ int len = qMin(l, right - x);
+
+ handler.process(x, y, len, coverage, src, offset);
+
+ l -= len;
+ x += len;
+ offset += len;
+
+ if (x == right) { // done with current span?
+ ++spans;
+ --count;
+ }
+ }
+ handler.store(process_x, y, process_length);
}
- ++spans;
}
}
+struct QBlendBase
+{
+ QBlendBase(QSpanData *d, Operator o)
+ : data(d)
+ , op(o)
+ , dest(0)
+ {
+ }
+
+ QSpanData *data;
+ Operator op;
+
+ uint *dest;
+
+ uint buffer[buffer_size];
+ uint src_buffer[buffer_size];
+};
+
+template <SpanMethod spanMethod>
+class BlendSrcGeneric : public QBlendBase
+{
+public:
+ BlendSrcGeneric(QSpanData *d, Operator o)
+ : QBlendBase(d, o)
+ {
+ }
+
+ const uint *fetch(int x, int y, int len)
+ {
+ if (spanMethod == RegularSpans)
+ dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, y, len) : buffer;
+
+ return op.src_fetch(src_buffer, &op, data, y, x, len);
+ }
+
+ void process(int x, int y, int len, int coverage, const uint *src, int offset)
+ {
+ if (spanMethod == RegularSpans)
+ op.func(dest + offset, src + offset, len, coverage);
+ else
+ drawBufferSpan(data, src + offset, len, x, y, len, coverage);
+ }
+
+ void store(int x, int y, int len)
+ {
+ if (spanMethod == RegularSpans && op.dest_store) {
+ op.dest_store(data->rasterBuffer, x, y, dest, len);
+ }
+ }
+};
+
+template <SpanMethod spanMethod>
+Q_STATIC_TEMPLATE_FUNCTION void blend_src_generic(int count, const QSpan *spans, void *userData)
+{
+ QSpanData *data = reinterpret_cast<QSpanData *>(userData);
+ BlendSrcGeneric<spanMethod> blend(data, getOperator(data, spans, count));
+ handleSpans(count, spans, data, blend);
+}
+
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_generic(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_generic(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
@@ -3454,13 +3210,12 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_generic(int count, const QSp
}
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_argb(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_argb(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
if (data->texture.format != QImage::Format_ARGB32_Premultiplied
&& data->texture.format != QImage::Format_RGB32) {
- blend_untransformed_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
+ blend_untransformed_generic<spanMethod>(count, spans, userData);
return;
}
@@ -4706,8 +4461,7 @@ void QT_FASTCALL blendUntransformed(int count, const QSpan *spans, void *userDat
if (mode != QPainter::CompositionMode_SourceOver &&
mode != QPainter::CompositionMode_Source)
{
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
return;
}
@@ -4769,8 +4523,7 @@ static void blend_untransformed_rgb888(int count, const QSpan *spans,
blendUntransformed<qrgb888, qrgb888>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_argb6666(int count, const QSpan *spans,
@@ -4785,8 +4538,7 @@ static void blend_untransformed_argb6666(int count, const QSpan *spans,
blendUntransformed<qargb6666, qrgb666>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_rgb666(int count, const QSpan *spans,
@@ -4801,8 +4553,7 @@ static void blend_untransformed_rgb666(int count, const QSpan *spans,
blendUntransformed<qrgb666, qrgb666>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_argb8565(int count, const QSpan *spans,
@@ -4817,8 +4568,7 @@ static void blend_untransformed_argb8565(int count, const QSpan *spans,
blendUntransformed<qargb8565, qrgb565>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_rgb565(int count, const QSpan *spans,
@@ -4833,8 +4583,7 @@ static void blend_untransformed_rgb565(int count, const QSpan *spans,
blendUntransformed<qrgb565, qrgb565>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_argb8555(int count, const QSpan *spans,
@@ -4849,8 +4598,7 @@ static void blend_untransformed_argb8555(int count, const QSpan *spans,
blendUntransformed<qargb8555, qrgb555>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_rgb555(int count, const QSpan *spans,
@@ -4865,8 +4613,7 @@ static void blend_untransformed_rgb555(int count, const QSpan *spans,
blendUntransformed<qrgb555, qrgb555>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_argb4444(int count, const QSpan *spans,
@@ -4881,8 +4628,7 @@ static void blend_untransformed_argb4444(int count, const QSpan *spans,
blendUntransformed<qargb4444, qrgb444>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
static void blend_untransformed_rgb444(int count, const QSpan *spans,
@@ -4897,13 +4643,11 @@ static void blend_untransformed_rgb444(int count, const QSpan *spans,
blendUntransformed<qrgb444, qrgb444>(count, spans, userData);
else
#endif
- blend_untransformed_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_untransformed_generic<RegularSpans>(count, spans, userData);
}
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_generic(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_generic(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
@@ -4957,13 +4701,12 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_generic(int count, const QSpan *span
}
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_argb(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_argb(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
if (data->texture.format != QImage::Format_ARGB32_Premultiplied
&& data->texture.format != QImage::Format_RGB32) {
- blend_tiled_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
+ blend_tiled_generic<spanMethod>(count, spans, userData);
return;
}
@@ -5019,8 +4762,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTiled(int count, const QSpan *spans, void *
if (mode != QPainter::CompositionMode_SourceOver &&
mode != QPainter::CompositionMode_Source)
{
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
return;
}
@@ -5090,8 +4832,7 @@ static void blend_tiled_rgb888(int count, const QSpan *spans, void *userData)
blendTiled<qrgb888, qrgb888>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_argb6666(int count, const QSpan *spans, void *userData)
@@ -5105,8 +4846,7 @@ static void blend_tiled_argb6666(int count, const QSpan *spans, void *userData)
blendTiled<qargb6666, qrgb666>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_rgb666(int count, const QSpan *spans, void *userData)
@@ -5120,8 +4860,7 @@ static void blend_tiled_rgb666(int count, const QSpan *spans, void *userData)
blendTiled<qrgb666, qrgb666>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_argb8565(int count, const QSpan *spans, void *userData)
@@ -5135,8 +4874,7 @@ static void blend_tiled_argb8565(int count, const QSpan *spans, void *userData)
blendTiled<qargb8565, qrgb565>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_rgb565(int count, const QSpan *spans, void *userData)
@@ -5150,8 +4888,7 @@ static void blend_tiled_rgb565(int count, const QSpan *spans, void *userData)
blendTiled<qrgb565, qrgb565>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_argb8555(int count, const QSpan *spans, void *userData)
@@ -5165,8 +4902,7 @@ static void blend_tiled_argb8555(int count, const QSpan *spans, void *userData)
blendTiled<qargb8555, qrgb555>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_rgb555(int count, const QSpan *spans, void *userData)
@@ -5180,8 +4916,7 @@ static void blend_tiled_rgb555(int count, const QSpan *spans, void *userData)
blendTiled<qrgb555, qrgb555>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_argb4444(int count, const QSpan *spans, void *userData)
@@ -5195,8 +4930,7 @@ static void blend_tiled_argb4444(int count, const QSpan *spans, void *userData)
blendTiled<qargb4444, qrgb444>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
static void blend_tiled_rgb444(int count, const QSpan *spans, void *userData)
@@ -5210,19 +4944,17 @@ static void blend_tiled_rgb444(int count, const QSpan *spans, void *userData)
blendTiled<qrgb444, qrgb444>(count, spans, userData);
else
#endif
- blend_tiled_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_tiled_generic<RegularSpans>(count, spans, userData);
}
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
if (data->texture.format != QImage::Format_ARGB32_Premultiplied
&& data->texture.format != QImage::Format_RGB32) {
- blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
+ blend_src_generic<spanMethod>(count, spans, userData);
return;
}
@@ -5401,8 +5133,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTransformedBilinear(int count, const QSpan
if (mode != QPainter::CompositionMode_SourceOver) {
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
return;
}
@@ -5605,8 +5336,7 @@ static void blend_transformed_bilinear_rgb888(int count, const QSpan *spans, voi
blendTransformedBilinear<qrgb888, qrgb888>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_argb6666(int count, const QSpan *spans, void *userData)
@@ -5620,8 +5350,7 @@ static void blend_transformed_bilinear_argb6666(int count, const QSpan *spans, v
blendTransformedBilinear<qargb6666, qrgb666>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_rgb666(int count, const QSpan *spans, void *userData)
@@ -5635,8 +5364,7 @@ static void blend_transformed_bilinear_rgb666(int count, const QSpan *spans, voi
blendTransformedBilinear<qrgb666, qrgb666>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_argb8565(int count, const QSpan *spans, void *userData)
@@ -5650,8 +5378,7 @@ static void blend_transformed_bilinear_argb8565(int count, const QSpan *spans, v
blendTransformedBilinear<qargb8565, qrgb565>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_rgb565(int count, const QSpan *spans,
@@ -5666,8 +5393,7 @@ static void blend_transformed_bilinear_rgb565(int count, const QSpan *spans,
blendTransformedBilinear<qrgb565, qargb8565>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_argb8555(int count, const QSpan *spans, void *userData)
@@ -5681,8 +5407,7 @@ static void blend_transformed_bilinear_argb8555(int count, const QSpan *spans, v
blendTransformedBilinear<qargb8555, qrgb555>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_rgb555(int count, const QSpan *spans, void *userData)
@@ -5696,8 +5421,7 @@ static void blend_transformed_bilinear_rgb555(int count, const QSpan *spans, voi
blendTransformedBilinear<qrgb555, qrgb555>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_argb4444(int count, const QSpan *spans, void *userData)
@@ -5711,8 +5435,7 @@ static void blend_transformed_bilinear_argb4444(int count, const QSpan *spans, v
blendTransformedBilinear<qargb4444, qrgb444>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_bilinear_rgb444(int count, const QSpan *spans, void *userData)
@@ -5726,18 +5449,16 @@ static void blend_transformed_bilinear_rgb444(int count, const QSpan *spans, voi
blendTransformedBilinear<qrgb444, qrgb444>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
if (data->texture.format != QImage::Format_ARGB32_Premultiplied
&& data->texture.format != QImage::Format_RGB32) {
- blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
+ blend_src_generic<spanMethod>(count, spans, userData);
return;
}
@@ -5923,13 +5644,12 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count,
}
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
if (data->texture.format != QImage::Format_ARGB32_Premultiplied
&& data->texture.format != QImage::Format_RGB32) {
- blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
+ blend_src_generic<spanMethod>(count, spans, userData);
return;
}
@@ -6051,8 +5771,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTransformed(int count, const QSpan *spans,
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode;
if (mode != QPainter::CompositionMode_SourceOver) {
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
return;
}
@@ -6201,8 +5920,7 @@ static void blend_transformed_rgb888(int count, const QSpan *spans,
blendTransformed<qrgb888, qrgb888>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_argb6666(int count, const QSpan *spans,
@@ -6217,8 +5935,7 @@ static void blend_transformed_argb6666(int count, const QSpan *spans,
blendTransformed<qargb6666, qrgb666>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_rgb666(int count, const QSpan *spans,
@@ -6233,8 +5950,7 @@ static void blend_transformed_rgb666(int count, const QSpan *spans,
blendTransformed<qrgb666, qrgb666>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_argb8565(int count, const QSpan *spans,
@@ -6249,8 +5965,7 @@ static void blend_transformed_argb8565(int count, const QSpan *spans,
blendTransformed<qargb8565, qrgb565>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_rgb565(int count, const QSpan *spans,
@@ -6265,8 +5980,7 @@ static void blend_transformed_rgb565(int count, const QSpan *spans,
blendTransformed<qrgb565, qrgb565>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_argb8555(int count, const QSpan *spans,
@@ -6281,8 +5995,7 @@ static void blend_transformed_argb8555(int count, const QSpan *spans,
blendTransformed<qargb8555, qrgb555>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_rgb555(int count, const QSpan *spans,
@@ -6297,8 +6010,7 @@ static void blend_transformed_rgb555(int count, const QSpan *spans,
blendTransformed<qrgb555, qrgb555>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_argb4444(int count, const QSpan *spans,
@@ -6313,8 +6025,7 @@ static void blend_transformed_argb4444(int count, const QSpan *spans,
blendTransformed<qargb4444, qrgb444>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_rgb444(int count, const QSpan *spans,
@@ -6329,18 +6040,16 @@ static void blend_transformed_rgb444(int count, const QSpan *spans,
blendTransformed<qrgb444, qrgb444>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
template <SpanMethod spanMethod>
-Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QSpan *spans, void *userData
- Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
+Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QSpan *spans, void *userData)
{
QSpanData *data = reinterpret_cast<QSpanData *>(userData);
if (data->texture.format != QImage::Format_ARGB32_Premultiplied
&& data->texture.format != QImage::Format_RGB32) {
- blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
+ blend_src_generic<spanMethod>(count, spans, userData);
return;
}
@@ -6474,8 +6183,7 @@ Q_STATIC_TEMPLATE_FUNCTION void blendTransformedTiled(int count, const QSpan *sp
QPainter::CompositionMode mode = data->rasterBuffer->compositionMode;
if (mode != QPainter::CompositionMode_SourceOver) {
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
return;
}
@@ -6625,8 +6333,7 @@ static void blend_transformed_tiled_rgb888(int count, const QSpan *spans,
blendTransformedTiled<qrgb888, qrgb888>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_argb6666(int count, const QSpan *spans,
@@ -6641,8 +6348,7 @@ static void blend_transformed_tiled_argb6666(int count, const QSpan *spans,
blendTransformedTiled<qargb6666, qrgb666>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_rgb666(int count, const QSpan *spans,
@@ -6657,8 +6363,7 @@ static void blend_transformed_tiled_rgb666(int count, const QSpan *spans,
blendTransformedTiled<qrgb666, qrgb666>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_argb8565(int count, const QSpan *spans,
@@ -6673,8 +6378,7 @@ static void blend_transformed_tiled_argb8565(int count, const QSpan *spans,
blendTransformedTiled<qargb8565, qrgb565>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_rgb565(int count, const QSpan *spans,
@@ -6689,8 +6393,7 @@ static void blend_transformed_tiled_rgb565(int count, const QSpan *spans,
blendTransformedTiled<qrgb565, qrgb565>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_argb8555(int count, const QSpan *spans,
@@ -6705,8 +6408,7 @@ static void blend_transformed_tiled_argb8555(int count, const QSpan *spans,
blendTransformedTiled<qargb8555, qrgb555>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_rgb555(int count, const QSpan *spans,
@@ -6721,8 +6423,7 @@ static void blend_transformed_tiled_rgb555(int count, const QSpan *spans,
blendTransformedTiled<qrgb555, qrgb555>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_argb4444(int count, const QSpan *spans,
@@ -6737,8 +6438,7 @@ static void blend_transformed_tiled_argb4444(int count, const QSpan *spans,
blendTransformedTiled<qargb4444, qrgb444>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
static void blend_transformed_tiled_rgb444(int count, const QSpan *spans,
@@ -6753,36 +6453,10 @@ static void blend_transformed_tiled_rgb444(int count, const QSpan *spans,
blendTransformedTiled<qrgb444, qrgb444>(count, spans, userData);
else
#endif
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
-#if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
-
-// explicit template instantiations needed to compile with VC6 and VC2002
-
-#define SPANFUNC_INSTANTIATION(Name, Arg) \
-static inline void Name##_##Arg(int count, const QSpan *spans, void *userData) \
-{ \
- Name<Arg>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, Arg)); \
-}
-
-SPANFUNC_INSTANTIATION(blend_untransformed_generic, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_untransformed_argb, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_tiled_generic, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_tiled_argb, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_src_generic, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_transformed_argb, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_transformed_tiled_argb, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_transformed_bilinear_argb, RegularSpans);
-SPANFUNC_INSTANTIATION(blend_transformed_bilinear_tiled_argb, RegularSpans);
-#undef SPANFUNC_INSTANTIATION
-
-#define SPANFUNC_POINTER(Name, Arg) Name##_##Arg
-
-#else // !VC6 && !VC2002
# define SPANFUNC_POINTER(Name, Arg) Name<Arg>
-#endif
/* Image formats here are target formats */
@@ -7149,8 +6823,7 @@ static void qt_gradient_quint32(int count, const QSpan *spans, void *userData)
}
} else {
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
}
@@ -7198,8 +6871,7 @@ static void qt_gradient_quint16(int count, const QSpan *spans, void *userData)
data->solid.color = oldColor;
} else {
- blend_src_generic<RegularSpans>(count, spans, userData
- Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
+ blend_src_generic<RegularSpans>(count, spans, userData);
}
}
@@ -7260,6 +6932,12 @@ static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer,
void qt_build_pow_tables() {
qreal smoothing = 1.7;
+#ifdef Q_WS_MAC
+ // decided by testing a few things on an iMac, should probably get this from the
+ // system...
+ smoothing = 2.0;
+#endif
+
#ifdef Q_WS_WIN
int winSmooth;
if (SystemParametersInfo(0x200C /* SPI_GETFONTSMOOTHINGCONTRAST */, 0, &winSmooth, 0))
@@ -7404,7 +7082,7 @@ static void qt_alphamapblit_quint32(QRasterBuffer *rasterBuffer,
#endif
{
int ialpha = 255 - coverage;
- dest[i] = BYTE_MUL(c, uint(coverage)) + BYTE_MUL(dest[i], ialpha);
+ dest[i] = INTERPOLATE_PIXEL_255(c, coverage, dest[i], ialpha);
}
}
}
@@ -7445,7 +7123,7 @@ static void qt_alphamapblit_quint32(QRasterBuffer *rasterBuffer,
#endif
{
int ialpha = 255 - coverage;
- dest[xp] = BYTE_MUL(c, uint(coverage)) + BYTE_MUL(dest[xp], ialpha);
+ dest[xp] = INTERPOLATE_PIXEL_255(c, coverage, dest[xp], ialpha);
}
}
diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp
index 2beeb0e..230d30b 100644
--- a/src/gui/painting/qdrawutil.cpp
+++ b/src/gui/painting/qdrawutil.cpp
@@ -1038,4 +1038,301 @@ void qDrawItem(QPainter *p, Qt::GUIStyle gs,
#endif
+/*!
+ \struct QMargins
+ \since 4.6
+
+ Holds the borders used to split a pixmap into nine segments in order to
+ draw it, similar to \l{http://www.w3.org/TR/css3-background/}
+ {CSS3 border-images}.
+
+ \sa qDrawBorderPixmap, Qt::TileRule, QTileRules
+*/
+
+/*!
+ \struct QTileRules
+ \since 4.6
+
+ Holds the rules used to draw a pixmap or image split into nine segments,
+ similar to \l{http://www.w3.org/TR/css3-background/}{CSS3 border-images}.
+
+ \sa qDrawBorderPixmap, Qt::TileRule, QMargins
+*/
+
+/*!
+ \fn qDrawBorderPixmap(QPainter *painter, const QRect &target, const QMargins &margins, const QPixmap &pixmap)
+ \since 4.6
+
+ Draws the given \a pixmap into the given \a target rectangle, using the
+ given \a painter. The pixmap will be split into nine segments and drawn
+ according to the \a margins structure.
+*/
+
+static inline void qVerticalRepeat(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source,
+ void (*drawPixmap)(QPainter*, const QRect&, const QPixmap&, const QRect&))
+{
+ const int x = target.x();
+ const int width = target.width();
+ const int height = source.height();
+ const int bottom = target.bottom() - height;
+ int y = target.y();
+ for (; y < bottom; y += height)
+ (*drawPixmap)(painter, QRect(x, y, width, height), pixmap, source);
+ const QRect remaining(source.x(), source.y(), source.width(), target.bottom() - y + 1);
+ (*drawPixmap)(painter, QRect(x, y, width, remaining.height()), pixmap, remaining);
+}
+
+static inline void qHorizontalRepeat(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source,
+ void (*drawPixmap)(QPainter*, const QRect&, const QPixmap&, const QRect&))
+{
+ const int y = target.y();
+ const int width = source.width();
+ const int height = target.height();
+ const int right = target.right() - width;
+ int x = target.x();
+ for (; x < right; x += width)
+ (*drawPixmap)(painter, QRect(x, y, width, height), pixmap, source);
+ const QRect remaining(source.x(), source.y(), target.right() - x + 1, source.height());
+ (*drawPixmap)(painter, QRect(x, y, remaining.width(), height), pixmap, remaining);
+}
+
+static inline void qVerticalRound(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source,
+ void (*drawPixmap)(QPainter*, const QRect&, const QPixmap&, const QRect&))
+{
+ // qreal based - slow on non-fpu devices
+ const qreal x = target.x();
+ const qreal width = target.width();
+ const qreal verticalFactor = static_cast<qreal>(target.height()) / static_cast<qreal>(source.height());
+ const qreal verticalIncrement = static_cast<qreal>(target.height()) / static_cast<int>(verticalFactor + 0.5);
+ const qreal bottom = target.bottom();
+ for (qreal y = static_cast<qreal>(target.y()); y < bottom; y += verticalIncrement)
+ (*drawPixmap)(painter, QRectF(x, y, width, verticalIncrement).toRect(), pixmap, source);
+
+}
+
+static inline void qHorizontalRound(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source,
+ void (*drawPixmap)(QPainter*, const QRect&, const QPixmap&, const QRect&))
+{
+ // qreal based - slow on non-fpu devices
+ const qreal y = target.y();
+ const qreal height = target.height();
+ const qreal horizontalFactor = static_cast<qreal>(target.width()) / static_cast<qreal>(source.width());
+ const qreal horizontalIncrement = static_cast<qreal>(target.width()) / static_cast<int>(horizontalFactor + 0.5);
+ const qreal right = target.right();
+ for (qreal x = target.x(); x < right; x += horizontalIncrement)
+ (*drawPixmap)(painter, QRectF(x, y, horizontalIncrement, height).toRect(), pixmap, source);
+}
+
+static inline void qDrawPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
+{
+ painter->drawPixmap(target, pixmap, source);
+}
+
+static inline void qDrawVerticallyRepeatedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
+{
+ qVerticalRepeat(painter, target, pixmap, source, qDrawPixmap);
+}
+
+static inline void qDrawHorizontallyRepeatedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
+{
+ qHorizontalRepeat(painter, target, pixmap, source, qDrawPixmap);
+}
+
+static inline void qDrawVerticallyRoundedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
+{
+ qVerticalRound(painter, target, pixmap, source, qDrawPixmap);
+}
+
+static inline void qDrawHorizontallyRoundedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
+{
+ qHorizontalRound(painter, target, pixmap, source, qDrawPixmap);
+}
+
+/*!
+ \since 4.6
+
+ Draws the indicated \a sourceRect rectangle from the given \a pixmap into
+ the given \a targetRect rectangle, using the given \a painter. The pixmap
+ will be split into nine segments according to the given \a targetMargins
+ and \a sourceMargins structures. Finally, the pixmap will be drawn
+ according to the given \a rules.
+
+ This function is used to draw a scaled pixmap, similar to
+ \l{http://www.w3.org/TR/css3-background/}{CSS3 border-images}
+
+ \sa Qt::TileRule, QTileRules, QMargins
+*/
+
+void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap,
+ const QRect &sourceRect, const QMargins &sourceMargins, const QTileRules &rules)
+{
+ // source center
+ const int sourceTop = sourceRect.top();
+ const int sourceLeft = sourceRect.left();
+ const int sourceCenterTop = sourceTop + sourceMargins.top;
+ const int sourceCenterLeft = sourceLeft + sourceMargins.left;
+ const int sourceCenterBottom = sourceRect.bottom() - sourceMargins.bottom + 1;
+ const int sourceCenterRight = sourceRect.right() - sourceMargins.right + 1;
+ const int sourceCenterWidth = sourceCenterRight - sourceMargins.left;
+ const int sourceCenterHeight = sourceCenterBottom - sourceMargins.top;
+ // target center
+ const int targetTop = targetRect.top();
+ const int targetLeft = targetRect.left();
+ const int targetCenterTop = targetTop + targetMargins.top;
+ const int targetCenterLeft = targetLeft + targetMargins.left;
+ const int targetCenterBottom = targetRect.bottom() - targetMargins.bottom + 1;
+ const int targetCenterRight = targetRect.right() - targetMargins.right + 1;
+ const int targetCenterWidth = targetCenterRight - targetCenterLeft;
+ const int targetCenterHeight = targetCenterBottom - targetCenterTop;
+
+ // corners
+ if (targetMargins.top > 0 && targetMargins.left > 0 && sourceMargins.top > 0 && sourceMargins.left > 0) { // top left
+ const QRect targetTopLeftRect(targetLeft, targetTop, targetMargins.left, targetMargins.top);
+ const QRect sourceTopLeftRect(sourceLeft, sourceTop, sourceMargins.left, sourceMargins.top);
+ qDrawPixmap(painter, targetTopLeftRect, pixmap, sourceTopLeftRect);
+ }
+ if (targetMargins.top > 0 && targetMargins.right > 0 && sourceMargins.top > 0 && sourceMargins.right > 0) { // top right
+ const QRect targetTopRightRect(targetCenterRight, targetTop, targetMargins.right, targetMargins.top);
+ const QRect sourceTopRightRect(sourceCenterRight, sourceTop, sourceMargins.right, sourceMargins.top);
+ qDrawPixmap(painter, targetTopRightRect, pixmap, sourceTopRightRect);
+ }
+ if (targetMargins.bottom > 0 && targetMargins.left > 0 && sourceMargins.bottom > 0 && sourceMargins.left > 0) { // bottom left
+ const QRect targetBottomLeftRect(targetLeft, targetCenterBottom, targetMargins.left, targetMargins.bottom);
+ const QRect sourceBottomLeftRect(sourceLeft, sourceCenterBottom, sourceMargins.left, sourceMargins.bottom);
+ qDrawPixmap(painter, targetBottomLeftRect, pixmap, sourceBottomLeftRect);
+ }
+ if (targetMargins.bottom > 0 && targetMargins.right > 0 && sourceMargins.bottom > 0 && sourceMargins.right > 0) { // bottom right
+ const QRect targetBottomRightRect(targetCenterRight, targetCenterBottom, targetMargins.right, targetMargins.bottom);
+ const QRect sourceBottomRightRect(sourceCenterRight, sourceCenterBottom, sourceMargins.right, sourceMargins.bottom);
+ qDrawPixmap(painter, targetBottomRightRect, pixmap, sourceBottomRightRect);
+ }
+
+ // horizontal edges
+ switch (rules.horizontal) {
+ case Qt::Stretch:
+ if (targetMargins.top > 0 && sourceMargins.top > 0) { // top
+ const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top);
+ const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top);
+ qDrawPixmap(painter, targetTopRect, pixmap, sourceTopRect);
+ }
+ if (targetMargins.bottom > 0 && sourceMargins.bottom > 0) { // bottom
+ const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom);
+ const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom);
+ qDrawPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
+ }
+ break;
+ case Qt::Repeat:
+ if (targetMargins.top > 0 && sourceMargins.top > 0) { // top
+ const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top);
+ const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top);
+ qDrawHorizontallyRepeatedPixmap(painter, targetTopRect, pixmap, sourceTopRect);
+ }
+ if (targetMargins.bottom > 0 && sourceMargins.bottom > 0) { // bottom
+ const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom);
+ const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom);
+ qDrawHorizontallyRepeatedPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
+ }
+ break;
+ case Qt::Round:
+ if (targetMargins.top > 0 && sourceMargins.top > 0) { // top
+ const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top);
+ const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top);
+ qDrawHorizontallyRoundedPixmap(painter, targetTopRect, pixmap, sourceTopRect);
+ }
+ if (targetMargins.bottom > 0 && sourceMargins.bottom > 0) { // bottom
+ const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom);
+ const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom);
+ qDrawHorizontallyRoundedPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
+ }
+ break;
+ }
+
+ // vertical edges
+ switch (rules.vertical) {
+ case Qt::Stretch:
+ if (targetMargins.left > 0 && sourceMargins.left > 0) { // left
+ const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left, targetCenterHeight);
+ const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left, sourceCenterHeight);
+ qDrawPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
+ }
+ if (targetMargins.right > 0 && sourceMargins.right > 0) { // right
+ const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right, targetCenterHeight);
+ const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right, sourceCenterHeight);
+ qDrawPixmap(painter, targetRightRect, pixmap, sourceRightRect);
+ }
+ break;
+ case Qt::Repeat:
+ if (targetMargins.left > 0 && sourceMargins.left > 0) { // left
+ const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left, targetCenterHeight);
+ const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left, sourceCenterHeight);
+ qDrawVerticallyRepeatedPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
+ }
+ if (targetMargins.right > 0 && sourceMargins.right > 0) { // right
+ const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right, targetCenterHeight);
+ const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right, sourceCenterHeight);
+ qDrawVerticallyRepeatedPixmap(painter, targetRightRect, pixmap, sourceRightRect);
+ }
+ break;
+ case Qt::Round:
+ if (targetMargins.left > 0 && sourceMargins.left > 0) { // left
+ const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left, targetCenterHeight);
+ const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left, sourceCenterHeight);
+ qDrawVerticallyRoundedPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
+ }
+ if (targetMargins.right > 0 && sourceMargins.right > 0) { // right
+ const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right, targetCenterHeight);
+ const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right, sourceCenterHeight);
+ qDrawVerticallyRoundedPixmap(painter, targetRightRect, pixmap, sourceRightRect);
+ }
+ break;
+ }
+
+ // center
+ if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) {
+ const QRect targetCenterRect(targetCenterLeft, targetCenterTop, targetCenterWidth, targetCenterHeight);
+ const QRect sourceCenterRect(sourceCenterLeft, sourceCenterTop, sourceCenterWidth, sourceCenterHeight);
+ switch (rules.horizontal) {
+ case Qt::Stretch:
+ switch (rules.vertical) {
+ case Qt::Stretch: // stretch stretch
+ qDrawPixmap(painter, targetCenterRect, pixmap, sourceCenterRect);
+ break;
+ case Qt::Repeat: // stretch repeat
+ qVerticalRepeat(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
+ break;
+ case Qt::Round: // stretch round
+ qVerticalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
+ break;
+ }
+ break;
+ case Qt::Repeat:
+ switch (rules.vertical) {
+ case Qt::Stretch: // repeat stretch
+ qHorizontalRepeat(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
+ break;
+ case Qt::Repeat: // repeat repeat
+ qVerticalRepeat(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawHorizontallyRepeatedPixmap);
+ break;
+ case Qt::Round: // repeat round
+ qVerticalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawHorizontallyRepeatedPixmap);
+ break;
+ }
+ break;
+ case Qt::Round:
+ switch (rules.vertical) {
+ case Qt::Stretch: // round stretch
+ qHorizontalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
+ break;
+ case Qt::Repeat: // round repeat
+ qHorizontalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawVerticallyRepeatedPixmap);
+ break;
+ case Qt::Round: // round round
+ qHorizontalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawVerticallyRoundedPixmap);
+ break;
+ }
+ break;
+ }
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/painting/qdrawutil.h b/src/gui/painting/qdrawutil.h
index 14901f3..38d9ec0 100644
--- a/src/gui/painting/qdrawutil.h
+++ b/src/gui/painting/qdrawutil.h
@@ -44,6 +44,7 @@
#include <QtCore/qnamespace.h>
#include <QtCore/qstring.h> // char*->QString conversion
+#include <QtGui/qpixmap.h>
QT_BEGIN_HEADER
@@ -60,7 +61,6 @@ class QPoint;
class QColor;
class QBrush;
class QRect;
-class QPixmap;
//
// Standard shade drawing
@@ -133,6 +133,42 @@ Q_GUI_EXPORT QT3_SUPPORT void qDrawArrow(QPainter *p, Qt::ArrowType type, Qt::GU
const QPalette &pal, bool enabled);
#endif
+struct Q_GUI_EXPORT QMargins
+{
+ inline QMargins(int margin = 0)
+ : top(margin),
+ left(margin),
+ bottom(margin),
+ right(margin) {}
+ inline QMargins(int topMargin, int leftMargin, int bottomMargin, int rightMargin)
+ : top(topMargin),
+ left(leftMargin),
+ bottom(bottomMargin),
+ right(rightMargin) {}
+ int top;
+ int left;
+ int bottom;
+ int right;
+};
+
+struct Q_GUI_EXPORT QTileRules
+{
+ inline QTileRules(Qt::TileRule horizontalRule, Qt::TileRule verticalRule = Qt::Stretch)
+ : horizontal(horizontalRule), vertical(verticalRule) {}
+ inline QTileRules(Qt::TileRule rule = Qt::Stretch)
+ : horizontal(rule), vertical(rule) {}
+ Qt::TileRule horizontal;
+ Qt::TileRule vertical;
+};
+
+Q_GUI_EXPORT void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap,
+ const QRect &sourceRect, const QMargins &sourceMargins, const QTileRules &rules = QTileRules());
+
+Q_GUI_EXPORT inline void qDrawBorderPixmap(QPainter *painter, const QRect &target, const QMargins &margins, const QPixmap &pixmap)
+{
+ qDrawBorderPixmap(painter, target, margins, pixmap, pixmap.rect(), margins);
+}
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp
index 4439d52..31abcad 100644
--- a/src/gui/painting/qmatrix.cpp
+++ b/src/gui/painting/qmatrix.cpp
@@ -208,9 +208,13 @@ QT_BEGIN_NAMESPACE
*/
QMatrix::QMatrix()
+ : _m11(1.)
+ , _m12(0.)
+ , _m21(0.)
+ , _m22(1.)
+ , _dx(0.)
+ , _dy(0.)
{
- _m11 = _m22 = 1.0;
- _m12 = _m21 = _dx = _dy = 0.0;
}
/*!
@@ -220,12 +224,14 @@ QMatrix::QMatrix()
\sa setMatrix()
*/
-QMatrix::QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
- qreal dx, qreal dy)
+QMatrix::QMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy)
+ : _m11(m11)
+ , _m12(m12)
+ , _m21(m21)
+ , _m22(m22)
+ , _dx(dx)
+ , _dy(dy)
{
- _m11 = m11; _m12 = m12;
- _m21 = m21; _m22 = m22;
- _dx = dx; _dy = dy;
}
@@ -233,8 +239,13 @@ QMatrix::QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
Constructs a matrix that is a copy of the given \a matrix.
*/
QMatrix::QMatrix(const QMatrix &matrix)
+ : _m11(matrix._m11)
+ , _m12(matrix._m12)
+ , _m21(matrix._m21)
+ , _m22(matrix._m22)
+ , _dx(matrix._dx)
+ , _dy(matrix._dy)
{
- *this = matrix;
}
/*!
@@ -249,12 +260,14 @@ QMatrix::QMatrix(const QMatrix &matrix)
\sa QMatrix()
*/
-void QMatrix::setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
- qreal dx, qreal dy)
+void QMatrix::setMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy)
{
- _m11 = m11; _m12 = m12;
- _m21 = m21; _m22 = m22;
- _dx = dx; _dy = dy;
+ _m11 = m11;
+ _m12 = m12;
+ _m21 = m21;
+ _m22 = m22;
+ _dx = dx;
+ _dy = dy;
}
@@ -968,18 +981,17 @@ QMatrix QMatrix::inverted(bool *invertible) const
if (determinant == 0.0) {
if (invertible)
*invertible = false; // singular matrix
- QMatrix defaultMatrix;
- return defaultMatrix;
+ return QMatrix(true);
}
else { // invertible matrix
if (invertible)
*invertible = true;
qreal dinv = 1.0/determinant;
- QMatrix imatrix((_m22*dinv), (-_m12*dinv),
- (-_m21*dinv), (_m11*dinv),
- ((_m21*_dy - _m22*_dx)*dinv),
- ((_m12*_dx - _m11*_dy)*dinv));
- return imatrix;
+ return QMatrix((_m22*dinv), (-_m12*dinv),
+ (-_m21*dinv), (_m11*dinv),
+ ((_m21*_dy - _m22*_dx)*dinv),
+ ((_m12*_dx - _m11*_dy)*dinv),
+ true);
}
}
@@ -1054,9 +1066,14 @@ QMatrix &QMatrix::operator *=(const QMatrix &m)
QMatrix QMatrix::operator *(const QMatrix &m) const
{
- QMatrix result = *this;
- result *= m;
- return result;
+ qreal tm11 = _m11*m._m11 + _m12*m._m21;
+ qreal tm12 = _m11*m._m12 + _m12*m._m22;
+ qreal tm21 = _m21*m._m11 + _m22*m._m21;
+ qreal tm22 = _m21*m._m12 + _m22*m._m22;
+
+ qreal tdx = _dx*m._m11 + _dy*m._m21 + m._dx;
+ qreal tdy = _dx*m._m12 + _dy*m._m22 + m._dy;
+ return QMatrix(tm11, tm12, tm21, tm22, tdx, tdy, true);
}
/*!
diff --git a/src/gui/painting/qmatrix.h b/src/gui/painting/qmatrix.h
index bf53c32..1e5fbb4 100644
--- a/src/gui/painting/qmatrix.h
+++ b/src/gui/painting/qmatrix.h
@@ -99,7 +99,7 @@ public:
QMatrix &shear(qreal sh, qreal sv);
QMatrix &rotate(qreal a);
- bool isInvertible() const { return !qFuzzyCompare(_m11*_m22 - _m12*_m21 + 1, 1); }
+ bool isInvertible() const { return !qFuzzyIsNull(_m11*_m22 - _m12*_m21); }
qreal det() const { return _m11*_m22 - _m12*_m21; }
QMatrix inverted(bool *invertible = 0) const;
@@ -121,6 +121,20 @@ public:
#endif
private:
+ inline QMatrix(bool)
+ : _m11(1.)
+ , _m12(0.)
+ , _m21(0.)
+ , _m22(1.)
+ , _dx(0.)
+ , _dy(0.) {}
+ inline QMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy, bool)
+ : _m11(m11)
+ , _m12(m12)
+ , _m21(m21)
+ , _m22(m22)
+ , _dx(dx)
+ , _dy(dy) {}
friend class QTransform;
qreal _m11, _m12;
qreal _m21, _m22;
@@ -147,8 +161,8 @@ Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m);
inline bool QMatrix::isIdentity() const
{
- return qFuzzyCompare(_m11, 1) && qFuzzyCompare(_m22, 1) && qFuzzyCompare(_m12 + 1, 1)
- && qFuzzyCompare(_m21 + 1, 1) && qFuzzyCompare(_dx + 1, 1) && qFuzzyCompare(_dy + 1, 1);
+ return qFuzzyIsNull(_m11 - 1) && qFuzzyIsNull(_m22 - 1) && qFuzzyIsNull(_m12)
+ && qFuzzyIsNull(_m21) && qFuzzyIsNull(_dx) && qFuzzyIsNull(_dy);
}
/*****************************************************************************
diff --git a/src/gui/painting/qpaintengine_d3d.cpp b/src/gui/painting/qpaintengine_d3d.cpp
deleted file mode 100644
index bb81623..0000000
--- a/src/gui/painting/qpaintengine_d3d.cpp
+++ /dev/null
@@ -1,4576 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qdebug.h>
-#include "qpaintengine_d3d_p.h"
-
-#include "private/qdrawhelper_p.h"
-#include "private/qfont_p.h"
-#include "private/qfontengine_p.h"
-#include "private/qpaintengine_p.h"
-#include "private/qtessellator_p.h"
-#include <private/qbezier_p.h>
-#include <private/qpainter_p.h>
-#include <private/qpixmap_raster_p.h>
-#include <private/qpolygonclipper_p.h>
-#include <qbuffer.h>
-#include <qcache.h>
-#include <qdir.h>
-#include <qfileinfo.h>
-#include <qlibrary.h>
-#include <qlibraryinfo.h>
-#include <qmath.h>
-#include <qpaintdevice.h>
-#include <qpixmapcache.h>
-
-#include <qwidget.h>
-#include <d3d9.h>
-#include <d3dx9.h>
-
-#include <mmintrin.h>
-#include <xmmintrin.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef M_PI
- #define M_PI 3.14159265358979323846
-#endif
-
-#define QD3D_MASK_MARGIN 1
-#define QD3D_BATCH_SIZE 256
-
-// for the ClearType detection stuff..
-#ifndef SPI_GETFONTSMOOTHINGTYPE
-#define SPI_GETFONTSMOOTHINGTYPE 0x200A
-#endif
-
-#ifndef FE_FONTSMOOTHINGCLEARTYPE
-#define FE_FONTSMOOTHINGCLEARTYPE 0x0002
-#endif
-
-//#include <performance.h>
-#define PM_INIT
-#define PM_MEASURE(A)
-#define PM_DISPLAY
-
-//debugging
-//#define QT_DEBUG_VERTEXBUFFER_ACCESS
-//#define QT_DEBUG_D3D
-//#define QT_DEBUG_D3D_CALLS
-
-#define QD3D_SET_MARK(output) \
- D3DPERF_SetMarker(0, QString(output).utf16());
-
-#define QT_VERTEX_RESET_LIMIT 24576
-#define QT_VERTEX_BUF_SIZE 32768
-#define QD3DFVF_CSVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE4(0) | D3DFVF_TEXCOORDSIZE4(1))
-
-// this is a different usage of the effect framework than intended,
-// but it's convenient for us to use (See effect file)
-#define PASS_STENCIL_ODDEVEN 0
-#define PASS_STENCIL_WINDING 1
-#define PASS_STENCIL_DRAW 2
-#define PASS_STENCIL_DRAW_DIRECT 3
-#define PASS_STENCIL_CLIP 4
-#define PASS_STENCIL_NOSTENCILCHECK 5
-#define PASS_STENCIL_NOSTENCILCHECK_DIRECT 6
-#define PASS_TEXT 7
-#define PASS_CLEARTYPE_TEXT 8
-#define PASS_ALIASED_LINES 9
-#define PASS_ALIASED_LINES_DIRECT 10
-
-#define PASS_AA_CREATEMASK 0
-#define PASS_AA_DRAW 1
-#define PASS_AA_DRAW_DIRECT 2
-
-#define D3D_STAGE_COUNT 2
-#define D3D_RENDER_STATES 210
-#define D3D_TEXTURE_STATES 33
-#define D3D_SAMPLE_STATES 14
-
-
-typedef HRESULT (APIENTRY *PFND3DXCREATEBUFFER)(DWORD, LPD3DXBUFFER *);
-typedef HRESULT (APIENTRY *PFND3DXCREATEEFFECT)(LPDIRECT3DDEVICE9, LPCVOID, UINT, CONST D3DXMACRO *,
- LPD3DXINCLUDE, DWORD, LPD3DXEFFECTPOOL,
- LPD3DXEFFECT *, LPD3DXBUFFER *);
-typedef D3DXMATRIX *(APIENTRY *PFND3DXMATRIXORTHOOFFCENTERLH)(D3DMATRIX *, FLOAT, FLOAT,
- FLOAT, FLOAT, FLOAT, FLOAT);
-typedef IDirect3D9 *(APIENTRY *PFNDIRECT3DCREATE9)(uint);
-
-static PFNDIRECT3DCREATE9 pDirect3DCreate9 = 0;
-static PFND3DXCREATEBUFFER pD3DXCreateBuffer = 0;
-static PFND3DXCREATEEFFECT pD3DXCreateEffect = 0;
-static PFND3DXMATRIXORTHOOFFCENTERLH pD3DXMatrixOrthoOffCenterLH = 0;
-
-
-class QD3DSurfaceManager : public QObject {
- Q_OBJECT
-
-public:
- enum QD3DSurfaceManagerStatus {
- NoStatus = 0,
- NeedsResetting = 0x01,
- MaxSizeChanged = 0x02
- };
-
- QD3DSurfaceManager();
- ~QD3DSurfaceManager();
-
- void init(LPDIRECT3D9 object);
-
- void setPaintDevice(QPaintDevice *pd);
-
- int status() const;
- void reset();
-
- LPDIRECT3DSURFACE9 renderTarget();
-
- LPDIRECT3DSURFACE9 surface(QPaintDevice *pd);
- LPDIRECT3DSWAPCHAIN9 swapChain(QPaintDevice *pd);
- void releasePaintDevice(QPaintDevice *pd);
-
- LPDIRECT3DDEVICE9 device();
- void cleanup();
-
- QSize maxSize() const;
-
-private:
- struct D3DSwapChain {
- QSize size;
- LPDIRECT3DSWAPCHAIN9 swapchain;
- LPDIRECT3DSURFACE9 surface;
- };
-
- void updateMaxSize();
- void initPresentParameters(D3DPRESENT_PARAMETERS *params);
- D3DSwapChain *createSwapChain(QWidget *w);
-
- QSize m_max_size;
- int m_status;
- QMap<QPaintDevice *, D3DSwapChain *> m_swapchains;
-
- LPDIRECT3DDEVICE9 m_device;
- QPaintDevice *m_pd;
- HWND m_dummy;
- D3DSwapChain *m_current;
-
-private Q_SLOTS:
- void cleanupPaintDevice(QObject *);
-};
-
-struct vertex {
- D3DVECTOR pos;
- DWORD color;
- FLOAT s0, t0, r0, q0;
- FLOAT s1, t1, r1, q1;
-};
-
-struct QD3DMaskPosition {
- int x, y, channel;
-};
-
-
-struct QD3DBatchItem {
- enum QD3DBatchInfo {
- BI_WINDING = 0x0001,
- BI_AA = 0x0002,
- BI_BRECT = 0x0004,
- BI_MASKFULL = 0x0008,
- BI_TEXT = 0x0010,
- BI_MASK = 0x0020,
- BI_CLIP = 0x0040,
- BI_SCISSOR = 0x0080,
-
- BI_PIXMAP = 0x0100,
- BI_IMAGE = 0x0200,
- BI_COMPLEXBRUSH = 0x0400,
-
- BI_CLEARCLIP = 0x0800, // clip nothing (filling the clip mask with 0)
- BI_TRANSFORM = 0x1000,
- BI_MASKSCISSOR = 0x2000,
- BI_FASTLINE = 0x4000,
- BI_COSMETICPEN = 0x8000
- };
-
- int m_info;
-
- int m_count;
- int m_offset;
-
- QD3DMaskPosition m_maskpos;
- qreal m_xoffset;
- qreal m_yoffset;
- qreal m_opacity;
-
- QPixmap m_pixmap;
- QRectF m_brect;
- QBrush m_brush;
-
- IDirect3DTexture9 *m_texture;
-
- qreal m_width;
- qreal m_distance;
-
- QTransform m_matrix;
- QPainter::CompositionMode m_cmode;
-
- QVector<int> m_pointstops;
-};
-
-struct QD3DBatch {
- int m_item_index;
- QD3DBatchItem items[QD3D_BATCH_SIZE];
-};
-
-class QD3DStateManager;
-class QD3DFontCache;
-class QD3DDrawHelper;
-class QD3DGradientCache;
-
-class QDirect3DPaintEnginePrivate : public QPaintEnginePrivate
-{
- Q_DECLARE_PUBLIC(QDirect3DPaintEngine)
-
-public:
- enum RenderTechnique {
- RT_NoTechnique,
- RT_Antialiased,
- RT_Aliased,
- };
-
- QDirect3DPaintEnginePrivate()
- : m_d3d_object(0)
- , m_d3d_device(0)
- , m_txop(QTransform::TxNone)
- , m_effect(0)
- , m_flush_on_end(0)
- { init(); }
-
- ~QDirect3DPaintEnginePrivate();
-
- bool init();
- void initDevice();
-
- inline QD3DBatchItem *nextBatchItem();
-
- QPolygonF brushCoordinates(const QRectF &r, bool stroke, qreal *fp) const;
- void fillAliasedPath(QPainterPath path, const QRectF &brect, const QTransform &txform);
- void fillAntialiasedPath(const QPainterPath &path, const QRectF &brect,
- const QTransform &txform, bool stroke);
- void fillPath(const QPainterPath &path, QRectF brect);
-
- void strokePath(const QPainterPath &path, QRectF brect, bool simple = false);
- QPainterPath strokePathFastPen(const QPainterPath &path);
- void strokeAliasedPath(QPainterPath path, const QRectF &brect, const QTransform &txform);
-
- void flushBatch();
- int flushAntialiased(int offset);
- void flushAliased(QD3DBatchItem *item, int offset);
- void flushText(QD3DBatchItem *item, int offset);
- void flushLines(QD3DBatchItem *item, int offset);
-
- void updateTransform(const QTransform &matrix);
- void updatePen(const QPen &pen);
- void updateBrush(const QBrush &pen);
- void updateClipRegion(const QRegion &clipregion, Qt::ClipOperation op = Qt::ReplaceClip);
- void updateClipPath(const QPainterPath &clipregion, Qt::ClipOperation op = Qt::ReplaceClip);
- void updateFont(const QFont &font);
-
- void setRenderTechnique(RenderTechnique technique);
-
- QPointF transformPoint(const QPointF &p, qreal *w) const;
-
- bool prepareBatch(QD3DBatchItem *item, int offset);
- void prepareItem(QD3DBatchItem *item);
- void cleanupItem(QD3DBatchItem *item);
- void setCompositionMode(QPainter::CompositionMode mode);
-
- void verifyTexture(const QPixmap &pixmap);
-
- bool isFastRect(const QRectF &rect);
-
- void releaseDC();
-
- void cleanup();
- bool testCaps();
-
- QPixmap getPattern(Qt::BrushStyle style) const;
-
- // clipping
- QPainterPath m_sysclip_path;
- QPainterPath m_clip_path;
- QRegion m_sysclip_region;
- QRegion m_clip_region;
-
- qreal m_opacity;
- D3DCOLOR m_opacity_color;
-
- int m_current_state;
-
- ID3DXEffect* m_effect;
-
- RenderTechnique m_current_technique;
-
- QTransform m_matrix;
- qreal m_inv_scale;
-
- QPen m_pen;
- Qt::BrushStyle m_pen_brush_style;
- QTransform m_inv_pen_matrix;
- D3DCOLOR m_pen_color;
- qreal m_pen_width;
-
- QBrush m_brush;
- Qt::BrushStyle m_brush_style;
- QTransform m_inv_brush_matrix;
- D3DCOLOR m_brush_color;
- QTransform m_brush_origin;
-
- uint m_clipping_enabled : 1;
- uint m_has_complex_clipping : 1;
- uint m_cleartype_text: 1;
- uint m_has_pen : 1;
- uint m_has_cosmetic_pen : 1;
- uint m_has_brush : 1;
- uint m_has_fast_pen : 1;
- uint m_has_aa_fast_pen : 1;
- uint m_flush_on_end : 1;
- uint m_supports_d3d : 1;
-
- QTransform::TransformationType m_txop;
-
- QPainter::CompositionMode m_cmode;
-
- QD3DSurfaceManager m_surface_manager;
- QSize m_surface_size;
-
- LPDIRECT3D9 m_d3d_object;
- LPDIRECT3DDEVICE9 m_d3d_device;
- IDirect3DSurface9 *m_current_surface;
- bool m_in_scene;
-
- QD3DGradientCache *m_gradient_cache;
- QD3DDrawHelper *m_draw_helper;
- QD3DBatch m_batch;
- QD3DStateManager *m_statemanager;
-
- HDC m_dc;
- IDirect3DSurface9 *m_dcsurface;
-
- QMap<Qt::BrushStyle, QPixmap> m_patterns;
-};
-
-
-class QD3DStateManager : public ID3DXEffectStateManager {
-public:
- QD3DStateManager(LPDIRECT3DDEVICE9 pDevice, ID3DXEffect *effect);
- void reset();
-
- inline void startStateBlock();
- inline void endStateBlock();
-
- inline void setCosmeticPen(bool enabled);
- inline void setBrushMode(int mode);
- inline void setTexture(LPDIRECT3DBASETEXTURE9 pTexture);
- inline void setTexture(LPDIRECT3DBASETEXTURE9 pTexture, QGradient::Spread spread);
- inline void setTransformation(const QTransform *matrix = 0);
- inline void setProjection(const D3DXMATRIX *pMatrix);
- inline void setMaskChannel(int channel);
- inline void setMaskOffset(qreal x, qreal y);
- inline void setFocalDistance(const qreal &fd);
-
- inline void beginPass(int pass);
- inline void endPass();
-
- STDMETHOD(QueryInterface)(REFIID iid, LPVOID *ppv);
- STDMETHOD_(ULONG, AddRef)();
- STDMETHOD_(ULONG, Release)();
-
- STDMETHOD(SetTransform)(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX *pMatrix);
- STDMETHOD(SetMaterial)(CONST D3DMATERIAL9 *pMaterial);
- STDMETHOD(SetLight)(DWORD Index, CONST D3DLIGHT9 *pLight);
- STDMETHOD(LightEnable)(DWORD Index, BOOL Enable);
- STDMETHOD(SetRenderState)(D3DRENDERSTATETYPE State, DWORD Value);
- STDMETHOD(SetTexture)(DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture);
- STDMETHOD(SetTextureStageState)(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
- STDMETHOD(SetSamplerState)(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
- STDMETHOD(SetNPatchMode)(FLOAT NumSegments);
- STDMETHOD(SetFVF)(DWORD FVF);
- STDMETHOD(SetVertexShader)(LPDIRECT3DVERTEXSHADER9 pShader);
- STDMETHOD(SetVertexShaderConstantF)(UINT RegisterIndex, CONST FLOAT *pConstantData, UINT RegisterCount);
- STDMETHOD(SetVertexShaderConstantI)(UINT RegisterIndex, CONST INT *pConstantData, UINT RegisterCount);
- STDMETHOD(SetVertexShaderConstantB)(UINT RegisterIndex, CONST BOOL *pConstantData, UINT RegisterCount);
- STDMETHOD(SetPixelShader)(LPDIRECT3DPIXELSHADER9 pShader);
- STDMETHOD(SetPixelShaderConstantF)(UINT RegisterIndex, CONST FLOAT *pConstantData, UINT RegisterCount);
- STDMETHOD(SetPixelShaderConstantI)(UINT RegisterIndex, CONST INT *pConstantData, UINT RegisterCount);
- STDMETHOD(SetPixelShaderConstantB)(UINT RegisterIndex, CONST BOOL *pConstantData, UINT RegisterCount);
-private:
- LPDIRECT3DVERTEXSHADER9 m_vertexshader;
- LPDIRECT3DPIXELSHADER9 m_pixelshader;
-
- LPDIRECT3DBASETEXTURE9 m_textures[D3D_STAGE_COUNT];
- DWORD m_texturestates[D3D_STAGE_COUNT][D3D_TEXTURE_STATES];
- DWORD m_samplerstates[D3D_STAGE_COUNT][D3D_SAMPLE_STATES];
- DWORD m_renderstate[D3D_RENDER_STATES];
-
- qreal m_radgradfd;
-
- bool m_cosmetic_pen;
- int m_pass;
- int m_maskchannel;
- int m_brushmode;
- LPDIRECT3DBASETEXTURE9 m_texture;
- D3DXMATRIX m_projection;
-
- D3DXMATRIX m_d3dIdentityMatrix;
- bool m_isIdentity;
- QTransform m_transformation;
-
- LPDIRECT3DDEVICE9 m_pDevice;
- ID3DXEffect *m_effect;
-
- LONG m_refs;
- bool m_changed;
- qreal m_xoffset, m_yoffset;
- static int m_mask_channels[4][4];
-};
-
-//
-// font cache stuff
-//
-
-struct QD3DGlyphCoord {
- // stores the offset and size of a glyph texture
- qreal x;
- qreal y;
- qreal width;
- qreal height;
- qreal log_width;
- qreal log_height;
- QFixed x_offset;
- QFixed y_offset;
-};
-
-struct QD3DFontTexture {
- int x_offset; // current glyph offset within the texture
- int y_offset;
- int width;
- int height;
- IDirect3DTexture9 *texture;
-};
-
-typedef QHash<glyph_t, QD3DGlyphCoord*> QD3DGlyphHash;
-typedef QHash<QFontEngine*, QD3DGlyphHash*> QD3DFontGlyphHash;
-typedef QHash<quint64, QD3DFontTexture*> QD3DFontTexHash;
-
-class QD3DGlyphCache : public QObject
-{
- Q_OBJECT
-public:
- QD3DGlyphCache()
- : QObject(0)
- , current_cache(0) {}
- ~QD3DGlyphCache();
- QD3DGlyphCoord *lookup(QFontEngine *, glyph_t);
- void cacheGlyphs(QDirect3DPaintEngine *, const QTextItemInt &, const QVarLengthArray<glyph_t> &,
- bool);
- void cleanCache();
- inline QD3DFontTexture *fontTexture(QFontEngine *engine) {
- return font_textures.constFind(reinterpret_cast<quint64>(engine)).value();
- }
-
-public slots:
- void fontEngineDestroyed(QObject *);
-
-private:
- QImage clearTypeGlyph(QFontEngine *, glyph_t glyph);
- QD3DGlyphHash *current_cache;
- QD3DFontTexHash font_textures;
- QD3DFontGlyphHash font_cache;
-};
-
-QD3DGlyphCache::~QD3DGlyphCache()
-{
-}
-
-QD3DGlyphCoord *QD3DGlyphCache::lookup(QFontEngine *, glyph_t g)
-{
- Q_ASSERT(current_cache != 0);
- QD3DGlyphHash::const_iterator it = current_cache->constFind(g);
- if (it == current_cache->constEnd())
- return 0;
- return it.value();
-}
-
-void QD3DGlyphCache::cleanCache()
-{
- QList<quint64> keys = font_textures.keys();
- for (int i=0; i<keys.size(); ++i)
- font_textures.value(keys.at(i))->texture->Release();
-
- qDeleteAll(font_textures);
- qDeleteAll(font_cache);
- font_textures.clear();
- font_cache.clear();
- current_cache = 0;
-}
-
-void QD3DGlyphCache::fontEngineDestroyed(QObject *object)
-{
-// qDebug() << "=> font engine destroyed: " << object;
- QFontEngine *engine = static_cast<QFontEngine *>(object);
-
- QD3DFontGlyphHash::iterator cache_it = font_cache.find(engine);
- if (cache_it != font_cache.end()) {
- QD3DGlyphHash *cache = font_cache.take(engine);
- delete cache;
- }
-
- quint64 font_key = reinterpret_cast<quint64>(engine);
- QD3DFontTexture *tex = font_textures.take(font_key);
- if (tex) {
- tex->texture->Release();
- delete tex;
- }
-}
-
-QImage QD3DGlyphCache::clearTypeGlyph(QFontEngine *engine, glyph_t glyph)
-{
- glyph_metrics_t gm = engine->boundingBox(glyph);
- int glyph_x = qFloor(gm.x.toReal());
- int glyph_y = qFloor(gm.y.toReal());
- int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x + 2;
- int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y + 2;
-
- if (glyph_width + glyph_x <= 0 || glyph_height <= 0)
- return QImage();
- QImage im(glyph_width + glyph_x, glyph_height, QImage::Format_ARGB32_Premultiplied);
- im.fill(0xff000000); // solid black
- QPainter p(&im);
-
- p.setPen(Qt::white);
- p.setBrush(Qt::NoBrush);
-
- QTextItemInt ti;
- ti.ascent = engine->ascent();
- ti.descent = engine->descent();
- ti.width = glyph_width;
- ti.fontEngine = engine;
-
- QGlyphLayoutArray<1> glyphLayout;
- ti.glyphs = glyphLayout;
- ti.glyphs.glyphs[0] = glyph;
- ti.glyphs.advances_x[0] = glyph_width;
- p.drawTextItem(QPointF(-glyph_x, -glyph_y), ti);
- p.end();
- return im;
-}
-
-#if 0
-static void dump_font_texture(QD3DFontTexture *tex)
-{
- QColor color(Qt::red);
- D3DLOCKED_RECT rect;
- if (FAILED(tex->texture->LockRect(0, &rect, 0, 0))) {
- qDebug() << "debug: unable to lock texture rect.";
- return;
- }
-
-// cleartype version
-// uint *tex_data = (uint *) rect.pBits;
-// QImage im(tex->width, tex->height, QImage::Format_ARGB32);
-// for (int y=0; y<tex->height; ++y) {
-// for (int x=0; x<tex->width; ++x) {
-// im.setPixel(x, y, ((*(tex_data+x+y*tex->width))));
-// }
-// }
- uchar *tex_data = (uchar *) rect.pBits;
- QImage im(rect.Pitch, tex->height, QImage::Format_ARGB32);
- for (int y=0; y<tex->height; ++y) {
- for (int x=0; x<rect.Pitch; ++x) {
- uchar val = ((*(tex_data+x+y*rect.Pitch)));
- im.setPixel(x, y, 0xff000000 | (val << 16) | (val << 8) | val);
- }
- }
- tex->texture->UnlockRect(0);
- static int i= 0;
- im.save(QString("tx%1.png").arg(i++));
-}
-#endif
-
-void QD3DGlyphCache::cacheGlyphs(QDirect3DPaintEngine *engine, const QTextItemInt &ti,
- const QVarLengthArray<glyph_t> &glyphs, bool clearType)
-{
- IDirect3DDevice9 *device = engine->d_func()->m_d3d_device;
- QD3DFontGlyphHash::const_iterator cache_it = font_cache.constFind(ti.fontEngine);
- QD3DGlyphHash *cache = 0;
- if (cache_it == font_cache.constEnd()) {
- cache = new QD3DGlyphHash;
- font_cache.insert(ti.fontEngine, cache);
- connect(ti.fontEngine, SIGNAL(destroyed(QObject *)), SLOT(fontEngineDestroyed(QObject *)));
- } else {
- cache = cache_it.value();
- }
-
- current_cache = cache;
-
- D3DFORMAT tex_format = clearType ? D3DFMT_A8R8G8B8 : D3DFMT_A8;
- quint64 font_key = reinterpret_cast<quint64>(ti.fontEngine);
- QD3DFontTexHash::const_iterator it = font_textures.constFind(font_key);
- QD3DFontTexture *font_tex = 0;
- if (it == font_textures.constEnd()) {
- // alloc a new texture, put it into the cache
- int tex_height = qCeil(ti.ascent.toReal() + ti.descent.toReal()) + 5;
- int tex_width = tex_height * 30; // ###
- IDirect3DTexture9 *tex;
- if (FAILED(device->CreateTexture(tex_width, tex_height, 1, 0,
- tex_format, D3DPOOL_MANAGED, &tex, NULL)))
- {
- qWarning("QD3DGlyphCache::cacheGlyphs(): can't allocate font texture (%dx%d).",
- tex_width, tex_height);
- return;
- } else {
-// qDebug() << "=> new font texture: " << QSize(tex_width,tex_height);
- font_tex = new QD3DFontTexture;
- font_tex->texture = tex;
- font_tex->x_offset = 0;
- font_tex->y_offset = 0;
- font_tex->width = tex_width;
- font_tex->height = tex_height;
- font_textures.insert(font_key, font_tex);
- }
- } else {
- font_tex = it.value();
- // make it current render target..
- }
-
- // cache each glyph
- for (int i=0; i<glyphs.size(); ++i) {
- QD3DGlyphHash::const_iterator it = cache->constFind(glyphs[i]);
- if (it == cache->constEnd()) {
- glyph_metrics_t metrics = ti.fontEngine->boundingBox(glyphs[i]);
- int glyph_width = qCeil(metrics.width.toReal()) + 5;
- int glyph_height = qCeil(ti.ascent.toReal() + ti.descent.toReal()) + 5;
- if (font_tex->x_offset + glyph_width > font_tex->width) {
- // no room on the current line, start new glyph strip
- int strip_height = glyph_height;
- font_tex->x_offset = 0;
- font_tex->y_offset += strip_height;
- if (font_tex->y_offset >= font_tex->height) {
- // if no room in the current texture - realloc a larger texture
- int old_tex_height = font_tex->height;
- font_tex->height += strip_height;
-
- IDirect3DTexture9 *new_tex;
- if (FAILED(device->CreateTexture(font_tex->width, font_tex->height, 1, 0,
- tex_format, D3DPOOL_MANAGED, &new_tex, NULL)))
- {
- qWarning("QD3DGlyphCache(): can't re-allocate font texture.");
- return;
- } else {
-// qDebug() << " -> new glyph strip added:" << QSize(font_tex->width,font_tex->height);
-
- D3DLOCKED_RECT new_rect, old_rect;
- if (FAILED(font_tex->texture->LockRect(0, &old_rect, 0, D3DLOCK_READONLY))) {
- qDebug() << "QD3DGlyphCache: unable to lock texture rect.";
- return;
- }
- if (FAILED(new_tex->LockRect(0, &new_rect, 0, 0))) {
- qDebug() << "QD3DGlyphCache: unable to lock texture rect.";
- return;
- }
- memcpy(new_rect.pBits, old_rect.pBits, new_rect.Pitch * old_tex_height);
- font_tex->texture->UnlockRect(0);
- new_tex->UnlockRect(0);
- engine->d_func()->flushBatch();
- font_tex->texture->Release();
- font_tex->texture = new_tex;
- }
-
- // update the texture coords and the y offset for the existing glyphs in
- // the cache, because of the texture size change
- QD3DGlyphHash::iterator it = cache->begin();
- while (it != cache->end()) {
- it.value()->height = (it.value()->height * old_tex_height) / font_tex->height;
- it.value()->y = (it.value()->y * old_tex_height) / font_tex->height;
- ++it;
- }
- }
- }
- QD3DGlyphCoord *d3d_glyph = new QD3DGlyphCoord;
- d3d_glyph->x = qreal(font_tex->x_offset) / font_tex->width;
- d3d_glyph->y = qreal(font_tex->y_offset) / font_tex->height;
- d3d_glyph->width = qreal(glyph_width) / font_tex->width;
- d3d_glyph->height = qreal(glyph_height) / font_tex->height;
- d3d_glyph->log_width = d3d_glyph->width * font_tex->width;
- d3d_glyph->log_height = d3d_glyph->height * font_tex->height;
- d3d_glyph->x_offset = -metrics.x;
- d3d_glyph->y_offset = metrics.y;
-
- QImage glyph_im;
- if (clearType)
- glyph_im = clearTypeGlyph(ti.fontEngine, glyphs[i]);
- else
- glyph_im = ti.fontEngine->alphaMapForGlyph(glyphs[i]).convertToFormat(QImage::Format_Indexed8);
-
- // write glyph to texture
- D3DLOCKED_RECT rect;
- RECT glyph_rect = { font_tex->x_offset, font_tex->y_offset,
- font_tex->x_offset + glyph_im.width(),
- font_tex->y_offset + glyph_im.height() };
-
-// qDebug() << " > new glyph char added:" << QSize(glyph_im.width(), glyph_im.height());
- if (FAILED(font_tex->texture->LockRect(0, &rect, &glyph_rect, 0))) {
- qDebug() << "QD3DGlyphCache: unable to lock texture rect.";
- return;
- }
-
- // ### unify these loops
- if (clearType) {
- int ppl = rect.Pitch / 4;
- uint *tex_data = (uint *) rect.pBits;
- for (int y=0; y<glyph_im.height(); ++y) {
- uint *s = (uint *) glyph_im.scanLine(y);
- for (int x=0; x<glyph_im.width(); ++x) {
- tex_data[ppl*y + x] = *s;
- ++s;
- }
- }
- } else {
- int ppl = rect.Pitch;
- uchar *tex_data = (uchar *) rect.pBits;
- for (int y=0; y<glyph_im.height(); ++y) {
- uchar *s = (uchar *) glyph_im.scanLine(y);
- for (int x=0; x<glyph_im.width(); ++x) {
- tex_data[ppl*y + x] = *s;
- ++s;
- }
- }
- }
- font_tex->texture->UnlockRect(0);
-
- // debug
-// dump_font_texture(font_tex);
-
- if (font_tex->x_offset + glyph_width > font_tex->width) {
- font_tex->x_offset = 0;
- font_tex->y_offset += glyph_height;
- } else {
- font_tex->x_offset += glyph_width;
- }
-
- cache->insert(glyphs[i], d3d_glyph);
- }
- }
-}
-
-Q_GLOBAL_STATIC(QD3DGlyphCache, qd3d_glyph_cache)
-
-//
-// end font caching stuff
-//
-
-
-//
-// D3D image cache stuff
-//
-
-// ### keep the GL stuff in mind..
-typedef void (*_qt_image_cleanup_hook_64)(qint64);
-extern Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64;
-
-static void qd3d_image_cleanup(qint64 key);
-
-class QD3DImage
-{
-public:
- QD3DImage(IDirect3DDevice9 *device, const QImage &image);
- ~QD3DImage();
-
- IDirect3DTexture9 *texture;
-};
-
-static QList<IDirect3DTexture9 *> qd3d_release_list;
-
-QD3DImage::QD3DImage(IDirect3DDevice9 *device, const QImage &image)
-{
- texture = 0;
- Q_ASSERT(device);
- QImage im = image.convertToFormat(QImage::Format_ARGB32);
- if (FAILED(device->CreateTexture(im.width(), im.height(), 1, 0,
- D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, 0))) {
- qWarning("QD3DImage(): unable to create Direct3D texture.");
- return;
- }
-// qDebug(" -> created image texture: %p - 0x%08x%08x",texture,uint (image.cacheKey() >> 32),uint (image.cacheKey() & 0xffffffff));
- D3DLOCKED_RECT rect;
- if (FAILED(texture->LockRect(0, &rect, 0, 0))) {
- qDebug() << "QD3DImage: unable to lock texture rect.";
- return;
- }
- DWORD *dst = (DWORD *) rect.pBits;
- DWORD *src = (DWORD *) im.scanLine(0);
-
- Q_ASSERT((rect.Pitch/4) == (im.bytesPerLine()/4));
- memcpy(dst, src, rect.Pitch*im.height());
- texture->UnlockRect(0);
-}
-
-QD3DImage::~QD3DImage()
-{
- if (texture)
- qd3d_release_list.append(texture);
-}
-
-static int qd3d_cache_limit = 64*1024; // cache ~64 MB worth of textures
-typedef QCache<quint64, QD3DImage> QD3DImageCache;
-
-class QD3DImageManager
-{
-public:
- QD3DImageManager() {
- // ### GL does the same!
- qt_image_cleanup_hook_64 = qd3d_image_cleanup;
- cache.setMaxCost(qd3d_cache_limit);
- }
- ~QD3DImageManager() {
-// qDebug() << "unhooking d3d image cache";
- qt_image_cleanup_hook_64 = 0;
- cache.clear();
- }
-
- IDirect3DTexture9 *lookup(IDirect3DDevice9 *device, const QImage &image);
- void remove(quint64 key);
-
-private:
- QD3DImageCache cache;
-};
-
-IDirect3DTexture9 *QD3DImageManager::lookup(IDirect3DDevice9 *device, const QImage &image)
-{
- QD3DImage *tex_image = 0;
-
- tex_image = cache.object(image.cacheKey());
- if (!tex_image) {
- // to avoid cache thrashing we remove images from the cache
- // that have the same serial no as the cached image, since
- // that image is most likely destoyed already, and we got a
- // stale cache entry
- uint serial = (uint) (image.cacheKey() >> 32);
- QList<quint64> keys = cache.keys();
- for (int i=0; i<keys.size(); ++i) {
- if ((uint)(keys.at(i) >> 32) == serial) {
- cache.remove(keys.at(i));
- break;
- }
- }
-// qDebug(" => cached: %d, adding cache image: 0x%08x%08x",cache.size(), uint (image.cacheKey() >> 32),uint (image.cacheKey() & 0xffffffff));
- // add cache entry
- int cost = image.width()*image.height()*4/1024;
- if (cache.totalCost() + cost > cache.maxCost()) {
- // no room for new entries? kick out half the cached images
- int old_max_cost = cache.maxCost();
- cache.setMaxCost(old_max_cost/2);
- cache.setMaxCost(old_max_cost);
- }
- tex_image = new QD3DImage(device, image);
- cache.insert(image.cacheKey(), tex_image, cost);
-// qDebug() << "==> total cache cost: " << cache.totalCost() << cost;
- }
-
- return tex_image->texture;
-}
-
-void QD3DImageManager::remove(quint64 key)
-{
-// QList<quint64> keys = cache.keys();
-// if (keys.contains(key))
-// qDebug() << "entery removed from cache";
- cache.remove(key);
-}
-
-Q_GLOBAL_STATIC(QD3DImageManager, qd3d_image_cache)
-
-static void qd3d_image_cleanup(qint64 key)
-{
-// qDebug() << "qd3d_image_cleanup:";
-// qDebug(" => key: 0x%08x%08x", (uint) (key >> 32), (uint)(key & 0xffffffff));
- qd3d_image_cache()->remove(key);
-}
-
-//
-// end D3D image cache stuff
-//
-
-class QD3DDrawHelper : public QTessellator
-{
-public:
- QD3DDrawHelper(QDirect3DPaintEnginePrivate *pe);
- ~QD3DDrawHelper();
-
- bool needsFlushing() const;
- QD3DMaskPosition allocateMaskPosition(const QRectF &brect, bool *breakbatch);
-
- void setClipPath(const QPainterPath &path, QD3DBatchItem **item);
-
- void queueAntialiasedMask(const QPolygonF &poly, QD3DBatchItem **item, const QRectF &brect);
- QRectF queueAliasedMask(const QPainterPath &path, QD3DBatchItem **item, D3DCOLOR color);
-
- void queueRect(const QRectF &rect, QD3DBatchItem *item, D3DCOLOR color, const QPolygonF &trect);
- void queueRect(const QRectF &rect, QD3DBatchItem *item, D3DCOLOR color);
-
- void queueTextGlyph(const QRectF &rect, const qreal *tex_coords, QD3DBatchItem *item,
- D3DCOLOR color);
-
- void queueAntialiasedLines(const QPainterPath &path, QD3DBatchItem **item, const QRectF &brect);
- void queueAliasedLines(const QLineF *lines, int lineCount, QD3DBatchItem **item);
-
- int drawAntialiasedMask(int offset, int maxoffset);
- void drawAliasedMask(int offset);
- void drawAntialiasedBoundingRect(QD3DBatchItem *item);
- void drawAliasedBoundingRect(QD3DBatchItem *item);
- void drawTextItem(QD3DBatchItem *item);
- void drawAliasedLines(QD3DBatchItem *item);
-
- void setMaskSize(QSize size);
-
- void beforeReset();
- void afterReset();
-
- IDirect3DSurface9 *freeMaskSurface();
-
- inline void lockVertexBuffer();
- inline void unlockVertexBuffer();
-
- inline int index() { return m_index; }
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- enum VertexBufferAccess {
- CLEAR = 0x00,
- READ = 0x01,
- WRITE = 0x02
- };
- int accesscontrol[QT_VERTEX_BUF_SIZE];
-#endif
-
-private:
- void addTrap(const Trapezoid &trap);
- void tessellate(const QPolygonF &poly);
- inline void lineToStencil(qreal x, qreal y);
- inline void curveToStencil(const QPointF &cp1, const QPointF &cp2, const QPointF &ep);
- QRectF pathToVertexArrays(const QPainterPath &path);
- void resetMask();
-
- QDirect3DPaintEnginePrivate *m_pe;
-
- qreal m_xoffset, m_yoffset;
- int m_startindex;
- int m_index;
- int m_height, m_width;
- LPDIRECT3DVERTEXBUFFER9 m_d3dvbuff;
- vertex *m_vbuff;
- QD3DBatchItem *m_item;
- QRectF m_boundingRect;
-
- qreal max_x;
- qreal max_y;
- qreal min_x;
- qreal min_y;
- qreal firstx;
- qreal firsty;
-
- QPointF tess_lastpoint;
- int tess_index;
-
- bool m_locked;
- IDirect3DTexture9 *m_mask;
- IDirect3DSurface9 *m_maskSurface;
- IDirect3DSurface9 *m_depthStencilSurface;
-
- D3DCOLOR m_color;
- bool m_clearmask;
- bool m_isLine;
- bool m_firstPoint;
-
- QD3DMaskPosition m_mask_position;
- int m_mask_offsetX2;
- int m_mask_offsetY2;
-};
-
-QD3DStateManager::QD3DStateManager(LPDIRECT3DDEVICE9 pDevice, ID3DXEffect *effect)
- : m_pDevice(pDevice), m_effect(effect), m_refs(0)
-{
- if (FAILED(D3DXMatrixIdentity(&m_d3dIdentityMatrix))) {
- qWarning("QDirect3DPaintEngine: D3DXMatrixIdentity failed");
- }
- reset();
-}
-
-void QD3DStateManager::reset()
-{
- m_radgradfd = -1;
-
- m_cosmetic_pen = false;
- m_pass = -1;
- m_maskchannel = -1;
- m_brushmode = -1;
- m_texture = 0;
- m_xoffset = INT_MAX;
- m_yoffset = INT_MAX;
-
- m_vertexshader = 0;
- m_pixelshader = 0;
-
- m_isIdentity = true;
- m_transformation = QTransform();
- m_effect->SetMatrix("g_mTransformation", &m_d3dIdentityMatrix);
-
- ZeroMemory(&m_projection, sizeof(D3DMATRIX));
- ZeroMemory(m_textures, sizeof(LPDIRECT3DBASETEXTURE9) * D3D_STAGE_COUNT);
- FillMemory(m_samplerstates, sizeof(DWORD) * D3D_SAMPLE_STATES * D3D_STAGE_COUNT, 0xFFFFFFFE);
- FillMemory(m_texturestates, sizeof(DWORD) * D3D_TEXTURE_STATES * D3D_STAGE_COUNT, 0xFFFFFFFE);
- FillMemory(m_renderstate, sizeof(DWORD) * D3D_RENDER_STATES, 0xFFFFFFFE);
-}
-
-inline void QD3DStateManager::beginPass(int pass)
-{
- if (pass != m_pass) {
- if (m_pass != -1)
- m_effect->EndPass();
- m_effect->BeginPass(pass);
- m_pass = pass;
- }
-}
-
-inline void QD3DStateManager::endPass()
-{
- if (m_pass != -1) {
- m_pass = -1;
- m_effect->EndPass();
- }
-}
-
-inline void QD3DStateManager::startStateBlock() {
- m_changed = false;
-}
-
-inline void QD3DStateManager::setCosmeticPen(bool enabled)
-{
- if (enabled != m_cosmetic_pen) {
- m_effect->SetBool("g_mCosmeticPen", enabled);
- m_cosmetic_pen = enabled;
- m_changed = true;
- }
-}
-
-inline void QD3DStateManager::setBrushMode(int mode)
-{
- if (mode != m_brushmode) {
- m_effect->SetInt("g_mBrushMode", mode);
- m_brushmode = mode;
- m_changed = true;
- }
-}
-
-inline void QD3DStateManager::setTexture(LPDIRECT3DBASETEXTURE9 pTexture)
-{
- SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
- SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
-
- if (pTexture != m_texture) {
- m_texture = pTexture;
- m_effect->SetTexture("g_mTexture", pTexture);
- m_changed = true;
- }
-}
-
-inline void QD3DStateManager::setTexture(LPDIRECT3DBASETEXTURE9 pTexture, QGradient::Spread spread)
-{
- switch(spread) {
- case QGradient::RepeatSpread:
- SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
- SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
- break;
- case QGradient::ReflectSpread:
- SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
- SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
- break;
- default:
- SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
- SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
- break;
- };
-
- if (pTexture != m_texture) {
- m_texture = pTexture;
- m_effect->SetTexture("g_mTexture", pTexture);
- m_changed = true;
- }
-}
-
-inline void QD3DStateManager::setTransformation(const QTransform *matrix)
-{
- if (matrix) {
- if (*matrix != m_transformation) {
- D3DXMATRIX dxmatrix(matrix->m11(), matrix->m12(), 0, matrix->m13(),
- matrix->m21(), matrix->m22(), 0, matrix->m23(),
- 0, 0, 1, 0,
- matrix->dx(), matrix->dy(), 0, 1);
- m_effect->SetMatrix("g_mTransformation", &dxmatrix);
- m_transformation = *matrix;
- m_changed = true;
- m_isIdentity = false;
- }
- } else if (!m_isIdentity) {
- m_effect->SetMatrix("g_mTransformation", &m_d3dIdentityMatrix);
- m_transformation = QTransform();
- m_changed = true;
- m_isIdentity = true;
- }
-}
-
-inline void QD3DStateManager::setProjection(const D3DXMATRIX *pMatrix)
-{
- if (*pMatrix != m_projection) {
- m_effect->SetMatrix("g_mViewProjection", pMatrix);
- m_projection = *pMatrix;
- m_changed = true;
- }
-}
-
-inline void QD3DStateManager::setFocalDistance(const qreal &fd)
-{
- if (fd != m_radgradfd) {
- m_effect->SetFloat("g_mFocalDist", fd);
- m_changed = true;
- m_radgradfd = fd;
- }
-}
-
-inline void QD3DStateManager::setMaskOffset(qreal x, qreal y)
-{
- if (x != m_xoffset || y != m_yoffset) {
- float offset[2] = {x, y};
- m_effect->SetFloatArray("g_mMaskOffset", offset, 2);
- m_xoffset = x;
- m_yoffset = y;
- m_changed = true;
- }
-}
-
-inline void QD3DStateManager::setMaskChannel(int channel)
-{
- if (m_maskchannel != channel) {
- m_effect->SetIntArray("g_mChannel", m_mask_channels[channel], 4);
- m_maskchannel = channel;
- m_changed = true;
- }
-}
-
-inline void QD3DStateManager::endStateBlock()
-{
- if (m_changed) {
- m_effect->CommitChanges();
- m_changed = false;
- }
-}
-
-STDMETHODIMP QD3DStateManager::QueryInterface(REFIID iid, LPVOID *ppv)
-{
- if(iid == IID_IUnknown || iid == IID_ID3DXEffectStateManager)
- {
- *ppv = this;
- ++m_refs;
- return NOERROR;
- }
- *ppv = NULL;
- return ResultFromScode(E_NOINTERFACE);
-}
-
-STDMETHODIMP_(ULONG) QD3DStateManager::AddRef(void)
-{
- return (ULONG)InterlockedIncrement( &m_refs );
-}
-
-
-STDMETHODIMP_(ULONG) QD3DStateManager::Release(void)
-{
- if( 0L == InterlockedDecrement( &m_refs ) ) {
- delete this;
- return 0L;
- }
-
- return m_refs;
-}
-STDMETHODIMP QD3DStateManager::SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX *pMatrix)
-{
- return m_pDevice->SetTransform(State, pMatrix);
-}
-
-STDMETHODIMP QD3DStateManager::SetMaterial(CONST D3DMATERIAL9 *pMaterial)
-{
- return m_pDevice->SetMaterial(pMaterial);
-}
-
-STDMETHODIMP QD3DStateManager::SetLight(DWORD Index, CONST D3DLIGHT9 *pLight)
-{
- return m_pDevice->SetLight(Index, pLight);
-}
-
-STDMETHODIMP QD3DStateManager::LightEnable(DWORD Index, BOOL Enable)
-{
- return m_pDevice->LightEnable(Index, Enable);
-}
-
-STDMETHODIMP QD3DStateManager::SetRenderState(D3DRENDERSTATETYPE State, DWORD Value)
-{
- if (State < D3D_RENDER_STATES) {
- if (m_renderstate[State] == Value)
- return S_OK;
- m_renderstate[State] = Value;
- }
- return m_pDevice->SetRenderState(State, Value);
-}
-
-STDMETHODIMP QD3DStateManager::SetTexture(DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture)
-{
- if (Stage < D3D_STAGE_COUNT) {
- if (m_textures[Stage] == pTexture)
- return S_OK;
- m_textures[Stage] = pTexture;
- }
- return m_pDevice->SetTexture(Stage, pTexture);
-}
-
-STDMETHODIMP QD3DStateManager::SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
-{
- if (Stage < D3D_STAGE_COUNT && Type < D3D_TEXTURE_STATES) {
- if (m_texturestates[Stage][Type] == Value)
- return S_OK;
- m_texturestates[Stage][Type] = Value;
- }
- return m_pDevice->SetTextureStageState(Stage, Type, Value);
-}
-
-STDMETHODIMP QD3DStateManager::SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
-{
- if (Sampler < D3D_STAGE_COUNT && Type < D3D_SAMPLE_STATES) {
- if (m_samplerstates[Sampler][Type] == Value)
- return S_OK;
- m_samplerstates[Sampler][Type] = Value;
- }
- return m_pDevice->SetSamplerState(Sampler, Type, Value);
-}
-
-STDMETHODIMP QD3DStateManager::SetNPatchMode(FLOAT NumSegments)
-{
- return m_pDevice->SetNPatchMode(NumSegments);
-}
-
-STDMETHODIMP QD3DStateManager::SetFVF(DWORD FVF)
-{
- return m_pDevice->SetFVF(FVF);
-}
-
-STDMETHODIMP QD3DStateManager::SetVertexShader(LPDIRECT3DVERTEXSHADER9 pShader)
-{
- if (m_vertexshader == pShader)
- return S_OK;
- m_vertexshader = pShader;
- return m_pDevice->SetVertexShader(pShader);
-}
-
-STDMETHODIMP QD3DStateManager::SetVertexShaderConstantF(UINT RegisterIndex, CONST FLOAT *pConstantData, UINT RegisterCount)
-{
- return m_pDevice->SetVertexShaderConstantF(RegisterIndex, pConstantData, RegisterCount);
-}
-
-STDMETHODIMP QD3DStateManager::SetVertexShaderConstantI(UINT RegisterIndex, CONST INT *pConstantData, UINT RegisterCount)
-{
- return m_pDevice->SetVertexShaderConstantI(RegisterIndex, pConstantData, RegisterCount);
-}
-
-STDMETHODIMP QD3DStateManager::SetVertexShaderConstantB(UINT RegisterIndex, CONST BOOL *pConstantData, UINT RegisterCount)
-{
- return m_pDevice->SetVertexShaderConstantB(RegisterIndex, pConstantData, RegisterCount);
-}
-
-STDMETHODIMP QD3DStateManager::SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader)
-{
- if (m_pixelshader == pShader)
- return S_OK;
- m_pixelshader = pShader;
- return m_pDevice->SetPixelShader(pShader);
-}
-
-STDMETHODIMP QD3DStateManager::SetPixelShaderConstantF(UINT RegisterIndex, CONST FLOAT *pConstantData, UINT RegisterCount)
-{
- return m_pDevice->SetPixelShaderConstantF(RegisterIndex, pConstantData, RegisterCount);
-}
-
-STDMETHODIMP QD3DStateManager::SetPixelShaderConstantI(UINT RegisterIndex, CONST INT *pConstantData, UINT RegisterCount)
-{
- return m_pDevice->SetPixelShaderConstantI(RegisterIndex, pConstantData, RegisterCount);
-}
-
-STDMETHODIMP QD3DStateManager::SetPixelShaderConstantB(UINT RegisterIndex, CONST BOOL *pConstantData, UINT RegisterCount)
-{
- return m_pDevice->SetPixelShaderConstantB(RegisterIndex, pConstantData, RegisterCount);
-}
-
-#define QD3D_GRADIENT_CACHE_SIZE 60
-#define QD3D_GRADIENT_PALETTE_SIZE 1024
-
-class QD3DGradientCache
-{
- struct CacheInfo
- {
- inline CacheInfo(QGradientStops s, qreal op) :
- stops(s), opacity(op) {}
-
- IDirect3DTexture9 *texture;
- QGradientStops stops;
- qreal opacity;
- };
-
- typedef QMultiHash<quint64, CacheInfo> QD3DGradientColorTableHash;
-
-public:
- QD3DGradientCache(LPDIRECT3DDEVICE9 device);
- ~QD3DGradientCache();
-
- inline IDirect3DTexture9 *getBuffer(const QGradientStops &stops, qreal opacity);
-
-protected:
- inline void generateGradientColorTable(const QGradientStops& s,
- uint *colorTable,
- int size, qreal opacity) const;
- IDirect3DTexture9 *addCacheElement(quint64 hash_val, const QGradientStops &stops, qreal opacity);
- void cleanCache();
-
- QD3DGradientColorTableHash cache;
- LPDIRECT3DDEVICE9 m_device;
-};
-
-QD3DGradientCache::QD3DGradientCache(LPDIRECT3DDEVICE9 device)
- : m_device(device)
-{
-
-}
-
-QD3DGradientCache::~QD3DGradientCache()
-{
- cleanCache();
-}
-
-inline IDirect3DTexture9 *QD3DGradientCache::getBuffer(const QGradientStops &stops, qreal opacity)
-{
- quint64 hash_val = 0;
-
- for (int i = 0; i < stops.size() && i <= 2; i++)
- hash_val += stops[i].second.rgba();
-
- QD3DGradientColorTableHash::const_iterator it = cache.constFind(hash_val);
-
- if (it == cache.constEnd())
- return addCacheElement(hash_val, stops, opacity);
- else {
- do {
- const CacheInfo &cache_info = it.value();
- if (cache_info.stops == stops && cache_info.opacity == opacity) {
- return cache_info.texture;
- }
- ++it;
- } while (it != cache.constEnd() && it.key() == hash_val);
- // an exact match for these stops and opacity was not found, create new cache
- return addCacheElement(hash_val, stops, opacity);
- }
-}
-
-void QD3DGradientCache::generateGradientColorTable(const QGradientStops& s, uint *colorTable, int size, qreal opacity) const
-{
- int pos = 0;
- qreal fpos = 0.0;
- qreal incr = 1.0 / qreal(size);
- QVector<uint> colors(s.size());
-
- for (int i = 0; i < s.size(); ++i)
- colors[i] = s[i].second.rgba();
-
- uint alpha = qRound(opacity * 255);
- while (fpos < s.first().first) {
- colorTable[pos] = ARGB_COMBINE_ALPHA(colors[0], alpha);
- pos++;
- fpos += incr;
- }
-
- for (int i = 0; i < s.size() - 1; ++i) {
- qreal delta = 1/(s[i+1].first - s[i].first);
- while (fpos < s[i+1].first && pos < size) {
- int dist = int(256 * ((fpos - s[i].first) * delta));
- int idist = 256 - dist;
- uint current_color = ARGB_COMBINE_ALPHA(colors[i], alpha);
- uint next_color = ARGB_COMBINE_ALPHA(colors[i+1], alpha);
-#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- colorTable[pos] = INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist);
-#else
- uint c = INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist);
- colorTable[pos] = ( (c << 24) & 0xff000000)
- | ((c >> 24) & 0x000000ff)
- | ((c << 8) & 0x00ff0000)
- | ((c >> 8) & 0x0000ff00);
-#endif // Q_BYTE_ORDER
- ++pos;
- fpos += incr;
- }
- }
- for (;pos < size; ++pos)
- colorTable[pos] = colors[s.size() - 1];
-}
-
-IDirect3DTexture9 *QD3DGradientCache::addCacheElement(quint64 hash_val, const QGradientStops &stops, qreal opacity)
-{
- if (cache.size() == QD3D_GRADIENT_CACHE_SIZE) {
- int elem_to_remove = qrand() % QD3D_GRADIENT_CACHE_SIZE;
- uint key = cache.keys()[elem_to_remove];
-
- // need to call release on each removed cache entry:
- QD3DGradientColorTableHash::const_iterator it = cache.constFind(key);
- do {
- it.value().texture->Release();
- } while (++it != cache.constEnd() && it.key() == key);
-
- cache.remove(key); // may remove more than 1, but OK
- }
-
- CacheInfo cache_entry(stops, opacity);
- uint buffer[QD3D_GRADIENT_PALETTE_SIZE];
- generateGradientColorTable(stops, buffer, QD3D_GRADIENT_PALETTE_SIZE, opacity);
-
- if (FAILED(m_device->CreateTexture(QD3D_GRADIENT_PALETTE_SIZE, 1, 1, 0,
- D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cache_entry.texture, 0))) {
- qWarning("QD3DGradientCache::addCacheElement(): unable to create Direct3D texture.");
- return 0;
- }
-
- D3DLOCKED_RECT rect;
- if (FAILED(cache_entry.texture->LockRect(0, &rect, 0, 0))) {
- qDebug() << "QD3DGradientCache::addCacheElement(): unable to lock texture rect.";
- return 0;
- }
- memcpy(rect.pBits, buffer, rect.Pitch);
- cache_entry.texture->UnlockRect(0);
-
- return cache.insert(hash_val, cache_entry).value().texture;
-}
-
-void QD3DGradientCache::cleanCache()
-{
- QD3DGradientColorTableHash::const_iterator it = cache.constBegin();
- for (; it != cache.constEnd(); ++it) {
- const CacheInfo &cache_info = it.value();
- cache_info.texture->Release();
- }
- cache.clear();
-}
-
-QD3DSurfaceManager::QD3DSurfaceManager() :
- m_status(NoStatus), m_dummy(0), m_device(0), m_pd(0), m_current(0)
-{
-
-}
-
-QD3DSurfaceManager::~QD3DSurfaceManager()
-{
-}
-
-void QD3DSurfaceManager::setPaintDevice(QPaintDevice *pd)
-{
- m_status = NoStatus;
- m_pd = pd;
- m_current = 0;
-
- if (m_device->TestCooperativeLevel() != D3D_OK) {
- m_status = NeedsResetting;
- return;
- }
-
- m_current = m_swapchains.value(pd, 0);
- QWidget *w = static_cast<QWidget*>(pd);
-
- if (m_current) {
- if (m_current->size != w->size()) {
- m_swapchains.remove(pd);
- m_current->surface->Release();
- m_current->swapchain->Release();
- delete m_current;
- m_current = 0;
- }
- }
-
- if (!m_current) {
- m_current = createSwapChain(w);
- updateMaxSize();
- }
-}
-
-int QD3DSurfaceManager::status() const
-{
- return m_status;
-}
-
-void QD3DSurfaceManager::reset()
-{
- QList<QPaintDevice *> pds = m_swapchains.keys();
-
- QMap<QPaintDevice *, D3DSwapChain *>::const_iterator i = m_swapchains.constBegin();
- while (i != m_swapchains.constEnd()) {
- i.value()->surface->Release();
- i.value()->swapchain->Release();
- ++i;
- }
- qDeleteAll(m_swapchains.values());
- m_swapchains.clear();
-
- D3DPRESENT_PARAMETERS params;
- initPresentParameters(&params);
- params.hDeviceWindow = m_dummy;
-
- HRESULT res = m_device->Reset(&params);
- if (FAILED(res)) {
- switch (res) {
- case D3DERR_DEVICELOST:
- qWarning("QDirect3DPaintEngine: Reset failed (D3DERR_DEVICELOST)");
- break;
- case D3DERR_DRIVERINTERNALERROR:
- qWarning("QDirect3DPaintEngine: Reset failed (D3DERR_DRIVERINTERNALERROR)");
- break;
- case D3DERR_OUTOFVIDEOMEMORY:
- qWarning("QDirect3DPaintEngine: Reset failed (D3DERR_OUTOFVIDEOMEMORY)");
- break;
- default:
- qWarning("QDirect3DPaintEngine: Reset failed");
- };
- }
-
- for (int i=0; i<pds.count(); ++i) {
- QWidget *w = static_cast<QWidget*>(pds.at(i));
- createSwapChain(w);
- }
-
- // reset the mask as well
- m_status = MaxSizeChanged;
-
- setPaintDevice(m_pd);
- updateMaxSize();
-}
-
-LPDIRECT3DSURFACE9 QD3DSurfaceManager::renderTarget()
-{
- return m_current ? m_current->surface : 0;
-}
-
-LPDIRECT3DSURFACE9 QD3DSurfaceManager::surface(QPaintDevice *pd)
-{
- D3DSwapChain *swapchain = m_swapchains.value(pd, 0);
- return swapchain ? swapchain->surface : 0;
-}
-
-LPDIRECT3DSWAPCHAIN9 QD3DSurfaceManager::swapChain(QPaintDevice *pd)
-{
- D3DSwapChain *swapchain = m_swapchains.value(pd, 0);
- return swapchain ? swapchain->swapchain : 0;
-}
-
-void QD3DSurfaceManager::releasePaintDevice(QPaintDevice *pd)
-{
- D3DSwapChain *swapchain = m_swapchains.take(pd);
-
- if (swapchain) {
- swapchain->surface->Release();
- swapchain->swapchain->Release();
- delete swapchain;
- if (swapchain == m_current)
- m_current = 0;
- }
-}
-
-LPDIRECT3DDEVICE9 QD3DSurfaceManager::device()
-{
- return m_device;
-}
-
-void QD3DSurfaceManager::cleanup()
-{
- QPixmapCache::clear();
- qd3d_glyph_cache()->cleanCache();
-
- // release doomed textures
- for (int k=0; k<qd3d_release_list.size(); ++k)
- qd3d_release_list.at(k)->Release();
- qd3d_release_list.clear();
-
- QMap<QPaintDevice *, D3DSwapChain *>::const_iterator i = m_swapchains.constBegin();
- while (i != m_swapchains.constEnd()) {
- i.value()->surface->Release();
- i.value()->swapchain->Release();
- ++i;
- }
- qDeleteAll(m_swapchains.values());
-
- if (m_device)
- m_device->Release();
-
- DestroyWindow(m_dummy);
- QString cname(QLatin1String("qt_d3d_dummy"));
- QT_WA({
- UnregisterClass((TCHAR*)cname.utf16(), (HINSTANCE)qWinAppInst());
- } , {
- UnregisterClassA(cname.toLatin1(), (HINSTANCE)qWinAppInst());
- });
-}
-
-QSize QD3DSurfaceManager::maxSize() const
-{
- return m_max_size;
-}
-
-extern "C" {
- LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
-};
-
-void QD3DSurfaceManager::init(LPDIRECT3D9 object)
-{
- QString cname(QLatin1String("qt_d3d_dummy"));
- uint style = CS_DBLCLKS | CS_SAVEBITS;
- ATOM atom;
- QT_WA({
- WNDCLASS wc;
- wc.style = style;
- wc.lpfnWndProc = (WNDPROC)QtWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = (HINSTANCE)qWinAppInst();
- wc.hIcon = 0;
- wc.hCursor = 0;
- wc.hbrBackground = 0;
- wc.lpszMenuName = 0;
- wc.lpszClassName = (TCHAR*)cname.utf16();
- atom = RegisterClass(&wc);
- } , {
- WNDCLASSA wc;
- wc.style = style;
- wc.lpfnWndProc = (WNDPROC)QtWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = (HINSTANCE)qWinAppInst();
- wc.hIcon = 0;
- wc.hCursor = 0;
- wc.hbrBackground = 0;
- wc.lpszMenuName = 0;
- QByteArray tempArray = cname.toLatin1();
- wc.lpszClassName = tempArray;
- atom = RegisterClassA(&wc);
- });
-
- QT_WA({
- const TCHAR *className = (TCHAR*)cname.utf16();
- m_dummy = CreateWindow(className, className, 0,
- 0, 0, 1, 1,
- 0, 0, qWinAppInst(), 0);
- } , {
- m_dummy = CreateWindowA(cname.toLatin1(), cname.toLatin1(), 0,
- 0, 0, 1, 1,
- 0, 0, qWinAppInst(), 0);
- });
-
- D3DPRESENT_PARAMETERS params;
- initPresentParameters(&params);
- params.hDeviceWindow = m_dummy;
-
- HRESULT res = object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0,
- D3DCREATE_PUREDEVICE|D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_NOWINDOWCHANGES|D3DCREATE_FPU_PRESERVE,
- &params, &m_device);
-
- if (FAILED(res) || m_device == 0)
- qWarning("QDirect3DPaintEngine: failed to create Direct3D device (error=0x%x).", res);
-}
-
-void QD3DSurfaceManager::updateMaxSize()
-{
- int w = 0, h = 0;
- QMap<QPaintDevice *, D3DSwapChain *>::const_iterator i = m_swapchains.constBegin();
- while (i != m_swapchains.constEnd()) {
-
- int nw = i.key()->width();
- if (nw > w)
- w = nw;
-
- int nh = i.key()->height();
- if (nh > h)
- h = nh;
-
- ++i;
- }
-
- QSize newsize = QSize(w, h);
- if (newsize != m_max_size) {
- m_status |= MaxSizeChanged;
- m_max_size = newsize;
- }
-}
-
-void QD3DSurfaceManager::initPresentParameters(D3DPRESENT_PARAMETERS *params)
-{
- ZeroMemory(params, sizeof(D3DPRESENT_PARAMETERS));
- params->Windowed = true;
- params->SwapEffect = D3DSWAPEFFECT_COPY;
- params->BackBufferFormat = D3DFMT_UNKNOWN;
- params->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- params->Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
-}
-
-QD3DSurfaceManager::D3DSwapChain *QD3DSurfaceManager::createSwapChain(QWidget *w)
-{
- D3DPRESENT_PARAMETERS params;
- initPresentParameters(&params);
- params.hDeviceWindow = w->winId();
- D3DSwapChain *swapchain = new D3DSwapChain();
- swapchain->size = w->size();
- if (FAILED(m_device->CreateAdditionalSwapChain(&params, &swapchain->swapchain)))
- qWarning("QDirect3DPaintEngine: CreateAdditionalSwapChain failed");
- if (FAILED(swapchain->swapchain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &swapchain->surface)))
- qWarning("QDirect3DPaintEngine: GetBackBuffer failed");
- m_swapchains.insert(w, swapchain);
- connect(w, SIGNAL(destroyed(QObject *)), SLOT(cleanupPaintDevice(QObject *)));
-
- // init with background color
- QColor bg = w->palette().color(QPalette::Background);
- m_device->ColorFill(swapchain->surface, 0, D3DCOLOR_ARGB(bg.alpha(), bg.red(),bg.green(),bg.blue()));
-
- return swapchain;
-}
-
-void QD3DSurfaceManager::cleanupPaintDevice(QObject *object)
-{
- QWidget *w = static_cast<QWidget *>(object);
- releasePaintDevice(w);
-}
-
-int QD3DStateManager::m_mask_channels[4][4] =
- {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};
-
-QD3DDrawHelper::QD3DDrawHelper(QDirect3DPaintEnginePrivate *pe)
- : m_pe(pe), m_d3dvbuff(0), m_maskSurface(0), m_depthStencilSurface(0),
- m_locked(false), m_mask(0), m_startindex(0), m_index(0), m_vbuff(0), m_clearmask(true),
- m_isLine(false), m_firstPoint(true)
-{
- resetMask();
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- memset(accesscontrol, 0, QT_VERTEX_BUF_SIZE * sizeof(VertexBufferAccess));
-#endif
-
- // create vertex buffer
- afterReset();
-}
-
-QD3DDrawHelper::~QD3DDrawHelper()
-{
- if (m_maskSurface)
- m_maskSurface->Release();
-
- if (m_mask)
- m_mask->Release();
-
- if (m_depthStencilSurface)
- m_depthStencilSurface->Release();
-
- if (m_d3dvbuff)
- m_d3dvbuff->Release();
-}
-
-inline void QD3DDrawHelper::lockVertexBuffer()
-{
- if (!m_locked) {
- DWORD lockflags = D3DLOCK_NOOVERWRITE;
- if (m_startindex >= QT_VERTEX_RESET_LIMIT) {
- m_startindex = 0;
- m_index = 0;
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- for (int i=0; i<QT_VERTEX_BUF_SIZE; ++i) {
- if (accesscontrol[i] != (WRITE|READ) && accesscontrol[i] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- }
- memset(accesscontrol, 0, QT_VERTEX_BUF_SIZE * sizeof(VertexBufferAccess));
-#endif
-
- lockflags = D3DLOCK_DISCARD;
- }
-
- if (FAILED(m_d3dvbuff->Lock(0, 0, (void**)&m_vbuff, lockflags))) {
- qWarning() << "QDirect3DPaintEngine: unable to lock vertex buffer.";
- }
- m_locked = true;
- }
-}
-
-inline void QD3DDrawHelper::unlockVertexBuffer()
-{
- if (m_locked) {
- if (FAILED(m_d3dvbuff->Unlock())) {
- qWarning() << "QDirect3DPaintEngine: unable to unlock vertex buffer.";
- }
- m_locked = false;
- }
-}
-
-void QD3DDrawHelper::setClipPath(const QPainterPath &path, QD3DBatchItem **item)
-{
- lockVertexBuffer();
-
- m_item = *item;
- m_item->m_maskpos.x = m_item->m_maskpos.y = 0;
- m_item->m_maskpos.channel = 3;
- m_item->m_info |= QD3DBatchItem::BI_CLIP;
-
- bool winding = (path.fillRule() == Qt::WindingFill);
- if (winding)
- m_item->m_info |= QD3DBatchItem::BI_WINDING;
-
- if (!path.isEmpty()) {
- m_item->m_info |= QD3DBatchItem::BI_MASK;
- m_item->m_info &= ~QD3DBatchItem::BI_AA;
- m_color = 0;
- QRectF brect = pathToVertexArrays(path);
- queueRect(brect, m_item, 0);
- }
-
- *item = m_item;
-}
-
-
-
-void QD3DDrawHelper::queueAntialiasedMask(const QPolygonF &poly, QD3DBatchItem **item, const QRectF &brect)
-{
- lockVertexBuffer();
-
- m_item = *item;
- m_item->m_info |= QD3DBatchItem::BI_MASK;
- setWinding(m_item->m_info & QD3DBatchItem::BI_WINDING);
-
- int xoffset = m_item->m_maskpos.x;
- int yoffset = m_item->m_maskpos.y;
-
- int x = brect.left();
- int y = brect.top();
-
- m_item->m_xoffset = (xoffset - x) + 1;
- m_item->m_yoffset = (yoffset - y) + 1;
-
- m_boundingRect = brect;
- tessellate(poly);
-
- *item = m_item;
-}
-
-QRectF QD3DDrawHelper::queueAliasedMask(const QPainterPath &path, QD3DBatchItem **item, D3DCOLOR color)
-{
- lockVertexBuffer();
-
- m_color = color;
- m_item = *item;
- m_item->m_info |= QD3DBatchItem::BI_MASK;
-
- bool winding = (path.fillRule() == Qt::WindingFill);
- if (winding)
- m_item->m_info |= QD3DBatchItem::BI_WINDING;
-
- QRectF result = pathToVertexArrays(path);
- *item = m_item;
- return result;
-}
-
-// used for drawing aliased transformed rects directly
-// don't use for antialiased or masked drawing
-void QD3DDrawHelper::queueRect(const QRectF &rect, QD3DBatchItem *item, D3DCOLOR color, const QPolygonF &trect)
-{
- lockVertexBuffer();
-
- qreal zval = (item->m_info & QD3DBatchItem::BI_CLIP) ? 0.0f : 0.5f;
- item->m_info |= QD3DBatchItem::BI_BRECT;
-
- // if the item does not have a mask, the offset is different
- if (!(item->m_info & QD3DBatchItem::BI_MASK)) {
- item->m_offset = m_index;
- item->m_count = (item->m_info & QD3DBatchItem::BI_AA) ? 0 : -2;
- }
-
- qreal x1 = rect.left();
- qreal y1 = rect.top();
- qreal x2 = rect.right();
- qreal y2 = rect.bottom();
-
- QPointF tc = trect.at(0);
- vertex v1 = { {x1, y1, zval} , color,
- tc.x(), tc.y(), 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f };
-
- tc = trect.at(1);
- vertex v2 = { {x2, y1, zval} , color,
- tc.x(), tc.y(), 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
-
- tc = trect.at(2);
- vertex v3 = { {x2, y2, zval} , color,
- tc.x(), tc.y(), 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};;
-
- tc = trect.at(3);
- vertex v4 = { {x1, y2, zval} , color,
- tc.x(), tc.y(), 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- for (int i=m_index; i<(m_index + 4); ++i) {
- if ((m_index + 4) > QT_VERTEX_BUF_SIZE)
- qDebug() << "Vertex Buffer: Buffer overflow";
- if (accesscontrol[i] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[i] |= WRITE;
- }
-#endif
-
- m_vbuff[m_index++] = v1;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v3;
- m_vbuff[m_index++] = v4;
-
- m_startindex = m_index;
-}
-
-
-QD3DMaskPosition QD3DDrawHelper::allocateMaskPosition(const QRectF &brect, bool *breakbatch)
-{
- int w = brect.width();
- int h = brect.height();
-
- w += 3;
- h += 3;
-
- if (w > m_width)
- w = m_width;
- if (h > m_height)
- h = m_height;
-
- *breakbatch = false;
-
- if ((m_height - m_mask_offsetY2) >= h && (m_width - m_mask_position.x) >= w) {
- m_mask_position.y = m_mask_offsetY2;
- } else if ((m_width - m_mask_offsetX2) >= w) {
- m_mask_position.y = QD3D_MASK_MARGIN;
- m_mask_position.x = m_mask_offsetX2;
- } else if (m_mask_position.channel < 3) {
- ++m_mask_position.channel;
- m_mask_position.x = m_mask_position.y = QD3D_MASK_MARGIN;
- m_mask_offsetX2 = m_mask_offsetY2 = QD3D_MASK_MARGIN;
- } else {
- resetMask();
- *breakbatch = true;
- }
-
- int newoffset = m_mask_position.x + w;
- if (m_mask_offsetX2 < newoffset)
- m_mask_offsetX2 = newoffset;
- m_mask_offsetY2 = (m_mask_position.y + h);
-
- return m_mask_position;
-
-}
-
-void QD3DDrawHelper::queueRect(const QRectF &rect, QD3DBatchItem *item, D3DCOLOR color)
-{
- lockVertexBuffer();
-
- QRectF brect;
- item->m_info |= QD3DBatchItem::BI_BRECT;
- qreal zval = (item->m_info & QD3DBatchItem::BI_CLIP) ? 0.0f : 0.5f;
-
- if (item->m_info & QD3DBatchItem::BI_AA) {
- int xoffset = item->m_maskpos.x;
- int yoffset = item->m_maskpos.y;
-
- int x = rect.left();
- int y = rect.top();
-
- brect = QRectF(x, y, rect.width() + 1, rect.height() + 1);
-
- item->m_xoffset = (xoffset - x) + 1;
- item->m_yoffset = (yoffset - y) + 1;
-
- // if the item does not have a mask, the offset is different
- if (!(item->m_info & QD3DBatchItem::BI_MASK)) {
- item->m_offset = m_index;
- item->m_count = 0;
- }
- } else {
- brect = rect;
-
- if (!(item->m_info & QD3DBatchItem::BI_MASK)) {
- item->m_offset = m_index;
- item->m_count = -2;
- }
- }
-
- qreal left = brect.left();
- qreal right = brect.right();
- qreal top = brect.top();
- qreal bottom = brect.bottom();
-
- vertex v1 = { {left, bottom, zval}, color,
- 0.f, 0.f, 0.f, 0.f,
- 0.f, 0.f, 0.f, 0.f};
- vertex v2 = { {left, top, zval}, color,
- 0.f, 0.f, 0.f, 0.f,
- 0.f, 0.f, 0.f, 0.f};
- vertex v3 = { {right, top, zval}, color,
- 0.f, 0.f, 0.f, 0.f,
- 0.f, 0.f, 0.f, 0.f};
- vertex v4 = { {right, bottom, zval}, color,
- 0.f, 0.f, 0.f, 0.f,
- 0.f, 0.f, 0.f, 0.f};
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- for (int i=m_index; i<(m_index + 4); ++i) {
- if ((m_index + 4) > QT_VERTEX_BUF_SIZE)
- qDebug() << "Vertex Buffer: Buffer overflow";
- if (accesscontrol[i] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[i] |= WRITE;
- }
-#endif
-
- m_vbuff[m_index++] = v1;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v3;
- m_vbuff[m_index++] = v4;
-
- m_startindex = m_index;
-}
-
-void QD3DDrawHelper::queueAntialiasedLines(const QPainterPath &path, QD3DBatchItem **item, const QRectF &brect)
-{
- lockVertexBuffer();
-
- m_item = *item;
- m_item->m_info |= QD3DBatchItem::BI_MASK;
- setWinding(m_item->m_info & QD3DBatchItem::BI_WINDING);
-
- int xoffset = m_item->m_maskpos.x;
- int yoffset = m_item->m_maskpos.y;
- int x = brect.left();
- int y = brect.top();
-
- m_item->m_xoffset = (xoffset - x) + 1;
- m_item->m_yoffset = (yoffset - y) + 1;
-
- m_boundingRect = brect;
-
- m_xoffset = (x - xoffset) + 0.5f;
- m_yoffset = (y - yoffset) + 0.5f;
-
- QPointF last;
- for (int i = 0; i < path.elementCount(); ++i) {
- QPainterPath::Element element = path.elementAt(i);
-
- //Q_ASSERT(!element.isCurveTo());
-
- if (element.isLineTo())
- QTessellator::tessellateRect(last, element, m_item->m_width);
-
- last = element;
- }
-
- m_item->m_offset = m_startindex;
- m_item->m_count = ( m_index - m_startindex ) / 3;
- m_startindex = m_index;
-
- *item = m_item;
-}
-
-void QD3DDrawHelper::queueAliasedLines(const QLineF *lines, int lineCount, QD3DBatchItem **item)
-{
- lockVertexBuffer();
-
- m_item = *item;
- m_item->m_info |= QD3DBatchItem::BI_FASTLINE;
-
- for (int i=0; i<lineCount; ++i) {
- const QLineF line = lines[i];
- qreal p1x = line.p1().x();
- qreal p1y = line.p1().y();
- qreal p2x = line.p2().x();
- qreal p2y = line.p2().y();
-
- vertex v1 = { {p1x, p1y, m_pe->m_pen_width} , m_pe->m_pen_color,
- -1.f, -1.f, p2x, p2y,
- 0.f, 0.f, 0.f, 0.f };
- vertex v2 = { {p1x, p1y, m_pe->m_pen_width} , m_pe->m_pen_color,
- 1.f, -1.f, p2x, p2y,
- 0.f, 0.f, 0.f, 0.f };
- vertex v3 = { {p1x, p1y, m_pe->m_pen_width} , m_pe->m_pen_color,
- 1.f, 1.f, p2x, p2y,
- 0.f, 0.f, 0.f, 0.f };
- vertex v4 = { {p1x, p1y, m_pe->m_pen_width} , m_pe->m_pen_color,
- -1.f, 1.f, p2x, p2y,
- 0.f, 0.f, 0.f, 0.f };
-
- m_vbuff[m_index++] = v1;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v4;
- m_vbuff[m_index++] = v4;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v3;
-
- if (m_index >= (QT_VERTEX_BUF_SIZE - 16)) {
- m_item->m_offset = m_startindex;
- m_item->m_count = ( m_index - m_startindex ) / 2;
- m_startindex = m_index;
-
- QD3DBatchItem itemcopy = *m_item;
- m_item = m_pe->nextBatchItem();
- *m_item = itemcopy;
-
- lockVertexBuffer();
- }
- }
-
- m_item->m_offset = m_startindex;
- m_item->m_count = ( m_index - m_startindex ) - 2;
- m_startindex = m_index;
-
- *item = m_item;
-}
-
-void QD3DDrawHelper::queueTextGlyph(const QRectF &rect, const qreal *tex_coords,
- QD3DBatchItem *item, D3DCOLOR color)
-{
- lockVertexBuffer();
-
- qreal x1 = rect.left();
- qreal y1 = rect.top();
- qreal x2 = rect.right();
- qreal y2 = rect.bottom();
-
- vertex v1 = { {x1, y1, 0.5f}, color,
- tex_coords[0], tex_coords[1], 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
- vertex v2 = { {x2, y1, 0.5f}, color,
- tex_coords[2], tex_coords[1], 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
- vertex v3 = { {x2, y2, 0.5f}, color,
- tex_coords[2], tex_coords[3], 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
- vertex v4 = { {x1, y1, 0.5f}, color,
- tex_coords[0], tex_coords[1], 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
- vertex v5 = { {x2, y2, 0.5f}, color,
- tex_coords[2], tex_coords[3], 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
- vertex v6 = { {x1, y2, 0.5f}, color,
- tex_coords[0], tex_coords[3], 0.f, 0.f,
- 0.f , 0.f , 0.f, 0.f};
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- for (int i=m_index; i<(m_index + 6); ++i) {
- if ((m_index + 6) > QT_VERTEX_BUF_SIZE)
- qDebug() << "Vertex Buffer: Buffer overflow";
- if (accesscontrol[i] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[i] |= WRITE;
- }
-#endif
-
- m_vbuff[m_index++] = v1;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v3;
- m_vbuff[m_index++] = v4;
- m_vbuff[m_index++] = v5;
- m_vbuff[m_index++] = v6;
-
- m_startindex = m_index;
- ++item->m_count;
-}
-
-bool QD3DDrawHelper::needsFlushing() const
-{
- return (m_pe->m_batch.m_item_index >= QD3D_BATCH_SIZE || m_startindex >= QT_VERTEX_RESET_LIMIT);
-}
-
-void QD3DDrawHelper::setMaskSize(QSize size)
-{
- m_width = size.width();
- m_height = size.height();
-
- if (m_maskSurface)
- m_maskSurface->Release();
-
- if (m_mask)
- m_mask->Release();
-
- if (FAILED(m_pe->m_d3d_device->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET,
- D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_mask, NULL))) {
- qWarning() << "QDirect3DPaintEngine: CreateTexture() failed.";
- }
-
- if (m_depthStencilSurface)
- m_depthStencilSurface->Release();
-
- if (FAILED(m_pe->m_d3d_device->CreateDepthStencilSurface(m_width, m_height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0,
- TRUE, &m_depthStencilSurface, NULL))) {
- qWarning() << "QDirect3DPaintEngine: CreateDepthStencilSurface() failed.";
- }
-
- m_pe->m_d3d_device->SetDepthStencilSurface(m_depthStencilSurface);
- m_pe->m_d3d_device->Clear(0, 0, D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0, 0.0f, 0);
-
- if (FAILED(m_mask->GetSurfaceLevel(0, &m_maskSurface))) {
- qWarning() << "QDirect3DPaintEngine: GetSurfaceLevel() failed.";
- }
-
- m_pe->m_d3d_device->ColorFill(m_maskSurface, 0, D3DCOLOR_ARGB(0,0,0,0));
- D3DXMATRIX projMatrix;
- pD3DXMatrixOrthoOffCenterLH(&projMatrix, 0, m_width, m_height, 0, 0, 1);
- m_pe->m_effect->SetMatrix("g_mMaskProjection", &projMatrix);
- m_pe->m_effect->SetTexture("g_mAAMask", m_mask);
-}
-
-void QD3DDrawHelper::beforeReset()
-{
- resetMask();
- m_clearmask = true;
-
- if (m_maskSurface) {
- m_maskSurface->Release();
- m_maskSurface = 0;
- }
-
- if (m_mask) {
- m_mask->Release();
- m_mask = 0;
- }
-
- if (m_depthStencilSurface) {
- m_depthStencilSurface->Release();
- m_depthStencilSurface = 0;
- }
-
- if (m_d3dvbuff)
- m_d3dvbuff->Release();
-}
-
-void QD3DDrawHelper::afterReset()
-{
- if (FAILED(m_pe->m_d3d_device->CreateVertexBuffer(QT_VERTEX_BUF_SIZE*sizeof(vertex), D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
- QD3DFVF_CSVERTEX,
- D3DPOOL_DEFAULT, &m_d3dvbuff, NULL))) {
- qWarning() << "QDirect3DPaintEngine: failed to create vertex buffer.";
- }
-
- m_pe->m_d3d_device->SetStreamSource(0, m_d3dvbuff, 0, sizeof(vertex));
- m_pe->m_d3d_device->SetFVF(QD3DFVF_CSVERTEX);
-
- m_startindex = 0;
- m_index = 0;
-}
-
-IDirect3DSurface9 *QD3DDrawHelper::freeMaskSurface()
-{
- // we need to make sure the mask is cleared when it's used for something else
- resetMask();
- m_clearmask = true;
-
- return m_maskSurface;
-}
-
-int QD3DDrawHelper::drawAntialiasedMask(int offset, int maxoffset)
-{
- int newoffset = offset;
- QD3DBatchItem *item = &(m_pe->m_batch.items[offset]);
-
- // set mask as render target
- if (FAILED(m_pe->m_d3d_device->SetRenderTarget(0, m_maskSurface)))
- qWarning() << "QDirect3DPaintEngine: SetRenderTarget failed!";
-
- if (m_clearmask) {
- m_pe->m_d3d_device->Clear(0, 0, D3DCLEAR_TARGET,D3DCOLOR_ARGB(0,0,0,0), 0, 0);
- m_clearmask = false;
- }
-
- // fill the mask
- m_pe->m_statemanager->beginPass(PASS_AA_CREATEMASK);
- for (; newoffset<maxoffset; ++newoffset) {
- item = &(m_pe->m_batch.items[newoffset]);
- if (!(item->m_info & QD3DBatchItem::BI_AA) || !(item->m_info & QD3DBatchItem::BI_MASK)) {
- break;
- } else if (item->m_info & QD3DBatchItem::BI_MASKFULL) {
- item->m_info &= ~QD3DBatchItem::BI_MASKFULL;
- m_clearmask = true;
- break;
- }
-
- m_pe->m_statemanager->startStateBlock();
- if (item->m_info & QD3DBatchItem::BI_MASKSCISSOR) {
- RECT rect;
- QRectF srect = item->m_brect.adjusted(item->m_xoffset, item->m_yoffset,
- item->m_xoffset, item->m_yoffset);
- rect.left = qMax(qRound(srect.left()), 0);
- rect.top = qMax(qRound(srect.top()), 0);
- rect.bottom = qMin(m_height, qRound(srect.bottom()));
- rect.right = qMin(m_width, qRound(srect.right()));
- m_pe->m_d3d_device->SetScissorRect(&rect);
- m_pe->m_statemanager->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
- }
- m_pe->m_statemanager->setMaskChannel(item->m_maskpos.channel);
- m_pe->m_statemanager->endStateBlock();
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- int vbstart = item->m_offset;
- for (int i=vbstart; i<(vbstart + (item->m_count * 3)); ++i) {
- if (accesscontrol[i] != WRITE)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[i] |= READ;
- }
-#endif
-
- m_pe->m_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, item->m_offset, item->m_count);
-
- if (item->m_info & QD3DBatchItem::BI_MASKSCISSOR) {
- m_pe->m_statemanager->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
- }
- }
- m_pe->m_statemanager->endPass();
-
- return newoffset;
-}
-
-void QD3DDrawHelper::drawAliasedMask(int offset)
-{
- QD3DBatchItem *item = &(m_pe->m_batch.items[offset]);
- if (item->m_info & QD3DBatchItem::BI_MASK) {
- m_pe->m_statemanager->beginPass( (item->m_info & QD3DBatchItem::BI_WINDING) ? PASS_STENCIL_WINDING : PASS_STENCIL_ODDEVEN );
- int prev_stop = 0;
- for (int i=0; i<item->m_pointstops.count(); ++i) {
- int stop = item->m_pointstops.at(i);
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- int vbstart = (item->m_offset + prev_stop);
- for (int j=vbstart; j<(vbstart+(stop - prev_stop)); ++j) {
- if (accesscontrol[j] != WRITE)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[j] |= READ;
- }
-#endif
- m_pe->m_d3d_device->DrawPrimitive(D3DPT_TRIANGLEFAN, item->m_offset + prev_stop, (stop - prev_stop) - 2);
- prev_stop = stop;
- }
- m_pe->m_statemanager->endPass();
- }
-}
-
-void QD3DDrawHelper::drawTextItem(QD3DBatchItem *item)
-{
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- int vbstart = item->m_offset;
- for (int j=vbstart; j<(vbstart + ((item->m_count * 2) * 3)); ++j) {
- if (accesscontrol[j] != WRITE)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[j] |= READ;
- }
-#endif
- m_pe->m_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, item->m_offset, item->m_count*2);
-}
-
-void QD3DDrawHelper::drawAliasedLines(QD3DBatchItem *item)
-{
- m_pe->m_statemanager->setCosmeticPen(item->m_info & QD3DBatchItem::BI_COSMETICPEN);
- if (item->m_info & QD3DBatchItem::BI_TRANSFORM) {
- m_pe->m_statemanager->setTransformation(&item->m_matrix);
- } else {
- m_pe->m_statemanager->setTransformation();
- }
- int pass = (item->m_info & QD3DBatchItem::BI_MASK)
- ? PASS_ALIASED_LINES
- : PASS_ALIASED_LINES_DIRECT;
- m_pe->m_statemanager->beginPass(pass);
- m_pe->m_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, item->m_offset, (item->m_count + 2) / 3);
- m_pe->m_statemanager->endPass();
-}
-
-void QD3DDrawHelper::drawAntialiasedBoundingRect(QD3DBatchItem *item)
-{
- if (item->m_info & QD3DBatchItem::BI_SCISSOR) {
- RECT rect;
- rect.left = qMax(qRound(item->m_brect.left()), 0);
- rect.top = qMax(qRound(item->m_brect.top()), 0);
- rect.bottom = qMin(m_height, qRound(item->m_brect.bottom()));
- rect.right = qMin(m_width, qRound(item->m_brect.right()));
- m_pe->m_d3d_device->SetScissorRect(&rect);
- m_pe->m_statemanager->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
- }
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- int vbstart = item->m_offset + (item->m_count * 3);
- for (int j=vbstart; j<(vbstart + 4); ++j) {
- if (accesscontrol[j] != WRITE)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[j] |= READ;
- }
-#endif
-
- m_pe->m_d3d_device->DrawPrimitive(D3DPT_TRIANGLEFAN, item->m_offset + (item->m_count * 3), 2);
-
- if (item->m_info & QD3DBatchItem::BI_SCISSOR) {
- m_pe->m_statemanager->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
- }
-}
-
-void QD3DDrawHelper::drawAliasedBoundingRect(QD3DBatchItem *item)
-{
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- int vbstart = (item->m_offset + item->m_count + 2);
- for (int j=vbstart; j<(vbstart + 4); ++j) {
- if (accesscontrol[j] != WRITE)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[j] |= READ;
- }
-#endif
-
- m_pe->m_d3d_device->DrawPrimitive(D3DPT_TRIANGLEFAN, item->m_offset + item->m_count + 2, 2);
-}
-
-void QD3DDrawHelper::addTrap(const Trapezoid &trap)
-{
- qreal topLeftY = Q27Dot5ToDouble(trap.topLeft->y) - m_yoffset;
- qreal topLeftX = Q27Dot5ToDouble(trap.topLeft->x) - m_xoffset;
- qreal topRightY = Q27Dot5ToDouble(trap.topRight->y) - m_yoffset;
- qreal topRightX = Q27Dot5ToDouble(trap.topRight->x) - m_xoffset;
- qreal top = Q27Dot5ToDouble(trap.top) - m_yoffset;
- qreal bottom = Q27Dot5ToDouble(trap.bottom) - m_yoffset;
-
- Q27Dot5 _h = trap.topLeft->y - trap.bottomLeft->y;
- Q27Dot5 _w = trap.topLeft->x - trap.bottomLeft->x;
- qreal _leftA = (qreal)_w/_h;
- qreal _leftB = topLeftX - _leftA * topLeftY;
-
- _h = trap.topRight->y - trap.bottomRight->y;
- _w = trap.topRight->x - trap.bottomRight->x;
- qreal _rightA = (qreal)_w/_h;
- qreal _rightB = topRightX - _rightA * topRightY;
-
- qreal invLeftA = qFuzzyCompare(_leftA + 1, 1) ? 0.0 : 1.0 / _leftA;
- qreal invRightA = qFuzzyCompare(_rightA + 1, 1) ? 0.0 : 1.0 / _rightA;
-
- vertex v1 = { {1.f, top - 1.f, 0.5f}, 0.f,
- top, bottom, invLeftA, -invRightA,
- _leftA, _leftB, _rightA, _rightB};
- vertex v2 = { {0.f, top - 1.f, 0.5f}, 0.f,
- top, bottom, invLeftA, -invRightA,
- _leftA, _leftB, _rightA, _rightB};
- vertex v3 = { {0.f, bottom + 1.f, 0.5f}, 0.f,
- top, bottom, invLeftA, -invRightA,
- _leftA, _leftB, _rightA, _rightB};
-
- vertex v4 = { {1.f, top - 1.f, 0.5f}, 0.f,
- top, bottom, invLeftA, -invRightA,
- _leftA, _leftB, _rightA, _rightB};
- vertex v5 = { {0.f, bottom + 1.f, 0.5f}, 0.f,
- top, bottom, invLeftA, -invRightA,
- _leftA, _leftB, _rightA, _rightB};
- vertex v6 = { {1.f, bottom + 1.f, 0.5f}, 0.f,
- top, bottom, invLeftA, -invRightA,
- _leftA, _leftB, _rightA, _rightB};
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- for (int i=m_index; i<(m_index + 6); ++i) {
- if ((m_index + 6) > QT_VERTEX_BUF_SIZE)
- qDebug() << "Vertex Buffer: Buffer overflow";
- if (accesscontrol[i] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[i] |= WRITE;
- }
-#endif
-
- m_vbuff[m_index++] = v1;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v3;
- m_vbuff[m_index++] = v4;
- m_vbuff[m_index++] = v5;
- m_vbuff[m_index++] = v6;
-
- // check if buffer is full
- if (m_index >= (QT_VERTEX_BUF_SIZE - 16)) {
- m_item->m_offset = m_startindex;
- m_item->m_count = ( m_index - m_startindex ) / 3;
- m_startindex = m_index;
-
- QD3DBatchItem itemcopy = *m_item;
- m_item = m_pe->nextBatchItem();
- *m_item = itemcopy;
- m_item->m_info &= ~QD3DBatchItem::BI_MASKFULL;
-
- lockVertexBuffer();
- }
-}
-
-void QD3DDrawHelper::tessellate(const QPolygonF &poly) {
- int xoffset = m_item->m_maskpos.x;
- int yoffset = m_item->m_maskpos.y;
-
- int x = m_boundingRect.left();
- int y = m_boundingRect.top();
- m_xoffset = (x - xoffset) + 0.5f;
- m_yoffset = (y - yoffset) + 0.5f;
-
- QTessellator::tessellate(poly.data(), poly.count());
-
- m_item->m_offset = m_startindex;
- m_item->m_count = ( m_index - m_startindex ) / 3;
- m_startindex = m_index;
-}
-
-inline void QD3DDrawHelper::lineToStencil(qreal x, qreal y)
-{
- QPointF lastPt = tess_lastpoint;
- tess_lastpoint = QPointF(x, y);
-
- if (m_isLine && m_firstPoint)
- return;
-
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- if (m_index > QT_VERTEX_BUF_SIZE)
- qDebug() << "Vertex Buffer: Buffer overflow";
- if (accesscontrol[m_index] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[m_index] |= WRITE;
-#endif
-
- vertex v;
- if (m_isLine) {
- vertex v1 = { {lastPt.x(), lastPt.y(), m_pe->m_pen_width }, m_color,
- -1.f, -1.f, x, y,
- 0.f, 0.f, 0.f, 0.f};
- vertex v2 = { {lastPt.x(), lastPt.y(), m_pe->m_pen_width }, m_color,
- 1.f, -1.f, x, y,
- 0.f, 0.f, 0.f, 0.f};
- vertex v3 = { {lastPt.x(), lastPt.y(), m_pe->m_pen_width }, m_color,
- 1.f, 1.f, x, y,
- 0.f, 0.f, 0.f, 0.f};
- vertex v4 = { {lastPt.x(), lastPt.y(), m_pe->m_pen_width }, m_color,
- -1.f, 1.f, x, y,
- 0.f, 0.f, 0.f, 0.f};
- m_vbuff[m_index++] = v1;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v4;
- m_vbuff[m_index++] = v4;
- m_vbuff[m_index++] = v2;
- m_vbuff[m_index++] = v3;
- } else {
- vertex v1 = { {x, y, 0.5f}, m_color,
- 0.f, 0.f, 0.f, 0.f,
- 0.f, 0.f, 0.f, 0.f};
- m_vbuff[m_index++] = v1;
- v = v1;
- }
- ++tess_index;
-
- // check if buffer is full
- if (m_index >= (QT_VERTEX_BUF_SIZE - 16)) {
- int firstindex = m_startindex;
- if (!m_item->m_pointstops.isEmpty())
- firstindex = m_item->m_pointstops.last();
-
- vertex first = m_vbuff[firstindex];
-
- // finish current polygon
- m_item->m_pointstops.append(tess_index);
- m_item->m_offset = m_startindex;
- m_startindex = m_index;
-
- // copy item
- QD3DBatchItem itemcopy = *m_item;
- m_item = m_pe->nextBatchItem();
- *m_item = itemcopy;
-
- // start new polygon
- lockVertexBuffer();
- m_item->m_pointstops.clear();
- if (!m_isLine) {
- tess_index = 2;
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- if (accesscontrol[m_index] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[m_index] |= WRITE;
-#endif
-
- m_vbuff[m_index++] = first;
-
-#ifdef QT_DEBUG_VERTEXBUFFER_ACCESS
- if (accesscontrol[m_index] != CLEAR)
- qDebug() << "Vertex Buffer: Access Error";
- accesscontrol[m_index] |= WRITE;
-#endif
-
- m_vbuff[m_index++] = v;
- } else {
- tess_index = 0;
- }
- }
-
- if (x > max_x)
- max_x = x;
- else if (x < min_x)
- min_x = x;
- if (y > max_y)
- max_y = y;
- else if (y < min_y)
- min_y = y;
-}
-
-inline void QD3DDrawHelper::curveToStencil(const QPointF &cp1, const QPointF &cp2,
- const QPointF &ep)
-{
- qreal inverseScale = 0.5f;
- qreal inverseScaleHalf = inverseScale / 2;
-
- QBezier beziers[32];
- beziers[0] = QBezier::fromPoints(tess_lastpoint, cp1, cp2, ep);
- QBezier *b = beziers;
- while (b >= beziers) {
- // check if we can pop the top bezier curve from the stack
- qreal l = qAbs(b->x4 - b->x1) + qAbs(b->y4 - b->y1);
- qreal d;
- if (l > inverseScale) {
- d = qAbs( (b->x4 - b->x1)*(b->y1 - b->y2) - (b->y4 - b->y1)*(b->x1 - b->x2) )
- + qAbs( (b->x4 - b->x1)*(b->y1 - b->y3) - (b->y4 - b->y1)*(b->x1 - b->x3) );
- d /= l;
- } else {
- d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) +
- qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
- }
- if (d < inverseScaleHalf || b == beziers + 31) {
- // good enough, we pop it off and add the endpoint
- lineToStencil(b->x4, b->y4);
- --b;
- } else {
- // split, second half of the polygon goes lower into the stack
- b->split(b+1, b);
- ++b;
- }
- }
-}
-
-QRectF QD3DDrawHelper::pathToVertexArrays(const QPainterPath &path)
-{
- m_isLine = (m_item->m_info & QD3DBatchItem::BI_FASTLINE);
- const QPainterPath::Element &first = path.elementAt(0);
- firstx = first.x;
- firsty = first.y;
- min_x = max_x = firstx;
- min_y = max_y = firsty;
-
- m_firstPoint = true;
- tess_index = 0;
- m_item->m_pointstops.clear();
- lineToStencil(firstx, firsty);
- m_firstPoint = false;
-
- for (int i=1; i<path.elementCount(); ++i) {
- const QPainterPath::Element &e = path.elementAt(i);
- switch (e.type) {
- case QPainterPath::MoveToElement:
- m_item->m_pointstops.append(tess_index);
- m_firstPoint = true;
- lineToStencil(e.x, e.y);
- m_firstPoint = false;
- break;
- case QPainterPath::LineToElement:
- lineToStencil(e.x, e.y);
- break;
- case QPainterPath::CurveToElement:
- curveToStencil(e, path.elementAt(i+1), path.elementAt(i+2));
- i+=2;
- break;
- default:
- break;
- }
- }
-
- if (!m_isLine)
- lineToStencil(firstx, firsty);
-
- m_item->m_pointstops.append(tess_index);
-
- m_item->m_offset = m_startindex;
- m_item->m_count = ( m_index - m_startindex ) - 2;
- m_startindex = m_index;
-
- QRectF result;
- result.setLeft(min_x);
- result.setRight(max_x);
- result.setTop(min_y);
- result.setBottom(max_y);
-
- if (m_isLine)
- result.adjust(0,0,1,1);
-
- return result;
-}
-
-void QD3DDrawHelper::resetMask()
-{
- m_mask_position.x = m_mask_position.y = QD3D_MASK_MARGIN;
- m_mask_position.channel = 0;
- m_mask_offsetX2 = m_mask_offsetY2 = QD3D_MASK_MARGIN;
-}
-
-
-static inline QPainterPath strokeForPath(const QPainterPath &path, const QPen &cpen) {
- QPainterPathStroker stroker;
- if (cpen.style() == Qt::CustomDashLine)
- stroker.setDashPattern(cpen.dashPattern());
- else
- stroker.setDashPattern(cpen.style());
-
- stroker.setCapStyle(cpen.capStyle());
- stroker.setJoinStyle(cpen.joinStyle());
- stroker.setMiterLimit(cpen.miterLimit());
- stroker.setWidth(cpen.widthF());
-
- QPainterPath stroke = stroker.createStroke(path);
- stroke.setFillRule(Qt::WindingFill);
- return stroke;
-}
-
-
-QDirect3DPaintEnginePrivate::~QDirect3DPaintEnginePrivate()
-{
-
-}
-
-void QDirect3DPaintEnginePrivate::updateClipPath(const QPainterPath &path, Qt::ClipOperation op)
-{
- //#### remove me
- QRegion r(path.toFillPolygon().toPolygon(), path.fillRule());
- updateClipRegion(r, op);
-
-/* if (m_draw_helper->needsFlushing())
- flushBatch();
-
- if (op == Qt::IntersectClip && !has_clipping)
- op = Qt::ReplaceClip;
-
- // switch to paths
- if (!m_has_complex_clipping) {
- m_clip_path = QPainterPath();
- m_clip_path.addRegion(m_clip_region);
- m_clip_region = QRegion();
- m_sysclip_path = QPainterPath();
- m_sysclip_path.addRegion(m_sysclip_region);
- m_sysclip_region = QRegion();
- m_has_complex_clipping = true;
- }
-
- QPainterPath cpath = m_matrix.map(path);
-
- QD3DBatchItem *item = &m_batch.items[m_batch.m_item_index++];
- item->m_info = QD3DBatchItem::BI_COMPLEXCLIP;
-
- switch (op) {
- case Qt::UniteClip:
- has_clipping = true;
- m_clip_path = m_clip_path.united(cpath);
- break;
- case Qt::ReplaceClip:
- has_clipping = true;
- m_clip_path = cpath;
- break;
- case Qt::NoClip:
- m_has_complex_clipping = false;
- has_clipping = false;
- item->m_info |= QD3DBatchItem::BI_CLEARCLIP;
- break;
- default: // intersect clip
- has_clipping = true;
- m_clip_path = m_clip_path.intersected(cpath);
- break;
- }
-
- if (!m_sysclip_path.isEmpty()) {
- item->m_info &= ~QD3DBatchItem::BI_CLEARCLIP;
- if (has_clipping)
- m_clip_path = m_clip_path.intersected(m_sysclip_path);
- else
- m_clip_path = m_sysclip_path;
- }
-
- // update the aliased clipping mask
- m_draw_helper->setClipPath(m_clip_path, item);
-
- // update the antialiased clipping mask
- if (m_draw_helper->needsFlushing())
- flushBatch();
-
- QD3DBatchItem *aaitem = &m_batch.items[m_batch.m_item_index++];
- aaitem->m_info = item->m_info|QD3DBatchItem::BI_AA;
- m_draw_helper->setClipPath(m_clip_path, aaitem); */
-}
-
-extern QPainterPath qt_regionToPath(const QRegion &region);
-
-void QDirect3DPaintEnginePrivate::updateClipRegion(const QRegion &clipregion, Qt::ClipOperation op)
-{
- if (m_draw_helper->needsFlushing())
- flushBatch();
- if (m_has_complex_clipping) {
- QPainterPath path = qt_regionToPath(clipregion);
- updateClipPath(path, op);
- return;
- }
-
- if (op == Qt::IntersectClip && m_clip_region.isEmpty())
- op = Qt::ReplaceClip;
-
- QRegion cregion = m_matrix.map(clipregion);
-
- QD3DBatchItem *item = nextBatchItem();
- item->m_info &= ~QD3DBatchItem::BI_AA;
-
- switch (op) {
- case Qt::UniteClip:
- m_clip_region = m_clip_region.united(cregion);
- break;
- case Qt::ReplaceClip:
- m_clip_region = cregion;
- break;
- case Qt::NoClip:
- m_clip_region = QRegion();
- item->m_info |= QD3DBatchItem::BI_CLEARCLIP;
- break;
- default: // intersect clip
- m_clip_region = m_clip_region.intersected(cregion);
- break;
- }
-
- QRegion crgn = m_clip_region;
- if (!m_sysclip_region.isEmpty()) {
- item->m_info &= ~QD3DBatchItem::BI_CLEARCLIP;
- if (!crgn.isEmpty())
- crgn = crgn.intersected(m_sysclip_region);
- else
- crgn = m_sysclip_region;
- }
-
- QPainterPath path = qt_regionToPath(crgn);
- m_draw_helper->setClipPath(path, &item);
-}
-
-void QDirect3DPaintEnginePrivate::updateFont(const QFont &)
-{
-}
-
-void QDirect3DPaintEnginePrivate::setRenderTechnique(RenderTechnique technique)
-{
- if (m_current_technique != technique) {
- if (m_current_technique != RT_NoTechnique)
- m_effect->End();
-
- if (technique == RT_Aliased) {
- m_effect->SetTechnique("Aliased");
- m_effect->Begin(0,D3DXFX_DONOTSAVESTATE);
- } else if (technique == RT_Antialiased) {
- m_effect->SetTechnique("Antialiased");
- m_effect->Begin(0,D3DXFX_DONOTSAVESTATE);
- }
- }
-
- m_current_technique = technique;
-}
-
-/*QPolygonF QDirect3DPaintEnginePrivate::transformedRect(const QRectF &brect) const
-{
- QPolygonF poly(brect);
- return m_matrix.map(poly);
-}
-
-QPolygonF QDirect3DPaintEnginePrivate::calcTextureCoords(const QPolygonF &trect) const
-{
- QPolygonF result(4);
- QRectF brect = trect.boundingRect();
- qreal angle = atan(trect.at(0).x() -
-}
-
-QPolygonF QDirect3DPaintEnginePrivate::offsetTextureCoords(const QRectF &brect, const QPolygonF &trect) const
-{
-
-}*/
-
-inline QD3DBatchItem *QDirect3DPaintEnginePrivate::nextBatchItem()
-{
- if (m_draw_helper->needsFlushing())
- flushBatch();
-
- QD3DBatchItem *item = &m_batch.items[m_batch.m_item_index++];
- item->m_info = m_current_state;
- item->m_cmode = m_cmode;
- return item;
-}
-
-qreal calculateAngle(qreal dx, qreal dy)
-{
- qreal angle;
-
- if (qFuzzyCompare(dx + 1, 1)) {
- angle = (dy < 0) ? -M_PI/2 : M_PI/2;
- } else {
- angle = atanf(dy/dx);
- if (dx < 0)
- angle += M_PI;
- }
-
- return angle;
-}
-
-QPolygonF QDirect3DPaintEnginePrivate::brushCoordinates(const QRectF &r, bool stroke, qreal *fd) const
-{
- QBrush brush;
- QTransform matrix;
- Qt::BrushStyle style;
-
- if (stroke) {
- brush = m_pen.brush();
- matrix = m_inv_pen_matrix;
- style = m_pen_brush_style;
- } else {
- brush = m_brush;
- matrix = m_inv_brush_matrix;
- style = m_brush_style;
- }
-
- QPolygonF bpoly;
- switch(style) {
- case Qt::TexturePattern: {
- QTransform totxcoords;
- QRectF adj_brect = r.adjusted(-0.5f, -0.5f, -0.5f, -0.5f);
- totxcoords.scale(1.0f/brush.texture().width(),
- 1.0f/brush.texture().height());
- bpoly = matrix.map(QPolygonF(adj_brect));
- bpoly = totxcoords.map(bpoly);
- break; }
- case Qt::LinearGradientPattern: {
- const QLinearGradient *g = static_cast<const QLinearGradient *>(brush.gradient());
- QPointF start = g->start();
- QPointF stop = g->finalStop();
- qreal dx = stop.x() - start.x();
- qreal dy = stop.y() - start.y();
- qreal length = sqrt(dx * dx + dy * dy);
- qreal angle = calculateAngle(dx, dy);
- QTransform totxcoords;
- QRectF adj_brect = r.adjusted(-0.5f, -0.5f, -0.5f, -0.5f);
- totxcoords.scale(1.0f/length, 1.0f/length);
- totxcoords.rotateRadians(-angle);
- totxcoords.translate(-start.x(), -start.y());
- bpoly = matrix.map(QPolygonF(adj_brect));
- bpoly = totxcoords.map(bpoly);
- break; }
- case Qt::ConicalGradientPattern: {
- const QConicalGradient *g = static_cast<const QConicalGradient *>(brush.gradient());
- QPointF center = g->center();
- qreal angle = g->angle();
- QTransform totxcoords;
- totxcoords.rotate(angle);
- totxcoords.translate(-center.x(), -center.y());
- bpoly = matrix.map(QPolygonF(r));
- bpoly = totxcoords.map(bpoly);
- break; }
- case Qt::RadialGradientPattern: {
- const QRadialGradient *g = static_cast<const QRadialGradient *>(brush.gradient());
- QPointF center = g->center();
- QPointF focalpoint = g->focalPoint();
- qreal dx = focalpoint.x() - center.x();
- qreal dy = focalpoint.y() - center.y();
- qreal radius = g->radius();
- *fd = sqrt(dx * dx + dy * dy) / radius;
- qreal angle = calculateAngle(dx, dy);
- QTransform totxcoords;
- totxcoords.scale(1.0f/radius, 1.0f/radius);
- totxcoords.rotateRadians(-angle);
- totxcoords.translate(-center.x(), -center.y());
- bpoly = matrix.map(QPolygonF(r));
- bpoly = totxcoords.map(bpoly);
- break; }
- default: {
- QTransform totxcoords;
- QRectF adj_brect = r.adjusted(-0.5f, -0.5f, -0.5f, -0.5f);
- QPixmap pat = getPattern(style);
- totxcoords.scale(1.0f/pat.width(),
- 1.0f/pat.height());
- bpoly = matrix.map(QPolygonF(adj_brect));
- bpoly = totxcoords.map(bpoly); }
- };
-
- return bpoly;
-}
-
-void QDirect3DPaintEnginePrivate::strokeAliasedPath(QPainterPath path, const QRectF &brect, const QTransform &txform)
-{
- D3DCOLOR solid_color;
- QD3DBatchItem *item = nextBatchItem();
-
- if (!txform.isIdentity())
- path = txform.map(path);
-
- QRectF trect;
- QPolygonF txcoord;
-
- solid_color = m_pen_color;
- bool has_complex_brush = false;
- if (m_pen_brush_style != Qt::SolidPattern) {
- has_complex_brush = true;
- item->m_brush = m_pen.brush();
- item->m_info |= QD3DBatchItem::BI_COMPLEXBRUSH;
- item->m_opacity = m_opacity;
- }
-
- if (m_has_fast_pen) {
- item->m_info |= QD3DBatchItem::BI_FASTLINE;
- if (m_pen_brush_style == Qt::SolidPattern) {
- m_draw_helper->queueAliasedMask(path, &item, solid_color);
- item->m_info &= ~QD3DBatchItem::BI_MASK; // bypass stencil buffer
- return;
- }
- }
-
- QRectF txrect = m_draw_helper->queueAliasedMask(path, &item, 0);
-
- if (has_complex_brush) {
- trect = brect;
- txcoord = brushCoordinates(brect, true, &item->m_distance);
- item->m_info |= QD3DBatchItem::BI_TRANSFORM;
- item->m_matrix = m_matrix;
- } else {
- trect = txrect;
- static const QPolygonF empty_poly(4);
- txcoord = empty_poly;
- }
-
- m_draw_helper->queueRect(trect, item, solid_color, txcoord);
-}
-
-void QDirect3DPaintEnginePrivate::fillAliasedPath(QPainterPath path, const QRectF &brect, const QTransform &txform)
-{
- D3DCOLOR solid_color;
- QD3DBatchItem *item = nextBatchItem();
-
- if (!txform.isIdentity())
- path = txform.map(path);
-
- QRectF trect;
- QPolygonF txcoord;
-
- solid_color = m_brush_color;
- bool has_complex_brush = false;
- if (m_brush_style != Qt::SolidPattern) {
- has_complex_brush = true;
- item->m_brush = m_brush;
- item->m_info |= QD3DBatchItem::BI_COMPLEXBRUSH;
- item->m_opacity = m_opacity;
- }
-
- QRectF txrect = m_draw_helper->queueAliasedMask(path, &item, 0);
-
- if (has_complex_brush) {
- trect = brect;
- txcoord = brushCoordinates(brect, false, &item->m_distance);
- item->m_info |= QD3DBatchItem::BI_TRANSFORM;
- item->m_matrix = m_matrix;
- } else {
- trect = txrect;
- static const QPolygonF empty_poly(4);
- txcoord = empty_poly;
- }
-
- m_draw_helper->queueRect(trect, item, solid_color, txcoord);
-}
-
-void QDirect3DPaintEnginePrivate::fillAntialiasedPath(const QPainterPath &path, const QRectF &brect,
- const QTransform &txform, bool stroke)
-{
- D3DCOLOR solid_color;
- bool winding = (path.fillRule() == Qt::WindingFill);
- QPolygonF poly;
- QRectF txrect;
- QPainterPath tpath;
-
- if (m_has_aa_fast_pen && stroke) {
- tpath = txform.map(path);
- txrect = tpath.controlPointRect();
- txrect.adjust(-(m_pen_width/2),-(m_pen_width/2), m_pen_width, m_pen_width);
- } else {
- poly = path.toFillPolygon(txform);
- txrect = poly.boundingRect();
- }
-
- // brect = approx. bounding rect before transformation
- // txrect = exact bounding rect after transformation
- // trect = the rectangle to be drawn
- // txcoord = the texture coordinates
- // adj_txrect = adjusted rect to include aliased outline
-
- bool use_scissor = false;
- if (txrect.left() < 0) {
- txrect.adjust(-txrect.left(),0,0,0);
- use_scissor = true;
- }
- if (txrect.top() < 0) {
- txrect.adjust(0,-txrect.top(),0,0);
- use_scissor = true;
- }
-
- if (!txrect.isValid())
- return;
-
- QD3DBatchItem *item = nextBatchItem();
-
- QRectF adj_txrect = txrect.adjusted(-1,-1,1,1);
- QRectF trect;
- QPolygonF txcoord;
-
- bool has_complex_brush = false;
- if (stroke) {
- solid_color = m_pen_color;
- if (m_pen_brush_style != Qt::SolidPattern) {
- has_complex_brush = true;
- item->m_brush = m_pen.brush();
- }
- item->m_width = m_pen_width;
- } else {
- solid_color = m_brush_color;
- if (m_brush_style != Qt::SolidPattern) {
- has_complex_brush = true;
- item->m_brush = m_brush;
- }
- }
-
- qreal focaldist = 0;
- if (has_complex_brush) {
- trect = brect;
- txcoord = brushCoordinates(brect, stroke, &focaldist);
- } else {
- trect = adj_txrect;
- static const QPolygonF empty_poly(4);
- txcoord = empty_poly;
- }
-
- bool maskfull;
- item->m_maskpos = m_draw_helper->allocateMaskPosition(txrect, &maskfull);
- if (maskfull)
- item->m_info |= QD3DBatchItem::BI_MASKFULL;
- item->m_distance = focaldist;
-
- if (winding)
- item->m_info |= QD3DBatchItem::BI_WINDING;
-
- if (has_complex_brush) {
- item->m_info |= QD3DBatchItem::BI_SCISSOR|QD3DBatchItem::BI_COMPLEXBRUSH|
- QD3DBatchItem::BI_TRANSFORM;
- item->m_brect = adj_txrect;
- item->m_matrix = m_matrix;
- item->m_opacity = m_opacity;
- }
- if (use_scissor) {
- item->m_info |= QD3DBatchItem::BI_MASKSCISSOR;
- item->m_brect = adj_txrect;
- }
-
- if (m_has_aa_fast_pen && stroke) {
- m_draw_helper->queueAntialiasedLines(tpath, &item, txrect);
- } else {
- m_draw_helper->queueAntialiasedMask(poly, &item, txrect);
- }
-
- m_draw_helper->queueRect(trect, item, solid_color, txcoord);
-}
-
-QPainterPath QDirect3DPaintEnginePrivate::strokePathFastPen(const QPainterPath &path)
-{
- QPainterPath result;
- QBezier beziers[32];
- for (int i=0; i<path.elementCount(); ++i) {
- const QPainterPath::Element &e = path.elementAt(i);
- switch (e.type) {
- case QPainterPath::MoveToElement:
- result.moveTo(e.x, e.y);
- break;
- case QPainterPath::LineToElement:
- result.lineTo(e.x, e.y);
- break;
-
- case QPainterPath::CurveToElement:
- {
- QPointF sp = path.elementAt(i-1);
- QPointF cp2 = path.elementAt(i+1);
- QPointF ep = path.elementAt(i+2);
- i+=2;
-
- qreal inverseScaleHalf = m_inv_scale / 2;
- beziers[0] = QBezier::fromPoints(sp, e, cp2, ep);
- QBezier *b = beziers;
- while (b >= beziers) {
- // check if we can pop the top bezier curve from the stack
- qreal l = qAbs(b->x4 - b->x1) + qAbs(b->y4 - b->y1);
- qreal d;
- if (l > m_inv_scale) {
- d = qAbs( (b->x4 - b->x1)*(b->y1 - b->y2)
- - (b->y4 - b->y1)*(b->x1 - b->x2) )
- + qAbs( (b->x4 - b->x1)*(b->y1 - b->y3)
- - (b->y4 - b->y1)*(b->x1 - b->x3) );
- d /= l;
- } else {
- d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) +
- qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
- }
- if (d < inverseScaleHalf || b == beziers + 31) {
- // good enough, we pop it off and add the endpoint
- result.lineTo(b->x4, b->y4);
- --b;
- } else {
- // split, second half of the polygon goes lower into the stack
- b->split(b+1, b);
- ++b;
- }
- }
- } // case CurveToElement
- default:
- break;
- } // end of switch
- }
- return result;
-}
-
-void QDirect3DPaintEnginePrivate::strokePath(const QPainterPath &path, QRectF brect, bool simple)
-{
- QTransform txform;
- QPainterPath tpath;
-
- if (m_has_fast_pen || m_has_aa_fast_pen) {
- if (!simple)
- tpath = strokePathFastPen(path);
- else
- tpath = path; //already only lines
- } else {
- tpath = strokeForPath(path, m_pen);
- }
-
- if (tpath.isEmpty())
- return;
-
- //brect is null if the path is not transformed
- if (brect.isNull())
- txform = m_matrix;
-
- if (!brect.isNull()) {
- // brect is set when the path is transformed already,
- // this is the case when we have a cosmetic pen.
- brect.adjust(-(m_pen_width/2),-(m_pen_width/2), m_pen_width, m_pen_width);
- }
-
- if (brect.isNull())
- brect = tpath.controlPointRect();
- brect.adjust(-m_inv_scale,-m_inv_scale,m_inv_scale,m_inv_scale); //adjust for antialiasing
-
- if (m_current_state & QD3DBatchItem::BI_AA) {
- fillAntialiasedPath(tpath, brect, txform, true);
- } else {
- strokeAliasedPath(tpath, brect, txform);
- }
-}
-
-void QDirect3DPaintEnginePrivate::fillPath(const QPainterPath &path, QRectF brect)
-{
- QTransform txform;
-
- //brect is null if the path is not transformed
- if (brect.isNull())
- txform = m_matrix;
-
- if (brect.isNull())
- brect = path.controlPointRect();
- brect.adjust(-m_inv_scale,-m_inv_scale,m_inv_scale,m_inv_scale); //adjust for antialiasing
-
- if (m_current_state & QD3DBatchItem::BI_AA) {
- fillAntialiasedPath(path, brect, txform, false);
- } else {
- fillAliasedPath(path, brect, txform);
- }
-}
-
-
-bool QDirect3DPaintEnginePrivate::init()
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEnginePrivate::init()";
-#endif
-
- m_draw_helper = 0;
- m_gradient_cache = 0;
- m_dc = 0;
- m_dcsurface = 0;
-
- m_supports_d3d = false;
- m_current_state = 0;
- m_in_scene = false;
- m_has_fast_pen = false;
- m_has_aa_fast_pen = false;
- m_has_pen = false;
- m_has_brush = false;
- m_pen_color = 0;
- m_brush_color = 0;
- m_current_surface = 0;
- m_batch.m_item_index = 0;
- m_current_technique = RT_NoTechnique;
-
- if (!pDirect3DCreate9) {
- QLibrary d3d_lib(QLatin1String("d3d9.dll"));
- pDirect3DCreate9 = (PFNDIRECT3DCREATE9) d3d_lib.resolve("Direct3DCreate9");
- if (!pDirect3DCreate9) {
- qWarning("QDirect3DPaintEngine: failed to resolve symbols from d3d9.dll.\n"
- "Make sure you have the DirectX run-time installed.");
- return false;
- }
- }
-
- if (!pD3DXCreateBuffer || !pD3DXCreateEffect || !pD3DXMatrixOrthoOffCenterLH) {
- QLibrary d3dx_lib(QLatin1String("d3dx9_32.dll"));
- pD3DXCreateBuffer = (PFND3DXCREATEBUFFER) d3dx_lib.resolve("D3DXCreateBuffer");
- pD3DXCreateEffect = (PFND3DXCREATEEFFECT) d3dx_lib.resolve("D3DXCreateEffect");
- pD3DXMatrixOrthoOffCenterLH = (PFND3DXMATRIXORTHOOFFCENTERLH)
- d3dx_lib.resolve("D3DXMatrixOrthoOffCenterLH");
- if (!(pD3DXCreateBuffer && pD3DXCreateEffect && pD3DXMatrixOrthoOffCenterLH)) {
- qWarning("QDirect3DPaintEngine: failed to resolve symbols from d3dx9_32.dll.\n"
- "Make sure you have the DirectX run-time installed.");
- return false;
- }
- }
-
- if (!m_d3d_object) {
- m_d3d_object = pDirect3DCreate9(D3D_SDK_VERSION);
- if (!m_d3d_object) {
- qWarning("QDirect3DPaintEngine: failed to create Direct3D object.\n"
- "Direct3D support in Qt will be disabled.");
- return false;
- }
- }
-
- m_supports_d3d = testCaps();
- if (!m_supports_d3d)
- return false;
-
- m_surface_manager.init(m_d3d_object);
- m_d3d_device = m_surface_manager.device();
-
- if (!m_d3d_device)
- return false;
-
- /* load shaders */
- QFile file(QLatin1String(":/qpaintengine_d3d.fx"));
- QByteArray fxFile;
- if (file.open(QFile::ReadOnly))
- fxFile = file.readAll();
-
- if (fxFile.size() > 0) {
- LPD3DXBUFFER compout;
- pD3DXCreateBuffer(4096, &compout);
- DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE|D3DXFX_DONOTSAVESTATE|D3DXSHADER_OPTIMIZATION_LEVEL3;
- if(FAILED(pD3DXCreateEffect(m_d3d_device, fxFile.constData(), fxFile.size(),
- NULL, NULL, dwShaderFlags, NULL, &m_effect, &compout))) {
- qWarning("QDirect3DPaintEngine: failed to compile effect file");
- if (compout)
- qWarning((char *)compout->GetBufferPointer());
- m_supports_d3d = false;
- return false;
- }
- if (m_effect) {
- m_statemanager = new QD3DStateManager(m_d3d_device, m_effect);
- m_effect->SetStateManager(m_statemanager);
- m_draw_helper = new QD3DDrawHelper(this);
- initDevice();
- m_gradient_cache = new QD3DGradientCache(m_d3d_device);
- }
- } else {
- return false;
- }
-
- return true;
-}
-
-QPixmap QDirect3DPaintEnginePrivate::getPattern(Qt::BrushStyle style) const
-{
- if (!m_patterns.contains(style)) {
- QImage img(16,16,QImage::Format_ARGB32);
- img.fill(0);
- QPainter p(&img);
- p.setBrush(QBrush(Qt::white, style));
- p.setPen(Qt::NoPen);
- p.drawRect(0,0,16,16);
- p.end();
- QPixmap pattern(QPixmap::fromImage(img));
- QDirect3DPaintEnginePrivate *ct = const_cast<QDirect3DPaintEnginePrivate *>(this);
- ct->verifyTexture(pattern);
- ct->m_patterns.insert(style, pattern);
- }
-
- return m_patterns.value(style);
-}
-
-bool QDirect3DPaintEnginePrivate::testCaps()
-{
- D3DCAPS9 caps;
- if (FAILED(m_d3d_object->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps)))
- return false;
-
- if ((caps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE)
- && (caps.DevCaps & D3DDEVCAPS_PUREDEVICE)
- && (caps.RasterCaps & D3DPRASTERCAPS_SCISSORTEST)
- && (caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED))
- return true;
-#if 0
- qDebug() << "Direct3D caps:";
- qDebug() << "D3DPRESENT_INTERVAL_IMMEDIATE:" << ((caps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) != 0);
- qDebug() << "D3DDEVCAPS_PUREDEVICE:" << ((caps.DevCaps & D3DDEVCAPS_PUREDEVICE) != 0);
- qDebug() << "D3DPRASTERCAPS_SCISSORTEST:" << ((caps.RasterCaps & D3DPRASTERCAPS_SCISSORTEST) != 0);
- qDebug() << "D3DSTENCILCAPS_TWOSIDED:" << ((caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED) != 0);
-#endif
- return false;
-}
-
-void QDirect3DPaintEnginePrivate::initDevice()
-{
- m_statemanager->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
- m_statemanager->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
- m_statemanager->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
- m_statemanager->SetRenderState(D3DRS_LIGHTING, FALSE);
- m_statemanager->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
- m_statemanager->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
- m_statemanager->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_DESTALPHA);
-}
-
-void QDirect3DPaintEnginePrivate::updatePen(const QPen &pen)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::updatePen";
-#endif
- m_pen = pen;
- m_has_cosmetic_pen = false;
- m_has_pen = (m_pen.style() != Qt::NoPen);
- if (m_has_pen) {
- m_pen_brush_style = m_pen.brush().style();
-
- if (m_pen_brush_style >= Qt::SolidPattern && m_pen_brush_style <= Qt::DiagCrossPattern) {
- int a, r, g, b;
- m_pen.color().getRgb(&r, &g, &b, &a);
- m_pen_color = D3DCOLOR_ARGB((int)(a * m_opacity),r,g,b);
- } else {
- m_pen_color = m_opacity_color;
- }
-
- m_has_cosmetic_pen = m_pen.isCosmetic();
-
- if (m_pen_brush_style != Qt::NoBrush &&
- m_pen_brush_style != Qt::SolidPattern) {
- bool ok;
- m_inv_pen_matrix = m_pen.brush().transform().inverted(&ok);
- if (!ok)
- qWarning() << "QDirect3DPaintEngine: No inverse matix for pen brush matrix.";
- }
-
- m_pen_width = m_pen.widthF();
- if (m_pen_width == 0.0f)
- m_pen_width = 1.0f;
- }
-}
-
-void QDirect3DPaintEnginePrivate::updateBrush(const QBrush &brush)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::updateBrush";
-#endif
- m_brush = brush;
- m_brush_style = m_brush.style();
- m_has_brush = (m_brush_style != Qt::NoBrush);
- if (m_has_brush) {
- if (m_brush_style >= Qt::SolidPattern && m_brush_style <= Qt::DiagCrossPattern) {
- int a, r, g, b;
- m_brush.color().getRgb(&r, &g, &b, &a);
- m_brush_color = D3DCOLOR_ARGB((int)(a * m_opacity),r,g,b);
- } else {
- m_brush_color = m_opacity_color;
- }
-
- if (m_brush_style != Qt::SolidPattern) {
- bool ok;
- m_inv_brush_matrix = (m_brush.transform() * m_brush_origin).inverted(&ok);
- if (!ok)
- qWarning() << "QDirect3DPaintEngine: No inverse matix for brush matrix.";
-
- // make sure the texture is loaded as a texture
- if (m_brush_style == Qt::TexturePattern)
- verifyTexture(m_brush.texture());
-
-
- }
- }
-}
-
-void QDirect3DPaintEnginePrivate::updateTransform(const QTransform &matrix)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::updateTransform";
-#endif
- m_matrix = matrix;
- m_inv_scale = qMax(1 / qMax( qMax(qAbs(m_matrix.m11()), qAbs(m_matrix.m22())),
- qMax(qAbs(m_matrix.m12()), qAbs(m_matrix.m21())) ), 0.0001);
- m_txop = matrix.type();
-}
-
-int QDirect3DPaintEnginePrivate::flushAntialiased(int offset)
-{
- // fills the mask (returns number of items added to the mask)
- int newoffset = m_draw_helper->drawAntialiasedMask(offset, m_batch.m_item_index);
-
- // set the render target to the current output surface
- if (FAILED(m_d3d_device->SetRenderTarget(0, m_current_surface)))
- qWarning() << "QDirect3DPaintEngine: SetRenderTarget failed!";
-
- // draw the bounding boxes (using the mask generated by drawAntialiasedMask)
- for (int i=offset; i<newoffset; ++i) {
- QD3DBatchItem *item = &(m_batch.items[i]);
- int pass = (item->m_info & QD3DBatchItem::BI_COMPLEXBRUSH) ? PASS_AA_DRAW : PASS_AA_DRAW_DIRECT;
- m_statemanager->beginPass(pass);
- prepareItem(item);
- if (item->m_info & QD3DBatchItem::BI_BRECT)
- m_draw_helper->drawAntialiasedBoundingRect(item);
- cleanupItem(item);
- }
-
- m_statemanager->endPass();
-
- return newoffset;
-}
-
-bool QDirect3DPaintEnginePrivate::prepareBatch(QD3DBatchItem *item, int offset)
-{
- if (item->m_info & QD3DBatchItem::BI_CLIP) {
- setRenderTechnique(RT_Aliased);
- if (item->m_info & QD3DBatchItem::BI_CLEARCLIP) {
- m_d3d_device->Clear(0, 0, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
- return true;
- }
-
- m_draw_helper->drawAliasedMask(offset);
- m_d3d_device->Clear(0, 0, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
- if (item->m_info & QD3DBatchItem::BI_BRECT) {
- m_statemanager->beginPass(PASS_STENCIL_CLIP);
- m_draw_helper->drawAliasedBoundingRect(item);
- m_statemanager->endPass();
- }
-
- return true;
- }
-
- if (item->m_info & QD3DBatchItem::BI_AA) {
- setRenderTechnique(RT_Antialiased);
- } else {
- setRenderTechnique(RT_Aliased);
- }
-
- return false;
-}
-
-void QDirect3DPaintEnginePrivate::prepareItem(QD3DBatchItem *item) {
- // pixmap
- int brushmode = 0;
- m_statemanager->startStateBlock();
- if ((item->m_info & QD3DBatchItem::BI_PIXMAP) || (item->m_info & QD3DBatchItem::BI_IMAGE)) {
- QRasterPixmapData *data = static_cast<QRasterPixmapData*>(item->m_pixmap.data);
- IDirect3DTexture9 *tex = (item->m_info & QD3DBatchItem::BI_PIXMAP) ?
- data->texture : item->m_texture;
- m_statemanager->setTexture(tex);
- brushmode = 5;
- }
-
- if (item->m_info & QD3DBatchItem::BI_AA) {
- m_statemanager->setMaskChannel(item->m_maskpos.channel);
- m_statemanager->setMaskOffset(item->m_xoffset, item->m_yoffset);
- }
-
- if (item->m_info & QD3DBatchItem::BI_COMPLEXBRUSH) {
- const QBrush brush = item->m_brush;
- switch (brush.style()) {
- case Qt::TexturePattern: {
- QRasterPixmapData *data = static_cast<QRasterPixmapData*>(brush.texture().data);
- m_statemanager->setTexture(data->texture, QGradient::RepeatSpread);
- brushmode = 1;
- break;
- }
- case Qt::LinearGradientPattern:
- m_statemanager->setTexture(m_gradient_cache->
- getBuffer(brush.gradient()->stops(), item->m_opacity),
- brush.gradient()->spread());
- brushmode = 2;
- break;
- case Qt::ConicalGradientPattern:
- m_statemanager->setTexture(m_gradient_cache->
- getBuffer(brush.gradient()->stops(), item->m_opacity),
- brush.gradient()->spread());
- brushmode = 3;
- break;
- case Qt::RadialGradientPattern:
- m_statemanager->setTexture(m_gradient_cache->
- getBuffer(brush.gradient()->stops(), item->m_opacity),
- brush.gradient()->spread());
- m_statemanager->setFocalDistance(item->m_distance);
- brushmode = 4;
- break;
- default: {
- QRasterPixmapData *data = static_cast<QRasterPixmapData*>(getPattern(brush.style()).data);
- m_statemanager->setTexture(data->texture, QGradient::RepeatSpread);
- brushmode = 5;
- }
- };
- }
-
- if (item->m_info & QD3DBatchItem::BI_TRANSFORM) {
- m_statemanager->setTransformation(&item->m_matrix);
- } else {
- m_statemanager->setTransformation();
- }
-
- m_statemanager->setBrushMode(brushmode);
- setCompositionMode(item->m_cmode);
- m_statemanager->endStateBlock();
-}
-
-
-void QDirect3DPaintEnginePrivate::releaseDC()
-{
- if (m_dc) {
- m_dcsurface->ReleaseDC(m_dc);
- m_dcsurface = 0;
- m_dc = 0;
- }
-}
-
-
-void QDirect3DPaintEnginePrivate::cleanupItem(QD3DBatchItem *item)
-{
- if (item->m_info & QD3DBatchItem::BI_PIXMAP)
- item->m_pixmap = QPixmap();
- item->m_brush = QBrush();
-}
-
-void QDirect3DPaintEnginePrivate::verifyTexture(const QPixmap &pm)
-{
- QRasterPixmapData *pmData = static_cast<QRasterPixmapData*>(pm.data);
- if (!pmData->texture) {
- QImage im = pmData->image;
- // bitmaps are drawn with the current pen color
- if (im.depth() == 1) {
- QVector<QRgb> colors(2);
- colors[0] = 0;
- colors[1] = m_pen.color().rgba();
- im.setColorTable(colors);
- }
- im = im.convertToFormat(QImage::Format_ARGB32);
- if (FAILED(m_d3d_device->CreateTexture(im.width(), im.height(), 1, 0,
- D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pmData->texture, 0)))
- {
- qWarning("QDirect3DPaintEngine: unable to create Direct3D texture from pixmap.");
- return;
- }
- D3DLOCKED_RECT rect;
- if (FAILED(pmData->texture->LockRect(0, &rect, 0, 0))) {
- qDebug() << "QDirect3DPaintEngine: unable to lock texture rect.";
- return;
- }
- DWORD *dst = (DWORD *) rect.pBits;
- DWORD *src = (DWORD *) im.scanLine(0);
-
- Q_ASSERT((rect.Pitch/4) == (im.bytesPerLine()/4));
- memcpy(dst, src, rect.Pitch*im.height());
- pmData->texture->UnlockRect(0);
- }
-}
-
-bool QDirect3DPaintEnginePrivate::isFastRect(const QRectF &rect)
-{
- if (m_matrix.type() < QTransform::TxRotate) {
- QRectF r = m_matrix.mapRect(rect);
- return r.topLeft().toPoint() == r.topLeft()
- && r.bottomRight().toPoint() == r.bottomRight();
- }
-
- return false;
-}
-
-void QDirect3DPaintEnginePrivate::setCompositionMode(QPainter::CompositionMode mode)
-{
- switch(mode) {
- case QPainter::CompositionMode_SourceOver:
- default:
- m_statemanager->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
- m_statemanager->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
- };
-}
-
-void QDirect3DPaintEnginePrivate::cleanup()
-{
- // clean batch
- for(int i=0; i<QD3D_BATCH_SIZE; ++i) {
- m_batch.items[i].m_brush = QBrush();
- m_batch.items[i].m_pixmap = QPixmap();
- }
-
- m_surface_manager.cleanup();
- m_patterns.clear();
-
- delete m_gradient_cache;
- delete m_draw_helper;
-
- if (m_effect)
- m_effect->Release();
-
- if (m_d3d_object)
- m_d3d_object->Release();
-
- m_effect = 0;
- m_d3d_object = 0;
- m_gradient_cache = 0;
- m_draw_helper = 0;
-}
-
-void QDirect3DPaintEnginePrivate::flushAliased(QD3DBatchItem *item, int offset)
-{
- m_draw_helper->drawAliasedMask(offset);
-
- if (item->m_info & QD3DBatchItem::BI_BRECT) {
- int pass = (item->m_info & QD3DBatchItem::BI_MASK) ? PASS_STENCIL_DRAW_DIRECT : PASS_STENCIL_NOSTENCILCHECK_DIRECT;
- if (item->m_info & (QD3DBatchItem::BI_COMPLEXBRUSH|QD3DBatchItem::BI_IMAGE|QD3DBatchItem::BI_PIXMAP) )
- pass = (item->m_info & QD3DBatchItem::BI_MASK) ? PASS_STENCIL_DRAW : PASS_STENCIL_NOSTENCILCHECK;
- m_statemanager->beginPass(pass);
- prepareItem(item);
- m_draw_helper->drawAliasedBoundingRect(item);
- cleanupItem(item);
- m_statemanager->endPass();
- }
-}
-
-void QDirect3DPaintEnginePrivate::flushText(QD3DBatchItem *item, int)
-{
- prepareItem(item);
- m_statemanager->setTexture(item->m_texture);
- m_statemanager->setBrushMode(1);
-// m_statemanager->SetRenderState(D3DRS_BLENDFACTOR, item->m_brush.color().rgba());
- m_statemanager->beginPass(m_cleartype_text ? PASS_CLEARTYPE_TEXT : PASS_TEXT);
- m_draw_helper->drawTextItem(item);
- m_statemanager->endPass();
- cleanupItem(item);
-}
-
-void QDirect3DPaintEnginePrivate::flushLines(QD3DBatchItem *item, int)
-{
- m_draw_helper->drawAliasedLines(item);
-
- if (item->m_info & QD3DBatchItem::BI_BRECT) {
- int pass = (item->m_info & QD3DBatchItem::BI_COMPLEXBRUSH) ? PASS_STENCIL_DRAW : PASS_STENCIL_DRAW_DIRECT;
- m_statemanager->beginPass(pass);
- prepareItem(item);
- m_draw_helper->drawAliasedBoundingRect(item);
- cleanupItem(item);
- m_statemanager->endPass();
- }
-}
-
-void QDirect3DPaintEnginePrivate::flushBatch()
-{
-// static int dbgcounter = 0;
-// ++dbgcounter;
-// qDebug() << " -> flush" << dbgcounter;
-
- int offset = 0;
- m_draw_helper->unlockVertexBuffer();
- releaseDC();
-
- // iterate over all items in the batch
- while (offset != m_batch.m_item_index) {
- QD3DBatchItem *item = &(m_batch.items[offset]);
-
- if (prepareBatch(item, offset)) {
- ++offset;
- continue;
- }
-
- if (item->m_info & QD3DBatchItem::BI_FASTLINE) {
- flushLines(item, offset++);
- } else if (item->m_info & QD3DBatchItem::BI_AA) {
- offset = flushAntialiased(offset);
- } else if (item->m_info & QD3DBatchItem::BI_TEXT) {
- flushText(item, offset++);
- } else {
- flushAliased(item, offset++);
- }
- }
-
- // reset batch
- m_batch.m_item_index = 0;
-
- // release doomed textures
- for (int i=0; i<qd3d_release_list.size(); ++i)
- qd3d_release_list.at(i)->Release();
- qd3d_release_list.clear();
-}
-
-QDirect3DPaintEngine::QDirect3DPaintEngine()
- : QPaintEngine(*(new QDirect3DPaintEnginePrivate),
- PaintEngineFeatures(AllFeatures & ~ObjectBoundingModeGradients))
-{ }
-
-QDirect3DPaintEngine::~QDirect3DPaintEngine()
-{
-}
-
-bool QDirect3DPaintEngine::begin(QPaintDevice *device)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::begin";
-#endif
- Q_D(QDirect3DPaintEngine);
- setActive(true);
-
- QSize old_size = d->m_surface_size;
- d->m_surface_size = QRect(0, 0, device->width(), device->height()).size();
-
- d->m_current_state = 0;
- d->m_inv_scale = 1;
- d->m_opacity = 1.0f;
- d->m_opacity_color = D3DCOLOR_ARGB(255,255,255,255);
- d->m_matrix = QTransform();
- d->m_brush_origin = QTransform();
- d->m_txop = QTransform::TxNone;
- d->m_cmode = QPainter::CompositionMode_SourceOver;
-
- Q_ASSERT(device && device->devType() == QInternal::Widget);
- if (d->m_d3d_device == 0) {
- qWarning() << "QDirect3DPaintEngine: No Device!";
- return false;
- }
-
- d->m_cleartype_text = false;
-// QT_WA({
-// UINT result;
-// BOOL ok;
-// ok = SystemParametersInfoW(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0);
-// if (ok)
-// d->m_cleartype_text = (result == FE_FONTSMOOTHINGCLEARTYPE);
-// }, {
-// UINT result;
-// BOOL ok;
-// ok = SystemParametersInfoA(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0);
-// if (ok)
-// d->m_cleartype_text = (result == FE_FONTSMOOTHINGCLEARTYPE);
-// });
-
- d->m_surface_manager.setPaintDevice(device);
- int status = d->m_surface_manager.status();
- if (status & QD3DSurfaceManager::NeedsResetting) {
- d->m_effect->OnLostDevice();
- d->m_draw_helper->beforeReset();
- d->m_statemanager->reset();
- d->m_surface_manager.reset();
- d->m_draw_helper->afterReset();
- d->m_effect->OnResetDevice();
- d->initDevice();
- }
-
- LPDIRECT3DSURFACE9 newsurface = d->m_surface_manager.renderTarget();
- if (d->m_current_surface != newsurface) {
- d->m_current_surface = newsurface;
- if (FAILED(d->m_d3d_device->SetRenderTarget(0, newsurface)))
- qWarning() << "QDirect3DPaintEngine: SetRenderTarget failed!";
- }
-
- status = d->m_surface_manager.status();
- if (status & QD3DSurfaceManager::MaxSizeChanged) {
- QSize maxsize = d->m_surface_manager.maxSize();
- d->m_draw_helper->setMaskSize(maxsize);
- int masksize[2] = {maxsize.width(), maxsize.height()};
- d->m_effect->SetIntArray("g_mMaskSize", masksize, 2);
- }
-
- if (old_size != d->m_surface_size) {
- D3DXMATRIX projMatrix;
- pD3DXMatrixOrthoOffCenterLH(&projMatrix, 0, d->m_surface_size.width(), d->m_surface_size.height(), 0, 0.0f, 1.0f);
- d->m_statemanager->setProjection(&projMatrix);
- }
-
- if (!d->m_in_scene) {
- if (FAILED(d->m_d3d_device->BeginScene())) {
- qWarning() << "QDirect3DPaintEngine: BeginScene() failed.";
- return false;
- }
- QWidget *widget = static_cast<QWidget *>(device);
- if (widget->autoFillBackground() == true) {
- QColor color = widget->palette().brush(widget->backgroundRole()).color();
- RECT rect = {0, 0, widget->width(), widget->height()};
- d->m_d3d_device->ColorFill(d->m_current_surface, &rect,
- D3DCOLOR_ARGB(color.alpha(), color.red(), color.green(), color.blue()));
- }
- d->m_in_scene = true;
- }
-
- // set system clip
- d->m_clipping_enabled = false;
- d->m_has_complex_clipping = false;
-
- d->m_sysclip_region = systemClip();
- QVector<QRect> rects = d->m_sysclip_region.rects();
- if (rects.count() == 1 && rects.at(0).size() == d->m_surface_size)
- d->m_sysclip_region = QRegion();
-
- d->updateClipRegion(QRegion(), Qt::NoClip);
-
- return true;
-}
-
-void QDirect3DPaintEngine::drawEllipse(const QRectF &rect)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawEllipse (float)";
-#endif
- QPaintEngine::drawEllipse(rect);
-}
-
-void QDirect3DPaintEngine::drawEllipse(const QRect &rect)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawEllipse";
-#endif
- QPaintEngine::drawEllipse(rect);
-}
-
-void QDirect3DPaintEngine::drawImage(const QRectF &r, const QImage &image, const QRectF &sr,
- Qt::ImageConversionFlags)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawImage";
-#endif
-
- Q_D(QDirect3DPaintEngine);
- int width = image.width();
- int height = image.height();
-
- // transform rectangle
- QPolygonF txrect(QRectF(sr.left() / width, sr.top() / height,
- sr.width() / width, sr.height() / height));
-
- QD3DBatchItem *item = d->nextBatchItem();
- item->m_info = QD3DBatchItem::BI_IMAGE | QD3DBatchItem::BI_TRANSFORM;
- item->m_texture = qd3d_image_cache()->lookup(d->m_d3d_device, image);
- item->m_matrix = d->m_matrix;
- d->m_draw_helper->queueRect(r.adjusted(-0.5f,-0.5f,-0.5f,-0.5f), item, d->m_opacity_color, txrect);
-}
-
-void QDirect3DPaintEngine::drawLines(const QLineF *lines, int lineCount)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawLines (float)";
-#endif
- Q_D(QDirect3DPaintEngine);
-
- if (!d->m_has_pen)
- return;
-
- if (d->m_has_fast_pen && (d->m_pen_brush_style == Qt::SolidPattern)) {
- QD3DBatchItem *item = d->nextBatchItem();
- if (d->m_pen.isCosmetic())
- item->m_info |= QD3DBatchItem::BI_COSMETICPEN;
- item->m_info |= QD3DBatchItem::BI_TRANSFORM;
- item->m_matrix = d->m_matrix;
- d->m_draw_helper->queueAliasedLines(lines, lineCount, &item);
- } else {
- QRectF brect;
- QPainterPath path;
-
- // creates a path with the lines
- path.moveTo(lines[0].x1(), lines[0].y1());
- qreal lastx = lines[0].x2();
- qreal lasty = lines[0].y2();
- path.lineTo(lastx, lasty);
-
- for (int i=1; i<lineCount; ++i) {
- qreal x = lines[i].x1();
- qreal y = lines[i].y1();
- if (lastx != x || lasty != y) {
- path.moveTo(x, y);
- }
- path.lineTo(lines[i].x2(), lines[i].y2());
- }
-
- if (d->m_has_cosmetic_pen) {
- brect = path.controlPointRect();
- path = d->m_matrix.map(path);
- }
-
- d->strokePath(path, brect, true);
- }
-}
-
-void QDirect3DPaintEngine::drawLines(const QLine *lines, int lineCount)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawLines";
-#endif
- QPaintEngine::drawLines(lines, lineCount);
-}
-
-void QDirect3DPaintEngine::drawPath(const QPainterPath &path)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawPath";
-#endif
- Q_D(QDirect3DPaintEngine);
-
- if (path.isEmpty())
- return;
-
- QRectF brect;
- QPainterPath tpath;
-
- if (d->m_has_cosmetic_pen) {
- brect = path.controlPointRect();
- tpath = d->m_matrix.map(path);
- } else {
- tpath = path;
- }
-
- if (d->m_has_brush)
- d->fillPath(tpath, brect);
-
- if (d->m_has_pen)
- d->strokePath(tpath, brect);
-}
-
-
-QPointF QDirect3DPaintEnginePrivate::transformPoint(const QPointF &p, qreal *w) const
-{
- (*w) = 1.0f;
- qreal fx = p.x();
- qreal fy = p.y();
- qreal nx = m_matrix.m11()*fx + m_matrix.m21()*fy + m_matrix.m31();
- qreal ny = m_matrix.m12()*fx + m_matrix.m22()*fy + m_matrix.m32();
- if (!m_matrix.isAffine()) {
- *w = m_matrix.m13()*fx + m_matrix.m23()*fy + m_matrix.m33();
- //*w = 1/(*w);
- nx = nx/(*w);
- ny = ny/(*w);
- }
- return QPointF(nx, ny);
-}
-
-void QDirect3DPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawPixmap";
-#endif
- Q_D(QDirect3DPaintEngine);
-
- if (d->m_draw_helper->needsFlushing())
- d->flushBatch();
-
- int width = pm.width();
- int height = pm.height();
-
- // transform rectangle
- QPolygonF txrect(QRectF(sr.left() / width, sr.top() / height,
- sr.width() / width, sr.height() / height));
-
- QD3DBatchItem *item = d->nextBatchItem();
- item->m_info = QD3DBatchItem::BI_PIXMAP|QD3DBatchItem::BI_TRANSFORM;
-
- item->m_pixmap = pm;
- d->verifyTexture(item->m_pixmap);
-
- item->m_matrix = d->m_matrix;
- d->m_draw_helper->queueRect(r.adjusted(-0.5f,-0.5f,-0.5f,-0.5f), item, d->m_opacity_color, txrect);
-}
-
-void QDirect3DPaintEngine::drawPoints(const QPointF *points, int pointCount)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawPoints (float)";
-#endif
- QPaintEngine::drawPoints(points, pointCount);
-}
-
-void QDirect3DPaintEngine::drawPoints(const QPoint *points, int pointCount)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawPoints";
-#endif
- QPaintEngine::drawPoints(points, pointCount);
-}
-
-void QDirect3DPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawPolygon";
-#endif
- Q_D(QDirect3DPaintEngine);
-
- if (d->m_has_brush && mode != PolylineMode) {
- QPainterPath path;
- path.setFillRule(mode == WindingMode ? Qt::WindingFill : Qt::OddEvenFill);
- path.moveTo(points[0]);
- for (int i=1; i<pointCount; ++i)
- path.lineTo(points[i]);
- if (path.isEmpty())
- return;
- d->fillPath(path, QRectF());
- }
-
- if (d->m_has_pen) {
- QPainterPath path(points[0]);
- for (int i = 1; i < pointCount; ++i)
- path.lineTo(points[i]);
- if (mode != PolylineMode)
- path.lineTo(points[0]);
-
- if (path.isEmpty())
- return;
- QRectF brect;
- if (d->m_has_cosmetic_pen) {
- brect = path.controlPointRect();
- path = d->m_matrix.map(path);
- }
-
- d->strokePath(path, brect);
- }
-}
-
-void QDirect3DPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawPolygon";
-#endif
- QPaintEngine::drawPolygon(points, pointCount, mode);
-}
-
-void QDirect3DPaintEngine::drawRects(const QRectF *rects, int rectCount)
-{
- Q_D(QDirect3DPaintEngine);
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawRects (float)";
-#endif
- for (int i=0; i<rectCount; ++i) {
- if ((d->m_brush_style == Qt::SolidPattern) &&
- (!(d->m_current_state & QD3DBatchItem::BI_AA) || d->isFastRect(rects[i]))) {
- QD3DBatchItem *item = d->nextBatchItem();
- item->m_info |= QD3DBatchItem::BI_TRANSFORM;
- item->m_info &= ~QD3DBatchItem::BI_AA;
- item->m_matrix = d->m_matrix;
- const QRectF rect = rects[i];
- d->m_draw_helper->queueRect(rect, item, d->m_brush_color);
-
- if (d->m_has_pen) {
- if (d->m_has_fast_pen && (d->m_pen_brush_style == Qt::SolidPattern)) {
- QLineF lines[4];
- qreal x1 = rect.x();
- qreal y1 = rect.y();
- qreal x2 = rect.width() + x1;
- qreal y2 = rect.height() + y1;
- lines[0] = QLineF(x1, y1, x2, y1);
- lines[1] = QLineF(x2, y1, x2, y2);
- lines[2] = QLineF(x2, y2, x1, y2);
- lines[3] = QLineF(x1, y2, x1, y1);
- QD3DBatchItem *item = d->nextBatchItem();
- if (d->m_pen.isCosmetic())
- item->m_info |= QD3DBatchItem::BI_COSMETICPEN;
- item->m_info |= QD3DBatchItem::BI_TRANSFORM;
- item->m_matrix = d->m_matrix;
- d->m_draw_helper->queueAliasedLines(lines, 4, &item);
- } else {
- QPainterPath path;
- QRectF brect;
-
- path.addRect(rects[i]);
- if (d->m_has_cosmetic_pen) {
- brect = path.controlPointRect();
- path = d->m_matrix.map(path);
- }
-
- d->strokePath(path, brect, true);
- }
- }
- } else {
- QPainterPath path;
- QRectF brect;
-
- path.addRect(rects[i]);
- if (d->m_has_cosmetic_pen) {
- brect = path.controlPointRect();
- path = d->m_matrix.map(path);
- }
-
- if (d->m_has_brush)
- d->fillPath(path, brect);
-
- if (d->m_has_pen)
- d->strokePath(path, brect, true);
- }
- }
-}
-
-void QDirect3DPaintEngine::drawRects(const QRect *rects, int rectCount)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawRects";
-#endif
- QPaintEngine::drawRects(rects, rectCount);
-}
-
-
-void QDirect3DPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
-{
- Q_D(QDirect3DPaintEngine);
-
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawTextItem";
-#endif
-// if (d->m_matrix.isScaling() || (d->m_pen_brush_style >= Qt::LinearGradientPattern
-// && d->m_pen_brush_style <= Qt::ConicalGradientPattern)) {
-// QPaintEngine::drawTextItem(p, textItem);
-// return;
-// }
-
- const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
- QVarLengthArray<QFixedPoint> positions;
- QVarLengthArray<glyph_t> glyphs;
- QTransform matrix;
- matrix.translate(p.x(), p.y());
- ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
-
- qd3d_glyph_cache()->cacheGlyphs(this, ti, glyphs, d->m_cleartype_text);
- QD3DFontTexture *font_tex = qd3d_glyph_cache()->fontTexture(ti.fontEngine);
-
- QD3DBatchItem *item = d->nextBatchItem();
- d->m_draw_helper->lockVertexBuffer();
-
- item->m_info = QD3DBatchItem::BI_TEXT
- | (d->m_current_state & ~QD3DBatchItem::BI_AA) | QD3DBatchItem::BI_TRANSFORM;
- item->m_texture = font_tex->texture;
- item->m_offset = d->m_draw_helper->index();
- item->m_matrix = d->m_matrix;
- item->m_count = 0;
- item->m_brush = d->m_pen.brush();
-
- for (int i=0; i< glyphs.size(); ++i) {
- QD3DGlyphCoord *g = qd3d_glyph_cache()->lookup(ti.fontEngine, glyphs[i]);
-
- // we don't cache glyphs with no width/height
- if (!g)
- continue;
-
- // texture coords
- qreal tex_coords[] = { g->x, g->y, g->x + g->width, g->y + g->height };
- QPointF logical_pos(qRound((positions[i].x - g->x_offset).toReal()) - 0.5f,
- qRound((positions[i].y + g->y_offset).toReal()) - 0.5f);
-
- QRectF glyph_rect(logical_pos, QSizeF(g->log_width, g->log_height));
- d->m_draw_helper->queueTextGlyph(glyph_rect, tex_coords, item, d->m_pen_color);
- }
-}
-
-void QDirect3DPaintEngine::drawTiledPixmap(const QRectF &rect, const QPixmap &pixmap, const QPointF &p)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::drawTiledPixmap";
-#endif
- QPaintEngine::drawTiledPixmap(rect, pixmap, p);
-}
-
-bool QDirect3DPaintEngine::end()
-{
- Q_D(QDirect3DPaintEngine);
-
- d->flushBatch();
-
- if (d->m_flush_on_end) {
- QPaintDevice *pdev = paintDevice();
- LPDIRECT3DSWAPCHAIN9 swapchain = swapChain(pdev);
-
-
- QWidget *w = 0;
- if (pdev->devType() == QInternal::Widget) {
- w = static_cast<QWidget *>(pdev);
- }
-
- if (w && swapchain) {
- QRect br = w->rect();
- QRect wbr = br;//.translated(-w->pos());
-
- RECT destrect;
- destrect.left = wbr.x();
- destrect.top = wbr.y();
- destrect.right = destrect.left + wbr.width();
- destrect.bottom = destrect.top + wbr.height();
-
- RECT srcrect;
- srcrect.left = br.x();// + w->x();
- srcrect.top = br.y();// + w->y();
- srcrect.right = wbr.width() + srcrect.left;
- srcrect.bottom = wbr.height() + srcrect.top;
- int devwidth = w->width();
- int devheight = w->height();
-
- if (devwidth <= srcrect.right) {
- int diff = srcrect.right - devwidth;
- srcrect.right -= diff;
- destrect.right -= diff;
- if (srcrect.right <= srcrect.left)
- return false;
- }
- if (devheight <= srcrect.bottom) {
- int diff = srcrect.bottom - devheight;
- srcrect.bottom -= diff;
- destrect.bottom -= diff;
- if (srcrect.bottom <= srcrect.top)
- return false;
- }
-
- if (FAILED(swapchain->Present(&srcrect, &destrect, w->winId(), 0, 0)))
- qWarning("QDirect3DPaintEngine: failed to present back buffer.");
- }
- }
-
-
- return true;
-}
-
-void QDirect3DPaintEngine::updateState(const QPaintEngineState &state)
-{
-#ifdef QT_DEBUG_D3D_CALLS
- qDebug() << "QDirect3DPaintEngine::updateState";
-#endif
- Q_D(QDirect3DPaintEngine);
-
- bool update_fast_pen = false;
- DirtyFlags flags = state.state();
-
- if (flags & DirtyOpacity) {
- d->m_opacity = state.opacity();
- if (d->m_opacity > 1.0f)
- d->m_opacity = 1.0f;
- if (d->m_opacity < 0.f)
- d->m_opacity = 0.f;
- uint c = (d->m_opacity * 255);
- d->m_opacity_color = D3DCOLOR_ARGB(c,c,c,c);
- flags |= (DirtyPen | DirtyBrush);
- }
-
- if (flags & DirtyCompositionMode) {
- d->m_cmode = state.compositionMode();
- }
-
- if (flags & DirtyTransform) {
- d->updateTransform(state.transform());
- update_fast_pen = true;
- }
-
- if (flags & DirtyHints) {
- if (state.renderHints() & QPainter::Antialiasing)
- d->m_current_state |= QD3DBatchItem::BI_AA;
- else
- d->m_current_state &= ~QD3DBatchItem::BI_AA;
- update_fast_pen = true;
- }
-
- if (flags & DirtyFont) {
- d->updateFont(state.font());
- }
-
- if (state.state() & DirtyClipEnabled) {
- if (state.isClipEnabled() && !d->m_clipping_enabled) {
- d->m_clipping_enabled = true;
- if (d->m_has_complex_clipping)
- d->updateClipPath(painter()->clipPath(), Qt::ReplaceClip);
- else
- d->updateClipRegion(painter()->clipRegion(), Qt::ReplaceClip);
- } else if (!state.isClipEnabled() && d->m_clipping_enabled) {
- d->m_clipping_enabled = false;
- if (d->m_has_complex_clipping)
- d->updateClipPath(QPainterPath(), Qt::NoClip);
- else
- d->updateClipRegion(QRegion(), Qt::NoClip);
- }
- }
-
- if (flags & DirtyClipRegion) {
- d->updateClipRegion(state.clipRegion(), state.clipOperation());
- }
-
- if (flags & DirtyClipPath) {
- d->updateClipPath(state.clipPath(), state.clipOperation());
- }
-
- if (flags & DirtyBrushOrigin) {
- d->m_brush_origin = QTransform();
- d->m_brush_origin.translate(-state.brushOrigin().x(),
- -state.brushOrigin().y());
- flags |= DirtyBrush;
- }
-
- if (flags & DirtyPen) {
- d->updatePen(state.pen());
- update_fast_pen = true;
- }
-
- if (flags & DirtyBrush)
- d->updateBrush(state.brush());
-
- if (update_fast_pen && d->m_has_pen) {
- if (d->m_current_state & QD3DBatchItem::BI_AA) {
- d->m_has_fast_pen = false;
- d->m_has_aa_fast_pen = ((d->m_txop <= QTransform::TxTranslate) || d->m_has_cosmetic_pen)
- && (d->m_pen_width <= 1.0f)
- && (d->m_pen.style() == Qt::SolidLine);
- } else {
- d->m_has_aa_fast_pen = false;
- d->m_has_fast_pen = ((d->m_txop <= QTransform::TxTranslate) || d->m_has_cosmetic_pen)
- && (d->m_pen.style() == Qt::SolidLine)
- && (d->m_pen.capStyle() == Qt::SquareCap);
- }
- }
-}
-
-void QDirect3DPaintEngine::cleanup()
-{
- Q_D(QDirect3DPaintEngine);
- d->cleanup();
-}
-
-void QDirect3DPaintEngine::scroll(QPaintDevice *pd, const RECT &srcrect, const RECT &destrect)
-{
- Q_D(QDirect3DPaintEngine);
- LPDIRECT3DSURFACE9 srcsurf = d->m_surface_manager.surface(pd);
- LPDIRECT3DSURFACE9 masksurf = d->m_draw_helper->freeMaskSurface();
- if (FAILED(d->m_d3d_device->StretchRect(srcsurf, &srcrect, masksurf, &srcrect, D3DTEXF_NONE)))
- qWarning("QDirect3DPaintEngine: StretchRect failed.");
- if (FAILED(d->m_d3d_device->StretchRect(masksurf, &srcrect, srcsurf, &destrect, D3DTEXF_NONE)))
- qWarning("QDirect3DPaintEngine: StretchRect failed.");
-}
-
-LPDIRECT3DSWAPCHAIN9 QDirect3DPaintEngine::swapChain(QPaintDevice *pd)
-{
- Q_D(QDirect3DPaintEngine);
-
- if (d->m_in_scene) {
- if (d->m_d3d_device == 0) {
- qWarning("QDirect3DPaintEngine: No device!");
- return false;
- }
-
- d->setRenderTechnique(QDirect3DPaintEnginePrivate::RT_NoTechnique);
- if (FAILED(d->m_d3d_device->EndScene()))
- qWarning("QDirect3DPaintEngine: failed to end scene.");
-
- d->m_in_scene = false;
- }
-
- return d->m_surface_manager.swapChain(pd);
-}
-
-void QDirect3DPaintEngine::releaseSwapChain(QPaintDevice *pd)
-{
- Q_D(QDirect3DPaintEngine);
- d->m_surface_manager.releasePaintDevice(pd);
-}
-
-HDC QDirect3DPaintEngine::getDC() const
-{
- QDirect3DPaintEnginePrivate *d = const_cast<QDirect3DPaintEnginePrivate *>(d_func());
-
- if (!d->m_dc && d->m_current_surface) {
- d->m_dcsurface = d->m_current_surface;
- if (FAILED(d->m_current_surface->GetDC(&d->m_dc)))
- qWarning() << "QDirect3DPaintEngine::getDC() failed!";
- }
-
- return d->m_dc;
-}
-
-void QDirect3DPaintEngine::setFlushOnEnd(bool flushOnEnd)
-{
- Q_D(QDirect3DPaintEngine);
-
- d->m_flush_on_end = flushOnEnd;
-}
-
-bool QDirect3DPaintEngine::hasDirect3DSupport()
-{
- Q_D(QDirect3DPaintEngine);
- return d->m_supports_d3d;
-}
-
-QT_END_NAMESPACE
-
-#include "qpaintengine_d3d.moc"
diff --git a/src/gui/painting/qpaintengine_d3d.fx b/src/gui/painting/qpaintengine_d3d.fx
deleted file mode 100644
index 1148b2a..0000000
--- a/src/gui/painting/qpaintengine_d3d.fx
+++ /dev/null
@@ -1,608 +0,0 @@
-bool g_mCosmeticPen;
-int4 g_mChannel;
-float2 g_mMaskOffset;
-int2 g_mMaskSize;
-float4x4 g_mMaskProjection;
-float4x4 g_mViewProjection;
-float4x4 g_mTransformation;
-texture g_mAAMask;
-texture g_mTexture;
-int g_mBrushMode;
-float g_mFocalDist;
-
-#define M_PI 3.14159265358979323846
-
-sampler PixmapSampler = sampler_state
-{
- texture = <g_mTexture>;
- MIPFILTER = NONE;
- MINFILTER = LINEAR;
- MAGFILTER = LINEAR;
-};
-
-sampler TextSampler = sampler_state
-{
- texture = <g_mTexture>;
- MIPFILTER = NONE;
- MINFILTER = POINT;
- MAGFILTER = POINT;
-};
-
-sampler AAMaskSampler = sampler_state
-{
- texture = <g_mAAMask>;
- AddressU = WRAP;
- AddressV = WRAP;
- AddressW = WRAP;
- MIPFILTER = NONE;
- MINFILTER = POINT;
- MAGFILTER = POINT;
-};
-
-struct VS_FULL
-{
- float4 Position : POSITION;
- float4 Diffuse : COLOR0;
- float4 TexCoords0 : TEXCOORD0;
- float4 TexCoords1 : TEXCOORD1;
-};
-
-VS_FULL TrapezoidVS( float4 Position : POSITION,
- float4 Diffuse : COLOR0,
- float4 TexCoords0 : TEXCOORD0,
- float4 TexCoords1 : TEXCOORD1)
-{
- VS_FULL Output;
-
- float a = (TexCoords1.x * Position.x) + (TexCoords1.z * (1.0 - Position.x) ); // left or right a
- float b = (TexCoords1.y * Position.x) + (TexCoords1.w * (1.0 - Position.x) ); // left or right b
- float d = 1.0 - (Position.x * 2);
-
- Position.x = (a * Position.y + b) + ( sqrt( abs(a * a) ) * d );
- //Position.x += step(abs(a), 0) * d;
- Position.x += (0.5 * d);
-
- Output.Position = mul(Position, g_mMaskProjection);
- Output.Diffuse = Diffuse;
- Output.TexCoords0 = TexCoords0;
- Output.TexCoords1 = TexCoords1;
-
- return Output;
-}
-
-struct PS_OUTPUT
-{
- float4 Color : COLOR0;
-};
-
-PS_OUTPUT TrapezoidPS(VS_FULL In, float2 pixelPos : VPOS)
-{
- PS_OUTPUT Out;
-
- float top = max(pixelPos.y - 0.5, In.TexCoords0.x);
- float bottom = min(pixelPos.y + 0.5, In.TexCoords0.y);
-
- float area = bottom - top;
-
- float left = pixelPos.x - 0.5;
- float right = pixelPos.x + 0.5;
-
- // use line equations to compute intersections of left/right edges with top/bottom of truncated pixel
- // vecX: x = (left, top), y = (left, bottom), z = (right, top), w = (right, bottom)
- float4 vecX = In.TexCoords1.xxzz * float2(top, bottom).xyxy + In.TexCoords1.yyww;
-
- float2 invA = In.TexCoords0.zw;
-
- // transform right line to left to be able to use same calculations for both
- vecX.zw = 2 * pixelPos.x - vecX.zw;
-
- float2 topX = float2(vecX.x, vecX.z);
- float2 bottomX = float2(vecX.y, vecX.w);
-
- // transform lines such that top intersection is to the right of bottom intersection
- float2 topXTemp = max(topX, bottomX);
- float2 bottomXTemp = min(topX, bottomX);
-
- // make sure line slope reflects mirrored lines
- invA = lerp(invA, -invA, step(topX, bottomX));
-
- float2 vecLeftRight = float2(left, right);
-
- // compute the intersections of the lines with the left and right edges of the pixel
- // intersectY: x = (left_line, left), y = (left_line, right), z = (right_line, left), w = (right_line, right)
- float4 intersectY = top + (vecLeftRight.xyxy - topXTemp.xxyy) * invA.xxyy;
-
- float2 temp = lerp(area - 0.5 * (right - bottomXTemp) * (bottom - intersectY.yw), // left < bottom < right < top
- (0.5 * (topXTemp + bottomXTemp) - left) * area, // left < bottom < top < right
- step(topXTemp, right));
-
- float2 excluded = 0.5 * (intersectY.xz - top) * (topXTemp - left); // bottom < left < top < right
-
- excluded = lerp(0.5 * (intersectY.yw + intersectY.xz) - top, // bottom < left < right < top
- excluded, step(topXTemp, right));
-
- excluded = lerp(temp, // left < bottom < right (see calculation of temp)
- excluded, step(bottomXTemp, left));
-
- excluded = lerp(float2(area, area), // right < bottom < top
- excluded, step(bottomXTemp, right));
-
- excluded *= step(left, topXTemp);
-
- float result = (area - excluded.x - excluded.y) * step(top, bottom);
- Out.Color.r = result * g_mChannel[0];
- Out.Color.g = result * g_mChannel[1];
- Out.Color.b = result * g_mChannel[2];
- Out.Color.a = result * g_mChannel[3];
-
- return Out;
-}
-
-VS_FULL ViewProjectionVS( float4 Position : POSITION,
- float4 Diffuse : COLOR0,
- float4 TexCoords0 : TEXCOORD0,
- float4 TexCoords1 : TEXCOORD1)
-{
- VS_FULL Output;
-
- Output.Position = mul(Position, g_mTransformation);
- Output.Position = mul(Output.Position, g_mViewProjection);
- Output.Diffuse = Diffuse;
- Output.TexCoords0 = TexCoords0;
- Output.TexCoords1 = TexCoords1;
-
- return Output;
-}
-
-PS_OUTPUT DirectMaskPS(VS_FULL In, float2 pixelPos : VPOS)
-{
- PS_OUTPUT Out;
- Out.Color = In.Diffuse;
-
- float2 maskcoords = ( (pixelPos + g_mMaskOffset) - 0.5 ) / g_mMaskSize;
- float2 clipcoords = (pixelPos - 0.5) / g_mMaskSize;
-
- float4 c = tex2D(AAMaskSampler, maskcoords.xy) * Out.Color.a;
- Out.Color.a = c.r * g_mChannel[0];
- Out.Color.a += c.g * g_mChannel[1];
- Out.Color.a += c.b * g_mChannel[2];
- Out.Color.a += c.a * g_mChannel[3];
-
- return Out;
-}
-
-PS_OUTPUT MaskPS(VS_FULL In, float2 pixelPos : VPOS)
-{
- PS_OUTPUT Out;
-
- if (g_mBrushMode == 1) {
- float x = In.TexCoords0.x;
- float y = In.TexCoords0.y;
- x = x - int(x);
- y = y - int(y);
- Out.Color = tex2D(PixmapSampler, float2(x, y));
- Out.Color.a = Out.Color.a * In.Diffuse.a;
- } else if (g_mBrushMode == 2) {
- Out.Color = tex1D(PixmapSampler, In.TexCoords0.x);
- } else if (g_mBrushMode == 3) {
- float t = atan2(In.TexCoords0.y, -In.TexCoords0.x) / (2 * M_PI);
- Out.Color = tex1D(PixmapSampler, t + 0.5);
- } else if (g_mBrushMode == 4) {
- float2 tc = float2(In.TexCoords0.x, abs(In.TexCoords0.y));
- float a = (tc.x - g_mFocalDist) / tc.y;
- float b = g_mFocalDist;
-
- float A = 1 + (a * a);
- float B = 2.0 * a * b;
- float C = (b * b) - 1;
-
- float y = (-B + sqrt(B*B - 4.0*A*C)) / (2.0*A);
- Out.Color = tex1D(PixmapSampler, (tc.y / y) );
- } else if (g_mBrushMode == 5) {
- Out.Color = tex2D(PixmapSampler, In.TexCoords0.xy);
- Out.Color = Out.Color * In.Diffuse;
- } else {
- Out.Color = In.Diffuse;
- }
-
- float2 maskcoords = ( (pixelPos + g_mMaskOffset) - 0.5 ) / g_mMaskSize;
-
- float4 c = tex2D(AAMaskSampler, maskcoords.xy) * Out.Color.a;
- Out.Color.a = c.r * g_mChannel[0];
- Out.Color.a += c.g * g_mChannel[1];
- Out.Color.a += c.b * g_mChannel[2];
- Out.Color.a += c.a * g_mChannel[3];
-
- return Out;
-}
-
-struct VS_NORMAL
-{
- float4 Position : POSITION;
- float4 Diffuse : COLOR0;
- float4 TexCoords : TEXCOORD0;
-};
-
-VS_NORMAL MaskProjectionVS(VS_NORMAL In)
-{
- VS_NORMAL Output;
-
- Output.Position = mul(In.Position, g_mMaskProjection);
- Output.Diffuse = In.Diffuse;
- Output.TexCoords = In.TexCoords;
-
- return Output;
-}
-
-float4 DirectSimplePS(float4 Color : COLOR0) : COLOR0
-{
- return Color;
-}
-
-float4 SimplePS(float4 Color : COLOR0, float4 TexCoords : TEXCOORD0) : COLOR0
-{
- if (g_mBrushMode == 1) {
- float opacity = Color.a;
- float x = TexCoords.x;
- float y = TexCoords.y;
- x = x - int(x);
- y = y - int(y);
- Color = tex2D(PixmapSampler, float2(x, y));
- Color.a = Color.a * opacity;
- } else if (g_mBrushMode == 2) {
- Color = tex1D(PixmapSampler, TexCoords.x);
- } else if (g_mBrushMode == 3) {
- float t = atan2(TexCoords.y, -TexCoords.x) / (2 * M_PI);
- Color = tex1D(PixmapSampler, t + 0.5);
- } else if (g_mBrushMode == 4) {
- float2 tc = float2(TexCoords.x, abs(TexCoords.y));
- float a = (tc.x - g_mFocalDist) / tc.y;
- float b = g_mFocalDist;
-
- float A = 1 + (a * a);
- float B = 2.0 * a * b;
- float C = (b * b) - 1;
-
- float y = (-B + sqrt(B*B - 4.0*A*C)) / (2.0*A);
- Color = tex1D(PixmapSampler, (tc.y / y) );
- } else if (g_mBrushMode == 5) {
- Color = tex2D(PixmapSampler, TexCoords.xy) * Color;
- }
-
- return Color;
-}
-
-float4 TextPS(float4 Color : COLOR0, float4 TexCoords : TEXCOORD0) : COLOR0
-{
- Color.a *= tex2D(TextSampler, TexCoords.xy).a;
- return Color;
-}
-
-float4 ClearTypePS(float4 Color : COLOR0, float4 TexCoords : TEXCOORD0) : COLOR0
-{
-// if (g_mUsePixmap) {
-// float4 MaskColor = tex2D(PixmapSampler, TexCoords.xy);
-// Color = float4(1.0, 0.0, 0.0, 1.0);
-// Color.a = (1 - MaskColor.a) + MaskColor.a * Color.a;
-// Color.r = (1.0 - MaskColor.r) + (MaskColor.r * Color.r);
-// Color.g = (1.0 - MaskColor.g) + (MaskColor.g * Color.g);
-// Color.b = (1.0 - MaskColor.b) + (MaskColor.b * Color.b);
-// Color = MaskColor;
- return tex2D(PixmapSampler, TexCoords.xy);
-}
-
-VS_NORMAL NoTxAliasedVS(VS_NORMAL In)
-{
- VS_NORMAL Output;
-
- Output.Position = mul(In.Position, g_mViewProjection);
- Output.Diffuse = In.Diffuse;
- Output.TexCoords = In.TexCoords;
-
- return Output;
-}
-
-VS_NORMAL AliasedVS(VS_NORMAL In)
-{
- VS_NORMAL Output;
-
- Output.Position = mul(In.Position, g_mTransformation);
- Output.Position = mul(Output.Position, g_mViewProjection);
- Output.Diffuse = In.Diffuse;
- Output.TexCoords = In.TexCoords;
-
- return Output;
-}
-
-VS_NORMAL AliasedLinesVS(VS_NORMAL In)
-{
- VS_NORMAL Output;
-
- float4 start = float4(In.Position.x, In.Position.y, 0.5, In.Position.w);
- float4 end = float4(In.TexCoords.z, In.TexCoords.w, 0.5, In.Position.w);
- if (g_mCosmeticPen) {
- start = mul(start, g_mTransformation);
- end = mul(end, g_mTransformation);
- }
-
- float2 line_vec = end - start;
- float2 vec = normalize(line_vec);
- float2 norm = float2(-vec.y, vec.x);
-
- float pen_width = In.Position.z;
- norm = norm * pen_width * 0.5;
- vec = vec * pen_width * 0.5;
-
- Output.Position.w = In.Position.w;
- Output.Position.x = start.x + (vec.x * In.TexCoords.x);
- Output.Position.x = Output.Position.x + (norm.x * In.TexCoords.y);
- Output.Position.x = Output.Position.x + (line_vec.x * step(0, In.TexCoords.x));
- Output.Position.y = start.y + (vec.y * In.TexCoords.x);
- Output.Position.y = Output.Position.y + (norm.y * In.TexCoords.y);
- Output.Position.y = Output.Position.y + (line_vec.y * step(0, In.TexCoords.x));
- Output.Position.z = 0.5;
-
- if (!g_mCosmeticPen) {
- Output.Position = mul(Output.Position, g_mTransformation);
- }
- Output.Position = mul(Output.Position, g_mViewProjection);
-
- Output.Diffuse = In.Diffuse;
- Output.TexCoords = In.TexCoords;
-
- return Output;
-}
-
-
-technique Antialiased
-{
- pass PASS_AA_CREATEMASK
- {
- StencilEnable = False;
- ZWriteEnable = False;
- ColorWriteEnable = 0x0f;
- ZEnable = False;
-
- SrcBlend = One;
- DestBlend = One;
-
- VertexShader = compile vs_3_0 TrapezoidVS();
- PixelShader = compile ps_3_0 TrapezoidPS();
- }
-
- pass PASS_AA_DRAW
- {
- StencilEnable = False;
- ZFunc = Greater;
- ZWriteEnable = False;
- ZEnable = True;
- ColorWriteEnable = 0x0f;
-
- VertexShader = compile vs_3_0 ViewProjectionVS();
- PixelShader = compile ps_3_0 MaskPS();
- }
-
- pass PASS_AA_DRAW_DIRECT
- {
- StencilEnable = False;
- ZFunc = Greater;
- ZEnable = True;
- ZWriteEnable = False;
- ColorWriteEnable = 0x0f;
-
- VertexShader = compile vs_3_0 ViewProjectionVS();
- PixelShader = compile ps_3_0 DirectMaskPS();
- }
-}
-
-technique Aliased
-{
- pass PASS_STENCIL_ODDEVEN
- {
- TwoSidedStencilMode = False;
- StencilEnable = True;
- StencilPass = Invert;
- StencilFunc = Always;
- ColorWriteEnable = 0;
-
- ZEnable = False;
- ZWriteEnable = False;
-
- VertexShader = compile vs_1_1 NoTxAliasedVS();
- PixelShader = compile ps_2_0 DirectSimplePS();
- }
-
- pass PASS_STENCIL_WINDING
- {
- TwoSidedStencilMode = True;
- StencilEnable = True;
- StencilRef = 0;
- StencilMask = 0xFFFFFFFF;
-
- CCW_StencilPass = Incr;
- CCW_StencilFunc = Always;
-
- StencilPass = Decr;
- StencilFunc = Always;
-
- ColorWriteEnable = 0;
-
- ZEnable = False;
- ZWriteEnable = False;
-
- VertexShader = compile vs_1_1 NoTxAliasedVS();
- PixelShader = compile ps_2_0 DirectSimplePS();
- }
-
- pass PASS_STENCIL_DRAW
- {
- TwoSidedStencilMode = False;
- StencilEnable = True;
- StencilFunc = NotEqual;
- StencilMask = 0xFFFFFFFF;
- StencilRef = 0;
- StencilPass = Zero;
- StencilFail = Zero;
- StencilZFail = Zero;
-
- ColorWriteEnable = 0x0f;
- ZEnable = True;
- ZWriteEnable = False;
- ZFunc = Greater;
-
- VertexShader = compile vs_1_1 AliasedVS();
- PixelShader = compile ps_2_0 SimplePS();
- }
-
- pass PASS_STENCIL_DRAW_DIRECT
- {
- TwoSidedStencilMode = False;
- StencilEnable = True;
- StencilFunc = NotEqual;
- StencilMask = 0xFFFFFFFF;
- StencilRef = 0;
- StencilPass = Zero;
- StencilFail = Zero;
- StencilZFail = Zero;
-
- ColorWriteEnable = 0x0f;
- ZEnable = True;
- ZWriteEnable = False;
- ZFunc = Greater;
-
- VertexShader = compile vs_1_1 AliasedVS();
- PixelShader = compile ps_2_0 DirectSimplePS();
- }
-
- pass PASS_STENCIL_CLIP
- {
- TwoSidedStencilMode = False;
- StencilEnable = True;
- StencilFunc = NotEqual;
- StencilMask = 0xFFFFFFFF;
- StencilRef = 0;
- StencilPass = Zero;
- StencilFail = Zero;
- StencilZFail = Zero;
-
- ColorWriteEnable = 0;
- ZEnable = True;
- ZWriteEnable = True;
- ZFunc = Always;
-
- VertexShader = compile vs_1_1 NoTxAliasedVS();
- PixelShader = compile ps_2_0 DirectSimplePS();
- }
-
- pass PASS_STENCIL_NOSTENCILCHECK
- {
- StencilEnable = False;
-
- ZEnable = True;
- ZWriteEnable = False;
- ZFunc = Greater;
-
- ColorWriteEnable = 0x0f;
-
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- VertexShader = compile vs_1_1 AliasedVS();
- PixelShader = compile ps_2_0 SimplePS();
- }
-
- pass PASS_STENCIL_NOSTENCILCHECK_DIRECT
- {
- StencilEnable = False;
-
- ZEnable = True;
- ZWriteEnable = False;
- ZFunc = Greater;
-
- ColorWriteEnable = 0x0f;
-
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- VertexShader = compile vs_1_1 AliasedVS();
- PixelShader = compile ps_2_0 DirectSimplePS();
- }
-
- pass PASS_TEXT
- {
- StencilEnable = False;
-
- ZEnable = True;
- ZWriteEnable = False;
- ZFunc = Greater;
-
- ColorWriteEnable = 0x0f;
-
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- VertexShader = compile vs_1_1 AliasedVS();
- PixelShader = compile ps_2_0 TextPS();
- }
-
- pass PASS_CLEARTYPE_TEXT
- {
- StencilEnable = False;
-
- ZEnable = True;
- ZWriteEnable = False;
- ZFunc = Greater;
-
- ColorWriteEnable = 0x0f;
-
-// SrcBlend = SrcAlpha;
-// DestBlend = InvSrcAlpha;
-
-// SrcBlend = DestColor;
-// DestBlend = Zero;
- SrcBlend = BlendFactor;
- DestBlend = InvSrcColor;
-
-// SrcBlend = Zero;
-// DestBlend = SrcColor;
-
-// SrcBlend = One;
-// DestBlend = Zero;
-
- VertexShader = compile vs_3_0 AliasedVS();
- PixelShader = compile ps_3_0 ClearTypePS();
- }
-
- pass PASS_ALIASED_LINES
- {
- TwoSidedStencilMode = False;
- StencilEnable = True;
- StencilPass = Invert;
- StencilFunc = Always;
- ColorWriteEnable = 0;
-
- ZEnable = False;
- ZWriteEnable = False;
-
- VertexShader = compile vs_1_1 AliasedLinesVS();
- PixelShader = compile ps_2_0 DirectSimplePS();
- }
-
- pass PASS_ALIASED_LINES_DIRECT
- {
- StencilEnable = False;
-
- ZEnable = True;
- ZWriteEnable = False;
- ZFunc = Greater;
-
- ColorWriteEnable = 0x0f;
-
- SrcBlend = SrcAlpha;
- DestBlend = InvSrcAlpha;
-
- VertexShader = compile vs_1_1 AliasedLinesVS();
- PixelShader = compile ps_2_0 DirectSimplePS();
- }
-}
-
diff --git a/src/gui/painting/qpaintengine_d3d.qrc b/src/gui/painting/qpaintengine_d3d.qrc
deleted file mode 100644
index c106f2b..0000000
--- a/src/gui/painting/qpaintengine_d3d.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>qpaintengine_d3d.fx</file>
-</qresource>
-</RCC>
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 847904b..c986e99 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -509,16 +509,20 @@ bool QRasterPaintEngine::begin(QPaintDevice *device)
if (d->mono_surface)
d->glyphCacheType = QFontEngineGlyphCache::Raster_Mono;
-#ifdef Q_WS_WIN
- else if (qt_cleartype_enabled) {
+#if defined(Q_WS_WIN)
+ else if (qt_cleartype_enabled)
+#elif defined (Q_WS_MAC)
+ else if (true)
+#else
+ else if (false)
+#endif
+ {
QImage::Format format = static_cast<QImage *>(d->device)->format();
if (format == QImage::Format_ARGB32_Premultiplied || format == QImage::Format_RGB32)
d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask;
else
d->glyphCacheType = QFontEngineGlyphCache::Raster_A8;
- }
-#endif
- else
+ } else
d->glyphCacheType = QFontEngineGlyphCache::Raster_A8;
setActive(true);
@@ -618,22 +622,22 @@ void QRasterPaintEngine::updateMatrix(const QTransform &matrix)
d->isPlain45DegreeRotation = false;
if (txop >= QTransform::TxRotate) {
d->isPlain45DegreeRotation =
- (qFuzzyCompare(matrix.m11() + 1, qreal(1))
- && qFuzzyCompare(matrix.m12(), qreal(1))
- && qFuzzyCompare(matrix.m21(), qreal(-1))
- && qFuzzyCompare(matrix.m22() + 1, qreal(1))
+ (qFuzzyIsNull(matrix.m11())
+ && qFuzzyIsNull(matrix.m12() - qreal(1))
+ && qFuzzyIsNull(matrix.m21() + qreal(1))
+ && qFuzzyIsNull(matrix.m22())
)
||
- (qFuzzyCompare(matrix.m11(), qreal(-1))
- && qFuzzyCompare(matrix.m12() + 1, qreal(1))
- && qFuzzyCompare(matrix.m21() + 1, qreal(1))
- && qFuzzyCompare(matrix.m22(), qreal(-1))
+ (qFuzzyIsNull(matrix.m11() + qreal(1))
+ && qFuzzyIsNull(matrix.m12())
+ && qFuzzyIsNull(matrix.m21())
+ && qFuzzyIsNull(matrix.m22() + qreal(1))
)
||
- (qFuzzyCompare(matrix.m11() + 1, qreal(1))
- && qFuzzyCompare(matrix.m12(), qreal(-1))
- && qFuzzyCompare(matrix.m21(), qreal(1))
- && qFuzzyCompare(matrix.m22() + 1, qreal(1))
+ (qFuzzyIsNull(matrix.m11())
+ && qFuzzyIsNull(matrix.m12() + qreal(1))
+ && qFuzzyIsNull(matrix.m21() - qreal(1))
+ && qFuzzyIsNull(matrix.m22())
)
;
}
@@ -3201,7 +3205,7 @@ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte
// ### cases we should delegate painting to the font engine
// ### directly...
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
QFontEngine::Type fontEngineType = ti.fontEngine->type();
// qDebug() << "type" << fontEngineType << s->matrix.type();
if ((fontEngineType == QFontEngine::Win && !((QFontEngineWin *) ti.fontEngine)->ttf && s->matrix.type() > QTransform::TxTranslate)
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index cc48d24..4744f14 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -6082,22 +6082,22 @@ void QPainter::drawTextItem(const QPointF &p, const QTextItem &_ti)
const QTransform &m = d->state->matrix;
if (d->state->matrix.type() < QTransform::TxShear) {
bool isPlain90DegreeRotation =
- (qFuzzyCompare(m.m11() + 1, qreal(1))
- && qFuzzyCompare(m.m12(), qreal(1))
- && qFuzzyCompare(m.m21(), qreal(-1))
- && qFuzzyCompare(m.m22() + 1, qreal(1))
+ (qFuzzyIsNull(m.m11())
+ && qFuzzyIsNull(m.m12() - qreal(1))
+ && qFuzzyIsNull(m.m21() + qreal(1))
+ && qFuzzyIsNull(m.m22())
)
||
- (qFuzzyCompare(m.m11(), qreal(-1))
- && qFuzzyCompare(m.m12() + 1, qreal(1))
- && qFuzzyCompare(m.m21() + 1, qreal(1))
- && qFuzzyCompare(m.m22(), qreal(-1))
+ (qFuzzyIsNull(m.m11() + qreal(1))
+ && qFuzzyIsNull(m.m12())
+ && qFuzzyIsNull(m.m21())
+ && qFuzzyIsNull(m.m22() + qreal(1))
)
||
- (qFuzzyCompare(m.m11() + 1, qreal(1))
- && qFuzzyCompare(m.m12(), qreal(-1))
- && qFuzzyCompare(m.m21(), qreal(1))
- && qFuzzyCompare(m.m22() + 1, qreal(1))
+ (qFuzzyIsNull(m.m11())
+ && qFuzzyIsNull(m.m12() + qreal(1))
+ && qFuzzyIsNull(m.m21() - qreal(1))
+ && qFuzzyIsNull(m.m22())
)
;
aa = !isPlain90DegreeRotation;
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index e1f5eea..9b10f3c 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -1299,10 +1299,10 @@ static QRectF qt_painterpath_bezier_extrema(const QBezier &b)
qreal bx = QT_BEZIER_B(b, x);
qreal cx = QT_BEZIER_C(b, x);
// specialcase quadratic curves to avoid div by zero
- if (qFuzzyCompare(ax + 1, 1)) {
+ if (qFuzzyIsNull(ax)) {
// linear curves are covered by initialization.
- if (!qFuzzyCompare(bx + 1, 1)) {
+ if (!qFuzzyIsNull(bx)) {
qreal t = -cx / bx;
QT_BEZIER_CHECK_T(b, t);
}
@@ -1329,10 +1329,10 @@ static QRectF qt_painterpath_bezier_extrema(const QBezier &b)
qreal cy = QT_BEZIER_C(b, y);
// specialcase quadratic curves to avoid div by zero
- if (qFuzzyCompare(ay + 1, 1)) {
+ if (qFuzzyIsNull(ay)) {
// linear curves are covered by initialization.
- if (!qFuzzyCompare(by + 1, 1)) {
+ if (!qFuzzyIsNull(by)) {
qreal t = -cy / by;
QT_BEZIER_CHECK_T(b, t);
}
@@ -2000,7 +2000,63 @@ bool QPainterPath::intersects(const QRectF &rect) const
return false;
}
+/*!
+ Translates all elements in the path by (\a{dx}, \a{dy}).
+
+ \since 4.6
+ \sa translated()
+*/
+void QPainterPath::translate(qreal dx, qreal dy)
+{
+ if (!d_ptr || (dx == 0 && dy == 0))
+ return;
+
+ int elementsLeft = d_ptr->elements.size();
+ if (elementsLeft <= 0)
+ return;
+
+ detach();
+ QPainterPath::Element *element = d_func()->elements.data();
+ Q_ASSERT(element);
+ while (elementsLeft--) {
+ element->x += dx;
+ element->y += dy;
+ ++element;
+ }
+}
+
+/*!
+ \fn void QPainterPath::translate(const QPointF &offset)
+ \overload
+ \since 4.6
+ Translates all elements in the path by the given \a offset.
+
+ \sa translated()
+*/
+
+/*!
+ Returns a copy of the path that is translated by (\a{dx}, \a{dy}).
+
+ \since 4.6
+ \sa translate()
+*/
+QPainterPath QPainterPath::translated(qreal dx, qreal dy) const
+{
+ QPainterPath copy(*this);
+ copy.translate(dx, dy);
+ return copy;
+}
+
+/*!
+ \fn void QPainterPath::translated(const QPointF &offset)
+ \overload
+ \since 4.6
+
+ Returns a copy of the path that is translated by the given \a offset.
+
+ \sa translate()
+*/
/*!
\fn bool QPainterPath::contains(const QRectF &rectangle) const
@@ -2867,7 +2923,7 @@ qreal QPainterPath::angleAtPercent(qreal t) const
return QLineF(0, 0, m1, m2).angle();
}
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#pragma warning( disable : 4056 4756 )
#endif
diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h
index 6cd2af8..e343a28 100644
--- a/src/gui/painting/qpainterpath.h
+++ b/src/gui/painting/qpainterpath.h
@@ -147,6 +147,12 @@ public:
bool contains(const QRectF &rect) const;
bool intersects(const QRectF &rect) const;
+ void translate(qreal dx, qreal dy);
+ inline void translate(const QPointF &offset);
+
+ QPainterPath translated(qreal dx, qreal dy) const;
+ inline QPainterPath translated(const QPointF &offset) const;
+
QRectF boundingRect() const;
QRectF controlPointRect() const;
@@ -365,6 +371,12 @@ inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QStrin
addText(QPointF(x, y), f, text);
}
+inline void QPainterPath::translate(const QPointF &offset)
+{ translate(offset.x(), offset.y()); }
+
+inline QPainterPath QPainterPath::translated(const QPointF &offset) const
+{ return translated(offset.x(), offset.y()); }
+
inline bool QPainterPath::isEmpty() const
{
return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement);
diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h
index 29c48df..6fb439d 100644
--- a/src/gui/painting/qpainterpath_p.h
+++ b/src/gui/painting/qpainterpath_p.h
@@ -124,7 +124,7 @@ private:
Q_DISABLE_COPY(QVectorPathConverter)
};
-class Q_GUI_EXPORT QPainterPathData : public QPainterPathPrivate
+class QPainterPathData : public QPainterPathPrivate
{
public:
QPainterPathData() :
diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp
index 297cdd3..9ef3eb7 100644
--- a/src/gui/painting/qpathclipper.cpp
+++ b/src/gui/painting/qpathclipper.cpp
@@ -138,11 +138,11 @@ bool QIntersectionFinder::linesIntersect(const QLineF &a, const QLineF &b) const
const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x();
- if (qFuzzyCompare(par + 1, 1)) {
+ if (qFuzzyIsNull(par)) {
const QPointF normal(-pDelta.y(), pDelta.x());
// coinciding?
- if (qFuzzyCompare(dot(normal, q1 - p1) + 1, 1)) {
+ if (qFuzzyIsNull(dot(normal, q1 - p1))) {
const qreal dp = dot(pDelta, pDelta);
const qreal tq1 = dot(pDelta, q1 - p1);
@@ -202,13 +202,13 @@ void QIntersectionFinder::intersectBeziers(const QBezier &one, const QBezier &tw
qreal alpha_q = t.at(i).second;
QPointF pt;
- if (qFuzzyCompare(alpha_p + 1, 1)) {
+ if (qFuzzyIsNull(alpha_p)) {
pt = one.pt1();
- } else if (qFuzzyCompare(alpha_p, 1)) {
+ } else if (qFuzzyIsNull(alpha_p - 1)) {
pt = one.pt4();
- } else if (qFuzzyCompare(alpha_q + 1, 1)) {
+ } else if (qFuzzyIsNull(alpha_q)) {
pt = two.pt1();
- } else if (qFuzzyCompare(alpha_q, 1)) {
+ } else if (qFuzzyIsNull(alpha_q - 1)) {
pt = two.pt4();
} else {
pt = one.pointAt(alpha_p);
@@ -250,11 +250,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData
const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x();
- if (qFuzzyCompare(par + 1, 1)) {
+ if (qFuzzyIsNull(par)) {
const QPointF normal(-pDelta.y(), pDelta.x());
// coinciding?
- if (qFuzzyCompare(dot(normal, q1 - p1) + 1, 1)) {
+ if (qFuzzyIsNull(dot(normal, q1 - p1))) {
const qreal invDp = 1 / dot(pDelta, pDelta);
const qreal tq1 = dot(pDelta, q1 - p1) * invDp;
@@ -315,11 +315,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData
if (tp<0 || tp>1 || tq<0 || tq>1)
return;
- const bool p_zero = qFuzzyCompare(tp + 1, 1);
- const bool p_one = qFuzzyCompare(tp, 1);
+ const bool p_zero = qFuzzyIsNull(tp);
+ const bool p_one = qFuzzyIsNull(tp - 1);
- const bool q_zero = qFuzzyCompare(tq + 1, 1);
- const bool q_one = qFuzzyCompare(tq, 1);
+ const bool q_zero = qFuzzyIsNull(tq);
+ const bool q_one = qFuzzyIsNull(tq - 1);
if ((q_zero || q_one) && (p_zero || p_one))
return;
@@ -922,7 +922,7 @@ qreal QWingedEdge::delta(int vertex, int a, int b) const
qreal result = b_angle - a_angle;
- if (qFuzzyCompare(result + 1, 1) || qFuzzyCompare(result, 128))
+ if (qFuzzyIsNull(result) || qFuzzyCompare(result, 128))
return 0;
if (result < 0)
@@ -951,7 +951,7 @@ static inline QPointF tangentAt(const QWingedEdge &list, int vi, int ei)
if (ep->bezier) {
normal = ep->bezier->derivedAt(t);
- if (qFuzzyCompare(normal.x() + 1, 1) && qFuzzyCompare(normal.y() + 1, 1))
+ if (qFuzzyIsNull(normal.x()) && qFuzzyIsNull(normal.y()))
normal = ep->bezier->secondDerivedAt(t);
} else {
const QPointF a = *list.vertex(ep->first);
@@ -1080,7 +1080,7 @@ QWingedEdge::TraversalStatus QWingedEdge::findInsertStatus(int vi, int ei) const
qDebug() << "Delta to edge" << status.edge << d2 << ", angles: " << op->angle << op->invAngle;
#endif
- if (!(qFuzzyCompare(d2 + 1, 1) && isLeftOf(*this, vi, status.edge, ei))
+ if (!(qFuzzyIsNull(d2) && isLeftOf(*this, vi, status.edge, ei))
&& (d2 < d || (qFuzzyCompare(d2, d) && isLeftOf(*this, vi, status.edge, position)))) {
position = status.edge;
d = d2;
@@ -1232,10 +1232,10 @@ int QWingedEdge::addEdge(int fi, int si, const QBezier *bezier, qreal t0, qreal
QPointF aTangent = bezier->derivedAt(t0);
QPointF bTangent = -bezier->derivedAt(t1);
- if (qFuzzyCompare(aTangent.x() + 1, 1) && qFuzzyCompare(aTangent.y() + 1, 1))
+ if (qFuzzyIsNull(aTangent.x()) && qFuzzyIsNull(aTangent.y()))
aTangent = bezier->secondDerivedAt(t0);
- if (qFuzzyCompare(bTangent.x() + 1, 1) && qFuzzyCompare(bTangent.y() + 1, 1))
+ if (qFuzzyIsNull(bTangent.x()) && qFuzzyIsNull(bTangent.y()))
bTangent = bezier->secondDerivedAt(t1);
ep->angle = computeAngle(aTangent);
@@ -1400,7 +1400,7 @@ static void addLineTo(QPainterPath &path, const QPointF &point)
const QPointF p(-d1.y(), d1.x());
- if (qFuzzyCompare(dot(p, d2) + 1, 1)) {
+ if (qFuzzyIsNull(dot(p, d2))) {
path.setElementPositionAt(elementCount - 1, point.x(), point.y());
return;
}
diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp
index 87dae0f..769c095 100644
--- a/src/gui/painting/qpolygon.cpp
+++ b/src/gui/painting/qpolygon.cpp
@@ -208,10 +208,15 @@ QPolygon::QPolygon(int nPoints, const int *points)
/*!
Translates all points in the polygon by (\a{dx}, \a{dy}).
+
+ \sa translated()
*/
void QPolygon::translate(int dx, int dy)
{
+ if (dx == 0 && dy == 0)
+ return;
+
register QPoint *p = data();
register int i = size();
QPoint pt(dx, dy);
@@ -226,8 +231,32 @@ void QPolygon::translate(int dx, int dy)
\overload
Translates all points in the polygon by the given \a offset.
+
+ \sa translated()
+*/
+
+/*!
+ Returns a copy of the polygon that is translated by (\a{dx}, \a{dy}).
+
+ \since 4.6
+ \sa translate()
*/
+QPolygon QPolygon::translated(int dx, int dy) const
+{
+ QPolygon copy(*this);
+ copy.translate(dx, dy);
+ return copy;
+}
+
+/*!
+ \fn void QPolygon::translated(const QPoint &offset) const
+ \overload
+ \since 4.6
+
+ Returns a copy of the polygon that is translated by the given \a offset.
+ \sa translate()
+*/
/*!
Extracts the coordinates of the point at the given \a index to
@@ -565,10 +594,15 @@ QPolygonF::QPolygonF(const QPolygon &a)
/*!
Translate all points in the polygon by the given \a offset.
+
+ \sa translated()
*/
void QPolygonF::translate(const QPointF &offset)
{
+ if (offset.isNull())
+ return;
+
register QPointF *p = data();
register int i = size();
while (i--) {
@@ -582,6 +616,31 @@ void QPolygonF::translate(const QPointF &offset)
\overload
Translates all points in the polygon by (\a{dx}, \a{dy}).
+
+ \sa translated()
+*/
+
+/*!
+ Returns a copy of the polygon that is translated by the given \a offset.
+
+ \since 4.6
+ \sa translate()
+*/
+QPolygonF QPolygonF::translated(const QPointF &offset) const
+{
+ QPolygonF copy(*this);
+ copy.translate(offset);
+ return copy;
+}
+
+/*!
+ \fn void QPolygonF::translated(qreal dx, qreal dy) const
+ \overload
+ \since 4.6
+
+ Returns a copy of the polygon that is translated by (\a{dx}, \a{dy}).
+
+ \sa translate()
*/
/*!
diff --git a/src/gui/painting/qpolygon.h b/src/gui/painting/qpolygon.h
index e5e0bd1..c52f48c 100644
--- a/src/gui/painting/qpolygon.h
+++ b/src/gui/painting/qpolygon.h
@@ -71,6 +71,10 @@ public:
void translate(int dx, int dy);
void translate(const QPoint &offset);
+
+ QPolygon translated(int dx, int dy) const;
+ inline QPolygon translated(const QPoint &offset) const;
+
QRect boundingRect() const;
void point(int i, int *x, int *y) const;
@@ -120,6 +124,9 @@ inline QPoint QPolygon::point(int index) const
inline void QPolygon::translate(const QPoint &offset)
{ translate(offset.x(), offset.y()); }
+inline QPolygon QPolygon::translated(const QPoint &offset) const
+{ return translated(offset.x(), offset.y()); }
+
class QRectF;
class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
@@ -136,6 +143,9 @@ public:
inline void translate(qreal dx, qreal dy);
void translate(const QPointF &offset);
+ inline QPolygonF translated(qreal dx, qreal dy) const;
+ QPolygonF translated(const QPointF &offset) const;
+
QPolygon toPolygon() const;
bool isClosed() const { return !isEmpty() && first() == last(); }
@@ -166,6 +176,9 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
inline void QPolygonF::translate(qreal dx, qreal dy)
{ translate(QPointF(dx, dy)); }
+inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
+{ return translated(QPointF(dx, dy)); }
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/gui/painting/qprinter.cpp b/src/gui/painting/qprinter.cpp
index 5090b3a..154d90c 100644
--- a/src/gui/painting/qprinter.cpp
+++ b/src/gui/painting/qprinter.cpp
@@ -834,11 +834,15 @@ void QPrinter::setPrinterName(const QString &name)
#endif
QList<QPrinterInfo> prnList = QPrinterInfo::availablePrinters();
- d->validPrinter = false;
- for (int i = 0; i < prnList.size(); ++i) {
- if (prnList[i].printerName() == name) {
- d->validPrinter = true;
- break;
+ if (name.isEmpty()) {
+ d->validPrinter = d->outputFormat == QPrinter::PdfFormat || d->outputFormat == QPrinter::PostScriptFormat;
+ } else {
+ d->validPrinter = false;
+ for (int i = 0; i < prnList.size(); ++i) {
+ if (prnList[i].printerName() == name) {
+ d->validPrinter = true;
+ break;
+ }
}
}
diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp
index b894c62..5fffc72 100644
--- a/src/gui/painting/qstroker.cpp
+++ b/src/gui/painting/qstroker.cpp
@@ -763,7 +763,7 @@ template <class Iterator> bool qt_stroke_side(Iterator *it,
qreal qt_t_for_arc_angle(qreal angle)
{
- if (qFuzzyCompare(angle + 1, qreal(1)))
+ if (qFuzzyIsNull(angle))
return 0;
if (qFuzzyCompare(angle, qreal(90)))
@@ -904,13 +904,13 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt
}
// avoid empty start segment
- if (qFuzzyCompare(startT, qreal(1))) {
+ if (qFuzzyIsNull(startT - qreal(1))) {
startT = 0;
startSegment += delta;
}
// avoid empty end segment
- if (qFuzzyCompare(endT + 1, qreal(1))) {
+ if (qFuzzyIsNull(endT)) {
endT = 1;
endSegment -= delta;
}
@@ -918,8 +918,8 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt
startT = qt_t_for_arc_angle(startT * 90);
endT = qt_t_for_arc_angle(endT * 90);
- const bool splitAtStart = !qFuzzyCompare(startT + 1, qreal(1));
- const bool splitAtEnd = !qFuzzyCompare(endT, qreal(1));
+ const bool splitAtStart = !qFuzzyIsNull(startT);
+ const bool splitAtEnd = !qFuzzyIsNull(endT - qreal(1));
const int end = endSegment + delta;
@@ -1018,7 +1018,7 @@ void QDashStroker::processCurrentSubpath()
sumLength += dashes[i];
}
- if (qFuzzyCompare(sumLength + 1, qreal(1)))
+ if (qFuzzyIsNull(sumLength))
return;
Q_ASSERT(dashCount > 0);
diff --git a/src/gui/painting/qstroker_p.h b/src/gui/painting/qstroker_p.h
index 72141aa..ca1f270 100644
--- a/src/gui/painting/qstroker_p.h
+++ b/src/gui/painting/qstroker_p.h
@@ -179,7 +179,7 @@ private:
};
-class Q_GUI_EXPORT QStroker : public QStrokerOps
+class QStroker : public QStrokerOps
{
public:
diff --git a/src/gui/painting/qtessellator.cpp b/src/gui/painting/qtessellator.cpp
index e02f02d..ce5ab74 100644
--- a/src/gui/painting/qtessellator.cpp
+++ b/src/gui/painting/qtessellator.cpp
@@ -1436,7 +1436,7 @@ void QTessellator::tessellateRect(const QPointF &a_, const QPointF &b_, qreal wi
QPointF perp(pb.y() - pa.y(), pa.x() - pb.x());
qreal length = qSqrt(perp.x() * perp.x() + perp.y() * perp.y());
- if (qFuzzyCompare(length + 1, static_cast<qreal>(1)))
+ if (qFuzzyIsNull(length))
return;
// need the half of the width
diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp
index cec2d16..ec8c1dc 100644
--- a/src/gui/painting/qtransform.cpp
+++ b/src/gui/painting/qtransform.cpp
@@ -238,11 +238,11 @@ QT_BEGIN_NAMESPACE
\sa reset()
*/
QTransform::QTransform()
- : m_13(0), m_23(0), m_33(1)
+ : affine(true)
+ , m_13(0), m_23(0), m_33(1)
, m_type(TxNone)
, m_dirty(TxNone)
{
-
}
/*!
@@ -256,12 +256,11 @@ QTransform::QTransform()
QTransform::QTransform(qreal h11, qreal h12, qreal h13,
qreal h21, qreal h22, qreal h23,
qreal h31, qreal h32, qreal h33)
- : affine(h11, h12, h21, h22, h31, h32),
- m_13(h13), m_23(h23), m_33(h33)
+ : affine(h11, h12, h21, h22, h31, h32, true)
+ , m_13(h13), m_23(h23), m_33(h33)
, m_type(TxNone)
, m_dirty(TxProject)
{
-
}
/*!
@@ -273,12 +272,11 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h13,
*/
QTransform::QTransform(qreal h11, qreal h12, qreal h21,
qreal h22, qreal dx, qreal dy)
- : affine(h11, h12, h21, h22, dx, dy),
- m_13(0), m_23(0), m_33(1)
+ : affine(h11, h12, h21, h22, dx, dy, true)
+ , m_13(0), m_23(0), m_33(1)
, m_type(TxNone)
, m_dirty(TxShear)
{
-
}
/*!
@@ -289,12 +287,11 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h21,
and 1 respectively.
*/
QTransform::QTransform(const QMatrix &mtx)
- : affine(mtx),
+ : affine(mtx._m11, mtx._m12, mtx._m21, mtx._m22, mtx._dx, mtx._dy, true),
m_13(0), m_23(0), m_33(1)
, m_type(TxNone)
, m_dirty(TxShear)
{
-
}
/*!
@@ -317,7 +314,7 @@ QTransform QTransform::adjoint() const
return QTransform(h11, h12, h13,
h21, h22, h23,
- h31, h32, h33);
+ h31, h32, h33, true);
}
/*!
@@ -327,7 +324,7 @@ QTransform QTransform::transposed() const
{
QTransform t(affine._m11, affine._m21, affine._dx,
affine._m12, affine._m22, affine._dy,
- m_13, m_23, m_33);
+ m_13, m_23, m_33, true);
t.m_type = m_type;
t.m_dirty = m_dirty;
return t;
@@ -345,11 +342,10 @@ QTransform QTransform::transposed() const
*/
QTransform QTransform::inverted(bool *invertible) const
{
- QTransform invert;
+ QTransform invert(true);
bool inv = true;
- qreal det;
- switch(type()) {
+ switch(inline_type()) {
case TxNone:
break;
case TxTranslate:
@@ -357,11 +353,11 @@ QTransform QTransform::inverted(bool *invertible) const
invert.affine._dy = -affine._dy;
break;
case TxScale:
- inv = !qFuzzyCompare(affine._m11 + 1, 1);
- inv &= !qFuzzyCompare(affine._m22 + 1, 1);
+ inv = !qFuzzyIsNull(affine._m11);
+ inv &= !qFuzzyIsNull(affine._m22);
if (inv) {
- invert.affine._m11 = 1 / affine._m11;
- invert.affine._m22 = 1 / affine._m22;
+ invert.affine._m11 = 1. / affine._m11;
+ invert.affine._m22 = 1. / affine._m22;
invert.affine._dx = -affine._dx * invert.affine._m11;
invert.affine._dy = -affine._dy * invert.affine._m22;
}
@@ -372,8 +368,8 @@ QTransform QTransform::inverted(bool *invertible) const
break;
default:
// general case
- det = determinant();
- inv = !qFuzzyCompare(det + 1, 1);
+ qreal det = determinant();
+ inv = !qFuzzyIsNull(det);
if (inv)
invert = adjoint() / det;
break;
@@ -397,12 +393,12 @@ QTransform QTransform::inverted(bool *invertible) const
\sa setMatrix()
*/
-QTransform & QTransform::translate(qreal dx, qreal dy)
+QTransform &QTransform::translate(qreal dx, qreal dy)
{
if (dx == 0 && dy == 0)
return *this;
- switch(type()) {
+ switch(inline_type()) {
case TxNone:
affine._dx = dx;
affine._dy = dy;
@@ -437,7 +433,7 @@ QTransform & QTransform::translate(qreal dx, qreal dy)
*/
QTransform QTransform::fromTranslate(qreal dx, qreal dy)
{
- QTransform transform(1, 0, 0, 1, dx, dy);
+ QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true);
if (dx == 0 && dy == 0)
transform.m_dirty = TxNone;
else
@@ -456,7 +452,7 @@ QTransform & QTransform::scale(qreal sx, qreal sy)
if (sx == 1 && sy == 1)
return *this;
- switch(type()) {
+ switch(inline_type()) {
case TxNone:
case TxTranslate:
affine._m11 = sx;
@@ -489,8 +485,8 @@ QTransform & QTransform::scale(qreal sx, qreal sy)
*/
QTransform QTransform::fromScale(qreal sx, qreal sy)
{
- QTransform transform(sx, 0, 0, sy, 0, 0);
- if (sx == 1 && sy == 1)
+ QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true);
+ if (sx == 1. && sy == 1.)
transform.m_dirty = TxNone;
else
transform.m_dirty = TxScale;
@@ -505,7 +501,7 @@ QTransform QTransform::fromScale(qreal sx, qreal sy)
*/
QTransform & QTransform::shear(qreal sh, qreal sv)
{
- switch(type()) {
+ switch(inline_type()) {
case TxNone:
case TxTranslate:
affine._m12 = sv;
@@ -574,7 +570,7 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
}
if (axis == Qt::ZAxis) {
- switch(type()) {
+ switch(inline_type()) {
case TxNone:
case TxTranslate:
affine._m11 = cosa;
@@ -646,7 +642,7 @@ QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
qreal cosa = qCos(a);
if (axis == Qt::ZAxis) {
- switch(type()) {
+ switch(inline_type()) {
case TxNone:
case TxTranslate:
affine._m11 = cosa;
@@ -730,11 +726,11 @@ bool QTransform::operator!=(const QTransform &o) const
*/
QTransform & QTransform::operator*=(const QTransform &o)
{
- const TransformationType otherType = o.type();
+ const TransformationType otherType = o.inline_type();
if (otherType == TxNone)
return *this;
- const TransformationType thisType = type();
+ const TransformationType thisType = inline_type();
if (thisType == TxNone)
return operator=(o);
@@ -812,9 +808,77 @@ QTransform & QTransform::operator*=(const QTransform &o)
*/
QTransform QTransform::operator*(const QTransform &m) const
{
- QTransform result = *this;
- result *= m;
- return result;
+ const TransformationType otherType = m.inline_type();
+ if (otherType == TxNone)
+ return *this;
+
+ const TransformationType thisType = inline_type();
+ if (thisType == TxNone)
+ return m;
+
+ QTransform t(true);
+ TransformationType type = qMax(thisType, otherType);
+ switch(type) {
+ case TxNone:
+ break;
+ case TxTranslate:
+ t.affine._dx = affine._dx + m.affine._dx;
+ t.affine._dy += affine._dy + m.affine._dy;
+ break;
+ case TxScale:
+ {
+ qreal m11 = affine._m11*m.affine._m11;
+ qreal m22 = affine._m22*m.affine._m22;
+
+ qreal m31 = affine._dx*m.affine._m11 + m.affine._dx;
+ qreal m32 = affine._dy*m.affine._m22 + m.affine._dy;
+
+ t.affine._m11 = m11;
+ t.affine._m22 = m22;
+ t.affine._dx = m31; t.affine._dy = m32;
+ break;
+ }
+ case TxRotate:
+ case TxShear:
+ {
+ qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21;
+ qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22;
+
+ qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21;
+ qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22;
+
+ qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m.affine._dx;
+ qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m.affine._dy;
+
+ t.affine._m11 = m11; t.affine._m12 = m12;
+ t.affine._m21 = m21; t.affine._m22 = m22;
+ t.affine._dx = m31; t.affine._dy = m32;
+ break;
+ }
+ case TxProject:
+ {
+ qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21 + m_13*m.affine._dx;
+ qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22 + m_13*m.affine._dy;
+ qreal m13 = affine._m11*m.m_13 + affine._m12*m.m_23 + m_13*m.m_33;
+
+ qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21 + m_23*m.affine._dx;
+ qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22 + m_23*m.affine._dy;
+ qreal m23 = affine._m21*m.m_13 + affine._m22*m.m_23 + m_23*m.m_33;
+
+ qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m_33*m.affine._dx;
+ qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m_33*m.affine._dy;
+ qreal m33 = affine._dx*m.m_13 + affine._dy*m.m_23 + m_33*m.m_33;
+
+ t.affine._m11 = m11; t.affine._m12 = m12; t.m_13 = m13;
+ t.affine._m21 = m21; t.affine._m22 = m22; t.m_23 = m23;
+ t.affine._dx = m31; t.affine._dy = m32; t.m_33 = m33;
+ }
+ }
+
+ t.m_dirty = type;
+ t.m_type = type;
+
+ return t;
}
/*!
@@ -976,7 +1040,7 @@ QPoint QTransform::map(const QPoint &p) const
qreal x = 0, y = 0;
- TransformationType t = type();
+ TransformationType t = inline_type();
switch(t) {
case TxNone:
x = fx;
@@ -1027,7 +1091,7 @@ QPointF QTransform::map(const QPointF &p) const
qreal x = 0, y = 0;
- TransformationType t = type();
+ TransformationType t = inline_type();
switch(t) {
case TxNone:
x = fx;
@@ -1098,7 +1162,7 @@ QLine QTransform::map(const QLine &l) const
qreal x1 = 0, y1 = 0, x2 = 0, y2 = 0;
- TransformationType t = type();
+ TransformationType t = inline_type();
switch(t) {
case TxNone:
x1 = fx1;
@@ -1157,7 +1221,7 @@ QLineF QTransform::map(const QLineF &l) const
qreal x1 = 0, y1 = 0, x2 = 0, y2 = 0;
- TransformationType t = type();
+ TransformationType t = inline_type();
switch(t) {
case TxNone:
x1 = fx1;
@@ -1245,7 +1309,10 @@ static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &pol
*/
QPolygonF QTransform::map(const QPolygonF &a) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
+ if (t <= TxTranslate)
+ return a.translated(affine._dx, affine._dy);
+
if (t >= QTransform::TxProject)
return mapProjective(*this, a);
@@ -1272,7 +1339,10 @@ QPolygonF QTransform::map(const QPolygonF &a) const
*/
QPolygon QTransform::map(const QPolygon &a) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
+ if (t <= TxTranslate)
+ return a.translated(qRound(affine._dx), qRound(affine._dy));
+
if (t >= QTransform::TxProject)
return mapProjective(*this, QPolygonF(a)).toPolygon();
@@ -1314,7 +1384,7 @@ extern QPainterPath qt_regionToPath(const QRegion &region);
*/
QRegion QTransform::map(const QRegion &r) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
if (t == TxNone)
return r;
@@ -1341,7 +1411,7 @@ struct QHomogeneousCoordinate
QHomogeneousCoordinate(qreal x_, qreal y_, qreal w_) : x(x_), y(y_), w(w_) {}
const QPointF toPoint() const {
- qreal iw = 1 / w;
+ qreal iw = 1. / w;
return QPointF(x * iw, y * iw);
}
};
@@ -1481,7 +1551,7 @@ static QPainterPath mapProjective(const QTransform &transform, const QPainterPat
*/
QPainterPath QTransform::map(const QPainterPath &path) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
if (t == TxNone || path.isEmpty())
return path;
@@ -1489,15 +1559,11 @@ QPainterPath QTransform::map(const QPainterPath &path) const
return mapProjective(*this, path);
QPainterPath copy = path;
- copy.detach();
if (t == TxTranslate) {
- for (int i=0; i<path.elementCount(); ++i) {
- QPainterPath::Element &e = copy.d_ptr->elements[i];
- e.x += affine._dx;
- e.y += affine._dy;
- }
+ copy.translate(affine._dx, affine._dy);
} else {
+ copy.detach();
// Full xform
for (int i=0; i<path.elementCount(); ++i) {
QPainterPath::Element &e = copy.d_ptr->elements[i];
@@ -1530,7 +1596,7 @@ QPainterPath QTransform::map(const QPainterPath &path) const
*/
QPolygon QTransform::mapToPolygon(const QRect &rect) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
QPolygon a(4);
qreal x[4] = { 0, 0, 0, 0 }, y[4] = { 0, 0, 0, 0 };
@@ -1704,7 +1770,10 @@ void QTransform::setMatrix(qreal m11, qreal m12, qreal m13,
QRect QTransform::mapRect(const QRect &rect) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
+ if (t <= TxTranslate)
+ return rect.translated(qRound(affine._dx), qRound(affine._dy));
+
if (t <= TxScale) {
int x = qRound(affine._m11*rect.x() + affine._dx);
int y = qRound(affine._m22*rect.y() + affine._dy);
@@ -1771,7 +1840,10 @@ QRect QTransform::mapRect(const QRect &rect) const
*/
QRectF QTransform::mapRect(const QRectF &rect) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
+ if (t <= TxTranslate)
+ return rect.translated(affine._dx, affine._dy);
+
if (t <= TxScale) {
qreal x = affine._m11*rect.x() + affine._dx;
qreal y = affine._m22*rect.y() + affine._dy;
@@ -1842,7 +1914,7 @@ QRectF QTransform::mapRect(const QRectF &rect) const
*/
void QTransform::map(qreal x, qreal y, qreal *tx, qreal *ty) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
MAP(x, y, *tx, *ty);
}
@@ -1856,7 +1928,7 @@ void QTransform::map(qreal x, qreal y, qreal *tx, qreal *ty) const
*/
void QTransform::map(int x, int y, int *tx, int *ty) const
{
- TransformationType t = type();
+ TransformationType t = inline_type();
qreal fx = 0, fy = 0;
MAP(x, y, fx, fy);
*tx = qRound(fx);
@@ -1885,25 +1957,41 @@ const QMatrix &QTransform::toAffine() const
*/
QTransform::TransformationType QTransform::type() const
{
- if (m_dirty >= m_type) {
- if (m_dirty > TxShear && (!qFuzzyCompare(m_13 + 1, 1) || !qFuzzyCompare(m_23 + 1, 1) || !qFuzzyCompare(m_33, 1)))
+ if(m_dirty == TxNone || m_dirty < m_type)
+ return static_cast<TransformationType>(m_type);
+
+ switch (static_cast<TransformationType>(m_dirty)) {
+ case TxProject:
+ if (!qFuzzyIsNull(m_13) || !qFuzzyIsNull(m_23) || !qFuzzyIsNull(m_33 - 1)) {
m_type = TxProject;
- else if (m_dirty > TxScale && (!qFuzzyCompare(affine._m12 + 1, 1) || !qFuzzyCompare(affine._m21 + 1, 1))) {
+ break;
+ }
+ case TxShear:
+ case TxRotate:
+ if (!qFuzzyIsNull(affine._m12) || !qFuzzyIsNull(affine._m21)) {
const qreal dot = affine._m11 * affine._m12 + affine._m21 * affine._m22;
- if (qFuzzyCompare(dot + 1, 1))
+ if (qFuzzyIsNull(dot))
m_type = TxRotate;
else
m_type = TxShear;
- } else if (m_dirty > TxTranslate && (!qFuzzyCompare(affine._m11, 1) || !qFuzzyCompare(affine._m22, 1)))
+ break;
+ }
+ case TxScale:
+ if (!qFuzzyIsNull(affine._m11 - 1) || !qFuzzyIsNull(affine._m22 - 1)) {
m_type = TxScale;
- else if (m_dirty > TxNone && (!qFuzzyCompare(affine._dx + 1, 1) || !qFuzzyCompare(affine._dy + 1, 1)))
+ break;
+ }
+ case TxTranslate:
+ if (!qFuzzyIsNull(affine._dx) || !qFuzzyIsNull(affine._dy)) {
m_type = TxTranslate;
- else
- m_type = TxNone;
-
- m_dirty = TxNone;
+ break;
+ }
+ case TxNone:
+ m_type = TxNone;
+ break;
}
+ m_dirty = TxNone;
return static_cast<TransformationType>(m_type);
}
diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h
index c76409b..aac7c31 100644
--- a/src/gui/painting/qtransform.h
+++ b/src/gui/painting/qtransform.h
@@ -159,6 +159,19 @@ public:
static QTransform fromScale(qreal dx, qreal dy);
private:
+ inline QTransform(qreal h11, qreal h12, qreal h13,
+ qreal h21, qreal h22, qreal h23,
+ qreal h31, qreal h32, qreal h33, bool)
+ : affine(h11, h12, h21, h22, h31, h32, true)
+ , m_13(h13), m_23(h23), m_33(h33)
+ , m_type(TxNone)
+ , m_dirty(TxProject) {}
+ inline QTransform(bool)
+ : affine(true)
+ , m_13(0), m_23(0), m_33(1)
+ , m_type(TxNone)
+ , m_dirty(TxNone) {}
+ inline TransformationType inline_type() const;
QMatrix affine;
qreal m_13;
qreal m_23;
@@ -173,18 +186,25 @@ private:
Q_DECLARE_TYPEINFO(QTransform, Q_MOVABLE_TYPE);
/******* inlines *****/
+inline QTransform::TransformationType QTransform::inline_type() const
+{
+ if (m_dirty == TxNone)
+ return static_cast<TransformationType>(m_type);
+ return type();
+}
+
inline bool QTransform::isAffine() const
{
- return type() < TxProject;
+ return inline_type() < TxProject;
}
inline bool QTransform::isIdentity() const
{
- return type() == TxNone;
+ return inline_type() == TxNone;
}
inline bool QTransform::isInvertible() const
{
- return !qFuzzyCompare(determinant() + 1, 1);
+ return !qFuzzyIsNull(determinant());
}
inline bool QTransform::isScaling() const
@@ -193,12 +213,12 @@ inline bool QTransform::isScaling() const
}
inline bool QTransform::isRotating() const
{
- return type() >= TxRotate;
+ return inline_type() >= TxRotate;
}
inline bool QTransform::isTranslating() const
{
- return type() >= TxTranslate;
+ return inline_type() >= TxTranslate;
}
inline qreal QTransform::determinant() const
diff --git a/src/gui/painting/qwindowsurface_d3d.cpp b/src/gui/painting/qwindowsurface_d3d.cpp
deleted file mode 100644
index 2b7f633..0000000
--- a/src/gui/painting/qwindowsurface_d3d.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//#define D3D_DEBUG_BACKBUFFER
-
-#include <QtGui/QPaintDevice>
-#include <QtGui/QWidget>
-#include "qdebug.h"
-
-#include "qpaintengine_d3d_p.h"
-#include "qwindowsurface_d3d_p.h"
-#include "private/qwidget_p.h"
-#include "private/qbackingstore_p.h"
-
-#include <d3d9.h>
-
-QT_BEGIN_NAMESPACE
-
-extern QDirect3DPaintEngine *qt_d3dEngine();
-
-struct QD3DWindowSurfacePrivate
-{
- QSize m_lastSize;
- QWidget *m_widget;
-};
-
-QD3DWindowSurface::QD3DWindowSurface(QWidget *window)
- : QWindowSurface(window), d_ptr(new QD3DWindowSurfacePrivate)
-{
- Q_ASSERT(window->isTopLevel());
- d_ptr->m_widget = window;
-}
-
-
-QD3DWindowSurface::~QD3DWindowSurface()
-{
- delete d_ptr;
-}
-
-QPaintDevice *QD3DWindowSurface::paintDevice()
-{
- return d_ptr->m_widget;
-}
-
-
-void QD3DWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
-{
- QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();
-
- QDirect3DPaintEngine *engine = qt_d3dEngine();
- LPDIRECT3DSWAPCHAIN9 swapchain = engine->swapChain(d_ptr->m_widget);
-
- if (swapchain) {
- QRect br = rgn.boundingRect();
- QRect wbr = br.translated(-wOffset);
-
- RECT destrect;
- destrect.left = wbr.x();
- destrect.top = wbr.y();
- destrect.right = destrect.left + wbr.width();
- destrect.bottom = destrect.top + wbr.height();
-
- RECT srcrect;
- srcrect.left = br.x() + offset.x();
- srcrect.top = br.y() + offset.y();
- srcrect.right = wbr.width() + srcrect.left;
- srcrect.bottom = wbr.height() + srcrect.top;
- int devwidth = d_ptr->m_lastSize.width();
- int devheight = d_ptr->m_lastSize.height();
-
- if (devwidth <= srcrect.right) {
- int diff = srcrect.right - devwidth;
- srcrect.right -= diff;
- destrect.right -= diff;
- if (srcrect.right <= srcrect.left)
- return;
- }
- if (devheight <= srcrect.bottom) {
- int diff = srcrect.bottom - devheight;
- srcrect.bottom -= diff;
- destrect.bottom -= diff;
- if (srcrect.bottom <= srcrect.top)
- return;
- }
-
- if (FAILED(swapchain->Present(&srcrect, &destrect, widget->winId(), 0, 0)))
- qWarning("QDirect3DPaintEngine: failed to present back buffer.");
-
-#ifdef D3D_DEBUG_BACKBUFFER
- qDebug() << widget << srcrect.left << srcrect.top << wbr.width() << wbr.height() << "Dest: " << destrect.left << destrect.top;
- IDirect3DSurface9 *surface;
- swapchain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &surface);
- QString filename("C:\\test.bmp");
- D3DXSaveSurfaceToFile(filename.utf16(), D3DXIFF_BMP, surface, 0, 0);
- surface->Release();
-#endif
- }
-}
-
-void QD3DWindowSurface::setGeometry(const QRect &rect)
-{
- if (rect.isEmpty())
- qt_d3dEngine()->releaseSwapChain(d_ptr->m_widget);
-
- d_ptr->m_lastSize = rect.size();
- QWindowSurface::setGeometry(rect);
-}
-
-
-bool QD3DWindowSurface::scroll(const QRegion &area, int dx, int dy)
-{
- QDirect3DPaintEngine *engine = qt_d3dEngine();
- QRect rect = area.boundingRect();
-
- RECT destrect;
- destrect.left = rect.x()+dx;
- destrect.top = rect.y()+dy;
- destrect.right = rect.width() + destrect.left;
- destrect.bottom = rect.height() + destrect.top;
-
- RECT srcrect;
- srcrect.left = rect.x();
- srcrect.top = rect.y();
- srcrect.right = rect.width() + srcrect.left;
- srcrect.bottom = rect.height() + srcrect.top;
-
- engine->scroll(d_ptr->m_widget, srcrect, destrect);
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp
index 110ba2f..3e7b015 100644
--- a/src/gui/painting/qwindowsurface_raster.cpp
+++ b/src/gui/painting/qwindowsurface_raster.cpp
@@ -82,7 +82,7 @@ public:
uint translucentBackground : 1;
#endif
#endif
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
uint canUseLayeredWindow : 1;
#endif
uint inSetGeometry : 1;
@@ -98,7 +98,7 @@ QRasterWindowSurface::QRasterWindowSurface(QWidget *window)
&& window->x11Info().depth() == 32;
#endif
#endif
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
d_ptr->canUseLayeredWindow = ptrUpdateLayeredWindowIndirect
&& (qt_widget_private(window)->data.window_flags & Qt::FramelessWindowHint);
#endif
@@ -127,9 +127,9 @@ QPaintDevice *QRasterWindowSurface::paintDevice()
void QRasterWindowSurface::beginPaint(const QRegion &rgn)
{
-#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_OS_WINCE))
+#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_WS_WINCE))
if (!qt_widget_private(window())->isOpaque) {
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
if (d_ptr->image->image.format() != QImage::Format_ARGB32_Premultiplied
&& d_ptr->canUseLayeredWindow)
prepareBuffer(QImage::Format_ARGB32_Premultiplied, window());
@@ -159,7 +159,7 @@ void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoi
#ifdef Q_WS_WIN
QRect br = rgn.boundingRect();
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
if (!qt_widget_private(window())->isOpaque && d->canUseLayeredWindow) {
QRect r = window()->frameGeometry();
QPoint frameOffset = qt_widget_private(window())->frameStrut().topLeft();
@@ -304,7 +304,7 @@ void QRasterWindowSurface::setGeometry(const QRect &rect)
Q_D(QRasterWindowSurface);
d->inSetGeometry = true;
if (d->image == 0 || d->image->width() < rect.width() || d->image->height() < rect.height()) {
-#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_OS_WINCE))
+#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_WS_WINCE))
#ifndef Q_WS_WIN
if (d_ptr->translucentBackground)
#else
diff --git a/src/gui/styles/gtksymbols.cpp b/src/gui/styles/gtksymbols.cpp
index 0842ec7..99d7261 100644
--- a/src/gui/styles/gtksymbols.cpp
+++ b/src/gui/styles/gtksymbols.cpp
@@ -207,118 +207,118 @@ static QString classPath(GtkWidget *widget)
static void resolveGtk()
{
- const QString GTK_PATH(QLS("gtk-x11-2.0"));
- QGtk::gtk_init = (Ptr_gtk_init)QLibrary::resolve(GTK_PATH, 0, "gtk_init");
- QGtk::gtk_window_new = (Ptr_gtk_window_new)QLibrary::resolve(GTK_PATH, 0, "gtk_window_new");
- QGtk::gtk_style_attach = (Ptr_gtk_style_attach)QLibrary::resolve(GTK_PATH, 0, "gtk_style_attach");
- QGtk::gtk_widget_destroy = (Ptr_gtk_widget_destroy)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_destroy");
- QGtk::gtk_widget_realize = (Ptr_gtk_widget_realize)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_realize");
-
- QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_set_current_folder");
- QGtk::gtk_file_filter_new = (Ptr_gtk_file_filter_new)QLibrary::resolve(GTK_PATH, 0, "gtk_file_filter_new");
- QGtk::gtk_file_filter_set_name = (Ptr_gtk_file_filter_set_name)QLibrary::resolve(GTK_PATH, 0, "gtk_file_filter_set_name");
- QGtk::gtk_file_filter_add_pattern = (Ptr_gtk_file_filter_add_pattern)QLibrary::resolve(GTK_PATH, 0, "gtk_file_filter_add_pattern");
- QGtk::gtk_file_chooser_add_filter = (Ptr_gtk_file_chooser_add_filter)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_add_filter");
- QGtk::gtk_file_chooser_set_filter = (Ptr_gtk_file_chooser_set_filter)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_set_filter");
- QGtk::gtk_file_chooser_dialog_new = (Ptr_gtk_file_chooser_dialog_new)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_dialog_new");
- QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_set_current_folder");
- QGtk::gtk_file_chooser_get_filename = (Ptr_gtk_file_chooser_get_filename)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_get_filename");
- QGtk::gtk_file_chooser_get_filenames = (Ptr_gtk_file_chooser_get_filenames)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_get_filenames");
- QGtk::gtk_file_chooser_set_current_name = (Ptr_gtk_file_chooser_set_current_name)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_set_current_name");
- QGtk::gtk_dialog_run = (Ptr_gtk_dialog_run)QLibrary::resolve(GTK_PATH, 0, "gtk_dialog_run");
- QGtk::gtk_file_chooser_set_filename = (Ptr_gtk_file_chooser_set_filename)QLibrary::resolve(GTK_PATH, 0, "gtk_file_chooser_set_filename");
-
- QGtk::gdk_pixbuf_get_pixels = (Ptr_gdk_pixbuf_get_pixels)QLibrary::resolve(GTK_PATH, 0, "gdk_pixbuf_get_pixels");
- QGtk::gdk_pixbuf_get_width = (Ptr_gdk_pixbuf_get_width)QLibrary::resolve(GTK_PATH, 0, "gdk_pixbuf_get_width");
- QGtk::gdk_pixbuf_get_height = (Ptr_gdk_pixbuf_get_height)QLibrary::resolve(GTK_PATH, 0, "gdk_pixbuf_get_height");
- QGtk::gdk_pixmap_new = (Ptr_gdk_pixmap_new)QLibrary::resolve(GTK_PATH, 0, "gdk_pixmap_new");
- QGtk::gdk_pixbuf_new = (Ptr_gdk_pixbuf_new)QLibrary::resolve(GTK_PATH, 0, "gdk_pixbuf_new");
- QGtk::gdk_pixbuf_get_from_drawable = (Ptr_gdk_pixbuf_get_from_drawable)QLibrary::resolve(GTK_PATH, 0, "gdk_pixbuf_get_from_drawable");
- QGtk::gdk_draw_rectangle = (Ptr_gdk_draw_rectangle)QLibrary::resolve(GTK_PATH, 0, "gdk_draw_rectangle");
- QGtk::gdk_pixbuf_unref = (Ptr_gdk_pixbuf_unref)QLibrary::resolve(GTK_PATH, 0, "gdk_pixbuf_unref");
- QGtk::gdk_drawable_unref = (Ptr_gdk_drawable_unref)QLibrary::resolve(GTK_PATH, 0, "gdk_drawable_unref");
- QGtk::gdk_drawable_get_depth = (Ptr_gdk_drawable_get_depth)QLibrary::resolve(GTK_PATH, 0, "gdk_drawable_get_depth");
- QGtk::gdk_color_free = (Ptr_gdk_color_free)QLibrary::resolve(GTK_PATH, 0, "gdk_color_free");
- QGtk::gdk_x11_window_set_user_time = (Ptr_gdk_x11_window_set_user_time)QLibrary::resolve(GTK_PATH, 0, "gdk_x11_window_set_user_time");
- QGtk::gdk_x11_drawable_get_xid = (Ptr_gdk_x11_drawable_get_xid)QLibrary::resolve(GTK_PATH, 0, "gdk_x11_drawable_get_xid");
- QGtk::gdk_x11_drawable_get_xdisplay = (Ptr_gdk_x11_drawable_get_xdisplay)QLibrary::resolve(GTK_PATH, 0, "gdk_x11_drawable_get_xdisplay");
-
- QGtk::gtk_widget_set_default_direction = (Ptr_gtk_widget_set_default_direction)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_set_default_direction");
- QGtk::gtk_widget_modify_fg = (Ptr_gtk_widget_modify_color)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_modify_fg");
- QGtk::gtk_widget_modify_bg = (Ptr_gtk_widget_modify_color)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_modify_bg");
- QGtk::gtk_arrow_new = (Ptr_gtk_arrow_new)QLibrary::resolve(GTK_PATH, 0, "gtk_arrow_new");
- QGtk::gtk_menu_item_new = (Ptr_gtk_menu_item_new)QLibrary::resolve(GTK_PATH, 0, "gtk_menu_item_new");
- QGtk::gtk_check_menu_item_new = (Ptr_gtk_check_menu_item_new)QLibrary::resolve(GTK_PATH, 0, "gtk_check_menu_item_new");
- QGtk::gtk_menu_bar_new = (Ptr_gtk_menu_bar_new)QLibrary::resolve(GTK_PATH, 0, "gtk_menu_bar_new");
- QGtk::gtk_menu_new = (Ptr_gtk_menu_new)QLibrary::resolve(GTK_PATH, 0, "gtk_menu_new");
- QGtk::gtk_toolbar_new = (Ptr_gtk_toolbar_new)QLibrary::resolve(GTK_PATH, 0, "gtk_toolbar_new");
- QGtk::gtk_separator_tool_item_new = (Ptr_gtk_separator_tool_item_new)QLibrary::resolve(GTK_PATH, 0, "gtk_separator_tool_item_new");
- QGtk::gtk_toolbar_insert = (Ptr_gtk_toolbar_insert)QLibrary::resolve(GTK_PATH, 0, "gtk_toolbar_insert");
- QGtk::gtk_button_new = (Ptr_gtk_button_new)QLibrary::resolve(GTK_PATH, 0, "gtk_button_new");
- QGtk::gtk_hbutton_box_new = (Ptr_gtk_hbutton_box_new)QLibrary::resolve(GTK_PATH, 0, "gtk_hbutton_box_new");
- QGtk::gtk_check_button_new = (Ptr_gtk_check_button_new)QLibrary::resolve(GTK_PATH, 0, "gtk_check_button_new");
- QGtk::gtk_radio_button_new = (Ptr_gtk_radio_button_new)QLibrary::resolve(GTK_PATH, 0, "gtk_radio_button_new");
- QGtk::gtk_notebook_new = (Ptr_gtk_notebook_new)QLibrary::resolve(GTK_PATH, 0, "gtk_notebook_new");
- QGtk::gtk_progress_bar_new = (Ptr_gtk_progress_bar_new)QLibrary::resolve(GTK_PATH, 0, "gtk_progress_bar_new");
- QGtk::gtk_spin_button_new = (Ptr_gtk_spin_button_new)QLibrary::resolve(GTK_PATH, 0, "gtk_spin_button_new");
- QGtk::gtk_hscale_new = (Ptr_gtk_hscale_new)QLibrary::resolve(GTK_PATH, 0, "gtk_hscale_new");
- QGtk::gtk_vscale_new = (Ptr_gtk_vscale_new)QLibrary::resolve(GTK_PATH, 0, "gtk_vscale_new");
- QGtk::gtk_hscrollbar_new = (Ptr_gtk_hscrollbar_new)QLibrary::resolve(GTK_PATH, 0, "gtk_hscrollbar_new");
- QGtk::gtk_vscrollbar_new = (Ptr_gtk_vscrollbar_new)QLibrary::resolve(GTK_PATH, 0, "gtk_vscrollbar_new");
- QGtk::gtk_scrolled_window_new = (Ptr_gtk_scrolled_window_new)QLibrary::resolve(GTK_PATH, 0, "gtk_scrolled_window_new");
- QGtk::gtk_menu_shell_append = (Ptr_gtk_menu_shell_append)QLibrary::resolve(GTK_PATH, 0, "gtk_menu_shell_append");
- QGtk::gtk_entry_new = (Ptr_gtk_entry_new)QLibrary::resolve(GTK_PATH, 0, "gtk_entry_new");
- QGtk::gtk_tree_view_new = (Ptr_gtk_tree_view_new)QLibrary::resolve(GTK_PATH, 0, "gtk_tree_view_new");
- QGtk::gtk_combo_box_new = (Ptr_gtk_combo_box_new)QLibrary::resolve(GTK_PATH, 0, "gtk_combo_box_new");
- QGtk::gtk_progress_set_adjustment = (Ptr_gtk_progress_set_adjustment)QLibrary::resolve(GTK_PATH, 0, "gtk_progress_set_adjustment");
- QGtk::gtk_range_set_adjustment = (Ptr_gtk_range_set_adjustment)QLibrary::resolve(GTK_PATH, 0, "gtk_range_set_adjustment");
- QGtk::gtk_range_set_inverted = (Ptr_gtk_range_set_inverted)QLibrary::resolve(GTK_PATH, 0, "gtk_range_set_inverted");
- QGtk::gtk_container_add = (Ptr_gtk_container_add)QLibrary::resolve(GTK_PATH, 0, "gtk_container_add");
- QGtk::gtk_icon_factory_lookup_default = (Ptr_gtk_icon_factory_lookup_default)QLibrary::resolve(GTK_PATH, 0, "gtk_icon_factory_lookup_default");
- QGtk::gtk_widget_style_get = (Ptr_gtk_widget_style_get)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_style_get");
- QGtk::gtk_icon_set_render_icon = (Ptr_gtk_icon_set_render_icon)QLibrary::resolve(GTK_PATH, 0, "gtk_icon_set_render_icon");
- QGtk::gtk_fixed_new = (Ptr_gtk_fixed_new)QLibrary::resolve(GTK_PATH, 0, "gtk_fixed_new");
- QGtk::gtk_tree_view_column_new = (Ptr_gtk_tree_view_column_new)QLibrary::resolve(GTK_PATH, 0, "gtk_tree_view_column_new");
- QGtk::gtk_tree_view_append_column= (Ptr_gtk_tree_view_append_column )QLibrary::resolve(GTK_PATH, 0, "gtk_tree_view_append_column");
- QGtk::gtk_tree_view_get_column = (Ptr_gtk_tree_view_get_column )QLibrary::resolve(GTK_PATH, 0, "gtk_tree_view_get_column");
- QGtk::gtk_paint_check = (Ptr_gtk_paint_check)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_check");
- QGtk::gtk_paint_box = (Ptr_gtk_paint_box)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_box");
- QGtk::gtk_paint_flat_box = (Ptr_gtk_paint_flat_box)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_flat_box");
- QGtk::gtk_paint_check = (Ptr_gtk_paint_check)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_check");
- QGtk::gtk_paint_box = (Ptr_gtk_paint_box)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_box");
- QGtk::gtk_paint_resize_grip = (Ptr_gtk_paint_resize_grip)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_resize_grip");
- QGtk::gtk_paint_focus = (Ptr_gtk_paint_focus)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_focus");
- QGtk::gtk_paint_shadow = (Ptr_gtk_paint_shadow)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_shadow");
- QGtk::gtk_paint_slider = (Ptr_gtk_paint_slider)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_slider");
- QGtk::gtk_paint_expander = (Ptr_gtk_paint_expander)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_expander");
- QGtk::gtk_paint_handle = (Ptr_gtk_paint_handle)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_handle");
- QGtk::gtk_paint_option = (Ptr_gtk_paint_option)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_option");
- QGtk::gtk_paint_arrow = (Ptr_gtk_paint_arrow)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_arrow");
- QGtk::gtk_paint_box_gap = (Ptr_gtk_paint_box_gap)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_box_gap");
- QGtk::gtk_paint_extension = (Ptr_gtk_paint_extension)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_extension");
- QGtk::gtk_paint_hline = (Ptr_gtk_paint_hline)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_hline");
- QGtk::gtk_paint_vline = (Ptr_gtk_paint_vline)QLibrary::resolve(GTK_PATH, 0, "gtk_paint_vline");
- QGtk::gtk_adjustment_new = (Ptr_gtk_adjustment_new)QLibrary::resolve(GTK_PATH, 0, "gtk_adjustment_new");
- QGtk::gtk_menu_item_set_submenu = (Ptr_gtk_menu_item_set_submenu)QLibrary::resolve(GTK_PATH, 0, "gtk_menu_item_set_submenu");
- QGtk::gtk_settings_get_default = (Ptr_gtk_settings_get_default)QLibrary::resolve(GTK_PATH, 0, "gtk_settings_get_default");
- QGtk::gtk_separator_menu_item_new = (Ptr_gtk_separator_menu_item_new)QLibrary::resolve(GTK_PATH, 0, "gtk_separator_menu_item_new");
- QGtk::gtk_frame_new = (Ptr_gtk_frame_new)QLibrary::resolve(GTK_PATH, 0, "gtk_frame_new");
- QGtk::gtk_expander_new = (Ptr_gtk_expander_new)QLibrary::resolve(GTK_PATH, 0, "gtk_expander_new");
- QGtk::gtk_statusbar_new = (Ptr_gtk_statusbar_new)QLibrary::resolve(GTK_PATH, 0, "gtk_statusbar_new");
- QGtk::gtk_combo_box_entry_new = (Ptr_gtk_combo_box_entry_new)QLibrary::resolve(GTK_PATH, 0, "gtk_combo_box_entry_new");
- QGtk::gtk_container_forall = (Ptr_gtk_container_forall)QLibrary::resolve(GTK_PATH, 0, "gtk_container_forall");
- QGtk::gtk_widget_size_allocate =(Ptr_gtk_widget_size_allocate)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_size_allocate");
- QGtk::gtk_widget_set_direction =(Ptr_gtk_widget_set_direction)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_set_direction");
- QGtk::gtk_widget_path =(Ptr_gtk_widget_path)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_path");
- QGtk::gtk_container_get_type =(Ptr_gtk_container_get_type)QLibrary::resolve(GTK_PATH, 0, "gtk_container_get_type");
- QGtk::gtk_window_get_type =(Ptr_gtk_window_get_type)QLibrary::resolve(GTK_PATH, 0, "gtk_window_get_type");
- QGtk::gtk_widget_get_type =(Ptr_gtk_widget_get_type)QLibrary::resolve(GTK_PATH, 0, "gtk_widget_get_type");
- QGtk::gtk_rc_get_style_by_paths =(Ptr_gtk_rc_get_style_by_paths)QLibrary::resolve(GTK_PATH, 0, "gtk_rc_get_style_by_paths");
- QGtk::gtk_check_version =(Ptr_gtk_check_version)QLibrary::resolve(GTK_PATH, 0, "gtk_check_version");
- QGtk::pango_font_description_get_size = (Ptr_pango_font_description_get_size)QLibrary::resolve(GTK_PATH, 0, "pango_font_description_get_size");
- QGtk::pango_font_description_get_weight = (Ptr_pango_font_description_get_weight)QLibrary::resolve(GTK_PATH, 0, "pango_font_description_get_weight");
- QGtk::pango_font_description_get_family = (Ptr_pango_font_description_get_family)QLibrary::resolve(GTK_PATH, 0, "pango_font_description_get_family");
- QGtk::pango_font_description_get_style = (Ptr_pango_font_description_get_style)QLibrary::resolve(GTK_PATH, 0, "pango_font_description_get_style");
+ QLibrary libgtk(QLS("gtk-x11-2.0"));
+ QGtk::gtk_init = (Ptr_gtk_init)libgtk.resolve("gtk_init");
+ QGtk::gtk_window_new = (Ptr_gtk_window_new)libgtk.resolve("gtk_window_new");
+ QGtk::gtk_style_attach = (Ptr_gtk_style_attach)libgtk.resolve("gtk_style_attach");
+ QGtk::gtk_widget_destroy = (Ptr_gtk_widget_destroy)libgtk.resolve("gtk_widget_destroy");
+ QGtk::gtk_widget_realize = (Ptr_gtk_widget_realize)libgtk.resolve("gtk_widget_realize");
+
+ QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder");
+ QGtk::gtk_file_filter_new = (Ptr_gtk_file_filter_new)libgtk.resolve("gtk_file_filter_new");
+ QGtk::gtk_file_filter_set_name = (Ptr_gtk_file_filter_set_name)libgtk.resolve("gtk_file_filter_set_name");
+ QGtk::gtk_file_filter_add_pattern = (Ptr_gtk_file_filter_add_pattern)libgtk.resolve("gtk_file_filter_add_pattern");
+ QGtk::gtk_file_chooser_add_filter = (Ptr_gtk_file_chooser_add_filter)libgtk.resolve("gtk_file_chooser_add_filter");
+ QGtk::gtk_file_chooser_set_filter = (Ptr_gtk_file_chooser_set_filter)libgtk.resolve("gtk_file_chooser_set_filter");
+ QGtk::gtk_file_chooser_dialog_new = (Ptr_gtk_file_chooser_dialog_new)libgtk.resolve("gtk_file_chooser_dialog_new");
+ QGtk::gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder");
+ QGtk::gtk_file_chooser_get_filename = (Ptr_gtk_file_chooser_get_filename)libgtk.resolve("gtk_file_chooser_get_filename");
+ QGtk::gtk_file_chooser_get_filenames = (Ptr_gtk_file_chooser_get_filenames)libgtk.resolve("gtk_file_chooser_get_filenames");
+ QGtk::gtk_file_chooser_set_current_name = (Ptr_gtk_file_chooser_set_current_name)libgtk.resolve("gtk_file_chooser_set_current_name");
+ QGtk::gtk_dialog_run = (Ptr_gtk_dialog_run)libgtk.resolve("gtk_dialog_run");
+ QGtk::gtk_file_chooser_set_filename = (Ptr_gtk_file_chooser_set_filename)libgtk.resolve("gtk_file_chooser_set_filename");
+
+ QGtk::gdk_pixbuf_get_pixels = (Ptr_gdk_pixbuf_get_pixels)libgtk.resolve("gdk_pixbuf_get_pixels");
+ QGtk::gdk_pixbuf_get_width = (Ptr_gdk_pixbuf_get_width)libgtk.resolve("gdk_pixbuf_get_width");
+ QGtk::gdk_pixbuf_get_height = (Ptr_gdk_pixbuf_get_height)libgtk.resolve("gdk_pixbuf_get_height");
+ QGtk::gdk_pixmap_new = (Ptr_gdk_pixmap_new)libgtk.resolve("gdk_pixmap_new");
+ QGtk::gdk_pixbuf_new = (Ptr_gdk_pixbuf_new)libgtk.resolve("gdk_pixbuf_new");
+ QGtk::gdk_pixbuf_get_from_drawable = (Ptr_gdk_pixbuf_get_from_drawable)libgtk.resolve("gdk_pixbuf_get_from_drawable");
+ QGtk::gdk_draw_rectangle = (Ptr_gdk_draw_rectangle)libgtk.resolve("gdk_draw_rectangle");
+ QGtk::gdk_pixbuf_unref = (Ptr_gdk_pixbuf_unref)libgtk.resolve("gdk_pixbuf_unref");
+ QGtk::gdk_drawable_unref = (Ptr_gdk_drawable_unref)libgtk.resolve("gdk_drawable_unref");
+ QGtk::gdk_drawable_get_depth = (Ptr_gdk_drawable_get_depth)libgtk.resolve("gdk_drawable_get_depth");
+ QGtk::gdk_color_free = (Ptr_gdk_color_free)libgtk.resolve("gdk_color_free");
+ QGtk::gdk_x11_window_set_user_time = (Ptr_gdk_x11_window_set_user_time)libgtk.resolve("gdk_x11_window_set_user_time");
+ QGtk::gdk_x11_drawable_get_xid = (Ptr_gdk_x11_drawable_get_xid)libgtk.resolve("gdk_x11_drawable_get_xid");
+ QGtk::gdk_x11_drawable_get_xdisplay = (Ptr_gdk_x11_drawable_get_xdisplay)libgtk.resolve("gdk_x11_drawable_get_xdisplay");
+
+ QGtk::gtk_widget_set_default_direction = (Ptr_gtk_widget_set_default_direction)libgtk.resolve("gtk_widget_set_default_direction");
+ QGtk::gtk_widget_modify_fg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_fg");
+ QGtk::gtk_widget_modify_bg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_bg");
+ QGtk::gtk_arrow_new = (Ptr_gtk_arrow_new)libgtk.resolve("gtk_arrow_new");
+ QGtk::gtk_menu_item_new = (Ptr_gtk_menu_item_new)libgtk.resolve("gtk_menu_item_new");
+ QGtk::gtk_check_menu_item_new = (Ptr_gtk_check_menu_item_new)libgtk.resolve("gtk_check_menu_item_new");
+ QGtk::gtk_menu_bar_new = (Ptr_gtk_menu_bar_new)libgtk.resolve("gtk_menu_bar_new");
+ QGtk::gtk_menu_new = (Ptr_gtk_menu_new)libgtk.resolve("gtk_menu_new");
+ QGtk::gtk_toolbar_new = (Ptr_gtk_toolbar_new)libgtk.resolve("gtk_toolbar_new");
+ QGtk::gtk_separator_tool_item_new = (Ptr_gtk_separator_tool_item_new)libgtk.resolve("gtk_separator_tool_item_new");
+ QGtk::gtk_toolbar_insert = (Ptr_gtk_toolbar_insert)libgtk.resolve("gtk_toolbar_insert");
+ QGtk::gtk_button_new = (Ptr_gtk_button_new)libgtk.resolve("gtk_button_new");
+ QGtk::gtk_hbutton_box_new = (Ptr_gtk_hbutton_box_new)libgtk.resolve("gtk_hbutton_box_new");
+ QGtk::gtk_check_button_new = (Ptr_gtk_check_button_new)libgtk.resolve("gtk_check_button_new");
+ QGtk::gtk_radio_button_new = (Ptr_gtk_radio_button_new)libgtk.resolve("gtk_radio_button_new");
+ QGtk::gtk_notebook_new = (Ptr_gtk_notebook_new)libgtk.resolve("gtk_notebook_new");
+ QGtk::gtk_progress_bar_new = (Ptr_gtk_progress_bar_new)libgtk.resolve("gtk_progress_bar_new");
+ QGtk::gtk_spin_button_new = (Ptr_gtk_spin_button_new)libgtk.resolve("gtk_spin_button_new");
+ QGtk::gtk_hscale_new = (Ptr_gtk_hscale_new)libgtk.resolve("gtk_hscale_new");
+ QGtk::gtk_vscale_new = (Ptr_gtk_vscale_new)libgtk.resolve("gtk_vscale_new");
+ QGtk::gtk_hscrollbar_new = (Ptr_gtk_hscrollbar_new)libgtk.resolve("gtk_hscrollbar_new");
+ QGtk::gtk_vscrollbar_new = (Ptr_gtk_vscrollbar_new)libgtk.resolve("gtk_vscrollbar_new");
+ QGtk::gtk_scrolled_window_new = (Ptr_gtk_scrolled_window_new)libgtk.resolve("gtk_scrolled_window_new");
+ QGtk::gtk_menu_shell_append = (Ptr_gtk_menu_shell_append)libgtk.resolve("gtk_menu_shell_append");
+ QGtk::gtk_entry_new = (Ptr_gtk_entry_new)libgtk.resolve("gtk_entry_new");
+ QGtk::gtk_tree_view_new = (Ptr_gtk_tree_view_new)libgtk.resolve("gtk_tree_view_new");
+ QGtk::gtk_combo_box_new = (Ptr_gtk_combo_box_new)libgtk.resolve("gtk_combo_box_new");
+ QGtk::gtk_progress_set_adjustment = (Ptr_gtk_progress_set_adjustment)libgtk.resolve("gtk_progress_set_adjustment");
+ QGtk::gtk_range_set_adjustment = (Ptr_gtk_range_set_adjustment)libgtk.resolve("gtk_range_set_adjustment");
+ QGtk::gtk_range_set_inverted = (Ptr_gtk_range_set_inverted)libgtk.resolve("gtk_range_set_inverted");
+ QGtk::gtk_container_add = (Ptr_gtk_container_add)libgtk.resolve("gtk_container_add");
+ QGtk::gtk_icon_factory_lookup_default = (Ptr_gtk_icon_factory_lookup_default)libgtk.resolve("gtk_icon_factory_lookup_default");
+ QGtk::gtk_widget_style_get = (Ptr_gtk_widget_style_get)libgtk.resolve("gtk_widget_style_get");
+ QGtk::gtk_icon_set_render_icon = (Ptr_gtk_icon_set_render_icon)libgtk.resolve("gtk_icon_set_render_icon");
+ QGtk::gtk_fixed_new = (Ptr_gtk_fixed_new)libgtk.resolve("gtk_fixed_new");
+ QGtk::gtk_tree_view_column_new = (Ptr_gtk_tree_view_column_new)libgtk.resolve("gtk_tree_view_column_new");
+ QGtk::gtk_tree_view_append_column= (Ptr_gtk_tree_view_append_column )libgtk.resolve("gtk_tree_view_append_column");
+ QGtk::gtk_tree_view_get_column = (Ptr_gtk_tree_view_get_column )libgtk.resolve("gtk_tree_view_get_column");
+ QGtk::gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check");
+ QGtk::gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box");
+ QGtk::gtk_paint_flat_box = (Ptr_gtk_paint_flat_box)libgtk.resolve("gtk_paint_flat_box");
+ QGtk::gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check");
+ QGtk::gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box");
+ QGtk::gtk_paint_resize_grip = (Ptr_gtk_paint_resize_grip)libgtk.resolve("gtk_paint_resize_grip");
+ QGtk::gtk_paint_focus = (Ptr_gtk_paint_focus)libgtk.resolve("gtk_paint_focus");
+ QGtk::gtk_paint_shadow = (Ptr_gtk_paint_shadow)libgtk.resolve("gtk_paint_shadow");
+ QGtk::gtk_paint_slider = (Ptr_gtk_paint_slider)libgtk.resolve("gtk_paint_slider");
+ QGtk::gtk_paint_expander = (Ptr_gtk_paint_expander)libgtk.resolve("gtk_paint_expander");
+ QGtk::gtk_paint_handle = (Ptr_gtk_paint_handle)libgtk.resolve("gtk_paint_handle");
+ QGtk::gtk_paint_option = (Ptr_gtk_paint_option)libgtk.resolve("gtk_paint_option");
+ QGtk::gtk_paint_arrow = (Ptr_gtk_paint_arrow)libgtk.resolve("gtk_paint_arrow");
+ QGtk::gtk_paint_box_gap = (Ptr_gtk_paint_box_gap)libgtk.resolve("gtk_paint_box_gap");
+ QGtk::gtk_paint_extension = (Ptr_gtk_paint_extension)libgtk.resolve("gtk_paint_extension");
+ QGtk::gtk_paint_hline = (Ptr_gtk_paint_hline)libgtk.resolve("gtk_paint_hline");
+ QGtk::gtk_paint_vline = (Ptr_gtk_paint_vline)libgtk.resolve("gtk_paint_vline");
+ QGtk::gtk_adjustment_new = (Ptr_gtk_adjustment_new)libgtk.resolve("gtk_adjustment_new");
+ QGtk::gtk_menu_item_set_submenu = (Ptr_gtk_menu_item_set_submenu)libgtk.resolve("gtk_menu_item_set_submenu");
+ QGtk::gtk_settings_get_default = (Ptr_gtk_settings_get_default)libgtk.resolve("gtk_settings_get_default");
+ QGtk::gtk_separator_menu_item_new = (Ptr_gtk_separator_menu_item_new)libgtk.resolve("gtk_separator_menu_item_new");
+ QGtk::gtk_frame_new = (Ptr_gtk_frame_new)libgtk.resolve("gtk_frame_new");
+ QGtk::gtk_expander_new = (Ptr_gtk_expander_new)libgtk.resolve("gtk_expander_new");
+ QGtk::gtk_statusbar_new = (Ptr_gtk_statusbar_new)libgtk.resolve("gtk_statusbar_new");
+ QGtk::gtk_combo_box_entry_new = (Ptr_gtk_combo_box_entry_new)libgtk.resolve("gtk_combo_box_entry_new");
+ QGtk::gtk_container_forall = (Ptr_gtk_container_forall)libgtk.resolve("gtk_container_forall");
+ QGtk::gtk_widget_size_allocate =(Ptr_gtk_widget_size_allocate)libgtk.resolve("gtk_widget_size_allocate");
+ QGtk::gtk_widget_set_direction =(Ptr_gtk_widget_set_direction)libgtk.resolve("gtk_widget_set_direction");
+ QGtk::gtk_widget_path =(Ptr_gtk_widget_path)libgtk.resolve("gtk_widget_path");
+ QGtk::gtk_container_get_type =(Ptr_gtk_container_get_type)libgtk.resolve("gtk_container_get_type");
+ QGtk::gtk_window_get_type =(Ptr_gtk_window_get_type)libgtk.resolve("gtk_window_get_type");
+ QGtk::gtk_widget_get_type =(Ptr_gtk_widget_get_type)libgtk.resolve("gtk_widget_get_type");
+ QGtk::gtk_rc_get_style_by_paths =(Ptr_gtk_rc_get_style_by_paths)libgtk.resolve("gtk_rc_get_style_by_paths");
+ QGtk::gtk_check_version =(Ptr_gtk_check_version)libgtk.resolve("gtk_check_version");
+ QGtk::pango_font_description_get_size = (Ptr_pango_font_description_get_size)libgtk.resolve("pango_font_description_get_size");
+ QGtk::pango_font_description_get_weight = (Ptr_pango_font_description_get_weight)libgtk.resolve("pango_font_description_get_weight");
+ QGtk::pango_font_description_get_family = (Ptr_pango_font_description_get_family)libgtk.resolve("pango_font_description_get_family");
+ QGtk::pango_font_description_get_style = (Ptr_pango_font_description_get_style)libgtk.resolve("pango_font_description_get_style");
}
void QGtk::cleanup_gtk_widgets()
diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp
index 468ada9..3fb63f2 100644
--- a/src/gui/styles/qcleanlooksstyle.cpp
+++ b/src/gui/styles/qcleanlooksstyle.cpp
@@ -44,6 +44,7 @@
#if !defined(QT_NO_STYLE_CLEANLOOKS) || defined(QT_PLUGIN)
+#include <private/qstylehelper_p.h>
#include "qwindowsstyle_p.h"
#include <qcombobox.h>
#include <qpushbutton.h>
@@ -72,7 +73,7 @@
QT_BEGIN_NAMESPACE
-static const bool UsePixmapCache = true;
+using namespace QStyleHelper;
enum Direction {
TopDown,
@@ -553,26 +554,6 @@ static void qt_cleanlooks_draw_buttongradient(QPainter *painter, const QRect &re
delete gradient;
}
-static QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size)
-{
- QString tmp;
- const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option);
- tmp.sprintf("%s-%d-%d-%lld-%dx%d-%d", key.toLatin1().constData(), uint(option->state),
- complexOption ? uint(complexOption->activeSubControls) : uint(0),
- option->palette.cacheKey(), size.width(), size.height(), option->direction);
-#ifndef QT_NO_SPINBOX
- if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
- tmp.append(QLatin1Char('-'));
- tmp.append(QString::number(spinBox->buttonSymbols));
- tmp.append(QLatin1Char('-'));
- tmp.append(QString::number(spinBox->stepEnabled));
- tmp.append(QLatin1Char('-'));
- tmp.append(QLatin1Char(spinBox->frame ? '1' : '0'));
- }
-#endif // QT_NO_SPINBOX
- return tmp;
-}
-
static void qt_cleanlooks_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
{
QColor dark;
@@ -1664,7 +1645,7 @@ void QCleanlooksStyle::drawControl(ControlElement element, const QStyleOption *o
// Draws the header in tables.
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
QPixmap cache;
- QString pixmapName = uniqueName(QLatin1String("headersection"), option, option->rect.size());
+ QString pixmapName = QStyleHelper::uniqueName(QLatin1String("headersection"), option, option->rect.size());
pixmapName += QLatin1String("-") + QString::number(int(header->position));
pixmapName += QLatin1String("-") + QString::number(int(header->orientation));
QRect r = option->rect;
@@ -2456,7 +2437,7 @@ void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOp
case CC_SpinBox:
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
QPixmap cache;
- QString pixmapName = uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
+ QString pixmapName = QStyleHelper::uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
if (!UsePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
cache = QPixmap(spinBox->rect.size());
cache.fill(Qt::transparent);
@@ -3137,7 +3118,7 @@ void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOp
// The AddLine (down/right) button
if (scrollBar->subControls & SC_ScrollBarAddLine) {
- QString addLinePixmapName = uniqueName(QLatin1String("scrollbar_addline"), option, QSize(16, 16));
+ QString addLinePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_addline"), option, QSize(16, 16));
QRect pixmapRect = scrollBarAddLine;
if (isEnabled) {
QRect fillRect = pixmapRect.adjusted(1, 1, -1, -1);
@@ -3198,7 +3179,7 @@ void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOp
bool isEnabled = (comboBox->state & State_Enabled);
bool focus = isEnabled && (comboBox->state & State_HasFocus);
QPixmap cache;
- QString pixmapName = uniqueName(QLatin1String("combobox"), option, comboBox->rect.size());
+ QString pixmapName = QStyleHelper::uniqueName(QLatin1String("combobox"), option, comboBox->rect.size());
if (sunken)
pixmapName += QLatin1String("-sunken");
if (comboBox->editable)
@@ -3421,7 +3402,7 @@ void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOp
highlightAlpha.setAlpha(80);
if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
- QString groovePixmapName = uniqueName(QLatin1String("slider_groove"), option, groove.size());
+ QString groovePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_groove"), option, groove.size());
QRect pixmapRect(0, 0, groove.width(), groove.height());
// draw background groove
@@ -3501,7 +3482,7 @@ void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOp
// draw handle
if ((option->subControls & SC_SliderHandle) ) {
- QString handlePixmapName = uniqueName(QLatin1String("slider_handle"), option, handle.size());
+ QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size());
if (!UsePixmapCache || !QPixmapCache::find(handlePixmapName, cache)) {
cache = QPixmap(handle.size());
cache.fill(Qt::transparent);
@@ -3656,6 +3637,12 @@ void QCleanlooksStyle::drawComplexControl(ComplexControl control, const QStyleOp
}
break;
#endif // QT_NO_SLIDER
+#ifndef QT_NO_DIAL
+ case CC_Dial:
+ if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
+ QStyleHelper::drawDial(dial, painter);
+ break;
+#endif // QT_NO_DIAL
default:
QWindowsStyle::drawComplexControl(control, option, painter, widget);
break;
@@ -3781,6 +3768,20 @@ QSize QCleanlooksStyle::sizeFromContents(ContentsType type, const QStyleOption *
}
break;
case CT_GroupBox:
+ // Since we use a bold font we have to recalculate base width
+ if (const QGroupBox *gb = qobject_cast<const QGroupBox*>(widget)) {
+ QFont font = gb->font();
+ font.setBold(true);
+ QFontMetrics metrics(font);
+ int baseWidth = metrics.width(gb->title()) + metrics.width(QLatin1Char(' '));
+ if (gb->isCheckable()) {
+ baseWidth += pixelMetric(QStyle::PM_IndicatorWidth, option, widget);
+ baseWidth += pixelMetric(QStyle::PM_CheckBoxLabelSpacing, option, widget);
+ }
+ newSize.setWidth(qMax(baseWidth, newSize.width()));
+ }
+ newSize += QSize(0, 1);
+ break;
case CT_RadioButton:
case CT_CheckBox:
newSize += QSize(0, 1);
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index 3cae08a..6972803 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -66,6 +66,7 @@
#include <private/qapplication_p.h>
#include <private/qcommonstylepixmaps_p.h>
#include <private/qmath_p.h>
+#include <private/qstylehelper_p.h>
#include <qdebug.h>
#include <qtextformat.h>
#include <qwizard.h>
@@ -1663,6 +1664,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (!styleHint(SH_UnderlineShortcut, opt, widget))
alignment |= Qt::TextHideMnemonic;
rect.translate(shiftX, shiftY);
+ p->setFont(toolbutton->font);
drawItemText(p, rect, alignment, toolbutton->palette,
opt->state & State_Enabled, toolbutton->text,
QPalette::ButtonText);
@@ -1979,7 +1981,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
: QIcon::Disabled);
QPixmap tabIcon = tabV2.icon.pixmap(iconSize,
(tabV2.state & State_Enabled) ? QIcon::Normal
- : QIcon::Disabled);
+ : QIcon::Disabled,
+ (tabV2.state & State_Selected) ? QIcon::On
+ : QIcon::Off);
int offset = 4;
int left = opt->rect.left();
@@ -2267,7 +2271,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
drawPrimitive(PE_PanelItemViewItem, opt, p, widget);
// draw the check mark
- if (checkRect.isValid()) {
+ if (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator) {
QStyleOptionViewItemV4 option(*vopt);
option.rect = checkRect;
option.state = option.state & ~QStyle::State_HasFocus;
@@ -2849,9 +2853,11 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
tr.setRect(0, 0, tr.height(), tr.width());
int verticalShift = pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
int horizontalShift = pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
+ int hpadding = pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
+ int vpadding = pixelMetric(QStyle::PM_TabBarTabVSpace, opt, widget) / 2;
if (tabV2.shape == QTabBar::RoundedSouth || tabV2.shape == QTabBar::TriangularSouth)
verticalShift = -verticalShift;
- tr.adjust(0, 0, horizontalShift, verticalShift);
+ tr.adjust(hpadding, vpadding, horizontalShift - hpadding, verticalShift - vpadding);
bool selected = tabV2.state & State_Selected;
if (selected) {
tr.setBottom(tr.bottom() - verticalShift);
@@ -3182,6 +3188,25 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
}
break;
#endif //QT_NO_ITEMVIEWS
+#ifndef QT_NO_TOOLBAR
+ case SE_ToolBarHandle:
+ if (const QStyleOptionToolBar *tbopt = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
+ if (tbopt->features & QStyleOptionToolBar::Movable) {
+ ///we need to access the widget here because the style option doesn't
+ //have all the information we need (ie. the layout's margin)
+ const QToolBar *tb = qobject_cast<const QToolBar*>(widget);
+ const int margin = tb && tb->layout() ? tb->layout()->margin() : 2;
+ const int handleExtent = pixelMetric(QStyle::PM_ToolBarExtensionExtent, opt, tb);
+ if (tbopt->state & QStyle::State_Horizontal) {
+ r = QRect(margin, margin, handleExtent, tbopt->rect.height() - 2*margin);
+ r = QStyle::visualRect(tbopt->direction, tbopt->rect, r);
+ } else {
+ r = QRect(margin, margin, tbopt->rect.width() - 2*margin, handleExtent);
+ }
+ }
+ }
+ break;
+#endif //QT_NO_TOOLBAR
default:
break;
}
@@ -3189,47 +3214,6 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
}
#ifndef QT_NO_DIAL
-static qreal angle(const QPointF &p1, const QPointF &p2)
-{
- static const qreal rad_factor = 180 / Q_PI;
- qreal _angle = 0;
-
- if (p1.x() == p2.x()) {
- if (p1.y() < p2.y())
- _angle = 270;
- else
- _angle = 90;
- } else {
- qreal x1, x2, y1, y2;
-
- if (p1.x() <= p2.x()) {
- x1 = p1.x(); y1 = p1.y();
- x2 = p2.x(); y2 = p2.y();
- } else {
- x2 = p1.x(); y2 = p1.y();
- x1 = p2.x(); y1 = p2.y();
- }
-
- qreal m = -(y2 - y1) / (x2 - x1);
- _angle = atan(m) * rad_factor;
-
- if (p1.x() < p2.x())
- _angle = 180 - _angle;
- else
- _angle = -_angle;
- }
- return _angle;
-}
-
-static int calcBigLineSize(int radius)
-{
- int bigLineSize = radius / 6;
- if (bigLineSize < 4)
- bigLineSize = 4;
- if (bigLineSize > radius / 2)
- bigLineSize = radius / 2;
- return bigLineSize;
-}
static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a)
{
@@ -3250,7 +3234,7 @@ static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a)
int xc = width / 2;
int yc = height / 2;
- int len = r - calcBigLineSize(r) - 5;
+ int len = r - QStyleHelper::calcBigLineSize(r) - 5;
if (len < 5)
len = 5;
int back = len / 2;
@@ -3265,45 +3249,6 @@ static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a)
return arrow;
}
-static QPolygonF calcLines(const QStyleOptionSlider *dial, const QWidget *)
-{
- QPolygonF poly;
- int width = dial->rect.width();
- int height = dial->rect.height();
- qreal r = qMin(width, height) / 2;
- int bigLineSize = calcBigLineSize(int(r));
-
- qreal xc = width / 2;
- qreal yc = height / 2;
- int ns = dial->tickInterval;
- int notches = (dial->maximum + ns - 1 - dial->minimum) / ns;
- if (notches <= 0)
- return poly;
- if (dial->maximum < dial->minimum
- || dial->maximum - dial->minimum > 1000) {
- int maximum = dial->minimum + 1000;
- notches = (maximum + ns - 1 - dial->minimum) / ns;
- }
-
- poly.resize(2 + 2 * notches);
- int smallLineSize = bigLineSize / 2;
- for (int i = 0; i <= notches; ++i) {
- qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
- : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6;
- qreal s = qSin(angle);
- qreal c = qCos(angle);
- if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
- poly[2 * i] = QPointF(xc + (r - bigLineSize) * c,
- yc - (r - bigLineSize) * s);
- poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s);
- } else {
- poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c,
- yc - (r - 1 - smallLineSize) * s);
- poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s);
- }
- }
- return poly;
-}
#endif // QT_NO_DIAL
/*!
@@ -3794,7 +3739,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
// draw notches
if (dial->subControls & QStyle::SC_DialTickmarks) {
p->setPen(pal.foreground().color());
- p->drawLines(calcLines(dial, widget)); // ### calcLines could be cached...
+ p->drawLines(QStyleHelper::calcLines(dial));
}
if (dial->state & State_Enabled) {
@@ -3816,7 +3761,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
p->setBrush(pal.button());
p->drawPolygon(arrow);
- a = angle(QPointF(width / 2, height / 2), arrow[0]);
+ a = QStyleHelper::angle(QPointF(width / 2, height / 2), arrow[0]);
p->setBrush(Qt::NoBrush);
if (a <= 0 || a > 200) {
diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm
index 7a870fe..5e538cb 100644
--- a/src/gui/styles/qmacstyle_mac.mm
+++ b/src/gui/styles/qmacstyle_mac.mm
@@ -50,6 +50,7 @@
#include <private/qpaintengine_mac_p.h>
#include <private/qpainter_p.h>
#include <private/qprintengine_mac_p.h>
+#include <private/qstylehelper_p.h>
#include <qapplication.h>
#include <qbitmap.h>
#include <qcheckbox.h>
@@ -125,6 +126,20 @@ static const QColor titlebarSeparatorLineInactive(131, 131, 131);
static const QColor mainWindowGradientBegin(240, 240, 240);
static const QColor mainWindowGradientEnd(200, 200, 200);
+#if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5)
+enum {
+ kThemePushButtonTextured = 31,
+ kThemePushButtonTexturedSmall = 32,
+ kThemePushButtonTexturedMini = 33
+};
+
+/* Search fields */
+enum {
+ kHIThemeFrameTextFieldRound = 1000,
+ kHIThemeFrameTextFieldRoundSmall = 1001,
+ kHIThemeFrameTextFieldRoundMini = 1002
+};
+#endif
// Resolve these at run-time, since the functions was moved in Leopard.
typedef HIRect * (*PtrHIShapeGetBounds)(HIShapeRef, HIRect *);
@@ -2643,6 +2658,9 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
case PM_MenuHMargin:
ret = 0;
break;
+ case PM_ToolBarFrameWidth:
+ ret = 0;
+ break;
default:
ret = QWindowsStyle::pixelMetric(metric, opt, widget);
break;
@@ -3638,7 +3656,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
QRect cr = tb->rect;
int shiftX = 0;
int shiftY = 0;
- if (tb->state & (State_Sunken | State_On)) {
+ bool needText = false;
+ int alignment = 0;
+ bool down = tb->state & (State_Sunken | State_On);
+ if (down) {
shiftX = pixelMetric(PM_ButtonShiftHorizontal, tb, w);
shiftY = pixelMetric(PM_ButtonShiftVertical, tb, w);
}
@@ -3646,51 +3667,76 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
// The text is a bit bolder and gets a drop shadow and the icons are also darkened.
// This doesn't really fit into any particular case in QIcon, so we
// do the majority of the work ourselves.
- if (tb->state & State_Sunken
- && !(tb->features & QStyleOptionToolButton::Arrow)) {
+ if (!(tb->features & QStyleOptionToolButton::Arrow)) {
Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
if (tb->icon.isNull() && !tb->text.isEmpty())
tbstyle = Qt::ToolButtonTextOnly;
switch (tbstyle) {
- case Qt::ToolButtonTextOnly:
- drawItemText(p, cr, Qt::AlignCenter, tb->palette,
- tb->state & State_Enabled, tb->text);
- break;
+ case Qt::ToolButtonTextOnly: {
+ needText = true;
+ alignment = Qt::AlignCenter;
+ break; }
case Qt::ToolButtonIconOnly:
case Qt::ToolButtonTextBesideIcon:
case Qt::ToolButtonTextUnderIcon: {
QRect pr = cr;
QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
- : QIcon::Disabled;
+ : QIcon::Disabled;
QIcon::State iconState = (tb->state & State_On) ? QIcon::On
- : QIcon::Off;
+ : QIcon::Off;
QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), iconMode, iconState);
// Draw the text if it's needed.
if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
- int alignment = 0;
+ needText = true;
if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
- pr.setHeight(pixmap.size().height() + 6);
- cr.adjust(0, pr.bottom(), 0, -3);
+ pr.setHeight(pixmap.size().height());
+ cr.adjust(0, pr.bottom() + 1, 0, 1);
alignment |= Qt::AlignCenter;
} else {
pr.setWidth(pixmap.width() + 8);
cr.adjust(pr.right(), 0, 0, 0);
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
}
- cr.translate(shiftX, shiftY);
- drawItemText(p, cr, alignment, tb->palette,
- tb->state & State_Enabled, tb->text);
- cr.adjust(0, 3, 0, -3); // the drop shadow
- drawItemText(p, cr, alignment, tb->palette,
- tb->state & State_Enabled, tb->text);
}
- pr.translate(shiftX, shiftY);
- pixmap = darkenPixmap(pixmap);
+ if (opt->state & State_Sunken) {
+ pr.translate(shiftX, shiftY);
+ pixmap = darkenPixmap(pixmap);
+ }
drawItemPixmap(p, pr, Qt::AlignCenter, pixmap);
break; }
}
+
+ if (needText) {
+ QPalette pal = tb->palette;
+ QPalette::ColorRole role = QPalette::NoRole;
+ if (down)
+ cr.translate(shiftX, shiftY);
+ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5
+ && (tbstyle == Qt::ToolButtonTextOnly
+ || (tbstyle != Qt::ToolButtonTextOnly && !down))) {
+ QPen pen = p->pen();
+ QColor light = down ? Qt::black : Qt::white;
+ light.setAlphaF(0.375f);
+ p->setPen(light);
+ p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text);
+ p->setPen(pen);
+ if (down && tbstyle == Qt::ToolButtonTextOnly) {
+ pal = QApplication::palette("QMenu");
+ pal.setCurrentColorGroup(tb->palette.currentColorGroup());
+ role = QPalette::HighlightedText;
+ }
+ }
+ drawItemText(p, cr, alignment, pal,
+ tb->state & State_Enabled, tb->text, role);
+ if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 &&
+ (tb->state & State_Sunken)) {
+ // Draw a "drop shadow" in earlier versions.
+ drawItemText(p, cr.adjusted(0, 1, 0, 1), alignment,
+ tb->palette, tb->state & State_Enabled, tb->text);
+ }
+ }
} else {
QWindowsStyle::drawControl(ce, &myTb, p, w);
}
@@ -4511,9 +4557,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
case CE_ToolBar: {
// For unified tool bars, draw nothing.
if (w) {
- if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window()))
+ if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
if (mainWindow->unifiedTitleAndToolBarOnMac())
break;
+ }
}
// draw background gradient
@@ -5239,16 +5286,22 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
drawToolbarButtonArrow(tb->rect, tds, cg);
}
if (tb->state & State_On) {
- QPen oldPen = p->pen();
- p->setPen(QColor(0, 0, 0, 0x3a));
- p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12));
- p->drawLine(tb->rect.left() + 1, tb->rect.top(),
- tb->rect.right() - 1, tb->rect.top());
- p->drawLine(tb->rect.left() + 1, tb->rect.bottom(),
- tb->rect.right() - 1, tb->rect.bottom());
- p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft());
- p->drawLine(tb->rect.topRight(), tb->rect.bottomRight());
- p->setPen(oldPen);
+ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
+ static QPixmap pm(QLatin1String(":/trolltech/mac/style/images/leopard-unified-toolbar-on.png"));
+ p->setRenderHint(QPainter::SmoothPixmapTransform);
+ QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2);
+ } else {
+ QPen oldPen = p->pen();
+ p->setPen(QColor(0, 0, 0, 0x3a));
+ p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12));
+ p->drawLine(tb->rect.left() + 1, tb->rect.top(),
+ tb->rect.right() - 1, tb->rect.top());
+ p->drawLine(tb->rect.left() + 1, tb->rect.bottom(),
+ tb->rect.right() - 1, tb->rect.bottom());
+ p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft());
+ p->drawLine(tb->rect.topRight(), tb->rect.bottomRight());
+ p->setPen(oldPen);
+ }
}
drawControl(CE_ToolButtonLabel, opt, p, widget);
} else {
@@ -5343,6 +5396,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
}
}
break;
+ case CC_Dial:
+ if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt))
+ QStyleHelper::drawDial(dial, p);
+ break;
default:
QWindowsStyle::drawComplexControl(cc, opt, p, widget);
break;
@@ -5984,6 +6041,14 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
}
break;
case CT_ToolButton:
+ if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) {
+ sz.rwidth() += 4;
+ if (sz.height() <= 32) {
+ // Workaround strange HIToolBar bug when getting constraints.
+ sz.rheight() += 1;
+ }
+ return sz;
+ }
sz.rwidth() += 10;
sz.rheight() += 10;
return sz;
diff --git a/src/gui/styles/qmotifstyle.cpp b/src/gui/styles/qmotifstyle.cpp
index 7d4fab8..be0e3eb 100644
--- a/src/gui/styles/qmotifstyle.cpp
+++ b/src/gui/styles/qmotifstyle.cpp
@@ -2026,10 +2026,6 @@ QMotifStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
QSize sz(contentsSize);
switch(ct) {
- case CT_Splitter:
- sz = QSize(10, 10);
- break;
-
case CT_RadioButton:
case CT_CheckBox:
sz = QCommonStyle::sizeFromContents(ct, opt, contentsSize, widget);
diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp
index 24d7748..66464ff 100644
--- a/src/gui/styles/qplastiquestyle.cpp
+++ b/src/gui/styles/qplastiquestyle.cpp
@@ -51,6 +51,7 @@ static const int ProgressBarFps = 25;
static const int blueFrameWidth = 2; // with of line edit focus frame
#include "qwindowsstyle_p.h"
+#include <private/qstylehelper_p.h>
#include <qapplication.h>
#include <qbitmap.h>
#include <qabstractitemview.h>
@@ -4970,6 +4971,12 @@ void QPlastiqueStyle::drawComplexControl(ComplexControl control, const QStyleOpt
painter->restore();
}
break;
+#ifndef QT_NO_DIAL
+ case CC_Dial:
+ if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
+ QStyleHelper::drawDial(dial, painter);
+ break;
+#endif // QT_NO_DIAL
default:
QWindowsStyle::drawComplexControl(control, option, painter, widget);
break;
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp
index 982f48f..514f67b 100644
--- a/src/gui/styles/qstyle.cpp
+++ b/src/gui/styles/qstyle.cpp
@@ -1048,6 +1048,8 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SE_TabBarTabRightButton Area for a widget on the right side of a tab in a tab bar.
\value SE_TabBarTabText Area for the text on a tab in a tab bar.
+ \value SE_ToolBarHandle Area for the handle of a tool bar.
+
\sa subElementRect()
*/
@@ -1330,7 +1332,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value PM_LayoutVerticalSpacing Default \l{QLayout::spacing}{vertical spacing} for a QLayout.
\value PM_MaximumDragDistance The maximum allowed distance between
- the mouse and a slider when dragging. Exceeding the specified
+ the mouse and a scrollbar when dragging. Exceeding the specified
distance will cause the slider to jump back to the original
position; a value of -1 disables this behavior.
diff --git a/src/gui/styles/qstyle.h b/src/gui/styles/qstyle.h
index 6191d51..cc92459 100644
--- a/src/gui/styles/qstyle.h
+++ b/src/gui/styles/qstyle.h
@@ -373,6 +373,8 @@ public:
SE_ShapedFrameContents,
+ SE_ToolBarHandle,
+
// do not add any values below/greater than this
SE_CustomBase = 0xf0000000
};
@@ -453,6 +455,7 @@ public:
SC_MdiNormalButton = 0x00000002,
SC_MdiCloseButton = 0x00000004,
+ SC_CustomBase = 0xf0000000,
SC_All = 0xffffffff
};
Q_DECLARE_FLAGS(SubControls, SubControl)
diff --git a/src/gui/styles/qstylehelper.cpp b/src/gui/styles/qstylehelper.cpp
new file mode 100644
index 0000000..69f8cd2
--- /dev/null
+++ b/src/gui/styles/qstylehelper.cpp
@@ -0,0 +1,353 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qstylehelper_p.h"
+
+#include <qstyleoption.h>
+#include <qpainter.h>
+#include <qpixmapcache.h>
+#include <private/qmath_p.h>
+#include <private/qstyle_p.h>
+#include <qmath.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QStyleHelper {
+const bool UsePixmapCache = true;
+
+QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size)
+{
+ QString tmp;
+ const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option);
+ tmp.sprintf("%s-%d-%d-%lld-%dx%d-%d", key.toLatin1().constData(), uint(option->state),
+ complexOption ? uint(complexOption->activeSubControls) : uint(0),
+ option->palette.cacheKey(), size.width(), size.height(), option->direction);
+#ifndef QT_NO_SPINBOX
+ if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
+ tmp.append(QLatin1Char('-'));
+ tmp.append(QString::number(spinBox->buttonSymbols));
+ tmp.append(QLatin1Char('-'));
+ tmp.append(QString::number(spinBox->stepEnabled));
+ tmp.append(QLatin1Char('-'));
+ tmp.append(QLatin1Char(spinBox->frame ? '1' : '0'));
+ }
+#endif // QT_NO_SPINBOX
+ return tmp;
+}
+
+#ifndef QT_NO_DIAL
+
+int calcBigLineSize(int radius)
+{
+ int bigLineSize = radius / 6;
+ if (bigLineSize < 4)
+ bigLineSize = 4;
+ if (bigLineSize > radius / 2)
+ bigLineSize = radius / 2;
+ return bigLineSize;
+}
+
+static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset)
+{
+ const int width = dial->rect.width();
+ const int height = dial->rect.height();
+ const int r = qMin(width, height) / 2;
+ const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
+ qreal a = 0;
+ if (dial->maximum == dial->minimum)
+ a = Q_PI / 2;
+ else if (dial->dialWrapping)
+ a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI
+ / (dial->maximum - dial->minimum);
+ else
+ a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI
+ / (dial->maximum - dial->minimum)) / 6;
+ qreal xc = width / 2.0;
+ qreal yc = height / 2.0;
+ qreal len = r - QStyleHelper::calcBigLineSize(r) - 3;
+ qreal back = offset * len;
+ QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a)));
+ return pos;
+}
+
+qreal angle(const QPointF &p1, const QPointF &p2)
+{
+ static const qreal rad_factor = 180 / Q_PI;
+ qreal _angle = 0;
+
+ if (p1.x() == p2.x()) {
+ if (p1.y() < p2.y())
+ _angle = 270;
+ else
+ _angle = 90;
+ } else {
+ qreal x1, x2, y1, y2;
+
+ if (p1.x() <= p2.x()) {
+ x1 = p1.x(); y1 = p1.y();
+ x2 = p2.x(); y2 = p2.y();
+ } else {
+ x2 = p1.x(); y2 = p1.y();
+ x1 = p2.x(); y1 = p2.y();
+ }
+
+ qreal m = -(y2 - y1) / (x2 - x1);
+ _angle = atan(m) * rad_factor;
+
+ if (p1.x() < p2.x())
+ _angle = 180 - _angle;
+ else
+ _angle = -_angle;
+ }
+ return _angle;
+}
+
+QPolygonF calcLines(const QStyleOptionSlider *dial)
+{
+ QPolygonF poly;
+ int width = dial->rect.width();
+ int height = dial->rect.height();
+ qreal r = qMin(width, height) / 2;
+ int bigLineSize = calcBigLineSize(int(r));
+
+ qreal xc = width / 2 + 0.5;
+ qreal yc = height / 2 + 0.5;
+ int ns = dial->tickInterval;
+ int notches = (dial->maximum + ns - 1 - dial->minimum) / ns;
+ if (notches <= 0)
+ return poly;
+ if (dial->maximum < dial->minimum || dial->maximum - dial->minimum > 1000) {
+ int maximum = dial->minimum + 1000;
+ notches = (maximum + ns - 1 - dial->minimum) / ns;
+ }
+
+ poly.resize(2 + 2 * notches);
+ int smallLineSize = bigLineSize / 2;
+ for (int i = 0; i <= notches; ++i) {
+ qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
+ : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6;
+ qreal s = qSin(angle);
+ qreal c = qCos(angle);
+ if (i == 0 || (((ns * i) % (dial->pageStep ? dial->pageStep : 1)) == 0)) {
+ poly[2 * i] = QPointF(xc + (r - bigLineSize) * c,
+ yc - (r - bigLineSize) * s);
+ poly[2 * i + 1] = QPointF(xc + r * c, yc - r * s);
+ } else {
+ poly[2 * i] = QPointF(xc + (r - 1 - smallLineSize) * c,
+ yc - (r - 1 - smallLineSize) * s);
+ poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s);
+ }
+ }
+ return poly;
+}
+
+
+// This will draw a nice and shiny QDial for us. We don't want
+// all the shinyness in QWindowsStyle, hence we place it here
+
+void drawDial(const QStyleOptionSlider *option, QPainter *painter)
+{
+ QPalette pal = option->palette;
+ QColor buttonColor = pal.button().color();
+ const int width = option->rect.width();
+ const int height = option->rect.height();
+ const bool enabled = option->state & QStyle::State_Enabled;
+ qreal r = qMin(width, height) / 2;
+ r -= r/50;
+ const qreal penSize = r/20.0;
+
+ painter->save();
+ painter->setRenderHint(QPainter::Antialiasing);
+
+ // Draw notches
+ if (option->subControls & QStyle::SC_DialTickmarks) {
+ painter->setPen(option->palette.dark().color().darker(120));
+ painter->drawLines(QStyleHelper::calcLines(option));
+ }
+
+ // Cache dial background
+ BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial"));
+ p->setRenderHint(QPainter::Antialiasing);
+
+ const qreal d_ = r / 6;
+ const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1;
+ const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1;
+
+ QRectF br = QRectF(dx + 0.5, dy + 0.5,
+ int(r * 2 - 2 * d_ - 2),
+ int(r * 2 - 2 * d_ - 2));
+ buttonColor.setHsv(buttonColor .hue(),
+ qMin(140, buttonColor .saturation()),
+ qMax(180, buttonColor.value()));
+ QColor shadowColor(0, 0, 0, 20);
+
+ if (enabled) {
+ // Drop shadow
+ qreal shadowSize = qMax(1.0, penSize/2.0);
+ QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize,
+ 2*shadowSize, 2*shadowSize);
+ QRadialGradient shadowGradient(shadowRect.center().x(),
+ shadowRect.center().y(), shadowRect.width()/2.0,
+ shadowRect.center().x(), shadowRect.center().y());
+ shadowGradient.setColorAt(0.91, QColor(0, 0, 0, 40));
+ shadowGradient.setColorAt(1.0, Qt::transparent);
+ p->setBrush(shadowGradient);
+ p->setPen(Qt::NoPen);
+ p->translate(shadowSize, shadowSize);
+ p->drawEllipse(shadowRect);
+ p->translate(-shadowSize, -shadowSize);
+
+ // Main gradient
+ QRadialGradient gradient(br.center().x() - br.width()/3, dy,
+ br.width()*1.3, br.center().x(),
+ br.center().y() - br.height()/2);
+ gradient.setColorAt(0, buttonColor.lighter(110));
+ gradient.setColorAt(0.5, buttonColor);
+ gradient.setColorAt(0.501, buttonColor.darker(102));
+ gradient.setColorAt(1, buttonColor.darker(115));
+ p->setBrush(gradient);
+ } else {
+ p->setBrush(Qt::NoBrush);
+ }
+
+ p->setPen(QPen(buttonColor.darker(280)));
+ p->drawEllipse(br);
+ p->setBrush(Qt::NoBrush);
+ p->setPen(buttonColor.lighter(110));
+ p->drawEllipse(br.adjusted(1, 1, -1, -1));
+
+ if (option->state & QStyle::State_HasFocus) {
+ QColor highlight = pal.highlight().color();
+ highlight.setHsv(highlight.hue(),
+ qMin(160, highlight.saturation()),
+ qMax(230, highlight.value()));
+ highlight.setAlpha(127);
+ p->setPen(QPen(highlight, 2.0));
+ p->setBrush(Qt::NoBrush);
+ p->drawEllipse(br.adjusted(-1, -1, 1, 1));
+ }
+
+ END_STYLE_PIXMAPCACHE
+
+ QPointF dp = calcRadialPos(option, 0.70);
+ buttonColor = buttonColor.lighter(104);
+ buttonColor.setAlphaF(0.8);
+ const qreal ds = r/7.0;
+ QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds);
+ QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2,
+ dialRect.center().y() + dialRect.width(),
+ dialRect.width()*2,
+ dialRect.center().x(), dialRect.center().y());
+ dialGradient.setColorAt(1, buttonColor.darker(140));
+ dialGradient.setColorAt(0.4, buttonColor.darker(120));
+ dialGradient.setColorAt(0, buttonColor.darker(110));
+ if (penSize > 3.0) {
+ painter->setPen(QPen(QColor(0, 0, 0, 25), penSize));
+ painter->drawLine(calcRadialPos(option, 0.90), calcRadialPos(option, 0.96));
+ }
+
+ painter->setBrush(dialGradient);
+ painter->setPen(QColor(255, 255, 255, 150));
+ painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1));
+ painter->setPen(QColor(0, 0, 0, 80));
+ painter->drawEllipse(dialRect);
+ painter->restore();
+}
+#endif //QT_NO_DIAL
+
+void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect,
+ int left, int top, int right,
+ int bottom)
+{
+ QSize size = pixmap.size();
+ //painter->setRenderHint(QPainter::SmoothPixmapTransform);
+
+ //top
+ if (top > 0) {
+ painter->drawPixmap(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), pixmap,
+ QRect(left, 0, size.width() -right - left, top));
+
+ //top-left
+ if(left > 0)
+ painter->drawPixmap(QRect(rect.left(), rect.top(), left, top), pixmap,
+ QRect(0, 0, left, top));
+
+ //top-right
+ if (right > 0)
+ painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top(), right, top), pixmap,
+ QRect(size.width() - right, 0, right, top));
+ }
+
+ //left
+ if (left > 0)
+ painter->drawPixmap(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), pixmap,
+ QRect(0, top, left, size.height() - bottom - top));
+
+ //center
+ painter->drawPixmap(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left,
+ rect.height() - bottom - top), pixmap,
+ QRect(left, top, size.width() -right -left,
+ size.height() - bottom - top));
+ //right
+ if (right > 0)
+ painter->drawPixmap(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), pixmap,
+ QRect(size.width() - right, top, right, size.height() - bottom - top));
+
+ //bottom
+ if (bottom > 0) {
+ painter->drawPixmap(QRect(rect.left() +left, rect.top() + rect.height() - bottom,
+ rect.width() - right - left, bottom), pixmap,
+ QRect(left, size.height() - bottom,
+ size.width() - right - left, bottom));
+ //bottom-left
+ if (left > 0)
+ painter->drawPixmap(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), pixmap,
+ QRect(0, size.height() - bottom, left, bottom));
+
+ //bottom-right
+ if (right > 0)
+ painter->drawPixmap(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), pixmap,
+ QRect(size.width() - right, size.height() - bottom, right, bottom));
+
+ }
+}
+}
+QT_END_NAMESPACE
diff --git a/src/gui/painting/qwindowsurface_d3d_p.h b/src/gui/styles/qstylehelper_p.h
index 9cdfe29..5385d9f 100644
--- a/src/gui/painting/qwindowsurface_d3d_p.h
+++ b/src/gui/styles/qstylehelper_p.h
@@ -39,46 +39,46 @@
**
****************************************************************************/
-#ifndef QWINDOWSURFACE_D3D_P_H
-#define QWINDOWSURFACE_D3D_P_H
+#include <QtCore/qglobal.h>
+#include <QtCore/qpoint.h>
+#include <QtGui/qpolygon.h>
+
+#ifndef QSTYLEHELPER_P_H
+#define QSTYLEHELPER_P_H
//
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. It exists for the convenience
-// of the QLibrary class. This header file may change from
-// version to version without notice, or even be removed.
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
//
// We mean it.
//
-#include <qglobal.h>
-#include "private/qwindowsurface_p.h"
-
QT_BEGIN_NAMESPACE
-class QPaintDevice;
-class QPoint;
-class QRegion;
-class QWidget;
-struct QD3DWindowSurfacePrivate;
+class QPainter;
+class QPixmap;
+class QStyleOptionSlider;
+class QStyleOption;
-class QD3DWindowSurface : public QWindowSurface
+namespace QStyleHelper
{
-public:
- QD3DWindowSurface(QWidget *widget);
- ~QD3DWindowSurface();
-
- QPaintDevice *paintDevice();
- void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
- void setGeometry(const QRect &rect);
- bool scroll(const QRegion &area, int dx, int dy);
-
-private:
- QD3DWindowSurfacePrivate *d_ptr;
-};
+ extern const bool UsePixmapCache;
+ QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size);
+#ifndef QT_NO_DIAL
+ qreal angle(const QPointF &p1, const QPointF &p2);
+ QPolygonF calcLines(const QStyleOptionSlider *dial);
+ int calcBigLineSize(int radius);
+ void drawDial(const QStyleOptionSlider *dial, QPainter *painter);
+#endif //QT_NO_DIAL
+ void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect,
+ int left = 0, int top = 0, int right = 0,
+ int bottom = 0);
+}
QT_END_NAMESPACE
-#endif // QWINDOWSURFACE_D3D_P_H
+#endif // QSTYLEHELPER_P_H
diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp
index ce053ae..5b1bc61 100644
--- a/src/gui/styles/qstyleoption.cpp
+++ b/src/gui/styles/qstyleoption.cpp
@@ -48,6 +48,7 @@
#ifndef QT_NO_DEBUG
#include <qdebug.h>
#endif
+#include <QtCore/qmath.h>
QT_BEGIN_NAMESPACE
@@ -4998,6 +4999,34 @@ QStyleOptionGraphicsItem::QStyleOptionGraphicsItem(int version)
}
/*!
+ \since 4.6
+
+ Returns the level of detail from the \a worldTransform.
+
+ Its value represents the maximum value of the height and
+ width of a unity rectangle, mapped using the \a worldTransform
+ of the painter used to draw the item. By default, if no
+ transformations are applied, its value is 1. If zoomed out 1:2, the level
+ of detail will be 0.5, and if zoomed in 2:1, its value is 2.
+
+ For more advanced level-of-detail metrics, use
+ QStyleOptionGraphicsItem::matrix directly.
+
+ \sa QStyleOptionGraphicsItem::matrix
+*/
+qreal QStyleOptionGraphicsItem::levelOfDetailFromTransform(const QTransform &worldTransform)
+{
+ if (worldTransform.type() <= QTransform::TxTranslate)
+ return 1; // Translation only? The LOD is 1.
+
+ // Two unit vectors.
+ QLineF v1(0, 0, 1, 0);
+ QLineF v2(0, 0, 0, 1);
+ // LOD is the transformed area of a 1x1 rectangle.
+ return qSqrt(worldTransform.map(v1).length() * worldTransform.map(v2).length());
+}
+
+/*!
\fn QStyleOptionGraphicsItem::QStyleOptionGraphicsItem(const QStyleOptionGraphicsItem &other)
Constructs a copy of \a other.
@@ -5029,19 +5058,10 @@ QStyleOptionGraphicsItem::QStyleOptionGraphicsItem(int version)
/*!
\variable QStyleOptionGraphicsItem::levelOfDetail
- \brief a simple metric for determining an item's level of detail
-
- This simple metric provides an easy way to determine the level of detail
- for an item. Its value represents the maximum value of the height and
- width of a unity rectangle, mapped using the complete transformation
- matrix of the painter used to draw the item. By default, if no
- transformations are applied, its value is 1. If zoomed out 1:2, the level
- of detail will be 0.5, and if zoomed in 2:1, its value is 2.
-
- For more advanced level-of-detail metrics, use
- QStyleOptionGraphicsItem::matrix directly.
+ \obsolete
- \sa QStyleOptionGraphicsItem::matrix
+ Use QStyleOptionGraphicsItem::levelOfDetailFromTransform
+ together with QPainter::worldTransform() instead.
*/
/*!
diff --git a/src/gui/styles/qstyleoption.h b/src/gui/styles/qstyleoption.h
index 5759a05..eb05324 100644
--- a/src/gui/styles/qstyleoption.h
+++ b/src/gui/styles/qstyleoption.h
@@ -856,6 +856,7 @@ public:
QStyleOptionGraphicsItem();
QStyleOptionGraphicsItem(const QStyleOptionGraphicsItem &other) : QStyleOption(Version, Type) { *this = other; }
+ static qreal levelOfDetailFromTransform(const QTransform &worldTransform);
protected:
QStyleOptionGraphicsItem(int version);
};
diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp
index 714b8c5..fdd51c3 100644
--- a/src/gui/styles/qstylesheetstyle.cpp
+++ b/src/gui/styles/qstylesheetstyle.cpp
@@ -81,6 +81,7 @@
#include <private/qwidget_p.h>
#include <QAbstractSpinBox>
#include <QLabel>
+#include "qdrawutil.h"
#include <limits.h>
@@ -312,15 +313,10 @@ struct QStyleSheetBorderImageData : public QSharedData
for (int i = 0; i < 4; i++)
cuts[i] = -1;
}
- QPixmap topEdge, bottomEdge, leftEdge, rightEdge, middle;
- QRect topEdgeRect, bottomEdgeRect, leftEdgeRect, rightEdgeRect, middleRect;
- QRect topLeftCorner, topRightCorner, bottomRightCorner, bottomLeftCorner;
int cuts[4];
QPixmap pixmap;
QImage image;
QCss::TileMode horizStretch, vertStretch;
-
- void cutBorderImage();
};
struct QStyleSheetBackgroundData : public QSharedData
@@ -1122,176 +1118,27 @@ void QRenderRule::fixupBorder(int nativeWidth)
for (int i = 0; i < 4; i++) // assume, cut = border
bi->cuts[i] = int(border()->borders[i]);
}
- bi->cutBorderImage();
-}
-
-void QStyleSheetBorderImageData::cutBorderImage()
-{
- const int w = pixmap.width();
- const int h = pixmap.height();
- const int &l = cuts[LeftEdge], &r = cuts[RightEdge],
- &t = cuts[TopEdge], &b = cuts[BottomEdge];
-
- topEdgeRect = QRect(l, 0, w - r - l, t);
- bottomEdgeRect = QRect(l, h - b, w - l - r, b);
- if (horizStretch != TileMode_Stretch) {
- if (topEdgeRect.isValid())
- topEdge = pixmap.copy(topEdgeRect).scaledToHeight(t);
- if (bottomEdgeRect.isValid())
- bottomEdge = pixmap.copy(bottomEdgeRect).scaledToHeight(b);
- }
-
- leftEdgeRect = QRect(0, t, l, h - b - t);
- rightEdgeRect = QRect(w - r, t, r, h - t- b);
- if (vertStretch != TileMode_Stretch) {
- if (leftEdgeRect.isValid())
- leftEdge = pixmap.copy(leftEdgeRect).scaledToWidth(l);
- if (rightEdgeRect.isValid())
- rightEdge = pixmap.copy(rightEdgeRect).scaledToWidth(r);
- }
-
- middleRect = QRect(l, t, w - r -l, h - t - b);
- if (middleRect.isValid()
- && !(horizStretch == TileMode_Stretch && vertStretch == TileMode_Stretch)) {
- middle = pixmap.copy(middleRect);
- }
}
-static void qDrawCenterTiledPixmap(QPainter *p, const QRectF& r, const QPixmap& pix)
-{
- p->drawTiledPixmap(r, pix, QPoint(pix.width() - int(r.width())%pix.width(),
- pix.height() - int(r.height())%pix.height()));
-}
-
-// Note: Round is not supported
void QRenderRule::drawBorderImage(QPainter *p, const QRect& rect)
{
- setClip(p, rect);
- const QRectF br(rect);
- const int *borders = border()->borders;
- const int &l = borders[LeftEdge], &r = borders[RightEdge],
- &t = borders[TopEdge], &b = borders[BottomEdge];
- QRectF pr = br.adjusted(l, t, -r, -b);
+ static const Qt::TileRule tileMode2TileRule[] = {
+ Qt::Stretch, Qt::Round, Qt::Stretch, Qt::Repeat, Qt::Stretch };
+
+ const QStyleSheetBorderImageData *borderImageData = border()->borderImage();
+ const int *targetBorders = border()->borders;
+ const int *sourceBorders = borderImageData->cuts;
+ QMargins sourceMargins(sourceBorders[TopEdge], sourceBorders[LeftEdge],
+ sourceBorders[BottomEdge], sourceBorders[RightEdge]);
+ QMargins targetMargins(targetBorders[TopEdge], targetBorders[LeftEdge],
+ targetBorders[BottomEdge], targetBorders[RightEdge]);
bool wasSmoothPixmapTransform = p->renderHints() & QPainter::SmoothPixmapTransform;
p->setRenderHint(QPainter::SmoothPixmapTransform);
-
- const QStyleSheetBorderImageData *bi = border()->borderImage();
- const QPixmap& pix = bi->pixmap;
- const int *c = bi->cuts;
- QRectF tlc(0, 0, c[LeftEdge], c[TopEdge]);
- if (tlc.isValid())
- p->drawPixmap(QRectF(br.topLeft(), QSizeF(l, t)), pix, tlc);
- QRectF trc(pix.width() - c[RightEdge], 0, c[RightEdge], c[TopEdge]);
- if (trc.isValid())
- p->drawPixmap(QRectF(br.left() + br.width() - r, br.y(), r, t), pix, trc);
- QRectF blc(0, pix.height() - c[BottomEdge], c[LeftEdge], c[BottomEdge]);
- if (blc.isValid())
- p->drawPixmap(QRectF(br.x(), br.y() + br.height() - b, l, b), pix, blc);
- QRectF brc(pix.width() - c[RightEdge], pix.height() - c[BottomEdge],
- c[RightEdge], c[BottomEdge]);
- if (brc.isValid())
- p->drawPixmap(QRectF(br.x() + br.width() - r, br.y() + br.height() - b, r, b),
- pix, brc);
-
- QRectF topEdgeRect(br.x() + l, br.y(), pr.width(), t);
- QRectF bottomEdgeRect(br.x() + l, br.y() + br.height() - b, pr.width(), b);
-
- switch (bi->horizStretch) {
- case TileMode_Stretch:
- if (bi->topEdgeRect.isValid())
- p->drawPixmap(topEdgeRect, pix, bi->topEdgeRect);
- if (bi->bottomEdgeRect.isValid())
- p->drawPixmap(bottomEdgeRect, pix, bi->bottomEdgeRect);
- if (bi->middleRect.isValid()) {
- if (bi->vertStretch == TileMode_Stretch)
- p->drawPixmap(pr, pix, bi->middleRect);
- else if (bi->vertStretch == TileMode_Repeat) {
- QPixmap scaled = bi->middle.scaled(int(pr.width()), bi->middle.height());
- qDrawCenterTiledPixmap(p, pr, scaled);
- }
- }
- break;
- case TileMode_Repeat:
- if (!bi->topEdge.isNull() && !topEdgeRect.isEmpty()) {
- QPixmap scaled = bi->topEdge.scaled(bi->topEdge.width(), t);
- qDrawCenterTiledPixmap(p, topEdgeRect, scaled);
- }
- if (!bi->bottomEdge.isNull() && !bottomEdgeRect.isEmpty()) {
- QPixmap scaled = bi->bottomEdge.scaled(bi->bottomEdge.width(), b);
- qDrawCenterTiledPixmap(p, bottomEdgeRect, scaled);
- }
- if (bi->middleRect.isValid()) {
- if (bi->vertStretch == TileMode_Repeat) {
- qDrawCenterTiledPixmap(p, pr, bi->middle);
- } else if (bi->vertStretch == TileMode_Stretch) {
- QPixmap scaled = bi->middle.scaled(bi->middle.width(), int(pr.height()));
- qDrawCenterTiledPixmap(p, pr, scaled);
- }
- }
- break;
- case TileMode_Round:
- if (!bi->topEdge.isNull()) {
- int rwh = (int)pr.width()/ceil(pr.width()/bi->topEdge.width());
- QPixmap scaled = bi->topEdge.scaled(rwh, bi->topEdge.height());
- int blank = int(pr.width()) % rwh;
- p->drawTiledPixmap(QRectF(br.x() + l + blank/2, br.y(), pr.width() - blank, t),
- scaled);
- }
- if (!bi->bottomEdge.isNull()) {
- int rwh = (int) pr.width()/ceil(pr.width()/bi->bottomEdge.width());
- QPixmap scaled = bi->bottomEdge.scaled(rwh, bi->bottomEdge.height());
- int blank = int(pr.width()) % rwh;
- p->drawTiledPixmap(QRectF(br.x() + l+ blank/2, br.y()+br.height()-b,
- pr.width() - blank, b), scaled);
- }
- break;
- default:
- break;
- }
-
- QRectF leftEdgeRect(br.x(), br.y() + t, l, pr.height());
- QRectF rightEdgeRect(br.x() + br.width()- r, br.y() + t, r, pr.height());
-
- switch (bi->vertStretch) {
- case TileMode_Stretch:
- if (bi->leftEdgeRect.isValid())
- p->drawPixmap(leftEdgeRect, pix, bi->leftEdgeRect);
- if (bi->rightEdgeRect.isValid())
- p->drawPixmap(rightEdgeRect, pix, bi->rightEdgeRect);
- break;
- case TileMode_Repeat:
- if (!bi->leftEdge.isNull() && !leftEdgeRect.isEmpty()) {
- QPixmap scaled = bi->leftEdge.scaled(l, bi->leftEdge.height());
- qDrawCenterTiledPixmap(p, leftEdgeRect, scaled);
- }
- if (!bi->rightEdge.isNull() && !rightEdgeRect.isEmpty()) {
- QPixmap scaled = bi->rightEdge.scaled(r, bi->rightEdge.height());
- qDrawCenterTiledPixmap(p, rightEdgeRect, scaled);
- }
- break;
- case TileMode_Round:
- if (!bi->leftEdge.isNull()) {
- int rwh = (int) pr.height()/ceil(pr.height()/bi->leftEdge.height());
- QPixmap scaled = bi->leftEdge.scaled(bi->leftEdge.width(), rwh);
- int blank = int(pr.height()) % rwh;
- p->drawTiledPixmap(QRectF(br.x(), br.y() + t + blank/2, l, pr.height() - blank),
- scaled);
- }
- if (!bi->rightEdge.isNull()) {
- int rwh = (int) pr.height()/ceil(pr.height()/bi->rightEdge.height());
- QPixmap scaled = bi->rightEdge.scaled(bi->rightEdge.width(), rwh);
- int blank = int(pr.height()) % rwh;
- p->drawTiledPixmap(QRectF(br.x() + br.width() - r, br.y()+t+blank/2, r,
- pr.height() - blank), scaled);
- }
- break;
- default:
- break;
- }
-
+ qDrawBorderPixmap(p, rect, targetMargins, borderImageData->pixmap,
+ QRect(QPoint(), borderImageData->pixmap.size()), sourceMargins,
+ QTileRules(tileMode2TileRule[borderImageData->horizStretch], tileMode2TileRule[borderImageData->vertStretch]));
p->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothPixmapTransform);
- unsetClip(p);
}
QRect QRenderRule::originRect(const QRect &rect, Origin origin) const
@@ -1525,7 +1372,7 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q
/* For embedded widgets (ComboBox, SpinBox and ScrollArea) we want the embedded widget
* to be transparent when we have a transparent background or border image */
if ((hasBackground() && background()->isTransparent())
- || (hasBorder() && border()->hasBorderImage() && border()->borderImage()->middleRect.isValid()))
+ || (hasBorder() && border()->hasBorderImage() && !border()->borderImage()->pixmap.isNull()))
p->setBrush(cg, w->backgroundRole(), Qt::NoBrush);
}
@@ -2876,12 +2723,6 @@ void QStyleSheetStyle::polish(QWidget *w)
QRenderRule rule = renderRule(w, PseudoElement_None, PseudoClass_Any);
if (rule.hasDrawable() || rule.hasBox()) {
if (w->metaObject() == &QWidget::staticMetaObject
-#ifndef QT_NO_MENUBAR
- || qobject_cast<QMenuBar *>(w)
-#endif
-#ifndef QT_NO_MENU
- || qobject_cast<QMenu *>(w)
-#endif
#ifndef QT_NO_ITEMVIEWS
|| qobject_cast<QHeaderView *>(w)
#endif
@@ -3189,6 +3030,7 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC
if (const QStyleOptionToolButton *tool = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
QStyleOptionToolButton toolOpt(*tool);
rule.configurePalette(&toolOpt.palette, QPalette::ButtonText, QPalette::Button);
+ toolOpt.font = rule.font.resolve(toolOpt.font);
toolOpt.rect = rule.borderRect(opt->rect);
bool customArrow = (tool->features & (QStyleOptionToolButton::HasMenu | QStyleOptionToolButton::MenuButtonPopup));
bool customDropDown = tool->features & QStyleOptionToolButton::MenuButtonPopup;
@@ -4164,9 +4006,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
rule.configurePalette(&frmOpt.palette, QPalette::Text, QPalette::Base);
frmOpt.rect = rule.borderRect(frmOpt.rect);
baseStyle()->drawControl(ce, &frmOpt, p, w);
- } else {
- rule.drawBorder(p, rule.borderRect(opt->rect));
}
+ // else, borders are already drawn in PE_Widget
}
return;
@@ -4220,12 +4061,6 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
QRect rect = opt->rect;
switch (pe) {
- case PE_PanelStatusBar:
- if (rule.hasDrawable()) {
- rule.drawRule(p, opt->rect);
- return;
- }
- break;
case PE_FrameStatusBar: {
QRenderRule subRule = renderRule(w->parentWidget(), opt, PseudoElement_Item);
@@ -4337,36 +4172,34 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
return;
case PE_Widget:
- if (!rule.hasBackground()) {
+ if (!rule.hasDrawable()) {
QWidget *container = containerWidget(w);
if (autoFillDisabledWidgets->contains(container)
- && (container == w || !renderRule(container, opt).hasBackground())) {
+ && (container == w || !renderRule(container, opt).hasDrawable())) {
//we do not have a background, but we disabled the autofillbackground anyway. so fill the background now.
// (this may happen if we have rules like :focus)
p->fillRect(opt->rect, opt->palette.brush(w->backgroundRole()));
}
break;
}
-
#ifndef QT_NO_SCROLLAREA
if (const QAbstractScrollArea *sa = qobject_cast<const QAbstractScrollArea *>(w)) {
const QAbstractScrollAreaPrivate *sap = sa->d_func();
rule.drawBackground(p, opt->rect, sap->contentsOffset());
- } else
-#endif
- {
- rule.drawBackground(p, opt->rect);
+ if (rule.hasBorder())
+ rule.drawBorder(p, rule.borderRect(opt->rect));
+ break;
}
-
- return;
-
- case PE_FrameMenu:
+#endif
+ //fall tghought
+ case PE_PanelMenu:
case PE_PanelMenuBar:
- if (!rule.hasNativeBorder()) {
- rule.drawBorder(p, rule.borderRect(opt->rect));
+ case PE_PanelStatusBar:
+ if(rule.hasDrawable()) {
+ rule.drawRule(p, opt->rect);
return;
}
- break;
+ break;
case PE_IndicatorToolBarSeparator:
case PE_IndicatorToolBarHandle: {
@@ -4973,13 +4806,10 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
if ((pe == PseudoElement_MenuSeparator) && subRule.hasContentsSize()) {
return QSize(sz.width(), subRule.size().height());
} else if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder())) {
- int width = csz.width(), height = qMax(csz.height(), mi->fontMetrics.height());
- if (!mi->icon.isNull()) {
- int iconExtent = pixelMetric(PM_SmallIconSize);
- height = qMax(height, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height());
- }
- width += mi->tabWidth;
- return subRule.boxSize(csz.expandedTo(subRule.minimumContentsSize()));
+ int width = csz.width();
+ if (mi->text.contains(QLatin1Char('\t')))
+ width += 12; //as in QCommonStyle
+ return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height())));
}
}
break;
@@ -5887,13 +5717,11 @@ void QStyleSheetStyle::clearWidgetFont(QWidget* w) const
w->setProperty("_q_styleSheetWidgetFont", QVariant(QVariant::Invalid));
}
-// Returns the palette that should be used when the particular widget is focused.
-// This needs to be called by some widgets that do drawing themselves instead
-// of through the style.
-// ### This should be removed ideally by Qt 4.5, and at least by Qt 5, and fixed
-// for good by letting the style draw everything.
+// Polish palette that should be used for a particular widget, with particular states
+// (eg. :focus, :hover, ...)
+// this is called by widgets that paint themself in their paint event
// Returns true if there is a new palette in pal.
-bool QStyleSheetStyle::focusPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)
+bool QStyleSheetStyle::styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)
{
if (!w || !opt || !pal)
return false;
diff --git a/src/gui/styles/qstylesheetstyle_p.h b/src/gui/styles/qstylesheetstyle_p.h
index 1f61445..e057274 100644
--- a/src/gui/styles/qstylesheetstyle_p.h
+++ b/src/gui/styles/qstylesheetstyle_p.h
@@ -131,7 +131,7 @@ public:
void saveWidgetFont(QWidget* w, const QFont& font) const;
void clearWidgetFont(QWidget* w) const;
- bool focusPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal);
+ bool styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal);
protected Q_SLOTS:
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt = 0,
diff --git a/src/gui/styles/qwindowsmobilestyle.cpp b/src/gui/styles/qwindowsmobilestyle.cpp
index 1c03b9e..f56d46c 100644
--- a/src/gui/styles/qwindowsmobilestyle.cpp
+++ b/src/gui/styles/qwindowsmobilestyle.cpp
@@ -72,12 +72,12 @@
#include "qdebug.h"
#include "qtabwidget.h"
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include "qt_windows.h"
#include "qguifunctions_wince.h"
extern bool qt_wince_is_high_dpi(); //defined in qguifunctions_wince.cpp
extern bool qt_wince_is_smartphone(); //defined in qguifunctions_wince.cpp
-#endif // Q_OS_WINCE
+#endif // Q_WS_WINCE
QT_BEGIN_NAMESPACE
@@ -685,13 +685,13 @@ QWindowsMobileStyle::QWindowsMobileStyle() : QWindowsStyle(*new QWindowsMobileSt
QWindowsMobileStylePrivate::QWindowsMobileStylePrivate() :QWindowsStylePrivate() {
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
doubleControls = qt_wince_is_high_dpi();
smartphone = qt_wince_is_smartphone();
#else
doubleControls = false;
smartphone = false;
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
#ifndef QT_NO_IMAGEFORMAT_XPM
diff --git a/src/gui/styles/qwindowsstyle.cpp b/src/gui/styles/qwindowsstyle.cpp
index 00c3f99..bf3a3cb 100644
--- a/src/gui/styles/qwindowsstyle.cpp
+++ b/src/gui/styles/qwindowsstyle.cpp
@@ -67,6 +67,9 @@
#include "qpixmapcache.h"
#include "qwizard.h"
#include "qlistview.h"
+#include <private/qmath_p.h>
+#include <qmath.h>
+
#ifdef Q_WS_X11
#include "qfileinfo.h"
@@ -3177,6 +3180,7 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp
}
break;
#endif // QT_NO_SPINBOX
+
default:
QCommonStyle::drawComplexControl(cc, opt, p, widget);
}
diff --git a/src/gui/styles/qwindowsxpstyle.cpp b/src/gui/styles/qwindowsxpstyle.cpp
index 2f4254e..3dac9f5 100644
--- a/src/gui/styles/qwindowsxpstyle.cpp
+++ b/src/gui/styles/qwindowsxpstyle.cpp
@@ -46,6 +46,7 @@
#include <private/qobject_p.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qapplication_p.h>
+#include <private/qstylehelper_p.h>
#include <qlibrary.h>
#include <qpainter.h>
#include <qpaintengine.h>
@@ -1791,7 +1792,12 @@ case PE_Frame:
return;
case PE_IndicatorToolBarSeparator:
-
+ if (option->rect.height() < 3) {
+ // XP style requires a few pixels for the separator
+ // to be visible.
+ QWindowsStyle::drawPrimitive(pe, option, p, widget);
+ return;
+ }
name = QLatin1String("TOOLBAR");
partId = TP_SEPARATOR;
@@ -3164,6 +3170,12 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
}
break;
#endif //QT_NO_WORKSPACE
+#ifndef QT_NO_DIAL
+ case CC_Dial:
+ if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
+ QStyleHelper::drawDial(dial, p);
+ break;
+#endif // QT_NO_DIAL
default:
QWindowsStyle::drawComplexControl(cc, option, p, widget);
break;
diff --git a/src/gui/styles/styles.pri b/src/gui/styles/styles.pri
index 376f834..2164e1e 100644
--- a/src/gui/styles/styles.pri
+++ b/src/gui/styles/styles.pri
@@ -7,12 +7,14 @@ HEADERS += \
styles/qstyleplugin.h \
styles/qcommonstylepixmaps_p.h \
styles/qcommonstyle.h \
+ styles/qstylehelper_p.h \
styles/qstylesheetstyle_p.h
SOURCES += \
styles/qstyle.cpp \
styles/qstylefactory.cpp \
styles/qstyleoption.cpp \
styles/qstyleplugin.cpp \
+ styles/qstylehelper.cpp \
styles/qcommonstyle.cpp \
styles/qstylesheetstyle.cpp \
styles/qstylesheetstyle_default.cpp
diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h
index 97a0aef..72bd637 100644
--- a/src/gui/text/qcssparser_p.h
+++ b/src/gui/text/qcssparser_p.h
@@ -403,7 +403,7 @@ struct BorderData {
// 4. QVector<Declaration> - { prop1: value1; prop2: value2; }
// 5. Declaration - prop1: value1;
-struct Q_GUI_EXPORT Declaration
+struct Q_AUTOTEST_EXPORT Declaration
{
struct DeclarationData : public QSharedData
{
@@ -495,7 +495,7 @@ const quint64 PseudoClass_Alternate = Q_UINT64_C(0x0000100000000000);
const quint64 PseudoClass_Any = Q_UINT64_C(0x0000ffffffffffff);
const int NumPseudos = 46;
-struct Q_GUI_EXPORT Pseudo
+struct Pseudo
{
Pseudo() : negated(false) { }
quint64 type;
@@ -504,7 +504,7 @@ struct Q_GUI_EXPORT Pseudo
bool negated;
};
-struct Q_GUI_EXPORT AttributeSelector
+struct AttributeSelector
{
enum ValueMatchType {
NoMatch,
@@ -519,7 +519,7 @@ struct Q_GUI_EXPORT AttributeSelector
ValueMatchType valueMatchCriterium;
};
-struct Q_GUI_EXPORT BasicSelector
+struct BasicSelector
{
inline BasicSelector() : relationToNext(NoRelation) {}
@@ -539,7 +539,7 @@ struct Q_GUI_EXPORT BasicSelector
Relation relationToNext;
};
-struct Q_GUI_EXPORT Selector
+struct Q_AUTOTEST_EXPORT Selector
{
QVector<BasicSelector> basicSelectors;
int specificity() const;
@@ -552,7 +552,7 @@ struct MediaRule;
struct PageRule;
struct ImportRule;
-struct Q_GUI_EXPORT ValueExtractor
+struct Q_AUTOTEST_EXPORT ValueExtractor
{
ValueExtractor(const QVector<Declaration> &declarations, const QPalette & = QPalette());
@@ -586,7 +586,7 @@ private:
QPalette pal;
};
-struct Q_GUI_EXPORT StyleRule
+struct StyleRule
{
StyleRule() : order(0) { }
QVector<Selector> selectors;
@@ -594,19 +594,19 @@ struct Q_GUI_EXPORT StyleRule
int order;
};
-struct Q_GUI_EXPORT MediaRule
+struct MediaRule
{
QStringList media;
QVector<StyleRule> styleRules;
};
-struct Q_GUI_EXPORT PageRule
+struct PageRule
{
QString selector;
QVector<Declaration> declarations;
};
-struct Q_GUI_EXPORT ImportRule
+struct ImportRule
{
QString href;
QStringList media;
@@ -620,7 +620,7 @@ enum StyleSheetOrigin {
StyleSheetOrigin_Inline
};
-struct Q_GUI_EXPORT StyleSheet
+struct StyleSheet
{
StyleSheet() : origin(StyleSheetOrigin_Unspecified), depth(0) { }
QVector<StyleRule> styleRules; //only contains rules that are not indexed
diff --git a/src/gui/text/qfontdatabase_qws.cpp b/src/gui/text/qfontdatabase_qws.cpp
index eb8a0cf..f62a6d1 100644
--- a/src/gui/text/qfontdatabase_qws.cpp
+++ b/src/gui/text/qfontdatabase_qws.cpp
@@ -58,6 +58,7 @@
#include "qabstractfontengine_qws.h"
#include "qabstractfontengine_p.h"
#include <qdatetime.h>
+#include "qplatformdefs.h"
// for mmap
#include <stdlib.h>
@@ -127,7 +128,7 @@ void QFontDatabasePrivate::addQPF2File(const QByteArray &file)
struct stat st;
if (stat(file.constData(), &st))
return;
- int f = ::open(file, O_RDONLY);
+ int f = ::open(file, O_RDONLY, 0);
if (f < 0)
return;
const uchar *data = (const uchar *)mmap(0, st.st_size, PROT_READ, MAP_SHARED, f, 0);
@@ -675,7 +676,7 @@ QFontEngine *loadSingleEngine(int script, const QFontPrivate *fp,
qDebug() << "Resource not valid" << size->fileName;
}
#else
- int f = ::open(size->fileName, O_RDONLY);
+ int f = ::open(size->fileName, O_RDONLY, 0);
if (f >= 0) {
QFontEngineQPF *fe = new QFontEngineQPF(request, f);
if (fe->isValid())
diff --git a/src/gui/text/qfontdatabase_win.cpp b/src/gui/text/qfontdatabase_win.cpp
index 780ae28..fe1c08c 100644
--- a/src/gui/text/qfontdatabase_win.cpp
+++ b/src/gui/text/qfontdatabase_win.cpp
@@ -364,7 +364,7 @@ void addFontToDatabase(QString familyName, const QString &scriptName,
signature->fsUsb[0], signature->fsUsb[1],
signature->fsUsb[2], signature->fsUsb[3]
};
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (signature->fsUsb[0] == 0) {
// If the unicode ranges bit mask is zero then
// EnumFontFamiliesEx failed to determine it properly.
@@ -715,7 +715,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
f = deffnt;
else if (fam == QLatin1String("system"))
f = SYSTEM_FONT;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
else if (fam == QLatin1String("system_fixed"))
f = SYSTEM_FIXED_FONT;
else if (fam == QLatin1String("ansi_fixed"))
@@ -774,7 +774,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
int strat = OUT_DEFAULT_PRECIS;
if (request.styleStrategy & QFont::PreferBitmap) {
strat = OUT_RASTER_PRECIS;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
} else if (request.styleStrategy & QFont::PreferDevice) {
strat = OUT_DEVICE_PRECIS;
} else if (request.styleStrategy & QFont::PreferOutline) {
@@ -794,7 +794,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
if (request.styleStrategy & QFont::PreferMatch)
qual = DRAFT_QUALITY;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
else if (request.styleStrategy & QFont::PreferQuality)
qual = PROOF_QUALITY;
#endif
@@ -872,7 +872,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
qErrnoWarning("QFontEngine::loadEngine: CreateFontIndirect with stretch failed");
}
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
if (hfont == 0) {
hfont = (HFONT)GetStockObject(ANSI_VAR_FONT);
stockFont = true;
diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm
index 425cab2..6b5bd0f 100644
--- a/src/gui/text/qfontengine_mac.mm
+++ b/src/gui/text/qfontengine_mac.mm
@@ -135,12 +135,12 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, con
symbolicTraits |= kCTFontItalicTrait;
break;
}
-
+
QCFString name;
ATSFontGetName(atsFontRef, kATSOptionFlagsDefault, &name);
- QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pixelSize);
- QCFType<CTFontRef> baseFont = CTFontCreateWithFontDescriptor(descriptor, fontDef.pixelSize, 0);
- ctfont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.pixelSize, 0, symbolicTraits, symbolicTraits);
+ QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pointSize);
+ QCFType<CTFontRef> baseFont = CTFontCreateWithFontDescriptor(descriptor, fontDef.pointSize, 0);
+ ctfont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.pointSize, 0, symbolicTraits, symbolicTraits);
// CTFontCreateCopyWithSymbolicTraits returns NULL if we ask for a trait that does
// not exist for the given font. (for example italic)
@@ -162,7 +162,7 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, con
QCoreTextFontEngine *fe = new QCoreTextFontEngine(ctfont, fontDef, this);
fe->ref.ref();
engines.append(fe);
-
+
}
QCoreTextFontEngineMulti::~QCoreTextFontEngineMulti()
@@ -176,7 +176,7 @@ uint QCoreTextFontEngineMulti::fontIndexForFont(CTFontRef id) const
if (CFEqual(engineAt(i)->ctfont, id))
return i;
}
-
+
QCoreTextFontEngineMulti *that = const_cast<QCoreTextFontEngineMulti *>(this);
QCoreTextFontEngine *fe = new QCoreTextFontEngine(id, fontDef, that);
fe->ref.ref();
@@ -227,7 +227,7 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay
CTFontRef runFont = static_cast<CTFontRef>(CFDictionaryGetValue(runAttribs, NSFontAttributeName));
const uint fontIndex = (fontIndexForFont(runFont) << 24);
//NSLog(@"Run Font Name = %@", CTFontCopyFamilyName(runFont));
- QVarLengthArray<CGGlyph, 512> cgglyphs(0);
+ QVarLengthArray<CGGlyph, 512> cgglyphs(0);
const CGGlyph *tmpGlyphs = CTRunGetGlyphsPtr(run);
if (!tmpGlyphs) {
cgglyphs.resize(glyphCount);
@@ -260,7 +260,7 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay
CFIndex k = 0;
CFIndex i = 0;
- for (i = stringRange.location;
+ for (i = stringRange.location;
(i < stringRange.location + stringRange.length) && (k < glyphCount); ++i) {
if (tmpIndices[k * rtlSign + rtlOffset] == i || i == stringRange.location) {
logClusters[i] = k + firstGlyphIndex;
@@ -425,28 +425,28 @@ void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextIt
getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
if (glyphs.size() == 0)
return;
-
+
CGContextSetFontSize(ctx, fontDef.pixelSize);
-
+
CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx);
-
+
CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, -1, 0, -paintDeviceHeight);
-
+
CGAffineTransformConcat(cgMatrix, oldTextMatrix);
-
+
if (synthesisFlags & QFontEngine::SynthesizedItalic)
cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0));
-
+
// ### cgMatrix = CGAffineTransformConcat(cgMatrix, transform);
-
+
CGContextSetTextMatrix(ctx, cgMatrix);
-
+
CGContextSetTextDrawingMode(ctx, kCGTextFill);
-
-
+
+
QVarLengthArray<CGSize> advances(glyphs.size());
QVarLengthArray<CGGlyph> cgGlyphs(glyphs.size());
-
+
for (int i = 0; i < glyphs.size() - 1; ++i) {
advances[i].width = (positions[i + 1].x - positions[i].x).toReal();
advances[i].height = (positions[i + 1].y - positions[i].y).toReal();
@@ -455,21 +455,21 @@ void QCoreTextFontEngine::draw(CGContextRef ctx, qreal x, qreal y, const QTextIt
advances[glyphs.size() - 1].width = 0;
advances[glyphs.size() - 1].height = 0;
cgGlyphs[glyphs.size() - 1] = glyphs[glyphs.size() - 1];
-
+
CGContextSetFont(ctx, cgFont);
//NSLog(@"Font inDraw %@ ctfont %@", CGFontCopyFullName(cgFont), CTFontCopyFamilyName(ctfont));
-
+
CGContextSetTextPosition(ctx, positions[0].x.toReal(), positions[0].y.toReal());
-
+
CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size());
-
+
if (synthesisFlags & QFontEngine::SynthesizedBold) {
CGContextSetTextPosition(ctx, positions[0].x.toReal() + 0.5 * lineThickness().toReal(),
positions[0].y.toReal());
-
+
CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size());
}
-
+
CGContextSetTextMatrix(ctx, oldTextMatrix);
}
@@ -622,7 +622,7 @@ QFontEngine::FaceId QCoreTextFontEngine::faceId() const
bool QCoreTextFontEngine::canRender(const QChar *string, int len)
{
- QCFType<CTFontRef> retFont = CTFontCreateForString(ctfont,
+ QCFType<CTFontRef> retFont = CTFontCreateForString(ctfont,
QCFType<CFStringRef>(CFStringCreateWithCharactersNoCopy(0,
reinterpret_cast<const UniChar *>(string),
len, kCFAllocatorNull)),
@@ -672,7 +672,7 @@ QFontEngineMacMulti::QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, cons
} else {
if (fontDef.weight >= QFont::Bold)
fntStyle |= ::bold;
- if (fontDef.style != QFont::StyleNormal)
+ if (fontDef.style != QFont::StyleNormal)
fntStyle |= ::italic;
FMFontStyle intrinsicStyle;
@@ -955,7 +955,7 @@ bool QFontEngineMacMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *
tmpItem.length = charCount;
tmpItem.glyphs = shaperItem.glyphs.mid(glyphIdx, glyphCount);
tmpItem.log_clusters = shaperItem.log_clusters + charIdx;
- if (!stringToCMapInternal(tmpItem.string + tmpItem.from, tmpItem.length,
+ if (!stringToCMapInternal(tmpItem.string + tmpItem.from, tmpItem.length,
&tmpItem.glyphs, &glyphCount, flags,
&tmpItem)) {
*nglyphs = glyphIdx + glyphCount;
@@ -1221,12 +1221,12 @@ QFontEngineMac::QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFo
transform = multiEngine->transform;
else
transform = CGAffineTransformIdentity;
-
+
ATSUTextMeasurement metric;
ATSUGetAttribute(style, kATSUAscentTag, sizeof(metric), &metric, 0);
m_ascent = FixRound(metric);
-
+
ATSUGetAttribute(style, kATSUDescentTag, sizeof(metric), &metric, 0);
m_descent = FixRound(metric);
@@ -1422,11 +1422,16 @@ void QFontEngineMac::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, in
addGlyphsToPathHelper(style, glyphs, positions, numGlyphs, path);
}
-QImage QFontEngineMac::alphaMapForGlyph(glyph_t glyph)
+
+/*!
+ Helper function for alphaMapForGlyph and alphaRGBMapForGlyph. The two are identical, except for
+ the subpixel antialiasing...
+*/
+QImage QFontEngineMac::imageForGlyph(glyph_t glyph, int margin, bool colorful)
{
const glyph_metrics_t br = boundingBox(glyph);
QImage im(qRound(br.width)+2, qRound(br.height)+4, QImage::Format_RGB32);
- im.fill(0);
+ im.fill(0xff000000);
CGColorSpaceRef colorspace = QCoreGraphicsPaintEngine::macGenericColorSpace();
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
@@ -1444,7 +1449,7 @@ QImage QFontEngineMac::alphaMapForGlyph(glyph_t glyph)
CGContextSetFontSize(ctx, fontDef.pixelSize);
CGContextSetShouldAntialias(ctx, fontDef.pointSize > qt_antialiasing_threshold && !(fontDef.styleStrategy & QFont::NoAntialias));
// turn off sub-pixel hinting - no support for that in OpenGL
- CGContextSetShouldSmoothFonts(ctx, false);
+ CGContextSetShouldSmoothFonts(ctx, colorful);
CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx);
CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, 1, 0, 0);
CGAffineTransformConcat(cgMatrix, oldTextMatrix);
@@ -1476,6 +1481,13 @@ QImage QFontEngineMac::alphaMapForGlyph(glyph_t glyph)
CGContextRelease(ctx);
+ return im;
+}
+
+QImage QFontEngineMac::alphaMapForGlyph(glyph_t glyph)
+{
+ QImage im = imageForGlyph(glyph, 2, false);
+
QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
QVector<QRgb> colors(256);
for (int i=0; i<256; ++i)
@@ -1495,6 +1507,32 @@ QImage QFontEngineMac::alphaMapForGlyph(glyph_t glyph)
return indexed;
}
+QImage QFontEngineMac::alphaRGBMapForGlyph(glyph_t glyph, int margin, const QTransform &t)
+{
+ QImage im = imageForGlyph(glyph, margin, true);
+
+ if (t.type() >= QTransform::TxScale) {
+ im = im.transformed(t);
+ }
+
+ extern uchar qt_pow_rgb_gamma[256];
+
+ // gamma correct the pixels back to linear color space...
+ for (int y=0; y<im.height(); ++y) {
+ uint *pixels = (uint *) im.scanLine(y);
+ for (int x=0; x<im.width(); ++x) {
+ uint p = pixels[x];
+ uint r = qt_pow_rgb_gamma[qRed(p)];
+ uint g = qt_pow_rgb_gamma[qGreen(p)];
+ uint b = qt_pow_rgb_gamma[qBlue(p)];
+ pixels[x] = (r << 16) | (g << 8) | b | 0xff000000;
+ }
+ }
+
+ return im;
+}
+
+
bool QFontEngineMac::canRender(const QChar *string, int len)
{
Q_ASSERT(false);
@@ -1648,7 +1686,7 @@ QFontEngine::Properties QFontEngineMac::properties() const
if (ATSFontGetTable(atsFont, MAKE_TAG('p', 'o', 's', 't'), 10, 2, &lw, 0) == noErr)
lw = qFromBigEndian<quint16>(lw);
props.lineWidth = lw;
-
+
// CTFontCopyPostScriptName
QCFString psName;
if (ATSFontGetPostScriptName(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &psName) == noErr)
@@ -1663,7 +1701,7 @@ void QFontEngineMac::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_m
ATSUCreateAndCopyStyle(style, &unscaledStyle);
int emSquare = properties().emSquare.toInt();
-
+
const int maxAttributeCount = 4;
ATSUAttributeTag tags[maxAttributeCount + 1];
ByteCount sizes[maxAttributeCount + 1];
@@ -1675,7 +1713,7 @@ void QFontEngineMac::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_m
sizes[attributeCount] = sizeof(size);
values[attributeCount] = &size;
++attributeCount;
-
+
Q_ASSERT(attributeCount < maxAttributeCount + 1);
OSStatus err = ATSUSetAttributes(unscaledStyle, attributeCount, tags, sizes, values);
Q_ASSERT(err == noErr);
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h
index dc18991..92efb6c 100644
--- a/src/gui/text/qfontengine_p.h
+++ b/src/gui/text/qfontengine_p.h
@@ -525,8 +525,11 @@ public:
virtual Properties properties() const;
virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
virtual QImage alphaMapForGlyph(glyph_t);
+ virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t);
private:
+ QImage imageForGlyph(glyph_t glyph, int margin, bool colorful);
+
ATSUFontID fontID;
QCFType<CGFontRef> cgFont;
ATSUStyle style;
diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp
index e9fcac4..b7d1c59 100644
--- a/src/gui/text/qfontengine_qpf.cpp
+++ b/src/gui/text/qfontengine_qpf.cpp
@@ -252,7 +252,7 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
for (int i = 0; i < int(dir.count()); ++i) {
const QByteArray fileName = QFile::encodeName(dir.absoluteFilePath(dir[i]));
- int fd = ::open(fileName.constData(), O_RDONLY);
+ int fd = ::open(fileName.constData(), O_RDONLY, 0);
if (fd >= 0) {
void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0);
if (header && header != MAP_FAILED) {
@@ -331,9 +331,9 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
qDebug() << "found existing qpf:" << fileName;
#endif
if (::access(encodedName, W_OK | R_OK) == 0)
- fd = ::open(encodedName, O_RDWR);
+ fd = ::open(encodedName, O_RDWR, 0);
else if (::access(encodedName, R_OK) == 0)
- fd = ::open(encodedName, O_RDONLY);
+ fd = ::open(encodedName, O_RDONLY, 0);
} else {
#if defined(DEBUG_FONTENGINE)
qDebug() << "creating qpf on the fly:" << fileName;
@@ -347,7 +347,7 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
generator.generate();
buffer.close();
const QByteArray &data = buffer.data();
- ::write(fd, data.constData(), data.size());
+ QT_WRITE(fd, data.constData(), data.size());
}
}
}
@@ -893,8 +893,8 @@ void QFontEngineQPF::loadGlyph(glyph_t glyph)
g.y = qRound(metrics.y);
g.advance = qRound(metrics.xoff);
- ::write(fd, &g, sizeof(g));
- ::write(fd, img.bits(), img.numBytes());
+ QT_WRITE(fd, &g, sizeof(g));
+ QT_WRITE(fd, img.bits(), img.numBytes());
glyphPos = oldSize - glyphDataOffset;
#if 0 && defined(DEBUG_FONTENGINE)
diff --git a/src/gui/text/qfontengine_qws.cpp b/src/gui/text/qfontengine_qws.cpp
index d776329..10aef4c 100644
--- a/src/gui/text/qfontengine_qws.cpp
+++ b/src/gui/text/qfontengine_qws.cpp
@@ -387,7 +387,7 @@ QFontEngineQPF1::QFontEngineQPF1(const QFontDef&, const QString &fn)
{
cache_cost = 1;
- int f = ::open( QFile::encodeName(fn), O_RDONLY );
+ int f = ::open( QFile::encodeName(fn), O_RDONLY, 0);
Q_ASSERT(f>=0);
QT_STATBUF st;
if ( QT_FSTAT( f, &st ) )
diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp
index bf3a176..feea1f2 100644
--- a/src/gui/text/qfontengine_win.cpp
+++ b/src/gui/text/qfontengine_win.cpp
@@ -65,7 +65,7 @@
#include <private/qpaintengine_raster_p.h>
#include <private/qnativeimage_p.h>
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
#include "qguifunctions_wince.h"
#endif
@@ -205,7 +205,7 @@ QFixed QFontEngineWin::lineThickness() const
return QFontEngine::lineThickness();
}
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
static OUTLINETEXTMETRICW *getOutlineTextMetric(HDC hdc)
{
int size;
@@ -249,7 +249,7 @@ void QFontEngineWin::getCMap()
designToDevice = 1;
_faceId.index = 0;
if(cmap) {
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
OUTLINETEXTMETRICW *otm = getOutlineTextMetric(hdc);
#else
OUTLINETEXTMETRICA *otm = getOutlineTextMetric(hdc);
@@ -286,7 +286,7 @@ int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout
int i = 0;
int glyph_pos = 0;
if (mirrored) {
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
{
#else
if (symbol) {
@@ -314,7 +314,7 @@ int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout
for (; i < numChars; ++i, ++glyph_pos) {
uint ucs = QChar::mirroredChar(getChar(str, i, numChars));
if (
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
tm.w.tmFirstChar > 60000 || // see line 375
#endif
ucs >= first && ucs <= last)
@@ -324,7 +324,7 @@ int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout
}
}
} else {
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
{
#else
if (symbol) {
@@ -352,7 +352,7 @@ int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout
for (; i < numChars; ++i, ++glyph_pos) {
uint uc = getChar(str, i, numChars);
if (
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
tm.w.tmFirstChar > 60000 || // see comment in QFontEngineWin
#endif
uc >= first && uc <= last)
@@ -482,7 +482,7 @@ bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph
if (flags & QTextEngine::GlyphIndicesOnly)
return true;
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
HDC hdc = shared_dc();
if (flags & QTextEngine::DesignMetrics) {
HGDIOBJ oldFont = 0;
@@ -585,7 +585,7 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
designAdvances[glyph] = QFixed(width) / designToDevice;
} else {
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
GLYPHMETRICS gm;
DWORD res = GDI_ERROR;
MAT2 mat;
@@ -647,7 +647,7 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
width -= overhang;
} else {
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
GLYPHMETRICS gm;
DWORD res = GDI_ERROR;
MAT2 mat;
@@ -693,14 +693,14 @@ glyph_metrics_t QFontEngineWin::boundingBox(const QGlyphLayout &glyphs)
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
typedef HRESULT (WINAPI *pGetCharABCWidthsFloat)(HDC, UINT, UINT, LPABCFLOAT);
static pGetCharABCWidthsFloat qt_GetCharABCWidthsFloat = 0;
#endif
glyph_metrics_t QFontEngineWin::boundingBox(glyph_t glyph, const QTransform &t)
{
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
GLYPHMETRICS gm;
HDC hdc = shared_dc();
@@ -871,7 +871,7 @@ qreal QFontEngineWin::minLeftBearing() const
qreal QFontEngineWin::minRightBearing() const
{
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (rbearing == SHRT_MIN) {
int ml = 0;
int mr = 0;
@@ -1047,7 +1047,7 @@ static inline QPointF qt_to_qpointf(const POINTFX &pt, qreal scale) {
static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
QPainterPath *path, bool ttf, glyph_metrics_t *metric = 0, qreal scale = 1)
{
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
Q_UNUSED(glyph);
Q_UNUSED(hdc);
#endif
@@ -1064,7 +1064,7 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
GLYPHMETRICS gMetric;
memset(&gMetric, 0, sizeof(GLYPHMETRICS));
int bufferSize = GDI_ERROR;
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
QT_WA( {
bufferSize = GetGlyphOutlineW(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat);
}, {
@@ -1077,7 +1077,7 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
void *dataBuffer = new char[bufferSize];
DWORD ret = GDI_ERROR;
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
QT_WA( {
ret = GetGlyphOutlineW(hdc, glyph, glyphFormat, &gMetric, bufferSize,
dataBuffer, &mat);
@@ -1199,7 +1199,7 @@ void QFontEngineWin::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, in
void QFontEngineWin::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs,
QPainterPath *path, QTextItem::RenderFlags flags)
{
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
if(tm.w.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) {
hasOutline = true;
QFontEngine::addOutlineToPath(x, y, glyphs, path, flags);
@@ -1267,7 +1267,7 @@ QFontEngine::Properties QFontEngineWin::properties() const
});
HDC hdc = shared_dc();
HGDIOBJ oldfont = SelectObject(hdc, hf);
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
OUTLINETEXTMETRICW *otm = getOutlineTextMetric(hdc);
#else
OUTLINETEXTMETRICA *otm = getOutlineTextMetric(hdc);
@@ -1351,7 +1351,7 @@ QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin
bool has_transformation = t.type() > QTransform::TxTranslate;
-#ifndef Q_OS_WINCE
+#ifndef Q_WS_WINCE
unsigned int options = ttf ? ETO_GLYPH_INDEX : 0;
XFORM xform;
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp
index 48963bb..d12e3fe 100644
--- a/src/gui/text/qtextcursor.cpp
+++ b/src/gui/text/qtextcursor.cpp
@@ -145,7 +145,6 @@ void QTextCursorPrivate::remove()
{
if (anchor == position)
return;
- priv->beginEditBlock();
currentCharFormat = -1;
int pos1 = position;
int pos2 = adjusted_anchor;
@@ -159,15 +158,18 @@ void QTextCursorPrivate::remove()
// deleting inside table? -> delete only content
QTextTable *table = complexSelectionTable();
if (table) {
+ priv->beginEditBlock();
int startRow, startCol, numRows, numCols;
selectedTableCells(&startRow, &numRows, &startCol, &numCols);
clearCells(table, startRow, startCol, numRows, numCols, op);
+ adjusted_anchor = anchor = position;
+ priv->endEditBlock();
} else {
priv->remove(pos1, pos2-pos1, op);
+ adjusted_anchor = anchor = position;
+ priv->finishEdit();
}
- adjusted_anchor = anchor = position;
- priv->endEditBlock();
}
void QTextCursorPrivate::clearCells(QTextTable *table, int startRow, int startCol, int numRows, int numCols, QTextUndoCommand::Operation op)
@@ -1291,9 +1293,14 @@ void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format
QTextCharFormat format = _format;
format.clearProperty(QTextFormat::ObjectIndex);
- d->priv->beginEditBlock();
+ bool hasEditBlock = false;
+
+ if (d->anchor != d->position) {
+ hasEditBlock = true;
+ d->priv->beginEditBlock();
+ d->remove();
+ }
- d->remove();
if (!text.isEmpty()) {
QTextFormatCollection *formats = d->priv->formatCollection();
int formatIdx = formats->indexForFormat(format);
@@ -1323,6 +1330,11 @@ void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format
|| ch == QChar::ParagraphSeparator
|| ch == QLatin1Char('\r')) {
+ if (!hasEditBlock) {
+ hasEditBlock = true;
+ d->priv->beginEditBlock();
+ }
+
if (blockEnd > blockStart)
d->priv->insert(d->position, textStart + blockStart, blockEnd - blockStart, formatIdx);
@@ -1333,7 +1345,8 @@ void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format
if (textStart + blockStart < textEnd)
d->priv->insert(d->position, textStart + blockStart, textEnd - textStart - blockStart, formatIdx);
}
- d->priv->endEditBlock();
+ if (hasEditBlock)
+ d->priv->endEditBlock();
d->setX();
}
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp
index 05ddf47..e1da4be 100644
--- a/src/gui/text/qtextdocument_p.cpp
+++ b/src/gui/text/qtextdocument_p.cpp
@@ -404,7 +404,7 @@ int QTextDocumentPrivate::insertBlock(const QChar &blockSeparator,
int b = blocks.findNode(pos);
QTextBlockData *B = blocks.fragment(b);
- QTextUndoCommand c = { QTextUndoCommand::BlockInserted, true,
+ QTextUndoCommand c = { QTextUndoCommand::BlockInserted, editBlock != 0,
op, charFormat, strPos, pos, { blockFormat },
B->revision };
@@ -439,20 +439,19 @@ void QTextDocumentPrivate::insert(int pos, int strPos, int strLength, int format
Q_ASSERT(pos >= 0 && pos < fragments.length());
Q_ASSERT(formats.format(format).isCharFormat());
- beginEditBlock();
insert_string(pos, strPos, strLength, format, QTextUndoCommand::MoveCursor);
if (undoEnabled) {
int b = blocks.findNode(pos);
QTextBlockData *B = blocks.fragment(b);
- QTextUndoCommand c = { QTextUndoCommand::Inserted, true,
+ QTextUndoCommand c = { QTextUndoCommand::Inserted, editBlock != 0,
QTextUndoCommand::MoveCursor, format, strPos, pos, { strLength },
B->revision };
appendUndoItem(c);
B->revision = undoState;
Q_ASSERT(undoState == undoStack.size());
}
- endEditBlock();
+ finishEdit();
}
void QTextDocumentPrivate::insert(int pos, const QString &str, int format)
@@ -584,8 +583,6 @@ void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::O
Q_ASSERT(startAndEndInSameFrame || endIsEndOfChildFrame || startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent || isFirstTableCell);
#endif
- beginEditBlock();
-
split(pos);
split(pos+length);
@@ -605,10 +602,10 @@ void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::O
int blockRevision = B->revision;
QTextFragmentData *X = fragments.fragment(x);
- QTextUndoCommand c = { QTextUndoCommand::Removed, true,
+ QTextUndoCommand c = { QTextUndoCommand::Removed, editBlock != 0,
op, X->format, X->stringPosition, key, { X->size_array[0] },
blockRevision };
- QTextUndoCommand cInsert = { QTextUndoCommand::Inserted, true,
+ QTextUndoCommand cInsert = { QTextUndoCommand::Inserted, editBlock != 0,
op, X->format, X->stringPosition, dstKey, { X->size_array[0] },
blockRevision };
@@ -648,7 +645,7 @@ void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::O
Q_ASSERT(blocks.length() == fragments.length());
- endEditBlock();
+ finishEdit();
}
void QTextDocumentPrivate::remove(int pos, int length, QTextUndoCommand::Operation op)
@@ -1004,8 +1001,12 @@ void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c)
if (!undoStack.isEmpty() && modified) {
QTextUndoCommand &last = undoStack[undoState - 1];
- if (last.tryMerge(c))
- return;
+ if ( (last.block && c.block) // part of the same block => can merge
+ || (!c.block && !last.block // two single undo items => can merge
+ && (undoState < 2 || !undoStack[undoState-2].block))) {
+ if (last.tryMerge(c))
+ return;
+ }
}
if (modifiedState > undoState)
modifiedState = -1;
@@ -1013,6 +1014,9 @@ void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c)
undoState++;
emitUndoAvailable(true);
emitRedoAvailable(false);
+
+ if (!c.block)
+ emit document()->undoCommandAdded();
}
void QTextDocumentPrivate::truncateUndoStack()
@@ -1082,7 +1086,6 @@ void QTextDocumentPrivate::joinPreviousEditBlock()
void QTextDocumentPrivate::endEditBlock()
{
- Q_Q(QTextDocument);
if (--editBlock)
return;
@@ -1093,6 +1096,16 @@ void QTextDocumentPrivate::endEditBlock()
emit document()->undoCommandAdded();
}
+ finishEdit();
+}
+
+void QTextDocumentPrivate::finishEdit()
+{
+ Q_Q(QTextDocument);
+
+ if (editBlock)
+ return;
+
if (framesDirty)
scan_frames(docChangeFrom, docChangeOldLength, docChangeLength);
@@ -1279,7 +1292,7 @@ void QTextDocumentPrivate::changeObjectFormat(QTextObject *obj, int format)
if (f)
documentChange(f->firstPosition(), f->lastPosition() - f->firstPosition());
- QTextUndoCommand c = { QTextUndoCommand::GroupFormatChange, true, QTextUndoCommand::MoveCursor, oldFormatIndex,
+ QTextUndoCommand c = { QTextUndoCommand::GroupFormatChange, editBlock != 0, QTextUndoCommand::MoveCursor, oldFormatIndex,
0, 0, { obj->d_func()->objectIndex }, 0 };
appendUndoItem(c);
diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h
index 25763e1..d754ff0 100644
--- a/src/gui/text/qtextdocument_p.h
+++ b/src/gui/text/qtextdocument_p.h
@@ -139,7 +139,7 @@ public:
MoveCursor = 1
};
quint16 command;
- quint8 block; ///< All undo commands that have this set to zero/false are combined with the preceding command on undo/redo.
+ quint8 block; ///< All undo commands that have this set to true are combined with the preceding command on undo/redo.
quint8 operation;
int format;
quint32 strPos;
@@ -202,6 +202,7 @@ public:
inline void beginEditBlock() { editBlock++; }
void joinPreviousEditBlock();
void endEditBlock();
+ void finishEdit();
inline bool isInEditBlock() const { return editBlock; }
void enableUndoRedo(bool enable);
inline bool isUndoRedoEnabled() const { return undoEnabled; }
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 80a5425..faa06b7 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -868,7 +868,7 @@ void QTextEngine::shapeText(int item) const
#if defined(Q_WS_MAC)
shapeTextMac(item);
-#elif defined(Q_OS_WINCE)
+#elif defined(Q_WS_WINCE)
shapeTextWithCE(item);
#else
shapeTextWithHarfbuzz(item);
@@ -923,7 +923,7 @@ void QTextEngine::shapeText(int item) const
si.width += glyphs.advances_x[i];
}
-#if defined(Q_OS_WINCE) //TODO
+#if defined(Q_WS_WINCE) //TODO
// set the glyph attributes heuristically. Assumes a 1 to 1 relationship between chars and glyphs
// and no reordering.
// also computes logClusters heuristically
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index cf241fa..6be525f 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -581,7 +581,7 @@ private:
void addRequiredBoundaries() const;
void shapeText(int item) const;
void shapeTextWithHarfbuzz(int item) const;
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
void shapeTextWithCE(int item) const;
#endif
#if defined(Q_WS_MAC)
diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp
index 1edc3b8..75e89d2 100644
--- a/src/gui/text/qtextodfwriter.cpp
+++ b/src/gui/text/qtextodfwriter.cpp
@@ -477,7 +477,7 @@ void QTextOdfWriter::writeBlockFormat(QXmlStreamWriter &writer, QTextBlockFormat
if (format.hasProperty(QTextFormat::BlockRightMargin))
writer.writeAttribute(foNS, QString::fromLatin1("margin-right"), pixelToPoint(qMax(qreal(0.), format.rightMargin())) );
if (format.hasProperty(QTextFormat::TextIndent))
- writer.writeAttribute(foNS, QString::fromLatin1("text-indent"), QString::number(format.textIndent()));
+ writer.writeAttribute(foNS, QString::fromLatin1("text-indent"), pixelToPoint(format.textIndent()));
if (format.hasProperty(QTextFormat::PageBreakPolicy)) {
if (format.pageBreakPolicy() & QTextFormat::PageBreak_AlwaysBefore)
writer.writeAttribute(foNS, QString::fromLatin1("break-before"), QString::fromLatin1("page"));
diff --git a/src/gui/util/qdesktopservices_mac.cpp b/src/gui/util/qdesktopservices_mac.cpp
index 5124068..fdafa1e 100644
--- a/src/gui/util/qdesktopservices_mac.cpp
+++ b/src/gui/util/qdesktopservices_mac.cpp
@@ -96,7 +96,7 @@ OSType translateLocation(QDesktopServices::StandardLocation type)
static bool lsOpen(const QUrl &url)
{
- if (!url.isValid())
+ if (!url.isValid() || url.scheme().isEmpty())
return false;
QCFType<CFURLRef> cfUrl = CFURLCreateWithString(0, QCFString(QString::fromLatin1(url.toEncoded())), 0);
diff --git a/src/gui/util/qsystemtrayicon.cpp b/src/gui/util/qsystemtrayicon.cpp
index 2e072c5..bfafe44 100644
--- a/src/gui/util/qsystemtrayicon.cpp
+++ b/src/gui/util/qsystemtrayicon.cpp
@@ -434,13 +434,13 @@ QBalloonTip::QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title
titleLabel->setText(title);
QFont f = titleLabel->font();
f.setBold(true);
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
f.setPointSize(f.pointSize() - 2);
#endif
titleLabel->setFont(f);
titleLabel->setTextFormat(Qt::PlainText); // to maintain compat with windows
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize);
const int closeButtonSize = style()->pixelMetric(QStyle::PM_SmallIconSize) - 2;
#else
@@ -456,7 +456,7 @@ QBalloonTip::QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title
QObject::connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
QLabel *msgLabel = new QLabel;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
f.setBold(false);
msgLabel->setFont(f);
#endif
@@ -466,7 +466,7 @@ QBalloonTip::QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title
msgLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
// smart size for the message label
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
int limit = QApplication::desktop()->availableGeometry(msgLabel).size().width() / 2;
#else
int limit = QApplication::desktop()->availableGeometry(msgLabel).size().width() / 3;
@@ -481,7 +481,7 @@ QBalloonTip::QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title
control->document()->setDefaultTextOption(opt);
}
}
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
// Make sure that the text isn't wrapped "somewhere" in the balloon widget
// in the case that we have a long title label.
setMaximumWidth(limit);
diff --git a/src/gui/util/qsystemtrayicon_win.cpp b/src/gui/util/qsystemtrayicon_win.cpp
index 84f9de4..a6dcea6 100644
--- a/src/gui/util/qsystemtrayicon_win.cpp
+++ b/src/gui/util/qsystemtrayicon_win.cpp
@@ -62,13 +62,13 @@
#include <QDesktopWidget>
#include <QSettings>
-#if defined(Q_OS_WINCE) && !defined(STANDARDSHELL_UI_MODEL)
+#if defined(Q_WS_WINCE) && !defined(STANDARDSHELL_UI_MODEL)
# include <streams.h>
#endif
QT_BEGIN_NAMESPACE
-#if defined(Q_OS_WINCE)
+#if defined(Q_WS_WINCE)
static const UINT q_uNOTIFYICONID = 13; // IDs from 0 to 12 are reserved on WinCE.
#else
static const UINT q_uNOTIFYICONID = 0;
@@ -331,7 +331,7 @@ bool QSystemTrayIconSys::showMessageA(const QString &title, const QString &messa
bool QSystemTrayIconSys::trayMessageA(DWORD msg)
{
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
NOTIFYICONDATAA tnd;
memset(&tnd, 0, notifyIconSizeA);
tnd.uID = q_uNOTIFYICONID;
@@ -462,7 +462,7 @@ bool QSystemTrayIconSys::winEvent( MSG *m, long *result )
emit q->activated(QSystemTrayIcon::Trigger);
break;
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_WS_WINCE)
case WM_LBUTTONDBLCLK:
emit q->activated(QSystemTrayIcon::DoubleClick);
break;
@@ -726,7 +726,7 @@ void QSystemTrayIconPrivate::updateMenu_sys()
void QSystemTrayIconPrivate::updateToolTip_sys()
{
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
// Calling sys->trayMessage(NIM_MODIFY) on an existing icon is broken on Windows CE.
// So we need to call updateIcon_sys() which creates a new icon handle.
updateIcon_sys();
diff --git a/src/gui/widgets/qabstractbutton.cpp b/src/gui/widgets/qabstractbutton.cpp
index 61ed0ea..1900016 100644
--- a/src/gui/widgets/qabstractbutton.cpp
+++ b/src/gui/widgets/qabstractbutton.cpp
@@ -215,11 +215,8 @@ void QButtonGroup::setExclusive(bool exclusive)
d->exclusive = exclusive;
}
-/*!
- Adds the given \a button to the end of the group's internal list of buttons.
- \sa removeButton()
-*/
+// TODO: Qt 5: Merge with addButton(QAbstractButton *button, int id)
void QButtonGroup::addButton(QAbstractButton *button)
{
addButton(button, -1);
@@ -232,8 +229,18 @@ void QButtonGroup::addButton(QAbstractButton *button, int id)
previous->removeButton(button);
button->d_func()->group = this;
d->buttonList.append(button);
- if (id != -1)
+ if (id == -1) {
+ QList<int> ids = d->mapping.values();
+ if (ids.isEmpty())
+ d->mapping[button] = -2;
+ else {
+ qSort(ids);
+ d->mapping[button] = ids.first()-1;
+ }
+ } else {
d->mapping[button] = id;
+ }
+
if (d->exclusive && button->isChecked())
button->d_func()->notifyChecked();
}
@@ -1236,7 +1243,9 @@ void QAbstractButton::timerEvent(QTimerEvent *e)
d->repeatTimer.start(d->autoRepeatInterval, this);
if (d->down) {
QPointer<QAbstractButton> guard(this);
- d->emitReleased();
+ nextCheckState();
+ if (guard)
+ d->emitReleased();
if (guard)
d->emitClicked();
if (guard)
diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp
index 9886969..0d8b4de 100644
--- a/src/gui/widgets/qabstractscrollarea.cpp
+++ b/src/gui/widgets/qabstractscrollarea.cpp
@@ -873,21 +873,22 @@ bool QAbstractScrollArea::event(QEvent *e)
case QEvent::Resize:
d->layoutChildren();
break;
- case QEvent::Paint:
+ case QEvent::Paint: {
+ QStyleOption option;
+ option.initFrom(this);
if (d->cornerPaintingRect.isValid()) {
- QStyleOption option;
option.rect = d->cornerPaintingRect;
QPainter p(this);
style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this);
}
#ifdef Q_WS_MAC
if (d->reverseCornerPaintingRect.isValid()) {
- QStyleOption option;
option.rect = d->reverseCornerPaintingRect;
QPainter p(this);
style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, &option, &p, this);
}
#endif
+ }
QFrame::paintEvent((QPaintEvent*)e);
break;
#ifndef QT_NO_CONTEXTMENU
diff --git a/src/gui/widgets/qabstractscrollarea_p.h b/src/gui/widgets/qabstractscrollarea_p.h
index e4c47e9..f153711 100644
--- a/src/gui/widgets/qabstractscrollarea_p.h
+++ b/src/gui/widgets/qabstractscrollarea_p.h
@@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE
class QScrollBar;
class QAbstractScrollAreaScrollBarContainer;
-class Q_GUI_EXPORT QAbstractScrollAreaPrivate: public QFramePrivate
+class QAbstractScrollAreaPrivate: public QFramePrivate
{
Q_DECLARE_PUBLIC(QAbstractScrollArea)
diff --git a/src/gui/widgets/qabstractspinbox.cpp b/src/gui/widgets/qabstractspinbox.cpp
index 347f89a..d640c70 100644
--- a/src/gui/widgets/qabstractspinbox.cpp
+++ b/src/gui/widgets/qabstractspinbox.cpp
@@ -193,6 +193,7 @@ void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols)
Q_D(QAbstractSpinBox);
if (d->buttonSymbols != buttonSymbols) {
d->buttonSymbols = buttonSymbols;
+ d->updateEditFieldGeometry();
update();
}
}
diff --git a/src/gui/widgets/qbuttongroup.cpp b/src/gui/widgets/qbuttongroup.cpp
index 06bcf1e..ebfafe3 100644
--- a/src/gui/widgets/qbuttongroup.cpp
+++ b/src/gui/widgets/qbuttongroup.cpp
@@ -176,11 +176,21 @@
*/
/*!
- \fn void QButtonGroup::addButton(QAbstractButton *button, int id = -1);
+ \fn void QButtonGroup::addButton(QAbstractButton *button);
+
+ Adds the given \a button to the end of the group's internal list of buttons.
+ An \a id will be assigned to the button by this QButtonGroup. Automatically
+ assigned ids are guaranteed to be negative, starting with -2. If you are also
+ assigning your own ids, use positive values to avoid conflicts.
+
+ \sa removeButton() buttons()
+*/
+
+/*!
+ \fn void QButtonGroup::addButton(QAbstractButton *button, int id);
Adds the given \a button to the button group, with the given \a
- id. If \a id is -1 (the default), an id will be assigned to the
- button by this QButtonGroup.
+ id. It is recommended to assign only positive ids.
\sa removeButton() buttons()
*/
diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp
index 09a51fe..f30ece4 100644
--- a/src/gui/widgets/qcombobox.cpp
+++ b/src/gui/widgets/qcombobox.cpp
@@ -949,6 +949,7 @@ QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer()
container->itemView()->setTextElideMode(Qt::ElideMiddle);
updateDelegate();
updateLayoutDirection();
+ updateViewContainerPaletteAndOpacity();
QObject::connect(container, SIGNAL(itemSelected(QModelIndex)),
q, SLOT(_q_itemSelected(QModelIndex)));
QObject::connect(container->itemView()->selectionModel(),
@@ -1051,6 +1052,27 @@ void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/,
}
+void QComboBoxPrivate::updateViewContainerPaletteAndOpacity()
+{
+ if (!container)
+ return;
+ Q_Q(QComboBox);
+ QStyleOptionComboBox opt;
+ q->initStyleOption(&opt);
+#ifndef QT_NO_MENU
+ if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
+ QMenu menu;
+ menu.ensurePolished();
+ container->setPalette(menu.palette());
+ container->setWindowOpacity(menu.windowOpacity());
+ } else
+#endif
+ {
+ container->setPalette(q->palette());
+ container->setWindowOpacity(1.0);
+ }
+}
+
/*!
Initialize \a option with the values from this QComboBox. This method
is useful for subclasses when they need a QStyleOptionComboBox, but don't want
@@ -2572,20 +2594,7 @@ void QComboBox::changeEvent(QEvent *e)
hidePopup();
break;
case QEvent::PaletteChange: {
- QStyleOptionComboBox opt;
- initStyleOption(&opt);
-#ifndef QT_NO_MENU
- if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
- QMenu menu;
- menu.ensurePolished();
- d->viewContainer()->setPalette(menu.palette());
- d->viewContainer()->setWindowOpacity(menu.windowOpacity());
- } else
-#endif
- {
- d->viewContainer()->setPalette(palette());
- d->viewContainer()->setWindowOpacity(1.0);
- }
+ d->updateViewContainerPaletteAndOpacity();
break;
}
case QEvent::FontChange:
diff --git a/src/gui/widgets/qcombobox_p.h b/src/gui/widgets/qcombobox_p.h
index c39a231..a0b76cf 100644
--- a/src/gui/widgets/qcombobox_p.h
+++ b/src/gui/widgets/qcombobox_p.h
@@ -370,6 +370,7 @@ public:
void updateDelegate();
void keyboardSearchString(const QString &text);
void modelChanged();
+ void updateViewContainerPaletteAndOpacity();
QAbstractItemModel *model;
QLineEdit *lineEdit;
diff --git a/src/gui/widgets/qcommandlinkbutton.cpp b/src/gui/widgets/qcommandlinkbutton.cpp
index 13ee6af..92d89a1 100644
--- a/src/gui/widgets/qcommandlinkbutton.cpp
+++ b/src/gui/widgets/qcommandlinkbutton.cpp
@@ -140,10 +140,12 @@ QFont QCommandLinkButtonPrivate::titleFont() const
Q_Q(const QCommandLinkButton);
QFont font = q->font();
if (usingVistaStyle()) {
- font.setPointSizeF(12.0);
+ if (!q->testAttribute(Qt::WA_SetFont))
+ font.setPointSizeF(12.0);
} else {
font.setBold(true);
- font.setPointSizeF(9.0);
+ if (!q->testAttribute(Qt::WA_SetFont))
+ font.setPointSizeF(9.0);
}
return font;
}
@@ -152,7 +154,8 @@ QFont QCommandLinkButtonPrivate::descriptionFont() const
{
Q_Q(const QCommandLinkButton);
QFont font = q->font();
- font.setPointSizeF(9.0);
+ if (!q->testAttribute(Qt::WA_SetFont))
+ font.setPointSizeF(9.0);
return font;
}
diff --git a/src/gui/widgets/qdatetimeedit.cpp b/src/gui/widgets/qdatetimeedit.cpp
index 83bec68..e7afea0 100644
--- a/src/gui/widgets/qdatetimeedit.cpp
+++ b/src/gui/widgets/qdatetimeedit.cpp
@@ -220,6 +220,9 @@ QDateTimeEdit::QDateTimeEdit(const QVariant &var, QVariant::Type parserType, QWi
\property QDateTimeEdit::dateTime
\brief the QDateTime that is set in the QDateTimeEdit
+ When setting this property the timespec of the QDateTimeEdit remains the same
+ and the timespec of the new QDateTime is ignored.
+
By default, this property contains a date that refers to January 1,
2000 and a time of 00:00:00 and 0 milliseconds.
@@ -239,7 +242,7 @@ void QDateTimeEdit::setDateTime(const QDateTime &datetime)
d->clearCache();
if (!(d->sections & DateSections_Mask))
setDateRange(datetime.date(), datetime.date());
- d->setValue(QVariant(datetime), EmitIfChanged);
+ d->setValue(QDateTime(datetime.date(), datetime.time(), d->spec), EmitIfChanged);
}
}
@@ -932,9 +935,6 @@ void QDateTimeEdit::setCalendarPopup(bool enable)
\property QDateTimeEdit::timeSpec
\brief the current timespec used by the date time edit.
\since 4.4
-
- All dates/passed to the date time edit will be converted to this
- timespec.
*/
Qt::TimeSpec QDateTimeEdit::timeSpec() const
diff --git a/src/gui/widgets/qdockwidget.cpp b/src/gui/widgets/qdockwidget.cpp
index a5be5f8..d573b8b 100644
--- a/src/gui/widgets/qdockwidget.cpp
+++ b/src/gui/widgets/qdockwidget.cpp
@@ -203,7 +203,7 @@ bool QDockWidgetLayout::nativeWindowDeco() const
bool QDockWidgetLayout::nativeWindowDeco(bool floating) const
{
-#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_WINCE)
+#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_WINCE)
Q_UNUSED(floating);
return false;
#else
diff --git a/src/gui/widgets/qframe_p.h b/src/gui/widgets/qframe_p.h
index 4fd341d..3ea0c8b 100644
--- a/src/gui/widgets/qframe_p.h
+++ b/src/gui/widgets/qframe_p.h
@@ -58,7 +58,7 @@
QT_BEGIN_NAMESPACE
-class Q_GUI_EXPORT QFramePrivate : public QWidgetPrivate
+class QFramePrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QFrame)
public:
diff --git a/src/gui/widgets/qgroupbox.cpp b/src/gui/widgets/qgroupbox.cpp
index 6a82483..876c5d6 100644
--- a/src/gui/widgets/qgroupbox.cpp
+++ b/src/gui/widgets/qgroupbox.cpp
@@ -644,15 +644,11 @@ bool QGroupBox::isChecked() const
void QGroupBox::setChecked(bool b)
{
Q_D(QGroupBox);
- if (d->checkable) {
- if (d->checked != b)
- update();
- bool wasToggled = (b != d->checked);
+ if (d->checkable && b != d->checked) {
+ update();
d->checked = b;
- if (wasToggled) {
- d->_q_setChildrenEnabled(b);
- emit toggled(b);
- }
+ d->_q_setChildrenEnabled(b);
+ emit toggled(b);
}
}
diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp
index 63c1315..016b7c1 100644
--- a/src/gui/widgets/qlabel.cpp
+++ b/src/gui/widgets/qlabel.cpp
@@ -971,6 +971,13 @@ void QLabel::paintEvent(QPaintEvent *)
#endif
if (d->isTextLabel) {
QRectF lr = d->layoutRect();
+ QStyleOption opt;
+ opt.initFrom(this);
+#ifndef QT_NO_STYLE_STYLESHEET
+ if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {
+ cssStyle->styleSheetPalette(this, &opt, &opt.palette);
+ }
+#endif
if (d->control) {
#ifndef QT_NO_SHORTCUT
const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0);
@@ -984,11 +991,9 @@ void QLabel::paintEvent(QPaintEvent *)
d->ensureTextLayouted();
QAbstractTextDocumentLayout::PaintContext context;
- QStyleOption opt(0);
- opt.init(this);
if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
- context.palette = palette();
+ context.palette = opt.palette;
context.palette.setColor(QPalette::Text, context.palette.light().color());
painter.save();
painter.translate(lr.x() + 1, lr.y() + 1);
@@ -999,12 +1004,7 @@ void QLabel::paintEvent(QPaintEvent *)
}
// Adjust the palette
- context.palette = palette();
-#ifndef QT_NO_STYLE_STYLESHEET
- if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {
- cssStyle->focusPalette(this, &opt, &context.palette);
- }
-#endif
+ context.palette = opt.palette;
if (foregroundRole() != QPalette::Text && isEnabled())
context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole()));
@@ -1019,12 +1019,10 @@ void QLabel::paintEvent(QPaintEvent *)
int flags = align;
if (d->hasShortcut) {
flags |= Qt::TextShowMnemonic;
- QStyleOption opt;
- opt.initFrom(this);
if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
flags |= Qt::TextHideMnemonic;
}
- style->drawItemText(&painter, lr.toRect(), flags, palette(), isEnabled(), d->text, foregroundRole());
+ style->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), d->text, foregroundRole());
}
} else
#ifndef QT_NO_PICTURE
diff --git a/src/gui/widgets/qlcdnumber.cpp b/src/gui/widgets/qlcdnumber.cpp
index 0136f1a..9d98dbc 100644
--- a/src/gui/widgets/qlcdnumber.cpp
+++ b/src/gui/widgets/qlcdnumber.cpp
@@ -403,7 +403,7 @@ QLCDNumber::QLCDNumber(QWidget *parent)
Constructs an LCD number, sets the number of digits to \a
numDigits, the base to decimal, the decimal point mode to 'small'
and the frame style to a raised box. The segmentStyle() is set to
- \c Outline.
+ \c Filled.
The \a parent argument is passed to the QFrame constructor.
@@ -427,7 +427,7 @@ void QLCDNumberPrivate::init()
base = QLCDNumber::Dec;
smallPoint = false;
q->setNumDigits(ndigits);
- q->setSegmentStyle(QLCDNumber::Outline);
+ q->setSegmentStyle(QLCDNumber::Filled);
q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
}
@@ -756,6 +756,10 @@ void QLCDNumber::paintEvent(QPaintEvent *)
Q_D(QLCDNumber);
QPainter p(this);
drawFrame(&p);
+ p.setRenderHint(QPainter::Antialiasing);
+ if (d->shadow)
+ p.translate(0.5, 0.5);
+
if (d->smallPoint)
d->drawString(d->digitStr, p, &d->points, false);
else
@@ -1070,7 +1074,7 @@ void QLCDNumberPrivate::drawSegment(const QPoint &pos, char segmentNo, QPainter
q->objectName().toLocal8Bit().constData(), segmentNo);
}
// End exact copy
- p.setPen(fgColor);
+ p.setPen(Qt::NoPen);
p.setBrush(fgColor);
p.drawPolygon(a);
p.setBrush(Qt::NoBrush);
@@ -1218,8 +1222,8 @@ void QLCDNumberPrivate::drawSegment(const QPoint &pos, char segmentNo, QPainter
\header \i Style \i Result
\row \i \c Outline
\i Produces raised segments filled with the background color
- (this is the default).
\row \i \c Filled
+ (this is the default).
\i Produces raised segments filled with the foreground color.
\row \i \c Flat
\i Produces flat segments filled with the foreground color.
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp
index b03df9e..d16ed10 100644
--- a/src/gui/widgets/qlineedit.cpp
+++ b/src/gui/widgets/qlineedit.cpp
@@ -2518,7 +2518,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
// draw text, selections and cursors
#ifndef QT_NO_STYLE_STYLESHEET
if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) {
- cssStyle->focusPalette(this, &panel, &pal);
+ cssStyle->styleSheetPalette(this, &panel, &pal);
}
#endif
p.setPen(pal.text().color());
@@ -3523,6 +3523,8 @@ void QLineEditPrivate::redo() {
case RemoveSelection:
case DeleteSelection:
text.remove(cmd.pos, 1);
+ selstart = cmd.selStart;
+ selend = cmd.selEnd;
cursor = cmd.pos;
break;
case Separator:
diff --git a/src/gui/widgets/qmainwindowlayout_mac.mm b/src/gui/widgets/qmainwindowlayout_mac.mm
index c807afb..53e1ad5 100644
--- a/src/gui/widgets/qmainwindowlayout_mac.mm
+++ b/src/gui/widgets/qmainwindowlayout_mac.mm
@@ -502,11 +502,11 @@ void QMainWindowLayout::fixSizeInUnifiedToolbar(QToolBar *tb) const
QMacCocoaAutoReleasePool pool;
QWidgetItem layoutItem(tb);
QSize size = layoutItem.maximumSize();
- NSSize nssize = NSMakeSize(size.width(), size.height());
+ NSSize nssize = NSMakeSize(size.width(), size.height() - 2);
[item setMaxSize:nssize];
size = layoutItem.minimumSize();
nssize.width = size.width();
- nssize.height = size.height();
+ nssize.height = size.height() - 2;
[item setMinSize:nssize];
}
}
diff --git a/src/gui/widgets/qmdisubwindow.cpp b/src/gui/widgets/qmdisubwindow.cpp
index 6bf7633..56df8ea 100644
--- a/src/gui/widgets/qmdisubwindow.cpp
+++ b/src/gui/widgets/qmdisubwindow.cpp
@@ -1772,7 +1772,7 @@ bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const
if (isChildOfTabbedQMdiArea(q))
return false;
-#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_OS_WINCE_WM)
+#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_WS_WINCE_WM)
return true;
#else
if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q))
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp
index 7396a9d..3004841 100644
--- a/src/gui/widgets/qmenu.cpp
+++ b/src/gui/widgets/qmenu.cpp
@@ -2837,7 +2837,7 @@ void QMenu::actionEvent(QActionEvent *e)
}
#endif
-#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
+#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR)
if (!d->wce_menu)
d->wce_menu = new QMenuPrivate::QWceMenuPrivate;
if (e->type() == QEvent::ActionAdded)
diff --git a/src/gui/widgets/qmenu.h b/src/gui/widgets/qmenu.h
index 867baee..e1a6256 100644
--- a/src/gui/widgets/qmenu.h
+++ b/src/gui/widgets/qmenu.h
@@ -141,7 +141,7 @@ public:
OSMenuRef macMenu(OSMenuRef merge=0);
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
HMENU wceMenu(bool create = false);
#endif
@@ -174,7 +174,7 @@ protected:
bool focusNextPrevChild(bool next);
void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
QAction* wceCommands(uint command);
#endif
diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm
index ad848c9..cce083f 100644
--- a/src/gui/widgets/qmenu_mac.mm
+++ b/src/gui/widgets/qmenu_mac.mm
@@ -71,7 +71,6 @@ QT_BEGIN_NAMESPACE
/*****************************************************************************
QMenu globals
*****************************************************************************/
-bool qt_mac_no_native_menubar = false;
bool qt_mac_no_menubar_merge = false;
bool qt_mac_quit_menu_item_enabled = true;
int qt_mac_menus_open_count = 0;
@@ -143,6 +142,39 @@ static int qt_mac_CountMenuItems(OSMenuRef menu)
return 0;
}
+static quint32 constructModifierMask(quint32 accel_key)
+{
+ quint32 ret = 0;
+ const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
+#ifndef QT_MAC_USE_COCOA
+ if ((accel_key & Qt::ALT) == Qt::ALT)
+ ret |= kMenuOptionModifier;
+ if ((accel_key & Qt::SHIFT) == Qt::SHIFT)
+ ret |= kMenuShiftModifier;
+ if (dontSwap) {
+ if ((accel_key & Qt::META) != Qt::META)
+ ret |= kMenuNoCommandModifier;
+ if ((accel_key & Qt::CTRL) == Qt::CTRL)
+ ret |= kMenuControlModifier;
+ } else {
+ if ((accel_key & Qt::CTRL) != Qt::CTRL)
+ ret |= kMenuNoCommandModifier;
+ if ((accel_key & Qt::META) == Qt::META)
+ ret |= kMenuControlModifier;
+ }
+#else
+ if ((accel_key & Qt::CTRL) == Qt::CTRL)
+ ret |= (dontSwap ? NSControlKeyMask : NSCommandKeyMask);
+ if ((accel_key & Qt::META) == Qt::META)
+ ret |= (dontSwap ? NSCommandKeyMask : NSControlKeyMask);
+ if ((accel_key & Qt::ALT) == Qt::ALT)
+ ret |= NSAlternateKeyMask;
+ if ((accel_key & Qt::SHIFT) == Qt::SHIFT)
+ ret |= NSShiftKeyMask;
+#endif
+ return ret;
+}
+
static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp,
const QMacMenuAction *action)
{
@@ -166,7 +198,7 @@ bool qt_mac_activate_action(MenuRef menu, uint command, QAction::ActionEvent act
QMenuMergeList *list = 0;
GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList,
sizeof(list), 0, &list);
- if (!list && qt_mac_current_menubar.qmenubar) {
+ if (!list && qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) {
MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu;
GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list);
if (list)
@@ -526,15 +558,7 @@ static bool qt_mac_auto_apple_menu(MenuCommand cmd)
static void qt_mac_get_accel(quint32 accel_key, quint32 *modif, quint32 *key) {
if (modif) {
- *modif = 0;
- if ((accel_key & Qt::CTRL) != Qt::CTRL)
- *modif |= kMenuNoCommandModifier;
- if ((accel_key & Qt::META) == Qt::META)
- *modif |= kMenuControlModifier;
- if ((accel_key & Qt::ALT) == Qt::ALT)
- *modif |= kMenuOptionModifier;
- if ((accel_key & Qt::SHIFT) == Qt::SHIFT)
- *modif |= kMenuShiftModifier;
+ *modif = constructModifierMask(accel_key);
}
accel_key &= ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL);
@@ -728,6 +752,18 @@ QMacMenuAction::~QMacMenuAction()
{
#ifdef QT_MAC_USE_COCOA
[menu release];
+ if (action) {
+ QAction::MenuRole role = action->menuRole();
+ // Check if the item is owned by Qt, and should be hidden to keep it from causing
+ // problems. Do it for everything but the quit menu item since that should always
+ // be visible.
+ if (role > QAction::ApplicationSpecificRole && role < QAction::QuitRole) {
+ [menuItem setHidden:YES];
+ } else if (role == QAction::TextHeuristicRole
+ && menuItem != [getMenuLoader() quitMenuItem]) {
+ [menuItem setHidden:YES];
+ }
+ }
[menuItem setTag:nil];
[menuItem release];
#endif
@@ -917,21 +953,22 @@ static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action)
ret = action->action->shortcut();
#ifndef QT_MAC_USE_COCOA
else if (action->command == kHICommandPreferences)
- ret = QKeySequence(Qt::CTRL+Qt::Key_Comma);
+ ret = QKeySequence(QKeySequence::Preferences);
else if (action->command == kHICommandQuit)
- ret = QKeySequence(Qt::CTRL+Qt::Key_Q);
+ ret = QKeySequence(QKeySequence::Quit);
#else
else if (action->menuItem == [loader preferencesMenuItem])
- ret = QKeySequence(Qt::CTRL+Qt::Key_Comma);
+ ret = QKeySequence(QKeySequence::Preferences);
else if (action->menuItem == [loader quitMenuItem])
- ret = QKeySequence(Qt::CTRL+Qt::Key_Q);
+ ret = QKeySequence(QKeySequence::Quit);
#endif
return ret;
}
void Q_GUI_EXPORT qt_mac_set_menubar_icons(bool b)
{ QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, !b); }
-void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b) { qt_mac_no_native_menubar = !b; }
+void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b)
+{ QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, !b); }
void Q_GUI_EXPORT qt_mac_set_menubar_merge(bool b) { qt_mac_no_menubar_merge = !b; }
/*****************************************************************************
@@ -1208,58 +1245,21 @@ QMenuPrivate::QMacMenuPrivate::addAction(QMacMenuAction *action, QMacMenuAction
NSString *keySequenceToKeyEqivalent(const QKeySequence &accel)
{
quint32 accel_key = (accel[0] & ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL));
- unichar keyEquiv[1] = { 0 };
- if (accel_key == Qt::Key_Return)
- keyEquiv[0] = kReturnCharCode;
- else if (accel_key == Qt::Key_Enter)
- keyEquiv[0] = kEnterCharCode;
- else if (accel_key == Qt::Key_Tab)
- keyEquiv[0] = kTabCharCode;
- else if (accel_key == Qt::Key_Backspace)
- keyEquiv[0] = kBackspaceCharCode;
- else if (accel_key == Qt::Key_Delete)
- keyEquiv[0] = NSDeleteFunctionKey;
- else if (accel_key == Qt::Key_Escape)
- keyEquiv[0] = kEscapeCharCode;
- else if (accel_key == Qt::Key_PageUp)
- keyEquiv[0] = NSPageUpFunctionKey;
- else if (accel_key == Qt::Key_PageDown)
- keyEquiv[0] = NSPageDownFunctionKey;
- else if (accel_key == Qt::Key_Up)
- keyEquiv[0] = NSUpArrowFunctionKey;
- else if (accel_key == Qt::Key_Down)
- keyEquiv[0] = NSDownArrowFunctionKey;
- else if (accel_key == Qt::Key_Left)
- keyEquiv[0] = NSLeftArrowFunctionKey;
- else if (accel_key == Qt::Key_Right)
- keyEquiv[0] = NSRightArrowFunctionKey;
- else if (accel_key == Qt::Key_CapsLock)
- keyEquiv[0] = kMenuCapsLockGlyph; // ### Cocoa has no equivalent
- else if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15)
- keyEquiv[0] = (accel_key - Qt::Key_F1) + NSF1FunctionKey;
- else if (accel_key == Qt::Key_Home)
- keyEquiv[0] = NSHomeFunctionKey;
- else if (accel_key == Qt::Key_End)
- keyEquiv[0] = NSEndFunctionKey;
- else
- keyEquiv[0] = unichar(QChar(accel_key).toLower().unicode());
- return [NSString stringWithCharacters:keyEquiv length:1];
+ extern QChar qt_macSymbolForQtKey(int key); // qkeysequence.cpp
+ QChar keyEquiv = qt_macSymbolForQtKey(accel_key);
+ if (keyEquiv.isNull()) {
+ if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15)
+ keyEquiv = (accel_key - Qt::Key_F1) + NSF1FunctionKey;
+ else
+ keyEquiv = unichar(QChar(accel_key).toLower().unicode());
+ }
+ return [NSString stringWithCharacters:&keyEquiv.unicode() length:1];
}
// return the cocoa modifier mask for the QKeySequence (currently only looks at the first one).
NSUInteger keySequenceModifierMask(const QKeySequence &accel)
{
- NSUInteger ret = 0;
- quint32 accel_key = accel[0];
- if ((accel_key & Qt::CTRL) == Qt::CTRL)
- ret |= NSCommandKeyMask;
- if ((accel_key & Qt::META) == Qt::META)
- ret |= NSControlKeyMask;
- if ((accel_key & Qt::ALT) == Qt::ALT)
- ret |= NSAlternateKeyMask;
- if ((accel_key & Qt::SHIFT) == Qt::SHIFT)
- ret |= NSShiftKeyMask;
- return ret;
+ return constructModifierMask(accel[0]);
}
void
@@ -1728,9 +1728,14 @@ QMenuBarPrivate::macCreateMenuBar(QWidget *parent)
{
Q_Q(QMenuBar);
static int checkEnv = -1;
+ // We call the isNativeMenuBar function here
+ // becasue that will make sure that local overrides
+ // are dealt with correctly.
+ bool qt_mac_no_native_menubar = !q->isNativeMenuBar();
if (qt_mac_no_native_menubar == false && checkEnv < 0) {
checkEnv = !qgetenv("QT_MAC_NO_NATIVE_MENUBAR").isEmpty();
- qt_mac_no_native_menubar = checkEnv;
+ QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, checkEnv);
+ qt_mac_no_native_menubar = !q->isNativeMenuBar();
}
if (!qt_mac_no_native_menubar) {
extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp
@@ -1765,7 +1770,7 @@ void QMenuBarPrivate::macDestroyMenuBar()
OSMenuRef QMenuBarPrivate::macMenu()
{
Q_Q(QMenuBar);
- if (!mac_menubar) {
+ if (!q->isNativeMenuBar() || !mac_menubar) {
return 0;
} else if (!mac_menubar->menu) {
mac_menubar->menu = qt_mac_create_menu(q);
@@ -1886,9 +1891,6 @@ static void cancelAllMenuTracking()
*/
bool QMenuBar::macUpdateMenuBar()
{
- if (qt_mac_no_native_menubar) //nothing to be done..
- return true;
-
cancelAllMenuTracking();
QMenuBar *mb = 0;
//find a menu bar
@@ -1922,7 +1924,7 @@ bool QMenuBar::macUpdateMenuBar()
mb = fallback;
//now set it
bool ret = false;
- if (mb) {
+ if (mb && mb->isNativeMenuBar()) {
#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
#endif
@@ -1943,7 +1945,7 @@ bool QMenuBar::macUpdateMenuBar()
qt_mac_current_menubar.qmenubar = mb;
qt_mac_current_menubar.modal = QApplicationPrivate::modalState();
ret = true;
- } else if (qt_mac_current_menubar.qmenubar) {
+ } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) {
const bool modal = QApplicationPrivate::modalState();
if (modal != qt_mac_current_menubar.modal) {
ret = true;
diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h
index e3c4890..dddd83e 100644
--- a/src/gui/widgets/qmenu_p.h
+++ b/src/gui/widgets/qmenu_p.h
@@ -112,7 +112,7 @@ struct QMenuMergeItem
typedef QList<QMenuMergeItem> QMenuMergeList;
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
struct QWceMenuAction {
uint command;
QPointer<QAction> action;
@@ -132,7 +132,7 @@ public:
#ifdef Q_WS_MAC
,mac_menu(0)
#endif
-#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
+#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR)
,wce_menu(0)
#endif
#ifdef QT3_SUPPORT
@@ -145,7 +145,7 @@ public:
#ifdef Q_WS_MAC
delete mac_menu;
#endif
-#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
+#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR)
delete wce_menu;
#endif
}
@@ -293,7 +293,7 @@ public:
bool emitHighlighted;
#endif
-#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
+#if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR)
struct QWceMenuPrivate {
QList<QWceMenuAction*> actionItems;
HMENU menuHandle;
diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp
index 42a4e0b..2ce89f9 100644
--- a/src/gui/widgets/qmenu_wince.cpp
+++ b/src/gui/widgets/qmenu_wince.cpp
@@ -40,7 +40,7 @@
****************************************************************************/
//Native menubars are only supported for Windows Mobile not the standard SDK/generic WinCE
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include "qmenu.h"
#include "qt_windows.h"
#include "qapplication.h"
@@ -621,4 +621,4 @@ void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() {
QT_END_NAMESPACE
#endif //QT_NO_MENUBAR
-#endif //Q_OS_WINCE
+#endif //Q_WS_WINCE
diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp
index ccf37db..d2e6bfb 100644
--- a/src/gui/widgets/qmenubar.cpp
+++ b/src/gui/widgets/qmenubar.cpp
@@ -67,7 +67,7 @@
#include "qmenubar_p.h"
#include "qdebug.h"
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
#endif
@@ -194,7 +194,7 @@ void QMenuBarPrivate::updateGeometries()
}
#ifdef Q_WS_MAC
- if(mac_menubar) {//nothing to see here folks, move along..
+ if(q->isNativeMenuBar()) {//nothing to see here folks, move along..
itemsDirty = false;
return;
}
@@ -725,7 +725,7 @@ void QMenuBarPrivate::init()
if(mac_menubar)
q->hide();
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qt_wince_is_mobile()) {
wceCreateMenuBar(q->parentWidget());
if(wce_menubar)
@@ -776,7 +776,7 @@ QMenuBar::~QMenuBar()
Q_D(QMenuBar);
d->macDestroyMenuBar();
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
Q_D(QMenuBar);
if (qt_wince_is_mobile())
d->wceDestroyMenuBar();
@@ -1025,14 +1025,8 @@ void QMenuBar::paintEvent(QPaintEvent *e)
*/
void QMenuBar::setVisible(bool visible)
{
-#ifdef Q_WS_MAC
- Q_D(QMenuBar);
- if(d->mac_menubar)
- return;
-#endif
-#ifdef Q_OS_WINCE
- Q_D(QMenuBar);
- if(d->wce_menubar)
+#if defined(Q_WS_MAC) || defined(Q_OS_WINCE)
+ if (isNativeMenuBar())
return;
#endif
QWidget::setVisible(visible);
@@ -1272,24 +1266,21 @@ void QMenuBar::actionEvent(QActionEvent *e)
{
Q_D(QMenuBar);
d->itemsDirty = true;
+#if defined (Q_WS_MAC) || defined(Q_OS_WINCE)
+ if (isNativeMenuBar()) {
#ifdef Q_WS_MAC
- if(d->mac_menubar) {
- if(e->type() == QEvent::ActionAdded)
- d->mac_menubar->addAction(e->action(), d->mac_menubar->findAction(e->before()));
- else if(e->type() == QEvent::ActionRemoved)
- d->mac_menubar->removeAction(e->action());
- else if(e->type() == QEvent::ActionChanged)
- d->mac_menubar->syncAction(e->action());
- }
+ QMenuBarPrivate::QMacMenuBarPrivate *nativeMenuBar = d->mac_menubar;
+#else
+ QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar;
#endif
-#ifdef Q_OS_WINCE
- if(d->wce_menubar) {
+ if (!nativeMenuBar)
+ return;
if(e->type() == QEvent::ActionAdded)
- d->wce_menubar->addAction(e->action(), d->wce_menubar->findAction(e->before()));
+ nativeMenuBar->addAction(e->action(), nativeMenuBar->findAction(e->before()));
else if(e->type() == QEvent::ActionRemoved)
- d->wce_menubar->removeAction(e->action());
+ nativeMenuBar->removeAction(e->action());
else if(e->type() == QEvent::ActionChanged)
- d->wce_menubar->syncAction(e->action());
+ nativeMenuBar->syncAction(e->action());
}
#endif
if(e->type() == QEvent::ActionAdded) {
@@ -1374,7 +1365,7 @@ void QMenuBarPrivate::handleReparent()
macCreateMenuBar(newParent);
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qt_wince_is_mobile() && wce_menubar)
wce_menubar->rebuild();
#endif
@@ -1612,10 +1603,8 @@ QRect QMenuBar::actionGeometry(QAction *act) const
QSize QMenuBar::minimumSizeHint() const
{
Q_D(const QMenuBar);
-#ifdef Q_WS_MAC
- const bool as_gui_menubar = !d->mac_menubar;
-#elif defined (Q_OS_WINCE)
- const bool as_gui_menubar = !d->wce_menubar;
+#if defined(Q_WS_MAC) || defined(Q_WS_WINCE)
+ const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif
@@ -1672,14 +1661,13 @@ QSize QMenuBar::minimumSizeHint() const
QSize QMenuBar::sizeHint() const
{
Q_D(const QMenuBar);
-#ifdef Q_WS_MAC
- const bool as_gui_menubar = !d->mac_menubar;
-#elif defined (Q_OS_WINCE)
- const bool as_gui_menubar = !d->wce_menubar;
+#if defined(Q_WS_MAC) || defined(Q_WS_WINCE)
+ const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif
+
ensurePolished();
QSize ret(0, 0);
const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this);
@@ -1735,13 +1723,12 @@ QSize QMenuBar::sizeHint() const
int QMenuBar::heightForWidth(int) const
{
Q_D(const QMenuBar);
-#ifdef Q_WS_MAC
- const bool as_gui_menubar = !d->mac_menubar;
-#elif defined (Q_OS_WINCE)
- const bool as_gui_menubar = !d->wce_menubar;
+#if defined(Q_WS_MAC) || defined(Q_WS_WINCE)
+ const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif
+
int height = 0;
const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
@@ -1856,6 +1843,60 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const
}
/*!
+ \property QMenuBar::nativeMenuBar
+ \brief Whether or not a menubar will be used as a native menubar on platforms that support it
+ \since 4.6
+
+ This property specifies whether or not the menubar should be used as a native menubar on platforms
+ that support it. The currently supported platforms are Mac OS X and Windows CE. On these platforms
+ if this property is true, the menubar is used in the native menubar and is not in the window of
+ its parent, if false the menubar remains in the window. On other platforms the value of this
+ attribute has no effect.
+
+ The default is to follow whether the Qt::AA_DontUseNativeMenuBar attribute
+ is set for the application. Explicitly settings this property overrides
+ the presence (or abscence) of the attribute.
+*/
+
+void QMenuBar::setNativeMenuBar(bool nativeMenuBar)
+{
+ Q_D(QMenuBar);
+ if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) {
+ d->nativeMenuBar = nativeMenuBar;
+#ifdef Q_WS_MAC
+ if (!d->nativeMenuBar) {
+ extern void qt_mac_clear_menubar();
+ qt_mac_clear_menubar();
+ d->macDestroyMenuBar();
+ const QList<QAction *> &menubarActions = actions();
+ for (int i = 0; i < menubarActions.size(); ++i) {
+ const QAction *action = menubarActions.at(i);
+ if (QMenu *menu = action->menu()) {
+ delete menu->d_func()->mac_menu;
+ menu->d_func()->mac_menu = 0;
+ }
+ }
+ } else {
+ d->macCreateMenuBar(parentWidget());
+ }
+ macUpdateMenuBar();
+ updateGeometry();
+ setVisible(false);
+ setVisible(true);
+#endif
+ }
+}
+
+bool QMenuBar::isNativeMenuBar() const
+{
+ Q_D(const QMenuBar);
+ if (d->nativeMenuBar == -1) {
+ return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar);
+ }
+ return d->nativeMenuBar;
+}
+
+/*!
\since 4.4
Sets the default action to \a act.
@@ -1869,13 +1910,13 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const
\sa defaultAction()
*/
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void QMenuBar::setDefaultAction(QAction *act)
{
Q_D(QMenuBar);
if (d->defaultAction == act)
return;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qt_wince_is_mobile())
if (d->defaultAction) {
disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));
@@ -1883,7 +1924,7 @@ void QMenuBar::setDefaultAction(QAction *act)
}
#endif
d->defaultAction = act;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
if (qt_wince_is_mobile())
if (d->defaultAction) {
connect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));
diff --git a/src/gui/widgets/qmenubar.h b/src/gui/widgets/qmenubar.h
index 42f0c0c..58a03ff 100644
--- a/src/gui/widgets/qmenubar.h
+++ b/src/gui/widgets/qmenubar.h
@@ -64,6 +64,7 @@ class Q_GUI_EXPORT QMenuBar : public QWidget
Q_OBJECT
Q_PROPERTY(bool defaultUp READ isDefaultUp WRITE setDefaultUp)
+ Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar)
public:
explicit QMenuBar(QWidget *parent = 0);
@@ -110,7 +111,7 @@ public:
static bool macUpdateMenuBar();
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void setDefaultAction(QAction *);
QAction *defaultAction() const;
@@ -118,6 +119,9 @@ public:
static void wceRefresh();
#endif
+ bool isNativeMenuBar() const;
+ void setNativeMenuBar(bool nativeMenuBar);
+
public Q_SLOTS:
virtual void setVisible(bool visible);
@@ -339,7 +343,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int))
Q_PRIVATE_SLOT(d_func(), void _q_updateLayout())
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
Q_PRIVATE_SLOT(d_func(), void _q_updateDefaultAction())
#endif
diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h
index 223346b..5dab310 100644
--- a/src/gui/widgets/qmenubar_p.h
+++ b/src/gui/widgets/qmenubar_p.h
@@ -57,7 +57,7 @@
#include "QtGui/qstyleoption.h"
#include <private/qmenu_p.h> // Mac needs what in this file!
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
#include "qguifunctions_wince.h"
#endif
@@ -70,12 +70,13 @@ class QMenuBarPrivate : public QWidgetPrivate
Q_DECLARE_PUBLIC(QMenuBar)
public:
QMenuBarPrivate() : itemsDirty(0), itemsWidth(0), itemsStart(-1), currentAction(0), mouseDown(0),
- closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0)
+ closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0),
+ nativeMenuBar(-1)
#ifdef Q_WS_MAC
, mac_menubar(0)
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
, wce_menubar(0), wceClassicMenu(false)
#endif
{ }
@@ -84,7 +85,7 @@ public:
#ifdef Q_WS_MAC
delete mac_menubar;
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
delete wce_menubar;
#endif
}
@@ -119,6 +120,8 @@ public:
uint keyboardState : 1, altPressed : 1;
QPointer<QWidget> keyboardFocusWidget;
+
+ int nativeMenuBar : 3; // Only has values -1, 0, and 1
//firing of events
void activateAction(QAction *, QAction::ActionEvent);
@@ -127,7 +130,7 @@ public:
void _q_internalShortcutActivated(int);
void _q_updateLayout();
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void _q_updateDefaultAction();
#endif
@@ -181,7 +184,7 @@ public:
void macDestroyMenuBar();
OSMenuRef macMenu();
#endif
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
void wceCreateMenuBar(QWidget *);
void wceDestroyMenuBar();
struct QWceMenuBarPrivate {
diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp
index e563fa1..f317742 100644
--- a/src/gui/widgets/qplaintextedit.cpp
+++ b/src/gui/widgets/qplaintextedit.cpp
@@ -370,11 +370,16 @@ void QPlainTextDocumentLayout::layoutBlock(const QTextBlock &block)
extraMargin += fm.width(QChar(0x21B5));
}
tl->beginLayout();
+ qreal availableWidth = d->width;
+ if (availableWidth <= 0) {
+ availableWidth = INT_MAX; // similar to text edit with pageSize.width == 0
+ }
+ availableWidth -= 2*margin + extraMargin;
while (1) {
QTextLine line = tl->createLine();
if (!line.isValid())
break;
- line.setLineWidth(d->width - 2*margin - extraMargin);
+ line.setLineWidth(availableWidth);
height += leading;
line.setPosition(QPointF(margin, height));
@@ -555,7 +560,8 @@ QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const {
if (!currentBlock.isValid())
return QRectF();
Q_ASSERT(currentBlock.blockNumber() == currentBlockNumber);
- QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout());
+ QTextDocument *doc = document();
+ QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout());
Q_ASSERT(documentLayout);
QPointF offset;
@@ -566,13 +572,22 @@ QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const {
offset.ry() += r.height();
currentBlock = currentBlock.next();
++currentBlockNumber;
+ if (!currentBlock.isVisible()) {
+ currentBlock = doc->findBlockByLineNumber(currentBlock.firstLineNumber());
+ currentBlockNumber = currentBlock.blockNumber();
+ }
r = documentLayout->blockBoundingRect(currentBlock);
}
while (currentBlockNumber > blockNumber && offset.y() >= -textEdit->viewport()->height()) {
currentBlock = currentBlock.previous();
+ --currentBlockNumber;
+ while (!currentBlock.isVisible()) {
+ currentBlock = currentBlock.previous();
+ --currentBlockNumber;
+ }
if (!currentBlock.isValid())
break;
- --currentBlockNumber;
+
r = documentLayout->blockBoundingRect(currentBlock);
offset.ry() -= r.height();
}
diff --git a/src/gui/widgets/qprintpreviewwidget.cpp b/src/gui/widgets/qprintpreviewwidget.cpp
index 16334b8..d4e5122 100644
--- a/src/gui/widgets/qprintpreviewwidget.cpp
+++ b/src/gui/widgets/qprintpreviewwidget.cpp
@@ -98,29 +98,8 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QRectF paperRect(0,0, paperSize.width(), paperSize.height());
- painter->setClipRect(paperRect & option->exposedRect);
- painter->fillRect(paperRect, Qt::white);
- if (!pagePicture)
- return;
- painter->drawPicture(pageRect.topLeft(), *pagePicture);
-
- // Effect: make anything drawn in the margins look washed out.
- QPainterPath path;
- path.addRect(paperRect);
- path.addRect(pageRect);
- painter->setPen(QPen(Qt::NoPen));
- painter->setBrush(QColor(255, 255, 255, 180));
- painter->drawPath(path);
-
- painter->setClipRect(option->exposedRect);
-#if 0
- // Draw frame around paper.
- painter->setPen(QPen(Qt::black, 0));
- painter->setBrush(Qt::NoBrush);
- painter->drawRect(paperRect);
-#endif
-
// Draw shadow
+ painter->setClipRect(option->exposedRect);
qreal shWidth = paperRect.width()/100;
QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth),
paperRect.bottomRight() + QPointF(shWidth, 0));
@@ -141,6 +120,27 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
cgrad.setColorAt(1.0, QColor(0,0,0,0));
painter->fillRect(cshadow, QBrush(cgrad));
+ painter->setClipRect(paperRect & option->exposedRect);
+ painter->fillRect(paperRect, Qt::white);
+ if (!pagePicture)
+ return;
+ painter->drawPicture(pageRect.topLeft(), *pagePicture);
+
+ // Effect: make anything drawn in the margins look washed out.
+ QPainterPath path;
+ path.addRect(paperRect);
+ path.addRect(pageRect);
+ painter->setPen(QPen(Qt::NoPen));
+ painter->setBrush(QColor(255, 255, 255, 180));
+ painter->drawPath(path);
+
+#if 0
+ // Draw frame around paper.
+ painter->setPen(QPen(Qt::black, 0));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(paperRect);
+#endif
+
// todo: drawtext "Page N" below paper
}
diff --git a/src/gui/widgets/qslider.cpp b/src/gui/widgets/qslider.cpp
index 32b9021..5b9c8a4 100644
--- a/src/gui/widgets/qslider.cpp
+++ b/src/gui/widgets/qslider.cpp
@@ -62,7 +62,6 @@ public:
int tickInterval;
QSlider::TickPosition tickPosition;
int clickOffset;
- int snapBackPosition;
void init();
void resetLayoutItemMargins();
int pixelPosToRangeValue(int pos) const;
@@ -493,7 +492,6 @@ void QSlider::mousePressEvent(QMouseEvent *ev)
setRepeatAction(SliderNoAction);
QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
d->clickOffset = d->pick(ev->pos() - sr.topLeft());
- d->snapBackPosition = d->position;
update(sr);
setSliderDown(true);
}
@@ -513,14 +511,6 @@ void QSlider::mouseMoveEvent(QMouseEvent *ev)
int newPosition = d->pixelPosToRangeValue(d->pick(ev->pos()) - d->clickOffset);
QStyleOptionSlider opt;
initStyleOption(&opt);
- int m = style()->pixelMetric(QStyle::PM_MaximumDragDistance, &opt, this);
- if (m >= 0) {
- QRect r = rect();
- r.adjust(-m, -m, m, m);
- if (!r.contains(ev->pos())) {
- newPosition = d->snapBackPosition;
- }
- }
setSliderPosition(newPosition);
}
diff --git a/src/gui/widgets/qsplitter.cpp b/src/gui/widgets/qsplitter.cpp
index bf8af35..06774bc 100644
--- a/src/gui/widgets/qsplitter.cpp
+++ b/src/gui/widgets/qsplitter.cpp
@@ -119,7 +119,6 @@ QSplitterHandle::QSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
{
Q_D(QSplitterHandle);
d->s = parent;
- d->hover = false;
setOrientation(orientation);
}
@@ -269,8 +268,11 @@ void QSplitterHandle::mouseMoveEvent(QMouseEvent *e)
void QSplitterHandle::mousePressEvent(QMouseEvent *e)
{
Q_D(QSplitterHandle);
- if (e->button() == Qt::LeftButton)
+ if (e->button() == Qt::LeftButton) {
d->mouseOffset = d->pick(e->pos());
+ d->pressed = true;
+ update();
+ }
}
/*!
@@ -285,6 +287,10 @@ void QSplitterHandle::mouseReleaseEvent(QMouseEvent *e)
d->s->setRubberBand(-1);
moveSplitter(pos);
}
+ if (e->button() == Qt::LeftButton) {
+ d->pressed = false;
+ update();
+ }
}
/*!
@@ -303,6 +309,8 @@ void QSplitterHandle::paintEvent(QPaintEvent *)
opt.state = QStyle::State_None;
if (d->hover)
opt.state |= QStyle::State_MouseOver;
+ if (d->pressed)
+ opt.state |= QStyle::State_Sunken;
if (isEnabled())
opt.state |= QStyle::State_Enabled;
parentWidget()->style()->drawControl(QStyle::CE_Splitter, &opt, &p, d->s);
diff --git a/src/gui/widgets/qsplitter_p.h b/src/gui/widgets/qsplitter_p.h
index 5cc43af..9f6fe0c 100644
--- a/src/gui/widgets/qsplitter_p.h
+++ b/src/gui/widgets/qsplitter_p.h
@@ -131,16 +131,17 @@ class QSplitterHandlePrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QSplitterHandle)
public:
- QSplitterHandlePrivate() : orient(Qt::Horizontal), opaq(false), s(0), mouseOffset(0) {}
+ QSplitterHandlePrivate() : s(0), orient(Qt::Horizontal), mouseOffset(0), opaq(false), hover(false), pressed(false) {}
inline int pick(const QPoint &pos) const
{ return orient == Qt::Horizontal ? pos.x() : pos.y(); }
- Qt::Orientation orient;
- bool opaq;
QSplitter *s;
- bool hover;
+ Qt::Orientation orient;
int mouseOffset;
+ bool opaq : 1;
+ bool hover : 1;
+ bool pressed : 1;
};
QT_END_NAMESPACE
diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp
index 69221ba..0b4ce9d 100644
--- a/src/gui/widgets/qtabbar.cpp
+++ b/src/gui/widgets/qtabbar.cpp
@@ -176,12 +176,11 @@ void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const
if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner))
option->cornerWidgets |= QStyleOptionTab::RightCornerWidget;
}
+#endif
QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this);
-
option->text = fontMetrics().elidedText(option->text, d->elideMode, textRect.width(),
Qt::TextShowMnemonic);
-#endif
}
/*!
@@ -1941,8 +1940,10 @@ void QTabBar::changeEvent(QEvent *event)
if (event->type() == QEvent::StyleChange) {
d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this));
d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this);
+ d->refresh();
+ } else if (event->type() == QEvent::FontChange) {
+ d->refresh();
}
- d->refresh();
QWidget::changeEvent(event);
}
diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp
index 1babb6d..d765794 100644
--- a/src/gui/widgets/qtoolbar.cpp
+++ b/src/gui/widgets/qtoolbar.cpp
@@ -274,9 +274,11 @@ void QToolBarPrivate::endDrag()
bool QToolBarPrivate::mousePressEvent(QMouseEvent *event)
{
- if (layout->handleRect().contains(event->pos()) == false) {
+ Q_Q(QToolBar);
+ QStyleOptionToolBar opt;
+ q->initStyleOption(&opt);
+ if (q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q).contains(event->pos()) == false) {
#ifdef Q_WS_MAC
- Q_Q(QToolBar);
// When using the unified toolbar on Mac OS X the user can can click and
// drag between toolbar contents to move the window. Make this work by
// implementing the standard mouse-dragging code and then call
@@ -1041,7 +1043,7 @@ void QToolBar::paintEvent(QPaintEvent *)
style->drawControl(QStyle::CE_ToolBar, &opt, &p, this);
}
- opt.rect = d->layout->handleRect();
+ opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, this);
if (opt.rect.isValid())
style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this);
}
@@ -1142,7 +1144,9 @@ bool QToolBar::event(QEvent *event)
case QEvent::HoverMove: {
#ifndef QT_NO_CURSOR
QHoverEvent *e = static_cast<QHoverEvent*>(event);
- if (d->layout->handleRect().contains(e->pos()))
+ QStyleOptionToolBar opt;
+ initStyleOption(&opt);
+ if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->pos()))
setCursor(Qt::SizeAllCursor);
else
unsetCursor();
@@ -1153,7 +1157,7 @@ bool QToolBar::event(QEvent *event)
if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event)))
return true;
break;
-#ifdef Q_OS_WINCE
+#ifdef Q_WS_WINCE
case QEvent::ContextMenu:
{
QContextMenuEvent* contextMenuEvent = static_cast<QContextMenuEvent*>(event);
diff --git a/src/gui/widgets/qtoolbarlayout.cpp b/src/gui/widgets/qtoolbarlayout.cpp
index 7771f46..0bfa493 100644
--- a/src/gui/widgets/qtoolbarlayout.cpp
+++ b/src/gui/widgets/qtoolbarlayout.cpp
@@ -334,7 +334,7 @@ void QToolBarLayout::updateGeomArray() const
if (QMainWindow *mw = qobject_cast<QMainWindow *>(parentWidget()->parentWidget())) {
if (mw->unifiedTitleAndToolBarOnMac()
&& mw->toolBarArea(static_cast<QToolBar *>(parentWidget())) == Qt::TopToolBarArea) {
- if (that->expandFlag) {
+ if (expandFlag) {
tb->setMaximumSize(0xFFFFFF, 0xFFFFFF);
} else {
tb->setMaximumSize(hint);
@@ -360,23 +360,11 @@ void QToolBarLayout::setGeometry(const QRect &rect)
QStyle *style = tb->style();
QStyleOptionToolBar opt;
tb->initStyleOption(&opt);
- const int handleExtent = movable()
- ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
const int margin = this->margin();
const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
Qt::Orientation o = tb->orientation();
QLayout::setGeometry(rect);
- if (movable()) {
- if (o == Qt::Horizontal) {
- handRect = QRect(margin, margin, handleExtent, rect.height() - 2*margin);
- handRect = QStyle::visualRect(parentWidget()->layoutDirection(), rect, handRect);
- } else {
- handRect = QRect(margin, margin, rect.width() - 2*margin, handleExtent);
- }
- } else {
- handRect = QRect();
- }
bool ranOutOfSpace = false;
if (!animating)
@@ -742,11 +730,6 @@ QToolBarItem *QToolBarLayout::createItem(QAction *action)
return result;
}
-QRect QToolBarLayout::handleRect() const
-{
- return handRect;
-}
-
QT_END_NAMESPACE
#endif // QT_NO_TOOLBAR
diff --git a/src/gui/widgets/qtoolbarlayout_p.h b/src/gui/widgets/qtoolbarlayout_p.h
index 2eca773..37755b1 100644
--- a/src/gui/widgets/qtoolbarlayout_p.h
+++ b/src/gui/widgets/qtoolbarlayout_p.h
@@ -65,7 +65,7 @@ class QAction;
class QToolBarExtension;
class QMenu;
-class Q_GUI_EXPORT QToolBarItem : public QWidgetItem
+class QToolBarItem : public QWidgetItem
{
public:
QToolBarItem(QWidget *widget);
@@ -75,7 +75,7 @@ public:
bool customWidget;
};
-class Q_GUI_EXPORT QToolBarLayout : public QLayout
+class QToolBarLayout : public QLayout
{
Q_OBJECT
@@ -100,8 +100,6 @@ public:
int indexOf(QAction *action) const;
int indexOf(QWidget *widget) const { return QLayout::indexOf(widget); }
- QRect handleRect() const;
-
bool layoutActions(const QSize &size);
QSize expandedSize(const QSize &size) const;
bool expanded, animating;
diff --git a/src/gui/widgets/qtoolbutton.cpp b/src/gui/widgets/qtoolbutton.cpp
index 7390d04..20b84ef 100644
--- a/src/gui/widgets/qtoolbutton.cpp
+++ b/src/gui/widgets/qtoolbutton.cpp
@@ -859,8 +859,7 @@ void QToolButtonPrivate::_q_buttonPressed()
Q_Q(QToolButton);
if (!hasMenu())
return; // no menu to show
-
- if (delay > 0 && popupMode == QToolButton::DelayedPopup)
+ if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup)
popupTimer.start(delay, q);
else if (delay == 0 || popupMode == QToolButton::InstantPopup)
q->showMenu();