2017-05-16 15:52:15 +02:00
|
|
|
#include "colorpickerscene.hpp"
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QGraphicsEllipseItem>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QGraphicsTextItem>
|
|
|
|
#include <QTimer>
|
2018-02-18 02:35:29 +01:00
|
|
|
#include <logger.hpp>
|
2017-12-06 14:08:49 +01:00
|
|
|
#include <screenoverlay/screenoverlayview.hpp>
|
2017-07-10 16:27:38 +02:00
|
|
|
#include <settings.hpp>
|
2017-05-16 15:52:15 +02:00
|
|
|
|
2017-07-02 20:51:15 +02:00
|
|
|
ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
|
2017-12-06 02:16:49 +01:00
|
|
|
: ScreenOverlay(pixmap, parentWidget), ScreenOverlayView(this, parentWidget), image(pixmap.toImage()) {
|
2017-07-29 17:22:17 +02:00
|
|
|
setWindowTitle(tr("KShare Color Picker"));
|
2017-07-03 12:07:49 +02:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2017-12-06 02:16:49 +01:00
|
|
|
setCursor(Qt::BlankCursor);
|
2017-08-03 22:00:15 +02:00
|
|
|
|
2017-07-10 16:27:38 +02:00
|
|
|
activateWindow();
|
|
|
|
setGeometry(pixmap.rect());
|
2017-12-06 14:08:49 +01:00
|
|
|
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-02-18 02:35:29 +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
|
|
|
}
|
2017-12-06 02:16:49 +01:00
|
|
|
|
|
|
|
QString ColorPickerScene::generateHint() {
|
2017-12-06 22:31:00 +01:00
|
|
|
color = image.pixelColor(cursorPos().toPoint());
|
2017-12-06 02:16:49 +01:00
|
|
|
return color.name();
|
|
|
|
}
|