Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/ui/dialogs/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#pragma once

#include <QColorDialog>
#include <QDialog>
#include <QtCore>

Expand All @@ -37,13 +38,16 @@ class OptionsDialog : public QDialog {
Ui::OptionsDialog* ui;
void show();
void applyChanges();
void updateColorButton();

public slots:
void accept() override;

private:
ColorPickerButton* color_3d_begin_button_;
ColorPickerButton* color_3d_end_button_;
QColorDialog* color_dialog;
QColorDialog* color_dialog_;
};

} // namespace ui
Expand Down
4 changes: 4 additions & 0 deletions include/util/settings/hexedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
#pragma once

#include <QColor>

namespace veles {
namespace util {
namespace settings {
Expand All @@ -25,6 +27,8 @@ int columnsNumber();
void setColumnsNumber(int number);
bool resizeColumnsToWindowWidth();
void setResizeColumnsToWindowWidth(bool on);
QColor colorOfBytes();
void setColorOfBytes(const QColor& color);

} // namespace hexedit
} // namespace settings
Expand Down
31 changes: 31 additions & 0 deletions src/ui/dialogs/optionsdialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
*/
#include "ui/dialogs/optionsdialog.h"

#include "include/ui/optionsdialog.h"

#include <QColorDialog>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>

#include "ui/veles_mainwindow.h"
#include "ui/velesapplication.h"
#include "ui/hexedit.h"
#include "ui/veles_mainwindow.h"
#include "ui_optionsdialog.h"
#include "util/settings/hexedit.h"
#include "util/settings/theme.h"
Expand All @@ -35,6 +41,15 @@ OptionsDialog::OptionsDialog(QWidget* parent)
ui->setupUi(this);
ui->colorsBox->addItems(util::settings::theme::availableThemes());

color_dialog_ = new QColorDialog(this);
color_dialog_->setCurrentColor(util::settings::hexedit::colorOfBytes());
ui->byteColorHexEdit->setAutoFillBackground(true);
ui->byteColorHexEdit->setFlat(true);

connect(ui->byteColorHexEdit, &QPushButton::clicked, color_dialog_,
&QColorDialog::show);
connect(color_dialog_, &QColorDialog::colorSelected, this,
&OptionsDialog::updateColorButton);
connect(ui->hexColumnsAutoCheckBox, &QCheckBox::stateChanged,
[this](int state) {
ui->hexColumnsSpinBox->setEnabled(state != Qt::Checked);
Expand All @@ -53,6 +68,13 @@ OptionsDialog::OptionsDialog(QWidget* parent)

OptionsDialog::~OptionsDialog() { delete ui; }

void OptionsDialog::updateColorButton() {
QPalette pal = ui->byteColorHexEdit->palette();
pal.setColor(QPalette::Button, color_dialog_->currentColor());
ui->byteColorHexEdit->setPalette(pal);
ui->byteColorHexEdit->update();
}

void OptionsDialog::show() {
ui->colorsBox->setCurrentText(util::settings::theme::currentTheme());
Qt::CheckState checkState = Qt::Unchecked;
Expand All @@ -62,6 +84,7 @@ void OptionsDialog::show() {
ui->hexColumnsAutoCheckBox->setCheckState(checkState);
ui->hexColumnsSpinBox->setValue(util::settings::hexedit::columnsNumber());
ui->hexColumnsSpinBox->setEnabled(checkState != Qt::Checked);
updateColorButton();

QWidget::show();
}
Expand All @@ -77,12 +100,20 @@ void OptionsDialog::applyChanges() {
util::settings::hexedit::setResizeColumnsToWindowWidth(
ui->hexColumnsAutoCheckBox->checkState() == Qt::Checked);
util::settings::hexedit::setColumnsNumber(ui->hexColumnsSpinBox->value());
util::settings::hexedit::setColorOfBytes(color_dialog_->currentColor());

util::settings::visualization::setColorBegin(
color_3d_begin_button_->getColor());
util::settings::visualization::setColorEnd(color_3d_end_button_->getColor());

emit VelesApplication::instance()->settingsChanged();
for (auto main_window :
MainWindowWithDetachableDockWidgets::getMainWindows()) {
QList<HexEdit*> widgets = main_window->findChildren<HexEdit*>();
for (auto widget : widgets) {
widget->viewport()->update();
}
}

if (restart_needed) {
QMessageBox::about(
Expand Down
21 changes: 18 additions & 3 deletions src/ui/dialogs/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<item>
<widget class="QLabel" name="labelHexEditColors">
<property name="text">
<string>Colors</string>
<string>Theme</string>
</property>
</widget>
</item>
Expand All @@ -47,15 +47,30 @@
<item>
<widget class="QGroupBox" name="gbHexEdit">
<property name="title">
<string>HexEdit defaults</string>
<string>HexEdit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="labelHexEditWidgetColors">
<property name="text">
<string>Byte color</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="byteColorHexEdit">
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="hexColumnsLabel">
<property name="text">
<string>Columns</string>
<string>Default Columns</string>
</property>
</widget>
</item>
Expand Down
12 changes: 12 additions & 0 deletions src/util/settings/hexedit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
#include "util/settings/hexedit.h"

#include <QColor>
#include <QSettings>

namespace veles {
Expand Down Expand Up @@ -43,6 +44,17 @@ void setResizeColumnsToWindowWidth(bool on) {
settings.setValue("hexedit.resizeColumnsToWindowWidth", on);
}

QColor colorOfBytes() {
QSettings settings;
auto v = settings.value("hexedit.colorOfBytes", QColor(10, 255, 10));
return v.value<QColor>();
}

void setColorOfBytes(const QColor& color) {
QSettings settings;
settings.setValue("hexedit.colorOfBytes", color);
}

} // namespace hexedit
} // namespace settings
} // namespace util
Expand Down
24 changes: 6 additions & 18 deletions src/util/settings/theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <QSettings>
#include <QStyleFactory>

#include "util/settings/hexedit.h"
#include "util/settings/theme.h"

namespace veles {
namespace util {
namespace settings {
Expand Down Expand Up @@ -88,28 +91,13 @@ QColor chunkBackground(int color_index) {
}
QColor ret =
chunkBackgroundColors_[color_index % chunkBackgroundColors_.size()];
if (isDark()) {
ret = QColor(ret.red() ^ 0xff, ret.green() ^ 0xff, ret.blue() ^ 0xff);
}

return ret;
return colorInvertedIfDark(ret);
}

QColor byteColor(uint8_t byte) {
if (isDark()) {
byte ^= 0xFF;
}

int red, blue, green = 0;
if (byte <= 0x80) {
blue = 0xff;
red = qMin(0xff, byte * 2);
} else {
blue = qMin(0xff, (0xff - byte) * 2);
red = 0xff;
}

return colorInvertedIfDark(QColor(red, green, blue));
QColor color = util::settings::hexedit::colorOfBytes();
return QColor::fromHsv(color.hue(), color.saturation(), 50 + byte * (220 - 50) / 256);
}

QFont font() {
Expand Down