const QBrush ribi::cmap::QtBrushFactory::CreateGrayGradientBrush() { QLinearGradient linearGradient(sm_left,sm_top,sm_right,sm_bottom); linearGradient.setColorAt(0.0,QColor(196,196,196)); linearGradient.setColorAt(1.0,QColor(255,255,255)); return linearGradient; }
void PrettyItemDelegate::paintActiveOverlay( QPainter *painter, qreal x, qreal y, qreal w, qreal h ) const { QPalette palette; QColor highlightColor = palette.color(QPalette::Highlight); QColor backgroundColor = palette.color(QPalette::Base); const float animation = 0.25; const int gradientRange = 16; QColor color2 = QColor::fromHsv( highlightColor.hue(), (int) (backgroundColor.saturation() * (1.0f - animation) + highlightColor.saturation() * animation), (int) (backgroundColor.value() * (1.0f - animation) + highlightColor.value() * animation) ); QColor color1 = QColor::fromHsv( color2.hue(), qMax(color2.saturation() - gradientRange, 0), qMin(color2.value() + gradientRange, 255) ); QRect rect((int) x, (int) y, (int) w, (int) h); painter->save(); painter->setPen(Qt::NoPen); QLinearGradient linearGradient(0, 0, 0, rect.height()); linearGradient.setColorAt(0.0, color1); linearGradient.setColorAt(1.0, color2); painter->setBrush(linearGradient); painter->drawRect(rect); painter->restore(); }
const QBrush ribi::cmap::QtBrushFactory::CreateYellowGradientBrush() { QLinearGradient linearGradient(sm_left,sm_top,sm_right,sm_bottom); linearGradient.setColorAt(0.0,QColor(255,255, sm_color_mid_value)); linearGradient.setColorAt(1.0,QColor(255,255,255)); return linearGradient; }
void Draw::brushChanged() { Qt::BrushStyle style = Qt::BrushStyle(brushStyleComboBox->itemData( brushStyleComboBox->currentIndex(), IdRole).toInt()); if (style == Qt::LinearGradientPattern) { QLinearGradient linearGradient(0, 0, 100, 100); linearGradient.setColorAt(0.0, Qt::white); linearGradient.setColorAt(0.2, Qt::green); linearGradient.setColorAt(1.0, Qt::black); m_renderArea->setBrush(linearGradient); } else if (style == Qt::RadialGradientPattern) { QRadialGradient radialGradient(50, 50, 50, 70, 70); radialGradient.setColorAt(0.0, Qt::white); radialGradient.setColorAt(0.2, Qt::green); radialGradient.setColorAt(1.0, Qt::black); m_renderArea->setBrush(radialGradient); } else if (style == Qt::ConicalGradientPattern) { QConicalGradient conicalGradient(50, 50, 150); conicalGradient.setColorAt(0.0, Qt::white); conicalGradient.setColorAt(0.2, Qt::green); conicalGradient.setColorAt(1.0, Qt::black); m_renderArea->setBrush(conicalGradient); } else if (style == Qt::TexturePattern) { m_renderArea->setBrush(QBrush(QPixmap(":/resources/brick.png"))); } else { m_renderArea->setBrush(QBrush(Qt::green, style)); } }
void PlaylistItemDelegate::paintActiveOverlay( QPainter *painter, const QStyleOptionViewItem& option, QRect line) const { QColor highlightColor = option.palette.color(QPalette::Highlight); QColor backgroundColor = option.palette.color(QPalette::Base); const float animation = 0.25; const int gradientRange = 16; QColor color2 = QColor::fromHsv( highlightColor.hue(), (int) (backgroundColor.saturation() * (1.0f - animation) + highlightColor.saturation() * animation), (int) (backgroundColor.value() * (1.0f - animation) + highlightColor.value() * animation) ); QColor color1 = QColor::fromHsv( color2.hue(), qMax(color2.saturation() - gradientRange, 0), qMin(color2.value() + gradientRange, 255) ); painter->save(); painter->setPen(Qt::NoPen); QLinearGradient linearGradient(0, 0, 0, line.height()); linearGradient.setColorAt(0.0, color1); linearGradient.setColorAt(1.0, color2); painter->fillRect(line, linearGradient); painter->restore(); }
void GcScopeBar::paintBackground(QPaintEvent *) { QPainter painter(this); painter.save(); QRect all(0,0,width(),height()); // fill with a linear gradient #ifdef Q_OS_MAC int shade = isActiveWindow() ? 178 : 225; #else int shade = isActiveWindow() ? 200 : 250; #endif QLinearGradient linearGradient(0, 0, 0, 23); linearGradient.setColorAt(0.0, QColor(shade,shade,shade, 100)); linearGradient.setColorAt(0.5, QColor(shade,shade,shade, 180)); linearGradient.setColorAt(1.0, QColor(shade,shade,shade, 255)); linearGradient.setSpread(QGradient::PadSpread); painter.setPen(Qt::NoPen); painter.fillRect(all, linearGradient); QPen black(QColor(100,100,100)); painter.setPen(black); painter.drawLine(0,height()-1, width()-1, height()-1); QPen gray(QColor(230,230,230)); painter.setPen(gray); painter.drawLine(0,0, width()-1, 0); painter.restore(); }
void DX11Widget::paintEvent(QPaintEvent */*e*/) { D_D(DX11Widget); int glowRadius = d->m_ShadowWidth; int radius = d->m_Radius; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QRect rect = this->rect().marginsRemoved(QMargins(glowRadius, glowRadius, glowRadius, glowRadius)); if (! d->m_Background.isNull()) { painter.drawPixmap(rect, d->m_Background); } else { QPoint topLeft(rect.x(), rect.y()); QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height()); QPainterPath border; border.addRoundedRect(rect, radius, radius); QLinearGradient linearGradient(topLeft, QPoint(topLeft.x(), bottomRight.y())); linearGradient.setColorAt(0.0, BackgroundTopColor); linearGradient.setColorAt(0.2, BackgroundBottonColor); linearGradient.setColorAt(1.0, BackgroundBottonColor); QPen borderPen(BorderColor); painter.setBrush(QBrush(linearGradient)); painter.strokePath(border, borderPen); painter.fillPath(border, palette().background()); } }
const QBrush ribi::cmap::QtBrushFactory::CreateWhiteGradientBrush() { QLinearGradient linearGradient(sm_left,sm_top,sm_right,sm_bottom); const int low_value = 250; linearGradient.setColorAt(0.0,QColor(low_value,low_value,low_value)); linearGradient.setColorAt(1.0,QColor(255,255,255)); return linearGradient; }
int KQtTester::testLinearFillRectPath() { QLinearGradient linearGradient(m_path.boundingRect().topLeft(), m_path.boundingRect().bottomRight()); linearGradient.setColorAt(0.0, Qt::white); linearGradient.setColorAt(0.2, Qt::green); linearGradient.setColorAt(1.0, Qt::black); return testFillRectPath(QBrush(linearGradient)); }
ModifyProduct::ModifyProduct(int id, QString name, QString code, QString price, QStandardItemModel** model, ViewStock* const stock) { setFixedSize(400, 200); setWindowTitle("Modifier un produit"); setWindowIcon(QIcon("pictures/app_icon.png")); setWindowFlags(Qt::WindowCloseButtonHint); QPalette* palette = new QPalette(); palette->setColor(QPalette::WindowText, Qt::white); QLinearGradient linearGradient(0, 0, 0, this->height()); linearGradient.setColorAt(0, "#090808"); linearGradient.setColorAt(1, "#242424"); palette->setBrush(QPalette::Window, *(new QBrush(linearGradient))); this->setPalette(*palette); m_mainLayout = new QVBoxLayout; m_addProductForm = new QFormLayout; m_buttonsLayout = new QHBoxLayout; m_stock = stock; m_model = *model; m_id = id; m_name = name; m_code = code; m_price = price; m_productName = new QLineEdit; m_productName->setText(m_name); m_productName->setFixedHeight(25); m_productBarCode = new QLineEdit; m_productBarCode->setText(m_code); m_productBarCode->setFixedHeight(25); m_productPrice = new QLineEdit; m_productPrice->setText(m_price); m_productPrice->setFixedHeight(25); m_validate = new QPushButton("Valider"); m_abort = new QPushButton("Annuler"); m_addProductForm->addRow("&Nom du produit : ", m_productName); m_addProductForm->addRow("&Code barre : ", m_productBarCode); m_addProductForm->addRow("&Prix : ", m_productPrice); m_buttonsLayout->addWidget(m_validate); m_buttonsLayout->addWidget(m_abort); m_buttonsLayout->setAlignment(Qt::AlignCenter); m_mainLayout->addLayout(m_addProductForm); m_mainLayout->addLayout(m_buttonsLayout); this->setLayout(m_mainLayout); connect(m_validate, SIGNAL(clicked()), this, SLOT(modify())); connect(m_abort, SIGNAL(clicked()), this, SLOT(accept())); }
void MyButton::paintWidget(int transparency, QPainter *device) { QPen pen(Qt::NoBrush, 1); device->setPen(pen); QLinearGradient linearGradient(this->rect().topLeft(), this->rect().bottomRight()); linearGradient.setColorAt(0, QColor(152, 251, 152, transparency)); QBrush brush(linearGradient); device->setBrush(brush); device->drawRoundRect(this->rect(), 2, 2); }
void MainWidget::resizeEvent(QResizeEvent *) { QLinearGradient linearGradient(10, 10, m_frmBanner->width(), m_frmBanner->height()-2); linearGradient.setColorAt(0.20, QColor(0,0,0) ); linearGradient.setColorAt(0.82, QColor(5,26,54) ); linearGradient.setColorAt(1.0, QColor(50,141,90)); QPalette palette; palette.setBrush(m_frmBanner->backgroundRole(), QBrush(linearGradient)); m_frmBanner->setPalette(palette); m_frmBanner->setAutoFillBackground(true); }
void DataTable::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { painter->drawRect(5,5,size().width(),size().height()); QLinearGradient linearGradient(QPointF(size().width()/4, -size().height()), QPointF(40, 40)); linearGradient.setColorAt(0, Qt::yellow); linearGradient.setColorAt(1, Qt::white); QPen penOutLine(Qt::black, 1); painter->setBrush(*(new QBrush(linearGradient))); painter->setPen(penOutLine); if (isSelected()) { painter->setPen(QPen(QColor(0,255,100), 2, Qt::DashLine)); } painter->drawRect(0,0,size().width(),size().height()); QPen pen(QColor(0,0,0)); painter->setPen(pen); painter->setFont(QFont(Support::fontFamilie, Support::fontSizeEssence)); qreal x = 0; qreal y = Support::getTableDeltaRow(); painter->drawText(x,y,size().width(),50,Qt::AlignHCenter,getIdWithoutPath()); y+=Support::getTableHeightRow() + Support::getTableDeltaRow(); painter->drawLine(0,y,size().width(),y); y+=Support::getTableDeltaRow(); foreach (QString key, getKeys()) { key += " - P"; if(getKeys().length() > 1) { key += ",C"; } if(key.lastIndexOf(":") != -1) { key += ",F"; } QFont font(Support::fontFamilie, Support::fontSizeProperty); font.setUnderline(true); painter->setFont(font); painter->drawText(x+5,y,size().width(),50,Qt::AlignLeft,Support::getStrippedProperty(key)); y+=Support::getTableHeightRow() + Support::getTableDeltaRow(); }
void MinifiedToolbar::paintEvent ( QPaintEvent * event ) { Q_UNUSED(event); QRectF rectangle(-15, 0, 43, 43); QPainter painter(this); QLinearGradient linearGradient(0, 0, 0, 20); linearGradient.setColorAt(0.0, QColor(180,180,180) ); linearGradient.setColorAt(0.33, Qt::gray ); linearGradient.setColorAt(1.0, QColor(120,120,120) ); painter.setPen( QColor(90, 90, 90) ); painter.setBrush(linearGradient); painter.drawRoundedRect(rectangle, 8.0, 8.0); }
AddProduct::AddProduct(QSqlDatabase db) { db.open(); setFixedSize(400, 200); setWindowTitle("Ajouter un produit"); setWindowIcon(QIcon("pictures/app_icon.png")); setWindowFlags(Qt::WindowCloseButtonHint); QPalette* palette = new QPalette(); palette->setColor(QPalette::WindowText, Qt::white); QLinearGradient linearGradient(0, 0, 0, this->height()); linearGradient.setColorAt(0, "#090808"); linearGradient.setColorAt(1, "#242424"); palette->setBrush(QPalette::Window, *(new QBrush(linearGradient))); this->setPalette(*palette); m_mainLayout = new QVBoxLayout; m_addProductForm = new QFormLayout; m_buttonsLayout = new QHBoxLayout; m_productName = new QLineEdit; m_productName->setFixedHeight(25); m_productBarCode = new QLineEdit; m_productBarCode->setFixedHeight(25); m_productPrice = new QLineEdit; m_productPrice->setFixedHeight(25); m_validate = new QPushButton("Valider"); m_abort = new QPushButton("Annuler"); m_addProductForm->addRow("&Nom du produit : ", m_productName); m_addProductForm->addRow("&Code barre : ", m_productBarCode); m_addProductForm->addRow("&Prix : ", m_productPrice); m_buttonsLayout->addWidget(m_validate); m_buttonsLayout->addWidget(m_abort); m_buttonsLayout->setAlignment(Qt::AlignCenter); m_mainLayout->addLayout(m_addProductForm); m_mainLayout->addLayout(m_buttonsLayout); this->setLayout(m_mainLayout); connect(m_validate, SIGNAL(clicked()), this, SLOT(createProduct())); connect(m_abort, SIGNAL(clicked()), this, SLOT(accept())); }
void GcBubble::paintEvent(QPaintEvent *) { // Init paint settings QPainter painter(this); // outline border, adjust to offset, for now we outline painter.setBrush(Qt::NoBrush); QColor shadow = QColor(0,0,0,alpha); QPen shadowPen(shadow); shadowPen.setWidth(lineWidth); painter.setPen(shadowPen); painter.translate(0,1); painter.drawPath(path); // now draw for real painter.translate(0,-1); // adjust to offset, for now we outline // contents fill with a linear gradient QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, QColor(80,80,80, alpha)); linearGradient.setColorAt(1.0, QColor(0, 0, 0, alpha)); linearGradient.setSpread(QGradient::PadSpread); painter.setBrush(linearGradient); // border gray and opaque QColor borderColor = QColor(150,150,150); QPen border = QPen(borderColor); border.setWidth(lineWidth); painter.setPen(border); // draw the background painter.drawPath(path); #if 0 // debugging painter.setBrush(Qt::NoBrush); painter.setPen(Qt::red); painter.drawRect(1,1,width()-2, height()-2); painter.setPen(Qt::blue); painter.drawRect(display->geometry()); #endif }
void PanelHisto::afficheRed(QPainter * painter,int size){ int heightMax = h->valeurMax(); QLinearGradient linearGradient(0, 0, 0, 255); linearGradient.setColorAt(0.2, Qt::white); linearGradient.setColorAt(1.0, "#C70208"); painter->setBrush(linearGradient); painter->setOpacity(0.8); QPolygon polygonCourbe; polygonCourbe << QPoint(0,255); for (int i = 0; i < 256; i++) { polygonCourbe << QPoint(0.5+i,size-(uint)((float)h->tab[i][1] * size / heightMax + 0.5)); } polygonCourbe << QPoint(255, 255); painter->drawPolygon(polygonCourbe); }
QRect DBarChartWidget::drawGraphicArea(QPainter &painter, QRect rect, const QString title, const QList<double> points) { double margin = rect.x(); double widgetSeparator1 = 5; double widgetSeparator2 = 25; double graphAreaWidth = width() - (rect.x() * 2); double graphAreaHeight = (height() - 50 - (6 * 10) - ((widgetSeparator1 * 3) + (widgetSeparator2 * 3))) / 3; double stepSeparator = graphAreaWidth / 60; //57 painter.setPen(QPen(Qt::blue, 2)); rect = drawWrapText(painter, QRect(margin, rect.y(), 0, 0), title); painter.setPen(QPen(Qt::black, 1)); rect = QRect(margin, rect.height() + rect.y() + widgetSeparator1, graphAreaWidth, graphAreaHeight); QLinearGradient linearGradient(QPointF(graphAreaWidth / 2, rect.y()), QPointF(graphAreaWidth / 2, rect.y() + rect.height())); linearGradient.setColorAt(0, Qt::red); linearGradient.setColorAt(0.5, Qt::yellow); linearGradient.setColorAt(1, Qt::green); linearGradient.setSpread(QGradient::PadSpread); QBrush brush(linearGradient); painter.drawRect(rect); painter.fillRect(rect, brush); // brush.setStyle(Qt::CrossPattern); // painter.fillRect(rect, brush); painter.setPen(QPen(Qt::blue, 2)); double maximun = 0; double minimun = 0; for (int step = 0; step < points.count(); step++) { if (maximun < points.at(step)) maximun = points.at(step); else minimun = points.at(step); } for (int step = 1; step < points.count(); step++) painter.drawLine(QPointF(rect.left() + ((step - 1) * stepSeparator), calculateYPosition(rect.height(), points.at(step - 1), maximun) + rect.y()) , QPointF(rect.left() + (step * stepSeparator), calculateYPosition(rect.height(), points.at(step), maximun) + rect.y())); rect = drawWrapText(painter, QRect(rect.left(), rect.y() + rect.height() + 10, 0, 0), tr("Current: %1").arg((points.count() == 0 ? 0 : points.last()))); rect = drawWrapText(painter, rect, tr("Max: %1").arg(maximun)); rect = drawWrapText(painter, rect, tr("Min: %1").arg(minimun)); return QRect(margin, rect.y() + rect.height() + widgetSeparator1 + widgetSeparator2, graphAreaWidth, graphAreaHeight); }
void ScreenWidget::paintEvent(QPaintEvent *e) { QPainter paint(this); paint.setRenderHint(QPainter::Antialiasing,true); QLinearGradient linearGradient(rect().width(),rect().height(),0,0); linearGradient.setSpread(QGradient::RepeatSpread); linearGradient.setColorAt(0.0, Qt::lightGray); linearGradient.setColorAt(0.2, Qt::lightGray); linearGradient.setColorAt(0.8, Qt::lightGray); linearGradient.setColorAt(1.0, Qt::lightGray); paint.setBrush(QBrush(linearGradient)); paint.drawRect(rect()); // if(!m_curMode) // { // return; // } // if(!m_isSelected) // { // linearGradient.setSpread(QGradient::RepeatSpread); // linearGradient.setColorAt(0.0, Qt::lightGray); // linearGradient.setColorAt(0.2, Qt::lightGray); // linearGradient.setColorAt(0.8, Qt::lightGray); // linearGradient.setColorAt(1.0, Qt::lightGray); // paint.setBrush(QBrush(linearGradient)); // paint.drawRect(rect()); // }else{ // linearGradient.setSpread(QGradient::RepeatSpread); // linearGradient.setColorAt(0.0, QColor(77,197,244)); // linearGradient.setColorAt(0.2, QColor(77,197,244)); // linearGradient.setColorAt(0.8, QColor(77,197,244)); // linearGradient.setColorAt(1.0, QColor(77,197,244)); // paint.setBrush(QBrush(linearGradient)); // paint.drawRect(rect()); // } }
void CpintPlot::calculate(RideItem *rideItem) { if (!rideItem) return; QString fileName = rideItem->fileName; QDateTime dateTime = rideItem->dateTime; QDir dir(path); QFileInfo file(fileName); // get current ride statistics current = new RideFileCache(mainWindow, mainWindow->home.absolutePath() + "/" + fileName); // get aggregates - incase not initialised from date change if (bests == NULL) bests = new RideFileCache(mainWindow, startDate, endDate, isFiltered, files); // // PLOT MODEL CURVE (DERIVED) // curveTitle.setLabel(QwtText("", QwtText::PlainText)); // default to no title if (series == RideFile::xPower || series == RideFile::NP || series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) { if (bests->meanMaxArray(series).size() > 1) { // calculate CP model from all-time best data cp = tau = t0 = 0; deriveCPParameters(); } // // CP curve only relevant for Energy or Watts (?) // if (series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) { if (!CPCurve) plot_CP_curve(this, cp, tau, t0); else { // make sure color reflects latest config QPen pen(GColor(CCP)); pen.setWidth(2.0); pen.setStyle(Qt::DashLine); CPCurve->setPen(pen); } } // // PLOT ZONE (RAINBOW) AGGREGATED CURVE // if (bests->meanMaxArray(series).size()) { int maxNonZero = 0; for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) { if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i; } plot_allCurve(this, maxNonZero, bests->meanMaxArray(series).constData() + 1); } } else { // // PLOT BESTS IN SERIES COLOR // if (allCurve) { delete allCurve; allCurve = NULL; } if (bests->meanMaxArray(series).size()) { int maxNonZero = 0; QVector<double> timeArray(bests->meanMaxArray(series).size()); for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) { timeArray[i] = i / 60.0; if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i; } if (maxNonZero > 1) { allCurve = new QwtPlotCurve(dateTime.toString(tr("ddd MMM d, yyyy h:mm AP"))); allCurve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen line; QColor fill; switch (series) { case RideFile::kph: line.setColor(GColor(CSPEED).darker(200)); fill = (GColor(CSPEED)); break; case RideFile::cad: line.setColor(GColor(CCADENCE).darker(200)); fill = (GColor(CCADENCE)); break; case RideFile::nm: line.setColor(GColor(CTORQUE).darker(200)); fill = (GColor(CTORQUE)); break; case RideFile::hr: line.setColor(GColor(CHEARTRATE).darker(200)); fill = (GColor(CHEARTRATE)); break; case RideFile::vam: line.setColor(GColor(CALTITUDE).darker(200)); fill = (GColor(CALTITUDE)); break; default: case RideFile::watts: // won't ever get here case RideFile::NP: case RideFile::xPower: line.setColor(GColor(CPOWER).darker(200)); fill = (GColor(CPOWER)); break; } // wow, QVector really doesn't have a max/min method! double ymax = 0; double ymin = 100000; foreach(double v, current->meanMaxArray(series)) { if (v > ymax) ymax = v; if (v && v < ymin) ymin = v; } foreach(double v, bests->meanMaxArray(series)) { if (v > ymax) ymax = v; if (v&& v < ymin) ymin = v; } if (ymin == 100000) ymin = 0; // VAM is a bit special if (series == RideFile::vam) { if (bests->meanMaxArray(series).size() > 300) ymax = bests->meanMaxArray(series)[300]; else ymax = 2000; } ymax *= 1.1; // bit of headroom ymin *= 0.9; // xmax is directly related to the size of the arrays double xmax = current->meanMaxArray(series).size(); if (bests->meanMaxArray(series).size() > xmax) xmax = bests->meanMaxArray(series).size(); xmax /= 60; // its in minutes not seconds setAxisScale(yLeft, ymin, ymax); if (series == RideFile::vam) setAxisScale(xBottom, 4.993, xmax); else setAxisScale(xBottom, 0.017, xmax); allCurve->setPen(line); fill.setAlpha(64); // use a linear gradient fill.setAlpha(240); QColor fill1 = fill; fill1.setAlpha(40); QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, fill); linearGradient.setColorAt(1.0, fill1); linearGradient.setSpread(QGradient::PadSpread); allCurve->setBrush(linearGradient); allCurve->attach(this); allCurve->setData(timeArray.data() + 1, bests->meanMaxArray(series).constData() + 1, maxNonZero - 1); } }
void CpintPlot::plot_allCurve(CpintPlot *thisPlot, int n_values, const double *power_values) { clear_CP_Curves(); QVector<double> energyBests(n_values); QVector<double> time_values(n_values); // generate an array of time values for (int t = 0; t < n_values; t++) { time_values[t] = (t + 1) / 60.0; energyBests[t] = power_values[t] * time_values[t] * 60.0 / 1000.0; } // generate zones from derived CP value if (cp > 0) { QList <int> power_zone; int n_zones = zones->lowsFromCP(&power_zone, (int) int(cp)); int high = n_values - 1; int zone = 0; while (zone < n_zones && high > 0) { int low = high - 1; int nextZone = zone + 1; if (nextZone >= power_zone.size()) low = 0; else { while ((low > 0) && (power_values[low] < power_zone[nextZone])) --low; } QColor color = zoneColor(zone, n_zones); QString name = zones->getDefaultZoneName(zone); QwtPlotCurve *curve = new QwtPlotCurve(name); if (appsettings->value(this, GC_ANTIALIAS, false).toBool() == true) curve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen pen(color.darker(200)); pen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble()); curve->setPen(pen); curve->attach(thisPlot); // use a linear gradient color.setAlpha(180); QColor color1 = color; color1.setAlpha(64); QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, color); linearGradient.setColorAt(1.0, color1); linearGradient.setSpread(QGradient::PadSpread); curve->setBrush(linearGradient); // fill below the line if (series == RideFile::none) { // this is Energy mode curve->setData(time_values.data() + low, energyBests.data() + low, high - low + 1); } else { curve->setData(time_values.data() + low, power_values + low, high - low + 1); } allCurves.append(curve); if (series != RideFile::none || energyBests[high] > 100.0) { QwtText text(name); text.setFont(QFont("Helvetica", 20, QFont::Bold)); color.setAlpha(255); text.setColor(color); QwtPlotMarker *label_mark = new QwtPlotMarker(); // place the text in the geometric mean in time, at a decent power double x, y; if (series == RideFile::none) { x = (time_values[low] + time_values[high]) / 2; y = (energyBests[low] + energyBests[high]) / 5; } else { x = sqrt(time_values[low] * time_values[high]); y = (power_values[low] + power_values[high]) / 5; } label_mark->setValue(x, y); label_mark->setLabel(text); label_mark->attach(thisPlot); allZoneLabels.append(label_mark); } high = low; ++zone; } } // no zones available: just plot the curve without zones else { QwtPlotCurve *curve = new QwtPlotCurve(tr("maximal power")); if (appsettings->value(this, GC_ANTIALIAS, false).toBool() == true) curve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen pen(GColor(CCP)); pen.setWidth(appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble()); curve->setPen(pen); QColor brush_color = GColor(CCP); brush_color.setAlpha(200); curve->setBrush(brush_color); // brush fills below the line if (series == RideFile::none) curve->setData(time_values.data(), energyBests.data(), n_values); else curve->setData(time_values.data(), power_values, n_values); curve->attach(thisPlot); allCurves.append(curve); } // Energy mode is really only interesting in the range where energy is // linear in interval duration--up to about 1 hour. double xmax = (series == RideFile::none) ? 60.0 : time_values[n_values - 1]; if (series == RideFile::vam) thisPlot->setAxisScale(thisPlot->xBottom, (double) 4.993, (double)xmax); else thisPlot->setAxisScale(thisPlot->xBottom, (double) 0.017, (double)xmax); double ymax; if (series == RideFile::none) { int i = std::lower_bound(time_values.begin(), time_values.end(), 60.0) - time_values.begin(); ymax = 10 * ceil(energyBests[i] / 10); } else { ymax = 100 * ceil(power_values[0] / 100); if (ymax == 100) ymax = 5 * ceil(power_values[0] / 5); } thisPlot->setAxisScale(thisPlot->yLeft, 0, ymax); }
ChatWindow::ChatWindow(QListWidgetItem *item, MainWindow *parent): QMainWindow(parent), username(CommonElements::getInstance()->getUsername()), item(item), friendName(item->text().left(item->text().size() - 4)), friendHead(new QLabel(this)), friendnameLabel(new QLabel(this)), messageEdit(new QTextEdit(this)), sendEdit(new QTextEdit(this)), sendButton(new QPushButton(this)), picButton(new QPushButton(this)), expressButton(new QPushButton(this)), filButton(new QPushButton(this)), closeButton(new CloseButton(this)), minButton(new MiniumButton(this)), trueImage(new QCheckBox(this)), manager(0), recmanager(0), filemanager(0), dmanager(0), pressed(false), expDialog(0) { this->setWindowFlags(Qt::FramelessWindowHint/* | Qt::Tool*/ | Qt::X11BypassWindowManagerHint); this->setMinimumSize(800, 600); this->setMaximumSize(800, 600); QLinearGradient linearGradient(QPoint(0, 0), QPoint(0, 600)); linearGradient.setColorAt(0, QColor(133, 218, 223)); linearGradient.setColorAt(1, QColor(255, 255, 255)); QPalette palette; palette.setBrush(QPalette::Background, QBrush(linearGradient)); this->setPalette(palette); QFont font; font.setPointSize(16); this->setWindowTitle(this->friendName); this->sendButton->setText("发送"); this->trueImage->setText("显示原图"); this->trueImage->setChecked(false); this->messageEdit->setReadOnly(true); this->friendHead->setGeometry(60, 32, 48, 48); this->friendnameLabel->setGeometry(120,32, 200, 48); this->messageEdit->setGeometry(50, 85, 700, 285); this->sendEdit->setGeometry(50, 420, 700, 120); this->sendButton->setGeometry(710, 550, 60, 30); this->picButton->setGeometry(90, 380, 30, 30); this->expressButton->setGeometry(50, 380, 30, 30); this->filButton->setGeometry(130, 380, 30, 30); this->closeButton->setGeometry(770, 0, 30, 30); this->minButton->setGeometry(740, 0, 30, 30); this->trueImage->setGeometry(170, 380, 80, 30); QImage head(":/images/photo"); head.scaled(48, 48, Qt::KeepAspectRatio); this->friendHead->setScaledContents(true); this->friendHead->setPixmap(QPixmap::fromImage(head)); this->friendnameLabel->setText(this->friendName); this->friendnameLabel->setFont(font); font.setPointSize(10); this->messageEdit->setFont(font); this->expressButton->setStyleSheet("QPushButton{border-image:url(:/images/expression);}" "QPushButton:hover{border-image:url(:/images/expression_1);}" "QPushButton:pressed{border-image:url(:/images/expression_2);}"); this->picButton->setStyleSheet("QPushButton{border-image:url(:/images/pic_0);}" "QPushButton:hover{border-image:url(:/images/pic_1);}" "QPushButton:pressed{border-image:url(:/images/pic_2);}"); this->filButton->setStyleSheet("QPushButton{border-image:url(:/images/file);}" "QPushButton:hover{border-image:url(:/images/file_1);}" "QPushButton:pressed{border-image:url(:/images/file_2);}"); connect(this->sendButton, SIGNAL(clicked()), this, SLOT(on_sendButton_clicked())); connect(this->picButton, SIGNAL(clicked()), this, SLOT(on_picButton_clicked())); connect(this->closeButton, SIGNAL(clicked()), this, SLOT(on_closeButton_clicked())); connect(this->minButton, SIGNAL(clicked()), this, SLOT(on_minButton_clicked())); connect(this->expressButton, SIGNAL(clicked()), this, SLOT(on_expressButton_clicked())); connect(this->filButton, SIGNAL(clicked()), this, SLOT(on_filButton_clicked())); expMap.insert("huaji", "(#滑稽)"); expMap.insert("dahan", "(#大汗)"); expMap.insert("fennu", "(#愤怒)"); expMap.insert("guaiqiao", "(#乖巧)"); expMap.insert("hecha", "(#喝茶)"); expMap.insert("kaixin", "(#开心)"); expMap.insert("penshui", "(#喷水)"); expMap.insert("weixiao", "(#微笑)"); expMap.insert("yinxian", "(#阴险)"); dPath = QDir::currentPath() + "/headImages/head_" + this->friendName + ".png"; updateFriendHead(); Database *db = Database::getInstance(""); db->loadMessage(this, this->friendName); }
void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); //绘制线条 painter.drawLine(QPoint(0, 0), QPoint(100, 100)); //创建画笔 QPen pen(Qt::green, 5, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin); //使用画笔 painter.setPen(pen); QRectF rectangle(70.0, 40.0, 80.0, 60.0); int startAngle = 30 * 16; int spanAngle = 120 * 16; //绘制圆弧 painter.drawArc(rectangle, startAngle, spanAngle); //重新设置画笔 pen.setWidth(1); pen.setStyle(Qt::SolidLine); painter.setPen(pen); //绘制一个矩形 painter.drawRect(160, 20, 50, 40); //创建画刷 QBrush brush(QColor(0, 0, 255), Qt::Dense4Pattern); //使用画刷 painter.setBrush(brush); //绘制椭圆 painter.drawEllipse(220, 20, 50, 50); //设置纹理 brush.setTexture(QPixmap("../myDrawing/yafeilinux.png")); //重新使用画刷 painter.setBrush(brush); //定义四个点 static const QPointF points[4] = { QPointF(270.0, 80.0), QPointF(290.0, 10.0), QPointF(350.0, 30.0), QPointF(390.0, 70.0) }; //使用四个点绘制多边形 painter.drawPolygon(points, 4); //使用画刷填充一个矩形区域 painter.fillRect(QRect(10, 100, 150, 20), QBrush(Qt::darkYellow)); //擦除一个矩形区域的内容 painter.eraseRect(QRect(50, 0, 50, 120)); //线性渐变 QLinearGradient linearGradient(QPointF(40, 190), QPointF(70, 190)); //插入颜色 linearGradient.setColorAt(0, Qt::yellow); linearGradient.setColorAt(0.5, Qt::red); linearGradient.setColorAt(1, Qt::green); //指定渐变区域以外的区域的扩散方式 linearGradient.setSpread(QGradient::RepeatSpread); //使用渐变作为画刷 painter.setBrush(linearGradient); painter.drawRect(10, 170, 90, 40); //辐射渐变 QRadialGradient radialGradient(QPointF(200, 190), 50, QPointF(275, 200)); radialGradient.setColorAt(0, QColor(255, 255, 100, 150)); radialGradient.setColorAt(1, QColor(0, 0, 0, 50)); painter.setBrush(radialGradient); painter.drawEllipse(QPointF(200, 190), 50, 50); //锥形渐变 QConicalGradient conicalGradient(QPointF(350, 190), 60); conicalGradient.setColorAt(0.2, Qt::cyan); conicalGradient.setColorAt(0.9, Qt::black); painter.setBrush(conicalGradient); painter.drawEllipse(QPointF(350, 190), 50, 50); //画笔使用线性渐变来绘制直线和文字 painter.setPen(QPen(linearGradient,2)); painter.drawLine(0, 280, 100, 280); painter.drawText(150, 280, tr("helloQt!")); }
void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); /* 1. 绘制线条 */ painter.drawLine(QPoint(0, 0), QPoint(100, 100)); /* 创建画笔 */ /* 画刷 线宽 画笔风格 画笔端点风格 画笔连接风格 */ QPen pen(Qt::green, 5, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin); //使用画笔 painter.setPen(pen); QRectF rectangle(70.0, 40.0, 80.0, 60.0); int startAngle = 30 * 16; /* 实际角度值 x 16*/ int spanAngle = 120 * 16; /* 2. 绘制圆弧 */ painter.drawArc(rectangle, startAngle, spanAngle); //重新设置画笔 pen.setWidth(1); pen.setStyle(Qt::SolidLine); painter.setPen(pen); /* 3. 绘制一个矩形 */ painter.drawRect(160, 20, 50, 40); //重新设置画笔 pen.setColor(QColor(255,0,0)); painter.setPen(pen); //创建画刷 QBrush brush(QColor(0, 0, 255), Qt::Dense4Pattern); //使用画刷 painter.setBrush(brush); /* 4. 绘制椭圆 */ painter.drawEllipse(220, 20, 60, 40); //设置纹理 brush.setTexture(QPixmap("../myDrawing/yafeilinux.png")); //重新使用画刷 painter.setBrush(brush); //定义四个点 static const QPointF points[4] = { QPointF(270.0, 80.0), QPointF(290.0, 10.0), QPointF(350.0, 30.0), QPointF(390.0, 70.0) }; /* 5. 使用四个点绘制多边形 */ painter.drawPolygon(points, 4); /* 6 使用画刷填充一个矩形区域 */ painter.fillRect(QRect(10, 100, 150, 20), QBrush(Qt::darkYellow)); //擦除一个矩形区域的内容 painter.eraseRect(QRect(50, 0, 50, 120)); /*线性渐变*/ QLinearGradient linearGradient(QPointF(40, 190), QPointF(70, 190)); // 线性渐变 /*插入颜色*/ linearGradient.setColorAt(0, Qt::yellow); linearGradient.setColorAt(0.5, Qt::red); linearGradient.setColorAt(1, Qt::green); /*指定渐变区域以外的区域的扩散方式*/ linearGradient.setSpread(QGradient::RepeatSpread); // 重复渐变 // linearGradient.setSpread(QGradient::PadSpread); // 使用最近使用的颜色进行填充 默认值 // linearGradient.setSpread(QGradient::ReflectSpread); // 反射渐变 /*使用渐变作为画刷*/ painter.setBrush(linearGradient); /* 7 绘制线性渐变*/ painter.drawRect(10, 170, 90, 40); /* 8 辐射渐变*/ QRadialGradient radialGradient(QPointF(200, 190), 50, QPointF(275, 200)); radialGradient.setColorAt(0, QColor(255, 255, 100, 150)); radialGradient.setColorAt(1, QColor(0, 0, 0, 50)); painter.setBrush(radialGradient); painter.drawEllipse(QPointF(200, 190), 50, 50); /* 9 锥形渐变 */ QConicalGradient conicalGradient(QPointF(350, 190), 60); conicalGradient.setColorAt(0.2, Qt::cyan); conicalGradient.setColorAt(0.5, Qt::blue); conicalGradient.setColorAt(0.9, Qt::black); painter.setBrush(conicalGradient); painter.drawEllipse(QPointF(350, 190), 50, 50); /* 10 画笔使用线性渐变来绘制直线和文字 */ painter.setPen(QPen(linearGradient,2)); painter.drawLine(0, 280, 100, 280); painter.drawText(150, 280, tr("helloQt!")); }
void PowerHist::configChanged() { // plot background setCanvasBackground(GColor(CPLOTBACKGROUND)); // curve QPen pen; QColor brush_color; if (source == Metric) { pen.setColor(metricColor.darker(200)); brush_color = metricColor; } else { switch (series) { case RideFile::watts: case RideFile::aPower: case RideFile::wattsKg: pen.setColor(GColor(CPOWER).darker(200)); brush_color = GColor(CPOWER); break; case RideFile::nm: pen.setColor(GColor(CTORQUE).darker(200)); brush_color = GColor(CTORQUE); break; case RideFile::kph: pen.setColor(GColor(CSPEED).darker(200)); brush_color = GColor(CSPEED); break; case RideFile::cad: pen.setColor(GColor(CCADENCE).darker(200)); brush_color = GColor(CCADENCE); break; default: case RideFile::hr: pen.setColor(GColor(CHEARTRATE).darker(200)); brush_color = GColor(CHEARTRATE); break; } } double width = appsettings->value(this, GC_LINEWIDTH, 2.0).toDouble(); if (appsettings->value(this, GC_ANTIALIAS, false).toBool()==true) { curve->setRenderHint(QwtPlotItem::RenderAntialiased); curveSelected->setRenderHint(QwtPlotItem::RenderAntialiased); } // use a linear gradient brush_color.setAlpha(64); QColor brush_color1 = brush_color.darker(); QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, brush_color); linearGradient.setColorAt(1.0, brush_color1); linearGradient.setSpread(QGradient::PadSpread); curve->setBrush(linearGradient); // fill below the line if (zoned == false || (zoned == true && (series != RideFile::watts && series != RideFile::wattsKg && series != RideFile::hr))) { pen.setWidth(width); curve->setPen(pen); } else { pen.setWidth(width); curve->setPen(Qt::NoPen); } // intervalselection QPen ivl(GColor(CINTERVALHIGHLIGHTER).darker(200)); ivl.setWidth(width); curveSelected->setPen(ivl); QColor ivlbrush = GColor(CINTERVALHIGHLIGHTER); ivlbrush.setAlpha(64); curveSelected->setBrush(ivlbrush); // fill below the line // grid QPen gridPen(GColor(CPLOTGRID)); //gridPen.setStyle(Qt::DotLine); grid->setPen(gridPen); }
ribi::cmap::QtConceptMap::QtConceptMap(QWidget* parent) : QtKeyboardFriendlyGraphicsView(parent), m_arrow{new QtNewArrow}, m_conceptmap{}, m_examples_item(new QtExamplesItem), m_highlighter{new QtItemHighlighter}, m_mode{Mode::uninitialized}, m_tools{new QtTool} { #ifndef NDEBUG this->SetVerbosity(false); #endif this->setScene(new QGraphicsScene(this)); assert(!m_highlighter->GetItem()); //Add QtNewArrow assert(!m_arrow->scene()); scene()->addItem(m_arrow); //Add the QtNewArrow so it has a parent assert(m_arrow->scene()); m_arrow->hide(); assert(!m_arrow->isVisible()); //Add QtExamplesItem assert(!m_examples_item->scene()); scene()->addItem(m_examples_item); //Add the examples so it has a parent assert(m_examples_item->scene()); //Add QtTool assert(!m_tools->scene()); this->scene()->addItem(m_tools); assert(m_tools->scene()); //Responds when selectionChanged is triggered assert(Collect<QtNode>(scene()).empty()); //Without this line, mouseMoveEvent won't be called this->setMouseTracking(true); { assert(this->scene()); QLinearGradient linearGradient(-500,-500,500,500); linearGradient.setColorAt(0.0,QColor(214,214,214)); linearGradient.setColorAt(1.0,QColor(255,255,255)); this->scene()->setBackgroundBrush(linearGradient); //this->scene()->setBackgroundBrush(QBrush(QColor(255,255,255))); } //Connect the scene #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) QObject::connect(scene(),SIGNAL(focusItemChanged(QGraphicsItem*,QGraphicsItem*,Qt::FocusReason)),this,SLOT(onFocusItemChanged(QGraphicsItem*,QGraphicsItem*,Qt::FocusReason))); #else #endif QObject::connect(scene(),SIGNAL(selectionChanged()),this,SLOT(onSelectionChanged())); m_examples_item->SetCenterPos(123,456); //Irrelevant where CheckInvariants(); { QTimer * const timer{new QTimer(this)}; QObject::connect(timer, SIGNAL(timeout()), this, SLOT(onCheckCollision())); timer->start(10); } }
void KCapacityBar::drawCapacityBar(QPainter *p, const QRect &rect) const { if (d->ce_capacityBar) { QStyleOptionProgressBar opt; opt.initFrom(this); opt.rect = rect; opt.minimum = 0; opt.maximum = 100; opt.progress = d->value; opt.text = d->text; opt.textAlignment = Qt::AlignCenter; opt.textVisible = true; style()->drawControl(d->ce_capacityBar, &opt, p, this); return; } p->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); p->save(); QRect drawRect(rect); if (d->drawTextMode == DrawTextOutline) { drawRect.setHeight(d->barHeight); } QPainterPath outline; outline.moveTo(rect.left() + ROUND_MARGIN / 4 + 1, rect.top()); outline.lineTo(rect.left() + drawRect.width() - ROUND_MARGIN / 4 - 1, rect.top()); outline.quadTo(rect.left() + drawRect.width() + ROUND_MARGIN / 2, drawRect.height() / 2 + rect.top(), rect.left() + drawRect.width() - ROUND_MARGIN / 4 - 1, drawRect.height() + rect.top()); outline.lineTo(rect.left() + ROUND_MARGIN / 4 + 1, drawRect.height() + rect.top()); outline.quadTo(-ROUND_MARGIN / 2 + rect.left(), drawRect.height() / 2 + rect.top(), rect.left() + ROUND_MARGIN / 4 + 1, rect.top()); const QColor fillColor = palette().window().color().darker(DarkShade); p->fillPath(outline, QColor(fillColor.red(), fillColor.green(), fillColor.blue(), 50)); QRadialGradient bottomGradient(QPointF(rect.width() / 2, drawRect.bottom() + 1), rect.width() / 2); bottomGradient.setColorAt(0, palette().window().color().darker(LightShade)); bottomGradient.setColorAt(1, Qt::transparent); p->fillRect(QRect(rect.left(), drawRect.bottom() + rect.top(), rect.width(), 1), bottomGradient); p->translate(rect.left() + 2, rect.top() + 1); drawRect.setWidth(drawRect.width() - 4); drawRect.setHeight(drawRect.height() - 2); QPainterPath path; path.moveTo(ROUND_MARGIN / 4, 0); path.lineTo(drawRect.width() - ROUND_MARGIN / 4, 0); path.quadTo(drawRect.width() + ROUND_MARGIN / 2, drawRect.height() / 2, drawRect.width() - ROUND_MARGIN / 4, drawRect.height()); path.lineTo(ROUND_MARGIN / 4, drawRect.height()); path.quadTo(-ROUND_MARGIN / 2, drawRect.height() / 2, ROUND_MARGIN / 4, 0); QLinearGradient linearGradient(0, 0, 0, drawRect.height()); linearGradient.setColorAt(0.5, palette().window().color().darker(MidShade)); linearGradient.setColorAt(1, palette().window().color().darker(LightShade)); p->fillPath(path, linearGradient); p->setBrush(Qt::NoBrush); p->setPen(Qt::NoPen); if (d->continuous || !d->fillFullBlocks) { int start = (layoutDirection() == Qt::LeftToRight) ? -1 : (drawRect.width() + 2) - (drawRect.width() + 2) * (d->value / 100.0); p->setClipRect(QRect(start, 0, (drawRect.width() + 2) * (d->value / 100.0), drawRect.height()), Qt::IntersectClip); } int left = (layoutDirection() == Qt::LeftToRight) ? 0 : drawRect.width(); int right = (layoutDirection() == Qt::LeftToRight) ? drawRect.width() : 0; int roundMargin = (layoutDirection() == Qt::LeftToRight) ? ROUND_MARGIN : -ROUND_MARGIN; int spacing = 2; int verticalSpacing = VERTICAL_SPACING; int slotWidth = 6; int start = roundMargin / 4; QPainterPath internalBar; internalBar.moveTo(left + roundMargin / 4, 0); internalBar.lineTo(right - roundMargin / 4, 0); internalBar.quadTo(right + roundMargin / 2, drawRect.height() / 2, right - roundMargin / 4, drawRect.height()); internalBar.lineTo(left + roundMargin / 4, drawRect.height()); internalBar.quadTo(left - roundMargin / 2, drawRect.height() / 2, left + roundMargin / 4, 0); QLinearGradient fillInternalBar(left, 0, right, 0); fillInternalBar.setColorAt(0, palette().window().color().darker(MidShade)); fillInternalBar.setColorAt(0.5, palette().window().color().darker(LightShade)); fillInternalBar.setColorAt(1, palette().window().color().darker(MidShade)); if (d->drawTextMode == KCapacityBar::DrawTextInline) { p->save(); p->setOpacity(p->opacity() * 0.7); } if (!d->continuous) { int numSlots = (drawRect.width() - ROUND_MARGIN - ((slotWidth + spacing) * 2)) / (slotWidth + spacing); int stopSlot = floor((numSlots + 2) * (d->value / 100.0)); int plusOffset = d->fillFullBlocks ? ((drawRect.width() - ROUND_MARGIN - ((slotWidth + spacing) * 2)) - (numSlots * (slotWidth + spacing))) / 2.0 : 0; if (!d->fillFullBlocks || stopSlot) { QPainterPath firstSlot; firstSlot.moveTo(left + roundMargin / 4, verticalSpacing); firstSlot.lineTo(left + slotWidth + roundMargin / 4 + plusOffset, verticalSpacing); firstSlot.lineTo(left + slotWidth + roundMargin / 4 + plusOffset, drawRect.height() - verticalSpacing); firstSlot.lineTo(left + roundMargin / 4, drawRect.height() - verticalSpacing); firstSlot.quadTo(left, drawRect.height() / 2, left + roundMargin / 4, verticalSpacing); p->fillPath(firstSlot, fillInternalBar); start += slotWidth + spacing + plusOffset; bool stopped = false; for (int i = 0; i < numSlots + 1; i++) { if (d->fillFullBlocks && (i == (stopSlot + 1))) { stopped = true; break; } p->fillRect(QRect(rect.left() + start, rect.top() + verticalSpacing, slotWidth, drawRect.height() - verticalSpacing * 2), fillInternalBar); start += slotWidth + spacing; } if (!d->fillFullBlocks || (!stopped && (stopSlot != (numSlots + 1)) && (stopSlot != numSlots))) { QPainterPath lastSlot; lastSlot.moveTo(start, verticalSpacing); lastSlot.lineTo(start, drawRect.height() - verticalSpacing); lastSlot.lineTo(start + slotWidth + plusOffset, drawRect.height() - verticalSpacing); lastSlot.quadTo(start + roundMargin, drawRect.height() / 2, start + slotWidth + plusOffset, verticalSpacing); lastSlot.lineTo(start, verticalSpacing); p->fillPath(lastSlot, fillInternalBar); } } } else { p->fillPath(internalBar, fillInternalBar); } if (d->drawTextMode == KCapacityBar::DrawTextInline) { p->restore(); } p->save(); p->setClipping(false); QRadialGradient topGradient(QPointF(rect.width() / 2, drawRect.top()), rect.width() / 2); const QColor fillTopColor = palette().window().color().darker(LightShade); topGradient.setColorAt(0, QColor(fillTopColor.red(), fillTopColor.green(), fillTopColor.blue(), 127)); topGradient.setColorAt(1, Qt::transparent); p->fillRect(QRect(rect.left(), rect.top() + drawRect.top(), rect.width(), 2), topGradient); p->restore(); p->save(); p->setClipRect(QRect(-1, 0, rect.width(), drawRect.height() / 2), Qt::ReplaceClip); QLinearGradient glassGradient(0, -5, 0, drawRect.height()); const QColor fillGlassColor = palette().base().color(); glassGradient.setColorAt(0, QColor(fillGlassColor.red(), fillGlassColor.green(), fillGlassColor.blue(), 255)); glassGradient.setColorAt(1, Qt::transparent); p->fillPath(internalBar, glassGradient); p->restore(); p->restore(); if (d->drawTextMode == KCapacityBar::DrawTextInline) { QRect rect(drawRect); rect.setHeight(rect.height() + 4); p->drawText(rect, Qt::AlignCenter, fontMetrics().elidedText(d->text, Qt::ElideRight, drawRect.width() - 2 * ROUND_MARGIN)); } else { p->drawText(rect, Qt::AlignBottom | d->horizontalTextAlignment, fontMetrics().elidedText(d->text, Qt::ElideRight, drawRect.width())); } }
void GradientLine::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); QPainter p(this); if (!isEnabled()) { p.setBrush(Qt::NoBrush); p.setPen(QColor(0x444444)); p.drawRect(9, 31, width() - 14, height() - 32); p.drawTiledPixmap(10, 32, width() - 16, height() - 34, tilePixMap(8)); } else { QLinearGradient linearGradient(QPointF(0, 0), QPointF(width(), 0)); for (int i =0; i < m_stops.size(); i++) linearGradient.setColorAt(m_stops.at(i), m_colorList.at(i)); p.setBrush(Qt::NoBrush); p.setPen(QColor(0x444444)); p.drawRect(9, 31, width() - 14, height() - 32); p.drawTiledPixmap(9, 31, width() - 16, height() - 34, tilePixMap(8)); p.setBrush(linearGradient); p.setPen(QColor(0x222222)); p.drawRect(8, 30, width() - 14, height() - 32); p.setPen(QColor(255, 255, 255, 40)); p.drawRect(9, 31, width() - 16, height() - 34); p.setPen(Qt::black); for (int i =0; i < m_colorList.size(); i++) { int localYOffset = 0; QColor arrowColor(Qt::black); if (i == currentColorIndex()) { localYOffset = m_yOffset; arrowColor = QColor(0x909090); } p.setPen(arrowColor); if (i == 0 || i == (m_colorList.size() - 1)) localYOffset = 0; int pos = qreal((width() - 16)) * m_stops.at(i) + 9; p.setBrush(arrowColor); QVector<QPointF> points; if (localYOffset < -8) p.setOpacity(0.5); points.append(QPointF(pos + 0.5, 28.5 + localYOffset)); //triangle points.append(QPointF(pos - 3.5, 22.5 + localYOffset)); points.append(QPointF(pos + 4.5, 22.5 + localYOffset)); p.setRenderHint(QPainter::Antialiasing, true); p.drawPolygon(points); p.setRenderHint(QPainter::Antialiasing, false); p.setBrush(Qt::NoBrush); p.setPen(QColor(0x424242)); p.drawRect(pos - 4, 9 + localYOffset, 10, 11); p.drawTiledPixmap(pos - 4, 9 + localYOffset, 9, 10, tilePixMap(5)); p.setPen(QColor(0x424242)); p.setBrush(m_colorList.at(i)); p.drawRect(pos - 5, 8 + localYOffset, 10, 11); p.setBrush(Qt::NoBrush); p.setPen(QColor(255, 255, 255, 30)); p.drawRect(pos - 4, 9 + localYOffset, 8, 9); p.setOpacity(1); } } }
void CpintPlot::calculate(RideItem *rideItem) { if (!rideItem) return; QString fileName = rideItem->fileName; QDateTime dateTime = rideItem->dateTime; QDir dir(path); QFileInfo file(fileName); // zap any existing ridefilecache then get new one if (current) delete current; current = new RideFileCache(context, context->athlete->home.absolutePath() + "/" + fileName); // get aggregates - incase not initialised from date change if (bests == NULL) bests = new RideFileCache(context, startDate, endDate, isFiltered, files, rangemode); // // PLOT MODEL CURVE (DERIVED) // if (series == RideFile::aPower || series == RideFile::xPower || series == RideFile::NP || series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) { if (bests->meanMaxArray(series).size() > 1) { // calculate CP model from all-time best data cp = tau = t0 = 0; deriveCPParameters(); if (useExtendedCP) { // calculate extended CP model from all-time best data //athleteModeleCP2 = ecp->deriveExtendedCP_2_3_Parameters(bests, series, sanI1, sanI2, anI1, anI2, aeI1, aeI2, laeI1, laeI2); athleteModeleCP4 = ecp->deriveExtendedCP_4_3_Parameters(true, bests, series, sanI1, sanI2, anI1, anI2, aeI1, aeI2, laeI1, laeI2); /*double best5sec = context->ride->ride()->getWeight() * 24.04; double best1min = context->ride->ride()->getWeight() * 11.50; double best5min = context->ride->ride()->getWeight() * 7.60; double best1hour = context->ride->ride()->getWeight() * 6.40; //worldClassModeleCP2 = ecp->deriveExtendedCP_2_3_ParametersForBest(best5sec, best1min, best5min, best1hour); worldClassModeleCP4 = ecp->deriveExtendedCP_4_3_ParametersForBest(best5sec, best1min, best5min, best1hour);*/ } } // // CP curve only relevant for Energy or Watts (?) // if (series == RideFile::aPower || series == RideFile::NP || series == RideFile::xPower || series == RideFile::watts || series == RideFile::wattsKg || series == RideFile::none) { if (!CPCurve) plot_CP_curve(this, cp, tau, t0); else { // make sure color reflects latest config QPen pen(GColor(CCP)); pen.setWidth(1.0); pen.setStyle(Qt::DashLine); CPCurve->setPen(pen); } if (useExtendedCP && CPCurve) CPCurve->setVisible(false); else if (CPCurve) CPCurve->setVisible(true); } // // PLOT ZONE (RAINBOW) AGGREGATED CURVE // if (bests->meanMaxArray(series).size()) { int maxNonZero = 0; for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) { if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i; } plot_allCurve(this, maxNonZero, bests->meanMaxArray(series).constData() + 1); } } else { // // PLOT BESTS IN SERIES COLOR // if (allCurve) { delete allCurve; allCurve = NULL; } if (bests->meanMaxArray(series).size()) { int maxNonZero = 0; QVector<double> timeArray(bests->meanMaxArray(series).size()); for (int i = 0; i < bests->meanMaxArray(series).size(); ++i) { timeArray[i] = i / 60.0; if (bests->meanMaxArray(series)[i] > 0) maxNonZero = i; } if (maxNonZero > 1) { allCurve = new QwtPlotCurve(dateTime.toString(tr("ddd MMM d, yyyy h:mm AP"))); allCurve->setRenderHint(QwtPlotItem::RenderAntialiased); QPen line; QColor fill; switch (series) { case RideFile::kph: line.setColor(GColor(CSPEED).darker(200)); fill = (GColor(CSPEED)); break; case RideFile::cad: line.setColor(GColor(CCADENCE).darker(200)); fill = (GColor(CCADENCE)); break; case RideFile::nm: line.setColor(GColor(CTORQUE).darker(200)); fill = (GColor(CTORQUE)); break; case RideFile::hr: line.setColor(GColor(CHEARTRATE).darker(200)); fill = (GColor(CHEARTRATE)); break; case RideFile::vam: line.setColor(GColor(CALTITUDE).darker(200)); fill = (GColor(CALTITUDE)); break; default: case RideFile::watts: // won't ever get here case RideFile::NP: case RideFile::xPower: line.setColor(GColor(CPOWER).darker(200)); fill = (GColor(CPOWER)); break; } // wow, QVector really doesn't have a max/min method! double ymax = 0; double ymin = 100000; foreach(double v, current->meanMaxArray(series)) { if (v > ymax) ymax = v; if (v && v < ymin) ymin = v; } foreach(double v, bests->meanMaxArray(series)) { if (v > ymax) ymax = v; if (v&& v < ymin) ymin = v; } if (ymin == 100000) ymin = 0; // VAM is a bit special if (series == RideFile::vam) { if (bests->meanMaxArray(series).size() > 300) ymax = bests->meanMaxArray(series)[300]; else ymax = 2000; } ymax *= 1.1; // bit of headroom ymin *= 0.9; // xmax is directly related to the size of the arrays double xmax = current->meanMaxArray(series).size(); if (bests->meanMaxArray(series).size() > xmax) xmax = bests->meanMaxArray(series).size(); xmax /= 60; // its in minutes not seconds setAxisScale(yLeft, ymin, ymax); QwtScaleDiv div((series == RideFile::vam ? (double) 4.993: (double) 0.017), (double)xmax); div.setTicks(QwtScaleDiv::MajorTick, LogTimeScaleDraw::ticks); setAxisScaleDiv(QwtPlot::xBottom, div); allCurve->setPen(line); fill.setAlpha(64); // use a linear gradient fill.setAlpha(64); QColor fill1 = fill.darker(); QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, fill); linearGradient.setColorAt(1.0, fill1); linearGradient.setSpread(QGradient::PadSpread); allCurve->setBrush(linearGradient); allCurve->attach(this); allCurve->setSamples(timeArray.data() + 1, bests->meanMaxArray(series).constData() + 1, maxNonZero - 1); } }
void PathBubble0::paintPathWays(QPainter *painter, vector<QString> PathWayNames) { int width=this->realRect().width(); int height=this->realRect().height(); int num=PathWayNames.size(); int column=sqrt(float(num)); int low=num/column; if(column*low<num) column+=1; int l,c; float x,y; int w=width/column; int h=height/low; int rw,rh; for(int i=0; i<PathWayNames.size(); i++) { l=i/column; c=i%column; x=l*w-width/2.0; y=c*h-height/2.0; rw=w-2, rh=h-2; QString qstr=PathWayNames[i]; QString fontType="Arial"; int fontSize=20; int style=QFont::Bold; if(rw<5) rw=5; if(rh<5) rh=5; x=x+1, y=y+1; if(highlighted==i) { QLinearGradient linearGradient(x, y, x, y+h); linearGradient.setColorAt(0.0, QColor(150,150,150,255)); linearGradient.setColorAt(1.0, QColor(138,138,168,255)); painter->setPen(QColor(148,148,178,255)); painter->setBrush( linearGradient ); } else { painter->setPen(Qt::NoPen); painter->setBrush( QColor(128,128,128,255) ); } painter->drawRect( x, y, rw, rh); //rect resizeFont(qstr, fontType , fontSize, style, rw, rh); QFont f(fontType, fontSize, style); //Arial, Courier, Arial Narrow, MS Gothic painter->setFont (f); painter->setFont(f); painter->setPen( QColor(255,255,255,255) ); painter->drawText( x, y, rw, rh, Qt::AlignCenter, qstr); //rect XL.push_back(x), XR.push_back(x+rw), YB.push_back(y), YT.push_back(y+rh); } }