From e7cf829c91716ceeb878309a29ef452681dedb09 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 29 Apr 2009 17:12:53 +0200 Subject: Corrected description of the QLayout::takeAt() function An item is not deleted when removed from the index. The remaining items get a new index. I changed deleted to removed. Tasknumber: 252547 Rev-by: janarve --- src/gui/kernel/qlayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qlayout.cpp b/src/gui/kernel/qlayout.cpp index aa46249..1d5a70d 100644 --- a/src/gui/kernel/qlayout.cpp +++ b/src/gui/kernel/qlayout.cpp @@ -1239,7 +1239,7 @@ bool QLayout::activate() Must be implemented in subclasses to remove the layout item at \a index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered - consecutively from 0. If an item is deleted, other items will be + consecutively from 0. If an item is removed, other items will be renumbered. The following code fragment shows a safe way to remove all items -- cgit v0.12 From d5d8ea9f879e67a7603f47a9a7b6facc489a01d8 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 29 Apr 2009 17:14:58 +0200 Subject: Corrected typo Changed smae to same Taks number:251646 --- doc/src/layout.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/layout.qdoc b/doc/src/layout.qdoc index 38163c8..55dfd8b 100644 --- a/doc/src/layout.qdoc +++ b/doc/src/layout.qdoc @@ -371,7 +371,7 @@ should store the value in a local variable if you need it again later within in the same function. \o You should not call QLayoutItem::setGeometry() twice on the same - item in the smae function. This call can be very expensive if the + item in the same function. This call can be very expensive if the item has several child widgets, because the layout manager must do a complete layout every time. Instead, calculate the geometry and then set it. (This does not only apply to layouts, you should do -- cgit v0.12 From 3c9fe1670ca0145a131764c26811f9d86ccd714e Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 29 Apr 2009 17:18:06 +0200 Subject: Corrected bugs in the flow layout example Corrected bugs in the example and added markers for snippets in the documentation. Task-number: 250616 Rev-by: Geir Vattekar --- examples/layouts/flowlayout/flowlayout.cpp | 27 ++++++++++++++++++++++++--- examples/layouts/flowlayout/flowlayout.h | 3 ++- examples/layouts/flowlayout/window.cpp | 3 ++- examples/layouts/flowlayout/window.h | 3 ++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/examples/layouts/flowlayout/flowlayout.cpp b/examples/layouts/flowlayout/flowlayout.cpp index c4032d0..263911d 100644 --- a/examples/layouts/flowlayout/flowlayout.cpp +++ b/examples/layouts/flowlayout/flowlayout.cpp @@ -42,7 +42,7 @@ #include #include "flowlayout.h" - +//! [1] FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) { @@ -54,19 +54,25 @@ FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) { setContentsMargins(margin, margin, margin, margin); } +//! [1] +//! [2] FlowLayout::~FlowLayout() { QLayoutItem *item; while ((item = takeAt(0))) delete item; } +//! [2] +//! [3] void FlowLayout::addItem(QLayoutItem *item) { itemList.append(item); } +//! [3] +//! [4] int FlowLayout::horizontalSpacing() const { if (m_hSpace >= 0) { @@ -84,7 +90,9 @@ int FlowLayout::verticalSpacing() const return smartSpacing(QStyle::PM_LayoutVerticalSpacing); } } +//! [4] +//! [5] int FlowLayout::count() const { return itemList.size(); @@ -102,12 +110,16 @@ QLayoutItem *FlowLayout::takeAt(int index) else return 0; } +//! [5] +//! [6] Qt::Orientations FlowLayout::expandingDirections() const { return 0; } +//! [6] +//! [7] bool FlowLayout::hasHeightForWidth() const { return true; @@ -118,7 +130,9 @@ int FlowLayout::heightForWidth(int width) const int height = doLayout(QRect(0, 0, width, 0), true); return height; } +//! [7] +//! [8] void FlowLayout::setGeometry(const QRect &rect) { QLayout::setGeometry(rect); @@ -140,7 +154,9 @@ QSize FlowLayout::minimumSize() const size += QSize(2*margin(), 2*margin()); return size; } +//! [8] +//! [9] int FlowLayout::doLayout(const QRect &rect, bool testOnly) const { int left, top, right, bottom; @@ -149,7 +165,9 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const int x = effectiveRect.x(); int y = effectiveRect.y(); int lineHeight = 0; +//! [9] +//! [10] QLayoutItem *item; foreach (item, itemList) { QWidget *wid = item->widget(); @@ -161,6 +179,8 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const if (spaceY == -1) spaceY = wid->style()->layoutSpacing( QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical); +//! [10] +//! [11] int nextX = x + item->sizeHint().width() + spaceX; if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) { x = effectiveRect.x(); @@ -177,7 +197,8 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const } return y + lineHeight - rect.y() + bottom; } - +//! [11] +//! [12] int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const { QObject *parent = this->parent(); @@ -190,4 +211,4 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const return static_cast(parent)->spacing(); } } - +//! [12] diff --git a/examples/layouts/flowlayout/flowlayout.h b/examples/layouts/flowlayout/flowlayout.h index 9940e55..bab7f36 100644 --- a/examples/layouts/flowlayout/flowlayout.h +++ b/examples/layouts/flowlayout/flowlayout.h @@ -45,7 +45,7 @@ #include #include #include - +//! [0] class FlowLayout : public QLayout { public: @@ -74,5 +74,6 @@ private: int m_hSpace; int m_vSpace; }; +//! [0] #endif diff --git a/examples/layouts/flowlayout/window.cpp b/examples/layouts/flowlayout/window.cpp index 51d9886..b7d9eae 100644 --- a/examples/layouts/flowlayout/window.cpp +++ b/examples/layouts/flowlayout/window.cpp @@ -43,7 +43,7 @@ #include "flowlayout.h" #include "window.h" - +//! [1] Window::Window() { FlowLayout *flowLayout = new FlowLayout; @@ -57,3 +57,4 @@ Window::Window() setWindowTitle(tr("Flow Layout")); } +//! [1] \ No newline at end of file diff --git a/examples/layouts/flowlayout/window.h b/examples/layouts/flowlayout/window.h index ffd60af..77f8b6f 100644 --- a/examples/layouts/flowlayout/window.h +++ b/examples/layouts/flowlayout/window.h @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE class QLabel; QT_END_NAMESPACE - +//! [0] class Window : public QWidget { Q_OBJECT @@ -55,5 +55,6 @@ class Window : public QWidget public: Window(); }; +//! [0] #endif -- cgit v0.12 From 48d9f395a2d2d0e9e4ff61b69c8c7e725aa3e3fd Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Wed, 29 Apr 2009 17:20:04 +0200 Subject: Documented the flow layout example. Wrote documentation for the flowlayout class. Task-number: 252548 Rev-by: Geir Vattekar Rev-by: janarve --- doc/src/examples/flowlayout.qdoc | 117 ++++++++++++++++++++++++++++++++-- doc/src/images/flowlayout-example.png | Bin 5054 -> 29350 bytes 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/doc/src/examples/flowlayout.qdoc b/doc/src/examples/flowlayout.qdoc index 557ba39..5fdafe2 100644 --- a/doc/src/examples/flowlayout.qdoc +++ b/doc/src/examples/flowlayout.qdoc @@ -43,8 +43,117 @@ \example layouts/flowlayout \title Flow Layout Example - The Flow Layout example demonstrates a custom layout that arranges child widgets from - left to right and top to bottom in a top-level widget. + The Flow Layout example demonstrates a custom layout that arranges child + widgets from left to right and top to bottom in a top-level widget. - \image flowlayout-example.png -*/ + \image flowlayout-example.png Screenshot of the Flow Layout example + + The items are first laid out horizontally and then vertically when each line + in the layout runs out of space. + + The Flowlayout class mainly uses QLayout and QWidgetItem, while the + Window uses QWidget and QLabel. We will only document the definition + and implementation of \cFlowLayout below. + + \section1 FlowLayout Class Definition + + The \c FlowLayout class inherits QLayout. It is a custom layout class + that arranges its child widgets horizontally and vertically. + + \snippet examples/layouts/flowlayout/flowlayout.h 0 + + We reimplement functions inherited from QLayout. These functions add items to + the layout and handle their orientation and geometry. + + We also declare two private methods, \c doLayout() and \c smartSpacing(). + \c doLayout() lays out the layout items, while the \c + smartSpacing() function calculates the spacing between them. + + \section1 FlowLayout Class Implementation + + We start off by looking at the constructor: + + \snippet examples/layouts/flowlayout/flowlayout.cpp 1 + + In the constructor we call \c setContentsMargins() to set the left, top, + right and bottom margin. By default, QLayout uses values provided by + the current style (see QStyle::PixelMetric). + + \snippet examples/layouts/flowlayout/flowlayout.cpp 2 + + In this example we reimplement \c addItem(), which is a pure virtual + function. When using \c addItem() the ownership of the layout items is + transferred to the layout, and it is therefore the layout's + responsibility to delete them. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 3 + + \c addItem() is implemented to add items to the layout. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 4 + + We implement \c horizontalSpacing() and \c verticalSpacing() to get + hold of the spacing between the widgets inside the layout. If the value + is less than or equal to 0, this value will be used. If not, + \c smartSpacing() will be called to calculate the spacing. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 5 + + We then implement \c count() to return the number of items in the + layout. To navigate the list of items we use \c itemAt() and + takeAt() to remove and return items from the list. If an item is + removed, the remaining items will be renumbered. All three + functions are pure virtual functions from QLayout. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 6 + + \c expandingDirections() returns the \l{Qt::Orientation}s in which the + layout can make use of more space than its \c sizeHint(). + + \snippet examples/layouts/flowlayout/flowlayout.cpp 7 + + To adjust to widgets of which height is dependent on width, we implement \c + heightForWidth(). The function \c hasHeightForWidth() is used to test for this + dependency, and \c heightForWidth() passes the width on to \c doLayout() which + in turn uses the width as an argument for the layout rect, i.e., the bounds in + which the items are laid out. This rect does not include the layout margin(). + + \snippet examples/layouts/flowlayout/flowlayout.cpp 8 + + \c setGeometry() is normally used to do the actual layout, i.e., calculate + the geometry of the layout's items. In this example, it calls \c doLayout() + and passes the layout rect. + + \c sizeHint() returns the preferred size of the layout and \c minimumSize() + returns the minimum size of the layout. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 9 + + \c doLayout() handles the layout if \c horizontalSpacing() or \c + verticalSpacing() don't return the default value. It uses + \c getContentsMargins() to calculate the area available to the + layout items. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 10 + + It then sets the proper amount of spacing for each widget in the + layout, based on the current style. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 11 + + The position of each item in the layout is then calculated by + adding the items width and the line height to the initial x and y + coordinates. This in turn lets us find out whether the next item + will fit on the current line or if it must be moved down to the next. + We also find the height of the current line based on the widgets height. + + \snippet examples/layouts/flowlayout/flowlayout.cpp 12 + + \c smartSpacing() is designed to get the default spacing for either + the top-level layouts or the sublayouts. The default spacing for + top-level layouts, when the parent is a QWidget, will be determined + by querying the style. The default spacing for sublayouts, when + the parent is a QLayout, will be determined by querying the spacing + of the parent layout. + +*/ \ No newline at end of file diff --git a/doc/src/images/flowlayout-example.png b/doc/src/images/flowlayout-example.png index 27660d6..61abe1f 100644 Binary files a/doc/src/images/flowlayout-example.png and b/doc/src/images/flowlayout-example.png differ -- cgit v0.12 From 5a9623cb54c598aa4226883076fb413ef88215e5 Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Wed, 29 Apr 2009 16:42:07 +0200 Subject: Wrong clip in QWidget::render(QPainter *, ...) when using Qt::(Replace|No)Clip. The problem was that we didn't take the painter's clip into account when setting the system viewport ("hard clip"). We only used the system clip, but we have to use system clip + painter clip, which is the current engine clip. Unfortunately, we have to calculate it again since there's no cross-platform way of retrieving it. This was only a problem with Qt::(Replace|No)Clip, since we in all other cases combine the old clip with the new one. (Uber cool) auto test included. Task-number: 250482 Reviewed-by: Samuel --- src/gui/kernel/qwidget.cpp | 9 +++- tests/auto/qwidget/tst_qwidget.cpp | 102 +++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index f612601..fb9c8cb 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4824,8 +4824,13 @@ void QWidget::render(QPainter *painter, const QPoint &targetOffset, const QRegion oldSystemClip = enginePriv->systemClip; const QRegion oldSystemViewport = enginePriv->systemViewport; - // This ensures that transformed system clips are inside the current system clip. - enginePriv->setSystemViewport(oldSystemClip); + // This ensures that all painting triggered by render() is clipped to the current engine clip. + if (painter->hasClipping()) { + const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion()); + enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip); + } else { + enginePriv->setSystemViewport(oldSystemClip); + } render(target, targetOffset, toBePainted, renderFlags); diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 767553a..72ffcc3 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -285,6 +285,8 @@ private slots: void render_systemClip(); void render_systemClip2_data(); void render_systemClip2(); + void render_systemClip3_data(); + void render_systemClip3(); void setContentsMargins(); @@ -6995,6 +6997,106 @@ void tst_QWidget::render_systemClip2() } } +void tst_QWidget::render_systemClip3_data() +{ + QTest::addColumn("size"); + QTest::addColumn("useSystemClip"); + + // Reference: http://en.wikipedia.org/wiki/Flag_of_Norway + QTest::newRow("Norwegian Civil Flag") << QSize(220, 160) << false; + QTest::newRow("Norwegian War Flag") << QSize(270, 160) << true; +} + +// This test ensures that the current engine clip (systemClip + painter clip) +// is preserved after QPainter::setClipRegion(..., Qt::ReplaceClip); +void tst_QWidget::render_systemClip3() +{ + QFETCH(QSize, size); + QFETCH(bool, useSystemClip); + + // Calculate the inner/outer cross of the flag. + QRegion outerCross(0, 0, size.width(), size.height()); + outerCross -= QRect(0, 0, 60, 60); + outerCross -= QRect(100, 0, size.width() - 100, 60); + outerCross -= QRect(0, 100, 60, 60); + outerCross -= QRect(100, 100, size.width() - 100, 60); + + QRegion innerCross(0, 0, size.width(), size.height()); + innerCross -= QRect(0, 0, 70, 70); + innerCross -= QRect(90, 0, size.width() - 90, 70); + innerCross -= QRect(0, 90, 70, 70); + innerCross -= QRect(90, 90, size.width() - 90, 70); + + const QRegion redArea(QRegion(0, 0, size.width(), size.height()) - outerCross); + const QRegion whiteArea(outerCross - innerCross); + const QRegion blueArea(innerCross); + QRegion systemClip; + + // Okay, here's the image that should look like a Norwegian civil/war flag in the end. + QImage flag(size, QImage::Format_ARGB32); + flag.fill(QColor(Qt::transparent).rgba()); + + if (useSystemClip) { + QPainterPath warClip(QPoint(size.width(), 0)); + warClip.lineTo(size.width() - 110, 60); + warClip.lineTo(size.width(), 80); + warClip.lineTo(size.width() - 110, 100); + warClip.lineTo(size.width(), 160); + warClip.closeSubpath(); + systemClip = QRegion(0, 0, size.width(), size.height()) - QRegion(warClip.toFillPolygon().toPolygon()); + flag.paintEngine()->setSystemClip(systemClip); + } + + QPainter painter(&flag); + painter.fillRect(QRect(QPoint(), size), Qt::red); // Fill image background with red. + painter.setClipRegion(outerCross); // Limit widget painting to inside the outer cross. + + // Here's the widget that's supposed to draw the inner/outer cross of the flag. + // The outer cross (white) should be drawn when the background is auto-filled, and + // the inner cross (blue) should be drawn in the paintEvent. + class MyWidget : public QWidget + { public: + void paintEvent(QPaintEvent *) + { + QPainter painter(this); + // Be evil and try to paint outside the outer cross. This should not be + // possible since the shared painter is clipped to the outer cross. + painter.setClipRect(0, 0, 60, 60, Qt::ReplaceClip); + painter.fillRect(rect(), Qt::green); + painter.setClipRegion(clip, Qt::ReplaceClip); + painter.fillRect(rect(), Qt::blue); + } + QRegion clip; + }; + + MyWidget widget; + widget.clip = innerCross; + widget.setFixedSize(size); + widget.setPalette(Qt::white); + widget.setAutoFillBackground(true); + widget.render(&painter); + +#ifdef RENDER_DEBUG + flag.save("flag.png"); +#endif + + // Let's make sure we got a Norwegian flag. + for (int i = 0; i < flag.height(); ++i) { + for (int j = 0; j < flag.width(); ++j) { + const QPoint pixel(j, i); + const QRgb pixelValue = flag.pixel(pixel); + if (useSystemClip && !systemClip.contains(pixel)) + QCOMPARE(pixelValue, QColor(Qt::transparent).rgba()); + else if (redArea.contains(pixel)) + QCOMPARE(pixelValue, QColor(Qt::red).rgba()); + else if (whiteArea.contains(pixel)) + QCOMPARE(pixelValue, QColor(Qt::white).rgba()); + else + QCOMPARE(pixelValue, QColor(Qt::blue).rgba()); + } + } +} + void tst_QWidget::setContentsMargins() { QLabel label("why does it always rain on me?"); -- cgit v0.12 From 5969625334270892e39b6b43f4da735b830abdbe Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Wed, 29 Apr 2009 17:33:10 +0200 Subject: Speed-up QPainter::clipRegion(). We can speed up the calculation by using rect intersections if possible, i.e. QRegion &= QRect instead of QRegion &= QRegion. Then we'll get rid of one QRegion construction and the intersection itself is slightly faster. Reviewed-by: Samuel --- src/gui/painting/qpainter.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 65d87fa..759bd7e 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -2398,7 +2398,6 @@ QRegion QPainter::clipRegion() const // ### Falcon: Use QPainterPath for (int i=0; istate->clipInfo.size(); ++i) { const QPainterClipInfo &info = d->state->clipInfo.at(i); - QRegion other; switch (info.clipType) { case QPainterClipInfo::RegionClip: { @@ -2451,15 +2450,20 @@ QRegion QPainter::clipRegion() const lastWasNothing = false; continue; } - if (info.operation == Qt::IntersectClip) - region &= QRegion(info.rect) * matrix; - else if (info.operation == Qt::UniteClip) + if (info.operation == Qt::IntersectClip) { + // Use rect intersection if possible. + if (matrix.type() <= QTransform::TxScale) + region &= matrix.mapRect(info.rect); + else + region &= matrix.map(QRegion(info.rect)); + } else if (info.operation == Qt::UniteClip) { region |= QRegion(info.rect) * matrix; - else if (info.operation == Qt::NoClip) { + } else if (info.operation == Qt::NoClip) { lastWasNothing = true; region = QRegion(); - } else + } else { region = QRegion(info.rect) * matrix; + } break; } @@ -2470,15 +2474,20 @@ QRegion QPainter::clipRegion() const lastWasNothing = false; continue; } - if (info.operation == Qt::IntersectClip) - region &= QRegion(info.rectf.toRect()) * matrix; - else if (info.operation == Qt::UniteClip) + if (info.operation == Qt::IntersectClip) { + // Use rect intersection if possible. + if (matrix.type() <= QTransform::TxScale) + region &= matrix.mapRect(info.rectf.toRect()); + else + region &= matrix.map(QRegion(info.rectf.toRect())); + } else if (info.operation == Qt::UniteClip) { region |= QRegion(info.rectf.toRect()) * matrix; - else if (info.operation == Qt::NoClip) { + } else if (info.operation == Qt::NoClip) { lastWasNothing = true; region = QRegion(); - } else + } else { region = QRegion(info.rectf.toRect()) * matrix; + } break; } } -- cgit v0.12 From 21958b48caca3423320f3e5e0e83096ca46b4d40 Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Wed, 29 Apr 2009 17:34:48 +0200 Subject: QTransform::map(const QRegion&) cut-off for single rect regions. Avoid QRegion<->QPainterPath conversion if possible. Reviewed-by: Samuel --- src/gui/painting/qtransform.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index af27fd5..2383272 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -1317,12 +1317,16 @@ QRegion QTransform::map(const QRegion &r) const TransformationType t = type(); if (t == TxNone) return r; + if (t == TxTranslate) { QRegion copy(r); copy.translate(qRound(affine._dx), qRound(affine._dy)); return copy; } + if (t == TxScale && r.numRects() == 1) + return QRegion(mapRect(r.boundingRect())); + QPainterPath p = map(qt_regionToPath(r)); return p.toFillPolygon(QTransform()).toPolygon(); } -- cgit v0.12 From 073b7ce298b0e079f310ec22dee44a9fc0af9ee6 Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Wed, 29 Apr 2009 18:19:13 +0200 Subject: Stabilize tst_QWidget::render_systemClip2 and remove wrong ifdef We only want to dump images *if* RENDER_DEBUG is defined. --- tests/auto/qwidget/tst_qwidget.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 72ffcc3..dee48a3 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -6956,7 +6956,7 @@ void tst_QWidget::render_systemClip2() // Render entire widget directly onto device. widget.render(&image); -#ifndef RENDER_DEBUG +#ifdef RENDER_DEBUG image.save("systemclip_with_device.png"); #endif // All pixels within the system clip should now be @@ -6972,17 +6972,17 @@ void tst_QWidget::render_systemClip2() // Refill image with red. image.fill(QColor(Qt::red).rgb()); + paintEngine->setSystemClip(systemClip); // Do the same with an untransformed painter. QPainter painter(&image); //Make sure we're using the same paint engine and has the right clip set. - paintEngine->setSystemClip(systemClip); QCOMPARE(painter.paintEngine(), paintEngine); QCOMPARE(paintEngine->systemClip(), systemClip); widget.render(&painter); -#ifndef RENDER_DEBUG +#ifdef RENDER_DEBUG image.save("systemclip_with_untransformed_painter.png"); #endif // All pixels within the system clip should now be -- cgit v0.12 From ac412256e2a4f5b0824bd8a836165b05dee118d1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 27 Feb 2009 11:48:05 +0100 Subject: Test for border images --- tests/auto/uiloader/baseline/css_borderimage.ui | 125 +++++++++++++++++++++ .../auto/uiloader/baseline/images/borderimage.png | Bin 0 -> 1672 bytes 2 files changed, 125 insertions(+) create mode 100644 tests/auto/uiloader/baseline/css_borderimage.ui create mode 100644 tests/auto/uiloader/baseline/images/borderimage.png diff --git a/tests/auto/uiloader/baseline/css_borderimage.ui b/tests/auto/uiloader/baseline/css_borderimage.ui new file mode 100644 index 0000000..4a59ca2 --- /dev/null +++ b/tests/auto/uiloader/baseline/css_borderimage.ui @@ -0,0 +1,125 @@ + + + Form + + + + 0 + 0 + 530 + 309 + + + + Form + + + QLabel { border-width: 28; color: #0f0; background-color: white; } + +#label_repeat_repeat { + border-image: url("images/borderimage.png") 28 repeat repeat; +} + +#label_stretch_repeat { + border-image: url("images/borderimage.png") 28 stretch repeat; +} + +#label_round_repeat { + border-image: url("images/borderimage.png") 28 round repeat; +} + + +#label_repeat_round { + border-image: url("images/borderimage.png") 28 repeat round; +} + +#label_stretch_round { + border-image: url("images/borderimage.png") 28 stretch round; +} + +#label_round_round { + border-image: url("images/borderimage.png") 28 round round; +} + +#label_repeat_stretch { + border-image: url("images/borderimage.png") 28 repeat stretch; +} + +#label_stretch_stretch { + border-image: url("images/borderimage.png") 28 stretch stretch; +} + +#label_round_stretch { + border-image: url("images/borderimage.png") 28 round stretch; +} + + + + + + + Strecth Stretch + + + + + + + Stretch Round + + + + + + + Stretch repeat + + + + + + + Round Stretch + + + + + + + Round Round + + + + + + + Round Repeat + + + + + + + Repeat Stretch + + + + + + + Repeat Round + + + + + + + Repeat Repeat + + + + + + + + diff --git a/tests/auto/uiloader/baseline/images/borderimage.png b/tests/auto/uiloader/baseline/images/borderimage.png new file mode 100644 index 0000000..199fc89 Binary files /dev/null and b/tests/auto/uiloader/baseline/images/borderimage.png differ -- cgit v0.12 From b4d642e639eabde5d72a4f2f95cffc13bdf193a4 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 29 Apr 2009 19:36:10 +0200 Subject: Port QStyleSheetStyle to the new qDrawBorderPixmap implementation Also add another constructor to QTileRules. Reviewed-by: Jens Bache-Wiig --- src/gui/painting/qdrawutil.h | 8 +- src/gui/styles/qstylesheetstyle.cpp | 183 +++--------------------------------- 2 files changed, 19 insertions(+), 172 deletions(-) diff --git a/src/gui/painting/qdrawutil.h b/src/gui/painting/qdrawutil.h index 08fa1ab..61110e0 100644 --- a/src/gui/painting/qdrawutil.h +++ b/src/gui/painting/qdrawutil.h @@ -153,10 +153,10 @@ struct Q_GUI_EXPORT QMargins struct Q_GUI_EXPORT QTileRules { - inline QTileRules(Qt::TileRule horizontalRule = Qt::Stretch, - Qt::TileRule verticalRule = Qt::Stretch) - : horizontal(horizontalRule), - vertical(verticalRule) {} + 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; }; diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index f480008..ac17e8d 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -81,6 +81,7 @@ #include #include #include +#include "qdrawutil.h" #include @@ -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); } -- cgit v0.12 From d20bf7c8b368cb56df1a965793edbd23ff0c3213 Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Wed, 29 Apr 2009 19:50:09 +0200 Subject: Compile. --- src/gui/painting/qdrawutil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/painting/qdrawutil.h b/src/gui/painting/qdrawutil.h index 61110e0..38d9ec0 100644 --- a/src/gui/painting/qdrawutil.h +++ b/src/gui/painting/qdrawutil.h @@ -44,6 +44,7 @@ #include #include // char*->QString conversion +#include QT_BEGIN_HEADER @@ -60,7 +61,6 @@ class QPoint; class QColor; class QBrush; class QRect; -class QPixmap; // // Standard shade drawing -- cgit v0.12 From 2c6fdd89086977708850043a075b2b880bd22c9e Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 30 Apr 2009 10:11:43 +0200 Subject: QApplication::setStyle() can cause a crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QApplication::setStyle() caused a crash if called before constructing the QApplication instance for custom styles. The reason was that polish tried to create a pixmap (which is not allowed before qApp is running). This fix checks that qApp exists. Polish will anyway be called again when qApp gets constructed. Task-number: 243697 Reviewed-by: Bjørn Erik Nilsen --- src/gui/styles/qmacstyle_mac.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index 398e11d..c973b41 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -2146,8 +2146,11 @@ void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QPoint /*! \reimp */ void QMacStyle::polish(QPalette &pal) { - if (qt_mac_backgroundPattern == 0) + if (!qt_mac_backgroundPattern) { + if (!qApp) + return; qt_mac_backgroundPattern = new QPixmap(d->generateBackgroundPattern()); + } QColor pc(Qt::black); pc = qcolorForTheme(kThemeBrushDialogBackgroundActive); -- cgit v0.12 From 60e5266eec332792d23f13ea63203f45f8e0f430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Wed, 29 Apr 2009 16:36:48 +0200 Subject: Fixed QFile::copy/rename fail after initial failed attempt These functions were checking the error state after calling close(), without first resetting the error state. Turns out close() only resets the error state if isOpen() returns false. Also, the fallback for the copy operation opens the file for reading but wasn't closing it again afterwards. Now fixed. Added autotests to cover these situations. Reviewed-by: MariusSO --- src/corelib/io/qfile.cpp | 3 +++ tests/auto/qfile/tst_qfile.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index d7da800..04750b0 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -708,6 +708,7 @@ QFile::rename(const QString &newName) d->setError(QFile::RenameError, tr("Destination file exists")); return false; } + unsetError(); close(); if(error() == QFile::NoError) { if (fileEngine()->rename(newName)) { @@ -849,6 +850,7 @@ QFile::copy(const QString &newName) d->setError(QFile::CopyError, tr("Destination file exists")); return false; } + unsetError(); close(); if(error() == QFile::NoError) { if(fileEngine()->copy(newName)) { @@ -908,6 +910,7 @@ QFile::copy(const QString &newName) out.setAutoRemove(false); #endif } + close(); } if(!error) { QFile::setPermissions(newName, permissions()); diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 98e1859..cb8091b 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -123,6 +123,7 @@ private slots: void permissions(); void setPermissions(); void copy(); + void copyAfterFail(); void copyRemovesTemporaryFile() const; void copyShouldntOverwrite(); void link(); @@ -216,8 +217,15 @@ void tst_QFile::cleanup() // for renameFallback() QFile::remove("file-rename-destination.txt"); + // for copyAfterFail() + QFile::remove("file-to-be-copied.txt"); + QFile::remove("existing-file.txt"); + QFile::remove("copied-file-1.txt"); + QFile::remove("copied-file-2.txt"); + // for renameMultiple() QFile::remove("file-to-be-renamed.txt"); + QFile::remove("existing-file.txt"); QFile::remove("file-renamed-once.txt"); QFile::remove("file-renamed-twice.txt"); } @@ -886,6 +894,39 @@ void tst_QFile::copy() QFile::copy(QDir::currentPath(), QDir::currentPath() + QLatin1String("/test2")); } +void tst_QFile::copyAfterFail() +{ + QFile file1("file-to-be-copied.txt"); + QFile file2("existing-file.txt"); + + QVERIFY(file1.open(QIODevice::ReadWrite) && "(test-precondition)"); + QVERIFY(file2.open(QIODevice::ReadWrite) && "(test-precondition)"); + QVERIFY(!QFile::exists("copied-file-1.txt") && "(test-precondition)"); + QVERIFY(!QFile::exists("copied-file-2.txt") && "(test-precondition)"); + + QVERIFY(!file1.copy("existing-file.txt")); + QCOMPARE(file1.error(), QFile::CopyError); + + QVERIFY(file1.copy("copied-file-1.txt")); + QVERIFY(!file1.isOpen()); + QCOMPARE(file1.error(), QFile::NoError); + + QVERIFY(!file1.copy("existing-file.txt")); + QCOMPARE(file1.error(), QFile::CopyError); + + QVERIFY(file1.copy("copied-file-2.txt")); + QVERIFY(!file1.isOpen()); + QCOMPARE(file1.error(), QFile::NoError); + + QVERIFY(QFile::exists("copied-file-1.txt")); + QVERIFY(QFile::exists("copied-file-2.txt")); + + QVERIFY(QFile::remove("file-to-be-copied.txt") && "(test-cleanup)"); + QVERIFY(QFile::remove("existing-file.txt") && "(test-cleanup)"); + QVERIFY(QFile::remove("copied-file-1.txt") && "(test-cleanup)"); + QVERIFY(QFile::remove("copied-file-2.txt") && "(test-cleanup)"); +} + void tst_QFile::copyRemovesTemporaryFile() const { const QString newName(QLatin1String("copyRemovesTemporaryFile")); @@ -2087,24 +2128,42 @@ void tst_QFile::renameMultiple() { // create the file if it doesn't exist QFile file("file-to-be-renamed.txt"); + QFile file2("existing-file.txt"); QVERIFY(file.open(QIODevice::ReadWrite) && "(test-precondition)"); + QVERIFY(file2.open(QIODevice::ReadWrite) && "(test-precondition)"); // any stale files from previous test failures? QFile::remove("file-renamed-once.txt"); QFile::remove("file-renamed-twice.txt"); // begin testing + QVERIFY(QFile::exists("existing-file.txt")); + QVERIFY(!file.rename("existing-file.txt")); + QCOMPARE(file.error(), QFile::RenameError); + QCOMPARE(file.fileName(), QString("file-to-be-renamed.txt")); + QVERIFY(file.rename("file-renamed-once.txt")); + QVERIFY(!file.isOpen()); QCOMPARE(file.fileName(), QString("file-renamed-once.txt")); + + QVERIFY(QFile::exists("existing-file.txt")); + QVERIFY(!file.rename("existing-file.txt")); + QCOMPARE(file.error(), QFile::RenameError); + QCOMPARE(file.fileName(), QString("file-renamed-once.txt")); + QVERIFY(file.rename("file-renamed-twice.txt")); + QVERIFY(!file.isOpen()); QCOMPARE(file.fileName(), QString("file-renamed-twice.txt")); + QVERIFY(QFile::exists("existing-file.txt")); QVERIFY(!QFile::exists("file-to-be-renamed.txt")); QVERIFY(!QFile::exists("file-renamed-once.txt")); QVERIFY(QFile::exists("file-renamed-twice.txt")); file.remove(); + file2.remove(); QVERIFY(!QFile::exists("file-renamed-twice.txt")); + QVERIFY(!QFile::exists("existing-file.txt")); } void tst_QFile::appendAndRead() -- cgit v0.12 From c70eae8288cccb92e54e3c73f0ca257af033178a Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 30 Apr 2009 12:07:59 +0200 Subject: Fixes a possible issue in itemviws where we would not scroll to the current item on show Task-number: 252534 Reviewed-by: ogoffart --- src/gui/itemviews/qabstractitemview.cpp | 26 ++++++++++++++++---------- src/gui/itemviews/qabstractitemview_p.h | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 975decc..83e05b4 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -88,6 +88,7 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate() autoScroll(true), autoScrollMargin(16), autoScrollCount(0), + shouldScrollToCurrentOnShow(false), alternatingColors(false), textElideMode(Qt::ElideRight), verticalScrollMode(QAbstractItemView::ScrollPerItem), @@ -1380,8 +1381,9 @@ bool QAbstractItemView::event(QEvent *event) d->executePostedLayout(); //make sure we set the layout properly break; case QEvent::Show: - if (d->delayedPendingLayout) { - d->executePostedLayout(); //make sure we set the layout properly + d->executePostedLayout(); //make sure we set the layout properly + if (d->shouldScrollToCurrentOnShow) { + d->shouldScrollToCurrentOnShow = false; const QModelIndex current = currentIndex(); if (current.isValid() && (d->state == QAbstractItemView::EditingState || d->autoScroll)) scrollTo(current); @@ -3163,14 +3165,18 @@ void QAbstractItemView::currentChanged(const QModelIndex ¤t, const QModelI d->updateDirtyRegion(); } } - if (isVisible() && current.isValid() && !d->autoScrollTimer.isActive()) { - if (d->autoScroll) - scrollTo(current); - d->setDirtyRegion(visualRect(current)); - d->updateDirtyRegion(); - edit(current, CurrentChanged, 0); - if (current.row() == (d->model->rowCount(d->root) - 1)) - d->_q_fetchMore(); + if (current.isValid() && !d->autoScrollTimer.isActive()) { + if (isVisible()) { + if (d->autoScroll) + scrollTo(current); + d->setDirtyRegion(visualRect(current)); + d->updateDirtyRegion(); + edit(current, CurrentChanged, 0); + if (current.row() == (d->model->rowCount(d->root) - 1)) + d->_q_fetchMore(); + } else { + d->shouldScrollToCurrentOnShow = d->autoScroll; + } } } diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 37fe4a2..16bd1ab 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -359,6 +359,7 @@ public: QBasicTimer autoScrollTimer; int autoScrollMargin; int autoScrollCount; + bool shouldScrollToCurrentOnShow; //used to know if we should scroll to current on show event bool alternatingColors; -- cgit v0.12 From db6f14776a298201e68e1d3646bb99b740c12867 Mon Sep 17 00:00:00 2001 From: jasplin Date: Thu, 30 Apr 2009 11:30:51 +0200 Subject: Fixed busy indicator for a QProgressBar with a style sheet applied to it. For a progress bar with a style sheet applied to it, this fix ensures that the timer event is passed to the event handler that updates the busy indicator animation state. Essentially, the bug was that the decision that the event was processed by the proxy style object (baseStyle()) was based only on the return value from the event() function. In this case it is necessary to check that the event was accepted as well. Reviewed-by: ogoffart Reviewed-by: brad Task-number: 252283 --- src/gui/styles/qstylesheetstyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 49ac57a..058660e 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -5842,7 +5842,7 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c bool QStyleSheetStyle::event(QEvent *e) { - return baseStyle()->event(e) || ParentStyle::event(e); + return (baseStyle()->event(e) && e->isAccepted()) || ParentStyle::event(e); } void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const -- cgit v0.12 From 9cb0419bd9559b5c9e0a95711a81391556306e51 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Thu, 30 Apr 2009 13:10:04 +0200 Subject: Correcting typo Missed a whitespace - corrected it. No task --- doc/src/examples/flowlayout.qdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/examples/flowlayout.qdoc b/doc/src/examples/flowlayout.qdoc index 5fdafe2..3e7ec22 100644 --- a/doc/src/examples/flowlayout.qdoc +++ b/doc/src/examples/flowlayout.qdoc @@ -53,7 +53,7 @@ The Flowlayout class mainly uses QLayout and QWidgetItem, while the Window uses QWidget and QLabel. We will only document the definition - and implementation of \cFlowLayout below. + and implementation of \c FlowLayout below. \section1 FlowLayout Class Definition @@ -156,4 +156,4 @@ the parent is a QLayout, will be determined by querying the spacing of the parent layout. -*/ \ No newline at end of file +*/ -- cgit v0.12 From 7727a011266e54bd0d1b31416cae81c35e57e694 Mon Sep 17 00:00:00 2001 From: Kavindra Devi Palaraja Date: Thu, 30 Apr 2009 13:35:39 +0200 Subject: Doc - some cleanups on the documentation of QDrawUtil --- src/gui/painting/qdrawutil.cpp | 54 +++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp index 4898b7e..230d30b 100644 --- a/src/gui/painting/qdrawutil.cpp +++ b/src/gui/painting/qdrawutil.cpp @@ -1039,31 +1039,34 @@ void qDrawItem(QPainter *p, Qt::GUIStyle gs, #endif /*! - \struct QMargins - \since 4.6 + \struct QMargins + \since 4.6 - Holds the borders used to split a pixmap on into nine segments in order to draw it, - similar to CSS3 border-images \l http://www.w3.org/TR/css3-background/. + 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 - */ + \sa qDrawBorderPixmap, Qt::TileRule, QTileRules +*/ /*! - \struct QTileRules - \since 4.6 + \struct QTileRules + \since 4.6 - Holds the rules used to draw a pixmap or image split into nine segments, similar to CSS3 border-images. + 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 - */ + \sa qDrawBorderPixmap, Qt::TileRule, QMargins +*/ /*! - \fn qDrawBorderPixmap(QPainter *painter, const QRect &target, const QMargins &margins, const QPixmap &pixmap) - \since 4.6 + \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 splitt into nine segments and drawn according to the given \a margins structure. - */ + 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&)) @@ -1146,17 +1149,20 @@ static inline void qDrawHorizontallyRoundedPixmap(QPainter *painter, const QRect } /*! - \since 4.6 + \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 splitt into nine segments according to the given \a targetMargins and - \a sourceMargins structures and drawn according to the given \a rules. + 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 CSS3 border-images. + 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 +*/ - \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) { -- cgit v0.12 From ea80a3dc8acdb95c0c217b3574718c88c7a36e9f Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Thu, 30 Apr 2009 15:31:55 +0200 Subject: New autotest for Windows Mobile: tst_windowsmobile This autotest tests some Windows Mobile 5.0 specific thing like the native menubar and the integration into the window manager by taking and comparing screenshots. This should prevent nasty regressions we had. This autotest makes only sense on Windows Mobile 5.0 in 480x640 Reviewed-by: maurice --- tests/auto/windowsmobile/test/ddhelper.cpp | 121 +++++++++++++ tests/auto/windowsmobile/test/ddhelper.h | 21 +++ tests/auto/windowsmobile/test/test.pro | 24 +++ .../windowsmobile/test/testQMenuBar_current.png | Bin 0 -> 23702 bytes .../test/testSimpleWidget_current.png | Bin 0 -> 21940 bytes .../auto/windowsmobile/test/tst_windowsmobile.cpp | 191 +++++++++++++++++++++ tests/auto/windowsmobile/test/windowsmobile.qrc | 6 + tests/auto/windowsmobile/testQMenuBar/main.cpp | 72 ++++++++ .../windowsmobile/testQMenuBar/testQMenuBar.pro | 2 + tests/auto/windowsmobile/windowsmobile.pro | 9 + 10 files changed, 446 insertions(+) create mode 100644 tests/auto/windowsmobile/test/ddhelper.cpp create mode 100644 tests/auto/windowsmobile/test/ddhelper.h create mode 100644 tests/auto/windowsmobile/test/test.pro create mode 100644 tests/auto/windowsmobile/test/testQMenuBar_current.png create mode 100644 tests/auto/windowsmobile/test/testSimpleWidget_current.png create mode 100644 tests/auto/windowsmobile/test/tst_windowsmobile.cpp create mode 100644 tests/auto/windowsmobile/test/windowsmobile.qrc create mode 100644 tests/auto/windowsmobile/testQMenuBar/main.cpp create mode 100644 tests/auto/windowsmobile/testQMenuBar/testQMenuBar.pro create mode 100644 tests/auto/windowsmobile/windowsmobile.pro diff --git a/tests/auto/windowsmobile/test/ddhelper.cpp b/tests/auto/windowsmobile/test/ddhelper.cpp new file mode 100644 index 0000000..5955cd3 --- /dev/null +++ b/tests/auto/windowsmobile/test/ddhelper.cpp @@ -0,0 +1,121 @@ + +#ifdef Q_OS_WINCE_WM + +#include +#include + +static LPDIRECTDRAW g_pDD = NULL; // DirectDraw object +static LPDIRECTDRAWSURFACE g_pDDSSurface = NULL; // DirectDraw primary surface + +static DDSCAPS ddsCaps; +static DDSURFACEDESC ddsSurfaceDesc; +static void *buffer = NULL; + +static int width = 0; +static int height = 0; +static int pitch = 0; +static int bitCount = 0; +static int windowId = 0; + +static bool initialized = false; +static bool locked = false; + +void q_lock() +{ + if (locked) { + qWarning("Direct Painter already locked (QDirectPainter::lock())"); + return; + } + locked = true; + + + memset(&ddsSurfaceDesc, 0, sizeof(ddsSurfaceDesc)); + ddsSurfaceDesc.dwSize = sizeof(ddsSurfaceDesc); + + HRESULT h = g_pDDSSurface->Lock(0, &ddsSurfaceDesc, DDLOCK_WRITEONLY, 0); + if (h != DD_OK) + qDebug() << "GetSurfaceDesc failed!"; + + width = ddsSurfaceDesc.dwWidth; + height = ddsSurfaceDesc.dwHeight; + bitCount = ddsSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; + pitch = ddsSurfaceDesc.lPitch; + buffer = ddsSurfaceDesc.lpSurface; +} + +void q_unlock() +{ + if( !locked) { + qWarning("Direct Painter not locked (QDirectPainter::unlock()"); + return; + } + g_pDDSSurface->Unlock(0); + locked = false; +} + +void q_initDD() +{ + if (initialized) + return; + + DirectDrawCreate(NULL, &g_pDD, NULL); + + HRESULT h; + h = g_pDD->SetCooperativeLevel(0, DDSCL_NORMAL); + + if (h != DD_OK) + qDebug() << "cooperation level failed"; + + h = g_pDD->TestCooperativeLevel(); + if (h != DD_OK) + qDebug() << "cooperation level failed test"; + + DDSURFACEDESC ddsd; + memset(&ddsd, 0, sizeof(ddsd)); + ddsd.dwSize = sizeof(ddsd); + + ddsd.dwFlags = DDSD_CAPS; + + ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + + h = g_pDD->CreateSurface(&ddsd, &g_pDDSSurface, NULL); + + if (h != DD_OK) + qDebug() << "CreateSurface failed!"; + + if (g_pDDSSurface->GetCaps(&ddsCaps) != DD_OK) + qDebug() << "GetCaps failed"; + + q_lock(); + q_unlock(); + initialized = true; +} + +uchar* q_frameBuffer() +{ + return (uchar*) buffer; +} + +int q_screenDepth() +{ + return bitCount; +} + +int q_screenWidth() +{ + return width; +} + +int q_screenHeight() +{ + return height; +} + +int q_linestep() +{ + return pitch; +} + +#endif //Q_OS_WINCE_WM + + diff --git a/tests/auto/windowsmobile/test/ddhelper.h b/tests/auto/windowsmobile/test/ddhelper.h new file mode 100644 index 0000000..3dfa9e6 --- /dev/null +++ b/tests/auto/windowsmobile/test/ddhelper.h @@ -0,0 +1,21 @@ +#ifndef __DDHELPER__ +#define __DDHELPER__ + +extern uchar* q_frameBuffer(); + +extern int q_screenDepth(); + +extern int q_screenWidth(); + +extern int q_screenHeight(); + +extern int q_linestep(); + +extern void q_initDD(); + +extern void q_unlock(); + +extern void q_lock(); + +#endif //__DDHELPER__ + diff --git a/tests/auto/windowsmobile/test/test.pro b/tests/auto/windowsmobile/test/test.pro new file mode 100644 index 0000000..2420bf1 --- /dev/null +++ b/tests/auto/windowsmobile/test/test.pro @@ -0,0 +1,24 @@ + +load(qttest_p4) + +HEADERS += ddhelper.h +SOURCES += tst_windowsmobile.cpp ddhelper.cpp +RESOURCES += windowsmobile.qrc + +TARGET = tst_windowsmobile + +wincewm*: { + addFiles.sources = \ + ../testQMenuBar/*.exe + + + addFiles.path = "\Program Files\tst_windowsmobile" + DEPLOYMENT += addFiles +} + +wincewm*: { + LIBS += Ddraw.lib +} + + + diff --git a/tests/auto/windowsmobile/test/testQMenuBar_current.png b/tests/auto/windowsmobile/test/testQMenuBar_current.png new file mode 100644 index 0000000..d03e69a Binary files /dev/null and b/tests/auto/windowsmobile/test/testQMenuBar_current.png differ diff --git a/tests/auto/windowsmobile/test/testSimpleWidget_current.png b/tests/auto/windowsmobile/test/testSimpleWidget_current.png new file mode 100644 index 0000000..5cbc2bb Binary files /dev/null and b/tests/auto/windowsmobile/test/testSimpleWidget_current.png differ diff --git a/tests/auto/windowsmobile/test/tst_windowsmobile.cpp b/tests/auto/windowsmobile/test/tst_windowsmobile.cpp new file mode 100644 index 0000000..391e206 --- /dev/null +++ b/tests/auto/windowsmobile/test/tst_windowsmobile.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite 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 +#include +#include +#include +#include +#include +#include + + + +class tst_WindowsMobile : public QObject +{ + Q_OBJECT +public: + tst_WindowsMobile() + { +#ifdef Q_OS_WINCE_WM + q_initDD(); +#endif + } + +#ifdef Q_OS_WINCE_WM + private slots: + void testMainWindowAndMenuBar(); + void testSimpleWidget(); +#endif +}; + +#ifdef Q_OS_WINCE_WM + +bool qt_wince_is_platform(const QString &platformString) { + TCHAR tszPlatform[64]; + if (SystemParametersInfo(SPI_GETPLATFORMTYPE, + sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0)) + if (0 == _tcsicmp(reinterpret_cast (platformString.utf16()), tszPlatform)) + return true; + return false; +} + +bool qt_wince_is_smartphone() { + return qt_wince_is_platform(QString::fromLatin1("Smartphone")); +} + +void openMenu() +{ + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,450,630,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,450,630,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,55535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,55535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,58535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,58535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,40535,55535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,40535,55535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,32535,55535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,32535,55535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,65535,65535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,50535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,50535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,55535,40535,0,0); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,55535,40535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE,48535,45535,0,0); + QTest::qWait(2000); + ::mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE,48535,45535,0,0); +} + +void compareScreenshots(const QString &image1, const QString &image2) +{ + if (qt_wince_is_smartphone()) + QSKIP("This test is only for Windows Mobile", SkipAll); + QImage screenShot(image1); + QImage original(image2); + + //ignore the clock + QPainter p1(&screenShot); + QPainter p2(&original); + p1.fillRect(310, 6, 400, 34, Qt::black); + p2.fillRect(310, 6, 400, 34, Qt::black); + + QVERIFY(original == screenShot); +} + +void takeScreenShot(const QString filename) +{ + q_lock(); + QImage image = QImage(( uchar *) q_frameBuffer(), q_screenWidth(), + q_screenHeight(), q_screenWidth() * q_screenDepth() / 8, QImage::Format_RGB16); + image.save(filename, "PNG"); + q_unlock(); +} + +void tst_WindowsMobile::testMainWindowAndMenuBar() +{ + QProcess process; + process.start("testQMenuBar.exe"); + QCOMPARE(process.state(), QProcess::Running); + QTest::qWait(6000); + openMenu(); + QTest::qWait(1000); + takeScreenShot("testQMenuBar_current.png"); + process.close(); + compareScreenshots("testQMenuBar_current.png", ":/testQMenuBar_current.png"); +} + +void tst_WindowsMobile::testSimpleWidget() +{ + QMenuBar menubar; + menubar.show(); + QWidget maximized; + QPalette pal = maximized.palette(); + pal.setColor(QPalette::Background, Qt::red); + maximized.setPalette(pal); + maximized.showMaximized(); + QWidget widget; + widget.setGeometry(100, 100, 200, 200); + widget.setWindowTitle("Widget"); + widget.show(); + qApp->processEvents(); + QTest::qWait(1000); + + QWidget widget2; + widget2.setGeometry(100, 380, 300, 200); + widget2.setWindowTitle("Widget 2"); + widget2.setWindowFlags(Qt::Popup); + widget2.show(); + + qApp->processEvents(); + QTest::qWait(1000); + takeScreenShot("testSimpleWidget_current.png"); + compareScreenshots("testSimpleWidget_current.png", ":/testSimpleWidget_current.png"); +} + + +#endif //Q_OS_WINCE_WM + + +QTEST_MAIN(tst_WindowsMobile) +#include "tst_windowsmobile.moc" + diff --git a/tests/auto/windowsmobile/test/windowsmobile.qrc b/tests/auto/windowsmobile/test/windowsmobile.qrc new file mode 100644 index 0000000..5d6f614 --- /dev/null +++ b/tests/auto/windowsmobile/test/windowsmobile.qrc @@ -0,0 +1,6 @@ + + + testQMenuBar_current.png + testSimpleWidget_current.png + + diff --git a/tests/auto/windowsmobile/testQMenuBar/main.cpp b/tests/auto/windowsmobile/testQMenuBar/main.cpp new file mode 100644 index 0000000..4a3b3b2 --- /dev/null +++ b/tests/auto/windowsmobile/testQMenuBar/main.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char * argv[]) +{ + int widgetNum = 20; + + QList widgets; + QApplication app(argc, argv); + + QMainWindow mainWindow; + mainWindow.setWindowTitle("Test"); + QMenu *fileMenu = mainWindow.menuBar()->addMenu("File"); + QMenu *editMenu = mainWindow.menuBar()->addMenu("Edit"); + QMenu *viewMenu = mainWindow.menuBar()->addMenu("View"); + QMenu *toolsMenu = mainWindow.menuBar()->addMenu("Tools"); + QMenu *optionsMenu = mainWindow.menuBar()->addMenu("Options"); + QMenu *helpMenu = mainWindow.menuBar()->addMenu("Help"); + + qApp->processEvents(); + + fileMenu->addAction("Open"); + QAction *close = fileMenu->addAction("Close"); + fileMenu->addSeparator(); + fileMenu->addAction("Exit"); + + close->setEnabled(false); + + editMenu->addAction("Cut"); + editMenu->addAction("Pase"); + editMenu->addAction("Copy"); + editMenu->addSeparator(); + editMenu->addAction("Find"); + + viewMenu->addAction("Hide"); + viewMenu->addAction("Show"); + viewMenu->addAction("Explore"); + QAction *visible = viewMenu->addAction("Visible"); + visible->setCheckable(true); + visible->setChecked(true); + + toolsMenu->addMenu("Hammer"); + toolsMenu->addMenu("Caliper"); + toolsMenu->addMenu("Helm"); + + optionsMenu->addMenu("Settings"); + optionsMenu->addMenu("Standard"); + optionsMenu->addMenu("Extended"); + + QMenu *subMenu = helpMenu->addMenu("Help"); + subMenu->addAction("Index"); + subMenu->addSeparator(); + subMenu->addAction("Vodoo Help"); + helpMenu->addAction("Contens"); + helpMenu->addSeparator(); + helpMenu->addAction("About"); + + QToolBar toolbar; + mainWindow.addToolBar(&toolbar); + toolbar.addAction(QIcon(qApp->style()->standardPixmap(QStyle::SP_FileIcon)), QString("textAction")); + + QTextEdit textEdit; + mainWindow.setCentralWidget(&textEdit); + + mainWindow.showMaximized(); + + app.exec(); +} diff --git a/tests/auto/windowsmobile/testQMenuBar/testQMenuBar.pro b/tests/auto/windowsmobile/testQMenuBar/testQMenuBar.pro new file mode 100644 index 0000000..6dd288b --- /dev/null +++ b/tests/auto/windowsmobile/testQMenuBar/testQMenuBar.pro @@ -0,0 +1,2 @@ +SOURCES += main.cpp +DESTDIR = ./ diff --git a/tests/auto/windowsmobile/windowsmobile.pro b/tests/auto/windowsmobile/windowsmobile.pro new file mode 100644 index 0000000..2e6b444 --- /dev/null +++ b/tests/auto/windowsmobile/windowsmobile.pro @@ -0,0 +1,9 @@ + +TEMPLATE = subdirs + +wincewm* { + SUBDIRS = testQMenuBar +} + SUBDIRS += test + + -- cgit v0.12 From 446085a8b3f22d7e2735b62b4511907e7aaba82a Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 30 Apr 2009 16:04:46 +0200 Subject: QDirModel now uses the same translations as QFileSystemModel to represent sizes Task-number: 251703 --- src/gui/itemviews/qdirmodel.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 #include +#include #include #include #include @@ -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 -- cgit v0.12 From 1a18308b311f031d001e3b3e98ffb61e840a6d8c Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Thu, 30 Apr 2009 14:35:46 +0200 Subject: QNetworkCookieJar: allow cookies with wrong domain attribute According to the (old) cookie RFC 2109, the domain attribute must always contain a leading dot. Some servers do not have that, but all browsers accept those cookies anyway, so we should do that as well. Reviewed-by: Olivier Reviewed-by: Denis Task-number: 228974 --- src/network/access/qnetworkcookie.cpp | 9 ++++----- tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index 01a743b..aaa5075 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -976,14 +976,14 @@ QList QNetworkCookie::parseCookies(const QByteArray &cookieStrin cookie.setExpirationDate(dt); } else if (field.first == "domain") { QByteArray rawDomain = field.second; - QString maybeLeadingDot; if (rawDomain.startsWith('.')) { - maybeLeadingDot = QLatin1Char('.'); rawDomain = rawDomain.mid(1); } - QString normalizedDomain = QUrl::fromAce(QUrl::toAce(QString::fromUtf8(rawDomain))); - cookie.setDomain(maybeLeadingDot + normalizedDomain); + // always add the dot, there are some servers that forget the + // leading dot. This is actually forbidden according to RFC 2109, + // but all browsers accept it anyway so we do that as well + cookie.setDomain(QLatin1Char('.') + normalizedDomain); } else if (field.first == "max-age") { bool ok = false; int secs = field.second.toInt(&ok); @@ -1184,7 +1184,6 @@ bool QNetworkCookieJar::setCookiesFromUrl(const QList &cookieLis cookie.expirationDate() < now; // validate the cookie & set the defaults if unset - // (RFC 2965: "The request-URI MUST path-match the Path attribute of the cookie.") if (cookie.path().isEmpty()) cookie.setPath(defaultPath); else if (!isParentPath(pathAndFileName, cookie.path())) diff --git a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp index 36a4b45..4ee5b9f 100644 --- a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp +++ b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp @@ -234,7 +234,7 @@ void tst_QNetworkCookie::parseSingleCookie_data() QTest::newRow("path-with-utf8-2") << "a=b;path=/R%C3%A9sum%C3%A9" << cookie; cookie.setPath(QString()); - cookie.setDomain("trolltech.com"); + cookie.setDomain(".trolltech.com"); QTest::newRow("plain-domain1") << "a=b;domain=trolltech.com" << cookie; QTest::newRow("plain-domain2") << "a=b; domain=trolltech.com " << cookie; QTest::newRow("plain-domain3") << "a=b;domain=TROLLTECH.COM" << cookie; @@ -246,7 +246,7 @@ void tst_QNetworkCookie::parseSingleCookie_data() QTest::newRow("dot-domain3") << "a=b; domain=.TROLLTECH.COM" << cookie; QTest::newRow("dot-domain4") << "a=b; Domain = .TROLLTECH.COM" << cookie; - cookie.setDomain(QString::fromUtf8("d\303\270gn\303\245pent.troll.no")); + cookie.setDomain(QString::fromUtf8(".d\303\270gn\303\245pent.troll.no")); QTest::newRow("idn-domain1") << "a=b;domain=xn--dgnpent-gxa2o.troll.no" << cookie; QTest::newRow("idn-domain2") << "a=b;domain=d\303\270gn\303\245pent.troll.no" << cookie; QTest::newRow("idn-domain3") << "a=b;domain=XN--DGNPENT-GXA2O.TROLL.NO" << cookie; @@ -259,7 +259,7 @@ void tst_QNetworkCookie::parseSingleCookie_data() QTest::newRow("dot-idn-domain3") << "a=b;domain=.XN--DGNPENT-GXA2O.TROLL.NO" << cookie; QTest::newRow("dot-idn-domain4") << "a=b;domain=.D\303\230GN\303\205PENT.troll.NO" << cookie; - cookie.setDomain("trolltech.com"); + cookie.setDomain(".trolltech.com"); cookie.setPath("/"); QTest::newRow("two-fields") << "a=b;domain=trolltech.com;path=/" << cookie; QTest::newRow("two-fields2") << "a=b; domain=trolltech.com; path=/" << cookie; @@ -662,7 +662,7 @@ void tst_QNetworkCookie::parseMultipleCookies_data() QTest::newRow("complex-1") << "c=d, a=, foo=bar; path=/" << list; cookie.setName("baz"); - cookie.setDomain("trolltech.com"); + cookie.setDomain(".trolltech.com"); list.prepend(cookie); QTest::newRow("complex-2") << "baz=bar; path=/; domain=trolltech.com, c=d,a=,foo=bar; path=/" << list; -- cgit v0.12 From 5f7cd6ca85b2cb2dc996f260694255d31670766e Mon Sep 17 00:00:00 2001 From: Bill King Date: Fri, 1 May 2009 14:24:13 +1000 Subject: Apparently this is the best way to determine which to use Best as I can determine via trial and error. It should make vc6 compile again though. --- src/sql/drivers/odbc/qsql_odbc.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 4e90777..9932463 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -70,13 +70,12 @@ QT_BEGIN_NAMESPACE #endif // newer platform SDKs use SQLLEN instead of SQLINTEGER -//#if defined(SQLLEN) || defined(Q_OS_WIN64) -#if ODBCVER >= 0x0270 -# define QSQLLEN SQLLEN -# define QSQLULEN SQLULEN -#else +#if defined(WIN32) && (_MSC_VER < 1300) # define QSQLLEN SQLINTEGER # define QSQLULEN SQLUINTEGER +#else +# define QSQLLEN SQLLEN +# define QSQLULEN SQLULEN #endif -- cgit v0.12 From 1569eaba5eaf99c810d4f205e890b68d069f189b Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Fri, 1 May 2009 08:31:32 -0700 Subject: Fixed possible crash in QDirectFBPaintEngine::clip d->clip() might return 0 at this point so make sure we check before accessing it. Reviewed-by: TrustMe --- src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp index 9e6f821..364c6e1 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp @@ -906,7 +906,7 @@ void QDirectFBPaintEngine::clip(const QRect &rect, Qt::ClipOperation op) { Q_D(QDirectFBPaintEngine); d->setClipDirty(); - if (!d->clip()->hasRectClip && d->clip()->enabled) { + if (d->clip() && !d->clip()->hasRectClip && d->clip()->enabled) { const QPoint bottom = d->transform.map(QPoint(0, rect.bottom())); if (bottom.y() >= d->lastLockedHeight) d->lock(); -- cgit v0.12 From ab03f0095a09fa961e53f741294ca8a890e1827f Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Fri, 1 May 2009 09:42:53 -0700 Subject: Improved readability of the flip code Reviewed-by: Donald --- src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp index 257efeb..09b7a30 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp @@ -371,18 +371,13 @@ void QDirectFBSurface::flush(QWidget *widget, const QRegion ®ion, } else { if (region.numRects() > 1) { const QVector rects = region.rects(); - DFBSurfaceFlipFlags tmpFlags = flipFlags; - if (flipFlags & DSFLIP_WAIT) - tmpFlags = DFBSurfaceFlipFlags(flipFlags & ~DSFLIP_WAIT); + const DFBSurfaceFlipFlags nonWaitFlags = DFBSurfaceFlipFlags(flipFlags & ~DSFLIP_WAIT); for (int i=0; iFlip(dfbSurface, &dfbReg, - i + 1 < rects.size() - ? tmpFlags - : flipFlags); + dfbSurface->Flip(dfbSurface, &dfbReg, i + 1 < rects.size() ? nonWaitFlags : flipFlags); } } else { const QRect r = region.boundingRect(); -- cgit v0.12 From 793ea1535f131b4ada2e0049f60cf5e24ad35a7b Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Fri, 1 May 2009 10:08:44 -0700 Subject: Cleaned up surface creation code Since I am taking a copy of the description anyway it makes sense to just pass this light-weight object in as a copy rather than a const pointer. Reviewed-by: Donald --- .../gfxdrivers/directfb/qdirectfbpaintengine.cpp | 19 ++++------- .../gfxdrivers/directfb/qdirectfbscreen.cpp | 39 +++++++++++----------- src/plugins/gfxdrivers/directfb/qdirectfbscreen.h | 2 +- .../gfxdrivers/directfb/qdirectfbsurface.cpp | 2 +- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp index 364c6e1..14d2146 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp @@ -189,11 +189,10 @@ CachedImage::CachedImage(const QImage &image) : s(0) { IDirectFBSurface *tmpSurface = 0; - DFBSurfaceDescription description; - description = QDirectFBScreen::getSurfaceDescription(image); + DFBSurfaceDescription description = QDirectFBScreen::getSurfaceDescription(image); QDirectFBScreen* screen = QDirectFBScreen::instance(); - tmpSurface = screen->createDFBSurface(&description, QDirectFBScreen::TrackSurface); + tmpSurface = screen->createDFBSurface(description, QDirectFBScreen::TrackSurface); if (!tmpSurface) { qWarning("CachedImage CreateSurface failed!"); return; @@ -205,7 +204,7 @@ CachedImage::CachedImage(const QImage &image) description.flags = DFBSurfaceDescriptionFlags(description.flags & ~DSDESC_PREALLOCATED); - s = screen->createDFBSurface(&description, QDirectFBScreen::TrackSurface); + s = screen->createDFBSurface(description, QDirectFBScreen::TrackSurface); if (!s) qWarning("QDirectFBPaintEngine failed caching image"); @@ -237,10 +236,8 @@ IDirectFBSurface* SurfaceCache::getSurface(const uint *buf, int size) clear(); - DFBSurfaceDescription description; - description = QDirectFBScreen::getSurfaceDescription(buf, size); - - surface = QDirectFBScreen::instance()->createDFBSurface(&description, QDirectFBScreen::TrackSurface); + const DFBSurfaceDescription description = QDirectFBScreen::getSurfaceDescription(buf, size); + surface = QDirectFBScreen::instance()->createDFBSurface(description, QDirectFBScreen::TrackSurface); if (!surface) qWarning("QDirectFBPaintEngine: SurfaceCache: Unable to create surface"); @@ -736,10 +733,8 @@ void QDirectFBPaintEnginePrivate::drawImage(const QRectF &dest, } if (!imgSurface) { - DFBSurfaceDescription description; - - description = QDirectFBScreen::getSurfaceDescription(image); - imgSurface = QDirectFBScreen::instance()->createDFBSurface(&description, + DFBSurfaceDescription description = QDirectFBScreen::getSurfaceDescription(image); + imgSurface = QDirectFBScreen::instance()->createDFBSurface(description, QDirectFBScreen::DontTrackSurface); if (!imgSurface) { qWarning("QDirectFBPaintEnginePrivate::drawImage"); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index a53b1c0..e2324ff 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -155,8 +155,7 @@ IDirectFBSurface* QDirectFBScreen::createDFBSurface(const QImage &img, SurfaceCr return surface; } - DFBSurfaceDescription desc = QDirectFBScreen::getSurfaceDescription(img); - IDirectFBSurface *surface = createDFBSurface(&desc, options); + IDirectFBSurface *surface = createDFBSurface(QDirectFBScreen::getSurfaceDescription(img), options); #ifdef QT_NO_DIRECTFB_PREALLOCATED if (surface) { int bpl; @@ -211,11 +210,11 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QSize &size, return 0; desc.width = size.width(); desc.height = size.height(); - return createDFBSurface(&desc, options); + return createDFBSurface(desc, options); } -IDirectFBSurface* QDirectFBScreen::createDFBSurface(const DFBSurfaceDescription *desc, SurfaceCreationOptions options) +IDirectFBSurface* QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc, SurfaceCreationOptions options) { DFBResult result; IDirectFBSurface* newSurface = 0; @@ -225,39 +224,39 @@ IDirectFBSurface* QDirectFBScreen::createDFBSurface(const DFBSurfaceDescription return 0; } - if (d_ptr->directFBFlags & VideoOnly && !(desc->flags & DSDESC_PREALLOCATED)) { + if (d_ptr->directFBFlags & VideoOnly && !(desc.flags & DSDESC_PREALLOCATED)) { // Add the video only capability. This means the surface will be created in video ram - DFBSurfaceDescription voDesc = *desc; - if (!(voDesc.flags & DSDESC_CAPS)) { - voDesc.caps = DSCAPS_VIDEOONLY; - voDesc.flags = DFBSurfaceDescriptionFlags(voDesc.flags | DSDESC_CAPS); + if (!(desc.flags & DSDESC_CAPS)) { + desc.caps = DSCAPS_VIDEOONLY; + desc.flags = DFBSurfaceDescriptionFlags(desc.flags | DSDESC_CAPS); } else { - voDesc.caps = DFBSurfaceCapabilities(voDesc.caps | DSCAPS_VIDEOONLY); + desc.caps = DFBSurfaceCapabilities(desc.caps | DSCAPS_VIDEOONLY); } - result = d_ptr->dfb->CreateSurface(d_ptr->dfb, &voDesc, &newSurface); + result = d_ptr->dfb->CreateSurface(d_ptr->dfb, &desc, &newSurface); if (result != DFB_OK #ifdef QT_NO_DEBUG - && (desc->flags & DSDESC_CAPS) && (desc->caps & DSCAPS_PRIMARY) + && (desc.flags & DSDESC_CAPS) && (desc.caps & DSCAPS_PRIMARY) #endif ) { qWarning("QDirectFBScreen::createDFBSurface() Failed to create surface in video memory!\n" " Flags %0x Caps %0x width %d height %d pixelformat %0x %d preallocated %p %d\n%s", - desc->flags, desc->caps, desc->width, desc->height, - desc->pixelformat, DFB_PIXELFORMAT_INDEX(desc->pixelformat), - desc->preallocated[0].data, desc->preallocated[0].pitch, + desc.flags, desc.caps, desc.width, desc.height, + desc.pixelformat, DFB_PIXELFORMAT_INDEX(desc.pixelformat), + desc.preallocated[0].data, desc.preallocated[0].pitch, DirectFBErrorString(result)); } + desc.caps = DFBSurfaceCapabilities(desc.caps & ~DSCAPS_VIDEOONLY); } if (!newSurface) - result = d_ptr->dfb->CreateSurface(d_ptr->dfb, desc, &newSurface); + result = d_ptr->dfb->CreateSurface(d_ptr->dfb, &desc, &newSurface); if (result != DFB_OK) { qWarning("QDirectFBScreen::createDFBSurface() Failed!\n" " Flags %0x Caps %0x width %d height %d pixelformat %0x %d preallocated %p %d\n%s", - desc->flags, desc->caps, desc->width, desc->height, - desc->pixelformat, DFB_PIXELFORMAT_INDEX(desc->pixelformat), - desc->preallocated[0].data, desc->preallocated[0].pitch, + desc.flags, desc.caps, desc.width, desc.height, + desc.pixelformat, DFB_PIXELFORMAT_INDEX(desc.pixelformat), + desc.preallocated[0].data, desc.preallocated[0].pitch, DirectFBErrorString(result)); return 0; } @@ -830,7 +829,7 @@ bool QDirectFBScreen::connect(const QString &displaySpec) description.caps = DFBSurfaceCapabilities(caps); // We don't track the primary surface as it's released in disconnect - d_ptr->dfbSurface = createDFBSurface(&description, DontTrackSurface); + d_ptr->dfbSurface = createDFBSurface(description, DontTrackSurface); if (!d_ptr->dfbSurface) { DirectFBError("QDirectFBScreen: error creating primary surface", result); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h index 8e75277..5e948ee 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h @@ -103,7 +103,7 @@ public: TrackSurface = 1 }; Q_DECLARE_FLAGS(SurfaceCreationOptions, SurfaceCreationOption); - IDirectFBSurface *createDFBSurface(const DFBSurfaceDescription *desc, + IDirectFBSurface *createDFBSurface(DFBSurfaceDescription desc, SurfaceCreationOptions options); IDirectFBSurface *createDFBSurface(const QImage &image, SurfaceCreationOptions options); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp index 09b7a30..6167980 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp @@ -184,7 +184,7 @@ void QDirectFBSurface::setGeometry(const QRect &rect, const QRegion &mask) description.height = rect.height(); QDirectFBScreen::initSurfaceDescriptionPixelFormat(&description, screen->pixelFormat()); - dfbSurface = screen->createDFBSurface(&description, false); + dfbSurface = screen->createDFBSurface(description, false); forceRaster = (dfbSurface && QDirectFBScreen::getImageFormat(dfbSurface) == QImage::Format_RGB32); } else { Q_ASSERT(dfbSurface); -- cgit v0.12 From a8692a079d0509fcfc45843dc68518007df27fbb Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Fri, 1 May 2009 10:20:53 -0700 Subject: Extended surface capabilities Clean up code and make it possible to set more DFBSurfaceCapabilities on the primary surface. Also allow users to force systemonly for the surfaces. --- .../gfxdrivers/directfb/qdirectfbscreen.cpp | 34 ++++++++++++++++++---- src/plugins/gfxdrivers/directfb/qdirectfbscreen.h | 3 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index e2324ff..858a958 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -214,10 +214,10 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QSize &size, } -IDirectFBSurface* QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc, SurfaceCreationOptions options) +IDirectFBSurface *QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc, SurfaceCreationOptions options) { - DFBResult result; - IDirectFBSurface* newSurface = 0; + DFBResult result = DFB_OK; + IDirectFBSurface *newSurface = 0; if (!d_ptr->dfb) { qWarning("QDirectFBScreen::createDFBSurface() - not connected"); @@ -247,6 +247,8 @@ IDirectFBSurface* QDirectFBScreen::createDFBSurface(DFBSurfaceDescription desc, } desc.caps = DFBSurfaceCapabilities(desc.caps & ~DSCAPS_VIDEOONLY); } + if (d_ptr->directFBFlags & SystemOnly) + desc.caps = DFBSurfaceCapabilities(desc.caps | DSCAPS_SYSTEMONLY); if (!newSurface) result = d_ptr->dfb->CreateSurface(d_ptr->dfb, &desc, &newSurface); @@ -805,6 +807,14 @@ bool QDirectFBScreen::connect(const QString &displaySpec) if (displayArgs.contains(QLatin1String("videoonly"), Qt::CaseInsensitive)) d_ptr->directFBFlags |= VideoOnly; + if (displayArgs.contains(QLatin1String("systemonly"), Qt::CaseInsensitive)) { + if (d_ptr->directFBFlags & VideoOnly) { + qWarning("QDirectFBScreen: error. videoonly and systemonly are mutually exclusive"); + } else { + d_ptr->directFBFlags |= SystemOnly; + } + } + if (displayArgs.contains(QLatin1String("ignoresystemclip"), Qt::CaseInsensitive)) d_ptr->directFBFlags |= IgnoreSystemClip; @@ -819,9 +829,23 @@ bool QDirectFBScreen::connect(const QString &displaySpec) description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_WIDTH); if (::setIntOption(displayArgs, QLatin1String("height"), &description.height)) description.flags = DFBSurfaceDescriptionFlags(description.flags | DSDESC_HEIGHT); + uint caps = DSCAPS_PRIMARY|DSCAPS_DOUBLE; - if (displayArgs.contains(QLatin1String("static_alloc"))) - caps |= DSCAPS_STATIC_ALLOC; + struct { + const char *name; + const DFBSurfaceCapabilities cap; + } const capabilities[] = { + { "static_alloc", DSCAPS_STATIC_ALLOC }, + { "triplebuffer", DSCAPS_TRIPLE }, + { "interlaced", DSCAPS_INTERLACED }, + { "separated", DSCAPS_SEPARATED }, +// { "depthbuffer", DSCAPS_DEPTH }, // only makes sense with TextureTriangles which are not supported + { 0, DSCAPS_NONE } + }; + for (int i=0; capabilities[i].name; ++i) { + if (displayArgs.contains(QString::fromLatin1(capabilities[i].name), Qt::CaseInsensitive)) + caps |= capabilities[i].cap; + } if (displayArgs.contains(QLatin1String("forcepremultiplied"), Qt::CaseInsensitive)) { caps |= DSCAPS_PREMULTIPLIED; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h index 5e948ee..6b3a975 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h @@ -62,7 +62,8 @@ public: enum DirectFBFlag { NoFlags = 0x00, VideoOnly = 0x01, - IgnoreSystemClip = 0x02 + SystemOnly = 0x02, + IgnoreSystemClip = 0x04 }; Q_DECLARE_FLAGS(DirectFBFlags, DirectFBFlag); -- cgit v0.12 From 8895643e1bd4b784a614bc8f275bb2e63dc2d9f8 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Fri, 1 May 2009 11:07:49 -0700 Subject: Improve debug output (in debug mode only) Print out detailed information about acceleration mask, blitting flags and drawing flags when passing debug. Reviewed-by: Donald --- .../gfxdrivers/directfb/qdirectfbscreen.cpp | 85 +++++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 858a958..4ce549d 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -739,6 +739,84 @@ QPixmapData* QDirectFBScreenPrivate::createPixmapData(QPixmapData::PixelType typ return new QDirectFBPixmapData(type); } +#ifdef QT_NO_DEBUG +struct FlagDescription; +static const FlagDescription *accelerationDescriptions = 0; +static const FlagDescription *blitDescriptions = 0; +static const FlagDescription *drawDescriptions = 0; +#else +struct FlagDescription { + const char *name; + uint flag; +}; + +static const FlagDescription accelerationDescriptions[] = { + { "DFXL_NONE ", DFXL_NONE }, + { "DFXL_FILLRECTANGLE", DFXL_FILLRECTANGLE }, + { "DFXL_DRAWRECTANGLE", DFXL_DRAWRECTANGLE }, + { "DFXL_DRAWLINE", DFXL_DRAWLINE }, + { "DFXL_FILLTRIANGLE", DFXL_FILLTRIANGLE }, + { "DFXL_BLIT", DFXL_BLIT }, + { "DFXL_STRETCHBLIT", DFXL_STRETCHBLIT }, + { "DFXL_TEXTRIANGLES", DFXL_TEXTRIANGLES }, + { "DFXL_DRAWSTRING", DFXL_DRAWSTRING }, + { 0, 0 } +}; + +static const FlagDescription blitDescriptions[] = { + { "DSBLIT_NOFX", DSBLIT_NOFX }, + { "DSBLIT_BLEND_ALPHACHANNEL", DSBLIT_BLEND_ALPHACHANNEL }, + { "DSBLIT_BLEND_COLORALPHA", DSBLIT_BLEND_COLORALPHA }, + { "DSBLIT_COLORIZE", DSBLIT_COLORIZE }, + { "DSBLIT_SRC_COLORKEY", DSBLIT_SRC_COLORKEY }, + { "DSBLIT_DST_COLORKEY", DSBLIT_DST_COLORKEY }, + { "DSBLIT_SRC_PREMULTIPLY", DSBLIT_SRC_PREMULTIPLY }, + { "DSBLIT_DST_PREMULTIPLY", DSBLIT_DST_PREMULTIPLY }, + { "DSBLIT_DEMULTIPLY", DSBLIT_DEMULTIPLY }, + { "DSBLIT_DEINTERLACE", DSBLIT_DEINTERLACE }, + { "DSBLIT_SRC_PREMULTCOLOR", DSBLIT_SRC_PREMULTCOLOR }, + { "DSBLIT_XOR", DSBLIT_XOR }, + { "DSBLIT_INDEX_TRANSLATION", DSBLIT_INDEX_TRANSLATION }, + { 0, 0 } +}; + +static const FlagDescription drawDescriptions[] = { + { "DSDRAW_NOFX", DSDRAW_NOFX }, + { "DSDRAW_BLEND", DSDRAW_BLEND }, + { "DSDRAW_DST_COLORKEY", DSDRAW_DST_COLORKEY }, + { "DSDRAW_SRC_PREMULTIPLY", DSDRAW_SRC_PREMULTIPLY }, + { "DSDRAW_DST_PREMULTIPLY", DSDRAW_DST_PREMULTIPLY }, + { "DSDRAW_DEMULTIPLY", DSDRAW_DEMULTIPLY }, + { "DSDRAW_XOR", DSDRAW_XOR }, + { 0, 0 } +}; +#endif + + + +static const QByteArray flagDescriptions(uint mask, const FlagDescription *flags) +{ +#ifdef QT_NO_DEBUG + Q_UNUSED(mask); + Q_UNUSED(flags); + return QByteArray(""); +#else + if (!mask) + return flags[0].name; + + QStringList list; + for (int i=1; flags[i].name; ++i) { + if (mask & flags[i].flag) { + list.append(QString::fromLatin1(flags[i].name)); + } + } + Q_ASSERT(!list.isEmpty()); + return (QLatin1Char(' ') + list.join(QLatin1String("|"))).toLatin1(); +#endif +} + + + static void printDirectFBInfo(IDirectFB *fb) { DFBResult result; @@ -751,10 +829,13 @@ static void printDirectFBInfo(IDirectFB *fb) } qDebug("Device: %s (%s), Driver: %s v%i.%i (%s)\n" - " acceleration: 0x%x, blit: 0x%x, draw: 0x%0x video: %i\n", + " acceleration: 0x%x%s,\nblit: 0x%x%s,\ndraw: 0x%0x%s\nvideo: %iKB\n", dev.name, dev.vendor, dev.driver.name, dev.driver.major, dev.driver.minor, dev.driver.vendor, dev.acceleration_mask, - dev.blitting_flags, dev.drawing_flags, dev.video_memory); + ::flagDescriptions(dev.acceleration_mask, accelerationDescriptions).constData(), + dev.blitting_flags, ::flagDescriptions(dev.blitting_flags, blitDescriptions).constData(), + dev.drawing_flags, ::flagDescriptions(dev.drawing_flags, drawDescriptions).constData(), + (dev.video_memory >> 10)); } static inline bool setIntOption(const QStringList &arguments, const QString &variable, int *value) -- cgit v0.12 From 111b2c3e40cc475d561d578663565e603963d6e3 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Sat, 2 May 2009 14:01:08 -0700 Subject: Beautified code Qt's coding style => Object *ptr, not Object* ptr Reviewed-by: TrustMe --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 20 ++++++++++---------- src/plugins/gfxdrivers/directfb/qdirectfbscreen.h | 14 +++++++------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 4ce549d..f8aaa5f 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -84,7 +84,7 @@ public: QImage::Format alphaPixmapFormat; }; -QDirectFBScreenPrivate::QDirectFBScreenPrivate(QDirectFBScreen* screen) +QDirectFBScreenPrivate::QDirectFBScreenPrivate(QDirectFBScreen *screen) : QWSGraphicsSystem(screen), dfb(0), dfbSurface(0), flipFlags(DSFLIP_NONE) #ifndef QT_NO_DIRECTFB_LAYER , dfbLayer(0) @@ -113,7 +113,7 @@ QDirectFBScreenPrivate::~QDirectFBScreenPrivate() delete keyboard; #endif - foreach (IDirectFBSurface* surf, allocatedSurfaces) + foreach (IDirectFBSurface *surf, allocatedSurfaces) surf->Release(surf); allocatedSurfaces.clear(); @@ -137,7 +137,7 @@ QDirectFBScreenPrivate::~QDirectFBScreenPrivate() // creates a preallocated surface with the same format as the image if // possible. -IDirectFBSurface* QDirectFBScreen::createDFBSurface(const QImage &img, SurfaceCreationOptions options) +IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QImage &img, SurfaceCreationOptions options) { if (img.isNull()) // assert? return 0; @@ -350,18 +350,18 @@ QDirectFBScreen::DirectFBFlags QDirectFBScreen::directFBFlags() const { return d_ptr->directFBFlags; } -IDirectFB* QDirectFBScreen::dfb() +IDirectFB *QDirectFBScreen::dfb() { return d_ptr->dfb; } -IDirectFBSurface* QDirectFBScreen::dfbSurface() +IDirectFBSurface *QDirectFBScreen::dfbSurface() { return d_ptr->dfbSurface; } #ifndef QT_NO_DIRECTFB_LAYER -IDirectFBDisplayLayer* QDirectFBScreen::dfbDisplayLayer() +IDirectFBDisplayLayer *QDirectFBScreen::dfbDisplayLayer() { return d_ptr->dfbLayer; } @@ -731,7 +731,7 @@ void QDirectFBScreenPrivate::setFlipFlags(const QStringList &args) } } -QPixmapData* QDirectFBScreenPrivate::createPixmapData(QPixmapData::PixelType type) const +QPixmapData *QDirectFBScreenPrivate::createPixmapData(QPixmapData::PixelType type) const { if (type == QPixmapData::BitmapType) return QWSGraphicsSystem::createPixmapData(type); @@ -1025,7 +1025,7 @@ void QDirectFBScreen::disconnect() d_ptr->dfbSurface->Release(d_ptr->dfbSurface); d_ptr->dfbSurface = 0; - foreach (IDirectFBSurface* surf, d_ptr->allocatedSurfaces) + foreach (IDirectFBSurface *surf, d_ptr->allocatedSurfaces) surf->Release(surf); d_ptr->allocatedSurfaces.clear(); @@ -1094,7 +1094,7 @@ void QDirectFBScreen::blank(bool on) (on ? DSPM_ON : DSPM_SUSPEND)); } -QWSWindowSurface* QDirectFBScreen::createSurface(QWidget *widget) const +QWSWindowSurface *QDirectFBScreen::createSurface(QWidget *widget) const { #ifdef QT_NO_DIRECTFB_WM if (QApplication::type() == QApplication::GuiServer) { @@ -1107,7 +1107,7 @@ QWSWindowSurface* QDirectFBScreen::createSurface(QWidget *widget) const #endif } -QWSWindowSurface* QDirectFBScreen::createSurface(const QString &key) const +QWSWindowSurface *QDirectFBScreen::createSurface(const QString &key) const { if (key == QLatin1String("directfb")) { return new QDirectFBSurface(d_ptr->flipFlags, const_cast(this)); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h index 6b3a975..8859d58 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h @@ -83,19 +83,19 @@ public: void setMode(int width, int height, int depth); void blank(bool on); - QWSWindowSurface* createSurface(QWidget *widget) const; - QWSWindowSurface* createSurface(const QString &key) const; + QWSWindowSurface *createSurface(QWidget *widget) const; + QWSWindowSurface *createSurface(const QString &key) const; - static inline QDirectFBScreen* instance() { + static inline QDirectFBScreen *instance() { QScreen *inst = QScreen::instance(); Q_ASSERT(!inst || inst->classId() == QScreen::DirectFBClass); return static_cast(inst); } - IDirectFB* dfb(); - IDirectFBSurface* dfbSurface(); + IDirectFB *dfb(); + IDirectFBSurface *dfbSurface(); #ifndef QT_NO_DIRECTFB_LAYER - IDirectFBDisplayLayer* dfbDisplayLayer(); + IDirectFBDisplayLayer *dfbDisplayLayer(); #endif // Track surface creation/release so we can release all on exit @@ -117,7 +117,7 @@ public: IDirectFBSurface *copyToDFBSurface(const QImage &image, QImage::Format format, SurfaceCreationOptions options); - void releaseDFBSurface(IDirectFBSurface* surface); + void releaseDFBSurface(IDirectFBSurface *surface); static int depth(DFBSurfacePixelFormat format); -- cgit v0.12 From bdcdb798d2cc4dc48079622a9c3cbe61be82e80b Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Sun, 3 May 2009 17:34:21 -0700 Subject: Implemented an option to tune flipping export QWS_DISPLAY=directfb:boundingrectflip to enable calling Flip on the bounding rect of the dirtied area rather than each dirty rectangle. This could be faster if you update many small rectangles. Reviewed-by: TrustMe --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 4 ++++ src/plugins/gfxdrivers/directfb/qdirectfbscreen.h | 3 ++- src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp | 6 ++++-- src/plugins/gfxdrivers/directfb/qdirectfbsurface.h | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index f8aaa5f..c1b75c5 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -896,6 +896,10 @@ bool QDirectFBScreen::connect(const QString &displaySpec) } } + if (displayArgs.contains(QLatin1String("boundingrectflip"), Qt::CaseInsensitive)) { + d_ptr->directFBFlags |= BoundingRectFlip; + } + if (displayArgs.contains(QLatin1String("ignoresystemclip"), Qt::CaseInsensitive)) d_ptr->directFBFlags |= IgnoreSystemClip; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h index 8859d58..42d0ebe 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h @@ -63,7 +63,8 @@ public: NoFlags = 0x00, VideoOnly = 0x01, SystemOnly = 0x02, - IgnoreSystemClip = 0x04 + IgnoreSystemClip = 0x04, + BoundingRectFlip = 0x08 }; Q_DECLARE_FLAGS(DirectFBFlags, DirectFBFlag); diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp index 6167980..beb9b5f 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbsurface.cpp @@ -50,13 +50,14 @@ //#define QT_DIRECTFB_DEBUG_SURFACES 1 -QDirectFBSurface::QDirectFBSurface(DFBSurfaceFlipFlags flip, QDirectFBScreen* scr) +QDirectFBSurface::QDirectFBSurface(DFBSurfaceFlipFlags flip, QDirectFBScreen *scr) : QDirectFBPaintDevice(scr) #ifndef QT_NO_DIRECTFB_WM , dfbWindow(0) #endif , engine(0) , flipFlags(flip) + , boundingRectFlip(scr->directFBFlags() & QDirectFBScreen::BoundingRectFlip) { setSurfaceFlags(Opaque | Buffered); #ifdef QT_DIRECTFB_TIMING @@ -72,6 +73,7 @@ QDirectFBSurface::QDirectFBSurface(DFBSurfaceFlipFlags flip, QDirectFBScreen *sc #endif , engine(0) , flipFlags(flip) + , boundingRectFlip(scr->directFBFlags() & QDirectFBScreen::BoundingRectFlip) { onscreen = widget->testAttribute(Qt::WA_PaintOnScreen); if (onscreen) @@ -369,7 +371,7 @@ void QDirectFBSurface::flush(QWidget *widget, const QRegion ®ion, if (!(flipFlags & DSFLIP_BLIT)) { dfbSurface->Flip(dfbSurface, 0, flipFlags); } else { - if (region.numRects() > 1) { + if (!boundingRectFlip && region.numRects() > 1) { const QVector rects = region.rects(); const DFBSurfaceFlipFlags nonWaitFlags = DFBSurfaceFlipFlags(flipFlags & ~DSFLIP_WAIT); for (int i=0; i bufferImages; DFBSurfaceFlipFlags flipFlags; + bool boundingRectFlip; #ifdef QT_DIRECTFB_TIMING int frames; QTime timer; -- cgit v0.12 From 279a45131ba60fad9f429c7c429271da5b9cc9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 4 May 2009 09:44:08 +0200 Subject: Make comment explaning the Mac deployment target setting clearer. --- configure | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/configure b/configure index b582d85..07a9415 100755 --- a/configure +++ b/configure @@ -6004,10 +6004,11 @@ if [ "$CFG_EXCEPTIONS" = "no" ]; then QMAKE_CONFIG="$QMAKE_CONFIG exceptions_off" fi -# On Mac, set the minimum deployment target using Xarch when that is supported (10.5 and up). -# On 10.4 the deployment version is set to 10.3 globally using the QMAKE_MACOSX_DEPLOYMENT_TARGET env. variable -# "-cocoa" on the command line means Cocoa is used in 32-bit mode also, in this case fall back on -# QMAKE_MACOSX_DEPLOYMENT_TARGET which will be set to 10.5. +# On Mac, set the minimum deployment target for the different architechtures +# using the Xarch compiler option when supported (10.5 and up). On 10.4 the +# deployment version is set to 10.3 globally using the QMAKE_MACOSX_DEPLOYMENT_TARGET +# env. variable. "-cocoa" on the command line means Cocoa is used in 32-bit mode also, +# in this case fall back on QMAKE_MACOSX_DEPLOYMENT_TARGET which will be set to 10.5. if [ "$PLATFORM_MAC" = "yes" ] && [ "$CFG_MAC_XARCH" != "no" ] && [ "$COMMANDLINE_MAC_COCOA" != "yes" ]; then if echo "$CFG_MAC_ARCHS" | grep '\' > /dev/null 2>&1; then QMakeVar add QMAKE_CFLAGS "-Xarch_i386 -mmacosx-version-min=10.4" -- cgit v0.12 From 8582f038ab46e26e04a97a481ebce6f89f5b3987 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 4 May 2009 10:07:46 +0200 Subject: QFileDialog::getOpenFileNames() is not shown at the correct position The correct behaviour for native file dialogs on mac is to use the previous size and location settings when reopening the dialog. So we implement this behaviour with this change Task-number: 250182 Reviewed-by: Trenton Schulz --- src/gui/dialogs/qfiledialog_mac.mm | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) 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; -- cgit v0.12 From aa077a8bd3ee3a134629ef6ac2367b7f11593724 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 4 May 2009 10:44:53 +0200 Subject: Do not crash when passing wrong indexes to QSortFilterProxyModel::indexFomSource and *ToSource Show a warning instead Task-number: 252507 Reviewed-by: Marius Bugge Monsen --- src/gui/itemviews/qsortfilterproxymodel.cpp | 9 +++++++++ .../tst_qsortfilterproxymodel.cpp | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp index 91431c4..43feda8 100644 --- a/src/gui/itemviews/qsortfilterproxymodel.cpp +++ b/src/gui/itemviews/qsortfilterproxymodel.cpp @@ -144,6 +144,7 @@ public: const QModelIndex &proxy_index) const { Q_ASSERT(proxy_index.isValid()); + Q_ASSERT(proxy_index.model() == q_func()); const void *p = proxy_index.internalPointer(); Q_ASSERT(p); QMap::const_iterator it = @@ -311,6 +312,10 @@ QModelIndex QSortFilterProxyModelPrivate::proxy_to_source(const QModelIndex &pro { if (!proxy_index.isValid()) return QModelIndex(); // for now; we may want to be able to set a root index later + if (proxy_index.model() != q_func()) { + qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapToSource"; + return QModelIndex(); + } IndexMap::const_iterator it = index_to_iterator(proxy_index); Mapping *m = it.value(); if ((proxy_index.row() >= m->source_rows.size()) || (proxy_index.column() >= m->source_columns.size())) @@ -324,6 +329,10 @@ QModelIndex QSortFilterProxyModelPrivate::source_to_proxy(const QModelIndex &sou { if (!source_index.isValid()) return QModelIndex(); // for now; we may want to be able to set a root index later + if (source_index.model() != model) { + qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapFromSource"; + return QModelIndex(); + } QModelIndex source_parent = source_index.parent(); IndexMap::const_iterator it = create_mapping(source_parent); Mapping *m = it.value(); diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 18aa5fc..bd66fdf 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -133,6 +133,7 @@ private slots: void task248868_dynamicSorting(); void task250023_fetchMore(); void task251296_hiddenChildren(); + void task252507_mapFromToSource(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -2612,6 +2613,7 @@ class QtTestModel: public QAbstractItemModel return fetched.contains(parent) ? rows : 0; } int columnCount(const QModelIndex& parent = QModelIndex()) const { + Q_UNUSED(parent); return cols; } @@ -2717,6 +2719,22 @@ void tst_QSortFilterProxyModel::task251296_hiddenChildren() QCOMPARE(proxy.data(indexC).toString(), QString::fromLatin1("C VISIBLE")); } +void tst_QSortFilterProxyModel::task252507_mapFromToSource() +{ + QtTestModel source(10,10); + source.fetchMore(QModelIndex()); + QSortFilterProxyModel proxy; + proxy.setSourceModel(&source); + QCOMPARE(proxy.mapFromSource(source.index(5, 4)), proxy.index(5, 4)); + QCOMPARE(proxy.mapToSource(proxy.index(3, 2)), source.index(3, 2)); + QCOMPARE(proxy.mapFromSource(QModelIndex()), QModelIndex()); + QCOMPARE(proxy.mapToSource(QModelIndex()), QModelIndex()); + + QTest::ignoreMessage(QtWarningMsg, "QSortFilterProxyModel: index from wrong model passed to mapToSource "); + QCOMPARE(proxy.mapToSource(source.index(2, 3)), QModelIndex()); + QTest::ignoreMessage(QtWarningMsg, "QSortFilterProxyModel: index from wrong model passed to mapFromSource "); + QCOMPARE(proxy.mapFromSource(proxy.index(6, 2)), QModelIndex()); +} QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" -- cgit v0.12 From e223a450ce57a7dc627e0eac14cea019f99fe601 Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Mon, 4 May 2009 13:13:51 +0200 Subject: Added comment to clearify the use of indexes. Added a comment about the use of negative indexes. Task-number: 249344 Rev-by: Marius Storm-Olsen --- src/corelib/tools/qlistdata.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/corelib/tools/qlistdata.cpp b/src/corelib/tools/qlistdata.cpp index d7c39a7..d40b6b6 100644 --- a/src/corelib/tools/qlistdata.cpp +++ b/src/corelib/tools/qlistdata.cpp @@ -764,6 +764,10 @@ void **QListData::erase(void **xi) This function requires the value type to have an implementation of \c operator==(). + Note that QList uses 0-based indexes, just like C++ arrays. Negative + indexes are not supported with the exception of the value mentioned + above. + \sa lastIndexOf(), contains() */ @@ -780,6 +784,10 @@ void **QListData::erase(void **xi) This function requires the value type to have an implementation of \c operator==(). + Note that QList uses 0-based indexes, just like C++ arrays. Negative + indexes are not supported with the exception of the value mentioned + above. + \sa indexOf() */ -- cgit v0.12 From 2caeea74bbd393546b77a34c79361bbbc31a067b Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 4 May 2009 13:25:53 +0200 Subject: Mac: QWidget::setMinimumSize does not work The reason is that we never applied the new max min values on the native window itself. This patch does that, and also makes sure that we do this on the appropriate times (window creation, etc) Task-number: 219695 Reviewed-by: Trenton Schulz --- src/gui/kernel/qwidget_mac.mm | 86 ++++++++++++++++++++++--------------------- src/gui/kernel/qwidget_p.h | 3 +- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index b238279..9da0b6b 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -2156,6 +2156,7 @@ void QWidgetPrivate::finishCreateWindow_sys_Carbon(OSWindowRef windowRef) setWindowModified_sys(q->isWindowModified()); updateFrameStrut(); qt_mac_update_sizer(q); + applyMaxAndMinSizeOnWindow(); } #else // QT_MAC_USE_COCOA void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWindowRef) @@ -2241,6 +2242,7 @@ void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWin syncCocoaMask(); macUpdateIsOpaque(); qt_mac_update_sizer(q); + applyMaxAndMinSizeOnWindow(); } #endif // QT_MAC_USE_COCOA @@ -3995,7 +3997,7 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect) } } -void QWidgetPrivate::applyMaxAndMinSizeConstraints(int &w, int &h) +void QWidgetPrivate::adjustWithinMaxAndMinSize(int &w, int &h) { if (QWExtra *extra = extraData()) { w = qMin(w, extra->maxw); @@ -4022,6 +4024,26 @@ void QWidgetPrivate::applyMaxAndMinSizeConstraints(int &w, int &h) } } +void QWidgetPrivate::applyMaxAndMinSizeOnWindow() +{ + Q_Q(QWidget); + const float max_f(20000); +#ifndef QT_MAC_USE_COCOA +#define SF(x) ((x > max_f) ? max_f : x) + HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh)); + HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh)); +#undef SF + SetWindowResizeLimits(qt_mac_window_for(q), &min, &max); +#else +#define SF(x) ((x > max_f) ? max_f : x) + NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh)); + NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh)); +#undef SF + [qt_mac_window_for(q) setMinSize:min]; + [qt_mac_window_for(q) setMaxSize:max]; +#endif +} + void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) { Q_Q(QWidget); @@ -4033,17 +4055,18 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) QMacCocoaAutoReleasePool pool; bool realWindow = isRealWindow(); - if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen) + if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){ + adjustWithinMaxAndMinSize(w, h); #ifndef QT_MAC_USE_COCOA - && !(w == 0 && h == 0) -#endif - ){ - applyMaxAndMinSizeConstraints(w, h); - topData()->isSetGeometry = 1; - topData()->isMove = isMove; -#ifndef QT_MAC_USE_COCOA - Rect r; SetRect(&r, x, y, x + w, y + h); - SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r); + if (w != 0 && h != 0) { + topData()->isSetGeometry = 1; + topData()->isMove = isMove; + Rect r; SetRect(&r, x, y, x + w, y + h); + SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r); + topData()->isSetGeometry = 0; + } else { + setGeometry_sys_helper(x, y, w, h, isMove); + } #else NSWindow *window = qt_mac_window_for(q); const QRect &fStrut = frameStrut(); @@ -4071,7 +4094,6 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) [window setFrameOrigin:cocoaFrameRect.origin]; } #endif - topData()->isSetGeometry = 0; } else { setGeometry_sys_helper(x, y, w, h, isMove); } @@ -4096,40 +4118,19 @@ void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isM data.crect = QRect(x, y, w, h); if (realWindow) { - if (QWExtra *extra = extraData()) { - applyMaxAndMinSizeConstraints(w, h); - qt_mac_update_sizer(q); + adjustWithinMaxAndMinSize(w, h); + qt_mac_update_sizer(q); - if (q->windowFlags() & Qt::WindowMaximizeButtonHint) { #ifndef QT_MAC_USE_COCOA - OSWindowRef window = qt_mac_window_for(q); - if(extra->maxw && extra->maxh && extra->maxw == extra->minw - && extra->maxh == extra->minh) { - ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute); - } else { - ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes); - } -#endif + if (q->windowFlags() & Qt::WindowMaximizeButtonHint) { + OSWindowRef window = qt_mac_window_for(q); + if (extra->maxw && extra->maxh && extra->maxw == extra->minw + && extra->maxh == extra->minh) { + ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute); + } else { + ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes); } - - // Update max and min constraints: - const float max_f(20000); -#ifndef QT_MAC_USE_COCOA -#define SF(x) ((x > max_f) ? max_f : x) - HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh)); - HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh)); -#undef SF - SetWindowResizeLimits(qt_mac_window_for(q), &min, &max); -#else -#define SF(x) ((x > max_f) ? max_f : x) - NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh)); - NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh)); -#undef SF - [qt_mac_window_for(q) setMinSize:min]; - [qt_mac_window_for(q) setMaxSize:max]; -#endif } -#ifndef QT_MAC_USE_COCOA HIRect bounds = CGRectMake(0, 0, w, h); HIViewSetFrame(qt_mac_nativeview_for(q), &bounds); #else @@ -4175,6 +4176,7 @@ void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isM void QWidgetPrivate::setConstraints_sys() { updateMaximizeButton_sys(); + applyMaxAndMinSizeOnWindow(); } void QWidgetPrivate::updateMaximizeButton_sys() diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 8731551..8c6a234 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -252,7 +252,8 @@ public: void macUpdateIsOpaque(); void setEnabled_helper_sys(bool enable); bool isRealWindow() const; - void applyMaxAndMinSizeConstraints(int &w, int &h); + void adjustWithinMaxAndMinSize(int &w, int &h); + void applyMaxAndMinSizeOnWindow(); #endif void raise_sys(); -- cgit v0.12 From f51ce7c1b349b31f61df48786148c8b3525e2a2c Mon Sep 17 00:00:00 2001 From: Kavindra Devi Palaraja Date: Mon, 4 May 2009 13:30:07 +0200 Subject: Doc - Clarifying how to override a Widget's size hint in the Getting to Know Qt Designer document. Task-number: 165435 Reviewed-by: Friedemann Kleint --- doc/src/designer-manual.qdoc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/src/designer-manual.qdoc b/doc/src/designer-manual.qdoc index e10a5be..03b74e6 100644 --- a/doc/src/designer-manual.qdoc +++ b/doc/src/designer-manual.qdoc @@ -344,10 +344,14 @@ of a QLineEdit or the width and height of item view widgets. This is where the widget size constraints -- \l{QWidget::minimumSize()}{minimumSize} and \l{QWidget::maximumSize()}{maximumSize} constraints come into play. These - are properties you can set in the property editor. Alternatively, to use - the current size as a size constraint value, choose one of the - \gui{Size Constraint} options from the widget's context menu. The layout - will then ensure that those constraints are met. + are properties you can set in the property editor. For example, to override + the default \l{QWidget::}{sizeHint()}, simply set + \l{QWidget::minimumSize()}{minimumSize} and \l{QWidget::maximumSize()} + {maximumSize} to the same value. Alternatively, to use the current size as + a size constraint value, choose one of the \gui{Size Constraint} options + from the widget's context menu. The layout will then ensure that those + constraints are met. To control the size of your widgets via code, you can + reimplement \l{QWidget::}{sizeHint()} in your code. The screenshot below shows the breakdown of a basic user interface designed using a grid. The coordinates on the screenshot show the position of each -- cgit v0.12 From 759338df758ad16cdfd9521b270f7e379bbfa57c Mon Sep 17 00:00:00 2001 From: mae Date: Mon, 4 May 2009 13:32:02 +0200 Subject: QTextEdit::ExtraSelection failure with style sheets the feature has to handle text with and without background, and extra selections with and without background, or even only with underline style. Trouble is that you sometimes want to accumulate styles, for example spell checking wiggly underline plus search result highlights or background markup from the css stylesheet. Task-number: 252310 --- src/gui/text/qtextformat.h | 6 ++++++ src/gui/text/qtextlayout.cpp | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index 0571d75..8eaeeb1 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -232,6 +232,12 @@ public: ImageWidth = 0x5010, ImageHeight = 0x5011, + // internal + /* + SuppressText = 0x5012, + SuppressBackground = 0x513 + */ + // selection properties FullWidthSelection = 0x06000, diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 434d1ca..3222237 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -61,6 +61,8 @@ QT_BEGIN_NAMESPACE #define ObjectSelectionBrush (QTextFormat::ForegroundBrush + 1) +#define SuppressText 0x5012 +#define SuppressBackground 0x513 static inline QFixed leadingSpaceWidth(QTextEngine *eng, const QScriptLine &line) { @@ -1143,6 +1145,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVectorrestore(); - if (selection.format.foreground().style() != Qt::NoBrush) // i.e. we have drawn text - excludedRegion += region; + if (noText) + needsTextButNoBackground += region; + else + needsTextButNoBackground -= region; + excludedRegion += region; + } + + if (!needsTextButNoBackground.isEmpty()){ + p->save(); + p->setClipPath(needsTextButNoBackground, Qt::IntersectClip); + FormatRange selection; + selection.start = 0; + selection.length = INT_MAX; + selection.format.setProperty(SuppressBackground, true); + for (int line = firstLine; line < lastLine; ++line) { + QTextLine l(line, d); + l.draw(p, position, &selection); + } + p->restore(); } if (!excludedRegion.isEmpty()) { @@ -1912,14 +1936,17 @@ static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si, static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf, const QRectF &r) { QBrush c = chf.foreground(); - if (c.style() == Qt::NoBrush) + if (c.style() == Qt::NoBrush) { p->setPen(defaultPen); + } QBrush bg = chf.background(); - if (bg.style() != Qt::NoBrush) + if (bg.style() != Qt::NoBrush && !chf.property(SuppressBackground).toBool()) p->fillRect(r, bg); - if (c.style() != Qt::NoBrush) + if (c.style() != Qt::NoBrush) { p->setPen(QPen(c, 0)); + } + } /*! @@ -1933,7 +1960,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR const QScriptLine &line = eng->lines[i]; QPen pen = p->pen(); - bool noText = (selection && selection->format.foreground().style() == Qt::NoBrush); + bool noText = (selection && selection->format.property(SuppressText).toBool()); if (!line.length) { if (selection -- cgit v0.12 From 80aef133fd2c8da3cc1a6607c1c044eaca768169 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 26 Apr 2009 17:21:24 +0200 Subject: Greatly reduced the complexity of the boilerplate function. I found out that all I needed to load the proper libraries was to add a string to the ".interp" section of the ELF executable containing the path to ld.so Reviewed-By: Marius Storm-Olsen --- src/corelib/global/qlibraryinfo.cpp | 107 ++++++------------------------------ 1 file changed, 17 insertions(+), 90 deletions(-) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index ada08c7..29e356e 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -485,100 +485,27 @@ QT_END_NAMESPACE #if defined(Q_CC_GNU) && defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) && !defined(QT_BOOTSTRAPPED) -# include -# include - -static const char boilerplate[] = - "This is the QtCore library version " QT_VERSION_STR "\n" - "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" - "Contact: Qt Software Information (qt-info@nokia.com)\n" - "\n" - "Build key: " QT_BUILD_KEY; - -extern "C" { -void qt_core_init_boilerplate() __attribute__((noreturn)); -} +# include +# include -# if defined(QT_ARCH_I386) -#define sysinit() (void)0 -#define syswrite(msg, len) \ - ({ int res; \ - asm volatile ("movl %%ebx, %%edi\n" \ - "movl $1, %%ebx\n" \ - "int $0x80\n" \ - "movl %%edi, %%ebx\n" \ - : "=a" (res) : "0" (SYS_write), "c" (msg), "d" (len) : "edi"); res; }) -#define sysexit(c) \ - asm ("xor %%ebx, %%ebx\n" \ - "int $0x80\n" \ - : : "a" (SYS_exit)); _exit(c) - -# elif defined(QT_ARCH_X86_64) -#define sysinit() (void)0 -#define syswrite(msg, len) \ - ({ int res; \ - asm volatile ("syscall\n" \ - : "=a" (res) : "0" (SYS_write), "D" (1), "S" (msg), "d" (len) : "rcx"); res; }) -#define sysexit(c) \ - asm ("syscall\n" \ - : : "a" (SYS_exit), "D" (0)); _exit(c) - -# elif defined(QT_ARCH_IA64) -#define sysinit() \ - asm volatile ("{.mlx\n" \ - " nop.m 0\n" \ - " movl r2 = @pcrel(boilerplate);;" \ - "}\n" \ - "{.mii\n" \ - " mov r10 = @ltoffx(boilerplate)\n" \ - " mov r1 = ip\n" \ - " adds r2 = -16, r2\n;;\n" \ - "}\n" \ - " add r1 = r2, r1;;\n" \ - " sub r1 = r1, r10;;\n" \ - : : : "r2", "r10") -#define syswrite(msg, len) \ - ({ const char *_msg = msg; \ - asm ("mov out0=%1\n" \ - "mov out1=%2\n" \ - "mov out2=%3\n" \ - ";;\n" \ - "mov r15=%0\n" \ - "break 0x100000;;\n" \ - : : "I" (SYS_write), "I" (1), "r" (_msg), "r" (len)); }) -#define sysexit(c) \ - asm ("mov out0=%1\n" \ - ";;\n" \ - "mov r15=%0\n" \ - "break 0x100000;;\n" \ - : : "I" (SYS_exit), "O" (0)); write(1, 0, 0); _exit(c) -# else -#define sysinit() (void)0 -#define syswrite(msg, len) (msg); (len) -#define sysexit(c) __builtin_exit(c) -# endif - -#define sysputs(msg) syswrite(msg, -1 + sizeof(msg)) -#define sysendl() syswrite("\n", 1) -#define print_qt_configure(_which) \ - ({const char *which = _which; \ - which += 12; \ - int len = 0; \ - while (which[len]) ++len; \ - syswrite(which, len); }) +extern const char qt_core_interpreter[] __attribute__((section(".interp"))) + = "/lib/ld-linux.so.2"; +extern "C" void qt_core_init_boilerplate() { - sysinit(); - sysputs(boilerplate); - sysputs("\nInstallation prefix: "); - print_qt_configure(qt_configure_prefix_path_str); - sysputs("\nLibrary path: "); - print_qt_configure(qt_configure_libraries_path_str); - sysputs("\nInclude path: "); - print_qt_configure(qt_configure_headers_path_str); - sysendl(); - sysexit(0); + printf("This is the QtCore library version " QT_VERSION_STR "\n" + "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" + "Contact: Qt Software Information (qt-info@nokia.com)\n" + "\n" + "Build key: " QT_BUILD_KEY "\n" + "Installation prefix: %s\n" + "Library path: %s\n" + "Include path: %s\n", + qt_configure_prefix_path_str + 12, + qt_configure_libraries_path_str + 12, + qt_configure_headers_path_str + 12); + exit(0); } #endif -- cgit v0.12 From 237b4b8c8e9b5184578b4776c5f1f554c0d8efb5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 4 May 2009 11:48:46 +0200 Subject: Fixed D-Bus socket write notifications, broken since d47c05b1 Shame on me: copy/paste from socketRead to socketWrite, I didn't change the DBUS_WATCH_READABLE to DBUS_WATCH_WRITABLE. Reviewed-by: Trust Me --- src/dbus/qdbusintegrator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 8c701f5..2c27381 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1102,7 +1102,7 @@ void QDBusConnectionPrivate::socketWrite(int fd) } for (int i = 0; i < pendingWatches.size(); ++i) - if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_READABLE)) + if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_WRITABLE)) qDebug("OUT OF MEM"); } -- cgit v0.12 From ea91eb38d81e37bd12d6abc2604f025ac1d254ce Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Mon, 4 May 2009 13:54:47 +0200 Subject: Ensure that we send the Apple Events even when Cocoa isn't ready. In general, Cocoa handles the the Apple Events for us. However, this is time between creating the NSApplication and Cocoa has set everything up, usually after the event loop is running. This means that until that time, the events are dropped on the floor :-/. The workaround is to use the same handler that we use for Carbon, but to only have it enabled for until Cocoa is ready to handle things. This will result in not stepping on the toes when used in a plugin (if it does, we can conditionalize it). Task-number: 252795 Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qapplication_mac.mm | 32 ++++++++++++++++--------- src/gui/kernel/qcocoaapplicationdelegate_mac.mm | 2 ++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index 5f8c572..69302ec 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -194,8 +194,8 @@ static bool appNoGrab = false; // mouse/keyboard grabbing #ifndef QT_MAC_USE_COCOA static EventHandlerRef app_proc_handler = 0; static EventHandlerUPP app_proc_handlerUPP = 0; -static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL; #endif +static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL; static EventHandlerRef tablet_proximity_handler = 0; static EventHandlerUPP tablet_proximity_UPP = 0; bool QApplicationPrivate::native_modal_dialog_active; @@ -951,7 +951,6 @@ void qt_mac_event_release(QWidget *w) } } -#ifndef QT_MAC_USE_COCOA struct QMacAppleEventTypeSpec { AEEventClass mac_class; AEEventID mac_id; @@ -959,6 +958,7 @@ struct QMacAppleEventTypeSpec { { kCoreEventClass, kAEQuitApplication }, { kCoreEventClass, kAEOpenDocuments } }; +#ifndef QT_MAC_USE_COCOA /* watched events */ static EventTypeSpec app_events[] = { { kEventClassQt, kEventQtRequestWindowChange }, @@ -1156,13 +1156,13 @@ void qt_init(QApplicationPrivate *priv, int) qt_init_app_proc_handler(); } +#endif if (!app_proc_ae_handlerUPP) { app_proc_ae_handlerUPP = AEEventHandlerUPP(QApplicationPrivate::globalAppleEventProcessor); for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, app_proc_ae_handlerUPP, SRefCon(qApp), true); } -#endif if (QApplicationPrivate::app_style) { QEvent ev(QEvent::Style); @@ -1210,6 +1210,17 @@ void qt_init(QApplicationPrivate *priv, int) } +void qt_release_apple_event_handler() +{ + if(app_proc_ae_handlerUPP) { + for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) + AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, + app_proc_ae_handlerUPP, true); + DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP); + app_proc_ae_handlerUPP = 0; + } +} + /***************************************************************************** qt_cleanup() - cleans up when the application is finished *****************************************************************************/ @@ -1223,15 +1234,8 @@ void qt_cleanup() DisposeEventHandlerUPP(app_proc_handlerUPP); app_proc_handlerUPP = 0; } - if(app_proc_ae_handlerUPP) { - for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) - AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, - app_proc_ae_handlerUPP, true); - DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP); - app_proc_ae_handlerUPP = NULL; - } #endif - + qt_release_apple_event_handler(); qt_release_tablet_proximity_handler(); if (tablet_proximity_UPP) DisposeEventHandlerUPP(tablet_proximity_UPP); @@ -2367,6 +2371,12 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event #endif } +// In Carbon this is your one stop for apple events. +// In Cocoa, it ISN'T. This is the catch-all Apple Event handler that exists +// for the time between instantiating the NSApplication, but before the +// NSApplication has installed it's OWN Apple Event handler. When Cocoa has +// that set up, we remove this. So, if you are debugging problems, you likely +// want to check out QCocoaApplicationDelegate instead. OSStatus QApplicationPrivate::globalAppleEventProcessor(const AppleEvent *ae, AppleEvent *, long handlerRefcon) { QApplication *app = (QApplication *)handlerRefcon; diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm index 6571068..dad15d9 100644 --- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm +++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm @@ -204,6 +204,8 @@ static void cleanupCocoaApplicationDelegate() { Q_UNUSED(aNotification); inLaunch = false; + extern void qt_release_apple_event_handler(); //qapplication_mac.mm + qt_release_apple_event_handler(); } - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames -- cgit v0.12 From c368a8ed6badab846c8e63c26d48b95788c12163 Mon Sep 17 00:00:00 2001 From: Trond Kjernaasen Date: Mon, 4 May 2009 14:01:07 +0200 Subject: Added an assert so that QColormap usage without a QApplication asserts. Task-number: 252668 Reviewed-by: Samuel --- src/gui/painting/qcolormap_win.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qcolormap_win.cpp b/src/gui/painting/qcolormap_win.cpp index d61b933..7d36582 100644 --- a/src/gui/painting/qcolormap_win.cpp +++ b/src/gui/painting/qcolormap_win.cpp @@ -138,7 +138,11 @@ void QColormap::cleanup() } QColormap QColormap::instance(int) -{ return QColormap(); } +{ + Q_ASSERT_X(screenMap, "QColormap", + "A QApplication object needs to be constructed before QColormap is used."); + return QColormap(); +} QColormap::QColormap() : d(screenMap) -- cgit v0.12 From f68f352dec04d796916dd8c4f5f60e8f62e4edf6 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Mon, 4 May 2009 14:12:40 +0200 Subject: prefer macro over stub - Windows Mobile does the same, thus we will not have double definitions or such - COINIT_MULTITHREADED is the default, meaning that 0 usually expands to it. Just be on the safe side and be more precise. Task-number: 237029 Reviewed-by: joerg --- src/corelib/kernel/qfunctions_wince.cpp | 5 ----- src/corelib/kernel/qfunctions_wince.h | 5 +++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/corelib/kernel/qfunctions_wince.cpp b/src/corelib/kernel/qfunctions_wince.cpp index 1c929c7..e0f7687 100644 --- a/src/corelib/kernel/qfunctions_wince.cpp +++ b/src/corelib/kernel/qfunctions_wince.cpp @@ -285,11 +285,6 @@ int qt_wince_SetErrorMode(int newValue) return result; } -HRESULT qt_wince_CoInitialize(void* reserved) -{ - return CoInitializeEx(reserved, 0); -} - bool qt_wince__chmod(const char *file, int mode) { return _wchmod( reinterpret_cast (QString::fromLatin1(file).utf16()), mode); diff --git a/src/corelib/kernel/qfunctions_wince.h b/src/corelib/kernel/qfunctions_wince.h index 123bd23..5f08bb3 100644 --- a/src/corelib/kernel/qfunctions_wince.h +++ b/src/corelib/kernel/qfunctions_wince.h @@ -199,7 +199,9 @@ int qt_wince__fstat( int handle, struct stat *buffer); #define SEM_FAILCRITICALERRORS 0x0001 #define SEM_NOOPENFILEERRORBOX 0x0002 int qt_wince_SetErrorMode(int); -HRESULT qt_wince_CoInitialize(void* reserved); +#ifndef CoInitialize +#define CoInitialize(x) CoInitializeEx(x, COINIT_MULTITHREADED) +#endif bool qt_wince__chmod(const char *file, int mode); bool qt_wince__wchmod(const WCHAR *file, int mode); @@ -376,7 +378,6 @@ typedef DWORD OLE_COLOR; #define _rename(a,b) qt_wince__rename(a,b) #define _remove(a) qt_wince__remove(a) #define SetErrorMode(a) qt_wince_SetErrorMode(a) -#define CoInitialize(a) qt_wince_CoInitialize(a) #define _chmod(a,b) qt_wince__chmod(a,b) #define _wchmod(a,b) qt_wince__wchmod(a,b) #define CreateFileA(a,b,c,d,e,f,g) qt_wince_CreateFileA(a,b,c,d,e,f,g) -- cgit v0.12 From 1e0e67406c3865717fef8b98d2c69adbefc54245 Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Wed, 22 Apr 2009 13:42:34 +0200 Subject: Deprecate qt_mac_set_show_menubar for a public cross-platform API. I'm tired of these "hidden" functions. We have an AA_MacPluginApplication, but sometimes you may have a legitimate reason for setting this outside of "plugin applications." In the footsteps of the menu icon attribute, the attribute is the main leader, but menubars can disable/enable this locally the new QMenuBar::setNativeMenuBar() property. Otherwise, the menubars take their que from the application attribute. This also works for Windows CE. So, there is a bit on convergence as well. Task-number: 236757 --- doc/src/exportedfunctions.qdoc | 3 + doc/src/qnamespace.qdoc | 8 ++- src/corelib/global/qnamespace.h | 1 + src/corelib/kernel/qcoreapplication.cpp | 14 +++++ src/gui/kernel/qaction.cpp | 2 +- src/gui/kernel/qapplication_mac.mm | 4 -- src/gui/kernel/qshortcutmap.cpp | 6 +- src/gui/widgets/qmenu_mac.mm | 34 +++++++--- src/gui/widgets/qmenubar.cpp | 107 ++++++++++++++++++++++---------- src/gui/widgets/qmenubar.h | 4 ++ src/gui/widgets/qmenubar_p.h | 5 +- 11 files changed, 133 insertions(+), 55 deletions(-) diff --git a/doc/src/exportedfunctions.qdoc b/doc/src/exportedfunctions.qdoc index f67950c..b421086 100644 --- a/doc/src/exportedfunctions.qdoc +++ b/doc/src/exportedfunctions.qdoc @@ -129,6 +129,9 @@ on Mac OS X or be part of the main window. This feature is on by default. + In Qt 4.6, this is equivalent to + \c { QApplication::instance()->setAttribute(Qt::AA_MacDontUseNativeMenuBar); }. + \section1 void qt_mac_set_press_and_hold_context(bool \e{enable}) Turns emulation of the right mouse button by clicking and holding diff --git a/doc/src/qnamespace.qdoc b/doc/src/qnamespace.qdoc index 9ea6b52..8a1e5e6 100644 --- a/doc/src/qnamespace.qdoc +++ b/doc/src/qnamespace.qdoc @@ -149,7 +149,13 @@ \value AA_MacPluginApplication Stops the a Qt mac application from doing specific initializations that do not necessarily make sense when using Qt to author a plugin. This includes avoiding loading our nib for the main - menu and not taking possession of the native menu bar. + menu and not taking possession of the native menu bar. When setting this + attribute to true will alse set the AA_MacDontUseNativeMenuBar attribute + to true. + + \value AA_DontUseNativeMenuBar All menubars created while this attribute is + set to true won't be used as a native menubar (e.g, the menubar at + the top of the main screen on Mac OS X or at the bottom in Windows CE). \omitvalue AA_AttributeCount */ diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 9b26ef3..4873b17 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -503,6 +503,7 @@ public: AA_NativeWindows = 3, AA_DontCreateNativeWidgetSiblings = 4, AA_MacPluginApplication = 5, + AA_DontUseNativeMenuBar = 6, // Add new attributes before this line AA_AttributeCount diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index e4bd664..c21cf87 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -556,6 +556,20 @@ void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on) QCoreApplicationPrivate::attribs |= 1 << attribute; else QCoreApplicationPrivate::attribs &= ~(1 << attribute); +#ifdef Q_OS_MAC + // Turn on the no native menubar here, since we used to + // do this implicitly. We DO NOT flip it off if someone sets + // it to false. + // Ideally, we'd have magic that would be something along the lines of + // "follow MacPluginApplication" unless explicitly set. + // Considering this attribute isn't only at the beginning + // it's unlikely it will ever be a problem, but I want + // to have the behavior documented here. + if (attribute == Qt::AA_MacPluginApplication && on + && !testAttribute(Qt::AA_DontUseNativeMenuBar)) { + setAttribute(Qt::AA_DontUseNativeMenuBar, true); + } +#endif } /*! diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index c6addc1..b2afbd0 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -1370,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_mac.mm b/src/gui/kernel/qapplication_mac.mm index 8d0b2c1..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) { diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index ed9654b..b6703e2 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(w)) + if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast(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(w)) + if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast(w)) visible = true; #endif diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm index ad848c9..d2aad99 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; @@ -166,7 +165,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) @@ -728,6 +727,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 @@ -931,7 +942,8 @@ static QKeySequence qt_mac_menu_merge_accel(QMacMenuAction *action) 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; } /***************************************************************************** @@ -1728,9 +1740,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 +1782,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 +1903,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 +1936,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 +1957,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/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index f235cd5..d4de5bd 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -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; } @@ -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_WS_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,19 @@ 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_WS_WINCE - if(d->wce_menubar) { 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) { @@ -1612,10 +1601,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_WS_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 +1659,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_WS_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 +1721,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_WS_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 +1841,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 &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. diff --git a/src/gui/widgets/qmenubar.h b/src/gui/widgets/qmenubar.h index 8e6dfb5..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); @@ -118,6 +119,9 @@ public: static void wceRefresh(); #endif + bool isNativeMenuBar() const; + void setNativeMenuBar(bool nativeMenuBar); + public Q_SLOTS: virtual void setVisible(bool visible); diff --git a/src/gui/widgets/qmenubar_p.h b/src/gui/widgets/qmenubar_p.h index c0bcb00..5dab310 100644 --- a/src/gui/widgets/qmenubar_p.h +++ b/src/gui/widgets/qmenubar_p.h @@ -70,7 +70,8 @@ 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 @@ -119,6 +120,8 @@ public: uint keyboardState : 1, altPressed : 1; QPointer keyboardFocusWidget; + + int nativeMenuBar : 3; // Only has values -1, 0, and 1 //firing of events void activateAction(QAction *, QAction::ActionEvent); -- cgit v0.12 From 7031e1d110bb1bc97cfe0377adc211030e1e7320 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Tue, 28 Apr 2009 14:08:59 +0200 Subject: When data was copied from Mozilla Firefox to Qt, the text format was not valid. Mozilla encodes the text/html format in UTF16 and adds a BOM, however it doesn't specify the charset in the html header. The fix is to guess the encoding by either charset in the html header or BOM for text/html format, or by BOM for non html formats. This commit adds a new public function QTextCodec::codecForUtfText() which can be used to guess encoding out of the BOM. Task-number: 250555 Reviewed-by: Benjamin Poulain Reviewed-by: Simon Hausmann Reviewed-by: Andreas Aardal Hanssen --- src/corelib/codecs/qtextcodec.cpp | 77 +++++++++++++++++++++++++++----- src/corelib/codecs/qtextcodec.h | 3 ++ src/gui/kernel/qclipboard.cpp | 24 +++++++--- tests/auto/qtextcodec/tst_qtextcodec.cpp | 59 ++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 19 deletions(-) diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 6e8ffa1..51ca43e 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1508,9 +1508,14 @@ QString QTextDecoder::toUnicode(const QByteArray &ba) /*! \since 4.4 - Tries to detect the encoding of the provided snippet of HTML in the given byte array, \a ba, - and returns a QTextCodec instance that is capable of decoding the html to unicode. - If the codec cannot be detected from the content provided, \a defaultCodec is returned. + Tries to detect the encoding of the provided snippet of HTML in + the given byte array, \a ba, by checking the BOM (Byte Order Mark) + and the content-type meta header and returns a QTextCodec instance + that is capable of decoding the html to unicode. If the codec + cannot be detected from the content provided, \a defaultCodec is + returned. + + \sa codecForUtfText */ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec) { @@ -1518,15 +1523,8 @@ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCo int pos; QTextCodec *c = 0; - if (ba.size() > 1 && (((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff) - || ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe))) { - c = QTextCodec::codecForMib(1015); // utf16 - } else if (ba.size() > 2 - && (uchar)ba[0] == 0xef - && (uchar)ba[1] == 0xbb - && (uchar)ba[2] == 0xbf) { - c = QTextCodec::codecForMib(106); // utf-8 - } else { + c = QTextCodec::codecForUtfText(ba, c); + if (!c) { QByteArray header = ba.left(512).toLower(); if ((pos = header.indexOf("http-equiv=")) != -1) { pos = header.indexOf("charset=", pos) + int(strlen("charset=")); @@ -1554,6 +1552,61 @@ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba) return codecForHtml(ba, QTextCodec::codecForMib(/*Latin 1*/ 4)); } +/*! + \since 4.6 + + Tries to detect the encoding of the provided snippet \a ba by + using the BOM (Byte Order Mark) and returns a QTextCodec instance + that is capable of decoding the text to unicode. If the codec + cannot be detected from the content provided, \a defaultCodec is + returned. + + \sa codecForHtml +*/ +QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec) +{ + const uint arraySize = ba.size(); + + if (arraySize > 3) { + if ((uchar)ba[0] == 0x00 + && (uchar)ba[1] == 0x00 + && (uchar)ba[2] == 0xFE + && (uchar)ba[3] == 0xFF) + return QTextCodec::codecForMib(1018); // utf-32 be + else if ((uchar)ba[0] == 0xFF + && (uchar)ba[1] == 0xFE + && (uchar)ba[2] == 0x00 + && (uchar)ba[3] == 0x00) + return QTextCodec::codecForMib(1019); // utf-32 le + } + + if (arraySize < 2) + return defaultCodec; + if ((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff) + return QTextCodec::codecForMib(1013); // utf16 be + else if ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe) + return QTextCodec::codecForMib(1014); // utf16 le + + if (arraySize < 3) + return defaultCodec; + if ((uchar)ba[0] == 0xef + && (uchar)ba[1] == 0xbb + && (uchar)ba[2] == 0xbf) + return QTextCodec::codecForMib(106); // utf-8 + + return defaultCodec; +} + +/*! + \overload + + If the codec cannot be detected, this overload returns a Latin-1 QTextCodec. +*/ +QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba) +{ + return codecForUtfText(ba, QTextCodec::codecForMib(/*Latin 1*/ 4)); +} + /*! \internal \since 4.3 diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h index e32650f..83097a5 100644 --- a/src/corelib/codecs/qtextcodec.h +++ b/src/corelib/codecs/qtextcodec.h @@ -82,6 +82,9 @@ public: static QTextCodec *codecForHtml(const QByteArray &ba); static QTextCodec *codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec); + static QTextCodec *codecForUtfText(const QByteArray &ba); + static QTextCodec *codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec); + QTextDecoder* makeDecoder() const; QTextEncoder* makeEncoder() const; 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/tests/auto/qtextcodec/tst_qtextcodec.cpp b/tests/auto/qtextcodec/tst_qtextcodec.cpp index cf4135b..22f9557 100644 --- a/tests/auto/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/qtextcodec/tst_qtextcodec.cpp @@ -79,6 +79,9 @@ private slots: void codecForHtml(); + void codecForUtfText_data(); + void codecForUtfText(); + #ifdef Q_OS_UNIX void toLocal8Bit(); #endif @@ -1744,6 +1747,62 @@ void tst_QTextCodec::codecForHtml() QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15 } +void tst_QTextCodec::codecForUtfText_data() +{ + QTest::addColumn("encoded"); + QTest::addColumn("detected"); + QTest::addColumn("mib"); + + + QTest::newRow("utf8 bom") + << QByteArray("\xef\xbb\xbfhello") + << true + << 106; + QTest::newRow("utf8 nobom") + << QByteArray("hello") + << false + << 0; + + QTest::newRow("utf16 bom be") + << QByteArray("\xfe\xff\0h\0e\0l", 8) + << true + << 1013; + QTest::newRow("utf16 bom le") + << QByteArray("\xff\xfeh\0e\0l\0", 8) + << true + << 1014; + QTest::newRow("utf16 nobom") + << QByteArray("\0h\0e\0l", 6) + << false + << 0; + + QTest::newRow("utf32 bom be") + << QByteArray("\0\0\xfe\xff\0\0\0h\0\0\0e\0\0\0l", 16) + << true + << 1018; + QTest::newRow("utf32 bom le") + << QByteArray("\xff\xfe\0\0h\0\0\0e\0\0\0l\0\0\0", 16) + << true + << 1019; + QTest::newRow("utf32 nobom") + << QByteArray("\0\0\0h\0\0\0e\0\0\0l", 12) + << false + << 0; +} + +void tst_QTextCodec::codecForUtfText() +{ + QFETCH(QByteArray, encoded); + QFETCH(bool, detected); + QFETCH(int, mib); + + QTextCodec *codec = QTextCodec::codecForUtfText(encoded, 0); + if (detected) + QCOMPARE(codec->mibEnum(), mib); + else + QVERIFY(codec == 0); +} + #ifdef Q_OS_UNIX void tst_QTextCodec::toLocal8Bit() { -- cgit v0.12 From a7b9c4e332dd03ab17a4d8f520fef95f5daeebe4 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Wed, 29 Apr 2009 10:59:37 +0200 Subject: Use the new QTextCodec::codecForUtfText in qtextstream to detect the utf encoding by BOM. Reviewed-by: Simon Hausmann --- src/corelib/io/qtextstream.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 73408dc..3c015da 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -559,13 +559,8 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes) if (!codec || autoDetectUnicode) { autoDetectUnicode = false; - if (bytesRead >= 4 && ((uchar(buf[0]) == 0xff && uchar(buf[1]) == 0xfe && uchar(buf[2]) == 0 && uchar(buf[3]) == 0) - || (uchar(buf[0]) == 0 && uchar(buf[1]) == 0 && uchar(buf[2]) == 0xfe && uchar(buf[3]) == 0xff))) { - codec = QTextCodec::codecForName("UTF-32"); - } else if (bytesRead >= 2 && ((uchar(buf[0]) == 0xff && uchar(buf[1]) == 0xfe) - || (uchar(buf[0]) == 0xfe && uchar(buf[1]) == 0xff))) { - codec = QTextCodec::codecForName("UTF-16"); - } else if (!codec) { + codec = QTextCodec::codecForUtfText(QByteArray::fromRawData(buf, bytesRead), 0); + if (!codec) { codec = QTextCodec::codecForLocale(); writeConverterState.flags |= QTextCodec::IgnoreHeader; } -- cgit v0.12 From c2d47f6717fdccd44838f3c128693a3c09f6cf68 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 4 May 2009 17:14:25 +0200 Subject: Fixed import of WebKit trunk Don't try to remove scons files that don't exist anymore. Reviewed-by: Trust me --- util/webkit/mkdist-webkit | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/webkit/mkdist-webkit b/util/webkit/mkdist-webkit index 701133e..a7ecbc6 100755 --- a/util/webkit/mkdist-webkit +++ b/util/webkit/mkdist-webkit @@ -142,13 +142,11 @@ files_to_remove="$files_to_remove WebKit/qt/QtLauncher/QtLauncher.pro" files_to_remove="$files_to_remove WebKit/qt/QtLauncher/main.cpp" files_to_remove="$files_to_remove JavaScriptCore/AllInOneFile.cpp" -files_to_remove="$files_to_remove JavaScriptCore/JavaScriptCore.scons" files_to_remove="$files_to_remove JavaScriptCore/JavaScriptCoreSources.bkl" files_to_remove="$files_to_remove JavaScriptCore/SConstruct" files_to_remove="$files_to_remove JavaScriptCore/jscore.bkl" files_to_remove="$files_to_remove WebCore/SConstruct" -files_to_remove="$files_to_remove WebCore/WebCore.scons" files_to_remove="$files_to_remove WebCore/WebCoreSources.bkl" files_to_remove="$files_to_remove WebCore/webcore-base.bkl" files_to_remove="$files_to_remove WebCore/webcore-wx.bkl" -- cgit v0.12