]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog_private.C
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / qt2 / 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
14 #include "FileDialog_private.h"
15 #include "qt_helpers.h"
16
17 #include "support/lstrings.h"
18
19 #include <qapplication.h>
20 #include <qtoolbutton.h>
21
22 using lyx::support::split;
23
24 using std::string;
25
26
27 namespace {
28
29 /// return the Qt form of the label
30 string const getLabel(string const & str) {
31         string label;
32         string sc(split(str, label, '|'));
33         if (sc.length() < 2)
34                 return label;
35         string::size_type pos = label.find(sc[1]);
36         if (pos == string::npos)
37                 return label;
38         label.insert(pos, 1, '&');
39         return label;
40 }
41
42 } // namespace anon
43
44
45 LyXFileDialog::LyXFileDialog(string const & p, string const & m,
46                              string const & t,
47                 FileDialog::Button const & b1, FileDialog::Button const & b2)
48         : QFileDialog(toqstr(p), toqstr(m),
49                       qApp->focusWidget() ? qApp->focusWidget() : qApp->mainWidget(), toqstr(t), true),
50           b1_(0), b2_(0)
51 {
52         setCaption(toqstr(t));
53
54         if (!b1.first.empty()) {
55                 b1_dir_ = b1.second;
56                 b1_ = new QToolButton(this);
57                 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
58                 b1_->setText(toqstr(getLabel(b1.first)));
59                 addToolButton(b1_, true);
60         }
61
62         if (!b2.first.empty()) {
63                 b2_dir_ = b2.second;
64                 b2_ = new QToolButton(this);
65                 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
66                 b2_->setText(toqstr(getLabel(b2.first)));
67                 addToolButton(b2_);
68         }
69 }
70
71
72 void LyXFileDialog::buttonClicked()
73 {
74         if (sender() == b1_)
75                 setDir(toqstr(b1_dir_));
76         else if (sender() == b2_)
77                 setDir(toqstr(b2_dir_));
78 }