1. 增加動態字形 2. fix color dialog issue in webassembly.
This commit is contained in:
parent
40d41b36e2
commit
7aa79287c8
@ -11,6 +11,11 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
|
||||||
#include "FiveToSingle.h"
|
#include "FiveToSingle.h"
|
||||||
#include "BirthdayCreater.h"
|
#include "BirthdayCreater.h"
|
||||||
@ -26,7 +31,9 @@
|
|||||||
|
|
||||||
#define FONT_SIZE 120
|
#define FONT_SIZE 120
|
||||||
|
|
||||||
#define FONT_CHT_URL "https://bazaar1688.ddns.net/font/TaiwanPearl-SemiBold.ttf"
|
//#define FONT_CHT_URL "https://bazaar1688.ddns.net/font/TaiwanPearl-SemiBold.ttf"
|
||||||
|
|
||||||
|
#define FONT_JSON_URL "https://bazaar1688.ddns.net/font/fonts.json"
|
||||||
|
|
||||||
//#define FONT_CHT_URL "http://45.32.51.135/font/TaiwanPearl-SemiBold.ttf"
|
//#define FONT_CHT_URL "http://45.32.51.135/font/TaiwanPearl-SemiBold.ttf"
|
||||||
|
|
||||||
@ -46,15 +53,61 @@ NameCreater::NameCreater(QWidget *parent)
|
|||||||
connect(ui.customlogo_btn, &QPushButton::released, this , &NameCreater::OnClickedCustomLogoBtn);
|
connect(ui.customlogo_btn, &QPushButton::released, this , &NameCreater::OnClickedCustomLogoBtn);
|
||||||
connect(ui.customlogo2_btn, &QPushButton::released, this, &NameCreater::OnClickedCustomLogo2Btn);
|
connect(ui.customlogo2_btn, &QPushButton::released, this, &NameCreater::OnClickedCustomLogo2Btn);
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
connect(ui.font_comboBox, &QComboBox::currentTextChanged, this, &NameCreater::OnFontComboBoxTextChanged);
|
||||||
|
#else
|
||||||
|
connect(ui.font_comboBox, &QComboBox::currentIndexChanged, this, &NameCreater::OnFontComboBoxIndexChanged);
|
||||||
|
#endif
|
||||||
//qDebug()<<"QSslSocket="<<QSslSocket::sslLibraryBuildVersionString();
|
//qDebug()<<"QSslSocket="<<QSslSocket::sslLibraryBuildVersionString();
|
||||||
|
|
||||||
connect(&network_mgr, &QNetworkAccessManager::finished, this, &NameCreater::onFontDownloadFinished);
|
connect(&network_mgr, &QNetworkAccessManager::finished, this, &NameCreater::onFontDownloadFinished);
|
||||||
network_mgr.get(QNetworkRequest(QUrl(FONT_CHT_URL)));
|
|
||||||
|
|
||||||
;
|
query(QUrl(FONT_JSON_URL));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NameCreater::parseFontJson(const QByteArray& data)
|
||||||
|
{
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(data);
|
||||||
|
|
||||||
|
if (jsonDoc.isNull()) {
|
||||||
|
qDebug() << "Failed to create JSON doc.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonDoc.isObject()) {
|
||||||
|
QJsonObject jsonObj = jsonDoc.object();
|
||||||
|
// Process the JSON object
|
||||||
|
qDebug() << "JSON Object:" << jsonObj;
|
||||||
|
}
|
||||||
|
else if (jsonDoc.isArray()) {
|
||||||
|
ui.font_comboBox->clear();
|
||||||
|
QJsonArray jsonArray = jsonDoc.array();
|
||||||
|
|
||||||
|
foreach(auto val, jsonArray) {
|
||||||
|
auto obj = val.toObject();
|
||||||
|
QString n = obj["font_name"].toString();
|
||||||
|
QString u = obj["font_url"].toString();
|
||||||
|
ui.font_comboBox->addItem(n, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process the JSON array
|
||||||
|
qDebug() << "JSON Array:" << jsonArray;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void NameCreater::query(const QUrl& url)
|
||||||
|
{
|
||||||
|
QNetworkRequest req(url);
|
||||||
|
network_mgr.get(req);
|
||||||
|
}
|
||||||
|
|
||||||
void NameCreater::loadFont(const QByteArray& fontdata){
|
void NameCreater::loadFont(const QByteArray& fontdata){
|
||||||
|
|
||||||
int id = QFontDatabase::addApplicationFontFromData(fontdata);
|
int id = QFontDatabase::addApplicationFontFromData(fontdata);
|
||||||
@ -116,6 +169,8 @@ void NameCreater::loadFont(const QByteArray& fontdata){
|
|||||||
tital->setFont(tital_font);
|
tital->setFont(tital_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "Load Font Succeed!";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,6 +200,7 @@ void NameCreater::OnClickedReadBtn() {
|
|||||||
|
|
||||||
void NameCreater::execCreater(QObject* sender, const QString& fileName, const QByteArray& fileContent) {
|
void NameCreater::execCreater(QObject* sender, const QString& fileName, const QByteArray& fileContent) {
|
||||||
|
|
||||||
|
|
||||||
// Use fileName and fileContent
|
// Use fileName and fileContent
|
||||||
if(sender == ui.fivesingle_btn) FiveToSingle().generaImageFromCSV(Name_Type_e::Name_zh,fileName, fileContent, this->font, this->font_color);
|
if(sender == ui.fivesingle_btn) FiveToSingle().generaImageFromCSV(Name_Type_e::Name_zh,fileName, fileContent, this->font, this->font_color);
|
||||||
|
|
||||||
@ -176,6 +232,8 @@ void NameCreater::execCreater(QObject* sender, const QString& fileName, const QB
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void NameCreater::OnClickedCustomLogoBtn() {
|
void NameCreater::OnClickedCustomLogoBtn() {
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
CustomLogo widget(&this->font);
|
CustomLogo widget(&this->font);
|
||||||
@ -197,9 +255,18 @@ void NameCreater::OnClickedCustomLogo2Btn(){
|
|||||||
void NameCreater::onFontDownloadFinished(QNetworkReply *reply){
|
void NameCreater::onFontDownloadFinished(QNetworkReply *reply){
|
||||||
|
|
||||||
if(reply->error() == QNetworkReply::NoError){
|
if(reply->error() == QNetworkReply::NoError){
|
||||||
//do somthine
|
QString url = reply->request().url().toString();
|
||||||
|
qDebug() << "req url:" << url;
|
||||||
|
|
||||||
|
if (url.contains("fonts.json")) {
|
||||||
|
qDebug() << "query fonts json succeed";
|
||||||
|
parseFontJson(reply->readAll());
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(url.contains(".ttf") || url.contains(".otf")) {
|
||||||
|
qDebug() << "query font family succeed";
|
||||||
loadFont(reply->readAll());
|
loadFont(reply->readAll());
|
||||||
qDebug()<<"Load Font Succeed!";
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
@ -213,3 +280,21 @@ void NameCreater::onFontDownloadFinished(QNetworkReply *reply){
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NameCreater::OnFontComboBoxTextChanged(const QString& str)
|
||||||
|
{
|
||||||
|
QComboBox* sender = (QComboBox*)QObject::sender();
|
||||||
|
QString u = sender->currentData().toString();
|
||||||
|
query(QUrl(u));
|
||||||
|
}
|
||||||
|
|
||||||
|
void NameCreater::OnFontComboBoxIndexChanged(int idx)
|
||||||
|
{
|
||||||
|
QComboBox* sender = (QComboBox*)QObject::sender();
|
||||||
|
QString u = sender->currentData().toString();
|
||||||
|
query(QUrl(u));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NameCreater : public QMainWindow
|
class NameCreater : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -21,15 +23,20 @@ private:
|
|||||||
|
|
||||||
QColor font_color;
|
QColor font_color;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QNetworkAccessManager network_mgr;
|
QNetworkAccessManager network_mgr;
|
||||||
|
void query(const QUrl& url);
|
||||||
|
|
||||||
void loadFont(const QByteArray& fontdata);
|
void loadFont(const QByteArray& fontdata);
|
||||||
void execCreater(QObject*sender, const QString&fileName, const QByteArray &fileContent);
|
void execCreater(QObject*sender, const QString&fileName, const QByteArray &fileContent);
|
||||||
|
void parseFontJson(const QByteArray& data);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void OnClickedReadBtn();
|
void OnClickedReadBtn();
|
||||||
void OnClickedCustomLogoBtn();
|
void OnClickedCustomLogoBtn();
|
||||||
void OnClickedCustomLogo2Btn();
|
void OnClickedCustomLogo2Btn();
|
||||||
void onFontDownloadFinished(QNetworkReply *reply);
|
void onFontDownloadFinished(QNetworkReply *reply);
|
||||||
|
|
||||||
|
void OnFontComboBoxTextChanged(const QString& str);
|
||||||
|
void OnFontComboBoxIndexChanged(int idx);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 14.0.1, 2024-09-20T13:23:45. -->
|
<!-- Written by QtCreator 14.0.1, 2024-09-27T09:47:08. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
@ -8,7 +8,7 @@
|
|||||||
</data>
|
</data>
|
||||||
<data>
|
<data>
|
||||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||||
<value type="qlonglong">1</value>
|
<value type="qlonglong">0</value>
|
||||||
</data>
|
</data>
|
||||||
<data>
|
<data>
|
||||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
@ -409,7 +409,6 @@
|
|||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/dev/namecreater/NameCreater/build/Desktop_Qt_5_15_2_MSVC2019_64bit-Debug</value>
|
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
@ -578,7 +577,6 @@
|
|||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/dev/namecreater/NameCreater/build/Desktop_Qt_6_7_2_MSVC2019_64bit-Debug</value>
|
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
|
|||||||
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>946</width>
|
<width>916</width>
|
||||||
<height>694</height>
|
<height>816</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@ -474,14 +474,24 @@ color: rgb(255, 255, 255);
|
|||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QComboBox" name="font_comboBox">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>380</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>201</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menuBar">
|
<widget class="QMenuBar" name="menuBar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>946</width>
|
<width>916</width>
|
||||||
<height>24</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@ -22,6 +22,7 @@ static QPointF NAME_OFFSET_START = QPointF(79, 377);
|
|||||||
static qreal EACH_WORD_OFFSET = 142;
|
static qreal EACH_WORD_OFFSET = 142;
|
||||||
static QColor FONT_COLOR = QColor(0, 0, 0);
|
static QColor FONT_COLOR = QColor(0, 0, 0);
|
||||||
|
|
||||||
|
static QColorDialog* s_colorDialog = nullptr;
|
||||||
|
|
||||||
|
|
||||||
class QGraphicsCloneTextItem : public QGraphicsTextItem {
|
class QGraphicsCloneTextItem : public QGraphicsTextItem {
|
||||||
@ -57,9 +58,18 @@ CustomLogo::CustomLogo(QFont* font, QDialog* parent) :
|
|||||||
connect(ui->load_list_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
connect(ui->load_list_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
||||||
connect(ui->color_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
connect(ui->color_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
||||||
|
|
||||||
|
|
||||||
|
QFont _f(*font);
|
||||||
|
_f.setPixelSize(20);
|
||||||
|
|
||||||
|
|
||||||
QPalette palette = ui->color_label->palette();
|
QPalette palette = ui->color_label->palette();
|
||||||
palette.setColor(QPalette::WindowText, fontColor);
|
palette.setColor(QPalette::WindowText, fontColor);
|
||||||
ui->color_label->setPalette(palette);
|
ui->color_label->setPalette(palette);
|
||||||
|
ui->color_label->setFont(_f);
|
||||||
|
ui->color_btn->setFont(_f);
|
||||||
|
ui->double_checkbox->setFont(_f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomLogo::~CustomLogo()
|
CustomLogo::~CustomLogo()
|
||||||
@ -169,7 +179,8 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
|
|||||||
QGraphicsCloneTextItem* textItem = new QGraphicsCloneTextItem(name.mid(k, 1), name_rectItem);
|
QGraphicsCloneTextItem* textItem = new QGraphicsCloneTextItem(name.mid(k, 1), name_rectItem);
|
||||||
textItem->setFont(*customFont);
|
textItem->setFont(*customFont);
|
||||||
textItem->setDefaultTextColor(fontColor);
|
textItem->setDefaultTextColor(fontColor);
|
||||||
textItem->setPos(pos.x(), pos.y() + k * EACH_WORD_OFFSET + y_offset);
|
qreal _posX = name_rectItem->boundingRect().width() / 2 - textItem->boundingRect().width() / 2;
|
||||||
|
textItem->setPos(_posX, pos.y() + k * EACH_WORD_OFFSET + y_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -253,6 +264,16 @@ QList<NameInfo_t> CustomLogo::getNameByFileContent(Name_Type_e type, const QByte
|
|||||||
return nameList;
|
return nameList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomLogo::onColorSelected(const QColor& color)
|
||||||
|
{
|
||||||
|
qDebug() << "color accept: r:" << color.red() << ", g:" << color.green() <<", b:" << color.blue();
|
||||||
|
fontColor = QColor(color);
|
||||||
|
|
||||||
|
QPalette palette = ui->color_label->palette();
|
||||||
|
palette.setColor(QPalette::WindowText, fontColor);
|
||||||
|
ui->color_label->setPalette(palette);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CustomLogo::onClickedBtn() {
|
void CustomLogo::onClickedBtn() {
|
||||||
auto sender = (QPushButton*)QObject::sender();
|
auto sender = (QPushButton*)QObject::sender();
|
||||||
@ -265,14 +286,12 @@ void CustomLogo::onClickedBtn() {
|
|||||||
}
|
}
|
||||||
else if (sender == ui->color_btn) {
|
else if (sender == ui->color_btn) {
|
||||||
|
|
||||||
QColor color = QColorDialog::getColor(Qt::red, this);
|
if (s_colorDialog == nullptr) {
|
||||||
|
s_colorDialog = new QColorDialog(ui->color_label->palette().color(QPalette::WindowText), this);
|
||||||
if (color.isValid()) {
|
connect(s_colorDialog, &QColorDialog::colorSelected, this, &CustomLogo::onColorSelected);
|
||||||
fontColor = color;
|
|
||||||
QPalette palette = ui->color_label->palette();
|
|
||||||
palette.setColor(QPalette::WindowText, color);
|
|
||||||
ui->color_label->setPalette(palette);
|
|
||||||
}
|
}
|
||||||
|
s_colorDialog->open();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ protected:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onClickedBtn();
|
void onClickedBtn();
|
||||||
|
void onColorSelected(const QColor& color);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user