Added logic to Qt trace logger and ram search to change fore/background color scheme based on style theme.

This commit is contained in:
Matthew Budd 2020-11-07 14:19:22 -05:00
parent e42232777e
commit f4da749a44
2 changed files with 50 additions and 7 deletions

View File

@ -1467,12 +1467,33 @@ QRamSearchView::QRamSearchView(QWidget *parent)
: QWidget(parent)
{
QPalette pal;
QColor fg(0,0,0), bg(255,255,255);
QColor c, fg(0,0,0), bg(255,255,255);
bool useDarkTheme = false;
pal = this->palette();
pal.setColor(QPalette::Base , bg );
pal.setColor(QPalette::Background, bg );
pal.setColor(QPalette::WindowText, fg );
// Figure out if we are using a light or dark theme by checking the
// default window text grayscale color. If more white, then we will
// use white text on black background, else we do the opposite.
c = pal.color(QPalette::WindowText);
if ( qGray( c.red(), c.green(), c.blue() ) > 128 )
{
useDarkTheme = true;
}
if ( useDarkTheme )
{
pal.setColor(QPalette::Base , fg );
pal.setColor(QPalette::Background, fg );
pal.setColor(QPalette::WindowText, bg );
}
else
{
pal.setColor(QPalette::Base , bg );
pal.setColor(QPalette::Background, bg );
pal.setColor(QPalette::WindowText, fg );
}
this->setPalette(pal);
font.setFamily("Courier New");

View File

@ -1056,15 +1056,37 @@ QTraceLogView::QTraceLogView(QWidget *parent)
{
QPalette pal;
QColor fg("black"), bg("white");
QColor c;
bool useDarkTheme = false;
font.setFamily("Courier New");
font.setStyle( QFont::StyleNormal );
font.setStyleHint( QFont::Monospace );
pal = this->palette();
pal.setColor(QPalette::Base , bg );
pal.setColor(QPalette::Background, bg );
pal.setColor(QPalette::WindowText, fg );
// Figure out if we are using a light or dark theme by checking the
// default window text grayscale color. If more white, then we will
// use white text on black background, else we do the opposite.
c = pal.color(QPalette::WindowText);
if ( qGray( c.red(), c.green(), c.blue() ) > 128 )
{
useDarkTheme = true;
}
if ( useDarkTheme )
{
pal.setColor(QPalette::Base , fg );
pal.setColor(QPalette::Background, fg );
pal.setColor(QPalette::WindowText, bg );
}
else
{
pal.setColor(QPalette::Base , bg );
pal.setColor(QPalette::Background, bg );
pal.setColor(QPalette::WindowText, fg );
}
this->setPalette(pal);