void PaintScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { qreal widthScene = sceneRect().width(); qreal sceneHeight = sceneRect().height(); QImage image(widthScene, sceneHeight,QImage::Format_RGB32); //image.fill(Qt::white); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing); render(&painter); QPoint newPos; newPos.setX(event->scenePos().x()); newPos.setY(event->scenePos().y()); QPen pen; pen.setWidth(brushWidth()); pen.setColor(brushColor()); painter.setPen(pen); QString type("Pencil"); QRect rect = drawRect(type, painter, m_oldPos, newPos); m_oldPos = newPos; QBrush br(image); br.setColor(Qt::transparent); setBackgroundBrush(br); update(); QGraphicsScene::mouseMoveEvent(event); }
void cgGdiplusRender::FillRect( const cgRectF& rect, cgColor color ) { Gdiplus::Color brushColor((Gdiplus::ARGB)color); Gdiplus::SolidBrush brush(brushColor);; m_pkGraphics->FillRectangle(&brush, rect.x, rect.y, rect.w, rect.h); }
void MainWindow::kmeansUpdate(QPainter &painter) { // paints updated kmeans + voronoi QPen penColor; QBrush brushColor(Qt::SolidPattern); QPainterPath path; painter.begin(this); for(KPoint &i : kmeans.getPoints()) { penColor.setColor(colors[i.getGroup()-1]); brushColor.setColor(colors[i.getGroup()-1]); painter.setPen(penColor); painter.setBrush(brushColor); painter.drawEllipse(i.paramAt(0),i.paramAt(1),5,5); } for(CPoint &i : kmeans.getCentroids()) { if(i.paramAt(0) != 0) { penColor.setColor(colors[i.getGroup()-1]); brushColor.setColor(Qt::black); painter.setPen(penColor); painter.setBrush(brushColor); painter.drawRect(i.paramAt(0)-4,i.paramAt(1)-4,8,8); } } // Voronoi drawing for(WORD i=0;i<kmeans.getCentroids().size();i++) { if(kmeans.getCentroids()[i].paramAt(0) != 0) ver->push_back(new VPoint(kmeans.getCentroids()[i].paramAt(0),kmeans.getCentroids()[i].paramAt(1))); } edg = v->GetEdges(ver, this->width(), this->height()); QPen pen(QColor(Qt::black)); pen.setWidth(2); painter.setPen(pen); for(Edges::iterator i = edg->begin(); i!= edg->end(); ++i) { path.moveTo((*i)->start->x, (*i)->start->y); path.lineTo((*i)->end->x, (*i)->end->y); painter.drawPath(path); path = QPainterPath(); } painter.setPen(QPen(QColor(Qt::white))); painter.fillRect(this->width()-200,18,200,20,Qt::SolidPattern); painter.drawText(this->width()-200,35,"Quantization error: " + QString::number(kmeans.getQuantizationError())); painter.end(); ver->clear(); }
ItemSettings::ItemSettings(ItemProperties *prop,QWidget *parent):QWidget(parent,Qt::Tool) { setupUi(this); this->prop = prop; this->fontColor = prop->fontColor; this->penColor = prop->itemPen.color(); this->brushColor = prop->itemBrush.color(); QPixmap penColor(45,11); penColor.fill(prop->itemPen.color()); QIcon penIcon(penColor); this->pb_penColor->setIcon(penIcon); this->pb_penColor->setIconSize(QSize(45,11)); this->sd_penWidth->setValue(prop->itemPen.width()); this->cb_penStyle->setCurrentIndex(this->prop->itemPen.style() - 1); QPixmap brushColor(45,11); brushColor.fill(prop->itemBrush.color()); QIcon brushIcon(brushColor); this->pb_brushColor->setIcon(brushIcon); this->pb_brushColor->setIconSize(QSize(45,11)); this->cb_brushStyle->setCurrentIndex(this->prop->itemBrush.style()); QPixmap fontColor(45,11); fontColor.fill(prop->fontColor); QIcon fontIcon(fontColor); this->pb_fontColor->setIcon(fontIcon); this->pb_fontColor->setIconSize(QSize(45,11)); connect(pb_penColor,SIGNAL(released()),this,SLOT(setPenColor())); connect(pb_brushColor,SIGNAL(released()),this,SLOT(setBrushColor())); connect(pb_done,SIGNAL(released()),this,SLOT(saveSettings())); connect(pb_selectFont,SIGNAL(released()),this,SLOT(selectFont())); connect(pb_fontColor,SIGNAL(released()),this,SLOT(setFontColor())); int p_midX = parent->x() + 100; int p_midY = parent->y() + 150; this->move(p_midX , p_midY) ; this->activateWindow(); }
void Plugin14CRefView::setDate(const Date& d, const ProjectSettings& settings) { QLocale locale=QLocale(); GraphViewRefAbstract::setDate(d, settings); Date date = d; mGraph->removeAllCurves(); mGraph->clearInfos(); mGraph->showInfos(true); mGraph->setRangeX(mSettings.mTmin, mSettings.mTmax); mGraph->setCurrentX(mSettings.mTmin, mSettings.mTmax); mGraph->setFormatFunctX(mFormatFuncX); if(!date.isNull()) { double age = date.mData.value(DATE_14C_AGE_STR).toDouble(); double error = date.mData.value(DATE_14C_ERROR_STR).toDouble(); double delta_r = date.mData.value(DATE_14C_DELTA_R_STR).toDouble(); double delta_r_error = date.mData.value(DATE_14C_DELTA_R_ERROR_STR).toDouble(); QString ref_curve = date.mData.value(DATE_14C_REF_CURVE_STR).toString().toLower(); // ---------------------------------------------- // Reference curve // ---------------------------------------------- QColor color2(150, 150, 150); Plugin14C* plugin = (Plugin14C*)date.mPlugin; const QMap<QString, QMap<double, double> >& curves = plugin->getRefData(ref_curve); QMap<double, double> curveG; QMap<double, double> curveG95Sup; QMap<double, double> curveG95Inf; double yMin = curves["G95Inf"][mSettings.mTmin]; double yMax = curves["G95Sup"][mSettings.mTmin]; double tMinGraph=curves["G"].firstKey()>mSettings.mTmin ? curves["G"].firstKey(): mSettings.mTmin; double tMaxGraph=curves["G"].lastKey()<mSettings.mTmax ? curves["G"].lastKey() : mSettings.mTmax; for(double t=tMinGraph; t<=tMaxGraph; ++t) { curveG[t] = curves["G"][t]; curveG95Sup[t] = curves["G95Sup"][t]; curveG95Inf[t] = curves["G95Inf"][t]; yMin = qMin(yMin, curveG95Inf[t]); yMax = qMax(yMax, curveG95Sup[t]); } GraphCurve graphCurveG; graphCurveG.mName = "G"; graphCurveG.mData = curveG; graphCurveG.mPen.setColor(Qt::blue); graphCurveG.mIsHisto = false; mGraph->addCurve(graphCurveG); GraphCurve graphCurveG95Sup; graphCurveG95Sup.mName = "G95Sup"; graphCurveG95Sup.mData = curveG95Sup; graphCurveG95Sup.mPen.setColor(QColor(180, 180, 180)); graphCurveG95Sup.mIsHisto = false; mGraph->addCurve(graphCurveG95Sup); GraphCurve graphCurveG95Inf; graphCurveG95Inf.mName = "G95Inf"; graphCurveG95Inf.mData = curveG95Inf; graphCurveG95Inf.mPen.setColor(QColor(180, 180, 180)); graphCurveG95Inf.mIsHisto = false; mGraph->addCurve(graphCurveG95Inf); // Display reference curve name mGraph->addInfo(tr("Ref : ") + ref_curve); // ------------------------------------------- yMin = qMin(yMin, age); yMin = floor(yMin/10)*10; yMax = qMax(yMax, age); yMax = ceil(yMax/10)*10; mGraph->setRangeY(yMin, yMax); // ---------------------------------------------- // Measure curve // ---------------------------------------------- GraphCurve curveMeasure; curveMeasure.mName = "Measure"; QColor penColor(mMeasureColor); QColor brushColor(mMeasureColor); // Lower opacity in case of delta r not null if(delta_r != 0 && delta_r_error != 0){ penColor.setAlpha(100); brushColor.setAlpha(15); }else{ penColor.setAlpha(255); brushColor.setAlpha(50); } curveMeasure.mPen = penColor; curveMeasure.mBrush = brushColor; curveMeasure.mIsVertical = true; curveMeasure.mIsHisto = false; // 5000 pts are used on vertical measure // because the y scale auto adjusts depending on x zoom. // => the visible part of the measure may be very reduced ! double step = (yMax - yMin) / 5000.; for(double t=yMin; t<yMax; t += step) { double v = exp(-0.5 * pow((age - t) / error, 2)); curveMeasure.mData[t] = v; } curveMeasure.mData = normalize_map(curveMeasure.mData); mGraph->addCurve(curveMeasure); // Infos to write : QString info = tr("Age BP : ") + locale.toString(age) + " ± " + locale.toString(error); // ---------------------------------------------- // Delta R curve // ---------------------------------------------- if(delta_r != 0 && delta_r_error != 0) { // Apply reservoir effect age = (age - delta_r); error = sqrt(error * error + delta_r_error * delta_r_error); GraphCurve curveDeltaR; curveDeltaR.mName = "Delta R"; penColor = mMeasureColor; brushColor = mMeasureColor; brushColor.setAlpha(50); curveDeltaR.mPen = penColor; curveDeltaR.mBrush = brushColor; curveDeltaR.mIsVertical = true; curveDeltaR.mIsHisto = false; // 5000 pts are used on vertical measure // because the y scale auto adjusts depending on x zoom. // => the visible part of the measure may be very reduced ! step = (yMax - yMin) / 5000.; for(double t=yMin; t<yMax; t += step) { double v = exp(-0.5 * pow((age - t) / error, 2)); curveDeltaR.mData[t] = v; } curveDeltaR.mData = normalize_map(curveDeltaR.mData); mGraph->addCurve(curveDeltaR); info += tr(", ΔR : ") + locale.toString(delta_r) + " ± " + locale.toString(delta_r_error); } // ---------------------------------------------- // Sub-dates curves (combination) // ---------------------------------------------- for(int i=0; i<date.mSubDates.size(); ++i){ const Date& d = date.mSubDates[i]; GraphCurve curveSubMeasure; curveSubMeasure.mName = "Sub-Measure " + QString::number(i); QColor penColor = QColor(167, 126, 73); QColor brushColor = QColor(167, 126, 73); double sub_age = d.mData.value(DATE_14C_AGE_STR).toDouble(); double sub_error = d.mData.value(DATE_14C_ERROR_STR).toDouble(); double sub_delta_r = d.mData.value(DATE_14C_DELTA_R_STR).toDouble(); double sub_delta_r_error = d.mData.value(DATE_14C_DELTA_R_ERROR_STR).toDouble(); // Apply reservoir effect sub_age = (sub_age - sub_delta_r); sub_error = sqrt(sub_error * sub_error + sub_delta_r_error * sub_delta_r_error); penColor.setAlpha(255); brushColor.setAlpha(50); curveSubMeasure.mPen = penColor; curveSubMeasure.mBrush = brushColor; curveSubMeasure.mIsVertical = true; curveSubMeasure.mIsHisto = false; // 5000 pts are used on vertical measure // because the y scale auto adjusts depending on x zoom. // => the visible part of the measure may be very reduced ! double step = (yMax - yMin) / 5000.; for(double t=yMin; t<yMax; t += step) { double v = exp(-0.5 * pow((sub_age - t) / sub_error, 2)); curveSubMeasure.mData[t] = v; } curveSubMeasure.mData = normalize_map(curveSubMeasure.mData); mGraph->addCurve(curveSubMeasure); } // ---------------------------------------------- // Textual info // ---------------------------------------------- mGraph->addInfo(info); // ---------------------------------------------- // Error on measure (horizontal lines) // ---------------------------------------------- GraphCurve curveMeasureAvg; curveMeasureAvg.mName = "MeasureAvg"; curveMeasureAvg.mPen.setColor(mMeasureColor); curveMeasureAvg.mPen.setStyle(Qt::SolidLine); curveMeasureAvg.mIsHorizontalLine = true; GraphCurve curveMeasureSup; curveMeasureSup.mName = "MeasureSup"; curveMeasureSup.mPen.setColor(mMeasureColor); curveMeasureSup.mPen.setStyle(Qt::DashLine); curveMeasureSup.mIsHorizontalLine = true; GraphCurve curveMeasureInf; curveMeasureInf.mName = "MeasureInf"; curveMeasureInf.mPen.setColor(mMeasureColor); curveMeasureInf.mPen.setStyle(Qt::DashLine); curveMeasureInf.mIsHorizontalLine = true; curveMeasureAvg.mHorizontalValue = age; curveMeasureSup.mHorizontalValue = age + error; curveMeasureInf.mHorizontalValue = age - error; mGraph->addCurve(curveMeasureAvg); mGraph->addCurve(curveMeasureSup); mGraph->addCurve(curveMeasureInf); } }
bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& doc ) { Q_UNUSED( doc ); if ( itemElem.isNull() ) { return false; } //rotation setItemRotation( itemElem.attribute( "itemRotation", "0" ).toDouble() ); //uuid mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() ); // temporary for groups imported from templates mTemplateUuid = itemElem.attribute( "templateUuid" ); //id QString id = itemElem.attribute( "id", "" ); setId( id ); //frame QString frame = itemElem.attribute( "frame" ); if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 ) { mFrame = true; } else { mFrame = false; } //frame QString background = itemElem.attribute( "background" ); if ( background.compare( "true", Qt::CaseInsensitive ) == 0 ) { mBackground = true; } else { mBackground = false; } //position lock for mouse moves/resizes QString positionLock = itemElem.attribute( "positionLock" ); if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 ) { setPositionLock( true ); } else { setPositionLock( false ); } //position int page; double x, y, pagex, pagey, width, height; bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK; x = itemElem.attribute( "x" ).toDouble( &xOk ); y = itemElem.attribute( "y" ).toDouble( &yOk ); page = itemElem.attribute( "page" ).toInt( &pageOk ); pagex = itemElem.attribute( "pagex" ).toDouble( &pagexOk ); pagey = itemElem.attribute( "pagey" ).toDouble( &pageyOk ); width = itemElem.attribute( "width" ).toDouble( &widthOk ); height = itemElem.attribute( "height" ).toDouble( &heightOk ); mLastUsedPositionMode = ( ItemPositionMode )itemElem.attribute( "positionMode" ).toInt( &positionModeOK ); if ( !positionModeOK ) { mLastUsedPositionMode = UpperLeft; } if ( pageOk && pagexOk && pageyOk ) { xOk = true; yOk = true; x = pagex; y = ( page - 1 ) * ( mComposition->paperHeight() + composition()->spaceBetweenPages() ) + pagey; } if ( !xOk || !yOk || !widthOk || !heightOk ) { return false; } mLastValidViewScaleFactor = itemElem.attribute( "lastValidViewScaleFactor", "-1" ).toDouble(); setSceneRect( QRectF( x, y, width, height ) ); setZValue( itemElem.attribute( "zValue" ).toDouble() ); //pen QDomNodeList frameColorList = itemElem.elementsByTagName( "FrameColor" ); if ( frameColorList.size() > 0 ) { QDomElement frameColorElem = frameColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk, widthOk; int penRed, penGreen, penBlue, penAlpha; double penWidth; penWidth = itemElem.attribute( "outlineWidth" ).toDouble( &widthOk ); penRed = frameColorElem.attribute( "red" ).toDouble( &redOk ); penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk ); penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk ); penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk ); mFrameJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "frameJoinStyle", "miter" ) ); if ( redOk && greenOk && blueOk && alphaOk && widthOk ) { QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) ); framePen.setWidthF( penWidth ); framePen.setJoinStyle( mFrameJoinStyle ); setPen( framePen ); } } //brush QDomNodeList bgColorList = itemElem.elementsByTagName( "BackgroundColor" ); if ( bgColorList.size() > 0 ) { QDomElement bgColorElem = bgColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int bgRed, bgGreen, bgBlue, bgAlpha; bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk ); bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk ); bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk ); bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha ); setBackgroundColor( brushColor ); } } //blend mode setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "blendMode", "0" ).toUInt() ) ); //transparency setTransparency( itemElem.attribute( "transparency" , "0" ).toInt() ); return true; }
// printAct = new QAction(tr("&Print..."), this); // connect(printAct, SIGNAL(triggered()), canvas, SLOT(print())); exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcuts(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); penColorAct = new QAction(tr("&Pen Color..."), this); connect(penColorAct, SIGNAL(triggered()), this, SLOT(penColor())); penWidthAct = new QAction(tr("Pen &Width..."), this); connect(penWidthAct, SIGNAL(triggered()), this, SLOT(penWidth())); brushColorAct = new QAction(tr("&Brush Color..."), this); connect(brushColorAct, SIGNAL(triggered()), this, SLOT(brushColor())); clearScreenAct = new QAction(tr("&Clear Screen"), this); clearScreenAct->setShortcut(tr("Ctrl+L")); connect(clearScreenAct, SIGNAL(triggered()), canvas, SLOT(clearImage())); connect(clearScreenAct, SIGNAL(triggered()), this, SLOT(updateStatusBar())); updateStatusAct = new QAction(tr("&Update Status"), this); updateStatusAct->setShortcut(tr("Ctrl+U")); connect(updateStatusAct, SIGNAL(triggered()), this, SLOT(updateStatusBar())); aboutAct = new QAction(tr("&About"), this); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); aboutQtAct = new QAction(tr("About &Qt"), this);
bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& doc ) { Q_UNUSED( doc ); if ( itemElem.isNull() ) { return false; } //rotation mRotation = itemElem.attribute( "rotation", "0" ).toDouble(); //id mId = itemElem.attribute( "id", "" ); //frame QString frame = itemElem.attribute( "frame" ); if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 ) { mFrame = true; } else { mFrame = false; } //position lock for mouse moves/resizes QString positionLock = itemElem.attribute( "positionLock" ); if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 ) { mItemPositionLocked = true; } else { mItemPositionLocked = false; } //position double x, y, width, height; bool xOk, yOk, widthOk, heightOk; x = itemElem.attribute( "x" ).toDouble( &xOk ); y = itemElem.attribute( "y" ).toDouble( &yOk ); width = itemElem.attribute( "width" ).toDouble( &widthOk ); height = itemElem.attribute( "height" ).toDouble( &heightOk ); if ( !xOk || !yOk || !widthOk || !heightOk ) { return false; } mLastValidViewScaleFactor = itemElem.attribute( "lastValidViewScaleFactor", "-1" ).toDouble(); setSceneRect( QRectF( x, y, width, height ) ); setZValue( itemElem.attribute( "zValue" ).toDouble() ); //pen QDomNodeList frameColorList = itemElem.elementsByTagName( "FrameColor" ); if ( frameColorList.size() > 0 ) { QDomElement frameColorElem = frameColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk, widthOk; int penRed, penGreen, penBlue, penAlpha; double penWidth; penWidth = itemElem.attribute( "outlineWidth" ).toDouble( &widthOk ); penRed = frameColorElem.attribute( "red" ).toDouble( &redOk ); penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk ); penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk ); penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk && widthOk ) { QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) ); framePen.setWidthF( penWidth ); setPen( framePen ); } } //brush QDomNodeList bgColorList = itemElem.elementsByTagName( "BackgroundColor" ); if ( bgColorList.size() > 0 ) { QDomElement bgColorElem = bgColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int bgRed, bgGreen, bgBlue, bgAlpha; bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk ); bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk ); bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk ); bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha ); setBrush( QBrush( brushColor ) ); } } return true; }
void KookaPrint::drawCutSign( const QPoint& p, int num, MarkerDirection dir ) { QBrush saveB = m_painter->brush(); int start = 0; const int radius=20; QColor brushColor( Qt::red ); int toffX=0; int toffY=0; QString numStr = QString::number(num); QFontMetrics fm = m_painter->fontMetrics(); int textWidth = fm.width( numStr )/2; int textHeight = fm.width( numStr )/2; int textYOff = 0; int textXOff = 0; switch( dir ) { case SW: start = -90; brushColor = Qt::green; toffX =-1; toffY = 1; textXOff = -1*textWidth; textYOff = textHeight; break; case NW: start = -180; brushColor = Qt::blue; toffX =-1; toffY =-1; textXOff = -1*textWidth; textYOff = textHeight; break; case NO: start = -270; brushColor = Qt::yellow; toffX = 1; toffY = -1; textXOff = -1*textWidth; textYOff = textHeight; break; case SO: start = 0; brushColor = Qt::magenta; toffX = 1; toffY = 1; textXOff = -1*textWidth; textYOff = textHeight; break; default: start = 0; } /* to draw around the point p, subtraction of the half radius is needed */ int x = p.x()-radius/2; int y = p.y()-radius/2; // m_painter->drawRect( x, y, radius, radius ); /* debug !!! */ const int tAway = radius*3/4; QRect bRect = fm.boundingRect( QString::number(num)); int textX = p.x()+ tAway * toffX + textXOff; int textY = p.y()+ tAway * toffY + textYOff; // m_painter->drawRect( textX, textY, bRect.width(), bRect.height() ); kdDebug(28000) << "Drawing to position " << textX << "/" << textY << endl; m_painter->drawText( textX, textY, QString::number(num)); QBrush b( brushColor, NoBrush /* remove this to get debug color*/ ); m_painter->setBrush( b ); m_painter->drawPie( x, y, radius, radius, 16*start, -16*90 ); m_painter->setBrush( saveB ); }
void DrawingPolygonItem::writeXmlAttributes(QXmlStreamWriter& xmlWriter, const QList<DrawingItem*>& items) { DrawingPolyItem::writeXmlAttributes(xmlWriter, items); xmlWriter.writeAttribute("brushColor", Drawing::colorToString(brushColor())); }
QBrush DrawingPolygonItem::brush() const { return QBrush(brushColor()); }
void FadePedal::paintEvent(QPaintEvent* /*event*/) { float lastValue = (m_Ticks.empty() ? 0 : m_Ticks.back().value); float angle = (35 * lastValue); QRectF r( rect() ); r.adjust(1, 1, -1, -1); QPainter painter; m_Canvas.fill(0); if( painter.begin(&m_Canvas) ) { painter.setRenderHints(QPainter::Antialiasing); float brightness = m_Click; if(m_Hover > 0) brightness += (m_Hover*0.2f); if( !m_Image.isNull() ) { painter.setOpacity(1.0-(brightness*0.5)); painter.drawPixmap( r.x() + qRound((r.width()-m_Image.width())*0.5), r.y() + qRound((r.height()-m_Image.height())*0.5), m_Image ); painter.setOpacity(1.0); } QColor brushColor( palette().color(QPalette::Button) ); if(m_Hover > 0) { qreal t = (brightness * BUTTON_BRIGHTESS); brushColor.setRedF( qMin(brushColor.redF()+t,1.0) ); brushColor.setGreenF( qMin(brushColor.greenF()+t,1.0) ); brushColor.setBlueF( qMin(brushColor.blueF()+t,1.0) ); } QColor lineColor(brushColor); Utils::MakeContrastingColor(1.0f, lineColor); if( !m_Image.isNull() ) { QPainterPath clip; clip.addRoundedRect(r, ROUNDED, ROUNDED); painter.setClipPath(clip); painter.drawPixmap( r.x() + qRound((r.width()-m_Image.width())*0.5), r.y() + qRound((r.height()-m_Image.height())*0.5), m_Image ); painter.setClipping(false); } painter.setBrush(brushColor); painter.setPen( QPen(lineColor,BORDER) ); painter.drawRoundedRect(r, ROUNDED, ROUNDED); if( m_Ticks.empty() ) m_Points.clear(); else m_Points.resize(m_Ticks.size() + 1); // end point if( !m_Points.empty() ) { float lineHeight = (r.height() * 0.8f); float lineX = (r.right() + HALF_BORDER); float lineY = (r.bottom() - 0.5f*(r.height()-lineHeight)); float lineWidth = (r.width() + BORDER); float toPercent = 1.0f/PEDAL_TIMEFRAME; for(size_t i=0; i<m_Ticks.size(); i++) { const sTick &t = m_Ticks[i]; QPointF &p = m_Points[i]; // end point float percent = (t.elapsed * toPercent); p.setX(lineX - lineWidth*percent); p.setY(lineY - lineHeight*t.value); } // end point m_Points[m_Points.size()-1] = QPointF(lineX, m_Points[m_Points.size()-2].y()); painter.drawPolyline(m_Points); } if(m_Hover > 0) { qreal dy = (-m_Hover * BUTTON_RAISE); if(dy != 0) r.adjust(0, 0, 0, dy); } QColor textColor( palette().color(QPalette::ButtonText) ); if( !isEnabled() ) textColor = textColor.darker(150); if( !text().isEmpty() ) { if( m_Label.isEmpty() ) { // just text centered painter.setFont( font() ); painter.setPen(textColor); painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, text()); } else { // both text and label text QRectF textRect; painter.setFont( font() ); painter.setPen(textColor); painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, text(), &textRect); QRectF labelRect; painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, m_Label, &labelRect); qreal h = (r.height() * 0.5 * (textRect.height()/labelRect.height())); painter.drawText(QRectF(r.x(),r.y(),r.width(),h), Qt::AlignCenter|Qt::TextWordWrap, text()); painter.drawText(QRectF(r.x(),r.y()+h,r.width(),r.height()-h), Qt::AlignCenter|Qt::TextWordWrap, m_Label); } } else if( !m_Label.isEmpty() ) { // just label text centered painter.setFont( font() ); painter.setPen(textColor); painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, m_Label); } painter.end(); } if( painter.begin(this) ) { if(angle > 0.00001) { qreal center = (m_Canvas.width() * 0.5); QMatrix4x4 matrix; matrix.translate(-center, m_Canvas.height()); matrix.rotate(angle, 1.0, 0, 0); painter.translate(center, 0); painter.setTransform(matrix.toTransform(300.0), /*combine*/true); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.drawImage(0, -m_Canvas.height(), m_Canvas); } else painter.drawImage(0, 0, m_Canvas); painter.end(); } }