void ScatterWidget::addText(const string &text, const PointD &origin, int q_color) { QCPItemText *textElem = new QCPItemText(ui->scatter); textElem->setText(QString::fromStdString(text)); textElem->position->setCoords(origin.x, origin.y); textElem->setColor(QColor((Qt::GlobalColor)q_color)); }
void MainWindow::labelItemAnchors(QCPAbstractItem *item, double fontSize, bool circle, bool labelBelow) { QList<QCPItemAnchor*> anchors = item->anchors(); for (int i=0; i<anchors.size(); ++i) { if (circle) { QCPItemEllipse *circ = new QCPItemEllipse(item->parentPlot()); item->parentPlot()->addItem(circ); circ->topLeft->setParentAnchor(anchors.at(i)); circ->bottomRight->setParentAnchor(anchors.at(i)); circ->topLeft->setCoords(-4, -4); circ->bottomRight->setCoords(4, 4); QPen p(Qt::blue, 0, Qt::CustomDashLine); #if (QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) // Qt 4.8 changed the meaning of this completely... p.setDashPattern(QVector<qreal>()<<2<<1); #else p.setDashPattern(QVector<qreal>()<<1<<3); #endif circ->setPen(p); if (dynamic_cast<QCPItemPosition*>(anchors.at(i))) { QCPItemEllipse *circ2 = new QCPItemEllipse(item->parentPlot()); item->parentPlot()->addItem(circ2); circ2->topLeft->setParentAnchor(anchors.at(i)); circ2->bottomRight->setParentAnchor(anchors.at(i)); circ2->topLeft->setCoords(-2.5, -2.5); circ2->bottomRight->setCoords(2.5, 2.5); circ2->setPen(Qt::NoPen); circ2->setBrush(Qt::blue); } } if (fontSize > 0) { QCPItemText *label = new QCPItemText(item->parentPlot()); item->parentPlot()->addItem(label); label->setFont(QFont(font().family(), fontSize)); label->setColor(Qt::blue); label->setText(QString("%2 (%1)").arg(i).arg(anchors.at(i)->name())); label->position->setParentAnchor(anchors.at(i)); if (circle) label->position->setCoords(0, fontSize*2*(labelBelow?1:-1)); else label->position->setCoords(0, 0); label->setTextAlignment(Qt::AlignCenter); } } }
void MainWindow::genAxisRectSpacingOverview() { resetPlot(); customPlot->xAxis->setRange(-0.4, 1.4); customPlot->yAxis->setRange(100, 900); customPlot->xAxis->setVisible(true); customPlot->yAxis->setVisible(true); customPlot->axisRect()->setupFullAxesBox(); customPlot->xAxis->setTickLabels(false); customPlot->axisRect()->setAutoMargins(QCP::msNone); customPlot->axisRect()->setMargins(QMargins(200, 50, 20, 165)); customPlot->axisRect()->setBackground(QColor(245, 245, 245)); customPlot->yAxis->setLabel("Axis Label"); customPlot->yAxis->setOffset(30); customPlot->yAxis->setTickLabelPadding(30); customPlot->yAxis->setLabelPadding(30); customPlot->yAxis->setTickLengthOut(5); customPlot->yAxis->setSubTickLengthOut(2); addBracket(QPointF(200-95-27-17, 30), QPointF(1, 30), "Padding (if auto margins enabled)", QPointF(-25, -5), false, Qt::AlignLeft|Qt::AlignBottom); addBracket(QPointF(1, 370), QPointF(200, 370), "Margin", QPointF(0, 5), false, Qt::AlignHCenter|Qt::AlignTop); addBracket(QPointF(200-30, 240), QPointF(200, 240), "Axis offset", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); addBracket(QPointF(200-35, 250), QPointF(200-30, 250), "Tick length out", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); addBracket(QPointF(200-65, 240), QPointF(200-35, 240), "Tick label padding", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); addBracket(QPointF(200-95-25, 240), QPointF(200-65-25, 240), "Label padding", QPointF(-1, 5), true, Qt::AlignRight|Qt::AlignVCenter); QCPItemLine *leftBorder = new QCPItemLine(customPlot); customPlot->addItem(leftBorder); leftBorder->setClipToAxisRect(false); leftBorder->start->setType(QCPItemPosition::ptViewportRatio); leftBorder->end->setType(QCPItemPosition::ptViewportRatio); leftBorder->start->setCoords(0, 0); leftBorder->end->setCoords(0, 1); leftBorder->setPen(QPen(Qt::gray, 0, Qt::DashLine)); QCPItemText *axisRectLabel = new QCPItemText(customPlot); customPlot->addItem(axisRectLabel); axisRectLabel->position->setType(QCPItemPosition::ptAxisRectRatio); axisRectLabel->position->setCoords(0.5, 0.5); axisRectLabel->setFont(QFont(QFont().family(), 16)); axisRectLabel->setText("QCPAxisRect"); axisRectLabel->setColor(QColor(0, 0, 0, 60)); customPlot->savePng(dir.filePath("AxisRectSpacingOverview.png"), 400, 400); }
GraphVisualizer::GraphVisualizer(QWidget *parent) : QCustomPlot(parent), labelCoord(NULL) { // Layer pour la position des octaves this->addGraph(); QPen graphPen; graphPen.setColor(QColor(0, 0, 0, 40)); graphPen.setWidth(1); this->graph(0)->setPen(graphPen); this->graph(0)->setLineStyle(QCPGraph::lsLine); for (int i = 0; i < 10; i++) { int note = 12 * (i + 1); QCPItemText *textLabel = new QCPItemText(this); listTextOctave << textLabel; this->addItem(textLabel); textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter); textLabel->position->setType(QCPItemPosition::ptPlotCoords); textLabel->position->setCoords(note, 0); textLabel->setText(Config::getInstance()->getKeyName(note)); textLabel->setFont(QFont(font().family(), 8)); textLabel->setColor(QColor(40, 40, 40)); } // Layer des moyennes this->addGraph(); graphPen.setColor(QColor(30, 250, 80)); graphPen.setWidth(2); this->graph(1)->setPen(graphPen); this->graph(1)->setLineStyle(QCPGraph::lsNone); this->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 7)); this->graph(1)->setAntialiasedScatters(true); // Layer des valeurs this->addGraph(); graphPen.setColor(QColor(100, 130, 250)); graphPen.setWidth(2); this->graph(2)->setPen(graphPen); this->graph(2)->setLineStyle(QCPGraph::lsNone); this->graph(2)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 5)); this->graph(2)->setAntialiasedScatters(false); // Layer des valeurs par défaut this->addGraph(); graphPen.setColor(QColor(100, 130, 250)); graphPen.setWidth(1); this->graph(3)->setPen(graphPen); this->graph(3)->setLineStyle(QCPGraph::lsNone); this->graph(3)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 5)); this->graph(3)->setAntialiasedScatters(false); // Layer aperçu valeurs this->addGraph(); graphPen.setColor(QColor(0, 0, 0)); graphPen.setWidth(1); this->graph(4)->setPen(graphPen); this->graph(4)->setScatterStyle(QCPScatterStyle::ssPlus); labelCoord = new QCPItemText(this); this->addItem(labelCoord); labelCoord->position->setType(QCPItemPosition::ptPlotCoords); labelCoord->setText(""); QFont fontLabel = QFont(font().family(), 9); fontLabel.setBold(true); labelCoord->setFont(fontLabel); labelCoord->setColor(QColor(0, 0, 0)); // Message warning textWarning = new QCPItemText(this); this->addItem(textWarning); textWarning->setPositionAlignment(Qt::AlignTop | Qt::AlignLeft); textWarning->position->setType(QCPItemPosition::ptPlotCoords); textWarning->position->setCoords(0, 0); textWarning->setFont(QFont(font().family(), 10, 100)); textWarning->setColor(QColor(255, 0, 0)); // Axes this->xAxis->setVisible(false); this->xAxis->setTicks(false); this->yAxis->setVisible(false); this->yAxis->setTicks(false); // Marges this->axisRect()->setAutoMargins(QCP::msNone); this->axisRect()->setMargins(QMargins(0, 0, 0, 0)); // Filtre sur les événements this->installEventFilter(this); }
GraphParamGlobal::GraphParamGlobal(QWidget * parent) : QCustomPlot(parent), forme(FORME_MANUELLE), flagEdit(false), limitEdit(0), nbPoints(140), raideurExp(50.0), yMin(0.), yMax(1.), xMin(0), xMax(140), labelCoord(NULL), previousX(-1) { // Layer pour la position des octaves this->addGraph(); QPen graphPen; graphPen.setColor(QColor(0, 0, 0, 40)); graphPen.setWidth(1); this->graph(0)->setPen(graphPen); this->graph(0)->setLineStyle(QCPGraph::lsLine); QVector<double> x, y; x.resize(20); y.resize(20); y[0] = y[3] = y[4] = y[7] = y[8] = y[11] = y[12] = y[15] = y[16] = y[19] = 2; y[1] = y[2] = y[5] = y[6] = y[9] = y[10] = y[13] = y[14] = y[17] = y[18] = -1; for (int i = 0; i < 10; i++) { int note = 12 * (i + 1); double pos = (double)(note * this->nbPoints) / 127.; x[2*i] = x[2*i+1] = pos; QCPItemText *textLabel = new QCPItemText(this); this->addItem(textLabel); textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter); textLabel->position->setType(QCPItemPosition::ptPlotCoords); textLabel->position->setCoords(pos, 0); textLabel->setText(Config::getInstance()->getKeyName(note)); textLabel->setFont(QFont(font().family(), 8)); textLabel->setColor(QColor(40, 40, 40)); } this->graph(0)->setData(x, y); // Layers coloration zone sur laquelle s'étend le clavier this->addGraph(); x.resize(2); y.resize(2); x[0] = -1; x[1] = this->nbPoints + 1; y[0] = y[1] = -2; graphPen.setWidth(0); this->graph(1)->setPen(graphPen); this->graph(1)->setData(x, y); this->graph(1)->setBrush(QBrush(QColor(255, 255, 0, 30))); this->addGraph(); this->graph(2)->setPen(graphPen); this->graph(1)->setChannelFillGraph(this->graph(2)); // Layer des valeurs this->addGraph(); graphPen.setColor(QColor(100, 130, 250)); graphPen.setWidth(2); this->graph(3)->setPen(graphPen); this->graph(3)->setLineStyle(QCPGraph::lsNone); this->graph(3)->setScatterStyle(QCPScatterStyle::ssDot); this->graph(3)->setAntialiased(true); this->graph(3)->setAntialiasedScatters(true); // Layer aperçu valeurs this->addGraph(); graphPen.setColor(QColor(0, 0, 0)); graphPen.setWidth(1); this->graph(4)->setPen(graphPen); this->graph(4)->setScatterStyle(QCPScatterStyle::ssPlus); labelCoord = new QCPItemText(this); this->addItem(labelCoord); labelCoord->position->setType(QCPItemPosition::ptPlotCoords); labelCoord->setText(""); QFont fontLabel = QFont(font().family(), 9); fontLabel.setBold(true); labelCoord->setFont(fontLabel); labelCoord->setColor(QColor(0, 0, 0)); // Axes this->xAxis->setRange(0, this->nbPoints); this->yAxis->setRange(0, 1); this->xAxis->setVisible(false); this->xAxis->setTicks(false); this->yAxis->setVisible(false); this->yAxis->setTicks(false); // Marges this->axisRect()->setAutoMargins(QCP::msNone); this->axisRect()->setMargins(QMargins(0, 0, 0, 0)); // Préparation des données this->dValues.resize(this->nbPoints); this->dValues.fill(0.5); // Filtre sur les événements this->installEventFilter(this); // Affichage this->replot(); }