]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSendto.cpp
Transfer Text::drawSelection() from InsetText::drawSelection() to InsetText::draw...
[lyx.git] / src / frontends / qt4 / QSendto.cpp
1 /**
2  * \file QSendto.cpp
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 "Qt2BC.h"
15 #include "qt_helpers.h"
16
17 #include "Format.h"
18
19 #include "controllers/ControlSendto.h"
20
21 #include <QListWidget>
22 #include <QPushButton>
23 #include <QCloseEvent>
24
25 using std::vector;
26 using std::string;
27
28
29 namespace lyx {
30 namespace frontend {
31
32 /////////////////////////////////////////////////////////////////////
33 //
34 // QSendtoDialog
35 //
36 /////////////////////////////////////////////////////////////////////
37
38 QSendtoDialog::QSendtoDialog(QSendto * form)
39         : form_(form)
40 {
41         setupUi(this);
42
43         connect(okPB, SIGNAL(clicked()),
44                 form, SLOT(slotOK()));
45         connect(applyPB, SIGNAL(clicked()),
46                 form, SLOT(slotApply()));
47         connect(closePB, SIGNAL(clicked()),
48                 form, SLOT(slotClose()));
49
50         connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ),
51                 this, SLOT( slotFormatHighlighted(QListWidgetItem *) ) );
52         connect( formatLW, SIGNAL( itemActivated(QListWidgetItem *) ),
53                 this, SLOT( slotFormatSelected(QListWidgetItem *) ) );
54         connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ),
55                 this, SLOT( changed_adaptor() ) );
56         connect( commandCO, SIGNAL( textChanged(const QString&) ),
57                 this, SLOT( changed_adaptor() ) );
58 }
59
60
61 void QSendtoDialog::changed_adaptor()
62 {
63         form_->changed();
64 }
65
66
67 void QSendtoDialog::closeEvent(QCloseEvent * e)
68 {
69         form_->slotWMHide();
70         e->accept();
71 }
72
73
74 /////////////////////////////////////////////////////////////////////
75 //
76 // QSendto
77 //
78 /////////////////////////////////////////////////////////////////////
79
80 typedef QController<ControlSendto, QView<QSendtoDialog> > SendtoBase;
81
82
83 QSendto::QSendto(Dialog & parent)
84         : SendtoBase(parent, _("Send Document to Command"))
85 {
86 }
87
88
89 void QSendto::build_dialog()
90 {
91         dialog_.reset(new QSendtoDialog(this));
92
93         // Manage the ok, apply, restore and cancel/close buttons
94         bcview().setOK(dialog_->okPB);
95         bcview().setApply(dialog_->applyPB);
96         bcview().setCancel(dialog_->closePB);
97 }
98
99
100 void QSendto::update_contents()
101 {
102         all_formats_ = controller().allFormats();
103
104         // Check whether the current contents of the browser will be
105         // changed by loading the contents of formats
106         vector<string> keys;
107         keys.resize(all_formats_.size());
108
109         vector<string>::iterator result = keys.begin();
110         vector<Format const *>::const_iterator it  = all_formats_.begin();
111         vector<Format const *>::const_iterator end = all_formats_.end();
112         for (; it != end; ++it, ++result) {
113                 *result = (*it)->prettyname();
114         }
115
116         // Reload the browser
117         dialog_->formatLW->clear();
118
119         for (vector<string>::const_iterator it = keys.begin();
120              it < keys.end(); ++it) {
121                 dialog_->formatLW->addItem(toqstr(*it));
122         }
123
124         dialog_->commandCO->addItem(toqstr(controller().getCommand()));
125 }
126
127
128 void QSendto::apply()
129 {
130         int const line(dialog_->formatLW->currentRow());
131
132         if (line < 0 || line > int(dialog_->formatLW->count()))
133                 return;
134
135         string const cmd(fromqstr(dialog_->commandCO->currentText()));
136
137         controller().setFormat(all_formats_[line]);
138         controller().setCommand(cmd);
139 }
140
141
142 bool QSendto::isValid()
143 {
144         int const line(dialog_->formatLW->currentRow());
145
146         if (line < 0 || line > int(dialog_->formatLW->count()))
147                 return false;
148
149         else return dialog_->formatLW->count() != 0 &&
150                 !dialog_->commandCO->currentText().isEmpty();
151 }
152
153 } // namespace frontend
154 } // namespace lyx
155
156 #include "QSendto_moc.cpp"