diff options
| author | Robert Bieber <robby@bieberphoto.com> | 2010-07-15 21:39:09 +0000 |
|---|---|---|
| committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-15 21:39:09 +0000 |
| commit | c272144867f94dc7e99f8333bec5dd052878ecd8 (patch) | |
| tree | 6ceb4ce5111b05da666ab2c0a1fda571d84ccd42 /utils/themeeditor/gui | |
| parent | e700e195d88f09a94fe681fd2906564ade2be0d0 (diff) | |
| download | rockbox-c272144867f94dc7e99f8333bec5dd052878ecd8.zip rockbox-c272144867f94dc7e99f8333bec5dd052878ecd8.tar.gz rockbox-c272144867f94dc7e99f8333bec5dd052878ecd8.tar.bz2 rockbox-c272144867f94dc7e99f8333bec5dd052878ecd8.tar.xz | |
Theme Editor: Added New Project feature
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27439 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/gui')
| -rw-r--r-- | utils/themeeditor/gui/editorwindow.cpp | 192 | ||||
| -rw-r--r-- | utils/themeeditor/gui/editorwindow.h | 5 | ||||
| -rw-r--r-- | utils/themeeditor/gui/editorwindow.ui | 9 | ||||
| -rw-r--r-- | utils/themeeditor/gui/newprojectdialog.cpp | 105 | ||||
| -rw-r--r-- | utils/themeeditor/gui/newprojectdialog.h | 95 | ||||
| -rw-r--r-- | utils/themeeditor/gui/newprojectdialog.ui | 209 |
6 files changed, 575 insertions, 40 deletions
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp index 247109c..043c08b 100644 --- a/utils/themeeditor/gui/editorwindow.cpp +++ b/utils/themeeditor/gui/editorwindow.cpp @@ -24,12 +24,16 @@ #include "ui_editorwindow.h" #include "rbfontcache.h" #include "rbtextcache.h" +#include "newprojectdialog.h" #include <QDesktopWidget> #include <QFileSystemModel> #include <QSettings> #include <QFileDialog> +#include <QMessageBox> #include <QGraphicsScene> +#include <QDir> +#include <QFile> EditorWindow::EditorWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0) @@ -200,6 +204,8 @@ void EditorWindow::setupMenus() /* Connecting the document management actions */ QObject::connect(ui->actionNew_Document, SIGNAL(triggered()), this, SLOT(newTab())); + QObject::connect(ui->actionNew_Project, SIGNAL(triggered()), + this, SLOT(newProject())); QObject::connect(ui->actionToolbarNew, SIGNAL(triggered()), this, SLOT(newTab())); @@ -261,6 +267,93 @@ void EditorWindow::newTab() ui->editorTabs->setCurrentWidget(doc); } +void EditorWindow::newProject() +{ + NewProjectDialog dialog(this); + if(dialog.exec() == QDialog::Rejected) + return; + + /* Assembling the new project if the dialog was accepted */ + NewProjectDialog::NewProjectInfo info = dialog.results(); + + QDir path(info.path); + if(!path.exists()) + { + QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" + " Project directory does not exist")); + return; + } + + if(path.exists(info.name)) + { + QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" + " Project directory already exists")); + return; + } + + if(!path.mkdir(info.name)) + { + QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:" + " Project directory not writeable")); + return; + } + + path.cd(info.name); + + /* Making standard directories */ + path.mkdir("fonts"); + path.mkdir("icons"); + path.mkdir("backdrops"); + + /* Adding the desired wps documents */ + path.mkdir("wps"); + path.cd("wps"); + + if(info.sbs) + createFile(path.filePath(info.name + ".sbs"), tr("# SBS Document\n")); + if(info.wps) + createFile(path.filePath(info.name + ".wps"), tr("# WPS Document\n")); + if(info.fms) + createFile(path.filePath(info.name + ".fms"), tr("# FMS Document\n")); + if(info.rsbs) + createFile(path.filePath(info.name + ".rsbs"), tr("# RSBS Document\n")); + if(info.rwps) + createFile(path.filePath(info.name + ".rwps"), tr("# RWPS Document\n")); + if(info.rfms) + createFile(path.filePath(info.name + ".rfms"), tr("# RFMS Document\n")); + + path.mkdir(info.name); + + path.cdUp(); + + /* Adding the config file */ + path.mkdir("themes"); + path.cd("themes"); + + /* Generating the config file */ + QString config = tr("# Config file for ") + info.name + "\n"; + QString wpsBase = "/.rockbox/wps/"; + if(info.sbs) + config.append("sbs: " + wpsBase + info.name + ".sbs\n"); + if(info.wps) + config.append("wps: " + wpsBase + info.name + ".wps\n"); + if(info.fms) + config.append("fms: " + wpsBase + info.name + ".fms\n"); + if(info.rsbs) + config.append("rsbs: " + wpsBase + info.name + ".rsbs\n"); + if(info.rwps) + config.append("rwps: " + wpsBase + info.name + ".rwps\n"); + if(info.rfms) + config.append("rfms: " + wpsBase + info.name + ".rfms\n"); + + + createFile(path.filePath(info.name + ".cfg"), + config); + + /* Opening the new project */ + loadProjectFile(path.filePath(info.name + ".cfg")); +} + void EditorWindow::shiftTab(int index) { TabContent* widget = dynamic_cast<TabContent*> @@ -424,47 +517,8 @@ void EditorWindow::openProject() fileName = QFileDialog::getOpenFileName(this, tr("Open Project"), directory, ProjectModel::fileFilter()); - if(QFile::exists(fileName)) - { - - if(project) - project->deleteLater(); - - ui->actionClose_Project->setEnabled(true); - - project = new ProjectModel(fileName, this); - ui->projectTree->setModel(project); - - if(project->getSetting("#screenwidth") != "") - deviceConfig->setData("screenwidth", - project->getSetting("#screenwidth")); - if(project->getSetting("#screenheight") != "") - deviceConfig->setData("screenheight", - project->getSetting("#screenheight")); - - QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)), - project, SLOT(activated(QModelIndex))); - - fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1); - settings.setValue("defaultDirectory", fileName); - - for(int i = 0; i < ui->editorTabs->count(); i++) - { - TabContent* doc = dynamic_cast<TabContent*> - (ui->editorTabs->widget(i)); - if(doc->type() == TabContent::Skin) - { - dynamic_cast<SkinDocument*>(doc)->setProject(project); - if(i == ui->editorTabs->currentIndex()) - { - viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene()); - } - } - } - - } - settings.endGroup(); + loadProjectFile(fileName); } @@ -657,3 +711,61 @@ void EditorWindow::sizeColumns() ui->parseTree->resizeColumnToContents(ParseTreeModel::typeColumn); ui->parseTree->resizeColumnToContents(ParseTreeModel::valueColumn); } + +void EditorWindow::loadProjectFile(QString fileName) +{ + QSettings settings; + settings.beginGroup("ProjectModel"); + + if(QFile::exists(fileName)) + { + if(project) + project->deleteLater(); + + ui->actionClose_Project->setEnabled(true); + + project = new ProjectModel(fileName, this); + ui->projectTree->setModel(project); + + if(project->getSetting("#screenwidth") != "") + deviceConfig->setData("screenwidth", + project->getSetting("#screenwidth")); + if(project->getSetting("#screenheight") != "") + deviceConfig->setData("screenheight", + project->getSetting("#screenheight")); + + QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)), + project, SLOT(activated(QModelIndex))); + + fileName.chop(fileName.length() - fileName.lastIndexOf('/') - 1); + settings.setValue("defaultDirectory", fileName); + + for(int i = 0; i < ui->editorTabs->count(); i++) + { + TabContent* doc = dynamic_cast<TabContent*> + (ui->editorTabs->widget(i)); + if(doc->type() == TabContent::Skin) + { + dynamic_cast<SkinDocument*>(doc)->setProject(project); + if(i == ui->editorTabs->currentIndex()) + { + viewer->setScene(dynamic_cast<SkinDocument*>(doc)->scene()); + } + } + } + + } + + settings.endGroup(); + +} + +void EditorWindow::createFile(QString filename, QString contents) +{ + QFile fout(filename); + fout.open(QFile::WriteOnly); + + fout.write(contents.toAscii()); + + fout.close(); +} diff --git a/utils/themeeditor/gui/editorwindow.h b/utils/themeeditor/gui/editorwindow.h index 0178f60..5bfa795 100644 --- a/utils/themeeditor/gui/editorwindow.h +++ b/utils/themeeditor/gui/editorwindow.h @@ -64,6 +64,7 @@ public slots: private slots: void showPanel(); void newTab(); + void newProject(); void shiftTab(int index); bool closeTab(int index); void closeCurrent(); @@ -88,11 +89,15 @@ private: void saveSettings(); void setupUI(); void setupMenus(); + void addTab(TabContent* doc); void expandLine(ParseTreeModel* model, QModelIndex parent, int line, bool highlight); void sizeColumns(); + void loadProjectFile(QString fileName); + static void createFile(QString filename, QString contents); + Ui::EditorWindow *ui; PreferencesDialog* prefs; QLabel* parseStatus; diff --git a/utils/themeeditor/gui/editorwindow.ui b/utils/themeeditor/gui/editorwindow.ui index ab8dc61..a7246b9 100644 --- a/utils/themeeditor/gui/editorwindow.ui +++ b/utils/themeeditor/gui/editorwindow.ui @@ -48,6 +48,7 @@ <string>&File</string> </property> <addaction name="actionNew_Document"/> + <addaction name="actionNew_Project"/> <addaction name="actionOpen_Document"/> <addaction name="actionOpen_Project"/> <addaction name="separator"/> @@ -386,6 +387,14 @@ <string>Ctrl+Shift+W</string> </property> </action> + <action name="actionNew_Project"> + <property name="text"> + <string>N&ew Project</string> + </property> + <property name="shortcut"> + <string>Ctrl+Shift+N</string> + </property> + </action> </widget> <tabstops> <tabstop>projectTree</tabstop> diff --git a/utils/themeeditor/gui/newprojectdialog.cpp b/utils/themeeditor/gui/newprojectdialog.cpp new file mode 100644 index 0000000..50a8bc4 --- /dev/null +++ b/utils/themeeditor/gui/newprojectdialog.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "newprojectdialog.h" +#include "ui_newprojectdialog.h" + +#include <QSettings> +#include <QFileDialog> +#include <QDir> + +NewProjectDialog::NewProjectDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::NewProjectDialog) +{ + ui->setupUi(this); + + /* Getting the default directory from the application settings */ + QSettings settings; + settings.beginGroup("NewProjectDialog"); + + ui->locationBox->setText(settings.value("defaultDir", + QDir::home().absolutePath()) + .toString()); + + settings.endGroup(); + + /* Connecting the browse button */ + QObject::connect(ui->browseButton, SIGNAL(clicked()), + this, SLOT(browse())); +} + +NewProjectDialog::~NewProjectDialog() +{ + delete ui; +} + +void NewProjectDialog::accept() +{ + status.name = ui->nameBox->text(); + status.path = ui->locationBox->text(); + status.sbs = ui->sbsBox->isChecked(); + status.wps = ui->wpsBox->isChecked(); + status.fms = ui->fmsBox->isChecked(); + status.rsbs = ui->rsbsBox->isChecked(); + status.rwps = ui->rwpsBox->isChecked(); + status.rfms = ui->rfmsBox->isChecked(); + + QSettings settings; + settings.beginGroup("NewProjectDialog"); + + settings.setValue("defaultDir", ui->locationBox->text()); + + settings.endGroup(); + + QDialog::accept(); +} + +void NewProjectDialog::reject() +{ + ui->nameBox->setText(status.name); + ui->locationBox->setText(status.path); + ui->sbsBox->setChecked(status.sbs); + ui->wpsBox->setChecked(status.wps); + ui->fmsBox->setChecked(status.fms); + ui->rsbsBox->setChecked(status.rsbs); + ui->rwpsBox->setChecked(status.rwps); + ui->rfmsBox->setChecked(status.rfms); + + QSettings settings; + settings.beginGroup("NewProjectDialog"); + + ui->locationBox->setText(settings.value("defaultDir", + QDir::home().absolutePath()) + .toString()); + + settings.endGroup(); + + QDialog::reject(); +} + +void NewProjectDialog::browse() +{ + QString path; + path = QFileDialog::getExistingDirectory(this, "New Project Location", + ui->locationBox->text()); + ui->locationBox->setText(path); +} diff --git a/utils/themeeditor/gui/newprojectdialog.h b/utils/themeeditor/gui/newprojectdialog.h new file mode 100644 index 0000000..c59607c --- /dev/null +++ b/utils/themeeditor/gui/newprojectdialog.h @@ -0,0 +1,95 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef NEWPROJECTDIALOG_H +#define NEWPROJECTDIALOG_H + +#include <QDialog> + +namespace Ui { + class NewProjectDialog; +} + +class NewProjectDialog : public QDialog { + Q_OBJECT +public: + struct NewProjectInfo + { + QString name; + QString path; + bool sbs; + bool wps; + bool fms; + bool rsbs; + bool rwps; + bool rfms; + + NewProjectInfo() + { + name = ""; + path = ""; + sbs = true; + wps = true; + fms = false; + rsbs = false; + rwps = false; + rfms = false; + } + + NewProjectInfo(const NewProjectInfo& other) + { + operator=(other); + } + + const NewProjectInfo& operator=(const NewProjectInfo& other) + { + name = other.name; + path = other.path; + sbs = other.sbs; + wps = other.wps; + fms = other.fms; + rsbs = other.rsbs; + rwps = other.rwps; + rfms = other.rfms; + + return *this; + } + }; + + NewProjectDialog(QWidget *parent = 0); + virtual ~NewProjectDialog(); + + NewProjectInfo results(){ return status; } + +public slots: + void accept(); + void reject(); + +private slots: + void browse(); + +private: + Ui::NewProjectDialog *ui; + + NewProjectInfo status; +}; + +#endif // NEWPROJECTDIALOG_H diff --git a/utils/themeeditor/gui/newprojectdialog.ui b/utils/themeeditor/gui/newprojectdialog.ui new file mode 100644 index 0000000..f6e2dcc --- /dev/null +++ b/utils/themeeditor/gui/newprojectdialog.ui @@ -0,0 +1,209 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>NewProjectDialog</class> + <widget class="QDialog" name="NewProjectDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>275</height> + </rect> + </property> + <property name="windowTitle"> + <string>New Project</string> + </property> + <property name="windowIcon"> + <iconset resource="../resources.qrc"> + <normaloff>:/resources/windowicon.png</normaloff>:/resources/windowicon.png</iconset> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QFormLayout" name="formLayout_2"> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Name:</string> + </property> + <property name="buddy"> + <cstring>nameBox</cstring> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="nameBox"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Create In:</string> + </property> + <property name="buddy"> + <cstring>locationBox</cstring> + </property> + </widget> + </item> + <item row="1" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLineEdit" name="locationBox"/> + </item> + <item> + <widget class="QPushButton" name="browseButton"> + <property name="text"> + <string>Browse...</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Target:</string> + </property> + <property name="buddy"> + <cstring>comboBox</cstring> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QComboBox" name="comboBox"> + <item> + <property name="text"> + <string>Not Yet Available</string> + </property> + </item> + </widget> + </item> + <item row="4" column="0" colspan="2"> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Add Documents</string> + </property> + <property name="flat"> + <bool>false</bool> + </property> + <property name="checkable"> + <bool>false</bool> + </property> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::AllNonFixedFieldsGrow</enum> + </property> + <item row="0" column="0"> + <widget class="QCheckBox" name="sbsBox"> + <property name="text"> + <string>SBS</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QCheckBox" name="rsbsBox"> + <property name="text"> + <string>RSBS</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QCheckBox" name="wpsBox"> + <property name="text"> + <string>WPS</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QCheckBox" name="rwpsBox"> + <property name="text"> + <string>RWPS</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QCheckBox" name="fmsBox"> + <property name="text"> + <string>FMS</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QCheckBox" name="rfmsBox"> + <property name="text"> + <string>RFMS</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="3" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources> + <include location="../resources.qrc"/> + </resources> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>NewProjectDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>NewProjectDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> |