diff options
author | Treeki <treeki@gmail.com> | 2012-08-19 01:48:36 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-08-19 01:48:36 +0200 |
commit | 2883326061ccadc1b21376dc25c92e1d6751d592 (patch) | |
tree | 8488da79605991d1b02a97d3eb78741c47647103 | |
parent | 195efe4ebab933bfbba7f7bf06cf4592b865d008 (diff) | |
download | LayoutStudio-2883326061ccadc1b21376dc25c92e1d6751d592.tar.gz LayoutStudio-2883326061ccadc1b21376dc25c92e1d6751d592.zip |
added a tex coord set editor and the beginnings of a Picture tab
-rw-r--r-- | LayoutStudio.pro | 6 | ||||
-rw-r--r-- | lspaneeditor.cpp | 40 | ||||
-rw-r--r-- | lspaneeditor.h | 9 | ||||
-rw-r--r-- | lstexcoordseteditor.cpp | 174 | ||||
-rw-r--r-- | lstexcoordseteditor.h | 40 | ||||
-rw-r--r-- | lyt/common.h | 8 |
6 files changed, 275 insertions, 2 deletions
diff --git a/LayoutStudio.pro b/LayoutStudio.pro index 66a8567..cf9287d 100644 --- a/LayoutStudio.pro +++ b/LayoutStudio.pro @@ -39,7 +39,8 @@ SOURCES += main.cpp \ lspackagemodel.cpp \ lslayoutwindow.cpp \ lsscenemodel.cpp \ - lspaneeditor.cpp + lspaneeditor.cpp \ + lstexcoordseteditor.cpp HEADERS += lsmainwindow.h \ lsglobals.h \ lyt/packagebase.h \ @@ -77,7 +78,8 @@ HEADERS += lsmainwindow.h \ lspackagemodel.h \ lslayoutwindow.h \ lsscenemodel.h \ - lspaneeditor.h + lspaneeditor.h \ + lstexcoordseteditor.h FORMS += RESOURCES += resources.qrc diff --git a/lspaneeditor.cpp b/lspaneeditor.cpp index 5548b75..32fa464 100644 --- a/lspaneeditor.cpp +++ b/lspaneeditor.cpp @@ -1,4 +1,5 @@ #include "lspaneeditor.h" +#include "lstexcoordseteditor.h" #include <QGroupBox> #include "lyt/bounding.h" @@ -37,6 +38,7 @@ LSPaneEditor::LSPaneEditor(QWidget *parent) : createPaneTab(); + createPictureTab(); m_currentlyLoadingPane = false; m_pane = 0; @@ -171,10 +173,33 @@ void LSPaneEditor::createPaneTab() { } +void LSPaneEditor::createPictureTab() { + m_pictureTab = new QWidget(this); + m_tabs->addTab(m_pictureTab, "Picture"); + + + QGroupBox *tcBox = new QGroupBox("Texture Coordinates", m_pictureTab); + QVBoxLayout *tcLayout = new QVBoxLayout(tcBox); + + m_picTexCoordEditor = new LSTexCoordSetEditor(tcBox); + tcLayout->addWidget(m_picTexCoordEditor); + + connect(m_picTexCoordEditor, SIGNAL(coordsEdited()), SIGNAL(mustRedrawLayout())); + + // put it all together into one + + QVBoxLayout *layout = new QVBoxLayout(m_pictureTab); + layout->addWidget(tcBox); + layout->addStretch(1); +} + + void LSPaneEditor::setPane(LYTPane *pane) { m_currentlyLoadingPane = true; m_pane = pane; + // General pane tab + m_nameEntry->setText(pane->name); m_userDataEntry->setText(pane->userdata); @@ -204,6 +229,21 @@ void LSPaneEditor::setPane(LYTPane *pane) { m_scaleY->setValue(pane->yScale); + // Type-specific tabs + + LYTPane::PaneTypes type = pane->type(); + m_tabs->setTabEnabled(m_tabs->indexOf(m_pictureTab), type == LYTPane::PictureType); + + switch (type) { + case LYTPane::PictureType: + LYTPicture *pic = (LYTPicture*)pane; + + m_picTexCoordEditor->setCoordPtr(&pic->texCoords); + + break; + } + + m_currentlyLoadingPane = false; } diff --git a/lspaneeditor.h b/lspaneeditor.h index 9aaf942..16f6d1b 100644 --- a/lspaneeditor.h +++ b/lspaneeditor.h @@ -12,6 +12,7 @@ #include <QComboBox> #include <QCheckBox> #include "lyt/pane.h" +class LSTexCoordSetEditor; class LSPaneEditor : public QWidget { Q_OBJECT @@ -52,7 +53,15 @@ private: }; }; + // Picture tab + QWidget *m_pictureTab; + + LSTexCoordSetEditor *m_picTexCoordEditor; + + void createPaneTab(); + void createPictureTab(); + bool m_currentlyLoadingPane; LYTPane *m_pane; diff --git a/lstexcoordseteditor.cpp b/lstexcoordseteditor.cpp new file mode 100644 index 0000000..e8173a0 --- /dev/null +++ b/lstexcoordseteditor.cpp @@ -0,0 +1,174 @@ +#include "lstexcoordseteditor.h" +#include <QLabel> +#include <QHBoxLayout> +#include <QGridLayout> + +LSTexCoordSetEditor::LSTexCoordSetEditor(QWidget *parent) : + QWidget(parent) { + + m_loadingThings = 1; + + m_coordCount = new QSpinBox(this); + m_coordCount->setRange(0, 8); + connect(m_coordCount, SIGNAL(valueChanged(int)), SLOT(handleCoordCountChanged(int))); + + m_chooser = new QComboBox(this); + connect(m_chooser, SIGNAL(currentIndexChanged(int)), SLOT(handleSetSelected(int))); + + for (int i = 0; i < 8; i++) { + m_coordEntry[i] = new QDoubleSpinBox(this); + m_coordEntry[i]->setRange(-10000000.0, 10000000.0); + connect(m_coordEntry[i], SIGNAL(valueChanged(double)), SLOT(handleCoordChanged(double))); + } + + + QHBoxLayout *topLayout = new QHBoxLayout; + topLayout->addWidget(new QLabel("Count:", this)); + topLayout->addWidget(m_coordCount); + topLayout->addSpacing(10); + topLayout->addWidget(m_chooser, 1); + + // Layout: + // 0 1 2 3 4 + // 0 <Chooser> + // 1 x y x y + // 2 + // 3 x y x y + + QGridLayout *layout = new QGridLayout(this); + layout->addLayout(topLayout, 0, 0, 1, 5); + + layout->addWidget(m_coordEntry[0], 1, 0, 1, 1); + layout->addWidget(m_coordEntry[1], 1, 1, 1, 1); + + layout->addWidget(m_coordEntry[2], 1, 3, 1, 1); + layout->addWidget(m_coordEntry[3], 1, 4, 1, 1); + + layout->addWidget(m_coordEntry[4], 3, 0, 1, 1); + layout->addWidget(m_coordEntry[5], 3, 1, 1, 1); + + layout->addWidget(m_coordEntry[6], 3, 3, 1, 1); + layout->addWidget(m_coordEntry[7], 3, 4, 1, 1); + + layout->setColumnMinimumWidth(2, 25); + layout->setRowMinimumHeight(2, 10); + + m_loadingThings--; +} + + +void LSTexCoordSetEditor::setCoordPtr(QVector<LYTTexCoords> *coords) { + m_loadingThings++; + + m_targetCoords = coords; + + m_coordCount->setValue(coords->count()); + + changeChooserCountTo(coords->count()); + + m_chooser->setCurrentIndex(coords->count() ? 0 : -1); + showCoordSet(coords->count() ? 0 : -1); + + m_loadingThings--; +} + +void LSTexCoordSetEditor::changeChooserCountTo(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 + showCoordSet(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 LSTexCoordSetEditor::showCoordSet(int index) { + m_loadingThings++; + + bool doesExist = (index != -1); + + for (int i = 0; i < 8; i++) + m_coordEntry[i]->setEnabled(doesExist); + + if (doesExist) { + const LYTTexCoords &set = m_targetCoords->at(index); + + for (int i = 0; i < 4; i++) { + m_coordEntry[i*2]->setValue(set.coord[i].x()); + m_coordEntry[i*2+1]->setValue(set.coord[i].y()); + } + } + + m_loadingThings--; +} + + +void LSTexCoordSetEditor::handleSetSelected(int index) { + if (!m_loadingThings) + showCoordSet(index); +} + +void LSTexCoordSetEditor::handleCoordCountChanged(int count) { + if (!m_loadingThings) { + int oldCount = m_targetCoords->count(); + if (oldCount == count) + return; + + changeChooserCountTo(count); + m_targetCoords->resize(count); + + // moving from 0 to something...? + if (oldCount == 0) { + m_chooser->setCurrentIndex(0); + showCoordSet(0); + } + + emit coordsEdited(); + } +} + +void LSTexCoordSetEditor::handleCoordChanged(double value) { + if (!m_loadingThings) { + // this code is.. kind of hacky. + + int whatID = -1; + for (int i = 0; i < 8; i++) + if (m_coordEntry[i] == sender()) { + whatID = i; + break; + } + + if (whatID >= 0) { + int coordIdx = m_chooser->currentIndex(); + if (coordIdx == -1) + return; + + LYTTexCoords &coord = (*m_targetCoords)[coordIdx]; + + if ((whatID % 2) == 1) + coord.coord[whatID / 2].setY(value); + else + coord.coord[whatID / 2].setX(value); + + emit coordsEdited(); + } + } +} diff --git a/lstexcoordseteditor.h b/lstexcoordseteditor.h new file mode 100644 index 0000000..5d7d567 --- /dev/null +++ b/lstexcoordseteditor.h @@ -0,0 +1,40 @@ +#ifndef LSTEXCOORDSETEDITOR_H +#define LSTEXCOORDSETEDITOR_H + +#include <QWidget> +#include <QComboBox> +#include <QDoubleSpinBox> +#include "lyt/common.h" + +class LSTexCoordSetEditor : public QWidget +{ + Q_OBJECT +public: + explicit LSTexCoordSetEditor(QWidget *parent = 0); + + void setCoordPtr(QVector<LYTTexCoords> *coords); + +private: + QVector<LYTTexCoords> *m_targetCoords; + QSpinBox *m_coordCount; + QComboBox *m_chooser; + QDoubleSpinBox *m_coordEntry[8]; + + int m_loadingThings; + + void changeChooserCountTo(int count); + void showCoordSet(int index); + +private slots: + void handleCoordCountChanged(int count); + void handleSetSelected(int index); + void handleCoordChanged(double value); + +signals: + void coordsEdited(); + +public slots: + +}; + +#endif // LSTEXCOORDSETEDITOR_H diff --git a/lyt/common.h b/lyt/common.h index 49061ce..a343c32 100644 --- a/lyt/common.h +++ b/lyt/common.h @@ -40,6 +40,14 @@ union Version { struct LYTTexCoords { QPointF coord[4]; + + LYTTexCoords() { + // Sane defaults + coord[0] = QPointF(0.0f, 0.0f); + coord[1] = QPointF(1.0f, 0.0f); + coord[2] = QPointF(0.0f, 1.0f); + coord[3] = QPointF(1.0f, 1.0f); + } }; |