]> git.lyx.org Git - lyx.git/blob - src/lyxled/LayoutEditor.cpp
Comment
[lyx.git] / src / lyxled / LayoutEditor.cpp
1
2 #include "LayoutEditor.h"
3
4 #include "ui_MainWindowUi.h"
5
6 #include <QDebug>
7 #include <QFile>
8 #include <QList>
9 #include <QStandardItem>
10 #include <QStandardItemModel>
11 #include <QString>
12 #include <QTreeView>
13
14
15 namespace lyx {
16
17 /////////////////////////////////////////////////////////////////////////
18 //
19 // LayoutTree
20 //
21 /////////////////////////////////////////////////////////////////////////
22
23 LayoutTree::LayoutTree(QWidget * parent) 
24         : QTreeView(parent)
25 {}
26
27
28 /////////////////////////////////////////////////////////////////////////
29 //
30 // LayoutEditor
31 //
32 /////////////////////////////////////////////////////////////////////////
33
34 LayoutEditor::LayoutEditor(QWidget * parent) 
35         : QWidget(parent)
36 {}
37
38
39 /////////////////////////////////////////////////////////////////////////
40 //
41 // MainWindow
42 //
43 /////////////////////////////////////////////////////////////////////////
44
45 MainWindow::MainWindow()
46 {
47         ui_ = new Ui::MainWindow;
48         ui_->setupUi(this);
49
50         model_ = new QStandardItemModel(this);
51         view_ = new LayoutTree(this);
52         view_->setModel(model_);
53         //setCentralWidget(view_);
54
55         ui_->dockLayoutTree->setWidget(view_);
56 }
57
58
59 MainWindow::~MainWindow()
60 {
61         delete ui_;
62 }
63
64 static bool isInsensitivelyEqual(QString const & s1, QString const & s2)
65 {
66         return s1.compare(s2, Qt::CaseInsensitive) == 0;
67 }
68
69 void MainWindow::loadLayoutFile(QString const & fileName)
70 {
71         loadLayoutFile(fileName, model_->invisibleRootItem());
72         view_->expandAll();
73 }
74
75
76 void MainWindow::loadLayoutFile(QString const & fileName,
77         QStandardItem * parent)
78 {
79         QFile file(fileName);
80 #if 0
81         file.open(QIODevice::ReadOnly);
82         QString contents = file.readAll();
83         file.close();
84         qDebug() << "contents: " << contents;
85 #endif
86
87         file.open(QIODevice::ReadOnly);
88
89         QTextStream ts(&file);
90         while (!ts.atEnd()) {
91                 QList<QStandardItem *> row;
92                 QString code;
93                 ts >> code;
94                 //qDebug() << "CODE: " << code;
95                 if (code.startsWith('#')) {
96                         QString line = code + ' ' + ts.readLine();
97                         //row.append(new QStandardItem("Comment"));
98                         //row.append(new QStandardItem(code + ' ' + ts.readLine()));
99                         //parent->appendRow(row);
100                 } else if (isInsensitivelyEqual(code, "Input")) {
101                         QString inputFile;
102                         ts >> inputFile;
103                         QStandardItem * item = new QStandardItem(inputFile);
104                         row.append(item);
105                         parent->appendRow(row);
106                         inputFile = fileName.left(fileName.lastIndexOf('/')) + '/' + inputFile;
107                         qDebug() << "INPUT: " << inputFile;
108                         loadLayoutFile(inputFile, item);
109                 } else if (isInsensitivelyEqual(code, "Style")) {
110                         QString style;
111                         ts >> style;
112                         //while (!ts.atEnd() && !isInsensitivelyEqual(code, "EndStyle"))
113                         //      ts >> code;
114                         QStandardItem * item = new QStandardItem(style);
115                         row.append(item);
116                         parent->appendRow(row);
117                 } else {
118                         //row.append(new QStandardItem(code));
119                         //parent->appendRow(row);
120                 }
121         }
122         
123         file.close();
124 }
125
126 } // namespace lyx
127
128 #include "LayoutEditor.h"
129
130 #include "ui_MainWindowUi.h"
131
132 #include <QDebug>
133 #include <QFile>
134 #include <QList>
135 #include <QStandardItem>
136 #include <QStandardItemModel>
137 #include <QString>
138 #include <QTreeView>
139
140
141 namespace lyx {
142
143 /////////////////////////////////////////////////////////////////////////
144 //
145 // LayoutTree
146 //
147 /////////////////////////////////////////////////////////////////////////
148
149 LayoutTree::LayoutTree(QWidget * parent) 
150         : QTreeView(parent)
151 {}
152
153
154 /////////////////////////////////////////////////////////////////////////
155 //
156 // LayoutEditor
157 //
158 /////////////////////////////////////////////////////////////////////////
159
160 LayoutEditor::LayoutEditor(QWidget * parent) 
161         : QWidget(parent)
162 {}
163
164
165 /////////////////////////////////////////////////////////////////////////
166 //
167 // MainWindow
168 //
169 /////////////////////////////////////////////////////////////////////////
170
171 MainWindow::MainWindow()
172 {
173         ui_ = new Ui::MainWindow;
174         ui_->setupUi(this);
175
176         model_ = new QStandardItemModel(this);
177         view_ = new LayoutTree(this);
178         view_->setModel(model_);
179         //setCentralWidget(view_);
180
181         ui_->dockLayoutTree->setWidget(view_);
182 }
183
184
185 MainWindow::~MainWindow()
186 {
187         delete ui_;
188 }
189
190 static bool isInsensitivelyEqual(QString const & s1, QString const & s2)
191 {
192         return s1.compare(s2, Qt::CaseInsensitive) == 0;
193 }
194
195 void MainWindow::loadLayoutFile(QString const & fileName)
196 {
197         loadLayoutFile(fileName, model_->invisibleRootItem());
198         view_->expandAll();
199 }
200
201
202 void MainWindow::loadLayoutFile(QString const & fileName,
203         QStandardItem * parent)
204 {
205         QFile file(fileName);
206 #if 0
207         file.open(QIODevice::ReadOnly);
208         QString contents = file.readAll();
209         file.close();
210         qDebug() << "contents: " << contents;
211 #endif
212
213         file.open(QIODevice::ReadOnly);
214
215         QTextStream ts(&file);
216         while (!ts.atEnd()) {
217                 QList<QStandardItem *> row;
218                 QString code;
219                 ts >> code;
220                 //qDebug() << "CODE: " << code;
221                 if (code.startsWith('#')) {
222                         QString line = code + ' ' + ts.readLine();
223                         //row.append(new QStandardItem("Comment"));
224                         //row.append(new QStandardItem(code + ' ' + ts.readLine()));
225                         //parent->appendRow(row);
226                 } else if (isInsensitivelyEqual(code, "Input")) {
227                         QString inputFile;
228                         ts >> inputFile;
229                         QStandardItem * item = new QStandardItem(inputFile);
230                         row.append(item);
231                         parent->appendRow(row);
232                         inputFile = fileName.left(fileName.lastIndexOf('/')) + '/' + inputFile;
233                         qDebug() << "INPUT: " << inputFile;
234                         loadLayoutFile(inputFile, item);
235                 } else if (isInsensitivelyEqual(code, "Style")) {
236                         QString style;
237                         ts >> style;
238                         //while (!ts.atEnd() && !isInsensitivelyEqual(code, "EndStyle"))
239                         //      ts >> code;
240                         QStandardItem * item = new QStandardItem(style);
241                         row.append(item);
242                         parent->appendRow(row);
243                 } else {
244                         //row.append(new QStandardItem(code));
245                         //parent->appendRow(row);
246                 }
247         }
248         
249         file.close();
250 }
251
252 } // namespace lyx