Add more colors and custom color item

This commit is contained in:
Yuriy Puchkov
2020-09-07 17:44:18 +03:00
parent eaa28b1da2
commit 3f708f3160
26 changed files with 638 additions and 433 deletions

View File

@@ -189,7 +189,10 @@ QPixmap CaptureWidget::pixmap() {
}
void CaptureWidget::deleteToolwidgetOrClose() {
if (m_toolWidget) {
if(m_panel->isVisible()){
m_panel->hide();
}
else if (m_toolWidget) {
m_toolWidget->deleteLater();
m_toolWidget = nullptr;
} else {
@@ -273,8 +276,8 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
void CaptureWidget::mousePressEvent(QMouseEvent *e) {
if (e->button() == Qt::RightButton) {
m_rightClick = true;
m_colorPicker->move(e->pos().x()-m_colorPicker->width()/2,
e->pos().y()-m_colorPicker->height()/2);
m_colorPicker->move(e->pos().x() - m_colorPicker->width() / 2,
e->pos().y() - m_colorPicker->height() / 2);
m_colorPicker->raise();
m_colorPicker->show();
} else if (e->button() == Qt::LeftButton) {
@@ -431,6 +434,9 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
if (e->button() == Qt::RightButton || m_colorPicker->isVisible()) {
m_colorPicker->hide();
m_rightClick = false;
if(!m_context.color.isValid()) {
m_panel->show();
}
// when we end the drawing we have to register the last point and
//add the temp modification to the list of modifications
} else if (m_mouseIsClicked && m_activeTool) {
@@ -559,7 +565,7 @@ void CaptureWidget::initPanel() {
panelRect = QGuiApplication::primaryScreen()->geometry();
}
panelRect.moveTo(mapFromGlobal(panelRect.topLeft()));
panelRect.setWidth(m_colorPicker->width() * 3);
panelRect.setWidth(m_colorPicker->width() * 1.5);
m_panel->setGeometry(panelRect);
SidePanelWidget *sidePanel =
@@ -713,8 +719,10 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r) {
void CaptureWidget::setDrawColor(const QColor &c) {
m_context.color = c;
ConfigHandler().setDrawColor(m_context.color);
emit colorChanged(c);
if(m_context.color.isValid()) {
ConfigHandler().setDrawColor(m_context.color);
emit colorChanged(c);
}
}
void CaptureWidget::setDrawThickness(const int &t)

View File

@@ -32,17 +32,17 @@ ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent) {
// extraSize represents the extra space needed for the highlight of the
// selected color.
const int extraSize = 6;
double radius = (m_colorList.size()*m_colorAreaSize/1.3)/(3.141592);
resize(radius*2 + m_colorAreaSize + extraSize,
radius*2 + m_colorAreaSize+ extraSize);
double radius = (m_colorList.size() * m_colorAreaSize / 1.3) / 3.141592;
resize(radius * 2 + m_colorAreaSize + extraSize,
radius * 2 + m_colorAreaSize + extraSize);
double degree = 360 / (m_colorList.size());
double degreeAcum = degree;
// this line is the radius of the circle which will be rotated to add
// the color components.
QLineF baseLine = QLineF(QPoint(radius+extraSize/2, radius+extraSize/2),
QPoint(radius*2, radius));
QLineF baseLine = QLineF(QPoint(radius + extraSize / 2, radius+extraSize / 2),
QPoint(radius * 2, radius));
for (int i = 0; i<m_colorList.size(); ++i) {
for (int i = 0; i < m_colorList.size(); ++i) {
m_colorAreaList.append(QRect(baseLine.x2(), baseLine.y2(),
m_colorAreaSize, m_colorAreaSize));
baseLine.setAngle(degreeAcum);
@@ -85,8 +85,38 @@ void ColorPicker::paintEvent(QPaintEvent *) {
painter.drawRoundRect(highlight, 100, 100);
painter.setPen(QColor(Qt::black));
}
painter.setBrush(QColor(m_colorList.at(i)));
painter.drawRoundRect(rects.at(i), 100, 100);
// draw available colors
if (m_colorList.at(i).isValid()) {
// draw preset color
painter.setBrush(QColor(m_colorList.at(i)));
painter.drawRoundRect(rects.at(i), 100, 100);
}
else {
// draw rainbow (part) for custom color
QRect lastRect = rects.at(i);
int nStep = 1;
int nSteps = lastRect.height() / nStep;
// 0.02 - start rainbow color, 0.33 - end rainbow color from range: 0.0 - 1.0
float h = 0.02;
for (int radius = nSteps; radius > 0; radius -= nStep*2) {
// calculate color
float fHStep = (0.33 - h) / (nSteps / nStep / 2);
QColor color = QColor::fromHslF(h, 0.95, 0.5);
// set color and draw circle
painter.setPen(color);
painter.setBrush(color);
painter.drawRoundRect(lastRect, 100, 100);
// set next color, circle geometry
h += fHStep;
lastRect.setX(lastRect.x() + nStep);
lastRect.setY(lastRect.y() + nStep);
lastRect.setHeight(lastRect.height() - nStep);
lastRect.setWidth(lastRect.width() - nStep);
}
}
}
}

View File

@@ -7,7 +7,6 @@
#include <QPixmap>
#include <QLabel>
#include <QScrollArea>
#include <QDebug>
#include <QFileInfo>
#include <QDateTime>
#include <QPushButton>

View File

@@ -21,6 +21,7 @@
#include <QTimer>
#include <QScrollArea>
#include <QWheelEvent>
#include <QPushButton>
UtilityPanel::UtilityPanel(QWidget *parent) : QWidget(parent) {
initInternalPanel();
@@ -63,18 +64,29 @@ void UtilityPanel::pushWidget(QWidget *w) {
m_layout->addWidget(w);
}
void UtilityPanel::show() {
setAttribute(Qt::WA_TransparentForMouseEvents, false);
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
m_internalPanel->show();
m_showAnimation->start();
QWidget::show();
}
void UtilityPanel::hide() {
setAttribute(Qt::WA_TransparentForMouseEvents);
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));
m_hideAnimation->start();
m_internalPanel->hide();
QWidget::hide();
}
void UtilityPanel::toggle() {
if (m_internalPanel->isHidden()) {
setAttribute(Qt::WA_TransparentForMouseEvents, false);
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
m_internalPanel->show();
m_showAnimation->start();
show();
} else {
setAttribute(Qt::WA_TransparentForMouseEvents);
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));
m_hideAnimation->start();
hide();
}
}
@@ -95,4 +107,13 @@ void UtilityPanel::initInternalPanel() {
m_internalPanel->setStyleSheet(QStringLiteral("QScrollArea {background-color: %1}")
.arg(bgColor.name()));
m_internalPanel->hide();
m_hide = new QPushButton();
m_hide->setText(tr("Hide"));
m_upLayout->addWidget(m_hide);
connect(m_hide, SIGNAL(clicked()), this, SLOT(slotHidePanel()));
}
void UtilityPanel::slotHidePanel() {
hide();
}

View File

@@ -23,6 +23,7 @@
class QVBoxLayout;
class QPropertyAnimation;
class QScrollArea;
class QPushButton;
class UtilityPanel : public QWidget {
Q_OBJECT
@@ -33,6 +34,8 @@ public:
void addToolWidget(QWidget *w);
void clearToolWidget();
void pushWidget(QWidget *w);
void hide();
void show();
signals:
void mouseEnter();
@@ -40,6 +43,7 @@ signals:
public slots:
void toggle();
void slotHidePanel();
private:
void initInternalPanel();
@@ -50,4 +54,5 @@ private:
QVBoxLayout *m_layout;
QPropertyAnimation *m_showAnimation;
QPropertyAnimation *m_hideAnimation;
QPushButton *m_hide;
};