add font setting dailog
This commit is contained in:
parent
1cff02124a
commit
8eb83d9cbf
@ -9,6 +9,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
@ -54,6 +55,16 @@ const QString RecourceHelper::GetResourcesPath() const {
|
|||||||
return QApplication::applicationDirPath() + "/resources";
|
return QApplication::applicationDirPath() + "/resources";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString RecourceHelper::GetUiConfigPath() const {
|
||||||
|
#if _DEBUG
|
||||||
|
const QString iniFile = QString("%1config/ui.ini").arg(QString(CONFIG_PATH));
|
||||||
|
#else
|
||||||
|
const QString appDirPath = QApplication::applicationDirPath();
|
||||||
|
const QString iniFile = QString("%1/config/ui.ini").arg(appDirPath);
|
||||||
|
#endif
|
||||||
|
return iniFile;
|
||||||
|
}
|
||||||
|
|
||||||
void RecourceHelper::ChangeSkin(const QString& skin) {
|
void RecourceHelper::ChangeSkin(const QString& skin) {
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
const QString qssFile = QString("%1skin/%2.qss").arg(QString(CONFIG_PATH)).arg(skin);
|
const QString qssFile = QString("%1skin/%2.qss").arg(QString(CONFIG_PATH)).arg(skin);
|
||||||
@ -104,3 +115,16 @@ void RecourceHelper::Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RecourceHelper::EmitFontChanged() {
|
||||||
|
emit FontChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecourceHelper::ApplyGlobalFont(const QFont& f) {
|
||||||
|
qApp->setFont(f);
|
||||||
|
const QWidgetList widgets = QApplication::allWidgets();
|
||||||
|
for (QWidget* w : widgets) {
|
||||||
|
if (w) w->setFont(f);
|
||||||
|
}
|
||||||
|
EmitFontChanged();
|
||||||
|
}
|
||||||
|
|||||||
@ -27,6 +27,14 @@ public:
|
|||||||
|
|
||||||
const QString GetBasePath() const;
|
const QString GetBasePath() const;
|
||||||
const QString GetResourcesPath() const;
|
const QString GetResourcesPath() const;
|
||||||
|
const QString GetUiConfigPath() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void FontChanged();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void EmitFontChanged();
|
||||||
|
void ApplyGlobalFont(const QFont& f);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init();
|
void Init();
|
||||||
|
|||||||
22
src/main.cpp
22
src/main.cpp
@ -8,6 +8,9 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QLockFile>
|
#include <QLockFile>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QFontInfo>
|
||||||
|
#include <QFontDatabase>
|
||||||
|
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
#include "common/RecourceHelper.h"
|
#include "common/RecourceHelper.h"
|
||||||
@ -32,7 +35,6 @@ int main(int argc, char* argv[]) {
|
|||||||
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||||
InstallCrashHandler();
|
InstallCrashHandler();
|
||||||
|
|
||||||
//字体高分屏自适应
|
|
||||||
const float DEFAULT_DPI = 96.0;
|
const float DEFAULT_DPI = 96.0;
|
||||||
HDC screen = GetDC(NULL);
|
HDC screen = GetDC(NULL);
|
||||||
FLOAT dpiX = static_cast<FLOAT>(GetDeviceCaps(screen, LOGPIXELSX));
|
FLOAT dpiX = static_cast<FLOAT>(GetDeviceCaps(screen, LOGPIXELSX));
|
||||||
@ -40,8 +42,22 @@ int main(int argc, char* argv[]) {
|
|||||||
float fontSize = dpiX / DEFAULT_DPI;
|
float fontSize = dpiX / DEFAULT_DPI;
|
||||||
|
|
||||||
QFont font = app.font();
|
QFont font = app.font();
|
||||||
font.setPointSize(font.pointSize()*fontSize);
|
const QString uiIni = RecourceHelper::Get().GetUiConfigPath();
|
||||||
app.setFont(font);
|
QSettings uiSettings(uiIni, QSettings::IniFormat);
|
||||||
|
double userScale = uiSettings.value("ui/fontScale", 1.0).toDouble();
|
||||||
|
QString fam = uiSettings.value("ui/fontFamily", font.family()).toString();
|
||||||
|
QString sty = uiSettings.value("ui/fontStyle", QString()).toString();
|
||||||
|
bool italic = uiSettings.value("ui/italic", font.italic()).toBool();
|
||||||
|
double basePt = uiSettings.value("ui/basePointSize", 0.0).toDouble();
|
||||||
|
if (basePt <= 0.0) basePt = QFontInfo(font).pointSizeF();
|
||||||
|
QFontDatabase db;
|
||||||
|
QFont cfgFont = db.font(fam, sty, static_cast<int>(basePt));
|
||||||
|
cfgFont.setItalic(italic);
|
||||||
|
int cssWeight = uiSettings.value("ui/fontWeight", cfgFont.bold() ? 700 : 400).toInt();
|
||||||
|
int qtW = (cssWeight < 150 ? QFont::Thin : cssWeight < 250 ? QFont::ExtraLight : cssWeight < 350 ? QFont::Light : cssWeight < 450 ? QFont::Normal : cssWeight < 550 ? QFont::Medium : cssWeight < 650 ? QFont::DemiBold : cssWeight < 750 ? QFont::Bold : cssWeight < 850 ? QFont::ExtraBold : QFont::Black);
|
||||||
|
cfgFont.setWeight(qtW);
|
||||||
|
cfgFont.setPointSizeF(basePt * fontSize * userScale);
|
||||||
|
RecourceHelper::Get().ApplyGlobalFont(cfgFont);
|
||||||
|
|
||||||
// Single-instance guard to avoid multiple launches from repeated clicks
|
// Single-instance guard to avoid multiple launches from repeated clicks
|
||||||
const QString lockPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/Dyt_app.lock";
|
const QString lockPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/Dyt_app.lock";
|
||||||
|
|||||||
@ -27,13 +27,14 @@ CodeEdtUI::CodeEdtUI(QWidget *parent)
|
|||||||
|
|
||||||
editor = new QPlainTextEdit(this);
|
editor = new QPlainTextEdit(this);
|
||||||
|
|
||||||
QFont serifFont("Times", 20, QFont::Bold);
|
|
||||||
editor->setFont(serifFont);
|
|
||||||
|
|
||||||
syntaxHighlighter = new SyntaxHighlighter(editor->document());
|
syntaxHighlighter = new SyntaxHighlighter(editor->document());
|
||||||
|
|
||||||
setCentralWidget(editor);
|
setCentralWidget(editor);
|
||||||
|
|
||||||
|
connect(&RecourceHelper::Get(), &RecourceHelper::FontChanged, this, [this]() {
|
||||||
|
editor->setFont(qApp->font());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
InitBat();
|
InitBat();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
#include "SystemManagerMenu.h"
|
#include "SystemManagerMenu.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QFontInfo>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
#include "ui/MainFrame.h"
|
#include "ui/MainFrame.h"
|
||||||
@ -8,6 +14,9 @@
|
|||||||
#include "workspace/WorkSpaceManager.h"
|
#include "workspace/WorkSpaceManager.h"
|
||||||
#include "workspace/WorkSpace.h"
|
#include "workspace/WorkSpace.h"
|
||||||
|
|
||||||
|
#include "common/RecourceHelper.h"
|
||||||
|
#include "ui/Setting/FontSettingDialog.h"
|
||||||
|
|
||||||
#include "ui_SystemManagerMenu.h"
|
#include "ui_SystemManagerMenu.h"
|
||||||
|
|
||||||
SystemManagerMenu::SystemManagerMenu(QWidget* parent)
|
SystemManagerMenu::SystemManagerMenu(QWidget* parent)
|
||||||
@ -19,7 +28,7 @@ SystemManagerMenu::SystemManagerMenu(QWidget* parent)
|
|||||||
LOG_INFO("SystemManagerMenu init");
|
LOG_INFO("SystemManagerMenu init");
|
||||||
windowManagerMenu_ = new QMenu(this);
|
windowManagerMenu_ = new QMenu(this);
|
||||||
windowManagerMenu_->setWindowFlags(windowManagerMenu_->windowFlags() | Qt::FramelessWindowHint);
|
windowManagerMenu_->setWindowFlags(windowManagerMenu_->windowFlags() | Qt::FramelessWindowHint);
|
||||||
ui->menu_uisetting->setVisible(false);
|
ui->menu_uisetting->setVisible(true);
|
||||||
|
|
||||||
// When workspace changes, clear and rebuild window manager menu
|
// When workspace changes, clear and rebuild window manager menu
|
||||||
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged,
|
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged,
|
||||||
@ -100,7 +109,7 @@ void SystemManagerMenu::InitConnect() {
|
|||||||
//ui->menu_window_manager->setContextMenuPolicy(Qt::CustomContextMenu);
|
//ui->menu_window_manager->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(ui->menu_window_manager, &QToolButton::clicked,
|
connect(ui->menu_window_manager, &QToolButton::clicked,
|
||||||
this, &SystemManagerMenu::OnWindowManagerMenu);
|
this, &SystemManagerMenu::OnWindowManagerMenu);
|
||||||
connect(ui->menu_uisetting, &QToolButton::clicked, this, &SystemManagerMenu::signalShowUISetting);
|
connect(ui->menu_uisetting, &QToolButton::clicked, this, &SystemManagerMenu::OnUiSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemManagerMenu::OnExit() {
|
void SystemManagerMenu::OnExit() {
|
||||||
@ -132,6 +141,38 @@ void SystemManagerMenu::OnWindowManagerMenu() {
|
|||||||
windowManagerMenu_->exec(QCursor::pos());
|
windowManagerMenu_->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SystemManagerMenu::OnUiSetting() {
|
||||||
|
FontSettingDialog dlg(this);
|
||||||
|
dlg.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemManagerMenu::AdjustFontScale(double delta) {
|
||||||
|
/* const QString uiIni = RecourceHelper::Get().GetUiConfigPath();
|
||||||
|
QFileInfo fi(uiIni);
|
||||||
|
QDir().mkpath(fi.dir().path());
|
||||||
|
QSettings uiSettings(uiIni, QSettings::IniFormat);
|
||||||
|
double curScale = uiSettings.value("ui/fontScale", 1.0).toDouble();
|
||||||
|
double newScale = std::clamp(curScale + delta, 0.75, 2.0);
|
||||||
|
ApplyFontScale(newScale);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemManagerMenu::ApplyFontScale(double newScale) {
|
||||||
|
/*const QString uiIni = RecourceHelper::Get().GetUiConfigPath();
|
||||||
|
QFileInfo fi(uiIni);
|
||||||
|
QDir().mkpath(fi.dir().path());
|
||||||
|
QSettings uiSettings(uiIni, QSettings::IniFormat);
|
||||||
|
double oldScale = uiSettings.value("ui/fontScale", 1.0).toDouble();
|
||||||
|
|
||||||
|
QFont f = qApp->font();
|
||||||
|
const double currentPt = QFontInfo(f).pointSizeF();
|
||||||
|
const double baseScaledPt = (oldScale > 0.0) ? (currentPt / oldScale) : currentPt;
|
||||||
|
f.setPointSizeF(baseScaledPt * newScale);
|
||||||
|
qApp->setFont(f);
|
||||||
|
|
||||||
|
uiSettings.setValue("ui/fontScale", newScale);
|
||||||
|
uiSettings.sync();*/
|
||||||
|
}
|
||||||
|
|
||||||
void SystemManagerMenu::ReloadWindowManagerMenu() {
|
void SystemManagerMenu::ReloadWindowManagerMenu() {
|
||||||
if (!windowManagerMenu_) return;
|
if (!windowManagerMenu_) return;
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,9 @@ private:
|
|||||||
void OnExit();
|
void OnExit();
|
||||||
void OnWindowManagerMenu();
|
void OnWindowManagerMenu();
|
||||||
void ReloadWindowManagerMenu();
|
void ReloadWindowManagerMenu();
|
||||||
|
void OnUiSetting();
|
||||||
|
void AdjustFontScale(double delta);
|
||||||
|
void ApplyFontScale(double newScale);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void OnWorkspaceChanged(class WorkSpace* ws);
|
void OnWorkspaceChanged(class WorkSpace* ws);
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFontInfo>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "common/RecourceHelper.h"
|
#include "common/RecourceHelper.h"
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
@ -79,7 +82,9 @@ void PresetModelListWidget::startDrag(Qt::DropActions supportedActions) {
|
|||||||
// Draw text below the icon
|
// Draw text below the icon
|
||||||
painter.setPen(Qt::black);
|
painter.setPen(Qt::black);
|
||||||
QFont font = painter.font();
|
QFont font = painter.font();
|
||||||
font.setPointSize(8);
|
double basePt = QFontInfo(qApp->font()).pointSizeF();
|
||||||
|
if (basePt <= 0.0) basePt = 8.0;
|
||||||
|
font.setPointSizeF(std::max(6.0, basePt * 0.85));
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
|
|
||||||
QRect textRect(0, iconSize + 5, totalWidth, textHeight);
|
QRect textRect(0, iconSize + 5, totalWidth, textHeight);
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
#include "ui/DockWidget.h"
|
#include "ui/DockWidget.h"
|
||||||
#include "ui/DockTitleBar.h"
|
#include "ui/DockTitleBar.h"
|
||||||
#include "common/SpdLogger.h"
|
#include "common/SpdLogger.h"
|
||||||
|
#include "common/RecourceHelper.h"
|
||||||
|
#include <QApplication>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -75,17 +77,17 @@ void PolarPanel::InitUI()
|
|||||||
m_pChart->setBackgroundRoundness(0);
|
m_pChart->setBackgroundRoundness(0);
|
||||||
m_pChart->setTheme(QChart::ChartThemeBlueIcy);
|
m_pChart->setTheme(QChart::ChartThemeBlueIcy);
|
||||||
|
|
||||||
//×ø±êÖá
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
m_pThetaAxis = new QValueAxis();
|
m_pThetaAxis = new QValueAxis();
|
||||||
m_pThetaAxis->setTickCount(13);
|
m_pThetaAxis->setTickCount(13);
|
||||||
m_pThetaAxis->setLabelsFont(QFont("Microsoft YaHei"));
|
m_pThetaAxis->setLabelsFont(qApp->font());
|
||||||
m_pThetaAxis->setLabelFormat("%d");
|
m_pThetaAxis->setLabelFormat("%d");
|
||||||
m_pThetaAxis->setRange(0, 360);
|
m_pThetaAxis->setRange(0, 360);
|
||||||
m_pChart->addAxis(m_pThetaAxis, QPolarChart::PolarOrientationAngular);
|
m_pChart->addAxis(m_pThetaAxis, QPolarChart::PolarOrientationAngular);
|
||||||
|
|
||||||
m_pRadiusAxis = new QValueAxis();
|
m_pRadiusAxis = new QValueAxis();
|
||||||
m_pRadiusAxis->setTickCount(6);
|
m_pRadiusAxis->setTickCount(6);
|
||||||
m_pRadiusAxis->setLabelsFont(QFont("Microsoft YaHei"));
|
m_pRadiusAxis->setLabelsFont(qApp->font());
|
||||||
m_pRadiusAxis->setLabelFormat("%d");
|
m_pRadiusAxis->setLabelFormat("%d");
|
||||||
m_pRadiusAxis->setRange(0, 30);
|
m_pRadiusAxis->setRange(0, 30);
|
||||||
m_pChart->addAxis(m_pRadiusAxis, QPolarChart::PolarOrientationRadial);
|
m_pChart->addAxis(m_pRadiusAxis, QPolarChart::PolarOrientationRadial);
|
||||||
@ -98,6 +100,11 @@ void PolarPanel::InitUI()
|
|||||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
mainLayout->addWidget(mChartView);
|
mainLayout->addWidget(mChartView);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
|
connect(&RecourceHelper::Get(), &RecourceHelper::FontChanged, this, [this]() {
|
||||||
|
if (m_pThetaAxis) m_pThetaAxis->setLabelsFont(qApp->font());
|
||||||
|
if (m_pRadiusAxis) m_pRadiusAxis->setLabelsFont(qApp->font());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PolarPanel::GetTypeDisplayName() const
|
QString PolarPanel::GetTypeDisplayName() const
|
||||||
@ -346,3 +353,4 @@ void PolarPanel::updateParseFile(const QString& strFile, int nT, FileEntryPolar:
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#include "common/RecourceHelper.h"
|
||||||
138
src/ui/Setting/FontSettingDialog.cpp
Normal file
138
src/ui/Setting/FontSettingDialog.cpp
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
#include "FontSettingDialog.h"
|
||||||
|
#include "ui_FontSettingDialog.h"
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFontInfo>
|
||||||
|
#include <QFontDatabase>
|
||||||
|
|
||||||
|
#include "common/RecourceHelper.h"
|
||||||
|
|
||||||
|
FontSettingDialog::FontSettingDialog(QWidget* parent)
|
||||||
|
: Dialog(parent)
|
||||||
|
, ui(new Ui::FontSettingDialog) {
|
||||||
|
SetupUI(ui);
|
||||||
|
SetTitle(tr("字体设置"));
|
||||||
|
|
||||||
|
QFont f = qApp->font();
|
||||||
|
const QString uiIni = RecourceHelper::Get().GetUiConfigPath();
|
||||||
|
QSettings uiSettings(uiIni, QSettings::IniFormat);
|
||||||
|
QString family = uiSettings.value("ui/fontFamily", f.family()).toString();
|
||||||
|
QString style = uiSettings.value("ui/fontStyle", QString()).toString();
|
||||||
|
bool underline = uiSettings.value("ui/underline", false).toBool();
|
||||||
|
bool strike = uiSettings.value("ui/strikeOut", false).toBool();
|
||||||
|
|
||||||
|
basePt_ = QFontInfo(f).pointSizeF();
|
||||||
|
if (basePt_ <= 0.0) basePt_ = 9.0;
|
||||||
|
|
||||||
|
ui->preview->setText(tr("AaBb中文预览"));
|
||||||
|
|
||||||
|
ui->fontCombo->setCurrentText(family);
|
||||||
|
QFontDatabase db;
|
||||||
|
ui->styleCombo->clear();
|
||||||
|
QStringList styles = db.styles(ui->fontCombo->currentText());
|
||||||
|
ui->styleCombo->addItems(styles);
|
||||||
|
if (!style.isEmpty()) ui->styleCombo->setCurrentText(style);
|
||||||
|
ui->underlineCheck->setChecked(underline);
|
||||||
|
ui->strikeCheck->setChecked(strike);
|
||||||
|
|
||||||
|
ui->sizeList->clear();
|
||||||
|
QList<int> pts = db.pointSizes(ui->fontCombo->currentText(), ui->styleCombo->currentText());
|
||||||
|
if (pts.isEmpty()) pts = db.standardSizes();
|
||||||
|
for (int p : pts) {
|
||||||
|
ui->sizeList->addItem(QString::number(p));
|
||||||
|
if (p == static_cast<int>(basePt_)) ui->sizeList->setCurrentRow(ui->sizeList->count()-1);
|
||||||
|
}
|
||||||
|
UpdatePreview();
|
||||||
|
|
||||||
|
connect(ui->fontCombo, &QFontComboBox::currentTextChanged, this, [this](const QString& fam) {
|
||||||
|
QFontDatabase db;
|
||||||
|
ui->styleCombo->clear();
|
||||||
|
ui->styleCombo->addItems(db.styles(fam));
|
||||||
|
ui->sizeList->clear();
|
||||||
|
QList<int> pts = db.pointSizes(fam, ui->styleCombo->currentText());
|
||||||
|
if (pts.isEmpty()) pts = db.standardSizes();
|
||||||
|
for (int p : pts) {
|
||||||
|
ui->sizeList->addItem(QString::number(p));
|
||||||
|
}
|
||||||
|
UpdatePreview();
|
||||||
|
});
|
||||||
|
connect(ui->styleCombo, &QComboBox::currentTextChanged, this, [this](const QString&) {
|
||||||
|
QFontDatabase db;
|
||||||
|
ui->sizeList->clear();
|
||||||
|
QList<int> pts = db.pointSizes(ui->fontCombo->currentText(), ui->styleCombo->currentText());
|
||||||
|
if (pts.isEmpty()) pts = db.standardSizes();
|
||||||
|
for (int p : pts) {
|
||||||
|
ui->sizeList->addItem(QString::number(p));
|
||||||
|
}
|
||||||
|
UpdatePreview();
|
||||||
|
});
|
||||||
|
connect(ui->sizeList, &QListWidget::currentRowChanged, this, [this](int) { UpdatePreview(); });
|
||||||
|
connect(ui->underlineCheck, &QCheckBox::toggled, this, [this](bool) { UpdatePreview(); });
|
||||||
|
connect(ui->strikeCheck, &QCheckBox::toggled, this, [this](bool) { UpdatePreview(); });
|
||||||
|
connect(ui->btnApply, &QPushButton::clicked, this, [this]() {
|
||||||
|
ApplySelection();
|
||||||
|
});
|
||||||
|
connect(ui->btnOk, &QPushButton::clicked, this, [this]() {
|
||||||
|
ApplySelection();
|
||||||
|
accept();
|
||||||
|
});
|
||||||
|
connect(ui->btnReset, &QPushButton::clicked, this, [this]() {
|
||||||
|
ui->fontCombo->setCurrentText(QFontInfo(qApp->font()).family());
|
||||||
|
ui->styleCombo->setCurrentIndex(0);
|
||||||
|
int idx = ui->sizeList->row(ui->sizeList->findItems(QString::number(static_cast<int>(basePt_)), Qt::MatchExactly).value(0));
|
||||||
|
if (idx >= 0) ui->sizeList->setCurrentRow(idx);
|
||||||
|
ui->underlineCheck->setChecked(false);
|
||||||
|
ui->strikeCheck->setChecked(false);
|
||||||
|
UpdatePreview();
|
||||||
|
});
|
||||||
|
connect(ui->btnCancel, &QPushButton::clicked, this, [this]() { reject(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontSettingDialog::UpdatePreview() {
|
||||||
|
QFontDatabase db;
|
||||||
|
QString fam = ui->fontCombo->currentText();
|
||||||
|
QString sty = ui->styleCombo->currentText();
|
||||||
|
int pt = basePt_;
|
||||||
|
if (ui->sizeList->currentItem()) pt = ui->sizeList->currentItem()->text().toInt();
|
||||||
|
QFont f = db.font(fam, sty, pt);
|
||||||
|
f.setUnderline(ui->underlineCheck->isChecked());
|
||||||
|
f.setStrikeOut(ui->strikeCheck->isChecked());
|
||||||
|
ui->preview->setFont(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontSettingDialog::ApplySelection() {
|
||||||
|
const QString uiIni = RecourceHelper::Get().GetUiConfigPath();
|
||||||
|
QFileInfo fi(uiIni);
|
||||||
|
QDir().mkpath(fi.dir().path());
|
||||||
|
QSettings uiSettings(uiIni, QSettings::IniFormat);
|
||||||
|
|
||||||
|
QFontDatabase db;
|
||||||
|
QString fam = ui->fontCombo->currentText();
|
||||||
|
QString sty = ui->styleCombo->currentText();
|
||||||
|
int pt = basePt_;
|
||||||
|
if (ui->sizeList->currentItem()) pt = ui->sizeList->currentItem()->text().toInt();
|
||||||
|
QFont f = db.font(fam, sty, pt);
|
||||||
|
bool bold = sty.contains("Bold", Qt::CaseInsensitive);
|
||||||
|
bool italic = sty.contains("Italic", Qt::CaseInsensitive);
|
||||||
|
int w = bold ? 700 : 400;
|
||||||
|
f.setBold(bold);
|
||||||
|
f.setItalic(italic);
|
||||||
|
f.setUnderline(ui->underlineCheck->isChecked());
|
||||||
|
f.setStrikeOut(ui->strikeCheck->isChecked());
|
||||||
|
RecourceHelper::Get().ApplyGlobalFont(f);
|
||||||
|
|
||||||
|
uiSettings.setValue("ui/fontScale", 1.0);
|
||||||
|
uiSettings.setValue("ui/fontFamily", fam);
|
||||||
|
uiSettings.setValue("ui/fontStyle", sty);
|
||||||
|
uiSettings.setValue("ui/italic", italic);
|
||||||
|
uiSettings.setValue("ui/basePointSize", pt);
|
||||||
|
uiSettings.setValue("ui/fontWeight", w);
|
||||||
|
uiSettings.setValue("ui/underline", ui->underlineCheck->isChecked());
|
||||||
|
uiSettings.setValue("ui/strikeOut", ui->strikeCheck->isChecked());
|
||||||
|
uiSettings.sync();
|
||||||
|
}
|
||||||
|
FontSettingDialog::~FontSettingDialog() {
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
21
src/ui/Setting/FontSettingDialog.h
Normal file
21
src/ui/Setting/FontSettingDialog.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ui/Dialog.h"
|
||||||
|
|
||||||
|
namespace Ui { class FontSettingDialog; }
|
||||||
|
|
||||||
|
class FontSettingDialog : public Dialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit FontSettingDialog(QWidget* parent = 0);
|
||||||
|
~FontSettingDialog() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void UpdatePreview();
|
||||||
|
void ApplySelection();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::FontSettingDialog* ui{};
|
||||||
|
double basePt_{};
|
||||||
|
};
|
||||||
156
src/ui/Setting/FontSettingDialog.ui
Normal file
156
src/ui/Setting/FontSettingDialog.ui
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>FontSettingDialog</class>
|
||||||
|
<widget class="QWidget" name="FontSettingDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>528</width>
|
||||||
|
<height>548</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>字体设置</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="fontLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QFontComboBox" name="fontCombo"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="styleCombo"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="italicCheck">
|
||||||
|
<property name="text">
|
||||||
|
<string>斜体</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="weightSpin">
|
||||||
|
<property name="suffix">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>900</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>50</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>400</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="topLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="sizeList"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="preview">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>120</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>AaBb中文预览</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="effectsLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="underlineCheck">
|
||||||
|
<property name="text">
|
||||||
|
<string>下划线</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="strikeCheck">
|
||||||
|
<property name="text">
|
||||||
|
<string>删除线</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="buttonLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="spacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnApply">
|
||||||
|
<property name="text">
|
||||||
|
<string>应用</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnOk">
|
||||||
|
<property name="text">
|
||||||
|
<string>确定</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnReset">
|
||||||
|
<property name="text">
|
||||||
|
<string>重置</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnCancel">
|
||||||
|
<property name="text">
|
||||||
|
<string>取消</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@ -90,10 +90,10 @@ void AddTableFileDlg::onHeadersChanged() {
|
|||||||
|
|
||||||
if (!data.isEmpty() && !validateCurveData(data, headers.size())) {
|
if (!data.isEmpty() && !validateCurveData(data, headers.size())) {
|
||||||
ui->dataValidationLabel->setText(QString("Data values must match the number of headers (%1)").arg(headers.size()));
|
ui->dataValidationLabel->setText(QString("Data values must match the number of headers (%1)").arg(headers.size()));
|
||||||
ui->dataValidationLabel->setStyleSheet("color: red; font-size: 11px;");
|
ui->dataValidationLabel->setStyleSheet("color: red;");
|
||||||
} else {
|
} else {
|
||||||
ui->dataValidationLabel->setText(QString("Data values must match the number of headers (%1)").arg(headers.size()));
|
ui->dataValidationLabel->setText(QString("Data values must match the number of headers (%1)").arg(headers.size()));
|
||||||
ui->dataValidationLabel->setStyleSheet("color: gray; font-size: 11px;");
|
ui->dataValidationLabel->setStyleSheet("color: gray;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,10 +201,10 @@ void AddTableFileDlg::onCurveDataChanged() {
|
|||||||
if (!dataText.isEmpty() && !validateCurveData(dataText, headers.size())) {
|
if (!dataText.isEmpty() && !validateCurveData(dataText, headers.size())) {
|
||||||
ui->dataValidationLabel->setText(QString("Data count (%1) doesn't match headers count (%2)")
|
ui->dataValidationLabel->setText(QString("Data count (%1) doesn't match headers count (%2)")
|
||||||
.arg(dataList.size()).arg(headers.size()));
|
.arg(dataList.size()).arg(headers.size()));
|
||||||
ui->dataValidationLabel->setStyleSheet("color: red; font-size: 11px;");
|
ui->dataValidationLabel->setStyleSheet("color: red;");
|
||||||
} else {
|
} else {
|
||||||
ui->dataValidationLabel->setText(QString("Data values must match the number of headers (%1)").arg(headers.size()));
|
ui->dataValidationLabel->setText(QString("Data values must match the number of headers (%1)").arg(headers.size()));
|
||||||
ui->dataValidationLabel->setStyleSheet("color: gray; font-size: 11px;");
|
ui->dataValidationLabel->setStyleSheet("color: gray;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user