]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/FileDialog_private.C
32eb8f3581981d852ba09ad866d961c44a0c969c
[lyx.git] / src / frontends / qt4 / FileDialog_private.C
1 /**
2  * \file FileDialog_private.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "FileDialog_private.h"
14 #include "qt_helpers.h"
15
16 #include "support/filefilterlist.h"
17 #include "support/lstrings.h"
18
19 #include <QApplication>
20 #include <QToolButton>
21 #include <QHBoxLayout>
22
23 using lyx::support::split;
24
25 using std::string;
26
27
28 namespace {
29
30 /// return the Qt form of the label
31 string const getLabel(string const & str) {
32         string label;
33         string sc(split(str, label, '|'));
34         if (sc.length() < 2)
35                 return label;
36         string::size_type pos = label.find(sc[1]);
37         if (pos == string::npos)
38                 return label;
39         label.insert(pos, 1, '&');
40         return label;
41 }
42
43 } // namespace anon
44
45
46 LyXFileDialog::LyXFileDialog(string const & t,
47                              string const & p,
48                              lyx::support::FileFilterList const & filters,
49                              FileDialog::Button const & b1,
50                              FileDialog::Button const & b2)
51         : QFileDialog(qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget(),
52                       toqstr(t), toqstr(p), toqstr(filters.as_string())),
53                       b1_(0), b2_(0)
54 {
55         setCaption(toqstr(t));
56
57         QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
58
59         if (!b1.first.empty()) {
60                 b1_dir_ = b1.second;
61                 b1_ = new QToolButton(this);
62                 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
63                 b1_->setText(toqstr(getLabel(b1.first)));
64                 layout.at(0)->addWidget(b1_);
65         }
66
67         if (!b2.first.empty()) {
68                 b2_dir_ = b2.second;
69                 b2_ = new QToolButton(this);
70                 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
71                 b2_->setText(toqstr(getLabel(b2.first)));
72                 layout.at(0)->addWidget(b2_);
73         }
74 }
75
76
77 void LyXFileDialog::buttonClicked()
78 {
79         if (sender() == b1_)
80                 setDir(toqstr(b1_dir_));
81         else if (sender() == b2_)
82                 setDir(toqstr(b2_dir_));
83 }
84
85 #include "FileDialog_private_moc.cpp"