summaryrefslogtreecommitdiff
path: root/lscolorpicker.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-09-04 19:56:58 +0200
committerTreeki <treeki@gmail.com>2012-09-04 19:56:58 +0200
commitf8c66ff96ae2417e744b2d46daa8577d642b9c9f (patch)
treef04bbf67442df5ec4fa8b97a58b39d1d842b37c7 /lscolorpicker.cpp
parent07e0eeb5ad9f81a62032aa37c0cfef84a9f6ed5c (diff)
downloadLayoutStudio-f8c66ff96ae2417e744b2d46daa8577d642b9c9f.tar.gz
LayoutStudio-f8c66ff96ae2417e744b2d46daa8577d642b9c9f.zip
pulled the colour picker out into a LSColorPicker widget
Diffstat (limited to '')
-rw-r--r--lscolorpicker.cpp47
1 files changed, 47 insertions, 0 deletions
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'));
+}