From 8bbe5d242a9534ad29f25f800fcb5b600b3d6750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 27 Jul 2009 09:53:47 +0200 Subject: Mac/Cocoa: Remove separator line for "unified document tabs" Call [NSToolbar setShowsBaselineSeparator] on the (unified) toolbar if the window contains tabs in document mode. Task-number: 252660 Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qt_cocoa_helpers_mac.mm | 11 +++++++++++ src/gui/kernel/qt_cocoa_helpers_mac_p.h | 1 + src/gui/widgets/qtabbar.cpp | 10 +++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 3d4164a..1c4177e 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -1069,6 +1069,17 @@ void qt_mac_updateContentBorderMetricts(void * /*OSWindowRef */window, const ::H #endif } +void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show) +{ +#if QT_MAC_USE_COCOA + QMacCocoaAutoReleasePool pool; + OSWindowRef theWindow = static_cast(window); + NSToolbar *macToolbar = [theWindow toolbar]; + if (macToolbar) + [macToolbar setShowsBaselineSeparator: show]; +#endif +} + QStringList qt_mac_NSArrayToQStringList(void *nsarray) { QStringList result; diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h index 2cc7dee..741edd6 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h +++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h @@ -125,6 +125,7 @@ void macWindowSetHasShadow( void * /*OSWindowRef*/ window, bool hasShadow ); void macWindowFlush(void * /*OSWindowRef*/ window); void macSendToolbarChangeEvent(QWidget *widget); void qt_mac_updateContentBorderMetricts(void * /*OSWindowRef */window, const ::HIContentBorderMetrics &metrics); +void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show); void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm); void qt_mac_update_mouseTracking(QWidget *widget); OSStatus qt_mac_drawCGImage(CGContextRef cg, const CGRect *inbounds, CGImageRef); diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index 690e624..6b027b1 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -87,13 +87,17 @@ void QTabBarPrivate::updateMacBorderMetrics() // TODO: get metrics to preserve the bottom value // TODO: test tab bar position - // push the black line at the bottom of the menu bar down to the client are so we can paint over it + OSWindowRef window = qt_mac_window_for(q); + + // push base line separator down to the client are so we can paint over it (Carbon) metrics.top = (documentMode && q->isVisible()) ? 1 : 0; metrics.bottom = 0; metrics.left = 0; metrics.right = 0; - - qt_mac_updateContentBorderMetricts(qt_mac_window_for(q), metrics); + qt_mac_updateContentBorderMetricts(window, metrics); + + // hide the base line separator if the tabs have docuemnt mode enabled (Cocoa) + qt_mac_showBaseLineSeparator(window, !documentMode); } #endif } -- cgit v0.12 From 2ff32a829ca0c8f2781eac0f90d14a0d70755e10 Mon Sep 17 00:00:00 2001 From: Kavindra Devi Palaraja Date: Mon, 27 Jul 2009 10:03:27 +0200 Subject: Doc - fixed a typo [describles->describes] Task: 258573 Reviewed-By: TrustMe --- src/gui/styles/qstyleoption.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp index 0ff1ccf..7547dda 100644 --- a/src/gui/styles/qstyleoption.cpp +++ b/src/gui/styles/qstyleoption.cpp @@ -657,7 +657,7 @@ QStyleOptionFrameV2 &QStyleOptionFrameV2::operator=(const QStyleOptionFrame &oth /*! \enum QStyleOptionFrameV2::FrameFeature - This enum describles the different types of features a frame can have. + This enum describes the different types of features a frame can have. \value None Indicates a normal frame. \value Flat Indicates a flat frame. @@ -899,7 +899,7 @@ QStyleOptionViewItemV2 &QStyleOptionViewItemV2::operator=(const QStyleOptionView /*! \enum QStyleOptionViewItemV2::ViewItemFeature - This enum describles the different types of features an item can have. + This enum describes the different types of features an item can have. \value None Indicates a normal item. \value WrapText Indicates an item with wrapped text. -- cgit v0.12 From a1ca36db95758e8929bcf2fbe4ecd1b2b5047f20 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 11:10:18 +0200 Subject: Doc: replace links to obsolete APIs --- src/script/qscriptengine.cpp | 2 +- src/script/qscriptvalue.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/script/qscriptengine.cpp b/src/script/qscriptengine.cpp index de78403..911d714 100644 --- a/src/script/qscriptengine.cpp +++ b/src/script/qscriptengine.cpp @@ -935,7 +935,7 @@ QScriptSyntaxCheckResult QScriptEngine::checkSyntax(const QString &program) the file name is accessible through the "fileName" property if it's provided with this function. - \sa canEvaluate(), hasUncaughtException(), isEvaluating(), abortEvaluation() + \sa checkSyntax(), hasUncaughtException(), isEvaluating(), abortEvaluation() */ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &fileName, int lineNumber) { diff --git a/src/script/qscriptvalue.cpp b/src/script/qscriptvalue.cpp index 48e1318..520e76f 100644 --- a/src/script/qscriptvalue.cpp +++ b/src/script/qscriptvalue.cpp @@ -1442,7 +1442,7 @@ bool QScriptValue::isUndefined() const Note that function values, variant values, and QObject values are objects, so this function returns true for such values. - \sa toObject(), QScriptEngine::newObject() + \sa QScriptEngine::toObject(), QScriptEngine::newObject() */ bool QScriptValue::isObject() const { -- cgit v0.12 From 9745d9d485e153d2f22e04770e9caecb9f0eaaca Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 27 Jul 2009 11:18:35 +0200 Subject: QHttpNetworkConnectionPrivate: Removed wrong comment The comment was speaking about upload progress, however the code is about download progress. Reviewed-by: TrustMe --- src/network/access/qhttpnetworkconnection.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 3f0b244..66aeb22 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -571,9 +571,6 @@ bool QHttpNetworkConnectionPrivate::expand(QAbstractSocket *socket, QHttpNetwork // make sure that the reply is valid if (channels[i].reply != reply) return true; - // emit dataReadProgress signal (signal is currently not connected - // to the rest of QNAM) since readProgress of the - // QNonContiguousByteDevice is used emit reply->dataReadProgress(reply->d_func()->totalProgress, 0); // make sure that the reply is valid if (channels[i].reply != reply) @@ -700,9 +697,6 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN // make sure that the reply is valid if (channels[i].reply != reply) return; - // emit dataReadProgress signal (signal is currently not connected - // to the rest of QNAM) since readProgress of the - // QNonContiguousByteDevice is used emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength); // make sure that the reply is valid if (channels[i].reply != reply) -- cgit v0.12 From a5190a05bfe809339e9612c9013f0f8213791768 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 11:26:22 +0200 Subject: Doc: QTextLayout is the class to use in interactive text controls. --- doc/src/i18n.qdoc | 12 ++++++------ src/gui/text/qfontmetrics.cpp | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/doc/src/i18n.qdoc b/doc/src/i18n.qdoc index 5964926..d043f45 100644 --- a/doc/src/i18n.qdoc +++ b/doc/src/i18n.qdoc @@ -144,13 +144,13 @@ aligned, so for these languages use the version of drawText() that takes a QRect since this will align in accordance with the language. - \o When you write your own text input controls, use \l - QFontMetrics::charWidth() to determine the width of a character in a - string. In some languages (e.g. Arabic or languages from the Indian + \o When you write your own text input controls, use QTextLayout. + In some languages (e.g. Arabic or languages from the Indian subcontinent), the width and shape of a glyph changes depending on the - surrounding characters. Writing input controls usually requires a - certain knowledge of the scripts it is going to be used in. Usually - the easiest way is to subclass QLineEdit or QTextEdit. + surrounding characters, which QTextLayout takes into account. + Writing input controls usually requires a certain knowledge of the + scripts it is going to be used in. Usually the easiest way is to + subclass QLineEdit or QTextEdit. \endlist diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index abab91c..f558011 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -557,9 +557,8 @@ int QFontMetrics::width(const QString &text, int len) const \warning This function will produce incorrect results for Arabic characters or non-spacing marks in the middle of a string, as the glyph shaping and positioning of marks that happens when - processing strings cannot be taken into account. Use charWidth() - instead if you aren't looking for the width of isolated - characters. + processing strings cannot be taken into account. When implementing + an interactive text control, use QTextLayout instead. \sa boundingRect(), charWidth() */ @@ -1386,9 +1385,8 @@ qreal QFontMetricsF::width(const QString &text) const \warning This function will produce incorrect results for Arabic characters or non-spacing marks in the middle of a string, as the glyph shaping and positioning of marks that happens when - processing strings cannot be taken into account. Use charWidth() - instead if you aren't looking for the width of isolated - characters. + processing strings cannot be taken into account. When implementing + an interactive text control, use QTextLayout instead. \sa boundingRect() */ -- cgit v0.12 From 1ba51aebe818746c13c58fda8e9c8cf4f73ea1ba Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 11:33:59 +0200 Subject: Doc: QTextLayout is the class to use in interactive text controls. --- src/gui/text/qfontmetrics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index f558011..012c0f6 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -560,7 +560,7 @@ int QFontMetrics::width(const QString &text, int len) const processing strings cannot be taken into account. When implementing an interactive text control, use QTextLayout instead. - \sa boundingRect(), charWidth() + \sa boundingRect() */ int QFontMetrics::width(QChar ch) const { -- cgit v0.12 From 14b772b03e0c1f5bcd5f7c25d0ae35593a9f6427 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 12:18:51 +0200 Subject: Doc: Obsolete QMatrix and QPainter APIs using it. QTransform and respective APIs should be used. Still some changes required - Some references to QMatrix left in documentation - Qt code uses QMatrix APIs (ie translationX) Reviewed-by: Samuel --- doc/src/paintsystem.qdoc | 2 +- src/gui/image/qbitmap.cpp | 3 +- src/gui/painting/qmatrix.cpp | 1 + src/gui/painting/qpainter.cpp | 90 ++++++++++++++++++++++++++----------------- 4 files changed, 58 insertions(+), 38 deletions(-) diff --git a/doc/src/paintsystem.qdoc b/doc/src/paintsystem.qdoc index a75908b..c2434e0 100644 --- a/doc/src/paintsystem.qdoc +++ b/doc/src/paintsystem.qdoc @@ -121,7 +121,7 @@ Normally, QPainter draws in a "natural" coordinate system, but it is able to perform view and world transformations using the - QMatrix class. For more information, see \l {The Coordinate + QTransform class. For more information, see \l {The Coordinate System} documentation which also describes the rendering process, i.e. the relation between the logical representation and the rendered pixels, and the benefits of anti-aliased painting. diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp index 6bca504..78c3396 100644 --- a/src/gui/image/qbitmap.cpp +++ b/src/gui/image/qbitmap.cpp @@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE 0 for black and 1 for white. The QBitmap class provides the transformed() function returning a - transformed copy of the bitmap; use the QMatrix argument to + transformed copy of the bitmap; use the QTransform argument to translate, scale, shear, and rotate the bitmap. In addition, QBitmap provides the static fromData() function which returns a bitmap constructed from the given \c uchar data, and the static @@ -318,6 +318,7 @@ QBitmap QBitmap::transformed(const QTransform &matrix) const /*! \overload + \obsolete This convenience function converts the \a matrix to a QTransform and calls the overloaded function. diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp index bc08235..39f4d95 100644 --- a/src/gui/painting/qmatrix.cpp +++ b/src/gui/painting/qmatrix.cpp @@ -55,6 +55,7 @@ QT_BEGIN_NAMESPACE \class QMatrix \brief The QMatrix class specifies 2D transformations of a coordinate system. + \obsolete \ingroup multimedia diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 4c10a5a..4ebfc50 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -1005,7 +1005,7 @@ void QPainterPrivate::updateState(QPainterState *newState) \o brushOrigin() defines the origin of the tiled brushes, normally the origin of widget's background. - \o viewport(), window(), worldMatrix() make up the painter's coordinate + \o viewport(), window(), worldTransform() make up the painter's coordinate transformation system. For more information, see the \l {Coordinate Transformations} section and the \l {The Coordinate System} documentation. @@ -1212,15 +1212,15 @@ void QPainterPrivate::updateState(QPainterState *newState) \endtable All the tranformation operations operate on the transformation - worldMatrix(). A matrix transforms a point in the plane to another + worldTransform(). A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see - the \l {The Coordinate System} and QMatrix documentation. + the \l {The Coordinate System} and QTransform documentation. - The setWorldMatrix() function can replace or add to the currently - set worldMatrix(). The resetMatrix() function resets any + The setWorldTransform() function can replace or add to the currently + set worldTransform(). The resetTransform() function resets any transformations that were made using translate(), scale(), - shear(), rotate(), setWorldMatrix(), setViewport() and setWindow() - functions. The deviceMatrix() returns the matrix that transforms + shear(), rotate(), setWorldTransform(), setViewport() and setWindow() + functions. The deviceTransform() returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. The latter function is only needed when using platform painting commands on the platform dependent handle, @@ -1229,11 +1229,11 @@ void QPainterPrivate::updateState(QPainterState *newState) When drawing with QPainter, we specify points using logical coordinates which then are converted into the physical coordinates of the paint device. The mapping of the logical coordinates to the - physical coordinates are handled by QPainter's combinedMatrix(), a - combination of viewport() and window() and worldMatrix(). The + physical coordinates are handled by QPainter's combinedTransform(), a + combination of viewport() and window() and worldTransform(). The viewport() represents the physical coordinates specifying an arbitrary rectangle, the window() describes the same rectangle in - logical coordinates, and the worldMatrix() is identical with the + logical coordinates, and the worldTransform() is identical with the transformation matrix. See also \l {The Coordinate System} documentation. @@ -2677,6 +2677,7 @@ void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) /*! \since 4.2 + \obsolete Sets the transformation matrix to \a matrix and enables transformations. @@ -2715,7 +2716,7 @@ void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) and window-viewport conversion, see \l {The Coordinate System} documentation. - \sa worldMatrixEnabled(), QMatrix + \sa setWorldTransform(), QTransform */ void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine) @@ -2725,6 +2726,7 @@ void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine) /*! \since 4.2 + \obsolete Returns the world transformation matrix. @@ -2774,6 +2776,7 @@ const QMatrix &QPainter::matrix() const /*! \since 4.2 + \obsolete Returns the transformation matrix combining the current window/viewport and world transformation. @@ -2781,7 +2784,7 @@ const QMatrix &QPainter::matrix() const It is advisable to use combinedTransform() instead of this function to preserve the properties of perspective transformations. - \sa setWorldMatrix(), setWindow(), setViewport() + \sa setWorldTransform(), setWindow(), setViewport() */ QMatrix QPainter::combinedMatrix() const { @@ -2790,6 +2793,8 @@ QMatrix QPainter::combinedMatrix() const /*! + \obsolete + Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. @@ -2817,6 +2822,8 @@ const QMatrix &QPainter::deviceMatrix() const } /*! + \obsolete + Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldMatrix(), setViewport() and setWindow(). @@ -2841,7 +2848,7 @@ void QPainter::resetMatrix() transformations if \a enable is false. The world transformation matrix is not changed. - \sa worldMatrixEnabled(), worldMatrix(), {QPainter#Coordinate + \sa worldMatrixEnabled(), worldTransform(), {QPainter#Coordinate Transformations}{Coordinate Transformations} */ @@ -2870,7 +2877,7 @@ void QPainter::setWorldMatrixEnabled(bool enable) Returns true if world transformation is enabled; otherwise returns false. - \sa setWorldMatrixEnabled(), worldMatrix(), {The Coordinate System} + \sa setWorldMatrixEnabled(), worldTransform(), {The Coordinate System} */ bool QPainter::worldMatrixEnabled() const @@ -2912,7 +2919,7 @@ bool QPainter::matrixEnabled() const /*! Scales the coordinate system by (\a{sx}, \a{sy}). - \sa setWorldMatrix() {QPainter#Coordinate Transformations}{Coordinate + \sa setWorldTransform() {QPainter#Coordinate Transformations}{Coordinate Transformations} */ @@ -2936,7 +2943,7 @@ void QPainter::scale(qreal sx, qreal sy) /*! Shears the coordinate system by (\a{sh}, \a{sv}). - \sa setWorldMatrix(), {QPainter#Coordinate Transformations}{Coordinate + \sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate Transformations} */ @@ -2962,7 +2969,7 @@ void QPainter::shear(qreal sh, qreal sv) Rotates the coordinate system the given \a angle clockwise. - \sa setWorldMatrix(), {QPainter#Coordinate Transformations}{Coordinate + \sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate Transformations} */ @@ -2987,7 +2994,7 @@ void QPainter::rotate(qreal a) Translates the coordinate system by the given \a offset; i.e. the given \a offset is added to points. - \sa setWorldMatrix(), {QPainter#Coordinate Transformations}{Coordinate + \sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate Transformations} */ void QPainter::translate(const QPointF &offset) @@ -6769,7 +6776,7 @@ QPainter::RenderHints QPainter::renderHints() const Returns true if view transformation is enabled; otherwise returns false. - \sa setViewTransformEnabled(), worldMatrix() + \sa setViewTransformEnabled(), worldTransform() */ bool QPainter::viewTransformEnabled() const @@ -6925,7 +6932,7 @@ QRect QPainter::viewport() const /*! \fn void QPainter::resetXForm() \compat - Use resetMatrix() instead. + Use resetTransform() instead. */ /*! \fn void QPainter::setViewXForm(bool enabled) @@ -6971,14 +6978,16 @@ void QPainter::setViewTransformEnabled(bool enable) #ifdef QT3_SUPPORT /*! - Use the worldMatrix() combined with QMatrix::dx() instead. + \obsolete + + Use the worldTransform() combined with QTransform::dx() instead. \oldcode QPainter painter(this); qreal x = painter.translationX(); \newcode QPainter painter(this); - qreal x = painter.worldMatrix().dx(); + qreal x = painter.worldTransform().dx(); \endcode */ qreal QPainter::translationX() const @@ -6992,14 +7001,16 @@ qreal QPainter::translationX() const } /*! - Use the worldMatrix() combined with QMatrix::dy() instead. + \obsolete + + Use the worldTransform() combined with QTransform::dy() instead. \oldcode QPainter painter(this); qreal y = painter.translationY(); \newcode QPainter painter(this); - qreal y = painter.worldMatrix().dy(); + qreal y = painter.worldTransform().dy(); \endcode */ qreal QPainter::translationY() const @@ -7097,7 +7108,7 @@ QPolygon QPainter::xForm(const QPolygon &a) const QPolygon transformed = painter.xForm(polygon, index, count) \newcode QPainter painter(this); - QPolygon transformed = polygon.mid(index, count) * painter.combinedMatrix(); + QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform(); \endcode */ @@ -7112,15 +7123,16 @@ QPolygon QPainter::xForm(const QPolygon &av, int index, int npoints) const /*! \fn QPoint QPainter::xFormDev(const QPoint &point) const \overload + \obsolete - Use combinedTransform() combined with QMatrix::inverted() instead. + Use combinedTransform() combined with QTransform::inverted() instead. \oldcode QPainter painter(this); QPoint transformed = painter.xFormDev(point); \newcode QPainter painter(this); - QPoint transformed = point * painter.combinedMatrix().inverted(); + QPoint transformed = point * painter.combinedTransform().inverted(); \endcode */ @@ -7139,15 +7151,16 @@ QPoint QPainter::xFormDev(const QPoint &p) const /*! \fn QRect QPainter::xFormDev(const QRect &rectangle) const \overload + \obsolete - Use mapRect() combined with QMatrix::inverted() instead. + Use combinedTransform() combined with QTransform::inverted() instead. \oldcode QPainter painter(this); QRect transformed = painter.xFormDev(rectangle); \newcode QPainter painter(this); - QRect transformed = painter.combinedMatrix().inverted(rectangle); + QRect transformed = painter.combinedTransform().inverted(rectangle); \endcode */ @@ -7167,16 +7180,16 @@ QRect QPainter::xFormDev(const QRect &r) const \overload \fn QPoint QPainter::xFormDev(const QPolygon &polygon) const - \overload + \obsolete - Use combinedMatrix() combined with QMatrix::inverted() instead. + Use combinedTransform() combined with QTransform::inverted() instead. \oldcode QPainter painter(this); QPolygon transformed = painter.xFormDev(rectangle); \newcode QPainter painter(this); - QPolygon transformed = polygon * painter.combinedMatrix().inverted(); + QPolygon transformed = polygon * painter.combinedTransform().inverted(); \endcode */ @@ -7195,15 +7208,16 @@ QPolygon QPainter::xFormDev(const QPolygon &a) const /*! \fn QPolygon QPainter::xFormDev(const QPolygon &polygon, int index, int count) const \overload + \obsolete - Use combinedMatrix() combined with QPolygon::mid() and QMatrix::inverted() instead. + Use combinedTransform() combined with QPolygon::mid() and QTransform::inverted() instead. \oldcode QPainter painter(this); QPolygon transformed = painter.xFormDev(polygon, index, count); \newcode QPainter painter(this); - QPolygon transformed = polygon.mid(index, count) * painter.combinedMatrix().inverted(); + QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform().inverted(); \endcode */ @@ -8107,7 +8121,7 @@ void bitBlt(QPaintDevice *dst, int dx, int dy, \row \o QPaintEngine::DirtyClipRegion \o clipRegion() \row \o QPaintEngine::DirtyCompositionMode \o compositionMode() \row \o QPaintEngine::DirtyFont \o font() - \row \o QPaintEngine::DirtyTransform \o matrix() + \row \o QPaintEngine::DirtyTransform \o transform() \row \o QPaintEngine::DirtyClipEnabled \o isClipEnabled() \row \o QPaintEngine::DirtyPen \o pen() \row \o QPaintEngine::DirtyHints \o renderHints() @@ -8226,10 +8240,14 @@ QFont QPaintEngineState::font() const /*! \since 4.2 + \obsolete Returns the matrix in the current paint engine state. + \note It is advisable to use transform() instead of this function to + preserve the properties of perspective transformations. + This variable should only be used when the state() returns a combination which includes the QPaintEngine::DirtyTransform flag. @@ -8534,7 +8552,7 @@ const QTransform & QPainter::worldTransform() const Returns the transformation matrix combining the current window/viewport and world transformation. - \sa setWorldMatrix(), setWindow(), setViewport() + \sa setWorldTransform(), setWindow(), setViewport() */ QTransform QPainter::combinedTransform() const -- cgit v0.12 From f2135cccffbef6d6accb49f404d9b23ade418641 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 13:28:52 +0200 Subject: "enabled" parameter should default to true, as with QGraphicsView and QPainter. Reviewed-by: Simon Hausmann --- src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp | 2 ++ src/3rdparty/webkit/WebKit/qt/Api/qwebview.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp index 34da644..6c5860c 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp @@ -617,6 +617,8 @@ qreal QWebView::textSizeMultiplier() const These hints are used to initialize QPainter before painting the web page. QPainter::TextAntialiasing is enabled by default. + + \sa QPainter::renderHints() */ QPainter::RenderHints QWebView::renderHints() const { diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.h b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.h index 5c2c7a0..0dab925 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.h +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.h @@ -106,7 +106,7 @@ public: QPainter::RenderHints renderHints() const; void setRenderHints(QPainter::RenderHints hints); - void setRenderHint(QPainter::RenderHint hint, bool enabled); + void setRenderHint(QPainter::RenderHint hint, bool enabled = true); bool findText(const QString &subString, QWebPage::FindFlags options = 0); -- cgit v0.12 From 1edad2af19ee67c3e3504c8226fc3cfef9fd51a1 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 27 Jul 2009 13:23:26 +0200 Subject: Refactor monotonic time code to avoid duplication. Merge the monotonic clock source detection in qeventdispatcher_unix.cpp with that in qcore_unix.cpp. As discussed with Thiago, we're also removing older compat code at the same time (spinning on select() when we think it woke up early). Reviewed-by: Thiago --- src/corelib/kernel/qcore_unix.cpp | 71 ++++++++++++++------ src/corelib/kernel/qcore_unix_p.h | 2 + src/corelib/kernel/qeventdispatcher_unix.cpp | 97 ++-------------------------- src/corelib/kernel/qeventdispatcher_unix_p.h | 4 -- 4 files changed, 60 insertions(+), 114 deletions(-) diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index c5b0fc7..6ef56fd 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -55,37 +55,72 @@ QT_BEGIN_NAMESPACE -static inline timeval gettime() +bool qt_gettime_is_monotonic() { - timeval tv; -#ifndef QT_NO_CLOCK_MONOTONIC - // use the monotonic clock - static volatile bool monotonicClockDisabled = false; - struct timespec ts; - if (!monotonicClockDisabled) { - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) { - monotonicClockDisabled = true; - } else { - tv.tv_sec = ts.tv_sec; - tv.tv_usec = ts.tv_nsec / 1000; - return tv; - } +#if (_POSIX_MONOTONIC_CLOCK-0 > 0) || defined(Q_OS_MAC) + return true; +#else + static int returnValue = 0; + + if (returnValue == 0) { +# if (_POSIX_MONOTONIC_CLOCK-0 < 0) + returnValue = -1; +# elif (_POSIX_MONOTONIC_CLOCK == 0) + // detect if the system support monotonic timers + long x = sysconf(_SC_MONOTONIC_CLOCK); + returnValue = (x >= 200112L) ? 1 : -1; +# endif } + + return returnValue != -1; #endif +} + +timeval qt_gettime() +{ + timeval tv; +#if defined(Q_OS_MAC) + static mach_timebase_info_data_t info = {0,0}; + if (info.denom == 0) + mach_timebase_info(&info); + + uint64_t cpu_time = mach_absolute_time(); + uint64_t nsecs = cpu_time * (info.numer / info.denom); + tv.tv_sec = nsecs * 1e-9; + tv.tv_usec = nsecs * 1e-3 - (t.tv_sec * 1e6); + return tv; +#elif (_POSIX_MONOTONIC_CLOCK-0 > 0) + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + tv.tv_sec = ts.tv_sec; + tv.tv_usec = ts.tv_nsec / 1000; + return tv; +#else +# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) + if (qt_gettime_is_monotonic()) { + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + tv.tv_sec = ts.tv_sec; + tv.tv_usec = ts.tv_nsec / 1000; + return tv; + } +# endif // use gettimeofday ::gettimeofday(&tv, 0); return tv; +#endif } static inline bool time_update(struct timeval *tv, const struct timeval &start, const struct timeval &timeout) { - struct timeval now = gettime(); - if (now < start) { - // clock reset, give up + if (!qt_gettime_is_monotonic()) { + // we cannot recalculate the timeout without a monotonic clock as the time may have changed return false; } + // clock source is monotonic, so we can recalculate how much timeout is left + struct timeval now = qt_gettime(); *tv = timeout + start - now; return true; } @@ -100,7 +135,7 @@ int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, return ret; } - timeval start = gettime(); + timeval start = qt_gettime(); timeval timeout = *orig_timeout; // loop and recalculate the timeout as needed diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index dd97841..bffd670 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -267,6 +267,8 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options) return ret; } +bool qt_gettime_is_monotonic(); +timeval qt_gettime(); Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timeval *tv); diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 2139545..6f1256b 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -67,25 +67,6 @@ QT_BEGIN_NAMESPACE Q_CORE_EXPORT bool qt_disable_lowpriority_timers=false; -// check for _POSIX_MONOTONIC_CLOCK support -static bool supportsMonotonicClock() -{ - bool returnValue; - -#if (_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC) - returnValue = false; -# if (_POSIX_MONOTONIC_CLOCK == 0) - // detect if the system support monotonic timers - long x = sysconf(_SC_MONOTONIC_CLOCK); - returnValue = x >= 200112L; -# endif -#else - returnValue = true; -#endif - - return returnValue; -} - /***************************************************************************** UNIX signal handling *****************************************************************************/ @@ -281,12 +262,11 @@ int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, */ QTimerInfoList::QTimerInfoList() - : useMonotonicTimers(supportsMonotonicClock()) { - getTime(currentTime); + currentTime = qt_gettime(); #if (_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC) - if (!useMonotonicTimers) { + if (!qt_gettime_is_monotonic()) { // not using monotonic timers, initialize the timeChanged() machinery previousTime = currentTime; @@ -309,8 +289,7 @@ QTimerInfoList::QTimerInfoList() timeval QTimerInfoList::updateCurrentTime() { - getTime(currentTime); - return currentTime; + return (currentTime = qt_gettime()); } #if ((_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC)) || defined(QT_BOOTSTRAPPED) @@ -364,38 +343,9 @@ bool QTimerInfoList::timeChanged(timeval *delta) return elapsedTimeTicks < ((qAbs(*delta) - tickGranularity) * 10); } -void QTimerInfoList::getTime(timeval &t) -{ -#if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) - if (useMonotonicTimers) { - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - t.tv_sec = ts.tv_sec; - t.tv_usec = ts.tv_nsec / 1000; - return; - } -#endif - - gettimeofday(&t, 0); - // NTP-related fix - while (t.tv_usec >= 1000000l) { - t.tv_usec -= 1000000l; - ++t.tv_sec; - } - while (t.tv_usec < 0l) { - if (t.tv_sec > 0l) { - t.tv_usec += 1000000l; - --t.tv_sec; - } else { - t.tv_usec = 0l; - break; - } - } -} - void QTimerInfoList::repairTimersIfNeeded() { - if (useMonotonicTimers) + if (qt_gettime_is_monotonic()) return; timeval delta; if (timeChanged(&delta)) @@ -404,25 +354,6 @@ void QTimerInfoList::repairTimersIfNeeded() #else // !(_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(QT_BOOTSTRAPPED) -void QTimerInfoList::getTime(timeval &t) -{ -#if defined(Q_OS_MAC) - static mach_timebase_info_data_t info = {0,0}; - if (info.denom == 0) - mach_timebase_info(&info); - - uint64_t cpu_time = mach_absolute_time(); - uint64_t nsecs = cpu_time * (info.numer / info.denom); - t.tv_sec = nsecs * 1e-9; - t.tv_usec = nsecs * 1e-3 - (t.tv_sec * 1e6); -#else - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - t.tv_sec = ts.tv_sec; - t.tv_usec = ts.tv_nsec / 1000; -#endif -} - void QTimerInfoList::repairTimersIfNeeded() { } @@ -648,25 +579,7 @@ QEventDispatcherUNIX::~QEventDispatcherUNIX() int QEventDispatcherUNIX::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout) { - Q_D(QEventDispatcherUNIX); - if (timeout && d->timerList.useMonotonicTimers) { - // handle the case where select returns with a timeout, too - // soon. - timeval tvStart = d->timerList.currentTime; - timeval tvCurrent = tvStart; - timeval originalTimeout = *timeout; - - int nsel; - do { - timeval tvRest = originalTimeout + tvStart - tvCurrent; - nsel = ::select(nfds, readfds, writefds, exceptfds, &tvRest); - d->timerList.getTime(tvCurrent); - } while (nsel == 0 && (tvCurrent - tvStart) < originalTimeout); - - return nsel; - } - - return ::select(nfds, readfds, writefds, exceptfds, timeout); + return ::qt_safe_select(nfds, readfds, writefds, exceptfds, timeout); } /*! diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h index 28e7f9b..61d94c9 100644 --- a/src/corelib/kernel/qeventdispatcher_unix_p.h +++ b/src/corelib/kernel/qeventdispatcher_unix_p.h @@ -141,10 +141,6 @@ class QTimerInfoList : public QList public: QTimerInfoList(); - const bool useMonotonicTimers; - - void getTime(timeval &t); - timeval currentTime; timeval updateCurrentTime(); -- cgit v0.12 From fb49d313e30fca8c3af58ecc7ed4310c78e99b79 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 27 Jul 2009 13:31:43 +0200 Subject: Avoid floating point code when converting Mach time to timeval Mac OS X only change Reviewed-by: Thiago --- src/corelib/kernel/qcore_unix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index 6ef56fd..d0a4d8f 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -86,8 +86,8 @@ timeval qt_gettime() uint64_t cpu_time = mach_absolute_time(); uint64_t nsecs = cpu_time * (info.numer / info.denom); - tv.tv_sec = nsecs * 1e-9; - tv.tv_usec = nsecs * 1e-3 - (t.tv_sec * 1e6); + tv.tv_sec = nsecs / 1000000000ull; + tv.tv_usec = (nsecs / 1000) - (t.tv_sec * 1000000); return tv; #elif (_POSIX_MONOTONIC_CLOCK-0 > 0) timespec ts; -- cgit v0.12 From 29031b406f0266b0b47ef7e8113ec861a90f201e Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Mon, 27 Jul 2009 13:15:19 +0200 Subject: Fixed SC_ComboBoxArrow returning inverted subControlRect on vista The arrow was reported to be on the wrong side of the control. Technically the arrow part seems to cover the whole rect on Vista and Gtk+ but due to compatibility it is probably safer to keep the old rects for now. Task-number: 252857 Reviewed-by: ogoffart --- src/gui/styles/qwindowsvistastyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/styles/qwindowsvistastyle.cpp b/src/gui/styles/qwindowsvistastyle.cpp index f3d0f04..298207d 100644 --- a/src/gui/styles/qwindowsvistastyle.cpp +++ b/src/gui/styles/qwindowsvistastyle.cpp @@ -2229,7 +2229,7 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt rect = cb->rect; break; case SC_ComboBoxArrow: - rect.setRect(cb->editable ? xpos : 0, y , wi - xpos, he); + rect.setRect(xpos, y , wi - xpos, he); break; case SC_ComboBoxEditField: rect.setRect(x + margin, y + margin, wi - 2 * margin - 16, he - 2 * margin); -- cgit v0.12 From ed00fff3cb3f3f1ec01f5d69168222c3ce8d51b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 27 Jul 2009 14:17:23 +0200 Subject: Make the Character Palette work on Mac/Cocoa. Handle the case when insertText is called with no corresponding keyDown. This fix is for the Cocoa port. Task-number: 147379 --- src/gui/kernel/qcocoaview_mac.mm | 20 ++++++++++++++++---- src/gui/kernel/qcocoaview_mac_p.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 3bc348c..57c9117 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -200,6 +200,7 @@ extern "C" { composingText = new QString(); composing = false; sendKeyEvents = true; + inKeyDown = false; currentCustomTypes = 0; [self setHidden:YES]; return self; @@ -983,6 +984,7 @@ extern "C" { - (void)keyDown:(NSEvent *)theEvent { + inKeyDown = true; sendKeyEvents = true; QWidget *widgetToGetKey = qwidget; @@ -1002,6 +1004,7 @@ extern "C" { if (!keyOK && !sendToPopup) [super keyDown:theEvent]; } + inKeyDown = false; } @@ -1039,14 +1042,23 @@ extern "C" { - (void) insertText:(id)aString { - if ([aString length] && composing) { - // Send the commit string to the widget. - QString commitText; + QString commitText; + if ([aString length]) { if ([aString isKindOfClass:[NSAttributedString class]]) { - commitText = QCFString::toQString(reinterpret_cast([aString string])); + commitText = QCFString::toQString(reinterpret_cast([aString string])); } else { commitText = QCFString::toQString(reinterpret_cast(aString)); }; + } + + if ([aString length] && !inKeyDown) { + // Handle the case where insertText is called from somewhere else than the keyDown + // implementation, for example when inserting text from the character palette. + QInputMethodEvent e; + e.setCommitString(commitText); + qt_sendSpontaneousEvent(qwidget, &e); + } else if ([aString length] && composing) { + // Send the commit string to the widget. composing = false; sendKeyEvents = false; QInputMethodEvent e; diff --git a/src/gui/kernel/qcocoaview_mac_p.h b/src/gui/kernel/qcocoaview_mac_p.h index 4762b17..932c6ca 100644 --- a/src/gui/kernel/qcocoaview_mac_p.h +++ b/src/gui/kernel/qcocoaview_mac_p.h @@ -85,6 +85,7 @@ Q_GUI_EXPORT bool composing; int composingLength; bool sendKeyEvents; + bool inKeyDown; QString *composingText; QStringList *currentCustomTypes; NSInteger dragEnterSequence; -- cgit v0.12 From 521f9b245330665f114238e1a888161c696fed03 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 27 Jul 2009 14:40:51 +0200 Subject: Compile on Mac OS X Need the right include for the mach_*() functions. --- src/corelib/kernel/qcore_unix.cpp | 4 ++++ src/corelib/kernel/qeventdispatcher_unix.cpp | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index d0a4d8f..b321518 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -47,6 +47,10 @@ #include "qeventdispatcher_unix_p.h" // for the timeval operators +#ifdef Q_OS_MAC +#include +#endif + #if !defined(QT_NO_CLOCK_MONOTONIC) # if defined(QT_BOOTSTRAPPED) # define QT_NO_CLOCK_MONOTONIC diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 6f1256b..2943c6d 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -59,10 +59,6 @@ # include #endif -#ifdef Q_OS_MAC -#include -#endif - QT_BEGIN_NAMESPACE Q_CORE_EXPORT bool qt_disable_lowpriority_timers=false; -- cgit v0.12 From 3fd2f0423bf9affe27c8f1cc801f7ded165f173d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 27 Jul 2009 14:46:48 +0200 Subject: Fix qmake dependency generation for include statements with local files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The header file should be looked up relative to the directory of the compilation unit and not qmake's current directory or the like. Simplified the logic slightly to achieve that. Reviewed-by: João Abecasis --- qmake/generators/makefiledeps.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/qmake/generators/makefiledeps.cpp b/qmake/generators/makefiledeps.cpp index 34a5322..d907394 100644 --- a/qmake/generators/makefiledeps.cpp +++ b/qmake/generators/makefiledeps.cpp @@ -378,17 +378,19 @@ bool QMakeSourceFileInfo::findDeps(SourceFile *file) files_changed = true; file->dep_checked = true; + const QMakeLocalFileName sourceFile = fixPathForFile(file->file, true); + struct stat fst; char *buffer = 0; int buffer_len = 0; { int fd; #if defined(_MSC_VER) && _MSC_VER >= 1400 - if (_sopen_s(&fd, fixPathForFile(file->file, true).local().toLatin1().constData(), + if (_sopen_s(&fd, sourceFile.local().toLatin1().constData(), _O_RDONLY, _SH_DENYNO, _S_IREAD) != 0) fd = -1; #else - fd = open(fixPathForFile(file->file, true).local().toLatin1().constData(), O_RDONLY); + fd = open(sourceFile.local().toLatin1().constData(), O_RDONLY); #endif if(fd == -1 || fstat(fd, &fst) || S_ISDIR(fst.st_mode)) return false; @@ -623,12 +625,8 @@ bool QMakeSourceFileInfo::findDeps(SourceFile *file) QMakeLocalFileName lfn(inc); if(QDir::isRelativePath(lfn.real())) { if(try_local) { - QString dir = findFileInfo(file->file).path(); - if(QDir::isRelativePath(dir)) - dir.prepend(qmake_getpwd() + "/"); - if(!dir.endsWith("/")) - dir += "/"; - QMakeLocalFileName f(dir + lfn.local()); + QDir sourceDir = findFileInfo(sourceFile).dir(); + QMakeLocalFileName f(sourceDir.absoluteFilePath(lfn.local())); if(findFileInfo(f).exists()) { lfn = fixPathForFile(f); exists = true; -- cgit v0.12 From f066d03865743d0e854202bec7e9b13523625fa6 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 15:20:01 +0200 Subject: Doc: QPictureIO and QPictureFormatPlugin have been obsolete for a while. --- doc/src/plugins-howto.qdoc | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/src/plugins-howto.qdoc b/doc/src/plugins-howto.qdoc index 4c37f8e..3e5cc93 100644 --- a/doc/src/plugins-howto.qdoc +++ b/doc/src/plugins-howto.qdoc @@ -92,7 +92,6 @@ \row \o QInputContextPlugin \o \c inputmethods \o Case Sensitive \row \o QKbdDriverPlugin \o \c kbddrivers \o Case Insensitive \row \o QMouseDriverPlugin \o \c mousedrivers \o Case Insensitive - \row \o QPictureFormatPlugin \o \c pictureformats \o Case Sensitive \row \o QScreenDriverPlugin \o \c gfxdrivers \o Case Insensitive \row \o QScriptExtensionPlugin \o \c script \o Case Sensitive \row \o QSqlDriverPlugin \o \c sqldrivers \o Case Sensitive -- cgit v0.12 From 38d668cb3026e4e3e253c8b0fbd075c52e251e90 Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Mon, 27 Jul 2009 15:34:35 +0200 Subject: Fix qmake.pro so it can build qmake. qmake now uses a few of the files from the 'codecs' directory so add that directory to the VPATH directory such that building qmake using this .pro file is possible. Reviewed-by: TrustMe --- qmake/qmake.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/qmake/qmake.pro b/qmake/qmake.pro index 38c58fb..5740061 100644 --- a/qmake/qmake.pro +++ b/qmake/qmake.pro @@ -15,6 +15,7 @@ MOC_DIR = . VPATH += $$QT_SOURCE_TREE/src/corelib/global \ $$QT_SOURCE_TREE/src/corelib/tools \ $$QT_SOURCE_TREE/src/corelib/kernel \ + $$QT_SOURCE_TREE/src/corelib/codecs \ $$QT_SOURCE_TREE/src/corelib/plugin \ $$QT_SOURCE_TREE/src/corelib/io \ $$QT_SOURCE_TREE/src/script -- cgit v0.12 From 85a410db4ded672566cb621ab1e13da691d26891 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Mon, 27 Jul 2009 15:53:43 +0200 Subject: Compile on Mac OS X --- src/corelib/kernel/qcore_unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index b321518..28c1d9c 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -91,7 +91,7 @@ timeval qt_gettime() uint64_t cpu_time = mach_absolute_time(); uint64_t nsecs = cpu_time * (info.numer / info.denom); tv.tv_sec = nsecs / 1000000000ull; - tv.tv_usec = (nsecs / 1000) - (t.tv_sec * 1000000); + tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); return tv; #elif (_POSIX_MONOTONIC_CLOCK-0 > 0) timespec ts; -- cgit v0.12 From 0daacc471911bccd9167a35aa83cd4ccd1a313f5 Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Mon, 27 Jul 2009 15:54:15 +0200 Subject: "MAP" is a too common name to use it without #undef'ing it first Reviewed-by: TrustMe --- src/gui/painting/qtransform.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index f0b2351..45939c1 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -52,7 +52,9 @@ QT_BEGIN_NAMESPACE #define Q_NEAR_CLIP 0.000001 - +#ifdef MAP +# undef MAP +#endif #define MAP(x, y, nx, ny) \ do { \ qreal FX_ = x; \ -- cgit v0.12 From 206adbb56bb80eab49b09bdd138e018bfe6be3dc Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 16:03:06 +0200 Subject: Doc: Document format for new Math3D classes as well as QTransform --- doc/src/datastreamformat.qdoc | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/doc/src/datastreamformat.qdoc b/doc/src/datastreamformat.qdoc index dea193f..5db85cb 100644 --- a/doc/src/datastreamformat.qdoc +++ b/doc/src/datastreamformat.qdoc @@ -220,6 +220,25 @@ \o dx (double) \o dy (double) \endlist + \row \o QMatrix4x4 + \o \list + \o m11 (double) + \o m12 (double) + \o m13 (double) + \o m14 (double) + \o m21 (double) + \o m22 (double) + \o m23 (double) + \o m24 (double) + \o m31 (double) + \o m32 (double) + \o m33 (double) + \o m34 (double) + \o m41 (double) + \o m42 (double) + \o m43 (double) + \o m44 (double) + \endlist \row \o QPair \o \list \o first (T1) @@ -266,6 +285,13 @@ \o The x coordinate (qint32) \o The y coordinate (qint32) \endlist + \row \o QQuaternion + \o \list + \o The scalar component (double) + \o The x coordinate (double) + \o The y coordinate (double) + \o The z coordinate (double) + \endlist \row \o QRect \o \list \o left (qint32) @@ -301,6 +327,18 @@ \o \list \o Milliseconds since midnight (quint32) \endlist + \row \o QTransform + \o \list + \o m11 (double) + \o m12 (double) + \o m13 (double) + \o m21 (double) + \o m22 (double) + \o m23 (double) + \o m31 (double) + \o m32 (double) + \o m33 (double) + \endlist \row \o QUrl \o \list \o Holds an URL (QString) @@ -311,6 +349,24 @@ \o The null flag (qint8) \o The data of the specified type \endlist + \row \o QVector2D + \o \list + \o the x coordinate (double) + \o the y coordinate (double) + \endlist + \row \o QVector3D + \o \list + \o the x coordinate (double) + \o the y coordinate (double) + \o the z coordinate (double) + \endlist + \row \o QVector4D + \o \list + \o the x coordinate (double) + \o the y coordinate (double) + \o the z coordinate (double) + \o the w coordinate (double) + \endlist \row \o QVector \o \list \o The number of items (quint32) -- cgit v0.12 From 6c1bc11a0a45f1ea04e271526997ea5002bf5f86 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 16:07:57 +0200 Subject: Doc: Remove reference to QMatrix As pointed out on IRC, setTransform is used most frequently in code and in an ideal world would be the only such function. --- src/gui/painting/qpainter.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 4ebfc50..9c7a7fa 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -8428,11 +8428,7 @@ qreal QPaintEngineState::opacity() const If \a combine is true, the specified \a transform is combined with the current matrix; otherwise it replaces the current matrix. - This function has been added for compatibility with setMatrix(), - but as with setMatrix() the preferred method of setting a - transformation on the painter is through setWorldTransform(). - - \sa transform() + \sa transform() setWorldTransform() */ void QPainter::setTransform(const QTransform &transform, bool combine ) @@ -8442,6 +8438,8 @@ void QPainter::setTransform(const QTransform &transform, bool combine ) /*! Returns the world transformation matrix. + + \sa worldTransform() */ const QTransform & QPainter::transform() const -- cgit v0.12 From e2d4cd1536345fc51b509affba45041f2cf1752f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 24 Jul 2009 13:18:34 +0200 Subject: Fix warning with Sun CC 5.9 and xlC 7: no new types inside anonymous unions. See ba191b0a26b966ad1fb596a905307399922bc44a for a similar commit done to QStringMatcher. Reviewed-By: Bradley T. Hughes --- src/corelib/tools/qbytearraymatcher.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/tools/qbytearraymatcher.h index 697b6ff..4bad24c 100644 --- a/src/corelib/tools/qbytearraymatcher.h +++ b/src/corelib/tools/qbytearraymatcher.h @@ -81,13 +81,14 @@ private: // explicitely allow anonymous unions for RVCT to prevent compiler warnings #pragma anon_unions #endif + struct Data { + uchar q_skiptable[256]; + const uchar *p; + int l; + }; union { uint dummy[256]; - struct { - uchar q_skiptable[256]; - const uchar *p; - int l; - } p; + Data p; }; }; -- cgit v0.12 From f7e837ae1534b519bbe604fbb1eef22c35d37de1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 24 Jul 2009 19:38:19 +0200 Subject: Sun CC 5.9 still doesn't support Template-Template Parameters I had added the version check when we only had CC 5.5 and 5.6, expecting that 5.7 would have the support. And if it didn't, then someone would notice the compile error in QtConcurrent, bumping the version number here. Except that QtConcurrent was never enabled with Sun CC. Which meant that we never got to test TTP support. Reviewed-By: Bradley T. Hughes --- src/corelib/global/qglobal.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 461bd36..3625f2b 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -653,9 +653,7 @@ namespace QT_NAMESPACE {} in which case _BOOL is not defined this is the default in 4.2 compatibility mode triggered by -compat=4 */ # if __SUNPRO_CC >= 0x500 -# if __SUNPRO_CC < 0x570 -# define QT_NO_TEMPLATE_TEMPLATE_PARAMETERS -# endif +# define QT_NO_TEMPLATE_TEMPLATE_PARAMETERS /* see http://developers.sun.com/sunstudio/support/Ccompare.html */ # if __SUNPRO_CC >= 0x590 # define Q_ALIGNOF(type) __alignof__(type) -- cgit v0.12 From f120b5e4b63cbc30874fa21947b75d352f18d7df Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 27 Jul 2009 14:43:35 +0200 Subject: Make the STL test a little more strict, using constructs used by Concurrent. At least the RogueWave STL found in Sun Studio 12 (latest version available) isn't standards-compliant enough for QtConcurrent's needs. Note that WebKit also requires STL support, so this means QtWebKit will not compile with RW STL on Solaris. Reviewed-By: Bradley T. Hughes --- config.tests/unix/stl/stltest.cpp | 61 ++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/config.tests/unix/stl/stltest.cpp b/config.tests/unix/stl/stltest.cpp index ff653a4..4d74ed1 100644 --- a/config.tests/unix/stl/stltest.cpp +++ b/config.tests/unix/stl/stltest.cpp @@ -9,6 +9,53 @@ templates for common STL container classes. #include #include +// something mean to see if the compiler and C++ standard lib are good enough +template +class DummyClass +{ + // everything in std namespace ? + typedef std::bidirectional_iterator_tag i; + typedef std::ptrdiff_t d; + // typename implemented ? + typedef typename std::map::iterator MyIterator; +}; + +// extracted from QVector's strict iterator +template +class DummyIterator +{ + typedef DummyIterator iterator; +public: + T *i; + typedef std::random_access_iterator_tag iterator_category; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T *pointer; + typedef T &reference; + + inline DummyIterator() : i(0) {} + inline DummyIterator(T *n) : i(n) {} + inline DummyIterator(const DummyIterator &o): i(o.i){} + inline T &operator*() const { return *i; } + inline T *operator->() const { return i; } + inline T &operator[](int j) const { return *(i + j); } + inline bool operator==(const DummyIterator &o) const { return i == o.i; } + inline bool operator!=(const DummyIterator &o) const { return i != o.i; } + inline bool operator<(const DummyIterator& other) const { return i < other.i; } + inline bool operator<=(const DummyIterator& other) const { return i <= other.i; } + inline bool operator>(const DummyIterator& other) const { return i > other.i; } + inline bool operator>=(const DummyIterator& other) const { return i >= other.i; } + inline DummyIterator &operator++() { ++i; return *this; } + inline DummyIterator operator++(int) { T *n = i; ++i; return n; } + inline DummyIterator &operator--() { i--; return *this; } + inline DummyIterator operator--(int) { T *n = i; i--; return n; } + inline DummyIterator &operator+=(int j) { i+=j; return *this; } + inline DummyIterator &operator-=(int j) { i-=j; return *this; } + inline DummyIterator operator+(int j) const { return DummyIterator(i+j); } + inline DummyIterator operator-(int j) const { return DummyIterator(i-j); } + inline int operator-(DummyIterator j) const { return i - j.i; } +}; + int main() { std::vector v1; @@ -53,16 +100,10 @@ int main() int m2size = m2.size(); m2size = 0; + DummyIterator it1, it2; + int n = std::distance(it1, it2); + std::advance(it1, 3); + return 0; } -// something mean to see if the compiler and C++ standard lib are good enough -template -class DummyClass -{ - // everything in std namespace ? - typedef std::bidirectional_iterator_tag i; - typedef std::ptrdiff_t d; - // typename implemented ? - typedef typename std::map::iterator MyIterator; -}; -- cgit v0.12 From b2261de3937e7574b4d17b055f685878c33ec319 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 24 Jul 2009 20:46:37 +0200 Subject: Work around a Sun CC 5.9 compiler bug: the threadEngine variable isn't found. QtConcurrent had the following code: template class ThreadEngineStarterBase { ... protected: ThreadEngine *threadEngine; }; template class ThreadEngineStarter : public ThreadEngineStarterBase { public: ThreadEngineStarter(ThreadEngine *threadEngine) :ThreadEngineStarterBase(threadEngine) {} [...] }; The Sun CC compiler simply didn't parse the parameter declaration in the constructor. Instead of complaining, it silently ignored the problem. Which meant that the constructor simply used the uninitialised member variable from the base class to call the parent constructor, which ended up initialised with itself. You'd think that it's just because the parameter has the same name as a member variable. But it appears to be a compiler bug altogether. If you change the name, then you start getting compile errors. This change is a workaround that worked. Reviewed-By: Bradley T. Hughes --- src/corelib/concurrent/qtconcurrentthreadengine.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/concurrent/qtconcurrentthreadengine.h b/src/corelib/concurrent/qtconcurrentthreadengine.h index 1f359fc..2f610de 100644 --- a/src/corelib/concurrent/qtconcurrentthreadengine.h +++ b/src/corelib/concurrent/qtconcurrentthreadengine.h @@ -238,9 +238,11 @@ protected: template class ThreadEngineStarter : public ThreadEngineStarterBase { + typedef ThreadEngineStarterBase Base; + typedef ThreadEngine TypedThreadEngine; public: - ThreadEngineStarter(ThreadEngine *threadEngine) - :ThreadEngineStarterBase(threadEngine) {} + ThreadEngineStarter(TypedThreadEngine *eng) + : Base(eng) { } T startBlocking() { -- cgit v0.12 From 1a81f8d676d7481e58f44dbb380acffe0800d93d Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 16:48:13 +0200 Subject: Make typeToName testcase pass, and add basic test for Math3D classes. Reviewed-by: Trustme --- tests/auto/qvariant/tst_qvariant.cpp | 86 +++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 63e47ab..a9b9afd 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -59,9 +59,14 @@ #include #include #include -#include +#include #include #include +#include +#include +#include +#include +#include #include @@ -194,6 +199,12 @@ private slots: void transform(); + void matrix4x4(); + void vector2D(); + void vector3D(); + void vector4D(); + void quaternion(); + void url(); void userType(); @@ -1403,6 +1414,19 @@ void tst_QVariant::matrix() QMetaType::destroy(QVariant::Matrix, mmatrix); } +void tst_QVariant::matrix4x4() +{ + QVariant variant; + QMatrix4x4 matrix = qVariantValue(variant); + QVERIFY(matrix.isIdentity()); + qVariantSetValue(variant, QMatrix4x4().scale(2.0)); + QCOMPARE(QMatrix4x4().scale(2.0), qVariantValue(variant)); + + void *mmatrix = QMetaType::construct(QVariant::Matrix4x4, 0); + QVERIFY(mmatrix); + QMetaType::destroy(QVariant::Matrix4x4, mmatrix); +} + void tst_QVariant::transform() { QVariant variant; @@ -1416,6 +1440,59 @@ void tst_QVariant::transform() QMetaType::destroy(QVariant::Transform, mmatrix); } + +void tst_QVariant::vector2D() +{ + QVariant variant; + QVector2D vector = qVariantValue(variant); + QVERIFY(vector.isNull()); + qVariantSetValue(variant, QVector2D(0.1, 0.2)); + QCOMPARE(QVector2D(0.1, 0.2), qVariantValue(variant)); + + void *pvector = QMetaType::construct(QVariant::Vector2D, 0); + QVERIFY(pvector); + QMetaType::destroy(QVariant::Vector2D, pvector); +} + +void tst_QVariant::vector3D() +{ + QVariant variant; + QVector3D vector = qVariantValue(variant); + QVERIFY(vector.isNull()); + qVariantSetValue(variant, QVector3D(0.1, 0.2, 0.3)); + QCOMPARE(QVector3D(0.1, 0.2, 0.3), qVariantValue(variant)); + + void *pvector = QMetaType::construct(QVariant::Vector3D, 0); + QVERIFY(pvector); + QMetaType::destroy(QVariant::Vector3D, pvector); +} + +void tst_QVariant::vector4D() +{ + QVariant variant; + QVector4D vector = qVariantValue(variant); + QVERIFY(vector.isNull()); + qVariantSetValue(variant, QVector4D(0.1, 0.2, 0.3, 0.4)); + QCOMPARE(QVector4D(0.1, 0.2, 0.3, 0.4), qVariantValue(variant)); + + void *pvector = QMetaType::construct(QVariant::Vector4D, 0); + QVERIFY(pvector); + QMetaType::destroy(QVariant::Vector4D, pvector); +} + +void tst_QVariant::quaternion() +{ + QVariant variant; + QQuaternion quaternion = qVariantValue(variant); + QVERIFY(quaternion.isIdentity()); + qVariantSetValue(variant, QQuaternion(0.1, 0.2, 0.3, 0.4)); + QCOMPARE(QQuaternion(0.1, 0.2, 0.3, 0.4), qVariantValue(variant)); + + void *pquaternion = QMetaType::construct(QVariant::Quaternion, 0); + QVERIFY(pquaternion); + QMetaType::destroy(QVariant::Quaternion, pquaternion); +} + void tst_QVariant::writeToReadFromDataStream_data() { @@ -1955,6 +2032,11 @@ void tst_QVariant::typeName_data() QTest::newRow("45") << int(QVariant::Matrix) << QByteArray("QMatrix"); QTest::newRow("46") << int(QVariant::Transform) << QByteArray("QTransform"); QTest::newRow("47") << int(QVariant::Hash) << QByteArray("QVariantHash"); + QTest::newRow("48") << int(QVariant::Matrix4x4) << QByteArray("QMatrix4x4"); + QTest::newRow("49") << int(QVariant::Vector2D) << QByteArray("QVector2D"); + QTest::newRow("50") << int(QVariant::Vector3D) << QByteArray("QVector3D"); + QTest::newRow("51") << int(QVariant::Vector4D) << QByteArray("QVector4D"); + QTest::newRow("52") << int(QVariant::Quaternion) << QByteArray("QQuaternion"); } void tst_QVariant::typeName() @@ -1972,7 +2054,7 @@ void tst_QVariant::typeToName() QCOMPARE( QVariant::typeToName( v.type() ), (const char*)0 ); // Invalid // assumes that QVariant::Type contains consecutive values - int max = QVariant::Transform; + int max = QVariant::Quaternion; for ( int t = 1; t <= max; t++ ) { const char *n = QVariant::typeToName( (QVariant::Type)t ); if (n) -- cgit v0.12 From 4d4d2714aa9e4ee9bec005531b24442d0a1a8665 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Mon, 27 Jul 2009 17:02:42 +0200 Subject: Don't animate widgets on first show in Vista Checkboxes would animate when first shown if they were checked. This is unintentional and looks a bit odd in wizard for instance. To fix this we simply check if the old state was set. Note that this is safe because we will at least require the enabled state flag to be set. Task-number:253075 Reviewed-by: ogoffart --- src/gui/styles/qwindowsvistastyle.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/styles/qwindowsvistastyle.cpp b/src/gui/styles/qwindowsvistastyle.cpp index 298207d..6f3017a 100644 --- a/src/gui/styles/qwindowsvistastyle.cpp +++ b/src/gui/styles/qwindowsvistastyle.cpp @@ -364,7 +364,8 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt w->setProperty("_q_stylestate", (int)option->state); w->setProperty("_q_stylerect", w->rect()); - bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) || + bool doTransition = oldState && + ((state & State_Sunken) != (oldState & State_Sunken) || (state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver)); -- cgit v0.12 From e5ef272382b124cf5d051ed7f25324fc804d97f6 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 27 Jul 2009 17:20:30 +0200 Subject: Fix build on Solaris Solaris seems to define glXReleaseTexImageEXT rather than let it be resolved as a function pointer. --- src/opengl/qgl_x11.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index a95b7a0..a76059c 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -1536,11 +1536,14 @@ void QGLExtensions::init() } } - +#if !defined(glXBindTexImageEXT) typedef void (*qt_glXBindTexImageEXT)(Display*, GLXDrawable, int, const int*); -typedef void (*qt_glXReleaseTexImageEXT)(Display*, GLXDrawable, int); static qt_glXBindTexImageEXT glXBindTexImageEXT = 0; +#endif +#if !defined(glXReleaseTexImageEXT) +typedef void (*qt_glXReleaseTexImageEXT)(Display*, GLXDrawable, int); static qt_glXReleaseTexImageEXT glXReleaseTexImageEXT = 0; +#endif static bool qt_resolved_texture_from_pixmap = false; QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmap *pm, const qint64 key, bool canInvert) -- cgit v0.12 From 2ab5c57b593cb6874c035cb3abee574464ea8f30 Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 27 Jul 2009 17:41:41 +0200 Subject: Assistant: Removed redundancy in index reader classes. Moved common parts of QHelpSearchIndexReader{Default,Clucene} into a new common base class QHelpSearchIndexReader. Reviewed-by: kh --- tools/assistant/lib/lib.pro | 96 +++++++++--------- tools/assistant/lib/qhelpsearchengine.cpp | 14 ++- tools/assistant/lib/qhelpsearchindexreader.cpp | 106 ++++++++++++++++++++ .../lib/qhelpsearchindexreader_clucene.cpp | 60 ++---------- .../lib/qhelpsearchindexreader_clucene_p.h | 36 +------ .../lib/qhelpsearchindexreader_default.cpp | 49 +--------- .../lib/qhelpsearchindexreader_default_p.h | 37 +------ tools/assistant/lib/qhelpsearchindexreader_p.h | 108 +++++++++++++++++++++ 8 files changed, 296 insertions(+), 210 deletions(-) create mode 100644 tools/assistant/lib/qhelpsearchindexreader.cpp create mode 100644 tools/assistant/lib/qhelpsearchindexreader_p.h diff --git a/tools/assistant/lib/lib.pro b/tools/assistant/lib/lib.pro index bd9ed53..5d6d436 100644 --- a/tools/assistant/lib/lib.pro +++ b/tools/assistant/lib/lib.pro @@ -1,65 +1,71 @@ -QT += sql xml network +QT += sql \ + xml \ + network TEMPLATE = lib TARGET = QtHelp -DEFINES += QHELP_LIB QT_CLUCENE_SUPPORT -CONFIG += qt warn_on - +DEFINES += QHELP_LIB \ + QT_CLUCENE_SUPPORT +CONFIG += qt \ + warn_on include(../../../src/qbase.pri) - QMAKE_TARGET_PRODUCT = Help -QMAKE_TARGET_DESCRIPTION = Help application framework. +QMAKE_TARGET_DESCRIPTION = Help \ + application \ + framework. DEFINES -= QT_ASCII_CAST_WARNINGS - qclucene = QtCLucene$${QT_LIBINFIX} -if(!debug_and_release|build_pass):CONFIG(debug, debug|release) { +if(!debug_and_release|build_pass):CONFIG(debug, debug|release) { mac:qclucene = $${qclucene}_debug win32:qclucene = $${qclucene}d } linux-lsb-g++:LIBS += --lsb-shared-libs=$$qclucene -unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork QtSql QtXml +unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork \ + QtSql \ + QtXml LIBS += -l$$qclucene -unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork QtSql QtXml - +unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork \ + QtSql \ + QtXml RESOURCES += helpsystem.qrc - SOURCES += qhelpenginecore.cpp \ - qhelpengine.cpp \ - qhelpdbreader.cpp \ - qhelpcontentwidget.cpp \ - qhelpindexwidget.cpp \ - qhelpgenerator.cpp \ - qhelpdatainterface.cpp \ - qhelpprojectdata.cpp \ - qhelpcollectionhandler.cpp \ - qhelpsearchengine.cpp \ - qhelpsearchquerywidget.cpp \ - qhelpsearchresultwidget.cpp \ - qhelpsearchindex_default.cpp \ - qhelpsearchindexwriter_default.cpp \ - qhelpsearchindexreader_default.cpp + qhelpengine.cpp \ + qhelpdbreader.cpp \ + qhelpcontentwidget.cpp \ + qhelpindexwidget.cpp \ + qhelpgenerator.cpp \ + qhelpdatainterface.cpp \ + qhelpprojectdata.cpp \ + qhelpcollectionhandler.cpp \ + qhelpsearchengine.cpp \ + qhelpsearchquerywidget.cpp \ + qhelpsearchresultwidget.cpp \ + qhelpsearchindex_default.cpp \ + qhelpsearchindexwriter_default.cpp \ + qhelpsearchindexreader_default.cpp \ + qhelpsearchindexreader.cpp # access to clucene SOURCES += qhelpsearchindexwriter_clucene.cpp \ - qhelpsearchindexreader_clucene.cpp - + qhelpsearchindexreader_clucene.cpp HEADERS += qhelpenginecore.h \ - qhelpengine.h \ - qhelpengine_p.h \ - qhelp_global.h \ - qhelpdbreader_p.h \ - qhelpcontentwidget.h \ - qhelpindexwidget.h \ - qhelpgenerator_p.h \ - qhelpdatainterface_p.h \ - qhelpprojectdata_p.h \ - qhelpcollectionhandler_p.h \ - qhelpsearchengine.h \ - qhelpsearchquerywidget.h \ - qhelpsearchresultwidget.h \ - qhelpsearchindex_default_p.h \ - qhelpsearchindexwriter_default_p.h \ - qhelpsearchindexreader_default_p.h + qhelpengine.h \ + qhelpengine_p.h \ + qhelp_global.h \ + qhelpdbreader_p.h \ + qhelpcontentwidget.h \ + qhelpindexwidget.h \ + qhelpgenerator_p.h \ + qhelpdatainterface_p.h \ + qhelpprojectdata_p.h \ + qhelpcollectionhandler_p.h \ + qhelpsearchengine.h \ + qhelpsearchquerywidget.h \ + qhelpsearchresultwidget.h \ + qhelpsearchindex_default_p.h \ + qhelpsearchindexwriter_default_p.h \ + qhelpsearchindexreader_default_p.h \ + qhelpsearchindexreader_p.h # access to clucene HEADERS += qhelpsearchindexwriter_clucene_p.h \ - qhelpsearchindexreader_clucene_p.h + qhelpsearchindexreader_clucene_p.h diff --git a/tools/assistant/lib/qhelpsearchengine.cpp b/tools/assistant/lib/qhelpsearchengine.cpp index 2a41d04..94c5f7e 100644 --- a/tools/assistant/lib/qhelpsearchengine.cpp +++ b/tools/assistant/lib/qhelpsearchengine.cpp @@ -44,6 +44,7 @@ #include "qhelpsearchquerywidget.h" #include "qhelpsearchresultwidget.h" +#include "qhelpsearchindexreader_p.h" #if defined(QT_CLUCENE_SUPPORT) # include "qhelpsearchindexreader_clucene_p.h" # include "qhelpsearchindexwriter_clucene_p.h" @@ -147,8 +148,11 @@ private: return; if (!indexReader) { - indexReader = new QHelpSearchIndexReader(); - +#if defined(QT_CLUCENE_SUPPORT) + indexReader = new QHelpSearchIndexReaderClucene(); +#else + indexReader = new QHelpSearchIndexReaderDefault(); +#endif // QT_CLUCENE_SUPPORT connect(indexReader, SIGNAL(searchingStarted()), this, SIGNAL(searchingStarted())); connect(indexReader, SIGNAL(searchingFinished(int)), this, SIGNAL(searchingFinished(int))); } @@ -181,7 +185,7 @@ private slots: { #if defined(QT_CLUCENE_SUPPORT) if (indexWriter && !helpEngine.isNull()) { - indexWriter->optimizeIndex(); + indexWriter->optimizeIndex(); } #endif } @@ -192,7 +196,7 @@ private: QHelpSearchQueryWidget *queryWidget; QHelpSearchResultWidget *resultWidget; - QHelpSearchIndexReader *indexReader; + qt::fulltextsearch::QHelpSearchIndexReader *indexReader; QHelpSearchIndexWriter *indexWriter; QPointer helpEngine; @@ -321,7 +325,7 @@ QHelpSearchEngine::QHelpSearchEngine(QHelpEngineCore *helpEngine, QObject *paren : QObject(parent) { d = new QHelpSearchEnginePrivate(helpEngine); - + connect(helpEngine, SIGNAL(setupFinished()), this, SLOT(indexDocumentation())); connect(d, SIGNAL(indexingStarted()), this, SIGNAL(indexingStarted())); diff --git a/tools/assistant/lib/qhelpsearchindexreader.cpp b/tools/assistant/lib/qhelpsearchindexreader.cpp new file mode 100644 index 0000000..a0fcbe5 --- /dev/null +++ b/tools/assistant/lib/qhelpsearchindexreader.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Assistant 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 http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qhelpsearchindexreader_p.h" + +QT_BEGIN_NAMESPACE + +namespace qt { + namespace fulltextsearch { + +QHelpSearchIndexReader::QHelpSearchIndexReader() + : QThread() + , m_cancel(false) +{ + // nothing todo +} + +QHelpSearchIndexReader::~QHelpSearchIndexReader() +{ + mutex.lock(); + this->m_cancel = true; + mutex.unlock(); + + wait(); +} + +void QHelpSearchIndexReader::cancelSearching() +{ + mutex.lock(); + this->m_cancel = true; + mutex.unlock(); +} + +void QHelpSearchIndexReader::search(const QString &collectionFile, const QString &indexFilesFolder, + const QList &queryList) +{ + wait(); + + this->hitList.clear(); + this->m_cancel = false; + this->m_query = queryList; + this->m_collectionFile = collectionFile; + this->m_indexFilesFolder = indexFilesFolder; + + start(QThread::NormalPriority); +} + +int QHelpSearchIndexReader::hitsCount() const +{ + QMutexLocker lock(&mutex); + return hitList.count(); +} + +QList QHelpSearchIndexReader::hits(int start, + int end) const +{ + QList hits; + QMutexLocker lock(&mutex); + for (int i = start; i < end && i < hitList.count(); ++i) + hits.append(hitList.at(i)); + return hits; +} + + + } // namespace fulltextsearch +} // namespace qt + +QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp index 89d6040..b417078 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp @@ -59,60 +59,18 @@ namespace qt { namespace fulltextsearch { namespace clucene { -QHelpSearchIndexReader::QHelpSearchIndexReader() - : QThread() - , m_cancel(false) +QHelpSearchIndexReaderClucene::QHelpSearchIndexReaderClucene() + : QHelpSearchIndexReader() { // nothing todo } -QHelpSearchIndexReader::~QHelpSearchIndexReader() +QHelpSearchIndexReaderClucene::~QHelpSearchIndexReaderClucene() { - mutex.lock(); - this->m_cancel = true; - mutex.unlock(); - - wait(); } -void QHelpSearchIndexReader::cancelSearching() -{ - mutex.lock(); - this->m_cancel = true; - mutex.unlock(); -} -void QHelpSearchIndexReader::search(const QString &collectionFile, const QString &indexFilesFolder, - const QList &queryList) -{ - wait(); - - this->hitList.clear(); - this->m_cancel = false; - this->m_query = queryList; - this->m_collectionFile = collectionFile; - this->m_indexFilesFolder = indexFilesFolder; - - start(QThread::NormalPriority); -} - -int QHelpSearchIndexReader::hitsCount() const -{ - QMutexLocker lock(&mutex); - return hitList.count(); -} - -QList QHelpSearchIndexReader::hits(int start, - int end) const -{ - QList hits; - QMutexLocker lock(&mutex); - for (int i = start; i < end && i < hitList.count(); ++i) - hits.append(hitList.at(i)); - return hits; -} - -void QHelpSearchIndexReader::run() +void QHelpSearchIndexReaderClucene::run() { mutex.lock(); @@ -140,7 +98,7 @@ void QHelpSearchIndexReader::run() if(QCLuceneIndexReader::indexExists(indexPath)) { mutex.lock(); if (m_cancel) { - mutex.unlock(); + mutex.unlock(); return; } mutex.unlock(); @@ -227,7 +185,7 @@ void QHelpSearchIndexReader::run() } } -bool QHelpSearchIndexReader::defaultQuery(const QString &term, QCLuceneBooleanQuery &booleanQuery, +bool QHelpSearchIndexReaderClucene::defaultQuery(const QString &term, QCLuceneBooleanQuery &booleanQuery, QCLuceneStandardAnalyzer &analyzer) { const QLatin1String c("content"); @@ -244,7 +202,7 @@ bool QHelpSearchIndexReader::defaultQuery(const QString &term, QCLuceneBooleanQu return false; } -bool QHelpSearchIndexReader::buildQuery(QCLuceneBooleanQuery &booleanQuery, +bool QHelpSearchIndexReaderClucene::buildQuery(QCLuceneBooleanQuery &booleanQuery, const QList &queryList, QCLuceneStandardAnalyzer &analyzer) { foreach (const QHelpSearchQuery query, queryList) { @@ -344,7 +302,7 @@ bool QHelpSearchIndexReader::buildQuery(QCLuceneBooleanQuery &booleanQuery, return true; } -bool QHelpSearchIndexReader::buildTryHarderQuery(QCLuceneBooleanQuery &booleanQuery, +bool QHelpSearchIndexReaderClucene::buildTryHarderQuery(QCLuceneBooleanQuery &booleanQuery, const QList &queryList, QCLuceneStandardAnalyzer &analyzer) { bool retVal = false; @@ -367,7 +325,7 @@ bool QHelpSearchIndexReader::buildTryHarderQuery(QCLuceneBooleanQuery &booleanQu return retVal; } -void QHelpSearchIndexReader::boostSearchHits(const QHelpEngineCore &engine, +void QHelpSearchIndexReaderClucene::boostSearchHits(const QHelpEngineCore &engine, QList &hitList, const QList &queryList) { foreach (const QHelpSearchQuery query, queryList) { diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h index 8876d80..93ac6a8 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h @@ -53,44 +53,24 @@ // We mean it. // -#include "qhelpsearchengine.h" +#include "qhelpsearchindexreader_p.h" #include "fulltextsearch/qanalyzer_p.h" #include "fulltextsearch/qquery_p.h" -#include -#include -#include -#include -#include -#include - -class QHelpEngineCore; - QT_BEGIN_NAMESPACE namespace qt { namespace fulltextsearch { namespace clucene { -class QHelpSearchIndexReader : public QThread +class QHelpSearchIndexReaderClucene : public QHelpSearchIndexReader { Q_OBJECT public: - QHelpSearchIndexReader(); - ~QHelpSearchIndexReader(); - - void cancelSearching(); - void search(const QString &collectionFile, - const QString &indexFilesFolder, - const QList &queryList); - int hitsCount() const; - QList hits(int start, int end) const; - -signals: - void searchingStarted(); - void searchingFinished(int hits); + QHelpSearchIndexReaderClucene(); + ~QHelpSearchIndexReaderClucene(); private: void run(); @@ -102,14 +82,6 @@ private: const QList &queryList, QCLuceneStandardAnalyzer &analyzer); void boostSearchHits(const QHelpEngineCore &engine, QList &hitList, const QList &queryList); - -private: - mutable QMutex mutex; - QList hitList; - bool m_cancel; - QString m_collectionFile; - QList m_query; - QString m_indexFilesFolder; }; } // namespace clucene diff --git a/tools/assistant/lib/qhelpsearchindexreader_default.cpp b/tools/assistant/lib/qhelpsearchindexreader_default.cpp index 91af925..fbf8a09 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_default.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader_default.cpp @@ -492,56 +492,17 @@ void Reader::cleanupIndex(EntryTable &entryTable) } -QHelpSearchIndexReader::QHelpSearchIndexReader() - : QThread() - , m_cancel(false) +QHelpSearchIndexReaderDefault::QHelpSearchIndexReaderDefault() + : QHelpSearchIndexReader() { // nothing todo } -QHelpSearchIndexReader::~QHelpSearchIndexReader() +QHelpSearchIndexReaderDefault::~QHelpSearchIndexReaderDefault() { - mutex.lock(); - this->m_cancel = true; - waitCondition.wakeOne(); - mutex.unlock(); - - wait(); -} - -void QHelpSearchIndexReader::cancelSearching() -{ - mutex.lock(); - this->m_cancel = true; - mutex.unlock(); -} - -void QHelpSearchIndexReader::search(const QString &collectionFile, - const QString &indexFilesFolder, - const QList &queryList) -{ - QMutexLocker lock(&mutex); - - this->hitList.clear(); - this->m_cancel = false; - this->m_query = queryList; - this->m_collectionFile = collectionFile; - this->m_indexFilesFolder = indexFilesFolder; - - start(QThread::NormalPriority); -} - -int QHelpSearchIndexReader::hitsCount() const -{ - return hitList.count(); } -QHelpSearchEngine::SearchHit QHelpSearchIndexReader::hit(int index) const -{ - return hitList.at(index); -} - -void QHelpSearchIndexReader::run() +void QHelpSearchIndexReaderDefault::run() { mutex.lock(); @@ -571,7 +532,7 @@ void QHelpSearchIndexReader::run() QHelpEngineCore engine(collectionFile, 0); if (!engine.setupData()) return; - + const QStringList registeredDocs = engine.registeredDocumentations(); const QStringList indexedNamespaces = engine.customValue(key).toString(). split(QLatin1String("|"), QString::SkipEmptyParts); diff --git a/tools/assistant/lib/qhelpsearchindexreader_default_p.h b/tools/assistant/lib/qhelpsearchindexreader_default_p.h index f0e59b4..d21fc08 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_default_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_default_p.h @@ -54,19 +54,10 @@ // #include "qhelpsearchindex_default_p.h" -#include "qhelpsearchengine.h" +#include "qhelpsearchindexreader_p.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include QT_BEGIN_NAMESPACE @@ -121,39 +112,19 @@ private: }; -class QHelpSearchIndexReader : public QThread +class QHelpSearchIndexReaderDefault : public QHelpSearchIndexReader { Q_OBJECT public: - QHelpSearchIndexReader(); - ~QHelpSearchIndexReader(); - - void cancelSearching(); - void search(const QString &collectionFile, - const QString &indexFilesFolder, - const QList &queryList); - - int hitsCount() const; - QHelpSearchEngine::SearchHit hit(int index) const; - -signals: - void searchingStarted(); - void searchingFinished(int hits); + QHelpSearchIndexReaderDefault(); + ~QHelpSearchIndexReaderDefault(); private: void run(); private: - QMutex mutex; Reader m_reader; - QWaitCondition waitCondition; - QList hitList; - - bool m_cancel; - QList m_query; - QString m_collectionFile; - QString m_indexFilesFolder; }; } // namespace std diff --git a/tools/assistant/lib/qhelpsearchindexreader_p.h b/tools/assistant/lib/qhelpsearchindexreader_p.h new file mode 100644 index 0000000..c8f2b44 --- /dev/null +++ b/tools/assistant/lib/qhelpsearchindexreader_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Assistant 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 http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QHELPSEARCHINDEXREADER_H +#define QHELPSEARCHINDEXREADER_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the help generator tools. This header file may change from version +// to version without notice, or even be removed. +// +// We mean it. +// + +#include "qhelpsearchengine.h" + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QHelpEngineCore; + +namespace qt { + namespace fulltextsearch { + +class QHelpSearchIndexReader : public QThread +{ + Q_OBJECT + +public: + QHelpSearchIndexReader(); + ~QHelpSearchIndexReader(); + + void cancelSearching(); + void search(const QString &collectionFile, + const QString &indexFilesFolder, + const QList &queryList); + int hitsCount() const; + QList hits(int start, int end) const; + +signals: + void searchingStarted(); + void searchingFinished(int hits); + +protected: + mutable QMutex mutex; + QList hitList; + bool m_cancel; + QString m_collectionFile; + QList m_query; + QString m_indexFilesFolder; + +private: + virtual void run()=0; +}; + + } // namespace fulltextsearch +} // namespace qt + +QT_END_NAMESPACE + +#endif // QHELPSEARCHINDEXREADER_H -- cgit v0.12 From a65a659eee21f451f0bad833c8498cf74158fd18 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 27 Jul 2009 21:20:21 +0200 Subject: Doc: Focus and key-event handling in QGraphicsItem. --- src/gui/graphicsview/qgraphicsitem.cpp | 45 +++++++++++++++++++--------------- src/gui/kernel/qevent.cpp | 20 +++++++++------ 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 2425354..c8e55e3 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2465,10 +2465,10 @@ void QGraphicsItem::setHandlesChildEvents(bool enabled) } /*! - Returns true if this item has keyboard input focus; otherwise, returns - false. + Returns true if this item or its \l{focusProxy()}{focus proxy} has keyboard + input focus; otherwise, returns false. - \sa QGraphicsScene::focusItem(), setFocus(), QGraphicsScene::setFocusItem() + \sa focusItem(), setFocus(), QGraphicsScene::setFocusItem() */ bool QGraphicsItem::hasFocus() const { @@ -2479,8 +2479,8 @@ bool QGraphicsItem::hasFocus() const /*! Gives keyboard input focus to this item. The \a focusReason argument will - be passed into any focus event generated by this function; it is used to - give an explanation of what caused the item to get focus. + be passed into any \l{QFocusEvent}{focus event} generated by this function; + it is used to give an explanation of what caused the item to get focus. Only enabled items that set the ItemIsFocusable flag can accept keyboard focus. @@ -2489,12 +2489,12 @@ bool QGraphicsItem::hasFocus() const gain immediate input focus. However, it will be registered as the preferred focus item for its subtree of items, should it later become visible. - As a result of calling this function, this item will receive a focus in - event with \a focusReason. If another item already has focus, that item - will first receive a focus out event indicating that it has lost input - focus. + As a result of calling this function, this item will receive a + \l{focusInEvent()}{focus in event} with \a focusReason. If another item + already has focus, that item will first receive a \l{focusOutEvent()} + {focus out event} indicating that it has lost input focus. - \sa clearFocus(), hasFocus(), focusItem() + \sa clearFocus(), hasFocus(), focusItem(), focusProxy() */ void QGraphicsItem::setFocus(Qt::FocusReason focusReason) { @@ -2527,13 +2527,13 @@ void QGraphicsItem::setFocus(Qt::FocusReason focusReason) /*! Takes keyboard input focus from the item. - If it has focus, a focus out event is sent to this item to tell it that it - is about to lose the focus. + If it has focus, a \l{focusOutEvent()}{focus out event} is sent to this item + to tell it that it is about to lose the focus. Only items that set the ItemIsFocusable flag, or widgets that set an appropriate focus policy, can accept keyboard focus. - \sa setFocus(), QGraphicsWidget::focusPolicy + \sa setFocus(), hasFocus(), QGraphicsWidget::focusPolicy */ void QGraphicsItem::clearFocus() { @@ -2550,10 +2550,10 @@ void QGraphicsItem::clearFocus() /*! \since 4.6 - Returns this item's focus proxy, or 0 if the item - does not have any focus proxy. + Returns this item's focus proxy, or 0 if this item has no + focus proxy. - \sa setFocusProxy() + \sa setFocusProxy(), ItemAutoDetectsFocusProxy, setFocus(), hasFocus() */ QGraphicsItem *QGraphicsItem::focusProxy() const { @@ -2574,7 +2574,10 @@ QGraphicsItem *QGraphicsItem::focusProxy() const such case, keyboard input will be handled by the outermost focus proxy. - \sa focusProxy() + The focus proxy \a item must belong to the same scene as + this item. + + \sa focusProxy(), ItemAutoDetectsFocusProxy, setFocus(), hasFocus() */ void QGraphicsItem::setFocusProxy(QGraphicsItem *item) { @@ -2608,11 +2611,13 @@ void QGraphicsItem::setFocusProxy(QGraphicsItem *item) } /*! + \since 4.6 + If this item, a child or descendant of this item currently has input focus, this function will return a pointer to that item. If no descendant has input focus, 0 is returned. - \sa QWidget::focusWidget() + \sa hasFocus(), setFocus(), QWidget::focusWidget() */ QGraphicsItem *QGraphicsItem::focusItem() const { @@ -6102,7 +6107,7 @@ void QGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent *event) focus in events for this item. The default implementation calls ensureVisible(). - \sa focusOutEvent(), sceneEvent() + \sa focusOutEvent(), sceneEvent(), setFocus() */ void QGraphicsItem::focusInEvent(QFocusEvent *event) { @@ -6113,7 +6118,7 @@ void QGraphicsItem::focusInEvent(QFocusEvent *event) This event handler, for event \a event, can be reimplemented to receive focus out events for this item. The default implementation does nothing. - \sa focusInEvent(), sceneEvent() + \sa focusInEvent(), sceneEvent(), setFocus() */ void QGraphicsItem::focusOutEvent(QFocusEvent *event) { diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 328ba3d..bc3633c 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -675,8 +675,9 @@ QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, The QWidget::setEnable() function can be used to enable or disable mouse and keyboard events for a widget. - The event handlers QWidget::keyPressEvent() and - QWidget::keyReleaseEvent() receive key events. + The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(), + QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent() + receive key events. \sa QFocusEvent, QWidget::grabKeyboard() */ @@ -992,8 +993,9 @@ bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const The reason for a particular focus event is returned by reason() in the appropriate event handler. - The event handlers QWidget::focusInEvent() and - QWidget::focusOutEvent() receive focus events. + The event handlers QWidget::focusInEvent(), + QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and + QGraphicsItem::focusOutEvent() receive focus events. \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus} */ @@ -1611,12 +1613,14 @@ Qt::ButtonState QContextMenuEvent::state() const string is controlled by the widget only). The AttributeType enum describes the different attributes that can be set. - A class implementing QWidget::inputMethodEvent() should at least - understand and honor the \l TextFormat and \l Cursor attributes. + A class implementing QWidget::inputMethodEvent() or + QGraphicsItem::inputMethodEvent() should at least understand and + honor the \l TextFormat and \l Cursor attributes. Since input methods need to be able to query certain properties - from the widget, the widget must also implement - QWidget::inputMethodQuery(). + from the widget or graphics item, subclasses must also implement + QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(), + respectively. When receiving an input method event, the text widget has to performs the following steps: -- cgit v0.12 From 6559c780893264b18a74fce42584cc1345363ef8 Mon Sep 17 00:00:00 2001 From: Henrik Hartz Date: Tue, 28 Jul 2009 11:10:07 +1000 Subject: Fixes: Compile on winscw RevBy: Frans Englich Details: QHash::value creates an internal compiler error in this case on Metrowerks, using find instead --- src/xmlpatterns/parser/qmaintainingreader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/xmlpatterns/parser/qmaintainingreader.cpp b/src/xmlpatterns/parser/qmaintainingreader.cpp index 8569f05..292e0fd 100644 --- a/src/xmlpatterns/parser/qmaintainingreader.cpp +++ b/src/xmlpatterns/parser/qmaintainingreader.cpp @@ -147,7 +147,8 @@ void MaintainingReader::validateElement(const Looku if(m_elementDescriptions.contains(elementName)) { - const ElementDescription &desc = m_elementDescriptions.value(elementName); + // QHash::value breaks in Metrowerks Compiler + const ElementDescription &desc = *m_elementDescriptions.find(elementName); const int attCount = m_currentAttributes.count(); QSet encounteredXSLTAtts; -- cgit v0.12 From e498880396d44c90e46308e2fa5903b51f9f4132 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 28 Jul 2009 08:21:32 +0200 Subject: Disable Texture-From-Pixmap on everything other than Linux --- src/opengl/qgl_x11.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index a76059c..6381bc2 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -1548,6 +1548,9 @@ static bool qt_resolved_texture_from_pixmap = false; QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmap *pm, const qint64 key, bool canInvert) { +#if !defined(Q_OS_LINUX) + return 0; +#else Q_Q(QGLContext); if (pm->data_ptr()->classId() != QPixmapData::X11Class) @@ -1562,6 +1565,7 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmap *pm, const qi !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0)) return 0; + if (!qt_resolved_texture_from_pixmap) { qt_resolved_texture_from_pixmap = true; @@ -1647,11 +1651,12 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmap *pm, const qi return texture; #endif //!defined(GLX_VERSION_1_3) || defined(Q_OS_HPUX) +#endif //!defined(Q_OS_LINUX } void QGLTexture::deleteBoundPixmap() { -#if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) +#if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) && defined(Q_OS_LINUX) if (boundPixmap) { glXReleaseTexImageEXT(QX11Info::display(), boundPixmap, GLX_FRONT_LEFT_EXT); glXDestroyPixmap(QX11Info::display(), boundPixmap); -- cgit v0.12 From d22d08f3f8a70edfc66c0f6c2fd952688b64fcc2 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 28 Jul 2009 11:38:19 +0200 Subject: Remove tank game example After discussions with product management, it was considered best that this example be removed until it can be improved. There are some bugs an irregularities that should be cleaned up, and the theme should be made less violent. Reviewed-by: Volker Hilsheimer --- doc/src/examples.qdoc | 1 - doc/src/examples/tankgame.qdoc | 117 ------- examples/statemachine/statemachine.pro | 4 +- examples/statemachine/tankgame/gameitem.cpp | 129 -------- examples/statemachine/tankgame/gameitem.h | 66 ---- .../statemachine/tankgame/gameovertransition.cpp | 80 ----- .../statemachine/tankgame/gameovertransition.h | 63 ---- examples/statemachine/tankgame/main.cpp | 53 ---- examples/statemachine/tankgame/mainwindow.cpp | 342 --------------------- examples/statemachine/tankgame/mainwindow.h | 93 ------ examples/statemachine/tankgame/plugin.h | 62 ---- examples/statemachine/tankgame/rocketitem.cpp | 101 ------ examples/statemachine/tankgame/rocketitem.h | 66 ---- examples/statemachine/tankgame/tankgame.pro | 19 -- examples/statemachine/tankgame/tankitem.cpp | 302 ------------------ examples/statemachine/tankgame/tankitem.h | 109 ------- .../tankgameplugins/random_ai/random_ai.pro | 13 - .../tankgameplugins/random_ai/random_ai_plugin.cpp | 78 ----- .../tankgameplugins/random_ai/random_ai_plugin.h | 105 ------- .../tankgameplugins/seek_ai/seek_ai.cpp | 89 ------ .../statemachine/tankgameplugins/seek_ai/seek_ai.h | 249 --------------- .../tankgameplugins/seek_ai/seek_ai.pro | 13 - .../tankgameplugins/spin_ai/spin_ai.cpp | 70 ----- .../statemachine/tankgameplugins/spin_ai/spin_ai.h | 92 ------ .../tankgameplugins/spin_ai/spin_ai.pro | 13 - .../spin_ai_with_error/spin_ai_with_error.cpp | 70 ----- .../spin_ai_with_error/spin_ai_with_error.h | 92 ------ .../spin_ai_with_error/spin_ai_with_error.pro | 13 - .../tankgameplugins/tankgameplugins.pro | 11 - 29 files changed, 1 insertion(+), 2514 deletions(-) delete mode 100644 doc/src/examples/tankgame.qdoc delete mode 100644 examples/statemachine/tankgame/gameitem.cpp delete mode 100644 examples/statemachine/tankgame/gameitem.h delete mode 100644 examples/statemachine/tankgame/gameovertransition.cpp delete mode 100644 examples/statemachine/tankgame/gameovertransition.h delete mode 100644 examples/statemachine/tankgame/main.cpp delete mode 100644 examples/statemachine/tankgame/mainwindow.cpp delete mode 100644 examples/statemachine/tankgame/mainwindow.h delete mode 100644 examples/statemachine/tankgame/plugin.h delete mode 100644 examples/statemachine/tankgame/rocketitem.cpp delete mode 100644 examples/statemachine/tankgame/rocketitem.h delete mode 100644 examples/statemachine/tankgame/tankgame.pro delete mode 100644 examples/statemachine/tankgame/tankitem.cpp delete mode 100644 examples/statemachine/tankgame/tankitem.h delete mode 100644 examples/statemachine/tankgameplugins/random_ai/random_ai.pro delete mode 100644 examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp delete mode 100644 examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h delete mode 100644 examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp delete mode 100644 examples/statemachine/tankgameplugins/seek_ai/seek_ai.h delete mode 100644 examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro delete mode 100644 examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp delete mode 100644 examples/statemachine/tankgameplugins/spin_ai/spin_ai.h delete mode 100644 examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro delete mode 100644 examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp delete mode 100644 examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h delete mode 100644 examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro delete mode 100644 examples/statemachine/tankgameplugins/tankgameplugins.pro diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc index 2861c90..e85acd1 100644 --- a/doc/src/examples.qdoc +++ b/doc/src/examples.qdoc @@ -324,7 +324,6 @@ \o \l{statemachine/pingpong}{Ping Pong States}\raisedaster \o \l{statemachine/trafficlight}{Traffic Light}\raisedaster \o \l{statemachine/twowaybutton}{Two-way Button}\raisedaster - \o \l{statemachine/tankgame}{Tank Game}\raisedaster \endlist \section1 Threads diff --git a/doc/src/examples/tankgame.qdoc b/doc/src/examples/tankgame.qdoc deleted file mode 100644 index 536e582..0000000 --- a/doc/src/examples/tankgame.qdoc +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the documentation 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example statemachine/tankgame - \title Tank Game Example - - The Tank Game example is part of the in \l{The State Machine Framework}. It shows how to use - parallel states to implement artificial intelligence controllers that run in parallel, and error - states to handle run-time errors in parts of the state graph created by external plugins. - - \image tankgame-example.png - - In this example we write a simple game. The application runs a state machine with two main - states: A "stopped" state and a "running" state. The user can load plugins from the disk by - selecting the "Add tank" menu item. - - When the "Add tank" menu item is selected, the "plugins" subdirectory in the example's - directory is searched for compatible plugins. If any are found, they will be listed in a - dialog box created using QInputDialog::getItem(). - - \snippet examples/statemachine/tankgame/mainwindow.cpp 1 - - If the user selects a plugin, the application will construct a TankItem object, which inherits - from QGraphicsItem and QObject, and which implements an agreed-upon interface using the - meta-object mechanism. - - \snippet examples/statemachine/tankgame/tankitem.h 0 - - The tank item will be passed to the plugin's create() function. This will in turn return a - QState object which is expected to implement an artificial intelligence which controls the - tank and attempts to destroy other tanks it detects. - - \snippet examples/statemachine/tankgame/mainwindow.cpp 2 - - Each returned QState object becomes a descendant of a \c region in the "running" state, which is - defined as a parallel state. This means that entering the "running" state will cause each of the - plugged-in QState objects to be entered simultaneously, allowing the tanks to run independently - of each other. - - \snippet examples/statemachine/tankgame/mainwindow.cpp 0 - - The maximum number of tanks on the map is four, and when this number is reached, the - "Add tank" menu item should be disabled. This is implemented by giving the "stopped" state two - children which define whether the map is full or not. - - \snippet examples/statemachine/tankgame/mainwindow.cpp 5 - - To make sure that we go into the correct child state when returning from the "running" state - (if the "Stop game" menu item is selected while the game is running) we also give the "stopped" - state a history state which we make the initial state of "stopped" state. - - \snippet examples/statemachine/tankgame/mainwindow.cpp 3 - - Since part of the state graph is defined by external plugins, we have no way of controlling - whether they contain errors. By default, run-time errors are handled in the state machine by - entering a top level state which prints out an error message and never exits. If we were to - use this default behavior, a run-time error in any of the plugins would cause the "running" - state to exit, and thus all the other tanks to stop running as well. A better solution would - be if the broken plugin was disabled and the rest of the tanks allowed to continue as before. - - This is done by setting the error state of the plugin's top-most state to a special error state - defined specifically for the plugin in question. - - \snippet examples/statemachine/tankgame/mainwindow.cpp 4 - - If a run-time error occurs in \c pluginState or any of its descendants, the state machine will - search the hierarchy of ancestors until it finds a state whose error state is different from - \c null. (Note that if we are worried that a plugin could inadvertedly be overriding our - error state, we could search the descendants of \c pluginState and verify that their error - states are set to \c null before accepting the plugin.) - - The specialized \c errorState sets the "enabled" property of the tank item in question to false, - causing it to be painted with a red cross over it to indicate that it is no longer running. - Since the error state is a child of the same region in the parallel "running" state as - \c pluginState, it will not exit the "running" state, and the other tanks will continue running - without disruption. - -*/ diff --git a/examples/statemachine/statemachine.pro b/examples/statemachine/statemachine.pro index 5074a3c..ea3e7a8 100644 --- a/examples/statemachine/statemachine.pro +++ b/examples/statemachine/statemachine.pro @@ -4,9 +4,7 @@ SUBDIRS = \ factorial \ pingpong \ trafficlight \ - twowaybutton \ - tankgame \ - tankgameplugins + twowaybutton # install target.path = $$[QT_INSTALL_EXAMPLES]/statemachine diff --git a/examples/statemachine/tankgame/gameitem.cpp b/examples/statemachine/tankgame/gameitem.cpp deleted file mode 100644 index 94affb4..0000000 --- a/examples/statemachine/tankgame/gameitem.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "gameitem.h" - -#include -#include - -GameItem::GameItem(QObject *parent) : QObject(parent) -{ -} - -QPointF GameItem::tryMove(const QPointF &requestedPosition, QLineF *collidedLine, - QGraphicsItem **collidedItem) const -{ - QLineF movementPath(pos(), requestedPosition); - - qreal cannonLength = 0.0; - { - QPointF p1 = boundingRect().center(); - QPointF p2 = QPointF(boundingRect().right() + 10.0, p1.y()); - - cannonLength = QLineF(mapToScene(p1), mapToScene(p2)).length(); - } - - movementPath.setLength(movementPath.length() + cannonLength); - - QRectF boundingRectPath(QPointF(qMin(movementPath.x1(), movementPath.x2()), qMin(movementPath.y1(), movementPath.y2())), - QPointF(qMax(movementPath.x1(), movementPath.x2()), qMax(movementPath.y1(), movementPath.y2()))); - - QList itemsInRect = scene()->items(boundingRectPath, Qt::IntersectsItemBoundingRect); - - QPointF nextPoint = requestedPosition; - QRectF sceneRect = scene()->sceneRect(); - - foreach (QGraphicsItem *item, itemsInRect) { - if (item == static_cast(this)) - continue; - - QPolygonF mappedBoundingRect = item->mapToScene(item->boundingRect()); - for (int i=0; isceneRect().topLeft(), scene()->sceneRect().bottomLeft()); - } - - if (nextPoint.x() > sceneRect.right()) { - nextPoint.rx() = sceneRect.right(); - if (collidedLine != 0) - *collidedLine = QLineF(scene()->sceneRect().topRight(), scene()->sceneRect().bottomRight()); - } - - if (nextPoint.y() < sceneRect.top()) { - nextPoint.ry() = sceneRect.top(); - if (collidedLine != 0) - *collidedLine = QLineF(scene()->sceneRect().topLeft(), scene()->sceneRect().topRight()); - } - - if (nextPoint.y() > sceneRect.bottom()) { - nextPoint.ry() = sceneRect.bottom(); - if (collidedLine != 0) - *collidedLine = QLineF(scene()->sceneRect().bottomLeft(), scene()->sceneRect().bottomRight()); - } - - return nextPoint; -} - diff --git a/examples/statemachine/tankgame/gameitem.h b/examples/statemachine/tankgame/gameitem.h deleted file mode 100644 index af012bb..0000000 --- a/examples/statemachine/tankgame/gameitem.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GAMEITEM_H -#define GAMEITEM_H - -#include - -QT_BEGIN_NAMESPACE -class QLineF; -QT_END_NAMESPACE -class GameItem: public QObject, public QGraphicsItem -{ - Q_OBJECT -public: - enum { Type = UserType + 1 }; - int type() const { return Type; } - - GameItem(QObject *parent = 0); - - virtual void idle(qreal elapsed) = 0; - -protected: - QPointF tryMove(const QPointF &requestedPosition, QLineF *collidedLine = 0, - QGraphicsItem **collidedItem = 0) const; -}; - -#endif diff --git a/examples/statemachine/tankgame/gameovertransition.cpp b/examples/statemachine/tankgame/gameovertransition.cpp deleted file mode 100644 index 634fbce..0000000 --- a/examples/statemachine/tankgame/gameovertransition.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "gameovertransition.h" -#include "tankitem.h" - -#include -#include - -GameOverTransition::GameOverTransition(QAbstractState *targetState) - : QSignalTransition(new QSignalMapper(), SIGNAL(mapped(QObject*))) -{ - setTargetState(targetState); - - QSignalMapper *mapper = qobject_cast(senderObject()); - mapper->setParent(this); -} - -void GameOverTransition::addTankItem(TankItem *tankItem) -{ - m_tankItems.append(tankItem); - - QSignalMapper *mapper = qobject_cast(senderObject()); - mapper->setMapping(tankItem, tankItem); - connect(tankItem, SIGNAL(aboutToBeDestroyed()), mapper, SLOT(map())); -} - -bool GameOverTransition::eventTest(QEvent *e) -{ - bool ret = QSignalTransition::eventTest(e); - - if (ret) { - QSignalEvent *signalEvent = static_cast(e); - QObject *sender = qvariant_cast(signalEvent->arguments().at(0)); - TankItem *tankItem = qobject_cast(sender); - m_tankItems.removeAll(tankItem); - - return m_tankItems.size() <= 1; - } else { - return false; - } -} diff --git a/examples/statemachine/tankgame/gameovertransition.h b/examples/statemachine/tankgame/gameovertransition.h deleted file mode 100644 index e918359..0000000 --- a/examples/statemachine/tankgame/gameovertransition.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GAMEOVERTRANSITION_H -#define GAMEOVERTRANSITION_H - -#include - -class TankItem; -class GameOverTransition: public QSignalTransition -{ - Q_OBJECT -public: - GameOverTransition(QAbstractState *targetState); - - void addTankItem(TankItem *tankItem); - -protected: - bool eventTest(QEvent *event); - -private: - QList m_tankItems; -}; - -#endif diff --git a/examples/statemachine/tankgame/main.cpp b/examples/statemachine/tankgame/main.cpp deleted file mode 100644 index 85e2747..0000000 --- a/examples/statemachine/tankgame/main.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "mainwindow.h" - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - MainWindow mainWindow; - mainWindow.show(); - - return app.exec(); -} diff --git a/examples/statemachine/tankgame/mainwindow.cpp b/examples/statemachine/tankgame/mainwindow.cpp deleted file mode 100644 index 596cdfe..0000000 --- a/examples/statemachine/tankgame/mainwindow.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mainwindow.h" -#include "tankitem.h" -#include "rocketitem.h" -#include "plugin.h" -#include "gameovertransition.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), m_scene(0), m_machine(0), m_runningState(0), m_started(false) -{ - init(); -} - -MainWindow::~MainWindow() -{ -} - -void MainWindow::addWall(const QRectF &wall) -{ - QGraphicsRectItem *item = new QGraphicsRectItem; - item->setRect(wall); - item->setBrush(Qt::darkGreen); - item->setPen(QPen(Qt::black, 0)); - - m_scene->addItem(item); -} - -void MainWindow::init() -{ - setWindowTitle("Pluggable Tank Game"); - - QGraphicsView *view = new QGraphicsView(this); - view->setRenderHints(QPainter::Antialiasing); - setCentralWidget(view); - - m_scene = new QGraphicsScene(this); - view->setScene(m_scene); - - QRectF sceneRect = QRectF(-200.0, -200.0, 400.0, 400.0); - m_scene->setSceneRect(sceneRect); - - { - TankItem *item = new TankItem(this); - - item->setPos(m_scene->sceneRect().topLeft() + QPointF(30.0, 30.0)); - item->setDirection(45.0); - item->setColor(Qt::red); - - m_spawns.append(item); - } - - { - TankItem *item = new TankItem(this); - - item->setPos(m_scene->sceneRect().topRight() + QPointF(-30.0, 30.0)); - item->setDirection(135.0); - item->setColor(Qt::green); - - m_spawns.append(item); - } - - { - TankItem *item = new TankItem(this); - - item->setPos(m_scene->sceneRect().bottomRight() + QPointF(-30.0, -30.0)); - item->setDirection(225.0); - item->setColor(Qt::blue); - - m_spawns.append(item); - } - - { - TankItem *item = new TankItem(this); - - item->setPos(m_scene->sceneRect().bottomLeft() + QPointF(30.0, -30.0)); - item->setDirection(315.0); - item->setColor(Qt::yellow); - - m_spawns.append(item); - } - - QPointF centerOfMap = sceneRect.center(); - - addWall(QRectF(centerOfMap + QPointF(-50.0, -60.0), centerOfMap + QPointF(50.0, -50.0))); - addWall(QRectF(centerOfMap - QPointF(-50.0, -60.0), centerOfMap - QPointF(50.0, -50.0))); - addWall(QRectF(centerOfMap + QPointF(-50.0, -50.0), centerOfMap + QPointF(-40.0, 50.0))); - addWall(QRectF(centerOfMap - QPointF(-50.0, -50.0), centerOfMap - QPointF(-40.0, 50.0))); - - addWall(QRectF(sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, -10.0), - sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, 100.0))); - addWall(QRectF(sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, 10.0), - sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, -100.0))); - addWall(QRectF(sceneRect.topLeft() + QPointF(-10.0, sceneRect.height() / 2.0 - 5.0), - sceneRect.topLeft() + QPointF(100.0, sceneRect.height() / 2.0 + 5.0))); - addWall(QRectF(sceneRect.topRight() + QPointF(10.0, sceneRect.height() / 2.0 - 5.0), - sceneRect.topRight() + QPointF(-100.0, sceneRect.height() / 2.0 + 5.0))); - - - QAction *addTankAction = menuBar()->addAction("&Add tank"); - QAction *runGameAction = menuBar()->addAction("&Run game"); - runGameAction->setObjectName("runGameAction"); - QAction *stopGameAction = menuBar()->addAction("&Stop game"); - menuBar()->addSeparator(); - QAction *quitAction = menuBar()->addAction("&Quit"); - - connect(addTankAction, SIGNAL(triggered()), this, SLOT(addTank())); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - - m_machine = new QStateMachine(this); - QState *stoppedState = new QState(m_machine); - stoppedState->setObjectName("stoppedState"); - stoppedState->assignProperty(runGameAction, "enabled", true); - stoppedState->assignProperty(stopGameAction, "enabled", false); - stoppedState->assignProperty(this, "started", false); - m_machine->setInitialState(stoppedState); - -//! [5] - QState *spawnsAvailable = new QState(stoppedState); - spawnsAvailable->assignProperty(addTankAction, "enabled", true); - - QState *noSpawnsAvailable = new QState(stoppedState); - noSpawnsAvailable->assignProperty(addTankAction, "enabled", false); -//! [5] - spawnsAvailable->setObjectName("spawnsAvailable"); - noSpawnsAvailable->setObjectName("noSpawnsAvailable"); - - spawnsAvailable->addTransition(this, SIGNAL(mapFull()), noSpawnsAvailable); - -//! [3] - QHistoryState *hs = new QHistoryState(stoppedState); - hs->setDefaultState(spawnsAvailable); -//! [3] - hs->setObjectName("hs"); - - stoppedState->setInitialState(hs); - -//! [0] - m_runningState = new QState(QState::ParallelStates, m_machine); -//! [0] - m_runningState->setObjectName("runningState"); - m_runningState->assignProperty(addTankAction, "enabled", false); - m_runningState->assignProperty(runGameAction, "enabled", false); - m_runningState->assignProperty(stopGameAction, "enabled", true); - - QState *gameOverState = new QState(m_machine); - gameOverState->setObjectName("gameOverState"); - gameOverState->assignProperty(stopGameAction, "enabled", false); - connect(gameOverState, SIGNAL(entered()), this, SLOT(gameOver())); - - stoppedState->addTransition(runGameAction, SIGNAL(triggered()), m_runningState); - m_runningState->addTransition(stopGameAction, SIGNAL(triggered()), stoppedState); - - m_gameOverTransition = new GameOverTransition(gameOverState); - m_runningState->addTransition(m_gameOverTransition); - - QTimer *timer = new QTimer(this); - timer->setInterval(100); - connect(timer, SIGNAL(timeout()), this, SLOT(runStep())); - connect(m_runningState, SIGNAL(entered()), timer, SLOT(start())); - connect(m_runningState, SIGNAL(exited()), timer, SLOT(stop())); - - m_machine->start(); - m_time.start(); -} - -void MainWindow::runStep() -{ - if (!m_started) { - m_time.restart(); - m_started = true; - } else { - int elapsed = m_time.elapsed(); - if (elapsed > 0) { - m_time.restart(); - qreal elapsedSecs = elapsed / 1000.0; - QList items = m_scene->items(); - foreach (QGraphicsItem *item, items) { - if (GameItem *gameItem = qgraphicsitem_cast(item)) - gameItem->idle(elapsedSecs); - } - } - } -} - -void MainWindow::gameOver() -{ - QList items = m_scene->items(); - - TankItem *lastTankStanding = 0; - foreach (QGraphicsItem *item, items) { - if (GameItem *gameItem = qgraphicsitem_cast(item)) { - if ((lastTankStanding = qobject_cast(gameItem)) != 0) - break; - } - } - - QMessageBox::information(this, "Game over!", - QString::fromLatin1("The tank played by '%1' has won!").arg(lastTankStanding->objectName())); -} - -void MainWindow::addRocket() -{ - TankItem *tankItem = qobject_cast(sender()); - if (tankItem != 0) { - RocketItem *rocketItem = new RocketItem; - - QPointF s = tankItem->mapToScene(QPointF(tankItem->boundingRect().right() + 10.0, - tankItem->boundingRect().center().y())); - rocketItem->setPos(s); - rocketItem->setDirection(tankItem->direction()); - m_scene->addItem(rocketItem); - } -} - -void MainWindow::addTank() -{ - Q_ASSERT(!m_spawns.isEmpty()); - - QDir pluginsDir(qApp->applicationDirPath()); -#if defined(Q_OS_WIN) - if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release") - pluginsDir.cdUp(); -#elif defined(Q_OS_MAC) - if (pluginsDir.dirName() == "MacOS") { - pluginsDir.cdUp(); - pluginsDir.cdUp(); - pluginsDir.cdUp(); - } -#endif - - pluginsDir.cd("plugins"); - - QStringList itemNames; - QList items; - foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { - QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); - QObject *possiblePlugin = loader.instance(); - if (Plugin *plugin = qobject_cast(possiblePlugin)) { - QString objectName = possiblePlugin->objectName(); - if (objectName.isEmpty()) - objectName = fileName; - - itemNames.append(objectName); - items.append(plugin); - } - } - - if (items.isEmpty()) { - QMessageBox::information(this, "No tank types found", "Please build the errorstateplugins directory"); - return; - } - - bool ok; -//! [1] - QString selectedName = QInputDialog::getItem(this, "Select a tank type", "Tank types", - itemNames, 0, false, &ok); -//! [1] - - if (ok && !selectedName.isEmpty()) { - int idx = itemNames.indexOf(selectedName); - if (Plugin *plugin = idx >= 0 ? items.at(idx) : 0) { - TankItem *tankItem = m_spawns.takeLast(); - tankItem->setObjectName(selectedName); - tankItem->setToolTip(selectedName); - m_scene->addItem(tankItem); - connect(tankItem, SIGNAL(cannonFired()), this, SLOT(addRocket())); - if (m_spawns.isEmpty()) - emit mapFull(); - - m_gameOverTransition->addTankItem(tankItem); - - QState *region = new QState(m_runningState); - region->setObjectName(QString::fromLatin1("region%1").arg(m_spawns.size())); -//! [2] - QState *pluginState = plugin->create(region, tankItem); -//! [2] - region->setInitialState(pluginState); - - // If the plugin has an error it is disabled -//! [4] - QState *errorState = new QState(region); - errorState->setObjectName(QString::fromLatin1("errorState%1").arg(m_spawns.size())); - errorState->assignProperty(tankItem, "enabled", false); - pluginState->setErrorState(errorState); -//! [4] - } - } -} - diff --git a/examples/statemachine/tankgame/mainwindow.h b/examples/statemachine/tankgame/mainwindow.h deleted file mode 100644 index d42b7ac..0000000 --- a/examples/statemachine/tankgame/mainwindow.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QGraphicsScene; -class QStateMachine; -class QState; -QT_END_NAMESPACE -class GameOverTransition; -class TankItem; - -class MainWindow: public QMainWindow -{ - Q_OBJECT - Q_PROPERTY(bool started READ started WRITE setStarted) -public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); - - void setStarted(bool b) { m_started = b; } - bool started() const { return m_started; } - -public slots: - void addTank(); - void addRocket(); - void runStep(); - void gameOver(); - -signals: - void mapFull(); - -private: - void init(); - void addWall(const QRectF &wall); - - QGraphicsScene *m_scene; - - QStateMachine *m_machine; - QState *m_runningState; - GameOverTransition *m_gameOverTransition; - - QList m_spawns; - QTime m_time; - - bool m_started : 1; -}; - -#endif - diff --git a/examples/statemachine/tankgame/plugin.h b/examples/statemachine/tankgame/plugin.h deleted file mode 100644 index 97e4640..0000000 --- a/examples/statemachine/tankgame/plugin.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PLUGIN_H -#define PLUGIN_H - -#include - -QT_BEGIN_NAMESPACE -class QState; -QT_END_NAMESPACE -class Plugin -{ -public: - virtual ~Plugin() {} - - virtual QState *create(QState *parentState, QObject *tank) = 0; -}; - -QT_BEGIN_NAMESPACE -Q_DECLARE_INTERFACE(Plugin, "TankPlugin") -QT_END_NAMESPACE - -#endif diff --git a/examples/statemachine/tankgame/rocketitem.cpp b/examples/statemachine/tankgame/rocketitem.cpp deleted file mode 100644 index d286e5d..0000000 --- a/examples/statemachine/tankgame/rocketitem.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "rocketitem.h" -#include "tankitem.h" - -#include -#include - -#include - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -RocketItem::RocketItem(QObject *parent) - : GameItem(parent), m_direction(0.0), m_distance(300.0) -{ -} - -QRectF RocketItem::boundingRect() const -{ - return QRectF(-1.0, -1.0, 2.0, 2.0); -} - -void RocketItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - painter->setBrush(Qt::black); - painter->drawEllipse(boundingRect()); -} - -void RocketItem::idle(qreal elapsed) -{ - qreal dist = elapsed * speed(); - - m_distance -= dist; - if (m_distance < 0.0) { - scene()->removeItem(this); - delete this; - return; - } - - qreal a = m_direction * M_PI / 180.0; - - qreal yd = dist * sin(a); - qreal xd = dist * sin(M_PI / 2.0 - a); - - QPointF requestedPosition = pos() + QPointF(xd, yd); - QGraphicsItem *collidedItem = 0; - QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem); - if (requestedPosition == nextPosition) { - setPos(nextPosition); - } else { - if (GameItem *gameItem = qgraphicsitem_cast(collidedItem)) { - TankItem *tankItem = qobject_cast(gameItem); - if (tankItem != 0) - tankItem->hitByRocket(); - } - - scene()->removeItem(this); - delete this; - } -} diff --git a/examples/statemachine/tankgame/rocketitem.h b/examples/statemachine/tankgame/rocketitem.h deleted file mode 100644 index a485d03..0000000 --- a/examples/statemachine/tankgame/rocketitem.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ROCKETITEM_H -#define ROCKETITEM_H - -#include "gameitem.h" - -class RocketItem: public GameItem -{ - Q_OBJECT -public: - RocketItem(QObject *parent = 0); - - virtual void idle(qreal elapsed); - qreal speed() const { return 100.0; } - void setDirection(qreal direction) { m_direction = direction; } - -protected: - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - QRectF boundingRect() const; - -private: - qreal m_direction; - qreal m_distance; -}; - -#endif diff --git a/examples/statemachine/tankgame/tankgame.pro b/examples/statemachine/tankgame/tankgame.pro deleted file mode 100644 index 59415be..0000000 --- a/examples/statemachine/tankgame/tankgame.pro +++ /dev/null @@ -1,19 +0,0 @@ -HEADERS += mainwindow.h \ - plugin.h \ - tankitem.h \ - rocketitem.h \ - gameitem.h \ - gameovertransition.h -SOURCES += main.cpp \ - mainwindow.cpp \ - tankitem.cpp \ - rocketitem.cpp \ - gameitem.cpp \ - gameovertransition.cpp -CONFIG += console - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tankgame.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame -INSTALLS += target sources diff --git a/examples/statemachine/tankgame/tankitem.cpp b/examples/statemachine/tankgame/tankitem.cpp deleted file mode 100644 index 192b272..0000000 --- a/examples/statemachine/tankgame/tankitem.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "tankitem.h" - -#include -#include -#include - -#include - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -class Action -{ -public: - Action(TankItem *item) : m_item(item) - { - } - - TankItem *item() const { return m_item; } - void setItem(TankItem *item) { m_item = item; } - - virtual bool apply(qreal timeDelta) = 0; - -private: - TankItem *m_item; -}; - -class MoveAction: public Action -{ -public: - MoveAction(TankItem *item, qreal distance) - : Action(item), m_distance(distance) - { - m_reverse = m_distance < 0.0; - } - - bool apply(qreal timeDelta) - { - qreal dist = timeDelta * item()->speed() * (m_reverse ? -1.0 : 1.0); - - bool done = false; - if (qAbs(m_distance) < qAbs(dist)) { - done = true; - dist = m_distance; - } - m_distance -= dist; - - qreal a = item()->direction() * M_PI / 180.0; - - qreal yd = dist * sin(a); - qreal xd = dist * sin(M_PI / 2.0 - a); - - item()->setPos(item()->pos() + QPointF(xd, yd)); - return !done; - } - -private: - qreal m_distance; - bool m_reverse; -}; - -class TurnAction: public Action -{ -public: - TurnAction(TankItem *item, qreal distance) - : Action(item), m_distance(distance) - { - m_reverse = m_distance < 0.0; - } - - bool apply(qreal timeDelta) - { - qreal dist = timeDelta * item()->angularSpeed() * (m_reverse ? -1.0 : 1.0); - bool done = false; - if (qAbs(m_distance) < qAbs(dist)) { - done = true; - dist = m_distance; - } - m_distance -= dist; - - item()->setDirection(item()->direction() + dist); - return !done; - } - -private: - qreal m_distance; - bool m_reverse; -}; - -TankItem::TankItem(QObject *parent) - : GameItem(parent), m_currentAction(0), m_currentDirection(0.0), m_enabled(true) -{ - connect(this, SIGNAL(cannonFired()), this, SIGNAL(actionCompleted())); -} - -void TankItem::idle(qreal elapsed) -{ - if (m_enabled) { - if (m_currentAction != 0) { - if (!m_currentAction->apply(elapsed)) { - setAction(0); - emit actionCompleted(); - } - - QGraphicsItem *item = 0; - qreal distance = distanceToObstacle(&item); - if (TankItem *tankItem = qgraphicsitem_cast(item)) - emit tankSpotted(tankItem->direction(), distance); - } - } -} - -void TankItem::hitByRocket() -{ - emit aboutToBeDestroyed(); - deleteLater(); -} - -void TankItem::setAction(Action *newAction) -{ - if (m_currentAction != 0) - delete m_currentAction; - - m_currentAction = newAction; -} - -void TankItem::fireCannon() -{ - emit cannonFired(); -} - -void TankItem::moveForwards(qreal length) -{ - setAction(new MoveAction(this, length)); -} - -void TankItem::moveBackwards(qreal length) -{ - setAction(new MoveAction(this, -length)); -} - -void TankItem::turn(qreal degrees) -{ - setAction(new TurnAction(this, degrees)); -} - -void TankItem::turnTo(qreal degrees) -{ - setAction(new TurnAction(this, degrees - direction())); -} - -void TankItem::stop() -{ - setAction(0); -} - -QVariant TankItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) -{ - if (change == ItemPositionChange && scene()) { - QPointF requestedPosition = value.toPointF(); - QLineF collidedLine; - QPointF nextPoint = tryMove(requestedPosition, &collidedLine); - if (nextPoint != requestedPosition) - emit collision(collidedLine); - return nextPoint; - } else { - return QGraphicsItem::itemChange(change, value); - } -} - - -void TankItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - QRectF brect = boundingRect(); - - painter->setBrush(m_color); - painter->setPen(Qt::black); - - // body - painter->drawRect(brect.adjusted(0.0, 4.0, -2.0, -4.0)); - - // cannon - QRectF cannonBase = brect.adjusted(10.0, 6.0, -12.0, -6.0); - painter->drawEllipse(cannonBase); - - painter->drawRect(QRectF(QPointF(cannonBase.center().x(), cannonBase.center().y() - 2.0), - QPointF(brect.right(), cannonBase.center().y() + 2.0))); - - // left track - painter->setBrush(QBrush(Qt::black, Qt::VerPattern)); - QRectF leftTrackRect = QRectF(brect.topLeft(), QPointF(brect.right() - 2.0, brect.top() + 4.0)); - painter->fillRect(leftTrackRect, Qt::darkYellow); - painter->drawRect(leftTrackRect); - - // right track - QRectF rightTrackRect = QRectF(QPointF(brect.left(), brect.bottom() - 4.0), - QPointF(brect.right() - 2.0, brect.bottom())); - painter->fillRect(rightTrackRect, Qt::darkYellow); - painter->drawRect(rightTrackRect); - - if (!m_enabled) { - painter->setPen(QPen(Qt::red, 5)); - - painter->drawEllipse(brect); - - QPainterPath path; - path.addEllipse(brect); - painter->setClipPath(path); - painter->drawLine(brect.topRight(), brect.bottomLeft()); - } -} - -QRectF TankItem::boundingRect() const -{ - return QRectF(-20.0, -10.0, 40.0, 20.0); -} - -qreal TankItem::direction() const -{ - return m_currentDirection; -} - -void TankItem::setDirection(qreal newDirection) -{ - int fullRotations = int(newDirection) / 360; - newDirection -= fullRotations * 360.0; - - qreal diff = newDirection - m_currentDirection; - m_currentDirection = newDirection; - rotate(diff); -} - -qreal TankItem::distanceToObstacle(QGraphicsItem **obstacle) const -{ - qreal dist = sqrt(pow(scene()->sceneRect().width(), 2) + pow(scene()->sceneRect().height(), 2)); - - qreal a = m_currentDirection * M_PI / 180.0; - - qreal yd = dist * sin(a); - qreal xd = dist * sin(M_PI / 2.0 - a); - - QPointF requestedPosition = pos() + QPointF(xd, yd); - QGraphicsItem *collidedItem = 0; - QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem); - if (collidedItem != 0) { - if (obstacle != 0) - *obstacle = collidedItem; - - QPointF d = nextPosition - pos(); - return sqrt(pow(d.x(), 2) + pow(d.y(), 2)); - } else { - return 0.0; - } -} - -qreal TankItem::distanceToObstacle() const -{ - return distanceToObstacle(0); -} - diff --git a/examples/statemachine/tankgame/tankitem.h b/examples/statemachine/tankgame/tankitem.h deleted file mode 100644 index a2f72de..0000000 --- a/examples/statemachine/tankgame/tankitem.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef TANKITEM_H -#define TANKITEM_H - -#include "gameitem.h" - -#include - -class Action; -class TankItem: public GameItem -{ - Q_OBJECT - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) - Q_PROPERTY(qreal direction READ direction WRITE turnTo) - Q_PROPERTY(qreal distanceToObstacle READ distanceToObstacle) -public: - TankItem(QObject *parent = 0); - - void setColor(const QColor &color) { m_color = color; } - QColor color() const { return m_color; } - - void idle(qreal elapsed); - void setDirection(qreal newDirection); - - qreal speed() const { return 90.0; } - qreal angularSpeed() const { return 90.0; } - - QRectF boundingRect() const; - - void hitByRocket(); - - void setEnabled(bool b) { m_enabled = b; } - bool enabled() const { return m_enabled; } - - qreal direction() const; - qreal distanceToObstacle() const; - qreal distanceToObstacle(QGraphicsItem **item) const; - -//! [0] -signals: - void tankSpotted(qreal direction, qreal distance); - void collision(const QLineF &collidedLine); - void actionCompleted(); - void cannonFired(); - void aboutToBeDestroyed(); - -public slots: - void moveForwards(qreal length = 10.0); - void moveBackwards(qreal length = 10.0); - void turn(qreal degrees = 30.0); - void turnTo(qreal degrees = 0.0); - void stop(); - void fireCannon(); -//! [0] - -protected: - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); - -private: - void setAction(Action *newAction); - - Action *m_currentAction; - qreal m_currentDirection; - QColor m_color; - bool m_enabled; -}; - -#endif diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai.pro b/examples/statemachine/tankgameplugins/random_ai/random_ai.pro deleted file mode 100644 index 5bc0b26..0000000 --- a/examples/statemachine/tankgameplugins/random_ai/random_ai.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -INCLUDEPATH += ../.. -HEADERS = random_ai_plugin.h -SOURCES = random_ai_plugin.cpp -TARGET = $$qtLibraryTarget(random_ai) -DESTDIR = ../../tankgame/plugins - -#! [0] -# install -target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS random_ai.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/random_ai \ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp deleted file mode 100644 index ddfd1c5..0000000 --- a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "random_ai_plugin.h" - -#include -#include -#include - -QState *RandomAiPlugin::create(QState *parentState, QObject *tank) -{ - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); - - QState *topLevel = new QState(parentState); - - QState *selectNextActionState = new SelectActionState(topLevel); - topLevel->setInitialState(selectNextActionState); - - QState *fireState = new RandomDistanceState(topLevel); - connect(fireState, SIGNAL(distanceComputed(qreal)), tank, SLOT(fireCannon())); - selectNextActionState->addTransition(selectNextActionState, SIGNAL(fireSelected()), fireState); - - QState *moveForwardsState = new RandomDistanceState(topLevel); - connect(moveForwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveForwards(qreal))); - selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveForwardsSelected()), moveForwardsState); - - QState *moveBackwardsState = new RandomDistanceState(topLevel); - connect(moveBackwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveBackwards(qreal))); - selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveBackwardsSelected()), moveBackwardsState); - - QState *turnState = new RandomDistanceState(topLevel); - connect(turnState, SIGNAL(distanceComputed(qreal)), tank, SLOT(turn(qreal))); - selectNextActionState->addTransition(selectNextActionState, SIGNAL(turnSelected()), turnState); - - topLevel->addTransition(tank, SIGNAL(actionCompleted()), selectNextActionState); - - return topLevel; -} - -Q_EXPORT_PLUGIN2(random_ai, RandomAiPlugin) diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h deleted file mode 100644 index 4c3fc0f..0000000 --- a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef RANDOM_AI_PLUGIN_H -#define RANDOM_AI_PLUGIN_H - -#include -#include - -#include - -class SelectActionState: public QState -{ - Q_OBJECT -public: - SelectActionState(QState *parent = 0) : QState(parent) - { - } - -signals: - void fireSelected(); - void moveForwardsSelected(); - void moveBackwardsSelected(); - void turnSelected(); - -protected: - void onEntry(QEvent *) - { - int rand = qrand() % 4; - switch (rand) { - case 0: emit fireSelected(); break; - case 1: emit moveForwardsSelected(); break; - case 2: emit moveBackwardsSelected(); break; - case 3: emit turnSelected(); break; - }; - } -}; - -class RandomDistanceState: public QState -{ - Q_OBJECT -public: - RandomDistanceState(QState *parent = 0) : QState(parent) - { - } - -signals: - void distanceComputed(qreal distance); - -protected: - void onEntry(QEvent *) - { - emit distanceComputed(qreal(qrand() % 180)); - } -}; - -class RandomAiPlugin: public QObject, public Plugin -{ - Q_OBJECT - Q_INTERFACES(Plugin) -public: - RandomAiPlugin() { setObjectName("Random"); } - - virtual QState *create(QState *parentState, QObject *tank); -}; - -#endif // RANDOM_AI_PLUGIN_H diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp deleted file mode 100644 index 79d7d0c..0000000 --- a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "seek_ai.h" - -QState *SeekAi::create(QState *parentState, QObject *tank) -{ - QState *topLevel = new QState(parentState); - topLevel->setObjectName("topLevel"); - - QState *seek = new QState(topLevel); - seek->setObjectName("seek"); - topLevel->setInitialState(seek); - - QState *lookForNearestWall = new SearchState(tank, seek); - lookForNearestWall->setObjectName("lookForNearestWall"); - seek->setInitialState(lookForNearestWall); - - QState *driveToFirstObstacle = new QState(seek); - driveToFirstObstacle->setObjectName("driveToFirstObstacle"); - lookForNearestWall->addTransition(lookForNearestWall, SIGNAL(nearestObstacleStraightAhead()), - driveToFirstObstacle); - - QState *drive = new QState(driveToFirstObstacle); - drive->setObjectName("drive"); - driveToFirstObstacle->setInitialState(drive); - connect(drive, SIGNAL(entered()), tank, SLOT(moveForwards())); - connect(drive, SIGNAL(exited()), tank, SLOT(stop())); - - // Go in loop - QState *finishedDriving = new QState(driveToFirstObstacle); - finishedDriving->setObjectName("finishedDriving"); - drive->addTransition(tank, SIGNAL(actionCompleted()), finishedDriving); - finishedDriving->addTransition(drive); - - QState *turnTo = new QState(seek); - turnTo->setObjectName("turnTo"); - driveToFirstObstacle->addTransition(new CollisionTransition(tank, turnTo)); - - turnTo->addTransition(tank, SIGNAL(actionCompleted()), driveToFirstObstacle); - - ChaseState *chase = new ChaseState(tank, topLevel); - chase->setObjectName("chase"); - seek->addTransition(new TankSpottedTransition(tank, chase)); - chase->addTransition(chase, SIGNAL(finished()), driveToFirstObstacle); - chase->addTransition(new TankSpottedTransition(tank, chase)); - - return topLevel; -} - -Q_EXPORT_PLUGIN2(seek_ai, SeekAi) diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h deleted file mode 100644 index 1bc5b26..0000000 --- a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SEEK_AI_H -#define SEEK_AI_H - -#include - -#include -#include -#include -#include -#include -#include -#include - -class SearchState: public QState -{ - Q_OBJECT -public: - SearchState(QObject *tank, QState *parentState = 0) - : QState(parentState), - m_tank(tank), - m_distanceToTurn(360.0), - m_nearestDistance(-1.0), - m_directionOfNearestObstacle(0.0) - { - } - -public slots: - void turnAlittle() - { - qreal dist = m_tank->property("distanceToObstacle").toDouble(); - - if (m_nearestDistance < 0.0 || dist < m_nearestDistance) { - m_nearestDistance = dist; - m_directionOfNearestObstacle = m_tank->property("direction").toDouble(); - } - - m_distanceToTurn -= 10.0; - if (m_distanceToTurn < 0.0) { - disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); - connect(m_tank, SIGNAL(actionCompleted()), this, SIGNAL(nearestObstacleStraightAhead())); - m_tank->setProperty("direction", m_directionOfNearestObstacle); - } - - qreal currentDirection = m_tank->property("direction").toDouble(); - m_tank->setProperty("direction", currentDirection + 10.0); - } - -signals: - void nearestObstacleStraightAhead(); - -protected: - void onEntry(QEvent *) - { - connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); - turnAlittle(); - } - - void onExit(QEvent *) - { - disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); - disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(nearestObstacleStraightAhead())); - } - -private: - QObject *m_tank; - - qreal m_distanceToTurn; - qreal m_nearestDistance; - qreal m_directionOfNearestObstacle; -}; - -class CollisionTransition: public QSignalTransition -{ -public: - CollisionTransition(QObject *tank, QState *turnTo) - : QSignalTransition(tank, SIGNAL(collision(QLineF))), - m_tank(tank), - m_turnTo(turnTo) - { - setTargetState(turnTo); - } - -protected: - bool eventTest(QEvent *event) - { - bool b = QSignalTransition::eventTest(event); - if (b) { - QSignalEvent *se = static_cast(event); - m_lastLine = se->arguments().at(0).toLineF(); - } - return b; - } - - void onTransition(QEvent *) - { - qreal angleOfWall = m_lastLine.angle(); - - qreal newDirection; - if (qrand() % 2 == 0) - newDirection = angleOfWall; - else - newDirection = angleOfWall - 180.0; - - m_turnTo->assignProperty(m_tank, "direction", newDirection); - } - -private: - QLineF m_lastLine; - QObject *m_tank; - QState *m_turnTo; -}; - -class ChaseState: public QState -{ - class GoToLocationState: public QState - { - public: - GoToLocationState(QObject *tank, QState *parentState = 0) - : QState(parentState), m_tank(tank), m_distance(0.0) - { - } - - void setDistance(qreal distance) { m_distance = distance; } - - protected: - void onEntry() - { - QMetaObject::invokeMethod(m_tank, "moveForwards", Q_ARG(qreal, m_distance)); - } - - private: - QObject *m_tank; - qreal m_distance; - }; - -public: - ChaseState(QObject *tank, QState *parentState = 0) : QState(parentState), m_tank(tank) - { - QState *fireCannon = new QState(this); - fireCannon->setObjectName("fireCannon"); - connect(fireCannon, SIGNAL(entered()), tank, SLOT(fireCannon())); - setInitialState(fireCannon); - - m_goToLocation = new GoToLocationState(tank, this); - m_goToLocation->setObjectName("goToLocation"); - fireCannon->addTransition(tank, SIGNAL(actionCompleted()), m_goToLocation); - - m_turnToDirection = new QState(this); - m_turnToDirection->setObjectName("turnToDirection"); - m_goToLocation->addTransition(tank, SIGNAL(actionCompleted()), m_turnToDirection); - - QFinalState *finalState = new QFinalState(this); - finalState->setObjectName("finalState"); - m_turnToDirection->addTransition(tank, SIGNAL(actionCompleted()), finalState); - } - - void setDirection(qreal direction) - { - m_turnToDirection->assignProperty(m_tank, "direction", direction); - } - - void setDistance(qreal distance) - { - m_goToLocation->setDistance(distance); - } - -private: - QObject *m_tank; - GoToLocationState *m_goToLocation; - QState *m_turnToDirection; - -}; - -class TankSpottedTransition: public QSignalTransition -{ -public: - TankSpottedTransition(QObject *tank, ChaseState *target) : QSignalTransition(tank, SIGNAL(tankSpotted(qreal,qreal))), m_chase(target) - { - setTargetState(target); - } - -protected: - bool eventTest(QEvent *event) - { - bool b = QSignalTransition::eventTest(event); - if (b) { - QSignalEvent *se = static_cast(event); - m_chase->setDirection(se->arguments().at(0).toDouble()); - m_chase->setDistance(se->arguments().at(1).toDouble()); - } - return b; - } - -private: - ChaseState *m_chase; -}; - -class SeekAi: public QObject, public Plugin -{ - Q_OBJECT - Q_INTERFACES(Plugin) -public: - SeekAi() { setObjectName("Seek and destroy"); } - - virtual QState *create(QState *parentState, QObject *tank); -}; - -#endif diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro deleted file mode 100644 index 0d8bf2e..0000000 --- a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -INCLUDEPATH += ../.. -HEADERS = seek_ai.h -SOURCES = seek_ai.cpp -TARGET = $$qtLibraryTarget(seek_ai) -DESTDIR = ../../tankgame/plugins - -#! [0] -# install -target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS seek_ai.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/seek_ai \ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp deleted file mode 100644 index 4e71285..0000000 --- a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "spin_ai.h" - -#include - -QState *SpinAi::create(QState *parentState, QObject *tank) -{ - QState *topLevel = new QState(parentState); - QState *spinState = new SpinState(tank, topLevel); - topLevel->setInitialState(spinState); - - // When tank is spotted, fire two times and go back to spin state - QState *fireState = new QState(topLevel); - - QState *fireOnce = new QState(fireState); - fireState->setInitialState(fireOnce); - connect(fireOnce, SIGNAL(entered()), tank, SLOT(fireCannon())); - - QState *fireTwice = new QState(fireState); - connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon())); - - fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice); - fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState); - - spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState); - - return topLevel; -} - -Q_EXPORT_PLUGIN2(spin_ai, SpinAi) diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h deleted file mode 100644 index a97024d..0000000 --- a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SPIN_AI_H -#define SPIN_AI_H - -#include - -#include -#include -#include - -class SpinState: public QState -{ - Q_OBJECT -public: - SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank) - { - } - -public slots: - void spin() - { - m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0); - } - -protected: - void onEntry(QEvent *) - { - connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); - spin(); - } - - void onExit(QEvent *) - { - disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); - } - -private: - QObject *m_tank; - -}; - -class SpinAi: public QObject, public Plugin -{ - Q_OBJECT - Q_INTERFACES(Plugin) -public: - SpinAi() { setObjectName("Spin and destroy"); } - - virtual QState *create(QState *parentState, QObject *tank); -}; - -#endif diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro deleted file mode 100644 index 8ab4da0..0000000 --- a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -INCLUDEPATH += ../.. -HEADERS = spin_ai.h -SOURCES = spin_ai.cpp -TARGET = $$qtLibraryTarget(spin_ai) -DESTDIR = ../../tankgame/plugins - -#! [0] -# install -target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spin_ai.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/spin_ai \ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp deleted file mode 100644 index 12a9656..0000000 --- a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "spin_ai_with_error.h" - -#include - -QState *SpinAiWithError::create(QState *parentState, QObject *tank) -{ - QState *topLevel = new QState(parentState); - QState *spinState = new SpinState(tank, topLevel); - topLevel->setInitialState(spinState); - - // When tank is spotted, fire two times and go back to spin state - // (no initial state set for fireState will lead to run-time error in machine) - QState *fireState = new QState(topLevel); - - QState *fireOnce = new QState(fireState); - connect(fireOnce, SIGNAL(entered()), tank, SLOT(fireCannon())); - - QState *fireTwice = new QState(fireState); - connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon())); - - fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice); - fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState); - - spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState); - - return topLevel; -} - -Q_EXPORT_PLUGIN2(spin_ai_with_error, SpinAiWithError) diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h deleted file mode 100644 index f35da26..0000000 --- a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples 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 http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SPIN_AI_WITH_ERROR_H -#define SPIN_AI_WITH_ERROR_H - -#include - -#include -#include -#include - -class SpinState: public QState -{ - Q_OBJECT -public: - SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank) - { - } - -public slots: - void spin() - { - m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0); - } - -protected: - void onEntry(QEvent *) - { - connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); - spin(); - } - - void onExit(QEvent *) - { - disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); - } - -private: - QObject *m_tank; - -}; - -class SpinAiWithError: public QObject, public Plugin -{ - Q_OBJECT - Q_INTERFACES(Plugin) -public: - SpinAiWithError() { setObjectName("Spin and destroy with runtime error in state machine"); } - - virtual QState *create(QState *parentState, QObject *tank); -}; - -#endif diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro deleted file mode 100644 index 124cf98..0000000 --- a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -INCLUDEPATH += ../.. -HEADERS = spin_ai_with_error.h -SOURCES = spin_ai_with_error.cpp -TARGET = $$qtLibraryTarget(spin_ai_with_error) -DESTDIR = ../../tankgame/plugins - -#! [0] -# install -target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spin_ai_with_error.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/spin_ai_with_error \ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/tankgameplugins.pro b/examples/statemachine/tankgameplugins/tankgameplugins.pro deleted file mode 100644 index a098e03..0000000 --- a/examples/statemachine/tankgameplugins/tankgameplugins.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = random_ai \ - spin_ai_with_error \ - spin_ai \ - seek_ai - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tankgameplugins.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins -INSTALLS += target sources -- cgit v0.12