From a3497fbde4efd0634c8a5ba452e6278cae836b90 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Tue, 28 Jul 2009 12:21:30 +0200 Subject: Fix menubar item size incorrect with icon When you have an icon set we do not show the text label, but the previous code would still use the text for the size hint calculation. Task-number: 218836 Reviewed-by: ogoffart --- src/gui/widgets/qmenubar.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 1cfb9b3..a3964f7 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -446,13 +446,12 @@ void QMenuBarPrivate::calcActionRects(int max_width, int start) const continue; //we don't really position these! } else { const QString s = action->text(); - if(!s.isEmpty()) { - sz = fm.size(Qt::TextShowMnemonic, s); - } - QIcon is = action->icon(); + // If an icon is set, only the icon is visible if (!is.isNull()) sz = sz.expandedTo(QSize(icone, icone)); + else if (!s.isEmpty()) + sz = fm.size(Qt::TextShowMnemonic, s); } //let the style modify the above size.. -- cgit v0.12 From e1e83e28f66c5cd500ab2961f59840a4e47e80c4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 28 Jul 2009 12:50:07 +0200 Subject: Fix webkit import from the trunk Exclude more files from the import that are not needed for the Qt build, and include jsc for qtscript debugging. Reviewed-by: Trust me --- util/webkit/mkdist-webkit | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/util/webkit/mkdist-webkit b/util/webkit/mkdist-webkit index a843c83..f4b36d0 100755 --- a/util/webkit/mkdist-webkit +++ b/util/webkit/mkdist-webkit @@ -47,6 +47,7 @@ excluded_directories="$excluded_directories JavaScriptCore/wtf/gtk" excluded_directories="$excluded_directories JavaScriptCore/wtf/mac" excluded_directories="$excluded_directories JavaScriptCore/wtf/win" excluded_directories="$excluded_directories JavaScriptCore/wtf/chromium" +excluded_directories="$excluded_directories JavaScriptCore/wtf/haiku" excluded_directories="$excluded_directories WebCore/WebCore.vcproj" excluded_directories="$excluded_directories WebCore/DerivedSources.make" @@ -68,21 +69,28 @@ excluded_directories="$excluded_directories WebCore/icu" excluded_directories="$excluded_directories WebCore/loader/mac" excluded_directories="$excluded_directories WebCore/loader/win" +excluded_directories="$excluded_directories WebCore/loader/icon/wince" excluded_directories="$excluded_directories WebCore/page/gtk" excluded_directories="$excluded_directories WebCore/page/mac" excluded_directories="$excluded_directories WebCore/page/wx" excluded_directories="$excluded_directories WebCore/page/chromium" +excluded_directories="$excluded_directories WebCore/page/haiku" excluded_directories="$excluded_directories WebCore/history/mac" excluded_directories="$excluded_directories WebCore/editing/mac" excluded_directories="$excluded_directories WebCore/editing/wx" +excluded_directories="$excluded_directories WebCore/editing/haiku" + +excluded_directories="$excluded_directories WebCore/platform/haiku" excluded_directories="$excluded_directories WebCore/platform/text/wx" excluded_directories="$excluded_directories WebCore/platform/text/gtk" excluded_directories="$excluded_directories WebCore/platform/text/chromium" +excluded_directories="$excluded_directories WebCore/platform/text/haiku" +excluded_directories="$excluded_directories WebCore/platform/sql/chromium" excluded_directories="$excluded_directories WebCore/manual-tests" @@ -101,6 +109,7 @@ excluded_directories="$excluded_directories WebCore/platform/graphics/mac" excluded_directories="$excluded_directories WebCore/platform/graphics/win" excluded_directories="$excluded_directories WebCore/platform/graphics/skia" excluded_directories="$excluded_directories WebCore/platform/graphics/chromium" +excluded_directories="$excluded_directories WebCore/platform/graphics/wince" excluded_directories="$excluded_directories WebCore/platform/image-decoders/bmp" excluded_directories="$excluded_directories WebCore/platform/image-decoders/gif" @@ -110,6 +119,7 @@ excluded_directories="$excluded_directories WebCore/platform/image-decoders/ico" excluded_directories="$excluded_directories WebCore/platform/image-decoders/jpeg" excluded_directories="$excluded_directories WebCore/platform/image-decoders/xbm" excluded_directories="$excluded_directories WebCore/platform/image-decoders/skia" +excluded_directories="$excluded_directories WebCore/platform/image-decoders/haiku" excluded_directories="$excluded_directories WebCore/platform/image-encoders/skia" @@ -122,12 +132,16 @@ excluded_directories="$excluded_directories WebCore/accessibility/mac" excluded_directories="$excluded_directories WebCore/accessibility/win" excluded_directories="$excluded_directories WebCore/accessibility/wx" +excluded_directories="$excluded_directories WebCore/storage/wince" +excluded_directories="$excluded_directories WebCore/svg/graphics/wince" + excluded_directories="$excluded_directories WebCore/platform/wx" excluded_directories="$excluded_directories WebKit/gtk" excluded_directories="$excluded_directories WebKit/win" excluded_directories="$excluded_directories WebKit/mac" excluded_directories="$excluded_directories WebKit/wx" excluded_directories="$excluded_directories WebKit/cf" +excluded_directories="$excluded_directories WebKit/haiku" excluded_directories="$excluded_directories WebKit/English.lproj WebKit/WebKit.xcodeproj" excluded_directories="$excluded_directories WebCore/English.lproj" @@ -147,8 +161,6 @@ files_to_remove="$files_to_remove configure.ac" files_to_remove="$files_to_remove WebKit.pro" -files_to_remove="$files_to_remove JavaScriptCore/jsc.pro" - files_to_remove="$files_to_remove WebKit/qt/QtLauncher/QtLauncher.pro" files_to_remove="$files_to_remove WebKit/qt/QtLauncher/main.cpp" -- cgit v0.12 From 2d9448d1c9bcf843e36931a9109fd9bd8d42b2be Mon Sep 17 00:00:00 2001 From: ck Date: Tue, 28 Jul 2009 14:44:50 +0200 Subject: Assistant/helpconverter: Remove hard-coded version check in ADP file. The AdpReader checked for a version attribute == 3.2.0. This has been replaced by a check for >= 3.2.0 Task-number: 258551 Reviewed-by: kh --- tools/assistant/tools/qhelpconverter/adpreader.cpp | 20 ++++++++++++++------ tools/assistant/tools/qhelpconverter/adpreader.h | 6 +++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/assistant/tools/qhelpconverter/adpreader.cpp b/tools/assistant/tools/qhelpconverter/adpreader.cpp index 35f8878..c427038 100644 --- a/tools/assistant/tools/qhelpconverter/adpreader.cpp +++ b/tools/assistant/tools/qhelpconverter/adpreader.cpp @@ -39,8 +39,16 @@ ** ****************************************************************************/ +#include + #include "adpreader.h" +static bool versionIsAtLeast320(const QString &version) +{ + return QRegExp("\\d.\\d\\.\\d").exactMatch(version) + && (version[0] > '3' || (version[0] == '3' && version[2] >= '2')); +} + QT_BEGIN_NAMESPACE void AdpReader::readData(const QByteArray &contents) @@ -51,11 +59,11 @@ void AdpReader::readData(const QByteArray &contents) m_properties.clear(); m_files.clear(); addData(contents); - while (!atEnd()) { - readNext(); - if (isStartElement()) { + while (!atEnd()) { + readNext(); + if (isStartElement()) { if (name().toString().toLower() == QLatin1String("assistantconfig") - && attributes().value(QLatin1String("version")) == QLatin1String("3.2.0")) { + && versionIsAtLeast320(attributes().value(QLatin1String("version")).toString())) { readProject(); } else if (name().toString().toLower() == QLatin1String("dcf")) { QString ref = attributes().value(QLatin1String("ref")).toString(); @@ -66,8 +74,8 @@ void AdpReader::readData(const QByteArray &contents) } else { raiseError(); } - } - } + } + } } QList AdpReader::contents() const diff --git a/tools/assistant/tools/qhelpconverter/adpreader.h b/tools/assistant/tools/qhelpconverter/adpreader.h index f2e7509..740a462 100644 --- a/tools/assistant/tools/qhelpconverter/adpreader.h +++ b/tools/assistant/tools/qhelpconverter/adpreader.h @@ -50,15 +50,15 @@ QT_BEGIN_NAMESPACE struct ContentItem { ContentItem(const QString &t, const QString &r, int d) - : title(t), reference(r), depth(d) {} + : title(t), reference(r), depth(d) {} QString title; QString reference; - int depth; + int depth; }; struct KeywordItem { KeywordItem(const QString &k, const QString &r) - : keyword(k), reference(r) {} + : keyword(k), reference(r) {} QString keyword; QString reference; }; -- cgit v0.12 From e61e40d1b89ef13d4cd65853df859945c357af93 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Tue, 28 Jul 2009 15:04:16 +0200 Subject: qdoc: Added superscript obsolete to obsolete links. Only for obsolete links from non-obsolete things. --- tools/qdoc3/htmlgenerator.cpp | 13 +++++++++++-- tools/qdoc3/htmlgenerator.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index ab74f13..f92391e 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -2881,7 +2881,9 @@ QString HtmlGenerator::highlightedCode(const QString& markedCode, } #endif -void HtmlGenerator::generateLink(const Atom *atom, const Node * /* relative */, CodeMarker *marker) +void HtmlGenerator::generateLink(const Atom* atom, + const Node* /* relative */, + CodeMarker* marker) { static QRegExp camelCase("[A-Z][A-Z][a-z]|[a-z][A-Z0-9]|_"); @@ -3472,6 +3474,7 @@ QString HtmlGenerator::getLink(const Atom *atom, { QString link; *node = 0; + inObsoleteLink = false; if (atom->string().contains(":") && (atom->string().startsWith("file:") @@ -3530,10 +3533,12 @@ QString HtmlGenerator::getLink(const Atom *atom, porting = true; } QString name = marker->plainFullName(relative); - if (!porting && !name.startsWith("Q3")) + if (!porting && !name.startsWith("Q3")) { relative->doc().location().warning(tr("Link to obsolete item '%1' in %2") .arg(atom->string()) .arg(name)); + inObsoleteLink = true; + } #if 0 qDebug() << "Link to Obsolete entity" << (*node)->name(); @@ -3689,10 +3694,14 @@ void HtmlGenerator::endLink() out() << ""; } else { + if (inObsoleteLink) { + out() << "(obsolete)"; + } out() << ""; } } inLink = false; + inObsoleteLink = false; } QT_END_NAMESPACE diff --git a/tools/qdoc3/htmlgenerator.h b/tools/qdoc3/htmlgenerator.h index a7f4009..a7632cd 100644 --- a/tools/qdoc3/htmlgenerator.h +++ b/tools/qdoc3/htmlgenerator.h @@ -230,6 +230,7 @@ class HtmlGenerator : public PageGenerator DcfSection dcfQmakeRoot; HelpProjectWriter *helpProjectWriter; bool inLink; + bool inObsoleteLink; bool inContents; bool inSectionHeading; bool inTableHeader; -- cgit v0.12 From 8e9921c43ae0b896aee091e1031b4f42c332332b Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 28 Jul 2009 15:44:48 +0200 Subject: Fixes doc typos and indentation in abstractitemview & itemselectionmodel Reviewed-by: Trustme --- src/gui/itemviews/qabstractitemview.cpp | 152 +++++++------- src/gui/itemviews/qitemselectionmodel.cpp | 322 +++++++++++++++--------------- 2 files changed, 236 insertions(+), 238 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 8887977..8b6b5cb 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -851,8 +851,8 @@ QAbstractItemDelegate *QAbstractItemView::itemDelegateForColumn(int column) cons } /*! - Returns the item delegate used by this view and model for - the given \a index. + Returns the item delegate used by this view and model for + the given \a index. */ QAbstractItemDelegate *QAbstractItemView::itemDelegate(const QModelIndex &index) const { @@ -861,14 +861,14 @@ QAbstractItemDelegate *QAbstractItemView::itemDelegate(const QModelIndex &index) } /*! - \property QAbstractItemView::selectionMode - \brief which selection mode the view operates in + \property QAbstractItemView::selectionMode + \brief which selection mode the view operates in - This property controls whether the user can select one or many items - and, in many-item selections, whether the selection must be a - continuous range of items. + This property controls whether the user can select one or many items + and, in many-item selections, whether the selection must be a + continuous range of items. - \sa SelectionMode SelectionBehavior + \sa SelectionMode SelectionBehavior */ void QAbstractItemView::setSelectionMode(SelectionMode mode) { @@ -883,13 +883,13 @@ QAbstractItemView::SelectionMode QAbstractItemView::selectionMode() const } /*! - \property QAbstractItemView::selectionBehavior - \brief which selection behavior the view uses + \property QAbstractItemView::selectionBehavior + \brief which selection behavior the view uses - This property holds whether selections are done - in terms of single items, rows or columns. + This property holds whether selections are done + in terms of single items, rows or columns. - \sa SelectionMode SelectionBehavior + \sa SelectionMode SelectionBehavior */ void QAbstractItemView::setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior) @@ -990,11 +990,11 @@ QModelIndex QAbstractItemView::rootIndex() const } /*! - Selects all item in the view. - This function wil use the selection selection behavior - set on the view when selecting. + Selects all items in the view. + This function will use the selection behavior + set on the view when selecting. - \sa setSelection(), selectedIndexes(), clearSelection() + \sa setSelection(), selectedIndexes(), clearSelection() */ void QAbstractItemView::selectAll() { @@ -1223,10 +1223,10 @@ bool QAbstractItemView::tabKeyNavigation() const #ifndef QT_NO_DRAGANDDROP /*! - \property QAbstractItemView::showDropIndicator - \brief whether the drop indicator is shown when dragging items and dropping. + \property QAbstractItemView::showDropIndicator + \brief whether the drop indicator is shown when dragging items and dropping. - \sa dragEnabled DragDropMode dragDropOverwriteMode acceptDrops + \sa dragEnabled DragDropMode dragDropOverwriteMode acceptDrops */ void QAbstractItemView::setDropIndicatorShown(bool enable) @@ -1242,10 +1242,10 @@ bool QAbstractItemView::showDropIndicator() const } /*! - \property QAbstractItemView::dragEnabled - \brief whether the view supports dragging of its own items + \property QAbstractItemView::dragEnabled + \brief whether the view supports dragging of its own items - \sa showDropIndicator DragDropMode dragDropOverwriteMode acceptDrops + \sa showDropIndicator DragDropMode dragDropOverwriteMode acceptDrops */ void QAbstractItemView::setDragEnabled(bool enable) @@ -1281,11 +1281,11 @@ bool QAbstractItemView::dragEnabled() const */ /*! - \property QAbstractItemView::dragDropMode - \brief the drag and drop event the view will act upon + \property QAbstractItemView::dragDropMode + \brief the drag and drop event the view will act upon - \since 4.2 - \sa showDropIndicator dragDropOverwriteMode + \since 4.2 + \sa showDropIndicator dragDropOverwriteMode */ void QAbstractItemView::setDragDropMode(DragDropMode behavior) { @@ -1321,14 +1321,14 @@ QAbstractItemView::DragDropMode QAbstractItemView::dragDropMode() const #endif // QT_NO_DRAGANDDROP /*! - \property QAbstractItemView::alternatingRowColors - \brief whether to draw the background using alternating colors + \property QAbstractItemView::alternatingRowColors + \brief whether to draw the background using alternating colors - If this property is true, the item background will be drawn using - QPalette::Base and QPalette::AlternateBase; otherwise the background - will be drawn using the QPalette::Base color. + If this property is true, the item background will be drawn using + QPalette::Base and QPalette::AlternateBase; otherwise the background + will be drawn using the QPalette::Base color. - By default, this property is false. + By default, this property is false. */ void QAbstractItemView::setAlternatingRowColors(bool enable) { @@ -2257,8 +2257,8 @@ void QAbstractItemView::inputMethodEvent(QInputMethodEvent *event) \value BelowItem The item will be dropped below the index. \value OnViewport The item will be dropped onto a region of the viewport with -no items. The way each view handles items dropped onto the viewport depends on -the behavior of the underlying model in use. + no items. The way each view handles items dropped onto the viewport depends on + the behavior of the underlying model in use. */ @@ -2275,11 +2275,11 @@ QAbstractItemView::DropIndicatorPosition QAbstractItemView::dropIndicatorPositio #endif /*! - This convenience function returns a list of all selected and - non-hidden item indexes in the view. The list contains no - duplicates, and is not sorted. + This convenience function returns a list of all selected and + non-hidden item indexes in the view. The list contains no + duplicates, and is not sorted. - \sa QItemSelectionModel::selectedIndexes() + \sa QItemSelectionModel::selectedIndexes() */ QModelIndexList QAbstractItemView::selectedIndexes() const { @@ -2361,8 +2361,8 @@ bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEve } /*! - \internal - Updates the data shown in the open editor widgets in the view. + \internal + Updates the data shown in the open editor widgets in the view. */ void QAbstractItemView::updateEditorData() { @@ -2371,8 +2371,8 @@ void QAbstractItemView::updateEditorData() } /*! - \internal - Updates the geometry of the open editor widgets in the view. + \internal + Updates the geometry of the open editor widgets in the view. */ void QAbstractItemView::updateEditorGeometries() { @@ -2421,7 +2421,7 @@ void QAbstractItemView::updateGeometries() } /*! - \internal + \internal */ void QAbstractItemView::verticalScrollbarValueChanged(int value) { @@ -2432,7 +2432,7 @@ void QAbstractItemView::verticalScrollbarValueChanged(int value) } /*! - \internal + \internal */ void QAbstractItemView::horizontalScrollbarValueChanged(int value) { @@ -2534,9 +2534,9 @@ void QAbstractItemView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndE } /*! - Commit the data in the \a editor to the model. + Commit the data in the \a editor to the model. - \sa closeEditor() + \sa closeEditor() */ void QAbstractItemView::commitData(QWidget *editor) { @@ -2555,9 +2555,9 @@ void QAbstractItemView::commitData(QWidget *editor) } /*! - This function is called when the given \a editor has been destroyed. + This function is called when the given \a editor has been destroyed. - \sa closeEditor() + \sa closeEditor() */ void QAbstractItemView::editorDestroyed(QObject *editor) { @@ -2628,12 +2628,12 @@ int QAbstractItemView::verticalStepsPerItem() const } /*! - Moves to and selects the item best matching the string \a search. - If no item is found nothing happens. + Moves to and selects the item best matching the string \a search. + If no item is found nothing happens. - In the default implementation, the search is reset if \a search is empty, or - the time interval since the last search has exceeded - QApplication::keyboardInputInterval(). + In the default implementation, the search is reset if \a search is empty, or + the time interval since the last search has exceeded + QApplication::keyboardInputInterval(). */ void QAbstractItemView::keyboardSearch(const QString &search) { @@ -2687,9 +2687,9 @@ void QAbstractItemView::keyboardSearch(const QString &search) setCurrentIndex(firstMatch); break; } - int row = firstMatch.row() + 1; - if (row >= d->model->rowCount(firstMatch.parent())) - row = 0; + int row = firstMatch.row() + 1; + if (row >= d->model->rowCount(firstMatch.parent())) + row = 0; current = firstMatch.sibling(row, firstMatch.column()); } } while (current != start && firstMatch.isValid()); @@ -2796,9 +2796,9 @@ void QAbstractItemView::openPersistentEditor(const QModelIndex &index) } /*! - Closes the persistent editor for the item at the given \a index. + Closes the persistent editor for the item at the given \a index. - \sa openPersistentEditor() + \sa openPersistentEditor() */ void QAbstractItemView::closePersistentEditor(const QModelIndex &index) { @@ -3333,14 +3333,14 @@ void QAbstractItemView::setDirtyRegion(const QRegion ®ion) } /*! - Prepares the view for scrolling by (\a{dx},\a{dy}) pixels by moving the dirty regions in the - opposite direction. You only need to call this function if you are implementing a scrolling - viewport in your view subclass. + Prepares the view for scrolling by (\a{dx},\a{dy}) pixels by moving the dirty regions in the + opposite direction. You only need to call this function if you are implementing a scrolling + viewport in your view subclass. - If you implement scrollContentsBy() in a subclass of QAbstractItemView, call this function - before you call QWidget::scroll() on the viewport. Alternatively, just call update(). + If you implement scrollContentsBy() in a subclass of QAbstractItemView, call this function + before you call QWidget::scroll() on the viewport. Alternatively, just call update(). - \sa scrollContentsBy(), dirtyRegionOffset(), setDirtyRegion() + \sa scrollContentsBy(), dirtyRegionOffset(), setDirtyRegion() */ void QAbstractItemView::scrollDirtyRegion(int dx, int dy) { @@ -3349,13 +3349,13 @@ void QAbstractItemView::scrollDirtyRegion(int dx, int dy) } /*! - Returns the offset of the dirty regions in the view. + Returns the offset of the dirty regions in the view. - If you use scrollDirtyRegion() and implement a paintEvent() in a subclass of - QAbstractItemView, you should translate the area given by the paint event with - the offset returned from this function. + If you use scrollDirtyRegion() and implement a paintEvent() in a subclass of + QAbstractItemView, you should translate the area given by the paint event with + the offset returned from this function. - \sa scrollDirtyRegion(), setDirtyRegion() + \sa scrollDirtyRegion(), setDirtyRegion() */ QPoint QAbstractItemView::dirtyRegionOffset() const { @@ -3527,7 +3527,7 @@ QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionC const bool shiftKeyPressed = modifiers & Qt::ShiftModifier; const bool controlKeyPressed = modifiers & Qt::ControlModifier; if (((index == pressedIndex && selectionModel->isSelected(index)) - || !index.isValid()) && state != QAbstractItemView::DragSelectingState + || !index.isValid()) && state != QAbstractItemView::DragSelectingState && !shiftKeyPressed && !controlKeyPressed && !rightButtonPressed) return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); return QItemSelectionModel::NoUpdate; @@ -3759,7 +3759,7 @@ void QAbstractItemViewPrivate::updateEditorData(const QModelIndex &tl, const QMo but the behavior is view dependant (table just clears the selected indexes for example). Either remove the selected rows or clear them - */ +*/ void QAbstractItemViewPrivate::clearOrRemove() { #ifndef QT_NO_DRAGANDDROP @@ -3795,7 +3795,7 @@ void QAbstractItemViewPrivate::clearOrRemove() When persistent aeditor gets/loses focus, we need to check and setcorrectly the current index. - */ +*/ void QAbstractItemViewPrivate::checkPersistentEditorFocus() { Q_Q(QAbstractItemView); @@ -3882,10 +3882,10 @@ bool QAbstractItemViewPrivate::openEditor(const QModelIndex &index, QEvent *even } /* - \internal + \internal - returns the pair QRect/QModelIndex that should be painted on the viewports's rect - */ + returns the pair QRect/QModelIndex that should be painted on the viewports's rect +*/ QItemViewPaintPairs QAbstractItemViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const { diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp index 87825d9..9dad95f 100644 --- a/src/gui/itemviews/qitemselectionmodel.cpp +++ b/src/gui/itemviews/qitemselectionmodel.cpp @@ -303,45 +303,44 @@ QModelIndexList QItemSelectionRange::indexes() const } /*! - \class QItemSelection + \class QItemSelection - \brief The QItemSelection class manages information about selected items in a model. + \brief The QItemSelection class manages information about selected items in a model. - \ingroup model-view - - A QItemSelection describes the items in a model that have been - selected by the user. A QItemSelection is basically a list of - selection ranges, see QItemSelectionRange. It provides functions for - creating and manipulating selections, and selecting a range of items - from a model. + \ingroup model-view - The QItemSelection class is one of the \l{Model/View Classes} - and is part of Qt's \l{Model/View Programming}{model/view framework}. + A QItemSelection describes the items in a model that have been + selected by the user. A QItemSelection is basically a list of + selection ranges, see QItemSelectionRange. It provides functions for + creating and manipulating selections, and selecting a range of items + from a model. - An item selection can be constructed and initialized to contain a - range of items from an existing model. The following example constructs - a selection that contains a range of items from the given \c model, - beginning at the \c topLeft, and ending at the \c bottomRight. + The QItemSelection class is one of the \l{Model/View Classes} + and is part of Qt's \l{Model/View Programming}{model/view framework}. - \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 0 + An item selection can be constructed and initialized to contain a + range of items from an existing model. The following example constructs + a selection that contains a range of items from the given \c model, + beginning at the \c topLeft, and ending at the \c bottomRight. - An empty item selection can be constructed, and later populated as - required. So, if the model is going to be unavailable when we construct - the item selection, we can rewrite the above code in the following way: + \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 0 - \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 1 + An empty item selection can be constructed, and later populated as + required. So, if the model is going to be unavailable when we construct + the item selection, we can rewrite the above code in the following way: - QItemSelection saves memory, and avoids unnecessary work, by working with - selection ranges rather than recording the model item index for each - item in the selection. Generally, an instance of this class will contain - a list of non-overlapping selection ranges. + \snippet doc/src/snippets/code/src_gui_itemviews_qitemselectionmodel.cpp 1 - Use merge() to merge one item selection into another without making - overlapping ranges. Use split() to split one selection range into - smaller ranges based on a another selection range. + QItemSelection saves memory, and avoids unnecessary work, by working with + selection ranges rather than recording the model item index for each + item in the selection. Generally, an instance of this class will contain + a list of non-overlapping selection ranges. - \sa {Model/View Programming}, QItemSelectionModel + Use merge() to merge one item selection into another without making + overlapping ranges. Use split() to split one selection range into + smaller ranges based on a another selection range. + \sa {Model/View Programming}, QItemSelectionModel */ /*! @@ -420,14 +419,14 @@ QModelIndexList QItemSelection::indexes() const } /*! - Merges the \a other selection with this QItemSelection using the - \a command given. This method guarantees that no ranges are overlapping. + Merges the \a other selection with this QItemSelection using the + \a command given. This method guarantees that no ranges are overlapping. - Note that only QItemSelectionModel::Select, - QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are - supported. + Note that only QItemSelectionModel::Select, + QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are + supported. - \sa split() + \sa split() */ void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command) { @@ -479,10 +478,10 @@ void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::Sel } /*! - Splits the selection \a range using the selection \a other range. - Removes all items in \a other from \a range and puts the result in \a result. - This can be compared with the semantics of the \e subtract operation of a set. - \sa merge() + Splits the selection \a range using the selection \a other range. + Removes all items in \a other from \a range and puts the result in \a result. + This can be compared with the semantics of the \e subtract operation of a set. + \sa merge() */ void QItemSelection::split(const QItemSelectionRange &range, @@ -529,11 +528,11 @@ void QItemSelection::split(const QItemSelectionRange &range, } /*! - \internal + \internal - returns a QItemSelection where all ranges have been expanded to: - Rows: left: 0 and right: columnCount()-1 - Columns: top: 0 and bottom: rowCount()-1 + returns a QItemSelection where all ranges have been expanded to: + Rows: left: 0 and right: columnCount()-1 + Columns: top: 0 and bottom: rowCount()-1 */ QItemSelection QItemSelectionModelPrivate::expandSelection(const QItemSelection &selection, @@ -568,7 +567,7 @@ QItemSelection QItemSelectionModelPrivate::expandSelection(const QItemSelection } /*! - \internal + \internal */ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) @@ -599,7 +598,7 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare } /*! - \internal + \internal */ void QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) @@ -630,9 +629,9 @@ void QItemSelectionModelPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &p } /*! - \internal + \internal - Split selection ranges if columns are about to be inserted in the middle. + Split selection ranges if columns are about to be inserted in the middle. */ void QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(const QModelIndex &parent, int start, int end) @@ -659,9 +658,9 @@ void QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(const QModelIndex & } /*! - \internal + \internal - Split selection ranges if rows are about to be inserted in the middle. + Split selection ranges if rows are about to be inserted in the middle. */ void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) @@ -688,11 +687,11 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(const QModelIndex &par } /*! - \internal + \internal - Split selection into individual (persistent) indexes. This is done in - preparation for the layoutChanged() signal, where the indexes can be - merged again. + Split selection into individual (persistent) indexes. This is done in + preparation for the layoutChanged() signal, where the indexes can be + merged again. */ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged() { @@ -726,10 +725,10 @@ void QItemSelectionModelPrivate::_q_layoutAboutToBeChanged() } /*! - \internal + \internal - Merges \a indexes into an item selection made up of ranges. - Assumes that the indexes are sorted. + Merges \a indexes into an item selection made up of ranges. + Assumes that the indexes are sorted. */ static QItemSelection mergeIndexes(const QList &indexes) { @@ -774,9 +773,9 @@ static QItemSelection mergeIndexes(const QList &indexes) } /*! - \internal + \internal - Merge the selected indexes into selection ranges again. + Merge the selected indexes into selection ranges again. */ void QItemSelectionModelPrivate::_q_layoutChanged() { @@ -818,41 +817,41 @@ void QItemSelectionModelPrivate::_q_layoutChanged() } /*! - \class QItemSelectionModel + \class QItemSelectionModel - \brief The QItemSelectionModel class keeps track of a view's selected items. + \brief The QItemSelectionModel class keeps track of a view's selected items. - \ingroup model-view + \ingroup model-view - A QItemSelectionModel keeps track of the selected items in a view, or - in several views onto the same model. It also keeps track of the - currently selected item in a view. + A QItemSelectionModel keeps track of the selected items in a view, or + in several views onto the same model. It also keeps track of the + currently selected item in a view. - The QItemSelectionModel class is one of the \l{Model/View Classes} - and is part of Qt's \l{Model/View Programming}{model/view framework}. + The QItemSelectionModel class is one of the \l{Model/View Classes} + and is part of Qt's \l{Model/View Programming}{model/view framework}. - The selected items are stored using ranges. Whenever you want to - modify the selected items use select() and provide either a - QItemSelection, or a QModelIndex and a QItemSelectionModel::SelectionFlag. + The selected items are stored using ranges. Whenever you want to + modify the selected items use select() and provide either a + QItemSelection, or a QModelIndex and a QItemSelectionModel::SelectionFlag. - The QItemSelectionModel takes a two layer approach to selection - management, dealing with both selected items that have been committed - and items that are part of the current selection. The current - selected items are part of the current interactive selection (for - example with rubber-band selection or keyboard-shift selections). + The QItemSelectionModel takes a two layer approach to selection + management, dealing with both selected items that have been committed + and items that are part of the current selection. The current + selected items are part of the current interactive selection (for + example with rubber-band selection or keyboard-shift selections). - To update the currently selected items, use the bitwise OR of - QItemSelectionModel::Current and any of the other SelectionFlags. - If you omit the QItemSelectionModel::Current command, a new current - selection will be created, and the previous one added to the whole - selection. All functions operate on both layers; for example, - selectedItems() will return items from both layers. + To update the currently selected items, use the bitwise OR of + QItemSelectionModel::Current and any of the other SelectionFlags. + If you omit the QItemSelectionModel::Current command, a new current + selection will be created, and the previous one added to the whole + selection. All functions operate on both layers; for example, + selectedItems() will return items from both layers. - \sa {Model/View Programming}, QAbstractItemModel, {Chart Example} + \sa {Model/View Programming}, QAbstractItemModel, {Chart Example} */ /*! - Constructs a selection model that operates on the specified item \a model. + Constructs a selection model that operates on the specified item \a model. */ QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model) : QObject(*new QItemSelectionModelPrivate, model) @@ -875,7 +874,7 @@ QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model) } /*! - Constructs a selection model that operates on the specified item \a model with \a parent. + Constructs a selection model that operates on the specified item \a model with \a parent. */ QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *parent) : QObject(*new QItemSelectionModelPrivate, parent) @@ -898,7 +897,7 @@ QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *par } /*! - \internal + \internal */ QItemSelectionModel::QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model) : QObject(dd, model) @@ -921,7 +920,7 @@ QItemSelectionModel::QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstra } /*! - Destroys the selection model. + Destroys the selection model. */ QItemSelectionModel::~QItemSelectionModel() { @@ -943,10 +942,10 @@ QItemSelectionModel::~QItemSelectionModel() } /*! - Selects the model item \a index using the specified \a command, and emits - selectionChanged(). + Selects the model item \a index using the specified \a command, and emits + selectionChanged(). - \sa QItemSelectionModel::SelectionFlags + \sa QItemSelectionModel::SelectionFlags */ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { @@ -955,37 +954,37 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: } /*! - \fn void QItemSelectionModel::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) + \fn void QItemSelectionModel::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) - This signal is emitted whenever the current item changes. The \a previous - model item index is replaced by the \a current index as the selection's - current item. + This signal is emitted whenever the current item changes. The \a previous + model item index is replaced by the \a current index as the selection's + current item. - Note that this signal will not be emitted when the item model is reset. + Note that this signal will not be emitted when the item model is reset. - \sa currentIndex() setCurrentIndex() selectionChanged() + \sa currentIndex() setCurrentIndex() selectionChanged() */ /*! - \fn void QItemSelectionModel::currentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous) + \fn void QItemSelectionModel::currentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous) - This signal is emitted if the \a current item changes and its column is - different to the column of the \a previous current item. + This signal is emitted if the \a current item changes and its column is + different to the column of the \a previous current item. - Note that this signal will not be emitted when the item model is reset. + Note that this signal will not be emitted when the item model is reset. - \sa currentChanged() currentRowChanged() currentIndex() setCurrentIndex() + \sa currentChanged() currentRowChanged() currentIndex() setCurrentIndex() */ /*! - \fn void QItemSelectionModel::currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) + \fn void QItemSelectionModel::currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) - This signal is emitted if the \a current item changes and its row is - different to the row of the \a previous current item. + This signal is emitted if the \a current item changes and its row is + different to the row of the \a previous current item. - Note that this signal will not be emitted when the item model is reset. + Note that this signal will not be emitted when the item model is reset. - \sa currentChanged() currentColumnChanged() currentIndex() setCurrentIndex() + \sa currentChanged() currentColumnChanged() currentIndex() setCurrentIndex() */ /*! @@ -1002,32 +1001,32 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel:: */ /*! - \enum QItemSelectionModel::SelectionFlag + \enum QItemSelectionModel::SelectionFlag - This enum describes the way the selection model will be updated. + This enum describes the way the selection model will be updated. - \value NoUpdate No selection will be made. - \value Clear The complete selection will be cleared. - \value Select All specified indexes will be selected. - \value Deselect All specified indexes will be deselected. - \value Toggle All specified indexes will be selected or - deselected depending on their current state. - \value Current The current selection will be updated. - \value Rows All indexes will be expanded to span rows. - \value Columns All indexes will be expanded to span columns. - \value SelectCurrent A combination of Select and Current, provided for - convenience. - \value ToggleCurrent A combination of Toggle and Current, provided for - convenience. - \value ClearAndSelect A combination of Clear and Select, provided for - convenience. + \value NoUpdate No selection will be made. + \value Clear The complete selection will be cleared. + \value Select All specified indexes will be selected. + \value Deselect All specified indexes will be deselected. + \value Toggle All specified indexes will be selected or + deselected depending on their current state. + \value Current The current selection will be updated. + \value Rows All indexes will be expanded to span rows. + \value Columns All indexes will be expanded to span columns. + \value SelectCurrent A combination of Select and Current, provided for + convenience. + \value ToggleCurrent A combination of Toggle and Current, provided for + convenience. + \value ClearAndSelect A combination of Clear and Select, provided for + convenience. */ /*! - Selects the item \a selection using the specified \a command, and emits - selectionChanged(). + Selects the item \a selection using the specified \a command, and emits + selectionChanged(). - \sa QItemSelectionModel::SelectionFlag + \sa QItemSelectionModel::SelectionFlag */ void QItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) { @@ -1067,7 +1066,7 @@ void QItemSelectionModel::select(const QItemSelection &selection, QItemSelection } /*! - Clears the selection model. Emits selectionChanged() and currentChanged(). + Clears the selection model. Emits selectionChanged() and currentChanged(). */ void QItemSelectionModel::clear() { @@ -1083,7 +1082,7 @@ void QItemSelectionModel::clear() } /*! - Clears the selection model. Does not emit any signals. + Clears the selection model. Does not emit any signals. */ void QItemSelectionModel::reset() { @@ -1093,8 +1092,8 @@ void QItemSelectionModel::reset() } /*! - \since 4.2 - Clears the selection in the selection model. Emits selectionChanged(). + \since 4.2 + Clears the selection in the selection model. Emits selectionChanged(). */ void QItemSelectionModel::clearSelection() { @@ -1110,14 +1109,14 @@ void QItemSelectionModel::clearSelection() /*! - Sets the model item \a index to be the current item, and emits - currentChanged(). The current item is used for keyboard navigation and - focus indication; it is independent of any selected items, although a - selected item can also be the current item. + Sets the model item \a index to be the current item, and emits + currentChanged(). The current item is used for keyboard navigation and + focus indication; it is independent of any selected items, although a + selected item can also be the current item. - Depending on the specified \a command, the \a index can also become part - of the current selection. - \sa select() + Depending on the specified \a command, the \a index can also become part + of the current selection. + \sa select() */ void QItemSelectionModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { @@ -1141,8 +1140,8 @@ void QItemSelectionModel::setCurrentIndex(const QModelIndex &index, QItemSelecti } /*! - Returns the model item index for the current item, or an invalid index - if there is no current item. + Returns the model item index for the current item, or an invalid index + if there is no current item. */ QModelIndex QItemSelectionModel::currentIndex() const { @@ -1150,7 +1149,7 @@ QModelIndex QItemSelectionModel::currentIndex() const } /*! - Returns true if the given model item \a index is selected. + Returns true if the given model item \a index is selected. */ bool QItemSelectionModel::isSelected(const QModelIndex &index) const { @@ -1187,12 +1186,12 @@ bool QItemSelectionModel::isSelected(const QModelIndex &index) const } /*! - Returns true if all items are selected in the \a row with the given - \a parent. + Returns true if all items are selected in the \a row with the given + \a parent. - Note that this function is usually faster than calling isSelected() - on all items in the same row and that unselectable items are - ignored. + Note that this function is usually faster than calling isSelected() + on all items in the same row and that unselectable items are + ignored. */ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) const { @@ -1247,12 +1246,12 @@ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) cons } /*! - Returns true if all items are selected in the \a column with the given - \a parent. + Returns true if all items are selected in the \a column with the given + \a parent. - Note that this function is usually faster than calling isSelected() - on all items in the same column and that unselectable items are - ignored. + Note that this function is usually faster than calling isSelected() + on all items in the same column and that unselectable items are + ignored. */ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent) const { @@ -1307,8 +1306,8 @@ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent } /*! - Returns true if there are any items selected in the \a row with the given - \a parent. + Returns true if there are any items selected in the \a row with the given + \a parent. */ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &parent) const { @@ -1336,8 +1335,8 @@ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &par } /*! - Returns true if there are any items selected in the \a column with the given - \a parent. + Returns true if there are any items selected in the \a column with the given + \a parent. */ bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelIndex &parent) const { @@ -1377,15 +1376,14 @@ bool QItemSelectionModel::hasSelection() const QItemSelection sel = d->ranges; sel.merge(d->currentSelection, d->currentCommand); return !sel.isEmpty(); - } - else { + } else { return !(d->ranges.isEmpty() && d->currentSelection.isEmpty()); } } /*! - Returns a list of all selected model item indexes. The list contains no - duplicates, and is not sorted. + Returns a list of all selected model item indexes. The list contains no + duplicates, and is not sorted. */ QModelIndexList QItemSelectionModel::selectedIndexes() const { @@ -1396,10 +1394,10 @@ QModelIndexList QItemSelectionModel::selectedIndexes() const } /*! - \since 4.2 - Returns the indexes in the given \a column for the rows where all columns are selected. + \since 4.2 + Returns the indexes in the given \a column for the rows where all columns are selected. - \sa selectedIndexes(), selectedColumns() + \sa selectedIndexes(), selectedColumns() */ QModelIndexList QItemSelectionModel::selectedRows(int column) const @@ -1460,7 +1458,7 @@ QModelIndexList QItemSelectionModel::selectedColumns(int row) const } /*! - Returns the selection ranges stored in the selection model. + Returns the selection ranges stored in the selection model. */ const QItemSelection QItemSelectionModel::selection() const { @@ -1480,7 +1478,7 @@ const QItemSelection QItemSelectionModel::selection() const } /*! - Returns the item model operated on by the selection model. + Returns the item model operated on by the selection model. */ const QAbstractItemModel *QItemSelectionModel::model() const { @@ -1488,8 +1486,8 @@ const QAbstractItemModel *QItemSelectionModel::model() const } /*! - Compares the two selections \a newSelection and \a oldSelection - and emits selectionChanged() with the deselected and selected items. + Compares the two selections \a newSelection and \a oldSelection + and emits selectionChanged() with the deselected and selected items. */ void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection) -- cgit v0.12 From 657044cefa87d092213308f2706c3770fb916eb7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 27 Jul 2009 20:50:05 +0200 Subject: Sun CC 5.9 does not support template friends But I'm told 5.10 does. --- src/corelib/global/qglobal.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 3625f2b..4ceabee 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -662,6 +662,9 @@ namespace QT_NAMESPACE {} // using CC 5.9: Warning: attribute visibility is unsupported and will be skipped.. //# define Q_DECL_EXPORT __attribute__((__visibility__("default"))) # endif +# if __SUNPRO_CC < 0x5a0 +# define Q_NO_TEMPLATE_FRIENDS +# endif # if !defined(_BOOL) # define Q_NO_BOOL_TYPE # endif -- cgit v0.12 From 096a0088aa75010c71a2a39dee5f3ee00d23fcf7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 27 Jul 2009 20:59:23 +0200 Subject: Disable the forwardDeclared1 test with SunCC: it doesn't work I added this test because I thought that the compiler would find the forward-declarations due to the "one definition" rule. In hindsight, it's not a good idea. Sun CC warns about this, gcc doesn't. With Sun CC, the code leaks, with gcc it doesn't. --- tests/auto/qsharedpointer/tst_qsharedpointer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp index dd53e3c..ae5155e 100644 --- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp @@ -231,6 +231,9 @@ extern int forwardDeclaredDestructorRunCount; void tst_QSharedPointer::forwardDeclaration1() { +#if defined(Q_CC_SUN) + QSKIP("This type of forward declaration is not valid with this compiler", SkipAll); +#else externalForwardDeclaration(); struct Wrapper { QSharedPointer pointer; }; @@ -242,6 +245,7 @@ void tst_QSharedPointer::forwardDeclaration1() QVERIFY(!w.pointer.isNull()); } QCOMPARE(forwardDeclaredDestructorRunCount, 1); +#endif } #include "forwarddeclared.h" -- cgit v0.12 From 745e12297f0133a6bd54e2809540c47370b405a5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 27 Jul 2009 21:00:58 +0200 Subject: Work around weird issue with Sun CC 5.9: Self was the wrong class. I don't know if this was only the debugging symbols or if the compiler was really wrong. But while debugging, Self was ExternalRefCountWithCustomDeleter, which is wrong at this point. --- src/corelib/tools/qsharedpointer_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 630ca4f..3d7a0e6 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -235,7 +235,6 @@ namespace QtSharedPointer { struct ExternalRefCountWithContiguousData: public ExternalRefCountWithDestroyFn { typedef ExternalRefCountWithDestroyFn Parent; - typedef ExternalRefCountWithContiguousData Self; T data; static void deleter(ExternalRefCountData *self) @@ -248,7 +247,8 @@ namespace QtSharedPointer { static inline ExternalRefCountData *create(T **ptr) { DestroyerFn destroy = &deleter; - Self *d = static_cast(::operator new(sizeof(Self))); + ExternalRefCountWithContiguousData *d = + static_cast(::operator new(sizeof(ExternalRefCountWithContiguousData))); // initialize the d-pointer sub-object // leave d->data uninitialized -- cgit v0.12 From 3a0eccfe7237fe69e41580d1fb780342f4c09691 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Jul 2009 10:56:12 +0200 Subject: Fix startDetached: the pipes must be CLOEXEC for them to work. In de05f9a40e41deb79daf5c4935b2645d70d7f322 I removed the fcntl that set FD_CLOEXEC because it was supposed to be set by qt_safe_pipe. Turns out that this code didn't call the wrapper function... Reviewed-by: ossi --- src/corelib/io/qprocess_unix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index fafce07..607b734 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -1161,10 +1161,10 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a // To catch the startup of the child int startedPipe[2]; - ::pipe(startedPipe); + qt_safe_pipe(startedPipe); // To communicate the pid of the child int pidPipe[2]; - ::pipe(pidPipe); + qt_safe_pipe(pidPipe); pid_t childPid = qt_fork(); if (childPid == 0) { -- cgit v0.12 From 9a21c1abb96426b7a9f168b007d05db303a8de65 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Jul 2009 12:49:33 +0200 Subject: Implement a new pointer-tracking mechanism for QSharedPointer. Some compilers don't obey the same rules of "top-of-object" values for casting a pointer from a given class to void *. In any case, that can only work for polymorphic types (with a virtual table). So don't track the pointers by their pointer value, but instead by the d-pointer of the QSharedPointer object. The same cases that were caught before should still be caught. We still won't catch the creating a second QSharedPointer for the same object if the pointer values are different, though (when cast to void*). Reviewed-by: Bradley T. Hughes --- src/corelib/tools/qsharedpointer.cpp | 113 ++++++++++++++++++++++++-------- src/corelib/tools/qsharedpointer_impl.h | 33 +++++----- 2 files changed, 105 insertions(+), 41 deletions(-) diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 85085c5..59dfffe 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -803,29 +803,19 @@ # endif # endif -# if !defined(BACKTRACE_SUPPORTED) -// Dummy implementation of the functions. -// Using QHashDummyValue also means that the QHash below is actually a QSet -typedef QT_PREPEND_NAMESPACE(QHashDummyValue) Backtrace; - -static inline Backtrace saveBacktrace() { return Backtrace(); } -static inline void printBacktrace(Backtrace) { } - -# else +# if defined(BACKTRACE_SUPPORTED) # include # include # include # include # include -typedef QT_PREPEND_NAMESPACE(QByteArray) Backtrace; - -static inline Backtrace saveBacktrace() __attribute__((always_inline)); -static inline Backtrace saveBacktrace() +static inline QByteArray saveBacktrace() __attribute__((always_inline)); +static inline QByteArray saveBacktrace() { static const int maxFrames = 32; - Backtrace stacktrace; + QByteArray stacktrace; stacktrace.resize(sizeof(void*) * maxFrames); int stack_size = backtrace((void**)stacktrace.data(), maxFrames); stacktrace.resize(sizeof(void*) * stack_size); @@ -833,7 +823,7 @@ static inline Backtrace saveBacktrace() return stacktrace; } -static void printBacktrace(Backtrace stacktrace) +static void printBacktrace(QByteArray stacktrace) { void *const *stack = (void *const *)stacktrace.constData(); int stack_size = stacktrace.size() / sizeof(void*); @@ -884,11 +874,19 @@ static void printBacktrace(Backtrace stacktrace) namespace { QT_USE_NAMESPACE + struct Data { + const volatile void *pointer; +# ifdef BACKTRACE_SUPPORTED + QByteArray backtrace; +# endif + }; + class KnownPointers { public: QMutex mutex; - QHash values; + QHash dPointers; + QHash dataPointers; }; } @@ -896,38 +894,101 @@ Q_GLOBAL_STATIC(KnownPointers, knownPointers) QT_BEGIN_NAMESPACE +namespace QtSharedPointer { + Q_CORE_EXPORT void internalSafetyCheckAdd(const volatile void *); + Q_CORE_EXPORT void internalSafetyCheckRemove(const volatile void *); +} + +/*! + \internal +*/ +void QtSharedPointer::internalSafetyCheckAdd(const volatile void *) +{ + // Qt 4.5 compatibility + // this function is broken by design, so it was replaced with internalSafetyCheckAdd2 + // + // it's broken because we tracked the pointers added and + // removed from QSharedPointer, converted to void*. + // That is, this is supposed to track the "top-of-object" pointer in + // case of multiple inheritance. + // + // However, it doesn't work well in some compilers: + // if you create an object with a class of type A and the last reference + // is dropped of type B, then the value passed to internalSafetyCheckRemove could + // be different than was added. That would leave dangling addresses. + // + // So instead, we track the pointer by the d-pointer instead. +} + /*! \internal */ -void QtSharedPointer::internalSafetyCheckAdd(const volatile void *ptr) +void QtSharedPointer::internalSafetyCheckRemove(const volatile void *) { + // Qt 4.5 compatibility + // see comments above +} + +/*! + \internal +*/ +void QtSharedPointer::internalSafetyCheckAdd2(const void *d_ptr, const volatile void *ptr) +{ + // see comments above for the rationale for this function KnownPointers *const kp = knownPointers(); if (!kp) return; // end-game: the application is being destroyed already QMutexLocker lock(&kp->mutex); - void *actual = const_cast(ptr); - if (kp->values.contains(actual)) { - printBacktrace(knownPointers()->values.value(actual)); - qFatal("QSharedPointerData: internal self-check failed: pointer %p was already tracked " - "by another QSharedPointerData object", actual); + Q_ASSERT(!kp->dPointers.contains(d_ptr)); + + //qDebug("Adding d=%p value=%p", d_ptr, ptr); + + const void *other_d_ptr = kp->dataPointers.value(ptr, 0); + if (other_d_ptr) { +# ifdef BACKTRACE_SUPPORTED + printBacktrace(knownPointers()->dPointers.value(other_d_ptr).backtrace); +# endif + qFatal("QSharedPointer: internal self-check failed: pointer %p was already tracked " + "by another QSharedPointer object %p", ptr, other_d_ptr); } - kp->values.insert(actual, saveBacktrace()); + Data data; + data.pointer = ptr; +# ifdef BACKTRACE_SUPPORTED + data.backtrace = saveBacktrace(); +# endif + + kp->dPointers.insert(d_ptr, data); + kp->dataPointers.insert(ptr, d_ptr); } /*! \internal */ -void QtSharedPointer::internalSafetyCheckRemove(const volatile void *ptr) +void QtSharedPointer::internalSafetyCheckRemove2(const void *d_ptr) { KnownPointers *const kp = knownPointers(); if (!kp) return; // end-game: the application is being destroyed already QMutexLocker lock(&kp->mutex); - void *actual = const_cast(ptr); - kp->values.remove(actual); + + QHash::iterator it = kp->dPointers.find(d_ptr); + if (it == kp->dPointers.end()) { + qFatal("QSharedPointer: internal self-check inconsistency: pointer %p was not tracked. " + "To use QT_SHAREDPOINTER_TRACK_POINTERS, you have to enable it throughout " + "in your code.", d_ptr); + } + + QHash::iterator it2 = kp->dataPointers.find(it->pointer); + Q_ASSERT(it2 != kp->dataPointers.end()); + + //qDebug("Removing d=%p value=%p", d_ptr, it->pointer); + + // remove entries + kp->dataPointers.erase(it2); + kp->dPointers.erase(it); } QT_END_NAMESPACE diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 3d7a0e6..b8f4139 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -98,9 +98,9 @@ namespace QtSharedPointer { template QSharedPointer copyAndSetPointer(X * ptr, const QSharedPointer &src); // used in debug mode to verify the reuse of pointers - Q_CORE_EXPORT void internalSafetyCheckAdd(const volatile void *); - Q_CORE_EXPORT void internalSafetyCheckRemove(const volatile void *); - + Q_CORE_EXPORT void internalSafetyCheckAdd2(const void *, const volatile void *); + Q_CORE_EXPORT void internalSafetyCheckRemove2(const void *); + template inline void executeDeleter(T *t, RetVal (Klass:: *memberDeleter)()) { (t->*memberDeleter)(); } @@ -146,17 +146,8 @@ namespace QtSharedPointer { inline void internalConstruct(T *ptr) { -#ifdef QT_SHAREDPOINTER_TRACK_POINTERS - if (ptr) internalSafetyCheckAdd(ptr); -#endif value = ptr; } - inline void internalDestroy() - { -#ifdef QT_SHAREDPOINTER_TRACK_POINTERS - if (value) internalSafetyCheckRemove(value); -#endif - } #if defined(Q_NO_TEMPLATE_FRIENDS) public: @@ -273,8 +264,9 @@ namespace QtSharedPointer { inline void ref() const { d->weakref.ref(); d->strongref.ref(); } inline bool deref() { - if (!d->strongref.deref()) - this->internalDestroy(); + if (!d->strongref.deref()) { + internalDestroy(); + } return d->weakref.deref(); } @@ -284,6 +276,9 @@ namespace QtSharedPointer { Q_ASSERT(!d); if (ptr) d = new Data; +#ifdef QT_SHAREDPOINTER_TRACK_POINTERS + if (ptr) internalSafetyCheckAdd2(d, ptr); +#endif } template @@ -293,6 +288,9 @@ namespace QtSharedPointer { Q_ASSERT(!d); if (ptr) d = ExternalRefCountWithCustomDeleter::create(ptr, deleter); +#ifdef QT_SHAREDPOINTER_TRACK_POINTERS + if (ptr) internalSafetyCheckAdd2(d, ptr); +#endif } inline void internalCreate() @@ -301,6 +299,9 @@ namespace QtSharedPointer { d = ExternalRefCountWithContiguousData::create(&ptr); Basic::internalConstruct(ptr); +#ifdef QT_SHAREDPOINTER_TRACK_POINTERS + if (ptr) internalSafetyCheckAdd2(d, ptr); +#endif } inline ExternalRefCount() : d(0) { } @@ -316,7 +317,9 @@ namespace QtSharedPointer { inline void internalDestroy() { - Basic::internalDestroy(); +#ifdef QT_SHAREDPOINTER_TRACK_POINTERS + internalSafetyCheckRemove2(d); +#endif if (!d->destroy()) delete this->value; } -- cgit v0.12 From 2094d3c03ba895e4458a0bb6b1b4935abacd4816 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Tue, 28 Jul 2009 16:32:31 +0200 Subject: Move sub-attaq from examples to demos because sub-attaq is a bit too "advanced". --- demos/demos.pro | 4 +- demos/qtdemo/xml/examples.xml | 2 +- demos/sub-attaq/animationmanager.cpp | 93 ++ demos/sub-attaq/animationmanager.h | 70 + demos/sub-attaq/boat.cpp | 318 +++++ demos/sub-attaq/boat.h | 101 ++ demos/sub-attaq/boat_p.h | 256 ++++ demos/sub-attaq/bomb.cpp | 124 ++ demos/sub-attaq/bomb.h | 75 + demos/sub-attaq/custompropertyanimation.cpp | 108 ++ demos/sub-attaq/custompropertyanimation.h | 114 ++ demos/sub-attaq/data.xml | 39 + demos/sub-attaq/graphicsscene.cpp | 374 +++++ demos/sub-attaq/graphicsscene.h | 131 ++ demos/sub-attaq/main.cpp | 57 + demos/sub-attaq/mainwindow.cpp | 97 ++ demos/sub-attaq/mainwindow.h | 64 + demos/sub-attaq/pics/big/background.png | Bin 0 -> 48858 bytes demos/sub-attaq/pics/big/boat.png | Bin 0 -> 5198 bytes demos/sub-attaq/pics/big/bomb.png | Bin 0 -> 760 bytes demos/sub-attaq/pics/big/explosion/boat/step1.png | Bin 0 -> 5760 bytes demos/sub-attaq/pics/big/explosion/boat/step2.png | Bin 0 -> 9976 bytes demos/sub-attaq/pics/big/explosion/boat/step3.png | Bin 0 -> 12411 bytes demos/sub-attaq/pics/big/explosion/boat/step4.png | Bin 0 -> 15438 bytes .../pics/big/explosion/submarine/step1.png | Bin 0 -> 3354 bytes .../pics/big/explosion/submarine/step2.png | Bin 0 -> 6205 bytes .../pics/big/explosion/submarine/step3.png | Bin 0 -> 6678 bytes .../pics/big/explosion/submarine/step4.png | Bin 0 -> 6666 bytes demos/sub-attaq/pics/big/submarine.png | Bin 0 -> 3202 bytes demos/sub-attaq/pics/big/surface.png | Bin 0 -> 575 bytes demos/sub-attaq/pics/big/torpedo.png | Bin 0 -> 951 bytes demos/sub-attaq/pics/scalable/background-n810.svg | 171 +++ demos/sub-attaq/pics/scalable/background.svg | 171 +++ demos/sub-attaq/pics/scalable/boat.svg | 279 ++++ demos/sub-attaq/pics/scalable/bomb.svg | 138 ++ demos/sub-attaq/pics/scalable/sand.svg | 103 ++ demos/sub-attaq/pics/scalable/see.svg | 44 + demos/sub-attaq/pics/scalable/sky.svg | 45 + demos/sub-attaq/pics/scalable/sub-attaq.svg | 1473 ++++++++++++++++++++ demos/sub-attaq/pics/scalable/submarine.svg | 214 +++ demos/sub-attaq/pics/scalable/surface.svg | 49 + demos/sub-attaq/pics/scalable/torpedo.svg | 127 ++ demos/sub-attaq/pics/small/background.png | Bin 0 -> 34634 bytes demos/sub-attaq/pics/small/boat.png | Bin 0 -> 2394 bytes demos/sub-attaq/pics/small/bomb.png | Bin 0 -> 760 bytes demos/sub-attaq/pics/small/submarine.png | Bin 0 -> 1338 bytes demos/sub-attaq/pics/small/surface.png | Bin 0 -> 502 bytes demos/sub-attaq/pics/small/torpedo.png | Bin 0 -> 951 bytes demos/sub-attaq/pics/welcome/logo-a.png | Bin 0 -> 5972 bytes demos/sub-attaq/pics/welcome/logo-a2.png | Bin 0 -> 5969 bytes demos/sub-attaq/pics/welcome/logo-b.png | Bin 0 -> 6869 bytes demos/sub-attaq/pics/welcome/logo-dash.png | Bin 0 -> 2255 bytes demos/sub-attaq/pics/welcome/logo-excl.png | Bin 0 -> 2740 bytes demos/sub-attaq/pics/welcome/logo-q.png | Bin 0 -> 7016 bytes demos/sub-attaq/pics/welcome/logo-s.png | Bin 0 -> 5817 bytes demos/sub-attaq/pics/welcome/logo-t.png | Bin 0 -> 3717 bytes demos/sub-attaq/pics/welcome/logo-t2.png | Bin 0 -> 3688 bytes demos/sub-attaq/pics/welcome/logo-u.png | Bin 0 -> 5374 bytes demos/sub-attaq/pixmapitem.cpp | 59 + demos/sub-attaq/pixmapitem.h | 63 + demos/sub-attaq/progressitem.cpp | 67 + demos/sub-attaq/progressitem.h | 61 + demos/sub-attaq/qanimationstate.cpp | 150 ++ demos/sub-attaq/qanimationstate.h | 92 ++ demos/sub-attaq/states.cpp | 325 +++++ demos/sub-attaq/states.h | 180 +++ demos/sub-attaq/sub-attaq.pro | 37 + demos/sub-attaq/subattaq.qrc | 39 + demos/sub-attaq/submarine.cpp | 211 +++ demos/sub-attaq/submarine.h | 92 ++ demos/sub-attaq/submarine_p.h | 139 ++ demos/sub-attaq/torpedo.cpp | 120 ++ demos/sub-attaq/torpedo.h | 75 + doc/src/demos/sub-attaq.qdoc | 54 + doc/src/images/sub-attaq-demo.png | Bin 0 -> 51552 bytes examples/animation/animation.pro | 1 - examples/animation/sub-attaq/animationmanager.cpp | 93 -- examples/animation/sub-attaq/animationmanager.h | 70 - examples/animation/sub-attaq/boat.cpp | 318 ----- examples/animation/sub-attaq/boat.h | 101 -- examples/animation/sub-attaq/boat_p.h | 256 ---- examples/animation/sub-attaq/bomb.cpp | 124 -- examples/animation/sub-attaq/bomb.h | 75 - .../sub-attaq/custompropertyanimation.cpp | 108 -- .../animation/sub-attaq/custompropertyanimation.h | 114 -- examples/animation/sub-attaq/data.xml | 15 - examples/animation/sub-attaq/graphicsscene.cpp | 374 ----- examples/animation/sub-attaq/graphicsscene.h | 131 -- examples/animation/sub-attaq/main.cpp | 57 - examples/animation/sub-attaq/mainwindow.cpp | 97 -- examples/animation/sub-attaq/mainwindow.h | 64 - .../animation/sub-attaq/pics/big/background.png | Bin 48858 -> 0 bytes examples/animation/sub-attaq/pics/big/boat.png | Bin 5198 -> 0 bytes examples/animation/sub-attaq/pics/big/bomb.png | Bin 760 -> 0 bytes .../sub-attaq/pics/big/explosion/boat/step1.png | Bin 5760 -> 0 bytes .../sub-attaq/pics/big/explosion/boat/step2.png | Bin 9976 -> 0 bytes .../sub-attaq/pics/big/explosion/boat/step3.png | Bin 12411 -> 0 bytes .../sub-attaq/pics/big/explosion/boat/step4.png | Bin 15438 -> 0 bytes .../pics/big/explosion/submarine/step1.png | Bin 3354 -> 0 bytes .../pics/big/explosion/submarine/step2.png | Bin 6205 -> 0 bytes .../pics/big/explosion/submarine/step3.png | Bin 6678 -> 0 bytes .../pics/big/explosion/submarine/step4.png | Bin 6666 -> 0 bytes .../animation/sub-attaq/pics/big/submarine.png | Bin 3202 -> 0 bytes examples/animation/sub-attaq/pics/big/surface.png | Bin 575 -> 0 bytes examples/animation/sub-attaq/pics/big/torpedo.png | Bin 951 -> 0 bytes .../sub-attaq/pics/scalable/background-n810.svg | 171 --- .../sub-attaq/pics/scalable/background.svg | 171 --- .../animation/sub-attaq/pics/scalable/boat.svg | 279 ---- .../animation/sub-attaq/pics/scalable/bomb.svg | 138 -- .../animation/sub-attaq/pics/scalable/sand.svg | 103 -- examples/animation/sub-attaq/pics/scalable/see.svg | 44 - examples/animation/sub-attaq/pics/scalable/sky.svg | 45 - .../sub-attaq/pics/scalable/sub-attaq.svg | 1473 -------------------- .../sub-attaq/pics/scalable/submarine.svg | 214 --- .../animation/sub-attaq/pics/scalable/surface.svg | 49 - .../animation/sub-attaq/pics/scalable/torpedo.svg | 127 -- .../animation/sub-attaq/pics/small/background.png | Bin 34634 -> 0 bytes examples/animation/sub-attaq/pics/small/boat.png | Bin 2394 -> 0 bytes examples/animation/sub-attaq/pics/small/bomb.png | Bin 760 -> 0 bytes .../animation/sub-attaq/pics/small/submarine.png | Bin 1338 -> 0 bytes .../animation/sub-attaq/pics/small/surface.png | Bin 502 -> 0 bytes .../animation/sub-attaq/pics/small/torpedo.png | Bin 951 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-a.png | Bin 5972 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-a2.png | Bin 5969 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-b.png | Bin 6869 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-dash.png | Bin 2255 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-excl.png | Bin 2740 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-q.png | Bin 7016 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-s.png | Bin 5817 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-t.png | Bin 3717 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-t2.png | Bin 3688 -> 0 bytes .../animation/sub-attaq/pics/welcome/logo-u.png | Bin 5374 -> 0 bytes examples/animation/sub-attaq/pixmapitem.cpp | 59 - examples/animation/sub-attaq/pixmapitem.h | 63 - examples/animation/sub-attaq/progressitem.cpp | 67 - examples/animation/sub-attaq/progressitem.h | 61 - examples/animation/sub-attaq/qanimationstate.cpp | 150 -- examples/animation/sub-attaq/qanimationstate.h | 92 -- examples/animation/sub-attaq/states.cpp | 325 ----- examples/animation/sub-attaq/states.h | 180 --- examples/animation/sub-attaq/sub-attaq.pro | 36 - examples/animation/sub-attaq/subattaq.qrc | 39 - examples/animation/sub-attaq/submarine.cpp | 211 --- examples/animation/sub-attaq/submarine.h | 92 -- examples/animation/sub-attaq/submarine_p.h | 139 -- examples/animation/sub-attaq/torpedo.cpp | 120 -- examples/animation/sub-attaq/torpedo.h | 75 - 147 files changed, 6603 insertions(+), 6523 deletions(-) create mode 100644 demos/sub-attaq/animationmanager.cpp create mode 100644 demos/sub-attaq/animationmanager.h create mode 100644 demos/sub-attaq/boat.cpp create mode 100644 demos/sub-attaq/boat.h create mode 100644 demos/sub-attaq/boat_p.h create mode 100644 demos/sub-attaq/bomb.cpp create mode 100644 demos/sub-attaq/bomb.h create mode 100644 demos/sub-attaq/custompropertyanimation.cpp create mode 100644 demos/sub-attaq/custompropertyanimation.h create mode 100644 demos/sub-attaq/data.xml create mode 100644 demos/sub-attaq/graphicsscene.cpp create mode 100644 demos/sub-attaq/graphicsscene.h create mode 100644 demos/sub-attaq/main.cpp create mode 100644 demos/sub-attaq/mainwindow.cpp create mode 100644 demos/sub-attaq/mainwindow.h create mode 100644 demos/sub-attaq/pics/big/background.png create mode 100644 demos/sub-attaq/pics/big/boat.png create mode 100644 demos/sub-attaq/pics/big/bomb.png create mode 100644 demos/sub-attaq/pics/big/explosion/boat/step1.png create mode 100644 demos/sub-attaq/pics/big/explosion/boat/step2.png create mode 100644 demos/sub-attaq/pics/big/explosion/boat/step3.png create mode 100644 demos/sub-attaq/pics/big/explosion/boat/step4.png create mode 100644 demos/sub-attaq/pics/big/explosion/submarine/step1.png create mode 100644 demos/sub-attaq/pics/big/explosion/submarine/step2.png create mode 100644 demos/sub-attaq/pics/big/explosion/submarine/step3.png create mode 100644 demos/sub-attaq/pics/big/explosion/submarine/step4.png create mode 100644 demos/sub-attaq/pics/big/submarine.png create mode 100644 demos/sub-attaq/pics/big/surface.png create mode 100644 demos/sub-attaq/pics/big/torpedo.png create mode 100644 demos/sub-attaq/pics/scalable/background-n810.svg create mode 100644 demos/sub-attaq/pics/scalable/background.svg create mode 100644 demos/sub-attaq/pics/scalable/boat.svg create mode 100644 demos/sub-attaq/pics/scalable/bomb.svg create mode 100644 demos/sub-attaq/pics/scalable/sand.svg create mode 100644 demos/sub-attaq/pics/scalable/see.svg create mode 100644 demos/sub-attaq/pics/scalable/sky.svg create mode 100644 demos/sub-attaq/pics/scalable/sub-attaq.svg create mode 100644 demos/sub-attaq/pics/scalable/submarine.svg create mode 100644 demos/sub-attaq/pics/scalable/surface.svg create mode 100644 demos/sub-attaq/pics/scalable/torpedo.svg create mode 100644 demos/sub-attaq/pics/small/background.png create mode 100644 demos/sub-attaq/pics/small/boat.png create mode 100644 demos/sub-attaq/pics/small/bomb.png create mode 100644 demos/sub-attaq/pics/small/submarine.png create mode 100644 demos/sub-attaq/pics/small/surface.png create mode 100644 demos/sub-attaq/pics/small/torpedo.png create mode 100644 demos/sub-attaq/pics/welcome/logo-a.png create mode 100644 demos/sub-attaq/pics/welcome/logo-a2.png create mode 100644 demos/sub-attaq/pics/welcome/logo-b.png create mode 100644 demos/sub-attaq/pics/welcome/logo-dash.png create mode 100644 demos/sub-attaq/pics/welcome/logo-excl.png create mode 100644 demos/sub-attaq/pics/welcome/logo-q.png create mode 100644 demos/sub-attaq/pics/welcome/logo-s.png create mode 100644 demos/sub-attaq/pics/welcome/logo-t.png create mode 100644 demos/sub-attaq/pics/welcome/logo-t2.png create mode 100644 demos/sub-attaq/pics/welcome/logo-u.png create mode 100644 demos/sub-attaq/pixmapitem.cpp create mode 100644 demos/sub-attaq/pixmapitem.h create mode 100644 demos/sub-attaq/progressitem.cpp create mode 100644 demos/sub-attaq/progressitem.h create mode 100644 demos/sub-attaq/qanimationstate.cpp create mode 100644 demos/sub-attaq/qanimationstate.h create mode 100644 demos/sub-attaq/states.cpp create mode 100644 demos/sub-attaq/states.h create mode 100644 demos/sub-attaq/sub-attaq.pro create mode 100644 demos/sub-attaq/subattaq.qrc create mode 100644 demos/sub-attaq/submarine.cpp create mode 100644 demos/sub-attaq/submarine.h create mode 100644 demos/sub-attaq/submarine_p.h create mode 100644 demos/sub-attaq/torpedo.cpp create mode 100644 demos/sub-attaq/torpedo.h create mode 100644 doc/src/demos/sub-attaq.qdoc create mode 100644 doc/src/images/sub-attaq-demo.png delete mode 100644 examples/animation/sub-attaq/animationmanager.cpp delete mode 100644 examples/animation/sub-attaq/animationmanager.h delete mode 100644 examples/animation/sub-attaq/boat.cpp delete mode 100644 examples/animation/sub-attaq/boat.h delete mode 100644 examples/animation/sub-attaq/boat_p.h delete mode 100644 examples/animation/sub-attaq/bomb.cpp delete mode 100644 examples/animation/sub-attaq/bomb.h delete mode 100644 examples/animation/sub-attaq/custompropertyanimation.cpp delete mode 100644 examples/animation/sub-attaq/custompropertyanimation.h delete mode 100644 examples/animation/sub-attaq/data.xml delete mode 100644 examples/animation/sub-attaq/graphicsscene.cpp delete mode 100644 examples/animation/sub-attaq/graphicsscene.h delete mode 100644 examples/animation/sub-attaq/main.cpp delete mode 100644 examples/animation/sub-attaq/mainwindow.cpp delete mode 100644 examples/animation/sub-attaq/mainwindow.h delete mode 100644 examples/animation/sub-attaq/pics/big/background.png delete mode 100644 examples/animation/sub-attaq/pics/big/boat.png delete mode 100644 examples/animation/sub-attaq/pics/big/bomb.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/boat/step1.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/boat/step2.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/boat/step3.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/boat/step4.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png delete mode 100644 examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png delete mode 100644 examples/animation/sub-attaq/pics/big/submarine.png delete mode 100644 examples/animation/sub-attaq/pics/big/surface.png delete mode 100644 examples/animation/sub-attaq/pics/big/torpedo.png delete mode 100644 examples/animation/sub-attaq/pics/scalable/background-n810.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/background.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/boat.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/bomb.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/sand.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/see.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/sky.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/sub-attaq.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/submarine.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/surface.svg delete mode 100644 examples/animation/sub-attaq/pics/scalable/torpedo.svg delete mode 100644 examples/animation/sub-attaq/pics/small/background.png delete mode 100644 examples/animation/sub-attaq/pics/small/boat.png delete mode 100644 examples/animation/sub-attaq/pics/small/bomb.png delete mode 100644 examples/animation/sub-attaq/pics/small/submarine.png delete mode 100644 examples/animation/sub-attaq/pics/small/surface.png delete mode 100644 examples/animation/sub-attaq/pics/small/torpedo.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-a.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-a2.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-b.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-dash.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-excl.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-q.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-s.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-t.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-t2.png delete mode 100644 examples/animation/sub-attaq/pics/welcome/logo-u.png delete mode 100644 examples/animation/sub-attaq/pixmapitem.cpp delete mode 100644 examples/animation/sub-attaq/pixmapitem.h delete mode 100644 examples/animation/sub-attaq/progressitem.cpp delete mode 100644 examples/animation/sub-attaq/progressitem.h delete mode 100644 examples/animation/sub-attaq/qanimationstate.cpp delete mode 100644 examples/animation/sub-attaq/qanimationstate.h delete mode 100644 examples/animation/sub-attaq/states.cpp delete mode 100644 examples/animation/sub-attaq/states.h delete mode 100644 examples/animation/sub-attaq/sub-attaq.pro delete mode 100644 examples/animation/sub-attaq/subattaq.qrc delete mode 100644 examples/animation/sub-attaq/submarine.cpp delete mode 100644 examples/animation/sub-attaq/submarine.h delete mode 100644 examples/animation/sub-attaq/submarine_p.h delete mode 100644 examples/animation/sub-attaq/torpedo.cpp delete mode 100644 examples/animation/sub-attaq/torpedo.h diff --git a/demos/demos.pro b/demos/demos.pro index 6084550..eda04dc 100644 --- a/demos/demos.pro +++ b/demos/demos.pro @@ -13,7 +13,8 @@ SUBDIRS = \ demos_textedit \ demos_chip \ demos_embeddeddialogs \ - demos_undo + demos_undo \ + demos_sub-attaq contains(QT_CONFIG, opengl):!contains(QT_CONFIG, opengles1):!contains(QT_CONFIG, opengles1cl):!contains(QT_CONFIG, opengles2):{ SUBDIRS += demos_boxes @@ -61,6 +62,7 @@ demos_mediaplayer.subdir = mediaplayer demos_browser.subdir = browser demos_boxes.subdir = boxes +demos_sub-attaq.subdir = sub-attaq #CONFIG += ordered !ordered { diff --git a/demos/qtdemo/xml/examples.xml b/demos/qtdemo/xml/examples.xml index 2560848..a81eead 100644 --- a/demos/qtdemo/xml/examples.xml +++ b/demos/qtdemo/xml/examples.xml @@ -18,6 +18,7 @@ + @@ -26,7 +27,6 @@ - diff --git a/demos/sub-attaq/animationmanager.cpp b/demos/sub-attaq/animationmanager.cpp new file mode 100644 index 0000000..13266f9 --- /dev/null +++ b/demos/sub-attaq/animationmanager.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "animationmanager.h" + +//Qt +#include +#include + +// the universe's only animation manager +AnimationManager *AnimationManager::instance = 0; + +AnimationManager::AnimationManager() +{ +} + +AnimationManager *AnimationManager::self() +{ + if (!instance) + instance = new AnimationManager; + return instance; +} + +void AnimationManager::registerAnimation(QAbstractAnimation *anim) +{ + animations.append(anim); +} + +void AnimationManager::unregisterAnimation(QAbstractAnimation *anim) +{ + animations.removeAll(anim); +} + +void AnimationManager::unregisterAllAnimations() +{ + animations.clear(); +} + +void AnimationManager::pauseAll() +{ + foreach (QAbstractAnimation* animation, animations) + { + if (animation->state() == QAbstractAnimation::Running) + animation->pause(); + } +} +void AnimationManager::resumeAll() +{ + foreach (QAbstractAnimation* animation, animations) + { + if (animation->state() == QAbstractAnimation::Paused) + animation->resume(); + } +} diff --git a/demos/sub-attaq/animationmanager.h b/demos/sub-attaq/animationmanager.h new file mode 100644 index 0000000..63ecae6 --- /dev/null +++ b/demos/sub-attaq/animationmanager.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANIMATIONMANAGER_H +#define ANIMATIONMANAGER_H + +#include + +QT_BEGIN_NAMESPACE +class QAbstractAnimation; +QT_END_NAMESPACE + +class AnimationManager : public QObject +{ +Q_OBJECT +public: + AnimationManager(); + void registerAnimation(QAbstractAnimation *anim); + void unregisterAnimation(QAbstractAnimation *anim); + void unregisterAllAnimations(); + static AnimationManager *self(); + +public slots: + void pauseAll(); + void resumeAll(); + +private: + static AnimationManager *instance; + QList animations; +}; + +#endif // ANIMATIONMANAGER_H diff --git a/demos/sub-attaq/boat.cpp b/demos/sub-attaq/boat.cpp new file mode 100644 index 0000000..68e646e --- /dev/null +++ b/demos/sub-attaq/boat.cpp @@ -0,0 +1,318 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "boat.h" +#include "boat_p.h" +#include "bomb.h" +#include "pixmapitem.h" +#include "graphicsscene.h" +#include "animationmanager.h" +#include "custompropertyanimation.h" +#include "qanimationstate.h" + +//Qt +#include +#include +#include +#include +#include +#include + +static QAbstractAnimation *setupDestroyAnimation(Boat *boat) +{ + QSequentialAnimationGroup *group = new QSequentialAnimationGroup(boat); +#if QT_VERSION >=0x040500 + PixmapItem *step1 = new PixmapItem(QString("explosion/boat/step1"),GraphicsScene::Big, boat); + step1->setZValue(6); + PixmapItem *step2 = new PixmapItem(QString("explosion/boat/step2"),GraphicsScene::Big, boat); + step2->setZValue(6); + PixmapItem *step3 = new PixmapItem(QString("explosion/boat/step3"),GraphicsScene::Big, boat); + step3->setZValue(6); + PixmapItem *step4 = new PixmapItem(QString("explosion/boat/step4"),GraphicsScene::Big, boat); + step4->setZValue(6); + step1->setOpacity(0); + step2->setOpacity(0); + step3->setOpacity(0); + step4->setOpacity(0); + CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(boat); + anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim1->setDuration(100); + anim1->setEndValue(1); + CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(boat); + anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim2->setDuration(100); + anim2->setEndValue(1); + CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(boat); + anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim3->setDuration(100); + anim3->setEndValue(1); + CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(boat); + anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim4->setDuration(100); + anim4->setEndValue(1); + CustomPropertyAnimation *anim5 = new CustomPropertyAnimation(boat); + anim5->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim5->setDuration(100); + anim5->setEndValue(0); + CustomPropertyAnimation *anim6 = new CustomPropertyAnimation(boat); + anim6->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim6->setDuration(100); + anim6->setEndValue(0); + CustomPropertyAnimation *anim7 = new CustomPropertyAnimation(boat); + anim7->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim7->setDuration(100); + anim7->setEndValue(0); + CustomPropertyAnimation *anim8 = new CustomPropertyAnimation(boat); + anim8->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim8->setDuration(100); + anim8->setEndValue(0); + group->addAnimation(anim1); + group->addAnimation(anim2); + group->addAnimation(anim3); + group->addAnimation(anim4); + group->addAnimation(anim5); + group->addAnimation(anim6); + group->addAnimation(anim7); + group->addAnimation(anim8); +#else + // work around for a bug where we don't transition if the duration is zero. + QtPauseAnimation *anim = new QtPauseAnimation(group); + anim->setDuration(1); + group->addAnimation(anim); +#endif + AnimationManager::self()->registerAnimation(group); + return group; +} + + + +Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), speed(0), bombsAlreadyLaunched(0), direction(Boat::None), movementAnimation(0) +{ + pixmapItem = new PixmapItem(QString("boat"),GraphicsScene::Big, this); + setZValue(4); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable); + resize(pixmapItem->boundingRect().size()); + + //The movement animation used to animate the boat + movementAnimation = new QPropertyAnimation(this, "pos"); + + //The movement animation used to animate the boat + destroyAnimation = setupDestroyAnimation(this); + + //We setup the state machien of the boat + machine = new QStateMachine(this); + QState *moving = new QState(machine); + StopState *stopState = new StopState(this, moving); + machine->setInitialState(moving); + moving->setInitialState(stopState); + MoveStateRight *moveStateRight = new MoveStateRight(this, moving); + MoveStateLeft *moveStateLeft = new MoveStateLeft(this, moving); + LaunchStateRight *launchStateRight = new LaunchStateRight(this, machine); + LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine); + + //then setup the transitions for the rightMove state + KeyStopTransition *leftStopRight = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Left); + leftStopRight->setTargetState(stopState); + KeyMoveTransition *leftMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Left); + leftMoveRight->setTargetState(moveStateRight); + KeyMoveTransition *rightMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightMoveRight->setTargetState(moveStateRight); + KeyMoveTransition *rightMoveStop = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightMoveStop->setTargetState(moveStateRight); + + //then setup the transitions for the leftMove state + KeyStopTransition *rightStopLeft = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightStopLeft->setTargetState(stopState); + KeyMoveTransition *rightMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightMoveLeft->setTargetState(moveStateLeft); + KeyMoveTransition *leftMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left); + leftMoveLeft->setTargetState(moveStateLeft); + KeyMoveTransition *leftMoveStop = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left); + leftMoveStop->setTargetState(moveStateLeft); + + //We set up the right move state + moveStateRight->addTransition(leftStopRight); + moveStateRight->addTransition(leftMoveRight); + moveStateRight->addTransition(rightMoveRight); + stopState->addTransition(rightMoveStop); + + //We set up the left move state + moveStateLeft->addTransition(rightStopLeft); + moveStateLeft->addTransition(leftMoveLeft); + moveStateLeft->addTransition(rightMoveLeft); + stopState->addTransition(leftMoveStop); + + //The animation is finished, it means we reached the border of the screen, the boat is stopped so we move to the stop state + moveStateLeft->addTransition(movementAnimation, SIGNAL(finished()), stopState); + moveStateRight->addTransition(movementAnimation, SIGNAL(finished()), stopState); + + //We set up the keys for dropping bombs + KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); + upFireLeft->setTargetState(launchStateRight); + KeyLaunchTransition *upFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); + upFireRight->setTargetState(launchStateRight); + KeyLaunchTransition *upFireStop = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); + upFireStop->setTargetState(launchStateRight); + KeyLaunchTransition *downFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); + downFireLeft->setTargetState(launchStateLeft); + KeyLaunchTransition *downFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); + downFireRight->setTargetState(launchStateLeft); + KeyLaunchTransition *downFireMove = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); + downFireMove->setTargetState(launchStateLeft); + + //We set up transitions for fire up + moveStateRight->addTransition(upFireRight); + moveStateLeft->addTransition(upFireLeft); + stopState->addTransition(upFireStop); + + //We set up transitions for fire down + moveStateRight->addTransition(downFireRight); + moveStateLeft->addTransition(downFireLeft); + stopState->addTransition(downFireMove); + + //Finally the launch state should come back to its original state + QHistoryState *historyState = new QHistoryState(moving); + launchStateLeft->addTransition(historyState); + launchStateRight->addTransition(historyState); + + QFinalState *final = new QFinalState(machine); + + //This state play the destroyed animation + QAnimationState *destroyedState = new QAnimationState(machine); + destroyedState->setAnimation(destroyAnimation); + + //Play a nice animation when the boat is destroyed + moving->addTransition(this, SIGNAL(boatDestroyed()),destroyedState); + + //Transition to final state when the destroyed animation is finished + destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the boat is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(boatExecutionFinished())); + +} + +void Boat::run() +{ + //We register animations + AnimationManager::self()->registerAnimation(movementAnimation); + AnimationManager::self()->registerAnimation(destroyAnimation); + machine->start(); +} + +void Boat::stop() +{ + movementAnimation->stop(); + machine->stop(); +} + +void Boat::updateBoatMovement() +{ + if (speed == 0 || direction == Boat::None) { + movementAnimation->stop(); + return; + } + + movementAnimation->stop(); + movementAnimation->setStartValue(pos()); + + if (direction == Boat::Left) { + movementAnimation->setEndValue(QPointF(0,y())); + movementAnimation->setDuration(x()/speed*15); + } + else /*if (direction == Boat::Right)*/ { + movementAnimation->setEndValue(QPointF(scene()->width()-size().width(),y())); + movementAnimation->setDuration((scene()->width()-size().width()-x())/speed*15); + } + movementAnimation->start(); +} + +void Boat::destroy() +{ + movementAnimation->stop(); + emit boatDestroyed(); +} + +int Boat::bombsLaunched() const +{ + return bombsAlreadyLaunched; +} + +void Boat::setBombsLaunched(int number) +{ + if (number > MAX_BOMB) { + qWarning("Boat::setBombsLaunched : It impossible to launch that number of bombs"); + return; + } + bombsAlreadyLaunched = number; +} + +int Boat::currentSpeed() const +{ + return speed; +} + +void Boat::setCurrentSpeed(int speed) +{ + if (speed > 3 || speed < 0) { + qWarning("Boat::setCurrentSpeed: The boat can't run on that speed"); + return; + } + this->speed = speed; +} + +enum Boat::Movement Boat::currentDirection() const +{ + return direction; +} + +void Boat::setCurrentDirection(Movement direction) +{ + this->direction = direction; +} + +int Boat::type() const +{ + return Type; +} diff --git a/demos/sub-attaq/boat.h b/demos/sub-attaq/boat.h new file mode 100644 index 0000000..f6b1a90 --- /dev/null +++ b/demos/sub-attaq/boat.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __BOAT__H__ +#define __BOAT__H__ + +//Qt +#include +#include + +#include + +class PixmapItem; +class Bomb; +QT_BEGIN_NAMESPACE +class QVariantAnimation; +class QAbstractAnimation; +class QStateMachine; +QT_END_NAMESPACE + +class Boat : public QGraphicsWidget +{ +Q_OBJECT +public: + enum Movement { + None = 0, + Left, + Right + }; + enum { Type = UserType + 2 }; + Boat(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); + void destroy(); + void run(); + void stop(); + + int bombsLaunched() const; + void setBombsLaunched(int number); + + int currentSpeed() const; + void setCurrentSpeed(int speed); + + enum Movement currentDirection() const; + void setCurrentDirection(Movement direction); + + void updateBoatMovement(); + + virtual int type() const; + +signals: + void boatDestroyed(); + void boatExecutionFinished(); + +private: + int speed; + int bombsAlreadyLaunched; + Movement direction; + QVariantAnimation *movementAnimation; + QAbstractAnimation *destroyAnimation; + QStateMachine *machine; + PixmapItem *pixmapItem; +}; + +#endif //__BOAT__H__ diff --git a/demos/sub-attaq/boat_p.h b/demos/sub-attaq/boat_p.h new file mode 100644 index 0000000..4e962fc --- /dev/null +++ b/demos/sub-attaq/boat_p.h @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** 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 BOAT_P_H +#define BOAT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +//Own +#include "bomb.h" +#include "graphicsscene.h" + +// Qt +#include + +static const int MAX_BOMB = 5; + + +//These transtion test if we have to stop the boat (i.e current speed is 1) +class KeyStopTransition : public QKeyEventTransition +{ +public: + KeyStopTransition(Boat *boat, QEvent::Type type, int key) + : QKeyEventTransition(boat, type, key) + { + this->boat = boat; + this->key = key; + } +protected: + virtual bool eventTest(QEvent *event) + { + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + if (boat->currentSpeed() == 1) + return true; + else + return false; + } +private: + Boat * boat; + int key; +}; + +//These transtion test if we have to move the boat (i.e current speed was 0 or another value) + class KeyMoveTransition : public QKeyEventTransition +{ +public: + KeyMoveTransition(Boat *boat, QEvent::Type type, int key) + : QKeyEventTransition(boat, type, key) + { + this->boat = boat; + this->key = key; + } +protected: + virtual bool eventTest(QEvent *event) + { + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + if (boat->currentSpeed() >= 0) + return true; + else + return false; + + } + void onTransition(QEvent *) + { + //We decrease the speed if needed + if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right) + boat->setCurrentSpeed(boat->currentSpeed() - 1); + else if (key == Qt::Key_Right && boat->currentDirection() == Boat::Left) + boat->setCurrentSpeed(boat->currentSpeed() - 1); + else if (boat->currentSpeed() < 3) + boat->setCurrentSpeed(boat->currentSpeed() + 1); + boat->updateBoatMovement(); + } +private: + Boat * boat; + int key; +}; + +//This transition trigger the bombs launch + class KeyLaunchTransition : public QKeyEventTransition +{ +public: + KeyLaunchTransition(Boat *boat, QEvent::Type type, int key) + : QKeyEventTransition(boat, type, key) + { + this->boat = boat; + this->key = key; + } +protected: + virtual bool eventTest(QEvent *event) + { + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + //We have enough bomb? + if (boat->bombsLaunched() < MAX_BOMB) + return true; + else + return false; + } +private: + Boat * boat; + int key; +}; + +//This state is describing when the boat is moving right +class MoveStateRight : public QState +{ +public: + MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + boat->setCurrentDirection(Boat::Right); + boat->updateBoatMovement(); + } +private: + Boat * boat; +}; + + //This state is describing when the boat is moving left +class MoveStateLeft : public QState +{ +public: + MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + boat->setCurrentDirection(Boat::Left); + boat->updateBoatMovement(); + } +private: + Boat * boat; +}; + +//This state is describing when the boat is in a stand by position +class StopState : public QState +{ +public: + StopState(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + boat->setCurrentSpeed(0); + boat->setCurrentDirection(Boat::None); + boat->updateBoatMovement(); + } +private: + Boat * boat; +}; + +//This state is describing the launch of the torpedo on the right +class LaunchStateRight : public QState +{ +public: + LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + Bomb *b = new Bomb(); + b->setPos(boat->x()+boat->size().width(),boat->y()); + GraphicsScene *scene = static_cast(boat->scene()); + scene->addItem(b); + b->launch(Bomb::Right); + boat->setBombsLaunched(boat->bombsLaunched() + 1); + } +private: + Boat * boat; +}; + +//This state is describing the launch of the torpedo on the left +class LaunchStateLeft : public QState +{ +public: + LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + Bomb *b = new Bomb(); + b->setPos(boat->x() - b->size().width(), boat->y()); + GraphicsScene *scene = static_cast(boat->scene()); + scene->addItem(b); + b->launch(Bomb::Left); + boat->setBombsLaunched(boat->bombsLaunched() + 1); + } +private: + Boat * boat; +}; + +#endif // BOAT_P_H diff --git a/demos/sub-attaq/bomb.cpp b/demos/sub-attaq/bomb.cpp new file mode 100644 index 0000000..e92a723 --- /dev/null +++ b/demos/sub-attaq/bomb.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "bomb.h" +#include "submarine.h" +#include "pixmapitem.h" +#include "animationmanager.h" +#include "qanimationstate.h" + +//Qt +#include +#include +#include +#include + +Bomb::Bomb(QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), launchAnimation(0) +{ + pixmapItem = new PixmapItem(QString("bomb"),GraphicsScene::Big, this); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFlags(QGraphicsItem::ItemIsMovable); + setZValue(2); + resize(pixmapItem->boundingRect().size()); +} + +void Bomb::launch(Bomb::Direction direction) +{ + launchAnimation = new QSequentialAnimationGroup(); + AnimationManager::self()->registerAnimation(launchAnimation); + qreal delta = direction == Right ? 20 : - 20; + QPropertyAnimation *anim = new QPropertyAnimation(this, "pos"); + anim->setEndValue(QPointF(x() + delta,y() - 20)); + anim->setDuration(150); + launchAnimation->addAnimation(anim); + anim = new QPropertyAnimation(this, "pos"); + anim->setEndValue(QPointF(x() + delta*2, y() )); + anim->setDuration(150); + launchAnimation->addAnimation(anim); + anim = new QPropertyAnimation(this, "pos"); + anim->setEndValue(QPointF(x() + delta*2,scene()->height())); + anim->setDuration(y()/2*60); + launchAnimation->addAnimation(anim); + connect(anim,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &))); + + //We setup the state machine of the bomb + QStateMachine *machine = new QStateMachine(this); + + //This state is when the launch animation is playing + QAnimationState *launched = new QAnimationState(machine); + launched->setAnimation(launchAnimation); + + //End + QFinalState *final = new QFinalState(machine); + + machine->setInitialState(launched); + + //### Add a nice animation when the bomb is destroyed + launched->addTransition(this, SIGNAL(bombExplosed()),final); + + //If the animation is finished, then we move to the final state + launched->addTransition(launched, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the boat is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(bombExecutionFinished())); + + machine->start(); + +} + +void Bomb::onAnimationLaunchValueChanged(const QVariant &) +{ + foreach (QGraphicsItem * item , collidingItems(Qt::IntersectsItemBoundingRect)) { + if (item->type() == SubMarine::Type) { + SubMarine *s = static_cast(item); + destroy(); + s->destroy(); + } + } +} + +void Bomb::destroy() +{ + launchAnimation->stop(); + emit bombExplosed(); +} diff --git a/demos/sub-attaq/bomb.h b/demos/sub-attaq/bomb.h new file mode 100644 index 0000000..ed6b0f5 --- /dev/null +++ b/demos/sub-attaq/bomb.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __BOMB__H__ +#define __BOMB__H__ + +//Qt +#include +#include + +class PixmapItem; + +class Bomb : public QGraphicsWidget +{ +Q_OBJECT +public: + enum Direction { + Left = 0, + Right + }; + Bomb(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); + void launch(Direction direction); + void destroy(); + +signals: + void bombExplosed(); + void bombExecutionFinished(); + +private slots: + void onAnimationLaunchValueChanged(const QVariant &); + +private: + QAnimationGroup *launchAnimation; + PixmapItem *pixmapItem; +}; + +#endif //__BOMB__H__ diff --git a/demos/sub-attaq/custompropertyanimation.cpp b/demos/sub-attaq/custompropertyanimation.cpp new file mode 100644 index 0000000..9282f42 --- /dev/null +++ b/demos/sub-attaq/custompropertyanimation.cpp @@ -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 QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "custompropertyanimation.h" + +// Qt +#include + +CustomPropertyAnimation::CustomPropertyAnimation(QObject *parent) : + QVariantAnimation(parent), animProp(0) +{ +} + +CustomPropertyAnimation::~CustomPropertyAnimation() +{ +} + +void CustomPropertyAnimation::setProperty(AbstractProperty *_animProp) +{ + if (animProp == _animProp) + return; + delete animProp; + animProp = _animProp; +} + +/*! + \reimp + */ +void CustomPropertyAnimation::updateCurrentValue(const QVariant &value) +{ + if (!animProp || state() == QAbstractAnimation::Stopped) + return; + + animProp->write(value); +} + + +/*! + \reimp +*/ +void CustomPropertyAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState) +{ + // Initialize start value + if (oldState == QAbstractAnimation::Stopped) { + if (!animProp) + return; + QVariant def = animProp->read(); + if (def.isValid()) { + const int t = def.userType(); + KeyValues values = keyValues(); + //this ensures that all the keyValues are of type t + for (int i = 0; i < values.count(); ++i) { + QVariantAnimation::KeyValue &pair = values[i]; + if (pair.second.userType() != t) + pair.second.convert(static_cast(t)); + } + //let's now update the key values + setKeyValues(values); + } + + if (animProp && !startValue().isValid() && currentTime() == 0 + || (currentTime() == duration() && currentLoop() == (loopCount() - 1))) { + setStartValue(def); + } + } + + QVariantAnimation::updateState(oldState, newState); +} + +#include "moc_custompropertyanimation.cpp" diff --git a/demos/sub-attaq/custompropertyanimation.h b/demos/sub-attaq/custompropertyanimation.h new file mode 100644 index 0000000..a984163 --- /dev/null +++ b/demos/sub-attaq/custompropertyanimation.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CUSTOMPROPERTYANIMATION_H +#define CUSTOMPROPERTYANIMATION_H + +#include + +QT_BEGIN_NAMESPACE +class QGraphicsItem; +QT_END_NAMESPACE + +struct AbstractProperty +{ + virtual QVariant read() const = 0; + virtual void write(const QVariant &value) = 0; +}; + + +class CustomPropertyAnimation : public QVariantAnimation +{ + Q_OBJECT + + template + class MemberFunctionProperty : public AbstractProperty + { + public: + typedef T (Target::*Getter)(void) const; + typedef void (Target::*Setter)(T2); + + MemberFunctionProperty(Target* target, Getter getter, Setter setter) + : m_target(target), m_getter(getter), m_setter(setter) {} + + virtual void write(const QVariant &value) + { + if (m_setter) (m_target->*m_setter)(qVariantValue(value)); + } + + virtual QVariant read() const + { + if (m_getter) return qVariantFromValue((m_target->*m_getter)()); + return QVariant(); + } + + private: + Target *m_target; + Getter m_getter; + Setter m_setter; + }; + +public: + CustomPropertyAnimation(QObject *parent = 0); + ~CustomPropertyAnimation(); + + template + void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(const T& )) + { + setProperty(new MemberFunctionProperty(target, getter, setter)); + } + + template + void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(T)) + { + setProperty(new MemberFunctionProperty(target, getter, setter)); + } + + void updateCurrentValue(const QVariant &value); + void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); + void setProperty(AbstractProperty *animProp); + +private: + Q_DISABLE_COPY(CustomPropertyAnimation); + AbstractProperty *animProp; +}; + +#endif // CUSTOMPROPERTYANIMATION_H diff --git a/demos/sub-attaq/data.xml b/demos/sub-attaq/data.xml new file mode 100644 index 0000000..0f30515 --- /dev/null +++ b/demos/sub-attaq/data.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/graphicsscene.cpp b/demos/sub-attaq/graphicsscene.cpp new file mode 100644 index 0000000..fcbc1b3 --- /dev/null +++ b/demos/sub-attaq/graphicsscene.cpp @@ -0,0 +1,374 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "graphicsscene.h" +#include "states.h" +#include "boat.h" +#include "submarine.h" +#include "torpedo.h" +#include "bomb.h" +#include "pixmapitem.h" +#include "custompropertyanimation.h" +#include "animationmanager.h" +#include "qanimationstate.h" +#include "progressitem.h" + +//Qt +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//helper function that creates an animation for position and inserts it into group +static CustomPropertyAnimation *addGraphicsItemPosAnimation(QSequentialAnimationGroup *group, + QGraphicsItem *item, const QPointF &endPos) +{ + CustomPropertyAnimation *ret = new CustomPropertyAnimation(group); + ret->setMemberFunctions(item, &QGraphicsItem::pos, &QGraphicsItem::setPos); + ret->setEndValue(endPos); + ret->setDuration(200); + ret->setEasingCurve(QEasingCurve::OutElastic); + group->addPause(50); + return ret; +} + +//helper function that creates an animation for opacity and inserts it into group +static void addGraphicsItemFadeoutAnimation(QAnimationGroup *group, QGraphicsItem *item) +{ +#if QT_VERSION >=0x040500 + CustomPropertyAnimation *anim = new CustomPropertyAnimation(group); + anim->setMemberFunctions(item, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim->setDuration(800); + anim->setEndValue(0); + anim->setEasingCurve(QEasingCurve::OutQuad); +#else + // work around for a bug where we don't transition if the duration is zero. + QtPauseAnimation *anim = new QtPauseAnimation(group); + anim->setDuration(1); +#endif +} + +GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode) + : QGraphicsScene(x,y,width,height), mode(mode), newAction(0), quitAction(0), boat(0) +{ + backgroundItem = new PixmapItem(QString("background"),mode); + backgroundItem->setZValue(1); + backgroundItem->setPos(0,0); + addItem(backgroundItem); + + PixmapItem *surfaceItem = new PixmapItem(QString("surface"),mode); + surfaceItem->setZValue(3); + surfaceItem->setPos(0,sealLevel() - surfaceItem->boundingRect().height()/2); + addItem(surfaceItem); + + //The item that display score and level + progressItem = new ProgressItem(backgroundItem); + + //We create the boat + boat = new Boat(); + addItem(boat); + boat->setPos(this->width()/2, sealLevel() - boat->size().height()); + boat->hide(); + + //parse the xml that contain all data of the game + QXmlStreamReader reader; + QFile file(":data.xml"); + file.open(QIODevice::ReadOnly); + reader.setDevice(&file); + LevelDescription currentLevel; + while (!reader.atEnd()) { + reader.readNext(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == "submarine") + { + SubmarineDescription desc; + desc.name = reader.attributes().value("name").toString(); + desc.points = reader.attributes().value("points").toString().toInt(); + desc.type = reader.attributes().value("type").toString().toInt(); + submarinesData.append(desc); + } + if (reader.name() == "level") + { + currentLevel.id = reader.attributes().value("id").toString().toInt(); + currentLevel.name = reader.attributes().value("name").toString(); + } + if (reader.name() == "subinstance") + { + currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toString().toInt(),reader.attributes().value("nb").toString().toInt())); + } + } + if (reader.tokenType() == QXmlStreamReader::EndElement) { + if (reader.name() == "level") + { + levelsData.insert(currentLevel.id,currentLevel); + currentLevel.submarines.clear(); + } + } + } +} + +qreal GraphicsScene::sealLevel() const +{ + if (mode == Big) + return 220; + else + return 160; +} + +void GraphicsScene::setupScene(const QList &actions) +{ + newAction = actions.at(0); + quitAction = actions.at(1); + + QGraphicsItem *logo_s = addWelcomeItem(QPixmap(":/logo-s")); + QGraphicsItem *logo_u = addWelcomeItem(QPixmap(":/logo-u")); + QGraphicsItem *logo_b = addWelcomeItem(QPixmap(":/logo-b")); + QGraphicsItem *logo_dash = addWelcomeItem(QPixmap(":/logo-dash")); + QGraphicsItem *logo_a = addWelcomeItem(QPixmap(":/logo-a")); + QGraphicsItem *logo_t = addWelcomeItem(QPixmap(":/logo-t")); + QGraphicsItem *logo_t2 = addWelcomeItem(QPixmap(":/logo-t2")); + QGraphicsItem *logo_a2 = addWelcomeItem(QPixmap(":/logo-a2")); + QGraphicsItem *logo_q = addWelcomeItem(QPixmap(":/logo-q")); + QGraphicsItem *logo_excl = addWelcomeItem(QPixmap(":/logo-excl")); + logo_s->setZValue(3); + logo_u->setZValue(4); + logo_b->setZValue(5); + logo_dash->setZValue(6); + logo_a->setZValue(7); + logo_t->setZValue(8); + logo_t2->setZValue(9); + logo_a2->setZValue(10); + logo_q->setZValue(11); + logo_excl->setZValue(12); + logo_s->setPos(QPointF(-1000, -1000)); + logo_u->setPos(QPointF(-800, -1000)); + logo_b->setPos(QPointF(-600, -1000)); + logo_dash->setPos(QPointF(-400, -1000)); + logo_a->setPos(QPointF(1000, 2000)); + logo_t->setPos(QPointF(800, 2000)); + logo_t2->setPos(QPointF(600, 2000)); + logo_a2->setPos(QPointF(400, 2000)); + logo_q->setPos(QPointF(200, 2000)); + logo_excl->setPos(QPointF(0, 2000)); + + QSequentialAnimationGroup * lettersGroupMoving = new QSequentialAnimationGroup(this); + QParallelAnimationGroup * lettersGroupFading = new QParallelAnimationGroup(this); + + //creation of the animations for moving letters + addGraphicsItemPosAnimation(lettersGroupMoving, logo_s, QPointF(300, 150)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_u, QPointF(350, 150)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_b, QPointF(400, 120)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_dash, QPointF(460, 150)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_a, QPointF(350, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_t, QPointF(400, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_t2, QPointF(430, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_a2, QPointF(465, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_q, QPointF(510, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_excl, QPointF(570, 220)); + + //creation of the animations for fading out the letters + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_s); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_u); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_b); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_dash); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t2); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a2); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_q); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_excl); + connect(lettersGroupFading, SIGNAL(finished()), this, SLOT(onIntroAnimationFinished())); + + QStateMachine *machine = new QStateMachine(this); + + //This state is when the player is playing + PlayState *gameState = new PlayState(this,machine); + + //Final state + QFinalState *final = new QFinalState(machine); + + //Animation when the player enter in the game + QAnimationState *lettersMovingState = new QAnimationState(machine); + lettersMovingState->setAnimation(lettersGroupMoving); + + //Animation when the welcome screen disappear + QAnimationState *lettersFadingState = new QAnimationState(machine); + lettersFadingState->setAnimation(lettersGroupFading); + + //if new game then we fade out the welcome screen and start playing + lettersMovingState->addTransition(newAction, SIGNAL(triggered()),lettersFadingState); + lettersFadingState->addTransition(lettersFadingState, SIGNAL(animationFinished()),gameState); + + //New Game is triggered then player start playing + gameState->addTransition(newAction, SIGNAL(triggered()),gameState); + + //Wanna quit, then connect to CTRL+Q + gameState->addTransition(quitAction, SIGNAL(triggered()),final); + lettersMovingState->addTransition(quitAction, SIGNAL(triggered()),final); + + //Welcome screen is the initial state + machine->setInitialState(lettersMovingState); + + machine->start(); + + //We reach the final state, then we quit + connect(machine,SIGNAL(finished()),this, SLOT(onQuitGameTriggered())); +} + +void GraphicsScene::addItem(Bomb *bomb) +{ + bombs.insert(bomb); + connect(bomb,SIGNAL(bombExecutionFinished()),this, SLOT(onBombExecutionFinished())); + QGraphicsScene::addItem(bomb); +} + +void GraphicsScene::addItem(Torpedo *torpedo) +{ + torpedos.insert(torpedo); + connect(torpedo,SIGNAL(torpedoExecutionFinished()),this, SLOT(onTorpedoExecutionFinished())); + QGraphicsScene::addItem(torpedo); +} + +void GraphicsScene::addItem(SubMarine *submarine) +{ + submarines.insert(submarine); + connect(submarine,SIGNAL(subMarineExecutionFinished()),this, SLOT(onSubMarineExecutionFinished())); + QGraphicsScene::addItem(submarine); +} + +void GraphicsScene::addItem(QGraphicsItem *item) +{ + QGraphicsScene::addItem(item); +} + +void GraphicsScene::mousePressEvent (QGraphicsSceneMouseEvent * event) +{ + event->ignore(); +} + +void GraphicsScene::onQuitGameTriggered() +{ + qApp->closeAllWindows(); +} + +void GraphicsScene::onBombExecutionFinished() +{ + Bomb *bomb = qobject_cast(sender()); + bombs.remove(bomb); + bomb->deleteLater(); + if (boat) + boat->setBombsLaunched(boat->bombsLaunched() - 1); +} + +void GraphicsScene::onTorpedoExecutionFinished() +{ + Torpedo *torpedo = qobject_cast(sender()); + torpedos.remove(torpedo); + torpedo->deleteLater(); +} + +void GraphicsScene::onSubMarineExecutionFinished() +{ + SubMarine *submarine = qobject_cast(sender()); + submarines.remove(submarine); + if (submarines.count() == 0) { + emit allSubMarineDestroyed(submarine->points()); + } else { + emit subMarineDestroyed(submarine->points()); + } + submarine->deleteLater(); +} + +int GraphicsScene::remainingSubMarines() const +{ + return submarines.count(); +} + +void GraphicsScene::clearScene() +{ + foreach (SubMarine *sub,submarines) { + sub->destroy(); + sub->deleteLater(); + } + + foreach (Torpedo *torpedo,torpedos) { + torpedo->destroy(); + torpedo->deleteLater(); + } + + foreach (Bomb *bomb,bombs) { + bomb->destroy(); + bomb->deleteLater(); + } + + submarines.clear(); + bombs.clear(); + torpedos.clear(); + + AnimationManager::self()->unregisterAllAnimations(); + + boat->stop(); + boat->hide(); +} + +QGraphicsPixmapItem *GraphicsScene::addWelcomeItem(const QPixmap &pm) +{ + QGraphicsPixmapItem *item = addPixmap(pm); + welcomeItems << item; + return item; +} + +void GraphicsScene::onIntroAnimationFinished() +{ + qDeleteAll(welcomeItems); + welcomeItems.clear(); +} + diff --git a/demos/sub-attaq/graphicsscene.h b/demos/sub-attaq/graphicsscene.h new file mode 100644 index 0000000..068ee97 --- /dev/null +++ b/demos/sub-attaq/graphicsscene.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __GRAPHICSSCENE__H__ +#define __GRAPHICSSCENE__H__ + +//Qt +#include +#include +#include + + +class Boat; +class SubMarine; +class Torpedo; +class Bomb; +class PixmapItem; +class ProgressItem; +QT_BEGIN_NAMESPACE +class QAction; +QT_END_NAMESPACE + +class GraphicsScene : public QGraphicsScene +{ +Q_OBJECT +public: + enum Mode { + Big = 0, + Small + }; + + struct SubmarineDescription { + int type; + int points; + QString name; + }; + + struct LevelDescription { + int id; + QString name; + QList > submarines; + }; + + GraphicsScene(int x, int y, int width, int height, Mode mode = Big); + qreal sealLevel() const; + void setupScene(const QList &actions); + void addItem(Bomb *bomb); + void addItem(Torpedo *torpedo); + void addItem(SubMarine *submarine); + void addItem(QGraphicsItem *item); + int remainingSubMarines() const; + void clearScene(); + QGraphicsPixmapItem *addWelcomeItem(const QPixmap &pm); + +signals: + void subMarineDestroyed(int); + void allSubMarineDestroyed(int); + +protected: + void mousePressEvent (QGraphicsSceneMouseEvent * event); + +private slots: + void onQuitGameTriggered(); + void onBombExecutionFinished(); + void onTorpedoExecutionFinished(); + void onSubMarineExecutionFinished(); + void onIntroAnimationFinished(); + +private: + Mode mode; + PixmapItem *backgroundItem; + ProgressItem *progressItem; + QAction * newAction; + QAction * quitAction; + Boat *boat; + QSet submarines; + QSet bombs; + QSet torpedos; + QVector welcomeItems; + QVector submarinesData; + QHash levelsData; + + friend class PauseState; + friend class PlayState; + friend class LevelState; + friend class LostState; + friend class WinState; + friend class WinTransition; + friend class UpdateScoreTransition; +}; + +#endif //__GRAPHICSSCENE__H__ + diff --git a/demos/sub-attaq/main.cpp b/demos/sub-attaq/main.cpp new file mode 100644 index 0000000..4f6f4f9 --- /dev/null +++ b/demos/sub-attaq/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Q_INIT_RESOURCE(subattaq); + + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + + MainWindow w; + w.show(); + + return app.exec(); +} diff --git a/demos/sub-attaq/mainwindow.cpp b/demos/sub-attaq/mainwindow.cpp new file mode 100644 index 0000000..bcccd34 --- /dev/null +++ b/demos/sub-attaq/mainwindow.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "mainwindow.h" +#include "graphicsscene.h" + +//Qt +#include + +#ifdef QT_NO_OPENGL + #include + #include + #include +#else + #include +#endif + +MainWindow::MainWindow() : QMainWindow(0) +{ + QMenuBar *menuBar = new QMenuBar; + QMenu *file = new QMenu(tr("&File"),menuBar); + + QAction *newAction = new QAction(tr("New Game"),file); + newAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); + file->addAction(newAction); + QAction *quitAction = new QAction(tr("Quit"),file); + quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); + file->addAction(quitAction); + + menuBar->addMenu(file); + setMenuBar(menuBar); + + QStringList list = QApplication::arguments(); + if (list.contains("-fullscreen")) { + scene = new GraphicsScene(0, 0, 750, 400,GraphicsScene::Small); + setWindowState(Qt::WindowFullScreen); + } else { + scene = new GraphicsScene(0, 0, 880, 630); + layout()->setSizeConstraint(QLayout::SetFixedSize); + } + + view = new QGraphicsView(scene,this); + view->setAlignment(Qt::AlignLeft | Qt::AlignTop); + QList actions; + actions << newAction << quitAction; + scene->setupScene(actions); +#ifndef QT_NO_OPENGL + view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); +#endif + + setCentralWidget(view); + +} + +MainWindow::~MainWindow() +{ +} + diff --git a/demos/sub-attaq/mainwindow.h b/demos/sub-attaq/mainwindow.h new file mode 100644 index 0000000..08cfcd9 --- /dev/null +++ b/demos/sub-attaq/mainwindow.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __MAINWINDOW__H__ +#define __MAINWINDOW__H__ + +//Qt +#include +class GraphicsScene; +QT_BEGIN_NAMESPACE +class QGraphicsView; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ +Q_OBJECT +public: + MainWindow(); + ~MainWindow(); + +private: + GraphicsScene *scene; + QGraphicsView *view; +}; + +#endif //__MAINWINDOW__H__ diff --git a/demos/sub-attaq/pics/big/background.png b/demos/sub-attaq/pics/big/background.png new file mode 100644 index 0000000..9f58157 Binary files /dev/null and b/demos/sub-attaq/pics/big/background.png differ diff --git a/demos/sub-attaq/pics/big/boat.png b/demos/sub-attaq/pics/big/boat.png new file mode 100644 index 0000000..be82dff Binary files /dev/null and b/demos/sub-attaq/pics/big/boat.png differ diff --git a/demos/sub-attaq/pics/big/bomb.png b/demos/sub-attaq/pics/big/bomb.png new file mode 100644 index 0000000..3af5f2f Binary files /dev/null and b/demos/sub-attaq/pics/big/bomb.png differ diff --git a/demos/sub-attaq/pics/big/explosion/boat/step1.png b/demos/sub-attaq/pics/big/explosion/boat/step1.png new file mode 100644 index 0000000..c9fd8b0 Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/boat/step1.png differ diff --git a/demos/sub-attaq/pics/big/explosion/boat/step2.png b/demos/sub-attaq/pics/big/explosion/boat/step2.png new file mode 100644 index 0000000..7528f2d Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/boat/step2.png differ diff --git a/demos/sub-attaq/pics/big/explosion/boat/step3.png b/demos/sub-attaq/pics/big/explosion/boat/step3.png new file mode 100644 index 0000000..aae9c9c Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/boat/step3.png differ diff --git a/demos/sub-attaq/pics/big/explosion/boat/step4.png b/demos/sub-attaq/pics/big/explosion/boat/step4.png new file mode 100644 index 0000000..d697c1b Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/boat/step4.png differ diff --git a/demos/sub-attaq/pics/big/explosion/submarine/step1.png b/demos/sub-attaq/pics/big/explosion/submarine/step1.png new file mode 100644 index 0000000..88ca514 Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/submarine/step1.png differ diff --git a/demos/sub-attaq/pics/big/explosion/submarine/step2.png b/demos/sub-attaq/pics/big/explosion/submarine/step2.png new file mode 100644 index 0000000..524f589 Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/submarine/step2.png differ diff --git a/demos/sub-attaq/pics/big/explosion/submarine/step3.png b/demos/sub-attaq/pics/big/explosion/submarine/step3.png new file mode 100644 index 0000000..2cca1e8 Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/submarine/step3.png differ diff --git a/demos/sub-attaq/pics/big/explosion/submarine/step4.png b/demos/sub-attaq/pics/big/explosion/submarine/step4.png new file mode 100644 index 0000000..82100a8 Binary files /dev/null and b/demos/sub-attaq/pics/big/explosion/submarine/step4.png differ diff --git a/demos/sub-attaq/pics/big/submarine.png b/demos/sub-attaq/pics/big/submarine.png new file mode 100644 index 0000000..df435dc Binary files /dev/null and b/demos/sub-attaq/pics/big/submarine.png differ diff --git a/demos/sub-attaq/pics/big/surface.png b/demos/sub-attaq/pics/big/surface.png new file mode 100644 index 0000000..4eba29e Binary files /dev/null and b/demos/sub-attaq/pics/big/surface.png differ diff --git a/demos/sub-attaq/pics/big/torpedo.png b/demos/sub-attaq/pics/big/torpedo.png new file mode 100644 index 0000000..f9c2687 Binary files /dev/null and b/demos/sub-attaq/pics/big/torpedo.png differ diff --git a/demos/sub-attaq/pics/scalable/background-n810.svg b/demos/sub-attaq/pics/scalable/background-n810.svg new file mode 100644 index 0000000..ece9f7a --- /dev/null +++ b/demos/sub-attaq/pics/scalable/background-n810.svg @@ -0,0 +1,171 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/background.svg b/demos/sub-attaq/pics/scalable/background.svg new file mode 100644 index 0000000..0be2680 --- /dev/null +++ b/demos/sub-attaq/pics/scalable/background.svg @@ -0,0 +1,171 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/boat.svg b/demos/sub-attaq/pics/scalable/boat.svg new file mode 100644 index 0000000..5298821b --- /dev/null +++ b/demos/sub-attaq/pics/scalable/boat.svg @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/bomb.svg b/demos/sub-attaq/pics/scalable/bomb.svg new file mode 100644 index 0000000..294771a --- /dev/null +++ b/demos/sub-attaq/pics/scalable/bomb.svg @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/sand.svg b/demos/sub-attaq/pics/scalable/sand.svg new file mode 100644 index 0000000..8af11b7 --- /dev/null +++ b/demos/sub-attaq/pics/scalable/sand.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/see.svg b/demos/sub-attaq/pics/scalable/see.svg new file mode 100644 index 0000000..0666691 --- /dev/null +++ b/demos/sub-attaq/pics/scalable/see.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/sky.svg b/demos/sub-attaq/pics/scalable/sky.svg new file mode 100644 index 0000000..1546c08 --- /dev/null +++ b/demos/sub-attaq/pics/scalable/sky.svg @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/sub-attaq.svg b/demos/sub-attaq/pics/scalable/sub-attaq.svg new file mode 100644 index 0000000..b075179 --- /dev/null +++ b/demos/sub-attaq/pics/scalable/sub-attaq.svg @@ -0,0 +1,1473 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/submarine.svg b/demos/sub-attaq/pics/scalable/submarine.svg new file mode 100644 index 0000000..8a0ffdd --- /dev/null +++ b/demos/sub-attaq/pics/scalable/submarine.svg @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/surface.svg b/demos/sub-attaq/pics/scalable/surface.svg new file mode 100644 index 0000000..40ed239 --- /dev/null +++ b/demos/sub-attaq/pics/scalable/surface.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/scalable/torpedo.svg b/demos/sub-attaq/pics/scalable/torpedo.svg new file mode 100644 index 0000000..48e429d --- /dev/null +++ b/demos/sub-attaq/pics/scalable/torpedo.svg @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/sub-attaq/pics/small/background.png b/demos/sub-attaq/pics/small/background.png new file mode 100644 index 0000000..5ad3db6 Binary files /dev/null and b/demos/sub-attaq/pics/small/background.png differ diff --git a/demos/sub-attaq/pics/small/boat.png b/demos/sub-attaq/pics/small/boat.png new file mode 100644 index 0000000..114ccc3 Binary files /dev/null and b/demos/sub-attaq/pics/small/boat.png differ diff --git a/demos/sub-attaq/pics/small/bomb.png b/demos/sub-attaq/pics/small/bomb.png new file mode 100644 index 0000000..3af5f2f Binary files /dev/null and b/demos/sub-attaq/pics/small/bomb.png differ diff --git a/demos/sub-attaq/pics/small/submarine.png b/demos/sub-attaq/pics/small/submarine.png new file mode 100644 index 0000000..0c0c350 Binary files /dev/null and b/demos/sub-attaq/pics/small/submarine.png differ diff --git a/demos/sub-attaq/pics/small/surface.png b/demos/sub-attaq/pics/small/surface.png new file mode 100644 index 0000000..06d0e47 Binary files /dev/null and b/demos/sub-attaq/pics/small/surface.png differ diff --git a/demos/sub-attaq/pics/small/torpedo.png b/demos/sub-attaq/pics/small/torpedo.png new file mode 100644 index 0000000..f9c2687 Binary files /dev/null and b/demos/sub-attaq/pics/small/torpedo.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-a.png b/demos/sub-attaq/pics/welcome/logo-a.png new file mode 100644 index 0000000..67dd76d Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-a.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-a2.png b/demos/sub-attaq/pics/welcome/logo-a2.png new file mode 100644 index 0000000..17668b0 Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-a2.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-b.png b/demos/sub-attaq/pics/welcome/logo-b.png new file mode 100644 index 0000000..cf6c045 Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-b.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-dash.png b/demos/sub-attaq/pics/welcome/logo-dash.png new file mode 100644 index 0000000..219233c Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-dash.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-excl.png b/demos/sub-attaq/pics/welcome/logo-excl.png new file mode 100644 index 0000000..8dd0a2e Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-excl.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-q.png b/demos/sub-attaq/pics/welcome/logo-q.png new file mode 100644 index 0000000..86e588d Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-q.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-s.png b/demos/sub-attaq/pics/welcome/logo-s.png new file mode 100644 index 0000000..7b6a36e Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-s.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-t.png b/demos/sub-attaq/pics/welcome/logo-t.png new file mode 100644 index 0000000..b2e3526 Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-t.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-t2.png b/demos/sub-attaq/pics/welcome/logo-t2.png new file mode 100644 index 0000000..b11a778 Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-t2.png differ diff --git a/demos/sub-attaq/pics/welcome/logo-u.png b/demos/sub-attaq/pics/welcome/logo-u.png new file mode 100644 index 0000000..24eede8 Binary files /dev/null and b/demos/sub-attaq/pics/welcome/logo-u.png differ diff --git a/demos/sub-attaq/pixmapitem.cpp b/demos/sub-attaq/pixmapitem.cpp new file mode 100644 index 0000000..ed0f075 --- /dev/null +++ b/demos/sub-attaq/pixmapitem.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "pixmapitem.h" + +//Qt +#include + +PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsPixmapItem(parent),name(fileName) +{ + loadPixmap(mode); +} + +void PixmapItem::loadPixmap(GraphicsScene::Mode mode) +{ + if (mode == GraphicsScene::Big) + setPixmap(":/big/" + name); + else + setPixmap(":/small/" + name); +} diff --git a/demos/sub-attaq/pixmapitem.h b/demos/sub-attaq/pixmapitem.h new file mode 100644 index 0000000..e32973e --- /dev/null +++ b/demos/sub-attaq/pixmapitem.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __PIXMAPITEM__H__ +#define __PIXMAPITEM__H__ + +//Own +#include "graphicsscene.h" + +//Qt +#include + +class PixmapItem : public QGraphicsPixmapItem +{ +public: + PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem * parent = 0); + +private: + void loadPixmap(GraphicsScene::Mode mode); + + QString name; + QPixmap pixmap; +}; + +#endif //__PIXMAPITEM__H__ diff --git a/demos/sub-attaq/progressitem.cpp b/demos/sub-attaq/progressitem.cpp new file mode 100644 index 0000000..9ccaa72 --- /dev/null +++ b/demos/sub-attaq/progressitem.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "progressitem.h" +#include "pixmapitem.h" + +ProgressItem::ProgressItem (QGraphicsItem * parent) + : QGraphicsTextItem(parent), currentLevel(1), currentScore(0) +{ + setFont(QFont("Comic Sans MS")); + setPos(parentItem()->boundingRect().topRight() - QPointF(180, -5)); +} + +void ProgressItem::setLevel(int level) +{ + currentLevel = level; + updateProgress(); +} + +void ProgressItem::setScore(int score) +{ + currentScore = score; + updateProgress(); +} + +void ProgressItem::updateProgress() +{ + setHtml(QString("Level : %1 Score : %2").arg(currentLevel).arg(currentScore)); +} diff --git a/demos/sub-attaq/progressitem.h b/demos/sub-attaq/progressitem.h new file mode 100644 index 0000000..7be57c9 --- /dev/null +++ b/demos/sub-attaq/progressitem.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PROGRESSITEM_H +#define PROGRESSITEM_H + +//Qt +#include + +class ProgressItem : public QGraphicsTextItem +{ +public: + ProgressItem(QGraphicsItem * parent = 0); + void setLevel(int level); + void setScore(int score); + +private: + void updateProgress(); + int currentLevel; + int currentScore; +}; + +#endif // PROGRESSITEM_H diff --git a/demos/sub-attaq/qanimationstate.cpp b/demos/sub-attaq/qanimationstate.cpp new file mode 100644 index 0000000..4e6df56 --- /dev/null +++ b/demos/sub-attaq/qanimationstate.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qanimationstate.h" + +#include + +QT_BEGIN_NAMESPACE + +/*! +\class QAnimationState + +\brief The QAnimationState class provides state that handle an animation and emit +a signal when this animation is finished. + +\ingroup statemachine + +QAnimationState provides a state that handle an animation. It will start this animation +when the state is entered and stop it when it is leaved. When the animation has finished the +state emit animationFinished signal. +QAnimationState is part of \l{The State Machine Framework}. + +\code +QStateMachine machine; +QAnimationState *s = new QAnimationState(machine->rootState()); +QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos"); +s->setAnimation(animation); +QState *s2 = new QState(machine->rootState()); +s->addTransition(s, SIGNAL(animationFinished()), s2); +machine.start(); +\endcode + +\sa QState, {The Animation Framework} +*/ + + +#ifndef QT_NO_ANIMATION + +/*! + Constructs a new state with the given \a parent state. +*/ +QAnimationState::QAnimationState(QState *parent) + : QState(parent), m_animation(0) +{ +} + +/*! + Destroys the animation state. +*/ +QAnimationState::~QAnimationState() +{ +} + +/*! + Set an \a animation for this QAnimationState. If an animation was previously handle by this + state then it won't emit animationFinished for the old animation. The QAnimationState doesn't + take the ownership of the animation. +*/ +void QAnimationState::setAnimation(QAbstractAnimation *animation) +{ + if (animation == m_animation) + return; + + //Disconnect from the previous animation if exist + if(m_animation) + disconnect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); + + m_animation = animation; + + if (m_animation) { + //connect the new animation + connect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); + } +} + +/*! + Returns the animation handle by this animation state, or 0 if there is no animation. +*/ +QAbstractAnimation* QAnimationState::animation() const +{ + return m_animation; +} + +/*! + \reimp +*/ +void QAnimationState::onEntry(QEvent *) +{ + if (m_animation) + m_animation->start(); +} + +/*! + \reimp +*/ +void QAnimationState::onExit(QEvent *) +{ + if (m_animation) + m_animation->stop(); +} + +/*! + \reimp +*/ +bool QAnimationState::event(QEvent *e) +{ + return QState::event(e); +} + +QT_END_NAMESPACE + +#endif diff --git a/demos/sub-attaq/qanimationstate.h b/demos/sub-attaq/qanimationstate.h new file mode 100644 index 0000000..6c5b565 --- /dev/null +++ b/demos/sub-attaq/qanimationstate.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANIMATIONSTATE_H +#define QANIMATIONSTATE_H + +#ifndef QT_STATEMACHINE_SOLUTION +# include +# include +#else +# include "qstate.h" +# include "qabstractanimation.h" +#endif + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +#ifndef QT_NO_ANIMATION + +class QAbstractAnimation; + +class QAnimationState : public QState +{ + Q_OBJECT +public: + QAnimationState(QState *parent = 0); + ~QAnimationState(); + + void setAnimation(QAbstractAnimation *animation); + QAbstractAnimation* animation() const; + +signals: + void animationFinished(); + +protected: + void onEntry(QEvent *); + void onExit(QEvent *); + bool event(QEvent *e); + +private: + Q_DISABLE_COPY(QAnimationState) + QAbstractAnimation *m_animation; +}; + +#endif + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QANIMATIONSTATE_H diff --git a/demos/sub-attaq/states.cpp b/demos/sub-attaq/states.cpp new file mode 100644 index 0000000..d63737f --- /dev/null +++ b/demos/sub-attaq/states.cpp @@ -0,0 +1,325 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "states.h" +#include "graphicsscene.h" +#include "boat.h" +#include "submarine.h" +#include "torpedo.h" +#include "animationmanager.h" +#include "progressitem.h" + +//Qt +#include +#include +#include +#include +#include +#include + +PlayState::PlayState(GraphicsScene *scene, QState *parent) + : QState(parent), + scene(scene), + machine(0), + currentLevel(0), + score(0) +{ +} + +PlayState::~PlayState() +{ +} + +void PlayState::onEntry(QEvent *) +{ + //We are now playing? + if (machine) { + machine->stop(); + scene->clearScene(); + currentLevel = 0; + score = 0; + delete machine; + } + + machine = new QStateMachine(this); + + //This state is when player is playing + LevelState *levelState = new LevelState(scene, this, machine); + + //This state is when the player is actually playing but the game is not paused + QState *playingState = new QState(levelState); + levelState->setInitialState(playingState); + + //This state is when the game is paused + PauseState *pauseState = new PauseState(scene, levelState); + + //We have one view, it receive the key press event + QKeyEventTransition *pressPplay = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P); + pressPplay->setTargetState(pauseState); + QKeyEventTransition *pressPpause = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P); + pressPpause->setTargetState(playingState); + + //Pause "P" is triggered, the player pause the game + playingState->addTransition(pressPplay); + + //To get back playing when the game has been paused + pauseState->addTransition(pressPpause); + + //This state is when player have lost + LostState *lostState = new LostState(scene, this, machine); + + //This state is when player have won + WinState *winState = new WinState(scene, this, machine); + + //The boat has been destroyed then the game is finished + levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState); + + //This transition check if we won or not + WinTransition *winTransition = new WinTransition(scene, this, winState); + + //The boat has been destroyed then the game is finished + levelState->addTransition(winTransition); + + //This state is an animation when the score changed + UpdateScoreState *scoreState = new UpdateScoreState(this, levelState); + + //This transition update the score when a submarine die + UpdateScoreTransition *scoreTransition = new UpdateScoreTransition(scene, this, levelState); + scoreTransition->setTargetState(scoreState); + + //The boat has been destroyed then the game is finished + playingState->addTransition(scoreTransition); + + //We go back to play state + scoreState->addTransition(playingState); + + //We start playing!!! + machine->setInitialState(levelState); + + //Final state + QFinalState *final = new QFinalState(machine); + + //This transition is triggered when the player press space after completing a level + CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space); + spaceTransition->setTargetState(levelState); + winState->addTransition(spaceTransition); + + //We lost we should reach the final state + lostState->addTransition(lostState, SIGNAL(finished()), final); + + machine->start(); +} + +LevelState::LevelState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) +{ +} +void LevelState::onEntry(QEvent *) +{ + initializeLevel(); +} + +void LevelState::initializeLevel() +{ + //we re-init the boat + scene->boat->setPos(scene->width()/2, scene->sealLevel() - scene->boat->size().height()); + scene->boat->setCurrentSpeed(0); + scene->boat->setCurrentDirection(Boat::None); + scene->boat->setBombsLaunched(0); + scene->boat->show(); + scene->setFocusItem(scene->boat,Qt::OtherFocusReason); + scene->boat->run(); + + scene->progressItem->setScore(game->score); + scene->progressItem->setLevel(game->currentLevel + 1); + + GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel); + + for (int i = 0; i < currentLevelDescription.submarines.size(); ++i ) { + + QPair subContent = currentLevelDescription.submarines.at(i); + GraphicsScene::SubmarineDescription submarineDesc = scene->submarinesData.at(subContent.first); + + for (int j = 0; j < subContent.second; ++j ) { + SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points); + scene->addItem(sub); + int random = (qrand() % 15 + 1); + qreal x = random == 13 || random == 5 ? 0 : scene->width() - sub->size().width(); + qreal y = scene->height() -(qrand() % 150 + 1) - sub->size().height(); + sub->setPos(x,y); + sub->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left); + sub->setCurrentSpeed(qrand() % 3 + 1); + } + } +} + +/** Pause State */ +PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene) +{ +} +void PauseState::onEntry(QEvent *) +{ + AnimationManager::self()->pauseAll(); + scene->boat->setEnabled(false); +} +void PauseState::onExit(QEvent *) +{ + AnimationManager::self()->resumeAll(); + scene->boat->setEnabled(true); + scene->boat->setFocus(); +} + +/** Lost State */ +LostState::LostState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) +{ +} + +void LostState::onEntry(QEvent *) +{ + //The message to display + QString message = QString("You lose on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); + + //We set the level back to 0 + game->currentLevel = 0; + + //We set the score back to 0 + game->score = 0; + + //We clear the scene + scene->clearScene(); + + //we have only one view + QMessageBox::information(scene->views().at(0),"You lose",message); +} + +/** Win State */ +WinState::WinState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) +{ +} + +void WinState::onEntry(QEvent *) +{ + //We clear the scene + scene->clearScene(); + + QString message; + if (scene->levelsData.size() - 1 != game->currentLevel) { + message = QString("You win the level %1. Your score is %2.\nPress Space to continue after closing this dialog.").arg(game->currentLevel+1).arg(game->score); + //We increment the level number + game->currentLevel++; + } else { + message = QString("You finish the game on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); + //We set the level back to 0 + game->currentLevel = 0; + //We set the score back to 0 + game->score = 0; + } + + //we have only one view + QMessageBox::information(scene->views().at(0),"You win",message); +} + +/** UpdateScore State */ +UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(parent) +{ + this->game = game; +} +void UpdateScoreState::onEntry(QEvent *e) +{ + QState::onEntry(e); +} + +/** Win transition */ +UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) + : QSignalTransition(scene,SIGNAL(subMarineDestroyed(int)), QList() << target), + game(game), scene(scene) +{ +} + +bool UpdateScoreTransition::eventTest(QEvent *event) +{ + if (!QSignalTransition::eventTest(event)) + return false; + else { + QSignalEvent *se = static_cast(event); + game->score += se->arguments().at(0).toInt(); + scene->progressItem->setScore(game->score); + return true; + } +} + +/** Win transition */ +WinTransition::WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) + : QSignalTransition(scene,SIGNAL(allSubMarineDestroyed(int)), QList() << target), + game(game), scene(scene) +{ +} + +bool WinTransition::eventTest(QEvent *event) +{ + if (!QSignalTransition::eventTest(event)) + return false; + else { + QSignalEvent *se = static_cast(event); + game->score += se->arguments().at(0).toInt(); + scene->progressItem->setScore(game->score); + return true; + } +} + +/** Space transition */ +CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key) + : QKeyEventTransition(widget, type, key), + game(game) +{ +} + +bool CustomSpaceTransition::eventTest(QEvent *event) +{ + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + if (game->currentLevel != 0) + return true; + else + return false; + +} diff --git a/demos/sub-attaq/states.h b/demos/sub-attaq/states.h new file mode 100644 index 0000000..c3d81e7 --- /dev/null +++ b/demos/sub-attaq/states.h @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STATES_H +#define STATES_H + +//Qt +#include +#include +#include +#include +#include + +class GraphicsScene; +class Boat; +class SubMarine; +QT_BEGIN_NAMESPACE +class QStateMachine; +QT_END_NAMESPACE + +class PlayState : public QState +{ +public: + PlayState(GraphicsScene *scene, QState *parent = 0); + ~PlayState(); + + protected: + void onEntry(QEvent *); + +private : + GraphicsScene *scene; + QStateMachine *machine; + int currentLevel; + int score; + QState *parallelChild; + + friend class UpdateScoreState; + friend class UpdateScoreTransition; + friend class WinTransition; + friend class CustomSpaceTransition; + friend class WinState; + friend class LostState; + friend class LevelState; +}; + +class LevelState : public QState +{ +public: + LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0); +protected: + void onEntry(QEvent *); +private : + void initializeLevel(); + GraphicsScene *scene; + PlayState *game; +}; + +class PauseState : public QState +{ +public: + PauseState(GraphicsScene *scene, QState *parent = 0); + +protected: + void onEntry(QEvent *); + void onExit(QEvent *); +private : + GraphicsScene *scene; + Boat *boat; +}; + +class LostState : public QState +{ +public: + LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0); + +protected: + void onEntry(QEvent *); +private : + GraphicsScene *scene; + PlayState *game; +}; + +class WinState : public QState +{ +public: + WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0); + +protected: + void onEntry(QEvent *); +private : + GraphicsScene *scene; + PlayState *game; +}; + +class UpdateScoreState : public QState +{ +public: + UpdateScoreState(PlayState *game, QState *parent); +protected: + void onEntry(QEvent *); +private: + QPropertyAnimation *scoreAnimation; + PlayState *game; +}; + +//These transtion is used to update the score +class UpdateScoreTransition : public QSignalTransition +{ +public: + UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target); +protected: + virtual bool eventTest(QEvent *event); +private: + PlayState * game; + GraphicsScene *scene; +}; + +//These transtion test if we have won the game +class WinTransition : public QSignalTransition +{ +public: + WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target); +protected: + virtual bool eventTest(QEvent *event); +private: + PlayState * game; + GraphicsScene *scene; +}; + +//These transtion is true if one level has been completed and the player want to continue + class CustomSpaceTransition : public QKeyEventTransition +{ +public: + CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key); +protected: + virtual bool eventTest(QEvent *event); +private: + PlayState *game; + int key; +}; + +#endif // STATES_H diff --git a/demos/sub-attaq/sub-attaq.pro b/demos/sub-attaq/sub-attaq.pro new file mode 100644 index 0000000..ad1327d --- /dev/null +++ b/demos/sub-attaq/sub-attaq.pro @@ -0,0 +1,37 @@ +contains(QT_CONFIG, opengl):QT += opengl + +HEADERS += boat.h \ + bomb.h \ + mainwindow.h \ + submarine.h \ + torpedo.h \ + pixmapitem.h \ + graphicsscene.h \ + animationmanager.h \ + states.h \ + boat_p.h \ + submarine_p.h \ + custompropertyanimation.h \ + qanimationstate.h \ + progressitem.h +SOURCES += boat.cpp \ + bomb.cpp \ + main.cpp \ + mainwindow.cpp \ + submarine.cpp \ + torpedo.cpp \ + pixmapitem.cpp \ + graphicsscene.cpp \ + animationmanager.cpp \ + states.cpp \ + custompropertyanimation.cpp \ + qanimationstate.cpp \ + progressitem.cpp +RESOURCES += subattaq.qrc + +# install +target.path = $$[QT_INSTALL_DEMOS]/animation/sub-attaq +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sub-attaq.pro pics +sources.path = $$[QT_INSTALL_DEMOS]/animation/sub-attaq +INSTALLS += target sources + diff --git a/demos/sub-attaq/subattaq.qrc b/demos/sub-attaq/subattaq.qrc new file mode 100644 index 0000000..80a3af1 --- /dev/null +++ b/demos/sub-attaq/subattaq.qrc @@ -0,0 +1,39 @@ + + + pics/scalable/sub-attaq.svg + pics/scalable/submarine.svg + pics/scalable/boat.svg + pics/scalable/torpedo.svg + pics/welcome/logo-s.png + pics/welcome/logo-u.png + pics/welcome/logo-b.png + pics/welcome/logo-dash.png + pics/welcome/logo-a.png + pics/welcome/logo-t.png + pics/welcome/logo-t2.png + pics/welcome/logo-a2.png + pics/welcome/logo-q.png + pics/welcome/logo-excl.png + pics/big/background.png + pics/big/boat.png + pics/big/bomb.png + pics/big/submarine.png + pics/big/surface.png + pics/big/torpedo.png + pics/small/background.png + pics/small/boat.png + pics/small/bomb.png + pics/small/submarine.png + pics/small/surface.png + pics/small/torpedo.png + pics/big/explosion/boat/step1.png + pics/big/explosion/boat/step2.png + pics/big/explosion/boat/step3.png + pics/big/explosion/boat/step4.png + pics/big/explosion/submarine/step1.png + pics/big/explosion/submarine/step2.png + pics/big/explosion/submarine/step3.png + pics/big/explosion/submarine/step4.png + data.xml + + diff --git a/demos/sub-attaq/submarine.cpp b/demos/sub-attaq/submarine.cpp new file mode 100644 index 0000000..78a9539 --- /dev/null +++ b/demos/sub-attaq/submarine.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "submarine.h" +#include "submarine_p.h" +#include "torpedo.h" +#include "pixmapitem.h" +#include "graphicsscene.h" +#include "animationmanager.h" +#include "custompropertyanimation.h" +#include "qanimationstate.h" + +#include +#include +#include +#include + +static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub) +{ + QSequentialAnimationGroup *group = new QSequentialAnimationGroup(sub); +#if QT_VERSION >=0x040500 + PixmapItem *step1 = new PixmapItem(QString("explosion/submarine/step1"),GraphicsScene::Big, sub); + step1->setZValue(6); + PixmapItem *step2 = new PixmapItem(QString("explosion/submarine/step2"),GraphicsScene::Big, sub); + step2->setZValue(6); + PixmapItem *step3 = new PixmapItem(QString("explosion/submarine/step3"),GraphicsScene::Big, sub); + step3->setZValue(6); + PixmapItem *step4 = new PixmapItem(QString("explosion/submarine/step4"),GraphicsScene::Big, sub); + step4->setZValue(6); + step1->setOpacity(0); + step2->setOpacity(0); + step3->setOpacity(0); + step4->setOpacity(0); + CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(sub); + anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim1->setDuration(100); + anim1->setEndValue(1); + CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(sub); + anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim2->setDuration(100); + anim2->setEndValue(1); + CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(sub); + anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim3->setDuration(100); + anim3->setEndValue(1); + CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(sub); + anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim4->setDuration(100); + anim4->setEndValue(1); + group->addAnimation(anim1); + group->addAnimation(anim2); + group->addAnimation(anim3); + group->addAnimation(anim4); +#else + // work around for a bug where we don't transition if the duration is zero. + QtPauseAnimation *anim = new QtPauseAnimation(group); + anim->setDuration(1); + group->addAnimation(anim); +#endif + AnimationManager::self()->registerAnimation(group); + return group; +} + + +SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), subType(type), subName(name), subPoints(points), speed(0), direction(SubMarine::None) +{ + pixmapItem = new PixmapItem(QString("submarine"),GraphicsScene::Big, this); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setZValue(5); + setFlags(QGraphicsItem::ItemIsMovable); + resize(pixmapItem->boundingRect().width(),pixmapItem->boundingRect().height()); + setTransformOrigin(boundingRect().center()); + + //We setup the state machine of the submarine + QStateMachine *machine = new QStateMachine(this); + + //This state is when the boat is moving/rotating + QState *moving = new QState(machine); + + //This state is when the boat is moving from left to right + MovementState *movement = new MovementState(this, moving); + + //This state is when the boat is moving from left to right + ReturnState *rotation = new ReturnState(this, moving); + + //This is the initial state of the moving root state + moving->setInitialState(movement); + + movement->addTransition(this, SIGNAL(subMarineStateChanged()), moving); + + //This is the initial state of the machine + machine->setInitialState(moving); + + //End + QFinalState *final = new QFinalState(machine); + + //If the moving animation is finished we move to the return state + movement->addTransition(movement, SIGNAL(animationFinished()), rotation); + + //If the return animation is finished we move to the moving state + rotation->addTransition(rotation, SIGNAL(animationFinished()), movement); + + //This state play the destroyed animation + QAnimationState *destroyedState = new QAnimationState(machine); + destroyedState->setAnimation(setupDestroyAnimation(this)); + + //Play a nice animation when the submarine is destroyed + moving->addTransition(this, SIGNAL(subMarineDestroyed()), destroyedState); + + //Transition to final state when the destroyed animation is finished + destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the submarine is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(subMarineExecutionFinished())); + + machine->start(); +} + +int SubMarine::points() +{ + return subPoints; +} + +void SubMarine::setCurrentDirection(SubMarine::Movement direction) +{ + if (this->direction == direction) + return; + if (direction == SubMarine::Right && this->direction == SubMarine::None) { + setYRotation(180); + } + this->direction = direction; +} + +enum SubMarine::Movement SubMarine::currentDirection() const +{ + return direction; +} + +void SubMarine::setCurrentSpeed(int speed) +{ + if (speed < 0 || speed > 3) { + qWarning("SubMarine::setCurrentSpeed : The speed is invalid"); + } + this->speed = speed; + emit subMarineStateChanged(); +} + +int SubMarine::currentSpeed() const +{ + return speed; +} + +void SubMarine::launchTorpedo(int speed) +{ + Torpedo * torp = new Torpedo(); + GraphicsScene *scene = static_cast(this->scene()); + scene->addItem(torp); + torp->setPos(x(), y()); + torp->setCurrentSpeed(speed); + torp->launch(); +} + +void SubMarine::destroy() +{ + emit subMarineDestroyed(); +} + +int SubMarine::type() const +{ + return Type; +} diff --git a/demos/sub-attaq/submarine.h b/demos/sub-attaq/submarine.h new file mode 100644 index 0000000..481e816 --- /dev/null +++ b/demos/sub-attaq/submarine.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __SUBMARINE__H__ +#define __SUBMARINE__H__ + +//Qt +#include +#include + +class PixmapItem; + +class Torpedo; + +class SubMarine : public QGraphicsWidget +{ +Q_OBJECT +public: + enum Movement { + None = 0, + Left, + Right + }; + enum { Type = UserType + 1 }; + SubMarine(int type, const QString &name, int points, QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); + + int points(); + + void setCurrentDirection(Movement direction); + enum Movement currentDirection() const; + + void setCurrentSpeed(int speed); + int currentSpeed() const; + + void launchTorpedo(int speed); + void destroy(); + + virtual int type() const; + +signals: + void subMarineDestroyed(); + void subMarineExecutionFinished(); + void subMarineStateChanged(); + +private: + int subType; + QString subName; + int subPoints; + int speed; + Movement direction; + PixmapItem *pixmapItem; +}; + +#endif //__SUBMARINE__H__ diff --git a/demos/sub-attaq/submarine_p.h b/demos/sub-attaq/submarine_p.h new file mode 100644 index 0000000..e8df877 --- /dev/null +++ b/demos/sub-attaq/submarine_p.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** 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 SUBMARINE_P_H +#define SUBMARINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +//Own +#include "animationmanager.h" +#include "submarine.h" +#include "qanimationstate.h" + +//Qt +#include +#include + +//This state is describing when the boat is moving right +class MovementState : public QAnimationState +{ +Q_OBJECT +public: + MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) + { + movementAnimation = new QPropertyAnimation(submarine, "pos"); + connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &))); + setAnimation(movementAnimation); + AnimationManager::self()->registerAnimation(movementAnimation); + this->submarine = submarine; + } + +protected slots: + void onAnimationMovementValueChanged(const QVariant &) + { + if (qrand() % 200 + 1 == 3) + submarine->launchTorpedo(qrand() % 3 + 1); + } + +protected: + void onEntry(QEvent *e) + { + if (submarine->currentDirection() == SubMarine::Left) { + movementAnimation->setEndValue(QPointF(0,submarine->y())); + movementAnimation->setDuration(submarine->x()/submarine->currentSpeed()*12); + } + else /*if (submarine->currentDirection() == SubMarine::Right)*/ { + movementAnimation->setEndValue(QPointF(submarine->scene()->width()-submarine->size().width(),submarine->y())); + movementAnimation->setDuration((submarine->scene()->width()-submarine->size().width()-submarine->x())/submarine->currentSpeed()*12); + } + movementAnimation->setStartValue(submarine->pos()); + QAnimationState::onEntry(e); + } + +private: + SubMarine *submarine; + QPropertyAnimation *movementAnimation; +}; + +//This state is describing when the boat is moving right +class ReturnState : public QAnimationState +{ +public: + ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) + { + returnAnimation = new QPropertyAnimation(submarine, "yRotation"); + AnimationManager::self()->registerAnimation(returnAnimation); + setAnimation(returnAnimation); + this->submarine = submarine; + } + +protected: + void onEntry(QEvent *e) + { + returnAnimation->stop(); + returnAnimation->setStartValue(submarine->yRotation()); + returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.); + returnAnimation->setDuration(500); + QAnimationState::onEntry(e); + } + + void onExit(QEvent *e) + { + submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right); + QAnimationState::onExit(e); + } + +private: + SubMarine *submarine; + QPropertyAnimation *returnAnimation; +}; + +#endif // SUBMARINE_P_H diff --git a/demos/sub-attaq/torpedo.cpp b/demos/sub-attaq/torpedo.cpp new file mode 100644 index 0000000..fe79488 --- /dev/null +++ b/demos/sub-attaq/torpedo.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "torpedo.h" +#include "pixmapitem.h" +#include "boat.h" +#include "graphicsscene.h" +#include "animationmanager.h" +#include "qanimationstate.h" + +#include +#include +#include + +Torpedo::Torpedo(QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), currentSpeed(0), launchAnimation(0) +{ + pixmapItem = new PixmapItem(QString::fromLatin1("torpedo"),GraphicsScene::Big, this); + setZValue(2); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFlags(QGraphicsItem::ItemIsMovable); + resize(pixmapItem->boundingRect().size()); +} + +void Torpedo::launch() +{ + launchAnimation = new QPropertyAnimation(this, "pos"); + AnimationManager::self()->registerAnimation(launchAnimation); + launchAnimation->setEndValue(QPointF(x(),qobject_cast(scene())->sealLevel() - 15)); + launchAnimation->setEasingCurve(QEasingCurve::InQuad); + launchAnimation->setDuration(y()/currentSpeed*10); + connect(launchAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &))); + + //We setup the state machine of the torpedo + QStateMachine *machine = new QStateMachine(this); + + //This state is when the launch animation is playing + QAnimationState *launched = new QAnimationState(machine); + launched->setAnimation(launchAnimation); + + //End + QFinalState *final = new QFinalState(machine); + + machine->setInitialState(launched); + + //### Add a nice animation when the torpedo is destroyed + launched->addTransition(this, SIGNAL(torpedoExplosed()),final); + + //If the animation is finished, then we move to the final state + launched->addTransition(launched, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the boat is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(torpedoExecutionFinished())); + + machine->start(); +} + +void Torpedo::setCurrentSpeed(int speed) +{ + if (speed < 0) { + qWarning("Torpedo::setCurrentSpeed : The speed is invalid"); + return; + } + currentSpeed = speed; +} + +void Torpedo::onAnimationLaunchValueChanged(const QVariant &) +{ + foreach (QGraphicsItem *item , collidingItems(Qt::IntersectsItemBoundingRect)) { + if (item->type() == Boat::Type) { + Boat *b = static_cast(item); + b->destroy(); + } + } +} + +void Torpedo::destroy() +{ + launchAnimation->stop(); + emit torpedoExplosed(); +} diff --git a/demos/sub-attaq/torpedo.h b/demos/sub-attaq/torpedo.h new file mode 100644 index 0000000..c44037f --- /dev/null +++ b/demos/sub-attaq/torpedo.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __TORPEDO__H__ +#define __TORPEDO__H__ + +//Qt +#include + +#include +#include + +class PixmapItem; + +class Torpedo : public QGraphicsWidget +{ +Q_OBJECT +public: + Torpedo(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); + void launch(); + void setCurrentSpeed(int speed); + void destroy(); + +signals: + void torpedoExplosed(); + void torpedoExecutionFinished(); + +private slots: + void onAnimationLaunchValueChanged(const QVariant &); + +private: + int currentSpeed; + PixmapItem *pixmapItem; + QVariantAnimation *launchAnimation; +}; + +#endif //__TORPEDO__H__ diff --git a/doc/src/demos/sub-attaq.qdoc b/doc/src/demos/sub-attaq.qdoc new file mode 100644 index 0000000..6bbf763 --- /dev/null +++ b/doc/src/demos/sub-attaq.qdoc @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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 demos/sub-attaq + \title Sub-Attaq + + This demo shows Qt's ability to combine \l{The Animation Framework}{the animation framework} + and \l{The State Machine Framework}{the state machine framework} to create a game. + + \image sub-attaq-demo.png + + The purpose of the game is to destroy all submarines to win the current level. + The boat can be controlled using left and right keys. To fire a bomb you can press + up and down keys. +*/ diff --git a/doc/src/images/sub-attaq-demo.png b/doc/src/images/sub-attaq-demo.png new file mode 100644 index 0000000..5a35ec6 Binary files /dev/null and b/doc/src/images/sub-attaq-demo.png differ diff --git a/examples/animation/animation.pro b/examples/animation/animation.pro index 9a2874b..c72c532 100644 --- a/examples/animation/animation.pro +++ b/examples/animation/animation.pro @@ -7,7 +7,6 @@ SUBDIRS += \ moveblocks \ states \ stickman \ - sub-attaq # install target.path = $$[QT_INSTALL_EXAMPLES]/animation diff --git a/examples/animation/sub-attaq/animationmanager.cpp b/examples/animation/sub-attaq/animationmanager.cpp deleted file mode 100644 index 13266f9..0000000 --- a/examples/animation/sub-attaq/animationmanager.cpp +++ /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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "animationmanager.h" - -//Qt -#include -#include - -// the universe's only animation manager -AnimationManager *AnimationManager::instance = 0; - -AnimationManager::AnimationManager() -{ -} - -AnimationManager *AnimationManager::self() -{ - if (!instance) - instance = new AnimationManager; - return instance; -} - -void AnimationManager::registerAnimation(QAbstractAnimation *anim) -{ - animations.append(anim); -} - -void AnimationManager::unregisterAnimation(QAbstractAnimation *anim) -{ - animations.removeAll(anim); -} - -void AnimationManager::unregisterAllAnimations() -{ - animations.clear(); -} - -void AnimationManager::pauseAll() -{ - foreach (QAbstractAnimation* animation, animations) - { - if (animation->state() == QAbstractAnimation::Running) - animation->pause(); - } -} -void AnimationManager::resumeAll() -{ - foreach (QAbstractAnimation* animation, animations) - { - if (animation->state() == QAbstractAnimation::Paused) - animation->resume(); - } -} diff --git a/examples/animation/sub-attaq/animationmanager.h b/examples/animation/sub-attaq/animationmanager.h deleted file mode 100644 index 63ecae6..0000000 --- a/examples/animation/sub-attaq/animationmanager.h +++ /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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef ANIMATIONMANAGER_H -#define ANIMATIONMANAGER_H - -#include - -QT_BEGIN_NAMESPACE -class QAbstractAnimation; -QT_END_NAMESPACE - -class AnimationManager : public QObject -{ -Q_OBJECT -public: - AnimationManager(); - void registerAnimation(QAbstractAnimation *anim); - void unregisterAnimation(QAbstractAnimation *anim); - void unregisterAllAnimations(); - static AnimationManager *self(); - -public slots: - void pauseAll(); - void resumeAll(); - -private: - static AnimationManager *instance; - QList animations; -}; - -#endif // ANIMATIONMANAGER_H diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp deleted file mode 100644 index 68e646e..0000000 --- a/examples/animation/sub-attaq/boat.cpp +++ /dev/null @@ -1,318 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "boat.h" -#include "boat_p.h" -#include "bomb.h" -#include "pixmapitem.h" -#include "graphicsscene.h" -#include "animationmanager.h" -#include "custompropertyanimation.h" -#include "qanimationstate.h" - -//Qt -#include -#include -#include -#include -#include -#include - -static QAbstractAnimation *setupDestroyAnimation(Boat *boat) -{ - QSequentialAnimationGroup *group = new QSequentialAnimationGroup(boat); -#if QT_VERSION >=0x040500 - PixmapItem *step1 = new PixmapItem(QString("explosion/boat/step1"),GraphicsScene::Big, boat); - step1->setZValue(6); - PixmapItem *step2 = new PixmapItem(QString("explosion/boat/step2"),GraphicsScene::Big, boat); - step2->setZValue(6); - PixmapItem *step3 = new PixmapItem(QString("explosion/boat/step3"),GraphicsScene::Big, boat); - step3->setZValue(6); - PixmapItem *step4 = new PixmapItem(QString("explosion/boat/step4"),GraphicsScene::Big, boat); - step4->setZValue(6); - step1->setOpacity(0); - step2->setOpacity(0); - step3->setOpacity(0); - step4->setOpacity(0); - CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(boat); - anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim1->setDuration(100); - anim1->setEndValue(1); - CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(boat); - anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim2->setDuration(100); - anim2->setEndValue(1); - CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(boat); - anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim3->setDuration(100); - anim3->setEndValue(1); - CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(boat); - anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim4->setDuration(100); - anim4->setEndValue(1); - CustomPropertyAnimation *anim5 = new CustomPropertyAnimation(boat); - anim5->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim5->setDuration(100); - anim5->setEndValue(0); - CustomPropertyAnimation *anim6 = new CustomPropertyAnimation(boat); - anim6->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim6->setDuration(100); - anim6->setEndValue(0); - CustomPropertyAnimation *anim7 = new CustomPropertyAnimation(boat); - anim7->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim7->setDuration(100); - anim7->setEndValue(0); - CustomPropertyAnimation *anim8 = new CustomPropertyAnimation(boat); - anim8->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim8->setDuration(100); - anim8->setEndValue(0); - group->addAnimation(anim1); - group->addAnimation(anim2); - group->addAnimation(anim3); - group->addAnimation(anim4); - group->addAnimation(anim5); - group->addAnimation(anim6); - group->addAnimation(anim7); - group->addAnimation(anim8); -#else - // work around for a bug where we don't transition if the duration is zero. - QtPauseAnimation *anim = new QtPauseAnimation(group); - anim->setDuration(1); - group->addAnimation(anim); -#endif - AnimationManager::self()->registerAnimation(group); - return group; -} - - - -Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags) - : QGraphicsWidget(parent,wFlags), speed(0), bombsAlreadyLaunched(0), direction(Boat::None), movementAnimation(0) -{ - pixmapItem = new PixmapItem(QString("boat"),GraphicsScene::Big, this); - setZValue(4); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable); - resize(pixmapItem->boundingRect().size()); - - //The movement animation used to animate the boat - movementAnimation = new QPropertyAnimation(this, "pos"); - - //The movement animation used to animate the boat - destroyAnimation = setupDestroyAnimation(this); - - //We setup the state machien of the boat - machine = new QStateMachine(this); - QState *moving = new QState(machine); - StopState *stopState = new StopState(this, moving); - machine->setInitialState(moving); - moving->setInitialState(stopState); - MoveStateRight *moveStateRight = new MoveStateRight(this, moving); - MoveStateLeft *moveStateLeft = new MoveStateLeft(this, moving); - LaunchStateRight *launchStateRight = new LaunchStateRight(this, machine); - LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine); - - //then setup the transitions for the rightMove state - KeyStopTransition *leftStopRight = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Left); - leftStopRight->setTargetState(stopState); - KeyMoveTransition *leftMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Left); - leftMoveRight->setTargetState(moveStateRight); - KeyMoveTransition *rightMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); - rightMoveRight->setTargetState(moveStateRight); - KeyMoveTransition *rightMoveStop = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); - rightMoveStop->setTargetState(moveStateRight); - - //then setup the transitions for the leftMove state - KeyStopTransition *rightStopLeft = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Right); - rightStopLeft->setTargetState(stopState); - KeyMoveTransition *rightMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); - rightMoveLeft->setTargetState(moveStateLeft); - KeyMoveTransition *leftMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left); - leftMoveLeft->setTargetState(moveStateLeft); - KeyMoveTransition *leftMoveStop = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left); - leftMoveStop->setTargetState(moveStateLeft); - - //We set up the right move state - moveStateRight->addTransition(leftStopRight); - moveStateRight->addTransition(leftMoveRight); - moveStateRight->addTransition(rightMoveRight); - stopState->addTransition(rightMoveStop); - - //We set up the left move state - moveStateLeft->addTransition(rightStopLeft); - moveStateLeft->addTransition(leftMoveLeft); - moveStateLeft->addTransition(rightMoveLeft); - stopState->addTransition(leftMoveStop); - - //The animation is finished, it means we reached the border of the screen, the boat is stopped so we move to the stop state - moveStateLeft->addTransition(movementAnimation, SIGNAL(finished()), stopState); - moveStateRight->addTransition(movementAnimation, SIGNAL(finished()), stopState); - - //We set up the keys for dropping bombs - KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); - upFireLeft->setTargetState(launchStateRight); - KeyLaunchTransition *upFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); - upFireRight->setTargetState(launchStateRight); - KeyLaunchTransition *upFireStop = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); - upFireStop->setTargetState(launchStateRight); - KeyLaunchTransition *downFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); - downFireLeft->setTargetState(launchStateLeft); - KeyLaunchTransition *downFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); - downFireRight->setTargetState(launchStateLeft); - KeyLaunchTransition *downFireMove = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); - downFireMove->setTargetState(launchStateLeft); - - //We set up transitions for fire up - moveStateRight->addTransition(upFireRight); - moveStateLeft->addTransition(upFireLeft); - stopState->addTransition(upFireStop); - - //We set up transitions for fire down - moveStateRight->addTransition(downFireRight); - moveStateLeft->addTransition(downFireLeft); - stopState->addTransition(downFireMove); - - //Finally the launch state should come back to its original state - QHistoryState *historyState = new QHistoryState(moving); - launchStateLeft->addTransition(historyState); - launchStateRight->addTransition(historyState); - - QFinalState *final = new QFinalState(machine); - - //This state play the destroyed animation - QAnimationState *destroyedState = new QAnimationState(machine); - destroyedState->setAnimation(destroyAnimation); - - //Play a nice animation when the boat is destroyed - moving->addTransition(this, SIGNAL(boatDestroyed()),destroyedState); - - //Transition to final state when the destroyed animation is finished - destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); - - //The machine has finished to be executed, then the boat is dead - connect(machine,SIGNAL(finished()),this, SIGNAL(boatExecutionFinished())); - -} - -void Boat::run() -{ - //We register animations - AnimationManager::self()->registerAnimation(movementAnimation); - AnimationManager::self()->registerAnimation(destroyAnimation); - machine->start(); -} - -void Boat::stop() -{ - movementAnimation->stop(); - machine->stop(); -} - -void Boat::updateBoatMovement() -{ - if (speed == 0 || direction == Boat::None) { - movementAnimation->stop(); - return; - } - - movementAnimation->stop(); - movementAnimation->setStartValue(pos()); - - if (direction == Boat::Left) { - movementAnimation->setEndValue(QPointF(0,y())); - movementAnimation->setDuration(x()/speed*15); - } - else /*if (direction == Boat::Right)*/ { - movementAnimation->setEndValue(QPointF(scene()->width()-size().width(),y())); - movementAnimation->setDuration((scene()->width()-size().width()-x())/speed*15); - } - movementAnimation->start(); -} - -void Boat::destroy() -{ - movementAnimation->stop(); - emit boatDestroyed(); -} - -int Boat::bombsLaunched() const -{ - return bombsAlreadyLaunched; -} - -void Boat::setBombsLaunched(int number) -{ - if (number > MAX_BOMB) { - qWarning("Boat::setBombsLaunched : It impossible to launch that number of bombs"); - return; - } - bombsAlreadyLaunched = number; -} - -int Boat::currentSpeed() const -{ - return speed; -} - -void Boat::setCurrentSpeed(int speed) -{ - if (speed > 3 || speed < 0) { - qWarning("Boat::setCurrentSpeed: The boat can't run on that speed"); - return; - } - this->speed = speed; -} - -enum Boat::Movement Boat::currentDirection() const -{ - return direction; -} - -void Boat::setCurrentDirection(Movement direction) -{ - this->direction = direction; -} - -int Boat::type() const -{ - return Type; -} diff --git a/examples/animation/sub-attaq/boat.h b/examples/animation/sub-attaq/boat.h deleted file mode 100644 index f6b1a90..0000000 --- a/examples/animation/sub-attaq/boat.h +++ /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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef __BOAT__H__ -#define __BOAT__H__ - -//Qt -#include -#include - -#include - -class PixmapItem; -class Bomb; -QT_BEGIN_NAMESPACE -class QVariantAnimation; -class QAbstractAnimation; -class QStateMachine; -QT_END_NAMESPACE - -class Boat : public QGraphicsWidget -{ -Q_OBJECT -public: - enum Movement { - None = 0, - Left, - Right - }; - enum { Type = UserType + 2 }; - Boat(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); - void destroy(); - void run(); - void stop(); - - int bombsLaunched() const; - void setBombsLaunched(int number); - - int currentSpeed() const; - void setCurrentSpeed(int speed); - - enum Movement currentDirection() const; - void setCurrentDirection(Movement direction); - - void updateBoatMovement(); - - virtual int type() const; - -signals: - void boatDestroyed(); - void boatExecutionFinished(); - -private: - int speed; - int bombsAlreadyLaunched; - Movement direction; - QVariantAnimation *movementAnimation; - QAbstractAnimation *destroyAnimation; - QStateMachine *machine; - PixmapItem *pixmapItem; -}; - -#endif //__BOAT__H__ diff --git a/examples/animation/sub-attaq/boat_p.h b/examples/animation/sub-attaq/boat_p.h deleted file mode 100644 index 4e962fc..0000000 --- a/examples/animation/sub-attaq/boat_p.h +++ /dev/null @@ -1,256 +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 BOAT_P_H -#define BOAT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -//Own -#include "bomb.h" -#include "graphicsscene.h" - -// Qt -#include - -static const int MAX_BOMB = 5; - - -//These transtion test if we have to stop the boat (i.e current speed is 1) -class KeyStopTransition : public QKeyEventTransition -{ -public: - KeyStopTransition(Boat *boat, QEvent::Type type, int key) - : QKeyEventTransition(boat, type, key) - { - this->boat = boat; - this->key = key; - } -protected: - virtual bool eventTest(QEvent *event) - { - Q_UNUSED(event); - if (!QKeyEventTransition::eventTest(event)) - return false; - if (boat->currentSpeed() == 1) - return true; - else - return false; - } -private: - Boat * boat; - int key; -}; - -//These transtion test if we have to move the boat (i.e current speed was 0 or another value) - class KeyMoveTransition : public QKeyEventTransition -{ -public: - KeyMoveTransition(Boat *boat, QEvent::Type type, int key) - : QKeyEventTransition(boat, type, key) - { - this->boat = boat; - this->key = key; - } -protected: - virtual bool eventTest(QEvent *event) - { - Q_UNUSED(event); - if (!QKeyEventTransition::eventTest(event)) - return false; - if (boat->currentSpeed() >= 0) - return true; - else - return false; - - } - void onTransition(QEvent *) - { - //We decrease the speed if needed - if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right) - boat->setCurrentSpeed(boat->currentSpeed() - 1); - else if (key == Qt::Key_Right && boat->currentDirection() == Boat::Left) - boat->setCurrentSpeed(boat->currentSpeed() - 1); - else if (boat->currentSpeed() < 3) - boat->setCurrentSpeed(boat->currentSpeed() + 1); - boat->updateBoatMovement(); - } -private: - Boat * boat; - int key; -}; - -//This transition trigger the bombs launch - class KeyLaunchTransition : public QKeyEventTransition -{ -public: - KeyLaunchTransition(Boat *boat, QEvent::Type type, int key) - : QKeyEventTransition(boat, type, key) - { - this->boat = boat; - this->key = key; - } -protected: - virtual bool eventTest(QEvent *event) - { - Q_UNUSED(event); - if (!QKeyEventTransition::eventTest(event)) - return false; - //We have enough bomb? - if (boat->bombsLaunched() < MAX_BOMB) - return true; - else - return false; - } -private: - Boat * boat; - int key; -}; - -//This state is describing when the boat is moving right -class MoveStateRight : public QState -{ -public: - MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent) - { - this->boat = boat; - } -protected: - void onEntry(QEvent *) - { - boat->setCurrentDirection(Boat::Right); - boat->updateBoatMovement(); - } -private: - Boat * boat; -}; - - //This state is describing when the boat is moving left -class MoveStateLeft : public QState -{ -public: - MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent) - { - this->boat = boat; - } -protected: - void onEntry(QEvent *) - { - boat->setCurrentDirection(Boat::Left); - boat->updateBoatMovement(); - } -private: - Boat * boat; -}; - -//This state is describing when the boat is in a stand by position -class StopState : public QState -{ -public: - StopState(Boat *boat,QState *parent = 0) : QState(parent) - { - this->boat = boat; - } -protected: - void onEntry(QEvent *) - { - boat->setCurrentSpeed(0); - boat->setCurrentDirection(Boat::None); - boat->updateBoatMovement(); - } -private: - Boat * boat; -}; - -//This state is describing the launch of the torpedo on the right -class LaunchStateRight : public QState -{ -public: - LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent) - { - this->boat = boat; - } -protected: - void onEntry(QEvent *) - { - Bomb *b = new Bomb(); - b->setPos(boat->x()+boat->size().width(),boat->y()); - GraphicsScene *scene = static_cast(boat->scene()); - scene->addItem(b); - b->launch(Bomb::Right); - boat->setBombsLaunched(boat->bombsLaunched() + 1); - } -private: - Boat * boat; -}; - -//This state is describing the launch of the torpedo on the left -class LaunchStateLeft : public QState -{ -public: - LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent) - { - this->boat = boat; - } -protected: - void onEntry(QEvent *) - { - Bomb *b = new Bomb(); - b->setPos(boat->x() - b->size().width(), boat->y()); - GraphicsScene *scene = static_cast(boat->scene()); - scene->addItem(b); - b->launch(Bomb::Left); - boat->setBombsLaunched(boat->bombsLaunched() + 1); - } -private: - Boat * boat; -}; - -#endif // BOAT_P_H diff --git a/examples/animation/sub-attaq/bomb.cpp b/examples/animation/sub-attaq/bomb.cpp deleted file mode 100644 index e92a723..0000000 --- a/examples/animation/sub-attaq/bomb.cpp +++ /dev/null @@ -1,124 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "bomb.h" -#include "submarine.h" -#include "pixmapitem.h" -#include "animationmanager.h" -#include "qanimationstate.h" - -//Qt -#include -#include -#include -#include - -Bomb::Bomb(QGraphicsItem * parent, Qt::WindowFlags wFlags) - : QGraphicsWidget(parent,wFlags), launchAnimation(0) -{ - pixmapItem = new PixmapItem(QString("bomb"),GraphicsScene::Big, this); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setFlags(QGraphicsItem::ItemIsMovable); - setZValue(2); - resize(pixmapItem->boundingRect().size()); -} - -void Bomb::launch(Bomb::Direction direction) -{ - launchAnimation = new QSequentialAnimationGroup(); - AnimationManager::self()->registerAnimation(launchAnimation); - qreal delta = direction == Right ? 20 : - 20; - QPropertyAnimation *anim = new QPropertyAnimation(this, "pos"); - anim->setEndValue(QPointF(x() + delta,y() - 20)); - anim->setDuration(150); - launchAnimation->addAnimation(anim); - anim = new QPropertyAnimation(this, "pos"); - anim->setEndValue(QPointF(x() + delta*2, y() )); - anim->setDuration(150); - launchAnimation->addAnimation(anim); - anim = new QPropertyAnimation(this, "pos"); - anim->setEndValue(QPointF(x() + delta*2,scene()->height())); - anim->setDuration(y()/2*60); - launchAnimation->addAnimation(anim); - connect(anim,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &))); - - //We setup the state machine of the bomb - QStateMachine *machine = new QStateMachine(this); - - //This state is when the launch animation is playing - QAnimationState *launched = new QAnimationState(machine); - launched->setAnimation(launchAnimation); - - //End - QFinalState *final = new QFinalState(machine); - - machine->setInitialState(launched); - - //### Add a nice animation when the bomb is destroyed - launched->addTransition(this, SIGNAL(bombExplosed()),final); - - //If the animation is finished, then we move to the final state - launched->addTransition(launched, SIGNAL(animationFinished()), final); - - //The machine has finished to be executed, then the boat is dead - connect(machine,SIGNAL(finished()),this, SIGNAL(bombExecutionFinished())); - - machine->start(); - -} - -void Bomb::onAnimationLaunchValueChanged(const QVariant &) -{ - foreach (QGraphicsItem * item , collidingItems(Qt::IntersectsItemBoundingRect)) { - if (item->type() == SubMarine::Type) { - SubMarine *s = static_cast(item); - destroy(); - s->destroy(); - } - } -} - -void Bomb::destroy() -{ - launchAnimation->stop(); - emit bombExplosed(); -} diff --git a/examples/animation/sub-attaq/bomb.h b/examples/animation/sub-attaq/bomb.h deleted file mode 100644 index ed6b0f5..0000000 --- a/examples/animation/sub-attaq/bomb.h +++ /dev/null @@ -1,75 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef __BOMB__H__ -#define __BOMB__H__ - -//Qt -#include -#include - -class PixmapItem; - -class Bomb : public QGraphicsWidget -{ -Q_OBJECT -public: - enum Direction { - Left = 0, - Right - }; - Bomb(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); - void launch(Direction direction); - void destroy(); - -signals: - void bombExplosed(); - void bombExecutionFinished(); - -private slots: - void onAnimationLaunchValueChanged(const QVariant &); - -private: - QAnimationGroup *launchAnimation; - PixmapItem *pixmapItem; -}; - -#endif //__BOMB__H__ diff --git a/examples/animation/sub-attaq/custompropertyanimation.cpp b/examples/animation/sub-attaq/custompropertyanimation.cpp deleted file mode 100644 index 9282f42..0000000 --- a/examples/animation/sub-attaq/custompropertyanimation.cpp +++ /dev/null @@ -1,108 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "custompropertyanimation.h" - -// Qt -#include - -CustomPropertyAnimation::CustomPropertyAnimation(QObject *parent) : - QVariantAnimation(parent), animProp(0) -{ -} - -CustomPropertyAnimation::~CustomPropertyAnimation() -{ -} - -void CustomPropertyAnimation::setProperty(AbstractProperty *_animProp) -{ - if (animProp == _animProp) - return; - delete animProp; - animProp = _animProp; -} - -/*! - \reimp - */ -void CustomPropertyAnimation::updateCurrentValue(const QVariant &value) -{ - if (!animProp || state() == QAbstractAnimation::Stopped) - return; - - animProp->write(value); -} - - -/*! - \reimp -*/ -void CustomPropertyAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState) -{ - // Initialize start value - if (oldState == QAbstractAnimation::Stopped) { - if (!animProp) - return; - QVariant def = animProp->read(); - if (def.isValid()) { - const int t = def.userType(); - KeyValues values = keyValues(); - //this ensures that all the keyValues are of type t - for (int i = 0; i < values.count(); ++i) { - QVariantAnimation::KeyValue &pair = values[i]; - if (pair.second.userType() != t) - pair.second.convert(static_cast(t)); - } - //let's now update the key values - setKeyValues(values); - } - - if (animProp && !startValue().isValid() && currentTime() == 0 - || (currentTime() == duration() && currentLoop() == (loopCount() - 1))) { - setStartValue(def); - } - } - - QVariantAnimation::updateState(oldState, newState); -} - -#include "moc_custompropertyanimation.cpp" diff --git a/examples/animation/sub-attaq/custompropertyanimation.h b/examples/animation/sub-attaq/custompropertyanimation.h deleted file mode 100644 index a984163..0000000 --- a/examples/animation/sub-attaq/custompropertyanimation.h +++ /dev/null @@ -1,114 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CUSTOMPROPERTYANIMATION_H -#define CUSTOMPROPERTYANIMATION_H - -#include - -QT_BEGIN_NAMESPACE -class QGraphicsItem; -QT_END_NAMESPACE - -struct AbstractProperty -{ - virtual QVariant read() const = 0; - virtual void write(const QVariant &value) = 0; -}; - - -class CustomPropertyAnimation : public QVariantAnimation -{ - Q_OBJECT - - template - class MemberFunctionProperty : public AbstractProperty - { - public: - typedef T (Target::*Getter)(void) const; - typedef void (Target::*Setter)(T2); - - MemberFunctionProperty(Target* target, Getter getter, Setter setter) - : m_target(target), m_getter(getter), m_setter(setter) {} - - virtual void write(const QVariant &value) - { - if (m_setter) (m_target->*m_setter)(qVariantValue(value)); - } - - virtual QVariant read() const - { - if (m_getter) return qVariantFromValue((m_target->*m_getter)()); - return QVariant(); - } - - private: - Target *m_target; - Getter m_getter; - Setter m_setter; - }; - -public: - CustomPropertyAnimation(QObject *parent = 0); - ~CustomPropertyAnimation(); - - template - void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(const T& )) - { - setProperty(new MemberFunctionProperty(target, getter, setter)); - } - - template - void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(T)) - { - setProperty(new MemberFunctionProperty(target, getter, setter)); - } - - void updateCurrentValue(const QVariant &value); - void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); - void setProperty(AbstractProperty *animProp); - -private: - Q_DISABLE_COPY(CustomPropertyAnimation); - AbstractProperty *animProp; -}; - -#endif // CUSTOMPROPERTYANIMATION_H diff --git a/examples/animation/sub-attaq/data.xml b/examples/animation/sub-attaq/data.xml deleted file mode 100644 index 41d4754..0000000 --- a/examples/animation/sub-attaq/data.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/graphicsscene.cpp b/examples/animation/sub-attaq/graphicsscene.cpp deleted file mode 100644 index fcbc1b3..0000000 --- a/examples/animation/sub-attaq/graphicsscene.cpp +++ /dev/null @@ -1,374 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "graphicsscene.h" -#include "states.h" -#include "boat.h" -#include "submarine.h" -#include "torpedo.h" -#include "bomb.h" -#include "pixmapitem.h" -#include "custompropertyanimation.h" -#include "animationmanager.h" -#include "qanimationstate.h" -#include "progressitem.h" - -//Qt -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//helper function that creates an animation for position and inserts it into group -static CustomPropertyAnimation *addGraphicsItemPosAnimation(QSequentialAnimationGroup *group, - QGraphicsItem *item, const QPointF &endPos) -{ - CustomPropertyAnimation *ret = new CustomPropertyAnimation(group); - ret->setMemberFunctions(item, &QGraphicsItem::pos, &QGraphicsItem::setPos); - ret->setEndValue(endPos); - ret->setDuration(200); - ret->setEasingCurve(QEasingCurve::OutElastic); - group->addPause(50); - return ret; -} - -//helper function that creates an animation for opacity and inserts it into group -static void addGraphicsItemFadeoutAnimation(QAnimationGroup *group, QGraphicsItem *item) -{ -#if QT_VERSION >=0x040500 - CustomPropertyAnimation *anim = new CustomPropertyAnimation(group); - anim->setMemberFunctions(item, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim->setDuration(800); - anim->setEndValue(0); - anim->setEasingCurve(QEasingCurve::OutQuad); -#else - // work around for a bug where we don't transition if the duration is zero. - QtPauseAnimation *anim = new QtPauseAnimation(group); - anim->setDuration(1); -#endif -} - -GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode) - : QGraphicsScene(x,y,width,height), mode(mode), newAction(0), quitAction(0), boat(0) -{ - backgroundItem = new PixmapItem(QString("background"),mode); - backgroundItem->setZValue(1); - backgroundItem->setPos(0,0); - addItem(backgroundItem); - - PixmapItem *surfaceItem = new PixmapItem(QString("surface"),mode); - surfaceItem->setZValue(3); - surfaceItem->setPos(0,sealLevel() - surfaceItem->boundingRect().height()/2); - addItem(surfaceItem); - - //The item that display score and level - progressItem = new ProgressItem(backgroundItem); - - //We create the boat - boat = new Boat(); - addItem(boat); - boat->setPos(this->width()/2, sealLevel() - boat->size().height()); - boat->hide(); - - //parse the xml that contain all data of the game - QXmlStreamReader reader; - QFile file(":data.xml"); - file.open(QIODevice::ReadOnly); - reader.setDevice(&file); - LevelDescription currentLevel; - while (!reader.atEnd()) { - reader.readNext(); - if (reader.tokenType() == QXmlStreamReader::StartElement) { - if (reader.name() == "submarine") - { - SubmarineDescription desc; - desc.name = reader.attributes().value("name").toString(); - desc.points = reader.attributes().value("points").toString().toInt(); - desc.type = reader.attributes().value("type").toString().toInt(); - submarinesData.append(desc); - } - if (reader.name() == "level") - { - currentLevel.id = reader.attributes().value("id").toString().toInt(); - currentLevel.name = reader.attributes().value("name").toString(); - } - if (reader.name() == "subinstance") - { - currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toString().toInt(),reader.attributes().value("nb").toString().toInt())); - } - } - if (reader.tokenType() == QXmlStreamReader::EndElement) { - if (reader.name() == "level") - { - levelsData.insert(currentLevel.id,currentLevel); - currentLevel.submarines.clear(); - } - } - } -} - -qreal GraphicsScene::sealLevel() const -{ - if (mode == Big) - return 220; - else - return 160; -} - -void GraphicsScene::setupScene(const QList &actions) -{ - newAction = actions.at(0); - quitAction = actions.at(1); - - QGraphicsItem *logo_s = addWelcomeItem(QPixmap(":/logo-s")); - QGraphicsItem *logo_u = addWelcomeItem(QPixmap(":/logo-u")); - QGraphicsItem *logo_b = addWelcomeItem(QPixmap(":/logo-b")); - QGraphicsItem *logo_dash = addWelcomeItem(QPixmap(":/logo-dash")); - QGraphicsItem *logo_a = addWelcomeItem(QPixmap(":/logo-a")); - QGraphicsItem *logo_t = addWelcomeItem(QPixmap(":/logo-t")); - QGraphicsItem *logo_t2 = addWelcomeItem(QPixmap(":/logo-t2")); - QGraphicsItem *logo_a2 = addWelcomeItem(QPixmap(":/logo-a2")); - QGraphicsItem *logo_q = addWelcomeItem(QPixmap(":/logo-q")); - QGraphicsItem *logo_excl = addWelcomeItem(QPixmap(":/logo-excl")); - logo_s->setZValue(3); - logo_u->setZValue(4); - logo_b->setZValue(5); - logo_dash->setZValue(6); - logo_a->setZValue(7); - logo_t->setZValue(8); - logo_t2->setZValue(9); - logo_a2->setZValue(10); - logo_q->setZValue(11); - logo_excl->setZValue(12); - logo_s->setPos(QPointF(-1000, -1000)); - logo_u->setPos(QPointF(-800, -1000)); - logo_b->setPos(QPointF(-600, -1000)); - logo_dash->setPos(QPointF(-400, -1000)); - logo_a->setPos(QPointF(1000, 2000)); - logo_t->setPos(QPointF(800, 2000)); - logo_t2->setPos(QPointF(600, 2000)); - logo_a2->setPos(QPointF(400, 2000)); - logo_q->setPos(QPointF(200, 2000)); - logo_excl->setPos(QPointF(0, 2000)); - - QSequentialAnimationGroup * lettersGroupMoving = new QSequentialAnimationGroup(this); - QParallelAnimationGroup * lettersGroupFading = new QParallelAnimationGroup(this); - - //creation of the animations for moving letters - addGraphicsItemPosAnimation(lettersGroupMoving, logo_s, QPointF(300, 150)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_u, QPointF(350, 150)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_b, QPointF(400, 120)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_dash, QPointF(460, 150)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_a, QPointF(350, 250)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_t, QPointF(400, 250)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_t2, QPointF(430, 250)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_a2, QPointF(465, 250)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_q, QPointF(510, 250)); - addGraphicsItemPosAnimation(lettersGroupMoving, logo_excl, QPointF(570, 220)); - - //creation of the animations for fading out the letters - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_s); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_u); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_b); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_dash); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t2); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a2); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_q); - addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_excl); - connect(lettersGroupFading, SIGNAL(finished()), this, SLOT(onIntroAnimationFinished())); - - QStateMachine *machine = new QStateMachine(this); - - //This state is when the player is playing - PlayState *gameState = new PlayState(this,machine); - - //Final state - QFinalState *final = new QFinalState(machine); - - //Animation when the player enter in the game - QAnimationState *lettersMovingState = new QAnimationState(machine); - lettersMovingState->setAnimation(lettersGroupMoving); - - //Animation when the welcome screen disappear - QAnimationState *lettersFadingState = new QAnimationState(machine); - lettersFadingState->setAnimation(lettersGroupFading); - - //if new game then we fade out the welcome screen and start playing - lettersMovingState->addTransition(newAction, SIGNAL(triggered()),lettersFadingState); - lettersFadingState->addTransition(lettersFadingState, SIGNAL(animationFinished()),gameState); - - //New Game is triggered then player start playing - gameState->addTransition(newAction, SIGNAL(triggered()),gameState); - - //Wanna quit, then connect to CTRL+Q - gameState->addTransition(quitAction, SIGNAL(triggered()),final); - lettersMovingState->addTransition(quitAction, SIGNAL(triggered()),final); - - //Welcome screen is the initial state - machine->setInitialState(lettersMovingState); - - machine->start(); - - //We reach the final state, then we quit - connect(machine,SIGNAL(finished()),this, SLOT(onQuitGameTriggered())); -} - -void GraphicsScene::addItem(Bomb *bomb) -{ - bombs.insert(bomb); - connect(bomb,SIGNAL(bombExecutionFinished()),this, SLOT(onBombExecutionFinished())); - QGraphicsScene::addItem(bomb); -} - -void GraphicsScene::addItem(Torpedo *torpedo) -{ - torpedos.insert(torpedo); - connect(torpedo,SIGNAL(torpedoExecutionFinished()),this, SLOT(onTorpedoExecutionFinished())); - QGraphicsScene::addItem(torpedo); -} - -void GraphicsScene::addItem(SubMarine *submarine) -{ - submarines.insert(submarine); - connect(submarine,SIGNAL(subMarineExecutionFinished()),this, SLOT(onSubMarineExecutionFinished())); - QGraphicsScene::addItem(submarine); -} - -void GraphicsScene::addItem(QGraphicsItem *item) -{ - QGraphicsScene::addItem(item); -} - -void GraphicsScene::mousePressEvent (QGraphicsSceneMouseEvent * event) -{ - event->ignore(); -} - -void GraphicsScene::onQuitGameTriggered() -{ - qApp->closeAllWindows(); -} - -void GraphicsScene::onBombExecutionFinished() -{ - Bomb *bomb = qobject_cast(sender()); - bombs.remove(bomb); - bomb->deleteLater(); - if (boat) - boat->setBombsLaunched(boat->bombsLaunched() - 1); -} - -void GraphicsScene::onTorpedoExecutionFinished() -{ - Torpedo *torpedo = qobject_cast(sender()); - torpedos.remove(torpedo); - torpedo->deleteLater(); -} - -void GraphicsScene::onSubMarineExecutionFinished() -{ - SubMarine *submarine = qobject_cast(sender()); - submarines.remove(submarine); - if (submarines.count() == 0) { - emit allSubMarineDestroyed(submarine->points()); - } else { - emit subMarineDestroyed(submarine->points()); - } - submarine->deleteLater(); -} - -int GraphicsScene::remainingSubMarines() const -{ - return submarines.count(); -} - -void GraphicsScene::clearScene() -{ - foreach (SubMarine *sub,submarines) { - sub->destroy(); - sub->deleteLater(); - } - - foreach (Torpedo *torpedo,torpedos) { - torpedo->destroy(); - torpedo->deleteLater(); - } - - foreach (Bomb *bomb,bombs) { - bomb->destroy(); - bomb->deleteLater(); - } - - submarines.clear(); - bombs.clear(); - torpedos.clear(); - - AnimationManager::self()->unregisterAllAnimations(); - - boat->stop(); - boat->hide(); -} - -QGraphicsPixmapItem *GraphicsScene::addWelcomeItem(const QPixmap &pm) -{ - QGraphicsPixmapItem *item = addPixmap(pm); - welcomeItems << item; - return item; -} - -void GraphicsScene::onIntroAnimationFinished() -{ - qDeleteAll(welcomeItems); - welcomeItems.clear(); -} - diff --git a/examples/animation/sub-attaq/graphicsscene.h b/examples/animation/sub-attaq/graphicsscene.h deleted file mode 100644 index 068ee97..0000000 --- a/examples/animation/sub-attaq/graphicsscene.h +++ /dev/null @@ -1,131 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef __GRAPHICSSCENE__H__ -#define __GRAPHICSSCENE__H__ - -//Qt -#include -#include -#include - - -class Boat; -class SubMarine; -class Torpedo; -class Bomb; -class PixmapItem; -class ProgressItem; -QT_BEGIN_NAMESPACE -class QAction; -QT_END_NAMESPACE - -class GraphicsScene : public QGraphicsScene -{ -Q_OBJECT -public: - enum Mode { - Big = 0, - Small - }; - - struct SubmarineDescription { - int type; - int points; - QString name; - }; - - struct LevelDescription { - int id; - QString name; - QList > submarines; - }; - - GraphicsScene(int x, int y, int width, int height, Mode mode = Big); - qreal sealLevel() const; - void setupScene(const QList &actions); - void addItem(Bomb *bomb); - void addItem(Torpedo *torpedo); - void addItem(SubMarine *submarine); - void addItem(QGraphicsItem *item); - int remainingSubMarines() const; - void clearScene(); - QGraphicsPixmapItem *addWelcomeItem(const QPixmap &pm); - -signals: - void subMarineDestroyed(int); - void allSubMarineDestroyed(int); - -protected: - void mousePressEvent (QGraphicsSceneMouseEvent * event); - -private slots: - void onQuitGameTriggered(); - void onBombExecutionFinished(); - void onTorpedoExecutionFinished(); - void onSubMarineExecutionFinished(); - void onIntroAnimationFinished(); - -private: - Mode mode; - PixmapItem *backgroundItem; - ProgressItem *progressItem; - QAction * newAction; - QAction * quitAction; - Boat *boat; - QSet submarines; - QSet bombs; - QSet torpedos; - QVector welcomeItems; - QVector submarinesData; - QHash levelsData; - - friend class PauseState; - friend class PlayState; - friend class LevelState; - friend class LostState; - friend class WinState; - friend class WinTransition; - friend class UpdateScoreTransition; -}; - -#endif //__GRAPHICSSCENE__H__ - diff --git a/examples/animation/sub-attaq/main.cpp b/examples/animation/sub-attaq/main.cpp deleted file mode 100644 index 4f6f4f9..0000000 --- a/examples/animation/sub-attaq/main.cpp +++ /dev/null @@ -1,57 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - Q_INIT_RESOURCE(subattaq); - - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); - - MainWindow w; - w.show(); - - return app.exec(); -} diff --git a/examples/animation/sub-attaq/mainwindow.cpp b/examples/animation/sub-attaq/mainwindow.cpp deleted file mode 100644 index bcccd34..0000000 --- a/examples/animation/sub-attaq/mainwindow.cpp +++ /dev/null @@ -1,97 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "mainwindow.h" -#include "graphicsscene.h" - -//Qt -#include - -#ifdef QT_NO_OPENGL - #include - #include - #include -#else - #include -#endif - -MainWindow::MainWindow() : QMainWindow(0) -{ - QMenuBar *menuBar = new QMenuBar; - QMenu *file = new QMenu(tr("&File"),menuBar); - - QAction *newAction = new QAction(tr("New Game"),file); - newAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); - file->addAction(newAction); - QAction *quitAction = new QAction(tr("Quit"),file); - quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); - file->addAction(quitAction); - - menuBar->addMenu(file); - setMenuBar(menuBar); - - QStringList list = QApplication::arguments(); - if (list.contains("-fullscreen")) { - scene = new GraphicsScene(0, 0, 750, 400,GraphicsScene::Small); - setWindowState(Qt::WindowFullScreen); - } else { - scene = new GraphicsScene(0, 0, 880, 630); - layout()->setSizeConstraint(QLayout::SetFixedSize); - } - - view = new QGraphicsView(scene,this); - view->setAlignment(Qt::AlignLeft | Qt::AlignTop); - QList actions; - actions << newAction << quitAction; - scene->setupScene(actions); -#ifndef QT_NO_OPENGL - view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); -#endif - - setCentralWidget(view); - -} - -MainWindow::~MainWindow() -{ -} - diff --git a/examples/animation/sub-attaq/mainwindow.h b/examples/animation/sub-attaq/mainwindow.h deleted file mode 100644 index 08cfcd9..0000000 --- a/examples/animation/sub-attaq/mainwindow.h +++ /dev/null @@ -1,64 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef __MAINWINDOW__H__ -#define __MAINWINDOW__H__ - -//Qt -#include -class GraphicsScene; -QT_BEGIN_NAMESPACE -class QGraphicsView; -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ -Q_OBJECT -public: - MainWindow(); - ~MainWindow(); - -private: - GraphicsScene *scene; - QGraphicsView *view; -}; - -#endif //__MAINWINDOW__H__ diff --git a/examples/animation/sub-attaq/pics/big/background.png b/examples/animation/sub-attaq/pics/big/background.png deleted file mode 100644 index 9f58157..0000000 Binary files a/examples/animation/sub-attaq/pics/big/background.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/boat.png b/examples/animation/sub-attaq/pics/big/boat.png deleted file mode 100644 index be82dff..0000000 Binary files a/examples/animation/sub-attaq/pics/big/boat.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/bomb.png b/examples/animation/sub-attaq/pics/big/bomb.png deleted file mode 100644 index 3af5f2f..0000000 Binary files a/examples/animation/sub-attaq/pics/big/bomb.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png deleted file mode 100644 index c9fd8b0..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png deleted file mode 100644 index 7528f2d..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png deleted file mode 100644 index aae9c9c..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png deleted file mode 100644 index d697c1b..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png deleted file mode 100644 index 88ca514..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png deleted file mode 100644 index 524f589..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png deleted file mode 100644 index 2cca1e8..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png deleted file mode 100644 index 82100a8..0000000 Binary files a/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/submarine.png b/examples/animation/sub-attaq/pics/big/submarine.png deleted file mode 100644 index df435dc..0000000 Binary files a/examples/animation/sub-attaq/pics/big/submarine.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/surface.png b/examples/animation/sub-attaq/pics/big/surface.png deleted file mode 100644 index 4eba29e..0000000 Binary files a/examples/animation/sub-attaq/pics/big/surface.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/big/torpedo.png b/examples/animation/sub-attaq/pics/big/torpedo.png deleted file mode 100644 index f9c2687..0000000 Binary files a/examples/animation/sub-attaq/pics/big/torpedo.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/scalable/background-n810.svg b/examples/animation/sub-attaq/pics/scalable/background-n810.svg deleted file mode 100644 index ece9f7a..0000000 --- a/examples/animation/sub-attaq/pics/scalable/background-n810.svg +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/background.svg b/examples/animation/sub-attaq/pics/scalable/background.svg deleted file mode 100644 index 0be2680..0000000 --- a/examples/animation/sub-attaq/pics/scalable/background.svg +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/boat.svg b/examples/animation/sub-attaq/pics/scalable/boat.svg deleted file mode 100644 index 5298821b..0000000 --- a/examples/animation/sub-attaq/pics/scalable/boat.svg +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/bomb.svg b/examples/animation/sub-attaq/pics/scalable/bomb.svg deleted file mode 100644 index 294771a..0000000 --- a/examples/animation/sub-attaq/pics/scalable/bomb.svg +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/sand.svg b/examples/animation/sub-attaq/pics/scalable/sand.svg deleted file mode 100644 index 8af11b7..0000000 --- a/examples/animation/sub-attaq/pics/scalable/sand.svg +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/see.svg b/examples/animation/sub-attaq/pics/scalable/see.svg deleted file mode 100644 index 0666691..0000000 --- a/examples/animation/sub-attaq/pics/scalable/see.svg +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/sky.svg b/examples/animation/sub-attaq/pics/scalable/sky.svg deleted file mode 100644 index 1546c08..0000000 --- a/examples/animation/sub-attaq/pics/scalable/sky.svg +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg b/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg deleted file mode 100644 index b075179..0000000 --- a/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg +++ /dev/null @@ -1,1473 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/submarine.svg b/examples/animation/sub-attaq/pics/scalable/submarine.svg deleted file mode 100644 index 8a0ffdd..0000000 --- a/examples/animation/sub-attaq/pics/scalable/submarine.svg +++ /dev/null @@ -1,214 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/surface.svg b/examples/animation/sub-attaq/pics/scalable/surface.svg deleted file mode 100644 index 40ed239..0000000 --- a/examples/animation/sub-attaq/pics/scalable/surface.svg +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/scalable/torpedo.svg b/examples/animation/sub-attaq/pics/scalable/torpedo.svg deleted file mode 100644 index 48e429d..0000000 --- a/examples/animation/sub-attaq/pics/scalable/torpedo.svg +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/animation/sub-attaq/pics/small/background.png b/examples/animation/sub-attaq/pics/small/background.png deleted file mode 100644 index 5ad3db6..0000000 Binary files a/examples/animation/sub-attaq/pics/small/background.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/small/boat.png b/examples/animation/sub-attaq/pics/small/boat.png deleted file mode 100644 index 114ccc3..0000000 Binary files a/examples/animation/sub-attaq/pics/small/boat.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/small/bomb.png b/examples/animation/sub-attaq/pics/small/bomb.png deleted file mode 100644 index 3af5f2f..0000000 Binary files a/examples/animation/sub-attaq/pics/small/bomb.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/small/submarine.png b/examples/animation/sub-attaq/pics/small/submarine.png deleted file mode 100644 index 0c0c350..0000000 Binary files a/examples/animation/sub-attaq/pics/small/submarine.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/small/surface.png b/examples/animation/sub-attaq/pics/small/surface.png deleted file mode 100644 index 06d0e47..0000000 Binary files a/examples/animation/sub-attaq/pics/small/surface.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/small/torpedo.png b/examples/animation/sub-attaq/pics/small/torpedo.png deleted file mode 100644 index f9c2687..0000000 Binary files a/examples/animation/sub-attaq/pics/small/torpedo.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-a.png b/examples/animation/sub-attaq/pics/welcome/logo-a.png deleted file mode 100644 index 67dd76d..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-a.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-a2.png b/examples/animation/sub-attaq/pics/welcome/logo-a2.png deleted file mode 100644 index 17668b0..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-a2.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-b.png b/examples/animation/sub-attaq/pics/welcome/logo-b.png deleted file mode 100644 index cf6c045..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-b.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-dash.png b/examples/animation/sub-attaq/pics/welcome/logo-dash.png deleted file mode 100644 index 219233c..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-dash.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-excl.png b/examples/animation/sub-attaq/pics/welcome/logo-excl.png deleted file mode 100644 index 8dd0a2e..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-excl.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-q.png b/examples/animation/sub-attaq/pics/welcome/logo-q.png deleted file mode 100644 index 86e588d..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-q.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-s.png b/examples/animation/sub-attaq/pics/welcome/logo-s.png deleted file mode 100644 index 7b6a36e..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-s.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-t.png b/examples/animation/sub-attaq/pics/welcome/logo-t.png deleted file mode 100644 index b2e3526..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-t.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-t2.png b/examples/animation/sub-attaq/pics/welcome/logo-t2.png deleted file mode 100644 index b11a778..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-t2.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pics/welcome/logo-u.png b/examples/animation/sub-attaq/pics/welcome/logo-u.png deleted file mode 100644 index 24eede8..0000000 Binary files a/examples/animation/sub-attaq/pics/welcome/logo-u.png and /dev/null differ diff --git a/examples/animation/sub-attaq/pixmapitem.cpp b/examples/animation/sub-attaq/pixmapitem.cpp deleted file mode 100644 index ed0f075..0000000 --- a/examples/animation/sub-attaq/pixmapitem.cpp +++ /dev/null @@ -1,59 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "pixmapitem.h" - -//Qt -#include - -PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsPixmapItem(parent),name(fileName) -{ - loadPixmap(mode); -} - -void PixmapItem::loadPixmap(GraphicsScene::Mode mode) -{ - if (mode == GraphicsScene::Big) - setPixmap(":/big/" + name); - else - setPixmap(":/small/" + name); -} diff --git a/examples/animation/sub-attaq/pixmapitem.h b/examples/animation/sub-attaq/pixmapitem.h deleted file mode 100644 index e32973e..0000000 --- a/examples/animation/sub-attaq/pixmapitem.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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef __PIXMAPITEM__H__ -#define __PIXMAPITEM__H__ - -//Own -#include "graphicsscene.h" - -//Qt -#include - -class PixmapItem : public QGraphicsPixmapItem -{ -public: - PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem * parent = 0); - -private: - void loadPixmap(GraphicsScene::Mode mode); - - QString name; - QPixmap pixmap; -}; - -#endif //__PIXMAPITEM__H__ diff --git a/examples/animation/sub-attaq/progressitem.cpp b/examples/animation/sub-attaq/progressitem.cpp deleted file mode 100644 index 9ccaa72..0000000 --- a/examples/animation/sub-attaq/progressitem.cpp +++ /dev/null @@ -1,67 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "progressitem.h" -#include "pixmapitem.h" - -ProgressItem::ProgressItem (QGraphicsItem * parent) - : QGraphicsTextItem(parent), currentLevel(1), currentScore(0) -{ - setFont(QFont("Comic Sans MS")); - setPos(parentItem()->boundingRect().topRight() - QPointF(180, -5)); -} - -void ProgressItem::setLevel(int level) -{ - currentLevel = level; - updateProgress(); -} - -void ProgressItem::setScore(int score) -{ - currentScore = score; - updateProgress(); -} - -void ProgressItem::updateProgress() -{ - setHtml(QString("Level : %1 Score : %2").arg(currentLevel).arg(currentScore)); -} diff --git a/examples/animation/sub-attaq/progressitem.h b/examples/animation/sub-attaq/progressitem.h deleted file mode 100644 index 7be57c9..0000000 --- a/examples/animation/sub-attaq/progressitem.h +++ /dev/null @@ -1,61 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PROGRESSITEM_H -#define PROGRESSITEM_H - -//Qt -#include - -class ProgressItem : public QGraphicsTextItem -{ -public: - ProgressItem(QGraphicsItem * parent = 0); - void setLevel(int level); - void setScore(int score); - -private: - void updateProgress(); - int currentLevel; - int currentScore; -}; - -#endif // PROGRESSITEM_H diff --git a/examples/animation/sub-attaq/qanimationstate.cpp b/examples/animation/sub-attaq/qanimationstate.cpp deleted file mode 100644 index 4e6df56..0000000 --- a/examples/animation/sub-attaq/qanimationstate.cpp +++ /dev/null @@ -1,150 +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 QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qanimationstate.h" - -#include - -QT_BEGIN_NAMESPACE - -/*! -\class QAnimationState - -\brief The QAnimationState class provides state that handle an animation and emit -a signal when this animation is finished. - -\ingroup statemachine - -QAnimationState provides a state that handle an animation. It will start this animation -when the state is entered and stop it when it is leaved. When the animation has finished the -state emit animationFinished signal. -QAnimationState is part of \l{The State Machine Framework}. - -\code -QStateMachine machine; -QAnimationState *s = new QAnimationState(machine->rootState()); -QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos"); -s->setAnimation(animation); -QState *s2 = new QState(machine->rootState()); -s->addTransition(s, SIGNAL(animationFinished()), s2); -machine.start(); -\endcode - -\sa QState, {The Animation Framework} -*/ - - -#ifndef QT_NO_ANIMATION - -/*! - Constructs a new state with the given \a parent state. -*/ -QAnimationState::QAnimationState(QState *parent) - : QState(parent), m_animation(0) -{ -} - -/*! - Destroys the animation state. -*/ -QAnimationState::~QAnimationState() -{ -} - -/*! - Set an \a animation for this QAnimationState. If an animation was previously handle by this - state then it won't emit animationFinished for the old animation. The QAnimationState doesn't - take the ownership of the animation. -*/ -void QAnimationState::setAnimation(QAbstractAnimation *animation) -{ - if (animation == m_animation) - return; - - //Disconnect from the previous animation if exist - if(m_animation) - disconnect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); - - m_animation = animation; - - if (m_animation) { - //connect the new animation - connect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); - } -} - -/*! - Returns the animation handle by this animation state, or 0 if there is no animation. -*/ -QAbstractAnimation* QAnimationState::animation() const -{ - return m_animation; -} - -/*! - \reimp -*/ -void QAnimationState::onEntry(QEvent *) -{ - if (m_animation) - m_animation->start(); -} - -/*! - \reimp -*/ -void QAnimationState::onExit(QEvent *) -{ - if (m_animation) - m_animation->stop(); -} - -/*! - \reimp -*/ -bool QAnimationState::event(QEvent *e) -{ - return QState::event(e); -} - -QT_END_NAMESPACE - -#endif diff --git a/examples/animation/sub-attaq/qanimationstate.h b/examples/animation/sub-attaq/qanimationstate.h deleted file mode 100644 index 6c5b565..0000000 --- a/examples/animation/sub-attaq/qanimationstate.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 QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANIMATIONSTATE_H -#define QANIMATIONSTATE_H - -#ifndef QT_STATEMACHINE_SOLUTION -# include -# include -#else -# include "qstate.h" -# include "qabstractanimation.h" -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_ANIMATION - -class QAbstractAnimation; - -class QAnimationState : public QState -{ - Q_OBJECT -public: - QAnimationState(QState *parent = 0); - ~QAnimationState(); - - void setAnimation(QAbstractAnimation *animation); - QAbstractAnimation* animation() const; - -signals: - void animationFinished(); - -protected: - void onEntry(QEvent *); - void onExit(QEvent *); - bool event(QEvent *e); - -private: - Q_DISABLE_COPY(QAnimationState) - QAbstractAnimation *m_animation; -}; - -#endif - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QANIMATIONSTATE_H diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp deleted file mode 100644 index d63737f..0000000 --- a/examples/animation/sub-attaq/states.cpp +++ /dev/null @@ -1,325 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "states.h" -#include "graphicsscene.h" -#include "boat.h" -#include "submarine.h" -#include "torpedo.h" -#include "animationmanager.h" -#include "progressitem.h" - -//Qt -#include -#include -#include -#include -#include -#include - -PlayState::PlayState(GraphicsScene *scene, QState *parent) - : QState(parent), - scene(scene), - machine(0), - currentLevel(0), - score(0) -{ -} - -PlayState::~PlayState() -{ -} - -void PlayState::onEntry(QEvent *) -{ - //We are now playing? - if (machine) { - machine->stop(); - scene->clearScene(); - currentLevel = 0; - score = 0; - delete machine; - } - - machine = new QStateMachine(this); - - //This state is when player is playing - LevelState *levelState = new LevelState(scene, this, machine); - - //This state is when the player is actually playing but the game is not paused - QState *playingState = new QState(levelState); - levelState->setInitialState(playingState); - - //This state is when the game is paused - PauseState *pauseState = new PauseState(scene, levelState); - - //We have one view, it receive the key press event - QKeyEventTransition *pressPplay = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P); - pressPplay->setTargetState(pauseState); - QKeyEventTransition *pressPpause = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P); - pressPpause->setTargetState(playingState); - - //Pause "P" is triggered, the player pause the game - playingState->addTransition(pressPplay); - - //To get back playing when the game has been paused - pauseState->addTransition(pressPpause); - - //This state is when player have lost - LostState *lostState = new LostState(scene, this, machine); - - //This state is when player have won - WinState *winState = new WinState(scene, this, machine); - - //The boat has been destroyed then the game is finished - levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState); - - //This transition check if we won or not - WinTransition *winTransition = new WinTransition(scene, this, winState); - - //The boat has been destroyed then the game is finished - levelState->addTransition(winTransition); - - //This state is an animation when the score changed - UpdateScoreState *scoreState = new UpdateScoreState(this, levelState); - - //This transition update the score when a submarine die - UpdateScoreTransition *scoreTransition = new UpdateScoreTransition(scene, this, levelState); - scoreTransition->setTargetState(scoreState); - - //The boat has been destroyed then the game is finished - playingState->addTransition(scoreTransition); - - //We go back to play state - scoreState->addTransition(playingState); - - //We start playing!!! - machine->setInitialState(levelState); - - //Final state - QFinalState *final = new QFinalState(machine); - - //This transition is triggered when the player press space after completing a level - CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space); - spaceTransition->setTargetState(levelState); - winState->addTransition(spaceTransition); - - //We lost we should reach the final state - lostState->addTransition(lostState, SIGNAL(finished()), final); - - machine->start(); -} - -LevelState::LevelState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) -{ -} -void LevelState::onEntry(QEvent *) -{ - initializeLevel(); -} - -void LevelState::initializeLevel() -{ - //we re-init the boat - scene->boat->setPos(scene->width()/2, scene->sealLevel() - scene->boat->size().height()); - scene->boat->setCurrentSpeed(0); - scene->boat->setCurrentDirection(Boat::None); - scene->boat->setBombsLaunched(0); - scene->boat->show(); - scene->setFocusItem(scene->boat,Qt::OtherFocusReason); - scene->boat->run(); - - scene->progressItem->setScore(game->score); - scene->progressItem->setLevel(game->currentLevel + 1); - - GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel); - - for (int i = 0; i < currentLevelDescription.submarines.size(); ++i ) { - - QPair subContent = currentLevelDescription.submarines.at(i); - GraphicsScene::SubmarineDescription submarineDesc = scene->submarinesData.at(subContent.first); - - for (int j = 0; j < subContent.second; ++j ) { - SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points); - scene->addItem(sub); - int random = (qrand() % 15 + 1); - qreal x = random == 13 || random == 5 ? 0 : scene->width() - sub->size().width(); - qreal y = scene->height() -(qrand() % 150 + 1) - sub->size().height(); - sub->setPos(x,y); - sub->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left); - sub->setCurrentSpeed(qrand() % 3 + 1); - } - } -} - -/** Pause State */ -PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene) -{ -} -void PauseState::onEntry(QEvent *) -{ - AnimationManager::self()->pauseAll(); - scene->boat->setEnabled(false); -} -void PauseState::onExit(QEvent *) -{ - AnimationManager::self()->resumeAll(); - scene->boat->setEnabled(true); - scene->boat->setFocus(); -} - -/** Lost State */ -LostState::LostState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) -{ -} - -void LostState::onEntry(QEvent *) -{ - //The message to display - QString message = QString("You lose on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); - - //We set the level back to 0 - game->currentLevel = 0; - - //We set the score back to 0 - game->score = 0; - - //We clear the scene - scene->clearScene(); - - //we have only one view - QMessageBox::information(scene->views().at(0),"You lose",message); -} - -/** Win State */ -WinState::WinState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) -{ -} - -void WinState::onEntry(QEvent *) -{ - //We clear the scene - scene->clearScene(); - - QString message; - if (scene->levelsData.size() - 1 != game->currentLevel) { - message = QString("You win the level %1. Your score is %2.\nPress Space to continue after closing this dialog.").arg(game->currentLevel+1).arg(game->score); - //We increment the level number - game->currentLevel++; - } else { - message = QString("You finish the game on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); - //We set the level back to 0 - game->currentLevel = 0; - //We set the score back to 0 - game->score = 0; - } - - //we have only one view - QMessageBox::information(scene->views().at(0),"You win",message); -} - -/** UpdateScore State */ -UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(parent) -{ - this->game = game; -} -void UpdateScoreState::onEntry(QEvent *e) -{ - QState::onEntry(e); -} - -/** Win transition */ -UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) - : QSignalTransition(scene,SIGNAL(subMarineDestroyed(int)), QList() << target), - game(game), scene(scene) -{ -} - -bool UpdateScoreTransition::eventTest(QEvent *event) -{ - if (!QSignalTransition::eventTest(event)) - return false; - else { - QSignalEvent *se = static_cast(event); - game->score += se->arguments().at(0).toInt(); - scene->progressItem->setScore(game->score); - return true; - } -} - -/** Win transition */ -WinTransition::WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) - : QSignalTransition(scene,SIGNAL(allSubMarineDestroyed(int)), QList() << target), - game(game), scene(scene) -{ -} - -bool WinTransition::eventTest(QEvent *event) -{ - if (!QSignalTransition::eventTest(event)) - return false; - else { - QSignalEvent *se = static_cast(event); - game->score += se->arguments().at(0).toInt(); - scene->progressItem->setScore(game->score); - return true; - } -} - -/** Space transition */ -CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key) - : QKeyEventTransition(widget, type, key), - game(game) -{ -} - -bool CustomSpaceTransition::eventTest(QEvent *event) -{ - Q_UNUSED(event); - if (!QKeyEventTransition::eventTest(event)) - return false; - if (game->currentLevel != 0) - return true; - else - return false; - -} diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h deleted file mode 100644 index c3d81e7..0000000 --- a/examples/animation/sub-attaq/states.h +++ /dev/null @@ -1,180 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef STATES_H -#define STATES_H - -//Qt -#include -#include -#include -#include -#include - -class GraphicsScene; -class Boat; -class SubMarine; -QT_BEGIN_NAMESPACE -class QStateMachine; -QT_END_NAMESPACE - -class PlayState : public QState -{ -public: - PlayState(GraphicsScene *scene, QState *parent = 0); - ~PlayState(); - - protected: - void onEntry(QEvent *); - -private : - GraphicsScene *scene; - QStateMachine *machine; - int currentLevel; - int score; - QState *parallelChild; - - friend class UpdateScoreState; - friend class UpdateScoreTransition; - friend class WinTransition; - friend class CustomSpaceTransition; - friend class WinState; - friend class LostState; - friend class LevelState; -}; - -class LevelState : public QState -{ -public: - LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0); -protected: - void onEntry(QEvent *); -private : - void initializeLevel(); - GraphicsScene *scene; - PlayState *game; -}; - -class PauseState : public QState -{ -public: - PauseState(GraphicsScene *scene, QState *parent = 0); - -protected: - void onEntry(QEvent *); - void onExit(QEvent *); -private : - GraphicsScene *scene; - Boat *boat; -}; - -class LostState : public QState -{ -public: - LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0); - -protected: - void onEntry(QEvent *); -private : - GraphicsScene *scene; - PlayState *game; -}; - -class WinState : public QState -{ -public: - WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0); - -protected: - void onEntry(QEvent *); -private : - GraphicsScene *scene; - PlayState *game; -}; - -class UpdateScoreState : public QState -{ -public: - UpdateScoreState(PlayState *game, QState *parent); -protected: - void onEntry(QEvent *); -private: - QPropertyAnimation *scoreAnimation; - PlayState *game; -}; - -//These transtion is used to update the score -class UpdateScoreTransition : public QSignalTransition -{ -public: - UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target); -protected: - virtual bool eventTest(QEvent *event); -private: - PlayState * game; - GraphicsScene *scene; -}; - -//These transtion test if we have won the game -class WinTransition : public QSignalTransition -{ -public: - WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target); -protected: - virtual bool eventTest(QEvent *event); -private: - PlayState * game; - GraphicsScene *scene; -}; - -//These transtion is true if one level has been completed and the player want to continue - class CustomSpaceTransition : public QKeyEventTransition -{ -public: - CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key); -protected: - virtual bool eventTest(QEvent *event); -private: - PlayState *game; - int key; -}; - -#endif // STATES_H diff --git a/examples/animation/sub-attaq/sub-attaq.pro b/examples/animation/sub-attaq/sub-attaq.pro deleted file mode 100644 index d13a099..0000000 --- a/examples/animation/sub-attaq/sub-attaq.pro +++ /dev/null @@ -1,36 +0,0 @@ -contains(QT_CONFIG, opengl):QT += opengl - -HEADERS += boat.h \ - bomb.h \ - mainwindow.h \ - submarine.h \ - torpedo.h \ - pixmapitem.h \ - graphicsscene.h \ - animationmanager.h \ - states.h \ - boat_p.h \ - submarine_p.h \ - custompropertyanimation.h \ - qanimationstate.h \ - progressitem.h -SOURCES += boat.cpp \ - bomb.cpp \ - main.cpp \ - mainwindow.cpp \ - submarine.cpp \ - torpedo.cpp \ - pixmapitem.cpp \ - graphicsscene.cpp \ - animationmanager.cpp \ - states.cpp \ - custompropertyanimation.cpp \ - qanimationstate.cpp \ - progressitem.cpp -RESOURCES += subattaq.qrc - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/animation/sub-attaq -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sub-attaq.pro pics -sources.path = $$[QT_INSTALL_EXAMPLES]/animation/sub-attaq -INSTALLS += target sources diff --git a/examples/animation/sub-attaq/subattaq.qrc b/examples/animation/sub-attaq/subattaq.qrc deleted file mode 100644 index 80a3af1..0000000 --- a/examples/animation/sub-attaq/subattaq.qrc +++ /dev/null @@ -1,39 +0,0 @@ - - - pics/scalable/sub-attaq.svg - pics/scalable/submarine.svg - pics/scalable/boat.svg - pics/scalable/torpedo.svg - pics/welcome/logo-s.png - pics/welcome/logo-u.png - pics/welcome/logo-b.png - pics/welcome/logo-dash.png - pics/welcome/logo-a.png - pics/welcome/logo-t.png - pics/welcome/logo-t2.png - pics/welcome/logo-a2.png - pics/welcome/logo-q.png - pics/welcome/logo-excl.png - pics/big/background.png - pics/big/boat.png - pics/big/bomb.png - pics/big/submarine.png - pics/big/surface.png - pics/big/torpedo.png - pics/small/background.png - pics/small/boat.png - pics/small/bomb.png - pics/small/submarine.png - pics/small/surface.png - pics/small/torpedo.png - pics/big/explosion/boat/step1.png - pics/big/explosion/boat/step2.png - pics/big/explosion/boat/step3.png - pics/big/explosion/boat/step4.png - pics/big/explosion/submarine/step1.png - pics/big/explosion/submarine/step2.png - pics/big/explosion/submarine/step3.png - pics/big/explosion/submarine/step4.png - data.xml - - diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp deleted file mode 100644 index 78a9539..0000000 --- a/examples/animation/sub-attaq/submarine.cpp +++ /dev/null @@ -1,211 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "submarine.h" -#include "submarine_p.h" -#include "torpedo.h" -#include "pixmapitem.h" -#include "graphicsscene.h" -#include "animationmanager.h" -#include "custompropertyanimation.h" -#include "qanimationstate.h" - -#include -#include -#include -#include - -static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub) -{ - QSequentialAnimationGroup *group = new QSequentialAnimationGroup(sub); -#if QT_VERSION >=0x040500 - PixmapItem *step1 = new PixmapItem(QString("explosion/submarine/step1"),GraphicsScene::Big, sub); - step1->setZValue(6); - PixmapItem *step2 = new PixmapItem(QString("explosion/submarine/step2"),GraphicsScene::Big, sub); - step2->setZValue(6); - PixmapItem *step3 = new PixmapItem(QString("explosion/submarine/step3"),GraphicsScene::Big, sub); - step3->setZValue(6); - PixmapItem *step4 = new PixmapItem(QString("explosion/submarine/step4"),GraphicsScene::Big, sub); - step4->setZValue(6); - step1->setOpacity(0); - step2->setOpacity(0); - step3->setOpacity(0); - step4->setOpacity(0); - CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(sub); - anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim1->setDuration(100); - anim1->setEndValue(1); - CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(sub); - anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim2->setDuration(100); - anim2->setEndValue(1); - CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(sub); - anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim3->setDuration(100); - anim3->setEndValue(1); - CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(sub); - anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); - anim4->setDuration(100); - anim4->setEndValue(1); - group->addAnimation(anim1); - group->addAnimation(anim2); - group->addAnimation(anim3); - group->addAnimation(anim4); -#else - // work around for a bug where we don't transition if the duration is zero. - QtPauseAnimation *anim = new QtPauseAnimation(group); - anim->setDuration(1); - group->addAnimation(anim); -#endif - AnimationManager::self()->registerAnimation(group); - return group; -} - - -SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * parent, Qt::WindowFlags wFlags) - : QGraphicsWidget(parent,wFlags), subType(type), subName(name), subPoints(points), speed(0), direction(SubMarine::None) -{ - pixmapItem = new PixmapItem(QString("submarine"),GraphicsScene::Big, this); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setZValue(5); - setFlags(QGraphicsItem::ItemIsMovable); - resize(pixmapItem->boundingRect().width(),pixmapItem->boundingRect().height()); - setTransformOrigin(boundingRect().center()); - - //We setup the state machine of the submarine - QStateMachine *machine = new QStateMachine(this); - - //This state is when the boat is moving/rotating - QState *moving = new QState(machine); - - //This state is when the boat is moving from left to right - MovementState *movement = new MovementState(this, moving); - - //This state is when the boat is moving from left to right - ReturnState *rotation = new ReturnState(this, moving); - - //This is the initial state of the moving root state - moving->setInitialState(movement); - - movement->addTransition(this, SIGNAL(subMarineStateChanged()), moving); - - //This is the initial state of the machine - machine->setInitialState(moving); - - //End - QFinalState *final = new QFinalState(machine); - - //If the moving animation is finished we move to the return state - movement->addTransition(movement, SIGNAL(animationFinished()), rotation); - - //If the return animation is finished we move to the moving state - rotation->addTransition(rotation, SIGNAL(animationFinished()), movement); - - //This state play the destroyed animation - QAnimationState *destroyedState = new QAnimationState(machine); - destroyedState->setAnimation(setupDestroyAnimation(this)); - - //Play a nice animation when the submarine is destroyed - moving->addTransition(this, SIGNAL(subMarineDestroyed()), destroyedState); - - //Transition to final state when the destroyed animation is finished - destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); - - //The machine has finished to be executed, then the submarine is dead - connect(machine,SIGNAL(finished()),this, SIGNAL(subMarineExecutionFinished())); - - machine->start(); -} - -int SubMarine::points() -{ - return subPoints; -} - -void SubMarine::setCurrentDirection(SubMarine::Movement direction) -{ - if (this->direction == direction) - return; - if (direction == SubMarine::Right && this->direction == SubMarine::None) { - setYRotation(180); - } - this->direction = direction; -} - -enum SubMarine::Movement SubMarine::currentDirection() const -{ - return direction; -} - -void SubMarine::setCurrentSpeed(int speed) -{ - if (speed < 0 || speed > 3) { - qWarning("SubMarine::setCurrentSpeed : The speed is invalid"); - } - this->speed = speed; - emit subMarineStateChanged(); -} - -int SubMarine::currentSpeed() const -{ - return speed; -} - -void SubMarine::launchTorpedo(int speed) -{ - Torpedo * torp = new Torpedo(); - GraphicsScene *scene = static_cast(this->scene()); - scene->addItem(torp); - torp->setPos(x(), y()); - torp->setCurrentSpeed(speed); - torp->launch(); -} - -void SubMarine::destroy() -{ - emit subMarineDestroyed(); -} - -int SubMarine::type() const -{ - return Type; -} diff --git a/examples/animation/sub-attaq/submarine.h b/examples/animation/sub-attaq/submarine.h deleted file mode 100644 index 481e816..0000000 --- a/examples/animation/sub-attaq/submarine.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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef __SUBMARINE__H__ -#define __SUBMARINE__H__ - -//Qt -#include -#include - -class PixmapItem; - -class Torpedo; - -class SubMarine : public QGraphicsWidget -{ -Q_OBJECT -public: - enum Movement { - None = 0, - Left, - Right - }; - enum { Type = UserType + 1 }; - SubMarine(int type, const QString &name, int points, QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); - - int points(); - - void setCurrentDirection(Movement direction); - enum Movement currentDirection() const; - - void setCurrentSpeed(int speed); - int currentSpeed() const; - - void launchTorpedo(int speed); - void destroy(); - - virtual int type() const; - -signals: - void subMarineDestroyed(); - void subMarineExecutionFinished(); - void subMarineStateChanged(); - -private: - int subType; - QString subName; - int subPoints; - int speed; - Movement direction; - PixmapItem *pixmapItem; -}; - -#endif //__SUBMARINE__H__ diff --git a/examples/animation/sub-attaq/submarine_p.h b/examples/animation/sub-attaq/submarine_p.h deleted file mode 100644 index e8df877..0000000 --- a/examples/animation/sub-attaq/submarine_p.h +++ /dev/null @@ -1,139 +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 SUBMARINE_P_H -#define SUBMARINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -//Own -#include "animationmanager.h" -#include "submarine.h" -#include "qanimationstate.h" - -//Qt -#include -#include - -//This state is describing when the boat is moving right -class MovementState : public QAnimationState -{ -Q_OBJECT -public: - MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) - { - movementAnimation = new QPropertyAnimation(submarine, "pos"); - connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &))); - setAnimation(movementAnimation); - AnimationManager::self()->registerAnimation(movementAnimation); - this->submarine = submarine; - } - -protected slots: - void onAnimationMovementValueChanged(const QVariant &) - { - if (qrand() % 200 + 1 == 3) - submarine->launchTorpedo(qrand() % 3 + 1); - } - -protected: - void onEntry(QEvent *e) - { - if (submarine->currentDirection() == SubMarine::Left) { - movementAnimation->setEndValue(QPointF(0,submarine->y())); - movementAnimation->setDuration(submarine->x()/submarine->currentSpeed()*12); - } - else /*if (submarine->currentDirection() == SubMarine::Right)*/ { - movementAnimation->setEndValue(QPointF(submarine->scene()->width()-submarine->size().width(),submarine->y())); - movementAnimation->setDuration((submarine->scene()->width()-submarine->size().width()-submarine->x())/submarine->currentSpeed()*12); - } - movementAnimation->setStartValue(submarine->pos()); - QAnimationState::onEntry(e); - } - -private: - SubMarine *submarine; - QPropertyAnimation *movementAnimation; -}; - -//This state is describing when the boat is moving right -class ReturnState : public QAnimationState -{ -public: - ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) - { - returnAnimation = new QPropertyAnimation(submarine, "yRotation"); - AnimationManager::self()->registerAnimation(returnAnimation); - setAnimation(returnAnimation); - this->submarine = submarine; - } - -protected: - void onEntry(QEvent *e) - { - returnAnimation->stop(); - returnAnimation->setStartValue(submarine->yRotation()); - returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.); - returnAnimation->setDuration(500); - QAnimationState::onEntry(e); - } - - void onExit(QEvent *e) - { - submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right); - QAnimationState::onExit(e); - } - -private: - SubMarine *submarine; - QPropertyAnimation *returnAnimation; -}; - -#endif // SUBMARINE_P_H diff --git a/examples/animation/sub-attaq/torpedo.cpp b/examples/animation/sub-attaq/torpedo.cpp deleted file mode 100644 index fe79488..0000000 --- a/examples/animation/sub-attaq/torpedo.cpp +++ /dev/null @@ -1,120 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//Own -#include "torpedo.h" -#include "pixmapitem.h" -#include "boat.h" -#include "graphicsscene.h" -#include "animationmanager.h" -#include "qanimationstate.h" - -#include -#include -#include - -Torpedo::Torpedo(QGraphicsItem * parent, Qt::WindowFlags wFlags) - : QGraphicsWidget(parent,wFlags), currentSpeed(0), launchAnimation(0) -{ - pixmapItem = new PixmapItem(QString::fromLatin1("torpedo"),GraphicsScene::Big, this); - setZValue(2); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setFlags(QGraphicsItem::ItemIsMovable); - resize(pixmapItem->boundingRect().size()); -} - -void Torpedo::launch() -{ - launchAnimation = new QPropertyAnimation(this, "pos"); - AnimationManager::self()->registerAnimation(launchAnimation); - launchAnimation->setEndValue(QPointF(x(),qobject_cast(scene())->sealLevel() - 15)); - launchAnimation->setEasingCurve(QEasingCurve::InQuad); - launchAnimation->setDuration(y()/currentSpeed*10); - connect(launchAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &))); - - //We setup the state machine of the torpedo - QStateMachine *machine = new QStateMachine(this); - - //This state is when the launch animation is playing - QAnimationState *launched = new QAnimationState(machine); - launched->setAnimation(launchAnimation); - - //End - QFinalState *final = new QFinalState(machine); - - machine->setInitialState(launched); - - //### Add a nice animation when the torpedo is destroyed - launched->addTransition(this, SIGNAL(torpedoExplosed()),final); - - //If the animation is finished, then we move to the final state - launched->addTransition(launched, SIGNAL(animationFinished()), final); - - //The machine has finished to be executed, then the boat is dead - connect(machine,SIGNAL(finished()),this, SIGNAL(torpedoExecutionFinished())); - - machine->start(); -} - -void Torpedo::setCurrentSpeed(int speed) -{ - if (speed < 0) { - qWarning("Torpedo::setCurrentSpeed : The speed is invalid"); - return; - } - currentSpeed = speed; -} - -void Torpedo::onAnimationLaunchValueChanged(const QVariant &) -{ - foreach (QGraphicsItem *item , collidingItems(Qt::IntersectsItemBoundingRect)) { - if (item->type() == Boat::Type) { - Boat *b = static_cast(item); - b->destroy(); - } - } -} - -void Torpedo::destroy() -{ - launchAnimation->stop(); - emit torpedoExplosed(); -} diff --git a/examples/animation/sub-attaq/torpedo.h b/examples/animation/sub-attaq/torpedo.h deleted file mode 100644 index c44037f..0000000 --- a/examples/animation/sub-attaq/torpedo.h +++ /dev/null @@ -1,75 +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 QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef __TORPEDO__H__ -#define __TORPEDO__H__ - -//Qt -#include - -#include -#include - -class PixmapItem; - -class Torpedo : public QGraphicsWidget -{ -Q_OBJECT -public: - Torpedo(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); - void launch(); - void setCurrentSpeed(int speed); - void destroy(); - -signals: - void torpedoExplosed(); - void torpedoExecutionFinished(); - -private slots: - void onAnimationLaunchValueChanged(const QVariant &); - -private: - int currentSpeed; - PixmapItem *pixmapItem; - QVariantAnimation *launchAnimation; -}; - -#endif //__TORPEDO__H__ -- cgit v0.12 From e70af37dba3defc0f1b0a08cb5770d3662f3f0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 1 Jul 2009 17:25:49 +0200 Subject: Fixed incorrect QGLFramebufferObject documentation. Reviewed-by: Gunnar Sletta --- src/opengl/qglframebufferobject.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index 3685661..abec78a 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -746,8 +746,11 @@ QGLFramebufferObject::~QGLFramebufferObject() The framebuffer can become invalid if the initialization process fails, the user attaches an invalid buffer to the framebuffer - object, or a non-power of 2 width/height is specified as the + object, or a non-power of two width/height is specified as the texture size if the texture target is \c{GL_TEXTURE_2D}. + The non-power of two limitation does not apply if the OpenGL version + is 2.0 or higher, or if the GL_ARB_texture_non_power_of_two extension + is present. */ bool QGLFramebufferObject::isValid() const { -- cgit v0.12 From a4e4c36af926bb00c59f71273b9f8d74e16dea0d Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 28 Jul 2009 14:51:40 +0200 Subject: Doc: Cleaning up. This closes task 235801. --- src/gui/painting/qtransform.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 45939c1..8a9d6f1 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -101,7 +101,7 @@ QT_BEGIN_NAMESPACE allowing perspective transformations. QTransform's toAffine() method allows casting QTransform to QMatrix. If a perspective transformation has been specified on the matrix, then the - conversion to an affine QMatrix will cause loss of data. + conversion will cause loss of data. QTransform is the recommended transformation class in Qt. @@ -125,11 +125,13 @@ QT_BEGIN_NAMESPACE which returns true if the matrix is non-singular (i.e. AB = BA = I). The inverted() function returns an inverted copy of \e this matrix if it is invertible (otherwise it returns the identity - matrix). In addition, QTransform provides the det() function - returning the matrix's determinant. + matrix), and adjoint() returns the matrix's classical adjoint. + In addition, QTransform provides the determinant() function which + returns the matrix's determinant. - Finally, the QTransform class supports matrix multiplication, and - objects of the class can be streamed as well as compared. + Finally, the QTransform class supports matrix multiplication, addition + and subtraction, and objects of the class can be streamed as well + as compared. \tableofcontents @@ -191,7 +193,7 @@ QT_BEGIN_NAMESPACE The various matrix elements can be set when constructing the matrix, or by using the setMatrix() function later on. They can also be manipulated using the translate(), rotate(), scale() and - shear() convenience functions, The currently set values can be + shear() convenience functions. The currently set values can be retrieved using the m11(), m12(), m13(), m21(), m22(), m23(), m31(), m32(), m33(), dx() and dy() functions. @@ -204,9 +206,9 @@ QT_BEGIN_NAMESPACE to 0) mapping a point to itself. Shearing is controlled by \c m12 and \c m21. Setting these elements to values different from zero will twist the coordinate system. Rotation is achieved by - carefully setting both the shearing factors and the scaling - factors. Perspective transformation is achieved by carefully setting - both the projection factors and the scaling factors. + setting both the shearing factors and the scaling factors. Perspective + transformation is achieved by setting both the projection factors and + the scaling factors. Here's the combined transformations example using basic matrix operations: @@ -958,8 +960,8 @@ QTransform & QTransform::operator=(const QTransform &matrix) /*! Resets the matrix to an identity matrix, i.e. all elements are set - to zero, except \c m11 and \c m22 (specifying the scale) which are - set to 1. + to zero, except \c m11 and \c m22 (specifying the scale) and \c m33 + which are set to 1. \sa QTransform(), isIdentity(), {QTransform#Basic Matrix Operations}{Basic Matrix Operations} @@ -2030,8 +2032,9 @@ QTransform::operator QVariant() const /*! \fn qreal QTransform::det() const + \obsolete - Returns the matrix's determinant. + Returns the matrix's determinant. Use determinant() instead. */ -- cgit v0.12 From 5e2ecd10ac2ffcd403731bbf47e48a4a4aeb2329 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 28 Jul 2009 17:49:40 +0200 Subject: Doc: typo. --- src/gui/styles/qstyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index c869976..598fe6b 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -564,7 +564,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, /*! \enum QStyle::PrimitiveElement - This enum describes that various primitive elements. A + This enum describes the various primitive elements. A primitive element is a common GUI element, such as a checkbox indicator or button bevel. -- cgit v0.12 From b5bcc529f67458c98571d3b726c9d173512aac27 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 28 Jul 2009 17:51:34 +0200 Subject: Doc: Document the purpose of the QTextFormat etc enums, and add a few links to respective APIs. --- src/gui/text/qtextformat.cpp | 101 ++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 29 deletions(-) diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 4e43418..a3dd83e 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -89,7 +89,7 @@ QT_BEGIN_NAMESPACE /*! \fn Type QTextLength::type() const - Returns the type of length. + Returns the type of this length object. \sa QTextLength::Type */ @@ -129,9 +129,15 @@ QT_BEGIN_NAMESPACE /*! \enum QTextLength::Type - \value VariableLength - \value FixedLength - \value PercentageLength + This enum describes the different types a length object can + have. + + \value VariableLength The width of the object is variable + \value FixedLength The width of the object is fixed + \value PercentageLength The width of the object is in + percentage of the maximum width + + \sa type() */ /*! @@ -417,7 +423,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) more useful, and describe the formatting that is applied to specific parts of the document. - A format has a \c FormatType which specifies the kinds of thing it + A format has a \c FormatType which specifies the kinds of text item it can format; e.g. a block of text, a list, a table, etc. A format also has various properties (some specific to particular format types), as described by the Property enum. Every property has a @@ -447,24 +453,32 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) /*! \enum QTextFormat::FormatType - \value InvalidFormat - \value BlockFormat - \value CharFormat - \value ListFormat - \value TableFormat - \value FrameFormat + This enum describes the text item a QTextFormat object is formatting. + + \value InvalidFormat An invalid format as created by the default + constructor + \value BlockFormat The object formats a text block + \value CharFormat The object formats a single character + \value ListFormat The object formats a list + \value TableFormat The object formats a table + \value FrameFormat The object formats a frame \value UserFormat + + \sa QTextCharFormat, QTextBlockFormat, QTextListFormat, + QTextTableFormat, type() */ /*! \enum QTextFormat::Property - \value ObjectIndex + This enum describes the different properties a format can have. + + \value ObjectIndex The index of the formatted object. See objectIndex(). Paragraph and character properties - \value CssFloat + \value CssFloat How a frame is located relative to the surrounding text \value LayoutDirection The layout direction of the text in the document (Qt::LayoutDirection). @@ -482,25 +496,25 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) \value BlockRightMargin \value TextIndent \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in - a QList (internally, in a QList). + a QList (internally, in a QList). \value BlockIndent \value BlockNonBreakableLines - \value BlockTrailingHorizontalRulerWidth + \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element. Character properties \value FontFamily \value FontPointSize + \value FontPixelSize \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using FontPointSize or FontPixelSize. + \value FontFixedPitch \omitvalue FontSizeIncrement \value FontWeight \value FontItalic \value FontUnderline \e{This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead. \value FontOverline \value FontStrikeOut - \value FontFixedPitch - \value FontPixelSize \value FontCapitalization Specifies the capitalization type that is to be applied to the text. \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is specified in percentage, with 100 as the default value. @@ -512,7 +526,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) \omitvalue FirstFontProperty \omitvalue LastFontProperty - + \value TextUnderlineColor \value TextVerticalAlignment \value TextOutline @@ -533,7 +547,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) \value FrameBorder \value FrameBorderBrush - \value FrameBorderStyle + \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum. \value FrameBottomMargin \value FrameHeight \value FrameLeftMargin @@ -565,33 +579,46 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) Selection properties - \value FullWidthSelection When set on the characterFormat of a selection, the whole width of the text will be shown selected + \value FullWidthSelection When set on the characterFormat of a selection, + the whole width of the text will be shown selected. Page break properties - \value PageBreakPolicy + \value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum. \value UserProperty + + \sa property(), setProperty() */ /*! \enum QTextFormat::ObjectTypes + This enum describes what kind of QTextObject this format is associated with. + \value NoObject \value ImageObject \value TableObject \value TableCellObject \value UserObject The first object that can be used for application-specific purposes. + + \sa QTextObject, QTextTable, QTextObject::format() */ /*! \enum QTextFormat::PageBreakFlag \since 4.2 + This enum describes how page breaking is performed when printing. It maps to the + corresponding css properties. + \value PageBreak_Auto The page break is determined automatically depending on the available space on the current page \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table + + \sa QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(), + PageBreakPolicy */ /*! @@ -971,6 +998,8 @@ QVector QTextFormat::lengthVectorProperty(int propertyId) const /*! Returns the property specified by the given \a propertyId. + + \sa Property */ QVariant QTextFormat::property(int propertyId) const { @@ -979,6 +1008,8 @@ QVariant QTextFormat::property(int propertyId) const /*! Sets the property specified by the \a propertyId to the given \a value. + + \sa Property */ void QTextFormat::setProperty(int propertyId, const QVariant &value) { @@ -1006,8 +1037,10 @@ void QTextFormat::setProperty(int propertyId, const QVector &value) } /*! - Clears the value of the property given by \a propertyId - */ + Clears the value of the property given by \a propertyId + + \sa Property +*/ void QTextFormat::clearProperty(int propertyId) { if (!d) @@ -1019,14 +1052,18 @@ void QTextFormat::clearProperty(int propertyId) /*! \fn void QTextFormat::setObjectType(int type) - Sets the text format's object \a type. See \c{ObjectTypes}. + Sets the text format's object type to \a type. + + \sa ObjectTypes, objectType() */ /*! \fn int QTextFormat::objectType() const - Returns the text format's object type. See \c{ObjectTypes}. + Returns the text format's object type. + + \sa ObjectTypes, setObjectType() */ @@ -2116,17 +2153,17 @@ QTextListFormat::QTextListFormat(const QTextFormat &fmt) /*! \fn void QTextListFormat::setStyle(Style style) - Sets the list format's \a style. See \c{Style} for the available styles. + Sets the list format's \a style. - \sa style() + \sa style() Style */ /*! \fn Style QTextListFormat::style() const - Returns the list format's style. See \c{Style}. + Returns the list format's style. - \sa setStyle() + \sa setStyle() Style */ @@ -2188,16 +2225,21 @@ QTextListFormat::QTextListFormat(const QTextFormat &fmt) /*! \enum QTextFrameFormat::Position + This enum describes how a frame is located relative to the surrounding text. + \value InFlow \value FloatLeft \value FloatRight + \sa position() CssFloat */ /*! \enum QTextFrameFormat::BorderStyle \since 4.3 + This enum describes different border styles for the text frame. + \value BorderStyle_None \value BorderStyle_Dotted \value BorderStyle_Dashed @@ -2210,6 +2252,7 @@ QTextListFormat::QTextListFormat(const QTextFormat &fmt) \value BorderStyle_Inset \value BorderStyle_Outset + \sa borderStyle() FrameBorderStyle */ /*! -- cgit v0.12 From 5c11a736367a854c3c201c31265f96e8153f20f5 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 28 Jul 2009 18:16:36 +0200 Subject: Implement a copy constructor for QXmlParseException to avoid crashes when throwing them. Autotest included. Task: 258081 Reviewed-by: Trustme --- src/xml/sax/qxml.cpp | 18 ++++++++++++++++++ src/xml/sax/qxml.h | 1 + tests/auto/qxml/tst_qxml.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index fe1e740..3b1726b 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -244,6 +244,16 @@ public: class QXmlParseExceptionPrivate { public: + QXmlParseExceptionPrivate() + : column(-1), line(-1) + { + } + QXmlParseExceptionPrivate(const QXmlParseExceptionPrivate &other) + : msg(other.msg), column(other.column), line(other.line), + pub(other.pub), sys(other.sys) + { + } + QString msg; int column; int line; @@ -553,6 +563,14 @@ QXmlParseException::QXmlParseException(const QString& name, int c, int l, } /*! + Creates a copy of \a other. +*/ +QXmlParseException::QXmlParseException(const QXmlParseException& other) +{ + d = new QXmlParseExceptionPrivate(*other.d); +} + +/*! Destroys the QXmlParseException. */ QXmlParseException::~QXmlParseException() diff --git a/src/xml/sax/qxml.h b/src/xml/sax/qxml.h index 8aa7e63..6ccd44e 100644 --- a/src/xml/sax/qxml.h +++ b/src/xml/sax/qxml.h @@ -193,6 +193,7 @@ class Q_XML_EXPORT QXmlParseException public: explicit QXmlParseException(const QString &name = QString(), int c = -1, int l = -1, const QString &p = QString(), const QString &s = QString()); + QXmlParseException(const QXmlParseException &other); ~QXmlParseException(); int columnNumber() const; diff --git a/tests/auto/qxml/tst_qxml.cpp b/tests/auto/qxml/tst_qxml.cpp index 13de82f..1bc5ef5 100644 --- a/tests/auto/qxml/tst_qxml.cpp +++ b/tests/auto/qxml/tst_qxml.cpp @@ -57,6 +57,7 @@ Q_OBJECT private slots: void getSetCheck(); void interpretedAs0D() const; + void exception(); }; class MyXmlEntityResolver : public QXmlEntityResolver @@ -213,5 +214,30 @@ void tst_QXml::interpretedAs0D() const QCOMPARE(myHandler.attrName, QChar(0x010D) + QString::fromLatin1("reated-by")); } +void tst_QXml::exception() +{ +#ifndef QT_NO_EXCEPTIONS + QString message = QString::fromLatin1("message"); + int column = 3; + int line = 2; + QString publicId = QString::fromLatin1("publicId"); + QString systemId = QString::fromLatin1("systemId"); + + try { + QXmlParseException e(message, column, line, publicId, systemId); + throw e; + } + catch (QXmlParseException e) { + QCOMPARE(e.message(), message); + QCOMPARE(e.columnNumber(), column); + QCOMPARE(e.lineNumber(), line); + QCOMPARE(e.publicId(), publicId); + QCOMPARE(e.systemId(), systemId); + } +#else + QSKIP("Exceptions not available", SkipAll); +#endif +} + QTEST_MAIN(tst_QXml) #include "tst_qxml.moc" -- cgit v0.12 From 865d5e92b80f8a567746775bb0a1d971af1acf8c Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Tue, 28 Jul 2009 12:40:18 -0700 Subject: Remove a warning in qdirectfbpaintengine These structures are only used in versions after 0.922. Reviewed-by: Donald --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 4b76ef6..030e51f 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -745,6 +745,7 @@ QPixmapData *QDirectFBScreenPrivate::createPixmapData(QPixmapData::PixelType typ return new QDirectFBPixmapData(type); } +#if (Q_DIRECTFB_VERSION >= 0x000923) #ifdef QT_NO_DEBUG struct FlagDescription; static const FlagDescription *accelerationDescriptions = 0; @@ -802,9 +803,6 @@ static const FlagDescription drawDescriptions[] = { }; #endif - - -#if (Q_DIRECTFB_VERSION >= 0x000923) static const QByteArray flagDescriptions(uint mask, const FlagDescription *flags) { #ifdef QT_NO_DEBUG -- cgit v0.12 From d0e8341c9a1549dcf1625381a3681d1dca73e945 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 28 Jul 2009 22:08:25 +0200 Subject: Doc: Re-apply relevant change from 1368c210ef9976f68eb9fb1c3e4dc14f4fa4edd2 Clarified that the format used in QImage::fromData() is the image format, not the pixel format. --- src/gui/image/qimage.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index dd56765..e8ca7a9 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4628,12 +4628,19 @@ bool QImage::loadFromData(const uchar *data, int len, const char *format) binary \a data. The loader attempts to read the image using the specified \a format. If \a format is not specified (which is the default), the loader probes the file for a header to guess the file format. + binary \a data. The loader attempts to read the image, either using the + optional image \a format specified or by determining the image format from + the data. - If the loading of the image failed, this object is a null image. + If \a format is not specified (which is the default), the loader probes the + file for a header to determine the file format. If \a format is specified, + it must be one of the values returned by QImageReader::supportedImageFormats(). + + If the loading of the image fails, the image returned will be a null image. + + \sa load(), save(), {QImage#Reading and Writing Image Files}{Reading and Writing Image Files} + */ - \sa load(), save(), {QImage#Reading and Writing Image - Files}{Reading and Writing Image Files} -*/ QImage QImage::fromData(const uchar *data, int size, const char *format) { QByteArray a = QByteArray::fromRawData(reinterpret_cast(data), size); -- cgit v0.12 From ca1060fbc3a949ec3e0f67017efe8ee6c0b7b86e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 29 Jul 2009 00:27:52 +0200 Subject: Doc: Some final QMatrix cleanups. --- src/gui/graphicsview/qgraphicsitem.cpp | 7 ++++--- src/gui/graphicsview/qgraphicswidget.cpp | 1 + src/gui/painting/qtransform.cpp | 9 ++++++--- src/gui/styles/qstyleoption.cpp | 25 ++++++++++++++++--------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index c8e55e3..06f26a1 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -303,11 +303,12 @@ drop shadow effects and for decoration objects that follow the parent item's geometry without drawing on top of it. - \value ItemUsesExtendedStyleOption The item makes use of either - QStyleOptionGraphicsItem::exposedRect or QStyleOptionGraphicsItem::matrix. + \value ItemUsesExtendedStyleOption The item makes use of either the + exposedRect or matrix member of the QStyleOptionGraphicsItem. Implementers + of QGraphicsItem subclasses should set that flag if this data is required. By default, the exposedRect is initialized to the item's boundingRect and the matrix is untransformed. Enable this flag for more fine-grained values. - Use QStyleOptionGraphicsItem::levelOfDetailFromTransform for a more + Use QStyleOptionGraphicsItem::levelOfDetailFromTransform() for a more fine-grained value. \value ItemHasNoContents The item does not paint anything (i.e., calling diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 6937584..6f56b84 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -2286,6 +2286,7 @@ bool QGraphicsWidget::close() #ifdef Q_NO_USING_KEYWORD /*! \fn const QObjectList &QGraphicsWidget::children() const + \internal This function returns the same value as QObject::children(). It's provided to differentiate between the obsolete member diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 8a9d6f1..a322fe4 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -1775,7 +1775,7 @@ bool QTransform::quadToQuad(const QPolygonF &one, Sets the matrix elements to the specified values, \a m11, \a m12, \a m13 \a m21, \a m22, \a m23 \a m31, \a m32 and \a m33. Note that this function replaces the previous values. - QMatrix provides the translate(), rotate(), scale() and shear() + QTransform provides the translate(), rotate(), scale() and shear() convenience functions to manipulate the various matrix elements based on the currently defined coordinate system. @@ -1953,8 +1953,11 @@ void QTransform::map(int x, int y, int *tx, int *ty) const } /*! - Returns the QTransform cast to a QMatrix. - */ + Returns the QTransform as an affine matrix. + + \warning If a perspective transformation has been specified, + then the conversion will cause loss of data. +*/ const QMatrix &QTransform::toAffine() const { return affine; diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp index 7547dda..0ff7995 100644 --- a/src/gui/styles/qstyleoption.cpp +++ b/src/gui/styles/qstyleoption.cpp @@ -5007,11 +5007,6 @@ QStyleOptionGraphicsItem::QStyleOptionGraphicsItem(int version) of the painter used to draw the item. By default, if no transformations are applied, its value is 1. If zoomed out 1:2, the level of detail will be 0.5, and if zoomed in 2:1, its value is 2. - - For more advanced level-of-detail metrics, use - QStyleOptionGraphicsItem::matrix directly. - - \sa QStyleOptionGraphicsItem::matrix */ qreal QStyleOptionGraphicsItem::levelOfDetailFromTransform(const QTransform &worldTransform) { @@ -5038,20 +5033,32 @@ qreal QStyleOptionGraphicsItem::levelOfDetailFromTransform(const QTransform &wor Make use of this rectangle to speed up item drawing when only parts of the item are exposed. If the whole item is exposed, this rectangle will be the same as QGraphicsItem::boundingRect(). + + This member is only initialized for items that have the + QGraphicsItem::ItemUsesExtendedStyleOption flag set. */ /*! \variable QStyleOptionGraphicsItem::matrix \brief the complete transformation matrix for the item + \obsolete - This matrix is the sum of the item's scene matrix and the matrix of the - painter used for drawing the item. It is provided for convenience, + The QMatrix provided through this member does include information about + any perspective transformations applied to the view or item. To get the + correct transformation matrix, use QPainter::transform() on the painter + passed into the QGraphicsItem::paint() implementation. + + This matrix is the combination of the item's scene matrix and the matrix + of the painter used for drawing the item. It is provided for convenience, allowing anvanced level-of-detail metrics that can be used to speed up item drawing. - To find the dimentions of an item in screen coordinates (i.e., pixels), + To find the dimensions of an item in screen coordinates (i.e., pixels), you can use the mapping functions of QMatrix, such as QMatrix::map(). + This member is only initialized for items that have the + QGraphicsItem::ItemUsesExtendedStyleOption flag set. + \sa QStyleOptionGraphicsItem::levelOfDetailFromTransform() */ @@ -5059,7 +5066,7 @@ qreal QStyleOptionGraphicsItem::levelOfDetailFromTransform(const QTransform &wor \variable QStyleOptionGraphicsItem::levelOfDetail \obsolete - Use QStyleOptionGraphicsItem::levelOfDetailFromTransform + Use QStyleOptionGraphicsItem::levelOfDetailFromTransform() together with QPainter::worldTransform() instead. */ -- cgit v0.12 From 62d81d9955f39bac327affd703b9df006ee8f6f7 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 28 Jul 2009 16:52:13 +1000 Subject: Added a QVariant testlib toString specialization. If comparing two variants fails, the failure message will now output the type and value of the variants (rather than "Compared values are not the same"). Reviewed-by: Thiago --- src/testlib/qtest.h | 25 +++++++++++++++ tests/auto/selftests/cmptest/tst_cmptest.cpp | 46 ++++++++++++++++++++++++++++ tests/auto/selftests/expected_cmptest.txt | 20 ++++++++++-- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 9d6f68d..8cdfab0 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -146,6 +147,30 @@ template<> inline char *toString(const QUrl &uri) return qstrdup(uri.toEncoded().constData()); } +template<> inline char *toString(const QVariant &v) +{ + QByteArray vstring("QVariant("); + if (v.isValid()) { + QByteArray type(v.typeName()); + if (type.isEmpty()) { + type = QByteArray::number(v.userType()); + } + vstring.append(type); + if (!v.isNull()) { + vstring.append(','); + if (v.canConvert(QVariant::String)) { + vstring.append(qVariantValue(v).toLatin1()); + } + else { + vstring.append(""); + } + } + } + vstring.append(')'); + + return qstrdup(vstring.constData()); +} + #ifndef QTEST_NO_SPECIALIZATIONS template<> #endif diff --git a/tests/auto/selftests/cmptest/tst_cmptest.cpp b/tests/auto/selftests/cmptest/tst_cmptest.cpp index 59dd678..7395210 100644 --- a/tests/auto/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/selftests/cmptest/tst_cmptest.cpp @@ -50,6 +50,8 @@ class tst_Cmptest: public QObject private slots: void compare_boolfuncs(); void compare_pointerfuncs(); + void compare_tostring(); + void compare_tostring_data(); }; static bool boolfunc() { return true; } @@ -76,6 +78,50 @@ void tst_Cmptest::compare_pointerfuncs() QCOMPARE(&i, intptr()); } +Q_DECLARE_METATYPE(QVariant) + +class PhonyClass +{}; + +void tst_Cmptest::compare_tostring_data() +{ + QTest::addColumn("actual"); + QTest::addColumn("expected"); + + QTest::newRow("int, string") + << QVariant::fromValue(123) + << QVariant::fromValue(QString("hi")) + ; + + QTest::newRow("both invalid") + << QVariant() + << QVariant() + ; + + QTest::newRow("null hash, invalid") + << QVariant(QVariant::Hash) + << QVariant() + ; + + QTest::newRow("string, null user type") + << QVariant::fromValue(QString::fromLatin1("A simple string")) + << QVariant(QVariant::Type(qRegisterMetaType("PhonyClass"))) + ; + + QTest::newRow("both non-null user type") + << QVariant(qRegisterMetaType("PhonyClass"), (const void*)0) + << QVariant(qRegisterMetaType("PhonyClass"), (const void*)0) + ; +} + +void tst_Cmptest::compare_tostring() +{ + QFETCH(QVariant, actual); + QFETCH(QVariant, expected); + + QCOMPARE(actual, expected); +} + QTEST_MAIN(tst_Cmptest) #include "tst_cmptest.moc" diff --git a/tests/auto/selftests/expected_cmptest.txt b/tests/auto/selftests/expected_cmptest.txt index dc89d9d..f70eba5 100644 --- a/tests/auto/selftests/expected_cmptest.txt +++ b/tests/auto/selftests/expected_cmptest.txt @@ -1,8 +1,24 @@ ********* Start testing of tst_Cmptest ********* -Config: Using QTest library 4.1.0, Qt 4.1.0 +Config: Using QTest library 4.6.0, Qt 4.6.0 PASS : tst_Cmptest::initTestCase() PASS : tst_Cmptest::compare_boolfuncs() PASS : tst_Cmptest::compare_pointerfuncs() +FAIL! : tst_Cmptest::compare_tostring(int, string) Compared values are not the same + Actual (actual): QVariant(int,123) + Expected (expected): QVariant(QString,hi) + Loc: [/home/rmcgover/depot/qt/master/tests/auto/selftests/cmptest/tst_cmptest.cpp(122)] +FAIL! : tst_Cmptest::compare_tostring(null hash, invalid) Compared values are not the same + Actual (actual): QVariant(QVariantHash) + Expected (expected): QVariant() + Loc: [/home/rmcgover/depot/qt/master/tests/auto/selftests/cmptest/tst_cmptest.cpp(122)] +FAIL! : tst_Cmptest::compare_tostring(string, null user type) Compared values are not the same + Actual (actual): QVariant(QString,A simple string) + Expected (expected): QVariant(PhonyClass) + Loc: [/home/rmcgover/depot/qt/master/tests/auto/selftests/cmptest/tst_cmptest.cpp(122)] +FAIL! : tst_Cmptest::compare_tostring(both non-null user type) Compared values are not the same + Actual (actual): QVariant(PhonyClass,) + Expected (expected): QVariant(PhonyClass,) + Loc: [/home/rmcgover/depot/qt/master/tests/auto/selftests/cmptest/tst_cmptest.cpp(122)] PASS : tst_Cmptest::cleanupTestCase() -Totals: 4 passed, 0 failed, 0 skipped +Totals: 4 passed, 4 failed, 0 skipped ********* Finished testing of tst_Cmptest ********* -- cgit v0.12 From a6ea9ce6990003856ecadcca8ce9ddf37949363d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 29 Jul 2009 02:26:43 +0200 Subject: Implement new transformation handling for graphics items. The idea of having separate rotationX/Y/Z, shearX/Y, etc. methods in QGraphicsItem turned out to be not giving us the flexibility we need and wanted. The new code now implements a different scheme, where we keep simple rotate (around z-axis), scale and transformOriginPoint methods, but remove the other ones. Instead we now have an additional list of QGraphicsTransform object. QGraphicsTransform is an abstract class that inherits QObject. Several specializations are provided and can be used to transform (and through property bindings animate) the item. Reviewed-By: Andreas --- demos/sub-attaq/submarine.cpp | 11 +- demos/sub-attaq/submarine.h | 4 + demos/sub-attaq/submarine_p.h | 4 +- src/gui/graphicsview/graphicsview.pri | 4 +- src/gui/graphicsview/qgraphicsitem.cpp | 339 +++++---------- src/gui/graphicsview/qgraphicsitem.h | 42 +- src/gui/graphicsview/qgraphicsitem_p.h | 39 +- src/gui/graphicsview/qgraphicstransform.cpp | 479 +++++++++++++++++++++ src/gui/graphicsview/qgraphicstransform.h | 168 ++++++++ src/gui/graphicsview/qgraphicswidget.cpp | 33 -- src/gui/graphicsview/qgraphicswidget.h | 8 - tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 158 ++----- .../auto/qgraphicstransform/qgraphicstransform.pro | 2 + .../qgraphicstransform/tst_qgraphicstransform.cpp | 162 +++++++ 14 files changed, 998 insertions(+), 455 deletions(-) create mode 100644 src/gui/graphicsview/qgraphicstransform.cpp create mode 100644 src/gui/graphicsview/qgraphicstransform.h create mode 100644 tests/auto/qgraphicstransform/qgraphicstransform.pro create mode 100644 tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp diff --git a/demos/sub-attaq/submarine.cpp b/demos/sub-attaq/submarine.cpp index 78a9539..029e04b 100644 --- a/demos/sub-attaq/submarine.cpp +++ b/demos/sub-attaq/submarine.cpp @@ -109,7 +109,14 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * setZValue(5); setFlags(QGraphicsItem::ItemIsMovable); resize(pixmapItem->boundingRect().width(),pixmapItem->boundingRect().height()); - setTransformOrigin(boundingRect().center()); + setTransformOriginPoint(boundingRect().center()); + + graphicsRotation = new QGraphicsRotation3D(this); + graphicsRotation->setAxis(QVector3D(0, 1, 0)); + graphicsRotation->setOrigin(QPointF(size().width()/2, size().height()/2)); + QList r; + r.append(graphicsRotation); + setTransformations(r); //We setup the state machine of the submarine QStateMachine *machine = new QStateMachine(this); @@ -166,7 +173,7 @@ void SubMarine::setCurrentDirection(SubMarine::Movement direction) if (this->direction == direction) return; if (direction == SubMarine::Right && this->direction == SubMarine::None) { - setYRotation(180); + graphicsRotation->setAngle(180); } this->direction = direction; } diff --git a/demos/sub-attaq/submarine.h b/demos/sub-attaq/submarine.h index 481e816..564e9c6 100644 --- a/demos/sub-attaq/submarine.h +++ b/demos/sub-attaq/submarine.h @@ -45,6 +45,7 @@ //Qt #include #include +#include class PixmapItem; @@ -75,6 +76,8 @@ public: virtual int type() const; + QGraphicsRotation3D *rotation3d() const { return graphicsRotation; } + signals: void subMarineDestroyed(); void subMarineExecutionFinished(); @@ -87,6 +90,7 @@ private: int speed; Movement direction; PixmapItem *pixmapItem; + QGraphicsRotation3D *graphicsRotation; }; #endif //__SUBMARINE__H__ diff --git a/demos/sub-attaq/submarine_p.h b/demos/sub-attaq/submarine_p.h index e8df877..c04b25b 100644 --- a/demos/sub-attaq/submarine_p.h +++ b/demos/sub-attaq/submarine_p.h @@ -109,7 +109,7 @@ class ReturnState : public QAnimationState public: ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) { - returnAnimation = new QPropertyAnimation(submarine, "yRotation"); + returnAnimation = new QPropertyAnimation(submarine->rotation3d(), "angle"); AnimationManager::self()->registerAnimation(returnAnimation); setAnimation(returnAnimation); this->submarine = submarine; @@ -119,7 +119,7 @@ protected: void onEntry(QEvent *e) { returnAnimation->stop(); - returnAnimation->setStartValue(submarine->yRotation()); + returnAnimation->setStartValue(submarine->rotation3d()->angle()); returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.); returnAnimation->setDuration(500); QAnimationState::onEntry(e); diff --git a/src/gui/graphicsview/graphicsview.pri b/src/gui/graphicsview/graphicsview.pri index 0c0747e..9d232e4 100644 --- a/src/gui/graphicsview/graphicsview.pri +++ b/src/gui/graphicsview/graphicsview.pri @@ -16,12 +16,13 @@ HEADERS += graphicsview/qgraphicsgridlayout.h \ graphicsview/qgraphicssceneevent.h \ graphicsview/qgraphicssceneindex_p.h \ graphicsview/qgraphicsscenelinearindex_p.h \ + graphicsview/qgraphicstransform.h \ + graphicsview/qgraphicstransform_p.h \ graphicsview/qgraphicsview.h \ graphicsview/qgraphicsview_p.h \ graphicsview/qgraphicswidget.h \ graphicsview/qgraphicswidget_p.h \ graphicsview/qgridlayoutengine_p.h - SOURCES += graphicsview/qgraphicsgridlayout.cpp \ graphicsview/qgraphicsitem.cpp \ graphicsview/qgraphicsitemanimation.cpp \ @@ -36,6 +37,7 @@ SOURCES += graphicsview/qgraphicsgridlayout.cpp \ graphicsview/qgraphicssceneevent.cpp \ graphicsview/qgraphicssceneindex.cpp \ graphicsview/qgraphicsscenelinearindex.cpp \ + graphicsview/qgraphicstransform.cpp \ graphicsview/qgraphicsview.cpp \ graphicsview/qgraphicswidget.cpp \ graphicsview/qgraphicswidget_p.cpp \ diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 06f26a1..6770206 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1197,6 +1197,13 @@ QGraphicsItem::~QGraphicsItem() else d_ptr->setParentItemHelper(0); + if (d_ptr->transformData) { + for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) { + QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i); + static_cast(t->d_ptr)->item = 0; + delete t; + } + } delete d_ptr->transformData; delete d_ptr; @@ -2980,94 +2987,19 @@ QTransform QGraphicsItem::transform() const /*! \since 4.6 - Returns the rotation around the X axis. - - The default is 0 - - \warning The value doesn't take in account any rotation set with - the setTransform() method. - - \sa setXRotation(), {Transformations} -*/ -qreal QGraphicsItem::xRotation() const -{ - if (!d_ptr->transformData) - return 0; - return d_ptr->transformData->xRotation; -} - -/*! - \since 4.6 - - Sets the rotation around the X axis to \a angle degrees. - - \warning The value doesn't take in account any rotation set with the setTransform() method. - - \sa xRotation(), setTransformOrigin(), {Transformations} -*/ -void QGraphicsItem::setXRotation(qreal angle) -{ - prepareGeometryChange(); - if (!d_ptr->transformData) - d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->xRotation = angle; - d_ptr->transformData->onlyTransform = false; - d_ptr->dirtySceneTransform = 1; -} - -/*! - \since 4.6 - - Returns the rotation around the Y axis. - - The default is 0 - - \warning The value doesn't take in account any rotation set with the setTransform() method. - - \sa setYRotation(), {Transformations} -*/ -qreal QGraphicsItem::yRotation() const -{ - if (!d_ptr->transformData) - return 0; - return d_ptr->transformData->yRotation; -} - -/*! - \since 4.6 - - Sets the rotation around the Y axis to \a angle degrees. - - \warning The value doesn't take in account any rotation set with the setTransform() method. - - \sa yRotation(), setTransformOrigin() {Transformations} -*/ -void QGraphicsItem::setYRotation(qreal angle) -{ - prepareGeometryChange(); - if (!d_ptr->transformData) - d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->yRotation = angle; - d_ptr->transformData->onlyTransform = false; - d_ptr->dirtySceneTransform = 1; -} - -/*! - \since 4.6 - Returns the rotation around the Z axis. The default is 0 \warning The value doesn't take in account any rotation set with the setTransform() method. - \sa setZRotation(), {Transformations} + \sa setRotation(), {Transformations} */ -qreal QGraphicsItem::zRotation() const +qreal QGraphicsItem::rotation() const { if (!d_ptr->transformData) return 0; - return d_ptr->transformData->zRotation; + return d_ptr->transformData->rotation; } /*! @@ -3077,224 +3009,107 @@ qreal QGraphicsItem::zRotation() const \warning The value doesn't take in account any rotation set with the setTransform() method. - \sa zRotation(), setTransformOrigin(), {Transformations} + \sa rotation(), setTransformOriginPoint(), {Transformations} */ -void QGraphicsItem::setZRotation(qreal angle) +void QGraphicsItem::setRotation(qreal angle) { prepareGeometryChange(); if (!d_ptr->transformData) d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->zRotation = angle; + d_ptr->transformData->rotation = angle; d_ptr->transformData->onlyTransform = false; d_ptr->dirtySceneTransform = 1; -} - -/*! - \since 4.6 - This convenience function set the rotation angles around the 3 axes - to \a x, \a y and \a z. - - \sa setXRotation(), setYRotation(), setZRotation(), {Transformations} -*/ -void QGraphicsItem::setRotation(qreal x, qreal y, qreal z) -{ - prepareGeometryChange(); - if (!d_ptr->transformData) - d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->xRotation = x; - d_ptr->transformData->yRotation = y; - d_ptr->transformData->zRotation = z; - d_ptr->transformData->onlyTransform = false; - d_ptr->dirtySceneTransform = 1; + if (d_ptr->isObject) + emit static_cast(this)->rotationChanged(); } /*! \since 4.6 - Returns the scale factor on the X axis. + Returns the scale factor of the item. The default is 1 \warning The value doesn't take in account any scaling set with the setTransform() method. - \sa setXScale(), {Transformations} + \sa setScale(), {Transformations} */ -qreal QGraphicsItem::xScale() const +qreal QGraphicsItem::scale() const { if (!d_ptr->transformData) - return 1; - return d_ptr->transformData->xScale; + return 1.; + return d_ptr->transformData->scale; } /*! \since 4.6 - Sets the scale factor on the X axis to \a factor. + Sets the scale factor of the item to \a factor. \warning The value doesn't take in account any scaling set with the setTransform() method. - \sa xScale(), setTransformOrigin(), {Transformations} + \sa scale(), setTransformOriginPoint(), {Transformations} */ -void QGraphicsItem::setXScale(qreal factor) +void QGraphicsItem::setScale(qreal factor) { prepareGeometryChange(); if (!d_ptr->transformData) d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->xScale = factor; + d_ptr->transformData->scale = factor; d_ptr->transformData->onlyTransform = false; d_ptr->dirtySceneTransform = 1; -} - -/*! - \since 4.6 - - Returns the scale factor on the Y axis. - - The default is 1 - - \warning The value doesn't take in account any scaling set with the setTransform() method. - - \sa setYScale(), {Transformations} -*/ -qreal QGraphicsItem::yScale() const -{ - if (!d_ptr->transformData) - return 1; - return d_ptr->transformData->yScale; -} - -/*! - \since 4.6 - - Sets the scale factor on the Y axis to \a factor. - \warning The value doesn't take in account any scaling set with the setTransform() method. - - \sa yScale(), setTransformOrigin(), {Transformations} -*/ -void QGraphicsItem::setYScale(qreal factor) -{ - prepareGeometryChange(); - if (!d_ptr->transformData) - d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->yScale = factor; - d_ptr->transformData->onlyTransform = false; - d_ptr->dirtySceneTransform = 1; + if (d_ptr->isObject) + emit static_cast(this)->scaleChanged(); } -/*! - \since 4.6 - - This convenience function set the scaling factors on X and Y axis to \a sx and \a sy. - - \warning The value doesn't take in account any scaling set with the setTransform() method. - - \sa setXScale(), setYScale(), {Transformations} -*/ -void QGraphicsItem::setScale(qreal sx, qreal sy) -{ - prepareGeometryChange(); - if (!d_ptr->transformData) - d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->xScale = sx; - d_ptr->transformData->yScale = sy; - d_ptr->transformData->onlyTransform = false; - d_ptr->dirtySceneTransform = 1; -} /*! \since 4.6 - Returns the horizontal shear. - - The default is 0 - - \warning The value doesn't take in account any shearing set with the setTransform() method. + returns list of graphics transformations on the item. - \sa setHorizontalShear(), {Transformations} + \sa scale(), setTransformOriginPoint(), {Transformations} */ -qreal QGraphicsItem::horizontalShear() const +QList QGraphicsItem::transformations() const { if (!d_ptr->transformData) - return 0; - return d_ptr->transformData->horizontalShear; + return QList(); + return d_ptr->transformData->graphicsTransforms; } /*! \since 4.6 - Sets the horizontal shear to \a shear. - - \warning The value doesn't take in account any shearing set with the setTransform() method. + Sets a list of graphics transformations on the item to \a transformations. - \sa horizontalShear(), {Transformations} + \sa scale(), setTransformOriginPoint(), {Transformations} */ -void QGraphicsItem::setHorizontalShear(qreal shear) +void QGraphicsItem::setTransformations(const QList &transformations) { prepareGeometryChange(); if (!d_ptr->transformData) d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->horizontalShear = shear; + d_ptr->transformData->graphicsTransforms = transformations; + for (int i = 0; i < transformations.size(); ++i) + transformations.at(i)->d_func()->setItem(this); d_ptr->transformData->onlyTransform = false; d_ptr->dirtySceneTransform = 1; } -/*! - \since 4.6 - - Returns the vertical shear. - - The default is 0 - - \warning The value doesn't take in account any shearing set with the setTransform() method. - \sa setHorizontalShear(), {Transformations} -*/ -qreal QGraphicsItem::verticalShear() const +void QGraphicsItemPrivate::appendGraphicsTransform(QGraphicsTransform *t) { - if (!d_ptr->transformData) - return 0; - return d_ptr->transformData->verticalShear; -} + if (!transformData) + transformData = new QGraphicsItemPrivate::TransformData; + if (!transformData->graphicsTransforms.contains(t)) + transformData->graphicsTransforms.append(t); -/*! - \since 4.6 - - Sets the vertical shear to \a shear. - - \warning The value doesn't take in account any shearing set with the setTransform() method. - - \sa verticalShear(), {Transformations} -*/ -void QGraphicsItem::setVerticalShear(qreal shear) -{ - prepareGeometryChange(); - if (!d_ptr->transformData) - d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->verticalShear = shear; - d_ptr->transformData->onlyTransform = false; - d_ptr->dirtySceneTransform = 1; -} - -/*! - \since 4.6 - - This convenience function sets the horizontal shear to \a sh and the vertical shear to \a sv. - - \warning The value doesn't take in account any shearing set with the setTransform() method. - - \sa setHorizontalShear(), setVerticalShear() -*/ -void QGraphicsItem::setShear(qreal sh, qreal sv) -{ - prepareGeometryChange(); - if (!d_ptr->transformData) - d_ptr->transformData = new QGraphicsItemPrivate::TransformData; - d_ptr->transformData->horizontalShear = sh; - d_ptr->transformData->verticalShear = sv; - d_ptr->transformData->onlyTransform = false; - d_ptr->dirtySceneTransform = 1; + Q_Q(QGraphicsItem); + t->d_func()->setItem(q); + transformData->onlyTransform = false; + dirtySceneTransform = 1; } /*! @@ -3304,9 +3119,9 @@ void QGraphicsItem::setShear(qreal sh, qreal sv) The default is QPointF(0,0). - \sa setTransformOrigin(), {Transformations} + \sa setTransformOriginPoint(), {Transformations} */ -QPointF QGraphicsItem::transformOrigin() const +QPointF QGraphicsItem::transformOriginPoint() const { if (!d_ptr->transformData) return QPointF(0,0); @@ -3318,9 +3133,9 @@ QPointF QGraphicsItem::transformOrigin() const Sets the \a origin point for the transformation in item coordinates. - \sa transformOrigin(), {Transformations} + \sa transformOriginPoint(), {Transformations} */ -void QGraphicsItem::setTransformOrigin(const QPointF &origin) +void QGraphicsItem::setTransformOriginPoint(const QPointF &origin) { prepareGeometryChange(); if (!d_ptr->transformData) @@ -3332,15 +3147,15 @@ void QGraphicsItem::setTransformOrigin(const QPointF &origin) } /*! - \fn void QGraphicsItem::setTransformOrigin(qreal x, qreal y) + \fn void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y) \since 4.6 \overload Sets the origin point for the transformation in item coordinates. - This is equivalent to calling setTransformOrigin(QPointF(\a x, \a y)). + This is equivalent to calling setTransformOriginPoint(QPointF(\a x, \a y)). - \sa setTransformOrigin(), {Transformations} + \sa setTransformOriginPoint(), {Transformations} */ @@ -3619,7 +3434,7 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine) \warning using this function doesnt affect the value of the transformation properties - \sa transform(), setRotation(), setScale(), setShear(), setTransformOrigin(), {The Graphics View Coordinate System}, {Transformations} + \sa transform(), setRotation(), setScale(), setTransformOriginPoint(), {The Graphics View Coordinate System}, {Transformations} */ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine) { @@ -3733,7 +3548,7 @@ void QGraphicsItem::shear(qreal sh, qreal sv) /*! \obsolete - Use setPos() or setTransformOrigin() instead. + Use setPos() or setTransformOriginPoint() instead. Translates the current item transformation by (\a dx, \a dy). @@ -6857,6 +6672,41 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent \sa pos() */ +/*! + \property QGraphicsObject::rotation + This property holds the rotation of the item in degrees. + + This specifies how many degrees to rotate the item around its transformOrigin. + The default rotation is 0 degrees (i.e. not rotated at all). +*/ + +/*! + \fn QGraphicsObject::rotationChanged() + + This signal gets emitted whenever the roation of the item changes. +*/ + +/*! + \property QGraphicsObject::scale + This property holds the scale of the item. + + A scale of less than 1 means the item will be displayed smaller than + normal, and a scale of greater than 1 means the item will be + displayed larger than normal. A negative scale means the item will + be mirrored. + + By default, items are displayed at a scale of 1 (i.e. at their + normal size). + + Scaling is from the item's transformOrigin. +*/ + +/*! + \fn void QGraphicsObject::scaleChanged() + + This signal is emitted when the scale of the item changes. +*/ + /*! \property QGraphicsObject::enabled @@ -6896,6 +6746,15 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent \sa visible */ +/*! + \property QGraphicsObject::transformOriginPoint + \brief the transformation origin + + This property sets a specific point in the items coordiante system as the + origin for scale and rotation. + + \sa scale, rotation, QGraphicsItem::transformOriginPoint() +*/ /*! diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 0e21a47..945163f 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -71,6 +71,7 @@ class QGraphicsSceneHoverEvent; class QGraphicsSceneMouseEvent; class QGraphicsSceneWheelEvent; class QGraphicsScene; +class QGraphicsTransform; class QGraphicsWidget; class QInputMethodEvent; class QKeyEvent; @@ -268,34 +269,19 @@ public: void shear(qreal sh, qreal sv); // ### obsolete void translate(qreal dx, qreal dy); // ### obsolete - qreal xRotation() const; - void setXRotation(qreal angle); + void setRotation(qreal angle); + qreal rotation() const; - qreal yRotation() const; - void setYRotation(qreal angle); + void setScale(qreal scale); + qreal scale() const; - qreal zRotation() const; - void setZRotation(qreal angle); - void setRotation(qreal x, qreal y, qreal z); + QList transformations() const; + void setTransformations(const QList &transformations); - qreal xScale() const; - void setXScale(qreal factor); - - qreal yScale() const; - void setYScale(qreal factor); - void setScale(qreal sx, qreal sy); - - qreal horizontalShear() const; - void setHorizontalShear(qreal shear); - - qreal verticalShear() const; - void setVerticalShear(qreal shear); - void setShear(qreal sh, qreal sv); - - QPointF transformOrigin() const; - void setTransformOrigin(const QPointF &origin); - inline void setTransformOrigin(qreal x, qreal y) - { setTransformOrigin(QPointF(x,y)); } + QPointF transformOriginPoint() const; + void setTransformOriginPoint(const QPointF &origin); + inline void setTransformOriginPoint(qreal x, qreal y) + { setTransformOriginPoint(QPointF(x,y)); } virtual void advance(int phase); @@ -456,6 +442,7 @@ private: friend class QGraphicsSceneIndexPrivate; friend class QGraphicsSceneBspTreeIndex; friend class QGraphicsSceneBspTreeIndexPrivate; + friend class QGraphicsTransformPrivate; friend class ::tst_QGraphicsItem; friend bool qt_closestLeaf(const QGraphicsItem *, const QGraphicsItem *); friend bool qt_closestItemFirst(const QGraphicsItem *, const QGraphicsItem *); @@ -521,6 +508,9 @@ class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged) + Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged) + Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged) + Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint WRITE setTransformOriginPoint) public: QGraphicsObject(QGraphicsItem *parent = 0); @@ -532,6 +522,8 @@ Q_SIGNALS: void xChanged(); void yChanged(); void zChanged(); + void rotationChanged(); + void scaleChanged(); protected: QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene); diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index c208b99..b8d98c1 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -57,6 +57,8 @@ #include "qset.h" #include "qpixmapcache.h" #include "qgraphicsview_p.h" +#include "qgraphicstransform.h" +#include "qgraphicstransform_p.h" #include @@ -192,7 +194,7 @@ public: void combineTransformToParent(QTransform *x, const QTransform *viewTransform = 0) const; void combineTransformFromParent(QTransform *x, const QTransform *viewTransform = 0) const; - void updateSceneTransformFromParent(); + virtual void updateSceneTransformFromParent(); // ### Qt 5: Remove. Workaround for reimplementation added after Qt 4.4. virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const; @@ -200,6 +202,7 @@ public: void setPosHelper(const QPointF &pos); void setTransformHelper(const QTransform &transform); + void appendGraphicsTransform(QGraphicsTransform *t); void setVisibleHelper(bool newVisible, bool explicitly, bool update = true); void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); bool discardUpdateRequest(bool ignoreClipping = false, bool ignoreVisibleBit = false, @@ -467,45 +470,35 @@ public: struct QGraphicsItemPrivate::TransformData { QTransform transform; - qreal xScale; - qreal yScale; - qreal xRotation; - qreal yRotation; - qreal zRotation; - qreal horizontalShear; - qreal verticalShear; + qreal scale; + qreal rotation; qreal xOrigin; qreal yOrigin; + QList graphicsTransforms; bool onlyTransform; TransformData() : - xScale(1.0), yScale(1.0), xRotation(0.0), yRotation(0.0), zRotation(0.0), - horizontalShear(0.0), verticalShear(0.0), xOrigin(0.0), yOrigin(0.0), + scale(1.0), rotation(0.0), + xOrigin(0.0), yOrigin(0.0), onlyTransform(true) {} QTransform computedFullTransform(QTransform *postmultiplyTransform = 0) const { if (onlyTransform) { - if (!postmultiplyTransform) - return transform; - if (postmultiplyTransform->isIdentity()) + if (!postmultiplyTransform || postmultiplyTransform->isIdentity()) return transform; if (transform.isIdentity()) return *postmultiplyTransform; - QTransform x(transform); - x *= *postmultiplyTransform; - return x; + return transform * *postmultiplyTransform; } QTransform x(transform); - if (xOrigin != 0 || yOrigin != 0) - x *= QTransform::fromTranslate(xOrigin, yOrigin); - x.rotate(xRotation, Qt::XAxis); - x.rotate(yRotation, Qt::YAxis); - x.rotate(zRotation, Qt::ZAxis); - x.shear(horizontalShear, verticalShear); - x.scale(xScale, yScale); + for (int i = 0; i < graphicsTransforms.size(); ++i) + graphicsTransforms.at(i)->applyTo(&x); + x.translate(xOrigin, yOrigin); + x.rotate(rotation, Qt::ZAxis); + x.scale(scale, scale); x.translate(-xOrigin, -yOrigin); if (postmultiplyTransform) x *= *postmultiplyTransform; diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp new file mode 100644 index 0000000..f18752a --- /dev/null +++ b/src/gui/graphicsview/qgraphicstransform.cpp @@ -0,0 +1,479 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgraphicstransform.h" +#include "qgraphicsitem_p.h" +#include "qgraphicstransform_p.h" +#include + +#include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +QT_BEGIN_NAMESPACE + + +void QGraphicsTransformPrivate::setItem(QGraphicsItem *i) +{ + if (item == i) + return; + + if (item) { + Q_Q(QGraphicsTransform); + QGraphicsItemPrivate *d_ptr = item->d_ptr; + + item->prepareGeometryChange(); + Q_ASSERT(d_ptr->transformData); + d_ptr->transformData->graphicsTransforms.remove(q); + d_ptr->dirtySceneTransform = 1; + item = 0; + } + + item = i; +} + +void QGraphicsTransformPrivate::updateItem(QGraphicsItem *item) +{ + item->prepareGeometryChange(); + item->d_ptr->dirtySceneTransform = 1; +} + +void QGraphicsTransform::update() +{ + Q_D(QGraphicsTransform); + if (d->item) + d->updateItem(d->item); +} + +/*! + returns this object as a QTransform. +*/ +QTransform QGraphicsTransform::transform() const +{ + QTransform t; + applyTo(&t); + return t; +} + +/*! + \class QGraphicsTransform + \brief The QGraphicsTransform class is an abstract base class for tranformations on QGraphicsItems. + \since 4.6 + + The classes that inherit QGraphicsTransform express different types of transformations + that can be applied to graphics items. + + A list of these transformations can be applied to any graphics item. These + transformations are then easily modifyable and usable from e.g. within animations. + + QGraphicsTransform is an abstract base class that is implemented by QGraphicsScale, + QGraphicsRotation and QGraphicsRotation3D. Subclasses have to implement the applyTo method. + + \sa QGraphicsItem::transform(), QGraphicsScale, QGraphicsRotation, QGraphicsRotation3D +*/ + +/*! + Constructs a new QGraphicsTransform with \a parent. +*/ +QGraphicsTransform::QGraphicsTransform(QObject *parent) : + QObject(*new QGraphicsTransformPrivate, parent) +{ +} + +/*! + Destructs the graphics transform. +*/ +QGraphicsTransform::~QGraphicsTransform() +{ + Q_D(QGraphicsTransform); + d->setItem(0); +} + +/*! + \internal +*/ +QGraphicsTransform::QGraphicsTransform(QGraphicsTransformPrivate &p, QObject *parent) + : QObject(p, parent) +{ +} + +/*! \fn void QGraphicsTransform::applyTo(QTransform *transform) const + + This pure virtual method has to be reimplemented in derived classes. + + It applies this transformation to \a transform. +*/ + + +/*! + \class QGraphicsScale + \brief The QGraphicsScale class provides a way to scale a graphics item in 2 dimensions. + \since 4.6 + + QGraphicsScale contains an \a origin around which the scaling happens, and two + scale factors, xScale and yScale, the x and one for the y axis. +*/ + +class QGraphicsScalePrivate : public QGraphicsTransformPrivate +{ +public: + QGraphicsScalePrivate() + : xScale(1), yScale(1) {} + QPointF origin; + qreal xScale; + qreal yScale; +}; + +/*! + Constructs a new graphics scale object with \a parent. +*/ +QGraphicsScale::QGraphicsScale(QObject *parent) + : QGraphicsTransform(*new QGraphicsScalePrivate, parent) +{ +} + +/*! + Destroys the object +*/ +QGraphicsScale::~QGraphicsScale() +{ +} + +/*! + \property QGraphicsScale::origin + The origin of the scale. All scaling will be done relative to this point. + + The \a origin is in other words the fixed point for the transformation. +*/ +QPointF QGraphicsScale::origin() const +{ + Q_D(const QGraphicsScale); + return d->origin; +} + +void QGraphicsScale::setOrigin(const QPointF &point) +{ + Q_D(QGraphicsScale); + d->origin = point; + update(); + emit originChanged(); +} + +/*! + \fn QGraphicsScale::originChanged() + + This signal is emitted whenever the origin of the object + changes. +*/ + +/*! + \property QGraphicsScale::xScale + + The scale factor in x direction. The x direction is + in the graphics items logical coordinates. + + \sa yScale +*/ +qreal QGraphicsScale::xScale() const +{ + Q_D(const QGraphicsScale); + return d->xScale; +} + +void QGraphicsScale::setXScale(qreal scale) +{ + Q_D(QGraphicsScale); + if (d->xScale == scale) + return; + d->xScale = scale; + update(); + emit scaleChanged(); +} + +/*! + \property QGraphicsScale::yScale + + The scale factor in y direction. The y direction is + in the graphics items logical coordinates. + + \sa xScale +*/ +qreal QGraphicsScale::yScale() const +{ + Q_D(const QGraphicsScale); + return d->yScale; +} + +void QGraphicsScale::setYScale(qreal scale) +{ + Q_D(QGraphicsScale); + if (d->yScale == scale) + return; + d->yScale = scale; + update(); + emit scaleChanged(); +} + +/*! + \fn QGraphicsScale::scaleChanged() + + This signal is emitted whenever the xScale or yScale of the object + changes. +*/ + +/*! + \reimp +*/ +void QGraphicsScale::applyTo(QTransform *transform) const +{ + Q_D(const QGraphicsScale); + transform->translate(d->origin.x(), d->origin.y()); + transform->scale(d->xScale, d->yScale); + transform->translate(-d->origin.x(), -d->origin.y()); +} + +/*! + \class QGraphicsRotation + \brief The QGraphicsRotation class provides a way to rotate a graphics item in 2 dimensions. + \since 4.6 + + QGraphicsRotation contains an \a origin around which the rotation happens, and one + angle in degrees describing the amount of the rotation. +*/ + +class QGraphicsRotationPrivate : public QGraphicsTransformPrivate +{ +public: + QGraphicsRotationPrivate() + : angle(0) {} + QPointF origin; + qreal originY; + qreal angle; +}; + +/*! + Constructs a new graphics rotation with \a parent. +*/ +QGraphicsRotation::QGraphicsRotation(QObject *parent) + : QGraphicsTransform(*new QGraphicsRotationPrivate, parent) +{ +} + +/*! + \internal +*/ +QGraphicsRotation::QGraphicsRotation(QGraphicsRotationPrivate &p, QObject *parent) + : QGraphicsTransform(p, parent) +{ +} + +/*! + Destructs the object +*/ +QGraphicsRotation::~QGraphicsRotation() +{ +} + +/*! + \property QGraphicsRotation::origin + The origin around which this object will rotate the graphics item. + + The \a origin is in other words the fixed point for the transformation. +*/ +QPointF QGraphicsRotation::origin() const +{ + Q_D(const QGraphicsRotation); + return d->origin; +} + +void QGraphicsRotation::setOrigin(const QPointF &point) +{ + Q_D(QGraphicsRotation); + d->origin = point; + update(); + emit originChanged(); +} + +/*! + \fn QGraphicsRotation::originChanged() + + This signal is emitted whenever the origin of the object + changes. +*/ + +/*! + \property QGraphicsRotation::angle + The angle, in degrees, of the rotation. +*/ +qreal QGraphicsRotation::angle() const +{ + Q_D(const QGraphicsRotation); + return d->angle; +} + +void QGraphicsRotation::setAngle(qreal angle) +{ + Q_D(QGraphicsRotation); + if (d->angle == angle) + return; + d->angle = angle; + update(); + emit angleChanged(); +} + +/*! + \fn void QGraphicsRotation::angleChanged() + + This signal is emitted whenever the angle of the object + changes. +*/ + +/*! + \reimp +*/ +void QGraphicsRotation::applyTo(QTransform *t) const +{ + Q_D(const QGraphicsRotation); + if(d->angle) { + t->translate(d->origin.x(), d->origin.y()); + t->rotate(d->angle); + t->translate(-d->origin.x(), -d->origin.y()); + } +} + + +/*! + \class QGraphicsRotation3D + \brief The QGraphicsRotation3D class provides a way to rotate a graphics item in 3 dimensions. + \since 4.6 + + In addition to the origin and angle of a simple QGraphicsRotation, QGraphicsRotation3D contains + also an axis that describes around which axis in space the rotation is supposed to happen. +*/ + +class QGraphicsRotation3DPrivate : public QGraphicsRotationPrivate +{ +public: + QGraphicsRotation3DPrivate() {} + + QVector3D axis; +}; + +/*! + Constructs a new 3D rotation with \a parent. +*/ +QGraphicsRotation3D::QGraphicsRotation3D(QObject *parent) + : QGraphicsRotation(*new QGraphicsRotation3DPrivate, parent) +{ +} + +/*! + Destroys the object +*/ +QGraphicsRotation3D::~QGraphicsRotation3D() +{ +} + +/*! + \property QGraphicsRotation3D::axis + + A rotation axis is specified by a vector in 3D space. +*/ +QVector3D QGraphicsRotation3D::axis() +{ + Q_D(QGraphicsRotation3D); + return d->axis; +} + +void QGraphicsRotation3D::setAxis(const QVector3D &axis) +{ + Q_D(QGraphicsRotation3D); + d->axis = axis; + update(); +} + +/*! + \fn void QGraphicsRotation3D::axisChanged() + + This signal is emitted whenever the axis of the object + changes. +*/ + +const qreal inv_dist_to_plane = 1. / 1024.; + +/*! + \reimp +*/ +void QGraphicsRotation3D::applyTo(QTransform *t) const +{ + Q_D(const QGraphicsRotation3D); + + if (d->angle == 0. || + (d->axis.z() == 0. && d->axis.y() == 0 && d->axis.x() == 0)) + return; + + qreal rad = d->angle * 2. * M_PI / 360.; + qreal c = ::cos(rad); + qreal s = ::sin(rad); + + qreal x = d->axis.x(); + qreal y = d->axis.y(); + qreal z = d->axis.z(); + + qreal len = x * x + y * y + z * z; + if (len != 1.) { + len = 1./::sqrt(len); + x *= len; + y *= len; + z *= len; + } + + t->translate(d->origin.x(), d->origin.y()); + *t = QTransform(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*inv_dist_to_plane, + y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane, + 0, 0, 1) * *t; + t->translate(-d->origin.x(), -d->origin.y()); +} + +#include "moc_qgraphicstransform.cpp" + +QT_END_NAMESPACE diff --git a/src/gui/graphicsview/qgraphicstransform.h b/src/gui/graphicsview/qgraphicstransform.h new file mode 100644 index 0000000..adf9438 --- /dev/null +++ b/src/gui/graphicsview/qgraphicstransform.h @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGRAPHICSTRANSFORM_H +#define QGRAPHICSTRANSFORM_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QGraphicsItem; +class QGraphicsTransformPrivate; + +class Q_GUI_EXPORT QGraphicsTransform : public QObject +{ + Q_OBJECT +public: + QGraphicsTransform(QObject *parent = 0); + ~QGraphicsTransform(); + + QTransform transform() const; + virtual void applyTo(QTransform *transform) const = 0; + +protected slots: + void update(); + +protected: + QGraphicsTransform(QGraphicsTransformPrivate &p, QObject *parent); +private: + friend class QGraphicsItem; + friend class QGraphicsItemPrivate; + Q_DECLARE_PRIVATE(QGraphicsTransform) +}; + +class QGraphicsScalePrivate; + +class Q_GUI_EXPORT QGraphicsScale : public QGraphicsTransform +{ + Q_OBJECT + + Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY originChanged) + Q_PROPERTY(qreal xScale READ xScale WRITE setXScale NOTIFY scaleChanged) + Q_PROPERTY(qreal yScale READ yScale WRITE setYScale NOTIFY scaleChanged) +public: + QGraphicsScale(QObject *parent = 0); + ~QGraphicsScale(); + + QPointF origin() const; + void setOrigin(const QPointF &point); + + qreal xScale() const; + void setXScale(qreal); + + qreal yScale() const; + void setYScale(qreal); + + void applyTo(QTransform *transform) const; + +Q_SIGNALS: + void originChanged(); + void scaleChanged(); + +private: + Q_DECLARE_PRIVATE(QGraphicsScale) +}; + +class QGraphicsRotationPrivate; + +class Q_GUI_EXPORT QGraphicsRotation : public QGraphicsTransform +{ + Q_OBJECT + + Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY originChanged) + Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) +public: + QGraphicsRotation(QObject *parent = 0); + ~QGraphicsRotation(); + + QPointF origin() const; + void setOrigin(const QPointF &point); + + qreal angle() const; + void setAngle(qreal); + + void applyTo(QTransform *transform) const; + +Q_SIGNALS: + void originChanged(); + void angleChanged(); + +protected: + QGraphicsRotation(QGraphicsRotationPrivate &p, QObject *parent); +private: + Q_DECLARE_PRIVATE(QGraphicsRotation) +}; + +class QGraphicsRotation3DPrivate; + +class Q_GUI_EXPORT QGraphicsRotation3D : public QGraphicsRotation +{ + Q_OBJECT + + Q_PROPERTY(QVector3D axis READ axis WRITE setAxis NOTIFY axisChanged) +public: + QGraphicsRotation3D(QObject *parent = 0); + ~QGraphicsRotation3D(); + + QVector3D axis(); + void setAxis(const QVector3D &axis); + + void applyTo(QTransform *transform) const; + +Q_SIGNALS: + void axisChanged(); + +private: + Q_DECLARE_PRIVATE(QGraphicsRotation3D) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QFXTRANSFORM_H diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 6f56b84..3ea80ce 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -1728,39 +1728,6 @@ QGraphicsWidget *QGraphicsWidget::focusWidget() const return 0; } -/*! \property QGraphicsWidget::horizontalShear - \brief This property holds the horizontal shear value for the item. - */ - -/*! \property QGraphicsWidget::transformOrigin - \brief This property holds the origin point used for transformations - in item coordinates. - */ - -/*! \property QGraphicsWidget::verticalShear - \brief This property holds the vertical shear value for the item. - */ - -/*! \property QGraphicsWidget::xRotation - \brief This property holds the value for rotation around the x axis. - */ - -/*! \property QGraphicsWidget::xScale - \brief This property holds the scale factor for the x axis. - */ - -/*! \property QGraphicsWidget::yRotation - \brief This property holds the value for rotation around the y axis. - */ - -/*! \property QGraphicsWidget::yScale - \brief This property holds the scale factor for the y axis. - */ - -/*! \property QGraphicsWidget::zRotation - \brief This property holds the value for rotation around the z axis. - */ - #ifndef QT_NO_SHORTCUT /*! \since 4.5 diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h index b72ec9f..d03a637 100644 --- a/src/gui/graphicsview/qgraphicswidget.h +++ b/src/gui/graphicsview/qgraphicswidget.h @@ -77,14 +77,6 @@ class Q_GUI_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLay Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags) Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle) Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry) - Q_PROPERTY(QPointF transformOrigin READ transformOrigin WRITE setTransformOrigin) - Q_PROPERTY(qreal xRotation READ xRotation WRITE setXRotation) - Q_PROPERTY(qreal yRotation READ yRotation WRITE setYRotation) - Q_PROPERTY(qreal zRotation READ zRotation WRITE setZRotation) - Q_PROPERTY(qreal xScale READ xScale WRITE setXScale) - Q_PROPERTY(qreal yScale READ yScale WRITE setYScale) - Q_PROPERTY(qreal horizontalShear READ horizontalShear WRITE setHorizontalShear) - Q_PROPERTY(qreal verticalShear READ verticalShear WRITE setVerticalShear) public: QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); ~QGraphicsWidget(); diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 9f1693d..7f6f322 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -6884,44 +6885,21 @@ void tst_QGraphicsItem::update() void tst_QGraphicsItem::setTransformProperties_data() { QTest::addColumn("origin"); - QTest::addColumn("rotationX"); - QTest::addColumn("rotationY"); - QTest::addColumn("rotationZ"); - QTest::addColumn("scaleX"); - QTest::addColumn("scaleY"); - QTest::addColumn("shearX"); - QTest::addColumn("shearY"); + QTest::addColumn("rotation"); + QTest::addColumn("scale"); - QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0); + QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(1.0); - QTest::newRow("rotationZ") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(42.2) - << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0); + QTest::newRow("rotation") << QPointF() << qreal(42.2) << qreal(1.0); - QTest::newRow("rotationXY") << QPointF() << qreal(12.5) << qreal(53.6) << qreal(0.0) - << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0); + QTest::newRow("rotation dicentred") << QPointF(qreal(22.3), qreal(-56.2)) + << qreal(-2578.2) + << qreal(1.0); - QTest::newRow("rotationXYZ") << QPointF() << qreal(-25) << qreal(12) << qreal(556) - << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0); + QTest::newRow("Scale") << QPointF() << qreal(0.0) + << qreal(6); - QTest::newRow("rotationXYZ dicentred") << QPointF(-53, 25.2) - << qreal(-2578.2) << qreal(4565.2) << qreal(56) - << qreal(1.0) << qreal(1.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("Scale") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(6) << qreal(0.5) << qreal(0.0) << qreal(0.0); - - QTest::newRow("Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(1.0) << qreal(1.0) << qreal(2.2) << qreal(0.5); - - QTest::newRow("Scale and Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(5.2) << qreal(2.1) << qreal(5.2) << qreal(5.5); - - QTest::newRow("Everything") << QPointF() << qreal(41) << qreal(-23) << qreal(0.56) - << qreal(8.2) << qreal(-0.2) << qreal(-12) << qreal(-0.8); - - QTest::newRow("Everything dicentred") << QPointF(qreal(22.3), qreal(-56.2)) << qreal(-175) << qreal(196) << qreal(-1260) - << qreal(4) << qreal(2) << qreal(2.56) << qreal(0.8); + QTest::newRow("Everything dicentred") << QPointF(qreal(22.3), qreal(-56.2)) << qreal(-175) << qreal(196); } /** @@ -6932,92 +6910,61 @@ void tst_QGraphicsItem::setTransformProperties_data() void tst_QGraphicsItem::setTransformProperties() { QFETCH(QPointF,origin); - QFETCH(qreal,rotationX); - QFETCH(qreal,rotationY); - QFETCH(qreal,rotationZ); - QFETCH(qreal,scaleX); - QFETCH(qreal,scaleY); - QFETCH(qreal,shearX); - QFETCH(qreal,shearY); + QFETCH(qreal,rotation); + QFETCH(qreal,scale); QTransform result; result.translate(origin.x(), origin.y()); - result.rotate(rotationX, Qt::XAxis); - result.rotate(rotationY, Qt::YAxis); - result.rotate(rotationZ, Qt::ZAxis); - result.shear(shearX, shearY); - result.scale(scaleX, scaleY); + result.rotate(rotation, Qt::ZAxis); + result.scale(scale, scale); result.translate(-origin.x(), -origin.y()); QGraphicsScene scene; QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); scene.addItem(item); - item->setRotation(rotationX, rotationY, rotationZ); - item->setScale(scaleX, scaleY); - item->setShear(shearX, shearY); - item->setTransformOrigin(origin); + item->setRotation(rotation); + item->setScale(scale); + item->setTransformOriginPoint(origin); - QCOMPARE(item->xRotation(), rotationX); - QCOMPARE(item->yRotation(), rotationY); - QCOMPARE(item->zRotation(), rotationZ); - QCOMPARE(item->xScale(), scaleX); - QCOMPARE(item->yScale(), scaleY); - QCOMPARE(item->horizontalShear(), shearX); - QCOMPARE(item->verticalShear(), shearY); - QCOMPARE(item->transformOrigin(), origin); + QCOMPARE(item->rotation(), rotation); + QCOMPARE(item->scale(), scale); + QCOMPARE(item->transformOriginPoint(), origin); QCOMPARE(QTransform(), item->transform()); QCOMPARE(result, item->sceneTransform()); //----------------------------------------------------------------- //Change the rotation Z - item->setZRotation(45); + item->setRotation(45); QTransform result2; result2.translate(origin.x(), origin.y()); - result2.rotate(rotationX, Qt::XAxis); - result2.rotate(rotationY, Qt::YAxis); - result2.rotate(45, Qt::ZAxis); - result2.shear(shearX, shearY); - result2.scale(scaleX, scaleY); + result2.rotate(45); + result2.scale(scale, scale); result2.translate(-origin.x(), -origin.y()); - QCOMPARE(item->xRotation(), rotationX); - QCOMPARE(item->yRotation(), rotationY); - QCOMPARE(item->zRotation(), 45.0); - QCOMPARE(item->xScale(), scaleX); - QCOMPARE(item->yScale(), scaleY); - QCOMPARE(item->horizontalShear(), shearX); - QCOMPARE(item->verticalShear(), shearY); - QCOMPARE(item->transformOrigin(), origin); + QCOMPARE(item->rotation(), 45.); + QCOMPARE(item->scale(), scale); + QCOMPARE(item->transformOriginPoint(), origin); QCOMPARE(QTransform(), item->transform()); QCOMPARE(result2, item->sceneTransform()); //----------------------------------------------------------------- - // calling setTransform() and setPos shoukld change the sceneTransform + // calling setTransform() and setPos should change the sceneTransform item->setTransform(result); item->setPos(100, -150.5); - QCOMPARE(item->xRotation(), rotationX); - QCOMPARE(item->yRotation(), rotationY); - QCOMPARE(item->zRotation(), 45.0); - QCOMPARE(item->xScale(), scaleX); - QCOMPARE(item->yScale(), scaleY); - QCOMPARE(item->horizontalShear(), shearX); - QCOMPARE(item->verticalShear(), shearY); - QCOMPARE(item->transformOrigin(), origin); + QCOMPARE(item->rotation(), 45.); + QCOMPARE(item->scale(), scale); + QCOMPARE(item->transformOriginPoint(), origin); QCOMPARE(result, item->transform()); - QTransform result3; + QTransform result3(result); result3.translate(origin.x(), origin.y()); - result3 = result * result3; - result3.rotate(rotationX, Qt::XAxis); - result3.rotate(rotationY, Qt::YAxis); - result3.rotate(45, Qt::ZAxis); - result3.shear(shearX, shearY); - result3.scale(scaleX, scaleY); + result3.rotate(45); + result3.scale(scale, scale); result3.translate(-origin.x(), -origin.y()); result3 *= QTransform::fromTranslate(100, -150.5); //the pos; @@ -7034,10 +6981,9 @@ void tst_QGraphicsItem::setTransformProperties() item1->setPos(12.3, -5); item2->setPos(12.3, -5); - item1->setRotation(rotationX, rotationY, rotationZ); - item1->setScale(scaleX, scaleY); - item1->setShear(shearX, shearY); - item1->setTransformOrigin(origin); + item1->setRotation(rotation); + item1->setScale(scale); + item1->setTransformOriginPoint(origin); item2->setTransform(result); @@ -7046,36 +6992,6 @@ void tst_QGraphicsItem::setTransformProperties() QCOMPARE_TRANSFORM(item1->itemTransform(item2), QTransform()); QCOMPARE_TRANSFORM(item2->itemTransform(item1), QTransform()); } - - {//with center origin on the item - QGraphicsRectItem *item1 = new QGraphicsRectItem(QRectF(50.2, -150, 230.5, 119)); - scene.addItem(item1); - QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(50.2, -150, 230.5, 119)); - scene.addItem(item2); - - item1->setPos(12.3, -5); - item2->setPos(12.3, -5); - item1->setTransformOrigin(origin); - item2->setTransformOrigin(origin); - - item1->setRotation(rotationX, rotationY, rotationZ); - item1->setScale(scaleX, scaleY); - item1->setShear(shearX, shearY); - - QTransform tr; - tr.rotate(rotationX, Qt::XAxis); - tr.rotate(rotationY, Qt::YAxis); - tr.rotate(rotationZ, Qt::ZAxis); - tr.shear(shearX, shearY); - tr.scale(scaleX, scaleY); - - item2->setTransform(tr); - - QCOMPARE_TRANSFORM(item1->sceneTransform(), item2->sceneTransform()); - - QCOMPARE_TRANSFORM(item1->itemTransform(item2), QTransform()); - QCOMPARE_TRANSFORM(item2->itemTransform(item1), QTransform()); - } } class MyStyleOptionTester : public QGraphicsRectItem diff --git a/tests/auto/qgraphicstransform/qgraphicstransform.pro b/tests/auto/qgraphicstransform/qgraphicstransform.pro new file mode 100644 index 0000000..709cff6 --- /dev/null +++ b/tests/auto/qgraphicstransform/qgraphicstransform.pro @@ -0,0 +1,2 @@ +load(qttest_p4) +SOURCES += tst_qgraphicstransform.cpp diff --git a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp new file mode 100644 index 0000000..672b1f1 --- /dev/null +++ b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include "../../shared/util.h" + +class tst_QGraphicsTransform : public QObject { + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void scale(); + void rotation(); + void rotation3d(); +}; + + +// This will be called before the first test function is executed. +// It is only called once. +void tst_QGraphicsTransform::initTestCase() +{ +} + +// This will be called after the last test function is executed. +// It is only called once. +void tst_QGraphicsTransform::cleanupTestCase() +{ +} + +// This will be called before each test function is executed. +void tst_QGraphicsTransform::init() +{ +} + +// This will be called after every test function. +void tst_QGraphicsTransform::cleanup() +{ +} + + +void tst_QGraphicsTransform::scale() +{ + QGraphicsScale scale; + scale.setOrigin(QPointF(10, 10)); + + QTransform t; + scale.applyTo(&t); + + QCOMPARE(t, QTransform()); + QCOMPARE(scale.transform(), QTransform()); + + scale.setXScale(10); + scale.setOrigin(QPointF(0, 0)); + + QTransform res; + res.scale(10, 1); + + QCOMPARE(scale.transform(), res); + QCOMPARE(scale.transform().map(QPointF(10, 10)), QPointF(100, 10)); + + scale.setOrigin(QPointF(10, 10)); + QCOMPARE(scale.transform().map(QPointF(10, 10)), QPointF(10, 10)); + QCOMPARE(scale.transform().map(QPointF(11, 10)), QPointF(20, 10)); +} + +void tst_QGraphicsTransform::rotation() +{ + QGraphicsRotation rotation; + rotation.setOrigin(QPointF(10, 10)); + + QTransform t; + rotation.applyTo(&t); + + QCOMPARE(t, QTransform()); + QCOMPARE(rotation.transform(), QTransform()); + + rotation.setAngle(40); + rotation.setOrigin(QPointF(0, 0)); + + QTransform res; + res.rotate(40); + + QCOMPARE(rotation.transform(), res); + + rotation.setOrigin(QPointF(10, 10)); + rotation.setAngle(90); + QCOMPARE(rotation.transform().map(QPointF(10, 10)), QPointF(10, 10)); + QCOMPARE(rotation.transform().map(QPointF(20, 10)), QPointF(10, 20)); +} + +void tst_QGraphicsTransform::rotation3d() +{ + QGraphicsRotation3D rotation; + rotation.setOrigin(QPointF(10, 10)); + + QTransform t; + rotation.applyTo(&t); + + QCOMPARE(t, QTransform()); + QCOMPARE(rotation.transform(), QTransform()); + + rotation.setAngle(180); + + QCOMPARE(t, QTransform()); + QCOMPARE(rotation.transform(), QTransform()); + + rotation.setOrigin(QPointF(0, 0)); + + QCOMPARE(t, QTransform()); + QCOMPARE(rotation.transform(), QTransform()); +} + + +QTEST_MAIN(tst_QGraphicsTransform) +#include "tst_qgraphicstransform.moc" + -- cgit v0.12 From e8b1b11731b6cb52985af35d9aaaa680859f99c2 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 29 Jul 2009 03:01:28 +0200 Subject: forgot to add this file in the last commit. --- src/gui/graphicsview/qgraphicstransform_p.h | 73 +++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/gui/graphicsview/qgraphicstransform_p.h diff --git a/src/gui/graphicsview/qgraphicstransform_p.h b/src/gui/graphicsview/qgraphicstransform_p.h new file mode 100644 index 0000000..2d36eda --- /dev/null +++ b/src/gui/graphicsview/qgraphicstransform_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGRAPHICSTRANSFORM_P_H +#define QGRAPHICSTRANSFORM_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header +// file may change from version to version without notice, or even be removed. +// +// We mean it. +// + +#include "private/qobject_p.h" + +class QGraphicsItem; + +class QGraphicsTransformPrivate : public QObjectPrivate { +public: + Q_DECLARE_PUBLIC(QGraphicsTransform) + + QGraphicsTransformPrivate() + : QObjectPrivate(), item(0) {} + + QGraphicsItem *item; + + void setItem(QGraphicsItem *item); + static void updateItem(QGraphicsItem *item); +}; + +#endif // QGRAPHICSTRANSFORM_P_H -- cgit v0.12 From 2c9bf5d611cbc293851c80d4df5a46c36eac41f7 Mon Sep 17 00:00:00 2001 From: Bill King Date: Wed, 29 Jul 2009 11:53:50 +1000 Subject: Fixes various db2 autotest issues. --- src/qt3support/sql/q3sqlcursor.cpp | 2 +- src/sql/drivers/db2/qsql_db2.cpp | 4 +++- tests/auto/qsqldatabase/tst_databases.h | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/qt3support/sql/q3sqlcursor.cpp b/src/qt3support/sql/q3sqlcursor.cpp index 6b0c69f..aa6aae2 100644 --- a/src/qt3support/sql/q3sqlcursor.cpp +++ b/src/qt3support/sql/q3sqlcursor.cpp @@ -879,7 +879,7 @@ QString Q3SqlCursor::toString(const QString& prefix, QSqlField* field, const QSt { QString f; if (field && driver()) { - f = (prefix.length() > 0 ? prefix + QLatin1Char('.') : QString()) + field->name(); + f = (prefix.length() > 0 ? prefix + QLatin1Char('.') : QString()) + driver()->escapeIdentifier(field->name(), QSqlDriver::FieldName); f += QLatin1Char(' ') + fieldSep + QLatin1Char(' '); if (field->isNull()) { f += QLatin1String("NULL"); diff --git a/src/sql/drivers/db2/qsql_db2.cpp b/src/sql/drivers/db2/qsql_db2.cpp index 474c53d..a32b3aa 100644 --- a/src/sql/drivers/db2/qsql_db2.cpp +++ b/src/sql/drivers/db2/qsql_db2.cpp @@ -868,11 +868,13 @@ bool QDB2Result::fetch(int i) SQL_FETCH_ABSOLUTE, actualIdx); } - if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { + if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r != SQL_NO_DATA) { setLastError(qMakeError(QCoreApplication::translate("QDB2Result", "Unable to fetch record %1").arg(i), QSqlError::StatementError, d)); return false; } + else if (r == SQL_NO_DATA) + return false; setAt(i); return true; } diff --git a/tests/auto/qsqldatabase/tst_databases.h b/tests/auto/qsqldatabase/tst_databases.h index 9c8c313..8253541 100644 --- a/tests/auto/qsqldatabase/tst_databases.h +++ b/tests/auto/qsqldatabase/tst_databases.h @@ -335,7 +335,7 @@ public: if(table2.compare(table.section('.', -1, -1), Qt::CaseInsensitive) == 0) { table=db.driver()->escapeIdentifier(table2, QSqlDriver::TableName); wasDropped = q.exec( "drop table " + table); - dbtables.removeAll(table); + dbtables.removeAll(table2); } } } @@ -430,8 +430,8 @@ public: return "IDENTITY"; /* if ( db.driverName().startsWith( "QPSQL" ) ) return "SERIAL";*/ - if ( db.driverName().startsWith( "QDB2" ) ) - return "GENERATED BY DEFAULT AS IDENTITY"; +// if ( db.driverName().startsWith( "QDB2" ) ) +// return "GENERATED BY DEFAULT AS IDENTITY"; return QString(); } @@ -483,6 +483,10 @@ public: { return db.driverName().startsWith("QMYSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("MySQL") ); } + static bool isDB2( QSqlDatabase db ) + { + return db.driverName().startsWith("QDB2") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("db2") ); + } // -1 on fail, else Oracle version static int getOraVersion( QSqlDatabase db ) -- cgit v0.12 From 509a04338bc2b556c15f494a73947e82e3cdcc62 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 29 Jul 2009 02:32:48 +0200 Subject: Disambiguate QGraphicsObject::children(). Add using to prefer QObject::children() over the obsolete QGraphicsItem::children() function. Reviewed-by: Henrik Hartz --- src/gui/graphicsview/qgraphicsitem.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 945163f..b94fb97 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -514,6 +514,13 @@ class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem public: QGraphicsObject(QGraphicsItem *parent = 0); + // ### Qt 5: Disambiguate +#ifdef Q_NO_USING_KEYWORD + const QObjectList &children() const { return QObject::children(); } +#else + using QObject::children; +#endif + Q_SIGNALS: void parentChanged(); void opacityChanged(); -- cgit v0.12 From e841cc37bf7fde58e7b0ffc024d31f6a46a83745 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 29 Jul 2009 03:21:09 +0200 Subject: Fix remaining autotest failures in tst_QGraphicsWidget Change f68fed3 introduced a few regressions in the QGraphicsWidget autotests. It turned out those autotests relied on behavior that this fix "fixed". The exact bugs were 1) that setting focus on a window or a child of a window that isn't active will automatically give that item focus, despite that its window is inactive (in contrast it should just set up subfocus and give the item focus when the window is activated), and 2) that adding a window to a scene that is active did not immediately activate that window. So one fix in the test and one in QGraphicsScene. The autotests were modified so that the respective tests operate on an active scene (by assigning the scene to an active view). The change in QGraphicsScene ensures that the first window that gets added to an active scene that does not have any active windows already, automatically gets activated. Reviewed-by: Michael Brasser --- src/gui/graphicsview/qgraphicsscene.cpp | 4 ++++ tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index f223cbe..e54efe0 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -2356,6 +2356,10 @@ void QGraphicsScene::addItem(QGraphicsItem *item) // Deliver post-change notification item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); + // Auto-activate the first inactive window if the scene is active. + if (d->activationRefCount > 0 && !d->activeWindow && item->isWindow()) + setActiveWindow(static_cast(item)); + // Ensure that newly added items that have subfocus set, gain // focus automatically if there isn't a focus item already. if (!d->focusItem && item->focusItem()) diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 78d13d3..2cfedb1 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -1315,6 +1315,12 @@ void tst_QGraphicsWidget::focusNextPrevChild() void tst_QGraphicsWidget::verifyFocusChain() { QGraphicsScene scene; + QGraphicsView view(&scene); + view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(250); { // parent/child focus SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); @@ -1448,6 +1454,11 @@ void tst_QGraphicsWidget::updateFocusChainWhenChildDie() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(250); + // delete item in focus chain with no focus and verify chain SubQGraphicsWidget *parent = new SubQGraphicsWidget(0, Qt::Window); SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); -- cgit v0.12 From b51f10492b40b94c25661ec42ccf951268f3a969 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 29 Jul 2009 04:51:50 +0200 Subject: Ensure hover enter events are dispatched on mouse press. This change ensures that mouse presses received by the scene when there are no current mouse grabbers trigger hover event delivery. This is useful when the scene only receives presses, and no mouse moves (e.g., disabling mouse tracking on the viewport, or on systems where the mouse press is the first received event). Reviewed-by: Michael Brasser --- src/gui/graphicsview/qgraphicsscene.cpp | 7 +++ tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 69 ++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index e54efe0..a846cf6 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -3682,6 +3682,13 @@ void QGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent) void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { Q_D(QGraphicsScene); + if (d->mouseGrabberItems.isEmpty()) { + // Dispatch hover events + QGraphicsSceneHoverEvent hover; + _q_hoverFromMouseEvent(&hover, mouseEvent); + d->dispatchHoverEvent(&hover); + } + d->mousePressEventHandler(mouseEvent); } diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index f7ea4ce..4ef1cdd 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -255,6 +255,7 @@ private slots: void sendEvent(); void inputMethod_data(); void inputMethod(); + void dispatchHoverOnPress(); // task specific tests below me void task139710_bspTreeCrash(); @@ -3719,5 +3720,73 @@ void tst_QGraphicsScene::inputMethod() QCOMPARE(item->queryCalls, 0); } +void tst_QGraphicsScene::dispatchHoverOnPress() +{ + QGraphicsScene scene; + EventTester *tester1 = new EventTester; + tester1->setAcceptHoverEvents(true); + EventTester *tester2 = new EventTester; + tester2->setAcceptHoverEvents(true); + tester2->setPos(30, 30); + scene.addItem(tester1); + scene.addItem(tester2); + + tester1->eventTypes.clear(); + tester2->eventTypes.clear(); + + { + QGraphicsSceneMouseEvent me(QEvent::GraphicsSceneMousePress); + me.setButton(Qt::LeftButton); + me.setButtons(Qt::LeftButton); + QGraphicsSceneMouseEvent me2(QEvent::GraphicsSceneMouseRelease); + me2.setButton(Qt::LeftButton); + qApp->sendEvent(&scene, &me); + qApp->sendEvent(&scene, &me2); + QCOMPARE(tester1->eventTypes, QList() + << QEvent::GraphicsSceneHoverEnter + << QEvent::GraphicsSceneHoverMove + << QEvent::GrabMouse + << QEvent::GraphicsSceneMousePress + << QEvent::UngrabMouse); + tester1->eventTypes.clear(); + qApp->sendEvent(&scene, &me); + qApp->sendEvent(&scene, &me2); + QCOMPARE(tester1->eventTypes, QList() + << QEvent::GraphicsSceneHoverMove + << QEvent::GrabMouse + << QEvent::GraphicsSceneMousePress + << QEvent::UngrabMouse); + } + { + QGraphicsSceneMouseEvent me(QEvent::GraphicsSceneMousePress); + me.setScenePos(QPointF(30, 30)); + me.setButton(Qt::LeftButton); + me.setButtons(Qt::LeftButton); + QGraphicsSceneMouseEvent me2(QEvent::GraphicsSceneMouseRelease); + me2.setScenePos(QPointF(30, 30)); + me2.setButton(Qt::LeftButton); + tester1->eventTypes.clear(); + qApp->sendEvent(&scene, &me); + qApp->sendEvent(&scene, &me2); + qDebug() << tester1->eventTypes; + QCOMPARE(tester1->eventTypes, QList() + << QEvent::GraphicsSceneHoverLeave); + QCOMPARE(tester2->eventTypes, QList() + << QEvent::GraphicsSceneHoverEnter + << QEvent::GraphicsSceneHoverMove + << QEvent::GrabMouse + << QEvent::GraphicsSceneMousePress + << QEvent::UngrabMouse); + tester2->eventTypes.clear(); + qApp->sendEvent(&scene, &me); + qApp->sendEvent(&scene, &me2); + QCOMPARE(tester2->eventTypes, QList() + << QEvent::GraphicsSceneHoverMove + << QEvent::GrabMouse + << QEvent::GraphicsSceneMousePress + << QEvent::UngrabMouse); + } +} + QTEST_MAIN(tst_QGraphicsScene) #include "tst_qgraphicsscene.moc" -- cgit v0.12 From 188ac02e2fb6cc6437b776f8c5b69a508728fbdb Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 29 Jul 2009 05:20:31 +0200 Subject: fix compilation without 3d support --- src/gui/graphicsview/qgraphicstransform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp index f18752a..b55d78e 100644 --- a/src/gui/graphicsview/qgraphicstransform.cpp +++ b/src/gui/graphicsview/qgraphicstransform.cpp @@ -63,7 +63,7 @@ void QGraphicsTransformPrivate::setItem(QGraphicsItem *i) item->prepareGeometryChange(); Q_ASSERT(d_ptr->transformData); - d_ptr->transformData->graphicsTransforms.remove(q); + d_ptr->transformData->graphicsTransforms.removeAll(q); d_ptr->dirtySceneTransform = 1; item = 0; } -- cgit v0.12