inputstring.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 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 <QComboBox>
21 #include <QLineEdit>
22 #include <QGridLayout>
23 #include <QWheelEvent>
24 #include <QToolBar>
25 #include <QFileInfo>
26 #include <QFileDialog>
27 #include <QTextCodec>
28 
29 class NoWheelComboBox : public QComboBox
30 {
31  protected:
32  void wheelEvent(QWheelEvent *e)
33  {
34  e->ignore();
35  }
36 };
37 
38 
39 InputString::InputString( QGridLayout *layout,int &row,
40  const QString & id, const QString &s,
41  StringMode m, const QString &docs,
42  const QString &absPath )
43  : m_default(s), m_sm(m), m_index(0), m_docs(docs), m_id(id),
44  m_absPath(absPath==QString::fromLatin1("1"))
45 {
46  m_lab = new HelpLabel(id);
47  if (m==StringFixed)
48  {
49  layout->addWidget( m_lab, row, 0 );
50  m_com = new NoWheelComboBox;
51  layout->addWidget( m_com, row, 1, 1, 3, Qt::AlignLeft );
52  m_le=0;
53  m_br=0;
54  m_im=0;
55  row++;
56  }
57  else
58  {
59  layout->addWidget( m_lab, row, 0 );
60  m_le = new QLineEdit;
61  m_le->setText( s );
62  m_im = 0;
63  //layout->setColumnMinimumWidth(2,150);
64  if (m==StringFile || m==StringDir || m==StringImage)
65  {
66  layout->addWidget( m_le, row, 1 );
67  m_br = new QToolBar;
68  m_br->setIconSize(QSize(24,24));
69  if (m==StringFile || m==StringImage)
70  {
71  QAction *file = m_br->addAction(QIcon(QString::fromLatin1(":/images/file.png")),QString(),this,SLOT(browse()));
72  file->setToolTip(tr("Browse to a file"));
73  layout->addWidget( m_br,row,2 );
74  if (m==StringImage)
75  {
76  m_im = new QLabel;
77  m_im->setMinimumSize(1,55);
78  m_im->setAlignment(Qt::AlignLeft|Qt::AlignTop);
79  row++;
80  layout->addWidget( m_im,row,1 );
81  }
82  }
83  else
84  {
85  QAction *dir = m_br->addAction(QIcon(QString::fromLatin1(":/images/folder.png")),QString(),this,SLOT(browse()));
86  dir->setToolTip(tr("Browse to a folder"));
87  layout->addWidget( m_br,row,2 );
88  }
89  }
90  else
91  {
92  layout->addWidget( m_le, row, 1, 1, 2 );
93  m_br=0;
94  m_im=0;
95  }
96  m_com=0;
97  row++;
98  }
99 
100  if (m_le) connect( m_le, SIGNAL(textChanged(const QString&)),
101  this, SLOT(setValue(const QString&)) );
102  if (m_com) connect( m_com, SIGNAL(activated(const QString &)),
103  this, SLOT(setValue(const QString &)) );
104  m_str = s+QChar::fromLatin1('!'); // force update
105  setValue(s);
106  connect( m_lab, SIGNAL(enter()), SLOT(help()) );
107  connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
108 }
109 
111 {
112  showHelp(this);
113 }
114 
115 
117 {
118 }
119 
120 
122 {
123  if (m_str!=s)
124  {
125  m_str = s;
126  m_value = m_str;
127  updateDefault();
128  }
129 }
131 {
132  {
133  if (m_str==m_default || !m_lab->isEnabled())
134  {
135  m_lab->setText(QString::fromLatin1("<qt>")+m_id+QString::fromLatin1("</qt"));
136  }
137  else
138  {
139  m_lab->setText(QString::fromLatin1("<qt><font color='red'>")+m_id+QString::fromLatin1("</font></qt>"));
140  }
141  if (m_im)
142  {
143  if (m_str.isEmpty())
144  {
145  m_im->setText(tr("No Project logo selected."));
146  }
147  else
148  {
149  QFile Fout(m_str);
150  if(!Fout.exists())
151  {
152  m_im->setText(tr("Sorry, cannot find file(")+m_str+QString::fromLatin1(");"));
153  }
154  else
155  {
156  QPixmap pm(m_str);
157  if (!pm.isNull())
158  {
159  m_im->setPixmap(pm.scaledToHeight(55,Qt::SmoothTransformation));
160  }
161  else
162  {
163  m_im->setText(tr("Sorry, no preview available (")+m_str+QString::fromLatin1(");"));
164  }
165  }
166  }
167  }
168  if (m_le && m_le->text()!=m_str) m_le->setText( m_str );
169  emit changed();
170  }
171 }
172 
173 void InputString::setEnabled(bool state)
174 {
175  m_lab->setEnabled(state);
176  if (m_le) m_le->setEnabled(state);
177  if (m_im) m_im->setEnabled(state);
178  if (m_br) m_br->setEnabled(state);
179  if (m_com) m_com->setEnabled(state);
180  updateDefault();
181 }
182 
184 {
185  QString path = QFileInfo(MainWindow::instance().configFileName()).path();
186  if (m_sm==StringFile || m_sm==StringImage)
187  {
188  QString fileName = QFileDialog::getOpenFileName(&MainWindow::instance(),
189  tr("Select file"),path);
190  if (!fileName.isNull())
191  {
192  QDir dir(path);
193  if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
194  {
195  fileName = m_absPath ? fileName : dir.relativeFilePath(fileName);
196  }
197  setValue(fileName);
198  }
199  }
200  else // sm==StringDir
201  {
202  QString dirName = QFileDialog::getExistingDirectory(&MainWindow::instance(),
203  tr("Select directory"),path);
204  if (!dirName.isNull())
205  {
206  QDir dir(path);
207  if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
208  {
209  dirName = m_absPath ? dirName : dir.relativeFilePath(dirName);
210  }
211  setValue(dirName);
212  }
213  }
214 }
215 
217 {
218  setValue(QString());
219 }
220 
222 {
223  if (m_sm==StringFixed)
224  {
225  m_values.append(s);
226  m_com->addItem(s);
227  }
228 }
229 
231 {
232  int index = m_values.indexOf(m_str);
233  if (index!=-1 && m_com) m_com->setCurrentIndex(index);
234 }
235 
236 QVariant &InputString::value()
237 {
238  return m_value;
239 }
240 
242 {
243  setValue(m_value.toString().trimmed());
244  setDefault();
245 }
246 
248 {
250  setDefault();
251 }
252 
254 {
255  writeStringValue(t,codec,m_str);
256 }
257 
Traverses directory structures and contents in a platform-independent way.
Definition: qdir.h:52
void addValue(QString s)
void setEnabled(bool)
QVariant & value()
void setValue(const QString &)
void showHelp(Input *)
bool isEmpty() const
Definition: qstring.h:682
Iterator append(const T &x)
Definition: qvaluelist.h:372
void changed()
void updateDefault()
QString m_str
Definition: inputstring.h:84
QLineEdit * m_le
Definition: inputstring.h:80
QToolBar * m_br
Definition: inputstring.h:82
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
string dir
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
def connect(nxgraph, k1, k2, p1=0, p2=0, kwds)
Definition: graph.py:30
void writeValue(QTextStream &t, QTextCodec *codec)
const double e
QLabel * m_im
Definition: inputstring.h:81
bool exists() const
Definition: qfile.cpp:183
QString m_id
Definition: inputstring.h:91
fileName
Definition: dumpTree.py:9
QString m_default
Definition: inputstring.h:85
bool m_absPath
Definition: inputstring.h:92
QComboBox * m_com
Definition: inputstring.h:83
void wheelEvent(QWheelEvent *e)
Definition: inputstring.cpp:32
QVariant m_value
Definition: inputstring.h:89
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
void setDefault()
The QTextStream class provides basic functions for reading and writing text using a QIODevice...
Definition: qtextstream.h:53
void writeStringValue(QTextStream &t, QTextCodec *codec, const QString &s)
StringMode m_sm
Definition: inputstring.h:86
bool isNull() const
Definition: qstring.h:379
QLabel * m_lab
Definition: inputstring.h:79
Provides conversion between text encodings.
Definition: qtextcodec.h:62
QStringList m_values
Definition: inputstring.h:87
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
static MainWindow & instance()
Definition: doxywizard.cpp:34
InputString(QGridLayout *layout, int &row, const QString &id, const QString &s, StringMode m, const QString &docs, const QString &absPath=QString())
Definition: inputstring.cpp:39
static QCString * s
Definition: config.cpp:1042
virtual bool exists() const
Definition: qdir.cpp:820