]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/LyXFileDialog.cpp
'using namespace std' instead of 'using std::xxx'
[lyx.git] / src / frontends / qt4 / LyXFileDialog.cpp
1 /**
2  * \file LyXFileDialog.cpp
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 "LyXFileDialog.h"
14
15 #include "qt_helpers.h"
16
17 #include "support/FileFilterList.h"
18 #include "support/lstrings.h"
19
20 #include <QApplication>
21 #include <QToolButton>
22 #include <QHBoxLayout>
23
24 using namespace std;
25
26 namespace lyx {
27
28 using support::split;
29
30 /// return the Qt form of the label
31 static docstring const getLabel(docstring const & ucs4str)
32 {
33         // FIXME UNICODE
34         string str = to_utf8(ucs4str);
35         string label;
36         string sc = split(str, label, '|');
37         if (sc.length() < 2)
38                 return from_utf8(label);
39         size_t pos = label.find(sc[1]);
40         if (pos != string::npos)
41                 label.insert(pos, 1, '&');
42         return from_utf8(label);
43 }
44
45
46 LyXFileDialog::LyXFileDialog(docstring const & t,
47                              docstring const & p,
48                              support::FileFilterList const & filters,
49                              FileDialog::Button const & b1,
50                              FileDialog::Button const & b2)
51                                  // FIXME replace that with guiApp->currentView()
52         : QFileDialog(qApp->focusWidget(),
53                       toqstr(t), toqstr(p), toqstr(filters.as_string()))
54 {
55         setWindowTitle(toqstr(t));
56
57         QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
58
59         if (!b1.first.empty()) {
60                 b1_dir_ = b1.second;
61                 QToolButton * tb = new QToolButton(this);
62                 connect(tb, SIGNAL(clicked()), this, SLOT(button1Clicked()));
63                 tb->setText(toqstr(getLabel(b1.first)));
64                 layout.at(0)->addWidget(tb);
65         }
66
67         if (!b2.first.empty()) {
68                 b2_dir_ = b2.second;
69                 QToolButton * tb = new QToolButton(this);
70                 connect(tb, SIGNAL(clicked()), this, SLOT(button2Clicked()));
71                 tb->setText(toqstr(getLabel(b2.first)));
72                 layout.at(0)->addWidget(tb);
73         }
74 }
75
76
77 void LyXFileDialog::button1Clicked()
78 {
79         setDirectory(toqstr(b1_dir_));
80 }
81
82
83 void LyXFileDialog::button2Clicked()
84 {
85         setDirectory(toqstr(b2_dir_));
86 }
87
88 } // namespace lyx
89
90 #include "LyXFileDialog_moc.cpp"