[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master dd62e9b: [ftinspect] Don't use size in pixels f
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master dd62e9b: [ftinspect] Don't use size in pixels for navigation buttons. |
Date: |
Wed, 04 May 2016 05:40:11 +0000 |
branch: master
commit dd62e9bc155e271e43c2f2cff866914e02988417
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Don't use size in pixels for navigation buttons.
Instead, derive the width from the displayed text.
* src/ftinspect.h (QPushButtonx): New class, derived from
`QPushButton'.
* src/ftinspect.cpp (QPushButtonx::QPushButtonx): New constructor.
(MainGUI::createLayout): Use `QPushButtonx' for navigation buttons.
---
ChangeLog | 12 +++++++++
src/ftinspect.cpp | 72 +++++++++++++++++++++++++++++++----------------------
src/ftinspect.h | 33 ++++++++++++++++--------
3 files changed, 77 insertions(+), 40 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dfba077..c59e6e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2016-05-04 Werner Lemberg <address@hidden>
+
+ [ftinspect] Don't use size in pixels for navigation buttons.
+
+ Instead, derive the width from the displayed text.
+
+ * src/ftinspect.h (QPushButtonx): New class, derived from
+ `QPushButton'.
+
+ * src/ftinspect.cpp (QPushButtonx::QPushButtonx): New constructor.
+ (MainGUI::createLayout): Use `QPushButtonx' for navigation buttons.
+
2016-05-03 Werner Lemberg <address@hidden>
[ftinspect] Make `previous font' and `next font' button logic work.
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index f9c3370..fb0f172 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -494,26 +494,16 @@ MainGUI::createLayout()
dpiSpinBox->setValue(96); // XXX default
dpiLabel->setBuddy(dpiSpinBox);
- toStartButton = new QPushButton("|<");
- toStartButton->setFixedWidth(40);
- toM1000Button = new QPushButton("-1000");
- toM1000Button->setFixedWidth(65);
- toM100Button = new QPushButton("-100");
- toM100Button->setFixedWidth(55);
- toM10Button = new QPushButton("-10");
- toM10Button->setFixedWidth(50);
- toM1Button = new QPushButton("-1");
- toM1Button->setFixedWidth(50);
- toP1Button = new QPushButton("+1");
- toP1Button->setFixedWidth(50);
- toP10Button = new QPushButton("+10");
- toP10Button->setFixedWidth(50);
- toP100Button = new QPushButton("+100");
- toP100Button->setFixedWidth(55);
- toP1000Button = new QPushButton("+1000");
- toP1000Button->setFixedWidth(65);
- toEndButton = new QPushButton(">|");
- toEndButton->setFixedWidth(40);
+ toStartButtonx = new QPushButtonx("|<");
+ toM1000Buttonx = new QPushButtonx("-1000");
+ toM100Buttonx = new QPushButtonx("-100");
+ toM10Buttonx = new QPushButtonx("-10");
+ toM1Buttonx = new QPushButtonx("-1");
+ toP1Buttonx = new QPushButtonx("+1");
+ toP10Buttonx = new QPushButtonx("+10");
+ toP100Buttonx = new QPushButtonx("+100");
+ toP1000Buttonx = new QPushButtonx("+1000");
+ toEndButtonx = new QPushButtonx(">|");
zoomLabel = new QLabel(tr("Zoom "));
zoomLabel->setAlignment(Qt::AlignRight);
@@ -531,16 +521,16 @@ MainGUI::createLayout()
navigationLayout = new QHBoxLayout;
navigationLayout->setSpacing(0);
navigationLayout->addStretch(1);
- navigationLayout->addWidget(toStartButton);
- navigationLayout->addWidget(toM1000Button);
- navigationLayout->addWidget(toM100Button);
- navigationLayout->addWidget(toM10Button);
- navigationLayout->addWidget(toM1Button);
- navigationLayout->addWidget(toP1Button);
- navigationLayout->addWidget(toP10Button);
- navigationLayout->addWidget(toP100Button);
- navigationLayout->addWidget(toP1000Button);
- navigationLayout->addWidget(toEndButton);
+ navigationLayout->addWidget(toStartButtonx);
+ navigationLayout->addWidget(toM1000Buttonx);
+ navigationLayout->addWidget(toM100Buttonx);
+ navigationLayout->addWidget(toM10Buttonx);
+ navigationLayout->addWidget(toM1Buttonx);
+ navigationLayout->addWidget(toP1Buttonx);
+ navigationLayout->addWidget(toP10Buttonx);
+ navigationLayout->addWidget(toP100Buttonx);
+ navigationLayout->addWidget(toP1000Buttonx);
+ navigationLayout->addWidget(toEndButtonx);
navigationLayout->addStretch(1);
fontSizeLayout = new QHBoxLayout;
@@ -727,6 +717,28 @@ QComboBoxx::setItemEnabled(int index,
}
+// code derived from Qt 4.8.7, function `QPushButton::sizeHint',
+// file `src/gui/widgets/qpushbutton.cpp'
+
+QPushButtonx::QPushButtonx(const QString &text,
+ QWidget *parent)
+: QPushButton(text, parent)
+{
+ QStyleOptionButton opt;
+ opt.initFrom(this);
+ QString s(this->text());
+ QFontMetrics fm = fontMetrics();
+ QSize sz = fm.size(Qt::TextShowMnemonic, s);
+ opt.rect.setSize(sz);
+
+ sz = style()->sizeFromContents(QStyle::CT_PushButton,
+ &opt,
+ sz,
+ this);
+ setFixedWidth(sz.width());
+}
+
+
int
main(int argc,
char** argv)
diff --git a/src/ftinspect.h b/src/ftinspect.h
index 5bd2ebb..0957753 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -95,6 +95,18 @@ public:
};
+// we want buttons that are horizontally as small as possible
+class QPushButtonx
+: public QPushButton
+{
+ Q_OBJECT
+
+public:
+ QPushButtonx(const QString&, QWidget* = 0);
+ virtual ~QPushButtonx(){}
+};
+
+
class MainGUI
: public QMainWindow
{
@@ -174,18 +186,19 @@ private:
QPushButton *nextFontButton;
QPushButton *previousFontButton;
- QPushButton *toEndButton;
- QPushButton *toM1000Button;
- QPushButton *toM100Button;
- QPushButton *toM10Button;
- QPushButton *toM1Button;
- QPushButton *toP1000Button;
- QPushButton *toP100Button;
- QPushButton *toP10Button;
- QPushButton *toP1Button;
- QPushButton *toStartButton;
QPushButton *watchButton;
+ QPushButtonx *toEndButtonx;
+ QPushButtonx *toM1000Buttonx;
+ QPushButtonx *toM100Buttonx;
+ QPushButtonx *toM10Buttonx;
+ QPushButtonx *toM1Buttonx;
+ QPushButtonx *toP1000Buttonx;
+ QPushButtonx *toP100Buttonx;
+ QPushButtonx *toP10Buttonx;
+ QPushButtonx *toP1Buttonx;
+ QPushButtonx *toStartButtonx;
+
QSlider *gammaSlider;
QSpinBox *dpiSpinBox;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master dd62e9b: [ftinspect] Don't use size in pixels for navigation buttons.,
Werner LEMBERG <=