void
RoutingStatsScene::addToProxyWidgetsMap(uint32_t nodeId, QString title, QString content)
{

    if(m_nodeIdProxyWidgets.find(nodeId) == m_nodeIdProxyWidgets.end())
    {
        TextBubble * tb = new TextBubble (title, content);
        QFont f(tb->font());
        f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize());
        tb->setFont(f);
        QGraphicsProxyWidget * pw = addWidget(tb);


        QFontMetrics fm(f);
        pw->setMaximumHeight(fm.height() * tb->text().count("\n"));
        pw->adjustSize();
        showInfoWidget(false);
        m_nodeIdProxyWidgets[nodeId] = pw;
        qreal newX = m_lastX + pw->widget()->width();
        if(newX >= sceneRect().right())
        {
            m_lastX = 0;
            m_lastY += pw->widget()->height() + INTERSTATS_SPACE;
        }
        pw->setPos(m_lastX, m_lastY);

        m_lastX = pw->pos().x() + pw->widget()->width() + INTERSTATS_SPACE;
        m_lastY = pw->pos().y();
        m_bottomY = m_lastY + pw->widget()->height();
        //qDebug(QString("Last X" + QString::number(m_lastX) + " w:" + QString::number(pw->widget()->width())));
        adjustRect();
        return;
    }

}
示例#2
0
void Summary::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * /*widget*/)
{
	QRectF rect = (option->type == QStyleOption::SO_GraphicsItem) ? boundingRect() : option->exposedRect;

	setupPainter(painter);
	painter->fillRect(rect,painter->brush());

	if (option->type == QStyleOption::SO_GraphicsItem)
	{
		drawSelection(painter, rect);
		drawTitle(tr("Summary"), TitleLeft, Qt::AlignCenter);
	}

	adjustRect(rect);

	if (frame()&DrawLeft)
		painter->drawLine(rect.left(), rect.top(), rect.left(), rect.bottom());

	if (frame()&DrawRight)
		painter->drawLine(rect.right(), rect.top(), rect.right(), rect.bottom());

	if (frame()&DrawTop)
		painter->drawLine(rect.left(), rect.top(), rect.right(), rect.top());

	if (frame()&DrawBottom)
		painter->drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom());
}
示例#3
0
void Overlay::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * /*widget*/)
{
	QRectF rect = (option->type == QStyleOption::SO_GraphicsItem) ? boundingRect() : option->exposedRect;

	setupPainter(painter);

	painter->fillRect(rect, painter->brush());

	if (option->type == QStyleOption::SO_GraphicsItem)
	{
		drawSelection(painter, rect);
		painter->setPen(QColor(225,224,224));
		painter->drawText(rect, tr("Overlay"));
	}

	adjustRect(rect);

	if (frame()&DrawLeft)
		painter->drawLine(rect.left(), rect.top(), rect.left(), rect.bottom());

	if (frame()&DrawRight)
		painter->drawLine(rect.right(), rect.top(), rect.right(), rect.bottom());

	if (frame()&DrawTop)
		painter->drawLine(rect.left(), rect.top(), rect.right(), rect.top());

	if (frame()&DrawBottom)
		painter->drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom());
}
示例#4
0
cv::Rect getMaxRectInPolygon(std::vector<cv::Point> poly, int seed_width, int seed_height, cv::Mat traj=cv::Mat())
{
    int i=0;
    cv::Point center=getPolygonCenter(poly);
    cv::Rect seed(center.x, center.y, seed_width, seed_height);
    cv::Rect rect=seed, curRect=seed;

    if(traj.data){
        cv::rectangle(traj, seed, cv::Scalar(0));
    }

    do{
        rect=adjustRect(poly, curRect, seed);
        if(curRect==rect) break;
        if(traj.data && (!(++i%4)) ){
            //cv::arrowline(traj, curRect.tl(), rect.tl(), cv::Scalar(100));
            cv::rectangle(traj, rect, cv::Scalar(200));
            //cv::line(img, RECT_CENTER(curRect), RECT_CENTER(rect), cv::Scalar(220));
        }
        curRect=rect;
    }while( 1 );

    if(traj.data){
        cv::rectangle(traj, rect, cv::Scalar(100));
    }

    return rect;
}
示例#5
0
void AnimationEventsTimeline::resizeEvent( QResizeEvent* event )
{
   QGraphicsView::resizeEvent( event );

   adjustRect();

   QList< QGraphicsItem* > items = scene()->items();
   foreach( QGraphicsItem* item, items )
   {
      BTAEventItem* eventItem = static_cast< BTAEventItem* >( item );
      eventItem->calculateBounds();
   }
void
RoutingStatsScene::reloadContent(bool force)
{
    if(m_nodeIdProxyWidgets.empty())
    {
        return;
    }

    m_lastX = 0;
    m_lastY = 0;
    m_bottomY = 0;
    qreal currentTime = StatsMode::getInstance()->getCurrentTime();

    qreal currentMaxHeight = 0;
    for(NodeIdProxyWidgetMap_t::const_iterator i = m_nodeIdProxyWidgets.begin();
        i != m_nodeIdProxyWidgets.end();
        ++i)
    {
        QGraphicsProxyWidget * pw = i->second;

        if((force) || (!m_lastTime) || (m_lastTime != currentTime))
        {
            updateContent(i->first, pw);
        }


        bool nodeIsActive = StatsMode::getInstance()->isNodeActive(i->first);
        pw->setVisible(nodeIsActive);
        if(nodeIsActive)
        {
            qreal newX = m_lastX + pw->size().width();
            currentMaxHeight = qMax(currentMaxHeight, pw->size().height());
            if(newX >= sceneRect().right())
            {
                m_lastX = 0;
                m_lastY += currentMaxHeight + INTERSTATS_SPACE;
                currentMaxHeight = 0;
            }
            pw->setPos(m_lastX, m_lastY);
            m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE;
            m_lastY = pw->pos().y();
            m_bottomY = m_lastY + currentMaxHeight;
            adjustRect();
        }

    }

    m_lastTime = currentTime;


}
示例#7
0
void getRectSubPix_Cn_(const _Tp* src, size_t src_step, Size src_size,
                       _DTp* dst, size_t dst_step, Size win_size, Point2f center, int cn )
{
    ScaleOp scale_op;
    CastOp cast_op;
    Point ip;
    _WTp a11, a12, a21, a22, b1, b2;
    float a, b;
    int i, j, c;

    center.x -= (win_size.width-1)*0.5f;
    center.y -= (win_size.height-1)*0.5f;

    ip.x = cvFloor( center.x );
    ip.y = cvFloor( center.y );

    a = center.x - ip.x;
    b = center.y - ip.y;
    a11 = scale_op((1.f-a)*(1.f-b));
    a12 = scale_op(a*(1.f-b));
    a21 = scale_op((1.f-a)*b);
    a22 = scale_op(a*b);
    b1 = scale_op(1.f - b);
    b2 = scale_op(b);

    src_step /= sizeof(src[0]);
    dst_step /= sizeof(dst[0]);

    if( 0 <= ip.x && ip.x < src_size.width - win_size.width &&
            0 <= ip.y && ip.y < src_size.height - win_size.height)
    {
        // extracted rectangle is totally inside the image
        src += ip.y * src_step + ip.x*cn;
        win_size.width *= cn;

        for( i = 0; i < win_size.height; i++, src += src_step, dst += dst_step )
        {
            for( j = 0; j <= win_size.width - 2; j += 2 )
            {
                _WTp s0 = src[j]*a11 + src[j+cn]*a12 + src[j+src_step]*a21 + src[j+src_step+cn]*a22;
                _WTp s1 = src[j+1]*a11 + src[j+cn+1]*a12 + src[j+src_step+1]*a21 + src[j+src_step+cn+1]*a22;
                dst[j] = cast_op(s0);
                dst[j+1] = cast_op(s1);
            }

            for( ; j < win_size.width; j++ )
            {
                _WTp s0 = src[j]*a11 + src[j+cn]*a12 + src[j+src_step]*a21 + src[j+src_step+cn]*a22;
                dst[j] = cast_op(s0);
            }
        }
    }
    else
    {
        Rect r;
        src = (const _Tp*)adjustRect( (const uchar*)src, src_step*sizeof(*src),
                                      sizeof(*src)*cn, src_size, win_size, ip, &r);

        for( i = 0; i < win_size.height; i++, dst += dst_step )
        {
            const _Tp *src2 = src + src_step;
            _WTp s0;

            if( i < r.y || i >= r.height )
                src2 -= src_step;

            for( c = 0; c < cn; c++ )
            {
                s0 = src[r.x*cn + c]*b1 + src2[r.x*cn + c]*b2;
                for( j = 0; j < r.x; j++ )
                    dst[j*cn + c] = cast_op(s0);
                s0 = src[r.width*cn + c]*b1 + src2[r.width*cn + c]*b2;
                for( j = r.width; j < win_size.width; j++ )
                    dst[j*cn + c] = cast_op(s0);
            }

            for( j = r.x*cn; j < r.width*cn; j++ )
            {
                s0 = src[j]*a11 + src[j+cn]*a12 + src2[j]*a21 + src2[j+cn]*a22;
                dst[j] = cast_op(s0);
            }

            if( i < r.height )
                src = src2;
        }
    }
}
void
FlowMonStatsScene::align()
{
    m_lastX = 0;
    m_lastY = 0;
    m_bottomY = 0;
    qreal currentMaxHeight = 0;

    for(FlowIdProxyWidgetMap_t::const_iterator i = m_flowIdProxyWidgets.begin();
        i != m_flowIdProxyWidgets.end();
        ++i)
    {
        QGraphicsProxyWidget * pw = i->second;
        bool flowIsActive = StatsMode::getInstance()->isNodeActive(i->first);
        pw->setVisible(flowIsActive);
        if(flowIsActive)
        {
            TextBubble * tb = (TextBubble *) pw->widget();
            QFont f(tb->font());
            f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize());
            tb->setFont(f);

            QFontMetrics fm(f);
            pw->setMaximumHeight(fm.height() * tb->text().count("\n"));
            pw->adjustSize();

            qreal newX = m_lastX + pw->size().width();
            currentMaxHeight = qMax(currentMaxHeight, pw->size().height());
            if(newX >= sceneRect().right())
            {
                m_lastX = 0;
                m_lastY += currentMaxHeight + INTERSTATS_SPACE;
                currentMaxHeight = 0;
            }
            pw->setPos(m_lastX, m_lastY);
            m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE;
            m_lastY = pw->pos().y();
            m_bottomY = m_lastY + currentMaxHeight;
            adjustRect();
        }
    }
    if(m_flowProbeWidget)
    {
            QGraphicsProxyWidget * pw = m_flowProbeWidget;
            TextBubble * tb = (TextBubble *) pw->widget();
            QFont f(tb->font());
            f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize());
            tb->setFont(f);

            QFontMetrics fm(f);
            pw->setMaximumHeight(fm.height() * tb->text().count("\n"));
            pw->adjustSize();

            qreal newX = m_lastX + pw->size().width();
            currentMaxHeight = qMax(currentMaxHeight, pw->size().height());
            if(newX >= sceneRect().right())
            {
                m_lastX = 0;
                m_lastY += currentMaxHeight + INTERSTATS_SPACE;
                currentMaxHeight = 0;
            }
            pw->setPos(m_lastX, m_lastY);
            m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE;
            m_lastY = pw->pos().y();
            m_bottomY = m_lastY + currentMaxHeight;
            adjustRect();

    }

}
void ExpandingDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &_rect, const QString &text) const
{
    QRect rect(_rect);

    adjustRect(rect);

    QTextLayout layout(text, option.font, painter->device());

    QList<QTextLayout::FormatRange> additionalFormats;

    int missingFormats = text.length();

    for (int i = 0; i < m_cachedHighlights.count(); ++i) {
        if (m_cachedHighlights[i].start + m_cachedHighlights[i].length <= m_currentColumnStart) {
            continue;
        }

        if (additionalFormats.isEmpty())
            if (i != 0 && m_cachedHighlights[i - 1].start + m_cachedHighlights[i - 1].length > m_currentColumnStart) {
                QTextLayout::FormatRange before;
                before.start = 0;
                before.length = m_cachedHighlights[i - 1].start + m_cachedHighlights[i - 1].length - m_currentColumnStart;
                before.format = m_cachedHighlights[i - 1].format;
                additionalFormats.append(before);
            }

        QTextLayout::FormatRange format;
        format.start = m_cachedHighlights[i].start - m_currentColumnStart;
        format.length = m_cachedHighlights[i].length;
        format.format = m_cachedHighlights[i].format;

        additionalFormats.append(format);
    }
    if (!additionalFormats.isEmpty()) {
        missingFormats = text.length() - (additionalFormats.back().length + additionalFormats.back().start);
    }

    if (missingFormats > 0) {
        QTextLayout::FormatRange format;
        format.start = text.length() - missingFormats;
        format.length = missingFormats;
        QTextCharFormat fm;
        fm.setForeground(option.palette.text());
        format.format = fm;
        additionalFormats.append(format);
    }

    if (m_backgroundColor.isValid()) {
        QColor background = m_backgroundColor;
//     qCDebug(LOG_KTE) << text << "background:" << background.name();
        //Now go through the formats, and make sure the contrast background/foreground is readable
        for (int a = 0; a < additionalFormats.size(); ++a) {
            QColor currentBackground = background;
            if (additionalFormats[a].format.hasProperty(QTextFormat::BackgroundBrush)) {
                currentBackground = additionalFormats[a].format.background().color();
            }

            QColor currentColor = additionalFormats[a].format.foreground().color();

            double currentContrast = readabilityContrast(currentColor, currentBackground);
            QColor invertedColor(0xffffffff - additionalFormats[a].format.foreground().color().rgb());
            double invertedContrast = readabilityContrast(invertedColor, currentBackground);

//       qCDebug(LOG_KTE) << "values:" << invertedContrast << currentContrast << invertedColor.name() << currentColor.name();

            if (invertedContrast > currentContrast) {
//         qCDebug(LOG_KTE) << text << additionalFormats[a].length << "switching from" << currentColor.name() << "to" << invertedColor.name();
                QBrush b(additionalFormats[a].format.foreground());
                b.setColor(invertedColor);
                additionalFormats[a].format.setForeground(b);
            }
        }
    }

    for (int a = additionalFormats.size() - 1; a >= 0; --a) {
        if (additionalFormats[a].length == 0) {
            additionalFormats.removeAt(a);
        } else {
            ///For some reason the text-formats seem to be invalid in some way, sometimes
            ///@todo Fix this properly, it sucks not copying everything over
            QTextCharFormat fm;
            fm.setForeground(QBrush(additionalFormats[a].format.foreground().color()));
            fm.setBackground(additionalFormats[a].format.background());
            fm.setUnderlineStyle(additionalFormats[a].format.underlineStyle());
            fm.setUnderlineColor(additionalFormats[a].format.underlineColor());
            fm.setFontWeight(additionalFormats[a].format.fontWeight());
            additionalFormats[a].format = fm;
        }
    }

//   qCDebug(LOG_KTE) << "Highlights for text [" << text << "] col start " << m_currentColumnStart << ":";
//   foreach (const QTextLayout::FormatRange& fr, additionalFormats)
//     qCDebug(LOG_KTE) << fr.start << " len " << fr.length << "foreground" << fr.format.foreground() << "background" << fr.format.background();

    layout.setAdditionalFormats(additionalFormats);

    QTextOption to;

    to.setAlignment( static_cast<Qt::Alignment>(m_cachedAlignment | option.displayAlignment) );

    to.setWrapMode(QTextOption::WrapAnywhere);
    layout.setTextOption(to);

    layout.beginLayout();
    QTextLine line = layout.createLine();
    // Leave some extra space when the text is right-aligned
    line.setLineWidth(rect.width() - (option.displayAlignment == Qt::AlignRight ? 8 : 0));
    layout.endLayout();

    //We need to do some hand layouting here
    if (to.alignment() & Qt::AlignBottom) {
        layout.draw(painter, QPoint(rect.left(), rect.bottom() - (int)line.height()));
    } else {
        layout.draw(painter, rect.topLeft());
    }

    return;

    //if (painter->fontMetrics().width(text) > textRect.width() && !text.contains(QLatin1Char('\n')))
    //str = elidedText(option.fontMetrics, textRect.width(), option.textElideMode, text);
    //qt_format_text(option.font, textRect, option.displayAlignment, str, 0, 0, 0, 0, painter);
}
示例#10
0
void ScummEngine_v71he::o71_kernelSetFunctions() {
	int args[29];
	int num;
	ActorHE *a;

	num = getStackList(args, ARRAYSIZE(args));

	switch (args[0]) {
	case 1:
		// Used to restore images when decorating cake in
		// Fatty Bear's Birthday Surprise
		virtScreenLoad(args[1], args[2], args[3], args[4], args[5]);
		break;
	case 20: // HE72+
		a = (ActorHE *)derefActor(args[1], "o71_kernelSetFunctions: 20");
		queueAuxBlock(a);
		break;
	case 21:
		_skipDrawObject = 1;
		break;
	case 22:
		_skipDrawObject = 0;
		break;
	case 23:
		clearCharsetMask();
		_fullRedraw = true;
		break;
	case 24:
		_skipProcessActors = 1;
		redrawAllActors();
		break;
	case 25:
		_skipProcessActors = 0;
		redrawAllActors();
		break;
	case 26:
		a = (ActorHE *)derefActor(args[1], "o71_kernelSetFunctions: 26");
		a->_auxBlock.r.left = 0;
		a->_auxBlock.r.right = -1;
		a->_auxBlock.r.top = 0;
		a->_auxBlock.r.bottom = -2;
		break;
	case 30:
		a = (ActorHE *)derefActor(args[1], "o71_kernelSetFunctions: 30");
		a->_clipOverride.bottom = args[2];
		break;
	case 42:
		_wiz->_rectOverrideEnabled = true;
		_wiz->_rectOverride.left = args[1];
		_wiz->_rectOverride.top = args[2];
		_wiz->_rectOverride.right = args[3];
		_wiz->_rectOverride.bottom = args[4];
		adjustRect(_wiz->_rectOverride);
		break;
	case 43:
		_wiz->_rectOverrideEnabled = false;
		break;
	default:
		error("o71_kernelSetFunctions: default case %d (param count %d)", args[0], num);
	}
}
示例#11
0
void
InterfaceStatsScene::add (uint32_t nodeId, QString pointADescription, uint32_t otherNodeId, QString pointBDescription, QString linkDescription)
{
  if (!StatsMode::getInstance ()->isNodeActive (nodeId))
    {
      return;
    }
  if (!pointADescription.contains ("~"))
    {
      return;
    }
  showInfoWidget (false);
  QStringList parts = pointADescription.split ('~');
  //qDebug (pointADescription);
  QString IP = parts.at (0);
  //qDebug (IP);
  QString MAC = parts.at (1);
  QString otherIP = "";
  QString otherMAC = "";

  if (pointBDescription != "")
    {
      parts = pointBDescription.split ('~');
      otherIP = parts.at (0);
      otherMAC = parts.at (1);
    }

  QString title = "Node:" + QString::number (nodeId);
  QString content = "IP:" + IP ;
  content += "\nMAC:" + MAC ;

  if (pointBDescription != "")
    {
      content += "\nOther Node:" + QString::number (otherNodeId) ;
      content += "\nOther IP:" + otherIP;
      content += "\nOther MAC:" + otherMAC;
      content += "\nInfo:" + linkDescription;
    }
  TextBubble * tb = new TextBubble (title, content);
  QGraphicsProxyWidget * pw = addWidget (tb);
  QFont f (tb->font ());
  f.setPointSizeF (StatsMode::getInstance ()->getCurrentFontSize ());
  tb->setFont (f);
  QFontMetrics fm (f);
  pw->setMaximumHeight (fm.height () * tb->text ().count ("\n"));

  addToProxyWidgetsMap (nodeId, pw);
  qreal newX = m_lastX + pw->widget ()->width ();
  m_currentMaxHeight = qMax (m_currentMaxHeight, pw->size ().height ());
  if (newX >= sceneRect ().right ())
    {
      m_lastX = 0;
      m_lastY += m_currentMaxHeight + INTERSTATS_SPACE;
      m_currentMaxHeight = 0;
    }
  pw->setPos (m_lastX, m_lastY);
  m_lastX = pw->pos ().x () + pw->widget ()->width () + INTERSTATS_SPACE;
  m_lastY = pw->pos ().y ();
  m_bottomY = m_lastY + m_currentMaxHeight;
  //qDebug (QString ("Last X" + QString::number (m_lastX) + " w:" + QString::number (pw->widget ()->width ())));
  adjustRect ();

}