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