3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -----------------------------------------------------------
11 // JLH 05/11/2010 Added this text. :-)
14 #include "qg_patternbox.h"
16 #include "rs_pattern.h"
17 #include "rs_patternlist.h"
21 * Default Constructor. You must call init manually if you choose
22 * to use this constructor.
24 QG_PatternBox::QG_PatternBox(QWidget * parent, const char */*name*/): QComboBox(parent)
31 QG_PatternBox::~QG_PatternBox()
36 * Initialisation (called manually and only once).
38 void QG_PatternBox::init()
42 for(RS_Pattern * f=RS_PATTERNLIST->firstPattern(); f!=NULL; f=RS_PATTERNLIST->nextPattern())
43 patterns.append(f->getFileName());
46 // insertStringList(patterns);
49 connect(this, SIGNAL(activated(int)), this, SLOT(slotPatternChanged(int)));
52 slotPatternChanged(currentIndex());
55 RS_Pattern * QG_PatternBox::getPattern()
57 return currentPattern;
61 * Sets the currently selected width item to the given width.
63 void QG_PatternBox::setPattern(const QString & pName)
65 RS_DEBUG->print("QG_PatternBox::setPattern %s\n", pName.toLatin1().data());
66 // setCurrentText(pName);
67 setItemText(currentIndex(), pName);
68 slotPatternChanged(currentIndex());
72 * Called when the pattern has changed. This method
73 * sets the current pattern to the value chosen.
75 void QG_PatternBox::slotPatternChanged(int index)
77 RS_DEBUG->print("QG_PatternBox::slotPatternChanged %d\n", index);
78 currentPattern = RS_PATTERNLIST->requestPattern(currentText());
80 if (currentPattern!=NULL)
81 RS_DEBUG->print("Current pattern is (%d): %s\n", index, currentPattern->getFileName().toLatin1().data());
83 emit patternChanged(currentPattern);