Skip to content

Commit 0ca8f81

Browse files
committed
Update HUD text color based on background
Added updateHeadsUpDisplayTextColor to adjust the Heads Up Display text color for better contrast depending on the background color. The text color now updates automatically when the background color changes or when loading settings.
1 parent de79c84 commit 0ca8f81

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/ScatterplotPlugin.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
264264
getLearningCenterAction().addVideos(QStringList({ "Practitioner", "Developer" }));
265265

266266
setOverlayActionsTargetWidget(_scatterPlotWidget);
267-
268-
269267
}
270268

271269
ScatterplotPlugin::~ScatterplotPlugin()
@@ -376,6 +374,10 @@ void ScatterplotPlugin::init()
376374
connect(&_settingsAction.getColoringAction().getColorByAction(), &OptionAction::currentIndexChanged, this, &ScatterplotPlugin::updateHeadsUpDisplay);
377375
connect(&_settingsAction.getPlotAction().getPointPlotAction().getSizeAction(), &ScalarAction::sourceDataChanged, this, &ScatterplotPlugin::updateHeadsUpDisplay);
378376
connect(&_settingsAction.getPlotAction().getPointPlotAction().getOpacityAction(), &ScalarAction::sourceDataChanged, this, &ScatterplotPlugin::updateHeadsUpDisplay);
377+
378+
updateHeadsUpDisplayTextColor();
379+
380+
connect(&_settingsAction.getMiscellaneousAction().getBackgroundColorAction(), &ColorAction::colorChanged, this, &ScatterplotPlugin::updateHeadsUpDisplayTextColor);
379381
}
380382

381383
void ScatterplotPlugin::loadData(const Datasets& datasets)
@@ -993,6 +995,19 @@ void ScatterplotPlugin::updateHeadsUpDisplay()
993995
}
994996
}
995997

998+
void ScatterplotPlugin::updateHeadsUpDisplayTextColor()
999+
{
1000+
if (auto headsUpDisplayWidget = getWidget().findChild<QWidget*>("HeadsUpDisplayWidget")) {
1001+
if (auto headsUpDisplayWidgetTreeView = headsUpDisplayWidget->findChild<QTreeView*>("TreeView")) {
1002+
QPalette palette = headsUpDisplayWidgetTreeView->palette();
1003+
1004+
palette.setColor(QPalette::Text, _settingsAction.getMiscellaneousAction().getBackgroundColorAction().getColor().lightnessF() > .5f ? Qt::black : Qt::white);
1005+
1006+
headsUpDisplayWidgetTreeView->setPalette(palette);
1007+
}
1008+
}
1009+
}
1010+
9961011
void ScatterplotPlugin::fromVariantMap(const QVariantMap& variantMap)
9971012
{
9981013
ViewPlugin::fromVariantMap(variantMap);
@@ -1014,6 +1029,8 @@ void ScatterplotPlugin::fromVariantMap(const QVariantMap& variantMap)
10141029

10151030
_scatterPlotWidget->update();
10161031
}
1032+
1033+
updateHeadsUpDisplayTextColor();
10171034
}
10181035

10191036
QVariantMap ScatterplotPlugin::toVariantMap() const

src/ScatterplotPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class ScatterplotPlugin : public ViewPlugin
9595
void updateSelection();
9696

9797
void updateHeadsUpDisplay();
98+
void updateHeadsUpDisplayTextColor();
9899

99100
public: // Serialization
100101

0 commit comments

Comments
 (0)