1 /******************************************************************************
5 * Copyright (C) 1997-2012 by Dimitri van Heesch.
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.
15 #include "inputstrlist.h"
16 #include "helplabel.h"
17 #include "doxywizard.h"
22 InputStrList::InputStrList( QGridLayout *layout,int &row,
24 const QStringList &sl, ListMode lm,
26 : m_default(sl), m_strList(sl), m_docs(docs), m_id(id)
28 m_lab = new HelpLabel( id );
33 QToolBar *toolBar = new QToolBar;
34 toolBar->setIconSize(QSize(24,24));
35 m_add = toolBar->addAction(QIcon(QString::fromAscii(":/images/add.png")),QString(),
36 this,SLOT(addString()));
37 m_add->setToolTip(tr("Add item"));
38 m_del = toolBar->addAction(QIcon(QString::fromAscii(":/images/del.png")),QString(),
39 this,SLOT(delString()));
40 m_del->setToolTip(tr("Delete selected item"));
41 m_upd = toolBar->addAction(QIcon(QString::fromAscii(":/images/refresh.png")),QString(),
42 this,SLOT(updateString()));
43 m_upd->setToolTip(tr("Update selected item"));
45 m_lb = new QListWidget;
46 //m_lb->setMinimumSize(400,100);
47 foreach (QString s, m_strList) m_lb->addItem(s);
55 m_brFile = toolBar->addAction(QIcon(QString::fromAscii(":/images/file.png")),QString(),
56 this,SLOT(browseFiles()));
57 m_brFile->setToolTip(tr("Browse to a file"));
61 m_brDir = toolBar->addAction(QIcon(QString::fromAscii(":/images/folder.png")),QString(),
62 this,SLOT(browseDir()));
63 m_brDir->setToolTip(tr("Browse to a folder"));
66 QHBoxLayout *rowLayout = new QHBoxLayout;
67 rowLayout->addWidget( m_le );
68 rowLayout->addWidget( toolBar );
69 layout->addWidget( m_lab, row,0 );
70 layout->addLayout( rowLayout, row,1,1,2 );
71 layout->addWidget( m_lb, row+1,1,1,2 );
76 connect(m_le, SIGNAL(returnPressed()),
77 this, SLOT(addString()) );
78 connect(m_lb, SIGNAL(currentTextChanged(const QString &)),
79 this, SLOT(selectText(const QString &)));
80 connect( m_lab, SIGNAL(enter()), SLOT(help()) );
81 connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
84 void InputStrList::help()
90 void InputStrList::addString()
92 if (!m_le->text().isEmpty())
94 m_lb->addItem(m_le->text());
95 m_strList.append(m_le->text());
103 void InputStrList::delString()
105 if (m_lb->currentRow()!=-1)
107 int itemIndex = m_lb->currentRow();
108 delete m_lb->currentItem();
109 m_strList.removeAt(itemIndex);
116 void InputStrList::updateString()
118 if (m_lb->currentRow()!=-1 && !m_le->text().isEmpty())
120 m_lb->currentItem()->setText(m_le->text());
121 m_strList.insert(m_lb->currentRow(),m_le->text());
122 m_strList.removeAt(m_lb->currentRow()+1);
129 void InputStrList::selectText(const QString &s)
134 void InputStrList::setEnabled(bool state)
136 m_lab->setEnabled(state);
137 m_le->setEnabled(state);
138 m_add->setEnabled(state);
139 m_del->setEnabled(state);
140 m_upd->setEnabled(state);
141 m_lb->setEnabled(state);
142 if (m_brFile) m_brFile->setEnabled(state);
143 if (m_brDir) m_brDir->setEnabled(state);
146 void InputStrList::browseFiles()
148 QString path = QFileInfo(MainWindow::instance().configFileName()).path();
149 QStringList fileNames = QFileDialog::getOpenFileNames();
151 if (!fileNames.isEmpty())
153 QStringList::Iterator it;
154 for ( it= fileNames.begin(); it != fileNames.end(); ++it )
158 if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
160 fileName = dir.relativeFilePath(*it);
162 if (fileName.isEmpty())
166 m_lb->addItem(fileName);
167 m_strList.append(fileName);
172 m_le->setText(m_strList[0]);
176 void InputStrList::browseDir()
178 QString path = QFileInfo(MainWindow::instance().configFileName()).path();
179 QString dirName = QFileDialog::getExistingDirectory();
181 if (!dirName.isNull())
184 if (!MainWindow::instance().configFileName().isEmpty() && dir.exists())
186 dirName = dir.relativeFilePath(dirName);
188 if (dirName.isEmpty())
190 dirName=QString::fromAscii(".");
192 m_lb->addItem(dirName);
193 m_strList.append(dirName);
197 m_le->setText(dirName);
201 void InputStrList::setValue(const QStringList &sl)
206 for (int i=0;i<m_strList.size();i++)
208 m_lb->addItem(m_strList[i].trimmed());
213 QVariant &InputStrList::value()
218 void InputStrList::update()
220 setValue(m_value.toStringList());
223 void InputStrList::updateDefault()
225 if (m_strList==m_default)
227 m_lab->setText(QString::fromAscii("<qt>")+m_id+QString::fromAscii("</qt"));
231 m_lab->setText(QString::fromAscii("<qt><font color='red'>")+m_id+QString::fromAscii("</font></qt>"));
235 void InputStrList::reset()
240 void InputStrList::writeValue(QTextStream &t,QTextCodec *codec)
243 foreach (QString s, m_strList)
251 writeStringValue(t,codec,s);