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