]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QTexinfo.C
96cb02b35bbaa168a77f042f948c20b6f34ca005
[lyx.git] / src / frontends / qt4 / QTexinfo.C
1 /**
2  * \file QTexinfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QTexinfo.h"
14 #include "Qt2BC.h"
15 #include "qt_helpers.h"
16
17 #include "support/filetools.h"
18
19 #include <QCheckBox>
20 #include <QListWidget>
21 #include <QPushButton>
22
23 using std::string;
24 using std::vector;
25
26 namespace lyx {
27 namespace frontend {
28
29 /////////////////////////////////////////////////////////////////////
30 //
31 // QTexinfoDialog
32 //
33 /////////////////////////////////////////////////////////////////////
34
35
36 QTexinfoDialog::QTexinfoDialog(QTexinfo * form)
37         : form_(form)
38 {
39         setupUi(this);
40
41         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
42
43         connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
44         connect(whatStyleCO, SIGNAL(activated(const QString &)),
45                 this, SLOT(enableViewPB()));
46         connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(update()));
47         connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(update()));
48         connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
49         connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
50         connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
51                 this, SLOT( enableViewPB() ) );
52         connect(fileListLW, SIGNAL(itemSelectionChanged()),
53                 this, SLOT(enableViewPB()));
54 }
55
56
57 void QTexinfoDialog::change_adaptor()
58 {
59         form_->changed();
60 }
61
62
63 void QTexinfoDialog::closeEvent(QCloseEvent * e)
64 {
65         form_->slotWMHide();
66         e->accept();
67 }
68
69
70 void QTexinfoDialog::rescanClicked()
71 {
72         // build new *Files.lst
73         rescanTexStyles();
74         form_->updateStyles();
75         enableViewPB();
76 }
77
78
79 void QTexinfoDialog::viewClicked()
80 {
81         vector<string>::size_type const fitem = fileListLW->currentRow();
82         vector<string> const & data = form_->texdata_[form_->activeStyle];
83         string file = data[fitem];
84         if (!pathCB->isChecked())
85                 file = getTexFileFromList(data[fitem],
86                         form_->controller().getFileType(form_->activeStyle));
87         form_->controller().viewFile(file);
88 }
89
90
91 void QTexinfoDialog::update()
92 {
93         switch (whatStyleCO->currentIndex()) {
94         case 0:
95                 form_->updateStyles(ControlTexinfo::cls);
96                 break;
97         case 1:
98                 form_->updateStyles(ControlTexinfo::sty);
99                 break;
100         case 2:
101                 form_->updateStyles(ControlTexinfo::bst);
102                 break;
103         default:
104                 break;
105         }
106
107         enableViewPB();
108 }
109
110
111 void QTexinfoDialog::enableViewPB()
112 {
113         viewPB->setEnabled(fileListLW->currentRow() > -1);
114 }
115
116
117
118 /////////////////////////////////////////////////////////////////////
119 //
120 // QTexinfo
121 //
122 /////////////////////////////////////////////////////////////////////
123
124 typedef QController<ControlTexinfo, QView<QTexinfoDialog> > texinfo_base_class;
125
126 QTexinfo::QTexinfo(Dialog & parent)
127         : texinfo_base_class(parent, _("TeX Information")),
128           warningPosted(false), activeStyle(ControlTexinfo::cls)
129 {
130 }
131
132
133 void QTexinfo::build_dialog()
134 {
135         dialog_.reset(new QTexinfoDialog(this));
136
137         updateStyles(ControlTexinfo::cls);
138
139         bcview().setCancel(dialog_->closePB);
140 }
141
142
143 void QTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
144 {
145         ContentsType & data = texdata_[whichStyle];
146         bool const withFullPath = dialog_->pathCB->isChecked();
147
148         getTexFileList(whichStyle, data, withFullPath);
149
150         dialog_->fileListLW->clear();
151         ContentsType::const_iterator it  = data.begin();
152         ContentsType::const_iterator end = data.end();
153         for (; it != end; ++it)
154                 dialog_->fileListLW->addItem(toqstr(*it));
155
156         activeStyle = whichStyle;
157 }
158
159
160 void QTexinfo::updateStyles()
161 {
162         updateStyles(activeStyle);
163 }
164
165 } // namespace frontend
166 } // namespace lyx
167
168
169 #include "QTexinfo_moc.cpp"