KShare/src/colorpicker/colorpickerscene.cpp

43 lines
1.4 KiB
C++
Raw Normal View History

2017-05-16 15:52:15 +02:00
#include "colorpickerscene.hpp"
#include <QApplication>
#include <QClipboard>
2018-01-01 16:37:31 +01:00
#include <logger.hpp>
2017-05-16 15:52:15 +02:00
#include <QGraphicsEllipseItem>
#include <QGraphicsPixmapItem>
#include <QGraphicsTextItem>
#include <QTimer>
#include <screenoverlay/screenoverlayview.hpp>
#include <settings.hpp>
2017-05-16 15:52:15 +02:00
ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
: ScreenOverlay(pixmap, parentWidget), ScreenOverlayView(this, parentWidget), image(pixmap.toImage()) {
setWindowTitle(tr("KShare Color Picker"));
setAttribute(Qt::WA_DeleteOnClose);
setCursor(Qt::BlankCursor);
2017-08-03 22:00:15 +02:00
activateWindow();
setGeometry(pixmap.rect());
ScreenOverlay::show();
2017-05-16 15:52:15 +02:00
}
void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
2017-12-06 22:31:00 +01:00
color = image.pixelColor(cursorPos().toPoint());
2017-08-28 13:01:58 +02:00
if (event->key() == Qt::Key_Return) {
QApplication::clipboard()->setText(color.name());
2018-01-01 16:37:31 +01:00
logger::info(tr("Copied hex code to clipboard."));
2017-08-28 13:01:58 +02:00
}
2017-05-16 15:52:15 +02:00
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close();
}
void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
2017-12-06 22:31:00 +01:00
color = image.pixelColor(cursorPos().toPoint());
2017-05-16 15:52:15 +02:00
QApplication::clipboard()->setText(color.name());
close();
2018-01-01 16:37:31 +01:00
logger::info(tr("Copied hex code to clipboard."));
2017-05-16 15:52:15 +02:00
}
QString ColorPickerScene::generateHint() {
2017-12-06 22:31:00 +01:00
color = image.pixelColor(cursorPos().toPoint());
return color.name();
}