]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/LyXFileDialog.cpp
PrefShortcuts: ShortcutEdit, adapted from Edwin's patch
[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 lyx::support::split;
25 using std::string;
26
27 namespace lyx {
28
29 /// return the Qt form of the label
30 static docstring const getLabel(docstring const & ucs4str)
31 {
32         // FIXME UNICODE
33         string str = to_utf8(ucs4str);
34         string label;
35         string sc = split(str, label, '|');
36         if (sc.length() < 2)
37                 return from_utf8(label);
38         string::size_type pos = label.find(sc[1]);
39         if (pos == string::npos)
40                 return from_utf8(label);
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 theApp->gui()->currentView()
52         : QFileDialog(qApp->focusWidget(),
53                       toqstr(t), toqstr(p), toqstr(filters.as_string())),
54                       b1_(0), b2_(0)
55 {
56         setWindowTitle(toqstr(t));
57
58         QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
59
60         if (!b1.first.empty()) {
61                 b1_dir_ = b1.second;
62                 b1_ = new QToolButton(this);
63                 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
64                 b1_->setText(toqstr(getLabel(b1.first)));
65                 layout.at(0)->addWidget(b1_);
66         }
67
68         if (!b2.first.empty()) {
69                 b2_dir_ = b2.second;
70                 b2_ = new QToolButton(this);
71                 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
72                 b2_->setText(toqstr(getLabel(b2.first)));
73                 layout.at(0)->addWidget(b2_);
74         }
75 }
76
77
78 void LyXFileDialog::buttonClicked()
79 {
80         if (sender() == b1_)
81                 setDirectory(toqstr(b1_dir_));
82         else if (sender() == b2_)
83                 setDirectory(toqstr(b2_dir_));
84 }
85
86 } // namespace lyx
87
88 #include "LyXFileDialog_moc.cpp"