]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSendto.cpp
some remnaming
[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
15 #include "ControlSendto.h"
16 #include "qt_helpers.h"
17
18 #include "Format.h"
19
20 #include <QListWidget>
21 #include <QPushButton>
22 #include <QCloseEvent>
23
24 using std::vector;
25 using std::string;
26
27
28 namespace lyx {
29 namespace frontend {
30
31 GuiSendtoDialog::GuiSendtoDialog(LyXView & lv)
32         : GuiDialog(lv, "sendto")
33 {
34         setupUi(this);
35         setViewTitle(_("Send Document to Command"));
36         setController(new ControlSendto(*this));
37
38         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
39         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
40         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
41
42         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
43                 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
44         connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
45                 this, SLOT(slotFormatSelected(QListWidgetItem *)));
46         connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
47                 this, SLOT(changed_adaptor()));
48         connect(commandCO, SIGNAL(textChanged(const QString&)),
49                 this, SLOT(changed_adaptor()));
50
51         bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
52         bc().setOK(okPB);
53         bc().setApply(applyPB);
54         bc().setCancel(closePB);
55 }
56
57
58 ControlSendto & GuiSendtoDialog::controller()
59 {
60         return static_cast<ControlSendto &>(GuiDialog::controller());
61 }
62
63
64 void GuiSendtoDialog::changed_adaptor()
65 {
66         changed();
67 }
68
69
70 void GuiSendtoDialog::closeEvent(QCloseEvent * e)
71 {
72         slotClose();
73         e->accept();
74 }
75
76
77 void GuiSendtoDialog::updateContents()
78 {
79         all_formats_ = controller().allFormats();
80
81         // Check whether the current contents of the browser will be
82         // changed by loading the contents of formats
83         vector<string> keys;
84         keys.resize(all_formats_.size());
85
86         vector<string>::iterator result = keys.begin();
87         vector<Format const *>::const_iterator it  = all_formats_.begin();
88         vector<Format const *>::const_iterator end = all_formats_.end();
89         for (; it != end; ++it, ++result)
90                 *result = (*it)->prettyname();
91
92         // Reload the browser
93         formatLW->clear();
94
95         for (vector<string>::const_iterator it = keys.begin();
96              it != keys.end(); ++it) {
97                 formatLW->addItem(toqstr(*it));
98         }
99
100         commandCO->addItem(toqstr(controller().getCommand()));
101 }
102
103
104 void GuiSendtoDialog::applyView()
105 {
106         int const line = formatLW->currentRow();
107
108         if (line < 0 || line > int(formatLW->count()))
109                 return;
110
111         controller().setFormat(all_formats_[line]);
112         controller().setCommand(fromqstr(commandCO->currentText()));
113 }
114
115
116 bool GuiSendtoDialog::isValid()
117 {
118         int const line = formatLW->currentRow();
119
120         if (line < 0 || line > int(formatLW->count()))
121                 return false;
122
123         return formatLW->count() != 0 &&
124                 !commandCO->currentText().isEmpty();
125 }
126
127 } // namespace frontend
128 } // namespace lyx
129
130 #include "GuiSendto_moc.cpp"