2017-05-16 15:52:15 +02:00
|
|
|
#include "colorpickerscene.hpp"
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2017-08-05 21:20:24 +02:00
|
|
|
#include <QDebug>
|
2017-05-16 15:52:15 +02:00
|
|
|
#include <QGraphicsEllipseItem>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QGraphicsTextItem>
|
|
|
|
#include <QTimer>
|
2017-09-06 19:16:31 +02:00
|
|
|
#include <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-11-23 20:33:49 +01:00
|
|
|
QPoint p = utils::smallestScreenCoordinate()
|
2017-07-10 16:27:38 +02:00
|
|
|
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
|
|
|
|
move(p.x(), p.y());
|
2017-12-06 02:16:49 +01:00
|
|
|
if (QApplication::screens().size() == 1)
|
|
|
|
showFullScreen();
|
|
|
|
else
|
|
|
|
show();
|
2017-05-16 15:52:15 +02:00
|
|
|
}
|
|
|
|
|
2017-12-06 02:16:49 +01:00
|
|
|
void ColorPickerScene::mouseMoved(QGraphicsSceneMouseEvent *event, QPointF cursor, QPointF delta) {
|
|
|
|
color = image.pixelColor(cursorPos().toPoint());
|
2017-05-16 16:22:32 +02:00
|
|
|
qreal bottom = rect().bottom(); // max y
|
|
|
|
qreal right = rect().right(); // max x
|
|
|
|
|
2017-12-06 02:16:49 +01:00
|
|
|
QPointF origPoint = cursorPos() + QPoint(25, 0);
|
|
|
|
QPointF scopePoint = cursorPos();
|
2017-05-16 16:22:32 +02:00
|
|
|
QPointF resPoint = origPoint;
|
2017-05-16 15:52:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
|
2017-08-28 13:01:58 +02:00
|
|
|
if (event->key() == Qt::Key_Return) {
|
|
|
|
QApplication::clipboard()->setText(color.name());
|
|
|
|
qInfo().noquote() << tr("Copied hex code to clipboard.");
|
|
|
|
}
|
2017-05-16 15:52:15 +02:00
|
|
|
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
|
|
|
|
QApplication::clipboard()->setText(color.name());
|
|
|
|
close();
|
2017-08-05 21:20:24 +02:00
|
|
|
qInfo().noquote() << 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() {
|
|
|
|
return color.name();
|
|
|
|
}
|