]> Shamusworld >> Repos - architektonas/blob - src/widgets/patternbox.cpp
a66fd169d3b222e56b4ab50803c6ed1978f7f878
[architektonas] / src / widgets / patternbox.cpp
1 // 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 "patternbox.h"
18
19 #include "pattern.h"
20 #include "patternlist.h"
21 #include "debug.h"
22
23 /**
24  * Default Constructor. You must call init manually if you choose
25  * to use this constructor.
26  */
27 PatternBox::PatternBox(QWidget * parent, const char */*name*/): QComboBox(parent)
28 {
29 }
30
31 /**
32  * Destructor
33  */
34 PatternBox::~PatternBox()
35 {
36 }
37
38 /**
39  * Initialisation (called manually and only once).
40  */
41 void PatternBox::init()
42 {
43         QStringList patterns;
44
45         for(Pattern * f=PATTERNLIST->firstPattern(); f!=NULL; f=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 Pattern * PatternBox::getPattern()
59 {
60         return currentPattern;
61 }
62
63 /**
64  * Sets the currently selected width item to the given width.
65  */
66 void PatternBox::setPattern(const QString & pName)
67 {
68         DEBUG->print("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 PatternBox::slotPatternChanged(int index)
79 {
80         DEBUG->print("PatternBox::slotPatternChanged %d\n", index);
81         currentPattern = PATTERNLIST->requestPattern(currentText());
82
83         if (currentPattern!=NULL)
84                 DEBUG->print("Current pattern is (%d): %s\n", index, currentPattern->getFileName().toLatin1().data());
85
86         emit patternChanged(currentPattern);
87 }