00001 #include "boxtool.h" 00002 #include "pdfscene.h" 00003 #include <QGraphicsView> 00004 00005 BoxTool::BoxTool(PDFScene* scene) : 00006 Tool(scene), 00007 box(NULL) 00008 { 00009 } 00010 00011 void BoxTool::activate() 00012 { 00013 scene->setTool(this); 00014 foreach(QGraphicsView* view, scene->views()) 00015 { 00016 view->setDragMode(QGraphicsView::NoDrag); 00017 view->viewport()->setCursor(Qt::CrossCursor); 00018 } 00019 } 00020 00021 void BoxTool::mousePressEvent ( QGraphicsSceneMouseEvent * ev) 00022 { 00023 box = new Rectangle(ev->scenePos().x(), ev->scenePos().y(), 10, 10); 00024 scene->addItem(box); 00025 box->setZValue(1.0); 00026 } 00027 00028 void BoxTool::mouseMoveEvent ( QGraphicsSceneMouseEvent * ev) 00029 { 00030 if (box) 00031 { 00032 QRectF rect = box->rect(); 00033 rect.setBottomRight(ev->scenePos()); 00034 // If we normalize rect here, there are no droppings 00035 // while dragging a rectangle to size, but, 00036 // drawing the rectangle backwards is also not allowed. 00037 // The upper-left corner is anchored and the lower-right corner 00038 // is dragged. 00041 box->setRect(rect.normalized()); 00042 } 00043 } 00044 00045 void BoxTool::mouseReleaseEvent ( QGraphicsSceneMouseEvent * /* ev */) 00046 { 00047 if (box) 00048 box->setRect(box->rect().normalized()); 00049 box = NULL; 00050 }
1.5.8