////////////////////////////////////////////////////////////////// // checkKeyboardMenu // Checks the keyboard for the menu options // // // Returns: // void // void checkKeyboardMenu() { u8 *pvideo; delay(20); if (( cpct_isKeyPressed(Key_1)) || (((cpct_isKeyPressed(keys.fire) || (cpct_isKeyPressed(Joy0_Fire1))) && (selectedOption == 0)))) { drawMarker(); selectedOption = 0; drawMarker(); waitKeyUp(Key_1); keys.up = redefineKey("UP"); keys.down = redefineKey("DOWN"); keys.left = redefineKey("LEFT"); keys.right = redefineKey("RIGHT"); keys.fire = redefineKey("FIRE"); keys.pause = redefineKey("PAUSE"); keys.abort = redefineKey("ABORT"); //keys.music = redefineKey("MUSIC"); pvideo = cpct_getScreenPtr(CPCT_VMEM_START, 8, 154); cpct_drawSolidBox(pvideo, #0, 64, FONT_H); }
//-------------------------------------------------------------- void testApp::draw() { ofSetColor(255); video->draw(0,0); //aruco.draw(); if(showMarkers) { for(int i=0; i<aruco.getNumMarkers(); i++) { aruco.begin(i); drawMarker(0.15,ofColor::white); aruco.end(); } } if(showBoard && aruco.getBoardProbability()>0.03) { aruco.beginBoard(); drawMarker(.5,ofColor::red); aruco.end(); } ofSetColor(255); if(showBoardImage) { board.draw(ofGetWidth()-320,0,320,320*float(board.getHeight())/float(board.getWidth())); } ofDrawBitmapString("markers detected: " + ofToString(aruco.getNumMarkers()),20,20); ofDrawBitmapString("fps " + ofToString(ofGetFrameRate()),20,40); ofDrawBitmapString("m toggles markers",20,60); ofDrawBitmapString("b toggles board",20,80); ofDrawBitmapString("i toggles board image",20,100); ofDrawBitmapString("s saves board image",20,120); ofDrawBitmapString("0-9 saves marker image",20,140); }
bool QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& context ) { double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit ); // calculate necessary image size for the cache double pw = (( mPen.widthF() == 0 ? 1 : mPen.widthF() ) + 1 ) / 2 * 2; // make even (round up); handle cosmetic pen int imageSize = (( int ) scaledSize + pw ) / 2 * 2 + 1; // make image width, height odd; account for pen width double center = imageSize / 2.0; if ( imageSize > mMaximumCacheWidth ) { return false; } mCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied ); mCache.fill( 0 ); QPainter p; p.begin( &mCache ); p.setRenderHint( QPainter::Antialiasing ); p.setBrush( mBrush ); p.setPen( mPen ); p.translate( QPointF( center, center ) ); drawMarker( &p, context ); p.end(); // Construct the selected version of the Cache QColor selColor = context.renderContext().selectionColor(); mSelCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied ); mSelCache.fill( 0 ); p.begin( &mSelCache ); p.setRenderHint( QPainter::Antialiasing ); p.setBrush( mSelBrush ); p.setPen( mSelPen ); p.translate( QPointF( center, center ) ); drawMarker( &p, context ); p.end(); // Check that the selected version is different. If not, then re-render, // filling the background with the selection color and using the normal // colors for the symbol .. could be ugly! if ( mSelCache == mCache ) { p.begin( &mSelCache ); p.setRenderHint( QPainter::Antialiasing ); p.fillRect( 0, 0, imageSize, imageSize, selColor ); p.setBrush( mBrush ); p.setPen( mPen ); p.translate( QPointF( center, center ) ); drawMarker( &p, context ); p.end(); } return true; }
void main(void) { short mx, my, tmx, tmy, ignoreBtn; char stat[14]; // TODO initialise variables with the riht value //mx = -1; //my = -1; //ignoreBtn = 0; lcd_init(); initIO(); adc_init(); lcd_clear(0); drawField(); for (;;) { tmx = (short) (2 - adc_getValue(1) / 255.0 * 2 + 0.5); tmy = (short) (2 - adc_getValue(2) / 255.0 * 2 + 0.5); if (tmy != my || tmx != mx) { drawMarker(mx, my, 0); if (fields[mx][my] == 1) { placePlayerMark(mx, my, 1); } drawMarker(mx = tmx, my = tmy, 1); } if (!BUTTON_RIGHT && !ignoreBtn && !fields[mx][my]) { ignoreBtn = 1; pushes++; placePlayerMark(mx, my, player); if (checkStatus(mx, my)) { lcd_clear(0); sprintf(stat, "Player %u won!", player); lcd_drawString(27, 4, 0, 4, 0, 0, &stat[0], 1, 1); lcd_flush(); break; } if (pushes == 9) { lcd_clear(0); sprintf(stat, "Undecided!"); lcd_drawString(32, 4, 0, 4, 0, 0, &stat[0], 1, 1); lcd_flush(); break; } if (player == 1) { player = 2; } else if (player == 2) { player = 1; } } else if (BUTTON_RIGHT && ignoreBtn) { ignoreBtn = 0; } } }
void QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& context ) { double scaledSize = context.outputPixelSize( mSize ); // calculate necessary image size for the cache double pw = (( mPen.widthF() == 0 ? 1 : mPen.widthF() ) + 1 ) / 2 * 2; // make even (round up); handle cosmetic pen int imageSize = (( int ) scaledSize + pw ) / 2 * 2 + 1; // make image width, height odd; account for pen width double center = (( double ) imageSize / 2 ) + 0.5; // add 1/2 pixel for proper rounding when the figure's coordinates are added mCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied ); mCache.fill( 0 ); QPainter p; p.begin( &mCache ); p.setRenderHint( QPainter::Antialiasing ); p.setBrush( mBrush ); p.setPen( mPen ); p.translate( QPointF( center, center ) ); drawMarker( &p, context ); p.end(); // Construct the selected version of the Cache QColor selColor = context.selectionColor(); mSelCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied ); mSelCache.fill( 0 ); p.begin( &mSelCache ); p.setRenderHint( QPainter::Antialiasing ); p.setBrush( mSelBrush ); p.setPen( mSelPen ); p.translate( QPointF( center, center ) ); drawMarker( &p, context ); p.end(); // Check that the selected version is different. If not, then re-render, // filling the background with the selection color and using the normal // colors for the symbol .. could be ugly! if ( mSelCache == mCache ) { p.begin( &mSelCache ); p.setRenderHint( QPainter::Antialiasing ); p.fillRect( 0, 0, imageSize, imageSize, selColor ); p.setBrush( mBrush ); p.setPen( mPen ); p.translate( QPointF( center, center ) ); drawMarker( &p, context ); p.end(); } }
/*! Repaint the knob \param event Paint event */ void QwtKnob::paintEvent( QPaintEvent *event ) { const QRectF knobRect = this->knobRect(); QPainter painter( this ); painter.setClipRegion( event->region() ); QStyleOption opt; opt.init(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); painter.setRenderHint( QPainter::Antialiasing, true ); if ( !knobRect.contains( event->region().boundingRect() ) ) { scaleDraw()->setRadius( 0.5 * knobRect.width() + d_data->scaleDist ); scaleDraw()->moveCenter( knobRect.center() ); scaleDraw()->draw( &painter, palette() ); } drawKnob( &painter, knobRect ); drawMarker( &painter, knobRect, qwtNormalizeDegrees( scaleMap().transform( value() ) ) ); painter.setRenderHint( QPainter::Antialiasing, false ); if ( hasFocus() ) drawFocusIndicator( &painter ); }
/*! \brief Draw the knob \param p painter \param r borders of the knob */ void QwtKnob::drawKnob(QPainter *p, const QRect &r) { const int bw2 = d_borderWidth / 2; QRect aRect(r.x() + bw2, r.y() + bw2, r.width() - 2 * bw2, r.height() - 2 * bw2); // // draw button face // p->setBrush(colorGroup().brush(QColorGroup::Button)); p->drawEllipse(aRect); // // draw button shades // QPen pn; pn.setWidth(d_borderWidth); pn.setColor(colorGroup().light()); p->setPen(pn); p->drawArc(aRect, 45*16,180*16); pn.setColor(colorGroup().dark()); p->setPen(pn); p->drawArc(aRect, 225*16,180*16); // // draw marker // if ( isValid() ) drawMarker(p, d_angle, colorGroup().buttonText()); }
void Slider::draw(gcn::Graphics *graphics) { int w = getWidth(); int h = getHeight(); int x = 0; int y = (h - hStart->getHeight()) / 2; if (isFocused()) static_cast<Graphics*>(graphics)->drawImage(hStartHi, x, y); else static_cast<Graphics*>(graphics)->drawImage(hStart, x, y); w -= hStart->getWidth() + hEnd->getWidth(); x += hStart->getWidth(); if (isFocused()) static_cast<Graphics*>(graphics)->drawImagePattern(hMidHi, x, y, w, hMidHi->getHeight()); else static_cast<Graphics*>(graphics)->drawImagePattern(hMid, x, y, w, hMid->getHeight()); x += w; if (isFocused()) static_cast<Graphics*>(graphics)->drawImage(hEndHi, x, y); else static_cast<Graphics*>(graphics)->drawImage(hEnd, x, y); drawMarker(graphics); }
void OriginalView::draw() { if(!valid()) { glClearColor(0.7f, 0.7f, 0.7f, 1.0); // We're only using 2-D, so turn off depth glDisable( GL_DEPTH_TEST ); // Tell openGL to read from the front buffer when capturing // out paint strokes glReadBuffer( GL_FRONT ); ortho(); } glClear( GL_COLOR_BUFFER_BIT ); if ( m_pDoc->m_ucBitmap ) { // note that both OpenGL pixel storage and the Windows BMP format // store pixels left-to-right, BOTTOM-to-TOP!! thus all the fiddling // around with startrow. m_nWindowWidth=w(); m_nWindowHeight=h(); int drawWidth, drawHeight; GLvoid* bitstart; // we are not using a scrollable window, so ignore it Point scrollpos; // = GetScrollPosition(); scrollpos.x=scrollpos.y=0; drawWidth = min( m_nWindowWidth, m_pDoc->m_nWidth ); drawHeight = min( m_nWindowHeight, m_pDoc->m_nHeight ); int startrow = m_pDoc->m_nHeight - (scrollpos.y + drawHeight); if ( startrow < 0 ) startrow = 0; if(this->bToggleEdge){ bitstart = m_pDoc->m_ucEdgeImage + 3 * ((m_pDoc->m_nWidth * startrow) + scrollpos.x); } else { bitstart = m_pDoc->m_ucBitmap + 3 * ((m_pDoc->m_nWidth * startrow) + scrollpos.x);} // just copy image to GLwindow conceptually glRasterPos2i( 0, m_nWindowHeight - drawHeight ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glPixelStorei( GL_UNPACK_ROW_LENGTH, m_pDoc->m_nWidth ); glDrawBuffer( GL_BACK ); glDrawPixels( drawWidth, drawHeight, GL_RGB, GL_UNSIGNED_BYTE, bitstart );} if(bMarker) drawMarker(); glFlush(); }
void Knob::drawKnob(QPainter* p, const QRect& r) { const QPalette& pal = palette(); QRect aRect; aRect.setRect(r.x() + d_borderWidth, r.y() + d_borderWidth, r.width() - 2*d_borderWidth, r.height() - 2*d_borderWidth); int width = r.width(); int height = r.height(); int size = qMin(width, height); p->setRenderHint(QPainter::Antialiasing, true); // // draw the rim // QLinearGradient linearg(QPoint(r.x(),r.y()), QPoint(size, size)); linearg.setColorAt(1 - M_PI_4, d_faceColor.lighter(125)); linearg.setColorAt(M_PI_4, d_faceColor.darker(175)); p->setBrush(linearg); p->setPen(Qt::NoPen); p->drawEllipse(r.x(),r.y(),size,size); // // draw shiny surrounding // QPen pn; pn.setCapStyle(Qt::FlatCap); pn.setColor(d_shinyColor.lighter(l_const + fabs(value() * l_slope))); pn.setWidth(d_shineWidth * 2); p->setPen(pn); p->drawArc(aRect, 0, 360 * 16); // // draw button face // QRadialGradient gradient(size/2, size/2, size-d_borderWidth, size/2-d_borderWidth, size/2-d_borderWidth); gradient.setColorAt(0, d_curFaceColor.lighter(150)); gradient.setColorAt(1, d_curFaceColor.darker(150)); p->setBrush(gradient); p->setPen(Qt::NoPen); p->drawEllipse(aRect); // // draw marker // //drawMarker(p, d_angle, isEnabled() ? d_markerColor : Qt::gray); drawMarker(p, d_angle, pal.currentColorGroup() == QPalette::Disabled ? pal.color(QPalette::Disabled, QPalette::WindowText) : d_markerColor); }
void Knob::drawKnob(QPainter* p, const QRect& r) { QRect aRect; const QPalette& pal = palette(); QPen pn; int bw2 = d_borderWidth / 2; aRect.setRect(r.x() + bw2, r.y() + bw2, r.width() - 2 * bw2, r.height() - 2 * bw2); // // draw button face // // p->setPen(Qt::NoPen); // p->setBrush(d_curFaceColor); // p->drawEllipse(aRect); // // draw button shades // // pn.setWidth(d_borderWidth); // pn.setColor(pal.color(QPalette::Light)); // p->setPen(pn); // p->drawArc(aRect, 45*16,180*16); // pn.setColor(pal.color(QPalette::Dark)); // p->setPen(pn); // p->drawArc(aRect, 225*16,180*16); QPixmap dial; bool loaded; if (!knobImage.isEmpty()) { loaded = dial.load(knobImage); } else { loaded = dial.load(":images/knob.png"); } if (loaded) p->drawPixmap(aRect, dial); //printf("\n\n\nButton size is X:%d : Y:%d : W:%d : H:%d \n\n\n\n",aRect.x(), aRect.y(), aRect.width(), aRect.height()); // // draw marker // //drawMarker(p, d_angle, isEnabled() ? d_markerColor : Qt::gray); drawMarker(p, d_angle, pal.currentColorGroup() == QPalette::Disabled ? d_markerColorDisabled : d_markerColor); }
void Slider::draw(gcn::Graphics* graphics) { Color shadowColor = getBaseColor() - 0x101010; int alpha = getBaseColor().a; shadowColor.a = alpha; graphics->setColor(shadowColor); graphics->fillRectangle(gcn::Rectangle(0,0,getWidth(),getHeight())); drawMarker(graphics); }
void videoProcessor::draw(){ videoInput->draw(0, 0); for(int i=0;i<aruco.getNumMarkers();i++){ aruco.begin(i); drawMarker(0.15,ofColor::white); aruco.end(); } ofDrawBitmapString("topLeft" + ofToString(TL) , TL.x , TL.y); ofDrawBitmapString("topRight"+ ofToString(TR), TR.x , TR.y); ofDrawBitmapString("bottomLeft"+ ofToString(BL), BL.x , BL.y); ofDrawBitmapString("bottomRight"+ ofToString(BR), BR.x , BR.y); }
bool CWRuler::on_expose_event(GdkEventExpose * theEvent) { //cerr << "CWRuler::on_expose_event()" << endl; DrawingArea::on_expose_event(theEvent); _myWindow->clear(); if (_myMode == MODE_CENTER_WIDTH) { float myHWindowWidth = 0.5f * _myWindowWidth; int myXStart = convertValueToScreenPos(_myWindowCenter - myHWindowWidth); int myXEnd = convertValueToScreenPos(_myWindowCenter + myHWindowWidth); _myWindow->draw_rectangle(get_style()->get_dark_gc(get_state()), true, myXStart, 0, myXEnd - myXStart, get_allocation().get_height()); drawMarker(_myWindowCenter + myHWindowWidth, get_style()->get_white_gc()); drawMarker(_myWindowCenter - myHWindowWidth, get_style()->get_white_gc()); drawMarker(_myWindowCenter, get_style()->get_black_gc()); } else if (_myMode == MODE_LOWER_UPPER) { int myXStart = convertValueToScreenPos(_myLower); int myXEnd = convertValueToScreenPos(_myUpper); _myWindow->draw_rectangle(get_style()->get_dark_gc(get_state()), true, myXStart, 0, myXEnd - myXStart, get_allocation().get_height()); drawMarker(_myLower, get_style()->get_white_gc()); drawMarker(_myUpper, get_style()->get_white_gc()); } else if (_myMode == MODE_THRESHOLD) { drawMarker(_myWindowCenter, get_style()->get_black_gc()); } return true; }
void KXYSelector::paintEvent( QPaintEvent * /* ev */ ) { QStyleOptionFrame opt; opt.initFrom(this); QPainter painter; painter.begin( this ); drawContents( &painter ); drawMarker( &painter, d->px, d->py ); style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this ); painter.end(); }
/*! \brief Draw the knob \param painter painter \param r Bounding rectangle of the knob (without scale) */ void QwtKnob::drawKnob(QPainter *painter, const QRect &r) { #if QT_VERSION < 0x040000 const QBrush buttonBrush = colorGroup().brush(QColorGroup::Button); const QColor buttonTextColor = colorGroup().buttonText(); const QColor lightColor = colorGroup().light(); const QColor darkColor = colorGroup().dark(); #else const QBrush buttonBrush = palette().brush(QPalette::Button); const QColor buttonTextColor = palette().color(QPalette::ButtonText); const QColor lightColor = palette().color(QPalette::Light); const QColor darkColor = palette().color(QPalette::Dark); #endif const int bw2 = d_data->borderWidth / 2; const int radius = (qwtMin(r.width(), r.height()) - bw2) / 2; const QRect aRect( r.center().x() - radius, r.center().y() - radius, 2 * radius, 2 * radius); // // draw button face // painter->setBrush(buttonBrush); painter->drawEllipse(aRect); // // draw button shades // QPen pn; pn.setWidth(d_data->borderWidth); pn.setColor(lightColor); painter->setPen(pn); painter->drawArc(aRect, 45*16, 180*16); pn.setColor(darkColor); painter->setPen(pn); painter->drawArc(aRect, 225*16, 180*16); // // draw marker // if ( isValid() ) drawMarker(painter, d_data->angle, buttonTextColor); }
////////////////////////////////////////////////////////////////// // drawMenu // // // // Returns: // void // void drawMenu() { u8* pvmem; cpct_waitVSYNC(); cpct_memset(CPCT_VMEM_START, cpct_px2byteM0(0, 0), 0x4000); //Small Logo pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 23, 0); cpct_drawSprite(logo_micro, pvmem, 5, 18); drawText("AMSTHREES", 30, 4, 0); // Session Highest Card drawText("SESSION", 1, 57, 0); drawText("HIGH", 5, 72, 0); pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 7, 92); cpct_drawSprite(cards[highestCardAll], pvmem, CARD_W, CARD_H); drawFrame(23, 43, 76, 151); //Camelot Mode Badgae if (camelotMode) { pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 80 - G_CAMELOTBADGE_W, 8); cpct_drawSpriteMaskedAlignedTable(g_camelotBadge, pvmem, G_CAMELOTBADGE_W, G_CAMELOTBADGE_H, am_tablatrans); } drawText("REDEFINE", 38, 60, 0); drawText("MUSIC", 38, 80, 0); if (playing) drawText("OFF", 56, 80, 0); else drawText("ON", 56, 80, 0); drawText("HELP", 38, 100, 0); drawText("PLAY", 38, 120, 0); drawNumber(1, 1, 31, 60); drawNumber(2, 1, 31, 80); drawNumber(3, 1, 31, 100); drawNumber(4, 1, 31, 120); drawText("JOHN LOBO", 25, 170, 1); drawText("@ GLASNOST CORP 2016", 11, 185, 1); drawMarker(); }
void scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(selecting) { switch (tool) { case 0: drawEllipse(start,event->scenePos().toPoint()); break; case 1: drawLine(start,event->scenePos().toPoint()); break; case 2: drawRect(start,event->scenePos().toPoint()); break; case 3: drawMarker(event->scenePos().toPoint()); break; default: break; } } if(!handles.empty()) { int check=0; for(int i=0;i<handles.size();i++) { if(handles.at(i)->contains(event->scenePos())) check=i+1; } QPen pen; pen.setWidth(0); pen.setColor(Qt::red); for(int i=0;i<handles.size();i++) { handles.at(i)->setPen(pen); } if(check) { QPen pen; pen.setWidthF(penwidth); pen.setColor(Qt::green); handles.at(check-1)->setPen(pen); } } }
void caLinearGauge::drawScale(QPainter *p) { QVector<QLineF> lines; if (m_orientation == Qt::Horizontal) { qreal x1=0, y1=scalePos, wM=scaleSize, wm=wM*.5; QLineF majorTickLine(x1,y1,x1,y1-wM); qreal interval = 100.0/(m_numMajorTicks-1)/(m_numMinorTicks); /* distance between 2 minor ticks */ for (int i = 0; i < (m_numMajorTicks-1); i++) { lines << majorTickLine; QLineF minorTickLine(majorTickLine.x1(), majorTickLine.y1(), majorTickLine.x2(), majorTickLine.y1()-wm); for (int j = 0; j < (m_numMinorTicks-1); j++) { minorTickLine.translate(QPointF(interval,0)); lines << minorTickLine; } majorTickLine.translate(QPointF(100.0/(m_numMajorTicks-1),0)); } lines << majorTickLine; } else { qreal x1=scalePos, y1=0, wM=scaleSize, wm=wM*.5; QLineF majorTickLine(x1, y1, x1+wM, y1); qreal interval = 100.0/(m_numMajorTicks-1)/(m_numMinorTicks); /* distance between 2 minor ticks */ for (int i = 0; i < (m_numMajorTicks-1); i++) { lines << majorTickLine; QLineF minorTickLine(majorTickLine.x1(), majorTickLine.y1(), majorTickLine.x1()+wm, majorTickLine.y1()); for (int j = 0; j < (m_numMinorTicks-1); j++) { minorTickLine.translate(QPointF(0, interval)); lines << minorTickLine; } majorTickLine.translate(QPointF(0, 100.0/(m_numMajorTicks-1))); } lines << majorTickLine; } p->drawLines(lines); if (m_referenceEnabled) drawMarker(p, false); }
void caLinearGauge::paintEvent(QPaintEvent *) { QPainter painter(this); int size, w, h; QFontMetrics fm(painter.font()); h = fm.height()+2; w = fm.width(labels[longestLabelIndex])+2; if (m_orientation == Qt::Horizontal) { size = qMin((int)(width()*totalSize/100.0), height()); } else { size = qMin((int)(height()*totalSize/100.0), width()); } painter.setRenderHint(QPainter::Antialiasing); if (m_orientation == Qt::Horizontal) { painter.setViewport((int)((width()-size*100.0/totalSize)*.5),(int)((height()-size)*.5), (int)(size*100.0/totalSize), size); painter.setWindow((int)(-w*.5), 0, 100+w, totalSize+2); /* border */ } else { painter.setViewport((int)((width()-size)*.5),(int)((height()-size*100.0/totalSize)*.5), size, (int)(size*100.0/totalSize)); painter.setWindow(-2, (int)(-h*.5), totalSize+2, 100+h); /* border */ } painter.setViewport(0,0, width(), height()); // A.Mezger I do not like above behaviour when resizing drawColorBar(&painter); if (m_scaleEnabled) { drawScale(&painter); drawLabels(&painter); } if (isEnabled() && (m_fillMode == ALL)) drawMarker(&painter, true); if (!isEnabled()) { QColor c = palette().color(QPalette::Background); c.setAlpha(200); painter.fillRect(painter.window(), c); } }
void MapWidget::drawPlayersMarkers(QPainter &p) { if (mapPositions.isEmpty() && !markers.isEmpty()) updateMapPositionsCache(); QMap<int, QList<MapMarker>> map; for (const MapMarker &marker : markers) { Position position= findBestEllipsePositionForMarker(marker, markers, mapPositions); map[position.index].append(marker); } for (int i : map.keys()) { while (map[i].size() > 1) { const MapMarker &marker = map[i].takeLast(); QList<MapWidget::Position> emptyPositions = getEmptyPositions(map, mapPositions); MapWidget::Position newEmptyPosition = findBestEllipsePositionForMarker(marker, markers, emptyPositions); if (newEmptyPosition.index != i) { // avoid append the Position in same index and create an infinite loop if (map[newEmptyPosition.index].isEmpty()) // new position is really empty? map[newEmptyPosition.index].append(marker); else qCritical() << " new marker position is not empty: position " << newEmptyPosition.index; } else{ qCritical() << "Warning! The newPosition.index is not really a new position!"; } } } //finally drawing the markers for (int positionIndex : map.keys()) { if (!map[positionIndex].isEmpty()) { const MapMarker &marker = map[positionIndex].first(); if (positionIndex >= 0 && positionIndex < mapPositions.size()) { QPointF rectPosition = mapPositions.at(positionIndex).coords; QPointF markerPosition = getMarkerScreenCoordinate(marker); drawMarker(marker, p, markerPosition, rectPosition); } } } }
void WCartesianChart::renderLegendIcon(WPainter& painter, const WPointF& pos, const WDataSeries& series) const { switch (series.type()) { case BarSeries: { WPainterPath path; path.moveTo(-6, 8); path.lineTo(-6, -8); path.lineTo(6, -8); path.lineTo(6, 8); painter.setPen(series.pen()); painter.setBrush(series.brush()); painter.translate(pos.x() + 7.5, pos.y()); painter.drawPath(path); painter.translate(-(pos.x() + 7.5), -pos.y()); break; } case LineSeries: case CurveSeries: { painter.setPen(series.pen()); double offset = (series.pen().width() == 0 ? 0.5 : 0); painter.drawLine(pos.x(), pos.y() + offset, pos.x() + 16, pos.y() + offset); } // no break; case PointSeries: { WPainterPath path; drawMarker(series, path); if (!path.isEmpty()) { painter.translate(pos.x() + 8, pos.y()); painter.setPen(series.markerPen()); painter.setBrush(series.markerBrush()); painter.drawPath(path); painter.translate(- (pos.x() + 8), -pos.y()); } break; } } }
/*! Repaint the knob \param event Paint event */ void QwtKnob::paintEvent( QPaintEvent *event ) { QPainter painter( this ); painter.setClipRegion( event->region() ); QStyleOption opt; opt.init(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); painter.setRenderHint( QPainter::Antialiasing, true ); if ( !d_data->knobRect.contains( event->region().boundingRect() ) ) scaleDraw()->draw( &painter, palette() ); drawKnob( &painter, d_data->knobRect ); drawMarker( &painter, d_data->knobRect, d_data->angle ); painter.setRenderHint( QPainter::Antialiasing, false ); if ( hasFocus() ) QwtPainter::drawFocusRect( &painter, this ); }
void TooltipView:: drawMarkers() { Heightmap::Position p = model_->pos(); if (prev_pos_ != p && model_->comment) model_->comment->model()->pos = p; prev_pos_ = p; const Heightmap::FreqAxis& display_scale = render_view_->model->display_scale(); double fundamental_frequency = model_->pos_hz / model_->markers; for (unsigned i=1; i<=2*model_->markers || i <= 10; ++i) { float harmonic = fundamental_frequency * i; p.scale = display_scale.getFrequencyScalar( harmonic ); if (p.scale>=1) break; if (p.scale>=0) drawMarker( p ); } }
void Building::draw(int shadertype) { // increase counter (for counting visible objects) World::counter += 1; // using normal shader for object if ((shadertype == SHADER_NORMAL) || (shadertype == SHADER_REFLECTION) || (shadertype == SHADER_VIRTUAL)) { if (age < 100.0) { age = age + 0.04; } // get matrix glm::mat4 ModelMatrix = glm::scale(glm::mat4(1.0f),glm::vec3(1.0,age/100.0, 1.0)); glm::mat4 ViewMatrix = glm::translate(World::world->getView(), glm::vec3(Pos.x,Pos.y,Pos.z)); ViewMatrix = glm::rotate(ViewMatrix, r, glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 MVP = World::world->getProjection() * ViewMatrix * ModelMatrix; // get light information glm::vec3 LightPos = World::world->getLightPos(); // position of light glm::vec3 LightDif = World::world->getLightDif(); // diffuse color of light glm::vec3 LightAmb = World::world->getLightAmb(); // ambient color of light glm::vec3 LightSpec = World::world->getLightSpe(); // specular color of light // start shader program if ((Shader::runningProgram != shaderID) && (shadertype != SHADER_VIRTUAL)) { glUseProgram(shaderID); Shader::runningProgram = shaderID; } else { glUseProgram(virtualShaderID); Shader::runningProgram = virtualShaderID; glEnable(GL_BLEND); } // send matrix to shader glUniformMatrix4fv(glGetUniformLocation(shaderID, "MVP"), 1, GL_FALSE, &MVP[0][0]); glUniformMatrix4fv(glGetUniformLocation(shaderID, "M"), 1, GL_FALSE, &ModelMatrix[0][0]); glUniformMatrix4fv(glGetUniformLocation(shaderID, "V"), 1, GL_FALSE, &ViewMatrix[0][0]); glUniform3f(glGetUniformLocation(shaderID, "LightPosition_worldspace"), LightPos.x, LightPos.y, LightPos.z); glUniform3f(glGetUniformLocation(shaderID, "lightAmb"), LightAmb.x, LightAmb.y, LightAmb.z); glUniform3f(glGetUniformLocation(shaderID, "lightDif"), LightDif.x, LightDif.y, LightDif.z); glUniform3f(glGetUniformLocation(shaderID, "lightSpec"), LightSpec.x, LightSpec.y, LightSpec.z); glUniform1i(glGetUniformLocation(shaderID, "tex0"),0); // draw model mPool->drawModelByID(modelID[0]); if (shadertype == SHADER_VIRTUAL) glDisable(GL_BLEND); drawMarker(4.0); // draw marker } // using shader for shadows else if (shadertype == SHADER_SHADOW) { // get shadow matrix glm::mat4 ModelMatrix = glm::scale(glm::mat4(1.0f),glm::vec3(1.0,age/100.0, 1.0)); glm::mat4 ViewMatrix = glm::translate(World::world->getShadowView(), glm::vec3(Pos.x,Pos.y,Pos.z)); ViewMatrix = glm::rotate(ViewMatrix, r, glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 MVP = World::world->getShadowProjection() * ViewMatrix * ModelMatrix; if (Shader::runningProgram != shadowShaderID) { glUseProgram(shadowShaderID); Shader::runningProgram = shadowShaderID; } // send matrix to shader glUniformMatrix4fv(glGetUniformLocation(shadowShaderID, "depthMVP"), 1, GL_FALSE, &MVP[0][0]); glUniform1i(glGetUniformLocation(shadowShaderID, "tex0"),0); mPool->drawModelByID(modelID[0]); //glUseProgram(0); } }
void displayUISettings() { // getting window dimensions GLshort w=glutGet(GLUT_WINDOW_WIDTH); uiS.height=glutGet(GLUT_WINDOW_HEIGHT); GLshort percUnitW = w/100; GLshort percUnitH = uiS.height/100; glDisable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); //to prepare for return to 3D glLoadIdentity(); gluOrtho2D(0,w,0,uiS.height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //UI background 20% of screen gap from edges glColor3f(1,1,1); //white glBegin(GL_QUADS); glVertex2s(percUnitW*20,percUnitH*20); glVertex2s(w-percUnitW*20,percUnitH*20); glVertex2s(w-percUnitW*20,uiS.height-percUnitH*20); glVertex2s(percUnitW*20,uiS.height-percUnitH*20); glEnd(); glColor3f(0,0,1); displayText("SETTINGS:", percUnitW*22, percUnitH*78, 'l'); //draw chosen colour if not random if(!tmpState.colourRand){ uiS.chosenClr[0] = percUnitW*25; uiS.chosenClr[1] = percUnitH*55; glColor3fv(tmpState.colour); glBegin(GL_QUADS); glVertex2sv(uiS.chosenClr); glVertex2s(uiS.chosenClr[0]+20, uiS.chosenClr[1]); glVertex2s(uiS.chosenClr[0]+20, uiS.chosenClr[1]+20); glVertex2s(uiS.chosenClr[0], uiS.chosenClr[1]+20); glEnd(); displayText("Chosen Colour", uiS.chosenClr[0]+25, uiS.chosenClr[1]+2, 'm'); } //for colourpicker triangle drawColourPicker(percUnitW, percUnitH); //check box for selection of random colour uiS.randClr[0]=percUnitW*35; uiS.randClr[1]=percUnitH*55; drawCheckBox(uiS.randClr[0],uiS.randClr[1],"Random Colour"); //if random colour selected draw cross if(tmpState.colourRand){ drawCheck(uiS.randClr[0],uiS.randClr[1]); } //for selection of angle: draw a box then distribute evenly within 9 circles of radius 10, in 3 rows of 3, filled in for chosen angle drawAnglePresets(percUnitW, percUnitH); //check box for selection of random angle uiS.randAng[0] = percUnitW*60; uiS.randAng[1] = percUnitH*55; drawCheckBox(uiS.randAng[0], uiS.randAng[1] ,"Random Angle"); //slider bar for selection of lift charge/intial velocity uiS.velocityL[0]= percUnitW*23; uiS.velocityL[1]= percUnitH*42; uiS.velocityR[0]= percUnitW*65; uiS.velocityR[1]= percUnitH*42; snprintf(uiS.velocityMnTxt, 6, "%4.1f", tmpState.velocityMin); snprintf(uiS.velocityMxTxt, 6, "%4.1f", tmpState.velocityMax); displayText("Lift Charge giving initial velocity in m/s:", uiS.velocityL[0]-20, uiS.velocityL[1]+15, 'm'); drawSlider(uiS.velocityL, uiS.velocityR); displayText(uiS.velocityMnTxt, uiS.velocityL[0]-30, uiS.velocityL[1]-4, 'm'); displayText(uiS.velocityMxTxt, uiS.velocityR[0]+5, uiS.velocityR[1]-4, 'm'); //x coords of chosen velocity determined by (chosenValue - minValue)*((xRight - xLeft)/(maxValue-minValue)) + xLeft uiS.velocityChX = ((tmpState.velocityCh - tmpState.velocityMin)*(((float)uiS.velocityR[0]-(float)uiS.velocityL[0])/(tmpState.velocityMax-tmpState.velocityMin))+(float)uiS.velocityL[0]); drawMarker(uiS.velocityChX, uiS.velocityL[1]); snprintf(uiS.velocityChTxt, 6, "%3.1f", tmpState.velocityCh); displayText(uiS.velocityChTxt, uiS.velocityChX-10, uiS.velocityL[1]-17, 'm'); //slider bar for selection of fuser timer uiS.fuseL[0]= percUnitW*23; uiS.fuseL[1]= percUnitH*32; uiS.fuseR[0]= percUnitW*65; uiS.fuseR[1]= percUnitH*32; snprintf(uiS.fuseMnTxt, 6, "%5.1f", tmpState.fuseMin); snprintf(uiS.fuseMxTxt, 6, "%5.1f", tmpState.fuseMax); displayText("Fuse timer from launch to explosion in milliseconds:", uiS.fuseL[0]-20, uiS.fuseL[1]+15, 'm'); drawSlider(uiS.fuseL, uiS.fuseR); displayText(uiS.fuseMnTxt, uiS.fuseL[0]-40, uiS.fuseL[1]-4, 'm'); displayText(uiS.fuseMxTxt, uiS.fuseR[0]+5, uiS.fuseR[1]-4, 'm'); //x coords of chosen fuse determined by (chosenValue - minValue)*((xRight - xLeft)/(maxValue-minValue)) + xLeft uiS.fuseChX = ((tmpState.fuseCh - tmpState.fuseMin)*(((float)uiS.fuseR[0]-(float)uiS.fuseL[0])/(tmpState.fuseMax-tmpState.fuseMin))+(float)uiS.fuseL[0]); drawMarker(uiS.fuseChX, uiS.fuseL[1]); snprintf(uiS.fuseChTxt, 6, "%5.1f", tmpState.fuseCh); displayText(uiS.fuseChTxt, uiS.fuseChX-10, uiS.fuseL[1]-17, 'm'); //save button uiS.saveBL[0] = percUnitW*70; uiS.saveBL[1] = percUnitH*31; uiS.saveTR[0] = percUnitW*79; uiS.saveTR[1] = percUnitH*39; glColor3f(0, 0.5, 0); glBegin(GL_QUADS); glVertex2sv(uiS.saveBL); glVertex2s(uiS.saveTR[0], uiS.saveBL[1]); glVertex2sv(uiS.saveTR); glVertex2s(uiS.saveBL[0], uiS.saveTR[1]); glEnd(); displayText("Save", uiS.saveBL[0]+5, uiS.saveBL[1]+5,'l'); //underline S glLineWidth(2); glBegin(GL_LINES); glVertex2s(uiS.saveBL[0]+6,uiS.saveBL[1]+3); glVertex2s(uiS.saveBL[0]+18,uiS.saveBL[1]+3); glEnd(); glLineWidth(1); //cancel button uiS.cancelBL[0] = percUnitW*70; uiS.cancelBL[1] = percUnitH*22; uiS.cancelTR[0] = percUnitW*79; uiS.cancelTR[1] = percUnitH*30; glColor3f(0.6, 0, 0); glBegin(GL_QUADS); glVertex2sv(uiS.cancelBL); glVertex2s(uiS.cancelTR[0], uiS.cancelBL[1]); glVertex2sv(uiS.cancelTR); glVertex2s(uiS.cancelBL[0], uiS.cancelTR[1]); glEnd(); displayText("Cancel", uiS.cancelBL[0]+5, uiS.cancelBL[1]+5,'l'); //underline C glLineWidth(2); glBegin(GL_LINES); glVertex2s(uiS.cancelBL[0]+6,uiS.cancelBL[1]+3); glVertex2s(uiS.cancelBL[0]+18,uiS.cancelBL[1]+3); glEnd(); glLineWidth(1); // returning to 3D glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); }
void Hruler::paintEvent(QPaintEvent *e) { if (m_doc->isLoading()) return; QString tx = ""; double sc = m_view->scale(); Scaling = sc; QFont ff = font(); ff.setPointSize(6); setFont(ff); QPainter p; p.begin(this); p.setClipRect(e->rect()); p.setFont(font()); drawMarks(p); if (textEditMode) { int rectX1 = textPosToLocal(Extra); int rectX2 = textPosToLocal(ItemEndPos-ItemPos-RExtra); p.eraseRect(QRect(QPoint(rectX1, 1), QPoint(rectX2, 15))); p.drawLine(rectX1, 16, rectX2, 16); p.save(); p.setRenderHints(QPainter::Antialiasing, true); if (Revers) { p.translate( textPosToLocal(0), 0); p.scale(-1, 1); p.translate( textPosToLocal(Extra) - textPosToLocal(ItemEndPos-ItemPos-RExtra), 0); p.translate(-textPosToLocal(0), 0); } for (int CurrCol = 0; CurrCol < Cols; ++CurrCol) { double ColWidth = (textWidth() - ColGap * (Cols - 1)) / Cols; double Pos = (ColWidth + ColGap) * CurrCol; double EndPos = Pos + ColWidth; drawTextMarks(Pos, EndPos, p); p.setPen(QPen(Qt::blue, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); int xPos = textPosToLocal(Pos); p.drawLine(xPos, topline, xPos, bottomline); if (CurrCol == 0) { p.drawLine(xPos, 15, (xPos+4), 15); p.drawLine(xPos, topline, (xPos+4), topline); } p.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); xPos = textPosToLocal(Pos+First+Indent); QPolygon cr; cr.setPoints(3, xPos, midline, xPos+3, topline, xPos-3, topline); p.drawPolygon(cr); xPos = textPosToLocal(Pos+Indent); QPolygon cr2; cr2.setPoints(3, xPos, midline, xPos+3, bottomline, xPos-3, bottomline); p.drawPolygon(cr2); xPos = textPosToLocal(Pos+RMargin); QPolygon cr3; cr3.setPoints(3, xPos, topline, xPos, bottomline, xPos-3, midline); p.drawPolygon(cr3); if (TabValues.count() != 0) { p.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); for (int yg = 0; yg < signed(TabValues.count()); yg++) { xPos = textPosToLocal(Pos+TabValues[yg].tabPosition); if (Pos+TabValues[yg].tabPosition < EndPos) { switch (static_cast<int>(TabValues[yg].tabType)) { case 0: if (Revers) { p.save(); p.translate(Pos + TabValues[yg].tabPosition,0); p.scale(-1,1); p.drawLine(0, tabline, 0, bottomline); p.drawLine(0, bottomline, 8, bottomline); p.restore(); } else { p.drawLine(xPos, tabline, xPos, bottomline); p.drawLine(xPos, bottomline, xPos+8, bottomline); } break; case 1: if (Revers) { p.save(); p.translate(Pos+TabValues[yg].tabPosition,0); p.scale(-1,1); p.drawLine(0, tabline, 0, bottomline); p.drawLine(0, bottomline, -8, bottomline); p.restore(); } else { p.drawLine(xPos, tabline, xPos, bottomline); p.drawLine(xPos, bottomline, xPos-8, bottomline); } break; case 2: case 3: p.drawLine(xPos, tabline, xPos, bottomline); p.drawLine(xPos-4, bottomline, xPos+4, bottomline); p.drawLine(xPos+3, bottomline-3, xPos+2, bottomline-3); break; case 4: p.drawLine(xPos, tabline, xPos, bottomline); p.drawLine(xPos-4, bottomline, xPos+4, bottomline); break; default: break; } } } } p.setPen(QPen(Qt::blue, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); xPos = textPosToLocal(EndPos); p.drawLine(xPos, topline, xPos, bottomline); if (CurrCol == Cols-1) { p.drawLine(xPos, bottomline, xPos-4 , bottomline); p.drawLine(xPos, topline, xPos-4, topline); } } p.restore(); } if (drawMark && !Mpressed) { drawMarker(p); } p.end(); }
void EvolutionGraphWidget::paintEvent( QPaintEvent* event ) { if (!m_keyColletion && dataLoad) return; event->accept(); QPainter paint(this); QMatrix m; m.translate(0.0, static_cast<float>(height())-1); m.scale(1.f, -1.f); paint.setMatrix(m); paint.setMatrixEnabled(true); paint.setRenderHint(QPainter::Antialiasing, false); paint.setPen(Qt::NoPen); paint.setBrush(QColor(40,40,40)); //0.156863, 0.156863, 0.156863 paint.drawRect(0, 0, width() - 1, height() - 1); ////////////////////////////////////////////////////////////////////////// // draw path paint.setPen(QColor(220, 220, 220)); paint.setRenderHint(QPainter::Antialiasing, false); Vector2f pmin = Vector2f(m_xRange.x, m_yRange.x); //相对坐标的范围 m_xRange(0.f, 1.f), m_yRange(0.f, 1.f) Vector2f pmax = Vector2f(m_xRange.y, m_yRange.y); int xgridNum = m_gridSpacingNum.x; int ygridNum = m_gridSpacingNum.y; m_gridSpacing.x = (pmax.x - pmin.x) / (m_timeNum+1); //xgridNum m_gridSpacing.y = (pmax.y - pmin.y) / ygridNum; float fx,fy; int h,hy; float m_xTimeSpacing=(pmax.x - pmin.x)/float(m_timeNum+1); ////////////////////////////////////////////////////////////////////////// //draw grid // draw grid paint.setPen(QColor(70, 70, 70)); paint.setRenderHint(QPainter::Antialiasing, false); int num = 0; for (float f=pmin.x; f<pmax.x-m_xTimeSpacing*0.5; f+=m_xTimeSpacing, ++num) { Vector2f p = wtos(Vector2f(f, 0.f)); Vector2f a = wtos(Vector2f(0.f, 0.f)); Vector2f b = wtos(Vector2f(0.f, 1.f)); //width() - m_iPadding paint.drawLine(QPointF(p.x, a.y),QPointF(p.x, b.y)); paint.scale(-1.f, 1.f); paint.rotate(180.f); QString strval = QString::number((int)(num)); paint.setPen(Qt::gray); if (num % 2 == 0) paint.drawText(static_cast<int>(p.x ), static_cast<int>(-0.7 * (m_iBottomSpace)), strval); else paint.drawText(static_cast<int>(p.x ), static_cast<int>(-0.45 * (m_iBottomSpace)), strval); paint.setPen(QColor(70, 70, 70)); paint.rotate(180.f); paint.scale(-1.f, 1.f); } paint.setPen(QColor(220, 220, 220)); //for (float f=pmin.y; f<pmax.y+m_gridSpacing.y*0.5; f+=m_gridSpacing.y) //{ // Vector2f p = wtos(Vector2f(0.f, f)); // Vector2f a = wtos(Vector2f(0.f, 0.f)); // Vector2f b = wtos(Vector2f(1.f, 0.f)); // paint.drawLine(QPointF(a.x, p.y), // QPointF(b.x, p.y)); //} //float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_arryNumFeature[]+1); //// 绘制路径 line //for (fy=m_yTimeSpacing,hy=0;hy<m_pathNum;++hy,fy+=m_yTimeSpacing) //{ // // //cout<<"cluster end:"<<*(pathInfo[hy].end()-1)<<endl; // fx=pmin.x+m_xTimeSpacing*startID;// here is the difference // // Vector2f y = wtos(Vector2f(1.f, fy)); // paint.setPen(QColor(113,189,232)); // paint.drawLine(QPointF(a.x, y.y), QPointF(a.y, y.y)); //} // //cout<<"m_curTimeStep"<<m_curTimeStep<<endl; ////////////////////////////////////////////////////////////////////////// //draw graph edge float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_arryNumFeature[0]+1); fx=m_xTimeSpacing; for (int timeStep=0; timeStep<m_timeNum;fx+=m_xTimeSpacing,timeStep++) { fy=m_yTimeSpacing; Vector2f node1X = wtos(Vector2f(fx, 0.f)); Vector2f node2X = wtos(Vector2f(fx+m_xTimeSpacing, 0.f)); m_keyColletion=m_keyColletionFull[timeStep]; int edgeSum=0; //std::cout<<"i:"<<timeStep<<"m_arryNumFeature:"<<int(m_arryNumFeature[timeStep+1])<<std::endl; //std::cout<<"i:"<<timeStep<<"m_keyColletion:"<<int(m_keyColletion->getNumKeys())<<std::endl; for (int yNum=0;yNum<m_arryNumFeature[timeStep+1];fy+=m_yTimeSpacing,yNum++) { Vector2f node1Y = wtos(Vector2f(1.f, fy)); edgeSum=dag.graph[timeStep][yNum].edgeSum; struct edgenode *p; p=dag.graph[timeStep][yNum].first; while (p!=NULL) { Vector2i nodeIndex=p->no; Vector2f node2Y = wtos(Vector2f(0.0, m_yTimeSpacing+ nodeIndex.y*m_yTimeSpacing)); paint.setPen(QColor(70, 70, 70)); paint.drawLine(QPointF(node1X.x, node1Y.y), QPointF(node2X.x, node2Y.y)); p=p->next; } } } ////////////////////////////////////////////////////////////////////////// //draw new add edge //m_newAddEdge ////////////////////////////////////////////////////////////////////////// //draw path // 绘制路径 line fx=m_xTimeSpacing; fy=m_yTimeSpacing; for (int i=0;i<dag.m_pathInfo.size();i++) { vector<Vector2i> onePahth=dag.m_pathInfo[i]; for (int j=0;j<onePahth.size()-1;j++)// 一条路径的长度 { float x1= fx + m_xTimeSpacing * onePahth[j].x; float x2= fx + m_xTimeSpacing * onePahth[j+1].x; float y1= fy + m_yTimeSpacing * onePahth[j].y; float y2= fy + m_yTimeSpacing * onePahth[j+1].y; Vector2f node1 = Vector2f( x1 ,y1); Vector2f node2 = Vector2f( x2 ,y2); node1 = wtos( node1 ) ; node2 = wtos( node2 ); paint.setPen(QColor(220,220,220)); paint.drawLine(QPointF(node1.x, node1.y), QPointF(node2.x, node2.y)); } } ////////////////////////////////////////////////////////////////////////// //draw marker fx=m_xTimeSpacing; for (int timeStep=0; timeStep<m_timeNum;fx+=m_xTimeSpacing,timeStep++) { float m_yTimeSpacing=(pmax.y - pmin.y)/float(m_arryNumFeature[0]+1); fy=m_yTimeSpacing; Vector2f p = wtos(Vector2f(fx, 0.f)); m_keyColletion=m_keyColletionFull[timeStep]; //std::cout<<"i:"<<timeStep<<"m_arryNumFeature:"<<int(m_arryNumFeature[timeStep+1])<<std::endl; //std::cout<<"i:"<<timeStep<<"m_keyColletion:"<<int(m_keyColletion->getNumKeys())<<std::endl; for (int yNum=0;yNum<m_arryNumFeature[timeStep+1];fy+=m_yTimeSpacing,yNum++) { TFMappingKey *key = m_keyColletion->getKey(yNum); int props; props = MARKER_NORMAL; if (key == m_pSelectedKey) { //std::cout<<"i:"<<timeStep<<"yNum:"<<yNum<<"key:"<<key<<"m_pSelectedKey:"<<m_pSelectedKey<<::endl; props |= MARKER_SELECTED; } Vector2f y = wtos(Vector2f(1.f, fy)); drawMarker(paint, key->getColor(),Vector2f(p.x, y.y),props); // key->getColor() } } ////////////////////////////////////////////////////////////////////////// //draw a square to show a feature's attribute paint.setPen(Qt::gray); paint.setBrush(QColor(40,40,40)); //0.156863, 0.156863, 0.156863 Vector2f bottom=wtos(Vector2f(0.7f, 0.8f)); Vector2f top=wtos(Vector2f(1.f, 1.f)); paint.drawRect(bottom.x, bottom.y, (width() - m_iPadding)*0.27, (height() - m_iPadding)*0.17); //xy wh //paint.scale(-1.f, 1.f); //paint.rotate(180.f); QString m_FeatureNo; QString m_CentroidText; QString m_VolumeText; QString m_MassText; vector <QString> attribute; m_FeatureNo.sprintf("%s %d %d ","Feature index: ",m_curTimeStep,m_clusterNumSelected); m_CentroidText.sprintf("%s %.0lf %.0lf %.0lf ","Centroid: ", dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].centroid.x, dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].centroid.y, dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].centroid.z);// m_VolumeText.sprintf("%s %.0lf ","Volume: ", dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].volume);//0);// m_MassText.sprintf("%s %.0lf","Mass: ", dag.m_FeatureInfo[m_curTimeStep][m_clusterNumSelected].mass);//);// attribute.push_back(m_FeatureNo); attribute.push_back(m_CentroidText); attribute.push_back(m_VolumeText); attribute.push_back(m_MassText); paint.setPen(Qt::gray); paint.setBrush(Qt::NoBrush); float yWide=(height() - m_iPadding)*0.17 /6.0; paint.scale(-1.f, 1.f); paint.rotate(180.f); for (int i=0;i<4;i++) { //x is the same // y yBase+i*wide; float x=bottom.x; float y=bottom.y+float(i+1)*yWide; paint.drawText( x+1.5f * m_iPadding,-y,attribute[i]); } paint.rotate(180.f); paint.scale(-1.f, 1.f); // paint.drawText(static_cast<int>(width() - 5.5f * m_iPadding), static_cast<int>(-1 * (origin.y - 0.8 * m_iBottomSpace)), m_CentroidText); //paint.drawText(static_cast<int>(1.6f * m_iPadding), static_cast<int>(-1 * (height() - 1.85f * m_iPadding)), m_yAxisText); ////////////////////////////////////////////////////////////////////////// // draw x and y axes paint.setRenderHint(QPainter::Antialiasing, true); paint.setPen(Qt::gray); paint.setBrush(Qt::gray); // draw axes independently from visible range float oldx0_ = m_xRange[0]; float oldx1_ = m_xRange[1]; m_xRange[0] = 0.f; m_xRange[1] = 1.f; Vector2f origin = wtos(Vector2f(0.f, 0.f)); origin.x = floor(origin.x) + 0.5f; origin.y = floor(origin.y) + 0.5f; paint.setRenderHint(QPainter::Antialiasing, true); paint.drawLine(QPointF(m_iPadding, origin.y), QPointF(width() - m_iPadding, origin.y)); paint.drawLine(QPointF(origin.x, m_iBottomSpace), QPointF(origin.x, height() - m_iPadding)); ////////////////////////////////////////////////////////////////////////// // draw arrows QPointF arrow[3]; arrow[0] = QPointF(origin.x, height() - m_iPadding); arrow[1] = QPointF(origin.x + m_iArrowWidth, height() - m_iPadding - m_iArrowLength); arrow[2] = QPointF(origin.x - m_iArrowWidth, height() - m_iPadding - m_iArrowLength); paint.drawConvexPolygon(arrow, 3); arrow[0] = QPointF(width() - m_iPadding, origin.y); arrow[1] = QPointF(width() - m_iPadding - m_iArrowLength, origin.y - m_iArrowWidth); arrow[2] = QPointF(width() - m_iPadding - m_iArrowLength, origin.y + m_iArrowWidth); paint.drawConvexPolygon(arrow, 3); paint.scale(-1.f, 1.f); paint.rotate(180.f); paint.drawText(static_cast<int>(width() - 5.5f * m_iPadding), static_cast<int>(-1 * (origin.y - 0.8 * m_iBottomSpace)), m_xAxisText); paint.drawText(static_cast<int>(1.6f * m_iPadding), static_cast<int>(-1 * (height() - 1.85f * m_iPadding)), m_yAxisText); paint.rotate(180.f); paint.scale(-1.f, 1.f); m_xRange[0] = oldx0_; m_xRange[1] = oldx1_; paint.setRenderHint(QPainter::Antialiasing, false); paint.setPen(Qt::lightGray); paint.setBrush(Qt::NoBrush); paint.drawRect(0, 0, width() - 1, height() - 1); paint.setMatrixEnabled(false); //m_MoveSelected.clear(); //m_sequenceSelected=-1; //setupTransfunc(); }
void KDChartLinesPainter::specificPaintData( QPainter* painter, const QRect& /*ourClipRect*/, KDChartTableDataBase* data, KDChartDataRegionList* regions, const KDChartAxisParams* ordinatePara, bool /*bNormalMode*/, uint chart, double logWidth, double /*areaWidthP1000*/, double logHeight, double axisYOffset, double minColumnValue, double maxColumnValue, double columnValueDistance, uint /*chartDatasetStart*/, uint /*chartDatasetEnd*/, uint datasetStart, uint datasetEnd ) { if( !data ) return; abscissaInfos ai; ai.bCenterThePoints = mCenterThePoints; calculateAbscissaInfos( *params(), *data, datasetStart, datasetEnd, logWidth, _dataRect, ai ); mCenterThePoints = ai.bCenterThePoints; bool bOrdinateDecreasing = ordinatePara ? ordinatePara->axisValuesDecreasing() : false; bool bOrdinateIsLogarithmic = ordinatePara ? (KDChartAxisParams::AxisCalcLogarithmic == ordinatePara->axisCalcMode()) : false; //const double ordinatePixelsPerUnit = logHeight / columnValueDistance; const double ordinatePixelsPerUnit = ( ordinatePara && (0.0 != ordinatePara->trueAxisDeltaPixels()) && (0.0 != ordinatePara->trueAxisDelta())) ? ordinatePara->trueAxisDeltaPixels() / ordinatePara->trueAxisDelta() : logHeight / columnValueDistance;; //qDebug("ordinatePixelsPerUnit: %f",ordinatePixelsPerUnit); const bool showThreeDLines = !mIsArea && params()->threeDLines(); enum { Normal, Stacked, Percent } mode = Normal; if ( ( ( mChartType == KDChartParams::Line ) && ( params()->lineChartSubType() == KDChartParams::LineNormal ) ) || ( ( mChartType == KDChartParams::Area ) && ( params()->areaChartSubType() == KDChartParams::AreaNormal ) ) ) mode = Normal; else if ( ( ( mChartType == KDChartParams::Line ) && ( params()->lineChartSubType() == KDChartParams::LineStacked ) ) || ( ( mChartType == KDChartParams::Area ) && ( params()->areaChartSubType() == KDChartParams::AreaStacked ) ) ) mode = Stacked; else if ( ( ( mChartType == KDChartParams::Line ) && ( params()->lineChartSubType() == KDChartParams::LinePercent ) ) || ( ( mChartType == KDChartParams::Area ) && ( params()->areaChartSubType() == KDChartParams::AreaPercent ) ) ) mode = Percent; else qDebug( "Internal error in KDChartLinesPainter::paintDataInternal(): Unknown subtype" ); QMap < int, double > currentValueSums; if ( mode == Stacked || mode == Percent ) { // this array is only used for stacked and percent lines, no need // to waste time initializing it for normal types for ( int value = 0; value < ai.numValues; ++value ) currentValueSums[ value ] = 0.0; } QMap < int, double > totalValueSums; // compute the position of the 0 axis double zeroXAxisI; if ( mode == Percent ) { if ( minColumnValue == 0.0 ) zeroXAxisI = logHeight + axisYOffset; else if( maxColumnValue == 0.0 ) zeroXAxisI = _dataRect.y() + axisYOffset; else zeroXAxisI = logHeight / 2.0 + _dataRect.y(); } else zeroXAxisI = ordinatePara->axisZeroLineStartY() - _dataRect.y(); // compute how to shift of the points in case we want them in the // middle of their respective columns int xShift = mCenterThePoints ? static_cast < int > ( ai.pointDist * 0.5 ) : 0; // calculate all points' positions // =============================== int arrayNumDatasets = 0; int arrayNumValues = ai.bAbscissaHasTrueAxisDtValues ? data->cols() : ai.numValues; int dataset; for( dataset = datasetEnd; ( dataset >= static_cast < int > ( datasetStart ) && dataset >= 0 ); --dataset ) ++arrayNumDatasets; #if COMPAT_QT_VERSION >= 0x030000 QValueVector<MyPoint> allPoints( #else QArray<MyPoint> allPoints( #endif arrayNumDatasets * arrayNumValues ); KDChartPropertySet curPropSet; int curPropSetId = KDChartPropertySet::UndefinedID; for( dataset = datasetEnd; ( dataset >= (int)datasetStart && dataset >= 0 ); --dataset ) { int prevPointX = -1; int prevPointY = -1; const KDChartParams::LineMarkerStyle defaultMarkerStyle = params()->lineMarkerStyle( dataset ); const QPen default2DPen( params()->lineColor().isValid() ? params()->lineColor() : params()->dataColor( dataset ), params()->lineWidth(), params()->lineStyle( dataset ) ); if( ai.bAbscissaHasTrueAxisDtValues ) ai.numValues = data->cols(); QVariant vValY; QVariant vValX; int cellPropID; for( int value = 0; value < ai.numValues; ++value ) { //if ( mode == Percent ) // valueTotal = data->colAbsSum( value ); double valueTotal = 0.0; // Will only be used for Percent if( mode == Percent ) { valueTotal = 0.0; // iterate over datasets of this axis only: for ( uint dataset2 = datasetStart; dataset2 <= datasetEnd; ++dataset2 ) { if( data->cellCoord( dataset2, value, vValY, 1 ) && QVariant::Double == vValY.type() ) valueTotal += vValY.toDouble(); } } if( data->cellContent( dataset, value, vValY, vValX, cellPropID ) && QVariant::Double == vValY.type() && ( !ai.bCellsHaveSeveralCoordinates || QVariant::Invalid != vValX.type() ) ){ //qDebug("a. cellPropID: %i",cellPropID); // calculate Ordinate axis value // ----------------------------- double cellValue = vValY.toDouble(); double drawValue = 0.0; // PENDING(kalle) This does not work for AreaPercent yet if ( mode == Stacked ) drawValue = ( cellValue + currentValueSums[ value ] ) * ordinatePixelsPerUnit; else if ( mode == Percent ) drawValue = ( ( cellValue + currentValueSums[ value ] ) / valueTotal ) * 100.0 * ordinatePixelsPerUnit; else { // LineNormal or AreaNormal if( bOrdinateIsLogarithmic ){ if( 0.0 < cellValue ) drawValue = log10( cellValue ) * ordinatePixelsPerUnit; else drawValue = -10250.0; //qDebug("\nlogarithmic calc - cellValue: %f drawValue: %f", // cellValue, drawValue ); }else{ drawValue = cellValue * ordinatePixelsPerUnit * (bOrdinateDecreasing ? -1.0 : 1.0); //qDebug("\nlinear calc - cellValue: %f\n - drawValue: %f", // cellValue, drawValue ); } } // calculate Abscissa axis value // ----------------------------- double xValue; bool skipMe = !calculateAbscissaAxisValue( vValX, ai, value, xValue ); // calculate and store the point and region / draw the marker // ---------------------------------------------------------- if( !skipMe ){ // prevent the point from being toooo far // below the bottom (or above the top, resp.) // of the cliprect double pY = QMIN( zeroXAxisI - drawValue, (logHeight + axisYOffset) * 3 ); pY = QMAX( pY, -(logHeight + axisYOffset) * 3 ); // specify the Point int myPointX = static_cast < int > ( xValue ) + xShift; int myPointY = static_cast < int > ( pY ); if( cellPropID == curPropSetId && myPointX == prevPointX && myPointY == prevPointY ){ allPoints[ static_cast < int > ( datasetEnd-dataset ) * arrayNumValues + value ].setSkipThis( true ); skipMe = true; //qDebug("skipped"); }else{ // use typecast to make it compile on windows using qt232 allPoints[ static_cast < int > ( datasetEnd-dataset ) * arrayNumValues + value ].set( myPointX, myPointY, cellValue ); //qDebug("ok"); } if( !skipMe ){ // -------------------------------------------------------- // determine any 'extra' properties assigned to this cell // by traversing the property set chain (if necessary) // -------------------------------------------------------- if( cellPropID != curPropSetId ){ //qDebug("b. ( curPropSetId: %i )",curPropSetId); //qDebug("b. cellPropID: %i",cellPropID); //qDebug(curPropSet.name().latin1()); if( cellPropID != KDChartPropertySet::UndefinedID && params()->calculateProperties( cellPropID, curPropSet ) ){ curPropSetId = cellPropID; //qDebug("c. curPropSetId: %i",curPropSetId); //qDebug(curPropSet.name().latin1()); }else{ curPropSetId = KDChartPropertySet::UndefinedID; } } // make sure any extra horiz. and/or vert. lines and/or markers // are drawn *before* the data lines and/or markers are painted if( mChartType == KDChartParams::Line ){ if( curPropSetId != KDChartPropertySet::UndefinedID ){ drawExtraLinesAndMarkers( curPropSet, default2DPen, defaultMarkerStyle, myPointX, myPointY, painter, ai.abscissaPara, ordinatePara, logWidth/1000.0, logHeight/1000.0, false ); } } prevPointX = myPointX; prevPointY = myPointY; } } // calculate running sum for stacked and percent if ( mode == Stacked || mode == Percent ) { if( cellValue == KDCHART_POS_INFINITE ) currentValueSums[ value ] = KDCHART_POS_INFINITE; else if( currentValueSums[ value ] != KDCHART_POS_INFINITE ) currentValueSums[ value ] += cellValue; } } } } QPointArray previousPoints; // no vector since only areas need it, // and these do not support 3d yet // Store some (dataset-independend) default values // to be used unless other properties // have been specified for the respective data cell: // const bool defaultDrawMarkers = mDrawMarkers; for ( dataset = datasetEnd; ( dataset >= (int)datasetStart && dataset >= 0 ); --dataset ) { // Store some (dataset-dependend) default values // to be used unless other properties // have been specified for the respective data cell: // const QPen default2DPen( params()->lineColor().isValid() ? params()->lineColor() : params()->dataColor( dataset ), params()->lineWidth(), params()->lineStyle( dataset ) ); bool currentDrawMarkers = defaultDrawMarkers; const KDChartParams::LineMarkerStyle markerStyle = params()->lineMarkerStyle( dataset ); // the +2 is for the areas (if any) QPtrVector< QPointArray > points( 2 ); points.setAutoDelete( true ); /* Pending Michel - we need to keep track of the * non rotated points for 3D lines */ QPtrVector< QPointArray > oripoints( 2 ); oripoints.setAutoDelete( true ); int i = 0; for( i = 0; i < 2; ++i ) { points.insert( i, new QPointArray( ai.numValues + 2 ) ); oripoints.insert( i, new QPointArray( ai.numValues + 2 ) ); } if( ai.bAbscissaHasTrueAxisDtValues ) ai.numValues = data->cols(); int point = 0; for ( int value = 0; value < ai.numValues; ++value ) { // determine and store marker properties assigned to this cell // ----------------------------------------------------------- currentDrawMarkers = defaultDrawMarkers; int cellPropID; if( data->cellProp( dataset, value, cellPropID ) && cellPropID != curPropSetId ){ if( cellPropID != KDChartPropertySet::UndefinedID && params()->calculateProperties( cellPropID, curPropSet ) ) curPropSetId = cellPropID; else curPropSetId = KDChartPropertySet::UndefinedID; } if( curPropSetId != KDChartPropertySet::UndefinedID ){ // we can safely call the following functions and ignore their // return values since they will touch the parameters' values // if the propSet *contains* corresponding own values only. int iDummy; curPropSet.hasOwnShowMarker( iDummy, currentDrawMarkers ); } int iVec = static_cast < int > ( datasetEnd-dataset ) * arrayNumValues + value; if( allPoints[ iVec ].bValid && !allPoints[ iVec ].bSkipThis ){ const MyPoint& mp = allPoints[iVec]; //qDebug("\np.x() %i p.y() %i", p.x(), p.y() ); // For 3D lines, we need two points (that lie // behind each other on the Z axis). For 2D lines and // areas, we need only one point. if( showThreeDLines ) { points[0]->setPoint( point, project( mp.p.x(), mp.p.y(), (datasetStart+dataset)*params()->threeDLineDepth() ) ); points[1]->setPoint( point, project( mp.p.x(), mp.p.y(), (datasetStart+dataset + 1)*params()->threeDLineDepth() ) ); oripoints[0]->setPoint( point, mp.p.x(), mp.p.y() ); oripoints[1]->setPoint( point, mp.p.x() - (datasetStart+dataset + 1)*params()->threeDLineDepth(), mp.p.y() - (datasetStart+dataset + 1)*params()->threeDLineDepth() ); } else // 2D lines or areas points[0]->setPoint( point, mp.p ); ++point; int x = mp.p.x(); int y = QMAX(QMIN(mp.p.y(), static_cast < int > (logHeight +axisYOffset)), 0); bool markerIsOutside = y != mp.p.y(); // draw the marker and store the region if ( currentDrawMarkers ){ uint theAlignment = Qt::AlignCenter; bool hasOwnSize = false; int theWidth = 0; int theHeight = 0; QColor theColor(params()->dataColor( dataset )); int theStyle = markerStyle; if( curPropSetId != KDChartPropertySet::UndefinedID ){ // we can safely call the following functions and ignore their // return values since they will touch the parameters' values // if the propSet *contains* corresponding own values only. int iDummy; curPropSet.hasOwnMarkerAlign( iDummy, theAlignment ); curPropSet.hasOwnMarkerColor( iDummy, theColor ); curPropSet.hasOwnMarkerStyle( iDummy, theStyle ); QSize size(theWidth, theHeight); hasOwnSize = curPropSet.hasOwnMarkerSize(iDummy, size); if( hasOwnSize ){ theWidth = size.width(); theHeight = size.height(); } } drawMarker( painter, params(), _areaWidthP1000, _areaHeightP1000, _dataRect.x(), _dataRect.y(), markerIsOutside ? KDChartParams::LineMarker1Pixel : theStyle, theColor, QPoint(x,y), dataset, value, chart, regions, hasOwnSize ? &theWidth : 0, hasOwnSize ? &theHeight : 0, theAlignment ); } // store the region else if( regions ) { QRect rect( QPoint( x-params()->lineWidth()-1, y-params()->lineWidth()-1 ), QPoint( x+params()->lineWidth()+1, y+params()->lineWidth()+1 ) ); rect.moveBy( _dataRect.x(), _dataRect.y() ); regions->append( new KDChartDataRegion(dataset, value, chart, rect) ); } } } if ( point ) { bool bDrawLines = (0 != params()->lineWidth()); if ( mIsArea ) { // first draw with the fill brush, no pen, with the // zero axis points or upper border points added for the first // dataset or with the previous points reversed for all other // datasets. painter->setPen( QPen( Qt::NoPen ) ); const QBrush datasetBrush( params()->dataColor( dataset ), Qt::SolidPattern ); painter->setBrush( datasetBrush ); QBrush currentBrush( datasetBrush ); if ( mode == Normal || dataset == (int)datasetEnd ) { /// first dataset (or any dataset in normal mode, where /// the datasets overwrite each other) // no 3d handling for areas yet QPoint lastPoint = points[0]->point( point - 1 ); // zeroXAxisI can be too far below the abscissa, but it's // the only thing we have. Likewise can 0 be too far above // the upper boundary, but again it's the only thing we // have, at the rest is clipped anyway. int yCoord; if ( params()->areaLocation() == KDChartParams::AreaBelow || mode == Percent ) yCoord = static_cast<int>(zeroXAxisI); else yCoord = static_cast<int>(axisYOffset); // old: draw the complete area in on go: /* // no 3d handling for areas yet points[0]->setPoint( point, lastPoint.x(), yCoord ); point++; QPoint firstPoint = points[0]->point( 0 ); points[0]->setPoint( point, firstPoint.x(), yCoord ); point++; painter->drawPolygon( *points[0], false, 0, point ); */ // new: draw individual area segments: curPropSetId = KDChartPropertySet::UndefinedID; for( int value = 0; value < point-1; ++value ) { int cellPropID; if( data->cellProp( dataset, value, cellPropID ) && cellPropID != curPropSetId ){ if( cellPropID != KDChartPropertySet::UndefinedID && params()->calculateProperties( cellPropID, curPropSet ) ){ curPropSetId = cellPropID; }else{ curPropSetId = KDChartPropertySet::UndefinedID; } // preset with default value QBrush theAreaBrush = datasetBrush; if( curPropSetId != KDChartPropertySet::UndefinedID ){ // we can safely call the following functions and ignore their // return values since they will touch the parameters' values // if the propSet *contains* corresponding own values only. int iDummy; curPropSet.hasOwnAreaBrush( iDummy, theAreaBrush ); } painter->setBrush( theAreaBrush ); } QPointArray segment( 4 ); segment.setPoint( 0, points[0]->point( value ) ); segment.setPoint( 1, points[0]->point( value+1 ) ); segment.setPoint( 2, points[0]->point( value+1 ).x(), yCoord ); segment.setPoint( 3, points[0]->point( value ).x(), yCoord ); painter->drawPolygon( segment ); } // old: draw the complete area in on go: /* // remove the last two points added point -= 2; */ //qDebug("\n111"); } // if ( mode == Normal || dataset == (int)datasetEnd ) else { // don't mess around with the original array; we'll need // that for the next time through. //qDebug("222"); // no 3d handling for areas yet QPointArray thisSection = points[0]->copy(); thisSection.resize( point + previousPoints.size() ); // append the previous array (there is guaranteed to be // one because we are at least the second time through // here) in reverse order for ( unsigned int i = 0; i < previousPoints.size(); ++i ) { thisSection.setPoint( point + i, previousPoints.point( previousPoints.size() - i - 1 ) ); //qDebug("\nx: %i",previousPoints.point( previousPoints.size() - i - 1 ).x()); //qDebug("y: %i",previousPoints.point( previousPoints.size() - i - 1 ).y()); } painter->drawPolygon( thisSection ); } // draw the line with no brush and outline color painter->setBrush( Qt::NoBrush ); painter->setPen( QPen( params()->outlineDataColor(), params()->outlineDataLineWidth() ) ); } else { // line if( showThreeDLines ) { // This is a 3D line: // We draw the line with the data color brush // and the outline data pen. painter->setBrush( params()->dataColor( dataset ) ); painter->setPen( QPen( params()->outlineDataColor(), params()->outlineDataLineWidth() ) ); } else { // This is a 2D line: // We draw the line with the no brush // and the data color if no special line color was specified. painter->setBrush( Qt::NoBrush ); painter->setPen( default2DPen ); } } // Neither draw the contour line if this is a pure Point chart // nor draw it for the last row of a percent area chart. if( bDrawLines && ( (mode != Percent) || !mIsArea || (dataset != (int)datasetEnd) ) ){ if( showThreeDLines ) { // A 3D line needs to be drawn piece-wise for ( int value = 0; value < point-1; ++value ) { // if( data->cell( dataset, value ).hasValue() && // data->cell( dataset, value+1 ).hasValue() ) { // qDebug( "Draw a segment in dataset %d from %d to %d", dataset, value, value+1 ); //store the rotated points ( see project() ) QPointArray rotatedSegment( 4 ); rotatedSegment.setPoint( 0, points[0]->point( value )); rotatedSegment.setPoint( 1, points[0]->point( value+1 ) ); rotatedSegment.setPoint( 2, points[1]->point( value+1 ) ); rotatedSegment.setPoint( 3, points[1]->point( value ) ); //store the true points without rotation QPointArray trueSegment( 4 ); trueSegment.setPoint( 0, oripoints[0]->point( value )); trueSegment.setPoint( 1, oripoints[0]->point( value+1 ) ); trueSegment.setPoint( 2, oripoints[1]->point( value+1 ) ); trueSegment.setPoint( 3, oripoints[1]->point( value ) ); // calculate the rotated points position relative to each other // we will then be able to keep the rotation ( see: project () ) // by reporting this position relative to the true segment line //left side pt3 and pt0 int dx30 = rotatedSegment.point(3).x() - rotatedSegment.point(0).x(); int dy30 = rotatedSegment.point(3).y() - rotatedSegment.point(0).y(); //right side pt1 and pt2 int dx12 = rotatedSegment.point(2).x() - rotatedSegment.point(1).x(); int dy12 = rotatedSegment.point(2).y() - rotatedSegment.point(1).y(); // store and paint the "3D" segment QPointArray segment( 4 ); segment.setPoint( 0, trueSegment.point(0) ); segment.setPoint( 1, trueSegment.point(1) ); segment.setPoint( 2, trueSegment.point(1).x() + dx12, trueSegment.point(1).y() + dy12 ); segment.setPoint( 3, trueSegment.point(0).x() + dx30, trueSegment.point(0).y() + dy30); //PENDING Michel 3dlines drawing a segment with showThreeDLines painter->drawPolygon( segment ); // } else // qDebug( "Can't draw a segment in dataset %d from %d to %d", dataset, value, value+1 ); } } else { QPoint p1, p2; // Note: If markers are drawn very near to each other // and tiny markers are used // we don't draw the connecting lines. bool b4PMarkers = KDChartParams::LineMarker4Pixels == markerStyle; bool bTinyMarkers = KDChartParams::LineMarker1Pixel == markerStyle || b4PMarkers; curPropSetId = KDChartPropertySet::UndefinedID; painter->setPen( default2DPen ); for ( int value = 0; value < point-1; ++value ) { p1 = points[0]->point( value ); p2 = points[0]->point( value+1 ); // Determine properties assigned to this cell // and change the painter if necessarry: currentDrawMarkers = defaultDrawMarkers; int cellPropID; if( data->cellProp( dataset, value, cellPropID ) && cellPropID != curPropSetId ){ if( cellPropID != KDChartPropertySet::UndefinedID && params()->calculateProperties( cellPropID, curPropSet ) ){ curPropSetId = cellPropID; }else{ curPropSetId = KDChartPropertySet::UndefinedID; } // preset with default values int theLineWidth = default2DPen.width(); QColor theLineColor = default2DPen.color(); Qt::PenStyle theLineStyle = default2DPen.style(); if( curPropSetId != KDChartPropertySet::UndefinedID ){ // we can safely call the following functions and ignore their // return values since they will touch the parameters' values // if the propSet *contains* corresponding own values only. int iDummy; curPropSet.hasOwnLineWidth ( iDummy, theLineWidth ); curPropSet.hasOwnLineColor ( iDummy, theLineColor ); curPropSet.hasOwnLineStyle ( iDummy, theLineStyle ); curPropSet.hasOwnShowMarker( iDummy, currentDrawMarkers ); } painter->setPen( QPen( theLineColor, theLineWidth, theLineStyle ) ); } if( !currentDrawMarkers ){ //PENDING Michel: drawing a line - not currentMarkers painter->drawLine( p1, p2 ); }else{ int dx = p2.x() - p1.x(); int dy = p2.y() - p1.y(); if( !bTinyMarkers || (abs(dx) > 4) || (abs(dy) > 4) ){ if( bTinyMarkers ) { double m = !dx ? 100.0 : !dy ? 0.01 : ((double)dy / (double)dx); double am = fabs(m); int dxx; int dyy; if( 0.25 > am ){ dxx = 3; dyy = 0; }else if( 0.67 > am ){ dxx = 3; dyy = 1; }else if( 1.33 > am ){ dxx = 2; dyy = 2; }else if( 4.0 > am ){ dxx = 1; dyy = 3; }else{ dxx = 0; dyy = 3; } if( 0 > dx ) dxx *= -1; if( 0 > dy ) dyy *= -1; if( b4PMarkers ){ if( 0 < dx ) ++p1.rx(); else if( 0 > dx ) ++p2.rx(); if( 0 < dy ) ++p1.ry(); else if( 0 > dy ) ++p2.ry(); } p1.rx() += dxx; p1.ry() += dyy; p2.rx() -= dxx; p2.ry() -= dyy; } //PENDING Michel: drawing a line - currentMarkers painter->drawLine( p1, p2 ); } } } } } } // Save point array for next way through (needed for e.g. stacked // areas), not for 3D currently points[0]->resize( point ); previousPoints = points[0]->copy(); } // Now draw any extra lines (and/or their markers, resp.) that // are to be printed IN FRONT of the normal lines: if( mChartType == KDChartParams::Line ){ for( dataset = datasetEnd; ( dataset >= (int)datasetStart && dataset >= 0 ); --dataset ) { const KDChartParams::LineMarkerStyle defaultMarkerStyle = params()->lineMarkerStyle( dataset ); const QPen default2DPen( params()->lineColor().isValid() ? params()->lineColor() : params()->dataColor( dataset ), params()->lineWidth(), params()->lineStyle( dataset ) ); if( ai.bAbscissaHasTrueAxisDtValues ) ai.numValues = data->cols(); for ( int value = 0; value < ai.numValues; ++value ) { int iVec = static_cast < int > ( datasetEnd-dataset ) * arrayNumValues + value; if( allPoints[ iVec ].bValid ){ const MyPoint& mp = allPoints[iVec]; //qDebug("\np.x() %i p.y() %i", p.x(), p.y() ); // -------------------------------------------------------- // determine any 'extra' properties assigned to this cell // by traversing the property set chain (if necessary) // -------------------------------------------------------- int cellPropID; if( data->cellProp( dataset, value, cellPropID ) && cellPropID != curPropSetId ){ if( cellPropID != KDChartPropertySet::UndefinedID && params()->calculateProperties( cellPropID, curPropSet ) ) curPropSetId = cellPropID; else curPropSetId = KDChartPropertySet::UndefinedID; } if( curPropSetId != KDChartPropertySet::UndefinedID ){ drawExtraLinesAndMarkers( curPropSet, default2DPen, defaultMarkerStyle, mp.p.x(), mp.p.y(), painter, ai.abscissaPara, ordinatePara, logWidth/1000.0, logHeight/1000.0, true ); } } } } } //qDebug(const_cast < KDChartParams* > ( params() )->properties( KDCHART_PROPSET_NORMAL_DATA )->name().latin1()); //qDebug(const_cast < KDChartParams* > ( params() )->properties( KDCHART_PROPSET_TRANSPARENT_DATA )->name().latin1()); //qDebug(const_cast < KDChartParams* > ( params() )->properties( KDCHART_PROPSET_HORI_LINE )->name().latin1()); //qDebug(const_cast < KDChartParams* > ( params() )->properties( KDCHART_PROPSET_VERT_LINE )->name().latin1()); //qDebug("--"); }