diff options
Diffstat (limited to 'utils/themeeditor/gui/editorwindow.cpp')
-rw-r--r-- | utils/themeeditor/gui/editorwindow.cpp | 192 |
1 files changed, 152 insertions, 40 deletions
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp index 247109cc19..043c08badd 100644 --- a/utils/themeeditor/gui/editorwindow.cpp +++ b/utils/themeeditor/gui/editorwindow.cpp | |||
@@ -24,12 +24,16 @@ | |||
24 | #include "ui_editorwindow.h" | 24 | #include "ui_editorwindow.h" |
25 | #include "rbfontcache.h" | 25 | #include "rbfontcache.h" |
26 | #include "rbtextcache.h" | 26 | #include "rbtextcache.h" |
27 | #include "newprojectdialog.h" | ||
27 | 28 | ||
28 | #include <QDesktopWidget> | 29 | #include <QDesktopWidget> |
29 | #include <QFileSystemModel> | 30 | #include <QFileSystemModel> |
30 | #include <QSettings> | 31 | #include <QSettings> |
31 | #include <QFileDialog> | 32 | #include <QFileDialog> |
33 | #include <QMessageBox> | ||
32 | #include <QGraphicsScene> | 34 | #include <QGraphicsScene> |
35 | #include <QDir> | ||
36 | #include <QFile> | ||
33 | 37 | ||
34 | EditorWindow::EditorWindow(QWidget *parent) : | 38 | EditorWindow::EditorWindow(QWidget *parent) : |
35 | QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0) | 39 | QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0) |
@@ -200,6 +204,8 @@ void EditorWindow::setupMenus() | |||
200 | /* Connecting the document management actions */ | 204 | /* Connecting the document management actions */ |
201 | QObject::connect(ui->actionNew_Document, SIGNAL(triggered()), | 205 | QObject::connect(ui->actionNew_Document, SIGNAL(triggered()), |
202 | this, SLOT(newTab())); | 206 | this, SLOT(newTab())); |
207 | QObject::connect(ui->actionNew_Project, SIGNAL(triggered()), | ||
208 | this, SLOT(newProject())); | ||
203 | QObject::connect(ui->actionToolbarNew, SIGNAL(triggered()), | 209 | QObject::connect(ui->actionToolbarNew, SIGNAL(triggered()), |
204 | this, SLOT(newTab())); | 210 | this, SLOT(newTab())); |
205 | 211 | ||
@@ -261,6 +267,93 @@ void EditorWindow::newTab() | |||
261 | ui->editorTabs->setCurrentWidget(doc); | 267 | ui->editorTabs->setCurrentWidget(doc); |
262 | } | 268 | } |
263 | 269 | ||
270 | void EditorWindow::newProject() | ||
271 | { | ||
272 | NewProjectDialog dialog(this); | ||
273 | if(dialog.exec() == QDialog::Rejected) | ||
274 | return; | ||
275 | |||
276 | /* Assembling the new project if the dialog was accepted */ | ||
277 | NewProjectDialog::NewProjectInfo info = dialog.results(); | ||
278 | |||
279 | QDir path(info.path); | ||
280 | if(!path.exists()) | ||
281 | { | ||
282 | QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" | ||
283 | " Project directory does not exist")); | ||
284 | return; | ||
285 | } | ||
286 | |||
287 | if(path.exists(info.name)) | ||
288 | { | ||
289 | QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" | ||
290 | " Project directory already exists")); | ||
291 | return; | ||
292 | } | ||
293 | |||
294 | if(!path.mkdir(info.name)) | ||
295 | { | ||
296 | QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" | ||
297 | " Project directory not writeable")); | ||
298 | return; | ||
299 | } | ||
300 | |||
301 | path.cd(info.name); | ||
302 | |||
303 | /* Making standard directories */ | ||
304 | path.mkdir("fonts"); | ||
305 | path.mkdir("icons"); | ||
306 | path.mkdir("backdrops"); | ||
307 | |||
308 | /* Adding the desired wps documents */ | ||
309 | path.mkdir("wps"); | ||
310 | path.cd("wps"); | ||
311 | |||
312 | if(info.sbs) | ||
313 | createFile(path.filePath(info.name + ".sbs"), tr("# SBS Document\n")); | ||
314 | if(info.wps) | ||
315 | createFile(path.filePath(info.name + ".wps"), tr("# WPS Document\n")); | ||
316 | if(info.fms) | ||
317 | createFile(path.filePath(info.name + ".fms"), tr("# FMS Document\n")); | ||
318 | if(info.rsbs) | ||
319 | createFile(path.filePath(info.name + ".rsbs"), tr("# RSBS Document\n")); | ||
320 | if(info.rwps) | ||
321 | createFile(path.filePath(info.name + ".rwps"), tr("# RWPS Document\n")); | ||
322 | if(info.rfms) | ||
323 | createFile(path.filePath(info.name + ".rfms"), tr("# RFMS Document\n")); | ||
324 | |||
325 | path.mkdir(info.name); | ||
326 | |||
327 | path.cdUp(); | ||
328 | |||
329 | /* Adding the config file */ | ||
330 | path.mkdir("themes"); | ||
331 | path.cd("themes"); | ||
332 | |||
333 | /* Generating the config file */ | ||
334 | QString config = tr("# Config file for ") + info.name + "\n"; | ||
335 | QString wpsBase = "/.rockbox/wps/"; | ||
336 | if(info.sbs) | ||
337 | config.append("sbs: " + wpsBase + info.name + ".sbs\n"); | ||
338 | if(info.wps) | ||
339 | config.append("wps: " + wpsBase + info.name + ".wps\n"); | ||
340 | if(info.fms) | ||
341 | config.append("fms: " + wpsBase + info.name + ".fms\n"); | ||
342 | if(info.rsbs) | ||
343 | config.append("rsbs: " + wpsBase + info.name + ".rsbs\n"); | ||
344 | if(info.rwps) | ||
345 | config.append("rwps: " + wpsBase + info.name + ".rwps\n"); | ||
346 | if(info.rfms) | ||
347 | config.append("rfms: " + wpsBase + info.name + ".rfms\n"); | ||
348 | |||
349 | |||
350 | createFile(path.filePath(info.name + ".cfg"), | ||
351 | config); | ||
352 | |||
353 | /* Opening the new project */ | ||
354 | loadProjectFile(path.filePath(info.name + ".cfg")); | ||
355 | } | ||
356 | |||
264 | void EditorWindow::shiftTab(int index) | 357 | void EditorWindow::shiftTab(int index) |
265 | { | 358 | { |
266 | TabContent* widget = dynamic_cast<TabContent*> | 359 | TabContent* widget = dynamic_cast<TabContent*> |
@@ -424,47 +517,8 @@ void EditorWindow::openProject() | |||
424 | fileName = QFileDialog::getOpenFileName(this, tr("Open Project"), directory, | 517 | fileName = QFileDialog::getOpenFileName(this, tr("Open Project"), directory, |
425 | ProjectModel::fileFilter()); | 518 | ProjectModel::fileFilter()); |
426 | 519 | ||
427 | if(QFile::exists(fileName)) | ||
428 | { | ||
429 | |||
430 | if(project) | ||
431 | project->deleteLater(); | ||
432 | |||
433 | ui->actionClose_Project->setEnabled(true); | ||
434 | |||
435 | project = new ProjectModel(fileName, this); | ||
436 | ui->projectTree->setModel(project); | ||
437 | |||
438 | if(project->getSetting("#screenwidth") != "") | ||
439 | deviceConfig->setData("screenwidth", | ||
440 | project->getSetting("#screenwidth")); | ||
441 | if(project->getSetting("#screenheight") != "") | ||
442 | deviceConfig->setData("screenheight", | ||
443 | project->getSetting("#screenheight")); | ||
444 | |||
445 | QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)), | ||
446 | project, SLOT(activated(QModelIndex))); | ||
447 | |||
448 | fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1); | ||
449 | settings.setValue("defaultDirectory", fileName); | ||
450 | |||
451 | for(int i = 0; i < ui->editorTabs->count(); i++) | ||
452 | { | ||
453 | TabContent* doc = dynamic_cast<TabContent*> | ||
454 | (ui->editorTabs->widget(i)); | ||
455 | if(doc->type() == TabContent::Skin) | ||
456 | { | ||
457 | dynamic_cast<SkinDocument*>(doc)->setProject(project); | ||
458 | if(i == ui->editorTabs->currentIndex()) | ||
459 | { | ||
460 | viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene()); | ||
461 | } | ||
462 | } | ||
463 | } | ||
464 | |||
465 | } | ||
466 | |||
467 | settings.endGroup(); | 520 | settings.endGroup(); |
521 | loadProjectFile(fileName); | ||
468 | 522 | ||
469 | } | 523 | } |
470 | 524 | ||
@@ -657,3 +711,61 @@ void EditorWindow::sizeColumns() | |||
657 | ui->parseTree->resizeColumnToContents(ParseTreeModel::typeColumn); | 711 | ui->parseTree->resizeColumnToContents(ParseTreeModel::typeColumn); |
658 | ui->parseTree->resizeColumnToContents(ParseTreeModel::valueColumn); | 712 | ui->parseTree->resizeColumnToContents(ParseTreeModel::valueColumn); |
659 | } | 713 | } |
714 | |||
715 | void EditorWindow::loadProjectFile(QString fileName) | ||
716 | { | ||
717 | QSettings settings; | ||
718 | settings.beginGroup("ProjectModel"); | ||
719 | |||
720 | if(QFile::exists(fileName)) | ||
721 | { | ||
722 | if(project) | ||
723 | project->deleteLater(); | ||
724 | |||
725 | ui->actionClose_Project->setEnabled(true); | ||
726 | |||
727 | project = new ProjectModel(fileName, this); | ||
728 | ui->projectTree->setModel(project); | ||
729 | |||
730 | if(project->getSetting("#screenwidth") != "") | ||
731 | deviceConfig->setData("screenwidth", | ||
732 | project->getSetting("#screenwidth")); | ||
733 | if(project->getSetting("#screenheight") != "") | ||
734 | deviceConfig->setData("screenheight", | ||
735 | project->getSetting("#screenheight")); | ||
736 | |||
737 | QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)), | ||
738 | project, SLOT(activated(QModelIndex))); | ||
739 | |||
740 | fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1); | ||
741 | settings.setValue("defaultDirectory", fileName); | ||
742 | |||
743 | for(int i = 0; i < ui->editorTabs->count(); i++) | ||
744 | { | ||
745 | TabContent* doc = dynamic_cast<TabContent*> | ||
746 | (ui->editorTabs->widget(i)); | ||
747 | if(doc->type() == TabContent::Skin) | ||
748 | { | ||
749 | dynamic_cast<SkinDocument*>(doc)->setProject(project); | ||
750 | if(i == ui->editorTabs->currentIndex()) | ||
751 | { | ||
752 | viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene()); | ||
753 | } | ||
754 | } | ||
755 | } | ||
756 | |||
757 | } | ||
758 | |||
759 | settings.endGroup(); | ||
760 | |||
761 | } | ||
762 | |||
763 | void EditorWindow::createFile(QString filename, QString contents) | ||
764 | { | ||
765 | QFile fout(filename); | ||
766 | fout.open(QFile::WriteOnly); | ||
767 | |||
768 | fout.write(contents.toAscii()); | ||
769 | |||
770 | fout.close(); | ||
771 | } | ||