Beispiel #1
0
/**
 * 功能
 *      当前单元格子元素布局
 */
void WinDigitalDelegate::doLayout(const QStyleOptionViewItem & option, QRectF &valRect, QRectF &unitRect, QRectF &tagRect, QRectF &alarmRect, qreal &alarmSpan) const
{
    /***********测量值***********/
    valRect = option.rect;
    valRect.setHeight(valRect.height()/3);
    valRect.moveTop(valRect.bottom());
    valRect.setRight(valRect.right() - valRect.width()/18- 3);

    /************标记**********/
    tagRect = valRect;
    tagRect.moveBottom(tagRect.top());
    tagRect.setTop(tagRect.top() + option.rect.height()/10);

    /************单位***********/
    unitRect = valRect;
    unitRect.moveTop(unitRect.bottom());
    unitRect.setRight(unitRect.right() - 15);

    /*************报警标记**********/
    alarmRect = unitRect;
    alarmRect.setHeight(alarmRect.height()/3);
    alarmRect.moveTop(alarmRect.bottom());
    alarmRect.setLeft(alarmRect.center().x() - 4*alarmRect.height());
    alarmRect.setWidth(alarmRect.height());
    alarmSpan = alarmRect.width() * 2;
}
void QgsComposerScaleBar::setSceneRect( const QRectF& rectangle )
{
  QRectF box = mStyle->calculateBoxSize();
  if ( rectangle.height() > box.height() )
  {
    //keep user specified item height if higher than minimum scale bar height
    box.setHeight( rectangle.height() );
  }
  box.moveTopLeft( rectangle.topLeft() );

  //update rect for data defined size and position
  QRectF newRect = evalItemRect( rectangle );

  //scale bars have a minimum size, respect that regardless of data defined settings
  if ( newRect.width() < box.width() )
  {
    newRect.setWidth( box.width() );
  }
  if ( newRect.height() < box.height() )
  {
    newRect.setHeight( box.height() );
  }

  QgsComposerItem::setSceneRect( newRect );
}
void NodeInspector::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                       QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    const auto r = boundingRect().adjusted(border, border, -border, -border);

    if (glow)
    {
        painter->setBrush(Qt::NoBrush);
        painter->setPen(QPen(QColor(255, 255, 255, Colors::base02.red()), 20));
        painter->drawRoundedRect(r, 8, 8);
    }

    painter->setBrush(Colors::base01);
    painter->setPen(Qt::NoPen);
    painter->drawRoundedRect(r, 8, 8);

    painter->setBrush(Colors::base03);
    QRectF br = title_row->boundingRect();
    br.setWidth(r.width());
    br.setHeight(br.height() + 2);
    painter->drawRoundedRect(br, 8, 8);
    br.setHeight(br.height()/2);
    br.moveTop(br.height());
    painter->drawRect(br);

    painter->setBrush(Qt::NoBrush);
    if (isSelected())
        painter->setPen(QPen(Colors::base05, 2));
    else
        painter->setPen(QPen(Colors::base03, 2));
    painter->drawRoundedRect(r, 8, 8);
}
Beispiel #4
0
void QgsComposerFrame::setSceneRect( const QRectF &rectangle )
{
  QRectF fixedRect = rectangle;

  if ( mMultiFrame )
  {
    //calculate index of frame
    int frameIndex = mMultiFrame->frameIndex( this );

    QSizeF fixedSize = mMultiFrame->fixedFrameSize( frameIndex );
    if ( fixedSize.width() > 0 )
    {
      fixedRect.setWidth( fixedSize.width() );
    }
    if ( fixedSize.height() > 0 )
    {
      fixedRect.setHeight( fixedSize.height() );
    }

    //check minimum size
    QSizeF minSize = mMultiFrame->minFrameSize( frameIndex );
    fixedRect.setWidth( qMax( minSize.width(), fixedRect.width() ) );
    fixedRect.setHeight( qMax( minSize.height(), fixedRect.height() ) );
  }

  QgsComposerItem::setSceneRect( fixedRect );
}
Beispiel #5
0
void RBAlbumArt::paint(QPainter *painter,
                       const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QRectF drawArea;

    /* Making sure the alignment flags are sane */
    if(hAlign != 'c' && hAlign != 'l' && hAlign != 'r')
        hAlign = 'c';
    if(vAlign != 'c' && vAlign != 't' && vAlign != 'b')
        vAlign = 'c';

    if(artWidth <= size.width() && artHeight <= size.height())
    {
        /* If the art is smaller than the viewport, just center it up */
        drawArea.setX((size.width() - artWidth) / 2);
        drawArea.setY((size.height() - artHeight) / 2);
        drawArea.setWidth(artWidth);
        drawArea.setHeight(artHeight);
    }
    else
    {
        /* Otherwise, figure out our scale factor, and which dimension needs
         * to be scaled, and how to align said dimension
         */
        double xScale = size.width() / artWidth;
        double yScale = size.height() / artHeight;
        double scale = xScale < yScale ? xScale : yScale;

        double scaleWidth = artWidth * scale;
        double scaleHeight = artHeight * scale;

        if(hAlign == 'l')
            drawArea.setX(0);
        else if(hAlign == 'c')
            drawArea.setX((size.width() - scaleWidth) / 2 );
        else
            drawArea.setX(size.width() - scaleWidth);

        if(vAlign == 't')
            drawArea.setY(0);
        else if(vAlign == 'c')
            drawArea.setY((size.height() - scaleHeight) / 2);
        else
            drawArea.setY(size.height() - scaleHeight);

        drawArea.setWidth(scaleWidth);
        drawArea.setHeight(scaleHeight);

    }

    painter->fillRect(drawArea, texture);

    RBMovable::paint(painter, option, widget);
}
Beispiel #6
0
void QgsComposerPicture::setSceneRect( const QRectF& rectangle )
{

  QSizeF currentPictureSize = pictureSize();

  if ( mResizeMode == QgsComposerPicture::Clip )
  {
    QgsComposerItem::setSceneRect( rectangle );
    mPictureWidth = rectangle.width();
    mPictureHeight = rectangle.height();
    return;
  }

  QRectF newRect = rectangle;

  if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) )
  {
    //if width has changed less than height, then fix width and set height correspondingly
    //else, do the opposite
    if ( qAbs( rect().width() - rectangle.width() ) <
         qAbs( rect().height() - rectangle.height() ) )
    {
      newRect.setHeight( currentPictureSize.height() * newRect.width() / currentPictureSize.width() );
    }
    else
    {
      newRect.setWidth( currentPictureSize.width() * newRect.height() / currentPictureSize.height() );
    }
  }
  else if ( mResizeMode == FrameToImageSize )
  {
    if ( !( currentPictureSize.isEmpty() ) )
    {
      newRect.setWidth( currentPictureSize.width() * 25.4 / mComposition->printResolution() );
      newRect.setHeight( currentPictureSize.height() * 25.4 / mComposition->printResolution() );
    }
  }

  //find largest scaling of picture with this rotation which fits in item
  if ( mResizeMode == Zoom )
  {
    QRectF rotatedImageRect = largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), newRect, mPictureRotation );
    mPictureWidth = rotatedImageRect.width();
    mPictureHeight = rotatedImageRect.height();
  }
  else
  {
    mPictureWidth = newRect.width();
    mPictureHeight = newRect.height();
  }

  QgsComposerItem::setSceneRect( newRect );
  emit itemChanged();
}
Beispiel #7
0
QRectF QwtPlotLayout::layoutLegend( Options options,
    const QRectF &rect ) const
{
    const QSize hint( d_data->layoutData.legend.hint );

    int dim;
    if ( d_data->legendPos == QwtPlot::LeftLegend
        || d_data->legendPos == QwtPlot::RightLegend )
    {
        // We don't allow vertical legends to take more than
        // half of the available space.

        dim = qMin( hint.width(), int( rect.width() * d_data->legendRatio ) );

        if ( !( options & IgnoreScrollbars ) )
        {
            if ( hint.height() > rect.height() )
            {
                // The legend will need additional
                // space for the vertical scrollbar.

                dim += d_data->layoutData.legend.vScrollBarWidth;
            }
        }
    }
    else
    {
        dim = qMin( hint.height(), int( rect.height() * d_data->legendRatio ) );
        dim = qMax( dim, d_data->layoutData.legend.hScrollBarHeight );
    }

    QRectF legendRect = rect;
    switch ( d_data->legendPos )
    {
        case QwtPlot::LeftLegend:
            legendRect.setWidth( dim );
            break;
        case QwtPlot::RightLegend:
            legendRect.setX( rect.right() - dim );
            legendRect.setWidth( dim );
            break;
        case QwtPlot::TopLegend:
            legendRect.setHeight( dim );
            break;
        case QwtPlot::BottomLegend:
            legendRect.setY( rect.bottom() - dim );
            legendRect.setHeight( dim );
            break;
        case QwtPlot::ExternalLegend:
            break;
    }

    return legendRect;
}
/*!
  Calculate the the rectangle for the color bar

  \param rect Bounding rectangle for all components of the scale
  \return Rectangle for the color bar
*/
QRectF QwtScaleWidget::colorBarRect( const QRectF& rect ) const
{
    QRectF cr = rect;

    if ( d_data->scaleDraw->orientation() == Qt::Horizontal )
    {
        cr.setLeft( cr.left() + d_data->borderDist[0] );
        cr.setWidth( cr.width() - d_data->borderDist[1] + 1 );
    }
    else
    {
        cr.setTop( cr.top() + d_data->borderDist[0] );
        cr.setHeight( cr.height() - d_data->borderDist[1] + 1 );
    }

    switch ( d_data->scaleDraw->alignment() )
    {
        case QwtScaleDraw::LeftScale:
        {
            cr.setLeft( cr.right() - d_data->margin
                - d_data->colorBar.width );
            cr.setWidth( d_data->colorBar.width );
            break;
        }

        case QwtScaleDraw::RightScale:
        {
            cr.setLeft( cr.left() + d_data->margin );
            cr.setWidth( d_data->colorBar.width );
            break;
        }

        case QwtScaleDraw::BottomScale:
        {
            cr.setTop( cr.top() + d_data->margin );
            cr.setHeight( d_data->colorBar.width );
            break;
        }

        case QwtScaleDraw::TopScale:
        {
            cr.setTop( cr.bottom() - d_data->margin
                - d_data->colorBar.width );
            cr.setHeight( d_data->colorBar.width );
            break;
        }
    }

    return cr;
}
Beispiel #9
0
void GraphBlock::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{ 
   QLinearGradient fillBrush( QPointF(0, 0), QPointF(0, m_captionBounds.height()));
   fillBrush.setColorAt( 0, isSelected() ? QColor( 255, 226, 96 ) : QColor( 200, 200, 200 ) );
   fillBrush.setColorAt( 0.5f, QColor( 70, 70, 70 ) );

   painter->save();

   painter->setRenderHint( QPainter::Antialiasing, true );
   painter->setRenderHint( QPainter::TextAntialiasing, true );
   painter->setFont( m_font );
   
   const float edgeRadius = 3.0f;

   // draw the block's layout
   {
      painter->setPen( GraphWidgetUtils::s_borderPen );

      painter->setBrush( QColor( 150, 150, 150 ) );
      painter->setOpacity( 0.5f );
      painter->drawRoundedRect( m_bounds, edgeRadius, edgeRadius );
   }

   // draw the header
   {
      
      QPainterPath path;

      QRectF topBB = m_captionBounds;
      topBB.setHeight( m_captionBounds.height() + edgeRadius );

      QRectF bottomBB = m_captionBounds;
      bottomBB.setTop( m_captionBounds.height() );
      bottomBB.setHeight( edgeRadius );

      path.addRoundedRect( topBB, edgeRadius, edgeRadius );
      path.addRect( bottomBB );

      painter->setOpacity( 1.0f );
      painter->setPen( Qt::NoPen );
      painter->setBrush( fillBrush );
      painter->drawPath( path );

      GraphWidgetUtils::drawShadowedText( painter, m_captionBounds, m_caption.c_str(), QTextOption( Qt::AlignCenter ) );
   }


   painter->restore();
}
Beispiel #10
0
QRectF Sheep::getSheepRect(qint32 _len, Qt::Orientation _orientation)
{
    QRectF itemRect;
    if (Qt::Orientation::Vertical == _orientation)
    {
        itemRect.setHeight(_len * SceneParams::cellSize);
        itemRect.setWidth(SceneParams::cellSize);
    }
    else
    {
        itemRect.setHeight(SceneParams::cellSize);
        itemRect.setWidth(_len * SceneParams::cellSize);
    }
    return itemRect;
}
Beispiel #11
0
void QgraphicsItemTable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)

    {

        QGraphicsItemResizable::paint(painter,option,widget);
        QPen pen;
        pen.setStyle(Qt::DashDotLine);
        QPen def = painter->pen();
        painter->setPen(pen);
        painter->drawRect(boundingRect());
        painter->setPen(def);
        QRectF bord = boundingRect();
        bord.setTop(bord.top()-my);
        bord.setLeft(bord.left()-mx);
        bord.setWidth(bord.width()-mw);
        bord.setHeight(bord.height()-mh);
        QRectF *bord2 = new QRectF();
        def.setColor(Qt::white);
        painter->setPen(def);
        painter->drawText(bord,Qt::AlignCenter,*(TableData->GetCaption()),bord2);
        qreal px = bord2->left()+TableData->getStrWidth();
        qreal py = bord2->top()+TableData->getStrHeight();
        bord2->setTop(bord2->top()-5);
        bord2->setHeight(bord2->height()+5);
        bord2->setLeft(bord2->left()-5);
        bord2->setWidth(bord2->width()+5);
        painter->fillRect(*bord2,QColor(128,128,128,100));
        painter->drawText(bord,Qt::AlignCenter,*(TableData->GetCaption()),bord2);
        if (GetgrabRefer()->GrabberItem()==this) painter->drawLine(px,py,px+5,py);

}
void QGraphicsPickerScene::setRowCount(int rowCount)
{
    m_rowCount = rowCount;
    QRectF rect = m_selection->rect();
    rect.setHeight(sceneRect().height()/rowCount);
    m_selection->setRect(rect);
}
Beispiel #13
0
// slot
void PrintWidget::printAreaResized()
{
	QRectF area = map_printer->getPrintArea();
	area.setWidth(width_edit->value());
	area.setHeight(height_edit->value());
	map_printer->setPrintArea(area);
}
Beispiel #14
0
Queue::Queue(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Queue)
{
    ui->setupUi(this);
    QGraphicsScene *scene = new QGraphicsScene(this);
    ui->graphicsView->setScene(scene);
    QPixmap bkgnd(":files/images/bckgnd.png");
    bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
    QPalette palette;
    palette.setBrush(QPalette::Background, bkgnd);
    this->setPalette(palette);
    QRectF coords;
    coords.setX(-500); coords.setY(-500);
    coords.setWidth(1000); coords.setHeight(1000);
    rPoint.setX(-500);
    rPoint.setY(-387);
    rLineCoords.setLine(-480, -387, -480, -410);
    qList = new Ui::List(ui->graphicsView, scene, coords, rPoint, rLineCoords, "Rear");

    QFont font;
    fPoint.setX(-500);
    fPoint.setY(-500);
    fLineCoords.setLine(-480, -480, -480, -460);
    fLabel = ui->graphicsView->scene()->addText("Front", font);
    fLabel->setPos(fPoint);
    fLine = ui->graphicsView->scene()->addLine(fLineCoords);
    v = new QIntValidator(0, 65535, this);
    ui->lineEdit->setValidator(v);
}
/*!
   \return Bounding rectangle of the data
   \sa QwtPlotRasterItem::interval()
*/
QRectF QwtPlotRasterItem::boundingRect() const
{
    const QwtInterval intervalX = interval( Qt::XAxis );
    const QwtInterval intervalY = interval( Qt::YAxis );

    if ( !intervalX.isValid() && !intervalY.isValid() )
        return QRectF(); // no bounding rect

    QRectF r;

    if ( intervalX.isValid() )
    {
        r.setLeft( intervalX.minValue() );
        r.setRight( intervalX.maxValue() );
    }
    else
    {
        r.setLeft(-0.5 * FLT_MAX);
        r.setWidth(FLT_MAX);
    }

    if ( intervalY.isValid() )
    {
        r.setTop( intervalY.minValue() );
        r.setBottom( intervalY.maxValue() );
    }
    else
    {
        r.setTop(-0.5 * FLT_MAX);
        r.setHeight(FLT_MAX);
    }

    return r.normalized();
}
void StyledTextboxView::configureObject(void)
{
  QRectF rect;
  QPolygonF pol;
  QPointF pnt;

  this->__configureObject();
  fold->setBrush(box->brush());
  fold->setPen(box->pen());

  rect=box->boundingRect();
  pol=box->polygon();

  if(rect.height() < fold->boundingRect().height())
    rect.setHeight(fold->boundingRect().height() + (2 * VERT_SPACING));

  this->resizePolygon(pol, rect.width() + fold->boundingRect().width(), rect.height());

  pnt=pol.at(2);
  pol.remove(2);
  pol.insert(2, QPointF(pnt.x(), roundf(pnt.y() - fold->boundingRect().height())));
  pol.insert(3, QPointF(roundf(pnt.x() - fold->boundingRect().width()), pnt.y()));
  box->setPolygon(pol);

  rect=box->boundingRect();
  fold->setPos(rect.width() - fold->boundingRect().width(),
               rect.height() - fold->boundingRect().height());

  this->configureObjectShadow();
  this->configureObjectSelection();
}
Beispiel #17
0
QRectF MessageBarIcon::boundingRect(){
    QRectF b = QGraphicsPixmapItem::boundingRect();
    QSize s = ((MessageIconWidget*)parent())->getChildSize();
    b.setWidth(s.width());
    b.setHeight(s.height());
    return b;
}
Beispiel #18
0
void ComponentItem::initPins()
{
    QDomNode pinsNode;
    QDomNodeList list = m_svgDocument.elementsByTagName("g");
    for (int i=0;i<list.count();i++){
        QDomNamedNodeMap attrs = list.item(i).attributes();
        if (attrs.contains("id") &&
            attrs.namedItem("id").toAttr().value() == QString("pins")){
            pinsNode = list.item(i);
            break;
        }
    }
    if (pinsNode.isNull() || !pinsNode.hasChildNodes()){
        kWarning() << "No pins definition found for this component";
        return;
    }
    QDomElement pin = pinsNode.firstChildElement();
    while (!pin.isNull()) {
        QRectF pinRect;
        double r = pin.attribute("r").toDouble();
        pinRect.setLeft(pin.attribute("cx").toDouble());
        pinRect.setTop(pin.attribute("cy").toDouble());
        pinRect.setWidth(r*2);
        pinRect.setHeight(r*2);
        PinItem* p = new PinItem(pinRect, this, qobject_cast< IDocumentScene* >(scene()));
        p->setId(pin.attribute("id"));
        pin = pin.nextSiblingElement();
    }
}
void BoxTextGraphicsItem::adaptHeight()
{
    QRectF r = rect();
    r.setHeight(getBoundedHeight(r));
    setRect(r);
    updateHandlesPosition();
}
Beispiel #20
0
/*!
  Align the legend to the canvas
  \param canvasRect Geometry of the canvas
  \param legendRect Maximum geometry for the legend
  \return Geometry for the aligned legend
*/
QRectF QwtPlotLayout::alignLegend( const QRectF &canvasRect,
    const QRectF &legendRect ) const
{
    QRectF alignedRect = legendRect;

    if ( d_data->legendPos == QwtPlot::BottomLegend
        || d_data->legendPos == QwtPlot::TopLegend )
    {
        if ( d_data->layoutData.legend.hint.width() < canvasRect.width() )
        {
            alignedRect.setX( canvasRect.x() );
            alignedRect.setWidth( canvasRect.width() );
        }
    }
    else
    {
        if ( d_data->layoutData.legend.hint.height() < canvasRect.height() )
        {
            alignedRect.setY( canvasRect.y() );
            alignedRect.setHeight( canvasRect.height() );
        }
    }

    return alignedRect;
}
Beispiel #21
0
static QList<FormField> getFormFields(Poppler::Page *popplerPage)
{
    QList<FormField> formFields;

//QTime t = QTime::currentTime();
    QList<Poppler::FormField*> popplerFormFields = popplerPage->formFields();
//qCritical() << t.msecsTo(QTime::currentTime());
    QSizeF popplerPageSizeF = popplerPage->pageSizeF();
    for (int i = 0; i < popplerFormFields.size(); ++i)
    {
        FormField formField;
        Poppler::FormField* popplerFormField = popplerFormFields.at(i);
        const QRectF popplerFormFieldRect = popplerFormField->rect();
        QRectF formFieldRect;
        formFieldRect.setX(popplerFormFieldRect.x() * popplerPageSizeF.width());
        formFieldRect.setY(popplerFormFieldRect.y() * popplerPageSizeF.height());
        formFieldRect.setWidth((popplerFormFieldRect.right() - popplerFormFieldRect.left()) * popplerPageSizeF.width());
        formFieldRect.setHeight((popplerFormFieldRect.bottom() - popplerFormFieldRect.top()) * popplerPageSizeF.height());
        formField.rect = formFieldRect;
//		if (popplerFormField->type() == Poppler::FormField::FormText)
//			formField.text = static_cast<Poppler::FormFieldText*>(popplerFormField)->text();
        formField.field = popplerFormField;
        formFields << formField;
    }

    return formFields;
}
Beispiel #22
0
QRectF ODrawClient::getRect(const MSO::OfficeArtClientAnchor& clientAnchor)
{
    const MSO::XlsOfficeArtClientAnchor* anchor = clientAnchor.anon.get<MSO::XlsOfficeArtClientAnchor>();
    if (anchor) {
        QRectF r;
        qreal colWidth = columnWidth(m_sheet, anchor->colL);
        r.setLeft(offset(colWidth, anchor->dxL, 1024));
        if (anchor->colR == anchor->colL) {
            r.setRight(offset(colWidth, anchor->dxR, 1024));
        } else {
            qreal width = colWidth - r.left();
            for (int col = anchor->colL + 1; col < anchor->colR; ++col) {
                width += columnWidth(m_sheet, col);
            }
            width += offset(columnWidth(m_sheet, anchor->colR), anchor->dxR, 1024);
            r.setWidth(width);
        }
        qreal rowHgt = rowHeight(m_sheet, anchor->rwT);
        r.setTop(offset(rowHgt, anchor->dyT, 256));
        if (anchor->rwT == anchor->rwB) {
            r.setBottom(offset(rowHgt, anchor->dyB, 256));
        } else {
            qreal height = rowHgt - r.top();
            for (int row = anchor->rwT + 1; row < anchor->rwB; ++row) {
                height += rowHeight(m_sheet, row);
            }
            height += offset(rowHeight(m_sheet, anchor->rwB), anchor->dyB, 256);
            r.setHeight(height);
        }
        return r;
    } else {
        qDebug() << "Invalid client anchor!";
    }
    return QRectF();
}
void InterpreterElementImpl::init(QRectF &contents, PortFactoryInterface const &portFactory
		, QList<PortInterface *> &ports, LabelFactoryInterface &labelFactory
		, QList<LabelInterface *> &labels, SdfRendererInterface *renderer, ElementRepoInterface *elementRepo)
{
	Q_UNUSED(elementRepo);
	if (mId.element() == "MetaEntityNode") {
		mGraphics.setContent(mEditorRepoApi->stringProperty(mId, "shape"));
		QDomDocument classDoc;
		QDomElement sdfElement = mGraphics.firstChildElement("graphics").firstChildElement("picture");
		classDoc.appendChild(classDoc.importNode(sdfElement, true));
		if (!classDoc.childNodes().isEmpty()) {
			mRenderer = renderer;
			mRenderer->load(classDoc);
		}

		int width = 0;
		int height = 0;
		if (!sdfElement.isNull()) {
			width = sdfElement.attribute("sizex").toInt();
			height = sdfElement.attribute("sizey").toInt();
		}

		initPointPorts(portFactory, ports, width, height);
		initLinePorts(portFactory, ports, width, height);

		contents.setWidth(width);
		contents.setHeight(height);
		initLabels(width, height, labelFactory, labels);
	}
}
Beispiel #24
0
/*! \brief Adds a road to the list of selected roads.
*
* Calls fitInView for the selected road and displays it in the ProfileGraph.
*/
void
CrossfallEditor::addSelectedRoad(RSystemElementRoad *road)
{
    if (!selectedCrossfallRoadItems_.contains(road))
    {
        // Activate Road in ProfileGraph //
        //
        CrossfallRoadPolynomialItem *roadItem = new CrossfallRoadPolynomialItem(roadSystemItemPolyGraph_, road);
        selectedCrossfallRoadItems_.insert(road, roadItem);

        // Fit View //
        //
        QRectF boundingBox = roadItem->boundingRect();
        if (boundingBox.width() < 15.0)
        {
            boundingBox.setWidth(15.0);
        }
        if (boundingBox.height() < 15.0)
        {
            boundingBox.setHeight(15.0);
        }

        profileGraph_->getView()->fitInView(boundingBox);
        profileGraph_->getView()->zoomOut(Qt::Horizontal | Qt::Vertical);
    }
    else
    {
        //qDebug("already there");
    }
}
Beispiel #25
0
void QGraphicsItemResizable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

        QRectF bord = boundingRect();// prendo la dimensione
        bord.setTop(bord.top()-my);
        bord.setLeft(bord.left()-mx);
        bord.setWidth(bord.width()-mw);
        bord.setHeight(bord.height()-mh);

        QRect  rect(bord.left()+5,bord.top()+5,bord.width()-10,bord.height()-10);// dimensione rettangolo selezionato

        painter->fillRect(bord,QBrush(BColor));// disegno il rettangolo di contorno
        painter->drawRect(bord);
        if (select){ // se è selezionato disegno
                QPen pen;// nuovo Qpen
                QPen pr =  painter->pen();// mi salvo il pen attuale
                pen.setColor(SColor); // setto il colore del pen nuovo
                pen.setStyle(Qt::DashDotLine);// metto il tratteggio al pen
                painter->setPen(pen);// setto il nuovo pen
                painter->drawRect(rect);  // disegno il rettangolo selezionato
                painter->setPen(pr);// ripristino il pen
            }




    }
