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