• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ QFontMetrics函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中QFontMetrics函数的典型用法代码示例。如果您正苦于以下问题:C++ QFontMetrics函数的具体用法?C++ QFontMetrics怎么用?C++ QFontMetrics使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了QFontMetrics函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: WiresharkDialog

SequenceDialog::SequenceDialog(QWidget &parent, CaptureFile &cf, seq_analysis_info_t *sainfo) :
    WiresharkDialog(parent, cf),
    ui(new Ui::SequenceDialog),
    sainfo_(sainfo),
    num_items_(0),
    packet_num_(0),
    node_label_w_(20)
{
    ui->setupUi(this);
    QCustomPlot *sp = ui->sequencePlot;
    setWindowSubtitle(sainfo ? tr("Call Flow") : tr("Flow"));

    if (!sainfo_) {
        sainfo_ = sequence_analysis_info_new();
        sainfo_->type = SEQ_ANALYSIS_ANY;
        sainfo_->all_packets = TRUE;
    } else {
        num_items_ = sequence_analysis_get_nodes(sainfo_);
    }

    seq_diagram_ = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2);
    sp->addPlottable(seq_diagram_);
    sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis);

    sp->xAxis->setVisible(false);
    sp->xAxis->setPadding(0);
    sp->xAxis->setLabelPadding(0);
    sp->xAxis->setTickLabelPadding(0);
    sp->xAxis2->setVisible(true);
    sp->yAxis2->setVisible(true);

    one_em_ = QFontMetrics(sp->yAxis->labelFont()).height();
    ui->horizontalScrollBar->setSingleStep(100 / one_em_);
    ui->verticalScrollBar->setSingleStep(100 / one_em_);

    sp->setInteractions(QCP::iRangeDrag);

    ui->gridLayout->setSpacing(0);
    connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), sp->yAxis2, SLOT(setRange(QCPRange)));

    ctx_menu_.addAction(ui->actionReset);
    ctx_menu_.addSeparator();
    ctx_menu_.addAction(ui->actionMoveRight10);
    ctx_menu_.addAction(ui->actionMoveLeft10);
    ctx_menu_.addAction(ui->actionMoveUp10);
    ctx_menu_.addAction(ui->actionMoveDown10);
    ctx_menu_.addAction(ui->actionMoveRight1);
    ctx_menu_.addAction(ui->actionMoveLeft1);
    ctx_menu_.addAction(ui->actionMoveUp1);
    ctx_menu_.addAction(ui->actionMoveDown1);
    ctx_menu_.addSeparator();
    ctx_menu_.addAction(ui->actionGoToPacket);

    ui->showComboBox->blockSignals(true);
    ui->showComboBox->setCurrentIndex(0);
    ui->showComboBox->blockSignals(false);
    ui->addressComboBox->blockSignals(true);
    ui->addressComboBox->setCurrentIndex(0);
    ui->addressComboBox->blockSignals(false);

    QComboBox *fcb = ui->flowComboBox;
    fcb->addItem(ui->actionFlowAny->text(), SEQ_ANALYSIS_ANY);
    fcb->addItem(ui->actionFlowTcp->text(), SEQ_ANALYSIS_TCP);

    ui->flowComboBox->blockSignals(true);
    ui->flowComboBox->setCurrentIndex(sainfo_->type);

    if (sainfo_->type == SEQ_ANALYSIS_VOIP) {
        ui->controlFrame->hide();
    } else {
        ui->flowComboBox->blockSignals(false);
    }

    QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save);
    save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS));

    // XXX Use recent settings instead
    resize(parent.width(), parent.height() * 4 / 5);

    connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(hScrollBarChanged(int)));
    connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vScrollBarChanged(int)));
    connect(sp->xAxis2, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange)));
    connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange)));
    connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(diagramClicked(QMouseEvent*)));
    connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*)));
    connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*)));
    connect(this, SIGNAL(goToPacket(int)), seq_diagram_, SLOT(setSelectedPacket(int)));

    disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));

    fillDiagram();
}
开发者ID:JunichiWatanuki,项目名称:wireshark,代码行数:92,代码来源:sequence_dialog.cpp


示例2: status_font

void DeviceItemDelegate::paint(QPainter* p, const QStyleOptionViewItem& opt, const QModelIndex& index) const {
  // Is it a device or a library item?
  if (index.data(DeviceManager::Role_State).isNull()) {
    LibraryItemDelegate::paint(p, opt, index);
    return;
  }

  // Draw the background
  const QStyleOptionViewItemV3* vopt = qstyleoption_cast<const QStyleOptionViewItemV3*>(&opt);
  const QWidget* widget = vopt->widget;
  QStyle* style = widget->style() ? widget->style() : QApplication::style();
  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, p, widget);

  p->save();

  // Font for the status line
  QFont status_font(opt.font);

#ifdef Q_OS_WIN32
  status_font.setPointSize(status_font.pointSize() - 1);
#else
  status_font.setPointSize(status_font.pointSize() - 2);
