scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ExtensibleFileDialog.cpp
Go to the documentation of this file.
1 
11 
30 #include "ExtensibleFileDialog.h"
31 #include <QGridLayout>
32 
33 ExtensibleFileDialog::ExtensibleFileDialog(QWidget *parent, bool extended, Qt::WindowFlags flags)
34  : QFileDialog(parent, flags)
35 {
36  d_extension = 0;
37 
38 #if QT_VERSION >= 0x050000
39  // needed to extend the Qt5 QFileDialog
40  setOption(QFileDialog::DontUseNativeDialog, true);
41 #endif
42 
43  d_extension_toggle = new QPushButton(tr("<< &Advanced"));
44  d_extension_toggle->setCheckable(true);
45  if (extended)
46  d_extension_toggle->toggle();
47  d_extension_toggle->hide(); // show only for d_extension != 0
48 
49  QGridLayout *main_layout = qobject_cast<QGridLayout*>(layout());
50  if (main_layout) {
51  d_extension_row = main_layout->rowCount();
52  main_layout->addWidget(d_extension_toggle, d_extension_row, main_layout->columnCount()-1);
53  main_layout->setRowStretch(d_extension_row, 0);
54  main_layout->setRowStretch(d_extension_row+1, 0);
55  } else {
56  // fallback in case QFileDialog uses a different layout in the future (=> main_layout==0)
57  // would probably look a mess, but at least all functions would be accessible
58  layout()->addWidget(d_extension_toggle);
59  }
60 
61  connect(d_extension_toggle, SIGNAL(toggled(bool)), this, SLOT(resize(bool)));
62  connect(this, SIGNAL(accepted()), this, SLOT(close()));
63  connect(this, SIGNAL(rejected()), this, SLOT(close()));
64 }
65 
67 {
68  if (d_extension == extension)
69  return;
70  if (d_extension) {
71  d_extension->hide();
72  disconnect(d_extension_toggle, SIGNAL(toggled(bool)));
73  }
74  d_extension = extension;
75  if (!d_extension) {
76  d_extension_toggle->hide();
77  return;
78  }
79  d_extension_toggle->show();
80 
81  QGridLayout *main_layout = qobject_cast<QGridLayout*>(layout());
82  if (main_layout)
83  main_layout->addWidget(d_extension, d_extension_row, 0, 2, main_layout->columnCount()-1);
84  else
85  layout()->addWidget(d_extension);
86 
87  d_extension->setVisible(d_extension_toggle->isChecked());
88  connect(d_extension_toggle, SIGNAL(toggled(bool)), d_extension, SLOT(setVisible(bool)));
89 }
90 
91 void ExtensibleFileDialog::resize(bool extension_on)
92 {
93  QSize geo = size();
94  geo.setHeight(geo.height() + (extension_on ? 1 : -1) * (d_extension->sizeHint().height()-44));
95  setGeometry(QRect(geometry().topLeft(), geo));
96 }
ExtensibleFileDialog::d_extension_row
int d_extension_row
The layout row (of the assumed QGridLayout) used for extensions.
Definition: ExtensibleFileDialog.h:76
ExtensibleFileDialog::setExtensionWidget
void setExtensionWidget(QWidget *extension)
Set the extension widget to be displayed when the user presses the toggle button.
Definition: ExtensibleFileDialog.cpp:66
ExtensibleFileDialog::d_extension
QWidget * d_extension
The extension widget.
Definition: ExtensibleFileDialog.h:74
ExtensibleFileDialog::ExtensibleFileDialog
ExtensibleFileDialog(QWidget *parent=0, bool extended=true, Qt::WindowFlags flags=0)
Constructor.
Definition: ExtensibleFileDialog.cpp:33
ExtensibleFileDialog::d_extension_toggle
QPushButton * d_extension_toggle
Button for toggling display of extension on/off.
Definition: ExtensibleFileDialog.h:62
python-sipcmd.flags
list flags
Definition: python-sipcmd.py:61
ExtensibleFileDialog::resize
void resize(bool extension_on)
Resize to make/take space for the extension widget.
Definition: ExtensibleFileDialog.cpp:91
ExtensibleFileDialog.h