mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
Handle non-1:1 aspect ratio bacgrounds.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@470 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
ad9227d7a4
commit
c15aba6b84
@ -27,18 +27,22 @@ void BasicDial::paintEvent(QPaintEvent *event) {
|
|||||||
|
|
||||||
void BasicDial::renderBackground(void) {
|
void BasicDial::renderBackground(void) {
|
||||||
int side = qMin(width(), height());
|
int side = qMin(width(), height());
|
||||||
if( bg.size() == QSize(side, side) ) {
|
if( bg.size() == size() ) {
|
||||||
qDebug() << "BasicDial::renderBackground(): Size not changed! Abort rerendering stuff";
|
qDebug() << "BasicDial::renderBackground(): Size not changed! Abort rerendering stuff";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QPixmap pixmap(QSize(side, side));
|
/* Create buffer pixmap and make it transparent */
|
||||||
|
QPixmap pixmap(size());
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
|
|
||||||
|
/* Configure painter */
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
QRectF frame( QPoint(0, 0), QPoint(side-1, side-1));
|
|
||||||
renderer->load(backgroundFile);
|
renderer->load(backgroundFile); /* load file; needed to calculate frame */
|
||||||
renderer->render(&painter, frame);
|
QRectF frame = calculateCenteredFrame(); /* viewport from renderer (based on loaded file */
|
||||||
bg = pixmap;
|
renderer->render(&painter, frame); /* dump bg on pixmap */
|
||||||
|
bg = pixmap; /* save it */
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicDial::renderNeedle(qreal angle) {
|
void BasicDial::renderNeedle(qreal angle) {
|
||||||
@ -93,3 +97,17 @@ void BasicDial::setPen(QPen p) {
|
|||||||
pen = p;
|
pen = p;
|
||||||
pen.setWidth(2);
|
pen.setWidth(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF BasicDial::calculateCenteredFrame(void) {
|
||||||
|
QRectF vb = renderer->viewBoxF(); /* get SVG viewport */
|
||||||
|
qreal scale = qMax( (vb.height()/height()), (vb.width()/width())); /* calc scale to fit SVG into widget */
|
||||||
|
vb.setWidth( vb.width()/scale ); /* scale viewport so SVG fit widget size */
|
||||||
|
vb.setHeight( vb.height()/scale );
|
||||||
|
|
||||||
|
QRectF frame; /* let's prepare render frame for bg */
|
||||||
|
frame.setX( (width()-vb.width())/2.0 ); /* frame is centered on widget */
|
||||||
|
frame.setY( (height()-vb.height())/2.0 );
|
||||||
|
frame.setWidth( vb.width() ); /* derive size from scaled viewport */
|
||||||
|
frame.setHeight( vb.height() );
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
@ -29,6 +29,8 @@ private:
|
|||||||
void renderNeedle(qreal angle);
|
void renderNeedle(qreal angle);
|
||||||
qreal value2angle(qreal value);
|
qreal value2angle(qreal value);
|
||||||
|
|
||||||
|
QRectF calculateCenteredFrame(void);
|
||||||
|
|
||||||
QSvgRenderer *renderer;
|
QSvgRenderer *renderer;
|
||||||
QPixmap bg;
|
QPixmap bg;
|
||||||
qreal angle;
|
qreal angle;
|
||||||
|
Loading…
Reference in New Issue
Block a user