コード例 #1
0
ファイル: Aerolab.cpp プロジェクト: ClaFio/GoldenCheetah
void
Aerolab::configChanged()
{

  // set colors
  setCanvasBackground(GColor(CPLOTBACKGROUND));
  QPen vePen = QPen(GColor(CAEROVE));
  vePen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble());
  veCurve->setPen(vePen);
  QPen altPen = QPen(GColor(CAEROEL));
  altPen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble());
  altCurve->setPen(altPen);
  QPen gridPen(GColor(CPLOTGRID));
  gridPen.setStyle(Qt::DotLine);
  grid->setPen(gridPen);

  QPen ihlPen = QPen( GColor( CINTERVALHIGHLIGHTER ) );
  ihlPen.setWidth(1);
  intervalHighlighterCurve->setPen( ihlPen );

  QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER));
  ihlbrush.setAlpha(40);
  intervalHighlighterCurve->setBrush(ihlbrush);   // fill below the line

  this->legend()->remove( intervalHighlighterCurve ); // don't show in legend
}
コード例 #2
0
ファイル: RiuPvtPlotPanel.cpp プロジェクト: OPM/ResInsight
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuPvtPlotWidget::setPlotDefaults(QwtPlot* plot)
{
    // Plot background and frame look
    QPalette newPalette(plot->palette());
    newPalette.setColor(QPalette::Background, Qt::white);
    plot->setPalette(newPalette);

    plot->setAutoFillBackground(true);
    plot->setCanvasBackground(Qt::white);

    QFrame* canvasFrame = dynamic_cast<QFrame*>(plot->canvas());
    if (canvasFrame)
    {
        canvasFrame->setFrameShape(QFrame::NoFrame);
    }

    // Grid
    {
        QwtPlotGrid* grid = new QwtPlotGrid;
        grid->attach(plot);
        QPen gridPen(Qt::SolidLine);
        gridPen.setColor(Qt::lightGray);
        grid->setPen(gridPen);
    }

    // Axis number font
    {
        QFont axisFont = plot->axisFont(QwtPlot::xBottom);
        axisFont.setPointSize(8);
        plot->setAxisFont(QwtPlot::xBottom, axisFont);
        plot->setAxisFont(QwtPlot::yLeft, axisFont);
    }

    // Axis title font
    {
        QwtText axisTitle = plot->axisTitle(QwtPlot::xBottom);
        QFont axisTitleFont = axisTitle.font();
        axisTitleFont.setPointSize(8);
        axisTitleFont.setBold(false);
        axisTitle.setFont(axisTitleFont);
        axisTitle.setRenderFlags(Qt::AlignRight);
        plot->setAxisTitle(QwtPlot::xBottom, axisTitle);
        plot->setAxisTitle(QwtPlot::yLeft, axisTitle);
    }

    // Title font
    {
        QwtText plotTitle = plot->title();
        QFont titleFont = plotTitle.font();
        titleFont.setPointSize(12);
        plotTitle.setFont(titleFont);
        plot->setTitle(plotTitle);
    }


    plot->setAxisMaxMinor(QwtPlot::xBottom, 2);
    plot->setAxisMaxMinor(QwtPlot::yLeft, 3);

    plot->plotLayout()->setAlignCanvasToScales(true);
}
コード例 #3
0
ファイル: Aerolab.cpp プロジェクト: MaksVasilev/GoldenCheetah
void
Aerolab::configChanged(qint32)
{

  // set colors
  setCanvasBackground(GColor(CPLOTBACKGROUND));
  QPen vePen = QPen(GColor(CAEROVE));
  vePen.setWidth(appsettings->value(this, GC_LINEWIDTH, 0.5).toDouble());
  veCurve->setPen(vePen);
  QPen altPen = QPen(GColor(CAEROEL));
  altPen.setWidth(appsettings->value(this, GC_LINEWIDTH, 0.5).toDouble());
  altCurve->setPen(altPen);
  QPen gridPen(GColor(CPLOTGRID));
  gridPen.setStyle(Qt::DotLine);
  grid->setPen(gridPen);

  QPen ihlPen = QPen( GColor( CINTERVALHIGHLIGHTER ) );
  ihlPen.setWidth(1);
  intervalHighlighterCurve->setPen( ihlPen );

  QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER));
  ihlbrush.setAlpha(40);
  intervalHighlighterCurve->setBrush(ihlbrush);   // fill below the line

  //XXX broken this->legend()->remove( intervalHighlighterCurve ); // don't show in legend
  QPalette palette;
  palette.setColor(QPalette::WindowText, GColor(CPLOTMARKER));
  palette.setColor(QPalette::Text, GColor(CPLOTMARKER));
  axisWidget(QwtPlot::xBottom)->setPalette(palette);
  axisWidget(QwtPlot::yLeft)->setPalette(palette);
}
コード例 #4
0
void QgsPointDisplacementRenderer::drawGrid( int gridSizeUnits, QgsSymbolRenderContext &context,
    QList<QPointF> pointSymbolPositions, int nSymbols )
{
  QPainter *p = context.renderContext().painter();
  if ( nSymbols < 2 || !p ) //draw grid only if multiple features
  {
    return;
  }

  QPen gridPen( mCircleColor );
  gridPen.setWidthF( context.outputLineWidth( mCircleWidth ) );
  p->setPen( gridPen );

  for ( int i = 0; i < pointSymbolPositions.size(); ++i )
  {
    if ( i + 1 < pointSymbolPositions.size() && 0 != ( i + 1 ) % gridSizeUnits )
    {
      QLineF gridLineRow( pointSymbolPositions[i], pointSymbolPositions[i + 1] );
      p->drawLine( gridLineRow );
    }

    if ( i + gridSizeUnits < pointSymbolPositions.size() )
    {
      QLineF gridLineColumn( pointSymbolPositions[i], pointSymbolPositions[i + gridSizeUnits] );
      p->drawLine( gridLineColumn );
    }
  }
}
コード例 #5
0
ファイル: projectscene.cpp プロジェクト: jaisurya/picworks
/*!
  \internal Sets this window to show grid lines.
  \param v true if grid lines should be shown
 */
