Color picker initial commit
This commit is contained in:
parent
0ca9e46f85
commit
df782571f9
@ -45,7 +45,8 @@ SOURCES += main.cpp\
|
|||||||
cropeditor/settings/blurdialog.cpp \
|
cropeditor/settings/blurdialog.cpp \
|
||||||
cropeditor/drawing/pathitem.cpp \
|
cropeditor/drawing/pathitem.cpp \
|
||||||
cropeditor/drawing/lineitem.cpp \
|
cropeditor/drawing/lineitem.cpp \
|
||||||
cropeditor/drawing/textitem.cpp
|
cropeditor/drawing/textitem.cpp \
|
||||||
|
colorpicker/colorpickerscene.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.hpp \
|
HEADERS += mainwindow.hpp \
|
||||||
cropeditor/cropeditor.hpp \
|
cropeditor/cropeditor.hpp \
|
||||||
@ -70,7 +71,8 @@ HEADERS += mainwindow.hpp \
|
|||||||
cropeditor/settings/blurdialog.hpp \
|
cropeditor/settings/blurdialog.hpp \
|
||||||
cropeditor/drawing/pathitem.hpp \
|
cropeditor/drawing/pathitem.hpp \
|
||||||
cropeditor/drawing/lineitem.hpp \
|
cropeditor/drawing/lineitem.hpp \
|
||||||
cropeditor/drawing/textitem.hpp
|
cropeditor/drawing/textitem.hpp \
|
||||||
|
colorpicker/colorpickerscene.hpp
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
cropeditor/settings/brushpenselection.ui \
|
cropeditor/settings/brushpenselection.ui \
|
||||||
|
51
colorpicker/colorpickerscene.cpp
Normal file
51
colorpicker/colorpickerscene.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "colorpickerscene.hpp"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QGraphicsEllipseItem>
|
||||||
|
#include <QGraphicsPixmapItem>
|
||||||
|
#include <QGraphicsTextItem>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
ColorPickerScene::ColorPickerScene(QPixmap *pixmap, QWidget *parentWidget)
|
||||||
|
: QGraphicsScene(), QGraphicsView(this, parentWidget) {
|
||||||
|
setFrameShape(QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
|
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||||
|
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
|
||||||
|
setCursor(QCursor(Qt::CrossCursor));
|
||||||
|
setMouseTracking(true);
|
||||||
|
|
||||||
|
pItem = addPixmap(*pixmap);
|
||||||
|
pItem->setZValue(-2);
|
||||||
|
ellipse = addEllipse(QRectF(QCursor::pos(), QSize(20, 20)), QPen(Qt::cyan), Qt::NoBrush);
|
||||||
|
QFont font("Monospace");
|
||||||
|
font.setStyleHint(QFont::Monospace);
|
||||||
|
text = addText("#hiyouu", font);
|
||||||
|
textBackground = addRect(text->boundingRect(), Qt::NoPen, QBrush(Qt::black));
|
||||||
|
text->setPos(QCursor::pos() + QPoint(25, 0));
|
||||||
|
textBackground->setPos(text->pos());
|
||||||
|
textBackground->setZValue(-1);
|
||||||
|
color = pItem->pixmap().toImage().pixelColor(QCursor::pos());
|
||||||
|
text->setPlainText(color.name());
|
||||||
|
ellipse->setBrush(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
ellipse->setRect(QRectF(event->scenePos(), QSize(20, 20)));
|
||||||
|
color = pItem->pixmap().toImage().pixelColor(event->scenePos().toPoint());
|
||||||
|
text->setPos(QCursor::pos() + QPoint(25, 0));
|
||||||
|
text->setPlainText(color.name());
|
||||||
|
textBackground->setPos(text->pos());
|
||||||
|
ellipse->setBrush(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
|
||||||
|
if (event->key() == Qt::Key_Return) QApplication::clipboard()->setText(color.name());
|
||||||
|
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
|
||||||
|
QApplication::clipboard()->setText(color.name());
|
||||||
|
close();
|
||||||
|
}
|
36
colorpicker/colorpickerscene.hpp
Normal file
36
colorpicker/colorpickerscene.hpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef COLORPICKERSCENE_HPP
|
||||||
|
#define COLORPICKERSCENE_HPP
|
||||||
|
|
||||||
|
#include <QGraphicsPixmapItem>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QGraphicsTextItem>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <screenshotutil.hpp>
|
||||||
|
|
||||||
|
class ColorPickerScene : public QGraphicsScene, public QGraphicsView {
|
||||||
|
public:
|
||||||
|
ColorPickerScene(QPixmap *pixmap, QWidget *parentWidget);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
|
||||||
|
static void showPicker() {
|
||||||
|
ColorPickerScene *s = new ColorPickerScene(screenshotutil::fullscreen(), 0);
|
||||||
|
QTimer::singleShot(0, [s] {
|
||||||
|
s->showFullScreen();
|
||||||
|
QScopedPointer<ColorPickerScene>(s);
|
||||||
|
// Before anyone asks I have 0 clue about how does this not segfault
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QColor color;
|
||||||
|
QGraphicsEllipseItem *ellipse = 0;
|
||||||
|
QGraphicsPixmapItem *pItem = 0;
|
||||||
|
QGraphicsTextItem *text;
|
||||||
|
QGraphicsRectItem *textBackground;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COLORPICKERSCENE_HPP
|
2
main.cpp
2
main.cpp
@ -3,6 +3,8 @@
|
|||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <colorpicker/colorpickerscene.hpp>
|
||||||
|
#include <screenshotutil.hpp>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <colorpicker/colorpickerscene.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <hotkeying.hpp>
|
#include <hotkeying.hpp>
|
||||||
#include <settings.hpp>
|
#include <settings.hpp>
|
||||||
@ -41,11 +42,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
QAction *shtoggle = new QAction("Show/Hide", this);
|
QAction *shtoggle = new QAction("Show/Hide", this);
|
||||||
QAction *fullscreen = new QAction("Take fullscreen shot", this);
|
QAction *fullscreen = new QAction("Take fullscreen shot", this);
|
||||||
QAction *area = new QAction("Take area shot", this);
|
QAction *area = new QAction("Take area shot", this);
|
||||||
menu->addActions({ quit, shtoggle });
|
QAction *picker = new QAction("Show color picker", this);
|
||||||
|
menu->addActions({ quit, shtoggle, picker });
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addActions({ fullscreen, area });
|
menu->addActions({ fullscreen, area });
|
||||||
connect(quit, &QAction::triggered, this, &MainWindow::quit);
|
connect(quit, &QAction::triggered, this, &MainWindow::quit);
|
||||||
connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible);
|
connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible);
|
||||||
|
connect(shtoggle, &QAction::triggered, [] { ColorPickerScene::showPicker(); });
|
||||||
connect(tray, &QSystemTrayIcon::messageClicked, this, &MainWindow::toggleVisible);
|
connect(tray, &QSystemTrayIcon::messageClicked, this, &MainWindow::toggleVisible);
|
||||||
connect(tray, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
connect(tray, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||||
if (reason == QSystemTrayIcon::DoubleClick) toggleVisible();
|
if (reason == QSystemTrayIcon::DoubleClick) toggleVisible();
|
||||||
@ -83,6 +86,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
|
|
||||||
addHotkeyItem("Fullscreen image", "fullscreen", new std::function<void()>([] { screenshotter::fullscreen(); }));
|
addHotkeyItem("Fullscreen image", "fullscreen", new std::function<void()>([] { screenshotter::fullscreen(); }));
|
||||||
addHotkeyItem("Area image", "area", new std::function<void()>([] { screenshotter::area(); }));
|
addHotkeyItem("Area image", "area", new std::function<void()>([] { screenshotter::area(); }));
|
||||||
|
addHotkeyItem("Color picker", "picker", new std::function<void()>([] { ColorPickerScene::showPicker(); }));
|
||||||
|
|
||||||
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
|
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
|
||||||
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
|
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
|
||||||
@ -181,3 +185,7 @@ void MainWindow::on_quickMode_clicked(bool checked) {
|
|||||||
void MainWindow::on_hideToTray_clicked(bool checked) {
|
void MainWindow::on_hideToTray_clicked(bool checked) {
|
||||||
settings::settings().setValue("hideOnClose", checked);
|
settings::settings().setValue("hideOnClose", checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionColor_Picker_triggered() {
|
||||||
|
ColorPickerScene::showPicker();
|
||||||
|
}
|
||||||
|
@ -25,17 +25,14 @@ class MainWindow : public QMainWindow {
|
|||||||
void on_actionArea_triggered();
|
void on_actionArea_triggered();
|
||||||
void on_uploaderList_clicked(const QModelIndex &);
|
void on_uploaderList_clicked(const QModelIndex &);
|
||||||
void on_nameScheme_textEdited(const QString &arg1);
|
void on_nameScheme_textEdited(const QString &arg1);
|
||||||
|
|
||||||
void on_delay_valueChanged(double arg1);
|
void on_delay_valueChanged(double arg1);
|
||||||
|
|
||||||
void on_hotkeys_doubleClicked(const QModelIndex &index);
|
void on_hotkeys_doubleClicked(const QModelIndex &index);
|
||||||
|
|
||||||
void on_settingsButton_clicked();
|
void on_settingsButton_clicked();
|
||||||
|
|
||||||
void on_quickMode_clicked(bool checked);
|
void on_quickMode_clicked(bool checked);
|
||||||
|
|
||||||
void on_hideToTray_clicked(bool checked);
|
void on_hideToTray_clicked(bool checked);
|
||||||
|
|
||||||
|
void on_actionColor_Picker_triggered();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
@ -136,8 +136,15 @@
|
|||||||
<addaction name="actionFullscreen"/>
|
<addaction name="actionFullscreen"/>
|
||||||
<addaction name="actionArea"/>
|
<addaction name="actionArea"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuUtilities">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Utilities</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionColor_Picker"/>
|
||||||
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuScreenshot"/>
|
<addaction name="menuScreenshot"/>
|
||||||
|
<addaction name="menuUtilities"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusBar"/>
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
<action name="actionQuit">
|
<action name="actionQuit">
|
||||||
@ -155,6 +162,11 @@
|
|||||||
<string>&Area</string>
|
<string>&Area</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionColor_Picker">
|
||||||
|
<property name="text">
|
||||||
|
<string>Color Picker</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@ -8,7 +8,10 @@
|
|||||||
|
|
||||||
void screenshotter::area() {
|
void screenshotter::area() {
|
||||||
CropEditor *editor = new CropEditor(screenshotutil::fullscreen());
|
CropEditor *editor = new CropEditor(screenshotutil::fullscreen());
|
||||||
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap *pixmap) { UploaderSingleton::inst().upload(pixmap); });
|
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap *pixmap) {
|
||||||
|
UploaderSingleton::inst().upload(pixmap);
|
||||||
|
QScopedPointer<CropEditor>(editor);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenshotter::fullscreen() {
|
void screenshotter::fullscreen() {
|
||||||
|
Loading…
Reference in New Issue
Block a user