]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog_private.C
fix rbearing
[lyx.git] / src / frontends / qt2 / FileDialog_private.C
1 /**
2  * \file FileDialog_private.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10
11 #include "LString.h"
12 #include "support/lstrings.h"
13
14 #include <qapplication.h>
15 #include <qfiledialog.h>
16 #include <qtoolbutton.h> 
17
18 #include "QtLyXView.h"
19 #include "debug.h"
20 #include "funcrequest.h"
21
22 #include "FileDialog_private.h"
23
24 namespace {
25         /// return the Qt form of the label
26         string const getLabel(string const & str) {
27                 string label;
28                 string sc(split(str, label, '|'));
29                 if (sc.length() < 2)
30                         return label;
31                 string::size_type pos = label.find(sc[1]);
32                 if (pos == string::npos)
33                         return label;
34                 label.insert(pos, "&");
35                 return label;
36         }
37 }
38  
39 LyXFileDialog::LyXFileDialog(string const & p, string const & m, string const & t,
40                 FileDialog::Button const & b1, FileDialog::Button const & b2)
41         : QFileDialog(p.c_str(), m.c_str(), qApp->mainWidget(), t.c_str(), true),
42           b1_(0), b2_(0)
43 {
44         setCaption(t.c_str());
45
46         if (!b1.first.empty()) { 
47                 b1_dir_ = b1.second;
48                 b1_ = new QToolButton(this);
49                 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
50                 b1_->setText(getLabel(b1.first).c_str());
51                 addToolButton(b1_, true);
52         }
53
54         if (!b2.first.empty()) {
55                 b2_dir_ = b2.second;
56                 b2_ = new QToolButton(this);
57                 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
58                 b2_->setText(getLabel(b2.first).c_str());
59                 addToolButton(b2_);
60         }
61 }
62
63
64 void LyXFileDialog::buttonClicked()
65 {
66         if (sender() == b1_)
67                 setDir(b1_dir_.c_str());
68         else if (sender() == b2_)
69                 setDir(b2_dir_.c_str());
70 }