26 #if defined (HAVE_CONFIG_H)
33 #include <QStringList>
34 #include <QStringListModel>
36 #include <QGridLayout>
38 #include <QHBoxLayout>
40 #include <QMessageBox>
41 #include <QPushButton>
42 #include <QVBoxLayout>
51 :
QObject (), m_octave_qobj (oct_qobj), m_dialog_result (-1),
52 m_dialog_button (), m_string_list (), m_list_index (), m_path_name ()
56 const QString&,
const QStringList&,
57 const QString&,
const QStringList&)),
60 const QString&,
const QStringList&,
61 const QString&,
const QStringList&)));
66 const QString&,
const QStringList&,
67 const QString&,
const QString&)),
71 const QString&,
const QStringList&,
72 const QString&,
const QString&)));
83 const QStringList&)));
87 const QString&,
const QString&,
91 const QString&,
const QString&,
97 QString text_wo_amp =
text;
98 text_wo_amp.replace (QRegExp (
"&(\\w)"),
"\\1");
103 const QString& title,
105 const QStringList& buttons,
106 const QString& defbutton,
107 const QStringList& role)
118 if (! buttons.isEmpty ())
121 QString xicon = icon;
122 if (xicon.isEmpty ())
138 const QStringList& prompt,
139 const QString& ok_string,
140 const QString& cancel_string)
143 return QPair<QIntList, int> ();
148 prompt, ok_string, cancel_string);
161 const QString& title,
164 const QStringList& defaults)
166 if (prompt.isEmpty ())
167 return QStringList ();
181 const QString& title,
182 const QString& filename,
184 const QString& multimode)
204 const QString& title,
206 const QStringList& button,
207 const QString& defbutton,
208 const QStringList& role)
212 button, defbutton, role);
214 connect (
message_dialog, SIGNAL (buttonClicked (QAbstractButton *)),
230 QString text_clean =
rm_amp (button->text ());
258 const QStringList& prompt,
259 const QString& ok_string,
260 const QString& cancel_string)
264 name, prompt, ok_string, cancel_string);
289 const QString& title,
292 const QStringList& defaults)
297 connect (
input_dialog, SIGNAL (finish_input (
const QStringList&,
int)),
317 const QString& title,
318 const QString& filename,
320 const QString& multimode)
326 connect (
file_dialog, SIGNAL (finish_input (
const QStringList&,
327 const QString&,
int)),
329 const QString&,
int)));
350 const QString& title,
const QString& qsicon,
351 const QStringList& qsbutton,
352 const QString& defbutton,
353 const QStringList& role)
358 setWindowModality (Qt::NonModal);
363 QMessageBox::Icon eicon = QMessageBox::NoIcon;
365 if (qsicon ==
"error")
366 eicon = QMessageBox::Critical;
367 else if (qsicon ==
"warn")
368 eicon = QMessageBox::Warning;
369 else if (qsicon ==
"help")
370 eicon = QMessageBox::Information;
371 else if (qsicon ==
"quest")
372 eicon = QMessageBox::Question;
376 int N = (qsbutton.size () < role.size () ? qsbutton.size () : role.size ());
379 addButton (QMessageBox::Ok);
382 for (
int i = 0; i <
N; i++)
388 QString srole = role.at (i);
389 QMessageBox::ButtonRole erole = QMessageBox::InvalidRole;
390 if (srole ==
"ResetRole")
391 erole = QMessageBox::ResetRole;
392 else if (srole ==
"YesRole")
393 erole = QMessageBox::YesRole;
394 else if (srole ==
"NoRole")
395 erole = QMessageBox::NoRole;
396 else if (srole ==
"RejectRole")
397 erole = QMessageBox::RejectRole;
398 else if (srole ==
"AcceptRole")
399 erole = QMessageBox::AcceptRole;
401 QPushButton *pbutton = addButton (qsbutton.at (i), erole);
402 if (qsbutton.at (i) == defbutton)
403 setDefaultButton (pbutton);
409 #define ACTIVE_ESCAPE 1
411 setEscapeButton (pbutton);
422 const QString& mode,
int wd,
int ht,
423 const QList<int>& initial,
const QString& title,
424 const QStringList& prompt,
425 const QString& ok_string,
426 const QString& cancel_string)
427 :
QDialog (), m_model (new QStringListModel (list))
429 QListView *view =
new QListView;
432 if (mode ==
"single")
433 view->setSelectionMode (QAbstractItemView::SingleSelection);
434 else if (mode ==
"multiple")
435 view->setSelectionMode (QAbstractItemView::ExtendedSelection);
437 view->setSelectionMode (QAbstractItemView::NoSelection);
441 for (
auto it = initial.begin (); it != initial.end (); it++)
443 QModelIndex idx =
m_model->index (initial.value (i++) - 1, 0,
445 selector->select (idx, QItemSelectionModel::Select);
448 bool fixed_layout =
false;
449 if (wd > 0 && ht > 0)
451 view->setFixedSize (wd, ht);
455 view->setEditTriggers (QAbstractItemView::NoEditTriggers);
457 QVBoxLayout *listLayout =
new QVBoxLayout;
458 if (! prompt.isEmpty ())
462 QString prompt_string;
463 for (
int j = 0; j < prompt.length (); j++)
469 prompt_string.append (
"<br>");
471 prompt_string.append (
"\n");
473 prompt_string.append (prompt.at (j));
475 QLabel *plabel =
new QLabel (prompt_string);
477 plabel->setTextFormat (Qt::RichText);
480 listLayout->addWidget (plabel);
482 listLayout->addWidget (view);
484 select_all->setVisible (mode ==
"multiple");
485 listLayout->addWidget (select_all);
489 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
490 buttonsLayout->addStretch (1);
491 buttonsLayout->addWidget (buttonOk);
492 buttonsLayout->addWidget (buttonCancel);
493 buttonOk->setDefault (
true);
495 QVBoxLayout *mainLayout =
new QVBoxLayout;
496 mainLayout->addLayout (listLayout);
497 mainLayout->addSpacing (12);
498 mainLayout->addLayout (buttonsLayout);
499 setLayout (mainLayout);
501 layout ()->setSizeConstraint (QLayout::SetFixedSize);
504 setWindowTitle (title.isEmpty () ?
" " : title);
506 connect (select_all, SIGNAL (clicked ()),
507 view, SLOT (selectAll ()));
509 connect (buttonOk, SIGNAL (clicked ()),
512 connect (buttonCancel, SIGNAL (clicked ()),
515 connect (view, SIGNAL (doubleClicked (
const QModelIndex&)),
529 QModelIndexList selected_index =
selector->selectedIndexes ();
532 for (
int i = 0; i < selected_index.size (); i++)
533 selected_int << selected_index.at (i).row () + 1;
537 done (QDialog::Accepted);
549 done (QDialog::Rejected);
564 const QFloatList& nc,
const QStringList& defaults)
568 #define LINE_EDIT_FOLLOWS_PROMPT 0
570 #if LINE_EDIT_FOLLOWS_PROMPT
572 QGridLayout *promptInputLayout =
new QGridLayout;
575 QVBoxLayout *promptInputLayout =
new QVBoxLayout;
577 int N_gridrows = prompt.size ();
578 for (
int i = 0; i < N_gridrows; i++)
580 QLabel *label =
new QLabel (prompt.at (i));
582 if (i < defaults.size ())
583 line_edit->setText (defaults.at (i));
584 if (i < nr.size () && nr.at (i) > 0)
586 QSize qsize = line_edit->sizeHint ();
587 int intval = qsize.height () * nr.at (i);
588 line_edit->setFixedHeight (intval);
589 if (i < nc.size () && nc.at (i) > 0)
591 intval = qsize.height () * nc.at (i) / 2;
592 line_edit->setFixedWidth (intval);
596 #if LINE_EDIT_FOLLOWS_PROMPT
597 promptInputLayout->addWidget (label, i + 1, 0);
598 promptInputLayout->addWidget (line_edit, i + 1, 1);
600 promptInputLayout->addWidget (label);
601 promptInputLayout->addWidget (line_edit);
604 #undef LINE_EDIT_FOLLOWS_PROMPT
608 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
609 buttonsLayout->addStretch (1);
610 buttonsLayout->addWidget (buttonOk);
611 buttonsLayout->addWidget (buttonCancel);
613 QVBoxLayout *mainLayout =
new QVBoxLayout;
614 mainLayout->addLayout (promptInputLayout);
615 mainLayout->addSpacing (12);
616 mainLayout->addLayout (buttonsLayout);
617 setLayout (mainLayout);
620 setWindowTitle (title.isEmpty () ?
" " : title);
622 connect (buttonOk, SIGNAL (clicked ()),
625 connect (buttonCancel, SIGNAL (clicked ()),
634 QStringList string_result;
638 done (QDialog::Accepted);
648 done (QDialog::Rejected);
657 const QStringList& name_filters,
658 const QString& title,
const QString& filename,
659 const QString&
dirname,
const QString& multimode)
663 setWindowModality (Qt::NonModal);
665 setWindowTitle (title.isEmpty () ?
" " : title);
672 setOption(QFileDialog::DontUseNativeDialog);
674 if (multimode ==
"on")
676 setFileMode (QFileDialog::ExistingFiles);
677 setAcceptMode (QFileDialog::AcceptOpen);
679 else if (multimode ==
"create")
681 setFileMode (QFileDialog::AnyFile);
682 setAcceptMode (QFileDialog::AcceptSave);
683 setOption (QFileDialog::DontConfirmOverwrite,
false);
685 else if (multimode ==
"dir")
687 setFileMode (QFileDialog::Directory);
688 setOption (QFileDialog::ShowDirsOnly,
true);
689 setOption (QFileDialog::HideNameFilterDetails,
true);
690 setAcceptMode (QFileDialog::AcceptOpen);
694 setFileMode (QFileDialog::ExistingFile);
695 setAcceptMode (QFileDialog::AcceptOpen);
698 setNameFilters (name_filters);
700 selectFile (filename);
715 QStringList string_result;
719 string_result = selectedFiles ();
721 if (testOption (QFileDialog::ShowDirsOnly) && string_result.size () > 0)
722 path = string_result[0];
724 path = directory ().absolutePath ();
729 for (
int i = 0; i < string_result.size (); i++)
730 string_result[i] = QFileInfo (string_result[i]).fileName ();
733 if (testOption (QFileDialog::ShowDirsOnly) ==
false)
737 path = QDir::toNativeSeparators (
path);
739 QStringList name_filters = nameFilters ();
740 idx = name_filters.indexOf (selectedNameFilter ()) + 1;
FileDialog(base_qobject &oct_qobj, const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
void acceptSelection(void)
void finish_input(const QStringList &, const QString &, int)
void rejectSelection(void)
ListDialog(base_qobject &oct_qobj, 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)
QAbstractItemModel * m_model
void buttonCancel_clicked(void)
void buttonOk_clicked(void)
void item_double_clicked(const QModelIndex &)
void finish_selection(const QIntList &, int)
QItemSelectionModel * selector
MessageDialog(base_qobject &oct_qobj, const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
gui_settings * get_settings(void) const
void message(const char *name, const char *fmt,...)
const gui_pref global_use_native_dialogs("use_native_file_dialogs", QVariant(true))
F77_RET_T const F77_INT & N
std::string dirname(const std::string &path)
static int input(yyscan_t yyscanner)
octave_value::octave_value(const Array< char > &chm, char type) return retval