BibleTime
btfontsizewidget.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btfontsizewidget.h"
14 
15 #include <QCompleter>
16 #include <QFontDatabase>
17 #include <QIntValidator>
18 #include <QNonConstOverload>
19 #include <QVariant>
20 #include "../../util/btconnect.h"
21 
22 
24  : QComboBox(parent)
25  , m_validator(new QIntValidator(1, 99, this))
26 {
27  setEditable(true);
28  setValidator(m_validator);
29  completer()->setCompletionMode(QCompleter::PopupCompletion);
30 
31  #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
32  for (int const size : QFontDatabase().standardSizes()) {
33  #else
34  for (int const size : QFontDatabase::standardSizes()) {
35  #endif
36  if (size > m_validator->top())
37  m_validator->setTop(size);
38  addItem(QString::number(size), QVariant(size));
39  }
40 
41  BT_CONNECT(this, qOverload<QString const &>(&QComboBox::currentTextChanged),
42  [this](QString const & text)
43  { Q_EMIT fontSizeChanged(text.toInt()); });
44 }
45 
47  if ((size < 1) || (size > m_validator->top()))
48  size = 12;
49  setCurrentText(QString::number(size));
50 }
51 
53  return currentText().toInt();
54 }
#define BT_CONNECT(...)
Definition: btconnect.h:20
QIntValidator *const m_validator
void setFontSize(int size)
BtFontSizeWidget(QWidget *parent=nullptr)
void fontSizeChanged(int)