mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Add initial code for the color picker
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "capturemodification.h"
|
||||
#include "capturewidget.h"
|
||||
#include "button.h"
|
||||
#include "capture/colorpicker.h"
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
#include <QGuiApplication>
|
||||
@@ -83,8 +84,9 @@ CaptureWidget::CaptureWidget(QWidget *parent) :
|
||||
resize(m_screenshot.size());
|
||||
// initi interface color
|
||||
m_uiColor = QSettings().value("uiColor").value<QColor>();
|
||||
|
||||
show();
|
||||
|
||||
m_colorPicker = new ColorPicker(this);
|
||||
}
|
||||
|
||||
CaptureWidget::~CaptureWidget() {
|
||||
@@ -148,24 +150,31 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
|
||||
}
|
||||
|
||||
void CaptureWidget::mousePressEvent(QMouseEvent *e) {
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
m_mouseIsClicked = true;
|
||||
if (m_state != Button::Type::move) {
|
||||
m_modifications.append(CaptureModification(m_state, e->pos()));
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (e->button() == Qt::RightButton) {
|
||||
m_colorPicker->move(e->pos().x()-m_colorPicker->width()/2,
|
||||
e->pos().y()-m_colorPicker->height()/2);
|
||||
m_colorPicker->show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
m_mouseIsClicked = true;
|
||||
if (m_state != Button::Type::move) {
|
||||
m_modifications.append(CaptureModification(m_state, e->pos()));
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
@@ -272,6 +281,11 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
}
|
||||
|
||||
void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||
if (e->button() == Qt::RightButton) {
|
||||
m_colorPicker->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_selection.isNull() && !m_buttonHandler->isVisible()) {
|
||||
updateSizeIndicator();
|
||||
m_buttonHandler->updatePosition(m_selection, rect());
|
||||
|
||||
@@ -35,6 +35,7 @@ class QMouseEvent;
|
||||
class CaptureModification;
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class ColorPicker;
|
||||
|
||||
class CaptureWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
@@ -111,6 +112,7 @@ private:
|
||||
ButtonHandler *m_buttonHandler;
|
||||
|
||||
QColor m_uiColor;
|
||||
ColorPicker *m_colorPicker;
|
||||
};
|
||||
|
||||
#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 \
|
||||
capture/screenshot.cpp \
|
||||
capture/capturewidget.cpp \
|
||||
capture/capturemodification.cpp
|
||||
capture/capturemodification.cpp \
|
||||
capture/colorpicker.cpp
|
||||
|
||||
HEADERS += \
|
||||
nativeeventfilter.h \
|
||||
@@ -51,7 +52,8 @@ HEADERS += \
|
||||
configwindow.h \
|
||||
capture/screenshot.h \
|
||||
capture/capturewidget.h \
|
||||
capture/capturemodification.h
|
||||
capture/capturemodification.h \
|
||||
capture/colorpicker.h
|
||||
|
||||
RESOURCES += \
|
||||
graphics.qrc
|
||||
|
||||
Reference in New Issue
Block a user