void Tweener::release(const TupInputDeviceInformation *input, TupBrushManager *brushManager, TupGraphicsScene *scene) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[Tweener::release()]"; #else T_FUNCINFO; #endif #endif Q_UNUSED(input); Q_UNUSED(brushManager); if (scene->currentFrameIndex() == k->initFrame) { if (k->editMode == TupToolPlugin::Properties) { if (k->nodesGroup) { k->nodesGroup->createNodes(k->path); k->nodesGroup->show(); k->nodesGroup->expandAllNodes(); k->configurator->updateSteps(k->path); QPainterPath::Element e = k->path->path().elementAt(0); QPointF begin = QPointF(e.x, e.y); if (begin != k->firstNode) { QPointF oldPos = k->firstNode; QPointF newPos = begin; int distanceX = newPos.x() - oldPos.x(); int distanceY = newPos.y() - oldPos.y(); if (k->objects.size() > 0) { foreach (QGraphicsItem *item, k->objects) item->moveBy(distanceX, distanceY); QGraphicsItem *item = k->objects.at(0); QRectF rect = item->sceneBoundingRect(); k->itemObjectReference = rect.center(); } k->firstNode = newPos; } updateTweenPoints(); } } else { if (scene->selectedItems().size() > 0) { k->objects = scene->selectedItems(); k->configurator->notifySelection(true); QGraphicsItem *item = k->objects.at(0); QRectF rect = item->sceneBoundingRect(); QPointF newPos = rect.center(); QPointF oldPos = k->itemObjectReference; k->itemObjectReference = newPos; if (!k->path) { k->path = new QGraphicsPathItem; k->path->setZValue(k->baseZValue); QColor color(55, 155, 55, 200); QPen pen(QBrush(color), 2, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin); k->path->setPen(pen); QPainterPath path; path.moveTo(newPos); k->firstNode = newPos; k->path->setPath(path); scene->addItem(k->path); k->isPathInScene = true; k->pathOffset = QPointF(0, 0); } else { int distanceX = newPos.x() - oldPos.x(); int distanceY = newPos.y() - oldPos.y(); k->path->moveBy(distanceX, distanceY); k->pathOffset = QPointF(distanceX, distanceY); // k->firstNode = newPos; } } } } }
// ------------------------------------------------------------------------- void GraphRingMap::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - painter->setPen( m_pen ); painter->drawEllipse( m_rect ); painter->setPen( QPen(QBrush(QColor(128,128,128,128)), 1.0) ); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Draw several pies that represent the quadrants of the ring map. if( m_bDrawQuadrants ) { painter->drawPie(m_rect, 0*16, 0); painter->drawPie(m_rect, 90*16, 0); painter->drawPie(m_rect, 180*16, 0); painter->drawPie(m_rect, 270*16, 0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Draw several rings representing 25%, 50%, and 75% of the ring map. if( m_bDrawRingMarkers ) { QRectF rect = m_rect; rect.setWidth ( m_rect.width() * 0.25 ); rect.setHeight( m_rect.height() * 0.25 ); rect.translate( m_rect.center().x()-rect.center().x(),m_rect.center().y()-rect.center().y() ); painter->drawEllipse( rect ); rect.setWidth ( m_rect.width() * 0.5 ); rect.setHeight( m_rect.height() * 0.5 ); rect.translate( m_rect.center().x()-rect.center().x(),m_rect.center().y()-rect.center().y() ); painter->drawEllipse( rect ); rect.setWidth ( m_rect.width() * 0.75 ); rect.setHeight( m_rect.height() * 0.75 ); rect.translate( m_rect.center().x()-rect.center().x(),m_rect.center().y()-rect.center().y() ); painter->drawEllipse( rect ); } #if 0 #ifdef _DEBUG // For each ring item child, draw the pie representing the area that it // has to draw its Graph object. QListIterator<QGraphicsItem*> i( this->childItems() ); while( i.hasNext() ) { GraphRingItem* ri = dynamic_cast<GraphRingItem*>(i.next()); if( ri ) { //! @todo The rotation to draw the GraphRingItem extents for debugging //! is off, presumably because there are other //! transformations going on. How can we account for that? //! At the moment it is accounted for with the +90 but that //! is not properly drawing all the quadrants. qreal fRotation = (-ri->getRotation()+90)*16; // Draw a center line QPen pen(Qt::DashLine); pen.setColor( QColor(128,128,128,128) ); painter->setPen( pen ); painter->drawPie(m_rect, fRotation, 0); // Draw the extents of the ring item. pen.setStyle(Qt::DotLine); painter->setPen( pen ); painter->drawPie(m_rect, fRotation-((ri->getSpan()/2)*16), ri->getSpan()*16); } } #endif // _DEBUG #endif }
void HandleItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { setPen({Qt::black, (qreal)(pen().width())}); QGraphicsItem::hoverLeaveEvent(event); }
void CColourPopup::DrawCell(CDC* pDC, int nIndex) { // For the Custom Text area if (m_strCustomText.GetLength() && nIndex == CUSTOM_BOX_VALUE) { // The extent of the actual text button CRect TextButtonRect = m_CustomTextRect; TextButtonRect.top += 2*m_nMargin; // Fill background pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw horizontal line pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW)); pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top+1, m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT)); TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strCustomText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } // For the Default Text area if (m_strDefaultText.GetLength() && nIndex == DEFAULT_BOX_VALUE) { // Fill background pDC->FillSolidRect(m_DefaultTextRect, ::GetSysColor(COLOR_3DFACE)); // The extent of the actual text button CRect TextButtonRect = m_DefaultTextRect; TextButtonRect.DeflateRect(1,1); // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT)); else pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE)); // Draw thin line around text CRect LineRect = TextButtonRect; LineRect.DeflateRect(2*m_nMargin,2*m_nMargin); CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CPen* pOldPen = pDC->SelectObject(&pen); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(LineRect); pDC->SelectObject(pOldPen); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT); // Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strDefaultText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); pDC->SelectObject(pOldFont); return; } CRect rect; if (!GetCellRect(nIndex, rect)) return; // Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_Palette, FALSE); pDC->RealizePalette(); } // fill background if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex) pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DHILIGHT)); else pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE)); // Draw button if (m_nCurrentSel == nIndex) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT); else if (m_nChosenColourSel == nIndex) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT); CBrush brush(PALETTERGB(GetRValue(GetColour(nIndex)), GetGValue(GetColour(nIndex)), GetBValue(GetColour(nIndex)) )); CPen pen; pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); // Draw the cell colour rect.DeflateRect(m_nMargin+1, m_nMargin+1); pDC->Rectangle(rect); // restore DC and cleanup pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); brush.DeleteObject(); pen.DeleteObject(); if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) pDC->SelectPalette(pOldPalette, FALSE); }
BOOL COwnerDrawnListControl::OnEraseBkgnd(CDC* pDC) { int i = 0; ASSERT(GetHeaderCtrl()->GetItemCount() > 0); // We should recalculate m_yFirstItem here (could have changed e.g. when // the XP-Theme changed). if(GetItemCount() > 0) { CRect rc; GetItemRect(GetTopIndex(), rc, LVIR_BOUNDS); m_yFirstItem = rc.top; } // else: if we did the same thing as in OnColumnsCreated(), we get // repaint problems. const COLORREF gridColor = RGB(212,208,200); CRect rcClient; GetClientRect(rcClient); CRect rcHeader; GetHeaderCtrl()->GetWindowRect(rcHeader); ScreenToClient(rcHeader); CRect rcBetween = rcClient; // between header and first item rcBetween.top = rcHeader.bottom; rcBetween.bottom = m_yFirstItem; pDC->FillSolidRect(rcBetween, gridColor); CArray<int, int> columnOrder; columnOrder.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(columnOrder.GetData(), int(columnOrder.GetSize())); CArray<int, int> vertical; vertical.SetSize(GetHeaderCtrl()->GetItemCount()); int x = - GetScrollPos(SB_HORZ); HDITEM hdi; ZeroMemory(&hdi, sizeof(hdi)); hdi.mask = HDI_WIDTH; for(i = 0; i < GetHeaderCtrl()->GetItemCount(); i++) { GetHeaderCtrl()->GetItem(columnOrder[i], &hdi); x += hdi.cxy; vertical[i]= x; } if(m_showGrid) { CPen pen(PS_SOLID, 1, gridColor); CSelectObject sopen(pDC, &pen); for(int y = m_yFirstItem + GetRowHeight() - 1; y < rcClient.bottom; y += GetRowHeight()) { pDC->MoveTo(rcClient.left, y); pDC->LineTo(rcClient.right, y); } // BUGBUG: re-using i could be a potential bug! for(i = 0; i < vertical.GetSize(); i++) { pDC->MoveTo(vertical[i] - 1, rcClient.top); pDC->LineTo(vertical[i] - 1, rcClient.bottom); } } const int gridWidth = m_showGrid ? 1 : 0; const COLORREF bgcolor = ::GetSysColor(COLOR_WINDOW); const int lineCount = GetCountPerPage() + 1; const int firstItem = GetTopIndex(); const int lastItem = min(firstItem + lineCount, GetItemCount()) - 1; ASSERT(GetItemCount() == 0 || firstItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem >= firstItem); const int itemCount = lastItem - firstItem + 1; CRect fill; fill.left = vertical[vertical.GetSize() - 1]; fill.right = rcClient.right; fill.top = m_yFirstItem; fill.bottom = fill.top + GetRowHeight() - gridWidth; for(i = 0; i < itemCount; i++) { pDC->FillSolidRect(fill, bgcolor); fill.OffsetRect(0, GetRowHeight()); } int top = fill.top; while(top < rcClient.bottom) { fill.top = top; fill.bottom = top + GetRowHeight() - gridWidth; int left = 0; for(int i = 0; i < vertical.GetSize(); i++) { fill.left = left; fill.right = vertical[i] - gridWidth; pDC->FillSolidRect(fill, bgcolor); left = vertical[i]; } fill.left = left; fill.right = rcClient.right; pDC->FillSolidRect(fill, bgcolor); top += GetRowHeight(); } return true; }
void SessionPositionsChart::drawAxes(QPainter *p, int firstLap, int lastLap) { p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); //x axe p->drawLine(paintRect.left(), paintRect.top(), paintRect.right(), paintRect.top()); //y axe p->drawLine(paintRect.left(), paintRect.bottom()-10, paintRect.left(), paintRect.top()); p->setFont(QFont("Arial", 10, QFont::Bold, false)); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); QList<SessionPositionsChart::DriverPosAtom> positionList = getDriverStartingPositions(); int chartMin = (tMin == 1 ? 0 : tMin), k = 0; double yFactor = (double)((paintRect.height())/(tMax-chartMin)); double yFactor2 = 1.0;//(double)((tMax-chartMin)/12.0); double j = tMin; for (double i = paintRect.top(); i <= paintRect.bottom(); i+= yFactor, j += yFactor2, ++k) { if (firstLap == 0) { DriverData dd; int k = round(j)-1; if (k >= 0 && k < positionList.size() && positionList[k].id-1 >= 0 && positionList[k].id-1 < EventData::getInstance().getDriversData().size()) dd = EventData::getInstance().getDriversData()[positionList[round(j)-1].id-1]; QColor color = getCarColor(dd.getLastLap()); p->setBrush(color); p->setPen(color); p->drawRect(5, i-6, 4, 11); QString driver = SeasonData::getInstance().getDriverShortName(dd.getDriverName()); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); p->drawText(13, i+5, QString("%1 %2").arg(round(j)).arg(driver)); } if (i != paintRect.top()) { QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(paintRect.left(), i, paintRect.right(), i); } } if (lastLap - firstLap > 0) { double xFactor = ((double)paintRect.width()) / /*((lapData.size() < 5) ?*/ (double)(lastLap - firstLap) /*: 5)*/; double j = firstLap; double i = paintRect.left(); int prevJ = firstLap; bool lap1Line = false; double jFactor = (lastLap - firstLap) < 6 ? 1.0 : (double)((lastLap - firstLap) / 10.0); for (; i < width()-15.0 && round(j) < lastLap; /*i += xFactor,*/ j += jFactor) { i += (double)(round(j) - prevJ) * xFactor; prevJ = round(j); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); QString lap = QString("L%1").arg(round(j)); if (lap == "L0") lap = "S"; p->drawText(round(i)-5, 15, lap); if (i > paintRect.left()) { QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(round(i), paintRect.bottom()-10, round(i), paintRect.top()); } if (firstLap == 0 && !lap1Line) { p->drawText(round(i)-5+xFactor, 15, "L1"); QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(round(i) + xFactor, paintRect.bottom()-10, round(i) + xFactor, paintRect.top()); lap1Line = true; } } } }
void SessionGapsChart::drawAxes(QPainter *p, int firstLap, int lastLap) { p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); //x axe p->drawLine(paintRect.left(), paintRect.bottom(), paintRect.right(), paintRect.bottom()); //y axe p->drawLine(paintRect.left(), paintRect.bottom(), paintRect.left(), paintRect.top()); p->setFont(QFont("Arial", 10, QFont::Bold, false)); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); double yFactor = (double)((paintRect.height()-40)/9.0); double yFactor2 = (double)((tMax-tMin)/9.0); double j = tMin; for (double i = paintRect.bottom(); i >= 40; i-= yFactor, j += yFactor2) { p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); p->drawText(5, i+5, QString::number(j, 'f', 0)); if (i != paintRect.bottom()) { QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(paintRect.left(), i, paintRect.right(), i); } } if (tMax >= max) { p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); p->drawText(5, 15, ">1L"); QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(paintRect.left(), paintRect.top(), paintRect.right(), paintRect.top()); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); p->drawText(5, 35, QString(">%1").arg(max)); pen.setColor(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(paintRect.left(), 30, paintRect.right(), 30); } if (lastLap - firstLap > 0) { double xFactor = ((double)paintRect.width()) / /*((lapData.size() < 5) ?*/ (double)(lastLap - firstLap) /*: 5)*/; double j = firstLap; double i = paintRect.left(); int prevJ = firstLap; double jFactor = (lastLap - firstLap) < 6 ? 1.0 : (double)((lastLap - firstLap) / 10.0); for (; i < width()-15.0 && round(j) < lastLap; /*i += xFactor,*/ j += jFactor) { i += (double)(round(j) - prevJ) * xFactor; prevJ = round(j); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); p->drawText(round(i)-5, height()-10, QString("L%1").arg(round(j))); if (i > paintRect.left()) { QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(round(i), paintRect.bottom(), round(i), paintRect.top()); } } } }
void CPlotWindow:: DrawAxis(CDC &MemDC) { CString str; // CBrush br,*oldbr; // br.CreateSolidBrush(backcolor); // oldbr = MemDC.SelectObject(&br); // // MemDC.Rectangle(X1,Y2,X2,Y1); // MemDC.SelectObject(oldbr); // br.DeleteObject(); MemDC.FillSolidRect(X1,Y2,X2,Y1,backcolor); // MemDC.Rectangle(X1,Y2,X2,Y1); // MemDC.SetBkColor(backcolor); // MemDC.SelectPalette() COLORREF color_text=RGB(255,255,255); CPen pen(PS_DASH,1,color_text); CPen* pOldPen = MemDC.SelectObject(&pen); MemDC.SetTextColor(color_text); //Draw X Axis MemDC.MoveTo(X1,Y2-2); MemDC.LineTo(X2,Y2-2); CPen pen1(PS_SOLID,1,color_text); MemDC.SelectObject(&pen1); if(y1<0 && y2>0) { int b; b= static_cast<int>(((Y1-10)*y2-(Y2+20)*y1)/(y2-y1)); //Draw Y Axis MemDC.MoveTo(X1+Xoffset,Y1-10); MemDC.LineTo(X1+Xoffset,Y2+2); //Draw Arrow; MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize); MemDC.LineTo(X1+Xoffset,Y2+2); MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize); //Draw X Axis MemDC.MoveTo(X1+Xoffset,b); MemDC.LineTo(X2-2,b); //Draw Arrow; MemDC.MoveTo(X2-2-arrowsize,b+arrowsize); MemDC.LineTo(X2-2,b); MemDC.LineTo(X2-2-arrowsize,b-arrowsize); CRect rect_text(X1,b-15,X1+Xoffset-4,b+5); str.Format(_T("%ld"),0); MemDC.DrawText(str,rect_text,DT_RIGHT|DT_SINGLELINE|DT_VCENTER); CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+100,Y2+30); str.Format(_T("%ld"),y2); MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER); CRect rect_text2(X1+Xoffset+10,Y1-10,X1+Xoffset+100,Y1-30); str.Format(_T("%ld"),y1); MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER); str.Format(_T("%d"),x_range-1); CRect rect_text3(X2-100,b+4,X2-10,b+24); MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER); MemDC.MoveTo(X1+Xoffset,Y2+20); MemDC.LineTo(X1+Xoffset+6,Y2+20); MemDC.MoveTo(X1+Xoffset,Y1-15); MemDC.LineTo(X1+Xoffset+6,Y1-15); MemDC.MoveTo(X2-20,b); MemDC.LineTo(X2-20,b-6); Axis_X1 = X1+Xoffset; Axis_X2 = X2-20; Axis_Y1 = Y1-15; Axis_Y2 = Y2+20; } else { //XÖáÔÚ×îÏÂÃæ CRect rect_text1(X1+Xoffset+10,Y2+10,X1+Xoffset+200,Y2+30); str.Format(_T("%ld"),y2); MemDC.DrawText(str,rect_text1,DT_LEFT|DT_SINGLELINE|DT_VCENTER); CRect rect_text2(X1+Xoffset+10,Y1-Yoffset,X1+Xoffset+200,Y1-Yoffset+20); str.Format(_T("%ld"),y1); MemDC.DrawText(str,rect_text2,DT_LEFT|DT_SINGLELINE|DT_VCENTER); //Draw Y Axis MemDC.MoveTo(X1+Xoffset,Y1-Yoffset); MemDC.LineTo(X1+Xoffset,Y2+2); //Draw Arrow; MemDC.MoveTo(X1+Xoffset-arrowsize,Y2+2+arrowsize); MemDC.LineTo(X1+Xoffset,Y2+2); MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize); //Draw X Axis MemDC.LineTo(X1+Xoffset+arrowsize,Y2+2+arrowsize); MemDC.MoveTo(X1+Xoffset,Y1-Yoffset); MemDC.LineTo(X2-2,Y1-Yoffset); //Draw Arrow; MemDC.MoveTo(X2-2-arrowsize,Y1-Yoffset+arrowsize); MemDC.LineTo(X2-2,Y1-Yoffset); MemDC.LineTo(X2-2-arrowsize,Y1-Yoffset-arrowsize); str.Format(_T("%d"),x_range-1); CRect rect_text3(X2-100,Y1-Yoffset+4,X2-10,Y1-Yoffset+24); MemDC.DrawText(str,rect_text3,DT_RIGHT|DT_SINGLELINE|DT_VCENTER); MemDC.MoveTo(X1+Xoffset,Y2+20); MemDC.LineTo(X1+Xoffset+6,Y2+20); MemDC.MoveTo(X2-20,Y1-Yoffset); MemDC.LineTo(X2-20,Y1-Yoffset-6); Axis_X1 = X1+Xoffset; Axis_X2 = X2-20; Axis_Y1 = Y1-Yoffset; Axis_Y2 = Y2+20; } MemDC.SelectObject(pOldPen); }
qint8 specCanvasItem::penStyle() const { // if (style() != QwtPlotCurve::Lines) return -1 ; return pen().style() ; }
void renderCode128(OROPage * page, const QRectF & r, const QString & _str, ORBarcodeData * bc) { QVector<int> str; int i = 0; // create the list.. if the list is empty then just set a start code and move on if(_str.isEmpty()) str.push_back(104); else { int rank_a = 0; int rank_b = 0; int rank_c = 0; QChar c; for(i = 0; i < _str.length(); i++) { c = _str.at(i); rank_a += (code128Index(c, SETA) != -1 ? 1 : 0); rank_b += (code128Index(c, SETB) != -1 ? 1 : 0); rank_c += (c >= '0' && c <= '9' ? 1 : 0); } if(rank_c == _str.length() && ((rank_c % 2) == 0 || rank_c > 4)) { // every value in the is a digit so we are going to go with mode C // and we have an even number or we have more than 4 values i = 0; if((rank_c % 2) == 1) { str.push_back(104); // START B c = _str.at(0); str.push_back(code128Index(c, SETB)); str.push_back(99); // MODE C i = 1; } else str.push_back(105); // START C for(i = i; i < _str.length(); i+=2) { char a, b; c = _str.at(i); a = c.toLatin1(); a -= 48; c = _str.at(i+1); b = c.toLatin1(); b -= 48; str.push_back(int((a * 10) + b)); } } else { // start in the mode that had the higher number of hits and then // just shift into the opposite mode as needed int set = ( rank_a > rank_b ? SETA : SETB ); str.push_back(( rank_a > rank_b ? 103 : 104 )); int v = -1; for(i = 0; i < _str.length(); i++) { c = _str.at(i); v = code128Index(c, set); if(v == -1) { v = code128Index(c, (set == SETA ? SETB : SETA)); if(v != -1) { str.push_back(98); // SHIFT str.push_back(v); } } else str.push_back(v); } } } // calculate and append the checksum value to the list int checksum = str.at(0); for(i = 1; i < str.size(); i++) checksum += (str.at(i) * i); checksum = checksum % 103; str.push_back(checksum); // lets determine some core attributes about this barcode qreal bar_width = bc->narrowBarWidth; // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; if(quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height(); // how long is the value we need to encode? int val_length = str.size() - 2; // we include start and checksum in are list so // subtract them out for our calculations // L = (11C + 35)X // L length of barcode (excluding quite zone) in units same as X and I // C the number of characters in the value excluding the start/stop and checksum characters // X the width of a bar (pixels in our case) qreal L; qreal C = val_length; qreal X = bar_width; L = (((11.0 * C) + 35.0) * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if(bc->align == 1) // center { qreal nqz = (draw_width - L) / 2.0; if(nqz > quiet_zone) quiet_zone = nqz; } else if(bc->align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); bool space = false; int idx = 0, b = 0; qreal w = 0.0; for(i = 0; i < str.size(); i++) { // loop through each value and render the barcode idx = str.at(i); if(idx < 0 || idx > 105) { qDebug("Encountered a non-compliant element while rendering a 3of9 barcode -- skipping"); continue; } space = false; for(b = 0; b < 6; b++, space = !space) { w = _128codes[idx].values[b] * bar_width; if(!space) { ORORect * rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, w,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); } pos += w; } } // we have to do the stop character seperatly like this because it has // 7 elements in it's bar sequence rather than 6 like the others int STOP_CHARACTER[]={ 2, 3, 3, 1, 1, 1, 2 }; space = false; for(b = 0; b < 7; b++, space = !space) { w = STOP_CHARACTER[b] * bar_width; if(!space) { ORORect * rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, w,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); } pos += w; } return; }
void TextLineSegment::draw(QPainter* painter) const { TextLine* tl = textLine(); qreal _spatium = spatium(); qreal textlineLineWidth = tl->lineWidth().val() * _spatium; qreal textlineTextDistance = _spatium * .5; QPointF pp2(pos2()); QColor color; bool normalColor = false; if (selected() && !(score() && score()->printing())) color = MScore::selectColor[0]; else if (!visible()) color = Qt::gray; else { color = curColor(); normalColor = true; } qreal l = 0.0; int sym = subtype() == SEGMENT_MIDDLE ? tl->continueSymbol() : tl->beginSymbol(); if (_text) { SpannerSegmentType st = subtype(); if ( ((st == SEGMENT_SINGLE || st == SEGMENT_BEGIN) && (tl->beginTextPlace() == PLACE_LEFT)) || ((st == SEGMENT_MIDDLE || st == SEGMENT_END) && (tl->continueTextPlace() == PLACE_LEFT)) ) { QRectF bb(_text->bbox()); l = _text->pos().x() + bb.width() + textlineTextDistance; } painter->translate(_text->pos()); painter->setPen(normalColor ? _text->curColor() : color); _text->draw(painter); painter->translate(-_text->pos()); } else if (sym != -1) { const QRectF& bb = symbols[score()->symIdx()][sym].bbox(magS()); qreal h = bb.height() * .5; QPointF o = tl->beginSymbolOffset() * _spatium; painter->setPen(color); symbols[score()->symIdx()][sym].draw(painter, 1.0, QPointF(o.x(), h + o.y())); l = bb.width() + textlineTextDistance; } QPen pen(normalColor ? tl->lineColor() : color, textlineLineWidth); pen.setStyle(tl->lineStyle()); painter->setPen(pen); if (subtype() == SEGMENT_SINGLE || subtype() == SEGMENT_END) { if (tl->endSymbol() != -1) { int sym = tl->endSymbol(); const QRectF& bb = symbols[score()->symIdx()][sym].bbox(magS()); qreal h = bb.height() * .5; QPointF o = tl->endSymbolOffset() * _spatium; pp2.setX(pp2.x() - bb.width() + textlineTextDistance); symbols[score()->symIdx()][sym].draw(painter, 1.0, QPointF(pp2.x() + textlineTextDistance + o.x(), h + o.y())); } } QPointF pp1(l, 0.0); if (tl->beginHook() && tl->beginHookType() == HOOK_45) pp1.rx() += fabs(tl->beginHookHeight().val() * _spatium * .4); if (tl->endHook() && tl->endHookType() == HOOK_45) pp2.rx() -= fabs(tl->endHookHeight().val() * _spatium * .4); painter->drawLine(QLineF(pp1.x(), pp1.y(), pp2.x(), pp2.y())); if (tl->beginHook()) { qreal hh = tl->beginHookHeight().val() * _spatium; if (subtype() == SEGMENT_SINGLE || subtype() == SEGMENT_BEGIN) { if (tl->beginHookType() == HOOK_45) painter->drawLine(QLineF(pp1.x(), pp1.y(), pp1.x() - fabs(hh * .4), pp1.y() + hh)); else painter->drawLine(QLineF(pp1.x(), pp1.y(), pp1.x(), pp1.y() + hh)); } } if (tl->endHook()) { qreal hh = tl->endHookHeight().val() * _spatium; if (subtype() == SEGMENT_SINGLE || subtype() == SEGMENT_END) { if (tl->endHookType() == HOOK_45) painter->drawLine(QLineF(pp2.x(), pp2.y(), pp2.x() + fabs(hh * .4), pp2.y() + hh)); else painter->drawLine(QLineF(pp2.x(), pp2.y(), pp2.x(), pp2.y() + hh)); } } }
// motif arrows look the same whether they are used or not // is this correct? static void qDrawMotifArrow(QPainter *p, Qt::ArrowType type, bool down, int x, int y, int w, int h, const QPalette &pal, bool) { QPolygon bFill; // fill polygon QPolygon bTop; // top shadow. QPolygon bBot; // bottom shadow. QPolygon bLeft; // left shadow. QTransform matrix; // xform matrix bool vertical = type == Qt::UpArrow || type == Qt::DownArrow; bool horizontal = !vertical; int dim = w < h ? w : h; int colspec = 0x0000; // color specification array if (dim < 2) // too small arrow return; if (dim > 3) { if (dim > 6) bFill.resize(dim & 1 ? 3 : 4); bTop.resize((dim/2)*2); bBot.resize(dim & 1 ? dim + 1 : dim); bLeft.resize(dim > 4 ? 4 : 2); bLeft.putPoints(0, 2, 0,0, 0,dim-1); if (dim > 4) bLeft.putPoints(2, 2, 1,2, 1,dim-3); bTop.putPoints(0, 4, 1,0, 1,1, 2,1, 3,1); bBot.putPoints(0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2); for(int i=0; i<dim/2-2 ; i++) { bTop.putPoints(i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i); bBot.putPoints(i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i); } if (dim & 1) // odd number size: extra line bBot.putPoints(dim-1, 2, dim-3,dim/2, dim-1,dim/2); if (dim > 6) { // dim>6: must fill interior bFill.putPoints(0, 2, 1,dim-3, 1,2); if (dim & 1) // if size is an odd number bFill.setPoint(2, dim - 3, dim / 2); else bFill.putPoints(2, 2, dim-4,dim/2-1, dim-4,dim/2); } } else { if (dim == 3) { // 3x3 arrow pattern bLeft.setPoints(4, 0,0, 0,2, 1,1, 1,1); bTop .setPoints(2, 1,0, 1,0); bBot .setPoints(2, 1,2, 2,1); } else { // 2x2 arrow pattern bLeft.setPoints(2, 0,0, 0,1); bTop .setPoints(2, 1,0, 1,0); bBot .setPoints(2, 1,1, 1,1); } } if (type == Qt::UpArrow || type == Qt::LeftArrow) { matrix.translate(x, y); if (vertical) { matrix.translate(0, h - 1); matrix.rotate(-90); } else { matrix.translate(w - 1, h - 1); matrix.rotate(180); } if (down) colspec = horizontal ? 0x2334 : 0x2343; else colspec = horizontal ? 0x1443 : 0x1434; } else if (type == Qt::DownArrow || type == Qt::RightArrow) { matrix.translate(x, y); if (vertical) { matrix.translate(w-1, 0); matrix.rotate(90); } if (down) colspec = horizontal ? 0x2443 : 0x2434; else colspec = horizontal ? 0x1334 : 0x1343; } const QColor *cols[5]; cols[0] = 0; cols[1] = &pal.button().color(); cols[2] = &pal.mid().color(); cols[3] = &pal.light().color(); cols[4] = &pal.dark().color(); #define CMID *cols[(colspec>>12) & 0xf] #define CLEFT *cols[(colspec>>8) & 0xf] #define CTOP *cols[(colspec>>4) & 0xf] #define CBOT *cols[colspec & 0xf] QPen savePen = p->pen(); // save current pen QBrush saveBrush = p->brush(); // save current brush QTransform wxm = p->transform(); QPen pen(Qt::NoPen); const QBrush &brush = pal.brush(QPalette::Button); p->setPen(pen); p->setBrush(brush); p->setTransform(matrix, true); // set transformation matrix p->drawPolygon(bFill); // fill arrow p->setBrush(Qt::NoBrush); // don't fill p->setPen(CLEFT); p->drawLines(bLeft); p->setPen(CTOP); p->drawLines(bTop); p->setPen(CBOT); p->drawLines(bBot); p->setTransform(wxm); p->setBrush(saveBrush); // restore brush p->setPen(savePen); // restore pen #undef CMID #undef CLEFT #undef CTOP #undef CBOT }
void Magazine::Paint(QPainter *painter) { if (painter == NULL) { qDebug() << "Error. Painter == NULL."; exit(-1); } QPainterPath path1; path1.addRoundedRect(_credits, 10, 10); path1.addRoundedRect(_gold, 10, 10); QPainterPath path; path.addRoundedRect(_one, 10, 10); path.addRoundedRect(_capt_one, 10, 10); path.addRoundedRect(_two, 10, 10); path.addRoundedRect(_capt_two, 10, 10); path.addRoundedRect(_three, 10, 10); path.addRoundedRect(_capt_three, 10, 10); path.addRoundedRect(_four, 10, 10); path.addRoundedRect(_capt_four, 10, 10); path.addRoundedRect(_prev, 10, 10); path.addRoundedRect(_next, 10, 10); path.addRoundedRect(_back, 10, 10); QPen pen(Qt::red, 4); painter->setPen(pen); painter->fillPath(path, Qt::lightGray); painter->fillPath(path1, Qt::lightGray); painter->drawPath(path1); painter->drawPath(path); painter->setPen(QPen(Qt::black)); QFont font; font.setPixelSize(32); painter->setFont(font); painter->drawText(_prev, Qt::AlignCenter, QStringLiteral("Предыдущий")); painter->drawText(_next, Qt::AlignCenter, QStringLiteral("Следующий")); painter->drawText(_back, Qt::AlignCenter, QStringLiteral("Назад")); font.setPixelSize(24); painter->setFont(font); painter->drawText(_credits, Qt::AlignCenter, QStringLiteral("Золото ")+_credits_num); painter->drawText(_gold, Qt::AlignCenter, QStringLiteral("Кредиты ")+_gold_num); switch (_state) { case 0: { painter->setPen(QPen(Qt::lightGray)); font.setPixelSize(24); painter->setFont(font); painter->drawText(_capt_one, Qt::AlignCenter, QStringLiteral("Корабль")); painter->drawText(_capt_two, Qt::AlignCenter, QStringLiteral("Двигатель")); painter->drawText(_capt_three, Qt::AlignCenter, QStringLiteral("Топливный бак")); painter->drawText(_capt_four, Qt::AlignCenter, QStringLiteral("Йотанет")); } break; case 1: { painter->setPen(QPen(Qt::lightGray)); font.setPixelSize(24); painter->setFont(font); painter->drawText(_capt_one, Qt::AlignCenter, QStringLiteral("Генератор энергии")); painter->drawText(_capt_two, Qt::AlignCenter, QStringLiteral("Картограф")); painter->drawText(_capt_three, Qt::AlignCenter, QStringLiteral("Корпус с энергетической защитой")); painter->drawText(_capt_four, Qt::AlignCenter, QStringLiteral("Радар")); } break; case 2: { painter->setPen(QPen(Qt::lightGray)); font.setPixelSize(24); painter->setFont(font); painter->drawText(_capt_one, Qt::AlignCenter, QStringLiteral("Сканер")); painter->drawText(_capt_two, Qt::AlignCenter, QStringLiteral("Чинилка")); painter->drawText(_capt_three, Qt::AlignCenter, QStringLiteral("Захват предметов")); painter->drawText(_capt_four, Qt::AlignCenter, QStringLiteral("Оружие")); } break; } }
void KGListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CClientDC dc(this); CDC* pDC = &dc; pDC->SelectObject(GetFont()); int uRowCount = CListCtrl::GetHeaderCtrl()->GetItemCount(); CString* pszText = new CString[uRowCount]; CRect* pRect = new CRect[uRowCount]; BOOL bIsSelected = FALSE; BOOL bIsFocused = FALSE; BOOL bIsDisabled = FALSE; COLORREF colorFrame = RGB(255, 255, 255); COLORREF colorText = RGB(255, 255, 255); COLORREF colorBack = RGB(255, 255, 255); COLORREF colorExpandFrame = RGB(255, 255, 255); COLORREF colorExpandBack = RGB(255, 255, 255); if(lpDrawItemStruct->itemID == -1 || uRowCount < 1) { return; } bIsSelected = (lpDrawItemStruct->itemState & ODS_SELECTED); bIsFocused = (lpDrawItemStruct->itemState & ODS_FOCUS); bIsDisabled = (lpDrawItemStruct->itemState & ODS_DISABLED); CRect rcItem = lpDrawItemStruct->rcItem; pDC->SetBkMode(TRANSPARENT); LPKGLISTITEM pItem = (LPKGLISTITEM)GetItemData(lpDrawItemStruct->itemID); KG_PROCESS_ERROR(pItem); int uDrawCound = uRowCount; if (uRowCount > (int)pItem->arryItemText.GetCount()) { uDrawCound = (int)pItem->arryItemText.GetCount(); } for (int i = 0; i < uDrawCound; i++) { pszText[i] = pItem->arryItemText.GetAt(i).szItemText; CListCtrl::GetSubItemRect( lpDrawItemStruct->itemID, i, LVIR_BOUNDS, pRect[i] ); } if (CString(pszText[0]) == "FK") { int a = 0; a++; } (*pRect).left += rcItem.Height() * pItem->nTitleLever; for (int i = 0; i < uDrawCound ; i++) { if (!i) { LPKGLISTITEM pParent = pItem; while (pParent->pPerantItem) pParent = pParent->pPerantItem; int nTitleLever = pParent->nTitleLever; while (pParent && pParent->nTitleLever < pItem->nTitleLever) { CRect rect = rcItem; rect.left += rcItem.Height() * pParent->nTitleLever; pDC->FillRect( &rect, &CBrush(pParent->arryItemText.GetAt(i).colorBack) ); CPen pen(PS_SOLID, 1, pParent->arryItemText.GetAt(i).colorFrame); CPen* pPenSave = pDC->SelectObject(&pen); pDC->MoveTo(rect.left, rect.top); pDC->LineTo(rect.left, rect.bottom); pDC->SelectObject(pPenSave); pParent = FindJunior(pParent); if (pItem->pPerantItem && pItem->pPerantItem->nTitleLever == pParent->nTitleLever) pParent = pItem->pPerantItem; //pParent = pParent->pFirstChildItem; //nTitleLever++; } } if (bIsSelected) { colorExpandFrame = pItem->arryItemText.GetAt(i).colorExpandRectFrameSel; colorExpandBack = pItem->arryItemText.GetAt(i).colorExpandRectBackSel; colorBack = pItem->arryItemText.GetAt(i).colorBackSel; colorFrame = pItem->arryItemText.GetAt(i).colorFrameSel; colorText = pItem->arryItemText.GetAt(i).colorTextSel; } else { colorExpandFrame = pItem->arryItemText.GetAt(i).colorExpandRectFrame; colorExpandBack = pItem->arryItemText.GetAt(i).colorExpandRectBack; colorText = pItem->arryItemText.GetAt(i).colorText; colorFrame = pItem->arryItemText.GetAt(i).colorFrame; colorBack = pItem->arryItemText.GetAt(i).colorBack; } if (!i && !pItem->pFirstChildItem) pRect[i].left += 1; pDC->FillRect(pRect[i], &CBrush(colorBack)); CPen pen(PS_SOLID, 1, colorFrame); CPen* pPenSave = pDC->SelectObject(&pen); pDC->MoveTo(pRect[i].left, pRect[i].bottom); pDC->LineTo(pRect[i].left, pRect[i].top); pDC->LineTo(pRect[i].right, pRect[i].top); pDC->SelectObject(pPenSave); if (m_listDataTree.IsTitle(pItem))//(uDrawCound == 1) { CRect rect = (*pRect); rect.left += 5; rect.top += 3; rect.bottom -= 4; rect.right = rect.left + (rect.bottom - rect.top); rcItem.left = (*pRect).left; (*pRect).left += rcItem.Height() + 4; DrawRect( pDC, &rect, colorExpandFrame, colorExpandBack, !pItem->nItemState ); } else { pRect[i].left += 12; } pDC->SetTextColor(colorText); pDC->DrawText( pszText[i], -1, pRect[i], DT_LEFT | DT_SINGLELINE | DT_VCENTER ); } Exit0: SAFE_DELETE_ARRAY(pRect); SAFE_DELETE_ARRAY(pszText); }
void ptSimpleRectInteraction::mouseAction(QMouseEvent* event) { switch (event->type()) { // left button press case QEvent::MouseButtonPress: { if (event->button() == Qt::LeftButton) { event->accept(); assert(m_RectItem == NULL); // map viewport coords to scene coords QPointF pos(FView->mapToScene(event->pos())); m_Rect->setTopLeft(pos); m_Rect->setBottomRight(pos); QPen pen(QColor(150, 150, 150)); m_RectItem = FView->scene()->addRect(*m_Rect, pen); FView->repaint(); m_NowDragging = 1; } break; } // left button release case QEvent::MouseButtonRelease: { if (event->button() == Qt::LeftButton) { event->accept(); Finalize(stSuccess); } break; } // mouse move case QEvent::MouseMove: { if (m_NowDragging) { event->accept(); // move rectangle if (m_CtrlPressed > 0) { m_DragDelta->setP2(event->pos()); qreal dx = m_DragDelta->dx() / FView->transform().m11(); qreal dy = m_DragDelta->dy() / FView->transform().m11(); m_Rect->moveTo(qBound(0.0, m_Rect->left() + dx, FView->scene()->sceneRect().width() - m_Rect->width()), qBound(0.0, m_Rect->top() + dy, FView->scene()->sceneRect().height() - m_Rect->height()) ); m_DragDelta->setP1(event->pos()); m_RectItem->setRect(*m_Rect); FView->repaint(); // change rectangle size } else { QPointF point = FView->mapToScene(event->pos()); m_Rect->setRight(qBound(0.0, point.x(), FView->scene()->sceneRect().right())); m_Rect->setBottom(qBound(0.0, point.y(), FView->scene()->sceneRect().bottom())); m_RectItem->setRect(m_Rect->normalized()); FView->repaint(); } } break; } default: { assert(!"Wrong event type"); break; } } //switch }
void specCanvasItem::setLineWidth(const double& w) { QPen newPen(pen()) ; newPen.setWidthF(w) ; setPen(newPen) ; }
//! 显示数据 void CViewerWnd::OnDraw(CDC* pDC, const CRect& rcClient) { if((rcClient.Width()<1) || (rcClient.Height()<1)) { return; } if(OGDCIS0(m_drawing.m_dCoordRatio)) { return; } if(m_drawing.m_rcClient != rcClient) { m_drawing.ChangeClient(rcClient); m_bRefresh = TRUE; } OgdcRect2D rcBounds = ComputeBounds(); if(m_drawing.m_rcBounds != rcBounds) { m_drawing.m_rcBounds = rcBounds; m_bRefresh = TRUE; } BOOL bDeviceChange = FALSE; LONG ncxFullScreen = GetSystemMetrics( SM_CXFULLSCREEN ); LONG ncyFullScreen = GetSystemMetrics( SM_CYFULLSCREEN ); if(m_bitmap.m_hObject != NULL) { BITMAP BM; m_bitmap.GetBitmap(&BM); if(BM.bmWidth != ncxFullScreen || BM.bmHeight != ncyFullScreen || pDC->GetDeviceCaps(BITSPIXEL) != BM.bmBitsPixel) { bDeviceChange = TRUE; m_bRefresh = TRUE; } } if(pDC->IsPrinting() || m_bRefresh) { if(!pDC->IsPrinting() && bDeviceChange && m_pOldBitmap != NULL) { m_memDC.SelectObject(m_pOldBitmap); m_pOldBitmap = NULL; m_bitmap.DeleteObject(); m_memDC.DeleteDC(); } if(!pDC->IsPrinting() && m_bitmap.m_hObject == NULL) { m_memDC.CreateCompatibleDC(pDC); if(!m_bitmap.CreateCompatibleBitmap(pDC, ncxFullScreen, ncyFullScreen)) { m_bRefresh = FALSE; return; } m_pOldBitmap = m_memDC.SelectObject(&m_bitmap); } CDC* pDeviceDC = pDC; if(!pDC->IsPrinting()) { pDeviceDC = &m_memDC; } //! 画背景矩形 CBrush brush(RGB(255,255,255)); pDeviceDC->FillRect(rcClient, &brush); //! 画数据 for(int i=0;i<m_datasets.GetSize();i++) { OgdcStyle style = m_styles[i]; OgdcDataset* pDT = m_datasets.GetAt(i); CPen pen(PS_SOLID, style.m_nLineWidth, style.m_clrLine); CPen* pOldPen = pDeviceDC->SelectObject(&pen); CBrush brush(style.m_clrFillFore); CBrush* pOldBrush = NULL; if(style.m_nFillStyle == 1) { pOldBrush = (CBrush*)pDeviceDC->SelectStockObject(NULL_BRUSH); } else { pOldBrush = pDeviceDC->SelectObject(&brush); } m_drawing.m_curStyle = style; m_drawing.DrawDataset(pDeviceDC, m_datasets[i]); pDeviceDC->SelectObject(pOldPen); pDeviceDC->SelectObject(pOldBrush); } m_bRefresh = FALSE; } if(!pDC->IsPrinting() && m_bitmap.m_hObject != NULL) { pDC->BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &m_memDC, rcClient.left, rcClient.top, SRCCOPY ); } //! 画选择 if(m_nSelectID >= 0 && m_pSelectDataset != NULL && !pDC->IsPrinting()) { OgdcDatasetVector* pDatasetV = m_pSelectDataset; OgdcQueryDef queryDef; queryDef.m_nType = OgdcQueryDef::IDs; queryDef.m_nOptions = OgdcQueryDef::Geometry; queryDef.m_nCursorType = OgdcQueryDef::OpenStatic; queryDef.m_nCursorLocation = OgdcQueryDef::UseClient; queryDef.m_IDs.Add(m_nSelectID); OgdcRecordset* pRecordset = pDatasetV->Query(queryDef); if(pRecordset != NULL) { pRecordset->Move(OgdcRecordset::End, 0); if (pDatasetV->GetType() == OgdcDataset::PointEPS || pDatasetV->GetType() == OgdcDataset::LineEPS || pDatasetV->GetType() == OgdcDataset::RegionEPS || pDatasetV->GetType() == OgdcDataset::TextEPS) { UGC::UGGeometry* pGeometry = NULL; while(!pRecordset->IsBOF()) { if(pRecordset->GetElement(pGeometry) && pGeometry != NULL) { CPen pen(PS_SOLID, 2, RGB(0,0,255)); CPen* pOldPen = pDC->SelectObject(&pen); CBrush brush(RGB(255,255,115)); CBrush *pOldBrush = pDC->SelectObject(&brush); m_drawing.DrawElement(pDC, pGeometry, true); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); delete pGeometry; pGeometry = NULL; break; } pRecordset->Move(OgdcRecordset::Current, -1); if(pGeometry != NULL) { delete pGeometry; pGeometry = NULL; } } } else { OgdcElement* pElement = NULL; while(!pRecordset->IsBOF()) { if(pRecordset->GetElement(pElement) && pElement != NULL) { CPen pen(PS_SOLID, 2, RGB(0,0,255)); CPen* pOldPen = pDC->SelectObject(&pen); CBrush brush(RGB(255,255,115)); CBrush *pOldBrush = pDC->SelectObject(&brush); m_drawing.DrawElement(pDC, pElement, true); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); delete pElement; pElement = NULL; break; } pRecordset->Move(OgdcRecordset::Current, -1); if(pElement != NULL) { delete pElement; pElement = NULL; } } } pDatasetV->ReleaseRecordset(pRecordset); pRecordset = NULL; } } }
double specCanvasItem::lineWidth() const { return pen().widthF() ; }
void SessionLapTimesChart::drawAxes(QPainter *p, int firstLap, int lastLap) { p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); //x axe p->drawLine(paintRect.left(), paintRect.bottom(), paintRect.right(), paintRect.bottom()); //y axe p->drawLine(paintRect.left(), paintRect.bottom(), paintRect.left(), paintRect.top()); p->setFont(QFont("Arial", 10, QFont::Bold, false)); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); double yFactor = (double)((paintRect.height())/10.0); double yFactor2 = (double)((tMax-tMin)/10.0); double j = tMin; for (double i = paintRect.bottom(); i >= 10; i-= yFactor, j += yFactor2) { p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); int msecs = j * 1000; LapTime lt(msecs); QString str = lt.toString(); int idx = str.indexOf("."); if (idx != -1) str = str.left(idx+2); p->drawText(5, i+5, str);//QString("%1").arg(j, 0, 'f', 1)); if (i != paintRect.bottom()) { QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(paintRect.left(), i, paintRect.right(), i); } } if (lastLap - firstLap > 0) { double xFactor = ((double)paintRect.width()) / /*((lapData.size() < 5) ?*/ (double)(lastLap - firstLap) /*: 5)*/; double j = firstLap; double i = paintRect.left(); int prevJ = firstLap; double jFactor = (lastLap - firstLap) < 6 ? 1.0 : (double)((lastLap - firstLap) / 10.0); for (; i < width()-15.0 && round(j) < lastLap; /*i += xFactor,*/ j += jFactor) { i += (double)(round(j) - prevJ) * xFactor; prevJ = round(j); p->setPen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::WHITE))); p->drawText(round(i)-5, height()-10, QString("L%1").arg(round(j))); if (i > paintRect.left()) { QPen pen(QColor(ColorsManager::getInstance().getDefaultColor(LTPackets::DEFAULT))); pen.setStyle(Qt::DashLine); p->setPen(pen); p->drawLine(round(i), paintRect.bottom(), round(i), paintRect.top()); } } } }
QColor specCanvasItem::penColor() const { return pen().color() ; }
//显示截取矩形信息 void CCatchScreenDlg::DrawMessage(CDC &dc, CRect &inRect) { //截取矩形大小信息离鼠标间隔 const int space=3; //设置字体颜色大小 CPoint pt; CPen pen(PS_SOLID,1,m_clrWndFrameColor); dc.SetTextColor(m_clrTextColor); CFont font; font.CreatePointFont(90,_T("宋体")); CFont *pOldFont = (CFont*) dc.SelectObject(&font); //得到字体宽度和高度 GetCursorPos(&pt); dc.SetBkMode(TRANSPARENT); TEXTMETRIC tm; int charHeight; CSize size; int nLineLength; dc.GetTextMetrics(&tm); charHeight = tm.tmHeight + tm.tmExternalLeading; size = dc.GetTextExtent(_T("顶点位置 "), strlen(_T("顶点位置 "))); nLineLength = size.cx; //初始化矩形, 以保证写下六行文字 CRect rect(pt.x + space, pt.y - charHeight * 6 - space, pt.x + nLineLength + space, pt.y - space); int x = GetDeviceCaps(dc, HORZRES); int y = GetDeviceCaps(dc, VERTRES); //创建临时矩形 CRect rectTemp; //当矩形到达桌面边缘时调整方向和大小 if((pt.x+rect.Width()) >= x) { //桌面上方显示不下矩形 rectTemp = rect; rectTemp.left = rect.left - rect.Width() - space * 2; rectTemp.right = rect.right - rect.Width() - space * 2;; rect = rectTemp; } if((pt.y - rect.Height())<=0) { //桌面右方显示不下矩形 rectTemp = rect; rectTemp.top = rect.top + rect.Height() + space * 2; rectTemp.bottom = rect.bottom + rect.Height() + space * 2; rect=rectTemp; } //创建空画刷画矩形 CBrush brush(m_clrWndBackgndColor); CPen* pOldPen = dc.SelectObject(&pen); CBrush* pOldBrush = dc.SelectObject(&brush); dc.Rectangle(rect); dc.SelectObject(pOldBrush); rect.top+=2; //在矩形中显示文字 CString string(_T(" 顶点位置 ")); dc.TextOut(rect.left,rect.top,string); string.Format(" (%d,%d)", inRect.left,inRect.top); dc.TextOut(rect.left, rect.top + charHeight, string); string = _T(" 矩形大小 "); dc.TextOut(rect.left, rect.top + charHeight*2, string); string.Format(" (%d,%d)", inRect.Width(), inRect.Height()); dc.TextOut(rect.left, rect.top+charHeight*3, string); string = _T(" 光标坐标 "); dc.TextOut(rect.left, rect.top+charHeight*4, string); string.Format(" (%d,%d)", pt.x, pt.y); dc.TextOut(rect.left, rect.top + charHeight*5, string); dc.SelectObject(pOldFont); dc.SelectObject(pOldPen); pen.DeleteObject(); brush.DeleteObject(); font.DeleteObject(); }
void specCanvasItem::setPenColor(const QColor& newColor) { QPen newPen(pen()); newPen.setColor(newColor); setPen(newPen) ; }
void renderCodeEAN13(OROPage * page, const QRectF & r, const QString & _str, ORBarcodeData * bc) { int val[13]; int i = 0; // initialize all the values just so we can be predictable for(i = 0; i < 13; i++) val[i] = -1; // verify that the passed in string is valid // if it's not either twelve or thirteen characters // then it must be invalid to begin with if(_str.length() != 12 && _str.length() != 13) return; // loop through and convert each char to a digit. // if we can't convert all characters then this is // an invalid number for(i = 0; i < _str.length(); i++) { val[i] = ((QChar)_str.at(i)).digitValue(); if(val[i] == -1) return; } // calculate and append the checksum value int old_sum = val[12]; // get the old check sum value (-1 if none was set) int checksum = 0; for(i = 0; i < 12; i++) checksum += val[i] * (i % 2 ? 3 : 1); checksum = (checksum % 10); if(checksum) checksum = 10 - checksum; val[12] = checksum; // if we had an old checksum value and if it doesn't match what we came // up with then the string must be invalid so we will bail if(old_sum != -1 && old_sum != checksum) return; // lets determine some core attributes about this barcode qreal bar_width = bc->narrowBarWidth; // this is are mandatory minimum quiet zone qreal quiet_zone = bar_width * 10; if(quiet_zone < 0.1) quiet_zone = 0.1; // what kind of area do we have to work with qreal draw_width = r.width(); qreal draw_height = r.height() - 0.02; // L = 95X // L length of barcode (excluding quite zone) in units same as X and I // X the width of a bar (pixels in our case) qreal L; qreal X = bar_width; L = (95.0 * X); // now we have the actual width the barcode will be so can determine the actual // size of the quiet zone (we assume we center the barcode in the given area // what should we do if the area is too small???? // At the moment the way the code is written is we will always start at the minimum // required quiet zone if we don't have enough space.... I guess we'll just have over-run // to the right // // calculate the starting position based on the alignment option // for left align we don't need to do anything as the values are already setup for it if(bc->align == 1) // center { qreal nqz = (draw_width - L) / 2; if(nqz > quiet_zone) quiet_zone = nqz; } else if(bc->align > 1) // right quiet_zone = draw_width - (L + quiet_zone); // else if(align < 1) {} // left : do nothing qreal pos = r.left() + quiet_zone; qreal top = r.top(); QPen pen(Qt::NoPen); QBrush brush(QColor("black")); int b = 0; int w = 0; // render open guard ORORect * rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += bar_width; // render first set for(i = 0; i < 6; i++) { b = val[i+1]; for(w = 0; w < 7; w++) { if(_encodings[b][_parity[val[0]][i]][w]) { rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height-0.07)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); } pos += bar_width; } } // render center guard pos += bar_width; rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); // render last set for(i = 0; i < 6; i++) { b = val[i+7]; for(w = 0; w < 7; w++) { if(_encodings[b][RIGHTHAND][w]) { rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height-0.07)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); } pos += bar_width; } } // render close guard rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); pos += (bar_width * 2.0); rect = new ORORect(bc); rect->setPen(pen); rect->setBrush(brush); rect->setRect(QRectF(pos,top, bar_width,draw_height)); rect->setRotationAxis(r.topLeft()); page->addPrimitive(rect); QString parstr = QString("%1").arg(val[0]); QString leftstr = QString().sprintf("%d%d%d%d%d%d", val[1], val[2], val[3], val[4], val[5], val[6]); QString rightstr = QString().sprintf("%d%d%d%d%d%d", val[7], val[8], val[9], val[10], val[11], val[12]); QFont font("Arial", 6); OROTextBox * tb = new OROTextBox(bc); tb->setPosition(QPointF(r.left(), r.top() + draw_height - 0.12)); tb->setSize(QSizeF(quiet_zone - 0.02, 0.12)); tb->setFont(font); tb->setText(parstr); tb->setFlags(Qt::AlignRight | Qt::AlignTop); tb->setRotationAxis(r.topLeft()); page->addPrimitive(tb); tb = new OROTextBox(bc); tb->setPosition(QPointF(r.left() + quiet_zone + bar_width*3, (r.top() + draw_height) - 0.07)); tb->setSize(QSizeF(bar_width*40, 0.1)); tb->setFont(font); tb->setText(leftstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); tb->setRotationAxis(r.topLeft()); page->addPrimitive(tb); tb = new OROTextBox(bc); tb->setPosition(QPointF(r.left() + quiet_zone + bar_width*50, (r.top() + draw_height) - 0.07)); tb->setSize(QSizeF(bar_width*40, 0.1)); tb->setFont(font); tb->setText(rightstr); tb->setFlags(Qt::AlignHCenter | Qt::AlignTop); tb->setRotationAxis(r.topLeft()); page->addPrimitive(tb); return; }
/**< paint wnd. */ void ImagePanel::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); wxSize szWnd = GetClientSize(); // erase background if (!m_dcMem.IsOk()) return; m_dcMem.Clear(); //--------------------Begin double buffer draw // draw image if (m_img.IsOk()) { wxBitmap bmp(m_img); wxMemoryDC dcImg(bmp); m_dcMem.StretchBlit( (wxCoord)m_rcDest.m_x, (wxCoord)m_rcDest.m_y, (wxCoord)m_rcDest.m_width, (wxCoord)m_rcDest.m_height, (wxDC*)&dcImg, (wxCoord)m_rcSrc.m_x, (wxCoord)m_rcSrc.m_y, (wxCoord)m_rcSrc.m_width, (wxCoord)m_rcSrc.m_height ); dcImg.SelectObject(wxNullBitmap); } // draw sel rect fot zoom if (m_stMP.emFuc == IMGPL_CMD::IMG_ZRECT && m_stMP.iState == 2 && m_stMP.rcSel.width > 0) { wxPen pen(wxColour(0x00ff0000), 1, wxPENSTYLE_DOT); m_dcMem.SetPen(pen); m_dcMem.SetLogicalFunction(wxOR_REVERSE); m_dcMem.SetBrush(wxNullBrush); m_dcMem.DrawRectangle(m_stMP.rcSel); m_dcMem.SetLogicalFunction(wxCOPY); m_dcMem.SetPen(wxNullPen); } // draw sel circle else if (m_stMP.emFuc == IMGPL_CMD::SEL_CIRCLE && m_stMP.iState == 2 && m_stMP.rcSel.width > 0) { wxPen pen(wxColour(0x00ff0000), 1, wxPENSTYLE_DOT); m_dcMem.SetPen(pen); m_dcMem.SetLogicalFunction(wxOR_REVERSE); m_dcMem.SetBrush(wxNullBrush); m_dcMem.DrawCircle(m_stMP.rcSel.x, m_stMP.rcSel.y, m_stMP.rcSel.width); m_dcMem.SetLogicalFunction(wxCOPY); m_dcMem.SetPen(wxNullPen); } // draw a sel ellipse else if (m_stMP.emFuc == IMGPL_CMD::SEL_ELLIPSE && m_stMP.iState == 2 && m_stMP.rcSel.width > 0) { wxPen pen(wxColour(0x00ff0000), 1, wxPENSTYLE_DOT); m_dcMem.SetPen(pen); m_dcMem.SetLogicalFunction(wxOR_REVERSE); m_dcMem.SetBrush(wxNullBrush); m_dcMem.DrawEllipse(m_stMP.rcSel); m_dcMem.SetLogicalFunction(wxCOPY); m_dcMem.SetPen(wxNullPen); } // draw a sel square / rectangle else if ((m_stMP.emFuc == IMGPL_CMD::SEL_SQUARE || m_stMP.emFuc == IMGPL_CMD::SEL_RECTANGLE) && m_stMP.iState == 2 && m_stMP.rcSel.width > 0) { wxPen pen(wxColour(0x00ff0000), 1, wxPENSTYLE_DOT); m_dcMem.SetPen(pen); m_dcMem.SetLogicalFunction(wxOR_REVERSE); m_dcMem.SetBrush(wxNullBrush); m_dcMem.DrawRectangle(m_stMP.rcSel); m_dcMem.SetLogicalFunction(wxCOPY); m_dcMem.SetPen(wxNullPen); } //--------------------End double buffer draw dc.Blit(0, 0, szWnd.x, szWnd.y, &m_dcMem, 0, 0); }
KoPenCmd::Pen KPrPenStyleWidget::getPen() const { KoPenCmd::Pen pen( getKPPen(), getLineBegin(), getLineEnd() ); return pen; }
void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) { Q_UNUSED( itemStyle ); Q_UNUSED( pWidget ); if ( !painter ) { return; } drawBackground( painter ); painter->save(); //antialiasing on painter->setRenderHint( QPainter::Antialiasing, true ); double penWidth = hasFrame() ? pen().widthF() : 0; QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin, rect().height() - 2 * penWidth - 2 * mMargin ); QString textToDraw = displayText(); if ( mHtmlState ) { painter->scale( 1.0 / mHtmlUnitsToMM / 10.0, 1.0 / mHtmlUnitsToMM / 10.0 ); QWebPage *webPage = new QWebPage(); webPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() ); //Setup event loop and timeout for rendering html QEventLoop loop; QTimer timeoutTimer; timeoutTimer.setSingleShot( true ); //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/ QPalette palette = webPage->palette(); palette.setBrush( QPalette::Base, Qt::transparent ); webPage->setPalette( palette ); //webPage->setAttribute(Qt::WA_OpaquePaintEvent, false); //this does not compile, why ? webPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToMM * 10.0, painterRect.height() * mHtmlUnitsToMM * 10.0 ) ); webPage->mainFrame()->setZoomFactor( 10.0 ); webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff ); webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff ); // QGIS segfaults when rendering web page while in composer if html // contains images. So if we are not printing the composition, then // disable image loading if ( mComposition->plotStyle() != QgsComposition::Print && mComposition->plotStyle() != QgsComposition::Postscript ) { webPage->settings()->setAttribute( QWebSettings::AutoLoadImages, false ); } //Connect timeout and webpage loadFinished signals to loop connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) ); connect( webPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) ); //mHtmlLoaded tracks whether the QWebPage has completed loading //its html contents, set it initially to false. The loadingHtmlFinished slot will //set this to true after html is loaded. mHtmlLoaded = false; connect( webPage, SIGNAL( loadFinished( bool ) ), SLOT( loadingHtmlFinished( bool ) ) ); webPage->mainFrame()->setHtml( textToDraw ); //For very basic html labels with no external assets, the html load will already be //complete before we even get a chance to start the QEventLoop. Make sure we check //this before starting the loop if ( !mHtmlLoaded ) { // Start a 20 second timeout in case html loading will never complete timeoutTimer.start( 20000 ); // Pause until html is loaded loop.exec(); } webPage->mainFrame()->render( painter );//DELETE WEBPAGE ? } else {
void HandleItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { //TODO: handle proper highlighting at scene level when dragging setPen({Qt::gray, (qreal)(pen().width())}); QGraphicsItem::hoverEnterEvent(event); }
/** * Reimplemented from QGraphicsItem::paint. * Draws the AssociationLine and also takes care of highlighting active point or line. */ void AssociationLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(widget) QPen _pen = pen(); const QColor orig = _pen.color().lighter(); QColor invertedColor(orig.green(), orig.blue(), orig.red()); if (invertedColor == _pen.color()) { // Ensure different color. invertedColor.setRed((invertedColor.red() + 50) % 256); } invertedColor.setAlpha(150); int sz = m_points.size(); if (sz < 1) { // not enough points - do nothing return; } QPointF savedStart = m_points.first(); QPointF savedEnd = m_points.last(); // modify the m_points array not to include the Symbol, the value depends on Symbol if (m_startSymbol) { QPointF newStart = m_startSymbol->mapToParent(m_startSymbol->symbolEndPoints().first); m_points[0] = newStart; } if (m_endSymbol) { QPointF newEnd = m_endSymbol->mapToParent(m_endSymbol->symbolEndPoints().first); m_points[sz - 1] = newEnd; } painter->setPen(_pen); painter->setBrush(Qt::NoBrush); painter->drawPath(path()); if (option->state & QStyle::State_Selected) { // make the association broader in the selected state QPainterPathStroker stroker; stroker.setWidth(3.0); QPainterPath outline = stroker.createStroke(path()); QColor shadowColor(Qt::lightGray); shadowColor.setAlpha(80); QBrush shadowBrush(shadowColor); painter->setBrush(shadowBrush); painter->setPen(Qt::NoPen); painter->drawPath(outline); // set color for selected painting _pen.setColor(Qt::blue); QRectF circle(0, 0, SelectedPointDiameter, SelectedPointDiameter); painter->setBrush(_pen.color()); painter->setPen(Qt::NoPen); // draw points circle.moveCenter(savedStart); painter->drawRect(circle); for (int i = 1; i < sz-1; ++i) { if (i != m_activePointIndex) { circle.moveCenter(m_points.at(i)); painter->drawRect(circle); } } circle.moveCenter(savedEnd); painter->drawRect(circle); if (m_activePointIndex != -1) { painter->setBrush(invertedColor); painter->setPen(Qt::NoPen); circle.setWidth(1.5*SelectedPointDiameter); circle.setHeight(1.5*SelectedPointDiameter); circle.moveCenter(m_points.at(m_activePointIndex)); painter->drawEllipse(circle); } else if (m_activeSegmentIndex != -1) { if (m_layout == Polyline) { painter->setPen(QPen(invertedColor, _pen.widthF() + 1)); painter->setBrush(Qt::NoBrush); QLineF segmentLine(m_points[m_activeSegmentIndex], m_points[m_activeSegmentIndex + 1]); painter->drawLine(segmentLine); } } // debug info if (Tracer::instance()->isEnabled(QString::fromLatin1(metaObject()->className()))) { painter->setPen(Qt::green); painter->setBrush(Qt::NoBrush); painter->drawPath(shape()); painter->setPen(Qt::red); painter->drawRect(boundingRect()); // origin painter->drawLine(-10, 0, 10, 0); painter->drawLine(0, -10, 0, 10); } } // now restore the points array m_points[0] = savedStart; m_points[sz - 1] = savedEnd; }
//! Update the widget that represents the curve on the legend void QwtPlotCurve::updateLegend(QwtLegend *legend) const { if ( !legend ) return; QwtPlotItem::updateLegend(legend); QWidget *widget = legend->find(this); if ( !widget || !widget->inherits("QwtLegendItem") ) return; QwtLegendItem *legendItem = (QwtLegendItem *)widget; #if QT_VERSION < 0x040000 const bool doUpdate = legendItem->isUpdatesEnabled(); #else const bool doUpdate = legendItem->updatesEnabled(); #endif legendItem->setUpdatesEnabled(false); const int policy = legend->displayPolicy(); if (policy == QwtLegend::FixedIdentifier) { int mode = legend->identifierMode(); if (mode & QwtLegendItem::ShowLine) legendItem->setCurvePen(pen()); if (mode & QwtLegendItem::ShowSymbol) legendItem->setSymbol(symbol()); if (mode & QwtLegendItem::ShowText) legendItem->setText(title()); else legendItem->setText(QwtText()); legendItem->setIdentifierMode(mode); } else if (policy == QwtLegend::AutoIdentifier) { int mode = 0; if (QwtPlotCurve::NoCurve != style()) { legendItem->setCurvePen(pen()); mode |= QwtLegendItem::ShowLine; } if (QwtSymbol::NoSymbol != symbol().style()) { legendItem->setSymbol(symbol()); mode |= QwtLegendItem::ShowSymbol; } if ( !title().isEmpty() ) { legendItem->setText(title()); mode |= QwtLegendItem::ShowText; } else { legendItem->setText(QwtText()); } legendItem->setIdentifierMode(mode); } legendItem->setUpdatesEnabled(doUpdate); legendItem->update(); }
void QNeedleIndicator::drawBackground(void) { int side = qMin(width(), height()); /* Keep side size an even number by trunkating odd pixel */ side &= ~0x01; QRadialGradient gradient; QPainter painter(this); QPen pen(Qt::black); pen.setWidth(1); /* Initialize painter */ painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); painter.scale(side / 256.0, side / 256.0); painter.setPen(pen); /* Draw external circle */ gradient = QRadialGradient (QPointF(-128,-128), 384, QPointF(-128,-128)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPoint(0,0),125,125); /* Draw inner circle */ gradient = QRadialGradient(QPointF(128,128), 384, QPointF(128,128)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPoint(0,0),118,118); /* Draw inner shield */ gradient = QRadialGradient (QPointF(-128,-128), 384, QPointF(-128,-128)); gradient.setColorAt(0, QColor(255,255,255)); gradient.setColorAt(1, QColor(224,224,224)); painter.setBrush(gradient); painter.setPen(Qt::NoPen); painter.drawEllipse(QPoint(0,0), 115, 115); painter.setPen(pen); painter.setBrush(Qt::black); painter.drawPoint(0,0); int line = 10; /* FIX #1 */ /* Draw scale majorTicks using coords rotation */ painter.save(); painter.setBrush(Qt::black); painter.rotate(start_angle); /* initial angle (first tick) */ painter.setBrush(QBrush(Qt::black)); qreal t_rot = stop_angle/(minorTicks*(majorTicks-1)+majorTicks-1); for(int i = 0; i < (minorTicks)*(majorTicks-1)+majorTicks; i++) { if( minorTicks ) { if( i%(int)(minorTicks+1) == 0 ) painter.drawLine(QPoint(105,0), QPoint(105-line, 0)); else painter.drawLine(QPoint(105,0), QPoint(105-line/3, 0)); } else { painter.drawLine(QPoint(105,0), QPoint(105-line, 0)); } painter.rotate(t_rot); } painter.restore(); /* Draw scale numbers using vector rotation */ /* x' = xcos(a)-ysin(a) */ /* y' = xsin(a)-ycos(a) */ painter.save(); qreal rotation = (start_angle/360)*2*M_PI; /* Initial rotation */ painter.setFont(digitFont); for(int i = 0; i < majorTicks; i++) { QPointF point((70*cos(rotation)), 70*sin(rotation)); /* calculate digit coords */ QString value = QString().sprintf(scaleFormat.constData(), min+(qreal)i*step); /* convert digit to string */ QSize size = painter.fontMetrics().size(Qt::TextSingleLine, value); /* get string size in px */ point.rx() -= size.width()/2; /* center-align string (horiz) */ point.ry() += size.height()/4; /* center-align string (vert) */ painter.drawText(point, value); //painter.drawPoint(point); rotation+=rot_rad; /* go to next tick */ } painter.restore(); /* Draw meter label */ if( label.size() ) { painter.setFont(labelFont); QSize size = painter.fontMetrics().size(Qt::TextSingleLine, label); QPointF point; point.rx() -= size.width()/2; /* center-align string (horiz) */ point.ry() += size.height()/4 + labelOffset; /* shift down, below needle */ painter.drawText(point, label); /* blop! */ } }