mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
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:
parent
e8cd69c45d
commit
cccc8ee1e3
@ -472,7 +472,12 @@ int main(int argc, char *argv[])
|
|||||||
if (d && *d)
|
if (d && *d)
|
||||||
debug_info::set_debug(QString(d));
|
debug_info::set_debug(QString(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
|
// If no style provided externally
|
||||||
|
if (!QApplication::style())
|
||||||
|
QApplication::setStyle("Fusion");
|
||||||
|
|
||||||
AttachConsole(-1);
|
AttachConsole(-1);
|
||||||
|
|
||||||
int wargc;
|
int wargc;
|
||||||
|
|||||||
@ -21,6 +21,7 @@ pki_lookup Store;
|
|||||||
QRegularExpression pki_base::limitPattern;
|
QRegularExpression pki_base::limitPattern;
|
||||||
bool pki_base::pem_comment;
|
bool pki_base::pem_comment;
|
||||||
QList<pki_base*> pki_base::allitems;
|
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)
|
pki_base::pki_base(const QString &name, pki_base *p)
|
||||||
{
|
{
|
||||||
@ -493,3 +494,17 @@ QStringList pki_base::icsVEVENT(const a1time &expires,
|
|||||||
"END:VALARM" <<
|
"END:VALARM" <<
|
||||||
"END:VEVENT";
|
"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));
|
||||||
|
}
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QBrush>
|
||||||
#include "BioByteArray.h"
|
#include "BioByteArray.h"
|
||||||
#include "asn1time.h"
|
#include "asn1time.h"
|
||||||
#include "pkcs11_lib.h"
|
#include "pkcs11_lib.h"
|
||||||
@ -55,6 +57,7 @@ class pki_base : public QObject
|
|||||||
static bool pem_comment;
|
static bool pem_comment;
|
||||||
static int count;
|
static int count;
|
||||||
static QList<pki_base*> allitems;
|
static QList<pki_base*> allitems;
|
||||||
|
static void setupColors(const QPalette &pal);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant sqlItemId;
|
QVariant sqlItemId;
|
||||||
@ -69,6 +72,7 @@ class pki_base : public QObject
|
|||||||
virtual void collect_properties(QMap<QString, QString> &) const;
|
virtual void collect_properties(QMap<QString, QString> &) const;
|
||||||
QList<pki_base*> childItems;
|
QList<pki_base*> childItems;
|
||||||
mutable QRegularExpression lastPattern;
|
mutable QRegularExpression lastPattern;
|
||||||
|
static QBrush red, yellow, cyan;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum msg_type {
|
enum msg_type {
|
||||||
|
|||||||
@ -1002,10 +1002,6 @@ bool pki_x509::visible() const
|
|||||||
|
|
||||||
QVariant pki_x509::bg_color(const dbheader *hd) 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"])
|
if (Settings["no_expire_colors"])
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
@ -1031,15 +1027,15 @@ QVariant pki_x509::bg_color(const dbheader *hd) const
|
|||||||
switch (hd->id) {
|
switch (hd->id) {
|
||||||
case HD_cert_notBefore:
|
case HD_cert_notBefore:
|
||||||
if (nb > now || !nb.isValid() || nb.isUndefined())
|
if (nb > now || !nb.isValid() || nb.isUndefined())
|
||||||
return QVariant(BG_RED);
|
return QVariant(red);
|
||||||
break;
|
break;
|
||||||
case HD_cert_notAfter: {
|
case HD_cert_notAfter: {
|
||||||
if (na.isUndefined())
|
if (na.isUndefined())
|
||||||
return QVariant(BG_CYAN);
|
return QVariant(cyan);
|
||||||
if (na < now)
|
if (na < now)
|
||||||
return QVariant(BG_RED);
|
return QVariant(red);
|
||||||
if (certwarn < now)
|
if (certwarn < now)
|
||||||
return QVariant(BG_YELLOW);
|
return QVariant(yellow);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HD_cert_crl_expire:
|
case HD_cert_crl_expire:
|
||||||
@ -1049,9 +1045,9 @@ QVariant pki_x509::bg_color(const dbheader *hd) const
|
|||||||
if (!crlExpire.isUndefined()) {
|
if (!crlExpire.isUndefined()) {
|
||||||
crlwarn = crlex.addSecs(-2 *60*60*24);
|
crlwarn = crlex.addSecs(-2 *60*60*24);
|
||||||
if (crlex < now)
|
if (crlex < now)
|
||||||
return QVariant(BG_RED);
|
return QVariant(red);
|
||||||
if (crlwarn < now || !crlex.isValid())
|
if (crlwarn < now || !crlex.isValid())
|
||||||
return QVariant(BG_YELLOW);
|
return QVariant(yellow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,6 +120,8 @@ MainWindow::MainWindow() : QMainWindow()
|
|||||||
|
|
||||||
views << keyView << reqView << certView << crlView << tempView;
|
views << keyView << reqView << certView << crlView << tempView;
|
||||||
|
|
||||||
|
pki_base::setupColors(palette());
|
||||||
|
|
||||||
foreach(XcaTreeView *v, views)
|
foreach(XcaTreeView *v, views)
|
||||||
v->setMainwin(this, searchEdit);
|
v->setMainwin(this, searchEdit);
|
||||||
|
|
||||||
|
|||||||
@ -549,3 +549,22 @@ void XcaTreeView::keyPressEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
QTreeView::keyPressEvent(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);
|
||||||
|
}
|
||||||
|
|||||||
@ -58,6 +58,7 @@ class XcaTreeView: public QTreeView
|
|||||||
void contextMenu(QContextMenuEvent *e,
|
void contextMenu(QContextMenuEvent *e,
|
||||||
QMenu *parent = NULL, int sect = -1);
|
QMenu *parent = NULL, int sect = -1);
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
void changeEvent(QEvent *event);
|
||||||
virtual void showPki(pki_base *) {};
|
virtual void showPki(pki_base *) {};
|
||||||
virtual void exportItems(const QModelIndexList &indexes);
|
virtual void exportItems(const QModelIndexList &indexes);
|
||||||
virtual void load_default(load_base *load);
|
virtual void load_default(load_base *load);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user