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 ())
118 const QString& path,
int filterindex)
137 const QString& title,
138 const QString& qsicon,
139 const QStringList& qsbutton,
140 const QString& defbutton,
141 const QStringList& role)
146 setWindowModality (Qt::NonModal);
150 QMessageBox::Icon eicon = QMessageBox::NoIcon;
151 if (qsicon ==
"error")
152 eicon = QMessageBox::Critical;
153 else if (qsicon ==
"warn")
154 eicon = QMessageBox::Warning;
155 else if (qsicon ==
"help")
156 eicon = QMessageBox::Information;
157 else if (qsicon ==
"quest")
158 eicon = QMessageBox::Question;
161 int N = qsbutton.size () < role.size () ? qsbutton.size () : role.size ();
163 addButton (QMessageBox::Ok);
166 for (
int i = N-1; i >= 0; i--)
170 QString srole = role.at (i);
171 QMessageBox::ButtonRole erole = QMessageBox::InvalidRole;
172 if (srole ==
"YesRole")
173 erole = QMessageBox::YesRole;
174 else if (srole ==
"NoRole")
175 erole = QMessageBox::NoRole;
176 else if (srole ==
"RejectRole")
177 erole = QMessageBox::RejectRole;
178 else if (srole ==
"AcceptRole")
179 erole = QMessageBox::AcceptRole;
181 QPushButton *pbutton = addButton (qsbutton.at (i), erole);
182 if (qsbutton.at (i) == defbutton)
183 setDefaultButton (pbutton);
187 #define ACTIVE_ESCAPE 1
189 setEscapeButton (pbutton);
198 connect (
this, SIGNAL (buttonClicked (QAbstractButton *)),
199 &uiwidget_creator, SLOT (dialog_button_clicked (QAbstractButton *)));
205 const QString& title,
const QStringList& prompt,
206 const QString& ok_string,
const QString& cancel_string)
211 QAbstractItemModel *model =
new QStringListModel (list);
213 QListView *view =
new QListView;
214 view->setModel (model);
216 if (mode ==
"single")
217 view->setSelectionMode (QAbstractItemView::SingleSelection);
218 else if (mode ==
"multiple")
219 view->setSelectionMode (QAbstractItemView::ExtendedSelection);
221 view->setSelectionMode (QAbstractItemView::NoSelection);
226 it != initial.end (); it++)
228 QModelIndex idx = model->index (initial.value (i++) - 1, 0,
230 selector->select (idx, QItemSelectionModel::Select);
233 bool fixed_layout =
false;
234 if (wd > 0 && ht > 0)
236 view->setFixedSize (wd, ht);
240 view->setEditTriggers (QAbstractItemView::NoEditTriggers);
242 QVBoxLayout *listLayout =
new QVBoxLayout;
243 if (! prompt.isEmpty ())
247 QString prompt_string;
248 for (
int j = 0; j < prompt.length (); j++)
253 prompt_string.append (
"<br>");
255 prompt_string.append (
"\n");
257 prompt_string.append (prompt.at (j));
259 QLabel *plabel =
new QLabel (prompt_string);
261 plabel->setTextFormat (Qt::RichText);
264 listLayout->addWidget (plabel);
266 listLayout->addWidget (view);
268 select_all->setEnabled (mode ==
"multiple");
269 listLayout->addWidget (select_all);
273 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
274 buttonsLayout->addStretch (1);
275 buttonsLayout->addWidget (buttonOk);
276 buttonsLayout->addWidget (buttonCancel);
278 QVBoxLayout *mainLayout =
new QVBoxLayout;
279 mainLayout->addLayout (listLayout);
280 mainLayout->addSpacing (12);
281 mainLayout->addLayout (buttonsLayout);
282 setLayout (mainLayout);
284 layout ()->setSizeConstraint (QLayout::SetFixedSize);
287 setWindowTitle (title.isEmpty () ?
" " : title);
289 connect (select_all, SIGNAL (clicked ()),
290 view, SLOT (selectAll ()));
292 connect (buttonOk, SIGNAL (clicked ()),
295 connect (buttonCancel, SIGNAL (clicked ()),
300 SLOT (list_select_finished (
const QIntList&,
int)));
309 QModelIndexList selected_index =
selector->selectedIndexes ();
312 for (
int i = 0; i < selected_index.size (); i++)
313 selected_int << selected_index.at (i).row () + 1;
317 done (QDialog::Accepted);
330 done (QDialog::Rejected);
343 const QStringList& defaults)
347 #define LINE_EDIT_FOLLOWS_PROMPT 0
349 #if LINE_EDIT_FOLLOWS_PROMPT
351 QGridLayout *promptInputLayout =
new QGridLayout;
354 QVBoxLayout *promptInputLayout =
new QVBoxLayout;
356 int N_gridrows = prompt.size ();
357 for (
int i = 0; i < N_gridrows; i++)
359 QLabel *label =
new QLabel (prompt.at (i));
363 QSize qsize = line_edit->sizeHint ();
364 int intval = qsize.height () * nr.at (i);
365 line_edit->setFixedHeight (intval);
368 intval = qsize.height () * nc.at (i) / 2;
369 line_edit->setFixedWidth (intval);
373 #if LINE_EDIT_FOLLOWS_PROMPT
374 promptInputLayout->addWidget (label, i + 1, 0);
375 promptInputLayout->addWidget (line_edit, i + 1, 1);
377 promptInputLayout->addWidget (label);
378 promptInputLayout->addWidget (line_edit);
381 #undef LINE_EDIT_FOLLOWS_PROMPT
385 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
386 buttonsLayout->addStretch (1);
387 buttonsLayout->addWidget (buttonOk);
388 buttonsLayout->addWidget (buttonCancel);
390 QVBoxLayout *mainLayout =
new QVBoxLayout;
391 mainLayout->addLayout (promptInputLayout);
392 mainLayout->addSpacing (12);
393 mainLayout->addLayout (buttonsLayout);
394 setLayout (mainLayout);
397 setWindowTitle (title.isEmpty () ?
" " : title);
399 connect (buttonOk, SIGNAL (clicked ()),
402 connect (buttonCancel, SIGNAL (clicked ()),
405 connect (
this, SIGNAL (
finish_input (
const QStringList&,
int)),
407 SLOT (input_finished (
const QStringList&,
int)));
416 QStringList string_result;
420 done (QDialog::Accepted);
430 done (QDialog::Rejected);
441 const QString& filename,
const QString& dirname,
442 const QString& multimode)
446 setWindowModality (Qt::NonModal);
448 setWindowTitle (title.isEmpty () ?
" " : title);
449 setDirectory (dirname);
451 if (multimode ==
"on")
453 setFileMode (QFileDialog::ExistingFiles);
454 setAcceptMode (QFileDialog::AcceptOpen);
456 else if (multimode ==
"create")
458 setFileMode (QFileDialog::AnyFile);
459 setAcceptMode (QFileDialog::AcceptSave);
460 setOption (QFileDialog::DontConfirmOverwrite,
false);
461 setConfirmOverwrite (
true);
463 else if (multimode ==
"dir")
465 setFileMode (QFileDialog::Directory);
466 setOption (QFileDialog::ShowDirsOnly,
true);
467 setOption (QFileDialog::HideNameFilterDetails,
true);
468 setAcceptMode (QFileDialog::AcceptOpen);
472 setFileMode (QFileDialog::ExistingFile);
473 setAcceptMode (QFileDialog::AcceptOpen);
476 setNameFilters (name_filters);
478 selectFile (filename);
481 SIGNAL (
finish_input (
const QStringList&,
const QString&,
int)),
483 SLOT (filedialog_finished (
const QStringList&,
const QString&,
498 QStringList string_result;
502 string_result = selectedFiles ();
504 if (testOption (QFileDialog::ShowDirsOnly) ==
true &&
505 string_result.size () > 0)
507 path = string_result[0];
511 path = directory ().absolutePath ();
517 for (
int i = 0; i < string_result.size (); i++)
518 string_result[i] = QFileInfo (string_result[i]).fileName ();
521 if (testOption (QFileDialog::ShowDirsOnly) ==
false)
525 path = QDir::toNativeSeparators (path);
527 QStringList name_filters = nameFilters ();
528 idx = name_filters.indexOf (selectedNameFilter ()) + 1;
void buttonOk_clicked(void)
void finish_selection(const QIntList &, int)
QItemSelectionModel * selector
FileDialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
ListDialog(const QStringList &list, const QString &mode, int width, int height, const QList< int > &initial, const QString &name, const QStringList &prompt, const QString &ok_string, const QString &cancel_string)
void rejectSelection(void)
QUIWidgetCreator uiwidget_creator
void message(const char *name, const char *fmt,...)
F77_RET_T const octave_idx_type & N
MessageDialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
void finish_input(const QStringList &, const QString &, int)
static int input(yyscan_t yyscanner)
void acceptSelection(void)
void buttonCancel_clicked(void)