示例#1
0
void TBox::layout()
      {
      setPos(QPointF());      // !?
      bbox().setRect(0.0, 0.0, system()->width(), 0);
      _text->layout();

      qreal h = _text->height();
      if (_text->empty()) {
            QFontMetricsF fm = QFontMetricsF(_text->font(), MScore::paintDevice());
            h = fm.ascent();
            }
      else
            h = _text->height();
      qreal y = topMargin() * DPMM;
#if 0
      if (_text->align() & Align::BOTTOM)
            y += h;
      else if (_text->align() & Align::VCENTER)
            y +=  h * .5;
      else
            ; // y = 0;
#endif
      _text->setPos(leftMargin() * DPMM, y);
      h += topMargin() * DPMM + bottomMargin() * DPMM;
      bbox().setRect(0.0, 0.0, system()->width(), h);

      MeasureBase::layout();  // layout LayoutBreak's
      }
示例#2
0
void Program::setText(const QString &text)
{
    prepareGeometryChange();
    myText = text;
    myTitle = text;

    QFontMetricsF metrics = qApp->font();
    int textWidth = metrics.width(myText);
    int programWidth = myPosition.width();


        if (programWidth < 50){
         myText = "i";
         }

        textWidth = metrics.width(myText);
         if (textWidth > programWidth){
         while(textWidth > programWidth){
         myText.chop(1);
         textWidth = metrics.width(myText);
         }
         myText = myText + "...";
         }


    update();
}
QRectF DiasporaClusterGraphicsItem::getBoundingRect()
{

    QFont fontMain = DiasporaDefaultFonts::TitleFont(); // Preferences::prefs().fontAspectTitle();
    QFont fontStat = DiasporaDefaultFonts::BodyFont(); //Preferences::prefs().fontBody();

    QFontMetricsF fmMain = QFontMetrics(fontMain);
    QFontMetricsF fmStat = QFontMetrics(fontStat);

    float hMain = fmMain.height();
    float wMain = fmMain.width("AEIOUjZ");

    float hStat = fmStat.height();

    _initials = _clusterItem.name().left(3);

    float fTotHeight = (hMain + hStat *3) * 1.2;
    float fReference = wMain > fTotHeight ? wMain : fTotHeight;

    _size.setWidth(fReference);
    _size.setHeight(fReference);

    _corner.setX (_corner.x()-fReference/2);
    _corner.setY (_corner.y()-fReference/2);

    return QRectF (_corner, _size);

}
QRectF
dmz::QtCanvasObjectText::_outline_rect () const {

   QRectF rect;

   if (_text.length ()) {

      const int Padding (8);
      QFontMetricsF metrics = qApp->font ();

      rect.setSize (metrics.size (0, _text));

      if (_drawBackground) {

         rect.adjust (-Padding, -Padding, Padding, Padding);
      }

      if (_alignment == Qt::AlignLeft) {

         rect.translate (0, -rect.center ().y ());
      }
      else if (_alignment == Qt::AlignRight) {

         rect.translate (-rect.width (), -rect.center ().y ());
      }
      else {

         rect.translate (-rect.center ());
      }
   }

   return rect;
}
示例#5
0
文件: node.cpp 项目: Atronax/Planndo
// shape functions
QRectF Node::outline_rect() const
{
    QFontMetricsF metrics = qApp->fontMetrics();
    QRectF outline_rect = metrics.boundingRect(text);
    outline_rect.adjust(-iWidthPadding, -iHeightPadding, iWidthPadding, iHeightPadding);
    outline_rect.translate(-outline_rect.center());
    return outline_rect;
}
示例#6
0
QRectF usecaseclass::outlineRect() const
{
    const int Padding = 60;
    QFontMetricsF metrics = qApp->font();
    QRectF rect = metrics.boundingRect(myText);
    rect.adjust(-Padding, -Padding, +Padding, +Padding);
    rect.translate(-rect.center());
    return rect;
}
示例#7
0
文件: qnetwork.cpp 项目: petalgem/scn
QRectF QNodeItem::outlineRect() const
{
    const int Padding = 6;
    QFontMetricsF metrics = qApp->font();
    QRectF rect = metrics.boundingRect(text);
    rect.adjust(-Padding, -Padding, +Padding, +Padding);
    rect.translate(-rect.center());
    return rect;
}
示例#8
0
  //----------------------------------------------------------------
  // getElidedText
  //
  static QString
  getElidedText(double maxWidth,
                const Text & item,
                const QFontMetricsF & fm,
                int flags)
  {
    QString text = item.text_.get().toString();

    if (item.elide_ != Qt::ElideNone)
    {
      QString textElided = fm.elidedText(text, item.elide_, maxWidth, flags);
#if 0
      if (text != textElided)
      {
        std::cerr
          << "original: " << text.toUtf8().constData() << std::endl
          << "  elided: " << textElided.toUtf8().constData() << std::endl;
        YAE_ASSERT(false);
      }
#endif
      text = textElided;
    }

    return text;
  }
