31 #include <QStringList>
32 #include <QStringListModel>
36 #include <QMessageBox>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
39 #include <QPushButton>
41 #include <QGridLayout>
48 :
QObject (), dialog_result (-1), dialog_button (),
49 string_list (new QStringList ()), list_index (new
QIntList ()),
50 path_name (new QString ())
103 const QString& path,
int filterindex)
117 const QString& title,
118 const QString& qsicon,
119 const QStringList& qsbutton,
120 const QString& defbutton,
121 const QStringList& role)
126 setWindowModality (Qt::NonModal);
130 QMessageBox::Icon eicon = QMessageBox::NoIcon;
131 if (qsicon ==
"error")
132 eicon = QMessageBox::Critical;
133 else if (qsicon ==
"warn")
134 eicon = QMessageBox::Warning;
135 else if (qsicon ==
"help")
136 eicon = QMessageBox::Information;
137 else if (qsicon ==
"quest")
138 eicon = QMessageBox::Question;
141 int N = qsbutton.size () < role.size () ? qsbutton.size () : role.size ();
143 addButton (QMessageBox::Ok);
146 for (
int i = N-1; i >= 0; i--)
150 QString srole = role.at (i);
151 QMessageBox::ButtonRole erole = QMessageBox::InvalidRole;
152 if (srole ==
"YesRole")
153 erole = QMessageBox::YesRole;
154 else if (srole ==
"NoRole")
155 erole = QMessageBox::NoRole;
156 else if (srole ==
"RejectRole")
157 erole = QMessageBox::RejectRole;
158 else if (srole ==
"AcceptRole")
159 erole = QMessageBox::AcceptRole;
161 QPushButton *pbutton = addButton (qsbutton.at (i), erole);
162 if (qsbutton.at (i) == defbutton)
163 setDefaultButton (pbutton);
167 #define ACTIVE_ESCAPE 1
169 setEscapeButton (pbutton);
178 connect (
this, SIGNAL (buttonClicked (QAbstractButton *)),
179 &uiwidget_creator, SLOT (dialog_button_clicked (QAbstractButton *)));
185 const QString& title,
const QStringList& prompt,
186 const QString& ok_string,
const QString& cancel_string)
191 QAbstractItemModel *model =
new QStringListModel (list);
193 QListView *view =
new QListView;
194 view->setModel (model);
196 if (mode ==
"Single")
197 view->setSelectionMode (QAbstractItemView::SingleSelection);
198 else if (mode ==
"Multiple")
199 view->setSelectionMode (QAbstractItemView::ExtendedSelection);
205 view->setSelectionMode (QAbstractItemView::NoSelection);
210 it != initial.end (); it++)
212 QModelIndex idx = model->index (initial.value (i++) - 1, 0,
214 selector->select (idx, QItemSelectionModel::Select);
217 bool fixed_layout =
false;
218 if (wd > 0 && ht > 0)
220 view->setFixedSize (wd, ht);
224 view->setEditTriggers (QAbstractItemView::NoEditTriggers);
226 QVBoxLayout *listLayout =
new QVBoxLayout;
227 if (! prompt.isEmpty ())
231 QString prompt_string;
232 for (
int j = 0; j < prompt.length (); j++)
237 prompt_string.append (
"<br>");
239 prompt_string.append (
"\n");
241 prompt_string.append (prompt.at (j));
243 QLabel *plabel =
new QLabel (prompt_string);
245 plabel->setTextFormat (Qt::RichText);
248 listLayout->addWidget (plabel);
250 listLayout->addWidget (view);
252 select_all->setEnabled (mode ==
"Multiple");
253 listLayout->addWidget (select_all);
257 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
258 buttonsLayout->addStretch (1);
259 buttonsLayout->addWidget (buttonOk);
260 buttonsLayout->addWidget (buttonCancel);
262 QVBoxLayout *mainLayout =
new QVBoxLayout;
263 mainLayout->addLayout (listLayout);
264 mainLayout->addSpacing (12);
265 mainLayout->addLayout (buttonsLayout);
266 setLayout (mainLayout);
268 layout ()->setSizeConstraint (QLayout::SetFixedSize);
271 setWindowTitle (title.isEmpty () ?
" " : title);
273 connect (select_all, SIGNAL (clicked ()),
274 view, SLOT (selectAll ()));
276 connect (buttonOk, SIGNAL (clicked ()),
279 connect (buttonCancel, SIGNAL (clicked ()),
284 SLOT (list_select_finished (
const QIntList&,
int)));
293 QModelIndexList selected_index =
selector->selectedIndexes ();
296 for (
int i = 0; i < selected_index.size (); i++)
297 selected_int << selected_index.at (i).row () + 1;
301 done (QDialog::Accepted);
314 done (QDialog::Rejected);
327 const QStringList& defaults)
331 #define LINE_EDIT_FOLLOWS_PROMPT 0
333 #if LINE_EDIT_FOLLOWS_PROMPT
335 QGridLayout *promptInputLayout =
new QGridLayout;
338 QVBoxLayout *promptInputLayout =
new QVBoxLayout;
340 int N_gridrows = prompt.size ();
341 for (
int i = 0; i < N_gridrows; i++)
343 QLabel *label =
new QLabel (prompt.at (i));
344 QLineEdit *line_edit =
new QLineEdit (defaults.at (i));
347 QSize qsize = line_edit->sizeHint ();
348 int intval = qsize.height () * nr.at (i);
349 line_edit->setFixedHeight (intval);
352 intval = qsize.height () * nc.at (i) / 2;
353 line_edit->setFixedWidth (intval);
357 #if LINE_EDIT_FOLLOWS_PROMPT
358 promptInputLayout->addWidget (label, i + 1, 0);
359 promptInputLayout->addWidget (line_edit, i + 1, 1);
361 promptInputLayout->addWidget (label);
362 promptInputLayout->addWidget (line_edit);
365 #undef LINE_EDIT_FOLLOWS_PROMPT
369 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
370 buttonsLayout->addStretch (1);
371 buttonsLayout->addWidget (buttonOk);
372 buttonsLayout->addWidget (buttonCancel);
374 QVBoxLayout *mainLayout =
new QVBoxLayout;
375 mainLayout->addLayout (promptInputLayout);
376 mainLayout->addSpacing (12);
377 mainLayout->addLayout (buttonsLayout);
378 setLayout (mainLayout);
381 setWindowTitle (title.isEmpty () ?
" " : title);
383 connect (buttonOk, SIGNAL (clicked ()),
386 connect (buttonCancel, SIGNAL (clicked ()),
389 connect (
this, SIGNAL (
finish_input (
const QStringList&,
int)),
391 SLOT (input_finished (
const QStringList&,
int)));
400 QStringList string_result;
404 done (QDialog::Accepted);
414 done (QDialog::Rejected);
425 const QString& filename,
const QString& dirname,
426 const QString& multimode)
430 setWindowModality (Qt::NonModal);
432 setWindowTitle (title.isEmpty () ?
" " : title);
433 setDirectory (dirname);
435 if (multimode ==
"on")
437 setFileMode (QFileDialog::ExistingFiles);
438 setAcceptMode (QFileDialog::AcceptOpen);
440 else if (multimode ==
"create")
442 setFileMode (QFileDialog::AnyFile);
443 setAcceptMode (QFileDialog::AcceptSave);
444 setOption (QFileDialog::DontConfirmOverwrite,
false);
445 setConfirmOverwrite (
true);
447 else if (multimode ==
"dir")
449 setFileMode (QFileDialog::Directory);
450 setOption (QFileDialog::ShowDirsOnly,
true);
451 setOption (QFileDialog::HideNameFilterDetails,
true);
452 setAcceptMode (QFileDialog::AcceptOpen);
456 setFileMode (QFileDialog::ExistingFile);
457 setAcceptMode (QFileDialog::AcceptOpen);
460 setNameFilters (name_filters);
462 selectFile (filename);
465 SIGNAL (
finish_input (
const QStringList&,
const QString&,
int)),
467 SLOT (filedialog_finished (
const QStringList&,
const QString&,
476 done (QDialog::Rejected);
482 QStringList string_result;
486 string_result = selectedFiles ();
491 for (
int i = 0; i < string_result.size (); i++)
492 string_result[i] = QFileInfo (string_result[i]).fileName ();
495 path = directory ().absolutePath ();
497 QStringList name_filters = nameFilters ();
498 idx = name_filters.indexOf (selectedNameFilter ()) + 1;
502 done (QDialog::Accepted);