]> Shamusworld >> Repos - architektonas/blob - src/widgets/patternbox.cpp
Fixed problem with MDI activation.
[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  * Initialization (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 #if 0
49 std::cout << "patterns size = " << patterns.size() << std::endl;
50
51 for(int i=0; i<patterns.size(); i++)
52         std::cout << patterns.at(i).toLocal8Bit().constData() << std::endl;
53
54 std::cout.flush();
55 #endif
56         patterns.sort();
57         addItems(patterns);
58
59         connect(this, SIGNAL(activated(int)), this, SLOT(slotPatternChanged(int)));
60
61         setCurrentIndex(0);
62         slotPatternChanged(currentIndex());
63 }
64
65 Pattern * PatternBox::getPattern()
66 {
67         return currentPattern;
68 }
69
70 /**
71  * Sets the currently selected width item to the given width.
72  */
73 void PatternBox::setPattern(const QString & pName)
74 {
75         DEBUG->print("PatternBox::setPattern %s\n", pName.toAscii().data());
76         setItemText(currentIndex(), pName);
77         slotPatternChanged(currentIndex());
78 }
79
80 /**
81  * Called when the pattern has changed. This method
82  * sets the current pattern to the value chosen.
83  */
84 void PatternBox::slotPatternChanged(int index)
85 {
86         DEBUG->print("PatternBox::slotPatternChanged %d\n", index);
87         currentPattern = PATTERNLIST->requestPattern(currentText());
88
89         if (currentPattern)
90                 DEBUG->print("Current pattern is (%d): %s\n", index, currentPattern->getFileName().toAscii().data());
91
92         emit patternChanged(currentPattern);
93 }