mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-26 20:00:30 +00:00
Add initial code for the color picker
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "capturemodification.h"
|
#include "capturemodification.h"
|
||||||
#include "capturewidget.h"
|
#include "capturewidget.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
#include "capture/colorpicker.h"
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
@@ -83,8 +84,9 @@ CaptureWidget::CaptureWidget(QWidget *parent) :
|
|||||||
resize(m_screenshot.size());
|
resize(m_screenshot.size());
|
||||||
// initi interface color
|
// initi interface color
|
||||||
m_uiColor = QSettings().value("uiColor").value<QColor>();
|
m_uiColor = QSettings().value("uiColor").value<QColor>();
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
|
||||||
|
m_colorPicker = new ColorPicker(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CaptureWidget::~CaptureWidget() {
|
CaptureWidget::~CaptureWidget() {
|
||||||
@@ -148,24 +150,31 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CaptureWidget::mousePressEvent(QMouseEvent *e) {
|
void CaptureWidget::mousePressEvent(QMouseEvent *e) {
|
||||||
if (e->button() == Qt::LeftButton) {
|
if (e->button() == Qt::RightButton) {
|
||||||
m_mouseIsClicked = true;
|
m_colorPicker->move(e->pos().x()-m_colorPicker->width()/2,
|
||||||
if (m_state != Button::Type::move) {
|
e->pos().y()-m_colorPicker->height()/2);
|
||||||
m_modifications.append(CaptureModification(m_state, e->pos()));
|
m_colorPicker->show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_dragStartPoint = e->pos();
|
|
||||||
m_selectionBeforeDrag = m_selection;
|
if (e->button() == Qt::LeftButton) {
|
||||||
m_buttonHandler->hide();
|
m_mouseIsClicked = true;
|
||||||
if (!m_selection.contains(e->pos()) && !m_mouseOverHandle) {
|
if (m_state != Button::Type::move) {
|
||||||
m_newSelection = true;
|
m_modifications.append(CaptureModification(m_state, e->pos()));
|
||||||
m_selection = QRect();
|
return;
|
||||||
setCursor(Qt::CrossCursor);
|
|
||||||
} else if (m_selection.contains(e->pos())){
|
|
||||||
setCursor(Qt::ClosedHandCursor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
update();
|
m_dragStartPoint = e->pos();
|
||||||
|
m_selectionBeforeDrag = m_selection;
|
||||||
|
m_buttonHandler->hide();
|
||||||
|
if (!m_selection.contains(e->pos()) && !m_mouseOverHandle) {
|
||||||
|
m_newSelection = true;
|
||||||
|
m_selection = QRect();
|
||||||
|
setCursor(Qt::CrossCursor);
|
||||||
|
} else if (m_selection.contains(e->pos())){
|
||||||
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||||
@@ -272,6 +281,11 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
|
void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
|
if (e->button() == Qt::RightButton) {
|
||||||
|
m_colorPicker->hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_selection.isNull() && !m_buttonHandler->isVisible()) {
|
if (!m_selection.isNull() && !m_buttonHandler->isVisible()) {
|
||||||
updateSizeIndicator();
|
updateSizeIndicator();
|
||||||
m_buttonHandler->updatePosition(m_selection, rect());
|
m_buttonHandler->updatePosition(m_selection, rect());
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class QMouseEvent;
|
|||||||
class CaptureModification;
|
class CaptureModification;
|
||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class ColorPicker;
|
||||||
|
|
||||||
class CaptureWidget : public QWidget {
|
class CaptureWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -111,6 +112,7 @@ private:
|
|||||||
ButtonHandler *m_buttonHandler;
|
ButtonHandler *m_buttonHandler;
|
||||||
|
|
||||||
QColor m_uiColor;
|
QColor m_uiColor;
|
||||||
|
ColorPicker *m_colorPicker;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CAPTUREWIDGET_H
|
#endif // CAPTUREWIDGET_H
|
||||||
|
|||||||
56
capture/colorpicker.cpp
Normal file
56
capture/colorpicker.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "colorpicker.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent),
|
||||||
|
m_colorAreaSize(18) {
|
||||||
|
setMouseTracking(true);
|
||||||
|
|
||||||
|
double radius = (colorList.size()*m_colorAreaSize/1.3)/(3.141592);
|
||||||
|
resize(radius*2 + m_colorAreaSize, radius*2 + m_colorAreaSize);
|
||||||
|
double degree = 360 / (colorList.size());
|
||||||
|
double degreeAcum = degree;
|
||||||
|
|
||||||
|
QLineF baseLine = QLineF(QPoint(radius, radius), QPoint(radius*2, radius));
|
||||||
|
|
||||||
|
for (int i = 0; i<colorList.size(); ++i) {
|
||||||
|
m_colorAreaList.append(QRect(baseLine.x2(), baseLine.y2(),
|
||||||
|
m_colorAreaSize, m_colorAreaSize));
|
||||||
|
baseLine.setAngle(degreeAcum);
|
||||||
|
degreeAcum += degree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorPicker::paintEvent(QPaintEvent *) {
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
QVector<QRect> rects = handleMask();
|
||||||
|
painter.setPen(QColor(Qt::black));
|
||||||
|
for(int i = 0; i < rects.size(); ++i) {
|
||||||
|
painter.setBrush(QColor(colorList.at(i)));
|
||||||
|
painter.drawRoundRect(rects.at(i), 100, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QRect> ColorPicker::handleMask() const {
|
||||||
|
QVector<QRect> areas;
|
||||||
|
for(QRect rect: m_colorAreaList) {
|
||||||
|
areas.append(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
return areas;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<Qt::GlobalColor> ColorPicker::colorList = {
|
||||||
|
Qt::darkRed,
|
||||||
|
Qt::red,
|
||||||
|
Qt::yellow,
|
||||||
|
Qt::green,
|
||||||
|
Qt::darkGreen,
|
||||||
|
Qt::darkCyan,
|
||||||
|
Qt::blue,
|
||||||
|
Qt::cyan,
|
||||||
|
Qt::magenta,
|
||||||
|
Qt::darkMagenta
|
||||||
|
};
|
||||||
26
capture/colorpicker.h
Normal file
26
capture/colorpicker.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef COLORPICKER_H
|
||||||
|
#define COLORPICKER_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class ColorPicker : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ColorPicker(QWidget *parent = 0);
|
||||||
|
static QVector<Qt::GlobalColor> colorList;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *);
|
||||||
|
QVector<QRect> handleMask() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int m_colorAreaSize;
|
||||||
|
QVector<QRect> m_colorAreaList;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COLORPICKER_H
|
||||||
@@ -40,7 +40,8 @@ SOURCES += main.cpp\
|
|||||||
configwindow.cpp \
|
configwindow.cpp \
|
||||||
capture/screenshot.cpp \
|
capture/screenshot.cpp \
|
||||||
capture/capturewidget.cpp \
|
capture/capturewidget.cpp \
|
||||||
capture/capturemodification.cpp
|
capture/capturemodification.cpp \
|
||||||
|
capture/colorpicker.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
nativeeventfilter.h \
|
nativeeventfilter.h \
|
||||||
@@ -51,7 +52,8 @@ HEADERS += \
|
|||||||
configwindow.h \
|
configwindow.h \
|
||||||
capture/screenshot.h \
|
capture/screenshot.h \
|
||||||
capture/capturewidget.h \
|
capture/capturewidget.h \
|
||||||
capture/capturemodification.h
|
capture/capturemodification.h \
|
||||||
|
capture/colorpicker.h
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
graphics.qrc
|
graphics.qrc
|
||||||
|
|||||||
Reference in New Issue
Block a user