Skip to content

Commit

Permalink
Theme: double slider UX #166
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Aug 30, 2024
1 parent 47902cc commit 10a4c82
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/core/themesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const QColor ThemeSupport::getThemeHighlightColor(int alpha)
return getQColor(104, 144, 206, alpha);
}

const QColor ThemeSupport::getThemeHighlightDarkerColor(int alpha)
{
return getQColor(53, 101, 176, alpha);
}

const QColor ThemeSupport::getThemeHighlightAlternativeColor(int alpha)
{
return getQColor(167, 185, 222, alpha);
Expand Down
1 change: 1 addition & 0 deletions src/core/themesupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CORE_EXPORT ThemeSupport
static const QColor getThemeBaseDarkerColor(int alpha = 255);
static const QColor getThemeAlternateColor(int alpha = 255);
static const QColor getThemeHighlightColor(int alpha = 255);
static const QColor getThemeHighlightDarkerColor(int alpha = 255);
static const QColor getThemeHighlightAlternativeColor(int alpha = 255);
static const QColor getThemeHighlightSelectedColor(int alpha = 255);
static SkColor getThemeHighlightSkColor(int alpha = 255);
Expand Down
33 changes: 31 additions & 2 deletions src/ui/widgets/qdoubleslider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void SliderEdit::keyPressEvent(QKeyEvent* e) {
void SliderEdit::hideEvent(QHideEvent* e) {
releaseMouse();
unsetCursor();
emit hoverChanged();
QLineEdit::hideEvent(e);
}

Expand All @@ -75,6 +76,12 @@ void SliderEdit::showEvent(QShowEvent* e) {
QLineEdit::showEvent(e);
}

void SliderEdit::leaveEvent(QEvent *e)
{
emit hoverChanged();
QLineEdit::leaveEvent(e);
}

void SliderEdit::lineEditingFinished() {
deselect();
clearFocus();
Expand Down Expand Up @@ -104,6 +111,12 @@ QDoubleSlider::QDoubleSlider(const qreal minVal, const qreal maxVal,
mLineEdit = new SliderEdit(this);
mLineEdit->hide();

connect(mLineEdit, &SliderEdit::hoverChanged,
this, [this] {
mHovered = false;
unsetCursor();
update();
});
connect(mLineEdit, &SliderEdit::valueSet,
this, [this](const qreal value) {
const qreal clampedValue = clamped(value);
Expand Down Expand Up @@ -210,7 +223,8 @@ void QDoubleSlider::paint(QPainter *p,
p->setRenderHint(QPainter::Antialiasing);
QRectF boundingRect = rect().adjusted(1, 1, -1, -1);
p->setPen(Qt::NoPen);
p->setBrush(allFill);
if (mHovered) { p->setBrush(ThemeSupport::getThemeBaseDarkerColor()); }
else { p->setBrush(allFill); }
if(mLeftNeighbour) {
p->setClipRect(width()/2, 0, width()/2, height());
} else if(mRightNeighbour) {
Expand All @@ -232,7 +246,8 @@ void QDoubleSlider::paint(QPainter *p,
p->setPen(Qt::NoPen);
const qreal valFrac = (mValue - mMinValue)/(mMaxValue - mMinValue);
const qreal valWidth = clamp(valFrac*width(), 0, width() - 3);
p->setBrush(sliderFill);
if (mHovered) { p->setBrush(ThemeSupport::getThemeHighlightDarkerColor()); }
else { p->setBrush(sliderFill); }
const qreal heightRemoval = qMax(0., eSizesUI::widget/2 - valWidth)*0.5;
p->drawRoundedRect(QRectF(1, 1, valWidth, height() - 2).
adjusted(0, heightRemoval,
Expand Down Expand Up @@ -405,3 +420,17 @@ void QDoubleSlider::mouseMoveEvent(QMouseEvent *event) {
cursor().setPos(mGlobalPressPos);
Document::sInstance->updateScenes();
}

void QDoubleSlider::enterEvent(QEvent *)
{
mHovered = true;
setCursor(Qt::SizeHorCursor);
update();
}

void QDoubleSlider::leaveEvent(QEvent *)
{
mHovered = false;
unsetCursor();
update();
}
7 changes: 7 additions & 0 deletions src/ui/widgets/qdoubleslider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class UI_EXPORT SliderEdit : public QLineEdit {
SliderEdit(QWidget* const parent);
signals:
void valueSet(const qreal value);
void hoverChanged();
protected:
void mousePressEvent(QMouseEvent* e) override;
void keyPressEvent(QKeyEvent *e) override;
void hideEvent(QHideEvent *e) override;
void showEvent(QShowEvent *e) override;
void leaveEvent(QEvent *e) override;
private:
void lineEditingFinished();

Expand Down Expand Up @@ -107,6 +109,9 @@ class UI_EXPORT QDoubleSlider : public QWidget {
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);

void enterEvent(QEvent *);
void leaveEvent(QEvent *);

void paint(QPainter *p,
const QColor &allFill,
const QColor &sliderFill,
Expand Down Expand Up @@ -151,6 +156,8 @@ class UI_EXPORT QDoubleSlider : public QWidget {
qreal mLastValue;
bool mShowValueSlider = true;
bool mAutoAdjustWidth = true;

bool mHovered = false;
};

#endif // QDOUBLESLIDER_H

0 comments on commit 10a4c82

Please # to comment.