QString MLabelViewSimple::textToRender(const QSizeF &renderSize) const
{
    QString text = viewPrivate->model()->text();

    const QChar multiLengthSeparator(0x9c, 0);
    if (text.contains(multiLengthSeparator)) {
        // The text consists of several strings. Find the first string that fits into the
        // available width. If no string has been found, the last string will be used.
        const QStringList strings = text.split(multiLengthSeparator);
        const QFontMetricsF metrics(viewPrivate->controller->font());
        foreach (const QString &string, strings) {
            text = string;
            if (metrics.width(text) <= renderSize.width()) {
                break;
            }
        }
    }
示例#10
0
QRectF KateTextAnimation::rectForText()
{
  const QFontMetricsF fm = m_view->view()->renderer()->currentFontMetrics();
  const int lineHeight = m_view->view()->renderer()->lineHeight();
  QPoint pixelPos = m_view->cursorToCoordinate(m_range.start(), /*bool realCursor*/ true, /*bool includeBorder*/ false);

  if (pixelPos.x() == -1 || pixelPos.y() == -1) {
    return QRectF();
  } else {
    QRectF rect(pixelPos.x(), pixelPos.y(),
                fm.width(m_view->view()->doc()->text(m_range)), lineHeight);
    const QPointF center = rect.center();
    const qreal factor = 1.0 + 0.5 * m_value;
    rect.setWidth(rect.width() * factor);
    rect.setHeight(rect.height() * factor);
    rect.moveCenter(center);
    return rect;
  }
}
示例#11
0
 qreal LongestDayWidth(const QFontMetricsF& fm)
 {
     const KCalendarSystem* cal = KGlobal::locale()->calendar();
     qreal wd = 0;
     for (int i = 1; i <= 7; i++)
     {
         qreal w = fm.width(cal->weekDayName(i));
         if (w > wd)
             wd = w;
     }
     return wd;
 }
示例#12
0
void FadingMultilineLabel::positionLayouts()
{
	QFontMetricsF fm = fontMetrics();
	qreal lineHeight = fm.height();

	delete textLayout_;
	textLayout_ = 0;

	textLayout_ = new QTextLayout(text_, font());
	textLayout_->setTextOption(textOption_);
	// textLayout_->setAdditionalFormats(formats[p]);
	textLayout_->beginLayout();

	qreal x = 0.0;
	qreal y = 0.0;
	qreal ymax = 0.0;

	fadeOuts_.clear();
	QTextLine line = textLayout_->createLine();

	while (line.isValid()) {
		line.setPosition(QPointF(x, y));
		line.setLineWidth(width());

		if (line.naturalTextWidth() > width()) {
			fadeOuts_ << QRect(x, y, width(), lineHeight);
		}

		y += line.height();
		line = textLayout_->createLine();
	}

	textLayout_->endLayout();

	sizeHint_ = QSize(width(), y);
	updateGeometry();
}
void tst_QQuickTextMetrics::functionsWithArguments()
{
    QFETCH(QString, text);
    QFETCH(Qt::TextElideMode, mode);
    QFETCH(qreal, width);

    QQuickTextMetrics metrics;
    // Ensures that the values actually change.
    metrics.setText(text + "extra");
    metrics.setElideWidth(width + 1);
    switch (mode) {
        case Qt::ElideNone: metrics.setElide(Qt::ElideMiddle); break;
        case Qt::ElideLeft: metrics.setElide(Qt::ElideRight); break;
        case Qt::ElideMiddle: metrics.setElide(Qt::ElideNone); break;
        case Qt::ElideRight: metrics.setElide(Qt::ElideLeft); break;
    }

    QSignalSpy textSpy(&metrics, SIGNAL(textChanged()));
    QSignalSpy metricsSpy(&metrics, SIGNAL(metricsChanged()));
    metrics.setText(text);
    QCOMPARE(textSpy.count(), 1);
    QCOMPARE(metricsSpy.count(), 1);

    QSignalSpy elideSpy(&metrics, SIGNAL(elideChanged()));
    metrics.setElide(mode);
    QCOMPARE(elideSpy.count(), 1);
    QCOMPARE(metricsSpy.count(), 2);

    QSignalSpy elideWidthSpy(&metrics, SIGNAL(elideWidthChanged()));
    metrics.setElideWidth(width);
    QCOMPARE(elideWidthSpy.count(), 1);
    QCOMPARE(metricsSpy.count(), 3);

    QFontMetricsF expected = QFontMetricsF(QFont());

    QCOMPARE(metrics.elidedText(), expected.elidedText(text, mode, width, 0));
    QCOMPARE(metrics.advanceWidth(), expected.width(text));
    QCOMPARE(metrics.boundingRect(), expected.boundingRect(text));
    QCOMPARE(metrics.width(), expected.boundingRect(text).width());
    QCOMPARE(metrics.height(), expected.boundingRect(text).height());
    QCOMPARE(metrics.tightBoundingRect(), expected.tightBoundingRect(text));
}
示例#14
0
void Lyrics::layout1()
      {
      setPos(textStyle().offset(spatium()));
      Text::layout1();
      if (!parent()) // palette & clone trick
          return;

      ChordRest* cr = chordRest();
      const QList<Lyrics*>* ll = &(cr->lyricsList());

      qreal lh = lineSpacing() * score()->styleD(StyleIdx::lyricsLineHeight);
      int line = ll->indexOf(this);
      qreal y  = lh * line + point(score()->styleS(StyleIdx::lyricsDistance));
      qreal x  = 0.0;

      //
      // parse leading verse number and/or punctuation, so we can factor it into layout separately
      // TODO: provide a way to disable this
      //
      bool hasNumber = false; // _verseNumber;
      qreal adjust = 0.0;
      QString s = plainText(true);
      // find:
      // 1) string of numbers and non-word characters at start of syllable
      // 2) at least one other character (indicating start of actual lyric)
      QRegularExpression leadingPattern("(^[\\d\\W]+)([^\\d\\W]+)");
      QRegularExpressionMatch leadingMatch = leadingPattern.match(s);
      if (leadingMatch.hasMatch()) {
            // leading string
            QString s1 = leadingMatch.captured(1);
            // actual lyric
            //QString s2 = leadingMatch.captured(2);
            Text leading(*this);
            leading.setPlainText(s1);
            leading.layout1();
            adjust = leading.width();
            if (!s1.isEmpty() && s1[0].isDigit())
                  hasNumber = true;
            }

      if (textStyle().align() & AlignmentFlags::HCENTER) {
            //
            // center under notehead, not origin
            // however, lyrics that are melismas or have verse numbers will be forced to left alignment
            // TODO: provide a way to disable the automatic left alignment
            //
            qreal maxWidth;
            if (cr->type() == Element::Type::CHORD)
                  maxWidth = static_cast<Chord*>(cr)->maxHeadWidth();
            else
                  maxWidth = cr->width();       // TODO: exclude ledger line for multivoice rest?
            qreal nominalWidth = symWidth(SymId::noteheadBlack);
            if (!isMelisma() && !hasNumber)     // center under notehead
                  x +=  nominalWidth * .5 - cr->x() - adjust * 0.5;
            else                                // force left alignment
                  x += (width() + nominalWidth - maxWidth) * .5 - cr->x() - adjust;
            }
      else {
            // even for left aligned syllables, ignore leading verse numbers and/or punctuation
            x -= adjust;
            }

      rxpos() += x;
      rypos() += y;

      if (_ticks > 0 || _syllabic == Syllabic::BEGIN || _syllabic == Syllabic::MIDDLE) {
            if (_separator == nullptr) {
                  _separator = new LyricsLine(score());
                  _separator->setTick(cr->tick());
                  score()->addUnmanagedSpanner(_separator);
                  }
            _separator->setParent(this);
            _separator->setTick(cr->tick());
            _separator->setTrack(track());
            _separator->setTrack2(track());
#if defined(USE_FONT_DASH_METRIC)
            // if font parameters different from font cached values, compute new dash values from font metrics
            if (textStyle().family() != g_fontFamily && textStyle().size() != g_fontSize) {
                  QFontMetricsF     fm    = textStyle().fontMetrics(spatium());
                  QRectF            r     = fm.tightBoundingRect("\u2013");   // U+2013 EN DASH
                  g_cachedDashY           = _dashY          = r.y() + (r.height() * HALF);
                  g_cachedDashLength      = _dashLength     = r.width();
   #if defined(USE_FONT_DASH_TICKNESS)
                  g_cachedDashThickness   = _dashThickness  = r.height();
   #endif
                  g_fontFamily            = textStyle().family();
                  g_fontSize              = textStyle().size();
                  }
            // if same font, use cached values
            else {
                  _dashY                  = g_cachedDashY;
                  _dashLength             = g_cachedDashLength;
   #if defined(USE_FONT_DASH_TICKNESS)
                  _dashThickness          = g_cachedDashThickness;
   #endif
                  }
#endif
            }
      else
            if (_separator != nullptr) {
                  _separator->unchain();
                  delete _separator;
                  _separator = nullptr;
                  }
      }
示例#15
0
qreal Telegram::messageBodyTextWidth(qint64 id) const
{
    const QString & txt = messageBody(id);
    QFontMetricsF metric = QFontMetricsF( QFont() );
    return metric.width(txt);
}
示例#16
0
void TextObject::prepareLineInfos() const
{
	const TextSymbol* text_symbol = reinterpret_cast<const TextSymbol*>(symbol);
	
	double scaling = text_symbol->calculateInternalScaling();
	QFontMetricsF metrics = text_symbol->getFontMetrics();
	double line_spacing = text_symbol->getLineSpacing() * metrics.lineSpacing();
	double paragraph_spacing = scaling * text_symbol->getParagraphSpacing() + (text_symbol->hasLineBelow() ? (scaling * (text_symbol->getLineBelowDistance() + text_symbol->getLineBelowWidth())) : 0);
	double ascent = metrics.ascent();
	
	bool word_wrap = ! hasSingleAnchor();
	double box_width  = word_wrap ? (scaling * getBoxWidth())  : 0.0;
	double box_height = word_wrap ? (scaling * getBoxHeight()) : 0.0;
	
	int text_end = text.length();
	const QLatin1Char line_break('\n');
	const QLatin1Char part_break('\t');
	const QLatin1Char word_break(' ');
	
	line_infos.clear();
	
	// Initialize offsets
	
	double line_x = 0.0;
	if (h_align == TextObject::AlignLeft)
		line_x -= 0.5 * box_width;
	else if (h_align == TextObject::AlignRight)
		line_x += 0.5 * box_width;

	double line_y = 0.0;
	if (v_align == TextObject::AlignTop || v_align == TextObject::AlignBaseline)
		line_y += -0.5 * box_height;
	if (v_align != TextObject::AlignBaseline)
		line_y += ascent;
	
	// Determine lines and parts
	
	//double next_line_x_offset = 0; // to keep indentation after word wrap in a line with tabs
	int num_paragraphs = 0;
	int line_num = 0;
	int line_start = 0;
	while (line_start <= text_end) 
	{
		// Initialize input line
		double line_width = 0.0;
		int line_end = text.indexOf(line_break, line_start);
		if (line_end == -1)
			line_end = text_end;
		bool paragraph_end = true;
		
		std::vector<TextObjectPartInfo> part_infos;
		
		int part_start = line_start;
		double part_x = line_x;
		
		while (part_start <= line_end)
		{
			// Initialize part (sequence of letters terminated by tab or line break)
			int part_end = text.indexOf(part_break, part_start);
			if (part_end == -1)
				part_end = line_end;
			else if (part_end > line_end)
				part_end = line_end;
			
			if (part_start > 0 && text[part_start - 1] == part_break)
				part_x = line_x + text_symbol->getNextTab(part_x - line_x);
			
			QString part = text.mid(part_start, part_end - part_start);
			double part_width = metrics.boundingRect(part).width();
			
			if (word_wrap)
			{
				// shrink overflowing part to maximum possible size
				while (part_x + part_width - line_x > box_width)
				{
					// find latest possible break
					int new_part_end =  text.lastIndexOf(word_break, part_end - 1);
					if (new_part_end <= part_start)
					{
						// part won't fit
						if (part_start > line_start)
						{
							// don't put another part on this line
							part_end = part_start - 1;
							paragraph_end = false;
						}
						break;
					}
					
					paragraph_end = false;
					
					// Shrink the part and the line
					part_end = new_part_end;
					part = text.mid(part_start, part_end - part_start);
					part_width = metrics.width(part);
					line_end = part_end;
				}
			}
			if (part_end < part_start)
				break;
			
			// Add the current part
			part_infos.push_back( { part, part_start, part_end, part_x, metrics.width(part), metrics } );
			
			// Advance to next part position
			part_start = part_end + 1;
			part_x += part_width;
		}
		
		TextObjectPartInfo& last_part_info = part_infos.back();
		line_end   = last_part_info.end_index;
		line_width = last_part_info.part_x + last_part_info.width - line_x;
		
		// Jump over whitespace after the end of the line and check if it contains a newline character to determine if it is a paragraph end
		int next_line_start = line_end + 1;
		/*while (next_line_start < text.size() && (text[next_line_start] == line_break || text[next_line_start] == part_break || text[next_line_start] == word_break))
		{
			if (text[next_line_start - 1] == line_break)
			{
				paragraph_end = true;
				break;
			}
			++next_line_start;
		}*/
		
		line_infos.push_back( { line_start, line_end, paragraph_end, line_x, line_y, line_width, metrics.ascent(), metrics.descent(), part_infos } );
		
		// Advance to next line
		line_y += line_spacing;
		if (paragraph_end)
		{
			line_y += paragraph_spacing;
			num_paragraphs++;
		}
		line_num++;
		line_start = next_line_start;
	}
	
	// Update the line and part offset for every other alignment than top-left or baseline-left
	
	double delta_y = 0.0;
	if (v_align == TextObject::AlignBottom || v_align == TextObject::AlignVCenter)
	{
		int num_lines = getNumLines();
		double height = ascent + (num_lines - 1) * line_spacing + (num_paragraphs - 1) * paragraph_spacing;
		
		if (v_align == TextObject::AlignVCenter)
			delta_y = -0.5 * height;
		else if (v_align == TextObject::AlignBottom)
			delta_y = -height + 0.5 * box_height;
	}
	
	if (delta_y != 0.0 || h_align != TextObject::AlignLeft)
	{
		int num_lines = getNumLines();
		for (int i = 0; i < num_lines; i++)
		{
			TextObjectLineInfo* line_info = &line_infos[i];
			
			double delta_x = 0.0;
			if (h_align == TextObject::AlignHCenter)
				delta_x = -0.5 * line_info->width;
			else if (h_align == TextObject::AlignRight)
				delta_x -= line_info->width;
			
			line_info->line_x += delta_x;
			line_info->line_y += delta_y;
			
			int num_parts = line_info->part_infos.size();
			for (int j = 0; j < num_parts; j++)
			{
				line_info->part_infos.at(j).part_x += delta_x;
			}
		}
	}
}
QSizeF AdjustColumnRowManipulator::textSize(const QString& text, const Style& style) const
{
    QSizeF size;
    DummyWidget dummyWiget;
    const QFontMetricsF fontMetrics(style.font(), &dummyWiget);

    // Set size to correct values according to
    // if the text is horizontal, vertical or rotated.
    if (!style.verticalText() && !style.angle()) {
        // Horizontal text.

        size = fontMetrics.size(0, text);
        double offsetFont = 0.0;
        if ((style.valign() == Style::Bottom) && style.underline())
            offsetFont = fontMetrics.underlinePos() + 1;

        size.setHeight((fontMetrics.ascent() + fontMetrics.descent() + offsetFont)
                       *(text.count('\n') + 1));
    } else if (style.angle() != 0) {
        // Rotated text.

        const double height = fontMetrics.ascent() + fontMetrics.descent();
        const double width  = fontMetrics.width(text);
        size.setHeight(height * ::cos(style.angle() * M_PI / 180)
                       + qAbs(width * ::sin(style.angle() * M_PI / 180)));
        size.setWidth(qAbs(height * ::sin(style.angle() * M_PI / 180))
                      + width * ::cos(style.angle() * M_PI / 180));
    } else {
        // Vertical text.

        qreal width = 0.0;
        for (int i = 0; i < text.length(); i++)
            width = qMax(width, fontMetrics.width(text.at(i)));

        size.setWidth(width);
        size.setHeight((fontMetrics.ascent() + fontMetrics.descent())
                       * text.length());
    }
    return size;
}
示例#18
0
void VerticalViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	QRectF rect = boundingRect();

	QString symboldir = QString("%1/images").arg(ConfigParser::getInstance().envMapDir());
	QDir dir(symboldir);
	if (!dir.exists()) return;

	QPen pen(Qt::black);
	painter->setPen(pen);

	QFont font(qApp->font());
	font.setPointSize(9);
	font.setBold(true);
	painter->setFont(font);

	QFontMetricsF metrics = qApp->font();
	QRectF fontRect;
	int maxData = 0;
	if (mode == 0) {
		maxData = getMaxAlt() * 25;	// feet
	}else {
		maxData = getMaxAlt();
	}

	qDebug() << maxData;

	if (mode == 0) {			// Altitude

		// 고도의 max 값을 구한다.
		if (maxData < 6) {
			painter->drawText(QPoint(20,  20), "Altitude");
			painter->drawText(QPoint(20,  40), " (Feet)");
			painter->drawText(QPoint(20, 100), "       6");
			painter->drawText(QPoint(20, 190), "       5");
			painter->drawText(QPoint(20, 280), "       4");
			painter->drawText(QPoint(20, 370), "       3");
			painter->drawText(QPoint(20, 460), "       2");
			painter->drawText(QPoint(20, 550), "       1");
		}else {

			int size = (int)(maxData / 6);
			QString t1 = QString("%1").arg(QString("%1").arg(size),     -8, ' ');
			QString t2 = QString("%1").arg(QString("%1").arg(size * 2), -8, ' ');
			QString t3 = QString("%1").arg(QString("%1").arg(size * 3), -8, ' ');
			QString t4 = QString("%1").arg(QString("%1").arg(size * 4), -8, ' ');
			QString t5 = QString("%1").arg(QString("%1").arg(size * 5), -8, ' ');
			QString t6 = QString("%1").arg(QString("%1").arg(maxData), -8, ' ');

			painter->drawText(QPoint(20,  20), "Altitude");
			painter->drawText(QPoint(20,  40), " (Feet)");
			painter->drawText(QPoint(20, 100), t6);
			painter->drawText(QPoint(20, 190), t5);
			painter->drawText(QPoint(20, 280), t4);
			painter->drawText(QPoint(20, 370), t3);
			painter->drawText(QPoint(20, 460), t2);
			painter->drawText(QPoint(20, 550), t1);
		}
		fontRect = metrics.boundingRect("Altitude  ");

	}else if(mode == 1) {	// Speed
		if (maxData < 6) {
			painter->drawText(QPoint(20,  20), "   Speed");
			painter->drawText(QPoint(20,  40), "   (NM) ");
			painter->drawText(QPoint(20, 100), "       6");
			painter->drawText(QPoint(20, 190), "       5");
			painter->drawText(QPoint(20, 280), "       4");
			painter->drawText(QPoint(20, 370), "       3");
			painter->drawText(QPoint(20, 460), "       2");
			painter->drawText(QPoint(20, 550), "       1");
		}else {
			int size = (int)(maxData / 6);
			QString t1 = QString("%1").arg(QString("%1").arg(size),     -8, ' ');
			QString t2 = QString("%1").arg(QString("%1").arg(size * 2), -8, ' ');
			QString t3 = QString("%1").arg(QString("%1").arg(size * 3), -8, ' ');
			QString t4 = QString("%1").arg(QString("%1").arg(size * 4), -8, ' ');
			QString t5 = QString("%1").arg(QString("%1").arg(size * 5), -8, ' ');
			QString t6 = QString("%1").arg(QString("%1").arg(maxData), -8, ' ');

			painter->drawText(QPoint(20,  20), "   Speed");
			painter->drawText(QPoint(20,  40), "   (NM) ");
			painter->drawText(QPoint(20, 100), t6);
			painter->drawText(QPoint(20, 190), t5);
			painter->drawText(QPoint(20, 280), t4);
			painter->drawText(QPoint(20, 370), t3);
			painter->drawText(QPoint(20, 460), t2);
			painter->drawText(QPoint(20, 550), t1);
		}
		fontRect = metrics.boundingRect("Speed     ");
	}
	// 가로 / 세로 라인
	painter->drawLine(QPoint(fontRect.width()+cap, 20),  QPoint(fontRect.width()+cap, 640));
	painter->drawLine(QPoint(fontRect.width()+cap, 640), QPoint(widthDef+fontRect.width()+cap, 640));

	// 고도 라인
	pen.setStyle(Qt::DotLine);
	painter->setPen(pen);
	painter->drawLine(QPoint(fontRect.width()+cap, 100),QPoint(widthDef+fontRect.width()+cap, 100));
	painter->drawLine(QPoint(fontRect.width()+cap, 190),QPoint(widthDef+fontRect.width()+cap, 190));
	painter->drawLine(QPoint(fontRect.width()+cap, 280),QPoint(widthDef+fontRect.width()+cap, 280));
	painter->drawLine(QPoint(fontRect.width()+cap, 370),QPoint(widthDef+fontRect.width()+cap, 370));
	painter->drawLine(QPoint(fontRect.width()+cap, 460),QPoint(widthDef+fontRect.width()+cap, 460));
	painter->drawLine(QPoint(fontRect.width()+cap, 550),QPoint(widthDef+fontRect.width()+cap, 550));

	// Time 추출 - 타임 라인
	int timeCount = timeList.size();
	int lineWidth = (int)((widthDef-100)/timeCount);		// time pixel per line width
	int secWidth  = (int)(lineWidth/plus);						// 1 second per pixel
	int printWidth = lineWidth;

	//qDebug() << timeCount;
	for (int i=0; i<timeCount; i++) {
		// Time line 출력
		painter->drawLine(QPoint(fontRect.width()+cap+printWidth, 20),  QPoint(fontRect.width()+cap+printWidth, 640));
		painter->drawText(QPoint(fontRect.width()+printWidth, 640+15), timeList[i].toString("hh:mm:ss"));

		printWidth += lineWidth;
	}

	//qDebug() << "secWidth : " << secWidth << ", lineWidth : " << lineWidth;

	// 고도에 따른 트랙 출력
	QTime minTime = timeList.at(0);

	// 데이터 블록은 서로 겹쳐 보일 수 있으로 출력시 +- 80 으로 해서 지그재그로 보일 수 있도록 한다.
	int dataBlock = 80;
	int idx       = 0;

	for (int i=0; i<model.size(); i++) {
		// TrackDataModel
		//qDebug() << "dataModel size : " << model[i].dataModel.size();
		for (int j=0; j<model[i].dataModel.size(); j++) {
			//qDebug() << model[i].dataModel[j].occur_dt;

			if (mode == 0) {		// altitude
				if (model[i].dataModel[j].alt == 0) continue;		   // alt = 0 에 대해서 처리하지 않는다.
			}else if(mode == 1) {	// speed
				if (model[i].dataModel[j].spd == 0) continue;			// spd = 0 에 대해서 처리하지 않는다.
			}
			idx++;

			QString occur_dt = model[i].dataModel[j].occur_dt;		// datetime
			QString tm = occur_dt.right(8);
			QTime t = QTime::fromString(tm, "hh:mm:ss");
			int sec = minTime.secsTo(t);

			int secPixel = sec * secWidth;

			//qDebug() << "sec : " << sec << ", secPixel : " << secPixel;
			QString fullname;
			if (model[i].dataModel[j].psr == "0" && model[i].dataModel[j].ssr == "1") {       // PSR only
				fullname = QString("%1%2%3").arg(symboldir).arg(QDir::separator()).arg("psr_only.xpm");
			}else if (model[i].dataModel[j].psr == "1" && model[i].dataModel[j].ssr == "0") { // SSR only
				fullname = QString("%1%2%3").arg(symboldir).arg(QDir::separator()).arg("ssr_only.xpm");
			}else if(model[i].dataModel[j].cst == "1") {									// Coasting
				fullname = QString("%1%2%3").arg(symboldir).arg(QDir::separator()).arg("coasting_only.xpm");
			}else {
				fullname = QString("%1%2%3").arg(symboldir).arg(QDir::separator()).arg(model[i].symbol);
			}

			//QString fullname = QString("%1%2%3").arg(symboldir).arg(QDir::separator()).arg(model[i].symbol);
			QPixmap icon2;
			icon2.load(fullname);
			QPixmap icon = icon2.scaled(QSize(10, 10));

			QPixmap batang(QSize(icon.width()+1, icon.height()+1));
			batang.fill(QColor(0, 0, 0));

			QPainter pp(&batang);
			pp.drawPixmap(0, 0, icon);

			// 고도
			int alt = 0;

			if (mode == 0) {			// Altitude
				alt = model[i].dataModel[j].alt;				// unit = FL
				alt = alt * 25;	// 1FL = 25 ft
			}else if(mode == 1) {	// Speed
				alt = (int)model[i].dataModel[j].spd;		// unit = NM
			}

			int fixel = 0;

			if (mode == 0) {			// Altitude
				// max 고도에서 640을 나눈 값을 곱한다.
				double s = 544.0 / maxData;
				// 1ft = 0.018 fixel
				fixel = (int)(s * alt);	// 고도 대 픽셀 위치

				qDebug() << "s : " << s << ", fixel : " << fixel;
			}else if(mode == 1) {	// Speed
				double s = 544.0 / maxData;
				fixel = (int)(s * alt);	   // 속도 대 픽셀 위치
			}

			painter->drawPixmap(QPoint(fontRect.width()+18+lineWidth+secPixel, 640 - fixel), batang);

			// Altitude와 Speed가 같다면 계속적으로 데이터 블럭을 표현할 필요가 없다.
			if (model[i].dataModel[j].alt == model[i].dataModel[j].prev_alt
					&& model[i].dataModel[j].spd == model[i].dataModel[j].prev_spd) {
				continue;
			}

			// 데이터 블럭 출력 옵션에 따라서 출력한다.
			if (rptOption->blockCount > 0) {
				if ((j+1) != 1) {		// first data
					//qDebug() << "blockCount : " << rptOption->blockCount;
					//qDebug() << "myNumber   : " << (j+1);
					//qDebug() << "cal        : " << ((j+1) / rptOption->blockCount);
					if ((j+1) % rptOption->blockCount != 0) {
						continue;
					}
				}
			}

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			// Data block define
			QPen pen(Qt::black);
			QColor textColor = Qt::black;
			painter->setPen(pen);
			if (idx%2) {
				dataBlock = -40;
			}else {
				dataBlock = +80;
			}


			QString msg = "";
			//////////////////////////////////////////////////////////////
			// 경보 상태가 있다면...

			//////////////////////////////////////////////////////////////
			int found = 0;
			int tmpHeight = 15;
			if (rptOption->trackNumber && model[i].dataModel[j].type == 0) {	// track data
				msg += QString("%1").arg(model[i].trackNo);
			}else {
				msg += "     ";
			}
			if (rptOption->ssr && model[i].dataModel[j].type == 0) {		// ReportOption check
				msg += QString("/%1").arg(model[i].ssr)+"\n";
			}else {
				msg += "    \n";
			}
			tmpHeight += 15;

			// 하강, 상승
			QString climb;
			if (model[i].dataModel[j].climb > 0) {		// 상승
				climb = "^";
			}else if(model[i].dataModel[j].climb == 0) {  // 수평비행
				climb = "-";
			}else {
				climb = "V";
			}
			QString cfl;
			if (model[i].dataModel[j].cfl == 0) {
				cfl = "";
			}else {
				cfl = QString("%1").arg(model[i].dataModel[j].cfl);
			}
			// 고도 | 상승,하강 | 배정고도 | 속도
			found = 0;
			QString tmp = "";
			if (rptOption->modec) {
				msg += QString("%1 %2 ").arg(model[i].dataModel[j].alt).arg(climb);
				found = 1;
			}else {
				msg += "    ";
			}
			if (rptOption->assignedFL && model[i].dataModel[j].type == 0) {
				msg += QString( "%1 ").arg(cfl);
				found = 1;
			}else {
				msg += "   ";
			}
			if (rptOption->velocity) {
				msg += QString(" /%1 \n").arg((int)model[i].dataModel[j].spd);
				found = 1;
			}else {
				msg += " /  \n";
			}
			tmpHeight += 15;
			QString callsign = model[i].callsign;
			if (callsign != "" && rptOption->callsing) {
				msg += callsign  + "/ ";  // + QString(" %1").arg(airplane->getTrackData().wt_type);
			}

	//		// 기종과 목적 공항
	//		if (!airplane->getTrackData().actp.trimmed().isEmpty() && airplane->getTrackData().type == 0) {
	//			if (airplane->getReportOption()->trackNumber || callsign != "" && airplane->getReportOption()->callsing || found == 1) {
	//				msg += "\n";
	//			}
	//			msg += QString("%1     %2").arg(airplane->getTrackData().actp).arg(airplane->getTrackData().arr_ad);
	//			found = 2;
	//			tmpHeight += 15;
	//		}


			tmpHeight += 5;

			QRectF rect(
							QPointF(fontRect.width()+18+lineWidth+secPixel - 45, 640 - fixel - 50+dataBlock),
							QSizeF(100, tmpHeight));

			painter->drawRect(rect);
			painter->setPen(textColor);
			painter->drawText(rect, Qt::AlignCenter, msg);

			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			// Line
			int dim1 = 5;
			int dim2 = -10;
			painter->setPen(pen);

			if (idx%2) {
				painter->drawLine(QLineF(QPointF(fontRect.width()+18+lineWidth+secPixel+dim1,  640 - fixel - 50+dataBlock + 50),
						QPointF(fontRect.width()+18+lineWidth+secPixel+dim1, 640 - fixel - dim2)));
			}else {
				painter->drawLine(QLineF(QPointF(fontRect.width()+18+lineWidth+secPixel+dim1,  640 - fixel - 50+dataBlock ),
						QPointF(fontRect.width()+18+lineWidth+secPixel+dim1, 640 - fixel - dim2)));
			}
		}
	}

}
示例#19
0

