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/drawing/pathitem.cpp \
|
||||
cropeditor/drawing/lineitem.cpp \
|
||||
cropeditor/drawing/textitem.cpp
|
||||
cropeditor/drawing/textitem.cpp \
|
||||
colorpicker/colorpickerscene.cpp
|
||||
|
||||
HEADERS += mainwindow.hpp \
|
||||
cropeditor/cropeditor.hpp \
|
||||
@ -70,7 +71,8 @@ HEADERS += mainwindow.hpp \
|
||||
cropeditor/settings/blurdialog.hpp \
|
||||
cropeditor/drawing/pathitem.hpp \
|
||||
cropeditor/drawing/lineitem.hpp \
|
||||
cropeditor/drawing/textitem.hpp
|
||||
cropeditor/drawing/textitem.hpp \
|
||||
colorpicker/colorpickerscene.hpp
|
||||
|
||||
FORMS += mainwindow.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 <QTimer>
|
||||
#include <QtGlobal>
|
||||
#include <colorpicker/colorpickerscene.hpp>
|
||||
#include <screenshotutil.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
bool verbose = false;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <QStatusBar>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <colorpicker/colorpickerscene.hpp>
|
||||
#include <functional>
|
||||
#include <hotkeying.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 *fullscreen = new QAction("Take fullscreen 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->addActions({ fullscreen, area });
|
||||
connect(quit, &QAction::triggered, this, &MainWindow::quit);
|
||||
connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible);
|
||||
connect(shtoggle, &QAction::triggered, [] { ColorPickerScene::showPicker(); });
|
||||
connect(tray, &QSystemTrayIcon::messageClicked, this, &MainWindow::toggleVisible);
|
||||
connect(tray, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||
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("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->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) {
|
||||
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_uploaderList_clicked(const QModelIndex &);
|
||||
void on_nameScheme_textEdited(const QString &arg1);
|
||||
|
||||
void on_delay_valueChanged(double arg1);
|
||||
|
||||
void on_hotkeys_doubleClicked(const QModelIndex &index);
|
||||
|
||||
void on_settingsButton_clicked();
|
||||
|
||||
void on_quickMode_clicked(bool checked);
|
||||
|
||||
void on_hideToTray_clicked(bool checked);
|
||||
|
||||
void on_actionColor_Picker_triggered();
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
@ -136,8 +136,15 @@
|
||||
<addaction name="actionFullscreen"/>
|
||||
<addaction name="actionArea"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuUtilities">
|
||||
<property name="title">
|
||||
<string>&Utilities</string>
|
||||
</property>
|
||||
<addaction name="actionColor_Picker"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuScreenshot"/>
|
||||
<addaction name="menuUtilities"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="actionQuit">
|
||||
@ -155,6 +162,11 @@
|
||||
<string>&Area</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionColor_Picker">
|
||||
<property name="text">
|
||||
<string>Color Picker</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
@ -8,7 +8,10 @@
|
||||
|
||||
void screenshotter::area() {
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user