4242#include < cmath>
4343
4444#include " QtSLiMPreferences.h"
45+ #include " QtSLiMAppDelegate.h"
4546
4647#include " eidos_value.h"
4748
@@ -208,8 +209,18 @@ void RGBForSelectionCoeff(double value, float *colorRed, float *colorGreen, floa
208209
209210// A subclass of QLineEdit that selects all its text when it receives keyboard focus
210211// thanks to https://stackoverflow.com/a/51807268/2752221
211- QtSLiMGenerationLineEdit::QtSLiMGenerationLineEdit (const QString &contents, QWidget *p_parent) : QLineEdit(contents, p_parent) { }
212- QtSLiMGenerationLineEdit::QtSLiMGenerationLineEdit (QWidget *p_parent) : QLineEdit(p_parent) { }
212+ QtSLiMGenerationLineEdit::QtSLiMGenerationLineEdit (const QString &contents, QWidget *p_parent) : QLineEdit(contents, p_parent)
213+ {
214+ connect (qtSLiMAppDelegate, &QtSLiMAppDelegate::applicationPaletteChanged, this , [this ]() { _ReconfigureAppearance (); });
215+ _ReconfigureAppearance ();
216+ }
217+
218+ QtSLiMGenerationLineEdit::QtSLiMGenerationLineEdit (QWidget *p_parent) : QLineEdit(p_parent)
219+ {
220+ connect (qtSLiMAppDelegate, &QtSLiMAppDelegate::applicationPaletteChanged, this , [this ]() { _ReconfigureAppearance (); });
221+ _ReconfigureAppearance ();
222+ }
223+
213224QtSLiMGenerationLineEdit::~QtSLiMGenerationLineEdit () {}
214225
215226void QtSLiMGenerationLineEdit::focusInEvent (QFocusEvent *p_event)
@@ -222,6 +233,103 @@ void QtSLiMGenerationLineEdit::focusInEvent(QFocusEvent *p_event)
222233 QTimer::singleShot (0 , this , &QLineEdit::selectAll);
223234}
224235
236+ void QtSLiMGenerationLineEdit::setProgress (double p_progress)
237+ {
238+ double newProgress = std::min (std::max (p_progress, 0.0 ), 1.0 );
239+
240+ if (newProgress != progress)
241+ {
242+ progress = newProgress;
243+ update ();
244+ }
245+ }
246+
247+ void QtSLiMGenerationLineEdit::_ReconfigureAppearance ()
248+ {
249+ // Eight states, based on three binary flags; but two states never happen in practice
250+ bool darkMode = QtSLiMInDarkMode ();
251+ bool enabled = isEnabled ();
252+
253+ if (darkMode)
254+ {
255+ if (enabled)
256+ {
257+ if (dimmed)
258+ setStyleSheet (" color: red; background-color: black" ); // doesn't happen
259+ else
260+ setStyleSheet (" color: rgb(255, 255, 255); background-color: black" ); // not playing
261+ }
262+ else
263+ {
264+ if (dimmed)
265+ setStyleSheet (" color: rgb(40, 40, 40); background-color: black" ); // error state (not normally visible)
266+ else
267+ setStyleSheet (" color: rgb(170, 170, 170); background-color: black" ); // playing
268+ }
269+ }
270+ else
271+ {
272+ if (enabled)
273+ {
274+ if (dimmed)
275+ setStyleSheet (" color: red; background-color: white" ); // doesn't happen
276+ else
277+ setStyleSheet (" color: rgb(0, 0, 0); background-color: white" ); // not playing
278+ }
279+ else
280+ {
281+ if (dimmed)
282+ setStyleSheet (" color: rgb(192, 192, 192); background-color: white" ); // error state (not normally visible)
283+ else
284+ setStyleSheet (" color: rgb(120, 120, 120); background-color: white" ); // playing
285+ }
286+ }
287+
288+ update ();
289+ }
290+
291+ void QtSLiMGenerationLineEdit::setAppearance (bool p_enabled, bool p_dimmed)
292+ {
293+ if ((isEnabled () != p_enabled) || (dimmed != p_dimmed))
294+ {
295+ setEnabled (p_enabled);
296+ dimmed = p_dimmed;
297+
298+ _ReconfigureAppearance ();
299+ }
300+ }
301+
302+ void QtSLiMGenerationLineEdit::paintEvent (QPaintEvent *p_paintEvent)
303+ {
304+ // first let super draw
305+ QLineEdit::paintEvent (p_paintEvent);
306+
307+ // then overlay a progress bar on top, if requested, and if we are not disabled & dimmed (error state)
308+ bool enabled = isEnabled ();
309+
310+ if (!enabled && dimmed)
311+ return ;
312+
313+ if (progress > 0.0 )
314+ {
315+ bool darkMode = QtSLiMInDarkMode ();
316+ QPainter painter (this );
317+ QRect bounds = rect ().adjusted (2 , 2 , -2 , -2 );
318+
319+ bounds.setWidth (round (bounds.width () * progress));
320+
321+ if (darkMode) {
322+ // lighten the black background to a dark green; text is unaffected since it's light
323+ painter.setCompositionMode (QPainter::CompositionMode_Lighten);
324+ painter.fillRect (bounds, QColor (0 , 120 , 0 ));
325+ } else {
326+ // darken the white background to a light green; text is unaffected since it's dark
327+ painter.setCompositionMode (QPainter::CompositionMode_Darken);
328+ painter.fillRect (bounds, QColor (180 , 255 , 180 ));
329+ }
330+ }
331+ }
332+
225333void ColorizePropertySignature (const EidosPropertySignature *property_signature, double pointSize, QTextCursor lineCursor)
226334{
227335 //
0 commit comments