summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LayoutStudio.pro6
-rw-r--r--lscolorpicker.cpp47
-rw-r--r--lscolorpicker.h27
-rw-r--r--lspaneeditor.cpp51
-rw-r--r--lspaneeditor.h5
5 files changed, 89 insertions, 47 deletions
diff --git a/LayoutStudio.pro b/LayoutStudio.pro
index 3cc5bc3..9f2fc26 100644
--- a/LayoutStudio.pro
+++ b/LayoutStudio.pro
@@ -41,7 +41,8 @@ SOURCES += main.cpp \
lsscenemodel.cpp \
lspaneeditor.cpp \
lstexcoordseteditor.cpp \
- lsmaterialeditor.cpp
+ lsmaterialeditor.cpp \
+ lscolorpicker.cpp
HEADERS += lsmainwindow.h \
lsglobals.h \
lyt/packagebase.h \
@@ -81,7 +82,8 @@ HEADERS += lsmainwindow.h \
lsscenemodel.h \
lspaneeditor.h \
lstexcoordseteditor.h \
- lsmaterialeditor.h
+ lsmaterialeditor.h \
+ lscolorpicker.h
FORMS +=
RESOURCES += resources.qrc
diff --git a/lscolorpicker.cpp b/lscolorpicker.cpp
new file mode 100644
index 0000000..df911a2
--- /dev/null
+++ b/lscolorpicker.cpp
@@ -0,0 +1,47 @@
+#include "lscolorpicker.h"
+#include <QColorDialog>
+
+LSColorPicker::LSColorPicker(QWidget *parent) :
+ QToolButton(parent) {
+
+ connect(this, SIGNAL(clicked()), SLOT(tryAndChoose()));
+ setColor(QColor::fromRgb(255,255,255,255));
+}
+
+void LSColorPicker::setColor(QColor newCol) {
+ m_color = newCol;
+ refreshButton();
+}
+
+void LSColorPicker::tryAndChoose() {
+ QColor newCol = QColorDialog::getColor(
+ m_color, this,
+ "Pick a Colour",
+ QColorDialog::ShowAlphaChannel);
+
+ if (newCol.isValid() && newCol != m_color) {
+ QColor oldCol = m_color;
+ m_color = newCol;
+ refreshButton();
+ emit colorPicked(newCol, oldCol);
+ }
+}
+
+
+void LSColorPicker::refreshButton() {
+ setStyleSheet(QString("QToolButton { background-color: rgba(%1,%2,%3,%4); }")
+ .arg(m_color.red())
+ .arg(m_color.green())
+ .arg(m_color.blue())
+ .arg(m_color.alpha()));
+
+ setText(QString("RGBA %1,%2,%3,%4 (#%5%6%7%8)")
+ .arg(m_color.red())
+ .arg(m_color.green())
+ .arg(m_color.blue())
+ .arg(m_color.alpha())
+ .arg(m_color.red(), 2, 16, (QChar)'0')
+ .arg(m_color.green(), 2, 16, (QChar)'0')
+ .arg(m_color.blue(), 2, 16, (QChar)'0')
+ .arg(m_color.alpha(), 2, 16, (QChar)'0'));
+}
diff --git a/lscolorpicker.h b/lscolorpicker.h
new file mode 100644
index 0000000..7f16c57
--- /dev/null
+++ b/lscolorpicker.h
@@ -0,0 +1,27 @@
+#ifndef LSCOLORPICKER_H
+#define LSCOLORPICKER_H
+
+#include <QToolButton>
+
+class LSColorPicker : public QToolButton
+{
+ Q_OBJECT
+public:
+ explicit LSColorPicker(QWidget *parent = 0);
+
+ QColor color() const { return m_color; }
+ void setColor(QColor newCol);
+
+private:
+ QColor m_color;
+
+private slots:
+ void tryAndChoose();
+ void refreshButton();
+
+signals:
+ void colorPicked(QColor newCol, QColor oldCol);
+
+};
+
+#endif // LSCOLORPICKER_H
diff --git a/lspaneeditor.cpp b/lspaneeditor.cpp
index 3c4413d..b58f683 100644
--- a/lspaneeditor.cpp
+++ b/lspaneeditor.cpp
@@ -192,8 +192,8 @@ void LSPaneEditor::createPictureTab() {
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()));
+ m_picColourButtons[i] = new LSColorPicker(this);
+ connect(m_picColourButtons[i], SIGNAL(colorPicked(QColor,QColor)), SLOT(handlePicColourPicked(QColor)));
}
vcLayout->addWidget(m_picColourButtons[0], 0, 0, 1, 1);
@@ -211,28 +211,6 @@ void LSPaneEditor::createPictureTab() {
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;
@@ -281,10 +259,8 @@ 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]));
+ LSColorPicker *button = m_picColourButtons[i];
+ button->setColor(pic->vtxColours[i]);
}
break;
@@ -421,12 +397,12 @@ void LSPaneEditor::handleScaleYChanged(double value) {
}
}
-void LSPaneEditor::handlePicColourClicked() {
+void LSPaneEditor::handlePicColourPicked(QColor value) {
// make sure ...
if (m_pane->type() != LYTPane::PictureType)
return;
- QToolButton *button = (QToolButton*)sender();
+ LSColorPicker *button = (LSColorPicker*)sender();
int index = -1;
for (int i = 0; i < 4; i++)
if (m_picColourButtons[i] == button) {
@@ -437,19 +413,8 @@ void LSPaneEditor::handlePicColourClicked() {
if (index == -1)
return;
- QColor newcol = QColorDialog::getColor(
- m_picture->vtxColours[index],
- this,
- "Choose a Vertex Colour",
- QColorDialog::ShowAlphaChannel);
+ m_picture->vtxColours[index] = value;
- if (newcol.isValid()) {
- m_picture->vtxColours[index] = newcol;
-
- button->setStyleSheet(bgColourSheet(newcol));
- button->setText(niceColourName(newcol));
-
- emit mustRedrawLayout();
- }
+ emit mustRedrawLayout();
}
diff --git a/lspaneeditor.h b/lspaneeditor.h
index 480dbb1..a1faa2c 100644
--- a/lspaneeditor.h
+++ b/lspaneeditor.h
@@ -12,6 +12,7 @@
#include <QComboBox>
#include <QCheckBox>
#include "lyt/pane.h"
+#include "lscolorpicker.h"
class LSTexCoordSetEditor;
class LYTPicture;
@@ -59,7 +60,7 @@ private:
QWidget *m_pictureTab;
LSTexCoordSetEditor *m_picTexCoordEditor;
- QToolButton *m_picColourButtons[4];
+ LSColorPicker *m_picColourButtons[4];
void createPaneTab();
@@ -92,7 +93,7 @@ private slots:
void handleScaleXChanged(double value);
void handleScaleYChanged(double value);
- void handlePicColourClicked();
+ void handlePicColourPicked(QColor value);
signals:
void mustRedrawLayout();