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 ()
69 QString text_wo_amp = text;
70 text_wo_amp.replace (QRegExp (
"&(\\w)"),
"\\1");
77 const QStringList& buttons,
78 const QString& defbutton,
79 const QStringList& role)
90 if (! buttons.isEmpty ())
110 const QStringList& prompt,
111 const QString& ok_string,
112 const QString& cancel_string)
115 return QPair<QIntList, int> ();
120 prompt, ok_string, cancel_string);
133 const QString& title,
136 const QStringList& defaults)
138 if (prompt.isEmpty ())
139 return QStringList ();
153 const QString& title,
154 const QString& filename,
156 const QString& multimode)
176 const QString& title,
178 const QStringList& button,
179 const QString& defbutton,
180 const QStringList& role)
184 button, defbutton, role);
202 QString text_clean =
rm_amp (button->text ());
230 const QStringList& prompt,
231 const QString& ok_string,
232 const QString& cancel_string)
236 name, prompt, ok_string, cancel_string);
261 const QString& title,
264 const QStringList& defaults)
289 const QString& title,
290 const QString& filename,
292 const QString& multimode)
320 const QString& title,
const QString& qsicon,
321 const QStringList& qsbutton,
322 const QString& defbutton,
323 const QStringList& role)
328 setWindowModality (Qt::NonModal);
333 QMessageBox::Icon eicon = QMessageBox::NoIcon;
335 if (qsicon ==
"error")
336 eicon = QMessageBox::Critical;
337 else if (qsicon ==
"warn")
338 eicon = QMessageBox::Warning;
339 else if (qsicon ==
"help")
340 eicon = QMessageBox::Information;
341 else if (qsicon ==
"quest")
342 eicon = QMessageBox::Question;
346 int N = (qsbutton.size () < role.size () ? qsbutton.size () : role.size ());
349 addButton (QMessageBox::Ok);
352 for (
int i = 0; i <
N; i++)
358 QString srole = role.at (i);
359 QMessageBox::ButtonRole erole = QMessageBox::InvalidRole;
360 if (srole ==
"ResetRole")
361 erole = QMessageBox::ResetRole;
362 else if (srole ==
"YesRole")
363 erole = QMessageBox::YesRole;
364 else if (srole ==
"NoRole")
365 erole = QMessageBox::NoRole;
366 else if (srole ==
"RejectRole")
367 erole = QMessageBox::RejectRole;
368 else if (srole ==
"AcceptRole")
369 erole = QMessageBox::AcceptRole;
371 QPushButton *pbutton = addButton (qsbutton.at (i), erole);
372 if (qsbutton.at (i) == defbutton)
373 setDefaultButton (pbutton);
379 #define ACTIVE_ESCAPE 1
381 setEscapeButton (pbutton);
392 const QString& mode,
int wd,
int ht,
393 const QList<int>& initial,
const QString& title,
394 const QStringList& prompt,
395 const QString& ok_string,
396 const QString& cancel_string)
397 :
QDialog (), m_model (new QStringListModel (list, this))
399 QListView *view =
new QListView;
402 if (mode ==
"single")
403 view->setSelectionMode (QAbstractItemView::SingleSelection);
404 else if (mode ==
"multiple")
405 view->setSelectionMode (QAbstractItemView::ExtendedSelection);
407 view->setSelectionMode (QAbstractItemView::NoSelection);
411 for (
auto it = initial.begin (); it != initial.end (); it++)
413 QModelIndex idx =
m_model->index (initial.value (i++) - 1, 0,
415 selector->select (idx, QItemSelectionModel::Select);
418 bool fixed_layout =
false;
419 if (wd > 0 && ht > 0)
421 view->setFixedSize (wd, ht);
425 view->setEditTriggers (QAbstractItemView::NoEditTriggers);
427 QVBoxLayout *listLayout =
new QVBoxLayout;
428 if (! prompt.isEmpty ())
432 QString prompt_string;
433 for (
int j = 0; j < prompt.length (); j++)
439 prompt_string.append (
"<br>");
441 prompt_string.append (
"\n");
443 prompt_string.append (prompt.at (j));
447 plabel->setTextFormat (Qt::RichText);
450 listLayout->addWidget (plabel);
452 listLayout->addWidget (view);
454 select_all->setVisible (mode ==
"multiple");
455 listLayout->addWidget (select_all);
459 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
460 buttonsLayout->addStretch (1);
461 buttonsLayout->addWidget (buttonOk);
462 buttonsLayout->addWidget (buttonCancel);
463 buttonOk->setDefault (
true);
465 QVBoxLayout *mainLayout =
new QVBoxLayout;
466 mainLayout->addLayout (listLayout);
467 mainLayout->addSpacing (12);
468 mainLayout->addLayout (buttonsLayout);
469 setLayout (mainLayout);
471 layout ()->setSizeConstraint (QLayout::SetFixedSize);
474 setWindowTitle (title.isEmpty () ?
" " : title);
476 connect (select_all, &QPushButton::clicked,
477 view, &QListView::selectAll);
479 connect (buttonOk, &QPushButton::clicked,
482 connect (buttonCancel, &QPushButton::clicked,
485 connect (view, &QListView::doubleClicked,
494 QModelIndexList selected_index =
selector->selectedIndexes ();
497 for (
int i = 0; i < selected_index.size (); i++)
498 selected_int << selected_index.at (i).row () + 1;
502 done (QDialog::Accepted);
514 done (QDialog::Rejected);
529 const QFloatList& nc,
const QStringList& defaults)
533 #define LINE_EDIT_FOLLOWS_PROMPT 0
535 #if LINE_EDIT_FOLLOWS_PROMPT
537 QGridLayout *promptInputLayout =
new QGridLayout;
540 QVBoxLayout *promptInputLayout =
new QVBoxLayout;
542 int N_gridrows = prompt.size ();
543 for (
int i = 0; i < N_gridrows; i++)
547 if (i < defaults.size ())
548 line_edit->setText (defaults.at (i));
549 if (i < nr.size () && nr.at (i) > 0)
551 QSize qsize = line_edit->sizeHint ();
552 int intval = qsize.height () * nr.at (i);
553 line_edit->setFixedHeight (intval);
554 if (i < nc.size () && nc.at (i) > 0)
556 intval = qsize.height () * nc.at (i) / 2;
557 line_edit->setFixedWidth (intval);
561 #if LINE_EDIT_FOLLOWS_PROMPT
562 promptInputLayout->addWidget (label, i + 1, 0);
563 promptInputLayout->addWidget (line_edit, i + 1, 1);
565 promptInputLayout->addWidget (label);
566 promptInputLayout->addWidget (line_edit);
569 #undef LINE_EDIT_FOLLOWS_PROMPT
573 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
574 buttonsLayout->addStretch (1);
575 buttonsLayout->addWidget (buttonOk);
576 buttonsLayout->addWidget (buttonCancel);
578 QVBoxLayout *mainLayout =
new QVBoxLayout;
579 mainLayout->addLayout (promptInputLayout);
580 mainLayout->addSpacing (12);
581 mainLayout->addLayout (buttonsLayout);
582 setLayout (mainLayout);
585 setWindowTitle (title.isEmpty () ?
" " : title);
587 connect (buttonOk, &QPushButton::clicked,
590 connect (buttonCancel, &QPushButton::clicked,
599 QStringList string_result;
603 done (QDialog::Accepted);
613 done (QDialog::Rejected);
622 const QStringList& name_filters,
623 const QString& title,
const QString& filename,
624 const QString&
dirname,
const QString& multimode)
628 setWindowModality (Qt::NonModal);
630 setWindowTitle (title.isEmpty () ?
" " : title);
637 setOption(QFileDialog::DontUseNativeDialog);
639 if (multimode ==
"on")
641 setFileMode (QFileDialog::ExistingFiles);
642 setAcceptMode (QFileDialog::AcceptOpen);
644 else if (multimode ==
"create")
646 setFileMode (QFileDialog::AnyFile);
647 setAcceptMode (QFileDialog::AcceptSave);
648 setOption (QFileDialog::DontConfirmOverwrite,
false);
650 else if (multimode ==
"dir")
652 setFileMode (QFileDialog::Directory);
653 setOption (QFileDialog::ShowDirsOnly,
true);
654 setOption (QFileDialog::HideNameFilterDetails,
true);
655 setAcceptMode (QFileDialog::AcceptOpen);
659 setFileMode (QFileDialog::ExistingFile);
660 setAcceptMode (QFileDialog::AcceptOpen);
663 setNameFilters (name_filters);
665 selectFile (filename);
680 QStringList string_result;
684 string_result = selectedFiles ();
686 if (testOption (QFileDialog::ShowDirsOnly) && string_result.size () > 0)
687 path = string_result[0];
689 path = directory ().absolutePath ();
694 for (
int i = 0; i < string_result.size (); i++)
695 string_result[i] = QFileInfo (string_result[i]).fileName ();
698 if (testOption (QFileDialog::ShowDirsOnly) ==
false)
702 path = QDir::toNativeSeparators (path);
704 QStringList name_filters = nameFilters ();
705 idx = name_filters.indexOf (selectedNameFilter ()) + 1;
void acceptSelection(void)
void rejectSelection(void)
FileDialog(base_qobject &oct_qobj, const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
void finish_input(const QStringList &, const QString &, int)
void buttonCancel_clicked(void)
QAbstractItemModel * m_model
QItemSelectionModel * selector
void finish_selection(const QIntList &, int)
void buttonOk_clicked(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)
void item_double_clicked(const QModelIndex &)
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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void message(const char *name, const char *fmt,...)
std::string dirname(const std::string &path)
const gui_pref global_use_native_dialogs("use_native_file_dialogs", QVariant(true))
F77_RET_T const F77_INT & N
static int input(yyscan_t yyscanner)