Need Help on Copying an Image from one GraphicsView/GraphicsScene to Another
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);
- }
- {
- switch(event->type())
- {
- {
- QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- if(touchPoints.count() == 1)
- {
- const QTouchEvent::TouchPoint &touchPoint = touchPoints.first();
- translate(line.dx(),line.dy());
- }
- else if(touchPoints.count() == 2)
- {
- const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.first();
- const QTouchEvent::TouchPoint &touchPoint2 = touchPoints.last();
- {
- 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();
- rotate(line2.angleTo(line1));
- }
- return true;
- }
- default:
- break;
- }
- }
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);
- }
- {
- switch(event->type())
- {
- {
- QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- if(touchPoints.count() == 1)
- {
- /*I don't know what to put here*/
- }
- return true;
- }
- default:
- break;
- }
- }
Finally, here are the relevant portions of the MainWindow class:
- ui(new Ui::MainWindow)
- {
- .
- .
- .
- scene = new QGraphicsScene;
- sliceScene = new QGraphicsScene;
- 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();
- }
- .
- .
- .
- {
- .
- .
- .
- IteratorType outputIt(newImage, newImage->GetBufferedRegion());
- const int width = newImage->GetLargestPossibleRegion().GetSize()[0];
- const int height = newImage->GetLargestPossibleRegion().GetSize()[1];
- outputIt.Begin();
- for(int i=0; i < height; ++i)
- {
- for(int j=0; j < width; ++j)
- {
- QRgb color;
- myQtImage->setPixel(j,i,color);
- ++outputIt;
- }
- }
- return *myQtImage;
- }
Please let me know if there’s any other information I should provide.
0 replies
You must log in to post a reply. Not a member yet? Register here!
