Some colorpicker fixes

This commit is contained in:
ArsenArsen 2017-12-06 22:31:00 +01:00
parent 276b645e2c
commit fc690d36da
No known key found for this signature in database
GPG Key ID: 683D2F43B0CA4BD2
2 changed files with 4 additions and 6 deletions

View File

@ -20,11 +20,8 @@ ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
ScreenOverlay::show(); ScreenOverlay::show();
} }
void ColorPickerScene::mouseMoved(QGraphicsSceneMouseEvent *, QPointF cursorPos, QPointF) {
color = image.pixelColor(cursorPos.toPoint());
}
void ColorPickerScene::keyPressEvent(QKeyEvent *event) { void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
color = image.pixelColor(cursorPos().toPoint());
if (event->key() == Qt::Key_Return) { if (event->key() == Qt::Key_Return) {
QApplication::clipboard()->setText(color.name()); QApplication::clipboard()->setText(color.name());
qInfo().noquote() << tr("Copied hex code to clipboard."); qInfo().noquote() << tr("Copied hex code to clipboard.");
@ -33,11 +30,13 @@ void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
} }
void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) { void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
color = image.pixelColor(cursorPos().toPoint());
QApplication::clipboard()->setText(color.name()); QApplication::clipboard()->setText(color.name());
close(); close();
qInfo().noquote() << tr("Copied hex code to clipboard."); qInfo().noquote() << tr("Copied hex code to clipboard.");
} }
QString ColorPickerScene::generateHint() { QString ColorPickerScene::generateHint() {
color = image.pixelColor(cursorPos().toPoint());
return color.name(); return color.name();
} }

View File

@ -17,13 +17,12 @@ public:
ColorPickerScene(QPixmap pixmap, QWidget *parent = nullptr); ColorPickerScene(QPixmap pixmap, QWidget *parent = nullptr);
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
QString generateHint() override;
static void showPicker() { static void showPicker() {
new ColorPickerScene(utils::fullscreen()); new ColorPickerScene(utils::fullscreen());
} }
protected: protected:
void mouseMoved(QGraphicsSceneMouseEvent *, QPointF cursorPos, QPointF) override; QString generateHint() override;
private: private:
QImage image; QImage image;