#endif

  const int text_height = QFontMetrics(opt.font).height() +
                          QFontMetrics(status_font).height();

  QRect line1(opt.rect);
  QRect line2(opt.rect);
  line1.setTop(line1.top() + (opt.rect.height() - text_height) / 2);
  line2.setTop(line1.top() + QFontMetrics(opt.font).height());
  line1.setLeft(line1.left() + DeviceManager::kDeviceIconSize + kIconPadding);
  line2.setLeft(line2.left() + DeviceManager::kDeviceIconSize + kIconPadding);

  // Change the color for selected items
  if (opt.state & QStyle::State_Selected) {
    p->setPen(opt.palette.color(QPalette::HighlightedText));
  }

  // Draw the icon
  p->drawPixmap(opt.rect.topLeft(), index.data(Qt::DecorationRole).value<QPixmap>());

  // Draw the first line (device name)
  p->drawText(line1, Qt::AlignLeft | Qt::AlignTop, index.data().toString());

  // Draw the second line (status)
  DeviceManager::State state =
      static_cast<DeviceManager::State>(index.data(DeviceManager::Role_State).toInt());
  QVariant progress = index.data(DeviceManager::Role_UpdatingPercentage);
  QString status_text;

  if (progress.isValid()) {
    status_text = tr("Updating %1%...").arg(progress.toInt());
  } else {
    switch (state) {
      case DeviceManager::State_Remembered:
        status_text = tr("Not connected");
        break;

      case DeviceManager::State_NotMounted:
        status_text = tr("Not mounted - double click to mount");
        break;

      case DeviceManager::State_NotConnected:
        status_text = tr("Double click to open");
        break;

      case DeviceManager::State_Connected: {
        QVariant song_count = index.data(DeviceManager::Role_SongCount);
        if (song_count.isValid()) {
          int count = song_count.toInt();
          if (count == 1) // TODO: Fix this properly
            status_text = tr("%1 song").arg(count);
          else
            status_text = tr("%1 songs").arg(count);
        } else {
          status_text = index.data(DeviceManager::Role_MountPath).toString();
        }
        break;
      }
    }
  }

  if (opt.state & QStyle::State_Selected)
    p->setPen(opt.palette.color(QPalette::HighlightedText));
  else
    p->setPen(opt.palette.color(QPalette::Dark));
  p->setFont(status_font);
  p->drawText(line2, Qt::AlignLeft | Qt::AlignTop, status_text);

  p->restore();
}
开发者ID:BrummbQ,项目名称:Clementine,代码行数:92,代码来源:deviceview.cpp


示例3: QWidget

