]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSendto.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / QSendto.C
1 /**
2  * \file QSendto.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QSendto.h"
14 #include "QSendtoDialog.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "format.h"
19
20 #include "controllers/ControlSendto.h"
21
22 #include <QListWidget>
23 #include <QPushButton>
24
25 using std::vector;
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 typedef QController<ControlSendto, QView<QSendtoDialog> > base_class;
32
33
34 QSendto::QSendto(Dialog & parent)
35         : base_class(parent, lyx::to_utf8(_("Send Document to Command")))
36 {
37 }
38
39
40 void QSendto::build_dialog()
41 {
42         dialog_.reset(new QSendtoDialog(this));
43
44         // Manage the ok, apply, restore and cancel/close buttons
45         bcview().setOK(dialog_->okPB);
46         bcview().setApply(dialog_->applyPB);
47         bcview().setCancel(dialog_->closePB);
48 }
49
50
51 void QSendto::update_contents()
52 {
53         all_formats_ = controller().allFormats();
54
55         // Check whether the current contents of the browser will be
56         // changed by loading the contents of formats
57         vector<string> keys;
58         keys.resize(all_formats_.size());
59
60         vector<string>::iterator result = keys.begin();
61         vector<Format const *>::const_iterator it  = all_formats_.begin();
62         vector<Format const *>::const_iterator end = all_formats_.end();
63         for (; it != end; ++it, ++result) {
64                 *result = (*it)->prettyname();
65         }
66
67         // Reload the browser
68         dialog_->formatLW->clear();
69
70         for (vector<string>::const_iterator it = keys.begin();
71              it < keys.end(); ++it) {
72                 dialog_->formatLW->addItem(toqstr(*it));
73         }
74
75         dialog_->commandCO->addItem(toqstr(controller().getCommand()));
76 }
77
78
79 void QSendto::apply()
80 {
81         int const line(dialog_->formatLW->currentRow());
82
83         if (line < 0 || line > int(dialog_->formatLW->count()))
84                 return;
85
86         string const cmd(fromqstr(dialog_->commandCO->currentText()));
87
88         controller().setFormat(all_formats_[line]);
89         controller().setCommand(cmd);
90 }
91
92
93 bool QSendto::isValid()
94 {
95         int const line(dialog_->formatLW->currentRow());
96
97         if (line < 0 || line > int(dialog_->formatLW->count()))
98                 return false;
99
100         else return dialog_->formatLW->count() != 0 &&
101                 !dialog_->commandCO->currentText().isEmpty();
102 }
103
104 } // namespace frontend
105 } // namespace lyx