Iax2AnalysisDialog::Iax2AnalysisDialog(QWidget &parent, CaptureFile &cf) : WiresharkDialog(parent, cf), ui(new Ui::Iax2AnalysisDialog), port_src_fwd_(0), port_dst_fwd_(0), port_src_rev_(0), port_dst_rev_(0), save_payload_error_(TAP_IAX2_NO_ERROR) { ui->setupUi(this); loadGeometry(parent.width() * 4 / 5, parent.height() * 4 / 5); setWindowSubtitle(tr("IAX2 Stream Analysis")); ui->progressFrame->hide(); stream_ctx_menu_.addAction(ui->actionGoToPacket); stream_ctx_menu_.addAction(ui->actionNextProblem); stream_ctx_menu_.addSeparator(); stream_ctx_menu_.addAction(ui->actionSaveAudio); stream_ctx_menu_.addAction(ui->actionSaveForwardAudio); stream_ctx_menu_.addAction(ui->actionSaveReverseAudio); stream_ctx_menu_.addSeparator(); stream_ctx_menu_.addAction(ui->actionSaveCsv); stream_ctx_menu_.addAction(ui->actionSaveForwardCsv); stream_ctx_menu_.addAction(ui->actionSaveReverseCsv); stream_ctx_menu_.addSeparator(); stream_ctx_menu_.addAction(ui->actionSaveGraph); ui->forwardTreeWidget->installEventFilter(this); ui->forwardTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->forwardTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showStreamMenu(QPoint))); ui->reverseTreeWidget->installEventFilter(this); ui->reverseTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->reverseTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showStreamMenu(QPoint))); connect(ui->streamGraph, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphClicked(QMouseEvent*))); graph_ctx_menu_.addAction(ui->actionSaveGraph); QStringList header_labels; for (int i = 0; i < ui->forwardTreeWidget->columnCount(); i++) { header_labels << ui->forwardTreeWidget->headerItem()->text(i); } ui->reverseTreeWidget->setHeaderLabels(header_labels); memset(&src_fwd_, 0, sizeof(address)); memset(&dst_fwd_, 0, sizeof(address)); memset(&src_rev_, 0, sizeof(address)); memset(&dst_rev_, 0, sizeof(address)); QList<QCheckBox *> graph_cbs = QList<QCheckBox *>() << ui->fJitterCheckBox << ui->fDiffCheckBox << ui->rJitterCheckBox << ui->rDiffCheckBox; for (int i = 0; i < num_graphs_; i++) { QCPGraph *graph = ui->streamGraph->addGraph(); graph->setPen(QPen(ColorUtils::graphColor(i))); graph->setName(graph_cbs[i]->text()); graphs_ << graph; graph_cbs[i]->setChecked(true); graph_cbs[i]->setIcon(StockIcon::colorIcon(ColorUtils::graphColor(i), QPalette::Text)); } ui->streamGraph->xAxis->setLabel("Arrival Time"); ui->streamGraph->yAxis->setLabel("Value (ms)"); // We keep our temp files open for the lifetime of the dialog. The GTK+ // UI opens and closes at various points. QString tempname = QString("%1/wireshark_iax2_f").arg(QDir::tempPath()); fwd_tempfile_ = new QTemporaryFile(tempname, this); fwd_tempfile_->open(); tempname = QString("%1/wireshark_iax2_r").arg(QDir::tempPath()); rev_tempfile_ = new QTemporaryFile(tempname, this); rev_tempfile_->open(); if (fwd_tempfile_->error() != QFile::NoError || rev_tempfile_->error() != QFile::NoError) { err_str_ = tr("Unable to save RTP data."); ui->actionSaveAudio->setEnabled(false); ui->actionSaveForwardAudio->setEnabled(false); ui->actionSaveReverseAudio->setEnabled(false); } QMenu *save_menu = new QMenu(); save_menu->addAction(ui->actionSaveAudio); save_menu->addAction(ui->actionSaveForwardAudio); save_menu->addAction(ui->actionSaveReverseAudio); save_menu->addSeparator(); save_menu->addAction(ui->actionSaveCsv); save_menu->addAction(ui->actionSaveForwardCsv); save_menu->addAction(ui->actionSaveReverseCsv); save_menu->addSeparator(); save_menu->addAction(ui->actionSaveGraph); ui->buttonBox->button(QDialogButtonBox::Save)->setMenu(save_menu); ui->buttonBox->button(QDialogButtonBox::Close)->setDefault(true); resetStatistics(); updateStatistics(); // Initialize stats if an error occurs #if 0 /* Only accept Voice or MiniPacket packets */ const gchar filter_text[] = "iax2.call && (ip || ipv6)"; #else const gchar filter_text[] = "iax2 && (ip || ipv6)"; #endif dfilter_t *sfcode; gchar *err_msg; /* Try to compile the filter. */ if (!dfilter_compile(filter_text, &sfcode, &err_msg)) { err_str_ = QString(err_msg); g_free(err_msg); updateWidgets(); return; } if (!cap_file_.capFile() || !cap_file_.capFile()->current_frame) { err_str_ = tr("Please select an IAX2 packet."); save_payload_error_ = TAP_IAX2_NO_PACKET_SELECTED; updateWidgets(); return; } frame_data *fdata = cap_file_.capFile()->current_frame; if (!cf_read_record(cap_file_.capFile(), fdata)) close(); epan_dissect_t edt; epan_dissect_init(&edt, cap_file_.capFile()->epan, TRUE, FALSE); epan_dissect_prime_with_dfilter(&edt, sfcode); epan_dissect_run(&edt, cap_file_.capFile()->cd_t, &cap_file_.capFile()->rec, frame_tvbuff_new_buffer(&cap_file_.capFile()->provider, fdata, &cap_file_.capFile()->buf), fdata, NULL); // This shouldn't happen (the menu item should be disabled) but check anyway if (!dfilter_apply_edt(sfcode, &edt)) { epan_dissect_cleanup(&edt); dfilter_free(sfcode); err_str_ = tr("Please select an IAX2 packet."); save_payload_error_ = TAP_IAX2_NO_PACKET_SELECTED; updateWidgets(); return; } dfilter_free(sfcode); /* ok, it is a IAX2 frame, so let's get the ip and port values */ copy_address(&(src_fwd_), &(edt.pi.src)); copy_address(&(dst_fwd_), &(edt.pi.dst)); port_src_fwd_ = edt.pi.srcport; port_dst_fwd_ = edt.pi.destport; /* assume the inverse ip/port combination for the reverse direction */ copy_address(&(src_rev_), &(edt.pi.dst)); copy_address(&(dst_rev_), &(edt.pi.src)); port_src_rev_ = edt.pi.destport; port_dst_rev_ = edt.pi.srcport; #ifdef IAX2_RTP_STREAM_CHECK rtpstream_tapinfot tapinfo; /* Register the tap listener */ memset(&tapinfo, 0, sizeof(rtpstream_tapinfot)); tapinfo.tap_data = this; tapinfo.mode = TAP_ANALYSE; // register_tap_listener_rtp_stream(&tapinfo, NULL); /* Scan for RTP streams (redissect all packets) */ rtpstream_scan(&tapinfo, cap_file_.capFile(), NULL); int num_streams = 0; GList *filtered_list = NULL; for (GList *strinfo_list = g_list_first(tapinfo.strinfo_list); strinfo_list; strinfo_list = g_list_next(strinfo_list)) { rtp_stream_info_t * strinfo = (rtp_stream_info_t*)(strinfo_list->data); << address_to_qstring(&strinfo->dest_addr) << address_to_qstring(&src_rev_) << address_to_qstring(&dst_rev_); if (addresses_equal(&(strinfo->src_addr), &(src_fwd_)) && (strinfo->src_port == port_src_fwd_) && (addresses_equal(&(strinfo->dest_addr), &(dst_fwd_))) && (strinfo->dest_port == port_dst_fwd_)) { ++num_streams; filtered_list = g_list_prepend(filtered_list, strinfo); } if (addresses_equal(&(strinfo->src_addr), &(src_rev_)) && (strinfo->src_port == port_src_rev_) && (addresses_equal(&(strinfo->dest_addr), &(dst_rev_))) && (strinfo->dest_port == port_dst_rev_)) { ++num_streams; filtered_list = g_list_append(filtered_list, strinfo); } }
/*! Default Constructor \param style Symbol Style The symbol is constructed with gray interior, black outline with zero width, no size and style 'NoSymbol'. */ QwtSymbol::QwtSymbol( Style style ) { d_data = new PrivateData( style, QBrush( Qt::gray ), QPen( Qt::black ), QSize( 0.0, 0.0 ) ); }
BOOL BasicGraph::LoadCSVDataFile(QString filename, TimeSeriesData* pOutputData) { int rc; char tempString[64]; FILE* pFile; // errno_t err = fopen_s(&pFile, filename.toLatin1().data(), "rt"); errno_t err = fopen_s(&pFile, "C:/trainingdata/8286/TimeSeries/Average_Z.csv", "rt"); if (err == 13) { CJTRACE(TRACE_ERROR_LEVEL, "ERROR: Failed to open file: PERMISSION DENIED", filename.toLatin1().data()); return FALSE; } else if (err != 0) { CJTRACE(TRACE_ERROR_LEVEL, "ERROR: Failed to open file. err=%d, file=%s", err, filename.toLatin1().data()); return FALSE; } pOutputData->filename = filename; // Get data name fscanf_s(pFile, "%s", tempString, 64); pOutputData->name.fromLatin1(tempString); pOutputData->name.remove(0, 5); CJTRACE(TRACE_ERROR_LEVEL, "Loading data file: %s", filename.toLatin1().data()); CJTRACE(TRACE_ERROR_LEVEL, " Name: %s", pOutputData->name.toLatin1().data()); // Get time delta in X axis fscanf_s(pFile, "%s", tempString, 64); pOutputData->timedelta = atof(&tempString[6]); CJTRACE(TRACE_ERROR_LEVEL, " Delta: %.10lf (sec)", pOutputData->timedelta); // Get first X axis value fscanf_s(pFile, "%s", tempString, 64); pOutputData->timestart = atof(&tempString[5]); CJTRACE(TRACE_ERROR_LEVEL, " Start: %.10lf (sec)", pOutputData->timestart); // Get X axis label fscanf_s(pFile, "%s", tempString, 64); pOutputData->Xaxislabel.fromLatin1(tempString); pOutputData->Xaxislabel.remove(0, 7); CJTRACE(TRACE_ERROR_LEVEL, " X Axis: %s", pOutputData->Xaxislabel.toLatin1().data()); // Get Y axis label fscanf_s(pFile, "%s", tempString, 64); pOutputData->Yaxislabel.fromLatin1(tempString); pOutputData->Yaxislabel.remove(0, 7); CJTRACE(TRACE_ERROR_LEVEL, " Y Axis: %s", pOutputData->Yaxislabel.toLatin1().data()); while (strcmp(tempString, "Values") != 0) { fscanf_s(pFile, "%s", tempString, 64); // Data Notes (skip for now) } // Get data values rc = 0; int count = 0; QVector<double> time(0); double nextTime = pOutputData->timestart; while (rc != EOF) { rc = fscanf_s(pFile, "%s", tempString, 64); pOutputData->pData.append(atof(tempString)); time.append(nextTime); nextTime += pOutputData->timedelta; count++; if ((count < 50) || (count % 500 == 0)) CJTRACE(TRACE_ERROR_LEVEL, " Value: %d, %.10lf", count, pOutputData->timedelta); } CJTRACE(TRACE_ERROR_LEVEL, "Data File Read (%d entries)", count); QCustomPlot* customPlot = ui.basicGraph; // add two new graphs and set their look: customPlot->addGraph(); customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph // configure right and top axis to show ticks but no labels: // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this) customPlot->xAxis2->setVisible(true); customPlot->xAxis2->setTickLabels(false); customPlot->yAxis2->setVisible(true); customPlot->yAxis2->setTickLabels(false); // make left and bottom axes always transfer their ranges to right and top axes: connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange))); connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange))); // pass data points to graphs: customPlot->graph(0)->setData(time, pOutputData->pData); // let the ranges scale themselves so graph 0 fits perfectly in the visible area: customPlot->graph(0)->rescaleAxes(); // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0): //customPlot->graph(1)->rescaleAxes(true); // Note: we could have also just called customPlot->rescaleAxes(); instead // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking: customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); ExternalReplot(); return TRUE; }
** this files contains a subclass of Touch ** ** Contributors: ** Benjamin Tissoires <*****@*****.**> ** ** ** This program is provided to you as free software; ** you can redistribute it and/or modify it under the terms of the ** GNU General Public License as published by the Free Software ** Foundation; either version 2 of the License, or (at your option) ** any later version. **/ #include "drawingtouch.h" static QPen pressedPen = QPen(Qt::black, 5); static QPen releasedPen = QPen(Qt::black, 1); DrawingTouch::DrawingTouch(QGraphicsScene *scene, int radius, QObject *parent) : Touch(parent), scene(scene), ellipse(0), radius(radius) { } bool DrawingTouch::update(QBrush *color) { bool wasVisible = false; if (ellipse) { wasVisible = ellipse->isVisible();
void KisCurveWidget::paintEvent(QPaintEvent *) { int wWidth = width() - 1; int wHeight = height() - 1; QPainter p(this); // Antialiasing is not a good idea here, because // the grid will drift one pixel to any side due to rounding of int // FIXME: let's user tell the last word (in config) //p.setRenderHint(QPainter::Antialiasing); // draw background if (!d->m_pix.isNull()) { if (d->m_pixmapDirty || !d->m_pixmapCache) { delete d->m_pixmapCache; d->m_pixmapCache = new QPixmap(width(), height()); QPainter cachePainter(d->m_pixmapCache); cachePainter.scale(1.0*width() / d->m_pix.width(), 1.0*height() / d->m_pix.height()); cachePainter.drawPixmap(0, 0, d->m_pix); d->m_pixmapDirty = false; } p.drawPixmap(0, 0, *d->m_pixmapCache); } else p.fillRect(rect(), palette().background()); d->drawGrid(p, wWidth, wHeight); KisConfig cfg; if (cfg.antialiasCurves()) p.setRenderHint(QPainter::Antialiasing); // Draw curve. double curY; double normalizedX; int x; QPolygonF poly; p.setPen(QPen(Qt::black, 1, Qt::SolidLine)); for (x = 0 ; x < wWidth ; x++) { normalizedX = double(x) / wWidth; curY = wHeight - d->m_curve.value(normalizedX) * wHeight; /** * Keep in mind that QLineF rounds doubles * to ints mathematically, not just rounds down * like in C */ poly.append(QPointF(x, curY)); } poly.append(QPointF(x, wHeight - d->m_curve.value(1.0) * wHeight)); p.drawPolyline(poly); // Drawing curve handles. double curveX; double curveY; if (!d->m_readOnlyMode) { for (int i = 0; i < d->m_curve.points().count(); ++i) { curveX = d->m_curve.points().at(i).x(); curveY = d->m_curve.points().at(i).y(); if (i == d->m_grab_point_index) { p.setPen(QPen(Qt::red, 3, Qt::SolidLine)); p.drawEllipse(QRectF(curveX * wWidth - 2, wHeight - 2 - curveY * wHeight, 4, 4)); } else { p.setPen(QPen(Qt::red, 1, Qt::SolidLine)); p.drawEllipse(QRectF(curveX * wWidth - 3, wHeight - 3 - curveY * wHeight, 6, 6)); } } } }
void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow) { QRect scr = QApplication::desktop()->screenGeometry(pos); QSize sh = sizeHint(); const int border = 1; const int ah = 18, ao = 18, aw = 18, rc = 7; bool arrowAtTop = (pos.y() + sh.height() + ah < scr.height()); bool arrowAtLeft = (pos.x() + sh.width() - ao < scr.width()); setContentsMargins(border + 3, border + (arrowAtTop ? ah : 0) + 2, border + 3, border + (arrowAtTop ? 0 : ah) + 2); updateGeometry(); sh = sizeHint(); int ml, mr, mt, mb; QSize sz = sizeHint(); if (!arrowAtTop) { ml = mt = 0; mr = sz.width() - 1; mb = sz.height() - ah - 1; } else { ml = 0; mt = ah; mr = sz.width() - 1; mb = sz.height() - 1; } QPainterPath path; #if defined(QT_NO_XSHAPE) && defined(Q_WS_X11) // XShape is required for setting the mask, so we just // draw an ugly square when its not available path.moveTo(0, 0); path.lineTo(sz.width() - 1, 0); path.lineTo(sz.width() - 1, sz.height() - 1); path.lineTo(0, sz.height() - 1); path.lineTo(0, 0); move(qMax(pos.x() - sz.width(), scr.left()), pos.y()); #else path.moveTo(ml + rc, mt); if (arrowAtTop && arrowAtLeft) { if (showArrow) { path.lineTo(ml + ao, mt); path.lineTo(ml + ao, mt - ah); path.lineTo(ml + ao + aw, mt); } move(qMax(pos.x() - ao, scr.left() + 2), pos.y()); } else if (arrowAtTop && !arrowAtLeft) { if (showArrow) { path.lineTo(mr - ao - aw, mt); path.lineTo(mr - ao, mt - ah); path.lineTo(mr - ao, mt); } move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), pos.y()); } path.lineTo(mr - rc, mt); path.arcTo(QRect(mr - rc*2, mt, rc*2, rc*2), 90, -90); path.lineTo(mr, mb - rc); path.arcTo(QRect(mr - rc*2, mb - rc*2, rc*2, rc*2), 0, -90); if (!arrowAtTop && !arrowAtLeft) { if (showArrow) { path.lineTo(mr - ao, mb); path.lineTo(mr - ao, mb + ah); path.lineTo(mr - ao - aw, mb); } move(qMin(pos.x() - sh.width() + ao, scr.right() - sh.width() - 2), pos.y() - sh.height()); } else if (!arrowAtTop && arrowAtLeft) { if (showArrow) { path.lineTo(ao + aw, mb); path.lineTo(ao, mb + ah); path.lineTo(ao, mb); } move(qMax(pos.x() - ao, scr.x() + 2), pos.y() - sh.height()); } path.lineTo(ml + rc, mb); path.arcTo(QRect(ml, mb - rc*2, rc*2, rc*2), -90, -90); path.lineTo(ml, mt + rc); path.arcTo(QRect(ml, mt, rc*2, rc*2), 180, -90); // Set the mask QBitmap bitmap = QBitmap(sizeHint()); bitmap.fill(Qt::color0); QPainter painter1(&bitmap); painter1.setPen(QPen(Qt::color1, border)); painter1.setBrush(QBrush(Qt::color1)); painter1.drawPath(path); setMask(bitmap); #endif // Draw the border pixmap = QPixmap(sz); QPainter painter2(&pixmap); painter2.setPen(QPen(palette().color(QPalette::Window).darker(160), border)); painter2.setBrush(palette().color(QPalette::Window)); painter2.drawPath(path); if (msecs > 0) timerId = startTimer(msecs); show(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_accelXPoints(100, QPointF(0, 0)), m_accelYPoints(100, QPointF(0, 0)), m_gyroXPoints(100, QPointF(0, 0)), m_gyroYPoints(100, QPointF(0, 0)), m_counter(0), m_power(0) { ui->setupUi(this); // init scenes xScene = new QGraphicsScene(); yScene = new QGraphicsScene(); xScene->setBackgroundBrush(Qt::white); yScene->setBackgroundBrush(Qt::white); ui->xGraphicsView->setScene(xScene); ui->yGraphicsView->setScene(yScene); m_tcpSocket = new QTcpSocket(this); connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(onTcpRead())); m_controlSocket = new QTcpSocket(this); connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(onControlRead())); // connecting connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(connectToServer())); connect(ui->disconnectButton, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); // control buttons connect(ui->up2Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->up1Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->zeroButton, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->down1Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); connect(ui->down2Button, SIGNAL(clicked()), this, SLOT(handleControlButton())); // plotting setup m_accelXData = new QwtPointSeriesData(); m_accelYData = new QwtPointSeriesData(); m_accelXCurve = new QwtPlotCurve("Accel X"); m_accelYCurve = new QwtPlotCurve("Accel Y"); m_accelXCurve->setPen( QPen( Qt::black ) ); m_accelYCurve->setPen( QPen( Qt::red)); m_accelXCurve->attach( ui->plot ); m_accelYCurve->attach(ui->plot); m_gyroXData = new QwtPointSeriesData(); m_gyroYData = new QwtPointSeriesData(); m_gyroXCurve = new QwtPlotCurve("Gyro X"); m_gyroYCurve = new QwtPlotCurve("Gyro Y"); m_gyroXCurve->setPen( QPen( Qt::green ) ); m_gyroYCurve->setPen( QPen( Qt::blue)); m_gyroXCurve->attach( ui->plot ); m_gyroYCurve->attach(ui->plot); ui->plot->setCanvasBackground(Qt::white); // Axes ui->plot->setAxisTitle( QwtPlot::xBottom, "Seconds" ); ui->plot->setAxisTitle( QwtPlot::yLeft, "Degrees" ); ui->plot->setAxisScale( QwtPlot::yLeft, -90, 90 ); // zero line QwtPlotMarker* zeroMarker = new QwtPlotMarker(); zeroMarker->setLineStyle(QwtPlotMarker::HLine); zeroMarker->setLinePen(QPen(Qt::DotLine)); zeroMarker->setSymbol(new QwtSymbol(QwtSymbol::HLine)); zeroMarker->setYValue(0); zeroMarker->attach(ui->plot); updatePlot(0, 0, 0, 0); }
void FFT::outputGraphs() { createOutputGraph(); MultiLayer *ml = d_output_graph->multiLayer(); d_output_graph->setTitle(QString::null); d_output_graph->setYAxisTitle(tr("Angle (deg)")); d_output_graph->enableAxis(QwtPlot::xTop, true); d_output_graph->enableAxis(QwtPlot::yRight, true); if (!d_inverse) d_output_graph->setAxisTitle(QwtPlot::xTop, tr("Frequency") + " (" + tr("Hz") + ")"); else d_output_graph->setAxisTitle(QwtPlot::xTop, tr("Time") + + " (" + tr("s") + ")"); ScaleDraw *sd = (ScaleDraw *)d_output_graph->axisScaleDraw(QwtPlot::yLeft); if (sd) sd->setShowTicksPolicy(ScaleDraw::HideBegin); sd = (ScaleDraw *)d_output_graph->axisScaleDraw(QwtPlot::yRight); if (sd) sd->setShowTicksPolicy(ScaleDraw::HideBegin); sd = (ScaleDraw *)d_output_graph->axisScaleDraw(QwtPlot::xBottom); if (sd){ sd->setShowTicksPolicy(ScaleDraw::HideBeginEnd); sd->enableComponent(QwtAbstractScaleDraw::Backbone, false); } QString tableName = d_result_table->objectName(); PlotCurve *pc = d_output_graph->insertCurve(d_result_table, 0, tableName + "_" + tr("Angle"), 0); pc->setPen(QPen(d_curveColor, 1)); d_output_graph->removeLegend(); d_output_graph->updatePlot(); Graph *g = ml->addLayer(0, 0, 0, 0, true); g->setTitle(QString::null); if (!d_inverse) g->setXAxisTitle(tr("Frequency") + " (" + tr("Hz") + ")"); else g->setXAxisTitle(tr("Time") + + " (" + tr("s") + ")"); g->setYAxisTitle(tr("Amplitude")); g->removeLegend(); sd = (ScaleDraw *)g->axisScaleDraw(QwtPlot::xTop); if (sd) sd->setShowTicksPolicy(ScaleDraw::HideBeginEnd); PlotCurve *c = g->insertCurve(d_result_table, 0, tableName + "_" + tr("Amplitude"), 0); c->setPen(QPen(d_curveColor, 1)); g->updatePlot(); double rb = g->axisScaleDiv(QwtPlot::xBottom)->upperBound(); d_output_graph->setAxisScale(QwtPlot::xBottom, 0, rb); d_output_graph->setAxisScale(QwtPlot::xTop, 0, rb); g->setAxisScale(QwtPlot::xBottom, 0, rb); g->setAxisScale(QwtPlot::xTop, 0, rb); ml->setAlignPolicy(MultiLayer::AlignCanvases); ml->setRows(2); ml->setCols(1); ml->setSpacing(0, 0); ml->linkXLayerAxes(); ml->setCommonLayerAxes(false, true); ml->arrangeLayers(false, false); }
void KTExposureHeader::paintSection(QPainter * painter, const QRect & rect, int layerIndex) const { if (!rect.isValid()) return; QStyleOptionHeader headerOption; headerOption.rect = rect; headerOption.orientation = Qt::Horizontal; headerOption.position = QStyleOptionHeader::Middle; headerOption.text = ""; QStyle::State state = QStyle::State_None; if (isEnabled()) state |= QStyle::State_Enabled; if (window()->isActiveWindow()) state |= QStyle::State_Active; style()->drawControl(QStyle::CE_HeaderSection, &headerOption, painter); QString text = m_layers[layerIndex].title; QFont font("Arial", 8, QFont::Normal, false); QFontMetrics fm(font); QStyleOptionButton buttonOption; if (m_layers[layerIndex].isVisible) { buttonOption.palette.setBrush(QPalette::Button, Qt::green); } else { buttonOption.palette.setBrush(QPalette::Button, Qt::red); buttonOption.state |= QStyle::State_Sunken; QColor color(255, 0, 0, 40); painter->fillRect(rect.normalized().adjusted(0, 1, 0, -1), color); } if ((layerIndex == currentCol) || (m_layers.size() == 1)) { QColor color(250, 209, 132, 80); painter->fillRect(rect.normalized().adjusted(0, 1, 0, -1), color); if (m_layers[layerIndex].isVisible) { painter->setPen(QPen(QColor(250, 209, 132, 255), 2, Qt::SolidLine)); // Header selected painter->drawRect(rect.normalized().adjusted(0, 1, 0, -1)); } else { painter->setPen(QPen(QColor(255, 0, 0, 70), 2, Qt::SolidLine)); // Header locked painter->drawRect(rect.normalized().adjusted(0, 1, 0, -1)); } } int buttonWidth = 12; int width = (rect.normalized().width() - (fm.width(text) + buttonWidth) + 4)/ 2; int x = rect.normalized().x() + width + buttonWidth; int y = rect.normalized().bottomLeft().y() - (1 + (rect.normalized().height() - fm.height())/2); painter->setFont(font); painter->setPen(QPen(Qt::black, 1, Qt::SolidLine)); painter->drawText(x, y, text); buttonOption.rect = QRect(rect.x() + width - 4, rect.y() + ((rect.normalized().height()-buttonWidth)/2) + 1, buttonWidth, buttonWidth); style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter); }
void RulerT::paintEvent(QPaintEvent *) { double xl; QPainter p; p.begin(this); p.drawLine(0, 24, width(), 24); p.translate(-offset, 0); p.setBrush(Qt::black); p.setFont(font()); p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); for (xl = 0; xl < width()+offset; xl += iter) { if (xl < offset) continue; p.drawLine(qRound(xl), 18, qRound(xl), 24); } for (xl = 0; xl < width()+(iter2/2)+offset; xl += iter2) { if (xl < offset) continue; p.drawLine(qRound(xl), 11, qRound(xl), 24); switch (unitIndex) { case 2: { QString tx = ""; int num1 = static_cast<int>(xl / iter2); if (num1 != 0) tx = QString::number(num1); double frac = (xl / iter2) - num1; if ((frac > 0.24) && (frac < 0.26)) tx += QChar(0xBC); if ((frac > 0.49) && (frac < 0.51)) tx += QChar(0xBD); if ((frac > 0.74) && (frac < 0.76)) tx += QChar(0xBE); p.drawText(qRound(xl+2), 17, tx); break; } case 3: p.drawText(qRound(xl+2), 17, QString::number(xl / iter)); break; default: p.drawText(qRound(xl+2), 17, QString::number(xl / iter * 10)); break; } } if (tabValues.count() != 0) { for (int yg = 0; yg < static_cast<int>(tabValues.count()); yg++) { if (yg == actTab) p.setPen(QPen(Qt::red, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); else p.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); switch (static_cast<int>(tabValues[yg].tabType)) { case 0: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition+8), 23); break; case 1: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition-8), 23); break; case 2: case 3: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23); p.drawLine(qRound(tabValues[yg].tabPosition+3), 20, qRound(tabValues[yg].tabPosition+2), 20); break; case 4: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23); break; default: break; } } } if (haveInd) { p.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p.setBrush(Qt::blue); QPolygon cr; cr.setPoints(3, qRound(firstLine+leftIndent), 12, qRound(firstLine+leftIndent-4), 0, qRound(firstLine+leftIndent+4), 0); p.drawPolygon(cr); QPolygon cr2; cr2.setPoints(3, qRound(leftIndent), 12, qRound(leftIndent+4), 24, qRound(leftIndent-4), 24); p.drawPolygon(cr2); } p.end(); }
void EasingGraph::paintEvent(QPaintEvent *event) //void EasingGraph::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { QWidget::paintEvent(event); QPainter *painter = new QPainter(this); painter->save(); bool drawZero = false; // no background int length = width(); int breadth = height()-2; QPainterPath path; path.moveTo(0,int((1-m_curveFunction.valueForProgress(0))*breadth)); for (int i=0;i<length;i++) { qreal progress = i/qreal(length); qreal value = m_curveFunction.valueForProgress(progress); int x = int(length*progress); int y = int(breadth*(1-value)); path.lineTo(x,y); } QRectF pathRect = path.controlPointRect(); if ( (pathRect.height()>breadth)) { // scale vertically qreal scale = breadth/pathRect.height(); qreal displacement = -pathRect.top(); // reset path and recompute scaled version path = QPainterPath(); path.moveTo(0,int(scale*((1-m_curveFunction.valueForProgress(0))*breadth+displacement))); for (int i=0;i<length;i++) { qreal progress = i/qreal(length); qreal value = m_curveFunction.valueForProgress(progress); int x = int(length*progress); int y = int(scale*(breadth*(1-value)+displacement)); path.lineTo(x,y); } drawZero = true; } painter->setBrush(Qt::transparent); if (drawZero) { // "zero" and "one" lines QPen zeroPen = QPen(m_zeroColor); zeroPen.setStyle(Qt::DashLine); painter->setPen(zeroPen); int y = int(-pathRect.top()*breadth/pathRect.height()); if (y>0) painter->drawLine(0,y,length,y); y = int(breadth/pathRect.height()*(breadth-pathRect.top())); if (y<breadth) painter->drawLine(0,y,length,y); } painter->setPen(m_color); painter->drawPath(path); painter->restore(); delete painter; }
Plot::Plot(QWidget *parent) : QwtPolarPlot(parent) , m_azimuthChange(new QTimer(this)) , m_currTime(new QTime) , m_nextAzimuthData(new QTimer(this)) , m_isStarted(false) , m_showIDs(true) , m_tracksStorage(new MarksTracksStorage(this)) /*, m_picker(new QwtPolarPicker(QwtPicker::CrossRubberBand, QwtPicker::ActiveOnly, this->canvas()))*/ , m_isIDMoving(false) , m_currMovingCurveID(0) , m_wrongMarksSound(new QSound(":/Resources/WrongMarksReceived.wav", this)) , m_rightMarksSound(new QSound(":/Resources/RadarShort.wav", this)) , m_offSounds(false) , m_markIndex(0) , m_upToIndex(0) , m_isIndexMarkFirstAppearance(true) , m_pauseAzimuth(0.0) , m_isPaused(false) { m_tracksStorage->setStorageSize(40); /*m_picker->setStateMachine(new QwtPickerDragPointMachine); m_picker->setMousePattern(QwtPicker::MouseSelect1, Qt::LeftButton); m_picker->setRubberBandPen(QColor("#00FF00")); m_picker->setTrackerPen(QColor(Qt::white)); m_picker->setTrackerFont(QFont("Verdana", 10));*/ setAutoReplot( false ); setPlotBackground( QColor("#0B0B3B") ); canvas()->setStyleSheet("background: #0B0B3B"); // Maked plot squared this->zoom(QwtPointPolar(0, 0), ZOOMDEFAULTFACTOR); // setting start point at 12 o'clock setAzimuthOrigin(M_PI/2); // scales setScale(QwtPolar::Azimuth, 360, 0, 30); setScaleMaxMinor(QwtPolar::Azimuth, 30); setScaleMaxMajor(QwtPolar::Azimuth, 30); setScale(QwtPolar::Radius, 0.0, 400.0 / ZOOMDEFAULTFACTOR, 50.0); setScaleMaxMinor(QwtPolar::Radius, qCeil(400.0 / (50.0 * ZOOMDEFAULTFACTOR))); setScaleMaxMajor(QwtPolar::Radius, qCeil(400.0 / (50.0 * ZOOMDEFAULTFACTOR))); // grids m_grid = new QwtPolarGrid(); m_grid->setPen(QPen(Qt::gray)); for(int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++) { m_grid->showGrid(scaleId); } m_grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::gray)); m_grid->setAzimuthScaleDraw(new AzimuthScaleDraw()); m_grid->showAxis(QwtPolar::AxisAzimuth, true); m_grid->showAxis(QwtPolar::AxisLeft, false); m_grid->showAxis(QwtPolar::AxisRight, true); m_grid->showAxis(QwtPolar::AxisTop, false); m_grid->showAxis(QwtPolar::AxisBottom, false); m_grid->showGrid(QwtPolar::Azimuth, true); m_grid->showGrid(QwtPolar::Radius, true); m_grid->attach(this); setMinimumSize(defaultPlotSize); m_currAzimuth = 0; QVector<double> azimuth; QVector<double> radius; azimuth.fill(m_currAzimuth, 2); radius.append(0); radius.append(maxBeamRadius); m_beamCurve = new QwtPolarCurve; m_beamCurve->setPen(QPen(QBrush(Qt::green), beamPenWidth)); m_beamData = new Data(azimuth, radius, beamId); m_beamCurve->setData(m_beamData); m_beamCurve->attach(this); // Blind Zone Curve radius.clear(); azimuth.clear(); radius.fill(5, 33); for(double i = 0; i <= 360; i += 11.25) { azimuth.append(i); } QwtPolarCurve *blindZoneCurve = new QwtPolarCurveJamming; blindZoneCurve->setPen(QPen(QBrush(Qt::yellow), 0)); Data *blindZoneData = new Data(azimuth, radius, 0x10000); blindZoneCurve->setData(blindZoneData); blindZoneCurve->attach(this); m_cycleTime = Cicle10; m_azimuthChange->setInterval(cicleInterval); m_nextAzimuthData->setInterval(packetsInterval); connect(m_azimuthChange, SIGNAL(timeout()), this, SLOT(azimuthChanged())); connect(m_nextAzimuthData, SIGNAL(timeout()), this, SLOT(nextAzimuthData())); // connect(m_picker, SIGNAL(moved(QwtPointPolar)), this, SLOT(moveMarkID(QwtPointPolar))); // connect(m_picker, SIGNAL(appended(QwtPointPolar)), this, SLOT(selectMarkID(QwtPointPolar))); // connect(m_picker, SIGNAL(activated(bool)), this, SLOT(stopMoving(bool))); }
void ProgressBar::paintEvent(QPaintEvent *) { // TODO move font into Utils::StyleHelper // TODO use Utils::StyleHelper white double range = maximum() - minimum(); double percent = 0.50; if (range != 0) percent = (value() - minimum()) / range; if (percent > 1) percent = 1; else if (percent < 0) percent = 0; QPainter p(this); QFont boldFont(p.font()); boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); boldFont.setBold(true); p.setFont(boldFont); QFontMetrics fm(boldFont); // Draw separator int h = fm.height(); p.setPen(QColor(0, 0, 0, 70)); p.drawLine(0,0, size().width(), 0); p.setPen(QColor(255, 255, 255, 70)); p.drawLine(0, 1, size().width(), 1); QRect textRect = rect().adjusted(0, 0, -1, 0); textRect.setHeight(h+5); p.setPen(QColor(30, 30, 30, 80)); p.drawText(textRect, Qt::AlignHCenter | Qt::AlignBottom, m_title); p.translate(0, -1); p.setPen(Utils::StyleHelper::panelTextColor()); p.drawText(textRect, Qt::AlignHCenter | Qt::AlignBottom, m_title); p.translate(0, 1); m_progressHeight = PROGRESSBAR_HEIGHT; m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd // draw outer rect QRect rect(INDENT - 1, h+6, size().width()-2*INDENT, m_progressHeight-1); p.setPen(Utils::StyleHelper::panelTextColor()); p.drawRect(rect); // draw inner rect QColor c = Utils::StyleHelper::panelTextColor(); c.setAlpha(180); p.setPen(Qt::NoPen); QRect inner = rect.adjusted(2, 2, -1, -1); inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0); if (m_error) { QColor red(255, 60, 0, 210); c = red; // avoid too small red bar if (inner.width() < 10) inner.adjust(0, 0, 10 - inner.width(), 0); } else if (value() == maximum()) { c = QColor(120, 245, 90, 180); } QLinearGradient grad(inner.topLeft(), inner.bottomLeft()); grad.setColorAt(0, c.lighter(114)); grad.setColorAt(0.5, c.lighter(104)); grad.setColorAt(0.51, c.darker(108)); grad.setColorAt(1, c.darker(120)); p.setBrush(grad); p.drawRect(inner); if (value() < maximum() && !m_error) { QColor cancelOutline = Utils::StyleHelper::panelTextColor(); p.setPen(cancelOutline); QRect cancelRect(rect.right() - m_progressHeight + 2, rect.top(), m_progressHeight-1, rect.height()); if (cancelRect.contains(mapFromGlobal(QCursor::pos()))) p.setBrush(QColor(230, 90, 40, 190)); else p.setBrush(Qt::NoBrush); p.drawRect(cancelRect); p.setPen(QPen(QColor(0, 0, 0, 70), 3)); p.drawLine(cancelRect.center()+QPoint(-1,-1), cancelRect.center()+QPoint(+3,+3)); p.drawLine(cancelRect.center()+QPoint(+3,-1), cancelRect.center()+QPoint(-1,+3)); p.setPen(Utils::StyleHelper::panelTextColor()); p.drawLine(cancelRect.center()+QPoint(-1,-1), cancelRect.center()+QPoint(+3,+3)); p.drawLine(cancelRect.center()+QPoint(+3,-1), cancelRect.center()+QPoint(-1,+3)); } }
/*!\reimp */ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, const QColorGroup &cg, SFlags flags, const QStyleOption& opt ) const { switch (pe) { case PE_HeaderSection: { // adjust the sunken flag, otherwise headers are drawn // sunken... if ( flags & Style_Sunken ) flags ^= Style_Sunken; drawPrimitive( PE_ButtonBevel, p, r, cg, flags, opt ); break; } case PE_ButtonTool: { // tool buttons don't change color when pushed in platinum, // so we need to make the mid and button color the same QColorGroup myCG = cg; QBrush fill; // quick trick to make sure toolbuttons drawn sunken // when they are activated... if ( flags & Style_On ) flags |= Style_Sunken; fill = myCG.brush( QColorGroup::Button ); myCG.setBrush( QColorGroup::Mid, fill ); drawPrimitive( PE_ButtonBevel, p, r, myCG, flags, opt ); break; } case PE_ButtonBevel: { int x, y, w, h; r.rect( &x, &y, &w, &h ); QPen oldPen = p->pen(); if ( w * h < 1600 || QABS(w - h) > 10 ) { // small buttons if ( !(flags & (Style_Sunken | Style_Down)) ) { p->fillRect( x + 2, y + 2, w - 4, h - 4, cg.brush(QColorGroup::Button) ); // the bright side p->setPen( cg.dark() ); // the bright side p->setPen( cg.dark() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.light() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the dark side p->setPen( cg.mid() ); p->drawLine( x + 2, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 2, x + w - 2, y + h - 3 ); p->setPen( cg.dark().dark() ); p->drawLine( x + 1, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y + 1, x + w - 1, y + h - 2 ); } else { p->fillRect(x + 2, y + 2, w - 4, h - 4, cg.brush( QColorGroup::Mid )); // the dark side p->setPen( cg.dark().dark() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.mid().dark()); p->drawLine( x + 1, y + 1, x + w-2, y + 1); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the bright side! p->setPen(cg.button()); p->drawLine( x + 1, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 ); p->setPen(cg.dark()); p->drawLine(x, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine(x + w - 1, y, x + w - 1, y + h - 1 ); } } else { // big ones if ( !(flags & (Style_Sunken | Style_Down)) ) { p->fillRect( x + 3, y + 3, w - 6, h - 6, cg.brush(QColorGroup::Button) ); // the bright side p->setPen( cg.button().dark() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.button() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); p->setPen( cg.light() ); p->drawLine( x + 2, y + 2, x + 2, y + h - 2 ); p->drawLine( x + 2, y + 2, x + w - 2, y + 2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( x + 3, y + h - 3, x + w - 3, y + h - 3 ); p->drawLine( x + w - 3, y + 3, x + w - 3, y + h - 3 ); p->setPen( cg.dark() ); p->drawLine( x + 2, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 2, x + w - 2, y + h - 2 ); p->setPen( cg.dark().dark() ); p->drawLine( x + 1, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y + 1, x + w - 1, y + h - 1 ); } else { p->fillRect( x + 3, y + 3, w - 6, h - 6, cg.brush( QColorGroup::Mid ) ); // the dark side p->setPen( cg.dark().dark().dark() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.dark().dark() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); p->setPen( cg.mid().dark() ); p->drawLine( x + 2, y + 2, x + 2, y + w - 2 ); p->drawLine( x + 2, y + 2, x + w - 2, y + 2 ); // the bright side! p->setPen( cg.button() ); p->drawLine( x + 2, y + h - 3, x + w - 3, y + h - 3 ); p->drawLine( x + w - 3, y + 3, x + w - 3, y + h - 3 ); p->setPen( cg.midlight() ); p->drawLine( x + 1, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // corners p->setPen( mixedColor(cg.dark().dark().dark(), cg.dark()) ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + w - 1, y ); p->setPen( mixedColor(cg.dark().dark(), cg.midlight()) ); p->drawPoint( x + 1, y + h - 2 ); p->drawPoint( x + w - 2, y + 1 ); p->setPen( mixedColor(cg.mid().dark(), cg.button() ) ); p->drawPoint( x + 2, y + h - 3 ); p->drawPoint( x + w - 3, y + 2 ); } } p->setPen( oldPen ); break; } case PE_ButtonCommand: { QPen oldPen = p->pen(); int x, y, w, h; r.rect( &x, &y, &w, &h); if ( !(flags & (Style_Down | Style_On)) ) { p->fillRect( x+3, y+3, w-6, h-6, cg.brush( QColorGroup::Button )); // the bright side p->setPen( cg.shadow() ); p->drawLine( x, y, x+w-1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.button() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); p->setPen( cg.light() ); p->drawLine( x + 2, y + 2, x + 2, y + h - 2 ); p->drawLine( x + 2, y + 2, x + w - 2, y + 2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( x + 3, y + h - 3 ,x + w - 3, y + h - 3 ); p->drawLine( x + w - 3, y + 3, x + w - 3, y + h - 3 ); p->setPen( cg.dark() ); p->drawLine( x + 2, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 2, x + w - 2, y + h - 2 ); p->setPen( cg.shadow() ); p->drawLine( x + 1, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen( cg.background() ); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y+1 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + 1 ); p->setPen( cg.button() ); p->drawPoint( x + 2, y + 2 ); p->setPen( white ); p->drawPoint( x + 3, y + 3 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + 2, y + h - 3 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w -1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + 1 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + 2 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); p->setPen( cg.mid() ); p->drawPoint( x + w - 4, y + h - 4 ); } else { p->fillRect( x + 2, y + 2, w - 4, h - 4, cg.brush(QColorGroup::Dark) ); // the dark side p->setPen( cg.shadow() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.dark().dark() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the bright side! p->setPen( cg.button() ); p->drawLine( x + 1, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen( cg.background() ); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + 1 ); p->setPen( cg.dark().dark() ); p->drawPoint( x + 3, y + 3 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + h - 2 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); p->setPen( cg.mid() ); p->drawPoint( x + w - 4, y + h - 4 ); } p->setPen( oldPen ); break; } case PE_Indicator: { drawPrimitive( PE_ButtonBevel, p, QRect(r.x(), r.y(), r.width() - 2, r.height()), cg, flags ); p->fillRect( r.x() + r.width() - 2, r.y(), 2, r.height(), cg.brush( QColorGroup::Background ) ); p->setPen( cg.shadow() ); p->drawRect( r.x(), r.y(), r.width() - 2, r.height() ); static const QCOORD nochange_mark[] = { 3,5, 9,5, 3,6, 9,6 }; static const QCOORD check_mark[] = { 3,5, 5,5, 4,6, 5,6, 5,7, 6,7, 5,8, 6,8, 6,9, 9,9, 6,10, 8,10, 7,11, 8,11, 7,12, 7,12, 8,8, 9,8, 8,7, 10,7, 9,6, 10,6, 9,5, 11,5, 10,4, 11,4, 10,3, 12,3, 11,2, 12,2, 11,1, 13,1, 12,0, 13,0 }; if ( !(flags & Style_Off) ) { QPen oldPen = p->pen(); int x1 = r.x(); int y1 = r.y(); if ( flags & Style_Down ) { x1++; y1++; } QPointArray amark; if ( flags & Style_On ) { amark = QPointArray( sizeof(check_mark)/(sizeof(QCOORD)*2), check_mark ); // ### KLUDGE!! flags ^= Style_On; flags ^= Style_Down; } else if ( flags & Style_NoChange ) { amark = QPointArray( sizeof(nochange_mark) / (sizeof(QCOORD) * 2), nochange_mark ); } amark.translate( x1 + 1, y1 + 1 ); p->setPen( cg.dark() ); p->drawLineSegments( amark ); amark.translate( -1, -1 ); p->setPen( cg.foreground() ); p->drawLineSegments( amark ); p->setPen( oldPen ); } break; } case PE_IndicatorMask: { int x, y, w, h; r.rect( &x, &y, &w, &h ); p->fillRect( x, y, w - 2, h, color1); if ( flags & Style_Off ) { QPen oldPen = p->pen(); p->setPen ( QPen(color1, 2)); p->drawLine( x + 2, y + h / 2 - 1, x + w / 2 - 1, y + h - 4 ); p->drawLine( x + w / 2 - 1, y + h - 4, x + w, 0); p->setPen( oldPen ); } break; } case PE_ExclusiveIndicator: { #define QCOORDARRLEN(x) sizeof(x) / (sizeof(QCOORD) * 2 ) bool down = flags & Style_Down; bool on = flags & Style_On; static const QCOORD pts1[] = { // normal circle 5,0, 8,0, 9,1, 10,1, 11,2, 12,3, 12,4, 13,5, 13,8, 12,9, 12,10, 11,11, 10,12, 9,12, 8,13, 5,13, 4,12, 3,12, 2,11, 1,10, 1,9, 0,8, 0,5, 1,4, 1,3, 2,2, 3,1, 4,1 }; static const QCOORD pts2[] = { // top left shadow 5,1, 8,1, 3,2, 7,2, 2,3, 5,3, 2,4, 4,4, 1,5, 3,5, 1,6, 1,8, 2,6, 2,7 }; static const QCOORD pts3[] = { // bottom right, dark 5,12, 8,12, 7,11, 10,11, 8,10, 11,10, 9,9, 11,9, 10,8, 12,8, 11,7, 11,7, 12,5, 12,7 }; static const QCOORD pts4[] = { // bottom right, light 5,12, 8,12, 7,11, 10,11, 9,10, 11,10, 10,9, 11,9, 11,7, 11,8, 12,5, 12,8 }; static const QCOORD pts5[] = { // check mark 6,4, 8,4, 10,6, 10,8, 8,10, 6,10, 4,8, 4,6 }; static const QCOORD pts6[] = { // check mark extras 4,5, 5,4, 9,4, 10,5, 10,9, 9,10, 5,10, 4,9 }; int x, y; x = r.x(); y = r.y(); p->eraseRect( r ); p->setBrush( (down||on) ? cg.brush( QColorGroup::Dark ) : cg.brush( QColorGroup::Button) ); p->setPen( NoPen ); p->drawEllipse( x, y, 13, 13 ); p->setPen( cg.shadow() ); QPointArray a( QCOORDARRLEN(pts1), pts1 ); a.translate( x, y ); p->drawPolyline( a ); // draw normal circle QColor tc, bc; const QCOORD *bp; int bl; if ( down || on ) { // pressed down or on tc = cg.dark().dark(); bc = cg.light(); bp = pts4; bl = QCOORDARRLEN(pts4); } else { // released tc = cg.light(); bc = cg.dark(); bp = pts3; bl = QCOORDARRLEN(pts3); } p->setPen( tc ); a.setPoints( QCOORDARRLEN(pts2), pts2 ); a.translate( x, y ); p->drawLineSegments( a ); // draw top shadow p->setPen( bc ); a.setPoints( bl, bp ); a.translate( x, y ); p->drawLineSegments( a ); if ( on ) { // draw check mark int x1 = x, y1 = y; p->setBrush( cg.foreground() ); p->setPen( cg.foreground() ); a.setPoints( QCOORDARRLEN(pts5), pts5 ); a.translate( x1, y1 ); p->drawPolygon( a ); p->setBrush( NoBrush ); p->setPen( cg.dark() ); a.setPoints( QCOORDARRLEN(pts6), pts6 ); a.translate( x1, y1 ); p->drawLineSegments( a ); } break; } case PE_ExclusiveIndicatorMask: { static const QCOORD pts1[] = { // normal circle 5,0, 8,0, 9,1, 10,1, 11,2, 12,3, 12,4, 13,5, 13,8, 12,9, 12,10, 11,11, 10,12, 9,12, 8,13, 5,13, 4,12, 3,12, 2,11, 1,10, 1,9, 0,8, 0,5, 1,4, 1,3, 2,2, 3,1, 4,1 }; QPointArray a(QCOORDARRLEN(pts1), pts1); a.translate(r.x(), r.y()); p->setPen(color1); p->setBrush(color1); p->drawPolygon(a); break; } case PE_ScrollBarAddLine: { drawPrimitive( PE_ButtonBevel, p, r, cg, (flags & Style_Enabled) | ((flags & Style_Down) ? Style_Sunken : Style_Raised) ); p->setPen( cg.shadow() ); p->drawRect( r ); drawPrimitive( ((flags & Style_Horizontal) ? PE_ArrowRight : PE_ArrowDown), p, QRect(r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4), cg, flags ); break; } case PE_ScrollBarSubLine: { drawPrimitive( PE_ButtonBevel, p, r, cg, (flags & Style_Enabled) | ((flags & Style_Down) ? Style_Sunken : Style_Raised) ); p->setPen( cg.shadow() ); p->drawRect( r ); drawPrimitive( ((flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp ), p, QRect(r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4), cg, flags ); break; } case PE_ScrollBarAddPage: case PE_ScrollBarSubPage: { QPen oldPen = p->pen(); if ( r.width() < 3 || r.height() < 3 ) { p->fillRect( r, cg.brush(QColorGroup::Mid) ); p->setPen( cg.shadow() ); p->drawRect( r ); p->setPen( oldPen ); } else { int x, y, w, h; r.rect( &x, &y, &w, &h ); if ( flags & Style_Horizontal ) { p->fillRect( x + 2, y + 2, w - 2, h - 4, cg.brush(QColorGroup::Mid) ); // the dark side p->setPen( cg.dark().dark() ); p->drawLine( x, y, x + w - 1, y ); p->setPen( cg.shadow()); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.mid().dark()); p->drawLine( x + 1, y + 1, x + w - 1, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the bright side! p->setPen( cg.button()); p->drawLine( x + 1, y + h - 2, x + w - 1, y + h - 2 ); p->setPen( cg.shadow()); p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 ); } else { p->fillRect( x + 2, y + 2, w - 4, h - 2, cg.brush(QColorGroup::Mid) ); // the dark side p->setPen( cg.dark().dark() ); p->drawLine( x, y, x + w - 1, y ); p->setPen( cg.shadow() ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.mid().dark() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 1 ); // the bright side! p->setPen( cg.button() ); p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 1 ); p->setPen( cg.shadow() ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); } } p->setPen( oldPen ); break; } case PE_ScrollBarSlider: { QPoint bo = p->brushOrigin(); p->setBrushOrigin( r.topLeft() ); drawPrimitive( PE_ButtonBevel, p, r, cg, Style_Raised ); p->setBrushOrigin( bo ); drawRiffles( p, r.x(), r.y(), r.width(), r.height(), cg, flags & Style_Horizontal ); p->setPen( cg.shadow() ); p->drawRect( r ); if ( flags & Style_HasFocus ) { drawPrimitive( PE_FocusRect, p, QRect(r.x() + 2, r.y() + 2, r.width() - 5, r.height() - 5 ), cg, flags ); } break; } default: QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt ); break; } }
/*! Build and assign the symbol pen In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it non cosmetic ( see QPen::isCosmetic() ). This method has been introduced to hide this incompatibility. \param color Pen color \param width Pen width \param style Pen style \sa pen(), brush() */ void QwtPlotTradingCurve::setSymbolPen( const QColor &color, qreal width, Qt::PenStyle style ) { setSymbolPen( QPen( color, width, style ) ); }
QString UBSettings::uniboardDocumentNamespaceUri = "http://uniboard.mnemis.com/document"; QString UBSettings::uniboardApplicationNamespaceUri = "http://uniboard.mnemis.com/application"; const int UBSettings::sDefaultFontPixelSize = 36; const char *UBSettings::sDefaultFontFamily = "Arial"; QString UBSettings::currentFileVersion = "4.6.0"; QColor UBSettings::crossDarkBackground = QColor(44, 44, 44, 200); QColor UBSettings::crossLightBackground = QColor(165, 225, 255); QBrush UBSettings::eraserBrushLightBackground = QBrush(QColor(255, 255, 255, 30)); QBrush UBSettings::eraserBrushDarkBackground = QBrush(QColor(127, 127, 127, 30)); QPen UBSettings::eraserPenDarkBackground = QPen(QColor(255, 255, 255, 63)); QPen UBSettings::eraserPenLightBackground = QPen(QColor(0, 0, 0, 63)); QColor UBSettings::documentSizeMarkColorDarkBackground = QColor(44, 44, 44, 200); QColor UBSettings::documentSizeMarkColorLightBackground = QColor(241, 241, 241); QColor UBSettings::paletteColor = QColor(127, 127, 127, 127); QColor UBSettings::opaquePaletteColor = QColor(66, 66, 66, 200); QColor UBSettings::documentViewLightColor = QColor(241, 241, 241); QPointer<QSettings> UBSettings::sAppSettings = 0; const int UBSettings::maxThumbnailWidth = 400; const int UBSettings::defaultThumbnailWidth = 150;
void EnvironmentScene::DrawLocations(QList <FossilRecord *> frlist, bool show) { if (show) { QList <bool> selecteds = MainWin->FRW->GetSelections(); //add any new items needed while (frlist.count()>HorizontalLineList.count()) { HorizontalLineList.append(new QGraphicsLineItem(0,this)); VerticalLineList.append(new QGraphicsLineItem(0,this)); LabelsList.append(new QGraphicsSimpleTextItem(0,this)); } //now remove any spurious ones while (frlist.count()<HorizontalLineList.count()) { QGraphicsLineItem *r1=HorizontalLineList.takeLast(); QGraphicsLineItem *r2=VerticalLineList.takeLast(); QGraphicsSimpleTextItem *t=LabelsList.takeLast(); removeItem(r1); removeItem(r2); removeItem(t); } //now set them up for (int i=0; i<frlist.count(); i++) { HorizontalLineList[i]->setLine(frlist[i]->xpos-.5,frlist[i]->ypos+.5, frlist[i]->xpos+1.5,frlist[i]->ypos+.5); VerticalLineList[i]->setLine(frlist[i]->xpos+.5,frlist[i]->ypos-.5, frlist[i]->xpos+.5,frlist[i]->ypos+1.5); HorizontalLineList[i]->setVisible(selecteds[i]); VerticalLineList[i]->setVisible(selecteds[i]); VerticalLineList[i]->setZValue(i+1); HorizontalLineList[i]->setZValue(i+1); LabelsList[i]->setText(frlist[i]->name); LabelsList[i]->setX(frlist[i]->xpos+1); LabelsList[i]->setY(frlist[i]->ypos-2); LabelsList[i]->setFont(QFont("Arial",12)); LabelsList[i]->setScale(.15); LabelsList[i]->setVisible(selecteds[i]); LabelsList[i]->setZValue(i+1); //sort out colours int bright = (int)(environment[frlist[i]->xpos][frlist[i]->ypos][0]) + (int)(environment[frlist[i]->xpos][frlist[i]->ypos][1]) + (int)(environment[frlist[i]->xpos][frlist[i]->ypos][2]); if (bright>250) { VerticalLineList[i]->setPen(QPen(Qt::black)); HorizontalLineList[i]->setPen(QPen(Qt::black)); LabelsList[i]->setBrush(QBrush(Qt::black)); } else { VerticalLineList[i]->setPen(QPen(Qt::white)); HorizontalLineList[i]->setPen(QPen(Qt::white)); LabelsList[i]->setBrush(QBrush(Qt::white)); } } } else for (int i=0; i<VerticalLineList.count(); i++) { HorizontalLineList[i]->setVisible(false); VerticalLineList[i]->setVisible(false); LabelsList[i]->setVisible(false); } }
void WaveformRendererEndOfTrack::draw(QPainter* painter, QPaintEvent* /*event*/) { const double trackSamples = m_waveformRenderer->getTrackSamples(); const double sampleRate = m_pTrackSampleRate->get(); /*qDebug() << "WaveformRendererEndOfTrack :: " << "trackSamples" << trackSamples << "sampleRate" << sampleRate << "m_playControl->get()" << m_playControl->get() << "m_loopControl->get()" << m_loopControl->get();*/ m_endOfTrackEnabled = m_pEndOfTrackControl->get() > 0.5; //special case of track not long enougth const double trackLength = 0.5 * trackSamples / sampleRate; if (sampleRate < 0.1 //not ready || trackSamples < 0.1 //not ready || m_pPlayControl->get() < 0.5 //not playing || m_pLoopControl->get() > 0.5 //in loop || trackLength <= m_remainingTimeTriggerSeconds //track too short ) { if (m_endOfTrackEnabled) { m_pEndOfTrackControl->slotSet(0.0); m_endOfTrackEnabled = false; } return; } const double dPlaypos = m_waveformRenderer->getPlayPos(); const double remainingFrames = (1.0 - dPlaypos) * 0.5 * trackSamples; const double remainingTime = remainingFrames / sampleRate; if (remainingTime > m_remainingTimeTriggerSeconds) { if (m_endOfTrackEnabled) { m_pEndOfTrackControl->slotSet(0.); m_endOfTrackEnabled = false; } return; } // end of track is on if (!m_endOfTrackEnabled) { m_pEndOfTrackControl->slotSet(1.); m_endOfTrackEnabled = true; //qDebug() << "EndOfTrack ON"; } //ScopedTimer t("WaveformRendererEndOfTrack::draw"); const int elapsed = m_timer.elapsed() % m_blinkingPeriodMillis; const double blickIntensity = (double)(2 * abs(elapsed - m_blinkingPeriodMillis/2)) / m_blinkingPeriodMillis; const double criticalIntensity = (m_remainingTimeTriggerSeconds - remainingTime) / m_remainingTimeTriggerSeconds; painter->save(); painter->resetTransform(); painter->setOpacity(0.5 * blickIntensity); painter->setPen(m_pen); painter->drawRect(1, 1, m_waveformRenderer->getWidth() - 2, m_waveformRenderer->getHeight() - 2); painter->setOpacity(0.5 * 0.25 * criticalIntensity * blickIntensity); painter->setPen(QPen(Qt::transparent)); painter->setBrush(m_color); painter->drawRects(m_backRects); // This is significant slower //painter->setOpacity(0.5 * criticalIntensity * blickIntensity); //painter->fillRect(m_waveformRenderer->getWidth()/2, 1, // m_waveformRenderer->getWidth() - 2, m_waveformRenderer->getHeight() - 2, // m_gradient); painter->restore(); }
void Plot::showSpectrogram(bool on) { d_spectrogram->setDisplayMode(QwtPlotSpectrogram::ImageMode, on); d_spectrogram->setDefaultContourPen(on ? QPen() : QPen(Qt::NoPen)); replot(); }
void Style::drawComboBox(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { ASSURE_OPTION(cmb, ComboBox); OPT_ENABLED OPT_HOVER OPT_FOCUS SAVE_PAINTER(Pen|Brush|Alias); if ( widget && widget->inherits("WebView") ) { // paints hardcoded black text bypassing the style?! grrr... const_cast<QStyleOptionComboBox*>(cmb)->palette.setColor(QPalette::Window, QColor(230,230,230,255)); widget = 0; } animStep = !widget ? MAX_STEPS*hover : Animator::Hover::step(widget); QRect ar; const QComboBox *combo = widget ? qobject_cast<const QComboBox*>(widget) : NULL; if ((cmb->subControls & SC_ComboBoxArrow) && (!combo || combo->count() > 0)) { // do we have an arrow? ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); const int dx = (F(2) & ~1) / 2; ar.translate(cmb->direction == Qt::LeftToRight ? -dx : dx, 0); } const bool listShown = combo && combo->view() && ((QWidget*)(combo->view()))->isVisible(); if (listShown) { // this messes up hover hover = hover || QRect(widget->mapToGlobal(RECT.topLeft()), RECT.size()).contains(QCursor::pos()); // TODO Qt5, avoid asking for the cursor pos animStep = MAX_STEPS; } QColor c = hasFocus ? FCOLOR(Highlight) : (cmb->editable ? FCOLOR(Text) : FCOLOR(WindowText)); if (cmb->editable) { drawLineEditFrame(option, painter, widget); c = FX::blend(FCOLOR(Base), c, MAX_STEPS, 1 + 2*animStep); } else { const int icon = cmb->currentIcon.isNull() ? 0 : cmb->iconSize.width() + F(4); QFont fnt(painter->font()); fnt.setBold(true); int text = QFontMetrics(fnt).width(cmb->currentText); if (text) text += F(4); if (!(text+icon)) // webkit etc. text = ar.left() - (F(16) + RECT.x()); painter->setRenderHint(QPainter::Antialiasing, true); painter->setPen(QPen(hasFocus ? FCOLOR(Highlight) : FX::blend(FCOLOR(Window), c, 4, 1), FRAME_STROKE)); painter->setBrush(Qt::NoBrush); const int y = ar.y() + ar.height()/2; const int da = animStep * 168 / MAX_STEPS; if (option->direction == Qt::LeftToRight) { DRAW_SEGMENT(ar, 16*(120 - da/2), 16*(192+da)); painter->drawLine(RECT.x() + icon + text + F(6), y, ar.left()-F(2), y); } else { DRAW_SEGMENT(ar, 16*(30 + da/2), -16*(192+da)); painter->drawLine(RECT.right() - (icon + text + F(6)), y, ar.right()+F(2), y); } c = FX::blend(FCOLOR(Window), FCOLOR(WindowText), MAX_STEPS - animStep, 1 + animStep); } if (!isEnabled) { RESTORE_PAINTER return; }
void MainWindow::setupRealtimeDataDemo(QCustomPlot *customPlot_0, QCustomPlot *customPlot_1){ demoName = "Real Time Data Demo"; server.show(); customPlot_0->addGraph(); // blue line customPlot_0->graph(0)->setPen(QPen(Qt::blue)); customPlot_0->addGraph(); // red line customPlot_0->graph(1)->setPen(QPen(Qt::red)); customPlot_0->graph(1)->setBrush(QBrush(QColor(240, 255, 200))); customPlot_0->graph(1)->setChannelFillGraph(customPlot_0->graph(0)); customPlot_0->addGraph(); // blue dot customPlot_0->graph(2)->setPen(QPen(Qt::blue)); customPlot_0->graph(2)->setLineStyle(QCPGraph::lsNone); customPlot_0->graph(2)->setScatterStyle(QCPScatterStyle::ssDisc); customPlot_0->addGraph(); // red upper dot customPlot_0->graph(3)->setPen(QPen(Qt::red)); customPlot_0->graph(3)->setLineStyle(QCPGraph::lsNone); customPlot_0->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc); customPlot_0->xAxis->setTickLabelType(QCPAxis::ltDateTime); customPlot_0->xAxis->setDateTimeFormat("hh:mm:ss"); customPlot_0->xAxis->setAutoTickStep(false); customPlot_0->xAxis->setTickStep(5); customPlot_0->axisRect()->setupFullAxesBox(); //********* added by Peng Li customPlot_1->addGraph(); // blue line customPlot_1->graph(0)->setPen(QPen(Qt::blue)); customPlot_1->graph(0)->setAntialiasedFill(false); customPlot_1->addGraph(); // blue dot customPlot_1->graph(1)->setPen(QPen(Qt::blue)); customPlot_1->graph(1)->setLineStyle(QCPGraph::lsNone); customPlot_1->graph(1)->setScatterStyle(QCPScatterStyle::ssDisc); customPlot_1->xAxis->setTickLabelType(QCPAxis::ltDateTime); customPlot_1->xAxis->setDateTimeFormat("hh:mm:ss"); customPlot_1->xAxis->setAutoTickStep(false); customPlot_1->xAxis->setTickStep(5); customPlot_1->axisRect()->setupFullAxesBox(); customPlot_0->yAxis->setRange(0, 110); customPlot_1->yAxis->setRange(0, 70); //********* stop adding // make left and bottom axes transfer their ranges to right and top axes: connect(customPlot_0->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_0->xAxis2, SLOT(setRange(QCPRange))); // connect(customPlot_0->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_0->yAxis2, SLOT(setRange(QCPRange))); //********* added by Peng Li connect(customPlot_1->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_1->xAxis2, SLOT(setRange(QCPRange))); // connect(customPlot_1->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_1->yAxis2, SLOT(setRange(QCPRange))); //********* stop adding // setup a timer that repeatedly calls MainWindow::realtimeDataSlot: connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot())); dataTimer.start(0); // Interval 0 means to refresh as fast as possible }
// Overloaded paint event to draw the actual state. void QSlideSwitch::paintEvent(QPaintEvent *) { #ifdef WITH_TEXT QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::TextAntialiasing); painter.setPen(QPen(Qt::NoPen)); if (isChecked()) { // Render ON background painter.setBrush(m_onBrush); painter.drawRoundedRect(m_rect, 8, 8); // Render ON text m_text_rect = QRect(5, m_textY, m_textOnWidth, m_textHeight); painter.setPen(QPen(Qt::white)); painter.drawText(m_text_rect, Qt::AlignVCenter, m_textOn); } else { // Render OFF background painter.setBrush(m_offBrush); painter.drawRoundedRect(m_rect, 8, 8); // Render OFF text m_text_rect = QRect(m_rect.width() - m_textOffWidth - 5, m_textY, m_textOffWidth, m_textHeight); painter.setPen(QPen(QColor("#7F7F7F"))); painter.drawText(m_text_rect, Qt::AlignVCenter, m_textOff); } // Render knob painter.setBrush(m_knobBrush); if (m_dragInProgress) { painter.setPen(QPen(Qt::green, m_knobBorder)); } else { painter.setPen(QPen(m_knobBorderBrush, m_knobBorder)); } painter.drawRoundedRect(knobRect(), 18, 18); #else /* iOS 7 Style */ QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); // sx and dx borders (half circles) qreal knobWidth = m_rect.height(); QRectF sxRect(0, 0, knobWidth, m_rect.height()); QRectF dxRect(m_rect.width() - knobWidth, 0, knobWidth, m_rect.height()); QPainterPath sliderPath; sliderPath.moveTo(knobWidth/2, 0); sliderPath.arcTo(sxRect, 90, 180); sliderPath.lineTo(m_rect.width() - knobWidth/2, m_rect.height()); sliderPath.arcTo(dxRect, -90, 180); sliderPath.lineTo(knobWidth/2, 0); if (isChecked()) { // Render ON m_sliderBrush.setColor(m_iOSGreen); m_sliderPen.setColor(m_iOSGreen); // m_knobBrush.setColor(Qt::white); UGUALE PER TUTTI m_knobPen.setColor(m_iOSGreen); // painter.setPen(QPen(m_iOSGreen, m_knobBorder)); // painter.setBrush(m_iOSGreen); // painter.setBrush(Qt::white); // Brush fro knob // painter.drawEllipse(knobRect()); } else { // Render OFF m_sliderBrush.setColor(Qt::white); m_sliderPen.setColor(m_iOSGrey); // m_knobBrush.setColor(Qt::white); m_knobPen.setColor(m_iOSGrey); // painter.setBrush(Qt::white); // painter.setPen(QPen(m_iOSGrey, m_knobBorder)); // painter.drawPath(sliderPath); } painter.setBrush(m_sliderBrush); painter.setPen(m_sliderPen); painter.drawPath(sliderPath); painter.setBrush(Qt::white); //painter.setBrush(m_knobBrush); painter.setPen(m_knobPen); // Higlight when dragging slider if (m_dragInProgress) { painter.setPen(QPen(QColor("#377FF8"), m_knobBorder)); painter.drawEllipse(knobRect()); } else { // Render knob with last Pen & Brush painter.drawEllipse(knobRect()); } #endif }
void TabBar::paintRectTabs(QStylePainter &p) { static const qreal penScaleFactor = 0.2; for (int i = 0; i < count(); i++) { QStyleOptionTab o; initStyleOption(&o, i); // Background color p.save(); if (i != currentIndex()) { o.rect.adjust(0, 2, 0, 0); } else if (i == count()) { o.rect.adjust(2, 2, -4, -4); } // Highlight the tab under the cursor if (o.state.testFlag(QStyle::State_MouseOver) && i != currentIndex()) { p.setPen(QPen(o.palette.highlight(), penScaleFactor)); p.fillRect(o.rect, o.palette.highlight().color().lighter()); } else { p.setPen(QPen(o.palette.mid(), penScaleFactor)); if (i == currentIndex()) { /// XXX if (SettingsPrivate::instance()->isCustomColors()) { p.fillRect(o.rect, o.palette.base().color().lighter(110)); } else { p.fillRect(o.rect, o.palette.base()); } } else { p.fillRect(o.rect, o.palette.window()); } } if (o.state.testFlag(QStyle::State_MouseOver)) { p.setPen(o.palette.highlight().color()); } else { p.setPen(o.palette.mid().color()); } // Frame tab, it is not a rectangle but only 3 lines p.drawLine(o.rect.topLeft(), o.rect.bottomLeft()); p.drawLine(o.rect.topRight(), o.rect.bottomRight()); p.drawLine(o.rect.topLeft(), o.rect.topRight()); //} p.restore(); // Icon QRect r = tabRect(i); r.setHeight(fontMetrics().ascent()); r.translate(10, (height() - r.height()) / 2); r.setWidth(r.height() / 2); p.setRenderHint(QPainter::SmoothPixmapTransform); o.icon.paint(&p, r, Qt::AlignLeft | Qt::AlignVCenter); // Playlist name if (i == currentIndex()) { p.setPen(o.palette.windowText().color()); } else if (o.state.testFlag(QStyle::State_MouseOver)) { p.setPen(o.palette.windowText().color()); } else { p.setPen(o.palette.mid().color()); } QRect rText(r.x() + r.width() + 10, r.y(), o.rect.width() - r.width() - 10, r.height()); p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, o.text); } }
// ------------------------------------------------------------------------- void GraphRingMap::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - painter->setPen( m_pen ); painter->drawEllipse( m_rect ); painter->setPen( QPen(QBrush(QColor(128,128,128,128)), 1.0) ); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Draw several pies that represent the quadrants of the ring map. if( m_bDrawQuadrants ) { painter->drawPie(m_rect, 0*16, 0); painter->drawPie(m_rect, 90*16, 0); painter->drawPie(m_rect, 180*16, 0); painter->drawPie(m_rect, 270*16, 0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Draw several rings representing 25%, 50%, and 75% of the ring map. if( m_bDrawRingMarkers ) { QRectF rect = m_rect; rect.setWidth ( m_rect.width() * 0.25 ); rect.setHeight( m_rect.height() * 0.25 ); rect.translate( m_rect.center().x()-rect.center().x(),m_rect.center().y()-rect.center().y() ); painter->drawEllipse( rect ); rect.setWidth ( m_rect.width() * 0.5 ); rect.setHeight( m_rect.height() * 0.5 ); rect.translate( m_rect.center().x()-rect.center().x(),m_rect.center().y()-rect.center().y() ); painter->drawEllipse( rect ); rect.setWidth ( m_rect.width() * 0.75 ); rect.setHeight( m_rect.height() * 0.75 ); rect.translate( m_rect.center().x()-rect.center().x(),m_rect.center().y()-rect.center().y() ); painter->drawEllipse( rect ); } #if 0 #ifdef _DEBUG // For each ring item child, draw the pie representing the area that it // has to draw its Graph object. QListIterator<QGraphicsItem*> i( this->childItems() ); while( i.hasNext() ) { GraphRingItem* ri = dynamic_cast<GraphRingItem*>(i.next()); if( ri ) { //! @todo The rotation to draw the GraphRingItem extents for debugging //! is off, presumably because there are other //! transformations going on. How can we account for that? //! At the moment it is accounted for with the +90 but that //! is not properly drawing all the quadrants. qreal fRotation = (-ri->getRotation()+90)*16; // Draw a center line QPen pen(Qt::DashLine); pen.setColor( QColor(128,128,128,128) ); painter->setPen( pen ); painter->drawPie(m_rect, fRotation, 0); // Draw the extents of the ring item. pen.setStyle(Qt::DotLine); painter->setPen( pen ); painter->drawPie(m_rect, fRotation-((ri->getSpan()/2)*16), ri->getSpan()*16); } } #endif // _DEBUG #endif }
symTrafo::symTrafo() { Description = QObject::tr("ideal symmetrical transformer"); QFont Font(QucsSettings.font); // default application font // symbol text is smaller (10 pt default) Font.setPointSize(10); // get the small font size; use the screen-compatible metric QFontMetrics smallmetrics(Font, 0); int w; QString stmp; Arcs.append(new Arc(-16,-58,12,12, 16*270,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc(-16,-46,12,12, 16*270,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc(-16,-34,12,12, 16*270,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc(-16, 46,12,12, 16*270,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc(-16, 34,12,12, 16*270,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc(-16, 22,12,12, 16*270,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc( 4,-18,12,12, 16*90,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc( 4, -6,12,12, 16*90,16*180, QPen(Qt::darkBlue,2))); Arcs.append(new Arc( 4, 6,12,12, 16*90,16*180, QPen(Qt::darkBlue,2))); Lines.append(new Line(-10,-58,-10,-70,QPen(Qt::darkBlue,2))); Lines.append(new Line(-10,-70,-30,-70,QPen(Qt::darkBlue,2))); Lines.append(new Line( 10,-18, 10,-30,QPen(Qt::darkBlue,2))); Lines.append(new Line( 10,-30, 30,-30,QPen(Qt::darkBlue,2))); Lines.append(new Line(-10, 58,-10, 70,QPen(Qt::darkBlue,2))); Lines.append(new Line(-10, 70,-30, 70,QPen(Qt::darkBlue,2))); Lines.append(new Line( 10, 18, 10, 30,QPen(Qt::darkBlue,2))); Lines.append(new Line( 10, 30, 30, 30,QPen(Qt::darkBlue,2))); Lines.append(new Line(-10,-10,-30,-10,QPen(Qt::darkBlue,2))); Lines.append(new Line(-10,-22,-10,-10,QPen(Qt::darkBlue,2))); Lines.append(new Line(-10, 10,-30, 10,QPen(Qt::darkBlue,2))); Lines.append(new Line(-10, 10,-10, 22,QPen(Qt::darkBlue,2))); // core lines Lines.append(new Line( -1,-57, -1, 57,QPen(Qt::darkBlue,1))); Lines.append(new Line( 1,-57, 1, 57,QPen(Qt::darkBlue,1))); stmp = "T1"; w = smallmetrics.width(stmp); // compute width to right-align Texts.append(new Text(-13-w,-57,stmp)); stmp = "T2"; w = smallmetrics.width(stmp); // compute width to right-align Texts.append(new Text(-13-w, 22,stmp)); // mark the turn direction Arcs.append(new Arc(-21,-64, 5, 5, 0, 16*360,QPen(Qt::darkBlue,2))); Arcs.append(new Arc(-21, 15, 5, 5, 0, 16*360,QPen(Qt::darkBlue,2))); Arcs.append(new Arc( 15,-24, 5, 5, 0, 16*360,QPen(Qt::darkBlue,2))); Ports.append(new Port(-30,-70)); Ports.append(new Port( 30,-30)); Ports.append(new Port( 30, 30)); Ports.append(new Port(-30, 70)); Ports.append(new Port(-30, 10)); Ports.append(new Port(-30,-10)); x1 = -33; y1 = -74; x2 = 33; y2 = 74; tx = x1+4; ty = y2+4; Model = "sTr"; Name = "Tr"; Props.append(new Property("T1", "1", true, QObject::tr("voltage transformation ratio of coil 1"))); Props.append(new Property("T2", "1", true, QObject::tr("voltage transformation ratio of coil 2"))); }
} void CometsComponent::draw( SkyPainter *skyp ) { Q_UNUSED(skyp) #ifndef KSTARS_LITE if( !selected() || Options::zoomFactor() < 10*MINZOOM ) return; bool hideLabels = ! Options::showCometNames() || (SkyMap::Instance()->isSlewing() && Options::hideLabels() ); double rsunLabelLimit = Options::maxRadCometName(); //FIXME: Should these be config'able? skyp->setPen( QPen( QColor( "darkcyan" ) ) ); skyp->setBrush( QBrush( QColor( "darkcyan" ) ) ); foreach ( SkyObject *so, m_ObjectList ) { KSComet *com = (KSComet*)so; double mag= com->mag(); if (std::isnan(mag) == 0) { bool drawn = skyp->drawPointSource(com,mag); if ( drawn && !(hideLabels || com->rsun() >= rsunLabelLimit) ) SkyLabeler::AddLabel( com, SkyLabeler::COMET_LABEL ); } } #endif }
Geometryval::Geometryval(const MltVideoProfile &profile, Timecode t, QPoint frame_size, int startPoint, QWidget* parent) : QWidget(parent), m_profile(profile), m_paramRect(NULL), m_geom(NULL), m_path(NULL), m_fixedMode(false), m_frameSize(frame_size), m_startPoint(startPoint), m_timePos(t) { setupUi(this); toolbarlayout->addWidget(&m_timePos); toolbarlayout->insertStretch(-1); QVBoxLayout* vbox = new QVBoxLayout(widget); m_sceneview = new QGraphicsView(this); m_sceneview->setBackgroundBrush(QBrush(Qt::black)); vbox->addWidget(m_sceneview); vbox->setContentsMargins(0, 0, 0, 0); QVBoxLayout* vbox2 = new QVBoxLayout(keyframeWidget); m_helper = new KeyframeHelper(this); vbox2->addWidget(m_helper); vbox2->setContentsMargins(0, 0, 0, 0); connect(m_helper, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int))); connect(m_helper, SIGNAL(keyframeMoved(int)), this, SLOT(slotKeyframeMoved(int))); connect(m_helper, SIGNAL(addKeyframe(int)), this, SLOT(slotAddFrame(int))); connect(m_helper, SIGNAL(removeKeyframe(int)), this, SLOT(slotDeleteFrame(int))); m_scene = new GraphicsSceneRectMove(this); m_scene->setTool(TITLE_SELECT); m_sceneview->setScene(m_scene); m_dar = (m_profile.height * m_profile.display_aspect_num / (double) m_profile.display_aspect_den) / (double) m_profile.width; m_realWidth = (int)(profile.height * profile.display_aspect_num / (double) profile.display_aspect_den + 0.5); QGraphicsRectItem *frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_realWidth, profile.height)); frameBorder->setZValue(-1100); frameBorder->setBrush(QColor(255, 255, 0, 30)); frameBorder->setPen(QPen(QBrush(QColor(255, 255, 255, 255)), 1.0, Qt::DashLine)); m_scene->addItem(frameBorder); buttonNext->setIcon(KIcon("media-skip-forward")); buttonNext->setToolTip(i18n("Go to next keyframe")); buttonPrevious->setIcon(KIcon("media-skip-backward")); buttonPrevious->setToolTip(i18n("Go to previous keyframe")); buttonAdd->setIcon(KIcon("document-new")); buttonAdd->setToolTip(i18n("Add keyframe")); buttonDelete->setIcon(KIcon("edit-delete")); buttonDelete->setToolTip(i18n("Delete keyframe")); m_configMenu = new QMenu(i18n("Misc..."), this); buttonMenu->setMenu(m_configMenu); buttonMenu->setPopupMode(QToolButton::MenuButtonPopup); m_editOptions = m_configMenu->addAction(KIcon("system-run"), i18n("Show/Hide options")); m_editOptions->setCheckable(true); buttonMenu->setDefaultAction(m_editOptions); connect(m_editOptions, SIGNAL(triggered()), this, SLOT(slotSwitchOptions())); slotSwitchOptions(); m_reset = m_configMenu->addAction(KIcon("view-refresh"), i18n("Reset"), this, SLOT(slotResetPosition())); m_syncAction = m_configMenu->addAction(i18n("Sync timeline cursor"), this, SLOT(slotSyncCursor())); m_syncAction->setCheckable(true); m_syncAction->setChecked(KdenliveSettings::transitionfollowcursor()); //scene->setSceneRect(0, 0, profile.width * 2, profile.height * 2); //view->fitInView(m_frameBorder, Qt::KeepAspectRatio); const double sc = 100.0 / profile.height * 0.8; QRectF srect = m_sceneview->sceneRect(); m_sceneview->setSceneRect(srect.x(), -srect.height() / 3 + 10, srect.width(), srect.height() + srect.height() / 3 * 2 - 10); m_scene->setZoom(sc); m_sceneview->centerOn(frameBorder); m_sceneview->setMouseTracking(true); connect(buttonNext , SIGNAL(clicked()) , this , SLOT(slotNextFrame())); connect(buttonPrevious , SIGNAL(clicked()) , this , SLOT(slotPreviousFrame())); connect(buttonDelete , SIGNAL(clicked()) , this , SLOT(slotDeleteFrame())); connect(buttonAdd , SIGNAL(clicked()) , this , SLOT(slotAddFrame())); connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateTransitionProperties())); buttonhcenter->setIcon(KIcon("kdenlive-align-hor")); buttonhcenter->setToolTip(i18n("Align item horizontally")); buttonvcenter->setIcon(KIcon("kdenlive-align-vert")); buttonvcenter->setToolTip(i18n("Align item vertically")); buttontop->setIcon(KIcon("kdenlive-align-top")); buttontop->setToolTip(i18n("Align item to top")); buttonbottom->setIcon(KIcon("kdenlive-align-bottom")); buttonbottom->setToolTip(i18n("Align item to bottom")); buttonright->setIcon(KIcon("kdenlive-align-right")); buttonright->setToolTip(i18n("Align item to right")); buttonleft->setIcon(KIcon("kdenlive-align-left")); buttonleft->setToolTip(i18n("Align item to left")); connect(buttonhcenter, SIGNAL(clicked()), this, SLOT(slotAlignHCenter())); connect(buttonvcenter, SIGNAL(clicked()), this, SLOT(slotAlignVCenter())); connect(buttontop, SIGNAL(clicked()), this, SLOT(slotAlignTop())); connect(buttonbottom, SIGNAL(clicked()), this, SLOT(slotAlignBottom())); connect(buttonright, SIGNAL(clicked()), this, SLOT(slotAlignRight())); connect(buttonleft, SIGNAL(clicked()), this, SLOT(slotAlignLeft())); connect(spinX, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryX(int))); connect(spinY, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryY(int))); connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryWidth(int))); connect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryHeight(int))); connect(spinResize, SIGNAL(editingFinished()), this, SLOT(slotResizeCustom())); connect(buttonResize, SIGNAL(clicked()), this, SLOT(slotResizeOriginal())); connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateGeometry())); }
void Strings::paint(QPainter *painter, bool printMode) { painter->save(); painter->setRenderHint(QPainter::Antialiasing); if(!printMode){ if(selected_){ painter->setBrush(Qt::darkBlue); painter->setPen(Qt::darkBlue); }else{ painter->setBrush(Qt::black); painter->setPen(Qt::black); } }else{ painter->setPen(Qt::lightGray); painter->setBrush(Qt::NoBrush); } painter->drawRect(0,0,size_.width(),size_.height()); //Base point QPoint base(20,25); //Rect where strings will be drawn QRect strings(base,QSize(size_.width()-base.x()-10,size_.height()-base.y()-10)); //Main Fret if(printMode){ painter->setPen(Qt::darkGray); painter->setBrush(Qt::darkGray); }else{ painter->setPen(Qt::white); painter->setBrush(Qt::white); } painter->drawRect(base.x(),base.y()-5,strings.width(),5); painter->setBrush(Qt::NoBrush); painter->drawRect(strings); QList<int> poses; int min = -1; int max = -1; //Find min and max, save poses QList<QString> fingers = fingers_.split(" ", QString::SkipEmptyParts); int nbString = fingers.size(); if(nbString<2|| nbString>12){ painter->restore(); return; } bool containEmpty = false; foreach(QString finger, fingers){ if(finger=="X"||finger=="x"){ poses.push_back(-1); continue; } bool ok; int pose = finger.toInt(&ok); if(!ok){ poses.push_back(-1); continue; }else{ poses.push_back(pose); } if(pose==0){ containEmpty = true; continue; } if(pose>max) max = pose; if(pose<min || min==-1) min = pose; } int shift = 0; if(max>5) shift = min-1; //Strings double incr_v = (double)(strings.width()) / (double)(nbString-1); for(int i=0;i<nbString;i++){ painter->drawLine(base.x()+incr_v*i,base.y(), base.x()+incr_v*i,base.y()+strings.height()); } //Frets double incr_h = (double)(strings.height()) / 5; for(int i=0;i<6;i++){ painter->drawLine(base.x(),base.y()+incr_h*i, base.x()+strings.width(),base.y()+incr_h*i); } int s = 5.0 * size_.width() / 150.0; for(int i=0;i<nbString;i++){ //Draw a cross in case of no playing string if(poses[i]<0){ if(printMode) painter->setPen(Qt::black); else painter->setPen(QPen(Qt::red,2)); painter->drawLine(base.x()+incr_v*i-s,10-s, base.x()+incr_v*i+s,10+s); painter->drawLine(base.x()+incr_v*i+s,10-s, base.x()+incr_v*i-s,10+s); continue; } int pose = poses[i]; //Draw a circle in case of empty string if(pose==0){ if(printMode) painter->setPen(Qt::black); else painter->setPen(QPen(Qt::red,2)); painter->setBrush(Qt::NoBrush); painter->drawEllipse(QPointF(base.x()+i*incr_v,10),s,s); continue; } pose -= shift; //If pose is out of the drawing if(pose>5) continue; if(printMode){ painter->setPen(Qt::black); painter->setBrush(Qt::black); }else{ painter->setPen(Qt::red); painter->setBrush(Qt::red); } painter->drawEllipse(QPointF(base.x()+i*incr_v,base.y()+pose*incr_h - (double)incr_h/2.0),s+2,s+2); } //Draw a bar if needed if(min>0 && !containEmpty){ QList<int> list; for(int i=0;i<nbString;i++){ if(poses[i]==min) list.push_back(i); } //If there are several minima, draw a bar if(list.size()>1){ if(printMode){ painter->setPen(Qt::black); painter->setBrush(Qt::black); }else{ painter->setPen(Qt::red); painter->setBrush(Qt::red); } painter->drawRect(base.x()+list.first()*incr_v, base.y()+(double)(min-shift)*incr_h-(s+2) - (double)incr_h/2.0, (double)(list.last()-list.first())*incr_v,2*s+5); } } //Print first fret QFont font = painter->font(); if(printMode){ painter->setPen(Qt::black); font.setPointSize(8); }else{ painter->setPen(Qt::white); font.setPointSize(12); } painter->setFont(font); painter->setBrush(Qt::NoBrush); painter->drawText(0,16,20,16,Qt::AlignCenter,QString::number(1+shift)); painter->restore(); }
/** Take data from image, draw text at x|y with specified parameters. If destPainter is null, draw to image, if destPainter is not null, draw directly using the painter. Returns modified area of image. */ QRect InsertTextWidget::composeImage(DImg* const image, QPainter* const destPainter, int x, int y, QFont font, float pointSize, int textRotation, QColor textColor, int alignMode, const QString& textString, bool transparentBackground, QColor backgroundColor, BorderMode borderMode, int borderWidth, int spacing) { /* The problem we have to solve is that we have no pixel access to font rendering, we have to let Qt do the drawing. On the other hand we need to support 16 bit, which cannot be done with QPixmap. The current solution cuts out the text area, lets Qt do its drawing, converts back and blits to original. */ DColorComposer* composer = DColorComposer::getComposer(DColorComposer::PorterDuffNone); int maxWidth, maxHeight; if (x == -1 && y == -1) { maxWidth = image->width(); maxHeight = image->height(); } else { maxWidth = image->width() - x; maxHeight = image->height() - y; } // find out size of the area that we are drawing to font.setPointSizeF(pointSize); QFontMetrics fontMt( font ); QRect fontRect = fontMt.boundingRect(0, 0, maxWidth, maxHeight, 0, textString); int fontWidth, fontHeight; switch (textRotation) { case ROTATION_NONE: case ROTATION_180: default: fontWidth = fontRect.width(); fontHeight = fontRect.height(); break; case ROTATION_90: case ROTATION_270: fontWidth = fontRect.height(); fontHeight = fontRect.width(); break; } // x, y == -1 means that we have to find a good initial position for the text here if (x == -1 && y == -1) { // was a valid position hint stored from last use? if (d->positionHint.isValid()) { // We assume that people tend to orient text along the edges, // so we do some guessing so that positions such as "in the lower right corner" // will be remembered across different image sizes. // get relative positions float fromTop = (float)d->positionHint.top() / 10000.0; float fromBottom = 1.0 - (float)d->positionHint.bottom() / 10000.0; float fromLeft = (float)d->positionHint.left() / 10000.0; float fromRight = 1.0 - (float)d->positionHint.right() / 10000.0; // calculate horizontal position if (fromLeft < fromRight) { x = (int)(fromLeft * maxWidth); // we are placing from the smaller distance, // so if now the larger distance is actually too small, // fall back to standard placement, nothing to lose. if (x + fontWidth > maxWidth) { x = qMax( (maxWidth - fontWidth) / 2, 0); } } else { x = maxWidth - (int)(fromRight * maxWidth) - fontWidth; if ( x < 0 ) { x = qMax( (maxWidth - fontWidth) / 2, 0); } } // calculate vertical position if (fromTop < fromBottom) { y = (int)(fromTop * maxHeight); if (y + fontHeight > maxHeight) { y = qMax( (maxHeight - fontHeight) / 2, 0); } } else { y = maxHeight - (int)(fromBottom * maxHeight) - fontHeight; if ( y < 0 ) { y = qMax( (maxHeight - fontHeight) / 2, 0); } } if (! QRect(x, y, fontWidth, fontHeight). intersects(QRect(0, 0, maxWidth, maxHeight)) ) { // emergency fallback - nothing is visible x = qMax( (maxWidth - fontWidth) / 2, 0); y = qMax( (maxHeight - fontHeight) / 2, 0); } // invalidate position hint, use only once d->positionHint = QRect(); } else { // use standard position x = qMax( (maxWidth - fontWidth) / 2, 0); y = qMax( (maxHeight - fontHeight) / 2, 0); } } // create a rectangle relative to image QRect drawRect( x, y, fontWidth + 2 * borderWidth + 2 * spacing, fontHeight + 2 * borderWidth + 2 * spacing); // create a rectangle relative to textArea, excluding the border QRect textAreaBackgroundRect( borderWidth, borderWidth, fontWidth + 2 * spacing, fontHeight + 2 * spacing); // create a rectangle relative to textArea, excluding the border and spacing QRect textAreaTextRect( borderWidth + spacing, borderWidth + spacing, fontWidth, fontHeight ); // create a rectangle relative to textArea, including the border, // for drawing the rectangle, taking into account that the width of the QPen goes in and out in equal parts QRect textAreaDrawRect( borderWidth / 2, borderWidth / 2, fontWidth + borderWidth + 2 * spacing, fontHeight + borderWidth + 2 * spacing ); // cut out the text area DImg textArea = image->copy(drawRect); if (textArea.isNull()) { return QRect(); } // compose semi-transparent background over textArea if (transparentBackground) { DImg transparentLayer(textAreaBackgroundRect.width(), textAreaBackgroundRect.height(), textArea.sixteenBit(), true); DColor transparent(backgroundColor); transparent.setAlpha(d->transparency); if (image->sixteenBit()) { transparent.convertToSixteenBit(); } transparentLayer.fill(transparent); textArea.bitBlendImage(composer, &transparentLayer, 0, 0, transparentLayer.width(), transparentLayer.height(), textAreaBackgroundRect.x(), textAreaBackgroundRect.y()); } DImg textNotDrawn; if (textArea.sixteenBit()) { textNotDrawn = textArea.copy(); textNotDrawn.convertToEightBit(); } else { textNotDrawn = textArea; } // We have no direct pixel access to font rendering, so now we need to use Qt/X11 for the drawing // convert text area to pixmap QPixmap pixmap; if (destPainter) { // We working on tool preview, deal with CM as well pixmap = d->iface->convertToPixmap(textNotDrawn); } else { // We working on target image. Do no apply double CM adjustement here. pixmap = textNotDrawn.convertToPixmap(); } // paint on pixmap QPainter p(&pixmap); p.setPen( QPen(textColor, 1) ) ; p.setFont( font ); p.save(); // translate to origin of text, leaving space for the border p.translate(textAreaTextRect.x(), textAreaTextRect.y()); switch (textRotation) { case ROTATION_NONE: p.drawText( 0, 0, textAreaTextRect.width(), textAreaTextRect.height(), alignMode, textString ); break; case ROTATION_90: p.translate(textAreaTextRect.width(), 0); p.rotate(90.0); p.drawText( 0, 0, textAreaTextRect.height(), textAreaTextRect.width(), alignMode, textString ); break; case ROTATION_180: p.translate(textAreaTextRect.width(), textAreaTextRect.height()); p.rotate(180.0); p.drawText( 0, 0, textAreaTextRect.width(), textAreaTextRect.height(), alignMode, textString ); break; case ROTATION_270: p.translate(0, textAreaTextRect.height()); p.rotate(270.0); p.drawText( 0, 0, textAreaTextRect.height(), textAreaTextRect.width(), alignMode, textString ); break; } p.restore(); // Drawing rectangle around text. if (borderMode == BORDER_NORMAL) // Decorative border using text color. { p.setPen( QPen(textColor, borderWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin) ) ; p.drawRect(textAreaDrawRect); } else if (borderMode == BORDER_SUPPORT) // Make simple dot line border to help user. { p.setPen(QPen(Qt::white, 1, Qt::SolidLine)); p.drawRect(textAreaDrawRect); p.setPen(QPen(Qt::red, 1, Qt::DotLine)); p.drawRect(textAreaDrawRect); } p.end(); if (!destPainter) { // convert to QImage, then to DImg QImage pixmapImage = pixmap.toImage(); DImg textDrawn(pixmapImage.width(), pixmapImage.height(), false, true, pixmapImage.bits()); // This does not work: during the conversion, colors are altered significantly (diffs of 1 to 10 in each component), // so we cannot find out which pixels have actually been touched. /* // Compare the result of drawing with the previous version. // Set all unchanged pixels to transparent DColor color, ncolor; uchar *ptr, *nptr; ptr = textDrawn.bits(); nptr = textNotDrawn.bits(); int bytesDepth = textDrawn.bytesDepth(); int numPixels = textDrawn.width() * textDrawn.height(); for (int i = 0; i < numPixels; ++i, ptr+= bytesDepth, nptr += bytesDepth) { color.setColor(ptr, false); ncolor.setColor(nptr, false); if ( color.red() == ncolor.red() && color.green() == ncolor.green() && color.blue() == ncolor.blue()) { color.setAlpha(0); color.setPixel(ptr); } } // convert to 16 bit if needed */ textDrawn.convertToDepthOfImage(&textArea); // now compose to original: only pixels affected by drawing text and border are changed, not whole area textArea.bitBlendImage(composer, &textDrawn, 0, 0, textDrawn.width(), textDrawn.height(), 0, 0); // copy result to original image image->bitBltImage(&textArea, drawRect.x(), drawRect.y()); } else { destPainter->drawPixmap(drawRect.x(), drawRect.y(), pixmap, 0, 0, pixmap.width(), pixmap.height()); } delete composer; return drawRect; }
void FilterCurve::paintEvent(QPaintEvent *) { int i, w, h; double v_sens, offset, h_step, rasterstep; w = width(); h = height(); QPainter painter(this); #if QT_VERSION >= 0x050000 painter.setRenderHint(QPainter::Qt4CompatiblePainting, true); #endif painter.fillRect(0, 0, w, h, BackgroundColor); if(w < 5) return; if(h < 5) return; /////////////////////////////////// draw the curve /////////////////////////////////////////// if(drawcurve_before_raster) { if(buf1 == NULL) return; if(buf2 != NULL) { if(max_value2 == min_value2) return; if(bufsize2 < 2) return; offset = (-(max_value2)); v_sens = (-(h / (max_value2 - min_value2))); h_step = (double)w / (double)(bufsize2 - 1); painter.setPen(QPen(QBrush(SignalColor2, Qt::SolidPattern), tracewidth, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin)); for(i = 0; i < (bufsize2 - 1); i++) { painter.drawLine(i * h_step, (buf2[i] + offset) * v_sens, (i + 1) * h_step, (buf2[i + 1] + offset) * v_sens); } } if(max_value1 == min_value1) return; if(bufsize1 < 2) return; offset = (-(max_value1)); v_sens = (-(h / (max_value1 - min_value1))); h_step = (double)w / (double)(bufsize1 - 1); painter.setPen(QPen(QBrush(SignalColor1, Qt::SolidPattern), tracewidth, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin)); for(i = 0; i < (bufsize1 - 1); i++) { painter.drawLine(i * h_step, (buf1[i] + offset) * v_sens, (i + 1) * h_step, (buf1[i + 1] + offset) * v_sens); } } /////////////////////////////////// draw the rasters /////////////////////////////////////////// painter.setPen(RasterColor); painter.drawRect (0, 0, w - 1, h - 1); if(h_rastersize > 1) { rasterstep = (double)w / h_rastersize; for(i = 1; i < h_rastersize; i++) { painter.drawLine(i * rasterstep, 0, i * rasterstep, h); } } if(v_rastersize > 1) { rasterstep = (double)h / v_rastersize; for(i = 1; i < v_rastersize; i++) { painter.drawLine(0, i * rasterstep, w, i * rasterstep); } } /////////////////////////////////// draw the curve /////////////////////////////////////////// if(!drawcurve_before_raster) { if(buf1 == NULL) return; if(buf2 != NULL) { if(max_value2 == min_value2) return; if(bufsize2 < 2) return; offset = (-(max_value2)); v_sens = (-(h / (max_value2 - min_value2))); h_step = (double)w / (double)(bufsize2 - 1); painter.setPen(QPen(QBrush(SignalColor2, Qt::SolidPattern), tracewidth, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin)); for(i = 0; i < (bufsize2 - 1); i++) { painter.drawLine(i * h_step, (buf2[i] + offset) * v_sens, (i + 1) * h_step, (buf2[i + 1] + offset) * v_sens); } } if(max_value1 == min_value1) return; if(bufsize1 < 2) return; offset = (-(max_value1)); v_sens = (-(h / (max_value1 - min_value1))); h_step = (double)w / (double)(bufsize1 - 1); painter.setPen(QPen(QBrush(SignalColor1, Qt::SolidPattern), tracewidth, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin)); for(i = 0; i < (bufsize1 - 1); i++) { painter.drawLine(i * h_step, (buf1[i] + offset) * v_sens, (i + 1) * h_step, (buf1[i + 1] + offset) * v_sens); } } /////////////////////////////////// draw the markers /////////////////////////////////////////// painter.setFont(QFont("Arial", 8)); if((marker_1) || (marker_2)) { painter.drawText(2, 10, "0 Hz"); } if(marker_1) { painter.drawText(2 + marker_1, 10, "F1"); } if(marker_2) { painter.drawText(1 + marker_2, 10, "F2"); } if((marker_1) || (marker_2)) { painter.setPen(SignalColor2); painter.drawText(w - 35, 10, "0 degr."); painter.drawText(w - 45, h - 2, "360 degr."); } if(marker_1) { painter.setPen(QPen(QBrush(MarkerColor, Qt::SolidPattern), 0, Qt::DotLine, Qt::SquareCap, Qt::BevelJoin)); painter.drawLine(marker_1, 0, marker_1, h); } if(marker_2) { painter.setPen(QPen(QBrush(MarkerColor, Qt::SolidPattern), 0, Qt::DotLine, Qt::SquareCap, Qt::BevelJoin)); painter.drawLine(marker_2, 0, marker_2, h); } }