PreFlightMiscPage::PreFlightMiscPage(QWidget *parent) :
  QWidget(parent)
{
  setObjectName("PreFlightMiscPage");
  setWindowFlags( Qt::Tool );
  setWindowModality( Qt::WindowModal );
  setAttribute(Qt::WA_DeleteOnClose);
  setWindowTitle( tr("PreFlight - Common") );

  if( parent )
    {
      resize( parent->size() );
    }

  // Layout used by scroll area
  QHBoxLayout *sal = new QHBoxLayout;

  // new widget used as container for the dialog layout.
  QWidget* sw = new QWidget;

  // Scroll area
  QScrollArea* sa = new QScrollArea;
  sa->setWidgetResizable( true );
  sa->setFrameStyle( QFrame::NoFrame );
  sa->setWidget( sw );

#ifdef QSCROLLER
  QScroller::grabGesture( sa->viewport(), QScroller::LeftMouseButtonGesture );
#endif

#ifdef QTSCROLLER
  QtScroller::grabGesture( sa->viewport(), QtScroller::LeftMouseButtonGesture );
#endif

  // Add scroll area to its own layout
  sal->addWidget( sa );

  QHBoxLayout *contentLayout = new QHBoxLayout(this);

  // Pass scroll area layout to the content layout.
  contentLayout->addLayout( sal, 10 );

  // Top layout's parent is the scroll widget
  QGridLayout *topLayout = new QGridLayout(sw);

  int row = 0;

  QLabel *lbl = new QLabel(tr("Minimal arrival altitude:"));
  topLayout->addWidget(lbl, row, 0);

  // get current set altitude unit. This unit must be considered during
  // storage. The internal storage is always in meters.
  m_altUnit = Altitude::getUnit();

  // Input accept only feet and meters all other make no sense. Therefore all
  // other (FL) is treated as feet.
  m_edtMinimalArrival = new NumberEditor;
  m_edtMinimalArrival->setDecimalVisible( false );
  m_edtMinimalArrival->setPmVisible( false );
  m_edtMinimalArrival->setRange( 0, 9999);
  m_edtMinimalArrival->setMaxLength(4);
  m_edtMinimalArrival->setSuffix(" " + Altitude::getUnitText());

  QRegExpValidator* eValidator = new QRegExpValidator( QRegExp( "([0-9]{1,4})" ), this );
  m_edtMinimalArrival->setValidator( eValidator );

  int maw = QFontMetrics(font()).width("9999 ft") + 10;
  m_edtMinimalArrival->setMinimumWidth( maw );

  topLayout->addWidget(m_edtMinimalArrival, row, 1);
  topLayout->setColumnStretch(2, 2);
  row++;

  lbl = new QLabel(tr("Arrival altitude display:"));
  topLayout->addWidget(lbl, row, 0);
  m_edtArrivalAltitude = new QComboBox;
  m_edtArrivalAltitude->addItem( tr("Landing Target"), GeneralConfig::landingTarget );
  m_edtArrivalAltitude->addItem( tr("Next Target"), GeneralConfig::nextTarget );
  topLayout->addWidget(m_edtArrivalAltitude, row, 1);
  row++;

  lbl = new QLabel(tr("QNH:"));
  topLayout->addWidget(lbl, row, 0);

  m_edtQNH = new NumberEditor;
  m_edtQNH->setDecimalVisible( false );
  m_edtQNH->setPmVisible( false );
  m_edtQNH->setRange( 0, 9999);
  m_edtQNH->setMaxLength(4);
  m_edtQNH->setSuffix(" hPa");

  eValidator = new QRegExpValidator( QRegExp( "([0-9]{1,4})" ), this );
  m_edtQNH->setValidator( eValidator );

  int mqw = QFontMetrics(font()).width("9999 hPa") + 10;
  m_edtQNH->setMinimumWidth( mqw );

  topLayout->addWidget(m_edtQNH, row, 1);
  row++;

//.........这里部分代码省略.........
开发者ID:Exadios,项目名称:Cumulus,代码行数:101,代码来源:preflightmiscpage.cpp


示例4: QPrinter

void clsImprimirVehiculos::ImprimirLista(QString strFiltro)
{
    printer = new QPrinter(QPrinter::PrinterResolution);
    printer->setPageSize(QPrinter::A4);

    QPrintDialog printDialog(printer);

    if (printDialog.exec())
    {
        printer->setPageMargins(20,20,15,20,QPrinter::Millimeter);

        QPainter painter(printer);
        painter.setRenderHint(QPainter::Antialiasing);
        QList<QStringList> pages;
        penInicial = painter.pen();
        brushInicial = painter.brush();
        fuenteInicial = painter.font();
        fuenteTitulo = painter.font();
        fuenteMedTitulo = painter.font();
        fuenteNegrita = painter.font();
        fuenteTitulo.setPointSize(20);
        fuenteNegrita.setBold(true);
        fuenteTitulo.setBold(true);
        fuenteMedTitulo.setBold(true);
        fuenteMedTitulo.setPointSize(15);
        fuenteNegrita.setPointSize(10);
        fuenteInicial.setPointSize(10);

        AnchoMat = 0;

        QStringList listaEntradas;
        QString entrada;

        clsVehiculos Vehiculo;
        QVector<QStringList> listaVehiculos = Vehiculo.ListaVehiculos(strFiltro);

        for (int i=0;i<listaVehiculos.size();i++)
        {
            QStringList strVehiculos = listaVehiculos.at(i);

            if (AnchoMat < QFontMetrics(fuenteInicial).width(strVehiculos.at(0)))
                AnchoMat = QFontMetrics(fuenteInicial).width(strVehiculos.at(0));

            entrada = strVehiculos.at(0) + "-|-" + strVehiculos.at(1) + "-|-" + strVehiculos.at(2) + "-|-" + strVehiculos.at(3);

            listaEntradas << entrada;
        }

        maxAlt = painter.window().height();
        maxAnch = painter.window().width();
        Espacio = (maxAlt*3)/257;

        titulo = QObject::tr("Listado de Vehículos");

        rectTitulo = QRect(0,0,maxAnch,(maxAlt*15)/257);
        rectFecha = QRect(0,0,maxAnch,(maxAlt*5)/257);
        rectPie = QRect(0,0,maxAnch,(maxAlt*5)/257);

        painter.setFont(fuenteNegrita);

        rectCabecera = QRect(0,0,maxAnch,QFontMetrics(painter.font()).height()+(maxAlt/257));

        rectfuenteNegrita = QRect(0,0,maxAnch,QFontMetrics(painter.font()).height()+(maxAlt/257));

        AnchoMat = qMax(AnchoMat,QFontMetrics(painter.font()).width(QObject::tr("Código")));
        AnchoFMat = QFontMetrics(painter.font()).width(QObject::tr("Fecha Matricula"));
        AnchoCol = (maxAnch - (AnchoMat + AnchoFMat + 3*Espacio))/2;

        painter.setFont(fuenteInicial);

        rectfuenteInicial = QRect(0,0,maxAnch,QFontMetrics(painter.font()).height()+(maxAlt/257));

        maxAltDispo = maxAlt - (rectTitulo.height()+rectFecha.height()+rectPie.height()+rectCabecera.height());

        colorLinea=0;

        yLinea = 0;

        DividirEnPaginasLV(&painter,&pages,listaEntradas);
        ImprimirPaginasLV(&painter,pages);
    }
}
开发者ID:moichm,项目名称:Almacen_v2,代码行数:82,代码来源:clsimprimirvehiculos.cpp


示例5: p

void WidgetTimeCoursePlot::paintEvent(QPaintEvent *e)
{
  QPainter p(this);
  QRectF rc_plot = rect();
  int nMargin = 10;
  rc_plot.adjust(nMargin, nMargin, -nMargin, -nMargin);
  rc_plot.adjust(15, 15, -25, -27);

  if (m_data.isEmpty())
  {
    p.fillRect(rc_plot, Qt::black);
    return;
  }

  QFont fnt = font();
  fnt.setPixelSize(11);
  int nTextLen = qMax(QFontMetrics(fnt).width(QString::number(m_dMax)),
                      QFontMetrics(fnt).width(QString::number(m_dMin)));
  rc_plot.adjust(nTextLen+6, 0, 0, 0);
  p.fillRect(rc_plot.adjusted(-1, -1, 1, 1), Qt::black);

  double dMin = m_dMin, dMax = m_dMax;
  if (m_bAutoScale)
  {
    dMin = dMax = m_data[0];
    for (int i = 1; i < m_data.size(); i++)
    {
      if (dMin > m_data[i])
        dMin = m_data[i];
      else if (dMax < m_data[i])
        dMax = m_data[i];
    }
    dMax += (dMax-dMin)/4;
    double old_min = dMin;
    dMin -= (dMax-dMin)/4;
    if (dMin < 0 && old_min >= 0)
      dMin = 0;
  }
  if (dMin == dMax)
    dMax += 1;
  double dSpacing = rc_plot.width() / (m_data.size()-1);
  p.setRenderHint(QPainter::Antialiasing);
  QPointF* pts = new QPointF[m_data.size()];
  for (int i = 0; i < m_data.size(); i++)
  {
    pts[i] = QPointF(rc_plot.left() + dSpacing*i,
                     rc_plot.bottom() - (m_data[i]-dMin)/(dMax-dMin)*rc_plot.height());
  }
  p.setPen(QPen(QBrush(Qt::yellow), 2));
  p.drawPolyline(pts, m_data.size());

  // draw cursor
  p.setPen(QPen(QBrush(Qt::red), 2));
  p.drawLine(pts[m_nCurrentFrame] - QPointF(0, 20),
             pts[m_nCurrentFrame] + QPointF(0, qMin(20., rc_plot.bottom()-pts[m_nCurrentFrame].y())));
  delete[] pts;

  // draw Y metrics
  p.setPen(QPen(Qt::black));
  p.setFont(fnt);
  double nMetricInterval = 30;
  double dMetricStep =  (dMax - dMin) / (rc_plot.height() / nMetricInterval);
  dMetricStep = MyUtils::RoundToGrid( dMetricStep );
  double dMetricPos = (int)(dMin/dMetricStep)*dMetricStep;
  double y = rc_plot.bottom()-(dMetricPos-dMin)/(dMax-dMin)*rc_plot.height();
  while (y > rc_plot.top())
  {
    if (y <= rc_plot.bottom())
    {
      QString strg = QString::number(dMetricPos);
      p.drawText(QRectF(rect().left(), y-10, rc_plot.left()-5-rect().left(), 20),
                 Qt::AlignVCenter | Qt::AlignRight, strg);
    }
    dMetricPos += dMetricStep;
    y = rc_plot.bottom()-(dMetricPos-dMin)/(dMax-dMin)*rc_plot.height();
  }

  p.save();
  p.translate(0, rc_plot.top()+rc_plot.height()/2);
  p.rotate(-90);
  p.drawText(QRect(-100, 0, 200, 20), Qt::AlignCenter, "Signal Intensity");
  p.restore();

  // draw X metrics
  nMetricInterval = 50;
  double dTR = 1; // m_dTR;
  dMetricStep =  (m_data.size()-1)*dTR / (rc_plot.width() / nMetricInterval);
  dMetricStep = MyUtils::RoundToGrid( dMetricStep );
  dMetricPos = 0;
  double x = rc_plot.left();
  while (x < rc_plot.right())
  {
    QString strg = QString::number(dMetricPos);
    p.drawText(QRectF(x-100, rc_plot.bottom()+5, 200, 20),
               Qt::AlignTop | Qt::AlignHCenter, strg);

    dMetricPos += dMetricStep;
    x = rc_plot.left() + dMetricPos/((m_data.size()-1)*dTR)*rc_plot.width();
  }

//.........这里部分代码省略.........
开发者ID:neurodebian,项目名称:freesurfer,代码行数:101,代码来源:WidgetTimeCoursePlot.cpp


示例6: geometry

void
MenuItem::drawLabel( QPainter* p )
{
	RasterOp origRasterOp = p->rasterOp();
	if( m_mouseOver )
	{
// 		p->setRasterOp( OrROP );
	}
	// Prepare the title and desc
	
	// This is the available width that we can print text. This is the place just next to the pixmap
	uint availableWidth = geometry().width() - ( 2 * m_offset ) - pixmap()->width() - ( 4 * m_secOffset );
	
	// If there's a sub menu we'll draw an arrow in this button, so texts area gets smaller
	if( m_sub )
		availableWidth -= KGlobal::iconLoader()->loadIcon( m_arrowIcon, KIcon::Toolbar ).width() - m_secOffset;
	
	// Titles will be printed in one line definetely, so squeze it to fit
	QString s_title = KStringHandler::rPixelSqueeze( title(), p->fontMetrics(), availableWidth );

	// Draw the icon
	p->drawPixmap( m_offset + m_secOffset,
				   m_offset + m_secOffset,
				   *pixmap() );

	if( !description().isNull() )
	{
		// Write the description with smaller font
		QFont smallerFont = p->font();
	
		// Make the font smaller by m_descFontOffset points
		smallerFont.setPointSize( smallerFont.pointSize() - m_descFontOffset );

		////// MOVE LINE SPLICING CODE TO ABOVE
		// Let's see if we can use more than one line, because descriptions
		// are more likely to be longer
		
		// Active area height = total widget height - 2 * primary offset
		int activeAreaHeight = geometry().height() - 2 * m_offset;
		// Available desc height = Active area height - title height
		int availableDescHeight = activeAreaHeight - p->fontMetrics().height();
		// One desc line height
		int descLineHeight = QFontMetrics( smallerFont ).height();
		// Let's see how many desc lines are available
		int lineCount =  availableDescHeight / descLineHeight;

		// Prepare each line of text
		QString desc = description().stripWhiteSpace();
		QString line = desc;
		QStringList lines;

		if( lineCount > 1 )
		{
			for( int j = 0; j < lineCount; j++ )
			{
				uint size = QFontMetrics( smallerFont ).width( desc );
	
				if( ( j + 1 ) != lineCount )
				{
					while( size > availableWidth )
					{
							// Remove the last word untill it fits in one line
						line = line.section( " ", 0, -2 );
						size = QFontMetrics( smallerFont ).width( line );
					}
				}
				else
				{
					// This is the last available line, so squeze the rest
					line = KStringHandler::rPixelSqueeze( desc,
														  p->fontMetrics(),
														  availableWidth
														);
				}
				lines.push_back( line );
				desc = desc.mid( line.length() ).stripWhiteSpace();
				line = desc;
				if( line.isEmpty() ) break;
			}
		}
		else
		{
			lines.push_back( KStringHandler::rPixelSqueeze( desc,
															p->fontMetrics(),
															availableWidth ) );
		}
	
		uint totalTextHeight = p->fontMetrics().height() + 
							   lines.count() * descLineHeight;
		int offset = ( geometry().height() - totalTextHeight ) / 2;
	
		// Write the title of the cell 
		p->drawText( QRect( m_offset + pixmap()->width() + 2 * m_secOffset,
							offset,
							availableWidth,
							p->fontMetrics().height()
					  	),
					 		Qt::AlignLeft, s_title );
	
		// Print each line of the comment
//.........这里部分代码省略.........
开发者ID:engina,项目名称:xkmenu,代码行数:101,代码来源:menuitem.cpp


示例7: QFontMetrics

void GraphScale::Draw(QPainter &painter)
{
    double scale;
    int x,y,w,w_max,font_h = QFontMetrics(font).height();

    painter.setPen(pen);
    painter.setFont(font);

    switch (pos)
    {
      case pos_bottom:
        scale = graph->w / (vmax-vmin);
        painter.drawLine(graph->xo,graph->yo,graph->xo+graph->w,graph->yo);
        for (double v=vmin;v<=vmax;v+=vinc)
        {
            QString s = (labdps<0 ? QString("%1").arg(v/labdiv) : QString("%1").arg(v/labdiv, 0, 'f', labdps)) + labsuffix;

            x=graph->xo + (v-vmin)*scale;
        //printf("x=%d\n",x);
            painter.drawLine(x,graph->yo,x,graph->yo + 10);
            x=x - QFontMetrics(font).boundingRect(s).width()/2;
            painter.drawText(x,graph->yo + 10 + font_h,s);
        }
        break;

    case pos_left:
        scale = graph->h / (vmax-vmin);
        painter.drawLine(graph->xo,graph->yo,graph->xo,graph->yo-graph->h);
        w_max=0;
        for (double v=vmin;v<=vmax;v+=vinc)
        {
            QString s = (labdps<0 ? QString("%1").arg(v/labdiv) : QString("%1").arg(v/labdiv, 0, 'f', labdps)) + labsuffix;
            y=graph->yo - (v-vmin)*scale;
            painter.drawLine(graph->xo,y,graph->xo-10,y);
            w = QFontMetrics(font).boundingRect(s).width();
            x=graph->xo - 12 - w;
            painter.drawText(x,y + font_h/2.5,s);
            if (w>w_max) w_max=w;
        }
        if (!title.isEmpty())
        {
            x=graph->xo;
            y=graph->yo - graph->h/2.0;
            w=QFontMetrics(font).boundingRect(title).width();
            painter.save();
            painter.translate(x,y);
            painter.rotate(-90.0);
            painter.drawText(-w/2.0,-w_max-font_h-4,title);
            painter.restore();
        }
        break;

    case pos_right:
        scale = graph->h / (vmax-vmin);
        painter.drawLine(graph->xo+graph->w,graph->yo,graph->xo+graph->w,graph->yo-graph->h);
        w_max=0;
        for (double v=vmin;v<=vmax;v+=vinc)
        {
//printf("scalev=%lf\n",v);
            QString s = (labdps<0 ? QString("%1").arg(v/labdiv) : QString("%1").arg(v/labdiv, 0, 'f', labdps)) + labsuffix;
            x=graph->xo + graph->w;
            y=graph->yo - (v-vmin)*scale;
            w = QFontMetrics(font).boundingRect(s).width();
            painter.drawLine(x,y,x+10,y);
            painter.drawText(x+12,y + font_h/2.5,s);
            if (w>w_max) w_max=w;
        }
        if (!title.isEmpty())
        {
            x=graph->xo + graph->w;
            y=graph->yo - graph->h/2.0;
            w=QFontMetrics(font).boundingRect(title).width();
            painter.save();
            painter.translate(x,y);
            painter.rotate(90.0);
            painter.drawText(-w/2.0,-w_max-font_h-4,title);
            painter.restore();
        }
        break;

      default: break;
    }
}
开发者ID:Analias,项目名称:sark-100-antenna-analyzer,代码行数:83,代码来源:graph.cpp


示例8: QWidget


//.........这里部分代码省略.........
	}
	QGroupBox *groupbox_video = new QGroupBox(tr("Video"), this);
	{
		QLabel *label_video_codec = new QLabel(tr("Codec:"), groupbox_video);
		m_combobox_video_codec = new QComboBox(groupbox_video);
		for(unsigned int i = 0; i < VIDEO_CODEC_COUNT; ++i) {
			m_combobox_video_codec->addItem(m_video_codecs[i].name);
		}
		m_combobox_video_codec->setToolTip(tr("The codec that will be used to compress the video stream.\n"
											  "- H.264 (libx264) is by far the best codec - high quality and very fast.\n"
											  "- VP8 (libvpx) is quite good but also quite slow.\n"
											  "- Theora (libtheora) isn't really recommended because the quality isn't very good."));
		m_label_video_codec_av = new QLabel(tr("Codec name:"), groupbox_video);
		m_combobox_video_codec_av = new QComboBox(groupbox_video);
		for(unsigned int i = 0; i < m_video_codecs_av.size(); ++i) {
			VideoCodecData &c = m_video_codecs_av[i];
			m_combobox_video_codec_av->addItem(c.avname);
		}
		m_combobox_video_codec_av->setToolTip(tr("For advanced users. You can use any libav/ffmpeg video codec, but many of them are not useful or may not work."));
		m_label_video_kbit_rate = new QLabel(tr("Bit rate (in kbps):"), groupbox_video);
		m_lineedit_video_kbit_rate = new QLineEdit(groupbox_video);
		m_lineedit_video_kbit_rate->setToolTip(tr("The video bit rate (in kilobit per second). A higher value means a higher quality."
												  "\nIf you have no idea where to start, try 5000 and change it if needed."));
		m_label_h264_crf = new QLabel(tr("Constant rate factor:", "libx264 setting: don't translate this unless you can come up with something sensible"), groupbox_video);
		m_slider_h264_crf = new QSlider(Qt::Horizontal, groupbox_video);
		m_slider_h264_crf->setRange(0, 51);
		m_slider_h264_crf->setSingleStep(1);
		m_slider_h264_crf->setPageStep(5);
		m_slider_h264_crf->setToolTip(tr("This setting changes the video quality. A lower value means a higher quality.\n"
										 "The allowed range is 0-51 (0 means lossless, the default is 23)."));
		m_label_h264_crf_value = new QLabel(groupbox_video);
		m_label_h264_crf_value->setNum(m_slider_h264_crf->value());
		m_label_h264_crf_value->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
		m_label_h264_crf_value->setMinimumWidth(QFontMetrics(m_label_h264_crf_value->font()).width("99") + 2);
		m_label_h264_preset = new QLabel(tr("Preset:", "libx264 setting: don't translate this unless you can come up with something sensible"), groupbox_video);
		m_combobox_h264_preset = new QComboBox(groupbox_video);
		for(unsigned int i = 0; i < H264_PRESET_COUNT; ++i) {
			m_combobox_h264_preset->addItem(EnumToString((enum_h264_preset) i));
		}
		m_combobox_h264_preset->setToolTip(tr("The encoding speed. A higher speed uses less CPU (making higher recording frame rates possible),\n"
											  "but results in larger files. The quality shouldn't be affected too much."));
		m_label_vp8_cpu_used = new QLabel(tr("CPU used:", "libvpx setting: don't translate this unless you can come up with something sensible"), groupbox_video);
		m_combobox_vp8_cpu_used = new QComboBox(groupbox_video);
		m_combobox_vp8_cpu_used->addItem("5 (" + tr("fastest") + ")");
		m_combobox_vp8_cpu_used->addItem("4");
		m_combobox_vp8_cpu_used->addItem("3");
		m_combobox_vp8_cpu_used->addItem("2");
		m_combobox_vp8_cpu_used->addItem("1");
		m_combobox_vp8_cpu_used->addItem("0 (" + tr("slowest") + ")");
		m_combobox_vp8_cpu_used->setToolTip(tr("The encoding speed. A higher value uses *less* CPU time. (I didn't choose the name, this is the name\n"
											   "used by the VP8 encoder). Higher values result in lower quality video, unless you increase the bit rate too."));
		m_label_video_options = new QLabel(tr("Custom options:"), groupbox_video);
		m_lineedit_video_options = new QLineEdit(groupbox_video);
		m_lineedit_video_options->setToolTip(tr("Custom codec options separated by commas (e.g. option1=value1,option2=value2,option3=value3)"));
		m_checkbox_video_allow_frame_skipping = new QCheckBox(tr("Allow frame skipping"), groupbox_video);
		m_checkbox_video_allow_frame_skipping->setToolTip(tr("If checked, the video encoder will be allowed to skip frames if the input frame rate is\n"
															 "lower than the output frame rate. If not checked, input frames will be duplicated to fill the holes.\n"
															 "This increases the file size and CPU usage, but reduces the latency for live streams in some cases.\n"
															 "It shouldn't affect the appearance of the video."));

		connect(m_combobox_video_codec, SIGNAL(activated(int)), this, SLOT(OnUpdateVideoCodecFields()));
		connect(m_slider_h264_crf, SIGNAL(valueChanged(int)), m_label_h264_crf_value, SLOT(setNum(int)));

		QGridLayout *layout = new QGridLayout(groupbox_video);
		layout->addWidget(label_video_codec, 0, 0);
		layout->addWidget(m_combobox_video_codec, 0, 1, 1, 2);
开发者ID:Yhonay,项目名称:ssr,代码行数:67,代码来源:PageOutput.cpp


示例9: initStyleOption

/** ***************************************************************************/
void ProposalList::ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const {

    painter->save();

    QStyleOptionViewItem option = options;
    initStyleOption(&option, index);

    /*
     * fm(x) := fontmetrics of x
     * DR := DisplayRole
     * TR := ToolTipRole
     *  +---------------------+----------------------------------------+
     *  |                     |                                        |
     *  |   +-------------+   |                                        |
     *  |   |             |   |                                        |
     *  |   |             |   |a*fm(DR)/(fm(DR)+fm(TR))    DisplayRole |
     * a|   |     icon    |   |                                        |
     *  |   |             |   |                                        |
     *  |   |             |   +----------------------------------------+
     *  |   |             |   |                                        |
     *  |   +-------------+   |a*fm(TR)/(fm(DR)+fm(TR))  ToolTipRole+x |
     *  |                     |                                        |
     * +---------------------------------------------------------------+
     */


    // Avoid ugly dark blue mouseover background
    // TODO: QT_MINREL 5.7 setFlag
    option.state &= ~QStyle::State_MouseOver;

    // Draw selection
    option.widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, option.widget);

    // Draw icon
    if ( drawIcon ){
        QRect iconRect = QRect(
                    QPoint((option.rect.height() - option.decorationSize.width())/2 + option.rect.x(),
                           (option.rect.height() - option.decorationSize.height())/2 + option.rect.y()),
                    option.decorationSize);
        QPixmap pixmap;
        QString iconPath = index.data(Qt::DecorationRole).value<QString>();
        QString cacheKey = QString("%1%2%3").arg(option.decorationSize.width(), option.decorationSize.height()).arg(iconPath);
        if ( !QPixmapCache::find(cacheKey, &pixmap) ) {
            pixmap = QPixmap(iconPath).scaled(option.decorationSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
            QPixmapCache::insert(cacheKey, pixmap);
        }
        painter->drawPixmap(iconRect, pixmap);
    }

    // Calculate text rects
    QFont font1 = option.font;
    QFont font2 = option.font;
    font2.setPixelSize(12);
    QFontMetrics fontMetrics1 = QFontMetrics(font1);
    QFontMetrics fontMetrics2 = QFontMetrics(font2);
    QRect contentRect = option.rect;
    contentRect.setLeft(drawIcon ? option.rect.height() : 0);
    contentRect.setTop(option.rect.y()+option.rect.height()/2-(fontMetrics1.height()+fontMetrics2.height())/2);
    contentRect.setBottom(option.rect.y()+option.rect.height()/2+(fontMetrics1.height()+fontMetrics2.height())/2);
    QRect textRect = contentRect.adjusted(0,-2,0,-fontMetrics2.height()-2);
    QRect subTextRect = contentRect.adjusted(0,fontMetrics1.height()-2,0,-2);

    //    // Test
    //    painter->fillRect(iconRect, Qt::magenta);
    //    painter->fillRect(contentRect, Qt::red);
    //    painter->fillRect(textRect, Qt::blue);
    //    painter->fillRect(subTextRect, Qt::yellow);


    // Draw display role
    painter->setFont(font1);
    QString text = fontMetrics1.elidedText(index.data(Qt::DisplayRole).toString(),
                                           option.textElideMode,
                                           textRect.width());
    option.widget->style()->drawItemText(painter,
                                         textRect,
                                         option.displayAlignment,
                                         option.palette,
                                         option.state & QStyle::State_Enabled,
                                         text,
                                         (option.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::WindowText);

    // Draw tooltip role
    painter->setFont(font2);
    text = fontMetrics2.elidedText(index.data(option.state.testFlag(QStyle::State_Selected)? subTextRole : Qt::ToolTipRole).toString(),
                                   option.textElideMode,
                                   subTextRect.width());
    option.widget->style()->drawItemText(painter,
                                         subTextRect,
                                         Qt::AlignBottom|Qt::AlignLeft,
                                         option.palette,
                                         option.state & QStyle::State_Enabled,
                                         text,
                                         (option.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::WindowText);
    painter->restore();
}
开发者ID:BoltsJ,项目名称:albert,代码行数:97,代码来源:proposallist.cpp


示例10: QModelIndex

 QModelIndex PieView::indexAt(const QPoint &point) const
 {
     if (validItems == 0)
         return QModelIndex();

     // Transform the view coordinates into contents widget coordinates.
     int wx = point.x() + horizontalScrollBar()->value();
     int wy = point.y() + verticalScrollBar()->value();

     if (wx < totalSize) {
         double cx = wx - totalSize/2;
         double cy = totalSize/2 - wy; // positive cy for items above the center

         // Determine the distance from the center point of the pie chart.
         double d = pow(pow(cx, 2) + pow(cy, 2), 0.5);

         if (d == 0 || d > pieSize/2)
             return QModelIndex();

         // Determine the angle of the point.
         double angle = (180 / M_PI) * acos(cx/d);
         if (cy < 0)
             angle = 360 - angle;

         // Find the relevant slice of the pie.
         double startAngle = 0.0;

         for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {

             QModelIndex index = model()->index(row, 1, rootIndex());
             double value = model()->data(index).toDouble();

             if (value > 0.0) {
                 double sliceAngle = 360*value/totalValue;

                 if (angle >= startAngle && angle < (startAngle + sliceAngle))
                     return model()->index(row, 1, rootIndex());

                 startAngle += sliceAngle;
             }
         }
     } else {
         double itemHeight = QFontMetrics(viewOptions().font).height();
         int listItem = int((wy - margin) / itemHeight);
         int validRow = 0;

         for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {

             QModelIndex index = model()->index(row, 1, rootIndex());
             if (model()->data(index).toDouble() > 0.0) {

                 if (listItem == validRow)
                     return model()->index(row, 0, rootIndex());

                 // Update the list index that corresponds to the next valid row.
                 validRow++;
             }
         }
     }

     return QModelIndex();
 }
开发者ID:RealGrep,项目名称:QMentat,代码行数:62,代码来源:pieview.cpp


示例11: font

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QImage PoleFigureImageUtilities::PaintPoleFigureOverlay(int imageWidth, int imageHeight, QString label, QImage image)
{
  int pxHigh = 0;
  int pxWide = 0;

  // Scale the Font Point size to something reasonable to the size of the image. Here our standard was 14Pt Font when the
  // Pole figure was 512 Pixels square.
  int fontPtSize = imageHeight / 32;

  QFont font("Ariel", fontPtSize, QFont::Bold);
  QFontMetrics metrics(font);
  pxHigh = metrics.height();
  pxWide = metrics.width(QString("Y"));

  int pxOffset = 2 * pxWide;
  int pyOffset = 2 * pxHigh;

  int pImageWidth = imageWidth + pxOffset * 2;
  int pImageHeight = imageHeight + pyOffset * 2;

  QImage pImage(pImageWidth, pImageHeight, QImage::Format_ARGB32_Premultiplied);
  pImage.fill(0xFFFFFFFF); // All white background

  // Create a Painter backed by a QImage to draw into
  QPainter painter;
  painter.begin(&pImage);
  painter.setRenderHint(QPainter::Antialiasing, true);
  qint32 penWidth = 1;

#if 0
  // DRAW A BORDER AROUND THE IMAGE FOR DEBUGGING
  QColor c(RgbColor::dRgb(255, 0, 0, 255));
  painter.setPen(QPen(c, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));

  painter.drawLine(0, 0, pImageWidth, 0); // Top
  painter.drawLine(0, 0, 0, pImageHeight); // Left
  painter.drawLine(pImageWidth, 0, pImageWidth, pImageHeight); // Right
  painter.drawLine(0, pImageHeight, pImageWidth, pImageHeight); // Bottom
  //-----------------
#endif

  painter.setFont(font);
//  metrics = painter.fontMetrics();
//  pxHigh = metrics.height();
//  pxWide = metrics.width(QString("Y"));

  // Draw the Pole Figure into the center of the canvas
  QPoint point(pxOffset, pyOffset);
  painter.drawImage(point, image);

  // Scale pen width based on the size of the image
  penWidth = imageHeight / 256;
  painter.setPen(QPen(QColor(0, 0, 0, 255), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));

  // Draw the Outer circular border around the pole figure
  QPainterPath circle;
  QPointF center(pImageWidth / 2, pImageHeight / 2);
  circle.addEllipse(center, imageWidth / 2, imageHeight / 2);
  painter.drawPath(circle);

  // Label the X Axis
  painter.drawText(pImageWidth - (pxWide * 1.5), pImageHeight / 2 + pxHigh / 3, "X");
  // Label the Y Axis
  pxWide = metrics.width(QString("Y"));
  painter.drawText(pImageWidth / 2 - pxWide / 2, pyOffset - penWidth - 1, "Y");

  // Draw the name of the Pole Figure
  int labelWidth = 0;
  int maxWidth = pImageWidth / 5; // No more than a Quarter of the width of the image
  while(labelWidth < maxWidth)
  {
    fontPtSize++;
    font = QFont("Ariel", fontPtSize, QFont::Bold);
    metrics = QFontMetrics(font);
    labelWidth = metrics.width(label); // Figure out which string is longer (pixel wise)
  }
  painter.setFont(font);
  pxHigh = metrics.height() + 2;
// pxWide = metrics.width(label);
  painter.drawText(pxOffset, pxHigh, label);

  // Draw slightly transparent lines
  //penWidth = 1;
  painter.setPen(QPen(QColor(0, 0, 0, 180), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
  // Draw the X Axis
  painter.drawLine(pxOffset, pImageHeight / 2, pImageWidth - pxOffset, pImageHeight / 2);
  // Draw the Y Axis
  painter.drawLine(pImageWidth / 2, pyOffset, pImageWidth / 2, pImageHeight - pyOffset);

  painter.end();
  return pImage;
}
开发者ID:kglowins,项目名称:DREAM3D,代码行数:95,代码来源:PoleFigureImageUtilities.cpp


示例12: pImage

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QImage PoleFigureImageUtilities::GenerateScalarBar(int imageWidth, int imageHeight, PoleFigureConfiguration_t& config)
{
  int numColors = config.numColors;
  QImage pImage(imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied);
  pImage.fill(0xFFFFFFFF); // All white background

  // Create a Painter backed by a QImage to draw into
  QPainter painter;
  painter.begin(&pImage);
  painter.setRenderHint(QPainter::Antialiasing, true);

  int penWidth = 1;

#if 0
  // DRAW A BORDER AROUND THE IMAGE FOR DEBUGGING
  QColor c(RgbColor::dRgb(255, 0, 0, 255));
  painter.setPen(QPen(c, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));

  painter.drawLine(0, 0, imageWidth, 0); // Top
  painter.drawLine(0, 0, 0, imageHeight); // Left
  painter.drawLine(imageWidth, 0, imageWidth, imageHeight); // Right
  painter.drawLine(0, imageHeight, imageWidth, imageHeight); // Bottom
  //-----------------
#endif

  //Get all the colors that we will need
  QVector<DREAM3D::Rgb> colorTable(numColors);
  QVector<float> colors(3 * numColors, 0.0);
  DREAM3DColorTable::GetColorTable(numColors, colors); // Generate the color table values
  float r = 0.0, g = 0.0, b = 0.0;
  for (int i = 0; i < numColors; i++) // Convert them to QRgbColor values
  {
    r = colors[3 * i];
    g = colors[3 * i + 1];
    b = colors[3 * i + 2];
    colorTable[i] = RgbColor::dRgb(r * 255, g * 255, b * 255, 255);
  }

  // Now start from the bottom and draw colored lines up the scale bar
  // A Slight Indentation for the scalar bar
  float margin = 0.05f;
  float scaleBarRelativeWidth = 0.10f;
  float scaleBarRelativeHeight = 1.0f - (margin * 2);

  int colorHeight = int( (imageHeight * scaleBarRelativeHeight) / numColors);

  QPointF topLeft(imageWidth * margin, imageHeight * margin);
  QSizeF size(imageWidth * scaleBarRelativeWidth, imageHeight * scaleBarRelativeHeight);

  int yLinePos = topLeft.y();

  QPointF start = topLeft;
  QPointF end = topLeft;

  for(int i = numColors - 1; i >= 0; i--)
  {
    QColor c(colorTable[i]);
    painter.setPen(QPen(c, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
    for(int j = 0; j < colorHeight; j++)
    {
      start.setY(yLinePos);
      end.setX(topLeft.x() + (imageWidth * scaleBarRelativeWidth));
      end.setY(yLinePos);
      painter.drawLine(start, end);
      yLinePos++;
    }
  }

  // Draw the border of the scale bar
  size = QSizeF(imageWidth * scaleBarRelativeWidth, numColors * colorHeight); // Add two pixel to the height so we don't over write part of the scale bar
  QRectF scaleBorder(topLeft, size);
  penWidth = 2;
  painter.setPen(QPen(QColor(0, 0, 0, 255), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
  painter.drawRect(scaleBorder);


  // Draw the Text Labels of the Scale Bar
  int startFontPtSize = 10;
  QFont font("Ariel", startFontPtSize, QFont::Bold);

  QFontMetrics metrics(font);
  int fontPixelsHeight = metrics.height();
  while(fontPixelsHeight < colorHeight * 2)
  {
    startFontPtSize++;
    font = QFont("Ariel", startFontPtSize, QFont::Bold);
    metrics = QFontMetrics(font);
    fontPixelsHeight = metrics.height();
  }
  painter.setFont(font);

  // Draw some more information to the right of the Scale Bar
  QString maxStr = QString::number(config.maxScale, 'f', 3);
  painter.drawText(topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10, topLeft.y() + fontPixelsHeight, maxStr);

  QString minStr = QString::number(config.minScale, 'f', 3);
  painter.drawText(topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10, topLeft.y() + size.height(), minStr);
//.........这里部分代码省略.........
开发者ID:kglowins,项目名称:DREAM3D,代码行数:101,代码来源:PoleFigureImageUtilities.cpp


示例13: p

void NormalState::paintEvent(CoreEdit *ctxt, QPaintEvent *e)
{
	QPainter p( ctxt->viewport() );
	
	int xOffset = ctxt->horizontalScrollBar()->value() + 4;
	int yOffset = ctxt->verticalScrollBar()->value();
	
	if ( ctxt->highlightCurrentLine() )
	{
		QRect r(0,
				ctxt->cursorRect().y(),
				ctxt->viewport()->width(),
				QFontMetrics( ctxt->document()->defaultFont() ).lineSpacing() );
		
		p.fillRect(r, QColor(0x00, 0xff, 0xff, 0x30));
	}
	
	if ( ctxt->drawMargin() )
	{
		int margin = QFontMetrics(ctxt->font()).width(" ") * (ctxt->margin() + 1);
		
		margin -= xOffset;
		
		p.drawLine(	margin, 0,
					margin, ctxt->viewport()->height());
	}
	
	//I was forced to do these standard painting afterward so as to get rid
	//of some scrollbars bugs!!!
	
	QRect r = e->rect();
	p.translate(-xOffset, -yOffset);
	r.translate(xOffset, yOffset);
	
	QAbstractTextDocumentLayout::PaintContext ctx;
	ctx.palette = ctxt->palette();
	
	if ( ctxt->bCursor && ctxt->isEnabled() && ctxt->hasFocus() )
		ctx.cursorPosition = ctxt->textCursor().position();
	
	if ( ctxt->parenMatching() && !ctxt->curLine.isNull() )
	{
		QPen backupPen = p.pen();
		
		QPen newPen(Qt::DotLine);
		newPen.setWidth(0);
		newPen.setColor((ctxt->pMatcher ? ctxt->pMatcher->matchColor() : Qt::black));
		p.setPen(newPen);	
		
		const QFontMetrics fm = ctxt->fontMetrics();
		const int fontHeight = fm.height();
		const int x = ctxt->curLine.x1();// + (fm.width(" ") / 2);
		
		int y1 = ctxt->curLine.y1() + 1;
		int y2 = 0;
		
		for (int y = y1; y < ctxt->curLine.y2(); y += fontHeight)
		{
			QTextCursor cursor = ctxt->cursorForPosition(QPoint(x, y));	
			QChar ch = ParenMatcher::charFromCursor(cursor,
													QTextCursor::NextCharacter);
			
			if (ch.isSpace())
				y2 = y + fontHeight;
			
			else
			{
				QChar ch2 = ParenMatcher::charFromCursor(cursor,
												QTextCursor::PreviousCharacter);
				if (ch2 == '\t')
				{
					ch2 = ParenMatcher::charFromCursor(
									ctxt->cursorForPosition(QPoint(
												x - (ctxt->tabStopWidth() / 2),
												y) ),
									QTextCursor::NextCharacter);
					
					if (ch2 == '\t')
						y2 = y + fontHeight;
					else
					{
						if (y1 < y2)
						{
							QLine lineToPrint(x, y1, x, y2);
							lineToPrint.translate(xOffset, yOffset);
							p.drawLine(lineToPrint);
						}
						y1 = y + fontHeight;
					}
				} else {
					if (y1 < y2)
					{
						QLine lineToPrint(x, y1, x, y2);
						lineToPrint.translate(xOffset, yOffset);
						p.drawLine(lineToPrint);
					}
					y1 = y + fontHeight;
				}
			}
		}
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:devqt-svn,代码行数:101,代码来源:normalstate.cpp


示例14: drawTextCommon

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ QFontMetricsF函数代码示例发布时间:2022-05-30
下一篇:
C++ QFlag函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap