Skip to content

Commit

Permalink
Fixed font for windows, added font name to preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-devim committed Feb 18, 2021
1 parent f92d18a commit 486ff1b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
30 changes: 22 additions & 8 deletions src/fhex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ Fhex::Fhex(QWidget *parent, QApplication *app, QString filepath)
int y_position = screenSize.height() / 2 - height / 2;
bool maximized = false;
this->fontSize = 12;

#ifdef Q_OS_WIN32
this->fontName = "Courier";
#else
this->fontName = "Monospace";
#endif
// Pattern
patternsEnabled = false;

Expand Down Expand Up @@ -78,8 +82,11 @@ Fhex::Fhex(QWidget *parent, QApplication *app, QString filepath)
if (!jconfig["FileSizeLimit"].is_null()) {
this->file_size_limit = jconfig["FileSizeLimit"].get<unsigned long>();
}
if (!jconfig["FontSize"].is_null()) {
this->fontSize = jconfig["FontSize"].get<short>();
if (!jconfig["Font"]["Size"].is_null()) {
this->fontSize = jconfig["Font"]["Size"].get<short>();
}
if (!jconfig["Font"]["Name"].is_null()) {
this->fontName = jconfig["Font"]["Name"].get<string>().c_str();
}
}

Expand Down Expand Up @@ -216,7 +223,7 @@ Fhex::Fhex(QWidget *parent, QApplication *app, QString filepath)
qhex->setAddressAreaColor(color_dark_gray);
qhex->setSelectionColor(color_dark_yellow);
qhex->setHighlightingColor(color_dark_violet);
qhex->setFont(QFont("Monospace", this->fontSize));
qhex->setFont(QFont(this->fontName, this->fontSize));

gridLayout->addWidget(qhex, 1, 0, 1, 2);

Expand Down Expand Up @@ -384,6 +391,11 @@ void Fhex::on_menu_open_settings_click() {
selectPatternsFile->setFixedWidth(80);
form->addRow(labelPatternsFile);
form->addRow(patternsFile, selectPatternsFile);
QLabel *labelFontName = new QLabel("Font Name:", newWindow);
QLineEdit *fontName = new QLineEdit(newWindow);
fontName->setText(this->fontName);
fontName->setFixedWidth(300);
form->addRow(labelFontName, fontName);
QPushButton *btnSave = new QPushButton("Save", newWindow);
btnSave->setFixedWidth(80);
QPushButton *btnCancel = new QPushButton("Cancel", newWindow);
Expand All @@ -399,11 +411,12 @@ void Fhex::on_menu_open_settings_click() {
{
newWindow->close();
});
connect(btnSave, &QPushButton::clicked, [this, newWindow, chunkSize, enablePatterns, patternsFile]()
connect(btnSave, &QPushButton::clicked, [this, newWindow, chunkSize, enablePatterns, patternsFile, fontName]()
{
this->patternsFile = patternsFile->text().toStdString();
this->patternsEnabled = enablePatterns->isChecked();
this->file_size_limit = chunkSize->text().toLongLong();
this->fontName = fontName->text();
newWindow->close();
});
QWidget *mainWidget = new QWidget(newWindow);
Expand Down Expand Up @@ -539,12 +552,12 @@ void Fhex::keyPressEvent(QKeyEvent *event) {
} else if (((event->key() == Qt::Key_Minus) || (event->key() == Qt::Key_Down)) && QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
if (this->fontSize > 2)
this->fontSize -= 1;
this->qhex->setFont(QFont("Monospace", this->fontSize));
this->qhex->setFont(QFont(this->fontName, this->fontSize));
this->updateUI();
} else if (((event->key() == Qt::Key_Plus) || (event->key() == Qt::Key_Up)) && QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
if (this->fontSize < 40)
this->fontSize += 1;
this->qhex->setFont(QFont("Monospace", this->fontSize));
this->qhex->setFont(QFont(this->fontName, this->fontSize));
this->updateUI();
}
updateOffsetBar();
Expand Down Expand Up @@ -1150,7 +1163,8 @@ void Fhex::saveSettings(string filePath){
jsettings["Patterns"]["enabled"] = this->patternsEnabled;
jsettings["Patterns"]["file"] = this->patternsFile;
jsettings["FileSizeLimit"] = this->file_size_limit;
jsettings["FontSize"] = this->fontSize;
jsettings["Font"]["Size"] = this->fontSize;
jsettings["Font"]["Name"] = this->fontName.toStdString();

// Merge changes
jconfig.merge_patch(jsettings);
Expand Down
1 change: 1 addition & 0 deletions src/fhex.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Fhex : public QMainWindow
HexEditor *hexEditor;
QHexEdit *qhex;
short fontSize;
QString fontName;
QFrame *convertBox;
QLabel statusBar;
QLabel offsetBar;
Expand Down
2 changes: 1 addition & 1 deletion src/qhexedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ QHexEdit::QHexEdit(QWidget *parent) : QAbstractScrollArea(parent)
_chunks = new Chunks(this);
_undoStack = new UndoStack(_chunks, this);
#ifdef Q_OS_WIN32
setFont(QFont("Courier", 10));
setFont(QFont("Courier", 12));
#else
setFont(QFont("Monospace", 12));
#endif
Expand Down

0 comments on commit 486ff1b

Please sign in to comment.