]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/FileDialog_private.C
* Painter.h:
[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
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 lyx::docstring;
26
27 using std::string;
28
29
30 namespace {
31
32 /// return the Qt form of the label
33 docstring const getLabel(docstring const & ucs4str) {
34         // FIXME UNICODE
35         string str = lyx::to_utf8(ucs4str);
36         string label;
37         string sc(split(str, label, '|'));
38         if (sc.length() < 2)
39                 return lyx::from_utf8(label);
40         string::size_type pos = label.find(sc[1]);
41         if (pos == string::npos)
42                 return lyx::from_utf8(label);
43         label.insert(pos, 1, '&');
44         return lyx::from_utf8(label);
45 }
46
47 } // namespace anon
48
49
50 namespace lyx {
51
52 LyXFileDialog::LyXFileDialog(docstring const & t,
53                              docstring const & p,
54                              lyx::support::FileFilterList const & filters,
55                              FileDialog::Button const & b1,
56                              FileDialog::Button const & b2)
57                                  // FIXME replace that with theApp->gui()->currentView()
58         : QFileDialog(qApp->focusWidget(),
59                       toqstr(t), toqstr(p), toqstr(filters.as_string())),
60                       b1_(0), b2_(0)
61 {
62         setWindowTitle(toqstr(t));
63
64         QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
65
66         if (!b1.first.empty()) {
67                 b1_dir_ = b1.second;
68                 b1_ = new QToolButton(this);
69                 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
70                 b1_->setText(toqstr(getLabel(b1.first)));
71                 layout.at(0)->addWidget(b1_);
72         }
73
74         if (!b2.first.empty()) {
75                 b2_dir_ = b2.second;
76                 b2_ = new QToolButton(this);
77                 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
78                 b2_->setText(toqstr(getLabel(b2.first)));
79                 layout.at(0)->addWidget(b2_);
80         }
81 }
82
83
84 void LyXFileDialog::buttonClicked()
85 {
86         if (sender() == b1_)
87                 setDirectory(toqstr(b1_dir_));
88         else if (sender() == b2_)
89                 setDirectory(toqstr(b2_dir_));
90 }
91
92 } // namespace lyx
93
94 #include "FileDialog_private_moc.cpp"
95