summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-08-25 04:33:38 +0200
committerTreeki <treeki@gmail.com>2012-08-25 04:33:38 +0200
commit8cb142e69d955e06aa160a8e02903cc57c4515c4 (patch)
treecf35b2d3c0521e2bd0c7c0a3084d8e451821f308
parente95cad36b68ebbce8fedb119ff2b41a0f345ffbb (diff)
downloadLayoutStudio-8cb142e69d955e06aa160a8e02903cc57c4515c4.tar.gz
LayoutStudio-8cb142e69d955e06aa160a8e02903cc57c4515c4.zip
editing for picture vertex colours
Diffstat (limited to '')
-rw-r--r--lspaneeditor.cpp75
-rw-r--r--lspaneeditor.h10
2 files changed, 84 insertions, 1 deletions
diff --git a/lspaneeditor.cpp b/lspaneeditor.cpp
index 32fa464..49939ec 100644
--- a/lspaneeditor.cpp
+++ b/lspaneeditor.cpp
@@ -1,6 +1,7 @@
#include "lspaneeditor.h"
#include "lstexcoordseteditor.h"
#include <QGroupBox>
+#include <QColorDialog>
#include "lyt/bounding.h"
#include "lyt/picture.h"
@@ -186,13 +187,52 @@ void LSPaneEditor::createPictureTab() {
connect(m_picTexCoordEditor, SIGNAL(coordsEdited()), SIGNAL(mustRedrawLayout()));
+
+ QGroupBox *vcBox = new QGroupBox("Vertex Colours", m_pictureTab);
+ QGridLayout *vcLayout = new QGridLayout(vcBox);
+
+ for (int i = 0; i < 4; i++) {
+ m_picColourButtons[i] = new QToolButton(this);
+ connect(m_picColourButtons[i], SIGNAL(clicked()), SLOT(handlePicColourClicked()));
+ }
+
+ vcLayout->addWidget(m_picColourButtons[0], 0, 0, 1, 1);
+ vcLayout->addWidget(m_picColourButtons[1], 0, 2, 1, 1);
+ vcLayout->addWidget(m_picColourButtons[2], 2, 0, 1, 1);
+ vcLayout->addWidget(m_picColourButtons[3], 2, 2, 1, 1);
+
+ // TODO: material
+
// put it all together into one
QVBoxLayout *layout = new QVBoxLayout(m_pictureTab);
layout->addWidget(tcBox);
+ layout->addWidget(vcBox);
layout->addStretch(1);
}
+// dunno where to throw this right now
+// TODO: move it
+static QString niceColourName(const QColor &col) {
+ return QString("RGBA %1,%2,%3,%4 (#%5%6%7%8)")
+ .arg(col.red())
+ .arg(col.green())
+ .arg(col.blue())
+ .arg(col.alpha())
+ .arg(col.red(), 2, 16, (QChar)'0')
+ .arg(col.green(), 2, 16, (QChar)'0')
+ .arg(col.blue(), 2, 16, (QChar)'0')
+ .arg(col.alpha(), 2, 16, (QChar)'0');
+}
+
+static QString bgColourSheet(const QColor &col) {
+ return QString("QToolButton { background-color: rgba(%1,%2,%3,%4); }")
+ .arg(col.red())
+ .arg(col.green())
+ .arg(col.blue())
+ .arg(col.alpha());
+}
+
void LSPaneEditor::setPane(LYTPane *pane) {
m_currentlyLoadingPane = true;
@@ -240,6 +280,13 @@ void LSPaneEditor::setPane(LYTPane *pane) {
m_picTexCoordEditor->setCoordPtr(&pic->texCoords);
+ for (int i = 0; i < 4; i++) {
+ QToolButton *button = m_picColourButtons[i];
+
+ button->setStyleSheet(bgColourSheet(pic->vtxColours[i]));
+ button->setText(niceColourName(pic->vtxColours[i]));
+ }
+
break;
}
@@ -374,3 +421,31 @@ void LSPaneEditor::handleScaleYChanged(double value) {
}
}
+void LSPaneEditor::handlePicColourClicked() {
+ // make sure ...
+ if (m_pane->type() != LYTPane::PictureType)
+ return;
+
+ QToolButton *button = (QToolButton*)sender();
+ int index = -1;
+ for (int i = 0; i < 4; i++)
+ if (m_picColourButtons[i] == button) {
+ index = i;
+ break;
+ }
+
+ if (index == -1)
+ return;
+
+ QColor newcol = QColorDialog::getColor(m_picture->vtxColours[index], this);
+
+ if (newcol.isValid()) {
+ m_picture->vtxColours[index] = newcol;
+
+ button->setStyleSheet(bgColourSheet(newcol));
+ button->setText(niceColourName(newcol));
+
+ emit mustRedrawLayout();
+ }
+}
+
diff --git a/lspaneeditor.h b/lspaneeditor.h
index 16f6d1b..480dbb1 100644
--- a/lspaneeditor.h
+++ b/lspaneeditor.h
@@ -14,6 +14,8 @@
#include "lyt/pane.h"
class LSTexCoordSetEditor;
+class LYTPicture;
+
class LSPaneEditor : public QWidget {
Q_OBJECT
public:
@@ -57,6 +59,7 @@ private:
QWidget *m_pictureTab;
LSTexCoordSetEditor *m_picTexCoordEditor;
+ QToolButton *m_picColourButtons[4];
void createPaneTab();
@@ -64,7 +67,10 @@ private:
bool m_currentlyLoadingPane;
- LYTPane *m_pane;
+ union {
+ LYTPane *m_pane;
+ LYTPicture *m_picture;
+ };
private slots:
void handleNameChanged(QString value);
@@ -86,6 +92,8 @@ private slots:
void handleScaleXChanged(double value);
void handleScaleYChanged(double value);
+ void handlePicColourClicked();
+
signals:
void mustRedrawLayout();