Fix for gamepad button text postioning and sizing.
This commit is contained in:
parent
21291430b4
commit
8314f7bad1
|
@ -1430,7 +1430,11 @@ GamePadView_t::GamePadView_t(QWidget *parent)
|
||||||
#else
|
#else
|
||||||
pxCharWidth = fm.width(QLatin1Char('2'));
|
pxCharWidth = fm.width(QLatin1Char('2'));
|
||||||
#endif
|
#endif
|
||||||
pxCharHeight = fm.lineSpacing();
|
pxCharHeight = fm.capHeight();
|
||||||
|
pxLineSpacing = fm.lineSpacing();
|
||||||
|
pxLineLead = fm.leading();
|
||||||
|
pxLineLead2 = pxLineLead / 2;
|
||||||
|
pxLeftBearing = fm.leftBearing(QLatin1Char('A'));
|
||||||
|
|
||||||
portNum = 0;
|
portNum = 0;
|
||||||
}
|
}
|
||||||
|
@ -1482,7 +1486,25 @@ void GamePadView_t::drawLetterOnButton(QPainter &painter, QRect &rect, QColor &c
|
||||||
y = rect.y() + (rect.height() - pxCharHeight) / 2;
|
y = rect.y() + (rect.height() - pxCharHeight) / 2;
|
||||||
|
|
||||||
painter.setPen(color);
|
painter.setPen(color);
|
||||||
painter.drawText(x, y + pxCharHeight, tr(c));
|
painter.setFont(font);
|
||||||
|
painter.drawText(x + pxLeftBearing, y + pxCharHeight - pxLineLead2, tr(c));
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void GamePadView_t::setFontPixelSize(int px)
|
||||||
|
{
|
||||||
|
font.setPixelSize( px );
|
||||||
|
QFontMetrics fm(font);
|
||||||
|
|
||||||
|
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
|
||||||
|
pxCharWidth = fm.horizontalAdvance(QLatin1Char('2'));
|
||||||
|
#else
|
||||||
|
pxCharWidth = fm.width(QLatin1Char('2'));
|
||||||
|
#endif
|
||||||
|
pxCharHeight = fm.capHeight();
|
||||||
|
pxLineSpacing = fm.lineSpacing();
|
||||||
|
pxLineLead = fm.leading();
|
||||||
|
pxLineLead2 = pxLineLead / 2;
|
||||||
|
pxLeftBearing = fm.leftBearing(QLatin1Char('A'));
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
void GamePadView_t::paintEvent(QPaintEvent *event)
|
void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
|
@ -1611,8 +1633,10 @@ void GamePadView_t::paintEvent(QPaintEvent *event)
|
||||||
//bw = w3 / 3;
|
//bw = w3 / 3;
|
||||||
bh = h / 3;
|
bh = h / 3;
|
||||||
bw = bh;
|
bw = bh;
|
||||||
|
setFontPixelSize( bh / 2 );
|
||||||
|
painter.setFont(font);
|
||||||
|
|
||||||
ht = pxCharHeight;
|
ht = pxLineSpacing;
|
||||||
bh = (h - ht) / 3;
|
bh = (h - ht) / 3;
|
||||||
bw = bh;
|
bw = bh;
|
||||||
hs = (ht - pxCharHeight) / 2;
|
hs = (ht - pxCharHeight) / 2;
|
||||||
|
|
|
@ -135,6 +135,7 @@ protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
//void contextMenuEvent(QContextMenuEvent *event);
|
//void contextMenuEvent(QContextMenuEvent *event);
|
||||||
|
|
||||||
|
void setFontPixelSize(int px);
|
||||||
void drawLetterOnButton(QPainter &painter, QRect &rect, QColor &color, int ch);
|
void drawLetterOnButton(QPainter &painter, QRect &rect, QColor &color, int ch);
|
||||||
|
|
||||||
int portNum;
|
int portNum;
|
||||||
|
@ -142,6 +143,10 @@ protected:
|
||||||
int viewHeight;
|
int viewHeight;
|
||||||
int pxCharWidth;
|
int pxCharWidth;
|
||||||
int pxCharHeight;
|
int pxCharHeight;
|
||||||
|
int pxLineSpacing;
|
||||||
|
int pxLineLead;
|
||||||
|
int pxLineLead2;
|
||||||
|
int pxLeftBearing;
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue