本文整理汇总了C++中QPainter::drawRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::drawRect方法的具体用法?C++ QPainter::drawRect怎么用?C++ QPainter::drawRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::drawRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
//.........这里部分代码省略.........
if(label.length() > 0 && ((pos + refwidth_div_2) - last_label_at) > ((label_offset * 2) + 1)) {
last_label_at = pos + refwidth_div_2;
int lx = (int)(((pos + refwidth_div_2) * cos45deg) - ((gy2 + label_offset) * sin45deg));
int ly = (int)(((pos + refwidth_div_2) * sin45deg) + ((gy2 + label_offset) * cos45deg));
int fmwidth = fm.width(label);
paint.save();
paint.rotate(-45);
paint.drawText(lx - fmwidth, ly - fmheight_div_2, fmwidth, fmheight, Qt::AlignRight | Qt::AlignTop, label);
paint.restore();
}
QMapIterator<int, double> sit(ref.second);
paint.save();
if(drawBars() == true) {
TSetValue tval;
QMap<double, TSetValue> sort_map;
sit = ref.second;
while(sit.hasNext())
{
sit.next();
if(sit.value() != 0.0 && _setStyle[sit.key()].bar == true) {
tval.first = sit.key();
tval.second = sit.value();
sort_map[(tval.second < 0.0 ? minValue() : maxValue()) - (tval.second < 0.0 ? -tval.second : tval.second)] = tval;
}
}
QMapIterator<double, TSetValue> it(sort_map);
while(it.hasNext())
{
it.next();
tval = it.value();
if(tval.second != 0.0) {
if(tval.second < 0) {
bar_height = (int)((tval.second / minValue()) * (gy_org - gy_min));
} else {
bar_height = (int)((tval.second / maxValue()) * (gy_org - gy_max));
}
paint.fillRect(pos + buf, gy_org - bar_height, refwidth - buf2, bar_height, getSetColor(tval.first));
}
}
}
if(drawLines() == true) {
this_map.clear();
sit = ref.second;
while(sit.hasNext())
{
sit.next();
if(_setStyle[sit.key()].line == true) {
this_map[sit.key()] = sit.value();
if(last_map.contains(sit.key())) {
paint.setPen(getSetColor(sit.key()));
double old_val = last_map[sit.key()];
double new_val = sit.value();
int ly1;
if(old_val < 0.0) ly1 = (int)((old_val / minValue()) * (gy_org - gy_min));
else ly1 = (int)((old_val / maxValue()) * (gy_org - gy_max));
ly1 = gy_org - ly1;
int lx1 = pos - refwidth_div_2;
int ly2;
if(new_val < 0.0) ly2 = (int)((new_val / minValue()) * (gy_org - gy_min));
else ly2 = (int)((new_val / maxValue()) * (gy_org - gy_max));
ly2 = gy_org - ly2;
int lx2 = pos + refwidth_div_2;
paint.drawLine(lx1, ly1, lx2, ly2);
}
}
}
last_map = this_map;
}
if(drawPoints() == true) {
sit = ref.second;
while(sit.hasNext())
{
sit.next();
if(_setStyle[sit.key()].point == true) {
paint.setBrush(getSetColor(sit.key()));
paint.setPen(QColor(0,0,0));
int ly1;
if(sit.value() < 0.0) ly1 = (int)((sit.value() / minValue()) * (gy_org - gy_min));
else ly1 = (int)((sit.value() / maxValue()) * (gy_org - gy_max));
ly1 = gy_org - ly1;
int lx1 = pos + refwidth_div_2;
paint.drawEllipse(lx1 - 2, ly1 - 2, 5, 5);
}
}
}
paint.restore();
pos += refwidth;
}
paint.restore();
}
paint.drawLine(gx1, gy_org, gx2 - 1, gy_org);
paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1);
// Now that we are done return the paint device back to the state
// it was when we started to mess with it
paint.restore();
}
示例2: createButton
void QmaxButton::createButton(QPainter &painter)
{
QRect scaledRect;
scaledRect = matrix.mapRect(QRect(0,0,this->logicalSize.width(),this->logicalSize.height()));
QImage bg(this->m_strImage);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
QLinearGradient brush1(0,0,0,scaledRect.height());
painter.drawImage(-2, -2, bg);
if(Colors::useEightBitPalette)
{
painter.setPen(QColor(120,120,120));
if(this->m_nPressed)
painter.setBrush(QColor(60,60,60));
else if(this->m_nHighlight)
painter.setBrush(QColor(100,100,100));
else
painter.setBrush(QColor(80,80,80));
}
else
{
QLinearGradient outlinebrush(0,0,0,scaledRect.height());
QLinearGradient brush(0,0,0,scaledRect.height());
brush.setSpread(QLinearGradient::PadSpread);
QColor highlight(255,255,255,128);
QColor shadow(0,0,0,70);
QColor sunken(220,220,220,30);
QColor normal1(255,255,245,60);
QColor normal2(255,255,235,10);
QColor normal3(200,200,200,10);
QColor normal4(255,255,250,255);
if(m_nType && m_nType != 5 )
{
normal1 = QColor(200,170,160,50);
normal2 = QColor(50,10,0,50);
}
if(m_nPressed)
{
outlinebrush.setColorAt(0.0f,shadow);
outlinebrush.setColorAt(1.0f,highlight);
brush.setColorAt(1.0f,sunken);
painter.setPen(Qt::NoPen);
}
else
{
outlinebrush.setColorAt(1.0f,shadow);
outlinebrush.setColorAt(0.0f,highlight);
brush.setColorAt(0.0f,normal1);
if(m_nHighlight)
brush.setColorAt(1.0f,normal2);
painter.setPen(QPen(outlinebrush,1));
}
if(this->isEnabled()==false )
{
outlinebrush.setColorAt(1.0f,shadow);
outlinebrush.setColorAt(0.0f,highlight);
brush.setColorAt(0.0f,normal3);
painter.setPen(QPen(outlinebrush,1));
}
if(m_nStatus )
{
outlinebrush.setColorAt(1.0f,shadow);
outlinebrush.setColorAt(0.0f,highlight);
brush.setColorAt(0.0f,normal4);
painter.setPen(QPen(outlinebrush,1));
}
painter.setBrush(brush);
}
if(m_nType == 1)
painter.drawRect(0,0,scaledRect.width(),scaledRect.height());
else if(m_nType == 0)
painter.drawRoundedRect(0,0,scaledRect.width(),scaledRect.height(),40.0,40.0,Qt::RelativeSize);
else if(m_nType == 5)
painter.drawEllipse(0,0,scaledRect.width(),scaledRect.height());
QFont font( "DejaVu Sans" );
font.setPointSize( 12 );
painter.setFont( font );
brush1.setColorAt(1.0f,QColor(255,255,255,255));
if(this->isEnabled()==false)
{
brush1.setColorAt(1.0f,QColor(200,200,200,100));
}
painter.setPen(QPen(brush1,1));
painter.setBrush(brush1);
QFontMetrics fMetrics = painter.fontMetrics();
QSize sz = fMetrics.size( Qt::TextWordWrap, m_strText );
QRectF txtRect( scaledRect.center(), sz );
int xPoint = (scaledRect.width()/2)- ((m_strText.count()/2)*10);
int yPoint = scaledRect.height()/2;
painter.drawText(xPoint,yPoint,m_strText);
//.........这里部分代码省略.........
示例3: render
void QgsLayoutTable::render( QgsLayoutItemRenderContext &context, const QRectF &, const int frameIndex )
{
bool emptyTable = mTableContents.length() == 0;
if ( emptyTable && mEmptyTableMode == QgsLayoutTable::HideTable )
{
//empty table set to hide table mode, so don't draw anything
return;
}
if ( !mLayout->renderContext().isPreviewRender() )
{
//exporting composition, so force an attribute refresh
//we do this in case vector layer has changed via an external source (e.g., another database user)
refreshAttributes();
}
//calculate which rows to show in this frame
QPair< int, int > rowsToShow = rowRange( frameIndex );
double gridSizeX = mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0;
double gridSizeY = mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0;
double cellHeaderHeight = QgsLayoutUtils::fontAscentMM( mHeaderFont ) + 2 * mCellMargin;
double cellBodyHeight = QgsLayoutUtils::fontAscentMM( mContentFont ) + 2 * mCellMargin;
QRectF cell;
//calculate whether a header is required
bool drawHeader = ( ( mHeaderMode == QgsLayoutTable::FirstFrame && frameIndex < 1 )
|| ( mHeaderMode == QgsLayoutTable::AllFrames ) );
//calculate whether drawing table contents is required
bool drawContents = !( emptyTable && mEmptyTableMode == QgsLayoutTable::ShowMessage );
int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
int numberEmptyRows = 0;
if ( drawContents && mShowEmptyRows )
{
numberRowsToDraw = rowsVisible( frameIndex, rowsToShow.first, true );
numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
}
bool mergeCells = false;
if ( emptyTable && mEmptyTableMode == QgsLayoutTable::ShowMessage )
{
//draw a merged row for the empty table message
numberRowsToDraw++;
rowsToShow.second++;
mergeCells = true;
}
QPainter *p = context.renderContext().painter();
p->save();
// painter is scaled to dots, so scale back to layout units
p->scale( context.renderContext().scaleFactor(), context.renderContext().scaleFactor() );
//draw the text
p->setPen( Qt::SolidLine );
double currentX = gridSizeX;
double currentY = gridSizeY;
if ( drawHeader )
{
//draw the headers
int col = 0;
for ( const QgsLayoutTableColumn *column : qgis::as_const( mColumns ) )
{
//draw background
p->save();
p->setPen( Qt::NoPen );
p->setBrush( backgroundColor( -1, col ) );
p->drawRect( QRectF( currentX, currentY, mMaxColumnWidthMap[col] + 2 * mCellMargin, cellHeaderHeight ) );
p->restore();
currentX += mCellMargin;
Qt::TextFlag textFlag = static_cast< Qt::TextFlag >( 0 );
if ( column->width() <= 0 )
{
//automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text
//which may slightly exceed the calculated width
//if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width
textFlag = Qt::TextDontClip;
}
cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellHeaderHeight );
//calculate alignment of header
Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
switch ( mHeaderHAlignment )
{
case FollowColumn:
headerAlign = column->hAlignment();
break;
case HeaderLeft:
headerAlign = Qt::AlignLeft;
break;
case HeaderCenter:
headerAlign = Qt::AlignHCenter;
break;
case HeaderRight:
headerAlign = Qt::AlignRight;
break;
}
//.........这里部分代码省略.........
示例4: show
void Brick::show(QPainter &painter) {
painter.drawRect(x(), y(), width(), height());
}
示例5: paint
void paint(QPaintDevice* pd) {
QPainter p;
if (!p.begin(pd)) return;
QPen pe(QColor("black"));
pe.setWidthF(6.0);
pe.setStyle(Qt::DashLine);
p.setPen(pe);
p.drawLine(QPointF(0,0),QPointF(100.0,100.0));
pe.setColor("red");
pe.setStyle(Qt::DotLine);
p.setPen(pe);
p.drawLine(QPointF(0,0),QPointF(50.0,25.0));
pe.setColor("green");
pe.setStyle(Qt::SolidLine);
p.setPen(pe);
p.drawLine(QPointF(0,0),QPointF(25.0,50.0));
pe.setColor("blue");
p.setPen(pe);
p.drawText(50,10, QString("Hello World!"));
p.drawLine(50,10,55,15);
QFont f;
QImage img(QString("qfe_plotterexportercairo.png"));
pe.setWidthF(0.5);
p.setPen(pe);
p.drawImage(QRectF(50,25,50,50), img);
//p.drawRect(QRectF(50,25,50,50));
p.drawImage(QRectF(25,50,15,10), img);
//p.drawRect(QRectF(25,50,15,10));
p.drawImage(QRectF(225,50,100,100), img, QRect(5,5,12,12));
p.drawRect(QRectF(125,50,15,10));
pe.setWidthF(2);
pe.setColor("red");
p.setPen(pe);
f.setFamily("Times New Roman");
f.setPointSizeF(10);
p.setFont(f);
p.drawText(50,30, QString("Hello World!"));
p.drawLine(50,30,55,35);
f.setFamily("Arial");
f.setPointSizeF(16);
p.setFont(f);
p.drawText(250,30, QString("Unicode-test: ")+QChar(0x2190)+QChar(0x2591)+QChar(0x2665)+QChar(0x039B)+QChar(0x03B6));
p.drawLine(250,30,255,35);
pe.setWidthF(1);
p.setPen(pe);
QBrush b(QColor("salmon"));
p.fillRect(QRectF(100,10,50,50), b);
p.drawRect(QRectF(100,10,50,50));
QColor c=b.color();
c.setAlphaF(0.5);
b.setColor(c);
pe.setWidthF(5);
p.setPen(pe);
p.setBrush(b);
p.drawEllipse(QRectF(130,40,50,30));
//p.drawRect(QRectF(130,40,50,30));
QPolygonF poly;
for (int phi=0; phi<60; phi++) {
double p=double(phi)/20.0*M_PI;
poly<<QPointF(50.0+cos(p)*35.0*double(phi)/60.0, 50.0-sin(p)*35.0*double(phi)/60.0);
}
p.setClipRect(0,0,200,50);
pe.setWidthF(1);
p.setPen(pe);
p.drawPolygon(poly);
pe.setColor("red");
pe.setStyle(Qt::DashDotDotLine);
p.setPen(pe);
p.setClipping(false);
p.drawPolyline(poly);
p.end();
}
示例6: paintShot
void CannonField::paintShot(QPainter &painter)
{
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::black);
painter.drawRect(shotRect());
}
示例7: paint
void SpaceElement::paint( QPainter& painter, AttributeManager* )
{
painter.setBrush( QBrush( Qt::lightGray, Qt::DiagCrossPattern ) );
painter.drawRect( QRectF( 0.0, 0.0, width(), height() ) );
}
示例8: draw
void QgsColorSwatchGrid::draw( QPainter &painter )
{
QPalette pal = QPalette( qApp->palette() );
QColor headerBgColor = pal.color( QPalette::Mid );
QColor headerTextColor = pal.color( QPalette::BrightText );
QColor highlight = pal.color( QPalette::Highlight );
//draw header background
painter.setBrush( headerBgColor );
painter.setPen( Qt::NoPen );
painter.drawRect( QRect( 0, 0, width(), LABEL_SIZE ) );
//draw header text
painter.setPen( headerTextColor );
painter.drawText( QRect( LABEL_MARGIN, 0, width() - 2 * LABEL_MARGIN, LABEL_SIZE ),
Qt::AlignLeft | Qt::AlignVCenter, mScheme->schemeName() );
//draw color swatches
QgsNamedColorList::iterator colorIt = mColors.begin();
int index = 0;
for ( ; colorIt != mColors.end(); ++colorIt )
{
int row = index / NUMBER_COLORS_PER_ROW;
int column = index % NUMBER_COLORS_PER_ROW;
QRect swatchRect = QRect( column * ( SWATCH_SIZE + SWATCH_SPACING ) + LEFT_MARGIN,
row * ( SWATCH_SIZE + SWATCH_SPACING ) + TOP_MARGIN + LABEL_SIZE,
SWATCH_SIZE, SWATCH_SIZE );
if ( mCurrentHoverBox == index )
{
//hovered boxes are slightly larger
swatchRect.adjust( -1, -1, 1, 1 );
}
//start with checkboard pattern for semi-transparent colors
if (( *colorIt ).first.alpha() != 255 )
{
QBrush checkBrush = QBrush( transparentBackground() );
painter.setPen( Qt::NoPen );
painter.setBrush( checkBrush );
painter.drawRect( swatchRect );
}
if ( mCurrentHoverBox == index )
{
if ( mDrawBoxDepressed )
{
painter.setPen( QColor( 100, 100, 100 ) );
}
else
{
//hover color
painter.setPen( QColor( 220, 220, 220 ) );
}
}
else if ( mFocused && index == mCurrentFocusBox )
{
painter.setPen( highlight );
}
else if (( *colorIt ).first.name() == mBaseColor.name() )
{
//currently active color
painter.setPen( QColor( 75, 75, 75 ) );
}
else
{
painter.setPen( QColor( 197, 197, 197 ) );
}
painter.setBrush(( *colorIt ).first );
painter.drawRect( swatchRect );
index++;
}
}
示例9: si
//***************************************************************************
void Kwave::LogoWidget::paintEvent(QPaintEvent *)
{
// if image has to be resized ...
if ((rect().height() != m_height) || (rect().width() != m_width)) {
m_height = rect().height();
m_width = rect().width();
if (m_image) delete m_image;
m_image = new QImage(size(), QImage::Format_ARGB32_Premultiplied);
m_repaint = true;
}
if ((m_repaint) && (m_image)) {
QPainter p;
QPolygon si(20 + 3);
p.begin(m_image);
// erase everything to black
p.setPen(Qt::black);
p.setBrush(Qt::black);
p.drawRect(0, 0, m_width, m_height);
// blit logo bitmap
int ampx = (m_logo.width() - m_width ) / 2;
int ampy = (m_logo.height() - m_height) / 2;
p.setCompositionMode(QPainter::CompositionMode_Source);
p.drawPixmap(
-ampx + Kwave::toInt(sin(m_deg[0]) * ampx),
-ampy + Kwave::toInt(sin(m_deg[1]) * ampy),
m_logo);
// draw the sine waves with XOR
p.setCompositionMode(QPainter::CompositionMode_Exclusion);
p.setBrush(QColor::fromHsvF(m_color_h, 1.0, 1.0));
m_color_h += COLOR_INCREMENT; // this gives the nice color change :-)
if (m_color_h > 1.0) m_color_h -= 1.0;
double amp = sin(m_deg[MAXSIN - 1] * 3);
for (int j = 0; j < MAXSIN; j++) {
for (int i = 0; i < 21; i++) {
si.setPoint(i, (j * m_width / MAXSIN) +
Kwave::toInt(amp * sin(M_PI * i / 10 + m_deg[j])
* m_width / 2),
m_height * i / 20);
}
si.setPoint(21, m_width / 2, m_height);
si.setPoint(22, m_width / 2, 0);
p.drawPolygon(si);
amp = sin(m_deg[j] * 3);
}
p.end();
m_repaint = false;
}
// blit the result to the display
if (m_image) {
QPainter p(this);
p.drawImage(0, 0, *m_image);
p.end();
}
}
示例10: paintEvent
void CharsetWidget::paintEvent(QPaintEvent *event)
{
QPainter painter;
painter.begin(this);
painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole()));
painter.setBrush(QColor(0,0,0));
painter.setPen(Qt::NoPen);
auto state = State::getInstance();
int end_x = 8;
int pixel_size_x = _pixelSize.width();
int increment_x = 1;
int bits_to_mask = 1;
if (state->shouldBeDisplayedInMulticolor())
{
end_x = 4;
pixel_size_x = _pixelSize.width() * 2;
increment_x = 2;
bits_to_mask = 3;
}
QPen pen;
pen.setColor({149,195,244,255});
if (hasFocus())
pen.setWidth(3);
else
pen.setWidth(1);
pen.setStyle(Qt::PenStyle::SolidLine);
for (int w=0; w<COLUMNS; w++) {
for (int h=0; h<ROWS; h++) {
int index = w + h * COLUMNS;
quint8* charPtr = state->getCharAtIndex(index);
for (int y=0; y<8; y++) {
char letter = charPtr[y];
for (int x=0; x<end_x; x++) {
// Warning: Don't use 'char'. Instead use 'unsigned char'.
// 'char' doesn't work Ok with << and >>
// only mask the bits are needed
unsigned char mask = bits_to_mask << (((end_x-1)-x) * increment_x);
unsigned char color = letter & mask;
// now transform those bits into values from 0-3 since those are the
// possible colors
int bits_to_shift = (((end_x-1)-x) * increment_x);
int color_pen = color >> bits_to_shift;
if (!state->shouldBeDisplayedInMulticolor() && color_pen )
color_pen = State::PEN_FOREGROUND;
painter.setBrush(Palette::getColorForPen(color_pen));
painter.drawRect((w*end_x+x) * pixel_size_x + OFFSET,
(h*8+y) * _pixelSize.height() + OFFSET,
pixel_size_x,
_pixelSize.height());
}
}
painter.setPen(Qt::NoPen);
}
}
if (_selecting) {
pen.setColor({149,195,244,255});
painter.setPen(pen);
painter.setBrush(QColor(149,195,244,64));
painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET,
_cursorPos.y() * 8 * _pixelSize.height() + OFFSET,
_selectingSize.width() * 8 * _pixelSize.width(),
_selectingSize.height() * 8 * _pixelSize.height());
}
else
{
pen.setColor({149,195,244,255});
painter.setPen(pen);
painter.setBrush(QColor(128,0,0,0));
painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET,
_cursorPos.y() * 8 * _pixelSize.height() + OFFSET,
8 * _pixelSize.width(),
8 * _pixelSize.height());
}
paintFocus(painter);
painter.end();
}
示例11: paintEvent
//--------------------------------------------------------------------------------------------
void MGyrohorizon::paintEvent(QPaintEvent * event)
{
//--
QImage imgagePaint(size(), QImage::Format_ARGB32_Premultiplied);
QPainter painter;
painter.begin(&imgagePaint);
//--
painter.setRenderHint(QPainter::Antialiasing, true);
QLinearGradient linearGrad;
QPointF mpointsF[5];
qreal yh;
//=============================
bool isUpDawn = false;
while(PitchAngle < -90.0)
{
PitchAngle += 180.0;
isUpDawn = !isUpDawn; //true;
}
while(PitchAngle > 90.0)
{
PitchAngle -= 180.0;
isUpDawn = !isUpDawn; //true;
}
if(isUpDawn)
{
RollAngle += 180.0;
}
while(RollAngle < -180.0)
{
RollAngle += 360.0;
}
while(RollAngle > 180.0)
{
RollAngle -= 360.0;
}
qreal hPitchAngle = HeightHalf/AngleHeightHalf*PitchAngle;//здвиг по пикселям в соответсвии с градусами
if(isUpDawn) {
hPitchAngle = -hPitchAngle;
}
painter.translate(WidthHalf,HeightHalf);//переместили цент с 0,0 на центр
painter.rotate(-RollAngle);
//===== Pitch: =====
painter.setPen(Qt::NoPen);
//-Sky:
// 0:
yh = hPitchAngle;
linearGrad.setStart(0.0, yh);
linearGrad.setFinalStop(0.0, yh-H1);
linearGrad.setColorAt(0, ColorSky0);
linearGrad.setColorAt(1, ColorSky1);
QBrush brushSky1(linearGrad); painter.setBrush(brushSky1);
painter.drawRect(-MaxDimHalf,yh+0.5, MaxDim,-H1-2.0);//первый верхний четерехугольник
yh -= H1;
linearGrad.setStart(0.0, yh);
linearGrad.setFinalStop(0.0, yh-H2);
linearGrad.setColorAt(0, ColorSky1);
linearGrad.setColorAt(1, ColorSky2);
QBrush brushSky2(linearGrad); painter.setBrush(brushSky2);
painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,-H2-2.0));
//90
yh -= H2;
linearGrad.setStart(0.0, yh);
linearGrad.setFinalStop(0.0, yh-H2);
linearGrad.setColorAt(0, ColorSky2);
linearGrad.setColorAt(1, ColorSky1);
QBrush brushSky3(linearGrad); painter.setBrush(brushSky3);
painter.drawRect(QRectF(-MaxDimHalf,yh, MaxDim,-H2-2.0));
yh -= H2;
linearGrad.setStart(0.0, yh);
linearGrad.setFinalStop(0.0, yh-H1);
linearGrad.setColorAt(0, ColorSky1);
linearGrad.setColorAt(1, ColorSky0);
QBrush brushSky4(linearGrad); painter.setBrush(brushSky4);
painter.drawRect(QRectF(-MaxDimHalf,yh+0.5, MaxDim,-H1-2.0));
//180
//-Ground:
// 0:
yh = hPitchAngle;
//.........这里部分代码省略.........
示例12: drawSlider
void ScrollPanner::drawSlider(QPainter& p, QRect r)
{
p.drawRect(r);
}
示例13: drawBackground
void ScrollPanner::drawBackground(QPainter& p, QRect r)
{
p.drawRect(r);
}
示例14: sceneEventFilter
bool c_graph_item::sceneEventFilter(QGraphicsItem *watched, QEvent *event){
//ajout fleche rouge sur le hover
if(event->type() == QEvent::GraphicsSceneHoverEnter && !model_graph->getTransClicked() && !model_graph->getNodeCLicked() && !model_graph->getFinalClicked() ){
if( !model_graph->addedToScene){
std::cout << "mouse enter QGraphics item\n";
//creation de la ligne bleu
m_transition * selectedTransition = getTransitionFromQGraphicsItem(watched,event);
QLineF * transition_line = selectedTransition->getGraphicalComponentLine();
QPointF p1(transition_line->p1().x(),transition_line->p1().y());
QPointF p2(transition_line->p2().x(),transition_line->p2().y());
//creation du polygon bleu
QPointF destPoint = p2.toPoint();
int arrowSize = 10;
double angle = ::acos(transition_line->dx() / transition_line->length());
if (transition_line->dy() >= 0)
angle = TwoPi - angle;
QPointF destArrowP1 = destPoint + QPointF( sin(angle - Pi / 3) * arrowSize, cos(angle - Pi / 3) * arrowSize);
QPointF destArrowP2 = destPoint + QPointF( sin(angle - Pi + Pi / 3) * arrowSize, cos(angle - Pi + Pi / 3) * arrowSize);
QPolygonF tmp_polygon;
tmp_polygon << p2 << destArrowP1 << destArrowP2;
model_graph->line = new QGraphicsLineItem(QLineF(p1,p2));
model_graph->arrow = new QGraphicsPolygonItem(tmp_polygon);
QPen * pen = new QPen();
pen->setColor(Qt::red);
pen->setBrush(Qt::red);
pen->setWidth(3);
model_graph->line->setPen(*pen);
model_graph->arrow->setPen(*pen);
model_graph->arrow->setBrush(Qt::red);
model_graph->view_graph->scene()->addItem(dynamic_cast<QGraphicsItem *>(model_graph->line));
model_graph->view_graph->scene()->addItem(dynamic_cast<QGraphicsItem *>(model_graph->arrow));
//view_graph->scene()->update();
model_graph->addedToScene = true;
}
}
if(event->type() == QEvent::GraphicsSceneHoverLeave && !model_graph->getTransClicked() && !model_graph->getNodeCLicked() && !model_graph->getFinalClicked()){
if(model_graph->addedToScene){
model_graph->view_graph->scene()->removeItem(dynamic_cast<QGraphicsItem *>(model_graph->line));
model_graph->view_graph->scene()->removeItem(dynamic_cast<QGraphicsItem *>(model_graph->arrow));
delete model_graph->line;
delete model_graph->arrow;
model_graph->addedToScene = false;
}
}
if(event->type() == QEvent::GraphicsSceneMousePress && !model_graph->getTransClicked() && !model_graph->getNodeCLicked() && !model_graph->getFinalClicked()){
if(QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event)){
if(mouseEvent->button() == Qt::RightButton){ //ajoute un menu pour le changement de couleur de la transition CLICK DROIT
std::cout << " the right button :D\n";
std::cout <<"declanche right button \n";
QSize iconSize = QSize (30,30);
QPixmap iconPmap (iconSize);
iconPmap.fill (Qt::transparent);
QPainter painter (&iconPmap);
painter.setBrush (QBrush (*m_colors::colorNonParcouru));
painter.setPen(QPen(Qt::NoPen));
painter.drawRect (0,0,30,30);
painter.drawPixmap (0, 0, iconPmap);
QIcon retIconNonParoucru;
retIconNonParoucru.addPixmap(iconPmap, QIcon::Normal, QIcon::Off);
retIconNonParoucru.addPixmap(iconPmap, QIcon::Normal, QIcon::On);
painter.setBrush (QBrush (*m_colors::colorActif));
painter.drawRect (0,0,30,30);
painter.drawPixmap (0, 0, iconPmap);
QIcon retIconActif;
retIconActif.addPixmap(iconPmap, QIcon::Normal, QIcon::Off);
retIconActif.addPixmap(iconPmap, QIcon::Normal, QIcon::On);
painter.setBrush (QBrush (*m_colors::colorParcouru));
painter.drawRect (0,0,30,30);
painter.drawPixmap (0, 0, iconPmap);
QIcon retIconParcouru;
retIconParcouru.addPixmap(iconPmap, QIcon::Normal, QIcon::Off);
retIconParcouru.addPixmap(iconPmap, QIcon::Normal, QIcon::On);
painter.setBrush (QBrush (*m_colors::colorSolution));
//.........这里部分代码省略.........
示例15: drawRect
void SurfaceImpl::drawRect(const PRectangle &rc)
{
painter->drawRect(
QRectF(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top));
}