void Bracket::draw(QPainter* painter) const { if (subtype() == BRACKET_AKKOLADE) { painter->setPen(Qt::NoPen); painter->setBrush(QBrush(curColor())); painter->drawPath(path); } else if (subtype() == BRACKET_NORMAL) { qreal h = 2 * h2 + yoff; qreal _spatium = spatium(); qreal w = score()->styleS(ST_bracketWidth).val() * _spatium; QPen pen(curColor(), w, Qt::SolidLine, Qt::FlatCap); painter->setPen(pen); qreal bd = _spatium * .25; painter->drawLine(QLineF(0.0, -bd, 0.0, h + bd)); int idx = score()->symIdx(); qreal mags = 1.0; qreal x = -w * .5; qreal y1 = -bd; qreal y2 = h + bd; symbols[idx][brackettipsRightUp].draw(painter, mags, QPointF(x, y1)); symbols[idx][brackettipsRightDown].draw(painter, mags, QPointF(x, y2)); } }
void ItemCircleAnimation::setupGuides() { int x = 0; int y = 20; this->qtGuide1 = new GuideCircle(QRectF(x, y, 260, 260), -36, 342); this->currGuide = 0; new GuideLine(QPointF(x + 240, y + 268), this->qtGuide1); new GuideLine(QPointF(x + 265, y + 246), this->qtGuide1); new GuideLine(QPointF(x + 158, y + 134), this->qtGuide1); new GuideLine(QPointF(x + 184, y + 109), this->qtGuide1); new GuideLine(QPointF(x + 160, y + 82), this->qtGuide1); new GuideLine(QPointF(x + 77, y + 163), this->qtGuide1); // T-top new GuideLine(QPointF(x + 100, y + 190), this->qtGuide1); new GuideLine(QPointF(x + 132, y + 159), this->qtGuide1); new GuideLine(QPointF(x + 188, y + 211), this->qtGuide1); new GuideCircle(QRectF(x + 30, y + 30, 200, 200), -30, 336, GuideCircle::CW, this->qtGuide1); new GuideLine(QPointF(x + 238, y + 201), this->qtGuide1); y = 30; this->qtGuide2 = new GuideCircle(QRectF(x + 30, y + 30, 200, 200), 135, 270, GuideCircle::CCW); new GuideLine(QPointF(x + 222, y + 38), this->qtGuide2); new GuideCircle(QRectF(x, y, 260, 260), 135, 270, GuideCircle::CW, this->qtGuide2); new GuideLine(QPointF(x + 59, y + 59), this->qtGuide2); x = 115; y = 10; this->qtGuide3 = new GuideLine(QLineF(x, y, x + 30, y)); new GuideLine(QPointF(x + 30, y + 170), this->qtGuide3); new GuideLine(QPointF(x, y + 170), this->qtGuide3); new GuideLine(QPointF(x, y), this->qtGuide3); this->qtGuide1->setFence(QRectF(0, 0, 800, 600)); this->qtGuide2->setFence(QRectF(0, 0, 800, 600)); this->qtGuide3->setFence(QRectF(0, 0, 800, 600)); }
VLCStatsView::VLCStatsView( QWidget *parent ) : QGraphicsView( parent ) { QColor history(0, 0, 0, 255), total(237, 109, 0, 160), content(109, 237, 0, 160); scale( 1.0, -1.0 ); /* invert our Y axis */ setOptimizationFlags( QGraphicsView::DontAdjustForAntialiasing ); setAlignment( Qt::AlignLeft ); setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); viewScene = new QGraphicsScene( this ); historyShape = viewScene->addPolygon( QPolygonF(), QPen(Qt::NoPen), QBrush(history) ); totalbitrateShape = viewScene->addPolygon( QPolygonF(), QPen(Qt::NoPen), QBrush(total) ); setScene( viewScene ); reset(); QPen linepen( Qt::DotLine ); linepen.setBrush( QBrush( QColor( 33, 33, 33 ) ) ); for ( int i=0; i<3; i++ ) rulers[i] = viewScene->addLine( QLineF(), linepen ); }
double CanvasMode_EditSpiral::computeRealAngle(double angle, bool fromDia) { PageItem *currItem = m_doc->m_Selection->itemAt(0); double ret = angle; int rev = static_cast<int>(angle / 360.0); double part = angle - (rev * 360); QTransform bb; bb.scale(currItem->width() / currItem->height(), 1.0); QLineF inp = QLineF(QPointF(currItem->width() / 2.0, currItem->height() / 2.0), QPointF(currItem->width(), currItem->height() / 2.0)); inp.setAngle(part); if (fromDia) { QLineF res = bb.map(inp); ret = res.angle(); } else { QTransform bt = bb.inverted(); QLineF res = bt.map(inp); ret = res.angle(); } ret += rev * 360; return ret; }
// ============================================================================ /// Renders void ControlSurface::render(QPainter& painter, const QRectF&, const RenderingOptions& ) { painter.save(); painter.setTransform( body()->transform(), true ); painter.setPen( Qt::black ); double angle = ( _value*_step + _inclination ) *parent()->orientation(); double wx = cos( angle ) * _width/2; double wy = sin( angle ) * _width/2; painter.drawLine( QLineF( _position.x()-wx, _position.y()-wy, _position.x()+wx, _position.y()+wy ) ); painter.restore(); // draw force (DEBUG ) /* double fs = 500 ; // force scale QPointF wf = aerodynamicForce() / fs; const b2Vec2& pos = body()->b2body()->GetWorldPoint( point2vec( _position ) ); painter.setPen( Qt::green ); painter.drawLine( QLineF( pos.x, pos.y, pos.x + wf.x(), pos.y + wf.y() ) ); */ }
void KiviatView::redrawAll() { //Delete markers and axes,keep the captions qDeleteAll(markers); qDeleteAll(axes); markers.clear(); axes.clear(); setupAxesCaptions(); //Paint Axes and adjust label position for(int i=0; i<axisCount; i++) { //Draw the axis-line QGraphicsLineItem * line= scene.addLine(QLineF(QPointF(0,0),calcPosition(i,1))); line->setZValue(1); axes.push_back(line); // Why Position 1.08? Pos 1.0 means end of axis // label is positioned a litte bit further away from center // also needed in setAxisLabel QPointF lPos = calcPosition(i, 1.08); axisLabels[i]->setPos(QPoint(0,0)); axisLabels[i]->moveBy(lPos.x(),lPos.y()); // If the axis is on the left side, the text has to be moved to the left if( axisLabels[i]->pos().x()<0 ) axisLabels[i]->moveBy(- axisLabels[i]->boundingRect().width(),0); } //Call setMarkerCount with current count, to paint them setMarkerCount(prop_markerCount); redrawData(); }
void LineItem::creationPolygonChanged(View::CreationEvent event) { if (event == View::EscapeEvent) { ViewItem::creationPolygonChanged(event); return; } if (event == View::MousePress) { const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MousePress)); setPos(poly.first().x(), poly.first().y()); setViewRect(QRectF(0.0, -sizeOfGrip().height()*0.5, 0.0, sizeOfGrip().height())); view()->scene()->addItem(this); return; } if (event == View::MouseMove) { const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseMove)); if (!rect().isEmpty()) { rotateTowards(line().p2(), poly.last()); } QRectF r = rect(); r.setSize(QSizeF(QLineF(line().p1(), poly.last()).length(), r.height())); setViewRect(r); return; } if (event == View::MouseRelease) { const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseRelease)); view()->disconnect(this, SLOT(deleteLater())); //Don't delete ourself view()->disconnect(this, SLOT(creationPolygonChanged(View::CreationEvent))); view()->setMouseMode(View::Default); updateViewItemParent(); _created = true; emit creationComplete(); return; } }
QPointF SCgNode::cross(const QPointF &from, float dot) const { QPointF p(0.f, 0.f); if (!mContentVisible) { QVector2D vec(from - scenePos()); p = vec.normalized().toPointF() * (mSize.width() / 2.f + 5.f); }else { // count intersection with content border QPolygonF polygon(boundingRect()); QPointF p1 = polygon.last(); QPointF p2, intersectPoint; QLineF line, pair(p, mapFromScene(from)); bool haveItersect = false; for (int i = 0; i < polygon.size(); i++) { p2 = polygon.at(i); line = QLineF(p1, p2); QLineF::IntersectType intersectType = line.intersect(pair, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) { haveItersect = true; break; } p1 = p2; } p = haveItersect ? intersectPoint : p; } return mapToScene(p); }
void ArcItem::updateArrowPath(){ QPainterPath path; if((_endItem && _startItem->primaryShape().intersects(_endItem->primaryShape())) || (!_endItem && _startItem->primaryShape().contains(_end))){ _cachedArrowPath = path; return; } QPointF start(0,0), point = _end - pos(); //The arrow line and reverse liune QLineF revline(point, start); //Compute various points QLineF s = revline.normalVector(); s.setAngle(revline.angle() - 45); s.setLength(ARROW_SIZE); QPointF side1 = s.p2(); s = revline.normalVector(); s.setAngle(revline.angle() + 45); s.setLength(ARROW_SIZE); QPointF side2 = s.p2(); s = QLineF(side1, side2); QPointF head = point; s.intersect(revline, &head); path.moveTo(start); path.lineTo(head); path.lineTo(side1); path.lineTo(point); path.lineTo(side2); path.lineTo(head); _cachedArrowPath = path; }
/** * @brief ... Draw vertical and horizontal axis on the frame. Marks are placed at step intervals in world reference frame * * @param c ... line color * @param w ... line width * @param step ...separation among axis marks * @return void **/ void RCDraw::drawAxis ( const QColor &c, int w, float step ) { drawLine ( QLineF ( effWin.left(), effWin.center().y(), effWin.right(), effWin.center().y()), w ); for ( float i=effWin.center().x() ; i< effWin.right(); i+=step ) { drawLine ( QLineF ( i, effWin.center().y()-step, i , effWin.center().y()+step), c, w ); } for ( float i=effWin.center().x() ; i> effWin.left(); i-=step ) { drawLine ( QLineF ( i, effWin.center().y()-step, i , effWin.center().y()+step), c, w ); } drawLine ( QLineF ( effWin.center().x(), effWin.top(), effWin.center().x(), effWin.bottom()), w ); for ( float i=effWin.center().y() ; i< effWin.bottom(); i+=step ) { drawLine ( QLineF ( effWin.center().x()-step, i, effWin.center().x()+step, i), c, w ); } for ( float i=effWin.center().y() ; i> effWin.top(); i-=step ) { drawLine ( QLineF ( effWin.center().x()-step, i, effWin.center().y()+step, i), c, w ); } drawText(QPointF(effWin.center().x()+1, effWin.top()), "0.5 m", effWin.width()/20, Qt::black); }
DataWidget::DataWidget(QWidget *parent) : QWidget(parent), ui(new Ui::DataWidget) { ui->setupUi(this); ui->graphicsView->setScene(&scene_1); ui->graphicsView_2->setScene(&scene_2); ui->graphicsView_3->setScene(&scene_3); QPen pen; pen.setColor(Qt::white); pen.setWidth(2); scene_1.addRect(QRect(0,0,185,20),pen, QBrush(Qt::NoBrush)); scene_1.addRect(QRect(0,40,185,20),pen, QBrush(Qt::NoBrush)); scene_1.addRect(QRect(0,80,185,20),pen, QBrush(Qt::NoBrush)); scene_2.addRect(QRect(0,0,185,20),pen, QBrush(Qt::NoBrush)); scene_2.addRect(QRect(0,40,185,20),pen, QBrush(Qt::NoBrush)); scene_2.addRect(QRect(0,80,185,20),pen, QBrush(Qt::NoBrush)); line1 = scene_1.addLine(QLineF(0.5*185,0,0.5*185,20),pen); line2 = scene_1.addLine(QLineF(0.5*185,40,0.5*185,60),pen); line3 = scene_1.addLine(QLineF(0.5*185,80,0.5*185,100),pen); line4 = scene_2.addLine(QLineF(0.5*185,0,0.5*185,20),pen); line5 = scene_2.addLine(QLineF(0.5*185,40,0.5*185,60),pen); line6 = scene_2.addLine(QLineF(0.5*185,80,0.5*185,100),pen); circle1 = scene_3.addEllipse(QRect(0,0,30,30),pen); circle2 = scene_3.addEllipse(QRect(0,35,30,30),pen); circle3 = scene_3.addEllipse(QRect(0,70,30,30),pen); changeLabelsColor(); drawData(); }
QLineF bottomLine(const QmlItemNode &qmlItemNode) { QRectF rectangle = qmlItemNode.instanceSceneTransform().mapRect(qmlItemNode.instanceBoundingRect()).adjusted(1, 0, 0, 0); return QLineF(rectangle.bottomLeft(), rectangle.bottomRight()); }
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill) { if (w == 0 || h == 0) return; if (!(w > 0 && h > 0 && lineWidth >= 0)) { qWarning("qDrawShadePanel: Invalid parameters"); } QColor shade = pal.dark().color(); QColor light = pal.light().color(); if (fill) { if (fill->color() == shade) shade = pal.shadow().color(); if (fill->color() == light) light = pal.midlight().color(); } QPen oldPen = p->pen(); // save pen QVector<QLineF> lines; lines.reserve(2*lineWidth); if (sunken) p->setPen(shade); else p->setPen(light); int x1, y1, x2, y2; int i; x1 = x; y1 = y2 = y; x2 = x+w-2; for (i=0; i<lineWidth; i++) { // top shadow lines << QLineF(x1, y1++, x2--, y2++); } x2 = x1; y1 = y+h-2; for (i=0; i<lineWidth; i++) { // left shado lines << QLineF(x1++, y1, x2++, y2--); } p->drawLines(lines); lines.clear(); if (sunken) p->setPen(light); else p->setPen(shade); x1 = x; y1 = y2 = y+h-1; x2 = x+w-1; for (i=0; i<lineWidth; i++) { // bottom shadow lines << QLineF(x1++, y1--, x2, y2--); } x1 = x2; y1 = y; y2 = y+h-lineWidth-1; for (i=0; i<lineWidth; i++) { // right shadow lines << QLineF(x1--, y1++, x2--, y2); } p->drawLines(lines); if (fill) // fill with fill color p->fillRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, *fill); p->setPen(oldPen); // restore pen }
void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill) { if (w == 0 || h == 0) return; if (! (w > 0 && h > 0 && lineWidth >= 0 && midLineWidth >= 0)) { qWarning("qDrawShadeRect: Invalid parameters"); return; } QPen oldPen = p->pen(); if (sunken) p->setPen(pal.dark().color()); else p->setPen(pal.light().color()); int x1=x, y1=y, x2=x+w-1, y2=y+h-1; if (lineWidth == 1 && midLineWidth == 0) {// standard shade rectangle p->drawRect(x1, y1, w-2, h-2); if (sunken) p->setPen(pal.light().color()); else p->setPen(pal.dark().color()); QLineF lines[4] = { QLineF(x1+1, y1+1, x2-2, y1+1), QLineF(x1+1, y1+2, x1+1, y2-2), QLineF(x1, y2, x2, y2), QLineF(x2,y1, x2,y2-1) }; p->drawLines(lines, 4); // draw bottom/right lines } else { // more complicated int m = lineWidth+midLineWidth; int i, j=0, k=m; for (i=0; i<lineWidth; i++) { // draw top shadow QLineF lines[4] = { QLineF(x1+i, y2-i, x1+i, y1+i), QLineF(x1+i, y1+i, x2-i, y1+i), QLineF(x1+k, y2-k, x2-k, y2-k), QLineF(x2-k, y2-k, x2-k, y1+k) }; p->drawLines(lines, 4); k++; } p->setPen(pal.mid().color()); j = lineWidth*2; for (i=0; i<midLineWidth; i++) { // draw lines in the middle p->drawRect(x1+lineWidth+i, y1+lineWidth+i, w-j-1, h-j-1); j += 2; } if (sunken) p->setPen(pal.light().color()); else p->setPen(pal.dark().color()); k = m; for (i=0; i<lineWidth; i++) { // draw bottom shadow QLineF lines[4] = { QLineF(x1+1+i, y2-i, x2-i, y2-i), QLineF(x2-i, y2-i, x2-i, y1+i+1), QLineF(x1+k, y2-k, x1+k, y1+k), QLineF(x1+k, y1+k, x2-k, y1+k) }; p->drawLines(lines, 4); k++; } } if (fill) { QBrush oldBrush = p->brush(); int tlw = lineWidth + midLineWidth; p->setPen(Qt::NoPen); p->setBrush(*fill); p->drawRect(x+tlw, y+tlw, w-2*tlw, h-2*tlw); p->setBrush(oldBrush); } p->setPen(oldPen); // restore pen }
void QcWaveform::paintEvent( QPaintEvent *ev ) { Q_ASSERT( pixmap != 0 ); QPainter p( this ); // if loading draw progress if( _cache && _cache->loading() ) { QRect r( rect() ); p.fillRect( r, QColor(100,100,100) ); r.setRight( r.right() * _cache->loadProgress() / 100 ); p.fillRect( r, QColor( 0, 0, 0 ) ); p.setPen( QColor(255,255,255) ); QTextOption opt; opt.setAlignment( Qt::AlignCenter ); p.drawText( rect(), "loading...", opt ); return; } p.fillRect( rect(), _bkgColor ); // draw waveform on pixmap if( _drawWaveform && dirty ) { draw( pixmap, 0, width(), _beg, _dur ); dirty = false; } // draw selections p.save(); p.scale( (double) width() / _dur, 1.0 ); p.translate( _beg * -1.0, 0.0 ); p.setPen( Qt::NoPen ); int i; for( i = 0; i < 64; ++i ) { const Selection &s = _selections[i]; if( s.size > 0 ) { QRectF r ( s.start, 0, s.size, height() ); p.setBrush( s.color ); p.drawRect( r ); } } p.restore(); // draw time grid if( _showGrid && sfInfo.samplerate > 0 && _gridResolution > 0.f ) { p.save(); double durSecs = (double) _dur / sfInfo.samplerate; double begSecs = (double) _beg / sfInfo.samplerate; p.scale( width() / durSecs, 1.0 ); p.setPen( _gridColor ); double offset = _gridOffset - begSecs; offset -= ( floor( offset / _gridResolution ) * _gridResolution ); while( offset < durSecs ) { p.drawLine( QLineF( offset, 0.0, offset, height() ) ); offset += _gridResolution; } p.restore(); } // paste the waveform pixmap on screen if( _drawWaveform ) p.drawPixmap( ev->rect(), *pixmap, ev->rect() ); // draw cursor if( _showCursor && _cursorPos >= _beg && _cursorPos < _beg + _dur ) { double cursorX = (_cursorPos - _beg) / _fpp; p.setPen( _cursorColor ); p.drawLine( QLineF( cursorX, 0, cursorX, height() ) ); } }
QLineF Articulation::dragAnchor() const { return QLineF(canvasPos(), parent()->canvasPos()); }
void SelectionItem::updateDeltaLines() { qreal x1, x2; x1 = this->leftSelected->x(); x2 = this->rightSelected->sceneBoundingRect().bottomRight().x(); // Text label for the delta between the left selected and the earlier item if (this->before) { if (textBefore == NULL && lineBefore == NULL) { // Create the elements textBefore = new QGraphicsTextItem(this); textBefore->setPlainText(QString::number(this->leftSelected->x() - this->before->pos().x())); textBefore->setPos(this->mapFromScene(x1 - textBefore->sceneBoundingRect().width(), 30.0)); lineBefore = new QGraphicsLineItem(this); //qDebug() << "new lineBefore "<<this->leftSelected->x()<<this->before->pos().x(); lineBefore->setLine(QLineF(this->mapFromScene(this->leftSelected->x(), 30.0), this->mapFromScene(this->before->pos().x(), 30.0))); } else { // Update the line and text label qreal d = this->leftSelected->x() - this->before->pos().x(); //if (d < 0) { // We have crossed one item, update the atfer and before item TimelineScene *timeline = qobject_cast<TimelineScene *>(this->leftSelected->scene()); this->before = timeline->getTriggerItemBefore(this->leftSelected); this->after = timeline->getTriggerItemAfter(this->rightSelected); if (this->before) { // Update the before line d = this->leftSelected->x() - this->before->pos().x(); QLineF line = this->lineBefore->line(); QPointF p2 = line.p2(); p2.setX(this->mapFromScene(this->before->pos()).x()); line.setP2(p2); line.setLength(d); this->lineBefore->setLine(line); textBefore->setPlainText(QString::number(d)); } else { // No more before item, remove everything qDebug() << "Remove before item"; timeline->removeItem(this->lineBefore); delete this->lineBefore; this->lineBefore = NULL; timeline->removeItem(this->textBefore); delete this->textBefore; this->textBefore = NULL; } // the after line will be handled in the next part of this method /*} else { textBefore->setPlainText(QString::number(d)); QLineF line = this->lineBefore->line(); line.setLength(d); this->lineBefore->setLine(line); }*/ } } // Text label for the delta between the right selected and the later item if (this->after) { if (textAfter == NULL && lineAfter == NULL) { // Create textAfter = new QGraphicsTextItem(this); textAfter->setPlainText(QString::number(this->after->pos().x() - this->rightSelected->x())); textAfter->setPos(this->mapFromScene(x2, 40.0)); lineAfter = new QGraphicsLineItem(this); lineAfter->setLine(QLineF(this->mapFromScene(this->rightSelected->x(), 40.0), this->mapFromScene(this->after->pos().x(), 40.0))); qDebug() << "Create lineAfter" << QLineF(this->mapFromScene(this->rightSelected->x(), 40.0), this->mapFromScene(this->after->pos().x(), 40.0)); } else { // Update qreal d = this->after->pos().x() - this->rightSelected->x(); //if (d < 0) { // We have crossed one item, update the atfer and before item TimelineScene *timeline = qobject_cast<TimelineScene *>(this->leftSelected->scene()); this->before = timeline->getTriggerItemBefore(this->leftSelected); this->after = timeline->getTriggerItemAfter(this->rightSelected); if (this->after) { // Update the after line d = this->after->pos().x() - this->rightSelected->x(); QLineF line = this->lineAfter->line(); QPointF p2 = line.p2(); p2.setX(this->mapFromScene(this->after->pos()).x()); line.setP2(p2); line.setLength(d); this->lineAfter->setLine(line); textAfter->setPlainText(QString::number(d)); qDebug() << "Update lineAfter" << line; } else { // No more after item, remove everything qDebug() << "Remove after item"; timeline->removeItem(this->lineAfter); delete this->lineAfter; this->lineAfter = NULL; timeline->removeItem(this->textAfter); delete this->textAfter; this->textAfter = NULL; } /*} else { textAfter->setPlainText(QString::number(d)); QLineF line = this->lineAfter->line(); line.setLength(d); this->lineAfter->setLine(line); }*/ } } }
bool HoverPoints::eventFilter(QObject *object, QEvent *event) { if (object == m_widget && m_enabled) { switch (event->type()) { case QEvent::MouseButtonPress: { if (!m_fingerPointMapping.isEmpty()) return true; QMouseEvent *me = (QMouseEvent *) event; QPointF clickPos = me->pos(); int index = -1; for (int i=0; i<m_points.size(); ++i) { QPainterPath path; if (m_shape == CircleShape) path.addEllipse(pointBoundingRect(i)); else path.addRect(pointBoundingRect(i)); if (path.contains(clickPos)) { index = i; break; } } if (me->button() == Qt::LeftButton) { if (index == -1) { if (!m_editable) return false; int pos = 0; // Insert sort for x or y if (m_sortType == XSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).x() > clickPos.x()) { pos = i; break; } } else if (m_sortType == YSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).y() > clickPos.y()) { pos = i; break; } } m_points.insert(pos, clickPos); m_locks.insert(pos, 0); m_currentIndex = pos; firePointChange(); } else { m_currentIndex = index; } return true; } else if (me->button() == Qt::RightButton) { if (index >= 0 && m_editable) { if ((m_points.size() - 1) < m_minCountPoints) return true; if (m_locks[index] == 0) { m_locks.remove(index); m_points.remove(index); } firePointChange(); return true; } } } break; case QEvent::MouseButtonRelease: if (!m_fingerPointMapping.isEmpty()) return true; m_currentIndex = -1; break; case QEvent::MouseMove: if (!m_fingerPointMapping.isEmpty()) return true; if (m_currentIndex >= 0) movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); break; case QEvent::TouchBegin: case QEvent::TouchUpdate: { const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event); const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height()); Q_FOREACH (const QTouchEvent::TouchPoint &touchPoint, points) { const int id = touchPoint.id(); switch (touchPoint.state()) { case Qt::TouchPointPressed: { // find the point, move it QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values()); int activePoint = -1; qreal distance = -1; const int pointsCount = m_points.size(); const int activePointCount = activePoints.size(); if (pointsCount == 2 && activePointCount == 1) { // only two points activePoint = activePoints.contains(0) ? 1 : 0; } else { for (int i=0; i<pointsCount; ++i) { if (activePoints.contains(i)) continue; qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length(); if ((distance < 0 && d < 12 * pointSize) || d < distance) { distance = d; activePoint = i; } } } if (activePoint != -1) { m_fingerPointMapping.insert(touchPoint.id(), activePoint); movePoint(activePoint, touchPoint.pos()); } } break; case Qt::TouchPointReleased: { // move the point and release QHash<int,int>::iterator it = m_fingerPointMapping.find(id); movePoint(it.value(), touchPoint.pos()); m_fingerPointMapping.erase(it); } break; case Qt::TouchPointMoved: { // move the point const int pointIdx = m_fingerPointMapping.value(id, -1); if (pointIdx >= 0) // do we track this point? movePoint(pointIdx, touchPoint.pos()); } break; default: break; } } if (m_fingerPointMapping.isEmpty()) { event->ignore(); return false; } else { return true; } } break; case QEvent::TouchEnd: if (m_fingerPointMapping.isEmpty()) { event->ignore(); return false; } return true; break; case QEvent::Resize: { QResizeEvent *e = (QResizeEvent *) event; if (e->oldSize().width() == 0 || e->oldSize().height() == 0) break; qreal stretch_x = e->size().width() / qreal(e->oldSize().width()); qreal stretch_y = e->size().height() / qreal(e->oldSize().height()); for (int i=0; i<m_points.size(); ++i) { QPointF p = m_points[i]; movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false); } firePointChange(); break; } case QEvent::Paint: { QWidget *that_widget = m_widget; m_widget = 0; QApplication::sendEvent(object, event); m_widget = that_widget; paintPoints(); return true; } default: break; } } return false; }
void EdgeItem::setToPoint( int x, int y ) { setLine(QLineF( line().p1().x(), line().p1().y(), x, y )); }
QLineF Line::line() const { return QLineF(mX1, mY1, mX2, mY2); }
void EdgeItem::setFromPoint( int x, int y ) { setLine(QLineF( x,y, line().p2().x(), line().p2().y() )); }
void SmudgeTool::drawStroke() { if ( !m_pScribbleArea->isLayerPaintable() ) return; Layer *layer = m_pEditor->getCurrentLayer(); if (layer == NULL) { return; } BitmapImage *targetImage = ((LayerBitmap *)layer)->getLastBitmapImageAtFrame(m_pEditor->m_nCurrentFrameIndex, 0); StrokeTool::drawStroke(); QList<QPointF> p = m_pStrokeManager->interpolateStroke(currentWidth); for (int i = 0; i < p.size(); i++) { p[i] = m_pScribbleArea->pixelToPoint(p[i]); } qreal opacity = 1.0; qreal brushWidth = currentWidth + 0.0 * properties.feather; qreal offset = qMax(0.0, currentWidth - 0.5 * properties.feather) / brushWidth; //opacity = currentPressure; // todo: Probably not interesting?! //brushWidth = brushWidth * opacity; BlitRect rect; QPointF a = lastBrushPoint; QPointF b = getCurrentPoint(); if (toolMode == 0) // default mode = blur smudge { qreal brushStep = 0.5 * ( currentWidth + properties.feather ) / 40.0; qreal distance = QLineF(b, a).length()*2; brushStep = qMax( 1.0, brushStep * opacity ); //brushStep = 2.0; //currentWidth = properties.width; // here ? int steps = qRound(distance / brushStep); int rad = qRound(brushWidth / 2.0) + 2; QPointF sourcePoint = lastBrushPoint; for (int i = 0; i < steps; i++) { QPointF targetPoint = lastBrushPoint + (i + 1) * (brushStep) * (b - lastBrushPoint) / distance; rect.extend(targetPoint.toPoint()); m_pScribbleArea->blurBrush( targetImage, sourcePoint, targetPoint, brushWidth, offset, opacity); if (i == (steps - 1)) { lastBrushPoint = targetPoint; } sourcePoint = targetPoint; m_pScribbleArea->refreshBitmap(rect, rad); m_pScribbleArea->paintBitmapBuffer(); } } else // hard smudge (liquify) { qreal brushStep = 0.5 * ( currentWidth + properties.feather ) / 80.0; qreal distance = QLineF(b, a).length()/4.0; brushStep = qMax( 1.0, brushStep * opacity ); //currentWidth = properties.width; // here ? int steps = qRound(distance / brushStep); int rad = qRound(brushWidth / 2.0) + 2; QPointF sourcePoint = lastBrushPoint; for (int i = 0; i < steps; i++) { QPointF targetPoint = lastBrushPoint + (i + 1) * (brushStep) * (b - lastBrushPoint) / distance; rect.extend(targetPoint.toPoint()); m_pScribbleArea->liquifyBrush( targetImage, sourcePoint, targetPoint, brushWidth, offset, opacity); if (i == (steps - 1)) { lastBrushPoint = targetPoint; } sourcePoint = targetPoint; m_pScribbleArea->refreshBitmap(rect, rad); m_pScribbleArea->paintBitmapBuffer(); } } }
void BrushTool::drawStroke() { StrokeTool::drawStroke(); QList<QPointF> p = m_pStrokeManager->interpolateStroke(); Layer* layer = mEditor->layers()->currentLayer(); if ( layer->type() == Layer::BITMAP ) { for ( int i = 0; i < p.size(); i++ ) { p[ i ] = mEditor->view()->mapScreenToCanvas( p[ i ] ); } qreal opacity = 1.0f; if (properties.pressure == true) { opacity = mCurrentPressure / 2; } mCurrentWidth = properties.width; qreal brushWidth = mCurrentWidth; qreal brushStep = (0.5 * brushWidth) - ((properties.feather/100.0) * brushWidth * 0.5); brushStep = qMax( 1.0, brushStep ); BlitRect rect; QPointF a = mLastBrushPoint; QPointF b = getCurrentPoint(); qreal distance = 4 * QLineF( b, a ).length(); int steps = qRound( distance ) / brushStep; for ( int i = 0; i < steps; i++ ) { QPointF point = mLastBrushPoint + ( i + 1 ) * ( brushStep )* ( b - mLastBrushPoint ) / distance; rect.extend( point.toPoint() ); mScribbleArea->drawBrush( point, brushWidth, properties.feather, mEditor->color()->frontColor(), opacity, properties.useFeather ); if ( i == ( steps - 1 ) ) { mLastBrushPoint = point; } } int rad = qRound( brushWidth ) / 2 + 2; mScribbleArea->paintBitmapBufferRect(rect); mScribbleArea->refreshBitmap( rect, rad ); } else if ( layer->type() == Layer::VECTOR ) { qreal brushWidth = properties.width * mCurrentPressure; int rad = qRound( ( brushWidth / 2 + 2 ) * mEditor->view()->scaling() ); QPen pen( mEditor->color()->frontColor(), brushWidth * mEditor->view()->scaling(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ); if ( p.size() == 4 ) { QPainterPath path( p[ 0 ] ); path.cubicTo( p[ 1 ], p[ 2 ], p[ 3 ] ); mScribbleArea->drawPath( path, pen, Qt::NoBrush, QPainter::CompositionMode_Source ); mScribbleArea->refreshVector( path.boundingRect().toRect(), rad ); } } }
void Chip::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color; if (option->state & QStyle::State_MouseOver) fillColor = fillColor.light(125); if (option->levelOfDetail < 0.2) { if (option->levelOfDetail < 0.125) { painter->fillRect(QRectF(0, 0, 110, 70), fillColor); return; } painter->setPen(QPen(Qt::black, 0)); painter->setBrush(fillColor); painter->drawRect(13, 13, 97, 57); return; } QPen oldPen = painter->pen(); QPen pen = oldPen; int width = 0; if (option->state & QStyle::State_Selected) width += 2; pen.setWidth(width); painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100))); painter->drawRect(QRect(14, 14, 79, 39)); if (option->levelOfDetail >= 1) { painter->setPen(QPen(Qt::gray, 1)); painter->drawLine(15, 54, 94, 54); painter->drawLine(94, 53, 94, 15); painter->setPen(QPen(Qt::black, 0)); } // Draw text if (option->levelOfDetail >= 2) { QFont font("Times", 10); font.setStyleStrategy(QFont::ForceOutline); painter->setFont(font); painter->save(); painter->scale(0.1, 0.1); painter->drawText(170, 180, QString("Model: VSC-2000 (Very Small Chip) at %1x%2").arg(x).arg(y)); painter->drawText(170, 200, QString("Serial number: DLWR-WEER-123L-ZZ33-SDSJ")); painter->drawText(170, 220, QString("Manufacturer: Chip Manufacturer")); painter->restore(); } // Draw lines QVarLengthArray<QLineF, 36> lines; if (option->levelOfDetail >= 0.5) { for (int i = 0; i <= 10; i += (option->levelOfDetail > 0.5 ? 1 : 2)) { lines.append(QLineF(18 + 7 * i, 13, 18 + 7 * i, 5)); lines.append(QLineF(18 + 7 * i, 54, 18 + 7 * i, 62)); } for (int i = 0; i <= 6; i += (option->levelOfDetail > 0.5 ? 1 : 2)) { lines.append(QLineF(5, 18 + i * 5, 13, 18 + i * 5)); lines.append(QLineF(94, 18 + i * 5, 102, 18 + i * 5)); } } if (option->levelOfDetail >= 0.4) { const QLineF lineData[] = { QLineF(25, 35, 35, 35), QLineF(35, 30, 35, 40), QLineF(35, 30, 45, 35), QLineF(35, 40, 45, 35), QLineF(45, 30, 45, 40), QLineF(45, 35, 55, 35) }; lines.append(lineData, 6); } painter->drawLines(lines.data(), lines.size()); // Draw red ink if (stuff.size() > 1) { painter->setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter->setBrush(Qt::NoBrush); QPainterPath path; path.moveTo(stuff.first()); for (int i = 1; i < stuff.size(); ++i) path.lineTo(stuff.at(i)); painter->drawPath(path); } }
void SelectionItem::updateDeltaLines() { qreal x1, x2; x1 = this->leftSelected->x(); x2 = this->rightSelected->sceneBoundingRect().bottomRight().x(); // Update before and after items since we may have crossed over an item TimelineScene *timeline = qobject_cast<TimelineScene *>(this->leftSelected->scene()); this->before = timeline->getTriggerItemBefore(this->leftSelected); this->after = timeline->getTriggerItemAfter(this->rightSelected); if (this->before) { qreal d = this->leftSelected->x() - this->before->pos().x(); if (textBefore == NULL && lineBefore == NULL) { // Create the elements QPointF p1 = this->mapFromScene(this->leftSelected->x(), 30.0); QPointF p2 = this->mapFromScene(this->before->pos().x(), 30.0); textBefore = new QGraphicsTextItem(this); textBefore->setPlainText(QString::number(d * timeline->ratio(), 'f', 1)); //textBefore->setPos(this->mapFromScene(x1 - textBefore->sceneBoundingRect().width(), 30.0)); textBefore->setPos( (p1.x() + p2.x()) / 2, p1.y()); lineBefore = new QGraphicsLineItem(this); lineBefore->setLine(QLineF(p1, p2)); lineBeforeRight = new QGraphicsLineItem(p1.x(), 0.0, p1.x(), 40.0, this); lineBeforeLeft = new QGraphicsLineItem(p2.x(), 0.0, p2.x(), 40.0, this); } else { // Update the before line and label QLineF line = this->lineBefore->line(); QPointF p2 = line.p2(); p2.setX(this->mapFromScene(this->before->pos()).x()); line.setP2(p2); line.setLength(d); this->lineBefore->setLine(line); textBefore->setPos((line.p1().x() + line.p2().x())/2, line.p1().y()); textBefore->setPlainText(QString::number(d * timeline->ratio(), 'f', 1)); // the left before line should not move this->lineBeforeLeft->setLine(QLine(this->mapFromScene(this->before->pos()).x(), this->lineBeforeLeft->line().y1(), this->mapFromScene(this->before->pos()).x(), this->lineBeforeLeft->line().y2())); } } else { // No more before item, remove everything if (this->lineBefore) { timeline->removeItem(this->lineBefore); timeline->removeItem(this->lineBeforeLeft); timeline->removeItem(this->lineBeforeRight); delete this->lineBefore; delete this->lineBeforeLeft; delete this->lineBeforeRight; this->lineBefore = NULL; this->lineBeforeLeft = NULL; this->lineBeforeRight = NULL; } if (this->textBefore) { timeline->removeItem(this->textBefore); delete this->textBefore; this->textBefore = NULL; } } // Text label for the delta between the right selected and the later item if (this->after) { qreal d = this->after->pos().x() - this->rightSelected->x(); if (textAfter == NULL && lineAfter == NULL) { // Create QPointF p1 = this->mapFromScene(this->rightSelected->x(), 30.0); QPointF p2 = this->mapFromScene(this->after->pos().x(), 30.0); textAfter = new QGraphicsTextItem(this); textAfter->setPlainText(QString::number(d * timeline->ratio(), 'f', 1)); textAfter->setPos(this->mapFromScene(x2, 30.0)); lineAfter = new QGraphicsLineItem(this); lineAfter->setLine(QLineF(p1, p2)); lineAfterLeft = new QGraphicsLineItem(p1.x(), 0.0, p1.x(), 40.0, this); lineAfterRight = new QGraphicsLineItem(p2.x(), 0.0, p2.x(), 40.0, this); } else { // Update the after line and label QLineF line = this->lineAfter->line(); QPointF p = line.p2(); p.setX(this->mapFromScene(this->after->pos()).x()); line.setP2(p); line.setLength(d); this->lineAfter->setLine(line); textAfter->setPlainText(QString::number(d * timeline->ratio(), 'f', 1)); // the right after line should not move this->lineAfterRight->setLine(QLine(this->mapFromScene(this->after->pos()).x(), this->lineAfterRight->line().y1(), this->mapFromScene(this->after->pos()).x(), this->lineAfterRight->line().y2())); } } else { // No more after item, remove everything if (this->lineAfter) { timeline->removeItem(this->lineAfter); timeline->removeItem(this->lineAfterLeft); timeline->removeItem(this->lineAfterRight); delete this->lineAfter; delete this->lineAfterLeft; delete this->lineAfterRight; this->lineAfter = NULL; this->lineAfterLeft = NULL; this->lineAfterRight = NULL; } if (this->textAfter) { timeline->removeItem(this->textAfter); delete this->textAfter; this->textAfter = NULL; } } }
void BarLine::draw(QPainter* painter) const { qreal lw = point(score()->styleS(ST_barWidth)); qreal y1, y2; getY(&y1, &y2); QPen pen(curColor(), lw, Qt::SolidLine, Qt::FlatCap); painter->setPen(pen); qreal mags = magS(); switch(barLineType()) { case BROKEN_BAR: pen.setStyle(Qt::DashLine); painter->setPen(pen); painter->drawLine(QLineF(lw * .5, y1, lw * .5, y2)); break; case DOTTED_BAR: pen.setStyle(Qt::DotLine); painter->setPen(pen); case NORMAL_BAR: painter->drawLine(QLineF(lw * .5, y1, lw * .5, y2)); break; case END_BAR: { qreal lw2 = point(score()->styleS(ST_endBarWidth)); qreal d = point(score()->styleS(ST_endBarDistance)); painter->drawLine(QLineF(lw * .5, y1, lw * .5, y2)); pen.setWidthF(lw2); painter->setPen(pen); qreal x = d + lw2 * .5 + lw; painter->drawLine(QLineF(x, y1, x, y2)); } break; case DOUBLE_BAR: { lw = point(score()->styleS(ST_doubleBarWidth)); qreal d = point(score()->styleS(ST_doubleBarDistance)); pen.setWidthF(lw); painter->setPen(pen); qreal x = lw * .5; painter->drawLine(QLineF(x, y1, x, y2)); x += d + lw; painter->drawLine(QLineF(x, y1, x, y2)); } break; case START_REPEAT: { qreal lw2 = point(score()->styleS(ST_endBarWidth)); qreal d1 = point(score()->styleS(ST_endBarDistance)); qreal x2 = lw2 * .5; // thick line (lw2) qreal x1 = lw2 + d1 + lw * .5; // thin line (lw) qreal x0 = lw2 + d1 + lw + d1; // dot position drawDots(painter, x0); painter->drawLine(QLineF(x1, y1, x1, y2)); pen.setWidthF(lw2); painter->setPen(pen); painter->drawLine(QLineF(x2, y1, x2, y2)); if (score()->styleB(ST_repeatBarTips)) { symbols[score()->symIdx()][brackettipsRightUp].draw(painter, mags, QPointF(0.0, y1)); symbols[score()->symIdx()][brackettipsRightDown].draw(painter, mags, QPointF(0.0, y2)); } } break; case END_REPEAT: { qreal lw2 = point(score()->styleS(ST_endBarWidth)); qreal d1 = point(score()->styleS(ST_endBarDistance)); const Sym& dotsym = symbols[score()->symIdx()][dotSym]; qreal dotw = dotsym.width(mags); qreal x1 = dotw + d1 + lw * .5; qreal x2 = dotw + d1 + lw + d1 + lw2 * .5; drawDots(painter, 0.0); painter->drawLine(QLineF(x1, y1, x1, y2)); pen.setWidthF(lw2); painter->setPen(pen); painter->drawLine(QLineF(x2, y1, x2, y2)); if (score()->styleB(ST_repeatBarTips)) { qreal x = x2 + lw2 * .5; symbols[score()->symIdx()][brackettipsLeftUp].draw(painter, mags, QPointF(x, y1)); symbols[score()->symIdx()][brackettipsLeftDown].draw(painter, mags, QPointF(x, y2)); } } break; case END_START_REPEAT: { qreal lw2 = point(score()->styleS(ST_endBarWidth)); qreal d1 = point(score()->styleS(ST_endBarDistance)); const Sym& dotsym = symbols[score()->symIdx()][dotSym]; qreal dotw = dotsym.width(mags); qreal x1 = dotw + d1 + lw * .5; // thin bar qreal x2 = dotw + d1 + lw + d1 + lw2 * .5; // thick bar qreal x3 = dotw + d1 + lw + d1 + lw2 + d1 + lw * .5; // thin bar qreal x4 = dotw + d1 + lw + d1 + lw2 + d1 + lw + d1; // dot position drawDots(painter, .0); drawDots(painter, x4); painter->drawLine(QLineF(x1, y1, x1, y2)); pen.setWidthF(lw2); painter->setPen(pen); painter->drawLine(QLineF(x2, y1, x2, y2)); pen.setWidthF(lw); painter->setPen(pen); painter->drawLine(QLineF(x3, y1, x3, y2)); if (score()->styleB(ST_repeatBarTips)) { qreal x = x2; symbols[score()->symIdx()][brackettipsRightUp].draw(painter, mags, QPointF(x, y1)); symbols[score()->symIdx()][brackettipsRightDown].draw(painter, mags, QPointF(x, y2)); symbols[score()->symIdx()][brackettipsLeftUp].draw(painter, mags, QPointF(x, y1)); symbols[score()->symIdx()][brackettipsLeftDown].draw(painter, mags, QPointF(x, y2)); } } break; } }
void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint, bool posIncludesFrame, int page ) { double upperLeftX = x; double upperLeftY = y; if ( page > 0 ) { double h = composition()->paperHeight() + composition()->spaceBetweenPages(); upperLeftY += ( page - 1 ) * h; } //store the item position mode mLastUsedPositionMode = itemPoint; //adjust x-coordinate if placement is not done to a left point if ( itemPoint == UpperMiddle || itemPoint == Middle || itemPoint == LowerMiddle ) { upperLeftX -= width / 2.0; } else if ( itemPoint == UpperRight || itemPoint == MiddleRight || itemPoint == LowerRight ) { upperLeftX -= width; } //adjust y-coordinate if placement is not done to an upper point if ( itemPoint == MiddleLeft || itemPoint == Middle || itemPoint == MiddleRight ) { upperLeftY -= height / 2.0; } else if ( itemPoint == LowerLeft || itemPoint == LowerMiddle || itemPoint == LowerRight ) { upperLeftY -= height; } if ( posIncludesFrame ) { //adjust position to account for frame size if ( qgsDoubleNear( mEvaluatedItemRotation, 0.0 ) ) { upperLeftX += estimatedFrameBleed(); upperLeftY += estimatedFrameBleed(); } else { //adjust position for item rotation QLineF lineToItemOrigin = QLineF( 0, 0, estimatedFrameBleed(), estimatedFrameBleed() ); lineToItemOrigin.setAngle( -45 - mEvaluatedItemRotation ); upperLeftX += lineToItemOrigin.x2(); upperLeftY += lineToItemOrigin.y2(); } width -= 2 * estimatedFrameBleed(); height -= 2 * estimatedFrameBleed(); } //consider data defined item size and position before finalising rect QRectF newRect = evalItemRect( QRectF( upperLeftX, upperLeftY, width, height ) ); setSceneRect( newRect ); }
/*! Draw the shape in response to an update event. */ void QgsRubberBand::paint( QPainter* p ) { if ( !mPoints.isEmpty() ) { p->setBrush( mBrush ); p->setPen( mPen ); Q_FOREACH ( const QList<QgsPoint>& line, mPoints ) { QVector<QPointF> pts; Q_FOREACH ( const QgsPoint& pt, line ) { const QPointF cur = toCanvasCoordinates( QgsPoint( pt.x() + mTranslationOffsetX, pt.y() + mTranslationOffsetY ) ) - pos(); if ( pts.empty() || std::abs( pts.back().x() - cur.x() ) > 1 || std::abs( pts.back().y() - cur.y() ) > 1 ) pts.append( cur ); } switch ( mGeometryType ) { case QgsWkbTypes::PolygonGeometry: { p->drawPolygon( pts ); } break; case QgsWkbTypes::PointGeometry: { Q_FOREACH ( QPointF pt, pts ) { double x = pt.x(); double y = pt.y(); qreal s = ( mIconSize - 1 ) / 2.0; switch ( mIconType ) { case ICON_NONE: break; case ICON_CROSS: p->drawLine( QLineF( x - s, y, x + s, y ) ); p->drawLine( QLineF( x, y - s, x, y + s ) ); break; case ICON_X: p->drawLine( QLineF( x - s, y - s, x + s, y + s ) ); p->drawLine( QLineF( x - s, y + s, x + s, y - s ) ); break; case ICON_BOX: p->drawLine( QLineF( x - s, y - s, x + s, y - s ) ); p->drawLine( QLineF( x + s, y - s, x + s, y + s ) ); p->drawLine( QLineF( x + s, y + s, x - s, y + s ) ); p->drawLine( QLineF( x - s, y + s, x - s, y - s ) ); break; case ICON_FULL_BOX: p->drawRect( x - s, y - s, mIconSize, mIconSize ); break; case ICON_CIRCLE: p->drawEllipse( x - s, y - s, mIconSize, mIconSize ); break; } } } break; case QgsWkbTypes::LineGeometry: default: { p->drawPolyline( pts ); } break; }
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (None == mCurrentTool) return; QLineF move = QLineF(mStartingPoint, event->scenePos()); qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal height = delegated()->boundingRect().height() * mTotalScaleY; if (mOperationMode == Scaling) { if(!rotating()) { mTranslateX = moveX; // Perform the resize if (resizingBottomRight()) { // ----------------------------------------------------- // ! We want to keep the aspect ratio with this resize ! // ----------------------------------------------------- qreal scaleX; qreal scaleY; if(!mMirrorX) { scaleX = (width + moveX) / width; } else { scaleX = (width - moveX) / width; } if(!mMirrorY) { scaleY = (height + moveY) / height; } else { scaleY = (height - moveY) / height; } qreal scaleFactor = (scaleX + scaleY) / 2; // Do not allow resizing of image size under frame size if (canResizeBottomRight(width, height, scaleFactor)) { if (mRespectRatio) { mScaleX = scaleFactor; mScaleY = scaleFactor; } else { mScaleX = scaleX; mScaleY = scaleY; } } } else if (resizingLeft() || resizingRight()) { if(width != 0) { qreal scaleX = 0.0; if(resizingLeft()) { scaleX = (width - moveX) / width; } else if(resizingRight()) { scaleX = (width + moveX) / width; } if(mDelegate->isFlippable() && qAbs(scaleX) != 0) { if((qAbs(width * scaleX)) < 2*mFrameWidth) { bool negative = (scaleX < 0)?true:false; if(negative) { if(mMirrorX) scaleX = 2*mFrameWidth/width; else scaleX = -2*mFrameWidth/width; } else { scaleX = -1; mFlippedX = !mFlippedX; } } mScaleX = scaleX; } else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth) { mScaleX = scaleX; if(resizingLeft()) { mTranslateX = moveX; } } } } else if(resizingTop() || resizingBottom()) { if(height != 0) { qreal scaleY = 0.0; if(resizingTop()) { scaleY = (height - moveY) / height; } else if(resizingBottom()) { scaleY = (height + moveY) / height; } if(mDelegate->isFlippable() && qAbs(scaleY) != 0) { if((qAbs(height * scaleY)) < 2*mFrameWidth) { bool negative = (scaleY < 0)?true:false; if(negative) { if(mMirrorY) scaleY = 2*mFrameWidth/width; else scaleY = -2*mFrameWidth/width; } else { scaleY = -1; mFlippedY = !mFlippedY; } } mScaleY = scaleY; } else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth) { mScaleY = scaleY; if(resizingTop()) { mTranslateY = moveY; } } } } } } if (rotating()) { mTranslateX = 0; mTranslateY = 0; QLineF startLine(sceneBoundingRect().center(), event->lastScenePos()); QLineF currentLine(sceneBoundingRect().center(), event->scenePos()); mAngle += startLine.angleTo(currentLine); if ((int)mAngle % 45 >= 45 - mAngleTolerance || (int)mAngle % 45 <= mAngleTolerance) { mAngle = qRound(mAngle / 45) * 45; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } else if ((int)mAngle % 30 >= 30 - mAngleTolerance || (int)mAngle % 30 <= mAngleTolerance) { mAngle = qRound(mAngle / 30) * 30; mAngleOffset += startLine.angleTo(currentLine); if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance) { mAngle += mAngleOffset; mAngleOffset = 0; } } setCursorFromAngle(QString::number((int)mAngle % 360)); } else if (moving()) { mTranslateX = move.dx(); mTranslateY = move.dy(); moveLinkedItems(move); } if (mOperationMode == Scaling || moving() || rotating()) { QTransform tr = buildTransform(); if (resizingRight() || resizingBottom() || resizingBottomRight()) { QPointF ref; // we just detects coordinates of corner before and after scaling and then moves object at diff between them. if (resizingBottomRight() && (mMirrorX || mMirrorY)) { if (mFlippedX && !mMirrorX && mFlippedY)// && !mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else if ((mFlippedX || mMirrorX) && (mFlippedY || mMirrorY)) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } else if (mFlippedX || mMirrorX) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topRight()).x() - tr.map(delegated()->boundingRect().topRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topRight()).y() - tr.map(delegated()->boundingRect().topRight()).y(); } else if (mFlippedY || mMirrorY) { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y(); } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); } } else { mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); } } else if (resizingTop() || resizingLeft()) { QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight()); mTranslateX += fixedPoint.x() - bottomRight.x(); mTranslateY += fixedPoint.y() - bottomRight.y(); } delegated()->setTransform(buildTransform()); } else // resizing/resizing horizontally { if (resizingBottomRight()) { static QSizeF incV = QSizeF(); static QSizeF incH = QSizeF(); if (mMirrorX && mMirrorY) mCurrentTool = ResizeTop; else mCurrentTool = ResizeBottom; incV = resizeDelegate(moveX, moveY); mOriginalSize += incV; if (mMirrorX && mMirrorY) mCurrentTool = ResizeLeft; else mCurrentTool = ResizeRight; move = QLineF(event->lastScenePos(), event->scenePos()); moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); mFixedPoint = getFixedPointFromPos(); incH = resizeDelegate(moveX, moveY); mOriginalSize -= incV; mOriginalSize += incH; mCurrentTool = ResizeBottomRight; } else resizeDelegate(moveX, moveY); } event->accept(); }
void Glissando::setSize(const QSizeF& s) { line = QLineF(0.0, s.height(), s.width(), 0.0); }