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

View File

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