{
font.
setStyleStrategy(QFont::ForceOutline);
int fontwidth
= QFontMetrics(font
).
boundingRect("N").
width();
matrix.translate( width()/2, height()/2 );
p.setMatrix( matrix );
p.
setRenderHint(QPainter::Antialiasing,
true);
// draw the surrounding ellipse
p.
setPen( QPen(Qt
::black,
1) );
p.
setBrush(QColor(192,
192,
192,
192));
int offset = qMax( fontheight, fontwidth ) +5;
int size = qMin( width(), height() );
int radius = (size-1)/2 - offset;
p.drawEllipse( -radius, -radius, radius*2, radius*2 );
// draw the text
qreal midx = (fontwidth/2+radius+4)*cos(-m_angle*DTOR);
qreal midy = (fontheight/2+radius+4)*sin(-m_angle*DTOR);
QRectF rect
( midx
-fontwidth
/2, midy
-fontheight
/2, fontwidth, fontheight
);
path.
addText( QPointF(midx
-fontwidth
/2, midy
+fontwidth
/2), font,
"N" );
p.setBrush( Qt::black );
p.drawPath( path );
p.setPen( Qt::NoPen );
p.drawPath( path );
// draw the compass
matrix.rotate( -m_angle );
p.setMatrix( matrix );
int outer = radius-5;
int inner = radius/4;
static const QPointF polyblack
[3] = { QPointF( inner
*cos(45.
*DTOR
),
-inner
*sin(45.
*DTOR
) ),
};
static const QPointF polywhite
[3] = { QPointF( inner
*cos(45.
*DTOR
), inner
*sin(45.
*DTOR
) ),
};
p.setPen( Qt::NoPen );
for (int i=0; i<4; ++i) {
matrix.rotate( 90. );
p.setMatrix(matrix);
p.setBrush( Qt::black );
p.drawPolygon( polyblack, 3 );
p.setBrush( Qt::white );
p.drawPolygon( polywhite, 3 );
}
}
void CompassRose::paintEvent( QPaintEvent *e )
{
QFont font = QFont("Sans Serif", 8);
font.setStyleStrategy(QFont::ForceOutline);
int fontheight = QFontMetrics(font).ascent();
int fontwidth = QFontMetrics(font).boundingRect("N").width();
QMatrix matrix;
matrix.translate( width()/2, height()/2 );
QPainter p(this);
p.setMatrix( matrix );
p.setRenderHint(QPainter::Antialiasing, true);
// draw the surrounding ellipse
p.setPen( QPen(Qt::black, 1) );
p.setBrush(QColor(192,192,192,192));
int offset = qMax( fontheight, fontwidth ) +5;
int size = qMin( width(), height() );
int radius = (size-1)/2 - offset;
p.drawEllipse( -radius, -radius, radius*2, radius*2 );
// draw the text
qreal midx = (fontwidth/2+radius+4)*cos(-m_angle*DTOR);
qreal midy = (fontheight/2+radius+4)*sin(-m_angle*DTOR);
QRectF rect( midx-fontwidth/2, midy-fontheight/2, fontwidth, fontheight );
QPainterPath path;
path.addText( QPointF(midx-fontwidth/2, midy+fontwidth/2), font, "N" );
p.setPen(QPen( QColor(192,192,192,192), 3 ));
p.setBrush( Qt::black );
p.drawPath( path );
p.setPen( Qt::NoPen );
p.drawPath( path );
// draw the compass
matrix.rotate( -m_angle );
p.setMatrix( matrix );
int outer = radius-5;
int inner = radius/4;
static const QPointF polyblack[3] = {
QPointF( outer, 0 ),
QPointF( inner*cos(45.*DTOR), -inner*sin(45.*DTOR) ),
QPointF( 0, 0 )
};
static const QPointF polywhite[3] = {
QPointF( outer, 0 ),
QPointF( inner*cos(45.*DTOR), inner*sin(45.*DTOR) ),
QPointF( 0, 0 )
};
p.setPen( Qt::NoPen );
for (int i=0; i<4; ++i) {
matrix.rotate( 90. );
p.setMatrix(matrix);
p.setBrush( Qt::black );
p.drawPolygon( polyblack, 3 );
p.setBrush( Qt::white );
p.drawPolygon( polywhite, 3 );
}
}
To copy to clipboard, switch view to plain text mode
ScrollArea
::ScrollArea( QWidget *parent
){
d = new ScrollAreaPrivate();
d->compass = new CompassRose( this );
setObjectName( "pss::ScrollArea" );
setAttribute( Qt::WA_StaticContents );
//setWidget(new myWidget(this));
viewport()->setFocusProxy( this );
viewport()->setFocusPolicy( Qt::StrongFocus );
//widget()->setAttribute( Qt::WA_OpaquePaintEvent );
//widget()->setAttribute( Qt::WA_NoSystemBackground );
//widget()->setMouseTracking( true );
setWidgetResizable( true );
}
{
qDebug() << "sa resize event" << re;
//d->compass->resize(viewport()->size());
d->compass->move( viewport()->width() - d->compass->width(), 0 );
}
ScrollArea::ScrollArea( QWidget *parent )
:QScrollArea( parent )
{
d = new ScrollAreaPrivate();
d->compass = new CompassRose( this );
setObjectName( "pss::ScrollArea" );
setAttribute( Qt::WA_StaticContents );
//setWidget(new myWidget(this));
viewport()->setFocusProxy( this );
viewport()->setFocusPolicy( Qt::StrongFocus );
//widget()->setAttribute( Qt::WA_OpaquePaintEvent );
//widget()->setAttribute( Qt::WA_NoSystemBackground );
//widget()->setMouseTracking( true );
setWidgetResizable( true );
}
void ScrollArea::resizeEvent( QResizeEvent *re )
{
qDebug() << "sa resize event" << re;
QScrollArea::resizeEvent(re);
//d->compass->resize(viewport()->size());
d->compass->move( viewport()->width() - d->compass->width(), 0 );
}
To copy to clipboard, switch view to plain text mode
Bookmarks