Improve Colorpicker (#2403)
* Fix * update preset functionality added * dynamic radius * added drag to swap * Refactor * Fix Bug
This commit is contained in:
@@ -21,7 +21,6 @@ target_sources(
|
||||
uploadlineitem.h
|
||||
updatenotificationwidget.h
|
||||
colorpickerwidget.h
|
||||
colorspinbox.h
|
||||
imguploaddialog.h
|
||||
capture/capturetoolobjects.h
|
||||
)
|
||||
@@ -39,7 +38,6 @@ target_sources(
|
||||
uploadlineitem.cpp
|
||||
updatenotificationwidget.cpp
|
||||
colorpickerwidget.cpp
|
||||
colorspinbox.cpp
|
||||
imguploaddialog.cpp
|
||||
capture/capturetoolobjects.cpp
|
||||
)
|
||||
|
||||
@@ -122,7 +122,8 @@ void ColorPickerWidget::initColorPicker()
|
||||
// extraSize represents the extra space needed for the highlight of the
|
||||
// selected color.
|
||||
const int extraSize = 6;
|
||||
double radius = GlobalValues::buttonBaseSize() * 2;
|
||||
const double slope = 3;
|
||||
double radius = slope * m_colorList.size() + GlobalValues::buttonBaseSize();
|
||||
setMinimumSize(radius * 2 + m_colorAreaSize + extraSize,
|
||||
radius * 2 + m_colorAreaSize + extraSize);
|
||||
resize(radius * 2 + m_colorAreaSize + extraSize,
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2022 Dearsh Oberoi
|
||||
|
||||
#include "src/widgets/colorspinbox.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
|
||||
ColorSpinBox::ColorSpinBox(QWidget* parent)
|
||||
: QSpinBox(parent)
|
||||
{
|
||||
initColorSpinbox();
|
||||
}
|
||||
|
||||
int ColorSpinBox::valueFromText(const QString& text) const
|
||||
{
|
||||
if (!QColor::isValidColor(text)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const QColor color = QColor(text);
|
||||
|
||||
for (int i = 1; i < m_colorList.size(); ++i) {
|
||||
if (m_colorList.at(i) == color) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString ColorSpinBox::textFromValue(int value) const
|
||||
{
|
||||
return m_colorList[value].name(QColor::HexRgb);
|
||||
}
|
||||
|
||||
void ColorSpinBox::initColorSpinbox()
|
||||
{
|
||||
ConfigHandler config;
|
||||
m_colorList = config.userColors();
|
||||
|
||||
setRange(1, m_colorList.size() - 1);
|
||||
setWrapping(true);
|
||||
}
|
||||
|
||||
void ColorSpinBox::updateWidget()
|
||||
{
|
||||
initColorSpinbox();
|
||||
update();
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2022 Dearsh Oberoi
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QSpinBox>
|
||||
|
||||
class ColorSpinBox : public QSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ColorSpinBox(QWidget* parent = nullptr);
|
||||
void updateWidget();
|
||||
|
||||
protected:
|
||||
int valueFromText(const QString& text) const override;
|
||||
QString textFromValue(int value) const override;
|
||||
|
||||
private:
|
||||
void initColorSpinbox();
|
||||
|
||||
QVector<QColor> m_colorList;
|
||||
};
|
||||
Reference in New Issue
Block a user