diff --git a/pglab/ConnectionConfigurationWidget.cpp b/pglab/ConnectionConfigurationWidget.cpp index 8690359..b1b5603 100644 --- a/pglab/ConnectionConfigurationWidget.cpp +++ b/pglab/ConnectionConfigurationWidget.cpp @@ -120,6 +120,7 @@ ConnectionConfigurationWidget::ConnectionConfigurationWidget( cmbbxSsl->setModelColumn(0); auto ssl_model = new SslModeModel(this); cmbbxSsl->setModel(ssl_model); + cmbbxSsl->setEditable(true); lblSsl->setBuddy(cmbbxSsl); lblCert = new QLabel; @@ -206,7 +207,8 @@ void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg) edtPassword->setText(""); cmbDbname->setCurrentText(cfg.dbname()); - cmbbxSsl->setCurrentIndex(static_cast(cfg.sslMode())); + //cmbbxSsl->setCurrentIndex(static_cast(cfg.sslMode())); + cmbbxSsl->setCurrentText(cfg.getParameter("sslmode")); edtCert->setText(cfg.sslCert()); edtKey->setText(cfg.sslKey()); edtRootCert->setText(cfg.sslRootCert()); diff --git a/pglab/ResultTableModelUtil.cpp b/pglab/ResultTableModelUtil.cpp index 998101c..7328083 100644 --- a/pglab/ResultTableModelUtil.cpp +++ b/pglab/ResultTableModelUtil.cpp @@ -1,5 +1,4 @@ #include "ResultTableModelUtil.h" -#include "Pgsql_oids.h" #include #include @@ -28,29 +27,7 @@ Qt::Alignment GetDefaultAlignmentForType(Oid o) return r; } -QColor GetDefaultColorForType(Oid o) -{ - QColor c; - switch (o) { - case int2_oid: - case int4_oid: - case int8_oid: - c = GetDefaultIntegerColor(); - break; - case float4_oid: - case float8_oid: - c = GetDefaultFloatColor(); - break; - case numeric_oid: - c = GetDefaultNumericColor(); - break; - case oid_oid: - case bool_oid: - default: - c = Qt::black; - } - return c; -} + QString FormatBoolForDisplay(bool v) { diff --git a/pglab/ResultTableModelUtil.h b/pglab/ResultTableModelUtil.h index c59f3fb..9f32f09 100644 --- a/pglab/ResultTableModelUtil.h +++ b/pglab/ResultTableModelUtil.h @@ -1,10 +1,36 @@ #pragma once -#include "Pgsql_declare.h" +#include "Pgsql_oids.h" #include #include +#include Qt::Alignment GetDefaultAlignmentForType(Oid oid); -QColor GetDefaultColorForType(Oid oid); + +// inline QColor GetDefaultColorForType(Oid oid) +// { +// using namespace Pgsql; +// const ColorTheme &theme = GetColorTheme(); +// QColor c; +// switch (oid) { +// case int2_oid: +// case int4_oid: +// case int8_oid: +// c = theme.integerColor; +// break; +// case float4_oid: +// case float8_oid: +// c = theme.floatColor; +// break; +// case numeric_oid: +// c = theme.numericColor; +// break; +// case oid_oid: +// case bool_oid: +// default: +// c = Qt::black; +// } +// return c; +// } inline Qt::Alignment GetDefaultAlignment() { return Qt::AlignLeft | Qt::AlignVCenter; } inline Qt::Alignment GetDefaultBoolAlignment() { return Qt::AlignCenter | Qt::AlignVCenter; } @@ -12,13 +38,14 @@ inline Qt::Alignment GetDefaultNumberAlignment() { return Qt::AlignRight | Qt::A inline QColor GetDefaultBoolColor(bool v) { - return v ? Qt::darkGreen : Qt::darkRed; + const ColorTheme& colorTheme = GetColorTheme(); + return v ? colorTheme.booleanTrue : colorTheme.booleanFalse; } -inline QColor GetDefaultIntegerColor() { return Qt::darkBlue; } -inline QColor GetDefaultFloatColor() { return Qt::darkCyan; } -inline QColor GetDefaultNumericColor() { return Qt::darkGreen; } -inline QColor GetDefaultNullColor() { return Qt::gray; } +// inline QColor GetDefaultIntegerColor() { return Qt::darkBlue; } +// inline QColor GetDefaultFloatColor() { return Qt::darkCyan; } +// inline QColor GetDefaultNumericColor() { return Qt::darkGreen; } +// inline QColor GetDefaultNullColor() { return Qt::gray; } QString FormatBoolForDisplay(bool v); diff --git a/pglab/catalog/models/ColumnTableModel.cpp b/pglab/catalog/models/ColumnTableModel.cpp index 0ff9b47..8511dcf 100644 --- a/pglab/catalog/models/ColumnTableModel.cpp +++ b/pglab/catalog/models/ColumnTableModel.cpp @@ -30,6 +30,13 @@ namespace { } +ColumnTableModel::ColumnTableModel(QObject *parent) + : BaseTableModel(parent) + , theme(GetColorTheme()) +{ + +} + void ColumnTableModel::setData(std::shared_ptr cat, const std::optional &table) { if (cat != m_catalog) { @@ -285,22 +292,19 @@ QVariant ColumnTableModel::data(const QModelIndex &index, int role) const QVariant v; const auto &t = m_columns[index.row()]; if (t.typid == InvalidOid) - v = QBrush(Qt::black); + v = QBrush(theme.defaultTextColor); else { auto c = m_catalog->types()->getByKey(t.typid); switch (c->category) { - case TypCategory::Boolean: - v = QBrush(Qt::darkGreen); - break; case TypCategory::Numeric: - v = QBrush(Qt::darkBlue); + v = QBrush(theme.numericTypeColor); break; case TypCategory::DateTime: case TypCategory::Timespan: - v = QBrush(Qt::darkMagenta); + v = QBrush(theme.dateTimeTypeColor); break; case TypCategory::String: - v = QBrush(Qt::darkYellow); + v = QBrush(theme.stringTypeColor); break; case TypCategory::Array: case TypCategory::Composite: @@ -313,7 +317,8 @@ QVariant ColumnTableModel::data(const QModelIndex &index, int role) const case TypCategory::BitString: case TypCategory::Unknown: default: - v = QBrush(Qt::black); + v = QBrush(theme.defaultTextColor); + break; } } return v; diff --git a/pglab/catalog/models/ColumnTableModel.h b/pglab/catalog/models/ColumnTableModel.h index edee3fd..680ee13 100644 --- a/pglab/catalog/models/ColumnTableModel.h +++ b/pglab/catalog/models/ColumnTableModel.h @@ -1,6 +1,7 @@ #ifndef COLUMNTABLEMODEL_H #define COLUMNTABLEMODEL_H +#include "util/Colors.h" #include "catalog/models/BaseTableModel.h" #include "catalog/PgAttribute.h" #include "catalog/PgDatabaseCatalog.h" @@ -29,7 +30,8 @@ public: colCount }; - using BaseTableModel::BaseTableModel; + + explicit ColumnTableModel(QObject *parent = nullptr); void setData(std::shared_ptr cat, const std::optional &table); // Header: @@ -57,6 +59,9 @@ protected: QString getFKey(const PgAttribute &column) const; QString getDefaultString(const PgAttribute &column) const; +private: + const ColorTheme &theme; + private slots: /// Retrieves required data from catalog, called everytime it might have changed void refresh(); diff --git a/pglab/codeeditor/CodeEditor.cpp b/pglab/codeeditor/CodeEditor.cpp index ee591a8..0107c7f 100644 --- a/pglab/codeeditor/CodeEditor.cpp +++ b/pglab/codeeditor/CodeEditor.cpp @@ -14,6 +14,7 @@ CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) , gutterArea(new EditorGutter(this)) + , colorTheme(GetColorTheme()) { connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateGutterAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateGutterArea(QRect,int))); @@ -69,8 +70,7 @@ void CodeEditor::resizeEvent(QResizeEvent *e) void CodeEditor::highlightCurrentLine() { QTextEdit::ExtraSelection selection; - QColor lineColor = QColor(Qt::yellow).lighter(160); - selection.format.setBackground(lineColor); + selection.format.setBackground(colorTheme.currentLine); selection.format.setProperty(QTextFormat::FullWidthSelection, true); selection.cursor = textCursor(); selection.cursor.clearSelection(); @@ -87,8 +87,7 @@ void CodeEditor::onTextChanged() void CodeEditor::addErrorMarker(int position, int length) { QTextEdit::ExtraSelection selection; - QColor lineColor = QColor(Qt::red).lighter(160); - selection.format.setBackground(lineColor); + selection.format.setBackground(colorTheme.errorLine); selection.format.setFontItalic(true); selection.cursor = textCursor(); selection.cursor.setPosition(position); diff --git a/pglab/codeeditor/CodeEditor.h b/pglab/codeeditor/CodeEditor.h index aa6ab02..4a3303d 100644 --- a/pglab/codeeditor/CodeEditor.h +++ b/pglab/codeeditor/CodeEditor.h @@ -3,6 +3,7 @@ #include #include +#include "util/Colors.h" /** This class adds some capabilities to QPlainTextEdit that are useful * in code editor scenarios. @@ -39,6 +40,7 @@ private: QTextEdit::ExtraSelection currentLine; QList errorMarkers; + const ColorTheme &colorTheme; std::set errorLines; diff --git a/pglab/codeeditor/GutterPainter.cpp b/pglab/codeeditor/GutterPainter.cpp index 59a4198..f662dff 100644 --- a/pglab/codeeditor/GutterPainter.cpp +++ b/pglab/codeeditor/GutterPainter.cpp @@ -7,11 +7,14 @@ GutterPainter::GutterPainter(CodeEditor *editor, QPaintEvent *event) , painter(editor->gutterArea) , event(event) , fontMetrics(editor->fontMetrics()) -{} + , colorTheme(GetColorTheme()) +{ + +} void GutterPainter::Paint() { - painter.fillRect(event->rect(), Qt::lightGray); + painter.fillRect(event->rect(), colorTheme.gutterBackground); LoopState loopState(editor); // We will now loop through all visible lines and paint the line numbers in the @@ -37,7 +40,7 @@ void GutterPainter::Paint() void GutterPainter::drawLineNumber(const LoopState &loopState) { QString number = QString::number(loopState.blockNumber() + 1); - painter.setPen(Qt::black); + painter.setPen(colorTheme.lineNumber); painter.drawText(0, loopState.top, editor->gutterArea->width(), fontMetrics.height(), Qt::AlignRight, number); } diff --git a/pglab/codeeditor/GutterPainter.h b/pglab/codeeditor/GutterPainter.h index ebe37f8..03e89f8 100644 --- a/pglab/codeeditor/GutterPainter.h +++ b/pglab/codeeditor/GutterPainter.h @@ -1,5 +1,6 @@ #include #include +#include "util/Colors.h" #pragma once @@ -13,10 +14,13 @@ public: void Paint(); private: + CodeEditor *editor; QPainter painter; QPaintEvent *event; QFontMetrics fontMetrics; + const ColorTheme &colorTheme; + struct LoopState { CodeEditor *editor; diff --git a/pglab/crud/CrudModel.cpp b/pglab/crud/CrudModel.cpp index 344f7c6..90637bb 100644 --- a/pglab/crud/CrudModel.cpp +++ b/pglab/crud/CrudModel.cpp @@ -234,7 +234,7 @@ void CrudModel::loadIntoModel(std::shared_ptr data) initializeColumnList(); lastRowKey = data->rows() - 1; initRowMapping(); - appendNewRow(); + appendNewRowInternal(); endResetModel(); } @@ -549,10 +549,15 @@ void CrudModel::appendNewRow() { int row = static_cast(m_rowMapping.size()); beginInsertRows(QModelIndex(), row, row); - m_rowMapping.emplace_back(allocNewRowKey(), std::vector(m_roData->cols())); + appendNewRowInternal(); endInsertRows(); } +void CrudModel::appendNewRowInternal() +{ + m_rowMapping.emplace_back(allocNewRowKey(), std::vector(m_roData->cols())); +} + std::tuple CrudModel::removeRows(const std::set> &row_ranges) { if (row_ranges.empty()) diff --git a/pglab/crud/CrudModel.h b/pglab/crud/CrudModel.h index 4cf7f77..822c5fd 100644 --- a/pglab/crud/CrudModel.h +++ b/pglab/crud/CrudModel.h @@ -246,6 +246,7 @@ private: std::tuple> saveRow(const PendingRow &pending_row); void appendNewRow(); + void appendNewRowInternal(); int lastRowKey = -1; int allocNewRowKey() { return ++lastRowKey; } diff --git a/pglab/main.cpp b/pglab/main.cpp index 1796186..cfb3924 100644 --- a/pglab/main.cpp +++ b/pglab/main.cpp @@ -1,8 +1,10 @@ #include "MasterController.h" +#include "util/Colors.h" #include #ifdef _WIN32 # include #endif +#include #include int main(int argc, char *argv[]) @@ -28,6 +30,8 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationDomain("eelkeklein.nl"); QCoreApplication::setApplicationName("pglab"); + InitApplicationPalette(); + int result = -1; { // make sure the io_service is stopped before we wait on the future diff --git a/pglab/pglab.pro b/pglab/pglab.pro index 2ff93a5..93a9186 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -58,6 +58,7 @@ SOURCES += main.cpp\ serverinspector/DatabasesPage.cpp \ serverinspector/RolesPage.cpp \ serverinspector/ServerInspector.cpp \ + util/Colors.cpp \ util/PgLabItemDelegate.cpp \ util/PgLabTableView.cpp \ util/SqlSyntaxHighlighter.cpp \ @@ -130,6 +131,7 @@ HEADERS += \ serverinspector/DatabasesPage.h \ serverinspector/RolesPage.h \ serverinspector/ServerInspector.h \ + util/Colors.h \ util/PgLabItemDelegate.h \ util/PgLabTableView.h \ util/PgLabTableViewHelper.h \ diff --git a/pglab/util/Colors.cpp b/pglab/util/Colors.cpp new file mode 100644 index 0000000..3a62693 --- /dev/null +++ b/pglab/util/Colors.cpp @@ -0,0 +1,147 @@ +#include "Colors.h" + +#include +#include +#include + + +bool isDarkModeInternal() +{ + QPalette palette = QGuiApplication::palette(); + QColor backgroundColor = palette.color(QPalette::Window); + return backgroundColor.lightness() < 128; // Check if the background color is dark +} + +bool isDarkMode() +{ + static bool darkMode = isDarkModeInternal(); + return darkMode; +} + +ColorTheme GetLightMode() +{ + ColorTheme t; + + t.defaultTextColor = Qt::black; + + t.gutterBackground = Qt::lightGray; + t.lineNumber = Qt::black; + t.currentLine = QColor(Qt::yellow).lighter(160); + t.errorLine = QColor(Qt::red).lighter(160); + + t.keyword = QColor(32, 32, 192); + t.comment = QColor(128, 128, 128); + t.quotedString = QColor(192, 32, 192); + t.quotedIdentifier = QColor(192, 128, 32); + t.type = QColor(32, 192, 32); + t.parameter = QColor(192, 32, 32); + + t.gigaBytes = QColorConstants::Svg::darkorange; + t.megaBytes = QColorConstants::Svg::darkgoldenrod; + t.kiloBytes = QColorConstants::Svg::darkgreen; + t.bytes = QColorConstants::Svg::darkblue; + + t.booleanTrue = Qt::darkGreen; + t.booleanFalse = Qt::darkRed; + + t.integerColor = Qt::darkBlue; + t.floatColor = Qt::darkCyan; + t.numericColor = Qt::darkGreen; + t.nullColor = Qt::gray; + + t.numericTypeColor = Qt::darkBlue; + t.dateTimeTypeColor = Qt::darkMagenta; + t.stringTypeColor = Qt::darkYellow; + + return t; +} + +ColorTheme GetDarkMode() +{ + ColorTheme t; + + t.defaultTextColor = Qt::lightGray; + + t.gutterBackground = QColor(Qt::darkGray).darker(400); + t.lineNumber = Qt::lightGray; + t.currentLine = QColor(Qt::darkGray).darker(400);; + t.errorLine = QColor(Qt::red).darker(180); + + t.keyword = QColor(160, 160, 255); + t.comment = QColor(160, 160, 160); + t.quotedString = QColor(255, 160, 255); + t.quotedIdentifier = QColor(255, 192, 128); + t.type = QColor(160, 255, 160); + t.parameter = QColor(255, 160, 160); + + t.gigaBytes = QColorConstants::Svg::lightcoral; + t.megaBytes = QColorConstants::Svg::lightgoldenrodyellow; + t.kiloBytes = QColorConstants::Svg::lightgreen; + t.bytes = QColorConstants::Svg::lightblue; + + t.booleanTrue = QColorConstants::Svg::lightgreen; + t.booleanFalse = QColorConstants::Svg::lightcoral; + + t.integerColor = QColorConstants::Svg::deepskyblue; + t.floatColor = QColorConstants::Svg::cyan; + t.numericColor = QColorConstants::Svg::lime; + t.nullColor = Qt::darkGray; + + t.numericTypeColor = QColorConstants::Svg::lightblue; + t.dateTimeTypeColor = QColor(Qt::magenta); + t.stringTypeColor = QColor(Qt::yellow); + + return t; +} + +const ColorTheme& GetColorTheme() +{ + static ColorTheme lightMode = GetLightMode(); + static ColorTheme darkMode = GetDarkMode(); + + return isDarkMode() ? darkMode : lightMode; +} + +void InitApplicationPalette() +{ + if (isDarkMode()) + { + QPalette pal = QGuiApplication::palette(); + pal.setColor(QPalette::Active, QPalette::Base, QColor(20, 20, 20)); + pal.setColor(QPalette::Active, QPalette::AlternateBase, Qt::black); + pal.setColor(QPalette::Inactive, QPalette::Base, QColor(20, 20, 20)); + pal.setColor(QPalette::Inactive, QPalette::AlternateBase, Qt::black); + QGuiApplication::setPalette(pal); + } +} + +QColor ColorTheme::GetColorForType(Oid oid) const +{ + using namespace Pgsql; + + QColor c; + switch (oid) { + case int2_oid: + case int4_oid: + case int8_oid: + c = integerColor; + break; + + case float4_oid: + case float8_oid: + c = floatColor; + break; + + case numeric_oid: + c = numericColor; + break; + + case varchar_oid: + case text_oid: + case oid_oid: + case bool_oid: + default: + c = defaultTextColor; + } + return c; +} diff --git a/pglab/util/Colors.h b/pglab/util/Colors.h new file mode 100644 index 0000000..e3f09c6 --- /dev/null +++ b/pglab/util/Colors.h @@ -0,0 +1,48 @@ +#include +#include "Pgsql_oids.h" + +#pragma once + +bool isDarkMode(); + +struct ColorTheme +{ + QColor defaultTextColor; + + QColor gutterBackground; + QColor lineNumber; + QColor currentLine; + QColor errorLine; + + QColor keyword; + QColor comment; + QColor quotedString; + QColor quotedIdentifier; + QColor type; + QColor parameter; + + QColor gigaBytes; + QColor megaBytes; + QColor kiloBytes; + QColor bytes; + + QColor booleanTrue; + QColor booleanFalse; + + QColor integerColor; + QColor floatColor; + QColor numericColor; + QColor nullColor; + + QColor numericTypeColor; + QColor dateTimeTypeColor; + QColor stringTypeColor; + + + QColor GetColorForType(Oid oid) const; + +}; + +const ColorTheme& GetColorTheme(); + +void InitApplicationPalette(); diff --git a/pglab/util/PgLabItemDelegate.cpp b/pglab/util/PgLabItemDelegate.cpp index d51f7b0..85fbc78 100644 --- a/pglab/util/PgLabItemDelegate.cpp +++ b/pglab/util/PgLabItemDelegate.cpp @@ -1,11 +1,14 @@ #include "util/PgLabItemDelegate.h" #include +#include #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(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 diff --git a/pglab/util/PgLabTableView.cpp b/pglab/util/PgLabTableView.cpp index 836dbdd..1038815 100644 --- a/pglab/util/PgLabTableView.cpp +++ b/pglab/util/PgLabTableView.cpp @@ -6,14 +6,19 @@ PgLabTableView::PgLabTableView(QWidget *parent) : QTableView(parent) { - setAlternatingRowColors(true); - setItemDelegate(new PgLabItemDelegate(this)); - setWordWrap(false); + setAlternatingRowColors(true); - auto pal = palette(); - pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight)); - pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText)); - setPalette(pal); + setItemDelegate(new PgLabItemDelegate(this)); + setWordWrap(false); + + QPalette pal = palette(); + + //pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight)); + //pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText)); + + // pal.setColor(QPalette::Active, QPalette::Base, QColor(20, 20, 20)); + // pal.setColor(QPalette::Active, QPalette::AlternateBase, Qt::black); + // setPalette(pal); auto vertical_header = verticalHeader(); vertical_header->setMinimumSectionSize(16); diff --git a/pglab/util/PgLabTableViewHelper.h b/pglab/util/PgLabTableViewHelper.h index e8c2363..ccc6f8c 100644 --- a/pglab/util/PgLabTableViewHelper.h +++ b/pglab/util/PgLabTableViewHelper.h @@ -47,6 +47,7 @@ public: m_itemView->setModel(m_sortFilter); m_itemView->setSortingEnabled(true); m_sortFilter->sort(0, Qt::AscendingOrder); + } PgLabTableViewHelper(QWidget * parent) diff --git a/pglab/util/SqlSyntaxHighlighter.cpp b/pglab/util/SqlSyntaxHighlighter.cpp index e5d0f11..2a5546e 100644 --- a/pglab/util/SqlSyntaxHighlighter.cpp +++ b/pglab/util/SqlSyntaxHighlighter.cpp @@ -2,25 +2,28 @@ #include "catalog/PgTypeContainer.h" #include "SqlLexer.h" +#include "util/Colors.h" SqlSyntaxHighlighter::SqlSyntaxHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { - m_keywordFormat.setForeground(QColor(32, 32, 192)); - m_keywordFormat.setFontWeight(QFont::Bold); + const ColorTheme& theme = GetColorTheme(); - m_commentFormat.setForeground(QColor(128, 128, 128)); + m_keywordFormat.setForeground(theme.keyword); + m_keywordFormat.setFontWeight(QFont::Bold); - m_quotedStringFormat.setForeground(QColor(192, 32, 192)); + m_commentFormat.setForeground(theme.comment); - m_quotedIdentifierFormat.setForeground(QColor(192, 128, 32)); + m_quotedStringFormat.setForeground(theme.quotedString); - m_typeFormat.setForeground(QColor(32, 192, 32)); + m_quotedIdentifierFormat.setForeground(theme.quotedIdentifier); + + m_typeFormat.setForeground(theme.type); m_typeFormat.setFontWeight(QFont::Bold); - m_parameterFormat.setForeground(QColor(192, 32, 32)); + m_parameterFormat.setForeground(theme.parameter); m_parameterFormat.setFontWeight(QFont::Bold); }