I'm working on a multitouch image viewer that has two graphics views: the main one for viewing the image, and another that stores thumbnails. I plan on either allowing users to drag and drop the thumbnails into the main graphics view (using one QGraphicsPixmapItem class) or allowing users to simply touch a thumbnail to copy it into the main graphics view (using two QGraphicsPixmapItem classes: one for the images and one for the thumbnails).

However, I don't know how to take either approach. I don't know if I can copy over data from the thumbnail class into the image class; I also don't know how to approach the drag and drop operations with them.

Here's the image class:

@#include "slice.h"
#include <QtGui>
#include <QTouchEvent>

slice::slice() : totalScaleFactor(1)
{
setAcceptTouchEvents(true);
}

bool slice::sceneEvent(QEvent *event)
{
switch(event->type())
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
if(touchPoints.count() == 1)
{
const QTouchEvent::TouchPoint &touchPoint = touchPoints.first();
QLineF line(touchPoint.lastScenePos(), touchPoint.scenePos());
translate(line.dx(),line.dy());
}
else if(touchPoints.count() == 2)
{
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint2 = touchPoints.last();

        qreal currentScaleFactor = QLineF(touchPoint1.pos(), touchPoint2.pos()).length()
                / QLineF(touchPoint1.startPos(), touchPoint2.startPos()).length();
        if(touchEvent->touchPointStates() & Qt::TouchPointReleased)
        {
            totalScaleFactor *= currentScaleFactor;
            currentScaleFactor = 1;
        }
        if((totalScaleFactor*currentScaleFactor) <= 0.8)
        {
            totalScaleFactor = 0.8;
        }
        else if((totalScaleFactor*currentScaleFactor) >= 5.0)
        {
            totalScaleFactor = 5.0;
        }
        else
        {
            setScale(totalScaleFactor*currentScaleFactor);
        }
    }
    else if(touchPoints.count() == 3)
    {
        const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.first();
        const QTouchEvent::TouchPoint &touchPoint2 = touchPoints.last();

        QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos());
        QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos());
        rotate(line2.angleTo(line1));
    }
    return true;
}
default:
    break;
}
return QGraphicsItem::sceneEvent(event);

}@

And here's the thumbnail class:

@#include "thumbnail.h"
#include "mainwindow.h"
#include "slice.h"
#include <QtGui>
#include <QTouchEvent>

thumbnail::thumbnail()
{
setAcceptTouchEvents(true);
scale(0.5, 0.5);
}

bool thumbnail::sceneEvent(QEvent *event)
{
switch(event->type())
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QTouchEvent touchEvent = static_cast<QTouchEvent >(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
if(touchPoints.count() == 1)
{
/
I don't know what to put here
/
}
return true;
}
default:
break;
}
return QGraphicsItem::sceneEvent(event);
}@

Finally, here are the relevant portions of the MainWindow class:

@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
.
.
.

QGraphicsScene *scene;
QGraphicsScene *sliceScene;
scene = new QGraphicsScene;
sliceScene = new QGraphicsScene;
QPixmap item(QPixmap::fromImage(extractSlice(0,60)));
QPixmap item2(QPixmap::fromImage(extractSlice(0,50)));
slice *newSlice = new slice;
slice *newSlice2 = new slice;
newSlice->setPixmap(item);
newSlice2->setPixmap(item2);
scene->addItem(newSlice);
sliceScene->addItem(newSlice2);
ui->sliceView->setScene(sliceScene);
ui->graphicsView->setScene(scene);
ui->graphicsView->show();

}

.
.
.

QImage MainWindow::extractSlice(int dimension, int sliceNumber)
{
.
.
.
IteratorType outputIt(newImage, newImage->GetBufferedRegion());
const int width = newImage->GetLargestPossibleRegion().GetSize()[0];
const int height = newImage->GetLargestPossibleRegion().GetSize()[1];
QImage *myQtImage = new QImage(width, height, QImage::Format_RGB32);
outputIt.Begin();
for(int i=0; i < height; ++i)
{
for(int j=0; j < width; ++j)
{
QRgb color;
color = qRgb(outputIt.Get(), outputIt.Get(), outputIt.Get());
myQtImage->setPixel(j,i,color);
++outputIt;
}
}
return *myQtImage;
}@

Please let me know if there's any other information I should provide.