ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
fontpushbutton.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "fontpushbutton.h"
9 
10 #include <QFontDialog>
11 
12 namespace Widgets {
13 
14 FontPushButton::FontPushButton(QWidget *parent) : QPushButton(parent) {
15  init();
16 }
17 
18 FontPushButton::FontPushButton(const QString &text, QWidget *parent)
19  : QPushButton(text, parent) {
20  init();
21 }
22 
23 void FontPushButton::onClicked() {
24  bool ok = false;
25  QFont f = QFontDialog::getFont(&ok, font());
26 
27  if (!ok) return;
28  emit fontSelected(f);
29  int fontSize = this->font().pointSize();
30  f.setPointSize(fontSize);
31  setFont(f);
32  setText(f.family());
33  setToolTip(f.family());
34 }
35 
36 void FontPushButton::init() {
37  setText(tr("Font"));
38  connect(this, SIGNAL(clicked()), SLOT(onClicked()));
39 }
40 } // namespace Widgets
void fontSelected(const QFont &font)
FontPushButton(QWidget *parent=0)