summaryrefslogtreecommitdiff
path: root/utils/themeeditor/editorwindow.cpp
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-15 06:54:58 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-15 06:54:58 +0000
commit2e320f66f4f3c831dcfd232b33da0e6ab6dd7dd0 (patch)
treea6ef8001d797213e9dd81cd41c48f5065c33f3f0 /utils/themeeditor/editorwindow.cpp
parent1d4dc9b3b0f094a70463395138fc920e5107eabc (diff)
downloadrockbox-2e320f66f4f3c831dcfd232b33da0e6ab6dd7dd0.tar.gz
rockbox-2e320f66f4f3c831dcfd232b33da0e6ab6dd7dd0.zip
Theme Editor: Changed color to colour in preferences. Made parse tree viewer alternate line colors and auto-scroll/expand with cursor in editor window. Implemented TabContent abstract class so that more than just skin documents can be loaded in tabs. Made SkinDocument implement TabContent. Began implementing ConfigDocument for editing configuration files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26851 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/editorwindow.cpp')
-rw-r--r--utils/themeeditor/editorwindow.cpp94
1 files changed, 80 insertions, 14 deletions
diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp
index 93cf3641f0..3603b24af1 100644
--- a/utils/themeeditor/editorwindow.cpp
+++ b/utils/themeeditor/editorwindow.cpp
@@ -40,14 +40,14 @@ EditorWindow::EditorWindow(QWidget *parent) :
40 setupMenus(); 40 setupMenus();
41} 41}
42 42
43void EditorWindow::loadTabFromFile(QString fileName) 43void EditorWindow::loadTabFromSkinFile(QString fileName)
44{ 44{
45 /* Checking to see if the file is already open */ 45 /* Checking to see if the file is already open */
46 for(int i = 0; i < ui->editorTabs->count(); i++) 46 for(int i = 0; i < ui->editorTabs->count(); i++)
47 { 47 {
48 SkinDocument* current = dynamic_cast<SkinDocument*> 48 TabContent* current = dynamic_cast<TabContent*>
49 (ui->editorTabs->widget(i)); 49 (ui->editorTabs->widget(i));
50 if(current->getFile() == fileName) 50 if(current->file() == fileName)
51 { 51 {
52 ui->editorTabs->setCurrentIndex(i); 52 ui->editorTabs->setCurrentIndex(i);
53 return; 53 return;
@@ -61,6 +61,27 @@ void EditorWindow::loadTabFromFile(QString fileName)
61 61
62} 62}
63 63
64void EditorWindow::loadConfigTab(ConfigDocument* doc)
65{
66 for(int i = 0; i < ui->editorTabs->count(); i++)
67 {
68 TabContent* current = dynamic_cast<TabContent*>
69 (ui->editorTabs->widget(i));
70 if(current->file() == doc->file())
71 {
72 ui->editorTabs->setCurrentIndex(i);
73 doc->deleteLater();
74 return;
75 }
76 }
77
78 addTab(doc);
79 ui->editorTabs->setCurrentWidget(doc);
80
81 QObject::connect(doc, SIGNAL(titleChanged(QString)),
82 this, SLOT(tabTitleChanged(QString)));
83}
84
64void EditorWindow::loadSettings() 85void EditorWindow::loadSettings()
65{ 86{
66 87
@@ -153,16 +174,19 @@ void EditorWindow::setupMenus()
153 this, SLOT(openProject())); 174 this, SLOT(openProject()));
154} 175}
155 176
156void EditorWindow::addTab(SkinDocument *doc) 177void EditorWindow::addTab(TabContent *doc)
157{ 178{
158 ui->editorTabs->addTab(doc, doc->getTitle()); 179 ui->editorTabs->addTab(doc, doc->title());
159 180
160 /* Connecting to title change events */ 181 /* Connecting to title change events */
161 QObject::connect(doc, SIGNAL(titleChanged(QString)), 182 QObject::connect(doc, SIGNAL(titleChanged(QString)),
162 this, SLOT(tabTitleChanged(QString))); 183 this, SLOT(tabTitleChanged(QString)));
184 QObject::connect(doc, SIGNAL(lineChanged(int)),
185 this, SLOT(lineChanged(int)));
163 186
164 /* Connecting to settings change events */ 187 /* Connecting to settings change events */
165 doc->connectPrefs(prefs); 188 if(doc->type() == TabContent::Skin)
189 dynamic_cast<SkinDocument*>(doc)->connectPrefs(prefs);
166} 190}
167 191
168 192
@@ -175,7 +199,9 @@ void EditorWindow::newTab()
175 199
176void EditorWindow::shiftTab(int index) 200void EditorWindow::shiftTab(int index)
177{ 201{
178 if(index < 0) 202 TabContent* widget = dynamic_cast<TabContent*>
203 (ui->editorTabs->currentWidget());
204 if(index < 0 || widget->type() != TabContent::Skin)
179 { 205 {
180 ui->parseTree->setModel(0); 206 ui->parseTree->setModel(0);
181 ui->actionSave_Document->setEnabled(false); 207 ui->actionSave_Document->setEnabled(false);
@@ -187,8 +213,7 @@ void EditorWindow::shiftTab(int index)
187 else 213 else
188 { 214 {
189 /* Syncing the tree view and the status bar */ 215 /* Syncing the tree view and the status bar */
190 SkinDocument* doc = dynamic_cast<SkinDocument*> 216 SkinDocument* doc = dynamic_cast<SkinDocument*>(widget);
191 (ui->editorTabs->currentWidget());
192 ui->parseTree->setModel(doc->getModel()); 217 ui->parseTree->setModel(doc->getModel());
193 parseStatus->setText(doc->getStatus()); 218 parseStatus->setText(doc->getStatus());
194 219
@@ -197,12 +222,15 @@ void EditorWindow::shiftTab(int index)
197 ui->actionClose_Document->setEnabled(true); 222 ui->actionClose_Document->setEnabled(true);
198 ui->actionToolbarSave->setEnabled(true); 223 ui->actionToolbarSave->setEnabled(true);
199 ui->fromTree->setEnabled(true); 224 ui->fromTree->setEnabled(true);
225
226 sizeColumns();
227
200 } 228 }
201} 229}
202 230
203bool EditorWindow::closeTab(int index) 231bool EditorWindow::closeTab(int index)
204{ 232{
205 SkinDocument* widget = dynamic_cast<SkinDocument*> 233 TabContent* widget = dynamic_cast<TabContent*>
206 (ui->editorTabs->widget(index)); 234 (ui->editorTabs->widget(index));
207 if(widget->requestClose()) 235 if(widget->requestClose())
208 { 236 {
@@ -222,13 +250,13 @@ void EditorWindow::closeCurrent()
222void EditorWindow::saveCurrent() 250void EditorWindow::saveCurrent()
223{ 251{
224 if(ui->editorTabs->currentIndex() >= 0) 252 if(ui->editorTabs->currentIndex() >= 0)
225 dynamic_cast<SkinDocument*>(ui->editorTabs->currentWidget())->save(); 253 dynamic_cast<TabContent*>(ui->editorTabs->currentWidget())->save();
226} 254}
227 255
228void EditorWindow::saveCurrentAs() 256void EditorWindow::saveCurrentAs()
229{ 257{
230 if(ui->editorTabs->currentIndex() >= 0) 258 if(ui->editorTabs->currentIndex() >= 0)
231 dynamic_cast<SkinDocument*>(ui->editorTabs->currentWidget())->saveAs(); 259 dynamic_cast<TabContent*>(ui->editorTabs->currentWidget())->saveAs();
232} 260}
233 261
234void EditorWindow::openFile() 262void EditorWindow::openFile()
@@ -248,7 +276,7 @@ void EditorWindow::openFile()
248 276
249 QString current = fileNames[i]; 277 QString current = fileNames[i];
250 278
251 loadTabFromFile(current); 279 loadTabFromSkinFile(current);
252 280
253 /* And setting the new default directory */ 281 /* And setting the new default directory */
254 current.chop(current.length() - current.lastIndexOf('/') - 1); 282 current.chop(current.length() - current.lastIndexOf('/') - 1);
@@ -292,7 +320,7 @@ void EditorWindow::openProject()
292 320
293void EditorWindow::tabTitleChanged(QString title) 321void EditorWindow::tabTitleChanged(QString title)
294{ 322{
295 SkinDocument* sender = dynamic_cast<SkinDocument*>(QObject::sender()); 323 TabContent* sender = dynamic_cast<TabContent*>(QObject::sender());
296 ui->editorTabs->setTabText(ui->editorTabs->indexOf(sender), title); 324 ui->editorTabs->setTabText(ui->editorTabs->indexOf(sender), title);
297} 325}
298 326
@@ -334,6 +362,44 @@ void EditorWindow::updateCurrent()
334 (ui->editorTabs->currentWidget())->genCode(); 362 (ui->editorTabs->currentWidget())->genCode();
335} 363}
336 364
365void EditorWindow::lineChanged(int line)
366{
367 ui->parseTree->collapseAll();
368 ParseTreeModel* model = dynamic_cast<ParseTreeModel*>
369 (ui->parseTree->model());
370 expandLine(model, QModelIndex(), line);
371 sizeColumns();
372
373}
374
375void EditorWindow::expandLine(ParseTreeModel* model, QModelIndex parent,
376 int line)
377{
378 for(int i = 0; i < model->rowCount(parent); i++)
379 {
380 QModelIndex data = model->index(i, ParseTreeModel::lineColumn, parent);
381 QModelIndex recurse = model->index(i, 0, parent);
382
383 expandLine(model, recurse, line);
384
385 if(model->data(data, Qt::DisplayRole) == line)
386 {
387 ui->parseTree->expand(parent);
388 ui->parseTree->expand(data);
389 ui->parseTree->scrollTo(parent, QAbstractItemView::PositionAtTop);
390 }
391
392 }
393}
394
395void EditorWindow::sizeColumns()
396{
397 /* Setting the column widths */
398 ui->parseTree->resizeColumnToContents(ParseTreeModel::lineColumn);
399 ui->parseTree->resizeColumnToContents(ParseTreeModel::typeColumn);
400 ui->parseTree->resizeColumnToContents(ParseTreeModel::valueColumn);
401}
402
337EditorWindow::~EditorWindow() 403EditorWindow::~EditorWindow()
338{ 404{
339 delete ui; 405 delete ui;