TextEditor::TextEditor(Graph *g): QTextEdit(g), d_target(NULL) { 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); QString text; if (g->selectedText()){ d_target = g->selectedText(); setGeometry(d_target->geometry()); auto legend = dynamic_cast<LegendWidget*>(d_target); text = legend ? legend->text() : ""; d_target->hide(); } else if (g->titleSelected()){ d_target = g->plotWidget()->titleLabel(); QwtText t = g->plotWidget()->title(); text = t.text(); setAlignment((Qt::Alignment)t.renderFlags()); 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()); 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); } } QTextCursor cursor = textCursor(); cursor.insertText(text); d_initial_text = text; show(); setFocus(); }
void TextEditor::closeEvent(QCloseEvent *e) { if(d_target != NULL) { Graph *g = dynamic_cast<Graph *>(parent()); if (g) { QString s = QString(); if (auto legend = dynamic_cast<LegendWidget*>(d_target)){ s = text(); legend->setText(s); d_target->show(); g->setSelectedText(NULL); } else if (auto pieLabel = dynamic_cast<PieLabel*>(d_target)){ s = text(); pieLabel->setCustomText(s); d_target->show(); g->setSelectedText(NULL); } else if (d_target->isA("QwtTextLabel")){ QwtText title = g->plotWidget()->title(); s = text(); if(s.isEmpty()) s = " "; title.setText(s); g->plotWidget()->setTitle(title); } else if (d_target->isA("QwtScaleWidget")){ QwtScaleWidget *scale = (QwtScaleWidget*)d_target; QwtText title = scale->title(); s = text(); if(s.isEmpty()) s = " "; title.setText(s); scale->setTitle(title); } if (d_initial_text != s) g->notifyChanges(); d_target->repaint(); } } e->accept(); }
void TextEditor::closeEvent(QCloseEvent *e) { QString s = text(); int lines = s.count(QRegExp("\n")); if ( lines >= 100 && QMessageBox::question(d_graph->multiLayer(), tr("QtiPlot") + " - " + tr("Confirmation"), tr("Are you sure you want to add %1 text lines into this text box?").arg(lines), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::Cancel) s = d_initial_text; if (d_target->isA("LegendWidget")){ ((LegendWidget*)d_target)->setText(s); d_target->show(); d_graph->setActiveText(NULL); } else if (d_target->isA("PieLabel")){ ((PieLabel*)d_target)->setCustomText(s); d_target->show(); d_graph->setActiveText(NULL); } else if (d_target->isA("QwtTextLabel")){ QwtText title = d_graph->title(); if(s.isEmpty()) s = " "; title.setText(s); d_graph->setTitle(title); } else if (d_target->isA("QwtScaleWidget")){ QwtScaleWidget *scale = (QwtScaleWidget*)d_target; QwtText title = scale->title(); if(s.isEmpty()) s = " "; title.setText(s); scale->setTitle(title); } if (d_initial_text != s) d_graph->notifyChanges(); d_target->repaint(); e->accept(); }
Plot::Plot(QWidget *parent, const char *name) : QwtPlot(parent) { marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; movedGraph=FALSE; graphToResize=FALSE; ShiftButton=FALSE; setGeometry(QRect(0,0,500,400)); setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); // grid d_grid = new Grid; d_grid->enableX(false); d_grid->enableY(false); d_grid->setMajPen(QPen(Qt::blue, 0, Qt::SolidLine)); d_grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); d_grid->attach(this); //custom scale for (int i= 0; i<QwtPlot::axisCnt; i++) { QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i); if (scale) { scale->setMargin(0); //the axis title color must be initialized QwtText title = scale->title(); title.setColor(Qt::black); scale->setTitle(title); ScaleDraw *sd = new ScaleDraw(); sd->setTickLength (QwtScaleDiv::MinorTick, minTickLength); sd->setTickLength (QwtScaleDiv::MediumTick, minTickLength); sd->setTickLength (QwtScaleDiv::MajorTick, majTickLength); setAxisScaleDraw (i, sd); } } QwtPlotLayout *pLayout=plotLayout(); pLayout->setCanvasMargin(0); QwtPlotCanvas* plCanvas = canvas(); plCanvas->setFocusPolicy(QWidget::StrongFocus); plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); plCanvas->setFocus(); plCanvas->setFrameShadow(QwtPlot::Plain); plCanvas->setCursor(Qt::arrowCursor); plCanvas->setLineWidth(0); setFocusPolicy(QWidget::StrongFocus); setFocusProxy(plCanvas); setFrameShape (QFrame::Box); setLineWidth(0); }
Plot::Plot(int width, int height, QWidget *parent, const char *) : QwtPlot(parent) { setAutoReplot (false); marker_key = 0; curve_key = 0; minTickLength = 5; majTickLength = 9; setGeometry(QRect(0, 0, width, height)); setAxisTitle(QwtPlot::yLeft, tr("Y Axis Title")); setAxisTitle(QwtPlot::xBottom, tr("X Axis Title")); //due to the plot layout updates, we must always have a non empty title setAxisTitle(QwtPlot::yRight, tr(" ")); setAxisTitle(QwtPlot::xTop, tr(" ")); // grid d_grid = new Grid(); d_grid->attach(this); //custom scale for (int i= 0; i<QwtPlot::axisCnt; i++) { QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i); if (scale) { scale->setMargin(0); //the axis title color must be initialized... QwtText title = scale->title(); title.setColor(Qt::black); scale->setTitle(title); //...same for axis color QPalette pal = scale->palette(); pal.setColor(QPalette::Foreground, QColor(Qt::black)); scale->setPalette(pal); ScaleDraw *sd = new ScaleDraw(this); sd->setTickLength(QwtScaleDiv::MinorTick, minTickLength); sd->setTickLength(QwtScaleDiv::MediumTick, minTickLength); sd->setTickLength(QwtScaleDiv::MajorTick, majTickLength); setAxisScaleDraw (i, sd); setAxisScaleEngine (i, new ScaleEngine()); } } QwtPlotLayout *pLayout = plotLayout(); pLayout->setCanvasMargin(0); pLayout->setAlignCanvasToScales (true); QwtPlotCanvas* plCanvas = canvas(); plCanvas->setFocusPolicy(Qt::StrongFocus); plCanvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator); //plCanvas->setFocus(); plCanvas->setFrameShadow(QwtPlot::Plain); plCanvas->setCursor(Qt::arrowCursor); plCanvas->setLineWidth(0); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintCached, false); plCanvas->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); QColor background = QColor(Qt::white); background.setAlpha(255); QPalette palette; palette.setColor(QPalette::Window, background); setPalette(palette); setCanvasBackground (background); setFocusPolicy(Qt::StrongFocus); //setFocusProxy(plCanvas); setFrameShape(QFrame::Box); setLineWidth(0); }
/*! 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(); }