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