diff --git a/capture/capturewidget.cpp b/capture/capturewidget.cpp index 06e84204..c6f459d1 100644 --- a/capture/capturewidget.cpp +++ b/capture/capturewidget.cpp @@ -25,6 +25,7 @@ #include "capturemodification.h" #include "capturewidget.h" #include "button.h" +#include "capture/colorpicker.h" #include #include #include @@ -83,8 +84,9 @@ CaptureWidget::CaptureWidget(QWidget *parent) : resize(m_screenshot.size()); // initi interface color m_uiColor = QSettings().value("uiColor").value(); - 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()); diff --git a/capture/capturewidget.h b/capture/capturewidget.h index 7e0bbd8a..28f9adaa 100644 --- a/capture/capturewidget.h +++ b/capture/capturewidget.h @@ -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 diff --git a/capture/colorpicker.cpp b/capture/colorpicker.cpp new file mode 100644 index 00000000..be6f00b8 --- /dev/null +++ b/capture/colorpicker.cpp @@ -0,0 +1,56 @@ +#include "colorpicker.h" +#include +#include + +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 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 ColorPicker::handleMask() const { + QVector areas; + for(QRect rect: m_colorAreaList) { + areas.append(rect); + } + + return areas; +} + +QVector ColorPicker::colorList = { + Qt::darkRed, + Qt::red, + Qt::yellow, + Qt::green, + Qt::darkGreen, + Qt::darkCyan, + Qt::blue, + Qt::cyan, + Qt::magenta, + Qt::darkMagenta +}; diff --git a/capture/colorpicker.h b/capture/colorpicker.h new file mode 100644 index 00000000..4ecf67a1 --- /dev/null +++ b/capture/colorpicker.h @@ -0,0 +1,26 @@ +#ifndef COLORPICKER_H +#define COLORPICKER_H + +#include + +class ColorPicker : public QWidget +{ + Q_OBJECT +public: + explicit ColorPicker(QWidget *parent = 0); + static QVector colorList; + +protected: + void paintEvent(QPaintEvent *); + QVector handleMask() const; + +signals: + +public slots: + +private: + const int m_colorAreaSize; + QVector m_colorAreaList; +}; + +#endif // COLORPICKER_H diff --git a/flameshot.pro b/flameshot.pro index ecca4541..c5da78f6 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -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