diff --git a/lib/main.cpp b/lib/main.cpp index 5d041726..a504c57d 100644 --- a/lib/main.cpp +++ b/lib/main.cpp @@ -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; diff --git a/lib/pki_base.cpp b/lib/pki_base.cpp index 803cfef9..40c1d2f2 100644 --- a/lib/pki_base.cpp +++ b/lib/pki_base.cpp @@ -21,6 +21,7 @@ pki_lookup Store; QRegularExpression pki_base::limitPattern; bool pki_base::pem_comment; QList 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)); +} diff --git a/lib/pki_base.h b/lib/pki_base.h index 01b89eb8..20bcb85f 100644 --- a/lib/pki_base.h +++ b/lib/pki_base.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include #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 allitems; + static void setupColors(const QPalette &pal); protected: QVariant sqlItemId; @@ -69,6 +72,7 @@ class pki_base : public QObject virtual void collect_properties(QMap &) const; QList childItems; mutable QRegularExpression lastPattern; + static QBrush red, yellow, cyan; public: enum msg_type { diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index 9d72de99..09c19eb0 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -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); } } } diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index 2d955bd2..679ed2ab 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -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); diff --git a/widgets/XcaTreeView.cpp b/widgets/XcaTreeView.cpp index fda07292..6702d022 100644 --- a/widgets/XcaTreeView.cpp +++ b/widgets/XcaTreeView.cpp @@ -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); +} diff --git a/widgets/XcaTreeView.h b/widgets/XcaTreeView.h index 7e58a18d..2b7ca187 100644 --- a/widgets/XcaTreeView.h +++ b/widgets/XcaTreeView.h @@ -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);