diff --git a/RetroEDv2/icons/ic_colorpick_48px.svg b/RetroEDv2/icons/ic_colorpick_48px.svg
new file mode 100644
index 0000000..084d107
--- /dev/null
+++ b/RetroEDv2/icons/ic_colorpick_48px.svg
@@ -0,0 +1,24 @@
+
+
diff --git a/RetroEDv2/resources.qrc b/RetroEDv2/resources.qrc
index ff57760..8baf233 100644
--- a/RetroEDv2/resources.qrc
+++ b/RetroEDv2/resources.qrc
@@ -61,5 +61,6 @@
resources/splash.svg
icons/ic_stamp_selection_48px.svg
resources/RSDKv5VarNames.txt
+ icons/ic_colorpick_48px.svg
diff --git a/RetroEDv2/tools/paletteeditor/colourdialog.cpp b/RetroEDv2/tools/paletteeditor/colourdialog.cpp
index d0c396a..2fb19ae 100644
--- a/RetroEDv2/tools/paletteeditor/colourdialog.cpp
+++ b/RetroEDv2/tools/paletteeditor/colourdialog.cpp
@@ -30,6 +30,9 @@ RSDKColorDialog::RSDKColorDialog(PaletteColor color, QWidget *parent)
ui->htmlInput->setModified(false);
setColor(color);
});
+
+ connect(ui->colorPick, &QToolButton::pressed, this, &RSDKColorDialog::pickScreenColor);
+
setColor(m_color.toQColor());
}
@@ -52,6 +55,72 @@ void RSDKColorDialog::setRGB()
setColor(col);
}
+bool RSDKColorDialog::mouseMoveColorEvent(QMouseEvent *e)
+{
+ setColor(grabScreenColor(e->globalPos()));
+ //PrintLog(QString("Move %1 %2").arg(e->globalPos().x()).arg(e->globalPos().y()));
+ return true;
+}
+
+bool RSDKColorDialog::mouseReleaseColorEvent(QMouseEvent *e)
+{
+ setColor(grabScreenColor(e->globalPos()));
+ ui->colorPick->setDown(false);
+
+ releaseMouse();
+ releaseKeyboard();
+ colorPickMode = false;
+ setMouseTracking(false);
+ return true;
+}
+
+bool RSDKColorDialog::keyPressColorEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape) {
+ setColor(PrevCol.toQColor());
+ releaseMouse();
+ releaseKeyboard();
+ colorPickMode = false;
+ setMouseTracking(false);
+ ui->colorPick->setDown(false);
+ return true;
+ }
+ return false;
+}
+
+bool RSDKColorDialog::event(QEvent *event)
+{
+ if (colorPickMode){
+ switch ((int)event->type()) {
+ default: break;
+ case QEvent::MouseMove:
+ return mouseMoveColorEvent(static_cast(event));
+ case QEvent::MouseButtonRelease:
+ return mouseReleaseColorEvent(static_cast(event));
+ case QEvent::KeyPress:
+ return keyPressColorEvent(static_cast(event));
+ }
+ }
+ return QWidget::event(event);
+}
+
+void RSDKColorDialog::pickScreenColor()
+{
+ PrevCol = m_color;
+
+#ifndef QT_NO_CURSOR
+ grabMouse(Qt::CrossCursor);
+#else
+ grabMouse();
+#endif
+
+ grabKeyboard();
+ setMouseTracking(true);
+ colorPickMode = true;
+ const QPoint globalPos = QCursor::pos();
+ setColor(grabScreenColor(globalPos));
+}
+
void RSDKColorDialog::setColor(QColor col)
{
@@ -123,4 +192,13 @@ PaletteColor RSDKColorDialog::getColor(PaletteColor color, bool *ok, QWidget *pa
return clr;
}
+QColor RSDKColorDialog::grabScreenColor(const QPoint &p)
+{
+ const QDesktopWidget *desktop = QApplication::desktop();
+ const QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
+ QImage i = pixmap.toImage();
+ return QColor(i.pixel(0, 0));
+}
+
+
#include "moc_colourdialog.cpp"
diff --git a/RetroEDv2/tools/paletteeditor/colourdialog.hpp b/RetroEDv2/tools/paletteeditor/colourdialog.hpp
index 0679b0d..202facd 100644
--- a/RetroEDv2/tools/paletteeditor/colourdialog.hpp
+++ b/RetroEDv2/tools/paletteeditor/colourdialog.hpp
@@ -15,15 +15,25 @@ class RSDKColorDialog : public QDialog
static PaletteColor getColor(PaletteColor color, bool *ok, QWidget *parent = nullptr);
inline PaletteColor color() { return m_color; }
+ QColor grabScreenColor(const QPoint &p);
+
+protected:
+ bool event(QEvent *event);
+ bool mouseMoveColorEvent(QMouseEvent *e);
+ bool mouseReleaseColorEvent(QMouseEvent *e);
+ bool keyPressColorEvent(QKeyEvent *e);
private slots:
void setColor(QColor col);
void setHsv();
void setRGB();
+ void pickScreenColor();
private:
Ui::RSDKColorDialog *ui;
PaletteColor m_color;
+ PaletteColor PrevCol;
+ bool colorPickMode = false;
};
diff --git a/RetroEDv2/tools/paletteeditor/colourdialog.ui b/RetroEDv2/tools/paletteeditor/colourdialog.ui
index e6f2453..4ade4bc 100644
--- a/RetroEDv2/tools/paletteeditor/colourdialog.ui
+++ b/RetroEDv2/tools/paletteeditor/colourdialog.ui
@@ -154,9 +154,6 @@
6
- -
-
-
-
@@ -383,6 +380,26 @@
+ -
+
+
+ -
+
+
+ Color picker (Press and Hold left click)
+
+
+ ...
+
+
+
+ :/icons/ic_colorpick_48px.svg:/icons/ic_colorpick_48px.svg
+
+
+ false
+
+
+