add preference option to select default and text font
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(lammps-gui VERSION 1.1.2 LANGUAGES CXX)
|
||||
project(lammps-gui VERSION 1.1.3 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
@ -213,8 +213,8 @@ void Highlighter::highlightBlock(const QString &text)
|
||||
auto undo = QRegularExpression("^(unfix|uncompute|undump)\\s+(\\w+)").match(text);
|
||||
bool do_style = true;
|
||||
bool do_force = true;
|
||||
bool do_defs = true;
|
||||
bool do_undo = true;
|
||||
bool do_defs = true;
|
||||
bool do_undo = true;
|
||||
for (const HighlightingRule &rule : qAsConst(highlightingRules)) {
|
||||
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
|
||||
while (matchIterator.hasNext()) {
|
||||
@ -226,17 +226,17 @@ void Highlighter::highlightBlock(const QString &text)
|
||||
setFormat(style.capturedStart(3), style.capturedLength(3), stringFormat);
|
||||
setFormat(style.capturedStart(4), style.capturedLength(4), runFormat);
|
||||
do_style = false;
|
||||
// special treatment for force styles styles
|
||||
// special treatment for force styles styles
|
||||
} else if (force.hasMatch() && do_force) {
|
||||
setFormat(force.capturedStart(1), force.capturedLength(1), particleFormat);
|
||||
setFormat(force.capturedStart(2), force.capturedLength(2), runFormat);
|
||||
do_force = false;
|
||||
// special treatment for undo commands
|
||||
// special treatment for undo commands
|
||||
} else if (undo.hasMatch() && do_undo) {
|
||||
setFormat(undo.capturedStart(1), undo.capturedLength(1), defineFormat);
|
||||
setFormat(undo.capturedStart(2), undo.capturedLength(2), stringFormat);
|
||||
do_undo = false;
|
||||
// special treatment for some definitions
|
||||
// special treatment for some definitions
|
||||
} else if (defs.hasMatch() && do_defs) {
|
||||
setFormat(defs.capturedStart(1), defs.capturedLength(1), particleFormat);
|
||||
setFormat(defs.capturedStart(2), defs.capturedLength(2), stringFormat);
|
||||
|
||||
@ -143,9 +143,14 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
|
||||
QFont all_font("Arial", -1);
|
||||
all_font.setStyleHint(QFont::SansSerif, QFont::PreferOutline);
|
||||
all_font.fromString(settings.value("allfont", all_font.toString()).toString());
|
||||
settings.setValue("allfont", all_font.toString());
|
||||
QApplication::setFont(all_font);
|
||||
QFont text_font("Monospace");
|
||||
|
||||
QFont text_font("Monospace", -1);
|
||||
text_font.setStyleHint(QFont::Monospace, QFont::PreferOutline);
|
||||
text_font.fromString(settings.value("textfont", text_font.toString()).toString());
|
||||
settings.setValue("textfont", text_font.toString());
|
||||
ui->textEdit->document()->setDefaultFont(text_font);
|
||||
ui->textEdit->setMinimumSize(600, 400);
|
||||
|
||||
|
||||
@ -24,6 +24,8 @@
|
||||
|
||||
// forward declarations
|
||||
|
||||
class GeneralTab;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class LammpsGui;
|
||||
@ -45,6 +47,7 @@ class LammpsGui : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
friend class CodeEditor;
|
||||
friend class GeneralTab;
|
||||
|
||||
public:
|
||||
LammpsGui(QWidget *parent = nullptr, const char *filename = nullptr);
|
||||
@ -81,8 +84,10 @@ private slots:
|
||||
void preferences();
|
||||
void defaults();
|
||||
|
||||
private:
|
||||
protected:
|
||||
Ui::LammpsGui *ui;
|
||||
|
||||
private:
|
||||
Highlighter *highlighter;
|
||||
StdCapture *capturer;
|
||||
QLabel *status;
|
||||
|
||||
@ -13,14 +13,18 @@
|
||||
|
||||
#include "preferences.h"
|
||||
|
||||
#include "lammpsgui.h"
|
||||
#include "lammpswrapper.h"
|
||||
#include "ui_lammpsgui.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QDoubleValidator>
|
||||
#include <QFileDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QIntValidator>
|
||||
@ -121,6 +125,7 @@ void Preferences::accept()
|
||||
if (box) settings->setValue("viewlog", box->isChecked());
|
||||
box = tabWidget->findChild<QCheckBox *>("viewchart");
|
||||
if (box) settings->setValue("viewchart", box->isChecked());
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
@ -158,6 +163,7 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
|
||||
tmplayout->addWidget(tmplabel);
|
||||
tmplayout->addWidget(tmpedit);
|
||||
tmplayout->addWidget(tmpbrowse);
|
||||
connect(tmpbrowse, &QPushButton::released, this, &GeneralTab::newtmpfolder);
|
||||
#endif
|
||||
|
||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||
@ -172,6 +178,15 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
|
||||
|
||||
connect(pluginbrowse, &QPushButton::released, this, &GeneralTab::pluginpath);
|
||||
#endif
|
||||
|
||||
auto *fontlayout = new QHBoxLayout;
|
||||
auto *getallfont = new QPushButton("Select Default Font...");
|
||||
auto *gettextfont = new QPushButton("Select Text Font...");
|
||||
fontlayout->addWidget(getallfont);
|
||||
fontlayout->addWidget(gettextfont);
|
||||
connect(getallfont, &QPushButton::released, this, &GeneralTab::newallfont);
|
||||
connect(gettextfont, &QPushButton::released, this, &GeneralTab::newtextfont);
|
||||
|
||||
layout->addWidget(echo);
|
||||
layout->addWidget(cite);
|
||||
layout->addWidget(logv);
|
||||
@ -185,10 +200,49 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
|
||||
layout->addWidget(pluginlabel);
|
||||
layout->addLayout(pluginlayout);
|
||||
#endif
|
||||
layout->addLayout(fontlayout);
|
||||
layout->addStretch(1);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void GeneralTab::updatefonts(const QFont &all, const QFont &text)
|
||||
{
|
||||
LammpsGui *main;
|
||||
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
|
||||
|
||||
QApplication::setFont(all);
|
||||
main->ui->textEdit->document()->setDefaultFont(text);
|
||||
}
|
||||
|
||||
void GeneralTab::newallfont()
|
||||
{
|
||||
QSettings settings;
|
||||
QFont all, text;
|
||||
all.fromString(settings.value("allfont", "").toString());
|
||||
text.fromString(settings.value("textfont", "").toString());
|
||||
|
||||
bool ok = false;
|
||||
QFont font = QFontDialog::getFont(&ok, all, this, QString("Select Default Font"));
|
||||
if (ok) updatefonts(font, text);
|
||||
|
||||
settings.setValue("allfont", font.toString());
|
||||
}
|
||||
|
||||
void GeneralTab::newtextfont()
|
||||
{
|
||||
QSettings settings;
|
||||
QFont all, text;
|
||||
all.fromString(settings.value("allfont", "").toString());
|
||||
text.fromString(settings.value("textfont", "").toString());
|
||||
|
||||
bool ok = false;
|
||||
QFont font = QFontDialog::getFont(&ok, text, this, QString("Select Text Font"));
|
||||
if (ok) updatefonts(all, font);
|
||||
|
||||
settings.setValue("textfont", font.toString());
|
||||
}
|
||||
|
||||
void GeneralTab::newtmpfolder()
|
||||
{
|
||||
QLineEdit *field = findChild<QLineEdit *>("tmpedit");
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include <QDialog>
|
||||
|
||||
class QDialogButtonBox;
|
||||
class QFont;
|
||||
class QSettings;
|
||||
class QTabWidget;
|
||||
class LammpsWrapper;
|
||||
@ -49,8 +50,11 @@ public:
|
||||
private slots:
|
||||
void pluginpath();
|
||||
void newtmpfolder();
|
||||
void newallfont();
|
||||
void newtextfont();
|
||||
|
||||
private:
|
||||
void updatefonts(const QFont &all, const QFont &text);
|
||||
QSettings *settings;
|
||||
LammpsWrapper *lammps;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user