Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/addon/doxywizard/inputstring.cpp

Source at commit 1322 created 12 years 8 months ago.
By meklort, Add doxygen to utils folder
1/******************************************************************************
2 *
3 *
4 *
5 * Copyright (C) 1997-2011 by Dimitri van Heesch.
6 *
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation under the terms of the GNU General Public License is hereby
9 * granted. No representations are made about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
11 * See the GNU General Public License for more details.
12 *
13 */
14
15#include "inputstring.h"
16#include "helplabel.h"
17#include "doxywizard.h"
18#include "config.h"
19
20#include <QtGui>
21
22InputString::InputString( QGridLayout *layout,int &row,
23 const QString & id, const QString &s,
24 StringMode m, const QString &docs,
25 const QString &absPath )
26 : m_default(s), m_sm(m), m_index(0), m_docs(docs), m_id(id),
27 m_absPath(absPath==QString::fromAscii("1"))
28{
29 m_lab = new HelpLabel(id);
30 if (m==StringFixed)
31 {
32 layout->addWidget( m_lab, row, 0 );
33 m_com = new QComboBox;
34 layout->addWidget( m_com, row, 1, 1, 3, Qt::AlignLeft );
35 m_le=0;
36 m_br=0;
37 row++;
38 }
39 else
40 {
41 layout->addWidget( m_lab, row, 0 );
42 m_le = new QLineEdit;
43 m_le->setText( s );
44 //layout->setColumnMinimumWidth(2,150);
45 if (m==StringFile || m==StringDir)
46 {
47 layout->addWidget( m_le, row, 1 );
48 m_br = new QToolBar;
49 m_br->setIconSize(QSize(24,24));
50 if (m==StringFile)
51 {
52 QAction *file = m_br->addAction(QIcon(QString::fromAscii(":/images/file.png")),QString(),this,SLOT(browse()));
53 file->setToolTip(tr("Browse to a file"));
54 }
55 else
56 {
57 QAction *dir = m_br->addAction(QIcon(QString::fromAscii(":/images/folder.png")),QString(),this,SLOT(browse()));
58 dir->setToolTip(tr("Browse to a folder"));
59 }
60 layout->addWidget( m_br,row,2 );
61 }
62 else
63 {
64 layout->addWidget( m_le, row, 1, 1, 2 );
65 m_br=0;
66 }
67 m_com=0;
68 row++;
69 }
70
71 if (m_le) connect( m_le, SIGNAL(textChanged(const QString&)),
72 this, SLOT(setValue(const QString&)) );
73 if (m_com) connect( m_com, SIGNAL(activated(const QString &)),
74 this, SLOT(setValue(const QString &)) );
75 m_str = s+QChar::fromAscii('!'); // force update
76 setValue(s);
77 connect( m_lab, SIGNAL(enter()), SLOT(help()) );
78 connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
79}
80
81void InputString::help()
82{
83 showHelp(this);
84}
85
86
87InputString::~InputString()
88{
89}
90
91
92void InputString::setValue(const QString &s)
93{
94 if (m_str!=s)
95 {
96 m_str = s;
97 m_value = m_str;
98 if (m_str==m_default)
99 {
100 m_lab->setText(QString::fromAscii("<qt>")+m_id+QString::fromAscii("</qt"));
101 }
102 else
103 {
104 m_lab->setText(QString::fromAscii("<qt><font color='red'>")+m_id+QString::fromAscii("</font></qt>"));
105 }
106 if (m_le && m_le->text()!=m_str) m_le->setText( m_str );
107 emit changed();
108 }
109}
110
111void InputString::setEnabled(bool state)
112{
113 m_lab->setEnabled(state);
114 if (m_le) m_le->setEnabled(state);
115 if (m_br) m_br->setEnabled(state);
116 if (m_com) m_com->setEnabled(state);
117}
118
119void InputString::browse()
120{
121 QString path = QFileInfo(MainWindow::instance().configFileName()).path();
122 if (m_sm==StringFile)
123 {
124 QString fileName = QFileDialog::getOpenFileName(&MainWindow::instance(),
125 tr("Select file"),path);
126 if (!fileName.isNull())
127 {
128 QDir dir(path);
129 if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
130 {
131 fileName = m_absPath ? fileName : dir.relativeFilePath(fileName);
132 }
133 setValue(fileName);
134 }
135 }
136 else // sm==StringDir
137 {
138 QString dirName = QFileDialog::getExistingDirectory(&MainWindow::instance(),
139 tr("Select directory"),path);
140 if (!dirName.isNull())
141 {
142 QDir dir(path);
143 if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
144 {
145 dirName = m_absPath ? dirName : dir.relativeFilePath(dirName);
146 }
147 setValue(dirName);
148 }
149 }
150}
151
152void InputString::clear()
153{
154 setValue(QString());
155}
156
157void InputString::addValue(QString s)
158{
159 if (m_sm==StringFixed)
160 {
161 m_values.append(s);
162 m_com->addItem(s);
163 }
164}
165
166void InputString::setDefault()
167{
168 int index = m_values.indexOf(m_str);
169 if (index!=-1 && m_com) m_com->setCurrentIndex(index);
170}
171
172QVariant &InputString::value()
173{
174 return m_value;
175}
176
177void InputString::update()
178{
179 setValue(m_value.toString().trimmed());
180 setDefault();
181}
182
183void InputString::reset()
184{
185 setValue(m_default);
186 setDefault();
187}
188
189void InputString::writeValue(QTextStream &t,QTextCodec *codec)
190{
191 writeStringValue(t,codec,m_str);
192}
193
194

Archive Download this file

Revision: 1322