void Ui::ProjectScene::showGrid(bool v)
{
    gridVisible = v;
    if(gridVisible) {
        int dpi = project->dpi();
        QPixmap grid(dpi, dpi);
        grid.fill(Qt::transparent);
        QPainter painter(&grid);
        QPen gridPen(QColor(204, 204, 204));
        painter.setPen(gridPen);
        int bor = dpi - 1;
        painter.drawLine(0, bor, bor, bor);
        painter.drawLine(bor, 0, bor, bor);
        gridPen.setStyle(Qt::DotLine);
        painter.setPen(gridPen);
        int dpip5 = dpi / 5;
        // FIXME if dpi is too low, grid lines should be changed as PS
        int borp5 = dpip5 - 1;
        painter.drawLine(0, borp5, bor, borp5);
        painter.drawLine(borp5, 0, borp5, bor);
        int bor2p5 = dpip5 * 2 - 1;
        painter.drawLine(0, bor2p5, bor, bor2p5);
        painter.drawLine(bor2p5, 0, bor2p5, bor);
        int bor3p5 = dpip5 * 3 - 1;
        painter.drawLine(0, bor3p5, bor, bor3p5);
        painter.drawLine(bor3p5, 0, bor3p5, bor);
        int bor4p5 = dpip5 * 4 - 1;
        painter.drawLine(0, bor4p5, bor, bor4p5);
        painter.drawLine(bor4p5, 0, bor4p5, bor);
        this->setForegroundBrush(QBrush(grid));
    } else {
        this->setForegroundBrush(Qt::NoBrush);
    }
}
コード例 #6
0
void MainWindow::setupPlot()
{
    plotTimer.setInterval(1000/settingsDialog->rate);
    connect(&plotTimer, SIGNAL(timeout()), this, SLOT(plotUpdate()));
    plotTimer.start();

    if (!ui->plot->legend()) {
        QwtLegend* legend = new QwtLegend;
        legend->setItemMode(QwtLegend::CheckableItem);
        ui->plot->insertLegend(legend, QwtPlot::RightLegend);
    }

    ui->plot->setAxisTitle(QwtPlot::xBottom, "seconds");
    ui->plot->setCanvasBackground(Qt::white);

    QColor gridColor;
    gridColor.setNamedColor("grey");
    QPen gridPen(gridColor);
    gridPen.setStyle(Qt::DotLine);
    QwtPlotGrid* grid = new QwtPlotGrid;
    grid->setMajPen(gridPen);
    grid->attach(ui->plot);

    connect(ui->plot, SIGNAL(legendChecked(QwtPlotItem*,bool)), this, SLOT(showCurve(QwtPlotItem*,bool)));
}
コード例 #7
0
ファイル: CpintPlot.cpp プロジェクト: dazzat/GoldenCheetah
void
CpintPlot::configChanged()
{
    setCanvasBackground(GColor(CPLOTBACKGROUND));
    QPen gridPen(GColor(CPLOTGRID));
    gridPen.setStyle(Qt::DotLine);
    grid->setPen(gridPen);
}
コード例 #8
0
ファイル: LinePlot.cpp プロジェクト: CUEBoxer/OpenStudio
void LinePlot::init()
{
  m_plot2DTimeAxis = NULL;
  // destroy windows when closed
  setAttribute(Qt::WA_DeleteOnClose);
  m_qwtPlot->plotLayout()->setAlignCanvasToScales(true);
  // legend - subclass qwtLegend to overwrite paint event
  // m_legend = new Plot2DLegend(this);
  m_legend = new QwtLegend(this);
  m_legend->setItemMode(QwtLegend::CheckableItem);
  //  m_legend->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  //  m_legend->setGeometry(120,100,150,150);
  QPalette p(palette());
  p.setColor(QPalette::Background, Qt::white);
  m_legend->setPalette(p);
  // m_qwtPlot->insertLegend(m_legend, QwtPlot::ExternalLegend);
  m_qwtPlot->insertLegend(m_legend, QwtPlot::BottomLegend);
  // m_legend->show();
  // for window menu in treeview application
  setAttribute(Qt::WA_DeleteOnClose);

  /// left and right axes units
  m_leftAxisUnits = "NONE SPECIFIED";
  m_rightAxisUnits = "NONE SPECIFIED";

  m_xAxisMin = DBL_MAX;
  m_xAxisMax = -DBL_MAX;

  // base on data
  this->bottomAxisTitle("Hour of Year");

  /// legend checked event
  connect(m_qwtPlot, SIGNAL(legendChecked(QwtPlotItem *, bool)), SLOT(showCurve(QwtPlotItem *, bool)));

  m_colorVec.push_back(Qt::black);
  m_colorVec.push_back(Qt::blue);
  m_colorVec.push_back(Qt::cyan);
  m_colorVec.push_back(Qt::magenta);
  m_colorVec.push_back(Qt::yellow);
  m_colorVec.push_back(Qt::darkBlue);
  m_colorVec.push_back(Qt::darkCyan);
  m_colorVec.push_back(Qt::darkMagenta);
  m_colorVec.push_back(Qt::darkYellow);


  // plot grid
  m_grid = new QwtPlotGrid();
  QPen gridPen(Qt::gray);
  gridPen.setCosmetic(true);
  gridPen.setWidth(1);
  gridPen.setStyle(Qt::DotLine);
  m_grid->setPen(gridPen);
  m_grid->attach(m_qwtPlot);

  
}
コード例 #9
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::setDefaults()
{
    QPalette newPalette(palette());
    newPalette.setColor(QPalette::Background, Qt::white);
    setPalette(newPalette);

    setAutoFillBackground(true);
    setCanvasBackground(Qt::white);

    QFrame* canvasFrame = dynamic_cast<QFrame*>(canvas());
    if (canvasFrame)
    {
        canvasFrame->setFrameShape(QFrame::NoFrame);
    }

    canvas()->setMouseTracking(true);
    canvas()->installEventFilter(this);

    QPen gridPen(Qt::SolidLine);
    gridPen.setColor(Qt::lightGray);
    m_grid->setPen(gridPen);

    enableAxis(QwtPlot::xBottom, true);
    enableAxis(QwtPlot::yLeft, true);
    enableAxis(QwtPlot::xTop, false);
    enableAxis(QwtPlot::yRight, false);

    plotLayout()->setAlignCanvasToScales(true);

    useDateBasedTimeAxis();

    QFont xAxisFont = axisFont(QwtPlot::xBottom);
    xAxisFont.setPixelSize(11);
    setAxisFont(QwtPlot::xBottom, xAxisFont);
    setAxisMaxMinor(QwtPlot::xBottom, 2);

    QFont yAxisFont = axisFont(QwtPlot::yLeft);
    yAxisFont.setPixelSize(11);
    setAxisFont(QwtPlot::yLeft, yAxisFont);

    setAxisMaxMinor(QwtPlot::yLeft, 3);

    QwtText axisTitleY = axisTitle(QwtPlot::yLeft);
    QFont yAxisTitleFont = axisTitleY.font();
    yAxisTitleFont.setPixelSize(11);
    yAxisTitleFont.setBold(false);
    axisTitleY.setFont(yAxisTitleFont);
    axisTitleY.setRenderFlags(Qt::AlignRight);
    setAxisTitle(QwtPlot::yLeft, axisTitleY);


    QwtLegend* legend = new QwtLegend(this);
    // The legend will be deleted in the destructor of the plot or when 
    // another legend is inserted.
    this->insertLegend(legend, BottomLegend);
}
コード例 #10
0
ファイル: PowerHist.cpp プロジェクト: ebrandt/GoldenCheetah
void
PowerHist::configChanged()
{
    // plot background
    setCanvasBackground(GColor(CPLOTBACKGROUND));

    // curve
    QPen pen;
    QColor brush_color;

    switch (selected) {
	case watts:
	case wattsZone:
        pen.setColor(GColor(CPOWER).darker(200));
        brush_color = GColor(CPOWER);
        break;
	case nm:
        pen.setColor(GColor(CTORQUE).darker(200));
        brush_color = GColor(CTORQUE);
        break;
	case hr:
	case hrZone:
        pen.setColor(GColor(CHEARTRATE).darker(200));
        brush_color = GColor(CHEARTRATE);
        break;
	case kph:
        pen.setColor(GColor(CSPEED).darker(200));
        brush_color = GColor(CSPEED);
        break;
	case cad:
        pen.setColor(GColor(CCADENCE).darker(200));
        brush_color = GColor(CCADENCE);
        break;
    }

    double width = 2.0;
    curve->setRenderHint(QwtPlotItem::RenderAntialiased);
    curveSelected->setRenderHint(QwtPlotItem::RenderAntialiased);
    pen.setWidth(width);
    curve->setPen(pen);
    brush_color.setAlpha(64);
    curve->setBrush(brush_color);   // fill below the line

    // intervalselection
    QPen ivl(GColor(CINTERVALHIGHLIGHTER).darker(200));
    ivl.setWidth(width);
    curveSelected->setPen(ivl);
    QColor ivlbrush = GColor(CINTERVALHIGHLIGHTER);
    ivlbrush.setAlpha(64);
    curveSelected->setBrush(ivlbrush);   // fill below the line

    // grid
    QPen gridPen(GColor(CPLOTGRID));
    gridPen.setStyle(Qt::DotLine);
    grid->setPen(gridPen);
}
コード例 #11
0
ファイル: PerfPlot.cpp プロジェクト: 27sparks/GoldenCheetah
void
PerfPlot::configUpdate()
{
    // set the colors et al
    setCanvasBackground(GColor(CPLOTBACKGROUND));
    grid->enableX(false);
    QPen gridPen(GColor(CPLOTGRID));
    gridPen.setStyle(Qt::DotLine);
    grid->setPen(gridPen);
}
コード例 #12
0
ファイル: myscene.cpp プロジェクト: Kabotyn/Langton-s-Ant
void MyScene::drawGrid() {
    QPen gridPen(QColor(230, 230, 230));

    for(int i = 0; i < width; i+=11) {
        addLine(i,0, i, height, gridPen);    // vertical line
    }

    for(int i = 0; i < height; i+=11) {
        addLine(0,i, width, i, gridPen);    // horizontal line
    }
}
コード例 #13
0
void DiveCartesianAxis::setPrintMode(bool mode)
{
	printMode = mode;
	// update the QPen of all lines depending on printMode
	QPen newPen = gridPen();
	QColor oldColor = pen().brush().color();
	newPen.setBrush(oldColor);
	setPen(newPen);
	Q_FOREACH (DiveLineItem *item, lines)
		item->setPen(pen());
}
コード例 #14
0
void
AllPlot::configChanged()
{

    double width = 1.0;

    boost::shared_ptr<QSettings> settings = GetApplicationSettings();
    useMetricUnits = (settings->value(GC_UNIT).toString() == "Metric");

    // placeholder for setting antialiasing, will come
    // in with a future patch. For now antialiasing is
    // not enabled since it can slow down plotting on
    // windows and linux platforms.
    if (false) {
        wattsCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
        hrCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
        speedCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
        cadCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
        altCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
        intervalHighlighterCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
    }

    setCanvasBackground(GColor(CPLOTBACKGROUND));
    QPen wattsPen = QPen(GColor(CPOWER));
    wattsPen.setWidth(width);
    wattsCurve->setPen(wattsPen);
    QPen hrPen = QPen(GColor(CHEARTRATE));
    hrPen.setWidth(width);
    hrCurve->setPen(hrPen);
    QPen speedPen = QPen(GColor(CSPEED));
    speedPen.setWidth(width);
    speedCurve->setPen(speedPen);
    QPen cadPen = QPen(GColor(CCADENCE));
    cadPen.setWidth(width);
    cadCurve->setPen(cadPen);
    QPen altPen(GColor(CALTITUDE));
    altPen.setWidth(width);
    altCurve->setPen(altPen);
    QColor brush_color = GColor(CALTITUDEBRUSH);
    brush_color.setAlpha(200);
    altCurve->setBrush(brush_color);   // fill below the line
    QPen ihlPen = QPen(GColor(CINTERVALHIGHLIGHTER));
    ihlPen.setWidth(width);
    intervalHighlighterCurve->setPen(ihlPen);
    QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER));
    ihlbrush.setAlpha(64);
    intervalHighlighterCurve->setBrush(ihlbrush);   // fill below the line
    this->legend()->remove(intervalHighlighterCurve); // don't show in legend
    QPen gridPen(GColor(CPLOTGRID));
    gridPen.setStyle(Qt::DotLine);
    grid->setPen(gridPen);
}
コード例 #15
0
DiveCartesianAxis::DiveCartesianAxis() : QObject(),
	QGraphicsLineItem(),
	unitSystem(0),
	orientation(LeftToRight),
	min(0),
	max(0),
	interval(1),
	tick_size(0),
	textVisibility(true),
	lineVisibility(true),
	labelScale(1.0),
	line_size(1)
{
	setPen(gridPen());
}
コード例 #16
0
ファイル: document.cpp プロジェクト: StefanHirche/stitchy
QGraphicsItemGroup* Document::grid()
{
  QGraphicsItemGroup *group = new QGraphicsItemGroup();
  group->setZValue(-1.0);

  QPen gridPen(QBrush(QColor("#DDDDDD")), 0.0);
  QPen gridPenDec(QBrush(QColor("#AAAAAA")), 0.0);
  QPen *activePen;
  double margin;

  for (int i = 0; i < size_.height() + 1; ++i) {
    if (i % 10 == 0) {
      margin = 10.0;
      activePen = &gridPenDec;
    } else {
      margin = 5.0;
      activePen = &gridPen;
    }

    QGraphicsLineItem *line = new QGraphicsLineItem(-margin,
                                                    10.0 * i,
                                                    10.0 * size_.width() + margin,
                                                    10.0 * i,
                                                    group);
    line->setPen(*activePen);
  }

  for (int i = 0; i < size_.width() + 1; ++i) {
    if (i % 10 == 0) {
      margin = 10.0;
      activePen = &gridPenDec;
    } else {
      margin = 5.0;
      activePen = &gridPen;
    }

    QGraphicsLineItem *line = new QGraphicsLineItem(10.0 * i,
                                                    -margin,
                                                    10.0 * i,
                                                    10.0 * size_.height() + margin,
                                                    group);
    line->setPen(*activePen);
  }

  return group;
}
コード例 #17
0
DiveCartesianAxis::DiveCartesianAxis(ProfileWidget2 *widget) : QObject(),
	QGraphicsLineItem(),
	printMode(false),
	unitSystem(0),
	profileWidget(widget),
	orientation(LeftToRight),
	min(0),
	max(0),
	interval(1),
	tick_size(0),
	textVisibility(true),
	lineVisibility(true),
	labelScale(1.0),
	line_size(1),
	changed(true)
{
	setPen(gridPen());
}
コード例 #18
0
void dialogAnalog::initPixmap(QSize size)
{
	// resize the pixmap
	//	complete it
	// Draw plot
	QPainter painter;
    int heightPerField = size.height() / NbBits;
	
	lastPixmap=QPixmap( size.width(), size.height() );
	lastPixmap.fill(Qt::black);
	painter.begin(&lastPixmap);
	
    // set font ------------------------------------------------------------------------------------
    QFont textFont;
    textFont.setPixelSize(heightPerField / 2);
    painter.setFont(textFont);

    // set the needed pens -------------------------------------------------------------------------
	QPen linePen(QColor(100,100,100));
    QPen textPen(QColor(255, 255, 255));
    QPen gridPen(QColor(100, 100, 100));
    QColor greenColor(Qt::green);
    QPen dataPen(greenColor);

	// draw the fields and the text ----------------------------------------------------------------
    {
        int current = heightPerField;
        for (int i = 0; i < (NbBits - 1); i++)
        {
            painter.setPen(linePen);
            painter.drawLine(0, current, size.width(), current);
            
            painter.setPen(textPen);
            QString lbl = QString::number(i+1);
            if (currentlabels.contains(i+1)) lbl += "-"+currentlabels[i+1];
            painter.drawText(10, current - heightPerField / 3, lbl);
            current += heightPerField;
        }
        painter.setPen(textPen);
        painter.drawText(10, current - 15, QString::number(NbBits));
    }

	painter.end();
}
コード例 #19
0
void DlgHisto::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CDemoDoc* pDoc = (CDemoDoc*) ((CMainFrame*)AfxGetMainWnd())->GetActiveFrame()->GetActiveDocument();

	RECT r;
	GetClientRect(&r);

	CPen gridPen(PS_DOT,1,::GetSysColor(COLOR_APPWORKSPACE));
	CPen* pOldPen = dc.SelectObject(&gridPen);
	for (int gx=9+32;gx<265;gx+=32){
		dc.MoveTo(gx,40);
		dc.LineTo(gx,r.bottom - 6);
	}
	for (int gy=0;gy<(r.bottom - 40);gy+=((r.bottom - 40)/10)){
		dc.MoveTo(8,r.bottom - 9 - gy);
		dc.LineTo(268,r.bottom - 9 - gy);
	}
	dc.SelectObject(pOldPen);

	CPen axisPen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
	pOldPen = dc.SelectObject(&axisPen);
	dc.MoveTo(9, 38);
	dc.LineTo(9, r.bottom - 9);
	dc.LineTo(266, r.bottom - 9);
	dc.LineTo(266, 38);
	dc.SelectObject(pOldPen);

	if (pDoc && pDoc->image) {

		if (pDoc->m_hmax){
			int ybase = r.bottom-10;
			if (m_logen){
				float yratio = (r.bottom - r.top - 50)/(float)log10((float)(pDoc->m_hmax+1));
				if (m_ren){
					CPen redPen(PS_SOLID, 1, RGB(222, 0, 0));
					pOldPen = dc.SelectObject(&redPen);
					dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hr[0]))*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hr[x]))*yratio));
				}
				if (m_gen){
					CPen greenPen(PS_SOLID, 1, RGB(0, 222, 0));
					pOldPen = dc.SelectObject(&greenPen);
					dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hg[0]))*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hg[x]))*yratio));
				}
				if (m_ben){
					CPen bluePen(PS_SOLID, 1, RGB(0, 0, 222));
					pOldPen = dc.SelectObject(&bluePen);
					dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hb[0]))*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hb[x]))*yratio));
				}
				if (m_grayen){
					CPen grayPen(PS_SOLID, 1, RGB(64, 64, 64));
					pOldPen = dc.SelectObject(&grayPen);
					dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hgray[0]))*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hgray[x]))*yratio));
				}
				dc.SelectObject(pOldPen);
			} else {
				float yratio = (r.bottom - r.top - 50)/(float)pDoc->m_hmax;
				if (m_ren){
					CPen redPen(PS_SOLID, 1, RGB(222, 0, 0));
					pOldPen = dc.SelectObject(&redPen);
					dc.MoveTo(10, (int)(ybase-pDoc->m_hr[0]*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-pDoc->m_hr[x]*yratio));
				}
				if (m_gen){
					CPen greenPen(PS_SOLID, 1, RGB(0, 222, 0));
					pOldPen = dc.SelectObject(&greenPen);
					dc.MoveTo(10, (int)(ybase-pDoc->m_hg[0]*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-pDoc->m_hg[x]*yratio));
				}
				if (m_ben){
					CPen bluePen(PS_SOLID, 1, RGB(0, 0, 222));
					pOldPen = dc.SelectObject(&bluePen);
					dc.MoveTo(10, (int)(ybase-pDoc->m_hb[0]*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-pDoc->m_hb[x]*yratio));
				}
				if (m_grayen){
					CPen grayPen(PS_SOLID, 1, RGB(64, 64, 64));
					pOldPen = dc.SelectObject(&grayPen);
					dc.MoveTo(10, (int)(ybase-pDoc->m_hgray[0]*yratio));
					for (int x=1; x<256; x++)
						dc.LineTo(x+10, (int)(ybase-pDoc->m_hgray[x]*yratio));
				}
				dc.SelectObject(pOldPen);
			}
		}
		else
		{
			pDoc->m_hmax=pDoc->GetImage()->Histogram(pDoc->m_hr,pDoc->m_hg,pDoc->m_hb,pDoc->m_hgray);
			if (pDoc->m_hmax) Invalidate();
		}
	}
}
コード例 #20
0
ファイル: tWindPlotGraph.cpp プロジェクト: dulton/53_hero
//-----------------------------------------------------------------------------
//!
//-----------------------------------------------------------------------------
void tWindPlotGraph::paintEvent( QPaintEvent* /*pEvent*/ )
{
    // TODO TC tidy up these comments
    //int w = contentsRect().width();

    // Create the painter
    QPainter p( this );
    p.setRenderHint( QPainter::Antialiasing, true );
    Widgets::DrawGaugeBackground(p, palette(), rect());

    QColor c = palette().text().color();
    c.setAlpha( 128 );
    QPen gridPen( c );
    p.setPen( gridPen );

    QColor brushColor = palette().base().color();
    brushColor.setAlpha( 128 );
    p.setBrush( brushColor );

    // Add graph backgrounds
    p.drawRect( m_GraphConfig.originX[0], m_GraphConfig.originY, m_GraphConfig.extentX[0], m_GraphConfig.extentY );
    p.drawRect( m_GraphConfig.originX[1], m_GraphConfig.originY, m_GraphConfig.extentX[1], m_GraphConfig.extentY );

    // Draw the numbers on the axes
    p.setFont( m_AxisFont );
    p.setRenderHint( QPainter::Antialiasing, false );
    p.setPen( palette().text().color() );

    // Draw the value numbers on the X Axes
    int graphCount;

    for(graphCount = 0; graphCount < 2; graphCount++)
    {
        if(m_GraphConfig.gotData[graphCount])
        {
            // Draw the average label
            QRect avoidRect;
            QRect averageRect = DrawXAxisLabel(&p, static_cast<eGraphType>(graphCount), m_GraphConfig.averageValue[graphCount], eXAxisLabel_Average, avoidRect);

            // Draw the min and max labels but only if they don't overwrite the average label
            DrawXAxisLabel(&p, static_cast<eGraphType>(graphCount), m_GraphConfig.minValue[graphCount], eXAxisLabel_Left, averageRect);
            DrawXAxisLabel(&p, static_cast<eGraphType>(graphCount), m_GraphConfig.maxValue[graphCount], eXAxisLabel_Right, averageRect);
        }
    }

    // Draw Time numbers on the Y Axis
    int timeIncrement;
    switch(m_TimePlotRange)
    {
        case TimePlot::eTPR_1Min :
            for(timeIncrement = 0; timeIncrement <= 1; timeIncrement++)
            {
                DrawTimeLabelAndGridLine(p, gridPen, timeIncrement);
            }
            break;

        case TimePlot::eTPR_5Min :
            for(timeIncrement = 0; timeIncrement <= 5; timeIncrement++)
            {
                DrawTimeLabelAndGridLine(p, gridPen, timeIncrement);
            }
            break;

        case TimePlot::eTPR_10Min :
            for(timeIncrement = 0; timeIncrement <= 10; timeIncrement += 2)
            {
                DrawTimeLabelAndGridLine(p, gridPen, timeIncrement);
            }
            break;

        case TimePlot::eTPR_30Min :
            for(timeIncrement = 0; timeIncrement <= 30; timeIncrement += 10)
            {
                DrawTimeLabelAndGridLine(p, gridPen, timeIncrement);
            }
            break;

        case TimePlot::eTPR_60Min :
            for(timeIncrement = 0; timeIncrement <= 60; timeIncrement += 15)
            {
                DrawTimeLabelAndGridLine(p, gridPen, timeIncrement);
            }
            break;

        default :
            Assert(0);
            break;
    }

    p.setRenderHint( QPainter::Antialiasing, true );

    // Setup the pen
    p.save();
    bool nightMode = tSystemSettings::Instance()->NightMode();
    QColor lineColor;
    if( nightMode )
    {
        lineColor = palette().highlight().color();
    }
    else
    {
        lineColor = tInstrumentUiSettings::Instance()->Color( tInstrumentUiSettings::PlotLine );
    }
    QPen penGraph( lineColor );
    penGraph.setWidth(2);
    p.setPen(penGraph);

    // Draw the data
    for(graphCount = 0; graphCount < 2; graphCount++)
    {
        if(m_GraphConfig.gotData[graphCount])
        {
            int time = 0;
            int lastTime;
            float value;
            float lastValue;
            bool lastValueValid;
            tDigitalTimePlotData::eDataEntryType entryType;

            bool gotValue;

            if(graphCount == eGraphType_TWD)
            {
                gotValue = m_TimePlotData[graphCount].GetLastValueInUserUnitsLinear(&entryType, &lastValue);
            }
            else
            {
                gotValue = m_TimePlotData[graphCount].GetLastValueInUserUnits(&entryType, &lastValue);
            }

            if(gotValue == true)
            {
                if(entryType != tDigitalTimePlotData::eDataEntryType_Valid)
                {
                    // Value is invalid
                    lastValueValid = false;
                    penGraph.setStyle(Qt::DotLine);
                    p.setPen( penGraph );
                }
                else
                {
                    // Value is valid
                    lastValueValid = true;
                    penGraph.setStyle(Qt::SolidLine);
                    p.setPen( penGraph );
                }

                // Set the time of the last entry
                lastTime = time;

                time++;

                if(graphCount == eGraphType_TWD)
                {
                    gotValue = m_TimePlotData[graphCount].GetPreviousValueInUserUnitsLinear(&entryType, &value);
                }
                else
                {
                    gotValue = m_TimePlotData[graphCount].GetPreviousValueInUserUnits(&entryType, &value);
                }

                while(gotValue)
                {
                    // Got the next value
                    if(entryType == tDigitalTimePlotData::eDataEntryType_Valid)
                    {
                        // If the last value was valid then draw a line between the last valid value and this value
                        if(lastValueValid)
                        {
                            p.drawLine(GraphToPixel(static_cast<eGraphType>(graphCount), lastTime, lastValue),
                                       GraphToPixel(static_cast<eGraphType>(graphCount), time, value));
                        }
                        else
                        {
                            // Last value is not valid so draw a dotted line from the top of the graph to the current value
                            p.drawLine(GraphToPixel(static_cast<eGraphType>(graphCount), lastTime, value),
                                       GraphToPixel(static_cast<eGraphType>(graphCount), time, value));
                        }

                        // Update the pen to be a solid line as value is valid
                        penGraph.setStyle(Qt::SolidLine);
                        p.setPen( penGraph );

                        // Save the details of this value and note that we've had valid data
                        lastValue = value;
                        lastTime = time;
                        lastValueValid = true;
                    }
                    else
                    {
                        // The value was invalid so set the pen to a dotted line and note
                        // we've had invalid data
                        penGraph.setStyle(Qt::DotLine);
                        p.setPen( penGraph );
                    }

                    // Increase the time
                    time++;

                    if(graphCount == eGraphType_TWD)
                    {
                        gotValue = m_TimePlotData[graphCount].GetPreviousValueInUserUnitsLinear(&entryType, &value);
                    }
                    else
                    {
                        gotValue = m_TimePlotData[graphCount].GetPreviousValueInUserUnits(&entryType, &value);
                    }
                }
            }
        }
    }

    p.restore();
}
コード例 #21
0
void statisticSource::drawStatisticsImage(QPixmap *img, StatisticsItemList statsList, StatisticsType statsType)
{
	QPainter painter(img);

	StatisticsItemList::iterator it;
	for (it = statsList.begin(); it != statsList.end(); ++it)
	{
		StatisticsItem anItem = *it;

		switch (anItem.type)
		{
		case arrowType:
		{
			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			int x, y;

			// start vector at center of the block
			x = displayRect.left() + displayRect.width() / 2;
			y = displayRect.top() + displayRect.height() / 2;

			QPoint startPoint = QPoint(x, y);

			float vx = anItem.vector[0];
			float vy = anItem.vector[1];

			QPoint arrowBase = QPoint(x + p_internalScaleFactor*vx, y + p_internalScaleFactor*vy);
			QColor arrowColor = anItem.color;
			//arrowColor.setAlpha( arrowColor.alpha()*((float)statsType.alphaFactor / 100.0) );

			QPen arrowPen(arrowColor);
			painter.setPen(arrowPen);
			painter.drawLine(startPoint, arrowBase);

			if (vx == 0 && vy == 0)
			{
				// nothing to draw...
			}
			else
			{
				// draw an arrow
				float nx, ny;

				// TODO: scale arrow head with
				float a = p_internalScaleFactor * 4;    // length of arrow
				float b = p_internalScaleFactor * 2;    // base width of arrow

				float n_abs = sqrtf(vx*vx + vy*vy);
				float vxf = (float)vx / n_abs;
				float vyf = (float)vy / n_abs;

				QPoint arrowTip = arrowBase + QPoint(vxf*a + 0.5, vyf*a + 0.5);

				// arrow head right
				rotateVector((float)-M_PI_2, -vx, -vy, nx, ny);
				QPoint offsetRight = QPoint(nx*b + 0.5, ny*b + 0.5);
				QPoint arrowHeadRight = arrowBase + offsetRight;

				// arrow head left
				rotateVector((float)M_PI_2, -vx, -vy, nx, ny);
				QPoint offsetLeft = QPoint(nx*b + 0.5, ny*b + 0.5);
				QPoint arrowHeadLeft = arrowBase + offsetLeft;

				// draw arrow head
				QPoint points[3] = { arrowTip, arrowHeadRight, arrowHeadLeft };
				painter.setBrush(arrowColor);
				painter.drawPolygon(points, 3);
			}

			break;
		}
		case blockType:
		{
			//draw a rectangle
			QColor rectColor = anItem.color;
			rectColor.setAlpha(rectColor.alpha()*((float)statsType.alphaFactor / 100.0));
			painter.setBrush(rectColor);

			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			painter.fillRect(displayRect, rectColor);

			break;
		}
		}

		// optionally, draw a grid around the region
		if (statsType.renderGrid) {
			//draw a rectangle
			QColor gridColor = anItem.gridColor;
			QPen gridPen(gridColor);
			gridPen.setWidth(1);
			painter.setPen(gridPen);
			painter.setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush));  // no fill color

			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			painter.drawRect(displayRect);
		}
	}
}
コード例 #22
0
// Draw the crossfader curve graph. Only needs to get drawn when a change
// has been made.
void DlgPrefCrossfader::drawXfaderDisplay()
{
    const int kGrindXLines = 4;
    const int kGrindYLines = 6;

    int sizeX = graphicsViewXfader->width();
    int sizeY = graphicsViewXfader->height();

    // Initialize Scene
    if (m_pxfScene) {
        delete m_pxfScene;
        m_pxfScene = NULL;
    }
    m_pxfScene = new QGraphicsScene();
    m_pxfScene->setSceneRect(0,0,sizeX, sizeY);
    m_pxfScene->setBackgroundBrush(Qt::black);

    // Initialize QPens
    QPen gridPen(Qt::green);
    QPen graphLinePen(Qt::white);

    // draw grid
    for (int i = 1; i < kGrindXLines; i++) {
        m_pxfScene->addLine(
                QLineF(0, i * (sizeY / kGrindXLines), sizeX,
                        i * (sizeY / kGrindXLines)), gridPen);
    }
    for (int i = 1; i < kGrindYLines; i++) {
        m_pxfScene->addLine(
                QLineF(i * (sizeX / kGrindYLines), 0,
                        i * (sizeX / kGrindYLines), sizeY), gridPen);
    }

    // Draw graph lines
    QPointF pointTotal, point1, point2;
    QPointF pointTotalPrev, point1Prev, point2Prev;
    int pointCount = sizeX - 4;
    // reduced by 2 x 1 for border + 2 x 1 for inner distance to border
    double xfadeStep = 2. / (pointCount - 1);
    for (int i = 0; i < pointCount; i++) {
        double gain1, gain2;
        EngineXfader::getXfadeGains((-1. + (xfadeStep * i)),
                                    m_transform, m_cal,
                                    m_xFaderMode,
                                    checkBoxReverse->isChecked(),
                                    &gain1, &gain2);

        double gain = sqrt(gain1 * gain1 + gain2 * gain2);
        // scale for graph
        gain1 *= 0.71;
        gain2 *= 0.71;
        gain *= 0.71;

        // draw it
        pointTotal = QPointF(i + 1, (1. - gain) * (sizeY) - 3);
        point1 = QPointF(i + 1, (1. - gain1) * (sizeY) - 3);
        point2 = QPointF(i + 1, (1. - gain2) * (sizeY) - 3);

        if (i > 0) {
            m_pxfScene->addLine(QLineF(pointTotal, pointTotalPrev), QPen(Qt::red));
            m_pxfScene->addLine(QLineF(point1, point1Prev), graphLinePen);
            m_pxfScene->addLine(QLineF(point2, point2Prev), graphLinePen);
        }

        // Save old values
        pointTotalPrev = pointTotal;
        point1Prev = point1;
        point2Prev = point2;
    }

    graphicsViewXfader->setScene(m_pxfScene);
    graphicsViewXfader->show();
    graphicsViewXfader->repaint();
}
コード例 #23
0
/** Draw the crossfader curve graph. Only needs to get drawn when a change has been made.*/
void DlgPrefCrossfader::drawXfaderDisplay()
{
#define GRID_X_LINES 4
#define GRID_Y_LINES 6

    int sizeX = graphicsViewXfader->width();
    int sizeY = graphicsViewXfader->height();

    //Initialize Scene
    if (m_pxfScene) {
        delete m_pxfScene;
        m_pxfScene = NULL;
    }
    m_pxfScene = new QGraphicsScene();
    m_pxfScene->setSceneRect(0,0,sizeX, sizeY);
    m_pxfScene->setBackgroundBrush(Qt::black);

    //Initialize QPens
    QPen gridPen(Qt::green);
    QPen graphLinePen(Qt::white);

    //draw grid
    for (int i=1; i < GRID_X_LINES; i++) {
        m_pxfScene->addLine(QLineF(0, i *(sizeY/GRID_X_LINES),sizeX,i *(sizeY/GRID_X_LINES)), gridPen);
    }
    for (int i=1; i < GRID_Y_LINES; i++) {
        m_pxfScene->addLine(QLineF( i * (sizeX/GRID_Y_LINES), 0, i * (sizeX/GRID_Y_LINES), sizeY), gridPen);
    }

    // Draw graph lines
    float gain1, gain2;
    QPoint pointTotal, point1, point2;
    QPoint pointTotalPrev, point1Prev, point2Prev;
    for (int i = 0; i < sizeX; i++) {
        double xfadeStep = 2. / (double)sizeX;

        EngineXfader::getXfadeGains(gain1, gain2, (-1. + (xfadeStep * (double) i)),
                                    m_transform, m_cal,
                                    (m_xFaderMode == MIXXX_XFADER_CONSTPWR),
                                    checkBoxReverse->isChecked());

        double sum = gain1 + gain2;
        //scale for graph
        gain1 *= 0.80;
        gain2 *= 0.80;
        sum *= 0.80;

        //draw it
        pointTotalPrev = pointTotal;
        point1Prev = point1;
        point2Prev = point2;
        pointTotal = QPoint(i - 2, (int)((1. - sum) * (sizeY)));
        point1 = QPoint(i - 2, (int)((1. - gain1) * (sizeY)));
        point2 = QPoint(i - 2, (int)((1. - gain2) * (sizeY)));
        if(i == 0) {
            pointTotalPrev = pointTotal;
            point1Prev = point1;
            point2Prev = point2;
        }

        if(pointTotal != point1)
            m_pxfScene->addLine(QLineF(point1, point1Prev), graphLinePen);
        if(pointTotal != point2)
            m_pxfScene->addLine(QLineF(point2, point2Prev), graphLinePen);
        m_pxfScene->addLine(QLineF(pointTotal, pointTotalPrev), QPen(Qt::red));
    }

    graphicsViewXfader->setScene(m_pxfScene);
    graphicsViewXfader->show();
}
コード例 #24
0
void Spectrograph::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)

    QPainter painter(this);
    painter.fillRect(rect(), Qt::black);

    const int numBars = m_bars.count();

    // Highlight region of selected bar
    if (m_barSelected != NullIndex && numBars) {
        QRect regionRect = rect();
        regionRect.setLeft(m_barSelected * rect().width() / numBars);
        regionRect.setWidth(rect().width() / numBars);
        QColor regionColor(0, 0, 64);
        painter.setBrush(Qt::DiagCrossPattern);
        painter.fillRect(regionRect, regionColor);
        painter.setBrush(Qt::NoBrush);
    }

    QColor barColor(0, 0, 255);
    QColor clipColor(255, 0, 0);

    // Draw the outline
    const QColor gridColor = barColor.darker();
    QPen gridPen(gridColor);
    painter.setPen(gridPen);
    painter.drawLine(rect().topLeft(), rect().topRight());
    painter.drawLine(rect().topRight(), rect().bottomRight());
    painter.drawLine(rect().bottomRight(), rect().bottomLeft());
    painter.drawLine(rect().bottomLeft(), rect().topLeft());

    QVector<qreal> dashes;
    dashes << 2 << 2;
    gridPen.setDashPattern(dashes);
    painter.setPen(gridPen);

    // Draw vertical lines between bars
    if (numBars) {
        const int numHorizontalSections = numBars;
        QLine line(rect().topLeft(), rect().bottomLeft());
        for (int i=1; i<numHorizontalSections; ++i) {
            line.translate(rect().width()/numHorizontalSections, 0);
            painter.drawLine(line);
        }
    }

    // Draw horizontal lines
    const int numVerticalSections = 10;
    QLine line(rect().topLeft(), rect().topRight());
    for (int i=1; i<numVerticalSections; ++i) {
        line.translate(0, rect().height()/numVerticalSections);
        painter.drawLine(line);
    }

    barColor = barColor.lighter();
    barColor.setAlphaF(0.75);
    clipColor.setAlphaF(0.75);

    // Draw the bars
    if (numBars) {
        // Calculate width of bars and gaps
        const int widgetWidth = rect().width();
        const int barPlusGapWidth = widgetWidth / numBars;
        const int barWidth = 0.8 * barPlusGapWidth;
        const int gapWidth = barPlusGapWidth - barWidth;
        const int paddingWidth = widgetWidth - numBars * (barWidth + gapWidth);
        const int leftPaddingWidth = (paddingWidth + gapWidth) / 2;
        const int barHeight = rect().height() - 2 * gapWidth;

        for (int i=0; i<numBars; ++i) {
            const qreal value = m_bars[i].value;
            Q_ASSERT(value >= 0.0 && value <= 1.0);
            QRect bar = rect();
            bar.setLeft(rect().left() + leftPaddingWidth + (i * (gapWidth + barWidth)));
            bar.setWidth(barWidth);
            bar.setTop(rect().top() + gapWidth + (1.0 - value) * barHeight);
            bar.setBottom(rect().bottom() - gapWidth);

            QColor color = barColor;
            if (m_bars[i].clipped)
                color = clipColor;

            painter.fillRect(bar, color);
        }
    }
}
コード例 #25
0
void BpDocument::composeGraphBasics( Graph *g,
    bool isLineGraph, EqVar *xVar, EqVar *yVar, EqVar *zVar,
    int curves, GraphAxleParms *xParms, GraphAxleParms *yParms )
{
    //--------------------------------------------------------------------------
    // Set the logical fonts and colors here
    //--------------------------------------------------------------------------

    // Axis text fonts.
    QFont  textFont( property()->string( "graphTextFontFamily" ),
                    property()->integer( "graphTextFontSize" ) );
    QPen   textPen( property()->color( "graphTextFontColor" ) );

    QFont  axleFont( textFont );
    QColor axleColor( property()->color( "graphAxleColor" ) );
    QPen   axlePen( axleColor,
                property()->integer( "graphAxleWidth" ), Qt::SolidLine );
    QPen   gridPen( property()->color( "graphGridColor" ),
                property()->integer( "graphGridWidth" ), Qt::SolidLine );

    // Title fonts and colors.
    QFont  subTitleFont( property()->string( "graphSubtitleFontFamily" ),
                    property()->integer( "graphSubtitleFontSize" ) );
    QColor subTitleColor( property()->color( "graphSubtitleFontColor" ) );

    QFont  titleFont( property()->string( "graphTitleFontFamily" ),
                    property()->integer( "graphTitleFontSize" ) );
    QColor titleColor( property()->color( "graphTitleFontColor" ) );

    // Background and canvas colors.
    QBrush worldBg( property()->color( "graphBackgroundColor" ),
                Qt::SolidPattern );
    QBrush canvasBg( "white", SolidPattern );
    QPen   canvasBox( "black", 1, NoPen );

    //--------------------------------------------------------------------------
    // Create the graph canvas, world, and decoration.
    //--------------------------------------------------------------------------

    // Get the x- and y-axle parameters
    double xValMin    = xParms->m_axleMin;
    double xValMax    = xParms->m_axleMax;
    double xMajorStep = xParms->m_majorStep;
    int    xDec       = xParms->m_decimals;

    double yValMin    = yParms->m_axleMin;
    double yValMax    = yParms->m_axleMax;
    double yMajorStep = yParms->m_majorStep;
    int    yDec       = yParms->m_decimals;

    // Graph title and subtitle.
    QString qStr = m_eqTree->m_eqCalc->docDescriptionStore().stripWhiteSpace();
    //if ( qStr.isNull() || qStr.isEmpty() )
    //{
    //  translate( qStr, "BpDocument:NoRunDescription" );
    //}
    g->setTitle( qStr, titleFont, titleColor );

    if ( property()->boolean( "graphTitleActive" ) )
    {
        QString text("");
        translate( text, "BpDocument:Graphs:By" );
        qStr = *(yVar->m_label) + "\n" + text + " " + *(xVar->m_label);
        if ( curves > 1 && isLineGraph && zVar )
        {
            translate( text, "BpDocument:Graphs:And" );
            qStr += "\n" + text + " " + *(zVar->m_label);
        }
        g->setSubTitle( qStr, subTitleFont, subTitleColor );
    }

    // Use portrait orientation (assuming screen output, not printer).
    g->setCanvasRotation( 0.0 );
    g->setCanvasScale( 1.0, 1.0 );
    // NOTE: to change the graph location or size,
    // we must manipulate the m_composer->graph() args!
    g->setCanvas(
        m_screenSize->m_marginLeft,     // upper left X pixel
        m_screenSize->m_marginTop,      // upper left Y pixel
        m_screenSize->m_bodyWd,         // graph canvas width in pixels
        m_screenSize->m_bodyHt,         // graph canvas height in pixels
        0                               // graph border in pixels
    );

    // Canvas background and box.
    g->setCanvasBg( canvasBg );
    g->setCanvasBox( canvasBox );

    // Make the world coordinate system 20% larger than the data range.
    g->setWorld(
        xValMin - 0.2 * (xValMax-xValMin),  // canvas WORLD left coordinate
        yValMin - 0.2 * (yValMax-yValMin),  // canvas WORLD bottom coordinate
        xValMax + 0.1 * (xValMax-xValMin),  // canvas WORLD right coordinate
        yValMax + 0.1 * (yValMax-yValMin)   // canvas WORLD top coordinate
    );

    // Provide a colored background for the graph area.
    g->setWorldBg(
        xValMin,                        // colored bg WORLD left coordinate
        yValMin,                        // colored bg WORLD bottom coordinate
        xValMax,                        // colored bg WORLD right coordinate
        yValMax,                        // colored bg WORLD top coordinate
        worldBg                         // brush color and pattern
    );

    //--------------------------------------------------------------------------
    // Create a bottom axle with endpoints in WORLD coordinates (not AXLE).
    // This has all elements of an axle EXCEPT a minor grid and subtitle.
    //--------------------------------------------------------------------------

    GraphAxle *b = g->addGraphAxle(
        xValMin,                        // axle's min scale (NOT WORLD) value
        xValMax,                        // axle's max scale (NOT WORLD) value
        axlePen                         // axle line pen (color, width, style)
    );

    b->setWorld(
        xValMin,                        // axle's start WORLD x coordinate
        yValMin,                        // axle's start WORLD y coordinate
        xValMax,                        // axle's end WORLD x coordinate
        yValMin                         // axle's end WORLD y coordinate
    );

    // Line graph bottom axles need labels and tic marks.
    if ( isLineGraph )
    {
        b->setMajorLabels(
            axleFont,                   // label font
            axleColor,                  // font color
            xDec                        // decimal places (-1 mean no label)
        );

        b->setMajorTics(
            GraphAxleBottom,                 // side of axle to draw tic marks
            xValMin,                    // first tic mark location in AXLE units
            xValMax,                    // last tic mark location in AXLE units
            xMajorStep,                 // tic spacing in AXLE units
            0.05 * (yValMax-yValMin),   // tic mark length in Y WORLD units
            axlePen                     // tic pen (color, width, style)
        );

        b->setMinorTics(
            GraphAxleBottom,                 // side of axle to draw tic marks
            xValMin,                    // first tic mark location in AXLE units
            xValMax,                    // last tic mark location in AXLE units
            0.50 * xMajorStep,          // tic spacing in AXLE units
            0.03 * (yValMax-yValMin),   // tic mark length in Y WORLD units
            axlePen                     // tic pen (color, width, style)
        );

        b->setMajorGrid(
            gridPen,                    // grid pen color, width, style
            (yValMax-yValMin)           // length in Y WORLD units !!
        );

        // Don't show the units for ratio variables.
        qStr = *(xVar->m_label) + " " + xVar->displayUnits(true);
        b->setTitle(
            qStr,                       // axle title string
            GraphAxleBottom,                 // axle side to write the string
            axleFont,                   // axle title font
            axleColor                   // axle title color
        );
    }
    // Bar graphs just need the title.
    else
    {
        b->setTitle(
            *(xVar->m_label),           // axle title string
            GraphAxleBottom,                 // axle side to write the string
            axleFont,                   // axle title font
            axleColor                   // axle title color
        );
    }

    //--------------------------------------------------------------------------
    // Create a top axle with endpoints in WORLD coordinates (not AXLE)
    // Same as bottom axle EXCEPT no tic labels or axle label
    //--------------------------------------------------------------------------

    // Line graph top axles need tic marks.
    if ( isLineGraph )
    {
        GraphAxle *t = g->addGraphAxle(
            xValMin,                    // axle's min scale (NOT WORLD) value
            xValMax,                    // axle's max scale (NOT WORLD) value
            axlePen                     // axle line pen (color, width, style)
        );

        t->setWorld(
            xValMin,                    // axle's start WORLD x coordinate
            yValMax,                    // axle's start WORLD y coordinate
            xValMax,                    // axle's end WORLD x coordinate
            yValMax                     // axle's end WORLD y coordinate
        );

        if ( false )
        t->setMajorTics(
            GraphAxleTop,                    // side of axle to draw tic marks
            xValMin,                    // first tic mark location in AXLE units
            xValMax,                    // last tic mark location in AXLE units
            xMajorStep,                 // tic spacing in AXLE units
            0.05 * (yValMax-yValMin),   // tic mark length in WORLD units
            axlePen                     // tic pen (color, width, style)
        );

        if ( false )
        t->setMinorTics(
            GraphAxleTop,                    // side of axle to draw tic marks
            xValMin,                    // first tic mark location in AXLE units
            xValMax,                    // last tic mark location in AXLE units
            0.50 * xMajorStep,          // tic spacing in AXLE units
            0.03 * (yValMax-yValMin),   // tic mark length in WORLD units
            axlePen                     // tic pen (color, width, style)
        );
    }

    //--------------------------------------------------------------------------
    // Create a left axle with endpoints in WORLD coordinates (not AXLE)
    // This has all elements of an axle EXCEPT a minor grid and subtitle
    //--------------------------------------------------------------------------

    GraphAxle *l = g->addGraphAxle(
        yValMin,                        // axle's min scale (NOT WORLD) value
        yValMax,                        // axle's max scale (NOT WORLD) value
        axlePen                         // axle line pen (color, width, style)
    );

    l->setWorld(
        xValMin,                        // axle's start WORLD x coordinate
        yValMin,                        // axle's start WORLD y coordinate
        xValMin,                        // axle's end WORLD x coordinate
        yValMax                         // axle's end WORLD y coordinate
    );

    l->setMajorLabels(
        axleFont,                       // label font
        axleColor,                      // font color
        yDec                            // decimal places (-1 mean no label)
    );

    l->setMajorTics(
        GraphAxleLeft,                       // side of axle to draw tic marks
        yValMin,                        // first tic mark location in AXLE units
        yValMax,                        // last tic mark location in AXLE units
        yMajorStep,                     // tic spacing in AXLE units
        0.04 * (xValMax-xValMin),       // tic mark length in X WORLD units
        axlePen                         // tic pen (color, width, style)
    );

    l->setMinorTics(
        GraphAxleLeft,                       // side of axle to draw tic marks
        yValMin,                        // first tic mark location in AXLE units
        yValMax,                        // last tic mark location in AXLE units
        0.50 * yMajorStep,              // tic spacing in AXLE units
        0.02 * (xValMax-xValMin),       // tic mark length in X WORLD units
        axlePen                         // tic pen (color, width, style)
    );

    l->setMajorGrid(
        gridPen,                        // grid pen color, width, style
        (xValMax-xValMin)               // length in X axis WORLD units !!
    );

    // Don't show the units for fraction or ratio variables.
    qStr = *(yVar->m_label) + " " + yVar->displayUnits(true);
    l->setTitle(
        qStr,                           // axle title string
        GraphAxleLeft,                  // axle side to write the string
        axleFont,                       // axle title font
        axleColor                       // axle title font color
    );

    //--------------------------------------------------------------------------
    // Create a right axle with endpoints in WORLD coordinates (not AXLE)
    // Same as the left axle EXCEPT no tic labels or axle label.
    //--------------------------------------------------------------------------

    GraphAxle *r = g->addGraphAxle(
        yValMin,                        // axle's min scale (NOT WORLD) value
        yValMax,                        // axle's max scale (NOT WORLD) value
        axlePen                         // axle line pen (color, width, style)
    );

    r->setWorld(
        xValMax,                        // axle's start WORLD x coordinate
        yValMin,                        // axle's start WORLD y coordinate
        xValMax,                        // axle's end WORLD x coordinate
        yValMax                         // axle's end WORLD y coordinate
    );

    if ( false )
    r->setMajorTics(
        GraphAxleRight,                      // side of axle to draw tic marks
        yValMin,                        // first tic mark location in AXLE units
        yValMax,                        // last tic mark location in AXLE units
        yMajorStep,                     // tic spacing in AXLE units
        0.04 * (xValMax-xValMin),       // tic mark length in X WORLD units
        axlePen                         // tic pen (color, width, style)
    );

    if ( false )
    r->setMinorTics(
        GraphAxleLeft,                       // side of axle to draw tic marks
        yValMin,                        // first tic mark location in AXLE units
        yValMax,                        // last tic mark location in AXLE units
        0.50 * yMajorStep,              // tic spacing in AXLE units
        0.02 * (xValMax-xValMin),       // tic mark length in X WORLD units
        axlePen                         // tic pen (color, width, style)
    );

    return;
}
コード例 #26
0
ファイル: PowerHist.cpp プロジェクト: ClaFio/GoldenCheetah
void
PowerHist::configChanged()
{
    // plot background
    setCanvasBackground(GColor(CPLOTBACKGROUND));

    // curve
    QPen pen;
    QColor brush_color;

    if (source == Metric) {

        pen.setColor(metricColor.darker(200));
        brush_color = metricColor;

    } else {

        switch (series) {
        case RideFile::watts:
        case RideFile::aPower:
        case RideFile::wattsKg:
            pen.setColor(GColor(CPOWER).darker(200));
            brush_color = GColor(CPOWER);
            break;
        case RideFile::nm:
            pen.setColor(GColor(CTORQUE).darker(200));
            brush_color = GColor(CTORQUE);
            break;
        case RideFile::kph:
            pen.setColor(GColor(CSPEED).darker(200));
            brush_color = GColor(CSPEED);
            break;
        case RideFile::cad:
            pen.setColor(GColor(CCADENCE).darker(200));
            brush_color = GColor(CCADENCE);
            break;
        default:
        case RideFile::hr:
            pen.setColor(GColor(CHEARTRATE).darker(200));
            brush_color = GColor(CHEARTRATE);
            break;
        }
    }

    double width = appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble();
    if (appsettings->value(this, GC_ANTIALIAS, false).toBool()==true) {
        curve->setRenderHint(QwtPlotItem::RenderAntialiased);
        curveSelected->setRenderHint(QwtPlotItem::RenderAntialiased);
    }

    // use a linear gradient
    brush_color.setAlpha(64);
    QColor brush_color1 = brush_color.darker();
    QLinearGradient linearGradient(0, 0, 0, height());
    linearGradient.setColorAt(0.0, brush_color);
    linearGradient.setColorAt(1.0, brush_color1);
    linearGradient.setSpread(QGradient::PadSpread);
    curve->setBrush(linearGradient);   // fill below the line

    if (zoned == false || (zoned == true && (series != RideFile::watts && series != RideFile::wattsKg && series != RideFile::hr))) {
        pen.setWidth(width);
        curve->setPen(pen);

    } else {
        pen.setWidth(width);
        curve->setPen(Qt::NoPen);
    }

    // intervalselection
    QPen ivl(GColor(CINTERVALHIGHLIGHTER).darker(200));
    ivl.setWidth(width);
    curveSelected->setPen(ivl);
    QColor ivlbrush = GColor(CINTERVALHIGHLIGHTER);
    ivlbrush.setAlpha(64);
    curveSelected->setBrush(ivlbrush);   // fill below the line

    // grid
    QPen gridPen(GColor(CPLOTGRID));
    //gridPen.setStyle(Qt::DotLine);
    grid->setPen(gridPen);
}
コード例 #27
0
ファイル: main.cpp プロジェクト: Wushaowei001/mksPlanner
int main(int argc, char *argv[]) {
	QApplication a(argc, argv);
	KDChart::Chart chart;

	QStandardItemModel model;

        const double offset = 600;
	model.setRowCount( 100 );
	model.setColumnCount( 2 ); // 1 data set
	for ( int i = 0; i < 100; ++i ) {
		double t = i + offset;
		double v = i + offset;
		QModelIndex index = model.index( i, 0 );
		model.setData( index, t );
		index = model.index( i, 1 );
		model.setData( index, v );
	}

	model.setHeaderData( 0, Qt::Horizontal, "Dataset 1" );

	// general chart layout
	KDChart::FrameAttributes fm = chart.frameAttributes();
	fm.setVisible( true );
	fm.setPen( QPen( Qt::black ) );
	chart.setFrameAttributes( fm );
	chart.setGlobalLeading( 10, 0, 10, 10 );

	KDChart::BackgroundAttributes chart_bg;
	chart_bg.setBrush( Qt::white );
	chart_bg.setVisible( true );
	chart.setBackgroundAttributes( chart_bg );

	// coordinate plane setup
	KDChart::AbstractCoordinatePlane * plane1 = chart.coordinatePlane();
	plane1->setRubberBandZoomingEnabled( true );

	// create cartesian diagrams
	KDChart::Plotter * plotter = new KDChart::Plotter;
	plotter->setAntiAliasing( false );
	plotter->setModel( &model );
	plane1->replaceDiagram( plotter );

	// customize grids
	KDChart::CartesianCoordinatePlane * cp1 = static_cast< KDChart::CartesianCoordinatePlane * >( plane1 );
	KDChart::GridAttributes gv = cp1->gridAttributes( Qt::Vertical );
	QPen gridPen( QColor( 200, 100, 100 ) );
	gridPen.setStyle( Qt::DashLine );
	gv.setGridPen( gridPen );
	gridPen.setStyle( Qt::DotLine );
	gridPen.setColor( QColor( 255,155,155 ) );
	gv.setSubGridPen( gridPen );
	cp1->setGridAttributes( Qt::Vertical,  gv );

        // Enable isometric scaling
        cp1->setIsometricScaling( true );

	// axis
	KDChart::CartesianAxis * xAxis = new KDChart::CartesianAxis( plotter );
	xAxis->setPosition( KDChart::CartesianAxis::Bottom );
	xAxis->setTitleText("X-Title");

	KDChart::TextAttributes att = xAxis->titleTextAttributes();
	QFont f = att.font();
	f.setBold( true );
	att.setFont( f );
	att.setAutoShrink( true );
	att.setFontSize( KDChart::Measure( 16 ) );
	xAxis->setTitleTextAttributes( att );

	KDChart::CartesianAxis * y1Axis = new KDChart::CartesianAxis( plotter );
	y1Axis->setPosition( KDChart::CartesianAxis::Left );
	y1Axis->setTitleText( "Y-Title" );

	att = y1Axis->titleTextAttributes();
	f = att.font();
	f.setBold( true );
	att.setFont( f );
	att.setAutoShrink( true );
	att.setFontSize( KDChart::Measure( 16 ) );
	y1Axis->setTitleTextAttributes( att );

	// add the axis to the plotter
	plotter->addAxis( xAxis );
	plotter->addAxis( y1Axis );

	// create legend
	KDChart::Legend * legend = new KDChart::Legend( plotter, &chart );
	chart.addLegend( legend );
	att = legend->textAttributes();
	f = att.font();
	f.setBold( false );
	att.setFont( f );
	att.setAutoShrink( true );
	legend->setTextAttributes( att );

	legend->setPosition( KDChart::Position::East );
	legend->setAlignment( Qt::AlignCenter );
	legend->setTitleText( "Curves" );
	att = legend->titleTextAttributes();
	f = att.font();
	f.setBold( true );
	att.setFont( f );
	att.setAutoShrink( true );
	att.setFontSize( KDChart::Measure( 16 ) );
	legend->setTitleTextAttributes( att );

	KDChart::BackgroundAttributes legend_bg;
	legend_bg.setBrush( Qt::white );
	legend_bg.setVisible( true );
	legend->setBackgroundAttributes( legend_bg );

	KDChart::DataValueAttributes attr = plotter->dataValueAttributes();
	KDChart::TextAttributes tattr = attr.textAttributes();
        tattr.setFontSize( KDChart::Measure( 12, KDChartEnums::MeasureCalculationModeAbsolute ) );
	tattr.setRotation( 0 );
	attr.setTextAttributes( tattr );
	plotter->setDataValueAttributes( attr );

	// customize marker properties

	// Dataset 1 : green, MarkerRing, no line
	QColor SERIES_1_OUTLINE = QColor( 0, 128, 0 );
	attr = plotter->dataValueAttributes( 0 );
	KDChart::MarkerAttributes mattr = attr.markerAttributes();
	mattr.setMarkerColor( SERIES_1_OUTLINE );
//        mattr.setMarkerStyle( KDChart::MarkerAttributes::MarkerRing );
	mattr.setMarkerSize( QSizeF( 6.0, 6.0 ) );
	mattr.setVisible( true );
	attr.setMarkerAttributes( mattr );
	attr.setVisible( true );
	plotter->setDataValueAttributes( 0, attr );
	plotter->setPen( 0, Qt::NoPen );

	chart.show();
	return a.exec();
}
コード例 #28
0
ファイル: ScatterPlot.cpp プロジェクト: ClaFio/GoldenCheetah
void ScatterPlot::setData (ScatterSettings *settings)
{
    // get application settings
    cranklength = appsettings->value(this, GC_CRANKLENGTH, 0.0).toDouble() / 1000.0;

    // if there are no settings or incomplete settings
    // create a null data plot
    if (settings == NULL || settings->ride == NULL || settings->ride->ride() == NULL ||
        settings->x == 0 || settings->y == 0 ) {
        return;
    }


    // if its not setup or no settings exist default to 175mm cranks
    if (cranklength == 0.0) cranklength = 0.175;

    //
    // Create Main Plot dataset - used to frame intervals
    //
    int points=0;

    x.clear();
    y.clear();
    x.resize(settings->ride->ride()->dataPoints().count());
    y.resize(settings->ride->ride()->dataPoints().count());

    double maxY = maxX = -65535;
    double minY = minX = 65535;

    foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) {

        double xv = x[points] = pointType(point, settings->x, context->athlete->useMetricUnits, cranklength);
        double yv = y[points] = pointType(point, settings->y, context->athlete->useMetricUnits, cranklength);

        // skip zeroes?
        if (!(settings->ignore && (x[points] == 0 || y[points] == 0))) {
            points++;
            if (yv > maxY) maxY = yv;
            if (yv < minY) minY = yv;
            if (xv > maxX) maxX = xv;
            if (xv < minX) minX = xv;
        }
    }

    QwtSymbol sym;
    sym.setStyle(QwtSymbol::Ellipse);
    sym.setSize(6);
    sym.setPen(GCColor::invert(GColor(CPLOTBACKGROUND)));
    sym.setBrush(QBrush(Qt::NoBrush));
    QPen p;
    p.setColor(GColor(CPLOTSYMBOL));
    sym.setPen(p);

    // wipe away existing
	if (all) {
        all->detach();
	    delete all;
    }

    // setup the framing curve
    if (settings->frame) {
        all = new QwtPlotCurve();
        all->setSymbol(new QwtSymbol(sym));
        all->setStyle(QwtPlotCurve::Dots);
        all->setRenderHint(QwtPlotItem::RenderAntialiased);
	    all->setData(x.constData(), y.constData(), points);
        all->attach(this);
    } else {
        all = NULL;
    }

    QPen gridPen(GColor(CPLOTGRID));
    gridPen.setStyle(Qt::DotLine);

    if (grid) {
        grid->detach();
        delete grid;
    }

    if (settings->gridlines) {
        grid = new QwtPlotGrid();
        grid->setPen(gridPen);
        grid->enableX(true);
        grid->enableY(true);
        grid->attach(this);
    } else {
        grid = NULL;
    }

    setAxisTitle(yLeft, describeType(settings->y, true, useMetricUnits));
    setAxisTitle(xBottom, describeType(settings->x, true, useMetricUnits));

    // truncate PfPv values to make easier to read
    if (settings->y == MODEL_AEPF) setAxisScale(yLeft, 0, 600);
    else setAxisScale(yLeft, minY, maxY);
    if (settings->x == MODEL_CPV) setAxisScale(xBottom, 0, 3);
    else setAxisScale(xBottom, minX, maxX);

    //
    // Create Interval Plot dataset - used to frame intervals
    //

    // clear out any interval curves which are presently defined
    if (intervalCurves.size()) {
       QListIterator<QwtPlotCurve *> i(intervalCurves);
       while (i.hasNext()) {
           QwtPlotCurve *curve = i.next();
           curve->detach();
           delete curve;
       }
    }
    intervalCurves.clear();

    // which ones are highlighted then?
    QVector<int> intervals;
    QMap<int,int> displaySequence;

    for (int child=0; child<context->athlete->allIntervalItems()->childCount(); child++) {
        IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(child));
        if ((current != NULL) && current->isSelected()) {
            intervals.append(child);
            displaySequence.insert(current->displaySequence, intervals.count()-1);
        }
    }

    if (intervals.count() > 0) {

        // interval data in here
        QVector<QVector<double> > xvals(intervals.count()); // array of curve x arrays
        QVector<QVector<double> > yvals(intervals.count()); // array of curve x arrays
        QVector<int> points(intervals.count());             // points in eac curve

        // extract interval data
        foreach(const RideFilePoint *point, settings->ride->ride()->dataPoints()) {

            double x = pointType(point, settings->x, useMetricUnits, cranklength);
            double y = pointType(point, settings->y, useMetricUnits, cranklength);

            if (!(settings->ignore && (x == 0 && y ==0))) {

                // which interval is it in?
                for (int idx=0; idx<intervals.count(); idx++) {

                    IntervalItem *current = dynamic_cast<IntervalItem *>(context->athlete->allIntervalItems()->child(intervals[idx]));

                    if (point->secs+settings->ride->ride()->recIntSecs() > current->start && point->secs< current->stop) {
                        xvals[idx].append(x);
                        yvals[idx].append(y);
                        points[idx]++;
                    }
                }
            }
        }

        // now we have the interval data lets create the curves
        QMapIterator<int, int> order(displaySequence);
        while (order.hasNext()) {
            order.next();
            int idx = order.value();

            QPen pen;
            QColor intervalColor;
            intervalColor.setHsv((255/context->athlete->allIntervalItems()->childCount()) * (intervals[idx]), 255,255);
            pen.setColor(intervalColor);
            sym.setPen(pen);

            QwtPlotCurve *curve = new QwtPlotCurve();

            curve->setSymbol(new QwtSymbol(sym));
            curve->setStyle(QwtPlotCurve::Dots);
            curve->setRenderHint(QwtPlotItem::RenderAntialiased);
            curve->setData(xvals[idx].constData(), yvals[idx].constData(), points[idx]);
            curve->attach(this);

            intervalCurves.append(curve);
        }
    }