From 0748751c9f097d9d866605306bbdd4b96e2a5c4e Mon Sep 17 00:00:00 2001 From: David Boddie Date: Wed, 27 Apr 2011 19:16:41 +0200 Subject: Squashed commit of the changes from the mobile-examples repository (4.7-generated-declarative branch). --- examples/draganddrop/puzzle/main.cpp | 4 ++++ examples/draganddrop/puzzle/mainwindow.cpp | 16 +++++++++++----- examples/draganddrop/puzzle/pieceslist.cpp | 6 +++--- examples/draganddrop/puzzle/pieceslist.h | 4 +++- examples/draganddrop/puzzle/puzzle.pro | 1 + examples/draganddrop/puzzle/puzzlewidget.cpp | 26 ++++++++++++++++++-------- examples/draganddrop/puzzle/puzzlewidget.h | 6 +++++- 7 files changed, 45 insertions(+), 18 deletions(-) (limited to 'examples/draganddrop/puzzle') diff --git a/examples/draganddrop/puzzle/main.cpp b/examples/draganddrop/puzzle/main.cpp index 60341948ab..b432ddc40e 100644 --- a/examples/draganddrop/puzzle/main.cpp +++ b/examples/draganddrop/puzzle/main.cpp @@ -49,6 +49,10 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); MainWindow window; window.openImage(":/images/example.jpg"); +#ifdef Q_OS_SYMBIAN + window.showMaximized(); +#else window.show(); +#endif return app.exec(); } diff --git a/examples/draganddrop/puzzle/mainwindow.cpp b/examples/draganddrop/puzzle/mainwindow.cpp index ea7cff12ce..09fcaf7c59 100644 --- a/examples/draganddrop/puzzle/mainwindow.cpp +++ b/examples/draganddrop/puzzle/mainwindow.cpp @@ -90,14 +90,15 @@ void MainWindow::setupPuzzle() { int size = qMin(puzzleImage.width(), puzzleImage.height()); puzzleImage = puzzleImage.copy((puzzleImage.width() - size)/2, - (puzzleImage.height() - size)/2, size, size).scaled(400, - 400, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + (puzzleImage.height() - size)/2, size, size).scaled(puzzleWidget->width(), + puzzleWidget->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); piecesList->clear(); for (int y = 0; y < 5; ++y) { for (int x = 0; x < 5; ++x) { - QPixmap pieceImage = puzzleImage.copy(x*80, y*80, 80, 80); + int pieceSize = puzzleWidget->pieceSize(); + QPixmap pieceImage = puzzleImage.copy(x * pieceSize, y * pieceSize, pieceSize, pieceSize); piecesList->addPiece(pieceImage, QPoint(x, y)); } } @@ -137,9 +138,14 @@ void MainWindow::setupWidgets() { QFrame *frame = new QFrame; QHBoxLayout *frameLayout = new QHBoxLayout(frame); +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR) + puzzleWidget = new PuzzleWidget(260); +#else + puzzleWidget = new PuzzleWidget(400); +#endif + + piecesList = new PiecesList(puzzleWidget->pieceSize(), this); - piecesList = new PiecesList; - puzzleWidget = new PuzzleWidget; connect(puzzleWidget, SIGNAL(puzzleCompleted()), this, SLOT(setCompleted()), Qt::QueuedConnection); diff --git a/examples/draganddrop/puzzle/pieceslist.cpp b/examples/draganddrop/puzzle/pieceslist.cpp index db27e7ad13..5eb4984146 100644 --- a/examples/draganddrop/puzzle/pieceslist.cpp +++ b/examples/draganddrop/puzzle/pieceslist.cpp @@ -42,12 +42,12 @@ #include "pieceslist.h" -PiecesList::PiecesList(QWidget *parent) - : QListWidget(parent) +PiecesList::PiecesList(int pieceSize, QWidget *parent) + : QListWidget(parent), m_PieceSize(pieceSize) { setDragEnabled(true); setViewMode(QListView::IconMode); - setIconSize(QSize(60, 60)); + setIconSize(QSize(m_PieceSize, m_PieceSize)); setSpacing(10); setAcceptDrops(true); setDropIndicatorShown(true); diff --git a/examples/draganddrop/puzzle/pieceslist.h b/examples/draganddrop/puzzle/pieceslist.h index 2068dceb17..967ade0c73 100644 --- a/examples/draganddrop/puzzle/pieceslist.h +++ b/examples/draganddrop/puzzle/pieceslist.h @@ -48,7 +48,7 @@ class PiecesList : public QListWidget Q_OBJECT public: - PiecesList(QWidget *parent = 0); + PiecesList(int pieceSize, QWidget *parent = 0); void addPiece(QPixmap pixmap, QPoint location); protected: @@ -56,6 +56,8 @@ protected: void dragMoveEvent(QDragMoveEvent *event); void dropEvent(QDropEvent *event); void startDrag(Qt::DropActions supportedActions); + + int m_PieceSize; }; #endif diff --git a/examples/draganddrop/puzzle/puzzle.pro b/examples/draganddrop/puzzle/puzzle.pro index 0d3a5dab2e..2682032e87 100644 --- a/examples/draganddrop/puzzle/puzzle.pro +++ b/examples/draganddrop/puzzle/puzzle.pro @@ -27,3 +27,4 @@ wince*: { addFile.path = . DEPLOYMENT += addFile } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) diff --git a/examples/draganddrop/puzzle/puzzlewidget.cpp b/examples/draganddrop/puzzle/puzzlewidget.cpp index 355c6d55cd..e83f248112 100644 --- a/examples/draganddrop/puzzle/puzzlewidget.cpp +++ b/examples/draganddrop/puzzle/puzzlewidget.cpp @@ -42,12 +42,12 @@ #include "puzzlewidget.h" -PuzzleWidget::PuzzleWidget(QWidget *parent) - : QWidget(parent) +PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent) + : QWidget(parent), m_ImageSize(imageSize) { setAcceptDrops(true); - setMinimumSize(400, 400); - setMaximumSize(400, 400); + setMinimumSize(m_ImageSize, m_ImageSize); + setMaximumSize(m_ImageSize, m_ImageSize); } void PuzzleWidget::clear() @@ -116,7 +116,7 @@ void PuzzleWidget::dropEvent(QDropEvent *event) event->setDropAction(Qt::MoveAction); event->accept(); - if (location == QPoint(square.x()/80, square.y()/80)) { + if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) { inPlace++; if (inPlace == 25) emit puzzleCompleted(); @@ -151,7 +151,7 @@ void PuzzleWidget::mousePressEvent(QMouseEvent *event) piecePixmaps.removeAt(found); pieceRects.removeAt(found); - if (location == QPoint(square.x()/80, square.y()/80)) + if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) inPlace--; update(square); @@ -175,7 +175,7 @@ void PuzzleWidget::mousePressEvent(QMouseEvent *event) pieceRects.insert(found, square); update(targetSquare(event->pos())); - if (location == QPoint(square.x()/80, square.y()/80)) + if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) inPlace++; } } @@ -200,5 +200,15 @@ void PuzzleWidget::paintEvent(QPaintEvent *event) const QRect PuzzleWidget::targetSquare(const QPoint &position) const { - return QRect(position.x()/80 * 80, position.y()/80 * 80, 80, 80); + return QRect(position.x()/pieceSize() * pieceSize(), position.y()/pieceSize() * pieceSize(), pieceSize(), pieceSize()); +} + +int PuzzleWidget::pieceSize() const +{ + return m_ImageSize / 5; +} + +int PuzzleWidget::imageSize() const +{ + return m_ImageSize; } diff --git a/examples/draganddrop/puzzle/puzzlewidget.h b/examples/draganddrop/puzzle/puzzlewidget.h index e0356b48fd..2cc789c292 100644 --- a/examples/draganddrop/puzzle/puzzlewidget.h +++ b/examples/draganddrop/puzzle/puzzlewidget.h @@ -57,9 +57,12 @@ class PuzzleWidget : public QWidget Q_OBJECT public: - PuzzleWidget(QWidget *parent = 0); + PuzzleWidget(int imageSize, QWidget *parent = 0); void clear(); + int pieceSize() const; + int imageSize() const; + signals: void puzzleCompleted(); @@ -80,6 +83,7 @@ private: QList pieceLocations; QRect highlightedRect; int inPlace; + int m_ImageSize; }; #endif -- cgit v1.2.3 From 0cbcc61ef35b9bce1d65d048853c79004b755b87 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Wed, 11 May 2011 17:35:46 +0200 Subject: Squashed commit of changes from the 4.8-temp branch. --- examples/draganddrop/puzzle/puzzle.desktop | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 examples/draganddrop/puzzle/puzzle.desktop (limited to 'examples/draganddrop/puzzle') diff --git a/examples/draganddrop/puzzle/puzzle.desktop b/examples/draganddrop/puzzle/puzzle.desktop new file mode 100644 index 0000000000..f6765e1e01 --- /dev/null +++ b/examples/draganddrop/puzzle/puzzle.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Drag and Drop Puzzle +Exec=/opt/usr/bin/puzzle +Icon=puzzle +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable -- cgit v1.2.3