From 8314f7bad163333d57f5619166c638a334bc20d2 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sat, 10 Jul 2021 14:18:03 -0400 Subject: [PATCH] Fix for gamepad button text postioning and sizing. --- src/drivers/Qt/GamePadConf.cpp | 30 +++++++++++++++++++++++++++--- src/drivers/Qt/GamePadConf.h | 5 +++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/drivers/Qt/GamePadConf.cpp b/src/drivers/Qt/GamePadConf.cpp index e1f90931..b31726b2 100644 --- a/src/drivers/Qt/GamePadConf.cpp +++ b/src/drivers/Qt/GamePadConf.cpp @@ -1430,7 +1430,11 @@ GamePadView_t::GamePadView_t(QWidget *parent) #else pxCharWidth = fm.width(QLatin1Char('2')); #endif - pxCharHeight = fm.lineSpacing(); + pxCharHeight = fm.capHeight(); + pxLineSpacing = fm.lineSpacing(); + pxLineLead = fm.leading(); + pxLineLead2 = pxLineLead / 2; + pxLeftBearing = fm.leftBearing(QLatin1Char('A')); portNum = 0; } @@ -1482,7 +1486,25 @@ void GamePadView_t::drawLetterOnButton(QPainter &painter, QRect &rect, QColor &c y = rect.y() + (rect.height() - pxCharHeight) / 2; 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) @@ -1611,8 +1633,10 @@ void GamePadView_t::paintEvent(QPaintEvent *event) //bw = w3 / 3; bh = h / 3; bw = bh; + setFontPixelSize( bh / 2 ); + painter.setFont(font); - ht = pxCharHeight; + ht = pxLineSpacing; bh = (h - ht) / 3; bw = bh; hs = (ht - pxCharHeight) / 2; diff --git a/src/drivers/Qt/GamePadConf.h b/src/drivers/Qt/GamePadConf.h index 936bc2bb..245a581a 100644 --- a/src/drivers/Qt/GamePadConf.h +++ b/src/drivers/Qt/GamePadConf.h @@ -135,6 +135,7 @@ protected: void mousePressEvent(QMouseEvent *event); //void contextMenuEvent(QContextMenuEvent *event); + void setFontPixelSize(int px); void drawLetterOnButton(QPainter &painter, QRect &rect, QColor &color, int ch); int portNum; @@ -142,6 +143,10 @@ protected: int viewHeight; int pxCharWidth; int pxCharHeight; + int pxLineSpacing; + int pxLineLead; + int pxLineLead2; + int pxLeftBearing; QFont font; };