//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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); }
/** * Constructor, creates a new HistogramToolWindow * * @param title * @param parent */ HistogramToolWindow::HistogramToolWindow(QString title,QWidget *parent) : PlotWindow(title, parent) { p_plot->enableAxis(QwtPlot::yRight); QwtText *leftLabel = new QwtText("Frequency", QwtText::PlainText); leftLabel->setColor(Qt::darkCyan); QFont font = leftLabel->font(); font.setPointSize(13); font.setBold(true); leftLabel->setFont(font); p_plot->setAxisTitle(QwtPlot::yLeft, *leftLabel); p_dock = new QDockWidget("Histogram Info",this); p_dock->setAllowedAreas(Qt::AllDockWidgetAreas); p_dock->setFloating(false); p_dock->setObjectName("DockWidget"); p_dock->setMinimumWidth(130); p_mainWindow->addDockWidget(Qt::LeftDockWidgetArea, p_dock, Qt::Vertical); QwtText *rtLabel = new QwtText("Percentage", QwtText::PlainText); rtLabel->setColor(Qt::red); font = rtLabel->font(); font.setPointSize(13); font.setBold(true); rtLabel->setFont(font); p_plot->setAxisTitle(QwtPlot::yRight,*rtLabel); setAxisLabel(QwtPlot::xBottom,"Pixel Value (DN)"); setScale(QwtPlot::yRight,0,100); setPlotBackground(Qt::white); }
void ScalePicker::selectTitle(QwtScaleWidget *scale, bool select) { if (!scale) return; if (d_title_selected == select && d_selected_axis == scale) return; Graph *g = plot(); g->deselect(); d_title_selected = select; d_selected_axis = scale; d_labels_selected = false; QwtText title = scale->title(); if (select){ title.setBackgroundPen(QPen(Qt::blue)); g->notifyFontChange(title.font()); g->notifyColorChange(title.color()); } else title.setBackgroundPen(QPen(Qt::NoPen)); scale->setTitle(title); }
void Plot2D::topAxisFontSize(const unsigned axisFontSize) { QwtText title = m_qwtPlot->axisTitle(QwtPlot::xTop); QFont font = title.font(); font.setPointSize(axisFontSize); title.setFont(font); m_qwtPlot->setAxisTitle(QwtPlot::xTop, title); }
void Plot2D::titleFontSize(const unsigned titleFontSize) { QwtText title = m_qwtPlot->title(); QFont font = title.font(); font.setPointSize(titleFontSize); title.setFont(font); m_qwtPlot->setTitle(title); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- 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); }
void VectorPlot::addHorizontalLine(double value, QString labelText) { QPen pen(QColor(0, 0, 255)); QwtPlotMarker* horizontalLineMarker = new QwtPlotMarker(); horizontalLineMarker->setLineStyle(QwtPlotMarker::HLine); horizontalLineMarker->setLinePen(pen); horizontalLineMarker->setYValue(value); QwtText label; label.setText(labelText); QFont font = label.font(); font.setPointSize(9); label.setFont(font); horizontalLineMarker->setLabel(label); horizontalLineMarker->setLabelAlignment(Qt::AlignTop | Qt::AlignLeft); horizontalLineMarker->attach(plot); }
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const { PrivateData::Cache &cache = *d_data->cache; switch(item->rtti()) { case QwtPlotItem::Rtti_PlotGrid: { QwtPlotGrid *grid = (QwtPlotGrid *)item; QPen pen = grid->majPen(); cache.gridColors[0] = pen.color(); pen.setColor(color(pen.color(), MajorGrid)); grid->setMajPen(pen); pen = grid->minPen(); cache.gridColors[1] = pen.color(); pen.setColor(color(pen.color(), MinorGrid)); grid->setMinPen(pen); break; } case QwtPlotItem::Rtti_PlotCurve: { QwtPlotCurve *c = (QwtPlotCurve *)item; QwtSymbol symbol = c->symbol(); QPen pen = symbol.pen(); cache.curveSymbolPenColors.insert(c, pen.color()); pen.setColor(color(pen.color(), CurveSymbol)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.curveSymbolBrushColors.insert(c, brush.color()); brush.setColor(color(brush.color(), CurveSymbol)); symbol.setBrush(brush); c->setSymbol(symbol); pen = c->pen(); cache.curveColors.insert(c, pen.color()); pen.setColor(color(pen.color(), Curve)); c->setPen(pen); break; } case QwtPlotItem::Rtti_PlotMarker: { QwtPlotMarker *m = (QwtPlotMarker *)item; QwtText label = m->label(); cache.markerFonts.insert(m, label.font()); label.setFont(font(label.font(), Marker)); cache.markerLabelColors.insert(m, label.color()); label.setColor(color(label.color(), Marker)); m->setLabel(label); QPen pen = m->linePen(); cache.markerLineColors.insert(m, pen.color()); pen.setColor(color(pen.color(), Marker)); m->setLinePen(pen); QwtSymbol symbol = m->symbol(); pen = symbol.pen(); cache.markerSymbolPenColors.insert(m, pen.color()); pen.setColor(color(pen.color(), MarkerSymbol)); symbol.setPen(pen); QBrush brush = symbol.brush(); cache.markerSymbolBrushColors.insert(m, brush.color()); brush.setColor(color(brush.color(), MarkerSymbol)); symbol.setBrush(brush); m->setSymbol(symbol); break; } default: break; } }
/*! Change color and fonts of a plot \sa apply() */ void QwtPlotPrintFilter::apply(QwtPlot *plot) const { const bool doAutoReplot = plot->autoReplot(); plot->setAutoReplot(false); delete d_data->cache; d_data->cache = new PrivateData::Cache; PrivateData::Cache &cache = *d_data->cache; if ( plot->titleLabel() ) { QPalette palette = plot->titleLabel()->palette(); cache.titleColor = palette.color( QPalette::Active, Palette::Text); palette.setColor(QPalette::Active, Palette::Text, color(cache.titleColor, Title)); plot->titleLabel()->setPalette(palette); cache.titleFont = plot->titleLabel()->font(); plot->titleLabel()->setFont(font(cache.titleFont, Title)); } if ( plot->legend() ) { #if QT_VERSION < 0x040000 QValueList<QWidget *> list = plot->legend()->legendItems(); for ( QValueListIterator<QWidget *> it = list.begin(); it != list.end(); ++it ) #else QList<QWidget *> list = plot->legend()->legendItems(); for ( QList<QWidget*>::iterator it = list.begin(); it != list.end(); ++it ) #endif { QWidget *w = *it; cache.legendFonts.insert(w, w->font()); w->setFont(font(w->font(), Legend)); if ( w->inherits("QwtLegendItem") ) { QwtLegendItem *label = (QwtLegendItem *)w; QwtSymbol symbol = label->symbol(); QPen pen = symbol.pen(); QBrush brush = symbol.brush(); pen.setColor(color(pen.color(), CurveSymbol)); brush.setColor(color(brush.color(), CurveSymbol)); symbol.setPen(pen); symbol.setBrush(brush); label->setSymbol(symbol); pen = label->curvePen(); pen.setColor(color(pen.color(), Curve)); label->setCurvePen(pen); } } } for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { QwtScaleWidget *scaleWidget = plot->axisWidget(axis); if ( scaleWidget ) { cache.scaleColor[axis] = scaleWidget->palette().color( QPalette::Active, Palette::Foreground); QPalette palette = scaleWidget->palette(); palette.setColor(QPalette::Active, Palette::Foreground, color(cache.scaleColor[axis], AxisScale)); scaleWidget->setPalette(palette); cache.scaleFont[axis] = scaleWidget->font(); scaleWidget->setFont(font(cache.scaleFont[axis], AxisScale)); cache.scaleTitle[axis] = scaleWidget->title(); QwtText scaleTitle = scaleWidget->title(); if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextColor) ) { cache.scaleTitleColor[axis] = scaleTitle.color(); scaleTitle.setColor( color(cache.scaleTitleColor[axis], AxisTitle)); } if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextFont) ) { cache.scaleTitleFont[axis] = scaleTitle.font(); scaleTitle.setFont( font(cache.scaleTitleFont[axis], AxisTitle)); } scaleWidget->setTitle(scaleTitle); int startDist, endDist; scaleWidget->getBorderDistHint(startDist, endDist); scaleWidget->setBorderDist(startDist, endDist); } } if ( hasBackgroundColor(plot) ) { QPalette p = plot->palette(); cache.widgetBackground = plot->palette().color( QPalette::Active, Palette::Background); p.setColor(QPalette::Active, Palette::Background, color(cache.widgetBackground, WidgetBackground)); plot->setPalette(p); } if ( hasBackgroundColor(plot->canvas())) { cache.canvasBackground = plot->canvasBackground(); plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground)); } const QwtPlotItemList& itmList = plot->itemList(); for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it ) { apply(*it); } plot->setAutoReplot(doAutoReplot); }
TextEditor::TextEditor(Graph *g): QTextEdit(g), d_graph(g) { setAttribute(Qt::WA_DeleteOnClose); setFrameShadow(QFrame::Plain); setFrameShape(QFrame::Box); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QPalette palette = this->palette(); palette.setColor(QPalette::Active, QPalette::WindowText, Qt::blue); palette.setColor(QPalette::Active, QPalette::Base, Qt::white); setPalette(palette); bool moveCrs = true; QString text; if (g->activeText()){ setParent(g->multiLayer()->canvas()); d_target = g->activeText(); setGeometry(d_target->geometry()); text = ((LegendWidget*)d_target)->text(); d_target->hide(); setFont(((LegendWidget*)d_target)->font()); } else if (g->titleSelected()){ d_target = g->titleLabel(); QwtText t = g->title(); text = t.text(); setAlignment((Qt::Alignment)t.renderFlags()); setFont(t.font()); setGeometry(d_target->geometry()); } else if (g->selectedScale()){ d_target = g->selectedScale(); QwtScaleWidget *scale = (QwtScaleWidget*)d_target; QwtText t = scale->title(); text = t.text(); setAlignment((Qt::Alignment)t.renderFlags()); setFont(t.font()); QRect rect = g->axisTitleRect(scale); if (scale->alignment() == QwtScaleDraw::BottomScale || scale->alignment() == QwtScaleDraw::TopScale){ resize(rect.size()); move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y())); } else { resize(QSize(rect.height(), rect.width())); if (scale->alignment() == QwtScaleDraw::LeftScale) move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y() + rect.height()/2)); else if (scale->alignment() == QwtScaleDraw::RightScale) move(QPoint(d_target->x() - rect.height(), d_target->y() + rect.y() + rect.height()/2)); t.setText(" "); t.setBackgroundPen(QPen(Qt::NoPen)); scale->setTitle(t); moveCrs = false; } } QTextCursor cursor = textCursor(); cursor.insertText(text); d_initial_text = text; setWordWrapMode (QTextOption::NoWrap); setAlignment(Qt::AlignCenter); QTextFrame *frame = document()->rootFrame(); QTextFrameFormat format = frame->frameFormat(); format.setTopMargin(format.topMargin () + 3); frame->setFrameFormat(format); show(); if (moveCrs) setTextCursor(cursorForPosition(mapFromGlobal(QCursor::pos()))); setFocus(); }
QFont Plot2D::titleFont() const { QwtText title = m_qwtPlot->title(); return title.font(); }
unsigned Plot2D::topAxisFontSize() const { QwtText title = m_qwtPlot->axisTitle(QwtPlot::xTop); QFont font = title.font(); return font.pointSize(); }
unsigned Plot2D::rightAxisFontSize() const { QwtText title = m_qwtPlot->axisTitle(QwtPlot::yRight); QFont font = title.font(); return font.pointSize(); }
unsigned Plot2D::titleFontSize() const { QwtText title = m_qwtPlot->title(); QFont font = title.font(); return font.pointSize(); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimSummaryPlotYAxisFormater::applyYAxisPropertiesToPlot(RiuSummaryQwtPlot* qwtPlot) { if (!qwtPlot) return; { QString axisTitle = m_axisProperties->customTitle; if (m_axisProperties->isAutoTitle) axisTitle = autoAxisTitle(); QwtText axisTitleY = qwtPlot->axisTitle(m_axisProperties->qwtPlotAxisType()); QFont axisTitleYFont = axisTitleY.font(); axisTitleYFont.setBold(true); axisTitleYFont.setPixelSize(m_axisProperties->fontSize); axisTitleY.setFont(axisTitleYFont); axisTitleY.setText(axisTitle); switch (m_axisProperties->titlePositionEnum()) { case RimSummaryYAxisProperties::AXIS_TITLE_CENTER: axisTitleY.setRenderFlags(Qt::AlignCenter); break; case RimSummaryYAxisProperties::AXIS_TITLE_END: axisTitleY.setRenderFlags(Qt::AlignRight); break; } qwtPlot->setAxisTitle(m_axisProperties->qwtPlotAxisType(), axisTitleY); } { QFont yAxisFont = qwtPlot->axisFont(m_axisProperties->qwtPlotAxisType()); yAxisFont.setBold(false); yAxisFont.setPixelSize(m_axisProperties->fontSize); qwtPlot->setAxisFont(m_axisProperties->qwtPlotAxisType(), yAxisFont); } { if (m_axisProperties->numberFormat == RimSummaryYAxisProperties::NUMBER_FORMAT_AUTO) { qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), new QwtScaleDraw); } else if (m_axisProperties->numberFormat == RimSummaryYAxisProperties::NUMBER_FORMAT_DECIMAL) { qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), new DecimalScaleDraw); } else if (m_axisProperties->numberFormat == RimSummaryYAxisProperties::NUMBER_FORMAT_SCIENTIFIC) { qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), new ScientificScaleDraw()); } } { if (m_axisProperties->isLogarithmicScaleEnabled) { QwtLogScaleEngine* currentScaleEngine = dynamic_cast<QwtLogScaleEngine*>(qwtPlot->axisScaleEngine(m_axisProperties->qwtPlotAxisType())); if (!currentScaleEngine) { qwtPlot->setAxisScaleEngine(m_axisProperties->qwtPlotAxisType(), new QwtLogScaleEngine); qwtPlot->setAxisMaxMinor(m_axisProperties->qwtPlotAxisType(), 5); } } else { QwtLinearScaleEngine* currentScaleEngine = dynamic_cast<QwtLinearScaleEngine*>(qwtPlot->axisScaleEngine(m_axisProperties->qwtPlotAxisType())); if (!currentScaleEngine) { qwtPlot->setAxisScaleEngine(m_axisProperties->qwtPlotAxisType(), new QwtLinearScaleEngine); qwtPlot->setAxisMaxMinor(m_axisProperties->qwtPlotAxisType(), 3); } } } }