]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QListings.cpp
InsetListings: touch up the include dialog
[lyx.git] / src / frontends / qt4 / QListings.cpp
1 /**
2  * \file QListings.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Bo Peng
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QListings.h"
14 #include "Qt2BC.h"
15 #include "qt_helpers.h"
16 #include "controllers/ControlListings.h"
17 #include "insets/InsetListingsParams.h"
18 #include "debug.h"
19
20 #include "support/convert.h"
21 #include "support/lstrings.h"
22
23 #include <QLineEdit>
24 #include <QCloseEvent>
25 #include <QPushButton>
26
27
28 using std::string;
29
30 namespace lyx {
31 namespace frontend {
32
33 /////////////////////////////////////////////////////////////////////
34 //
35 // QListingsDialog
36 //
37 /////////////////////////////////////////////////////////////////////
38
39
40 QListingsDialog::QListingsDialog(QListings * form)
41         : form_(form)
42 {
43         setupUi(this);
44         
45         connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
46         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
47         connect(inlineCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
48         connect(listingsED,  SIGNAL(textChanged()), this, SLOT(change_adaptor()));
49         connect(listingsED,  SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
50 }
51
52
53 void QListingsDialog::closeEvent(QCloseEvent * e)
54 {
55         form_->slotWMHide();
56         e->accept();
57 }
58
59
60 void QListingsDialog::change_adaptor()
61 {
62         form_->changed();
63 }
64
65
66 void QListingsDialog::validate_listings_params()
67 {
68         static bool isOK = true;
69         try {
70                 InsetListingsParams par(fromqstr(listingsED->toPlainText()));
71                 if (!isOK) {
72                         isOK = true;
73                         // listingsTB->setTextColor("black");
74                         listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
75                         okPB->setEnabled(true);
76                 }
77         } catch (invalidParam & e) {
78                 isOK = false;
79                 // listingsTB->setTextColor("red");
80                 listingsTB->setPlainText(e.what());
81                 okPB->setEnabled(false);
82         }
83 }
84
85 /////////////////////////////////////////////////////////////////////
86 //
87 // QListings
88 //
89 /////////////////////////////////////////////////////////////////////
90
91 typedef QController<ControlListings, QView<QListingsDialog> > listings_wrap_base_class;
92
93 QListings::QListings(Dialog & parent)
94         : listings_wrap_base_class(parent, _("Program Listings Settings"))
95 {
96 }
97
98
99 void QListings::build_dialog()
100 {
101         dialog_.reset(new QListingsDialog(this));
102         
103         bcview().setOK(dialog_->okPB);
104         bcview().setCancel(dialog_->closePB);
105         dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
106
107         update_contents();
108 }
109
110
111 /// not used right now.
112 void QListings::apply()
113 {
114         InsetListingsParams & params = controller().params();
115         params.setInline(dialog_->inlineCB->isChecked());
116         params.setParams(fromqstr(dialog_->listingsED->toPlainText()));
117         controller().setParams(params);
118 }
119
120
121 void QListings::update_contents()
122 {
123         InsetListingsParams & params = controller().params();
124         dialog_->listingsED->setPlainText(toqstr(params.separatedParams()));
125         
126         if (params.isInline())
127                 dialog_->inlineCB->setChecked(true);
128         else
129                 dialog_->inlineCB->setChecked(false);
130 }
131
132
133 } // namespace frontend
134 } // namespace lyx
135
136
137 #include "QListings_moc.cpp"