Code refactoring - change code style to the new clang-format rules
This commit is contained in:
@@ -18,10 +18,12 @@
|
||||
#include "colorpicker.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/globalvalues.h"
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent) {
|
||||
ColorPicker::ColorPicker(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
ConfigHandler config;
|
||||
m_colorList = config.getUserColors();
|
||||
m_colorAreaSize = GlobalValues::buttonBaseSize() * 0.6;
|
||||
@@ -39,32 +41,37 @@ ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent) {
|
||||
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) {
|
||||
m_colorAreaList.append(QRect(baseLine.x2(), baseLine.y2(),
|
||||
m_colorAreaSize, m_colorAreaSize));
|
||||
m_colorAreaList.append(QRect(
|
||||
baseLine.x2(), baseLine.y2(), m_colorAreaSize, m_colorAreaSize));
|
||||
baseLine.setAngle(degreeAcum);
|
||||
degreeAcum += degree;
|
||||
}
|
||||
}
|
||||
|
||||
QColor ColorPicker::drawColor() {
|
||||
QColor ColorPicker::drawColor()
|
||||
{
|
||||
return m_drawColor;
|
||||
}
|
||||
|
||||
void ColorPicker::show() {
|
||||
void ColorPicker::show()
|
||||
{
|
||||
grabMouse();
|
||||
QWidget::show();
|
||||
}
|
||||
|
||||
void ColorPicker::hide() {
|
||||
void ColorPicker::hide()
|
||||
{
|
||||
releaseMouse();
|
||||
QWidget::hide();
|
||||
}
|
||||
|
||||
void ColorPicker::paintEvent(QPaintEvent *) {
|
||||
void ColorPicker::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
@@ -91,15 +98,15 @@ void ColorPicker::paintEvent(QPaintEvent *) {
|
||||
// draw preset color
|
||||
painter.setBrush(QColor(m_colorList.at(i)));
|
||||
painter.drawRoundRect(rects.at(i), 100, 100);
|
||||
}
|
||||
else {
|
||||
} 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
|
||||
// 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) {
|
||||
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);
|
||||
@@ -120,7 +127,8 @@ void ColorPicker::paintEvent(QPaintEvent *) {
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPicker::mouseMoveEvent(QMouseEvent *e) {
|
||||
void ColorPicker::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
for (int i = 0; i < m_colorList.size(); ++i) {
|
||||
if (m_colorAreaList.at(i).contains(e->pos())) {
|
||||
m_drawColor = m_colorList.at(i);
|
||||
@@ -131,9 +139,10 @@ void ColorPicker::mouseMoveEvent(QMouseEvent *e) {
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QRect> ColorPicker::handleMask() const {
|
||||
QVector<QRect> ColorPicker::handleMask() const
|
||||
{
|
||||
QVector<QRect> areas;
|
||||
for (const QRect &rect: m_colorAreaList) {
|
||||
for (const QRect& rect : m_colorAreaList) {
|
||||
areas.append(rect);
|
||||
}
|
||||
return areas;
|
||||
|
||||
Reference in New Issue
Block a user