diff --git a/slsDetectorGui/forms/form_cloneplot.ui b/slsDetectorGui/forms/form_cloneplot.ui index c9ac491d5..61d9dc6c2 100644 --- a/slsDetectorGui/forms/form_cloneplot.ui +++ b/slsDetectorGui/forms/form_cloneplot.ui @@ -53,9 +53,9 @@ - 0 - 150 - 110 + 60 + 200 + 150 @@ -64,9 +64,9 @@ - 0 - 150 - 110 + 60 + 200 + 150 @@ -75,9 +75,9 @@ - 139 - 142 - 142 + 125 + 125 + 125 @@ -119,8 +119,8 @@ 255 - 0 - 0 + 95 + 95 @@ -130,8 +130,8 @@ 255 - 0 - 0 + 95 + 95 @@ -140,9 +140,9 @@ - 139 - 142 - 142 + 125 + 125 + 125 diff --git a/slsDetectorGui/forms/form_detectormain.ui b/slsDetectorGui/forms/form_detectormain.ui index 0ed41d5d8..53d2aba35 100755 --- a/slsDetectorGui/forms/form_detectormain.ui +++ b/slsDetectorGui/forms/form_detectormain.ui @@ -19,124 +19,6 @@ 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - - - 185 - 185 - 185 - - - - - - - 185 - 185 - 185 - - - - - - - 185 - 185 - 185 - - - - - - - 89 - 89 - 89 - - - - - - Cantarell @@ -193,178 +75,6 @@ - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - - - - 185 - 185 - 185 - - - - - - - 255 - 255 - 255 - - - - - - - 185 - 185 - 185 - - - - - - - 185 - 185 - 185 - - - - - - - 255 - 255 - 255 - - - - - - - 255 - 255 - 255 - - - - - - Cantarell @@ -374,9 +84,6 @@ Qt::NoFocus - - background-color: rgb(255, 255, 255); - 0 @@ -857,43 +564,6 @@ 16777215 - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - - - 119 - 119 - 119 - - - - - - Cantarell diff --git a/slsDetectorGui/forms/form_plot.ui b/slsDetectorGui/forms/form_plot.ui index 66d6e64a8..9bcae6d84 100644 --- a/slsDetectorGui/forms/form_plot.ui +++ b/slsDetectorGui/forms/form_plot.ui @@ -52,8 +52,8 @@ - 0 - 0 + 110 + 160 255 @@ -63,8 +63,8 @@ - 0 - 0 + 110 + 160 255 @@ -74,9 +74,9 @@ - 139 - 142 - 142 + 125 + 125 + 125 @@ -416,9 +416,9 @@ - 0 - 150 - 110 + 60 + 200 + 150 @@ -427,9 +427,9 @@ - 0 - 150 - 110 + 60 + 200 + 150 @@ -438,9 +438,9 @@ - 139 - 142 - 142 + 125 + 125 + 125 @@ -491,8 +491,8 @@ 255 - 0 - 0 + 95 + 95 @@ -502,8 +502,8 @@ 255 - 0 - 0 + 95 + 95 @@ -512,9 +512,9 @@ - 139 - 142 - 142 + 125 + 125 + 125 diff --git a/slsDetectorGui/forms/form_tab_dataoutput.ui b/slsDetectorGui/forms/form_tab_dataoutput.ui index 190aff041..0ea0bf320 100755 --- a/slsDetectorGui/forms/form_tab_dataoutput.ui +++ b/slsDetectorGui/forms/form_tab_dataoutput.ui @@ -98,43 +98,6 @@ 16777215 - - - - - - - 2 - 2 - 2 - - - - - - - - - 0 - 0 - 0 - - - - - - - - - 119 - 119 - 119 - - - - - - Cantarell @@ -195,43 +158,6 @@ 16777215 - - - - - - - 2 - 2 - 2 - - - - - - - - - 0 - 0 - 0 - - - - - - - - - 119 - 119 - 119 - - - - - - Cantarell @@ -301,43 +227,6 @@ 16777215 - - - - - - - 2 - 2 - 2 - - - - - - - - - 0 - 0 - 0 - - - - - - - - - 119 - 119 - 119 - - - - - - Cantarell diff --git a/slsDetectorGui/forms/form_tab_debugging.ui b/slsDetectorGui/forms/form_tab_debugging.ui index b71992c06..7fc7eea8c 100755 --- a/slsDetectorGui/forms/form_tab_debugging.ui +++ b/slsDetectorGui/forms/form_tab_debugging.ui @@ -474,9 +474,9 @@ - 204 - 0 - 0 + 255 + 95 + 95 @@ -485,9 +485,9 @@ - 204 - 0 - 0 + 255 + 95 + 95 @@ -496,9 +496,9 @@ - 190 - 190 - 190 + 125 + 125 + 125 @@ -544,9 +544,9 @@ - 78 - 154 - 6 + 130 + 200 + 70 @@ -555,9 +555,9 @@ - 78 - 154 - 6 + 130 + 200 + 70 @@ -566,9 +566,9 @@ - 190 - 190 - 190 + 125 + 125 + 125 @@ -701,9 +701,9 @@ - 204 - 0 - 0 + 255 + 95 + 95 @@ -712,9 +712,9 @@ - 204 - 0 - 0 + 255 + 95 + 95 @@ -723,9 +723,9 @@ - 190 - 190 - 190 + 125 + 125 + 125 @@ -771,9 +771,9 @@ - 78 - 154 - 6 + 130 + 200 + 70 @@ -782,9 +782,9 @@ - 78 - 154 - 6 + 130 + 200 + 70 @@ -793,9 +793,9 @@ - 190 - 190 - 190 + 125 + 125 + 125 diff --git a/slsDetectorGui/forms/form_tab_plot.ui b/slsDetectorGui/forms/form_tab_plot.ui index 49fe85ca4..1500f2742 100755 --- a/slsDetectorGui/forms/form_tab_plot.ui +++ b/slsDetectorGui/forms/form_tab_plot.ui @@ -1075,70 +1075,6 @@ 25 - - - - - - - 11 - 11 - 11 - - - - - - - 20 - 20 - 20 - - - - - - - - - 11 - 11 - 11 - - - - - - - 20 - 20 - 20 - - - - - - - - - 119 - 119 - 119 - - - - - - - 20 - 20 - 20 - - - - - - Cantarell @@ -1183,70 +1119,6 @@ 25 - - - - - - - 11 - 11 - 11 - - - - - - - 20 - 20 - 20 - - - - - - - - - 11 - 11 - 11 - - - - - - - 20 - 20 - 20 - - - - - - - - - 119 - 119 - 119 - - - - - - - 20 - 20 - 20 - - - - - - Cantarell @@ -1757,43 +1629,6 @@ 35 - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - Cantarell @@ -1879,43 +1714,6 @@ 35 - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - Cantarell @@ -2500,43 +2298,6 @@ Displays minimum, maximum and sum of values for each plot. 35 - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - Cantarell @@ -2622,43 +2383,6 @@ Displays minimum, maximum and sum of values for each plot. 35 - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - Cantarell @@ -3056,43 +2780,6 @@ Displays statistics, ie. minimum, maximum and sum of values for each plot. 35 - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - Cantarell @@ -3153,43 +2840,6 @@ Displays statistics, ie. minimum, maximum and sum of values for each plot. 35 - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - Cantarell diff --git a/slsDetectorGui/forms/form_tab_settings.ui b/slsDetectorGui/forms/form_tab_settings.ui index 025e44186..d5ca43600 100755 --- a/slsDetectorGui/forms/form_tab_settings.ui +++ b/slsDetectorGui/forms/form_tab_settings.ui @@ -582,43 +582,6 @@ 35 - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - - - - 20 - 20 - 20 - - - - - - Cantarell diff --git a/slsDetectorGui/include/qTabMessages.h b/slsDetectorGui/include/qTabMessages.h index 141c5ec57..bfcbd9853 100644 --- a/slsDetectorGui/include/qTabMessages.h +++ b/slsDetectorGui/include/qTabMessages.h @@ -28,6 +28,7 @@ class qTabMessages : public QWidget, private Ui::TabMessagesObject { void SetupWidgetWindow(); void Initialization(); void PrintNextLine(); + QString CommandFontTag() const; void GetLastCommand(); void ClearCommand(); void AppendOutput(); diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h index d15e166bc..d1444f65f 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQtFastImage.h @@ -105,7 +105,8 @@ class SlsQtFastImage : public QWidget { QFont axisTitleFont() const; signals: - /** The user zoomed or panned, or the widget was resized */ + /** The user zoomed or panned, or a resize changed what is visible. A + * resize is reported from the event loop, not from within the resize. */ void visibleAreaChanged(const QRectF &area); /** Palette, log scale or colour range changed */ void colorMapChanged(); @@ -189,6 +190,7 @@ class SlsQtFastImage : public QWidget { QRectF m_viewport; // (x, y) is the lower left corner bool m_fillPlot = true; // show more than m_viewport to fill the plot area + bool m_resizeReportPending = false; QRectF m_axisRange; // null: pixel index bool m_zoomEnabled = true; bool m_axesVisible = true; diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h index 0c4b65630..28f22d65f 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -94,5 +95,11 @@ struct PlotTheme { // subtracted. Never smaller than 10x10 so a tiny widget still paints. QRect plotRectFor(const QSize &widgetSize, const PlotTheme &theme); +// Widget palette of the gui, made from the colours of PlotTheme so that the +// tabs, docks and dialogs around the plots are as dark as the plots. Text +// entry fields get the plot background, the windows are a little lighter. +// QPalette::Link is the accent colour, for text that has to stand out. +QPalette darkPalette(); + } // namespace plot } // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp index f2cf368b3..297a1787b 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp @@ -44,7 +44,7 @@ QString formatValue(double v, int digits) { SlsQtFastImage::SlsQtFastImage(QWidget *parent) : QWidget(parent) { setMouseTracking(true); setFocusPolicy(Qt::StrongFocus); - setMinimumSize(200, 200); + setMinimumSize(50, 50); // the gain plot of the gui is small setAttribute(Qt::WA_OpaquePaintEvent, true); m_titleFont = font(); @@ -711,9 +711,22 @@ bool SlsQtFastImage::event(QEvent *e) { return QWidget::event(e); } +// A layout resizes the widget from within other calls, for example when a +// neighbour is shown. Whoever made that call does not expect a signal in the +// middle of it (qDrawPlot holds a mutex there that its slot takes as well), so +// the new visible area is reported from the event loop. void SlsQtFastImage::resizeEvent(QResizeEvent *) { - if (hasImage()) - emit visibleAreaChanged(visibleArea()); + if (!hasImage() || !m_fillPlot || m_resizeReportPending) + return; + m_resizeReportPending = true; + QMetaObject::invokeMethod( + this, + [this] { + m_resizeReportPending = false; + if (hasImage()) + emit visibleAreaChanged(visibleArea()); + }, + Qt::QueuedConnection); } } // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQtPlotCommon.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQtPlotCommon.cpp index 7bcd43e16..ee6b307a0 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQtPlotCommon.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQtPlotCommon.cpp @@ -496,5 +496,42 @@ QRect plotRectFor(const QSize &widgetSize, const PlotTheme &theme) { return QRect(x0, y0, x1 - x0, y1 - y0); } +QPalette darkPalette() { + const PlotTheme theme; + const QColor window(45, 45, 45); + const QColor button(60, 60, 60); + const QColor disabledText(125, 125, 125); + const QColor accent(110, 160, 255); + + QPalette p; + p.setColor(QPalette::Window, window); + p.setColor(QPalette::WindowText, theme.text); + p.setColor(QPalette::Base, theme.background); + p.setColor(QPalette::AlternateBase, QColor(38, 38, 38)); + p.setColor(QPalette::Text, theme.text); + p.setColor(QPalette::PlaceholderText, disabledText); + p.setColor(QPalette::Button, button); + p.setColor(QPalette::ButtonText, theme.text); + p.setColor(QPalette::BrightText, Qt::white); + p.setColor(QPalette::ToolTipBase, button); + p.setColor(QPalette::ToolTipText, theme.text); + p.setColor(QPalette::Light, QColor(85, 85, 85)); + p.setColor(QPalette::Midlight, QColor(70, 70, 70)); + p.setColor(QPalette::Mid, QColor(38, 38, 38)); + p.setColor(QPalette::Dark, QColor(24, 24, 24)); + p.setColor(QPalette::Shadow, QColor(12, 12, 12)); + p.setColor(QPalette::Highlight, QColor(50, 100, 180)); + p.setColor(QPalette::HighlightedText, Qt::white); + p.setColor(QPalette::Link, accent); + p.setColor(QPalette::LinkVisited, QColor(180, 150, 255)); + + for (auto role : {QPalette::WindowText, QPalette::Text, + QPalette::ButtonText, QPalette::HighlightedText}) + p.setColor(QPalette::Disabled, role, disabledText); + p.setColor(QPalette::Disabled, QPalette::Base, window); + p.setColor(QPalette::Disabled, QPalette::Highlight, QColor(75, 75, 75)); + return p; +} + } // namespace plot } // namespace sls diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 20145a798..944e7ede2 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -12,6 +12,8 @@ #include "qTabPlot.h" #include "qTabSettings.h" +#include "SlsQtPlotCommon.h" + #include "sls/ToString.h" #include "sls/versionAPI.h" @@ -23,6 +25,7 @@ #include #include #include +#include #include "sls/Version.h" #include @@ -111,6 +114,11 @@ int main(int argc, char **argv) { if (QStyleFactory::keys().contains("Fusion", Qt::CaseInsensitive)) { app.setStyle(QStyleFactory::create("Fusion")); } + // The plots are dark, and so is everything around them. Tool tips take + // their palette from the platform, they have to be told separately. + const QPalette darkPalette = sls::plot::darkPalette(); + app.setPalette(darkPalette); + QToolTip::setPalette(darkPalette); try { sls::qDetectorMain det(multiId, fname, isDeveloper); det.show(); @@ -186,8 +194,8 @@ void qDetectorMain::SetUpWidgetWindow() { tabs->setCurrentIndex(MEASUREMENT); defaultTabColor = tabs->tabBar()->tabTextColor(DATAOUTPUT); - // set current tab to blue - tabs->tabBar()->setTabTextColor(0, QColor(0, 0, 200, 255)); + // highlight the current tab + tabs->tabBar()->setTabTextColor(0, palette().color(QPalette::Link)); tabs->setTabEnabled(DEBUGGING, false); tabs->setTabEnabled(ADVANCED, false); tabs->setTabEnabled(DEVELOPER, isDeveloper); @@ -520,7 +528,7 @@ void qDetectorMain::Refresh(int index) { } for (int i = 0; i < NumberOfTabs; ++i) tabs->tabBar()->setTabTextColor(i, defaultTabColor); - tabs->tabBar()->setTabTextColor(index, QColor(0, 0, 200, 255)); + tabs->tabBar()->setTabTextColor(index, palette().color(QPalette::Link)); } void qDetectorMain::ResizeMainWindow(bool b) { @@ -612,8 +620,10 @@ void qDetectorMain::SetPlotSettingsDetached(bool detached) { void qDetectorMain::SetZoomToolTip(bool disable) { if (disable) dockWidgetPlot->setToolTip( - "To Enable mouse-controlled " - "zooming capabilities,\ndisable min and max for all axes. "); + QString("To Enable mouse-controlled " + "zooming capabilities,\ndisable min and max for all " + "axes. ") + .arg(palette().color(QPalette::Link).name())); else dockWidgetPlot->setToolTip(zoomToolTip); } diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index c2df7922b..031049951 100644 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -23,13 +23,14 @@ void qTabMeasurement::SetupWidgetWindow() { setFont(QFont("Carlito", 9, QFont::Normal)); // palette red = QPalette(); - red.setColor(QPalette::Active, QPalette::WindowText, Qt::red); + red.setColor(QPalette::Active, QPalette::WindowText, + QColor(255, 95, 95)); // readable on the dark window acqPeriodTip = spinPeriod->toolTip(); errPeriodTip = QString("Frame period between exposures.
" " #period#

") + QString( - "Acquisition Period should be" + "Acquisition Period should be" " greater than or equal to Exposure Time."); // timer to update the progress bar diff --git a/slsDetectorGui/src/qTabMessages.cpp b/slsDetectorGui/src/qTabMessages.cpp index 4fe50a8e2..404fe9fb5 100644 --- a/slsDetectorGui/src/qTabMessages.cpp +++ b/slsDetectorGui/src/qTabMessages.cpp @@ -60,6 +60,11 @@ void qTabMessages::PrintNextLine() { QString("")); } +QString qTabMessages::CommandFontTag() const { + return QString("") + .arg(palette().color(QPalette::Link).name()); +} + void qTabMessages::GetLastCommand() { dispCommand->setText(lastCommand.join(" ")); } @@ -73,8 +78,8 @@ void qTabMessages::ExecuteCommand() { dispCommand->clear(); // appending command to log without newline dispLog->moveCursor(QTextCursor::End); - dispLog->insertHtml(QString("") + - param.join(" ") + QString("")); + dispLog->insertHtml(CommandFontTag() + param.join(" ") + + QString("")); QString command = param.at(0); param.removeFirst(); @@ -94,8 +99,7 @@ void qTabMessages::ExecuteCommand() { void qTabMessages::AppendOutput() { QByteArray result = process->readAll(); result.replace("\n", "
"); - dispLog->append(QString("") + result + - QString("")); + dispLog->append(CommandFontTag() + result + QString("
")); LOG(logDEBUG) << "Command executed successfully"; PrintNextLine(); } diff --git a/slsDetectorGui/tests/plotting_test.cpp b/slsDetectorGui/tests/plotting_test.cpp index 4796860ea..27ee4bfe8 100644 --- a/slsDetectorGui/tests/plotting_test.cpp +++ b/slsDetectorGui/tests/plotting_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -229,6 +230,8 @@ class PlottingTest : public QObject { void imageReadout(); void imageAxisValues(); + void darkPaletteGoesWithThePlots(); + void scaleHistoDrag(); void scaleHistoLogAxis(); void scalePanel(); @@ -243,6 +246,7 @@ class PlottingTest : public QObject { void plot2dLogZ(); void plot2dContours(); void plot2dRoiAndZoom(); + void plot2dResizeIsReportedLater(); void plot2dGain(); void performance1024x512(); @@ -1588,6 +1592,88 @@ void PlottingTest::plot2dRoiAndZoom() { QVERIFY(view->zoomEnabled()); } +// qDrawPlot shows the gain plot next to the data plot while it holds a mutex, +// and its slot for PlotZoomedSignal takes the same mutex. Showing a widget +// resizes its neighbours on the spot, so the plot may not report its new +// visible area from within that resize. +void PlottingTest::plot2dResizeIsReportedLater() { + QWidget window; + auto *plot = new sls::SlsQt2DPlot(&window); + auto *gain = new sls::SlsQt2DPlot(&window, true); + gain->setFixedSize(180, 120); + gain->hide(); + auto *layout = new QHBoxLayout(&window); + layout->addWidget(plot); + layout->addWidget(gain); + window.resize(900, 600); + window.show(); + for (int i = 0; i < 3; i++) // the visible area now depends on the size + sendWheel(*plot->imageView(), QPointF(300.0, 250.0), 120); + const QSize before = plot->size(); + const QRectF areaBefore = plot->imageView()->visibleArea(); + + bool showing = false; + int reportedWhileShowing = 0; + QSignalSpy spy(plot, &sls::SlsQt2DPlot::PlotZoomedSignal); + connect(plot, &sls::SlsQt2DPlot::PlotZoomedSignal, &window, [&] { + if (showing) + reportedWhileShowing++; + }); + showing = true; + gain->show(); + showing = false; + QVERIFY(plot->width() < before.width()); // resized inside show() + QVERIFY(plot->imageView()->visibleArea() != areaBefore); + QCOMPARE(reportedWhileShowing, 0); + + // but once that is over, for the gain plot to follow + QCoreApplication::processEvents(); + QCOMPARE(spy.count(), 1); + + // the gain plot is small, all of it has to be visible + QVERIFY(gain->rect().contains(gain->imageView()->geometry())); + if (!qEnvironmentVariableIsEmpty("PLOTTING_TEST_IMAGES")) + window.grab().save(qEnvironmentVariable("PLOTTING_TEST_IMAGES") + + QStringLiteral("/gain-next-to-data.png")); +} + +// The widgets around the plots use the plot colours, and every text colour is +// readable on the background it is drawn on. +void PlottingTest::darkPaletteGoesWithThePlots() { + const sls::plot::PlotTheme theme; + const QPalette p = sls::plot::darkPalette(); + QCOMPARE(p.color(QPalette::Base), theme.background); + QCOMPARE(p.color(QPalette::Text), theme.text); + QCOMPARE(p.color(QPalette::WindowText), theme.text); + + auto luminance = [](const QColor &c) { + auto lin = [](double v) { + return v <= 0.03928 ? v / 12.92 + : std::pow((v + 0.055) / 1.055, 2.4); + }; + return 0.2126 * lin(c.redF()) + 0.7152 * lin(c.greenF()) + + 0.0722 * lin(c.blueF()); + }; + auto contrast = [&](QPalette::ColorRole fg, QPalette::ColorRole bg) { + const double a = luminance(p.color(fg)); + const double b = luminance(p.color(bg)); + return (std::max(a, b) + 0.05) / (std::min(a, b) + 0.05); + }; + QVERIFY(contrast(QPalette::WindowText, QPalette::Window) > 7.0); + QVERIFY(contrast(QPalette::Text, QPalette::Base) > 7.0); + QVERIFY(contrast(QPalette::ButtonText, QPalette::Button) > 7.0); + QVERIFY(contrast(QPalette::ToolTipText, QPalette::ToolTipBase) > 7.0); + QVERIFY(contrast(QPalette::Link, QPalette::Window) > 4.5); + QVERIFY(contrast(QPalette::Link, QPalette::Base) > 4.5); + QVERIFY(contrast(QPalette::HighlightedText, QPalette::Highlight) > 4.5); + + // disabled text is dimmer, but still there + QVERIFY(p.color(QPalette::Disabled, QPalette::WindowText) != + p.color(QPalette::Active, QPalette::WindowText)); + QVERIFY(luminance(p.color(QPalette::Disabled, QPalette::WindowText)) > + 2.0 * luminance(p.color(QPalette::Window))); +} + void PlottingTest::plot2dGain() { sls::SlsQt2DPlot gain(nullptr, true); gain.resize(200, 200);