2 * \file LyXFileDialog.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "LyXFileDialog.h"
15 #include "qt_helpers.h"
17 #include "support/FileFilterList.h"
18 #include "support/lstrings.h"
20 #include <QApplication>
21 #include <QToolButton>
22 #include <QHBoxLayout>
24 using lyx::support::split;
29 /// return the Qt form of the label
30 static docstring const getLabel(docstring const & ucs4str) {
32 string str = to_utf8(ucs4str);
34 string sc(split(str, label, '|'));
36 return from_utf8(label);
37 string::size_type pos = label.find(sc[1]);
38 if (pos == string::npos)
39 return from_utf8(label);
40 label.insert(pos, 1, '&');
41 return from_utf8(label);
45 LyXFileDialog::LyXFileDialog(docstring const & t,
47 support::FileFilterList const & filters,
48 FileDialog::Button const & b1,
49 FileDialog::Button const & b2)
50 // FIXME replace that with theApp->gui()->currentView()
51 : QFileDialog(qApp->focusWidget(),
52 toqstr(t), toqstr(p), toqstr(filters.as_string())),
55 setWindowTitle(toqstr(t));
57 QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
59 if (!b1.first.empty()) {
61 b1_ = new QToolButton(this);
62 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
63 b1_->setText(toqstr(getLabel(b1.first)));
64 layout.at(0)->addWidget(b1_);
67 if (!b2.first.empty()) {
69 b2_ = new QToolButton(this);
70 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
71 b2_->setText(toqstr(getLabel(b2.first)));
72 layout.at(0)->addWidget(b2_);
77 void LyXFileDialog::buttonClicked()
80 setDirectory(toqstr(b1_dir_));
81 else if (sender() == b2_)
82 setDirectory(toqstr(b2_dir_));
87 #include "LyXFileDialog_moc.cpp"