Dark mode support
Centralized all colors, tweaked application paletter in darkmode to make it darker.
This commit is contained in:
parent
aac55b0ed1
commit
86a9a0d709
19 changed files with 335 additions and 73 deletions
|
|
@ -1,11 +1,14 @@
|
|||
#include "util/PgLabItemDelegate.h"
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
#include "Pgsql_oids.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "AbstractEditorFactory.h"
|
||||
#include "Colors.h"
|
||||
#include "utils/HumanReadableBytes.h"
|
||||
#include "qstyleoption.h"
|
||||
|
||||
PgLabItemDelegate::PgLabItemDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
|
|
@ -83,6 +86,8 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
// }
|
||||
// }
|
||||
|
||||
const ColorTheme &theme = GetColorTheme();
|
||||
|
||||
Oid oid = InvalidOid;
|
||||
value = index.data(CustomDataTypeRole); // get OID
|
||||
if (value.isValid())
|
||||
|
|
@ -99,9 +104,7 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
|
||||
|
||||
if (value.isValid() && ! value.isNull()) {
|
||||
QColor forground_color = oid == Pgsql::bool_oid
|
||||
? GetDefaultBoolColor(value.toBool())
|
||||
: GetDefaultColorForType(oid);
|
||||
QColor forground_color;
|
||||
|
||||
option->features |= QStyleOptionViewItem::HasDisplay;
|
||||
if (oid == Pgsql::bool_oid) {
|
||||
|
|
@ -110,7 +113,7 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
option->text = FormatBoolForDisplay(b);
|
||||
}
|
||||
else {
|
||||
forground_color = GetDefaultColorForType(oid);
|
||||
forground_color = theme.GetColorForType(oid);
|
||||
if (meaning == DataMeaning::Bytes) {
|
||||
option->text = HandleBytes(value.toLongLong(), forground_color);
|
||||
}
|
||||
|
|
@ -123,13 +126,22 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
|
||||
}
|
||||
else {
|
||||
option->palette.setBrush(QPalette::Text, QBrush(GetDefaultNullColor()));
|
||||
option->palette.setBrush(QPalette::Text, QBrush(theme.nullColor));
|
||||
|
||||
option->features |= QStyleOptionViewItem::HasDisplay;
|
||||
option->text = "null";
|
||||
}
|
||||
|
||||
|
||||
// if (option->state & QStyle::State_HasFocus) {
|
||||
// QColor color = Qt::darkYellow;
|
||||
// option->palette.setColor(QPalette::Active, QPalette::Highlight, color);
|
||||
// // option->palette.setColor(QPalette::Active, QPalette::AlternateBase, color);
|
||||
// option->backgroundBrush = QBrush(color);
|
||||
// option->font.setWeight(QFont::ExtraBold);
|
||||
// }
|
||||
|
||||
|
||||
// option->backgroundBrush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole));
|
||||
|
||||
// disable style animations for checkboxes etc. within itemviews (QTBUG-30146)
|
||||
|
|
@ -138,22 +150,25 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
|
||||
QString PgLabItemDelegate::HandleBytes(qlonglong s, QColor &forground_color) const
|
||||
{
|
||||
const ColorTheme& theme = GetColorTheme();
|
||||
auto str = HumanReadableBytes(s);
|
||||
if (s > 1024 * 1024 * 1024) {
|
||||
forground_color = QColorConstants::Svg::darkorange;
|
||||
forground_color = theme.gigaBytes;
|
||||
}
|
||||
else if (s > 1024 * 1024) {
|
||||
forground_color = QColorConstants::Svg::darkgoldenrod;
|
||||
forground_color = theme.megaBytes;
|
||||
}
|
||||
else if (s > 1024) {
|
||||
forground_color = QColorConstants::Svg::darkgreen;
|
||||
forground_color = theme.kiloBytes;
|
||||
}
|
||||
else {
|
||||
forground_color = QColorConstants::Svg::darkblue;
|
||||
forground_color = theme.bytes;
|
||||
}
|
||||
return QString::fromStdString(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PgLabItemDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
|
|
@ -165,6 +180,13 @@ void PgLabItemDelegate::paint(QPainter *painter,
|
|||
const QWidget *widget = option.widget; // QStyledItemDelegatePrivate::widget(option);
|
||||
QStyle *style = widget ? widget->style() : QApplication::style();
|
||||
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
|
||||
|
||||
if (option.state & QStyle::State_HasFocus) {
|
||||
QColor color = Qt::red;
|
||||
painter->setPen(QPen(QBrush(color), 2.0));
|
||||
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QWidget *PgLabItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue