WMNMap::WMNMap(QWidget *parent) : QWidget(parent) { qsrand(QTime::currentTime().hour() * 3600 + QTime::currentTime().minute() * 60 + QTime::currentTime().second()); _Self = this; TrafficMap << 35 << 10 << 45 << 100 << 70 << 85 << 60 << 50; bzero(&inputParams, 0); haveInputParams = false; QPen redPen(Qt::red); redPen.setWidth(4); QPen bluePen(Qt::blue); bluePen.setWidth(4); QPen greenPen(Qt::green); greenPen.setWidth(4); QPen grayPen(Qt::gray); grayPen.setWidth(4); WMNArea = new QwtPlot(QwtText("Wireless Mesh Network Implementation")); // WMNArea->setAxisScale(0, 0, inputParams.squareArea); // WMNArea->setAxisScale(2, 0, inputParams.squareArea); curveMAP = new QwtPlotCurve("MAPs"); curveMAP->setRenderHint(QwtPlotItem::RenderAntialiased); curveMAP->setPen(redPen); curveMAP->setStyle(QwtPlotCurve::Dots); curveMAP->attach(WMNArea); curveMR = new QwtPlotCurve("MRs"); curveMR->setRenderHint(QwtPlotItem::RenderAntialiased); curveMR->setPen(bluePen); curveMR->setStyle(QwtPlotCurve::Dots); curveMR->attach(WMNArea); curveTP = new QwtPlotCurve("TPs"); curveTP->setRenderHint(QwtPlotItem::RenderAntialiased); curveTP->setPen(greenPen); curveTP->setStyle(QwtPlotCurve::Dots); curveTP->attach(WMNArea); curveDA = new QwtPlotCurve("MAPs"); curveDA->setRenderHint(QwtPlotItem::RenderAntialiased); curveDA->setPen(grayPen); curveDA->setStyle(QwtPlotCurve::Dots); curveDA->attach(WMNArea); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(WMNArea); this->setLayout(layout); this->setWindowTitle(QTextCodec::codecForName("UTF8")->toUnicode("Сгенерированная WMN")); }
void DlgHisto::OnPaint() { CPaintDC dc(this); // device context for painting CDemoDoc* pDoc = (CDemoDoc*) ((CMainFrame*)AfxGetMainWnd())->GetActiveFrame()->GetActiveDocument(); RECT r; GetClientRect(&r); CPen gridPen(PS_DOT,1,::GetSysColor(COLOR_APPWORKSPACE)); CPen* pOldPen = dc.SelectObject(&gridPen); for (int gx=9+32;gx<265;gx+=32){ dc.MoveTo(gx,40); dc.LineTo(gx,r.bottom - 6); } for (int gy=0;gy<(r.bottom - 40);gy+=((r.bottom - 40)/10)){ dc.MoveTo(8,r.bottom - 9 - gy); dc.LineTo(268,r.bottom - 9 - gy); } dc.SelectObject(pOldPen); CPen axisPen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); pOldPen = dc.SelectObject(&axisPen); dc.MoveTo(9, 38); dc.LineTo(9, r.bottom - 9); dc.LineTo(266, r.bottom - 9); dc.LineTo(266, 38); dc.SelectObject(pOldPen); if (pDoc && pDoc->image) { if (pDoc->m_hmax){ int ybase = r.bottom-10; if (m_logen){ float yratio = (r.bottom - r.top - 50)/(float)log10((float)(pDoc->m_hmax+1)); if (m_ren){ CPen redPen(PS_SOLID, 1, RGB(222, 0, 0)); pOldPen = dc.SelectObject(&redPen); dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hr[0]))*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hr[x]))*yratio)); } if (m_gen){ CPen greenPen(PS_SOLID, 1, RGB(0, 222, 0)); pOldPen = dc.SelectObject(&greenPen); dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hg[0]))*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hg[x]))*yratio)); } if (m_ben){ CPen bluePen(PS_SOLID, 1, RGB(0, 0, 222)); pOldPen = dc.SelectObject(&bluePen); dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hb[0]))*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hb[x]))*yratio)); } if (m_grayen){ CPen grayPen(PS_SOLID, 1, RGB(64, 64, 64)); pOldPen = dc.SelectObject(&grayPen); dc.MoveTo(10, (int)(ybase-log10((float)(1+pDoc->m_hgray[0]))*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-log10((float)(1+pDoc->m_hgray[x]))*yratio)); } dc.SelectObject(pOldPen); } else { float yratio = (r.bottom - r.top - 50)/(float)pDoc->m_hmax; if (m_ren){ CPen redPen(PS_SOLID, 1, RGB(222, 0, 0)); pOldPen = dc.SelectObject(&redPen); dc.MoveTo(10, (int)(ybase-pDoc->m_hr[0]*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-pDoc->m_hr[x]*yratio)); } if (m_gen){ CPen greenPen(PS_SOLID, 1, RGB(0, 222, 0)); pOldPen = dc.SelectObject(&greenPen); dc.MoveTo(10, (int)(ybase-pDoc->m_hg[0]*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-pDoc->m_hg[x]*yratio)); } if (m_ben){ CPen bluePen(PS_SOLID, 1, RGB(0, 0, 222)); pOldPen = dc.SelectObject(&bluePen); dc.MoveTo(10, (int)(ybase-pDoc->m_hb[0]*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-pDoc->m_hb[x]*yratio)); } if (m_grayen){ CPen grayPen(PS_SOLID, 1, RGB(64, 64, 64)); pOldPen = dc.SelectObject(&grayPen); dc.MoveTo(10, (int)(ybase-pDoc->m_hgray[0]*yratio)); for (int x=1; x<256; x++) dc.LineTo(x+10, (int)(ybase-pDoc->m_hgray[x]*yratio)); } dc.SelectObject(pOldPen); } } else { pDoc->m_hmax=pDoc->GetImage()->Histogram(pDoc->m_hr,pDoc->m_hg,pDoc->m_hb,pDoc->m_hgray); if (pDoc->m_hmax) Invalidate(); } } }
void CalendarWidget::calculateAndDrawMonth(int j_y, int j_m, int j_d) { monthPixmap = QPixmap(this->size()); //Must be done. //`Qt::transparent` is equivalent to `QColor::fromRgb(0,0,0,0)` or `QColor::fromRgba(0)`. //We could also have used `palette().color(QPalette::Window)`. monthPixmap.fill(Qt::transparent); QPainter p(&monthPixmap); QPen blackPen(QColor(0, 0, 0)); QPen grayPen(QColor(192, 192, 192)); QPen blueThickPen(QColor(0, 0, 255), 2); p.setPen(blackPen); int hUnit = this->width() / 7; int vUnit = this->height() / 7; QString title = Ct::Date::PersianDate::nameOfMonth(j_m) + " " + QString::number(j_y); QRect titleRect(0, 0, this->width(), vUnit); titleRect.adjust(1, 1, -1, -1); p.fillRect(titleRect, QColor(64, 128, 255)); QFont boldFont = this->font(); boldFont.setBold(true); p.setFont(boldFont); p.drawText(titleRect, Qt::AlignCenter, title); for (int i = 0; i < 7; i++) { QRect cellRect((6 - i) * hUnit, vUnit, hUnit, vUnit); cellRect.adjust(1, 1, -1, -1); if (i == 6) p.fillRect(cellRect, QColor(96, 160, 255)); else p.fillRect(cellRect, QColor(128, 192, 255)); p.drawText(cellRect, Qt::AlignCenter, Ct::Date::PersianDate::nameOfPersianWeekDay(i + 1)); for (int j = 0; j < 7; j++) datestamps[j][i] = 0; } QDate firstDayOfJalaliMonth; Ct::Date::PersianDate::JalaliToGregorian(firstDayOfJalaliMonth, j_y, j_m, 1); //Without the QTime of 12 P.M, we got problems on 26/27 Esfand 1391 = 16/17 March 2013: // Both shows the same date! This was on Win7. On WinXP it was on the same month at different // days and in linux I did not test. QDateTime dateStamp(firstDayOfJalaliMonth, QTime(12, 0, 0)); int hPos = 0; int vPos = 2; int mapWeekStartDayFromMondayToSaturday[] = { 0, 3, 4, 5, 6, 7, 1, 2 }; int PersianWeekStartDay = mapWeekStartDayFromMondayToSaturday[firstDayOfJalaliMonth.dayOfWeek()]; hPos = PersianWeekStartDay - 1; int modFridays = (8 - PersianWeekStartDay) % 7; int jalaliMonthDayCount = Ct::Date::PersianDate::numberOfDaysInJalaliMonth(j_y, j_m); QFont smallEnglishFont("Tahoma", 8, QFont::Bold); for (int i = 1; i <= jalaliMonthDayCount; i++) { QRect cellRect((6 - hPos) * hUnit, vPos * vUnit, hUnit, vUnit); cellRect.adjust(1, 1, -1, -1); if (i % 7 == modFridays) p.fillRect(cellRect, QColor(128, 192, 255)); else p.fillRect(cellRect, Qt::white); if (i == j_d) //Today { p.setPen(blueThickPen); p.drawRect(cellRect); } //Draw the Gregorian number FIRST so that it goes lower than the Persian day in high-DPI. if (settings.showGregorianDates) { p.setPen(grayPen); p.setFont(smallEnglishFont); QString dayText = ""; //In case either Persian or Gregorian day is 1, we add the short month name (MMM). Since // in Persian locale the month name is localized, we also add space before it to have // some right margin. if (i == 1 || dateStamp.date().day() == 1) dayText = " " + dateStamp.date().toString("MMM") + " "; //We add space after the day because some right margin is always useful! Of course this space // is used if a localized month name wasn't added to the day number. dayText += QString::number(dateStamp.date().day()) + " "; p.drawText(cellRect, Qt::AlignRight | Qt::AlignBottom, dayText); } p.setPen(blackPen); p.setFont(this->font()); p.drawText(cellRect, Qt::AlignCenter, QString::number(i)); //FIRST save the datestamps datestamps[(6 - hPos)][vPos] = dateStamp.toMSecsSinceEpoch(); dateStamp = dateStamp.addDays(1); //THEN 'increase' hPos/vPos hPos++; if (hPos == 7) { hPos = 0; vPos++; if (vPos == 7) vPos = 2; //Draw the excess 30th and 31th day in the top row. } } }
void CListViewNode::OnPaint(Gdiplus::Graphics* graphics, INT xPos, INT yPos, INT cBottom, INT cRight) { if ( !m_listView ) return; RECT iconRect; ::CopyRect(&iconRect, &m_iconRect); ::OffsetRect(&iconRect, -xPos, -yPos); RECT textRect; ::CopyRect(&textRect, &m_textRect); ::OffsetRect(&textRect, -xPos, -yPos); RECT borderRect; ::CopyRect(&borderRect, &m_borderRect); borderRect.right = borderRect.left + cRight; ::OffsetRect(&borderRect, 0, -yPos); if ( iconRect.bottom < 0 ) return; if ( iconRect.top >= cBottom ) return; Gdiplus::Font* pFont = NULL; Gdiplus::Brush* pBrushBackground = NULL; Gdiplus::Brush* pBrushForeground = NULL; if ( m_selected ) { pFont = m_listView->get_Font(_T(".Font.Selected"), _T("ListView")); pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Selected"), _T("ListView"), Gdiplus::Color::Blue); pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Selected"), _T("ListView"), Gdiplus::Color::White); } else { pFont = m_listView->get_Font(_T(".Font.Normal"), _T("ListView")); pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Normal"), _T("ListView"), Gdiplus::Color::White); pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Normal"), _T("ListView"), Gdiplus::Color::Black); } Gdiplus::RectF iconRectF; Convert2RectF(&iconRectF, &iconRect); Gdiplus::RectF textRectF; Convert2RectF(&textRectF, &textRect); Gdiplus::RectF borderRectF; Convert2RectF(&borderRectF, &borderRect); Gdiplus::PointF pt; pt.X = textRectF.X; pt.Y = textRectF.Y; graphics->FillRectangle(pBrushBackground, borderRectF); Gdiplus::Bitmap* image = NULL; UINT hImage = 0; if ( (m_imageIndex >= 0) && (((dword)m_imageIndex) < m_listView->get_ImageCount()) ) image = m_listView->get_Image(m_imageIndex); if ( image && (image->GetHeight() > 0) ) hImage = image->GetHeight(); if ( hImage > 0 ) { Gdiplus::Color transparentcolor; Gdiplus::ImageAttributes imAtt; image->GetPixel(0, hImage - 1, &transparentcolor); imAtt.SetColorKey(transparentcolor, transparentcolor, Gdiplus::ColorAdjustTypeBitmap); graphics->DrawImage(image, iconRectF, 0.0, 0.0, Cast(Gdiplus::REAL,hImage), Cast(Gdiplus::REAL,hImage), Gdiplus::UnitPixel, &imAtt); } if ( !(m_text.IsEmpty()) ) graphics->DrawString(m_text.GetString(), m_textDisplayLength, pFont, pt, Gdiplus::StringFormat::GenericTypographic(), pBrushForeground); if ( m_focused ) { Gdiplus::Pen grayPen(Gdiplus::Color::Gray); grayPen.SetDashStyle(Gdiplus::DashStyleDot); graphics->DrawRectangle(&grayPen, textRectF); } }
void BehavePlusApp::drawSplashPage( void ) { // If unable to load the picture, make a plain cyan backdrop instead if ( m_pixmap.isNull() ) // This code block should never be executed! { m_pixmap.resize( 700, 500 ); QPainter paint( &m_pixmap ); paint.fillRect( 0, 0, 700, 500, QBrush( "cyan", SolidPattern ) ); paint.end(); } // Painter attributes int align = Qt::AlignHCenter | Qt::AlignTop ; //static QString fontName( "Times New Roman" ); static QString fontName( "Arial" ); QFont fnt1( fontName, 48, QFont::Bold, false ); QFont fnt2( fontName, 24, QFont::Bold, false ); QFont fnt3( fontName, 16, QFont::Bold, false ); QFontMetrics fm1( fnt1 ); QFontMetrics fm2( fnt2 ); QFontMetrics fm3( fnt3 ); QPen blackPen( black ); QPen grayPen( gray ); QPen redPen( red ); QPen whitePen( white ); // Draw shadowed name QPainter paint( &m_pixmap ); int wd = m_pixmap.width(); int ht = m_pixmap.height() + 3 * fm3.lineSpacing(); paint.setFont( fnt1 ); paint.setPen( grayPen ); int y0 = fm1.lineSpacing()/8; paint.drawText( 4, y0+4, wd, ht, align, m_program ); paint.setPen( blackPen ); paint.drawText( 2, y0+2, wd, ht, align, m_program ); paint.setPen( whitePen ); paint.drawText( 0, y0, wd, ht, align, m_program ); // Draw sub name and version y0 += 3*fm1.lineSpacing()/4; paint.setFont( fnt2 ); paint.drawText( 0, y0, wd, ht-y0, align, "fire modeling system" ); y0 += 3*fm2.lineSpacing()/4; paint.drawText( 0, y0, wd, ht-y0, align, "Version " + m_version ); // Warning if ( ShowWarning ) { y0 += 3 * fm2.lineSpacing(); paint.setFont( fnt2 ); paint.setPen( redPen ); paint.drawText( 0, y0, wd, ht-y0, align, "This is pre-release software" ); y0 += fm2.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "for testing purposes only!" ); y0 += fm2.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "Use at Your Own Risk!" ); } // Authors y0 = ht - 6 * fm3.lineSpacing(); paint.setFont( fnt3 ); paint.setPen( whitePen ); paint.drawText( 0, y0, wd, ht-y0, align, "US Forest Service, Rocky Mountain Research Station" ); y0 += fm3.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "& Systems for Environmental Management" ); paint.end(); // Status message display area m_statusLine = ht - 2 * fm3.lineSpacing(); return; }