SvgView::SvgView(QWidget *parent) : QGraphicsView(parent) , m_renderer(Native) , m_svgItem(0) , m_backgroundItem(0) , m_outlineItem(0) { setScene(new QGraphicsScene(this)); setTransformationAnchor(AnchorUnderMouse); setDragMode(ScrollHandDrag); setViewportUpdateMode(FullViewportUpdate); // Prepare background check-board pattern QPixmap tilePixmap(64, 64); tilePixmap.fill(Qt::white); QPainter tilePainter(&tilePixmap); QColor color(220, 220, 220); tilePainter.fillRect(0, 0, 32, 32, color); tilePainter.fillRect(32, 32, 32, 32, color); tilePainter.end(); setBackgroundBrush(tilePixmap); }
MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget * shareWidget, QGraphicsScene* scene) : QGraphicsView(parent), _mainWindow(mainWindow), _mousePressedOnVertex(false), _activeVertex(NO_VERTEX), _shapeGrabbed(false), // comment out? _shapeFirstGrab(false), // comment out? _zoomLevel(0) { // For now clicking on the window doesn't do anything. setDragMode(QGraphicsView::NoDrag); setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform); setResizeAnchor(AnchorViewCenter); setInteractive(true); //setFrameStyle(Sunken | StyledPanel); // TODO: check this // setOptimizationFlags(QGraphicsView::DontSavePainterState); //setViewportUpdateMode(QGraphicsView::FullViewportUpdate); setTransformationAnchor(QGraphicsView::AnchorUnderMouse); resetTransform(); // setAcceptDrops(true); // Render with OpenGL. setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers), this, shareWidget)); setViewportUpdateMode(QGraphicsView::FullViewportUpdate); // TODO: do we need to delete scene (or call new QGraphicsScene(this)?) setScene(scene ? scene : new QGraphicsScene); // Black background. this->scene()->setBackgroundBrush(Qt::black); }
PlotGraph::PlotGraph(std::vector<double> & firstRow_in, std::vector<double> & secondRow_in, std::vector<double> & thirdRow_in, std::vector<double> & fourthRow_in, QWidget *parent) :QGraphicsView(parent) { firstRow = firstRow_in; secondRow = secondRow_in; thirdRow = thirdRow_in; fourthRow = fourthRow_in; nPlottingPoints = firstRow.size(); QGraphicsScene *scene = new QGraphicsScene(this); scene->setItemIndexMethod(QGraphicsScene::NoIndex); sceneX = -250; sceneY = -250; sceneHeigth = 490; sceneWidth = 490; xOrigin = sceneX + 30; yOrigin = sceneY + sceneHeigth - 80; xMax = sceneX + sceneWidth - 30; yMax = sceneY + 30; scene->setSceneRect(sceneX, sceneY, sceneHeigth, sceneWidth); setScene(scene); setCacheMode(CacheBackground); setViewportUpdateMode(BoundingRectViewportUpdate); setRenderHint(QPainter::Antialiasing); setTransformationAnchor(AnchorUnderMouse); setWindowTitle(tr("Bacterial Growth - Graph")); timerId = startTimer(1000 / 50); addingLine = 0; }
HPiano::HPiano(QWidget* parent) : QGraphicsView(parent) { setLineWidth(0); setMidLineWidth(0); setScene(new QGraphicsScene); setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setResizeAnchor(QGraphicsView::AnchorUnderMouse); setMouseTracking(true); setRubberBandSelectionMode(Qt::IntersectsItemBoundingRect); setDragMode(QGraphicsView::RubberBandDrag); setMaximumSize(QSize(KEY_WIDTH * 52+8, KEY_HEIGHT+8+80)); setMinimumSize(QSize(100, KEY_HEIGHT+8)); scene()->setSceneRect(0.0, 0.0, KEY_WIDTH * 52, KEY_HEIGHT); _firstKey = 21; _lastKey = 108; // 88 key piano _currentKey = -1; qreal x = 0.0; for (int i = _firstKey; i <= _lastKey; ++i) { PianoKeyItem* k = new PianoKeyItem(this, i); switch(i % 12) { case 0: case 5: k->setType(i == _lastKey ? 6 : 0); k->setPos(x, 0); x += KEY_WIDTH; break; case 2: k->setType(1); k->setPos(x, 0); x += KEY_WIDTH; break; case 4: case 11: k->setType(2); k->setPos(x, 0); x += KEY_WIDTH; break; case 7: k->setType(3); k->setPos(x, 0); x += KEY_WIDTH; break; case 9: k->setType(i == _firstKey ? 5 : 4); k->setPos(x, 0); x += KEY_WIDTH; break; case 1: case 6: k->setType(7); k->setPos(x - BKEY_WIDTH * 5/9, 0); break; case 3: case 10: k->setType(7); k->setPos(x - BKEY_WIDTH * 4/9, 0); break; case 8: k->setType(7); k->setPos(x - BKEY_WIDTH / 2.0, 0); break; } keys.append(k); scene()->addItem(k); } }
OutputWindow::OutputWindow() : QGraphicsView(new QGraphicsScene()) , m_url("") , m_pollDviz(false) , m_updateTime(1000) , m_isDataPoll(false) , m_slideId(-1) , m_slideName("") //, m_startStopButton(0) , m_countValue(0) , m_drw(0) , m_blinkCount(0) { // Setup graphics view setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform ); setCacheMode(QGraphicsView::CacheBackground); setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); setOptimizationFlags(QGraphicsView::DontSavePainterState); setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); setTransformationAnchor(AnchorUnderMouse); setResizeAnchor(AnchorViewCenter); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Add pixmap item for background QPixmap bluePixmap(32,23); bluePixmap.fill(Qt::blue); m_pixmap = scene()->addPixmap(bluePixmap); // Background behind text m_counterBgRect = scene()->addRect(0,0,100,60,QPen(), Qt::black); m_counterBgRect->setZValue(99); // Add text (for use with clock) QFont font("Monospace", 50, 600); m_counterText = new QGraphicsSimpleTextItem("0"); m_counterText->setFont(font); m_counterText->setPen(QPen(Qt::black)); m_counterText->setBrush(Qt::white); m_counterText->setPos(0, -13); m_counterText->setZValue(100); scene()->addItem(m_counterText); // Background behind text m_overlayBgRect = scene()->addRect(0,300,100,60,QPen(), Qt::black); m_overlayBgRect->setZValue(99); // Add text (for use with clock) //QFont font("Monospace", 50, 600); m_overlayText = new QGraphicsSimpleTextItem("Hello, World!"); m_overlayText->setFont(font); m_overlayText->setPen(QPen(Qt::black)); m_overlayText->setBrush(Qt::white); m_overlayText->setPos(0, 300-13); m_overlayText->setZValue(100); scene()->addItem(m_overlayText); m_blinkOverlay = false; connect(&m_blinkOverlayTimer, SIGNAL(timeout()), this, SLOT(blinkOverlaySlot())); GET_CONFIG(); QPoint windowPos(1024,0); QPoint windowSize(1024,768); //QPoint windowPos(10,10); //QPoint windowSize = QPoint(640,480); QString windowGeomString = config.value("geom","1024,0,1024,768").toString(); if(!windowGeomString.isEmpty()) { QStringList list = windowGeomString.split(","); windowPos = QPoint(list[0].toInt(), list[1].toInt()); windowSize = QPoint(list[2].toInt(), list[3].toInt()); } setWindowGeom(QRect(windowPos.x(),windowPos.y(),windowSize.x(),windowSize.y())); bool frameless = config.value("frameless","true").toString() == "true"; if(frameless) setWindowFlags(Qt::FramelessWindowHint);// | Qt::ToolTip); connect(&m_pollDvizTimer, SIGNAL(timeout()), this, SLOT(initDvizPoll())); //connect(&m_pollImageTimer, SIGNAL(timeout()), this, SLOT(initImagePoll())); setUpdateTime(m_updateTime); //setUrl("http://10.10.9.90:8081/image"); //setUrl(""); //setPollDviz(true); setInputSource(config.value("source","dviz://192.168.0.10:8081/image").toString()); // m_startStopButton = new QPushButton("Start Counter"); // connect(m_startStopButton, SIGNAL(clicked()), this, SLOT(toggleCounter())); connect(&m_counterTimer, SIGNAL(timeout()), this, SLOT(counterTick())); m_counterTimer.setInterval(1000); // // m_startStopButton->show(); //toggleCounter(); setCounterActive(false); setBlinkOverlay(config.value("blink-overlay","false").toString() == "true", config.value("blink-speed", 333).toInt()); //setOverlayVisible(config.value("overlay-visible", "true").toString() == "true"); setCounterVisible(config.value("counter-visible", "true").toString() == "true"); setCounterAlignment((Qt::Alignment)config.value("counter-alignment", (int)(Qt::AlignLeft | Qt::AlignTop)).toInt()); setOverlayAlignment((Qt::Alignment)config.value("overlay-alignment", (int)(Qt::AlignCenter | Qt::AlignBottom)).toInt()); setOverlayText(config.value("overlay-text").toString()); }
// Construct a view showing problem/solution from the given input stream. View::View(std::istream &in, Options options, QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent), m_legPen(Qt::black, 1.0), m_currentLegPen(QColor(Qt::green).darker(), 1.0), m_currentLeg(0), m_hudFont("Courier", 10), m_labelFont("Courier", 6), m_solutionLength(0), m_options(options) { resize(900, 600); setRenderHints(QPainter::Antialiasing); setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setDragMode(QGraphicsView::ScrollHandDrag); setViewportUpdateMode(QGraphicsView::FullViewportUpdate); // :( setBackgroundBrush(Qt::white); m_legPen.setCosmetic(true); m_currentLegPen.setCosmetic(true); // Read points. int numPoints; in >> numPoints; m_points.resize(numPoints); float minX = std::numeric_limits<float>::max(); float minY = std::numeric_limits<float>::max(); float maxX = std::numeric_limits<float>::lowest(); float maxY = std::numeric_limits<float>::lowest(); double sumX = 0; double sumY = 0; for (int i = 0; i < numPoints; ++i) { float x, y; in >> x >> y; m_points[i].setX(x); m_points[i].setY(y); minX = qMin(minX, x); minY = qMin(minY, y); maxX = qMax(maxX, x); maxY = qMax(maxY, y); sumX += x; sumY += y; Vertex *item; if (numPoints < 100) { // If we have less than 100 vertices, we label them. item = new Vertex(x, y, 8, i, Vertex::ShowLabel); } else { // We just draw them as dots. item = new Vertex(x, y, 2, i, Vertex::NoLabel); } scene->addItem(item); item->setZValue(1); // On top of edges. } if (m_options & CompleteGraph) { // Add the complete set of edges. QPen edgePen(Qt::gray); edgePen.setCosmetic(true); for (int i = 0; i < numPoints; ++i) { for (int j = 0; j < numPoints; ++j) { if (i == j) continue; float x1 = m_points[i].x(); float y1 = m_points[i].y(); float x2 = m_points[j].x(); float y2 = m_points[j].y(); QGraphicsLineItem *edgeItem = scene->addLine(x1, y1, x2, y2, edgePen); m_edges.append(edgeItem); if (m_options & ShowLengths) { addLengthLabel(x1, y1, x2, y2); } } } } // Read solution, if any. if (m_options & PointPairs) { readPointPairs(in); } else { readPointSequence(in); } // Center view on mean coordinate and zoom to fit entire scene. const float margin = qAbs(maxX - minX) / 30; setSceneRect(minX - margin, minY - margin, maxX - minX + 2*margin, maxY - minY + 2*margin); centerOn(QPointF(sumX / numPoints, sumY / numPoints)); fitInView(sceneRect(), Qt::KeepAspectRatio); }
UglyGraphicsView::UglyGraphicsView( QWidget* parent ) : QGraphicsView(parent) { setTransformationAnchor(QGraphicsView::NoAnchor); setMouseTracking(true); }
void CQLayoutView::slotZoomOut() { setTransformationAnchor(QGraphicsView::AnchorUnderMouse); scale(1.0 / mScaleFactor, 1.0 / mScaleFactor); }
void CQLayoutView::slotFitOnScreen() { setTransformationAnchor(QGraphicsView::AnchorUnderMouse); fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio); update(); }
void NodeGraph::mouseMoveEvent(QMouseEvent* e) { QPointF newPos = mapToScene( e->pos() ); QPointF lastMousePosScene = mapToScene( _imp->_lastMousePos.x(), _imp->_lastMousePos.y() ); double dx, dy; { QPointF newPosRoot = _imp->_root->mapFromScene(newPos); QPointF lastMousePosRoot = _imp->_root->mapFromScene(lastMousePosScene); dx = newPosRoot.x() - lastMousePosRoot.x(); dy = newPosRoot.y() - lastMousePosRoot.y(); } _imp->_hasMovedOnce = true; bool mustUpdate = true; boost::shared_ptr<NodeCollection> collection = getGroup(); NodeGroup* isGroup = dynamic_cast<NodeGroup*>( collection.get() ); bool isGroupEditable = true; bool groupEdited = true; if (isGroup) { isGroupEditable = isGroup->isSubGraphEditable(); groupEdited = isGroup->getNode()->hasPyPlugBeenEdited(); } if (!groupEdited && isGroupEditable) { ///check if user is nearby unlock int iw = _imp->unlockIcon.width(); int ih = _imp->unlockIcon.height(); int w = width(); if ( ( e->x() >= (w - iw - 10 - 15) ) && ( e->x() <= (w - 10 + 15) ) && ( e->y() >= (10 - 15) ) && ( e->y() <= (10 + ih + 15) ) ) { assert(isGroup); QPoint pos = mapToGlobal( e->pos() ); QToolTip::showText( pos, GuiUtils::convertFromPlainText(QCoreApplication::translate("NodeGraph", "Clicking the unlock button will convert the PyPlug to a regular group saved in the project and dettach it from the script.\n" "Any modification will not be written to the Python script. Subsequent loading of the project will no longer load this group from the python script."), Qt::WhiteSpaceNormal) ); } } QRectF sceneR = visibleSceneRect(); if ( groupEdited && (_imp->_evtState != eEventStateSelectionRect) && (_imp->_evtState != eEventStateDraggingArrow) ) { // Set cursor std::set<NodeGui*> visibleNodes; getNodesWithinViewportRect(visibleWidgetRect(), &visibleNodes); NodeGuiPtr selected; Edge* selectedEdge = 0; bool optionalInputsAutoHidden = areOptionalInputsAutoHidden(); for (std::set<NodeGui*>::iterator it = visibleNodes.begin(); it != visibleNodes.end(); ++it) { QPointF evpt = (*it)->mapFromScene(newPos); QRectF bbox = (*it)->mapToScene( (*it)->boundingRect() ).boundingRect(); if ( (*it)->isActive() && bbox.intersects(sceneR) ) { if ( (*it)->contains(evpt) ) { selected = (*it)->shared_from_this(); if (optionalInputsAutoHidden) { (*it)->refreshEdgesVisility(true); } else { break; } } else { Edge* edge = (*it)->hasEdgeNearbyPoint(newPos); if (edge) { selectedEdge = edge; if (!optionalInputsAutoHidden) { break; } } else if ( optionalInputsAutoHidden && !(*it)->getIsSelected() ) { (*it)->refreshEdgesVisility(false); } } } } if (selected) { _imp->cursorSet = true; setCursor( QCursor(Qt::OpenHandCursor) ); } else if (selectedEdge) { } else if (!selectedEdge && !selected) { if (_imp->cursorSet) { _imp->cursorSet = false; unsetCursor(); } } } bool mustUpdateNavigator = false; ///Apply actions switch (_imp->_evtState) { case eEventStateDraggingArrow: { QPointF np = _imp->_arrowSelected->mapFromScene(newPos); if ( _imp->_arrowSelected->isOutputEdge() ) { _imp->_arrowSelected->dragDest(np); } else { _imp->_arrowSelected->dragSource(np); } checkAndStartAutoScrollTimer(newPos); mustUpdate = true; break; } case eEventStateDraggingNode: { mustUpdate = true; mustUpdateNavigator = true; bool controlDown = modifierHasControl(e); bool shiftdown = modifierHasShift(e); moveSelectedNodesBy(shiftdown, controlDown, lastMousePosScene, newPos, sceneR, true); break; } case eEventStateMovingArea: { mustUpdateNavigator = true; moveRootInternal(dx, dy); _imp->cursorSet = true; setCursor( QCursor(Qt::SizeAllCursor) ); mustUpdate = true; break; } case eEventStateResizingBackdrop: { mustUpdateNavigator = true; assert(_imp->_backdropResized); QPointF p = _imp->_backdropResized->scenePos(); int w = newPos.x() - p.x(); int h = newPos.y() - p.y(); checkAndStartAutoScrollTimer(newPos); mustUpdate = true; pushUndoCommand( new ResizeBackdropCommand(_imp->_backdropResized, w, h) ); break; } case eEventStateSelectionRect: { QPointF startDrag = _imp->_lastSelectionStartPointScene; QPointF cur = newPos; double xmin = std::min( cur.x(), startDrag.x() ); double xmax = std::max( cur.x(), startDrag.x() ); double ymin = std::min( cur.y(), startDrag.y() ); double ymax = std::max( cur.y(), startDrag.y() ); checkAndStartAutoScrollTimer(newPos); QRectF selRect(xmin, ymin, xmax - xmin, ymax - ymin); _imp->_selectionRect = selRect; mustUpdate = true; break; } case eEventStateDraggingNavigator: { QPointF mousePosSceneCoordinates; bool insideNavigator = isNearbyNavigator(e->pos(), mousePosSceneCoordinates); if (insideNavigator) { _imp->_refreshOverlays = true; centerOn(mousePosSceneCoordinates); _imp->_lastMousePos = e->pos(); update(); return; } break; } case eEventStateZoomingArea: { int delta = 2 * ( ( e->x() - _imp->_lastMousePos.x() ) - ( e->y() - _imp->_lastMousePos.y() ) ); setTransformationAnchor(QGraphicsView::AnchorViewCenter); wheelEventInternal(modCASIsControl(e), delta); setTransformationAnchor(QGraphicsView::AnchorUnderMouse); mustUpdate = true; break; } default: mustUpdate = false; break; } // switch _imp->_lastMousePos = e->pos(); if (mustUpdateNavigator) { _imp->_refreshOverlays = true; mustUpdate = true; } if (mustUpdate) { update(); } QGraphicsView::mouseMoveEvent(e); } // mouseMoveEvent
FieldWidget::FieldWidget(QWidget *parent) : QGraphicsView(parent), m_geometryUpdated(true), m_rotation(0.0f), m_worldStateUpdated(false), m_visualizationsUpdated(false), m_hasTouchInput(false), m_dragType(DragNone), m_dragItem(NULL) { m_touchStatusType = QGestureRecognizer::registerRecognizer(new TouchStatusRecognizer); grabGesture(m_touchStatusType); grabGesture(Qt::PanGesture); grabGesture(Qt::PinchGesture); geometrySetDefault(&m_geometry); // setup context menu m_contextMenu = new QMenu(this); QAction *actionHorizontal = m_contextMenu->addAction("Horizontal"); connect(actionHorizontal, SIGNAL(triggered()), SLOT(setHorizontal())); QAction *actionVertical = m_contextMenu->addAction("Vertical"); connect(actionVertical, SIGNAL(triggered()), SLOT(setVertical())); QAction *actionFlip = m_contextMenu->addAction("Flip"); connect(actionFlip, SIGNAL(triggered()), SLOT(flip())); m_contextMenu->addSeparator(); // add actions to allow hiding visualizations of a team m_actionShowBlueVis = m_contextMenu->addAction("Show blue visualizations"); m_actionShowBlueVis->setCheckable(true); m_actionShowBlueVis->setChecked(true); connect(m_actionShowBlueVis, SIGNAL(triggered()), SLOT(updateVisualizationVisibility())); m_actionShowYellowVis = m_contextMenu->addAction("Show yellow visualizations"); m_actionShowYellowVis->setCheckable(true); m_actionShowYellowVis->setChecked(true); connect(m_actionShowYellowVis, SIGNAL(triggered()), SLOT(updateVisualizationVisibility())); m_actionShowControllerVis = m_contextMenu->addAction("Show controller visualizations"); m_actionShowControllerVis->setCheckable(true); m_actionShowControllerVis->setChecked(true); connect(m_actionShowControllerVis, SIGNAL(triggered()), SLOT(updateVisualizationVisibility())); updateVisualizationVisibility(); // update the visibility map m_contextMenu->addSeparator(); // other actions QAction *actionShowAOI = m_contextMenu->addAction("Enable custom vision area"); actionShowAOI->setCheckable(true); connect(actionShowAOI, SIGNAL(toggled(bool)), SLOT(setAOIVisible(bool))); m_actionAntialiasing = m_contextMenu->addAction("Anti-aliasing"); m_actionAntialiasing->setCheckable(true); connect(m_actionAntialiasing, SIGNAL(toggled(bool)), SLOT(setAntialiasing(bool))); m_actionGL = m_contextMenu->addAction("OpenGL"); m_actionGL->setCheckable(true); connect(m_actionGL, SIGNAL(toggled(bool)), SLOT(setOpenGL(bool))); m_contextMenu->addSeparator(); QAction *actionScreenshot = m_contextMenu->addAction("Take screenshot"); connect(actionScreenshot, SIGNAL(triggered()), SLOT(takeScreenshot())); QAction *actionSaveSituation = m_contextMenu->addAction("Save Situation"); connect(actionSaveSituation, SIGNAL(triggered()), SLOT(saveSituation())); // create graphics scene m_scene = new QGraphicsScene(this); setScene(m_scene); // ball object const float ballRadius = 0.02133f; m_ball = new QGraphicsEllipseItem; m_ball->setPen(Qt::NoPen); m_ball->setBrush(QColor(255, 66, 0)); m_ball->setZValue(100.0f); m_ball->setRect(QRectF(-ballRadius, -ballRadius, ballRadius * 2.0f, ballRadius * 2.0f)); m_ball->hide(); m_scene->addItem(m_ball); // rectangle for area of interest m_aoiItem = new QGraphicsPathItem; m_aoiItem->setPen(Qt::NoPen); m_aoiItem->setBrush(QColor(0, 0, 0, 128)); m_aoiItem->setZValue(10000.0f); m_aoiItem->hide(); m_scene->addItem(m_aoiItem); m_aoi = QRectF(-1, -1, 2, 2); updateAOI(); m_scene->setBackgroundBrush(Qt::black); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); // should improve the performance setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // transforms are centered on the mouse cursor setTransformationAnchor(QGraphicsView::NoAnchor); setOptimizationFlag(QGraphicsView::DontSavePainterState); setCacheMode(QGraphicsView::CacheBackground); setHorizontal(); // view update timer QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), SLOT(updateAll())); timer->start(30); setMouseTracking(true); // create label to show field coordinates m_lblMousePos = new QLabel(this); m_lblMousePos->setAutoFillBackground(true); // solid background // draw frame m_lblMousePos->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); m_lblMousePos->setMargin(2); // some space m_lblMousePos->hide(); // ensure that the label is hidden on startup // load settings QSettings s; s.beginGroup("Field"); m_actionGL->setChecked(s.value("OpenGL").toBool()); m_actionAntialiasing->setChecked(s.value("AntiAliasing").toBool()); s.endGroup(); }
QGraphicsViewEc::QGraphicsViewEc(QWidget* parent) : QGraphicsView(parent) { setTransformationAnchor(QGraphicsView::AnchorUnderMouse); }
void NodeGraph::mouseMoveEvent(QMouseEvent* e) { QPointF newPos = mapToScene( e->pos() ); QPointF lastMousePosScene = mapToScene( _imp->_lastMousePos.x(), _imp->_lastMousePos.y() ); double dx, dy; { QPointF newPosRoot = _imp->_root->mapFromScene(newPos); QPointF lastMousePosRoot = _imp->_root->mapFromScene(lastMousePosScene); dx = newPosRoot.x() - lastMousePosRoot.x(); dy = newPosRoot.y() - lastMousePosRoot.y(); } _imp->_hasMovedOnce = true; bool mustUpdate = true; NodeCollectionPtr collection = getGroup(); NodeGroupPtr isGroup = toNodeGroup(collection); bool isGroupEditable = true; bool groupEdited = true; if (isGroup) { isGroupEditable = isGroup->isSubGraphEditable(); groupEdited = isGroup->isSubGraphEditedByUser(); } if (!groupEdited && isGroupEditable) { ///check if user is nearby unlock // see NodeGraph::paintEvent() QPoint pixPos = _imp->getPyPlugUnlockPos(); int pixW = _imp->unlockIcon.width(); int pixH = _imp->unlockIcon.height(); QRect pixRect(pixPos.x(), pixPos.y(), pixW, pixH); pixRect.adjust(-2, -2, 2, 2); QRect selRect = pixRect; selRect.adjust(-3, -3, 3, 3); if ( selRect.contains( e->pos() ) ) { assert(isGroup); QPoint pos = mapToGlobal( e->pos() ); // Unfortunately, the timeout delay for the tooltip is hardcoded in Qt 4, and the last parameter to showText doesn't seem to influence anything // Can not fix https://github.com/MrKepzie/Natron/issues/1151 (at least in Qt4) QToolTip::showText( pos, NATRON_NAMESPACE::convertFromPlainText(QCoreApplication::translate("NodeGraph", "Clicking the unlock button will convert the PyPlug to a regular group saved in the project and dettach it from the script.\n" "Any modification will not be written to the Python script. Subsequent loading of the project will no longer load this group from the python script."), NATRON_NAMESPACE::WhiteSpaceNormal), this, selRect); e->accept(); return; } } QRectF sceneR = visibleSceneRect(); bool mustUpdateNavigator = false; ///Apply actions switch (_imp->_evtState) { case eEventStateDraggingArrow: { QPointF np = _imp->_arrowSelected->mapFromScene(newPos); if ( _imp->_arrowSelected->isOutputEdge() ) { _imp->_arrowSelected->dragDest(np); } else { _imp->_arrowSelected->dragSource(np); } checkAndStartAutoScrollTimer(newPos); mustUpdate = true; if (_imp->cursorSet) { _imp->cursorSet = false; unsetCursor(); } break; } case eEventStateDraggingNode: { mustUpdate = true; mustUpdateNavigator = true; bool controlDown = modifierHasControl(e); bool shiftdown = modifierHasShift(e); moveSelectedNodesBy(shiftdown, controlDown, lastMousePosScene, newPos, sceneR, true); _imp->cursorSet = true; setCursor( QCursor(Qt::ClosedHandCursor) ); break; } case eEventStateMovingArea: { mustUpdateNavigator = true; moveRootInternal(dx, dy); mustUpdate = true; _imp->cursorSet = true; setCursor( QCursor(Qt::SizeAllCursor) ); break; } case eEventStateResizingBackdrop: { mustUpdateNavigator = true; assert(_imp->_backdropResized.lock()); QPointF p = _imp->_backdropResized.lock()->scenePos(); int w = newPos.x() - p.x(); int h = newPos.y() - p.y(); checkAndStartAutoScrollTimer(newPos); mustUpdate = true; pushUndoCommand( new ResizeBackdropCommand(_imp->_backdropResized.lock(), w, h) ); _imp->cursorSet = true; setCursor( QCursor(Qt::SizeFDiagCursor) ); break; } case eEventStateSelectionRect: { QPointF startDrag = _imp->_lastSelectionStartPointScene; QPointF cur = newPos; double xmin = std::min( cur.x(), startDrag.x() ); double xmax = std::max( cur.x(), startDrag.x() ); double ymin = std::min( cur.y(), startDrag.y() ); double ymax = std::max( cur.y(), startDrag.y() ); checkAndStartAutoScrollTimer(newPos); QRectF selRect(xmin, ymin, xmax - xmin, ymax - ymin); _imp->_selectionRect = selRect; mustUpdate = true; _imp->cursorSet = true; setCursor( QCursor(Qt::CrossCursor) ); break; } case eEventStateDraggingNavigator: { _imp->cursorSet = true; setCursor( QCursor(Qt::ClosedHandCursor) ); QPointF mousePosSceneCoordinates; bool insideNavigator = isNearbyNavigator(e->pos(), mousePosSceneCoordinates); if (insideNavigator) { _imp->_refreshOverlays = true; centerOn(mousePosSceneCoordinates); _imp->_lastMousePos = e->pos(); update(); return; } break; } case eEventStateZoomingArea: { int delta = 2 * ( ( e->x() - _imp->_lastMousePos.x() ) - ( e->y() - _imp->_lastMousePos.y() ) ); setTransformationAnchor(QGraphicsView::AnchorViewCenter); wheelEventInternal(modCASIsControl(e), delta); setTransformationAnchor(QGraphicsView::AnchorUnderMouse); mustUpdate = true; _imp->cursorSet = true; setCursor( QCursor(Qt::SizeAllCursor) ); break; } case eEventStateNone: default: { mustUpdate = false; // Test if mouse is inside the navigator QPointF mousePosSceneCoordinates; bool insideNavigator = isNearbyNavigator(e->pos(), mousePosSceneCoordinates); if (insideNavigator) { _imp->cursorSet = true; setCursor( QCursor(Qt::OpenHandCursor) ); } else if (!groupEdited) { if (_imp->cursorSet) { _imp->cursorSet = false; unsetCursor(); } } else { // Set cursor // The cursor should clearly indicate when will happen if mouse is pressed NodeGuiPtr nearbyNode; Edge* nearbyEdge = NULL; NearbyItemEnum nearbyItemCode = hasItemNearbyMouse(e->pos(), &nearbyNode, &nearbyEdge); switch (nearbyItemCode) { case eNearbyItemNode: case eNearbyItemBackdropFrame: case eNearbyItemEdgeBendPoint: { _imp->cursorSet = true; setCursor( QCursor(Qt::OpenHandCursor) ); break; } case eNearbyItemBackdropResizeHandle: { _imp->cursorSet = true; setCursor( QCursor(Qt::SizeFDiagCursor) ); break; } case eNearbyItemNone: { _imp->cursorSet = true; setCursor( QCursor(Qt::CrossCursor) ); break; } case eNearbyItemNodeEdge: default: { if (_imp->cursorSet) { _imp->cursorSet = false; unsetCursor(); } break; } } } break; } } // switch _imp->_lastMousePos = e->pos(); if (mustUpdateNavigator) { _imp->_refreshOverlays = true; mustUpdate = true; } if (mustUpdate) { update(); } TabWidget* tab = getParentPane() ; if (tab && _imp->_evtState == eEventStateNone) { // If the Viewer is in a tab, send the tab widget the event directly qApp->sendEvent(tab, e); } QGraphicsView::mouseMoveEvent(e); } // mouseMoveEvent
MapGraphicsView::MapGraphicsView() : QGraphicsView() { #ifndef Q_OS_WIN srand ( time(NULL) ); #endif m_scaleFactor = 1.; #ifndef QT_NO_OPENGL //setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); #endif setCacheMode(CacheBackground); //setViewportUpdateMode(BoundingRectViewportUpdate); //setRenderHint(QPainter::Antialiasing); //setTransformationAnchor(AnchorUnderMouse); #ifdef Q_OS_ANDROID setTransformationAnchor(QGraphicsView::AnchorViewCenter); #endif setResizeAnchor(AnchorViewCenter); setDragMode(QGraphicsView::ScrollHandDrag); setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform ); // if there are ever graphic glitches to be found, remove this again setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing | QGraphicsView::DontClipPainter | QGraphicsView::DontSavePainterState); //setCacheMode(QGraphicsView::CacheBackground); //setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); setOptimizationFlags(QGraphicsView::DontSavePainterState); setFrameStyle(QFrame::NoFrame); #ifdef Q_OS_ANDROID setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); #endif QWidget *viewport = new QWidget(); QVBoxLayout *vbox = new QVBoxLayout(viewport); QHBoxLayout *hbox; hbox = new QHBoxLayout(); { hbox->setSpacing(0); hbox->addStretch(1); m_hudLabel = new QLabel(); hbox->addWidget(m_hudLabel); vbox->addLayout(hbox); } vbox->addStretch(1); hbox = new QHBoxLayout(); { hbox->setSpacing(0); hbox->addStretch(1); m_statusLabel = new QLabel(); hbox->addWidget(m_statusLabel); m_statusLabel->hide(); hbox->addStretch(1); } vbox->addLayout(hbox); hbox = new QHBoxLayout(); { hbox->setSpacing(0); hbox->addStretch(1); QPushButton *btn; { btn = new QPushButton("-"); btn->setStyleSheet("QPushButton {" #ifdef Q_OS_ANDROID "background: url(':/data/images/android-zoom-minus-button.png'); width: 117px; height: 47px; " #else "background: url(':/data/images/zoom-minus-button.png'); width: 58px; height: 24px; " #endif "padding:0; margin:0; border:none; color: transparent; outline: none; }"); btn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); btn->setAutoRepeat(true); btn->setMaximumSize(117,48); connect(btn, SIGNAL(clicked()), this, SLOT(zoomOut())); hbox->addWidget(btn); } { btn = new QPushButton("+"); btn->setStyleSheet("QPushButton {" #ifdef Q_OS_ANDROID "background: url(':/data/images/android-zoom-plus-button.png'); width: 117px; height: 47px; " #else "background: url(':/data/images/zoom-plus-button.png'); width: 58px; height: 24px; " #endif "padding:0; margin:0; border:none; color: transparent; outline: none; }"); btn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); btn->setAttribute(Qt::WA_TranslucentBackground, true); btn->setAutoRepeat(true); btn->setMaximumSize(117,48); connect(btn, SIGNAL(clicked()), this, SLOT(zoomIn())); hbox->addWidget(btn); } hbox->addStretch(1); } vbox->addLayout(hbox); m_viewportLayout = vbox; setViewport(viewport); // Set a timer to update layout because it doesn't give buttons correct position right at the start QTimer::singleShot(500, this, SLOT(updateViewportLayout())); // Disable here because it interferes with the 'longpress' functionality in MapGraphicsScene // FlickCharm *flickCharm = new FlickCharm(this); // flickCharm->activateOn(this); }
WbWidget::WbWidget(SxeSession* session, QWidget *parent) : QGraphicsView(parent) { newWbItem_ = 0; adding_ = 0; addVertex_ = false; strokeColor_ = Qt::black; fillColor_ = Qt::transparent; strokeWidth_ = 1; session_ = session; // setCacheMode(CacheBackground); setRenderHint(QPainter::Antialiasing); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // Make the scroll bars always stay on because otherwise the resize event can cause // an infinite loop as the effective size of the widget changes when scroll bars are // added/removed setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); // create the scene scene_ = new WbScene(session_, this); scene_->setItemIndexMethod(QGraphicsScene::NoIndex); setRenderHint(QPainter::Antialiasing); setTransformationAnchor(AnchorUnderMouse); setResizeAnchor(AnchorViewCenter); setScene(scene_); // render the initial document rerender(); // rerender on update connect(session_, SIGNAL(documentUpdated(bool)), SLOT(handleDocumentUpdated(bool))); // add the initial items const QDomNodeList children = session_->document().documentElement().childNodes(); for(int i = 0; i < (int)children.length(); i++) { const QDomNode node = children.at(i); if(node.isElement()) { queueNodeInspection(node.toElement()); } } inspectNodes(); // add new items as nodes are added // remove/add items if corresponding nodes are moved connect(session_, SIGNAL(nodeAdded(QDomNode, bool)), SLOT(queueNodeInspection(QDomNode))); connect(session_, SIGNAL(nodeMoved(QDomNode, bool)), SLOT(queueNodeInspection(QDomNode))); // remove items if corresponding nodes are deleted connect(session_, SIGNAL(nodeToBeRemoved(QDomNode, bool)), SLOT(removeWbItem(QDomNode))); connect(session_, SIGNAL(nodeToBeRemoved(QDomNode, bool)), SLOT(checkForRemovalOfId(QDomNode))); // adjust the viewBox as necessary connect(session_, SIGNAL(nodeAdded(QDomNode, bool)), SLOT(checkForViewBoxChange(QDomNode))); connect(session_, SIGNAL(nodeMoved(QDomNode, bool)), SLOT(checkForViewBoxChange(QDomNode))); connect(session_, SIGNAL(chdataChanged(QDomNode, bool)), SLOT(checkForViewBoxChange(QDomNode))); // set the default mode to select setMode(Select); // set the initial size if(session_->document().documentElement().hasAttribute("viewBox")) checkForViewBoxChange(session_->document().documentElement().attributeNode("viewBox")); else { QSize size; QRectF rect = scene_->sceneRect(); size.setWidth(rect.x() + rect.width()); size.setHeight(rect.y() + rect.height()); if(size.width() > 0 && size.height() > 0) setSize(size); else setSize(QSize(400, 600)); } }