diff options
author | Treeki <treeki@gmail.com> | 2012-09-06 00:31:19 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-09-06 00:31:19 +0200 |
commit | 2e52bea24a65cf70380c4e13c2f9f1238f023e91 (patch) | |
tree | 771d4c0b74db52ebecde1af722714905a072b149 | |
parent | f928869357765e3a73501064408bb7bc0ee363ef (diff) | |
download | LayoutStudio-2e52bea24a65cf70380c4e13c2f9f1238f023e91.tar.gz LayoutStudio-2e52bea24a65cf70380c4e13c2f9f1238f023e91.zip |
some black magic involving templates which doesn't even work, pushing so I can work on it at home
-rw-r--r-- | LayoutStudio.pro | 6 | ||||
-rw-r--r-- | lsmaterialeditor.cpp | 23 | ||||
-rw-r--r-- | lsmaterialeditor.h | 13 | ||||
-rw-r--r-- | lsseteditor.cpp | 60 | ||||
-rw-r--r-- | lsseteditor.h | 148 |
5 files changed, 244 insertions, 6 deletions
diff --git a/LayoutStudio.pro b/LayoutStudio.pro index e4c57c6..2c937a3 100644 --- a/LayoutStudio.pro +++ b/LayoutStudio.pro @@ -43,7 +43,8 @@ SOURCES += main.cpp \ lstexcoordseteditor.cpp \ lsmaterialeditor.cpp \ lscolorpicker.cpp \ - lsmaterialmodel.cpp + lsmaterialmodel.cpp \ + lsseteditor.cpp HEADERS += lsmainwindow.h \ lsglobals.h \ lyt/packagebase.h \ @@ -85,7 +86,8 @@ HEADERS += lsmainwindow.h \ lstexcoordseteditor.h \ lsmaterialeditor.h \ lscolorpicker.h \ - lsmaterialmodel.h + lsmaterialmodel.h \ + lsseteditor.h FORMS += RESOURCES += resources.qrc diff --git a/lsmaterialeditor.cpp b/lsmaterialeditor.cpp index f1c5736..5ff2825 100644 --- a/lsmaterialeditor.cpp +++ b/lsmaterialeditor.cpp @@ -5,11 +5,13 @@ LSMaterialEditor::LSMaterialEditor(QWidget *parent) : QWidget(parent) { QGridLayout *grid = new QGridLayout(this); + int gridRow = 0; m_nameEntry = new QLineEdit(this); - grid->addWidget(new QLabel("Name:", this), 0, 0, 1, 1); - grid->addWidget(m_nameEntry, 0, 1, 1, 1); + grid->addWidget(new QLabel("Name:", this), gridRow, 0, 1, 1); + grid->addWidget(m_nameEntry, gridRow, 1, 1, 1); + gridRow++; // TEV colour box QGroupBox *tevCBox = new QGroupBox("TEV Colours", this); @@ -24,10 +26,21 @@ LSMaterialEditor::LSMaterialEditor(QWidget *parent) : tevCLayout->addWidget(m_colourPickers[i], isKonst?3:1, isKonst?(i-3):i, 1, 1); } - grid->addWidget(tevCBox, 1, 0, 1, 2); + grid->addWidget(tevCBox, gridRow, 0, 1, 2); + gridRow++; + // TEV stages + QGroupBox *stageBox = new QGroupBox("TEV Stages", this); + QVBoxLayout *stageLayout = new QVBoxLayout(stageBox); - grid->setRowStretch(2, 1); + m_tevStageSetEditor = new LSSetEditor<LYTTevStage, LSTevStageEditor>(8, stageBox); + stageLayout->addWidget(m_tevStageSetEditor); + + grid->addWidget(stageBox, gridRow, 0, 1, 2); + gridRow++; + + // finish it all up + grid->setRowStretch(gridRow, 1); m_currentlyLoadingMaterial = false; @@ -45,6 +58,8 @@ void LSMaterialEditor::setMaterial(LYTMaterial *mat) { for (int i = 0; i < 4; i++) m_colourPickers[i+3]->setColor(mat->tevKColour[i]); + m_tevStageSetEditor->setData(&mat->tevStages); + m_currentlyLoadingMaterial = false; } diff --git a/lsmaterialeditor.h b/lsmaterialeditor.h index ba18762..b09c474 100644 --- a/lsmaterialeditor.h +++ b/lsmaterialeditor.h @@ -7,6 +7,17 @@ #include <QLineEdit> #include "lyt/materials/materialcontainer.h" #include "lscolorpicker.h" +#include "lsseteditor.h" + +class LSTevStageEditor : public LSSetEntryEditorBase<LYTTevStage> { + Q_OBJECT +public: + explicit LSTevStageEditor(QWidget *parent = 0) : + LSSetEntryEditorBase(parent) { } + + void loadEntryFrom(const LYTTevStage &entry) { + } +}; class LSMaterialEditor : public QWidget { Q_OBJECT @@ -21,6 +32,8 @@ private: bool m_currentlyLoadingMaterial; LYTMaterial *m_material; + LSSetEditor<LYTTevStage, LSTevStageEditor> *m_tevStageSetEditor; + private slots: void handleNameChanged(QString value); void handleSaveChangedName(); diff --git a/lsseteditor.cpp b/lsseteditor.cpp new file mode 100644 index 0000000..bc63476 --- /dev/null +++ b/lsseteditor.cpp @@ -0,0 +1,60 @@ +#include "lsseteditor.h" +#include <QGridLayout> +#include <QLabel> + +_LSSetEditorBase::_LSSetEditorBase(int maxEntries, QWidget *parent) : + QWidget(parent) { + + m_maxEntries = maxEntries; + m_loadingThings = 0; +} + + +void _LSSetEditorBase::handleEntrySelected(int index) { + if (!m_loadingThings) + showEntry(index); +} + + +void _LSSetEditorBase::handleEntryCountChanged(int count) { + if (!m_loadingThings) { + int oldCount = m_chooser->count(); + if (oldCount == count) + return; + + changeEntryCountTo(count); + resizeDataListTo(count); + + // moving from 0 to something...? + if (oldCount == 0) { + m_chooser->setCurrentIndex(0); + showEntry(0); + } + + emit dataEdited(); + } +} + + +void _LSSetEditorBase::setup(QWidget *eWidget) { + m_loadingThings++; + + m_entryCount = new QSpinBox(this); + m_entryCount->setRange(0, m_maxEntries); + connect(m_entryCount, SIGNAL(valueChanged(int)), SLOT(handleEntryCountChanged(int))); + + m_chooser = new QComboBox(this); + connect(m_chooser, SIGNAL(currentIndexChanged(int)), SLOT(handleEntrySelected(int))); + + QGridLayout *layout = new QGridLayout(this); + + layout->addWidget(new QLabel("Count:", this), 0, 0, 1, 1); + layout->addWidget(m_entryCount, 0, 1, 1, 1); + layout->setColumnMinimumWidth(2, 10); + layout->addWidget(m_chooser, 0, 3, 1, 1); + layout->setColumnStretch(3, 1); + + layout->addWidget(eWidget, 1, 0, 1, 4); + + m_loadingThings--; +} diff --git a/lsseteditor.h b/lsseteditor.h new file mode 100644 index 0000000..a89131d --- /dev/null +++ b/lsseteditor.h @@ -0,0 +1,148 @@ +#ifndef LSSETEDITOR_H +#define LSSETEDITOR_H + +#include <QWidget> +#include <QSpinBox> +#include <QComboBox> + +class _LSSetEntryEditorBaseBase : public QWidget { + Q_OBJECT +protected: + explicit _LSSetEntryEditorBaseBase(QWidget *parent = 0) : + QWidget(parent) { } + +signals: + void dataEdited(); +}; + +template <typename TData> +class LSSetEntryEditorBase : public _LSSetEntryEditorBaseBase { +protected: + explicit LSSetEntryEditorBase(QWidget *parent = 0) : + _LSSetEntryEditorBaseBase(parent) { } + +private: + void setCurrentEntry(TData &entry); + // what?? + //friend class LSSetEditor<TData, LSSetEntryEditorBase<TData> >; + + TData *m_currentEntry; + +protected: + virtual void loadEntryFrom(const TData &entry) = 0; + TData *currentEntry() const { return m_currentEntry; } +}; + + + + +class _LSSetEditorBase : public QWidget { + Q_OBJECT +public: + explicit _LSSetEditorBase(int maxEntries, QWidget *parent = 0); + +protected: + int m_maxEntries; + QSpinBox *m_entryCount; + QComboBox *m_chooser; + + QWidget *m_setEditorWidget; + + int m_loadingThings; + + void setup(QWidget *eWidget); + + virtual void changeEntryCountTo(int count) = 0; + virtual void showEntry(int index) = 0; + virtual void resizeDataListTo(int count) = 0; + +private slots: + void handleEntryCountChanged(int count); + void handleEntrySelected(int index); + +signals: + void dataEdited(); + +}; + +template <typename TData, typename TWidget> +class LSSetEditor : public _LSSetEditorBase { +public: + explicit LSSetEditor(int maxEntries, QWidget *parent = 0) : + _LSSetEditorBase(maxEntries, parent) { + + TWidget *w = new TWidget(this); + setup(w); + + LSSetEntryEditorBase<TData> *checkMe = w; + connect(checkMe, SIGNAL(dataEdited()), SIGNAL(dataEdited())); + } + + void setData(QList<TData> *newData) { + m_loadingThings++; + + m_data = newData; + m_entryCount->setValue(newData->count()); + changeEntryCountTo(newData->count()); + + m_chooser->setCurrentIndex(newData->count() ? 0 : -1); + showEntry(newData->count() ? 0 : -1); + + m_loadingThings--; + } + +protected: + QList<TData> *m_data; + + void changeEntryCountTo(int count) { + m_loadingThings++; + + int existingCount = m_chooser->count(); + + if (existingCount > count) { + // remove something + int nowSelected = m_chooser->currentIndex(); + + if (nowSelected >= count) { + // oops, we'll need to select something else + showEntry(count - 1); + m_chooser->setCurrentIndex(count - 1); + } + + for (int i = (existingCount - 1); i >= count; i--) + m_chooser->removeItem(i); + + } else if (count > existingCount) { + // add something + + for (int i = existingCount; i < count; i++) + m_chooser->addItem(QString("Set %1").arg(i + 1)); + } + + m_loadingThings--; + } + + void resizeDataListTo(int count) { + m_data->reserve(count); + + while (m_data->count() < count) + m_data->append(TData()); + while (m_data->count() > count) + m_data->removeLast(); + } + + void showEntry(int index) { + m_loadingThings++; + + if (index == -1) { + m_setEditorWidget->setEnabled(false); + } else { + const TData &entry = m_data->at(index); + } + } +}; + + + + +#endif // LSSETEDITOR_H |