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