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