SceneGraphic::SceneGraphic(QWidget* parent) : QGraphicsView(parent){ //setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); setDragMode(ScrollHandDrag); }
void koregui::SceneViewer::keyPressEvent(QKeyEvent * event) { if (event->key() == Qt::Key_Escape) QGuiApplication::quit(); if (event->key() == Qt::Key_Shift) setDragMode(ScrollHandDrag); QGraphicsView::keyPressEvent(event); }
ChatLog::ChatLog(QWidget* parent) : QGraphicsView(parent) { // Create the scene busyScene = new QGraphicsScene(this); scene = new QGraphicsScene(this); scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex); setScene(scene); // Cfg. setInteractive(true); setAcceptDrops(false); setAlignment(Qt::AlignTop | Qt::AlignLeft); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setDragMode(QGraphicsView::NoDrag); setViewportUpdateMode(MinimalViewportUpdate); setContextMenuPolicy(Qt::CustomContextMenu); setBackgroundBrush(QBrush(Qt::white, Qt::SolidPattern)); // The selection rect for multi-line selection selGraphItem = scene->addRect(0,0,0,0,selectionRectColor.darker(120),selectionRectColor); selGraphItem->setZValue(-1.0); // behind all other items // copy action (ie. Ctrl+C) copyAction = new QAction(this); copyAction->setIcon(QIcon::fromTheme("edit-copy")); copyAction->setShortcut(QKeySequence::Copy); copyAction->setEnabled(false); connect(copyAction, &QAction::triggered, this, [this]() { copySelectedText(); }); addAction(copyAction); #ifdef Q_OS_LINUX // Ctrl+Insert shortcut QShortcut* copyCtrlInsShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Insert), this); connect(copyCtrlInsShortcut, &QShortcut::activated, this, [this]() { copySelectedText(); }); #endif // select all action (ie. Ctrl+A) selectAllAction = new QAction(this); selectAllAction->setIcon(QIcon::fromTheme("edit-select-all")); selectAllAction->setShortcut(QKeySequence::SelectAll); connect(selectAllAction, &QAction::triggered, this, [this]() { selectAll(); }); addAction(selectAllAction); // This timer is used to scroll the view while the user is // moving the mouse past the top/bottom edge of the widget while selecting. selectionTimer = new QTimer(this); selectionTimer->setInterval(1000/30); selectionTimer->setSingleShot(false); selectionTimer->start(); connect(selectionTimer, &QTimer::timeout, this, &ChatLog::onSelectionTimerTimeout); // Background worker // Updates the layout of all chat-lines after a resize workerTimer = new QTimer(this); workerTimer->setSingleShot(false); workerTimer->setInterval(5); connect(workerTimer, &QTimer::timeout, this, &ChatLog::onWorkerTimeout); // selection connect(this, &ChatLog::selectionChanged, this, [this]() { copyAction->setEnabled(hasTextToBeCopied()); #ifdef Q_OS_LINUX copySelectedText(true); #endif }); retranslateUi(); Translator::registerHandler(std::bind(&ChatLog::retranslateUi, this), this); }
void MyGraphicsView::mouseReleaseEvent(QMouseEvent * event) { QGraphicsView::mouseReleaseEvent(event); setDragMode(QGraphicsView::RubberBandDrag); g_settings->nodeDragging = NEARBY_PIECES; }
GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), mScale(1.0) { setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); setDragMode(ScrollHandDrag); }
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); }
void View::mouseReleaseEvent(QMouseEvent * e){ setDragMode(e->buttons()); }
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); setScale(1.5); 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); } }
void View::mousePressEvent(QMouseEvent * e){ setDragMode(e->buttons()); xDragBegin = e->x(); yDragBegin = e->y(); }
void GraphicsNodeView::leftMouseButtonPress(QMouseEvent *event) { QGraphicsView::mousePressEvent(event); // GUI logic: if we click on a socket, we need to handle // the event appropriately QGraphicsItem *item = itemAt(event->pos()); if (!item) { setDragMode(QGraphicsView::RubberBandDrag); QGraphicsView::mousePressEvent(event); return; } switch (item->type()) { case GraphicsNodeItemTypes::TypeSocket: { QPointF scenePos = mapToScene(event->pos()); QPointF itemPos = item->mapFromScene(scenePos); GraphicsNodeSocket *sock = static_cast<GraphicsNodeSocket *>(item); if (sock->isInSocketCircle(itemPos)) { viewport()->setCursor(Qt::ClosedHandCursor); // initialize a new drag mode event _drag_event = new EdgeDragEvent(); auto edges = sock->get_edges(); if (edges.size() == 1) { // get the first edge for (auto e : edges) { _tmp_edge = e; break; } _drag_event->e = _tmp_edge; if (sock->socket_type() == Port::Direction::IN) { _drag_event->e->disconnect_sink(); _drag_event->e->set_stop(mapToScene(event->pos())); _drag_event->mode = EdgeDragEvent::move_to_sink; } else { _drag_event->e->disconnect_source(); _drag_event->e->set_start(mapToScene(event->pos())); _drag_event->mode = EdgeDragEvent::move_to_source; } } else { GraphicsNodeScene *gscene = dynamic_cast<GraphicsNodeScene *>(scene()); _drag_event->e = gscene->make_edge(); if (sock->socket_type() == Port::Direction::IN) { _drag_event->e->set_start(mapToScene(event->pos())); _drag_event->e->connect_sink(sock); _drag_event->mode = EdgeDragEvent::connect_to_source; } else { _drag_event->e->connect_source(sock); _drag_event->e->set_stop(mapToScene(event->pos())); _drag_event->mode = EdgeDragEvent::connect_to_sink; } } event->ignore(); } else { QGraphicsView::mousePressEvent(event); } break; } case GraphicsNodeItemTypes::TypeNode: { QPointF scenePos = mapToScene(event->pos()); QPointF itemPos = item->mapFromScene(scenePos); GraphicsNode *node = static_cast<GraphicsNode *>(item); if (itemPos.x() > (node->width() - 10) && (itemPos.y() > (node->height() - 10))) { setViewportUpdateMode( QGraphicsView::BoundingRectViewportUpdate); _resize_event = new NodeResizeEvent(); _resize_event->node = node; _resize_event->orig_width = node->width(); _resize_event->orig_height = node->height(); _resize_event->pos = event->pos(); event->ignore(); } else { QGraphicsView::mousePressEvent(event); } break; } default: QGraphicsView::mousePressEvent(event); } }
/*! Reimplemets the QGraphicsView::mouseReleaseEvent() */ void SchematicSceneViewer::mouseReleaseEvent(QMouseEvent *me) { m_buttonState = Qt::NoButton; QGraphicsView::mouseReleaseEvent(me); setDragMode(QGraphicsView::NoDrag); // update(); }
GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent), totalScaleFactor(1) { viewport()->setAttribute(Qt::WA_AcceptTouchEvents); setDragMode(ScrollHandDrag); }
LinkDialogGraphicsView::LinkDialogGraphicsView(QWidget* parent) : QGraphicsView(parent), scene_(nullptr) { setRenderHint(QPainter::Antialiasing, true); setMouseTracking(true); setDragMode(QGraphicsView::RubberBandDrag); }