Skip to content

Commit c97f397

Browse files
committed
feat: integrate HSLGradientSlider for enhanced color selection in ContrastChecker
1 parent 86876b4 commit c97f397

File tree

6 files changed

+662
-427
lines changed

6 files changed

+662
-427
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(SOURCES
5050
src/BrightnessSliderWidget.cpp
5151
src/ShortcutsDialog.cpp
5252
src/ContrastChecker.cpp
53+
src/HSLGradientSlider.cpp
5354
)
5455

5556
# Headers
@@ -69,6 +70,7 @@ set(HEADERS
6970
include/BrightnessSliderWidget.h
7071
include/ShortcutsDialog.h
7172
include/ContrastChecker.h
73+
include/HSLGradientSlider.h
7274
)
7375

7476
# UI files

include/ContrastChecker.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
class QLineEdit;
88
class QLabel;
9-
class QSlider;
109
class QSpinBox;
1110
class QPushButton;
1211
class QFrame;
12+
class HSLGradientSlider;
13+
class ScreenPicker;
1314

1415
class ContrastChecker : public QDialog {
1516
Q_OBJECT
@@ -32,6 +33,9 @@ private slots:
3233
void onPickTextColor();
3334
void onPickBackgroundColor();
3435
void onSwapColors();
36+
void onTextColorPicked(const QColor &color);
37+
void onBackgroundColorPicked(const QColor &color);
38+
void onPickerError(const QString &message);
3539
void updateContrastRatio();
3640

3741
private:
@@ -45,7 +49,6 @@ private slots:
4549

4650
double calculateContrastRatio(const QColor &foreground, const QColor &background);
4751
double calculateRelativeLuminance(const QColor &color);
48-
QString getComplianceLevel(double ratio);
4952

5053
void saveGeometry();
5154
void loadGeometry();
@@ -58,17 +61,17 @@ private slots:
5861
QFrame *m_contrastPreview;
5962

6063
// Text color HSL sliders
61-
QSlider *m_textHueSlider;
62-
QSlider *m_textSatSlider;
63-
QSlider *m_textLightSlider;
64+
HSLGradientSlider *m_textHueSlider;
65+
HSLGradientSlider *m_textSatSlider;
66+
HSLGradientSlider *m_textLightSlider;
6467
QSpinBox *m_textHueSpin;
6568
QSpinBox *m_textSatSpin;
6669
QSpinBox *m_textLightSpin;
6770

6871
// Background color HSL sliders
69-
QSlider *m_bgHueSlider;
70-
QSlider *m_bgSatSlider;
71-
QSlider *m_bgLightSlider;
72+
HSLGradientSlider *m_bgHueSlider;
73+
HSLGradientSlider *m_bgSatSlider;
74+
HSLGradientSlider *m_bgLightSlider;
7275
QSpinBox *m_bgHueSpin;
7376
QSpinBox *m_bgSatSpin;
7477
QSpinBox *m_bgLightSpin;
@@ -77,6 +80,9 @@ private slots:
7780
QPushButton *m_pickBgColorBtn;
7881
QPushButton *m_swapColorsBtn;
7982

83+
ScreenPicker *m_textScreenPicker;
84+
ScreenPicker *m_bgScreenPicker;
85+
8086
// Contrast ratio display
8187
QLabel *m_ratioLabel;
8288
QLabel *m_normalTextLabel;

include/HSLGradientSlider.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef GRADIENTSLIDER_H
2+
#define GRADIENTSLIDER_H
3+
4+
#include <QSlider>
5+
#include <QColor>
6+
7+
class HSLGradientSlider : public QSlider {
8+
Q_OBJECT
9+
10+
public:
11+
enum GradientType {
12+
Hue,
13+
Saturation,
14+
Lightness
15+
};
16+
17+
explicit HSLGradientSlider(Qt::Orientation orientation, GradientType type, QWidget *parent = nullptr);
18+
19+
void setGradientType(GradientType type);
20+
void setBaseColor(const QColor &color); // For saturation and lightness gradients
21+
22+
protected:
23+
void paintEvent(QPaintEvent *event) override;
24+
25+
private:
26+
GradientType m_gradientType;
27+
QColor m_baseColor;
28+
29+
QLinearGradient createHueGradient(const QRect &rect) const;
30+
QLinearGradient createSaturationGradient(const QRect &rect) const;
31+
QLinearGradient createLightnessGradient(const QRect &rect) const;
32+
};
33+
34+
#endif // GRADIENTSLIDER_H

0 commit comments

Comments
 (0)