void ArrangementDemoWindow::removeCallback( unsigned int tabIndex ) { if (tabIndex == static_cast<unsigned int>(-1)) return; ArrangementDemoTabBase* activeTab = this->tabs[ tabIndex ]; QGraphicsScene* activeScene = activeTab->getScene( ); QGraphicsView* activeView = activeTab->getView( ); #if 0 QAction* activeMode = this->activeModes[ tabIndex ]; #endif activeScene->removeEventFilter( activeTab->getCurveInputCallback( ) ); activeView->setDragMode( QGraphicsView::NoDrag ); activeScene->removeEventFilter( activeTab->getDeleteCurveCallback( ) ); activeScene->removeEventFilter( activeTab->getPointLocationCallback( ) ); activeScene->removeEventFilter( activeTab->getVerticalRayShootCallback( ) ); activeScene->removeEventFilter( activeTab->getMergeEdgeCallback( ) ); activeScene->removeEventFilter( activeTab->getSplitEdgeCallback( ) ); activeScene->removeEventFilter( activeTab->getVerticalRayShootCallback( ) ); activeScene->removeEventFilter( activeTab->getFillFaceCallback( ) ); // unhook the old active mode #if 0 if ( activeMode == this->ui->actionInsert ) { activeScene->removeEventFilter( activeTab->getCurveInputCallback( ) ); } else if ( activeMode == this->ui->actionDrag ) { activeView->setDragMode( QGraphicsView::NoDrag ); } else if ( activeMode == this->ui->actionDelete ) { activeScene->removeEventFilter( activeTab->getDeleteCurveCallback( ) ); } else if ( activeMode == this->ui->actionPointLocation ) { activeScene->removeEventFilter( activeTab->getPointLocationCallback( ) ); } else if ( activeMode == this->ui->actionRayShootingUp ) { activeScene->removeEventFilter( activeTab->getVerticalRayShootCallback( ) ); } else if ( activeMode == this->ui->actionRayShootingDown ) { activeScene->removeEventFilter( activeTab->getVerticalRayShootCallback( ) ); } else if ( activeMode == this->ui->actionMerge ) { activeScene->removeEventFilter( activeTab->getMergeEdgeCallback( ) ); } else if ( activeMode == this->ui->actionSplit ) { activeScene->removeEventFilter( activeTab->getSplitEdgeCallback( ) ); } #endif }
SEXP qt_qsetDragMode(SEXP v, SEXP mode) { QGraphicsView *view = unwrapQObject(v, QGraphicsView); if (view) { int m = INTEGER(mode)[0]; if (m == 0) view->setDragMode(QGraphicsView::NoDrag); else if (m == 1) view->setDragMode(QGraphicsView::ScrollHandDrag); else if (m == 2) view->setDragMode(QGraphicsView::RubberBandDrag); } return R_NilValue; }
void ArrangementDemoWindow::updateMode( QAction* newMode ) { // QWidget* widget = this->ui->tabWidget->currentWidget( ); // ArrangementDemoTabBase* demoTab = // static_cast< ArrangementDemoTabBase* >( widget ); const unsigned int TabIndex = this->ui->tabWidget->currentIndex( ); if (TabIndex == static_cast<unsigned int>(-1)) return; ArrangementDemoTabBase* activeTab = this->tabs[ TabIndex ]; QGraphicsScene* activeScene = activeTab->getScene( ); QGraphicsView* activeView = activeTab->getView( ); this->resetCallbackState( TabIndex ); this->removeCallback( TabIndex ); // update the active mode this->activeModes.at( 0 ) = newMode; // hook up the new active mode if ( newMode == this->ui->actionInsert ) { activeScene->installEventFilter( activeTab->getCurveInputCallback( ) ); } else if ( newMode == this->ui->actionDrag ) { activeView->setDragMode( QGraphicsView::ScrollHandDrag ); } else if ( newMode == this->ui->actionDelete ) { activeScene->installEventFilter( activeTab->getDeleteCurveCallback( ) ); } else if ( newMode == this->ui->actionPointLocation ) { activeScene->installEventFilter( activeTab->getPointLocationCallback( ) ); } else if ( newMode == this->ui->actionRayShootingUp ) { // -y is up for Qt, so we shoot down activeTab->getVerticalRayShootCallback( )->setShootingUp( true ); activeScene->installEventFilter( activeTab->getVerticalRayShootCallback()); } else if ( newMode == this->ui->actionRayShootingDown ) { // the bottom of the viewport for Qt is +y, so we shoot up activeTab->getVerticalRayShootCallback( )->setShootingUp( false ); activeScene->installEventFilter( activeTab->getVerticalRayShootCallback()); } else if ( newMode == this->ui->actionMerge ) { activeScene->installEventFilter( activeTab->getMergeEdgeCallback( ) ); } else if ( newMode == this->ui->actionSplit ) { activeScene->installEventFilter( activeTab->getSplitEdgeCallback( ) ); } else if ( newMode == this->ui->actionFill ) { activeScene->installEventFilter( activeTab->getFillFaceCallback( ) ); } this->updateFillColorSwatch( ); }
SEXP qt_qsceneView(SEXP scene) { QGraphicsView *v = new QGraphicsView(unwrapSmoke(scene, QGraphicsScene), 0); v->setRenderHints(QPainter::TextAntialiasing); v->setInteractive(true); // v->setDragMode(QGraphicsView::RubberBandDrag); v->setDragMode(QGraphicsView::ScrollHandDrag); return wrapSmoke(v, QGraphicsView, true); }
void NoteEditScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if(_grabItem != 0) { QGraphicsView *view = this->views().at(0); view->setDragMode(QGraphicsView::DragMode::RubberBandDrag); dynamic_cast<Note*>(_grabItem)->calculateInfo(bpm); _grabItem = 0; } }
QGraphicsView *Page::GenerateGraphicsView() { QGraphicsView *graphicsView = new QGraphicsView(); graphicsView->setRenderHint(QPainter::Antialiasing, false); graphicsView->setDragMode(QGraphicsView::RubberBandDrag); graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState); graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); #ifndef QT_NO_OPENGL //graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); #endif graphicsView->setRenderHint(QPainter::Antialiasing, true); return graphicsView; }
void NoteEditScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { QPointF mousePoint; mousePoint = event->scenePos(); m_clickPoint = mousePoint; if(currentMode == MOVE ||currentMode == LONGNOTE) { QGraphicsItem *gItem = itemAt(mousePoint.x(), mousePoint.y(), QTransform()); if(gItem != nullptr && gItem->type() == Note::Type) { //もしもオブジェクトをつかんだら QGraphicsView *view = this->views().at(0); view->setDragMode(QGraphicsView::DragMode::NoDrag); _grabItem = gItem; return; } } else if(currentMode == ERASE) { QGraphicsItem *gItem = itemAt(mousePoint.x(), mousePoint.y(), QTransform()); if(gItem != nullptr && gItem->type() == Note::Type) { noteList.removeOne(dynamic_cast<Note*>(gItem)); removeItem(gItem); } } else { qreal widthRatio = Note::NOTE_WIDTH; qreal heightRatio = Note::NOTE_HEIGHT; auto note = new Note(QRect(0,0, widthRatio, heightRatio)); //QRectF rect = this->sceneRect(); int px = static_cast<int>(mousePoint.x() / widthRatio) * widthRatio; int py = static_cast<int>(mousePoint.y() / heightRatio) * heightRatio; note->setPos(px, py); addItem(note); note->calculateInfo(bpm); noteList.append(note); qDebug("X: %lf, Y: %lf", mousePoint.x(), mousePoint.y()); } return; }
void Scene::setMode(Mode mode){ sceneMode = mode; QGraphicsView::DragMode vMode = QGraphicsView::NoDrag; if(mode == DrawLine){ makeItemsControllable(false); vMode = QGraphicsView::NoDrag; } else if(mode == SelectObject){ makeItemsControllable(true); vMode = QGraphicsView::RubberBandDrag; } QGraphicsView* mView = views().at(0); if(mView) mView->setDragMode(vMode); }
void PieceAppearanceWidget::setupUI() { QLayout * lay = new QGridLayout( this ); lay->setSpacing(0); lay->setContentsMargins(0,0,0,0); QGraphicsView * v = this->impl->gv = //new QGraphicsView( impl->gs.scene() ) new QBoardView( impl->gs ) ; v->setTransformationAnchor(QGraphicsView::NoAnchor); #if 0 v->setAlignment(Qt::AlignLeft | Qt::AlignTop); v->setInteractive(true); // required to get mouse events to the children v->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); v->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); v->setDragMode(QGraphicsView::RubberBandDrag); v->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); #endif v->setBackgroundBrush(QColor("#abb8fb")); v->viewport()->setObjectName( "PieceAppearanceWidget"); lay->addWidget( v ); QStringList tip; tip << "<html><body>These widgets are appearance templates for game pieces.\n" << "Edit them by right-clicking them.\n" << "Select a template by left-clicking it. " << "QBoard will use the selected template as the default look\n" << "for newly-added pieces which are loaded from image files.\n" << "This list will be saved automatically when QBoard exits,\n" << "and loaded when QBoard starts up.</body></html>" ; impl->gv->setToolTip( tip.join("") ); }
Debugger::Debugger(Shift::Database *db, QWidget *parent) : QWidget(parent) { _db = db; move(10, 10); QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); QToolBar *toolbar = new QToolBar("mainTool", this); layout->addWidget(toolbar); toolbar->addAction("Snapshot", this, SLOT(snapshot())); _scene = new QGraphicsScene(this); _scene->setBackgroundBrush(QColor(64, 64, 64)); QGraphicsView *view = new QGraphicsView(_scene, this); layout->addWidget(view); view->setRenderHints(QPainter::Antialiasing); view->setDragMode(QGraphicsView::ScrollHandDrag); }