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.
8 * Full author contact details are available in file CREDITS.
13 #include "FileDialog_private.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;
32 /// return the Qt form of the label
33 docstring const getLabel(docstring const & ucs4str) {
35 string str = lyx::to_utf8(ucs4str);
37 string sc(split(str, label, '|'));
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);
50 LyXFileDialog::LyXFileDialog(docstring const & t,
52 lyx::support::FileFilterList const & filters,
53 FileDialog::Button const & b1,
54 FileDialog::Button const & b2)
55 // FIXME replace that with theApp->gui()->currentView()
56 : QFileDialog(qApp->focusWidget(),
57 toqstr(t), toqstr(p), toqstr(filters.as_string())),
60 setWindowTitle(toqstr(t));
62 QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
64 if (!b1.first.empty()) {
66 b1_ = new QToolButton(this);
67 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
68 b1_->setText(toqstr(getLabel(b1.first)));
69 layout.at(0)->addWidget(b1_);
72 if (!b2.first.empty()) {
74 b2_ = new QToolButton(this);
75 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
76 b2_->setText(toqstr(getLabel(b2.first)));
77 layout.at(0)->addWidget(b2_);
82 void LyXFileDialog::buttonClicked()
85 setDirectory(toqstr(b1_dir_));
86 else if (sender() == b2_)
87 setDirectory(toqstr(b2_dir_));
90 #include "FileDialog_private_moc.cpp"