fontbutton.cpp
1 //------------------------------------------------------------------------------
2 // fontbutton.cpp
3 //
4 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
5 //------------------------------------------------------------------------------
6 #include "fontbutton.h"
7 #include <QFontDialog>
8 
9 FontButton::FontButton(QWidget* parent)
10 : QPushButton(parent)
11 {
12  connect(this, SIGNAL( clicked() ), SLOT( thisClicked() ) );
13 
14  this->updateAppearance();
15 }
16 
17 void FontButton::setSelectedFont(const QFont& font)
18 {
19  this->currentFont = font;
20  this->updateAppearance();
21 }
22 
23 void FontButton::thisClicked()
24 {
25  bool bOk = false;
26  QFont fontTmp = QFontDialog::getFont(&bOk, this->currentFont, this->parentWidget());
27 
28  if(bOk)
29  {
30  this->updateFont(fontTmp);
31  }
32 }
33 
34 void FontButton::updateAppearance()
35 {
36  QString text = QString("%1, %2").arg(this->currentFont.family()).arg(this->currentFont.pointSize());
37  QFont textFont = this->currentFont;
38 
39  this->setFont(textFont);
40  this->setText(text);
41 }
42 
43 void FontButton::updateFont(const QFont& newFont)
44 {
45  QFont oldFont = this->currentFont;
46  this->currentFont = newFont;
47  updateAppearance();
48 
49  emit fontUpdated(oldFont, this->currentFont);
50 }
51 
void updateFont(const QFont &newFont)
Will always emit fontUpdated() signal.
Definition: fontbutton.cpp:43