Beispiel #26
0
QRectF GraphicNetNode::boundingRect() const {
	QRectF bounds;

	qreal height = icon->boundingRect().height() + (2.0 * CLOUD_Y_MARGIN);
	qreal width = icon->boundingRect().width() + (2.0 * CLOUD_X_MARGIN);

	if(addressText->isVisible()){
		width = fmax(width, addressText->boundingRect().width());
		height += addressText->boundingRect().height();
	}

	if(hostnameText->isVisible()){
		width = fmax(width, hostnameText->boundingRect().width());
		height += hostnameText->boundingRect().height();
	}

	if(secondAddrsText->isVisible()){
		width = fmax(width, secondAddrsText->boundingRect().width());
		height += secondAddrsText->boundingRect().height();
	}

	bounds.setX(0);
	bounds.setY(0);

	bounds.setWidth(width);
	bounds.setHeight(height);

	return bounds;
}
Beispiel #27
0
void GfxBlockItem::sizeToFit() {
  QRectF r = generousChildrenBounds();
  double minh = style().real("gfx-block-minh");
  if (r.height() < minh)
    r.setHeight(minh);

  double yref = data()->yref();
  double h = data()->height();

  bool mustemit = false;
  
  if (yref!=r.top()) {
    prepareGeometryChange();
    if (isWritable())
      data()->setYref(r.top());
    else
      data()->sneakilySetYref(r.top());
    mustemit = true;
  }
  if (h!=r.height()) {
    prepareGeometryChange();
    if (isWritable())
      data()->setHeight(r.height());
    else
      data()->sneakilySetHeight(r.height());        
    mustemit = true;
  }

  if (mustemit)
    emit heightChanged();
}
Beispiel #28
0
TimelineBar::Marker *TimelineBar::findMarker(QVector<Marker> &markers, QRectF markerRect, QPointF pos)
{
  QFontMetrics fm(Formatter::PreferredFont());

  for(Marker &m : markers)
  {
    QRectF r = markerRect;
    r.setLeft(qMax(m_markerRect.left() + borderWidth * 2, offsetOf(m.eidStart)));
    r.setRight(qMin(m_markerRect.right() - borderWidth, offsetOf(m.eidEnd + 1)));
    r.setHeight(fm.height() + borderWidth * 2);

    if(r.width() <= borderWidth * 2)
      continue;

    if(r.contains(pos))
    {
      return &m;
    }

    if(!m.children.isEmpty() && m.expanded)
    {
      QRectF childRect = r;
      childRect.setTop(r.bottom() + borderWidth * 2);
      childRect.setBottom(markerRect.bottom());

      Marker *res = findMarker(m.children, childRect, pos);

      if(res)
        return res;
    }
  }

  return NULL;
}
QVariant PixmapItem::itemChange(GraphicsItemChange change,
                                const QVariant &value)
{
    if (change == ItemPositionChange)
    {
        // value is the new position.
        QPointF newPos = value.toPointF();
        QRectF rect = parentItem()->boundingRect();

        rect.moveLeft(boundingRect().width()*3/4*-1);
        rect.setWidth(rect.width() + boundingRect().width()*2/4 );

        rect.moveTop(boundingRect().height()*3/4*-1);
        rect.setHeight(rect.height() + boundingRect().height()*2/4 );

        CardItem *card = qgraphicsitem_cast<CardItem *>(parentItem());

        if (!rect.contains(newPos))
        {
            // Keep the item inside the scene rect.
            int newX = (int)qMin(rect.right(), qMax(newPos.x(), rect.left()));
            int newY = (int)qMin(rect.bottom(), qMax(newPos.y(), rect.top()));



            if(card->isAlign())
            {
                int gridSize = card->getGridSize();
                newX = (newX/(10*gridSize))*(10*gridSize);
                newY = (newY/(10*gridSize))*(10*gridSize);
            }

            newPos.setX(newX);
            newPos.setY(newY);
            return newPos;
        }
        else
        {
            int newX =  newPos.x();
            int newY = newPos.y();

            if(card->isAlign())
            {
                int gridSize = card->getGridSize();
                newX = newPos.x()/(10*gridSize);
                newX = newX * (10*gridSize);
                newY = newPos.y()/(10*gridSize);
                newY = newY*(10*gridSize);

            }

            newPos.setX(newX);
            newPos.setY(newY);
            return newPos;

        }
    }

    return QGraphicsItem::itemChange(change, value);
}
Beispiel #30
0
void PieChart::paint(QPainter *painter)
{
    painter->setRenderHints(QPainter::Antialiasing, true);
    //Обчислення області для малювання
    QRectF fillRect = boundingRect();
    if(fillRect.height() > fillRect.width()){
        fillRect.setY(fillRect.y() + (fillRect.height()-fillRect.width())/2);
        fillRect.setHeight(fillRect.width());
    } else {
        fillRect.setX(fillRect.x() + (fillRect.width()-fillRect.height())/2);
        fillRect.setWidth(fillRect.height());
    }
    fillRect.adjust(pStrokePen->width(), pStrokePen->width(), -pStrokePen->width(),
                    -pStrokePen->width());

    //Малювання сегментів
    painter->setPen(pStrokePen->getPen());
    double beginAngle = pAngleOffset;
    double segmentAngle;
    for(PieSlice* i:slicesList){
        painter->setBrush(QBrush(i->color()));
        segmentAngle = 5760.0 * fabs(i->value())/sumSliceValue;
        painter->drawPie(fillRect, beginAngle, segmentAngle);
        beginAngle += segmentAngle;
    }
}