Close #440: yellow background makes date text hard to read in dark themes

Adapt red and yellow background colors depending on the used theme,
detected by: "Text color lighter than Background color?"
This commit is contained in:
Christian Hohnstaedt 2023-09-22 13:36:12 +02:00
parent e8cd69c45d
commit cccc8ee1e3
7 changed files with 52 additions and 10 deletions

View File

@ -472,7 +472,12 @@ int main(int argc, char *argv[])
if (d && *d)
debug_info::set_debug(QString(d));
}
#if defined(Q_OS_WIN32)
// If no style provided externally
if (!QApplication::style())
QApplication::setStyle("Fusion");
AttachConsole(-1);
int wargc;

View File

@ -21,6 +21,7 @@ pki_lookup Store;
QRegularExpression pki_base::limitPattern;
bool pki_base::pem_comment;
QList<pki_base*> pki_base::allitems;
QBrush pki_base::red, pki_base::cyan, pki_base::yellow;
pki_base::pki_base(const QString &name, pki_base *p)
{
@ -493,3 +494,17 @@ QStringList pki_base::icsVEVENT(const a1time &expires,
"END:VALARM" <<
"END:VEVENT";
}
void pki_base::setupColors(const QPalette &pal)
{
int factor = 50;
if (pal.window().color().value() > pal.windowText().color().value())
factor = 125;
qDebug() << "WindowColor" << pal.window().color().value()
<< "TextColor" << pal.windowText().color().value()
<< "Factor" << factor;
red = QBrush(QColor(255, 0, 0).lighter(factor));
yellow = QBrush(QColor(255, 255, 0).lighter(factor));
cyan = QBrush(QColor(127, 255, 212).lighter(factor));
}

View File

@ -12,6 +12,8 @@
#include <QRegularExpression>
#include <QVariant>
#include <QByteArray>
#include <QPalette>
#include <QBrush>
#include "BioByteArray.h"
#include "asn1time.h"
#include "pkcs11_lib.h"
@ -55,6 +57,7 @@ class pki_base : public QObject
static bool pem_comment;
static int count;
static QList<pki_base*> allitems;
static void setupColors(const QPalette &pal);
protected:
QVariant sqlItemId;
@ -69,6 +72,7 @@ class pki_base : public QObject
virtual void collect_properties(QMap<QString, QString> &) const;
QList<pki_base*> childItems;
mutable QRegularExpression lastPattern;
static QBrush red, yellow, cyan;
public:
enum msg_type {

View File

@ -1002,10 +1002,6 @@ bool pki_x509::visible() const
QVariant pki_x509::bg_color(const dbheader *hd) const
{
#define BG_RED QBrush(QColor(255, 0, 0))
#define BG_YELLOW QBrush(QColor(255,255, 0))
#define BG_CYAN QBrush(QColor(127,255,212))
if (Settings["no_expire_colors"])
return QVariant();
@ -1031,15 +1027,15 @@ QVariant pki_x509::bg_color(const dbheader *hd) const
switch (hd->id) {
case HD_cert_notBefore:
if (nb > now || !nb.isValid() || nb.isUndefined())
return QVariant(BG_RED);
return QVariant(red);
break;
case HD_cert_notAfter: {
if (na.isUndefined())
return QVariant(BG_CYAN);
return QVariant(cyan);
if (na < now)
return QVariant(BG_RED);
return QVariant(red);
if (certwarn < now)
return QVariant(BG_YELLOW);
return QVariant(yellow);
break;
}
case HD_cert_crl_expire:
@ -1049,9 +1045,9 @@ QVariant pki_x509::bg_color(const dbheader *hd) const
if (!crlExpire.isUndefined()) {
crlwarn = crlex.addSecs(-2 *60*60*24);
if (crlex < now)
return QVariant(BG_RED);
return QVariant(red);
if (crlwarn < now || !crlex.isValid())
return QVariant(BG_YELLOW);
return QVariant(yellow);
}
}
}

View File

@ -120,6 +120,8 @@ MainWindow::MainWindow() : QMainWindow()
views << keyView << reqView << certView << crlView << tempView;
pki_base::setupColors(palette());
foreach(XcaTreeView *v, views)
v->setMainwin(this, searchEdit);

View File

@ -549,3 +549,22 @@ void XcaTreeView::keyPressEvent(QKeyEvent *event)
}
QTreeView::keyPressEvent(event);
}
void XcaTreeView::changeEvent(QEvent *event)
{
bool c = false;
if (event->type() == QEvent::StyleChange)
{
qDebug() << "Style has been changed.";
c = true;
}
if (event->type() == QEvent::PaletteChange)
{
qDebug() << "Style has been changed.";
c = true;
}
if (c)
pki_base::setupColors(palette());
QTreeView::changeEvent(event);
}

View File

@ -58,6 +58,7 @@ class XcaTreeView: public QTreeView
void contextMenu(QContextMenuEvent *e,
QMenu *parent = NULL, int sect = -1);
void keyPressEvent(QKeyEvent *event);
void changeEvent(QEvent *event);
virtual void showPki(pki_base *) {};
virtual void exportItems(const QModelIndexList &indexes);
virtual void load_default(load_base *load);