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