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