Skip to content

Commit 486ff1b

Browse files
committed
Fixed font for windows, added font name to preferences
1 parent f92d18a commit 486ff1b

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/fhex.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ Fhex::Fhex(QWidget *parent, QApplication *app, QString filepath)
4848
int y_position = screenSize.height() / 2 - height / 2;
4949
bool maximized = false;
5050
this->fontSize = 12;
51-
51+
#ifdef Q_OS_WIN32
52+
this->fontName = "Courier";
53+
#else
54+
this->fontName = "Monospace";
55+
#endif
5256
// Pattern
5357
patternsEnabled = false;
5458

@@ -78,8 +82,11 @@ Fhex::Fhex(QWidget *parent, QApplication *app, QString filepath)
7882
if (!jconfig["FileSizeLimit"].is_null()) {
7983
this->file_size_limit = jconfig["FileSizeLimit"].get<unsigned long>();
8084
}
81-
if (!jconfig["FontSize"].is_null()) {
82-
this->fontSize = jconfig["FontSize"].get<short>();
85+
if (!jconfig["Font"]["Size"].is_null()) {
86+
this->fontSize = jconfig["Font"]["Size"].get<short>();
87+
}
88+
if (!jconfig["Font"]["Name"].is_null()) {
89+
this->fontName = jconfig["Font"]["Name"].get<string>().c_str();
8390
}
8491
}
8592

@@ -216,7 +223,7 @@ Fhex::Fhex(QWidget *parent, QApplication *app, QString filepath)
216223
qhex->setAddressAreaColor(color_dark_gray);
217224
qhex->setSelectionColor(color_dark_yellow);
218225
qhex->setHighlightingColor(color_dark_violet);
219-
qhex->setFont(QFont("Monospace", this->fontSize));
226+
qhex->setFont(QFont(this->fontName, this->fontSize));
220227

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

@@ -384,6 +391,11 @@ void Fhex::on_menu_open_settings_click() {
384391
selectPatternsFile->setFixedWidth(80);
385392
form->addRow(labelPatternsFile);
386393
form->addRow(patternsFile, selectPatternsFile);
394+
QLabel *labelFontName = new QLabel("Font Name:", newWindow);
395+
QLineEdit *fontName = new QLineEdit(newWindow);
396+
fontName->setText(this->fontName);
397+
fontName->setFixedWidth(300);
398+
form->addRow(labelFontName, fontName);
387399
QPushButton *btnSave = new QPushButton("Save", newWindow);
388400
btnSave->setFixedWidth(80);
389401
QPushButton *btnCancel = new QPushButton("Cancel", newWindow);
@@ -399,11 +411,12 @@ void Fhex::on_menu_open_settings_click() {
399411
{
400412
newWindow->close();
401413
});
402-
connect(btnSave, &QPushButton::clicked, [this, newWindow, chunkSize, enablePatterns, patternsFile]()
414+
connect(btnSave, &QPushButton::clicked, [this, newWindow, chunkSize, enablePatterns, patternsFile, fontName]()
403415
{
404416
this->patternsFile = patternsFile->text().toStdString();
405417
this->patternsEnabled = enablePatterns->isChecked();
406418
this->file_size_limit = chunkSize->text().toLongLong();
419+
this->fontName = fontName->text();
407420
newWindow->close();
408421
});
409422
QWidget *mainWidget = new QWidget(newWindow);
@@ -539,12 +552,12 @@ void Fhex::keyPressEvent(QKeyEvent *event) {
539552
} else if (((event->key() == Qt::Key_Minus) || (event->key() == Qt::Key_Down)) && QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
540553
if (this->fontSize > 2)
541554
this->fontSize -= 1;
542-
this->qhex->setFont(QFont("Monospace", this->fontSize));
555+
this->qhex->setFont(QFont(this->fontName, this->fontSize));
543556
this->updateUI();
544557
} else if (((event->key() == Qt::Key_Plus) || (event->key() == Qt::Key_Up)) && QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
545558
if (this->fontSize < 40)
546559
this->fontSize += 1;
547-
this->qhex->setFont(QFont("Monospace", this->fontSize));
560+
this->qhex->setFont(QFont(this->fontName, this->fontSize));
548561
this->updateUI();
549562
}
550563
updateOffsetBar();
@@ -1150,7 +1163,8 @@ void Fhex::saveSettings(string filePath){
11501163
jsettings["Patterns"]["enabled"] = this->patternsEnabled;
11511164
jsettings["Patterns"]["file"] = this->patternsFile;
11521165
jsettings["FileSizeLimit"] = this->file_size_limit;
1153-
jsettings["FontSize"] = this->fontSize;
1166+
jsettings["Font"]["Size"] = this->fontSize;
1167+
jsettings["Font"]["Name"] = this->fontName.toStdString();
11541168

11551169
// Merge changes
11561170
jconfig.merge_patch(jsettings);

src/fhex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Fhex : public QMainWindow
110110
HexEditor *hexEditor;
111111
QHexEdit *qhex;
112112
short fontSize;
113+
QString fontName;
113114
QFrame *convertBox;
114115
QLabel statusBar;
115116
QLabel offsetBar;

src/qhexedit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ QHexEdit::QHexEdit(QWidget *parent) : QAbstractScrollArea(parent)
2929
_chunks = new Chunks(this);
3030
_undoStack = new UndoStack(_chunks, this);
3131
#ifdef Q_OS_WIN32
32-
setFont(QFont("Courier", 10));
32+
setFont(QFont("Courier", 12));
3333
#else
3434
setFont(QFont("Monospace", 12));
3535
#endif

0 commit comments

Comments
 (0)