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