Skip to content

Commit

Permalink
Merge pull request sqlitebrowser#377 from schdub/browser.colors
Browse files Browse the repository at this point in the history
enhancement: advanced data browser colors preferences
  • Loading branch information
schdub committed Jul 1, 2015
2 parents 3343345 + b2e8dc3 commit 42583a3
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 88 deletions.
59 changes: 43 additions & 16 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
ui->setupUi(this);
ui->treeSyntaxHighlighting->setColumnHidden(0, true);

ui->frameNullBgColour->installEventFilter(this);
ui->frameNullFgColour->installEventFilter(this);
ui->fr_bin_bg->installEventFilter(this);
ui->fr_bin_fg->installEventFilter(this);
ui->fr_reg_bg->installEventFilter(this);
ui->fr_reg_fg->installEventFilter(this);
ui->fr_null_bg->installEventFilter(this);
ui->fr_null_fg->installEventFilter(this);

#ifndef CHECKNEWVERSION
ui->labelUpdates->setVisible(false);
Expand Down Expand Up @@ -58,15 +62,12 @@ void PreferencesDialog::loadSettings()
ui->foreignKeysCheckBox->setChecked(getSettingsValue("db", "foreignkeys").toBool());
ui->spinPrefetchSize->setValue(getSettingsValue("db", "prefetchsize").toInt());

QPalette palette = ui->frameNullBgColour->palette();
palette.setColor(ui->frameNullBgColour->backgroundRole(),
QColor(getSettingsValue("databrowser", "null_bg_colour").toString()));
ui->frameNullBgColour->setPalette(palette);

palette = ui->frameNullFgColour->palette();
palette.setColor(ui->frameNullFgColour->backgroundRole(),
QColor(getSettingsValue("databrowser", "null_fg_colour").toString()));
ui->frameNullFgColour->setPalette(palette);
loadColorSetting(ui->fr_null_fg, "null_fg");
loadColorSetting(ui->fr_null_bg, "null_bg");
loadColorSetting(ui->fr_reg_fg, "reg_fg");
loadColorSetting(ui->fr_reg_bg, "reg_bg");
loadColorSetting(ui->fr_bin_fg, "bin_fg");
loadColorSetting(ui->fr_bin_bg, "bin_bg");

ui->txtNull->setText(getSettingsValue("databrowser", "null_text").toString());

Expand Down Expand Up @@ -106,10 +107,12 @@ void PreferencesDialog::saveSettings()

setSettingsValue("checkversion", "enabled", ui->checkUpdates->isChecked());

setSettingsValue("databrowser", "null_bg_colour",
ui->frameNullBgColour->palette().color(ui->frameNullBgColour->backgroundRole()));
setSettingsValue("databrowser", "null_fg_colour",
ui->frameNullFgColour->palette().color(ui->frameNullFgColour->backgroundRole()));
saveColorSetting(ui->fr_null_fg, "null_fg");
saveColorSetting(ui->fr_null_bg, "null_bg");
saveColorSetting(ui->fr_reg_fg, "reg_fg");
saveColorSetting(ui->fr_reg_bg, "reg_bg");
saveColorSetting(ui->fr_bin_fg, "bin_fg");
saveColorSetting(ui->fr_bin_bg, "bin_bg");
setSettingsValue("databrowser", "null_text", ui->txtNull->text());

for(int i=0; i < ui->treeSyntaxHighlighting->topLevelItemCount(); ++i)
Expand Down Expand Up @@ -241,6 +244,14 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
return QColor(Qt::lightGray).name();
if (name == "null_bg_colour")
return QColor(Qt::white).name();
if (name == "reg_fg_colour")
return QColor(Qt::black).name();
if (name == "reg_bg_colour")
return QColor(Qt::white).name();
if (name == "bin_fg_colour")
return QColor(Qt::lightGray).name();
if (name == "bin_bg_colour")
return QColor(Qt::white).name();
}

// syntaxhighlighter?
Expand Down Expand Up @@ -339,7 +350,9 @@ void PreferencesDialog::showColourDialog(QTreeWidgetItem* item, int column)
bool PreferencesDialog::eventFilter(QObject *obj, QEvent *event)
{
// Use mouse click and enter press on the frames to pop up a colour dialog
if (obj == ui->frameNullBgColour || obj == ui->frameNullFgColour)
if (obj == ui->fr_bin_bg || obj == ui->fr_bin_fg ||
obj == ui->fr_reg_bg || obj == ui->fr_reg_fg ||
obj == ui->fr_null_bg || obj == ui->fr_null_fg)
{
if (event->type() == QEvent::KeyPress)
{
Expand Down Expand Up @@ -455,3 +468,17 @@ void PreferencesDialog::fillLanguageBox()
ui->languageComboBox->insertItem(0, chosenIcon, chosenLanguage, chosenLocale);
ui->languageComboBox->setCurrentIndex(0);
}

void PreferencesDialog::loadColorSetting(QFrame *frame, const QString & settingName)
{
QPalette palette = frame->palette();
palette.setColor(frame->backgroundRole(),
QColor(getSettingsValue("databrowser", settingName + "_colour").toString()));
frame->setPalette(palette);
}

void PreferencesDialog::saveColorSetting(QFrame *frame, const QString & settingName)
{
setSettingsValue("databrowser", settingName + "_colour",
frame->palette().color(frame->backgroundRole()));
}
3 changes: 3 additions & 0 deletions src/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QHash>

class QTreeWidgetItem;
class QFrame;

namespace Ui {
class PreferencesDialog;
Expand Down Expand Up @@ -42,6 +43,8 @@ private slots:
static QHash<QString, QVariant> m_hCache;

void fillLanguageBox();
void loadColorSetting(QFrame *frame, const QString &name);
void saveColorSetting(QFrame *frame, const QString &name);

protected:
bool eventFilter(QObject *obj, QEvent *event);
Expand Down
Loading

0 comments on commit 42583a3

Please sign in to comment.