/** Traduit en coordonnees locales un mouvement / vecteur initialement exprime en coordonnees du parent. @param movement Vecteur exprime en coordonnees du parent @return le meme vecteur, exprime en coordonnees locales */ QPointF DiagramTextItem::mapMovementFromParent(const QPointF &movement) const { // on definit deux points sur le parent QPointF parent_origin(0.0, 0.0); QPointF parent_movement_point(movement); // on les mappe sur ce QGraphicsItem QPointF local_origin(mapFromParent(parent_origin)); QPointF local_movement_point(mapFromParent(parent_movement_point)); // on calcule le vecteur represente par ces deux points return(local_movement_point - local_origin); }
/** * This method aligns *this* Symbol to the line being * passed. That is, it ensures that the axis of this symbol aligns * exactly with the \a "to" line passed. * * Also this item is moved such that the second end point of the * SymbolEndPoints for the current symbol *collides* with the second end * point of \a "to" line. */ void Symbol::alignTo(const QLineF& to) { QLineF toMapped(mapFromParent(to.p1()), mapFromParent(to.p2())); QLineF origAxis = Symbol::symbolTable[m_symbolType].axisLine; QLineF translatedAxis = origAxis.translated(toMapped.p2() - origAxis.p2()); qreal angle = translatedAxis.angleTo(toMapped); rotate(-angle); QPointF delta = to.p2() - mapToParent(symbolEndPoints().second); moveBy(delta.x(), delta.y()); }
void VCWidget::resize(QPoint p) { // Grid settings if (_app->virtualConsole()->isGridEnabled()) { p.setX(p.x() - (p.x() % _app->virtualConsole()->gridX())); p.setY(p.y() - (p.y() % _app->virtualConsole()->gridY())); } // Map to parent coordinates so that they can be compared p = mapToParent(p); // Don't move beyond left or right if (p.x() < 0) p.setX(0); else if (p.x() > parentWidget()->width()) p.setX(parentWidget()->width()); // Don't move beyond top or bottom if (p.y() < 0) p.setY(0); else if (p.y() > parentWidget()->height()) p.setY(parentWidget()->height()); // Map back so that this can be resized p = mapFromParent(p); // Do the resize QFrame::resize(p.x(), p.y()); }
//____________________________________________________________________________________ void SunkenFrameShadow::paintEvent(QPaintEvent *event ) { // this fixes shadows in frames that change frameStyle() after polish() if (QFrame *frame = qobject_cast<QFrame *>(parentWidget())) { if (frame->frameStyle() != (QFrame::StyledPanel | QFrame::Sunken)) return; } QWidget *parent = parentWidget(); if(!parent) return; QRect r = parent->contentsRect(); r.translate(mapFromParent(QPoint(0, 0))); QColor base( palette().color(QPalette::Window) ); TileSet::Tiles tiles; switch( shadowArea() ) { case Top: { tiles = TileSet::Left|TileSet::Top|TileSet::Right; r.adjust( -2, -2, 2, -1 ); break; } case Bottom: { tiles = TileSet::Left|TileSet::Bottom|TileSet::Right; r.adjust( -2, 1, 2, 2 ); break; } case Left: { tiles = TileSet::Left; r.adjust( -2, -4, -1, 4 ); break; } case Right: { tiles = TileSet::Right; r.adjust( -1, -4, 2, 4 ); break; } default: return; } HoleOptions options( HoleOutline ); if( _focus ) options |= HoleFocus; if( _hover ) options |= HoleHover; if( hasContrast() ) options |= HoleContrast; QPainter painter(this); painter.setClipRegion( event->region() ); _helper.renderHole( &painter, palette().color( QPalette::Window ), r, options, _opacity, _mode, tiles ); return; }
void NodeBackDrop::resize(int w,int h) { QMutexLocker l(&_imp->bboxMutex); QPointF p = pos(); QPointF thisItemPos = mapFromParent(p); QRectF textBbox = _imp->name->boundingRect(); if (w < textBbox.width()) { w = textBbox.width(); } int minH = (textBbox.height() * 1.5) + 20; if (h < minH) { h = minH; } setRect(QRectF(thisItemPos.x(),thisItemPos.y(),w,h)); _imp->header->setRect(QRect(thisItemPos.x(),thisItemPos.y(),w,textBbox.height() * 1.5)); _imp->name->setPos(thisItemPos.x() + w / 2 - textBbox.width() / 2,thisItemPos.y() + 0.25 * textBbox.height()); _imp->label->setPos(thisItemPos.x(), thisItemPos.y() + textBbox.height() * 1.5 + 10); _imp->label->setTextWidth(w); QPolygonF resizeHandle; QPointF bottomRight(thisItemPos.x() + w,thisItemPos.y() + h); resizeHandle.push_back(QPointF(bottomRight.x() - 20,bottomRight.y())); resizeHandle.push_back(bottomRight); resizeHandle.push_back(QPointF(bottomRight.x(), bottomRight.y() - 20)); _imp->resizeHandle->setPolygon(resizeHandle); }
GraphConnectionEndpoint GraphDraw::mousedEndpoint(const QPoint &pos) { auto objs = this->items(pos); if (_connectLineItem) objs.removeOne(_connectLineItem.get()); if (objs.empty()) return GraphConnectionEndpoint(); auto topObj = dynamic_cast<GraphObject *>(objs.front()); if (topObj == nullptr) return GraphConnectionEndpoint(); const auto point = topObj->mapFromParent(this->mapToScene(pos)); return GraphConnectionEndpoint(topObj, topObj->isPointingToConnectable(point)); }
QPointF Fidelity::GUI::ANodeItem::NodeCenterScenePosition() const { // Get adjusted local center position QPointF center = mapFromParent(pos()); center.setX(center.x() + NodeSize / 2); center.setY(center.y() + NodeSize / 2); // Return position in scene coordinates return(mapToScene(center)); }
void GraphDraw::doClickSelection(const QPointF &point) { const bool ctrlDown = QApplication::keyboardModifiers() & Qt::ControlModifier; const auto objs = this->items(this->mapFromScene(point)); //nothing selected, clear the last selected endpoint if (objs.empty()) _lastClickSelectEp = GraphConnectionEndpoint(); //connection creation logic if (not ctrlDown and not objs.empty()) { auto topObj = dynamic_cast<GraphObject *>(objs.front()); if (topObj == nullptr) return; GraphConnectionEndpoint thisEp(topObj, topObj->isPointingToConnectable(topObj->mapFromParent(point))); //valid keys, attempt to make a connection QPointer<GraphConnection> conn; if (thisEp.isValid() and _lastClickSelectEp.isValid() and not (thisEp == _lastClickSelectEp) and //end points valid (_lastClickSelectEp.getConnectableAttrs().direction == GRAPH_CONN_OUTPUT or _lastClickSelectEp.getConnectableAttrs().direction == GRAPH_CONN_SIGNAL) and //last endpoint is output (thisEp.getConnectableAttrs().direction == GRAPH_CONN_INPUT or thisEp.getConnectableAttrs().direction == GRAPH_CONN_SLOT)) //this click endpoint is input { try { conn = this->getGraphEditor()->makeConnection(thisEp, _lastClickSelectEp); this->getGraphEditor()->handleStateChange(GraphState("connect-arrow", tr("Connect %1[%2] to %3[%4]").arg( conn->getOutputEndpoint().getObj()->getId(), conn->getOutputEndpoint().getKey().id, conn->getInputEndpoint().getObj()->getId(), conn->getInputEndpoint().getKey().id ))); } catch (const Pothos::Exception &ex) { poco_warning(Poco::Logger::get("PothosGui.GraphDraw.connect"), Poco::format("Cannot connect port %s[%s] to port %s[%s]: %s", _lastClickSelectEp.getObj()->getId().toStdString(), _lastClickSelectEp.getKey().id.toStdString(), thisEp.getObj()->getId().toStdString(), thisEp.getKey().id.toStdString(), ex.message())); } } //cleanup after new connection if (not conn.isNull()) { _lastClickSelectEp = GraphConnectionEndpoint(); this->deselectAllObjs(); } //otherwise save the click select else { _lastClickSelectEp = thisEp; } } }
bool RichTextLabel::mouseEvent(QEvent *e) { Qt::MouseButtons button; QPointF pos; if (QGraphicsSceneMouseEvent *event = dynamic_cast<QGraphicsSceneMouseEvent*>(e)) { button = event->button(); pos = mapFromParent(event->pos()); } else if (QGraphicsSceneWheelEvent *event = dynamic_cast<QGraphicsSceneWheelEvent*>(e)) { button = event->buttons(); pos = mapFromParent(event->pos()); } QString link = text->documentLayout()->anchorAt(pos); if (link[0] != '#') { if (button == Qt::LeftButton) KRun::runCommand(link,0L); return false; } else return true; }
bool GameItem::isShadow(QPointF const position) const { // Get the realated point. QPointF mappedPosition = mapFromParent(position); int newPosX = mappedPosition.x() + getShadowDeltaX(); int newPosY = mappedPosition.y() + getShadowDeltaY(); if ((newPosX < 0 || newPosX > m_selPix->width()) || (newPosY < 0 || newPosY > m_selPix->height())) { return true; } return false; }
void BackdropGui::resizeExtraContent(int /*w*/, int /*h*/, bool forceResize) { QPointF p = pos(); QPointF thisItemPos = mapFromParent(p); int nameHeight = getFrameNameHeight(); _imp->label->setPos( thisItemPos.x(), thisItemPos.y() + nameHeight + TO_DPIY(10) ); if (!forceResize) { _imp->label->adjustSize(); } }
void Callout::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* w) { Q_UNUSED(option); Q_UNUSED(w); QPainterPath path; path.addRoundedRect(rect, 5, 5); auto anchor = mapFromParent(chart->mapToPosition(this->anchor)); if (!rect.contains(anchor)) { QPointF point1, point2; // establish the position of the anchor point in relation to rect auto above = anchor.y() <= rect.top(); auto aboveCenter = anchor.y() > rect.top() && anchor.y() <= rect.center().y(); auto belowCenter = anchor.y() > rect.center().y() && anchor.y() <= rect.bottom(); auto below = anchor.y() > rect.bottom(); auto onLeft = anchor.x() <= rect.left(); auto leftOfCenter = anchor.x() > rect.left() && anchor.x() <= rect.center().x(); auto rightOfCenter = anchor.x() > rect.center().x() && anchor.x() <= rect.right(); auto onRight = anchor.x() > rect.right(); // get the nearest rect corner. auto x = (onRight + rightOfCenter) * rect.width(); auto y = (below + belowCenter) * rect.height(); auto cornerCase = (above && onLeft) || (above && onRight) || (below && onLeft) || (below && onRight); auto vertical = qAbs(anchor.x() - x) > qAbs(anchor.y() - y); auto x1 = x + leftOfCenter * 10 - rightOfCenter * 20 + cornerCase * !vertical * (onLeft * 10 - onRight * 20); auto y1 = y + aboveCenter * 10 - belowCenter * 20 + cornerCase * vertical * (above * 10 - below * 20);; point1.setX(x1); point1.setY(y1); auto x2 = x + leftOfCenter * 20 - rightOfCenter * 10 + cornerCase * !vertical * (onLeft * 20 - onRight * 10);; auto y2 = y + aboveCenter * 20 - belowCenter * 10 + cornerCase * vertical * (above * 20 - below * 10);; point2.setX(x2); point2.setY(y2); path.moveTo(point1); path.lineTo(anchor); path.lineTo(point2); path = path.simplified(); } painter->setBrush(QColor(255, 255, 255)); painter->drawPath(path); painter->drawText(textRect, text); }
void QFormulatorEditWidget::customEvent_MouseMoveOnParentWindow( QMouseEvent *e ) { if( e->buttons() & Qt::LeftButton ) { QPoint pos = e->pos(); mapFromParent( pos ); PointFde ptf( pos.x(), pos.y() ); RectFde rcf = clientRect(); CFmlDrawEngineQt::DPtoLPEx( ptf, scale(), scale() ); CFmlDrawEngineQt::DPtoLPEx( rcf, scale(), scale() ); if( rootNode()->MoveCaret( rcf, ptf, -1 ) == 0 ) updateFormulatorWidget(); } //mouseMoveEvent( e ); }
void GraphDraw::mouseMoveEvent(QMouseEvent *event) { QGraphicsView::mouseMoveEvent(event); //implement mouse tracking for blocks const auto scenePos = this->mapToScene(event->pos()); for (auto obj : this->getGraphObjects()) { obj->updateMouseTracking(obj->mapFromParent(scenePos)); } //handle drawing in the click, drag, connect mode const auto topObj = _lastClickSelectEp.getObj(); if (_connectLineItem and topObj) { const auto attrs = topObj->getConnectableAttrs(_lastClickSelectEp.getKey()); const auto newPos = topObj->mapFromParent(scenePos); _connectLineItem->setLine(QLineF(attrs.point, newPos)); } //handle the first move event transition from a press event if (_selectionState == SELECTION_STATE_PRESS) { _selectionState = SELECTION_STATE_MOVE; //record positions to determine movement on release _preMovePositions.clear(); for (auto obj : getObjectsSelected(~GRAPH_CONNECTION)) { _preMovePositions[obj] = obj->pos(); } } //cause full render when moving objects for clean animation if (_selectionState == SELECTION_STATE_MOVE) this->render(); //auto scroll near boundaries if (_selectionState != SELECTION_STATE_NONE) { handleAutoScroll(this->horizontalScrollBar(), this->size().width(), this->mapToScene(event->pos()).x()); handleAutoScroll(this->verticalScrollBar(), this->size().height(), this->mapToScene(event->pos()).y()); } }
void Mesa::mouseMoveEvent(QMouseEvent* event) { if (!g_bloqueo) { if (m_escalando > 0 && m_escalando < 9 ) { if (m_escalando == 1) { /// Abajo a la derecha if (isWindow()) { m_XScale += (event->globalPos().x() - m_offset.x()); m_YScale += (event->globalPos().y() - m_offset.y()); } else { m_XScale = event->pos().x(); m_YScale = event->pos().y(); } // end if } else if (m_escalando == 2) { /// Abajo en el centro. if (isWindow()) { m_YScale += (event->globalPos().y() - m_offset.y()); } else { m_YScale = event->pos().y(); } // end if } else if (m_escalando == 3) { /// A la derecha en el centro if (isWindow()) { m_XScale += (event->globalPos().x() - m_offset.x()); } else { m_XScale = event->pos().x(); } // end if } else if (m_escalando == 4) { /// Arriba a la izquierda if (isWindow()) { m_XScale -= (event->globalPos().x() - m_offset.x()); m_YScale -= (event->globalPos().y() - m_offset.y()); move(event->globalPos() - m_offset); } else { m_XScale -= (event->pos().x() - m_offset.x()); m_YScale -= (event->pos().y() - m_offset.y()); move(mapToParent(event->pos() - m_offset)); } // end if } else if (m_escalando == 5) { /// Arriba a la derecha if (isWindow()) { m_XScale += (event->globalPos().x() - m_offset.x()); m_YScale -= (event->globalPos().y() - m_offset.y()); QPoint rm_offset = event->globalPos() - m_offset; rm_offset.setX(x()); move(rm_offset); } else { m_XScale = event->pos().x(); m_YScale -= (event->pos().y() - m_offset.y()); QPoint rm_offset = event->pos() - m_offset; rm_offset.setX(mapFromParent(pos()).x()); move(mapToParent(rm_offset)); } // end if } else if (m_escalando == 6) { /// Abajo a la izquierda if (isWindow()) { m_XScale -= (event->globalPos().x() - m_offset.x()); m_YScale += (event->globalPos().y() - m_offset.y()); QPoint rm_offset = event->globalPos() - m_offset; rm_offset.setY(y()); move(rm_offset); } else { m_XScale -= (event->pos().x() - m_offset.x()); m_YScale = event->pos().y(); QPoint rm_offset = event->pos() - m_offset; rm_offset.setY(mapFromParent(pos()).y()); move(mapToParent(rm_offset)); } // end if } else if (m_escalando == 7) { /// Enmedio a la izquierda if (isWindow()) { m_XScale -= (event->globalPos().x() - m_offset.x()); QPoint rm_offset = event->globalPos() - m_offset; rm_offset.setY(y()); move(rm_offset); } else { m_XScale -= (event->pos().x() - m_offset.x()); QPoint rm_offset = event->pos() - m_offset; rm_offset.setY(mapFromParent(pos()).y()); move(mapToParent(rm_offset)); } // end if } else if (m_escalando == 8) { /// El cuadro de arriba en el centro if (isWindow()) { m_YScale -= (event->globalPos().y() - m_offset.y()); QPoint rm_offset = event->globalPos() - m_offset; rm_offset.setX(x()); move(rm_offset); } else { m_YScale -= (event->pos().y() - m_offset.y()); QPoint rm_offset = event->pos() - m_offset; rm_offset.setX(mapFromParent(pos()).x()); move(mapToParent(rm_offset)); } // end if } if (m_XScale > 20 && m_YScale > 20) setFixedSize(m_XScale+10 ,m_YScale+10); } else if (m_escalando == 9) { if (isWindow()) move(event->globalPos() - m_offset); else move(mapToParent(event->pos() - m_offset)); } // end if event->accept(); // do not propagate } // end if }
QGeneralSettingWidget::QGeneralSettingWidget(QT3kDevice*& pHandle, QWidget *parent) : QWidget(parent), m_pT3kHandle(pHandle) { setupUi(this); setFont( qApp->font() ); m_nInputModeV = 0x0000; m_nInputMode = 0; m_nTimerAutoInputMode = 0; m_nChkUsbCfgMode = -1; m_nDisplayOrientation = -1; m_bOSXGesture = false; ChkInputModeAutoSelect->setChecked( false ); TitleLanguage->SetIconImage( ":/T3kCfgRes/resources/PNG_ICON_LANGUAGE.png"); TitleInputMode->SetIconImage( ":/T3kCfgRes/resources/PNG_ICON_INPUT_MODE.png"); TitleDisplayOrientation->SetIconImage( ":/T3kCfgRes/resources/PNG_ICON_MULTI_MONITOR.png"); int nSelectLanguage = QLangManager::instance()->getActiveLanguage(); int nSelIdx = -1; int nPos = QLangManager::instance()->getFirstAvailableLanguage(); while( nPos >= 0 ) { QString strLangName = QLangManager::instance()->getLanguageName( nPos ); CBLLanguage->addItem( strLangName ); int nIdx = CBLLanguage->count()-1; CBLLanguage->setItemData( nIdx, nPos ); if( nPos == nSelectLanguage ) nSelIdx = nIdx; nPos = QLangManager::instance()->getNextAvailableLanguage(); } CBLLanguage->setCurrentIndex( nSelIdx ); // usbconfigmode // TitleDisplayOrientation->setVisible( false ); // GBOrientation->setVisible( false ); // RBtnLandscape->setVisible( false ); // RBtnPortrait->setVisible( false ); // RBtnLandscapeF->setVisible( false ); // RBtnPortraitF->setVisible( false ); onChangeLanguage(); QRect rcL( CBLLanguage->x(), CBLLanguage->y(), CBLLanguage->width()-1, CBLLanguage->height() ); rcL.setTopLeft( mapFromParent( rcL.topLeft() ) ); LBLanguageMsg->setGeometry( rcL.left()-rcL.width()/2, rcL.top()+rcL.height()/2, rcL.width()*2, rcL.height() ); CBLLanguage->setVisible( false ); TitleTrayIcon->SetIconImage( ":/T3kCfgRes/resources/PNG_ICON_TRAYICON.png" ); QString strPath = QCoreApplication::applicationDirPath(); if( strPath.at( strPath.size()-1 ) == '/' ) strPath.remove( strPath.size()-1, 1 ); QSettings RegOption( "Habilience", "T3kCfg" ); RegOption.beginGroup( "Options" ); if( RegOption.value( "Exec Path", "" ).toString().compare( strPath ) ) { RegOption.setValue( "TrayIcon", false ); RegOption.setValue( "Exec Path", strPath ); } chkTrayIcon->setChecked( RegOption.value( "TrayIcon", false ).toBool() ); RegOption.endGroup(); if( QLangManager::instance()->getAvailableLanguageCount() <= 1 ) { CBLLanguage->hide(); LBLanguageMsg->show(); LanguageLayout->removeWidget( CBLLanguage ); LanguageLayout->addWidget( LBLanguageMsg ); } else { CBLLanguage->show(); LBLanguageMsg->hide(); } chkOSXGesture->setVisible( false ); }
QPoint GetLocal(QPoint Window) { Window = mapFromParent(Window); Window = mapToScene(Window).toPoint(); return Window; };
void CornerHandler::doSetRect(const QRectF &newRect) { setFlag(QGraphicsItem::ItemIgnoresTransformations,false); setRect(mapFromParent(newRect).boundingRect()); }