3131#include < QApplication>
3232#include < QCheckBox>
3333#include < QDoubleSpinBox>
34+ #include < QFontDialog>
3435#include < QHBoxLayout>
3536#include < QLabel>
3637#include < QLineEdit>
3738#include < QMenu>
3839#include < QMenuBar>
3940#include < QMessageBox>
41+ #include < QPushButton>
4042#include < QScreen>
4143#include < QSpinBox>
4244#include < QToolBar>
@@ -63,6 +65,7 @@ MainWindow::MainWindow()
6365 , m_redoAction(new QAction(tr(" Redo" ), this))
6466 , m_edgeWidthSpinBox(new QDoubleSpinBox(this ))
6567 , m_cornerRadiusSpinBox(new QSpinBox(this ))
68+ , m_fontButton(new QPushButton(this ))
6669 , m_gridSizeSpinBox(new QSpinBox(this ))
6770 , m_textSizeSpinBox(new QSpinBox(this ))
6871 , m_copyOnDragCheckBox(new QCheckBox(tr(" Copy on drag" ), this))
@@ -234,6 +237,27 @@ QWidgetAction * MainWindow::createTextSizeAction()
234237 return WidgetFactory::buildToolBarWidgetActionWithLabel (tr (" Text size:" ), *m_textSizeSpinBox, *this ).second ;
235238}
236239
240+ QWidgetAction * MainWindow::createFontAction ()
241+ {
242+ m_fontButton->setText (tr (" Font" ) + threeDots);
243+ connect (m_fontButton, &QPushButton::clicked, [=] {
244+ bool ok;
245+ QFont defaultFont = m_fontButton->font ();
246+ defaultFont.setPointSize (m_textSizeSpinBox->value ());
247+ const auto font = QFontDialog::getFont (&ok, defaultFont, this );
248+ if (ok) {
249+ // Note: Support for multiple families implemented in Qt 5.13 =>
250+ juzzlin::L ().debug () << " Font family selected: '" << font.family ().toStdString () << " '" ;
251+ juzzlin::L ().debug () << " Font weight selected: " << font.weight ();
252+ updateFontButtonFont (font);
253+ m_textSizeSpinBox->setValue (font.pointSize ());
254+ emit textSizeChanged (font.pointSize ());
255+ emit fontChanged (font);
256+ }
257+ });
258+ return WidgetFactory::buildToolBarWidgetAction (*m_fontButton, *this ).second ;
259+ }
260+
237261QWidgetAction * MainWindow::createGridSizeAction ()
238262{
239263 m_gridSizeSpinBox->setMinimum (Constants::Grid::MIN_SIZE);
@@ -412,6 +436,8 @@ void MainWindow::createToolBar()
412436 toolBar->addSeparator ();
413437 toolBar->addAction (createTextSizeAction ());
414438 toolBar->addSeparator ();
439+ toolBar->addAction (createFontAction ());
440+ toolBar->addSeparator ();
415441 toolBar->addAction (createCornerRadiusAction ());
416442 toolBar->addSeparator ();
417443 toolBar->addAction (createGridSizeAction ());
@@ -552,6 +578,13 @@ void MainWindow::populateMenuBar()
552578 createHelpMenu ();
553579}
554580
581+ void MainWindow::updateFontButtonFont (const QFont & font)
582+ {
583+ QFont newFont (font);
584+ newFont.setPointSize (m_fontButton->font ().pointSize ());
585+ m_fontButton->setFont (newFont);
586+ }
587+
555588void MainWindow::appear ()
556589{
557590 if (Settings::loadFullScreen ()) {
@@ -604,6 +637,11 @@ void MainWindow::setEdgeWidth(double value)
604637 }
605638}
606639
640+ void MainWindow::setFont (const QFont & font)
641+ {
642+ updateFontButtonFont (font);
643+ }
644+
607645void MainWindow::setTextSize (int textSize)
608646{
609647 if (m_textSizeSpinBox->value () != textSize) {
0 commit comments