All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ResourceChooser.cpp
Go to the documentation of this file.
1 #include "ResourceChooser.h"
2 
3 #include "FileChooser.h"
4 
5 //! Qt include files
6 #include <QHBoxLayout>
7 #include <QVBoxLayout>
8 #include <QGridLayout>
9 #include <QRadioButton>
10 #include <QPushButton>
11 #include <QButtonGroup>
12 #include <QDialog>
13 
14 namespace te_qt = te::qt::widgets;
15 
17 QWidget(parent)
18 {
19  m_fchooser = new FileChooser(this);
20  QRadioButton* f = new QRadioButton(tr("File"), this);
21  QRadioButton* d = new QRadioButton(tr("Directory"), this);
22  QButtonGroup* grp = new QButtonGroup(this);
23  QHBoxLayout* hlay = new QHBoxLayout;
24  QVBoxLayout* vlay = new QVBoxLayout;
25 
26  hlay->addWidget(m_fchooser);
27  vlay->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
28  hlay->addWidget(f);
29  hlay->addWidget(d);
30 
31  vlay->addLayout(hlay);
32  vlay->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
33 
34  QGridLayout* grd = new QGridLayout(this);
35  grd->addLayout(vlay, 0, 0, 1, 1);
36 
37  grp->addButton(f, FileChooser::FILE);
38  grp->addButton(d, FileChooser::FOLDER);
39 
40  f->setChecked(true);
41 
42  connect(grp, SIGNAL(buttonClicked(int)), SLOT(setResource(int)));
43 }
44 
46 {
47 }
48 
50 {
51  return m_fchooser->getSelectedResource();
52 }
53 
54 void te_qt::ResourceChooser::setFilterPattern(const QString& filter)
55 {
56  m_fchooser->setFilterPattern(filter);
57 }
58 
59 QString te_qt::ResourceChooser::getResource(const QString& initialPath, const QString& filter, QWidget* parent)
60 {
61  QDialog dlg(parent);
62  ResourceChooser* rsc = new ResourceChooser(&dlg);
63  QPushButton* okBtn = new QPushButton(tr("&Ok"), &dlg);
64  QPushButton* cancelBtn = new QPushButton(tr("&Cancel"), &dlg);
65  QPushButton* helpBtn = new QPushButton(tr("&Help"), &dlg);
66  QHBoxLayout* hlay = new QHBoxLayout;
67  QVBoxLayout* vlay = new QVBoxLayout;
68  QGridLayout* grd = new QGridLayout(&dlg);
69 
70  hlay->addWidget(helpBtn);
71  hlay->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
72  hlay->addWidget(okBtn);
73  hlay->addWidget(cancelBtn);
74 
75  vlay->addWidget(rsc);
76  vlay->addLayout(hlay);
77  grd->addLayout(vlay, 0, 0, 1, 1);
78 
79  rsc->m_fchooser->setInitialPath(initialPath);
80  rsc->setFilterPattern(filter);
81 
82  dlg.setWindowTitle(tr("Choose a xml file or a directory containing xml plug-in files"));
83 
84  dlg.connect(okBtn, SIGNAL(pressed()), SLOT(accept()));
85  dlg.connect(cancelBtn, SIGNAL(pressed()), SLOT(reject()));
86 // dlg.connect(helpBtn, SIGNAL(), SLOT());
87 
88  if(dlg.exec() == QDialog::Accepted)
89  return rsc->getSelectedResource();
90 
91  return "";
92 }
93 
95 {
96  m_fchooser->setResourceType((FileChooser::ResourceType)id);
97 }
void setResource(int id)
This is called when the user changes the type of resource to search.
QString getSelectedResource()
Returns the selected resource.
Defines a component for choose a file.
void setInitialPath(const QString &path)
This will open the dialog of file selection in the given path.
Definition: FileChooser.cpp:60
FileChooser * m_fchooser
File chooser component.
Defines a component for choose a file.
Definition: FileChooser.h:60
static QString getResource(const QString &initialPath, const QString &filter, QWidget *parent=0)
use the static when the ResourceChooser have to be presented as a Dialog.
ResourceType
Type of resource required.
Definition: FileChooser.h:69
Defines a component for choosing a file or directory.
ResourceChooser(QWidget *parent=0)
Constructor.
Defines a component for choosing a file or directory.
void setFilterPattern(const QString &filter)
Setts a pattern for filtering the searched files.