void QgsDecorationTitle::render( const QgsMapSettings &mapSettings, QgsRenderContext &context )
{
  Q_UNUSED( mapSettings )
  if ( !enabled() )
    return;

  context.painter()->save();
  context.painter()->setRenderHint( QPainter::Antialiasing, true );

  QString displayString = QgsExpression::replaceExpressionText( mLabelText, &context.expressionContext() );
  QStringList displayStringList = displayString.split( '\n' );

  QFontMetricsF fm( mTextFormat.scaledFont( context ) );
  QFontMetricsF textMetrics = QgsTextRenderer::fontMetrics( context, mTextFormat );
  double textDescent = textMetrics.descent();
  double textWidth = QgsTextRenderer::textWidth( context, mTextFormat, displayStringList, &fm );
  double textHeight = QgsTextRenderer::textHeight( context, mTextFormat, displayStringList, QgsTextRenderer::Point, &fm );

  QPaintDevice *device = context.painter()->device();
  int deviceHeight = device->height() / device->devicePixelRatioF();
  int deviceWidth = device->width() / device->devicePixelRatioF();

  float xOffset( 0 ), yOffset( 0 );

  // Set  margin according to selected units
  switch ( mMarginUnit )
  {
    case QgsUnitTypes::RenderMillimeters:
    {
void DiasporaClusterGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QColor borderColor = QColor(192,192,192);
    QColor starColor = QColor (255,255,192);
    QColor techColor = QColor (255,255,0);
    QColor textColor = QColor(0,0,0);
    QColor borderSelectedColor = QColor(255,0,0);

    QBrush starBrush = QBrush(starColor,Qt::SolidPattern);
    QBrush techBrush = QBrush(techColor,Qt::SolidPattern);
    QBrush textBrush = QBrush(textColor, Qt::SolidPattern);

    QPen borderPen;

    if (!this->isSelected()) {
        borderPen= QPen(borderColor);
        borderPen.setWidthF(2.0);
    } else {
        borderPen= QPen(borderSelectedColor);
        borderPen.setWidthF(2.0);

    }

    QPen textPen = QPen(textColor);

    painter->setPen(borderPen);
    painter->setBrush(_clusterItem.technology() >= 2 ? techBrush : starBrush);

    QRectF boundingRect = this->boundingRect();

    painter->drawEllipse(boundingRect);

    QFont fontMain = DiasporaDefaultFonts::TitleFont(); //Preferences::prefs().fontAspectTitle();
    QFont fontStat = DiasporaDefaultFonts::BodyFont();// Preferences::prefs().fontBody();

    QFontMetricsF fmMain = QFontMetrics(fontMain);
    QFontMetricsF fmStat = QFontMetrics(fontStat);

    float hMain = fmMain.height() * 1.1;
    float wMain = fmMain.width(_initials);

    QString t1 = QString("Env: %1")
                 .arg(_clusterItem.environment());
    QString t2 = QString("Tech: %1").arg(_clusterItem.technology());
    QString t3 = QString("Res: %1").arg(_clusterItem.resources());


    float hStat = fmStat.height() * 1.1;
    float w1 = fmStat.width(t1);
    float w2 = fmStat.width(t2);
    float w3 = fmStat.width(t3);

    float wRect = boundingRect.width();

    wMain = (wRect- wMain)/2;
    w1 = (wRect- w1)/2;
    w2 = (wRect- w2)/2;
    w3 = (wRect- w3)/2;


    QPoint p1 = QPoint (_corner.x()+wMain, boundingRect.top()+hMain);
    QPoint p2 = QPoint (_corner.x()+w1, _corner.y()+hMain+hStat);
    QPoint p3 = QPoint (_corner.x()+w2, _corner.y()+hMain+2*hStat);
    QPoint p4 = QPoint (_corner.x()+w3, _corner.y()+hStat*3+hMain);

    painter->setFont(fontMain);
    painter->setBrush(textBrush);
    painter->setPen(textPen);
    painter->drawText(p1,_initials );
    painter->setFont(fontStat);
    painter->drawText(p2,t1 );
    painter->drawText(p3,t2 );
    painter->drawText(p4,t3 );

    //painter->setPen(borderPen);
    //painter->drawPoint(QPointF(_x,_y));

}