]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_fontbox.cpp
e9a0c758d249c9eafc852560d3ce25e3783494b0
[architektonas] / src / widgets / qg_fontbox.cpp
1 // qg_fontbox.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Added this text. :-)
13 //
14
15 #include "qg_fontbox.h"
16
17 #include "rs_debug.h"
18 #include "rs_font.h"
19 #include "rs_fontlist.h"
20
21 /**
22  * Default Constructor. You must call init manually if you choose
23  * to use this constructor.
24  */
25 QG_FontBox::QG_FontBox(QWidget * parent/*= 0*/, const char */*name = 0*/): QComboBox(parent)
26 {
27 }
28
29 /**
30  * Destructor
31  */
32 QG_FontBox::~QG_FontBox()
33 {
34 }
35
36 /**
37  * Initialisation (called from constructor or manually but only
38  * once).
39  */
40 void QG_FontBox::init()
41 {
42         QStringList fonts;
43
44         for(RS_Font * f=RS_FONTLIST->firstFont(); f!=NULL; f=RS_FONTLIST->nextFont())
45                 fonts.append(f->getFileName());
46
47         fonts.sort();
48 //      insertStringList(fonts);
49         addItems(fonts);
50
51         connect(this, SIGNAL(activated(int)), this, SLOT(slotFontChanged(int)));
52
53 //      setCurrentItem(0);
54         setCurrentIndex(0);
55 //      slotFontChanged(currentItem());
56         slotFontChanged(currentIndex());
57 }
58
59 RS_Font * QG_FontBox::getFont()
60 {
61         return currentFont;
62 }
63
64 /**
65  * Sets the currently selected width item to the given width.
66  */
67 void QG_FontBox::setFont(const QString & fName)
68 {
69         RS_DEBUG->print("QG_FontBox::setFont %s\n", fName.toLatin1().data());
70 //      setCurrentText(fName);
71         setItemText(currentIndex(), fName);
72 //      slotFontChanged(currentItem());
73         slotFontChanged(currentIndex());
74 }
75
76 /**
77  * Called when the font has changed. This method
78  * sets the current font to the value chosen.
79  */
80 void QG_FontBox::slotFontChanged(int index)
81 {
82     RS_DEBUG->print("QG_FontBox::slotFontChanged %d\n", index);
83     currentFont = RS_FONTLIST->requestFont(currentText());
84
85     if (currentFont != NULL)
86         RS_DEBUG->print("Current font is (%d): %s\n", index, currentFont->getFileName().toLatin1().data());
87
88     emit fontChanged(currentFont);
89 }