summaryrefslogtreecommitdiffstats
path: root/src/widget
diff options
context:
space:
mode:
authorBe <be@mixxx.org>2019-11-20 20:57:15 -0600
committerGitHub <noreply@github.com>2019-11-20 20:57:15 -0600
commit35da91b786eb7979d4cacf1c7e650978c33ea499 (patch)
tree8141114976665c20f477577c462d70dc8f4d5f93 /src/widget
parent7b1f4d106b14b5be9bee1a2e3d192c07a5ec5055 (diff)
parent7c699b7b69cfb661d51018ebdfeb7720e52bd506 (diff)
Merge pull request #2353 from daschuer/lp1850644
Lp1850644: Restore slider nature of WOverview
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/colormenu.cpp81
-rw-r--r--src/widget/colormenu.h20
-rw-r--r--src/widget/cuemenu.cpp10
-rw-r--r--src/widget/cuemenu.h7
-rw-r--r--src/widget/woverview.cpp138
-rw-r--r--src/widget/woverview.h19
-rw-r--r--src/widget/wtracktableview.cpp2
-rw-r--r--src/widget/wwidget.cpp28
-rw-r--r--src/widget/wwidget.h19
9 files changed, 233 insertions, 91 deletions
diff --git a/src/widget/colormenu.cpp b/src/widget/colormenu.cpp
index 543b271084..1ceabc888f 100644
--- a/src/widget/colormenu.cpp
+++ b/src/widget/colormenu.cpp
@@ -1,39 +1,78 @@
#include "widget/colormenu.h"
+
#include "util/color/color.h"
-ColorMenu::ColorMenu(QWidget *parent)
- : QMenu(parent) {
+ColorMenu::ColorMenu(QWidget* parent)
+ : QMenu(parent), m_pColorDialog(new QColorDialog(this)) {
// If another title would be more appropriate in some context, setTitle
// can be called again after construction.
setTitle(tr("Set color"));
- for (const auto& pColor : Color::kPredefinedColorsSet.allColors) {
- if (*pColor == *Color::kPredefinedColorsSet.noColor) {
- continue;
- }
+ useColorPalette(ColorPalette::mixxxHotcuesPalette);
+
+ connect(m_pColorDialog,
+ &QColorDialog::colorSelected,
+ this,
+ [this](const QColor& newColor) {
+ if (newColor.isValid()) {
+ emit(colorPicked(newColor));
+ }
+ });
+}
+
+void ColorMenu::useColorPalette(const ColorPalette& colorPalette) {
+ clear();
+ m_pActionGroup = new QActionGroup(this);
+ m_pActionGroup->setExclusive(true);
+
+ createPaletteColorsActions(colorPalette);
+ createColorPickerAction();
+}
- QAction* pColorAction = new QAction(pColor->m_sDisplayName, this);
+void ColorMenu::setCurrentColor(QColor currentColor) {
+ m_currentColor = currentColor;
+ selectCurrentColorAction(currentColor);
+}
+
+void ColorMenu::openColorDialog() {
+ m_pColorDialog->setCurrentColor(m_currentColor);
+ m_pColorDialog->open();
+}
+
+void ColorMenu::createPaletteColorsActions(const ColorPalette& colorPalette) {
+ for (const auto& color : colorPalette.m_colorList) {
+ QAction* pColorAction = new QAction(m_pActionGroup);
QPixmap pixmap(80, 80);
- pixmap.fill(pColor->m_defaultRgba);
+ pixmap.fill(color);
pColorAction->setIcon(QIcon(pixmap));
+ pColorAction->setCheckable(true);
+ pColorAction->setData(color);
- m_pColorActions.insert(pColor, pColorAction);
addAction(pColorAction);
- connect(pColorAction, &QAction::triggered, this, [pColor, this]() {
- emit(colorPicked(pColor));
+ connect(pColorAction, &QAction::triggered, this, [color, this]() {
+ emit(colorPicked(color));
});
}
}
-void ColorMenu::useColorSet(PredefinedColorsRepresentation* pColorRepresentation) {
- QMapIterator<PredefinedColorPointer, QAction*> i(m_pColorActions);
- while (i.hasNext()) {
- i.next();
- QPixmap pixmap(80, 80);
- if (pColorRepresentation == nullptr) {
- pixmap.fill(i.key()->m_defaultRgba);
- } else {
- pixmap.fill(pColorRepresentation->representationFor(i.key()));
+void ColorMenu::createColorPickerAction() {
+ m_pColorPickerAction = new QAction(m_pActionGroup);
+ m_pColorPickerAction->setText(tr("Other") + "…");
+ m_pColorPickerAction->setCheckable(true);
+ addAction(m_pColorPickerAction);
+ connect(m_pColorPickerAction,
+ &QAction::triggered,
+ this,
+ &ColorMenu::openColorDialog);
+}
+
+void ColorMenu::selectCurrentColorAction(const QColor& currentColor) const {
+ for (QAction* pAction : actions()) {
+ QColor color = pAction->data().value<QColor>();
+ // Other color action is the last one, if we find it, we didn't
+ // matched to any color action.
+ if (color == currentColor || pAction == m_pColorPickerAction) {
+ pAction->setChecked(true);
+ return;
}
- i.value()->setIcon(QIcon(pixmap));
}
}
diff --git a/src/widget/colormenu.h b/src/widget/colormenu.h
index 4c82943cbb..e661a8996f 100644
--- a/src/widget/colormenu.h
+++ b/src/widget/colormenu.h
@@ -1,19 +1,31 @@
#pragma once
+#include <QColorDialog>
#include <QMenu>
-#include "util/color/color.h"
+#include "util/color/colorpalette.h"
class ColorMenu : public QMenu {
Q_OBJECT
public:
ColorMenu(QWidget *parent = nullptr);
- void useColorSet(PredefinedColorsRepresentation* pColorRepresentation);
+ void useColorPalette(const ColorPalette& colorPalette);
+ void setCurrentColor(QColor currentColor);
signals:
- void colorPicked(PredefinedColorPointer pColor);
+ void colorPicked(QColor pColor);
+
+ private slots:
+ void openColorDialog();
private:
- QMap<PredefinedColorPointer, QAction*> m_pColorActions;
+ void createPaletteColorsActions(const ColorPalette& colorPalette);
+ void createColorPickerAction();
+ void selectCurrentColorAction(const QColor& currentColor) const;
+
+ QColor m_currentColor;
+ QAction* m_pColorPickerAction;
+ QActionGroup* m_pActionGroup;
+ QColorDialog* m_pColorDialog;
};
diff --git a/src/widget/cuemenu.cpp b/src/widget/cuemenu.cpp
index b9d62a3091..53d88736e8 100644
--- a/src/widget/cuemenu.cpp
+++ b/src/widget/cuemenu.cpp
@@ -37,14 +37,8 @@ void CueMenu::slotEditLabel() {
}
}
-void CueMenu::slotChangeCueColor(PredefinedColorPointer pColor) {
- VERIFY_OR_DEBUG_ASSERT(m_pCue != nullptr) {
- return;
- }
- VERIFY_OR_DEBUG_ASSERT(pColor != nullptr) {
- return;
- }
- m_pCue->setColor(pColor);
+void CueMenu::slotChangeCueColor(QColor color) {
+ m_pCue->setColor(color);
}
void CueMenu::slotRemoveCue() {
diff --git a/src/widget/cuemenu.h b/src/widget/cuemenu.h
index 3802292e44..5bf1a08064 100644
--- a/src/widget/cuemenu.h
+++ b/src/widget/cuemenu.h
@@ -14,22 +14,23 @@ class CueMenu : public QMenu {
void setCue(CuePointer pCue) {
m_pCue = pCue;
+ m_pColorMenu->setCurrentColor(m_pCue->getColor());
}
void setTrack(TrackPointer pTrack) {
m_pTrack = pTrack;
}
- void useColorSet(PredefinedColorsRepresentation* pColorRepresentation) {
+ void useColorSet(const ColorPalette& colorPalette) {
if (m_pColorMenu != nullptr) {
- m_pColorMenu->useColorSet(pColorRepresentation);
+ m_pColorMenu->useColorPalette(colorPalette);
}
}
private slots:
void slotEditLabel();
void slotRemoveCue();
- void slotChangeCueColor(PredefinedColorPointer pColor);
+ void slotChangeCueColor(QColor color);
private:
CuePointer m_pCue;
diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp
index aa24b3ecf8..792ba94447 100644
--- a/src/widget/woverview.cpp
+++ b/src/widget/woverview.cpp
@@ -25,6 +25,7 @@
#include "control/controlproxy.h"
#include "engine/engine.h"
#include "mixer/playermanager.h"
+#include "preferences/hotcuecolorpalettesettings.h"
#include "track/track.h"
#include "util/color/color.h"
#include "util/compatibility.h"
@@ -57,11 +58,14 @@ WOverview::WOverview(
m_pCueMenu(std::make_unique<CueMenu>(this)),
m_bShowCueTimes(true),
m_iPosSeconds(0),
- m_iPos(0),
+ m_bLeftClickDragging(false),
+ m_iPickupPos(0),
+ m_iPlayPos(0),
m_pHoveredMark(nullptr),
m_bHotcueMenuShowing(false),
m_bTimeRulerActive(false),
m_orientation(Qt::Horizontal),
+ m_iLabelFontSize(10),
m_a(1.0),
m_b(0.0),
m_analyzerProgress(kAnalyzerProgressUnknown),
@@ -108,9 +112,9 @@ void WOverview::setup(const QDomNode& node, const SkinContext& context) {
}
bool okay = false;
- m_iLabelFontSize = context.selectInt(node, "LabelFontSize", &okay);
- if (!okay) {
- m_iLabelFontSize = 10;
+ int labelFontSize = context.selectInt(node, "LabelFontSize", &okay);
+ if (okay) {
+ m_iLabelFontSize = labelFontSize;
}
// Clear the background pixmap, if it exists.
@@ -131,12 +135,9 @@ void WOverview::setup(const QDomNode& node, const SkinContext& context) {
// setup hotcues and cue and loop(s)
m_marks.setup(m_group, node, context, m_signalColors);
- WaveformMarkPointer defaultMark(m_marks.getDefaultMark());
- QColor defaultColor = defaultMark
- ? defaultMark->fillColor()
- : m_signalColors.getAxesColor();
- m_predefinedColorsRepresentation = context.getCueColorRepresentation(node, defaultColor);
- m_pCueMenu->useColorSet(&m_predefinedColorsRepresentation);
+ HotcueColorPaletteSettings colorPaletteSettings(m_pConfig);
+ auto colorPalette = colorPaletteSettings.getHotcueColorPalette();
+ m_pCueMenu->useColorSet(colorPalette);
for (const auto& pMark: m_marks) {
if (pMark->isValid()) {
@@ -204,17 +205,23 @@ void WOverview::setup(const QDomNode& node, const SkinContext& context) {
void WOverview::onConnectedControlChanged(double dParameter, double dValue) {
// this is connected via skin to "playposition"
Q_UNUSED(dValue);
+
// Calculate handle position. Clamp the value within 0-1 because that's
// all we represent with this widget.
dParameter = math_clamp(dParameter, 0.0, 1.0);
bool redraw = false;
- int oldPos = m_iPos;
- m_iPos = valueToPosition(dParameter);
- if (oldPos != m_iPos) {
+ int oldPos = m_iPlayPos;
+ m_iPlayPos = valueToPosition(dParameter);
+ if (oldPos != m_iPlayPos) {
redraw = true;
}
+ if (!m_bLeftClickDragging) {
+ // if not dragged the pick-up moves with the play position
+ m_iPickupPos = m_iPlayPos;
+ }
+
// In case the user is hovering a cue point or holding right click, the
// calculated time between the playhead and cue/cursor should be updated at
// least once per second, regardless of m_iPos which depends on the length
@@ -341,7 +348,7 @@ void WOverview::updateCues(const QList<CuePointer> &loadedCues) {
const WaveformMarkPointer pMark = m_marks.getHotCueMark(currentCue->getHotCue());
if (pMark != nullptr && pMark->isValid() && pMark->isVisible() && pMark->getSamplePosition() != Cue::kNoPosition) {
- QColor newColor = m_predefinedColorsRepresentation.representationFor(currentCue->getColor());
+ QColor newColor = currentCue->getColor();
if (newColor != pMark->fillColor() || newColor != pMark->m_textColor) {
pMark->setBaseColor(newColor);
}
@@ -381,6 +388,14 @@ void WOverview::receiveCuesUpdated() {
}
void WOverview::mouseMoveEvent(QMouseEvent* e) {
+ if (m_bLeftClickDragging) {
+ if (m_orientation == Qt::Horizontal) {
+ m_iPickupPos = math_clamp(e->x(), 0, width() - 1);
+ } else {
+ m_iPickupPos = math_clamp(e->y(), 0, height() - 1);
+ }
+ }
+
// Do not activate cue hovering while right click is held down and the
// button down event was not on a cue.
if (m_bTimeRulerActive) {
@@ -427,7 +442,17 @@ void WOverview::mouseReleaseEvent(QMouseEvent* e) {
mouseMoveEvent(e);
//qDebug() << "WOverview::mouseReleaseEvent" << e->pos() << m_iPos << ">>" << dValue;
- if (e->button() == Qt::RightButton) {
+ if (e->button() == Qt::LeftButton) {
+ if (m_bLeftClickDragging) {
+ m_iPlayPos = m_iPickupPos;
+ double dValue = positionToValue(m_iPickupPos);
+ setControlParameterUp(dValue);
+ m_bLeftClickDragging = false;
+ }
+ m_bTimeRulerActive = false;
+ } else if (e->button() == Qt::RightButton) {
+ // Do not seek when releasing a right click. This is important to
+ // prevent accidental seeking when trying to right click a hotcue.
m_bTimeRulerActive = false;
}
}
@@ -438,22 +463,30 @@ void WOverview::mousePressEvent(QMouseEvent* e) {
if (m_pCurrentTrack == nullptr) {
return;
}
-
if (e->button() == Qt::LeftButton) {
if (m_orientation == Qt::Horizontal) {
- m_iPos = math_clamp(e->x(), 0, width() - 1);
+ m_iPickupPos = math_clamp(e->x(), 0, width() - 1);
} else {
- m_iPos = math_clamp(e->y(), 0, height() - 1);
+ m_iPickupPos = math_clamp(e->y(), 0, height() - 1);
}
- double dValue = positionToValue(m_iPos);
+ double dValue = positionToValue(m_iPickupPos);
if (m_pHoveredMark != nullptr) {
dValue = m_pHoveredMark->getSamplePosition() / m_trackSamplesControl->get();
- m_iPos = valueToPosition(dValue);
+ m_iPickupPos = valueToPosition(dValue);
+ setControlParameterUp(dValue);
+ m_bLeftClickDragging = false;
+ } else {
+ m_bLeftClickDragging = true;
+ m_bTimeRulerActive = true;
+ m_timeRulerPos = e->pos();
}
- setControlParameterUp(dValue);
} else if (e->button() == Qt::RightButton) {
- if (m_pHoveredMark == nullptr) {
+ if (m_bLeftClickDragging) {
+ m_iPickupPos = m_iPlayPos;
+ m_bLeftClickDragging = false;
+ m_bTimeRulerActive = false;
+ } else if (m_pHoveredMark == nullptr) {
m_bTimeRulerActive = true;
m_timeRulerPos = e->pos();
} else if (m_pHoveredMark->getHotCue() != Cue::kNoHotCue) {
@@ -491,6 +524,7 @@ void WOverview::leaveEvent(QEvent* e) {
if (!m_bHotcueMenuShowing) {
m_pHoveredMark.clear();
}
+ m_bLeftClickDragging = false;
m_bTimeRulerActive = false;
update();
}
@@ -521,7 +555,7 @@ void WOverview::paintEvent(QPaintEvent * /*unused*/) {
drawRangeMarks(&painter, offset, gain);
drawMarks(&painter, offset, gain);
- drawCurrentPosition(&painter);
+ drawPickupPosition(&painter);
drawTimeRuler(&painter);
drawMarkLabels(&painter, offset, gain);
}
@@ -578,12 +612,24 @@ void WOverview::drawWaveformPixmap(QPainter* pPainter) {
QColor playedOverlayColor = m_signalColors.getPlayedOverlayColor();
if (playedOverlayColor.alpha() > 0) {
if (m_orientation == Qt::Vertical) {
- pPainter->fillRect(0, 0, m_waveformImageScaled.width(), m_iPos, playedOverlayColor);
+ pPainter->fillRect(0, 0, m_waveformImageScaled.width(), m_iPlayPos, playedOverlayColor);
} else {
- pPainter->fillRect(0, 0, m_iPos, m_waveformImageScaled.height(), playedOverlayColor);
+ pPainter->fillRect(0, 0, m_iPlayPos, m_waveformImageScaled.height(), playedOverlayColor);
}
}
}
+ if (m_bLeftClickDragging) {
+ PainterScope painterScope(pPainter);
+ QLineF line;
+ if (m_orientation == Qt::Horizontal) {
+ line.setLine(m_iPlayPos, 0.0, m_iPlayPos, height());
+ } else {
+ line.setLine(0.0, m_iPlayPos, width(), m_iPlayPos);
+ }
+ pPainter->setPen(QPen(m_signalColors.getPlayPosColor(), 1 * m_scaleFactor));
+ pPainter->setOpacity(0.5);
+ pPainter->drawLine(line);
+ }
}
void WOverview::drawEndOfTrackFrame(QPainter* pPainter) {
@@ -845,7 +891,7 @@ void WOverview::drawMarks(QPainter* pPainter, const float offset, const float ga
}
}
-void WOverview::drawCurrentPosition(QPainter* pPainter) {
+void WOverview::drawPickupPosition(QPainter* pPainter) {
PainterScope painterScope(pPainter);
if (m_orientation == Qt::Vertical) {
@@ -854,20 +900,20 @@ void WOverview::drawCurrentPosition(QPainter* pPainter) {
pPainter->setPen(QPen(QBrush(m_qColorBackground), 1 * m_scaleFactor));
pPainter->setOpacity(0.5);
- pPainter->drawLine(m_iPos + 1, 0, m_iPos + 1, breadth());
- pPainter->drawLine(m_iPos - 1, 0, m_iPos - 1, breadth());
+ pPainter->drawLine(m_iPickupPos + 1, 0, m_iPickupPos + 1, breadth());
+ pPainter->drawLine(m_iPickupPos - 1, 0, m_iPickupPos - 1, breadth());
pPainter->setPen(QPen(m_signalColors.getPlayPosColor(), 1 * m_scaleFactor));
pPainter->setOpacity(1.0);
- pPainter->drawLine(m_iPos, 0, m_iPos, breadth());
+ pPainter->drawLine(m_iPickupPos, 0, m_iPickupPos, breadth());
- pPainter->drawLine(m_iPos - 2, 0, m_iPos, 2);
- pPainter->drawLine(m_iPos, 2, m_iPos + 2, 0);
- pPainter->drawLine(m_iPos - 2, 0, m_iPos + 2, 0);
+ pPainter->drawLine(m_iPickupPos - 2, 0, m_iPickupPos, 2);
+ pPainter->drawLine(m_iPickupPos, 2, m_iPickupPos + 2, 0);
+ pPainter->drawLine(m_iPickupPos - 2, 0, m_iPickupPos + 2, 0);
- pPainter->drawLine(m_iPos - 2, breadth() - 1, m_iPos, breadth() - 3);
- pPainter->drawLine(m_iPos, breadth() - 3, m_iPos + 2, breadth() - 1);
- pPainter->drawLine(m_iPos - 2, breadth() - 1, m_iPos + 2, breadth() - 1);
+ pPainter->drawLine(m_iPickupPos - 2, breadth() - 1, m_iPickupPos, breadth() - 3);
+ pPainter->drawLine(m_iPickupPos, breadth() - 3, m_iPickupPos + 2, breadth() - 1);
+ pPainter->drawLine(m_iPickupPos - 2, breadth() - 1, m_iPickupPos + 2, breadth() - 1);
}
void WOverview::drawTimeRuler(QPainter* pPainter) {
@@ -881,17 +927,19 @@ void WOverview::drawTimeRuler(QPainter* pPainter) {
QPen shadowPen(Qt::black, 2.5 * m_scaleFactor);
if (m_bTimeRulerActive) {
- QLineF line;
- if (m_orientation == Qt::Horizontal) {
- line.setLine(m_timeRulerPos.x(), 0.0, m_timeRulerPos.x(), height());
- } else {
- line.setLine(0.0, m_timeRulerPos.x(), width(), m_timeRulerPos.x());
- }
- pPainter->setPen(shadowPen);
- pPainter->drawLine(line);
+ if (!m_bLeftClickDragging) {
+ QLineF line;
+ if (m_orientation == Qt::Horizontal) {
+ line.setLine(m_timeRulerPos.x(), 0.0, m_timeRulerPos.x(), height());
+ } else {
+ line.setLine(0.0, m_timeRulerPos.x(), width(), m_timeRulerPos.x());
+ }
+ pPainter->setPen(shadowPen);
+ pPainter->drawLine(line);
- pPainter->setPen(Qt::green);
- pPainter->drawLine(line);
+ pPainter->setPen(QPen(m_signalColors.getPlayPosColor(), 1 * m_scaleFactor));
+ pPainter->drawLine(line);
+ }
QPointF textPoint = m_timeRulerPos;
QPointF textPointDistance = m_timeRulerPos;
diff --git a/src/widget/woverview.h b/src/widget/woverview.h
index d5bcc4792a..583b7d132e 100644
--- a/src/widget/woverview.h
+++ b/src/widget/woverview.h
@@ -57,12 +57,12 @@ class WOverview : public WWidget, public TrackDropTarget {
UserSettingsPointer pConfig,
QWidget* parent = nullptr);
- void mouseMoveEvent(QMouseEvent *e) override;
- void mouseReleaseEvent(QMouseEvent *e) override;
- void mousePressEvent(QMouseEvent *e) override;
+ void mouseMoveEvent(QMouseEvent* e) override;
+ void mouseReleaseEvent(QMouseEvent* e) override;
+ void mousePressEvent(QMouseEvent* e) override;
void leaveEvent(QEvent* event) override;
- void paintEvent(QPaintEvent * /*unused*/) override;
- void resizeEvent(QResizeEvent * /*unused*/) override;
+ void paintEvent(QPaintEvent* /*unused*/) override;
+ void resizeEvent(QResizeEvent* /*unused*/) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
@@ -114,7 +114,7 @@ class WOverview : public WWidget, public TrackDropTarget {
void drawAnalyzerProgress(QPainter* pPainter);
void drawRangeMarks(QPainter* pPainter, const float& offset, const float& gain);
void drawMarks(QPainter* pPainter, const float offset, const float gain);
- void drawCurrentPosition(QPainter* pPainter);
+ void drawPickupPosition(QPainter* pPainter);
void drawTimeRuler(QPainter* pPainter);
void drawMarkLabels(QPainter* pPainter, const float offset, const float gain);
void paintText(const QString& text, QPainter* pPainter);
@@ -147,8 +147,12 @@ class WOverview : public WWidget, public TrackDropTarget {
bool m_bShowCueTimes;
int m_iPosSeconds;
+ // True if pick-up is dragged. Only used when m_bEventWhileDrag is false
+ bool m_bLeftClickDragging;
// Internal storage of slider position in pixels
- int m_iPos;
+ int m_iPickupPos;
+ // position of the overlay shaddow
+ int m_iPlayPos;
WaveformMarkPointer m_pHoveredMark;
bool m_bHotcueMenuShowing;
@@ -167,7 +171,6 @@ class WOverview : public WWidget, public TrackDropTarget {
QColor m_labelBackgroundColor;
QColor m_endOfTrackColor;
- PredefinedColorsRepresentation m_predefinedColorsRepresentation;
// All WaveformMarks
WaveformMarkSet m_marks;
// List of visible WaveformMarks sorted by the order they appear in the track
diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp
index 271dd42be0..ac8ce5a910 100644
--- a/src/widget/wtracktableview.cpp
+++ b/src/widget/wtracktableview.cpp
@@ -764,7 +764,7 @@ void WTrackTableView::showTrackInfo(QModelIndex index) {
if (m_pTrackInfo.isNull()) {
// Give a NULL parent because otherwise it inherits our style which can
// make it unreadable. Bug #673411
- m_pTrackInfo.reset(new DlgTrackInfo(nullptr));
+ m_pTrackInfo.reset(new DlgTrackInfo(nullptr, m_pConfig));
connect(m_pTrackInfo.data(), SIGNAL(next()),
this, SLOT(slotNextTrackInfo()));
diff --git a/src/widget/wwidget.cpp b/src/widget/wwidget.cpp
index 364b46280a..5d52366313 100644
--- a/src/widget/wwidget.cpp
+++ b/src/widget/wwidget.cpp
@@ -26,7 +26,8 @@ WWidget::WWidget(QWidget* parent, Qt::WindowFlags flags)
: QWidget(parent, flags),
WBaseWidget(this),
m_activeTouchButton(Qt::NoButton),
- m_scaleFactor(1.0) {
+ m_scaleFactor(1.0),
+ m_bShouldHighlightBackgroundOnHover(false) {
m_pTouchShift = new ControlProxy("[Controls]", "touch_shift");
setAttribute(Qt::WA_StaticContents);
setAttribute(Qt::WA_AcceptTouchEvents);
@@ -37,6 +38,31 @@ WWidget::~WWidget() {
delete m_pTouchShift;
}
+double WWidget::getBackgroundColorRgba() const {
+ if (m_backgroundColorRgba >= 0) {
+ return m_backgroundColorRgba;
+ }
+ return -1;
+}
+
+void WWidget::setBackgroundColorRgba(double rgba) {
+ QColor backgroundColor = QColor::fromRgba(rgba);
+ QColor highlightedBackgroundColor = backgroundColor.lighter();
+ QString style = QString("WWidget { background-color: %1; }");
+ if (m_bShouldHighlightBackgroundOnHover) {
+ style += "WWidget:hover { background-color: %2; }";
+ }
+
+ if (rgba >= 0) {
+ setStyleSheet(style.arg(backgroundColor.name())
+ .arg(highlightedBackgroundColor.name()));
+ } else {
+ setStyleSheet("");
+ }
+ m_backgroundColorRgba = rgba;
+ m_bBackgroundIsDark = Color::isDimmColor(backgroundColor);
+}
+
bool WWidget::touchIsRightButton() {
return (m_pTouchShift->get() != 0.0);
}
diff --git a/src/widget/wwidget.h b/src/widget/wwidget.h
index cbadf8ab2f..0fbf10631c 100644
--- a/src/widget/wwidget.h
+++ b/src/widget/wwidget.h
@@ -23,6 +23,7 @@
#include <QString>
#include "preferences/usersettings.h"
+#include "util/color/color.h"
#include "widget/wbasewidget.h"
class ControlProxy;
@@ -44,6 +45,21 @@ class WWidget : public QWidget, public WBaseWidget {
~WWidget() override;
Q_PROPERTY(double value READ getControlParameterDisplay);
+ Q_PROPERTY(double backgroundColorRgba READ getBackgroundColorRgba WRITE
+ setBackgroundColorRgba);
+ Q_PROPERTY(bool shouldHighlightBackgroundOnHover MEMBER
+ m_bShouldHighlightBackgroundOnHover);
+ Q_PROPERTY(bool hasBackgroundColor READ hasBackgroundColor);
+ Q_PROPERTY(bool backgroundIsDark READ backgroundIsDark);
+
+ double getBackgroundColorRgba() const;
+ void setBackgroundColorRgba(double rgba);
+ bool hasBackgroundColor() const {
+ return m_backgroundColorRgba >= 0;
+ }
+ bool backgroundIsDark() const {
+ return m_bBackgroundIsDark;
+ }
protected:
bool touchIsRightButton();
@@ -60,6 +76,9 @@ class WWidget : public QWidget, public WBaseWidget {
private:
ControlProxy* m_pTouchShift;
double m_scaleFactor;
+ double m_backgroundColorRgba;
+ bool m_bBackgroundIsDark;
+ bool m_bShouldHighlightBackgroundOnHover;
};
#endif