From 1ae6ee263b9ef6f356760002f3f02197927a963b Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Thu, 24 Jun 2010 07:59:41 +0000 Subject: Theme Editor: Fixed some resource alias issues, implemented device configuration panel that loads options from a text file git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27102 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/gui/devicestate.cpp | 182 +++++++++++++++++++++++++++++++++- 1 file changed, 178 insertions(+), 4 deletions(-) (limited to 'utils/themeeditor/gui/devicestate.cpp') diff --git a/utils/themeeditor/gui/devicestate.cpp b/utils/themeeditor/gui/devicestate.cpp index af0b846..fb35e77 100644 --- a/utils/themeeditor/gui/devicestate.cpp +++ b/utils/themeeditor/gui/devicestate.cpp @@ -22,14 +22,188 @@ #include "devicestate.h" #include "ui_devicestate.h" +#include +#include +#include +#include +#include + DeviceState::DeviceState(QWidget *parent) : - QWidget(parent), - ui(new Ui::DeviceState) + QWidget(parent), tabs(this) { - ui->setupUi(this); + /* UI stuff */ + resize(500,400); + setWindowIcon(QIcon(":/resources/windowicon.png")); + setWindowTitle(tr("Device Settings")); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addWidget(&tabs); + this->setLayout(layout); + + /* Loading the tabs */ + QScrollArea* currentArea; + QHBoxLayout* subLayout; + QWidget* panel; + QWidget* temp; + + QFile fin(":/resources/deviceoptions"); + fin.open(QFile::Text | QFile::ReadOnly); + while(!fin.atEnd()) + { + QString line = QString(fin.readLine()); + line = line.trimmed(); + + /* Continue on a comment or an empty line */ + if(line[0] == '#' || line.length() == 0) + continue; + + if(line[0] == '[') + { + QString buffer; + for(int i = 1; line[i] != ']'; i++) + buffer.append(line[i]); + buffer = buffer.trimmed(); + + panel = new QWidget(); + currentArea = new QScrollArea(); + layout = new QVBoxLayout(panel); + currentArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + currentArea->setWidget(panel); + currentArea->setWidgetResizable(true); + + tabs.addTab(currentArea, buffer); + + continue; + } + + QStringList elements = line.split(";"); + QString tag = elements[0].trimmed(); + QString title = elements[1].trimmed(); + QString type = elements[2].trimmed(); + QString defVal = elements[3].trimmed(); + + subLayout = new QHBoxLayout(); + if(type != "check") + subLayout->addWidget(new QLabel(elements[1].trimmed(), currentArea)); + layout->addLayout(subLayout); + + + elements = type.split("("); + if(elements[0].trimmed() == "text") + { + temp = new QLineEdit(defVal, currentArea); + subLayout->addWidget(temp); + inputs.insert(tag, QPair(Text, temp)); + } + else if(elements[0].trimmed() == "check") + { + temp = new QCheckBox(title, currentArea); + subLayout->addWidget(temp); + if(defVal.toLower() == "true") + dynamic_cast(temp)->setChecked(true); + else + dynamic_cast(temp)->setChecked(false); + inputs.insert(tag, QPair(Check, temp)); + } + else if(elements[0].trimmed() == "slider") + { + elements = elements[1].trimmed().split(","); + int min = elements[0].trimmed().toInt(); + QString maxS = elements[1].trimmed(); + maxS.chop(1); + int max = maxS.toInt(); + + temp = new QSlider(Qt::Horizontal, currentArea); + dynamic_cast(temp)->setMinimum(min); + dynamic_cast(temp)->setMaximum(max); + dynamic_cast(temp)->setValue(defVal.toInt()); + subLayout->addWidget(temp); + inputs.insert(tag, QPair(Slide, temp)); + } + else if(elements[0].trimmed() == "spin") + { + elements = elements[1].trimmed().split(","); + int min = elements[0].trimmed().toInt(); + QString maxS = elements[1].trimmed(); + maxS.chop(1); + int max = maxS.toInt(); + + temp = new QSpinBox(currentArea); + dynamic_cast(temp)->setMinimum(min); + dynamic_cast(temp)->setMaximum(max); + dynamic_cast(temp)->setValue(defVal.toInt()); + subLayout->addWidget(temp); + inputs.insert(tag, QPair(Spin, temp)); + } + else if(elements[0].trimmed() == "fspin") + { + elements = elements[1].trimmed().split(","); + int min = elements[0].trimmed().toDouble(); + QString maxS = elements[1].trimmed(); + maxS.chop(1); + int max = maxS.toDouble(); + + temp = new QDoubleSpinBox(currentArea); + dynamic_cast(temp)->setMinimum(min); + dynamic_cast(temp)->setMaximum(max); + dynamic_cast(temp)->setValue(defVal.toDouble()); + dynamic_cast(temp)->setSingleStep(0.1); + subLayout->addWidget(temp); + inputs.insert(tag, QPair(DSpin, temp)); + } + else if(elements[0].trimmed() == "combo") + { + elements = elements[1].trimmed().split(","); + + int defIndex; + temp = new QComboBox(currentArea); + for(int i = 0; i < elements.count(); i++) + { + QString current = elements[i].trimmed(); + if(i == elements.count() - 1) + current.chop(1); + dynamic_cast(temp)->addItem(current, i); + if(current == defVal) + defIndex = i; + } + dynamic_cast(temp)->setCurrentIndex(defIndex); + subLayout->addWidget(temp); + inputs.insert(tag, QPair(Combo, temp)); + } + + } } DeviceState::~DeviceState() { - delete ui; +} + +QVariant DeviceState::data(QString tag) +{ + QPair found = + inputs.value(tag, QPair(Slide, 0)); + + if(found.second == 0) + return QVariant(); + + switch(found.first) + { + case Text: + return dynamic_cast(found.second)->text(); + + case Slide: + return dynamic_cast(found.second)->value(); + + case Spin: + return dynamic_cast(found.second)->value(); + + case DSpin: + return dynamic_cast(found.second)->value(); + + case Combo: + return dynamic_cast(found.second)->currentIndex(); + + case Check: + return dynamic_cast(found.second)->isChecked(); + } } -- cgit v1.1