mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
refact: update files of project
This commit is contained in:
parent
3ea3d400e1
commit
0637bc238f
@ -27,9 +27,11 @@ if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(X_TOOLS_BUILD_WITH_CMAKE)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS ${X_TOOLS_QT_COMPONENTS})
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${X_TOOLS_QT_COMPONENTS})
|
||||
if(NOT Qt${QT_VERSION_MAJOR}_VERSION VERSION_LESS "5.14.0")
|
||||
add_compile_definitions(X_TOOLS_ENABLE_HIGH_DPI_POLICY)
|
||||
endif()
|
||||
|
||||
include(CMake/xToolsCommon.cmake)
|
||||
include(CMake/xToolsGitInfo.cmake)
|
||||
@ -145,7 +147,7 @@ endif()
|
||||
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# The private modules is not open-source.
|
||||
if(NOT Qt6_VERSION VERSION_LESS "6.5.0")
|
||||
if(NOT Qt{QT_VERSION_MAJOR}_VERSION VERSION_LESS "6.5.0")
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/Private)
|
||||
add_subdirectory(${CMAKE_SOURCE_DIR}/Private)
|
||||
endif()
|
||||
|
||||
@ -27,8 +27,7 @@ xToolsBroadcastAssistant::xToolsBroadcastAssistant(QWidget* parent)
|
||||
connect(m_broadcastThread, &xToolsBroadcastThread::bytesWritten, this, [=](const QByteArray& bytes) {
|
||||
QByteArray temp = bytes;
|
||||
int format = ui->comboBoxOutputFormat->currentData().toInt();
|
||||
auto cookedFormat = xToolsDataStructure::SAKEnumTextFormatOutput(format);
|
||||
auto bytesString = xToolsDataStructure::byteArrayToString(temp, cookedFormat);
|
||||
auto bytesString = xToolsDataStructure::byteArrayToString(temp, format);
|
||||
auto info = QDateTime::currentDateTime().toString("hh:mm:ss");
|
||||
info += " Tx: ";
|
||||
info = QString("<font color=silver>%1</font>").arg(info);
|
||||
|
||||
@ -43,9 +43,9 @@ void xToolsStringAssistant::onTextEditTextChanged()
|
||||
{
|
||||
if (!ui->textEdit->blockSignals(true)) {
|
||||
QString inputString = ui->textEdit->toPlainText();
|
||||
auto inputFormat = static_cast<xToolsDataStructure::SAKEnumTextFormatInput>(
|
||||
auto inputFormat = static_cast<xToolsDataStructure::TextFormat>(
|
||||
ui->inputFormatComboBox->currentData().toInt());
|
||||
QString cookedString = xToolsDataStructure::formattingString(inputString, inputFormat);
|
||||
QString cookedString = xToolsDataStructure::formatString(inputString, inputFormat);
|
||||
ui->textEdit->setText(cookedString);
|
||||
ui->textEdit->moveCursor(QTextCursor::End);
|
||||
ui->textEdit->blockSignals(false);
|
||||
@ -65,10 +65,10 @@ void xToolsStringAssistant::onInputFormatComboBoxCurrentIndexChanged(int index)
|
||||
void xToolsStringAssistant::onCreatePushButtonClicked()
|
||||
{
|
||||
QString inputString = ui->textEdit->toPlainText();
|
||||
auto inputFormat = static_cast<xToolsDataStructure::SAKEnumTextFormatInput>(
|
||||
auto inputFormat = static_cast<xToolsDataStructure::TextFormat>(
|
||||
ui->inputFormatComboBox->currentData().toInt());
|
||||
QByteArray inputArray = xToolsDataStructure::stringToByteArray(inputString, inputFormat);
|
||||
auto outputFormat = static_cast<xToolsDataStructure::SAKEnumTextFormatOutput>(
|
||||
auto outputFormat = static_cast<xToolsDataStructure::TextFormat>(
|
||||
ui->outputFormatComboBox->currentData().toInt());
|
||||
auto outputString = xToolsDataStructure::byteArrayToString(inputArray, outputFormat);
|
||||
ui->textBrowser->setText(outputString);
|
||||
|
||||
@ -11,14 +11,15 @@
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QMetaEnum>
|
||||
#include <QStyleFactory>
|
||||
|
||||
#ifdef X_TOOLS_USING_GLOG
|
||||
#include "glog/logging.h"
|
||||
#endif
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
#include "xToolsInterface.h"
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
#include "xToolsDataStructure.h"
|
||||
#endif
|
||||
#include "xToolsSettings.h"
|
||||
|
||||
@ -125,12 +126,18 @@ static void xToolsInitHdpi()
|
||||
#if 0
|
||||
qputenv("QT_SCALE_FACTOR", "1.5");
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
int policy = xToolsSettings::instance()->hdpiPolicy();
|
||||
if (xToolsInterface::isQtHighDpiScalePolicy(policy)) {
|
||||
const auto cookedPolicy = static_cast<Qt::HighDpiScaleFactorRoundingPolicy>(policy);
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(cookedPolicy);
|
||||
if (!xToolsDataStructure::isValidHighDpiPolicy(policy)) {
|
||||
qWarning() << "The value of hdpi policy is not specified, set to default value:"
|
||||
<< QGuiApplication::highDpiScaleFactorRoundingPolicy();
|
||||
return;
|
||||
}
|
||||
|
||||
auto cookedPolicy = Qt::HighDpiScaleFactorRoundingPolicy(policy);
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(cookedPolicy);
|
||||
qInfo() << "The current high dpi policy is:" << cookedPolicy;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -139,7 +146,6 @@ static void xToolsInitAppStyle()
|
||||
const QStringList keys = QStyleFactory::keys();
|
||||
qInfo() << "The supported application styles are:" << qPrintable(keys.join(QChar(',')));
|
||||
const QString style = xToolsSettings::instance()->appStyle();
|
||||
qInfo() << style;
|
||||
if (keys.contains(style)) {
|
||||
qInfo() << "The current style of application is:" << qPrintable(style);
|
||||
QApplication::setStyle(QStyleFactory::create(style));
|
||||
|
||||
@ -9,17 +9,224 @@
|
||||
#include "xToolsDataStructure.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QMap>
|
||||
#include <QMetaEnum>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
#include "xToolsCompatibility.h"
|
||||
|
||||
xToolsDataStructure::xToolsDataStructure(QObject *parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
xToolsDataStructure::~xToolsDataStructure() {}
|
||||
|
||||
QVariantList xToolsDataStructure::supportedTextFormats()
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<TextFormat>();
|
||||
QVariantList list;
|
||||
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||
list.append(metaEnum.value(i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::textFormatName(int textFormat)
|
||||
{
|
||||
static QMap<int, QString> textFormatMap;
|
||||
if (textFormatMap.isEmpty()) {
|
||||
textFormatMap.insert(TextFormatBin, QString("BIN"));
|
||||
textFormatMap.insert(TextFormatOct, QString("OCT"));
|
||||
textFormatMap.insert(TextFormatDec, QString("DEC"));
|
||||
textFormatMap.insert(TextFormatHex, QString("HEX"));
|
||||
textFormatMap.insert(TextFormatAscii, QString("ASCII"));
|
||||
textFormatMap.insert(TextFormatUtf8, QString("UTF8"));
|
||||
textFormatMap.insert(TextFormatSystem, QString("SYSTEM"));
|
||||
}
|
||||
|
||||
return textFormatMap.value(textFormat, "Unknown");
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::byteArrayToString(const QByteArray &array, int format)
|
||||
{
|
||||
auto cookedArray = [](const QByteArray &array, int base, int len) -> QString {
|
||||
QString str, numStr;
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
if (base == 10 || base == 8) {
|
||||
numStr = QString::number(array.at(i), base);
|
||||
str.append(QString("%1 ").arg(numStr));
|
||||
} else {
|
||||
numStr = QString::number(quint8(array.at(i)), base);
|
||||
str.append(QString("%1 ").arg(numStr, len, '0'));
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
if (xToolsDataStructure::TextFormatBin == format) {
|
||||
return cookedArray(array, 2, 8);
|
||||
} else if (xToolsDataStructure::TextFormatOct == format) {
|
||||
return cookedArray(array, 8, 3);
|
||||
} else if (xToolsDataStructure::TextFormatDec == format) {
|
||||
return cookedArray(array, 10, 3);
|
||||
} else if (xToolsDataStructure::TextFormatHex == format) {
|
||||
return cookedArray(array, 16, 2);
|
||||
} else if (xToolsDataStructure::TextFormatAscii == format) {
|
||||
return QString::fromLatin1(array);
|
||||
} else if (xToolsDataStructure::TextFormatUtf8) {
|
||||
return QString::fromUtf8(array);
|
||||
} else if (xToolsDataStructure::TextFormatSystem) {
|
||||
return QString::fromLocal8Bit(array);
|
||||
} else {
|
||||
Q_ASSERT_X(false, __FUNCTION__, "Unsupported text format");
|
||||
return QString("Unsupported text format: %1").arg(format);
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray xToolsDataStructure::stringToByteArray(const QString &str, int format)
|
||||
{
|
||||
auto cookString = [](const QString &str, int base) -> QByteArray {
|
||||
QByteArray data;
|
||||
QStringList strList = str.split(' ', xToolsSkipEmptyParts);
|
||||
for (int i = 0; i < strList.length(); i++) {
|
||||
QString str = strList.at(i);
|
||||
qint8 value = QString(str).toInt(Q_NULLPTR, base);
|
||||
data.append(reinterpret_cast<char *>(&value), 1);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
QByteArray data;
|
||||
if (format == xToolsDataStructure::TextFormatBin) {
|
||||
cookString(str, 2);
|
||||
} else if (format == xToolsDataStructure::TextFormatOct) {
|
||||
cookString(str, 8);
|
||||
} else if (format == xToolsDataStructure::TextFormatDec) {
|
||||
cookString(str, 10);
|
||||
} else if (format == xToolsDataStructure::TextFormatHex) {
|
||||
cookString(str, 16);
|
||||
} else if (format == xToolsDataStructure::TextFormatAscii) {
|
||||
data = str.toLatin1();
|
||||
} else if (format == xToolsDataStructure::TextFormatUtf8) {
|
||||
data = str.toUtf8();
|
||||
} else if (format == xToolsDataStructure::TextFormatSystem) {
|
||||
data = str.toLocal8Bit();
|
||||
} else {
|
||||
Q_ASSERT_X(false, __FUNCTION__, "Unsupported text format");
|
||||
data = str.toLocal8Bit();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::formatString(const QString &str, int format)
|
||||
{
|
||||
static QRegularExpression binRegularExpression("[^0-1]");
|
||||
static QRegularExpression octRegularExpression("[^0-7]");
|
||||
static QRegularExpression decRegularExpression("[^0-9]");
|
||||
static QRegularExpression hexRegularExpression("[^0-9a-fA-F]");
|
||||
static QRegularExpression asciiRegularExpression("[^ -~]");
|
||||
|
||||
auto cookString = [](const QString &str, int length, QRegularExpression &re) -> QString {
|
||||
QString rawString = str;
|
||||
QString cookedString;
|
||||
rawString.remove(re);
|
||||
for (int i = 0; i < rawString.length(); i++) {
|
||||
if ((i != 0) && (i % length == 0)) {
|
||||
cookedString.append(QChar(' '));
|
||||
}
|
||||
cookedString.append(rawString.at(i));
|
||||
}
|
||||
|
||||
return cookedString;
|
||||
};
|
||||
|
||||
if (format == xToolsDataStructure::TextFormatBin) {
|
||||
return cookString(str, 8, binRegularExpression);
|
||||
} else if (format == xToolsDataStructure::TextFormatOct) {
|
||||
return cookString(str, 3, octRegularExpression);
|
||||
} else if (format == xToolsDataStructure::TextFormatDec) {
|
||||
return cookString(str, 3, decRegularExpression);
|
||||
} else if (format == xToolsDataStructure::TextFormatHex) {
|
||||
return cookString(str, 3, hexRegularExpression);
|
||||
} else if (format == xToolsDataStructure::TextFormatAscii) {
|
||||
return QString(str).remove(asciiRegularExpression);
|
||||
} else if (format == xToolsDataStructure::TextFormatUtf8) {
|
||||
return QString::fromUtf8(str.toUtf8());
|
||||
} else if (format == xToolsDataStructure::TextFormatSystem) {
|
||||
return QString::fromUtf8(str.toLocal8Bit());
|
||||
} else {
|
||||
Q_ASSERT_X(false, __FUNCTION__, "Unknown input model!");
|
||||
return QString::fromUtf8(str.toLocal8Bit());
|
||||
}
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::cookedString(int escapeCharacter, const QString &str)
|
||||
{
|
||||
return xToolsDataStructure::cookEscapeCharacter(escapeCharacter, str);
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::cookEscapeCharacter(int option, const QString &str)
|
||||
{
|
||||
QString newStr = str;
|
||||
if (option == EscapeCharacterR) {
|
||||
newStr.replace("\\r", "\r");
|
||||
} else if (option == EscapeCharacterN) {
|
||||
newStr.replace("\\n", "\n");
|
||||
} else if (option == EscapeCharacterRN) {
|
||||
newStr.replace("\\r\\n", "\r\n");
|
||||
} else if (option == EscapeCharacterNR) {
|
||||
newStr.replace("\\n\\r", "\n\\r");
|
||||
} else if (option == EscapeCharacterRAndN) {
|
||||
newStr.replace("\\r", "\r");
|
||||
newStr.replace("\\n", "\n");
|
||||
}
|
||||
|
||||
return newStr;
|
||||
}
|
||||
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
QVariantList xToolsDataStructure::supportedHighDpiPolicies()
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<HighDpiPolicy>();
|
||||
QVariantList list;
|
||||
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||
list.append(metaEnum.value(i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
QString xToolsDataStructure::highDpiPolicyName(int policy)
|
||||
{
|
||||
static QMap<int, QString> policyMap;
|
||||
if (policyMap.isEmpty()) {
|
||||
policyMap.insert(HighDpiPolicyRound, tr("Round up for .5 and above"));
|
||||
policyMap.insert(HighDpiPolicyCeil, tr("Always round up"));
|
||||
policyMap.insert(HighDpiPolicyFloor, tr("Always round down"));
|
||||
policyMap.insert(HighDpiPolicyRoundPreferFloor, tr("Round up for .75 and above"));
|
||||
policyMap.insert(HighDpiPolicyPassThrough, tr("Don't round"));
|
||||
#ifdef Q_OS_WIN
|
||||
policyMap.insert(HighDpiPolicySystem, tr("System"));
|
||||
#endif
|
||||
}
|
||||
|
||||
return policyMap.value(policy, "Unknown");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
bool xToolsDataStructure::isValidHighDpiPolicy(int policy)
|
||||
{
|
||||
auto policies = supportedHighDpiPolicies();
|
||||
return policies.contains(QVariant(policy));
|
||||
}
|
||||
#endif
|
||||
|
||||
QString xToolsDataStructure::cookedAffixes(int affixes)
|
||||
{
|
||||
if (affixes == AffixesN) {
|
||||
@ -35,20 +242,52 @@ QString xToolsDataStructure::cookedAffixes(int affixes)
|
||||
}
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::affixesName(int affixes)
|
||||
{
|
||||
if (xToolsDataStructure::AffixesNone == affixes) {
|
||||
return "None";
|
||||
} else if (xToolsDataStructure::AffixesR == affixes) {
|
||||
return "//r";
|
||||
} else if (xToolsDataStructure::AffixesN == affixes) {
|
||||
return "//n";
|
||||
} else if (xToolsDataStructure::AffixesRN == affixes) {
|
||||
return "//r//n";
|
||||
} else if (xToolsDataStructure::AffixesNR == affixes) {
|
||||
return "//n//r";
|
||||
}
|
||||
|
||||
return "None";
|
||||
}
|
||||
|
||||
QByteArray xToolsDataStructure::affixesData(int affixes)
|
||||
{
|
||||
if (affixes == xToolsDataStructure::AffixesNone) {
|
||||
return QByteArray("");
|
||||
} else if (affixes == xToolsDataStructure::AffixesR) {
|
||||
return QByteArray("\r");
|
||||
} else if (affixes == xToolsDataStructure::AffixesN) {
|
||||
return QByteArray("\n");
|
||||
} else if (affixes == xToolsDataStructure::AffixesRN) {
|
||||
return QByteArray("\r\n");
|
||||
} else if (affixes == xToolsDataStructure::AffixesNR) {
|
||||
return QByteArray("\n\r");
|
||||
}
|
||||
|
||||
return QByteArray("");
|
||||
}
|
||||
|
||||
void xToolsDataStructure::setComboBoxTextOutputFormat(QComboBox *comboBox)
|
||||
{
|
||||
if (comboBox) {
|
||||
QMap<int, QString> formatMap;
|
||||
formatMap.insert(OutputFormatBin, QString("BIN"));
|
||||
formatMap.insert(OutputFormatOct, QString("OCT"));
|
||||
formatMap.insert(OutputFormatDec, QString("DEC"));
|
||||
formatMap.insert(OutputFormatHex, QString("HEX"));
|
||||
formatMap.insert(OutputFormatUtf8, QString("UTF8"));
|
||||
formatMap.insert(OutputFormatUcs4, QString("UCS4"));
|
||||
formatMap.insert(OutputFormatAscii, QString("ASCII"));
|
||||
formatMap.insert(OutputFormatUtf16, QString("UTF16"));
|
||||
formatMap.insert(OutputFormatLocal, QString("SYSTEM"));
|
||||
setComboBoxItems(comboBox, formatMap, OutputFormatHex);
|
||||
formatMap.insert(TextFormatBin, QString("BIN"));
|
||||
formatMap.insert(TextFormatOct, QString("OCT"));
|
||||
formatMap.insert(TextFormatDec, QString("DEC"));
|
||||
formatMap.insert(TextFormatHex, QString("HEX"));
|
||||
formatMap.insert(TextFormatUtf8, QString("UTF8"));
|
||||
formatMap.insert(TextFormatAscii, QString("ASCII"));
|
||||
formatMap.insert(TextFormatSystem, QString("SYSTEM"));
|
||||
setComboBoxItems(comboBox, formatMap, TextFormatHex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,13 +296,13 @@ void xToolsDataStructure::setComboBoxTextInputFormat(QComboBox *comboBox)
|
||||
if (comboBox) {
|
||||
if (comboBox) {
|
||||
QMap<int, QString> formatMap;
|
||||
formatMap.insert(InputFormatBin, QString("BIN"));
|
||||
formatMap.insert(InputFormatOct, QString("OTC"));
|
||||
formatMap.insert(InputFormatDec, QString("DEC"));
|
||||
formatMap.insert(InputFormatHex, QString("HEX"));
|
||||
formatMap.insert(InputFormatAscii, QString("ASCII"));
|
||||
formatMap.insert(InputFormatLocal, QString("SYSTEM"));
|
||||
setComboBoxItems(comboBox, formatMap, InputFormatLocal);
|
||||
formatMap.insert(TextFormatBin, QString("BIN"));
|
||||
formatMap.insert(TextFormatOct, QString("OTC"));
|
||||
formatMap.insert(TextFormatDec, QString("DEC"));
|
||||
formatMap.insert(TextFormatHex, QString("HEX"));
|
||||
formatMap.insert(TextFormatAscii, QString("ASCII"));
|
||||
formatMap.insert(TextFormatSystem, QString("SYSTEM"));
|
||||
setComboBoxItems(comboBox, formatMap, TextFormatSystem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,171 +315,7 @@ void xToolsDataStructure::setComboBoxTextWebSocketSendingType(QComboBox *comboBo
|
||||
}
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::formattingString(QString &origingString, SAKEnumTextFormatInput format)
|
||||
{
|
||||
QString cookedString;
|
||||
if (format == xToolsDataStructure::InputFormatBin) {
|
||||
static auto tmp = QRegularExpression("[^0-1]");
|
||||
origingString.remove(tmp);
|
||||
for (int i = 0; i < origingString.length(); i++) {
|
||||
if ((i != 0) && (i % 8 == 0)) {
|
||||
cookedString.append(QChar(' '));
|
||||
}
|
||||
cookedString.append(origingString.at(i));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatOct) {
|
||||
static auto tmp = QRegularExpression("[^0-7]");
|
||||
origingString.remove(tmp);
|
||||
for (int i = 0; i < origingString.length(); i++) {
|
||||
if ((i != 0) && (i % 2 == 0)) {
|
||||
cookedString.append(QChar(' '));
|
||||
}
|
||||
cookedString.append(origingString.at(i));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatDec) {
|
||||
static auto tmp = QRegularExpression("[^0-9]");
|
||||
origingString.remove(tmp);
|
||||
for (int i = 0; i < origingString.length(); i++) {
|
||||
if ((i != 0) && (i % 2 == 0)) {
|
||||
cookedString.append(QChar(' '));
|
||||
}
|
||||
cookedString.append(origingString.at(i));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatHex) {
|
||||
static auto tmp = QRegularExpression("[^0-9a-fA-F]");
|
||||
origingString.remove(tmp);
|
||||
for (int i = 0; i < origingString.length(); i++) {
|
||||
if ((i != 0) && (i % 2 == 0)) {
|
||||
cookedString.append(QChar(' '));
|
||||
}
|
||||
cookedString.append(origingString.at(i));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatAscii) {
|
||||
for (int i = 0; i < origingString.length(); i++) {
|
||||
if (origingString.at(i).unicode() <= 127) {
|
||||
cookedString.append(origingString.at(i));
|
||||
}
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatLocal) {
|
||||
cookedString = origingString;
|
||||
} else {
|
||||
Q_ASSERT_X(false, __FUNCTION__, "Unknown input model!");
|
||||
}
|
||||
|
||||
return cookedString;
|
||||
}
|
||||
|
||||
QByteArray xToolsDataStructure::stringToByteArray(QString &origingString, SAKEnumTextFormatInput format)
|
||||
{
|
||||
QByteArray data;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||
auto behavior = QString::SkipEmptyParts;
|
||||
#else
|
||||
auto behavior = Qt::SkipEmptyParts;
|
||||
#endif
|
||||
if (format == xToolsDataStructure::InputFormatBin) {
|
||||
QStringList strList = origingString.split(' ', behavior);
|
||||
for (int i = 0; i < strList.length(); i++) {
|
||||
QString str = strList.at(i);
|
||||
qint8 value = QString(str).toInt(Q_NULLPTR, 2);
|
||||
data.append(reinterpret_cast<char *>(&value), 1);
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatOct) {
|
||||
QStringList strList = origingString.split(' ', behavior);
|
||||
for (int i = 0; i < strList.length(); i++) {
|
||||
QString str = strList.at(i);
|
||||
qint8 value = QString(str).toInt(Q_NULLPTR, 8);
|
||||
data.append(reinterpret_cast<char *>(&value), 1);
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatDec) {
|
||||
QStringList strList = origingString.split(' ', behavior);
|
||||
for (int i = 0; i < strList.length(); i++) {
|
||||
QString str = strList.at(i);
|
||||
qint8 value = QString(str).toInt(Q_NULLPTR, 10);
|
||||
data.append(reinterpret_cast<char *>(&value), 1);
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatHex) {
|
||||
QStringList strList = origingString.split(' ', behavior);
|
||||
for (int i = 0; i < strList.length(); i++) {
|
||||
QString str = strList.at(i);
|
||||
qint8 value = QString(str).toInt(Q_NULLPTR, 16);
|
||||
data.append(reinterpret_cast<char *>(&value), 1);
|
||||
}
|
||||
} else if (format == xToolsDataStructure::InputFormatAscii) {
|
||||
data = origingString.toLatin1();
|
||||
} else if (format == xToolsDataStructure::InputFormatLocal) {
|
||||
data = origingString.toLocal8Bit();
|
||||
} else {
|
||||
data = origingString.toUtf8();
|
||||
Q_ASSERT_X(false, __FUNCTION__, "Unknown input mode!");
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
QByteArray xToolsDataStructure::stringToByteArray(QString &origingString, int format)
|
||||
{
|
||||
auto cookedFormat = static_cast<xToolsDataStructure::SAKEnumTextFormatInput>(format);
|
||||
return stringToByteArray(origingString, cookedFormat);
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::byteArrayToString(const QByteArray &origingData,
|
||||
SAKEnumTextFormatOutput format)
|
||||
{
|
||||
QString str;
|
||||
if (format == xToolsDataStructure::OutputFormatBin) {
|
||||
for (int i = 0; i < origingData.length(); i++) {
|
||||
str.append(
|
||||
QString("%1 ").arg(QString::number(static_cast<uint8_t>(origingData.at(i)), 2),
|
||||
8,
|
||||
'0'));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::OutputFormatOct) {
|
||||
for (int i = 0; i < origingData.length(); i++) {
|
||||
str.append(
|
||||
QString("%1 ").arg(QString::number(static_cast<uint8_t>(origingData.at(i)), 8),
|
||||
3,
|
||||
'0'));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::OutputFormatDec) {
|
||||
for (int i = 0; i < origingData.length(); i++) {
|
||||
str.append(
|
||||
QString("%1 ").arg(QString::number(static_cast<uint8_t>(origingData.at(i)), 10)));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::OutputFormatHex) {
|
||||
for (int i = 0; i < origingData.length(); i++) {
|
||||
str.append(
|
||||
QString("%1 ").arg(QString::number(static_cast<uint8_t>(origingData.at(i)), 16),
|
||||
2,
|
||||
'0'));
|
||||
}
|
||||
} else if (format == xToolsDataStructure::OutputFormatAscii) {
|
||||
str.append(QString::fromLatin1(origingData));
|
||||
} else if (format == xToolsDataStructure::OutputFormatUtf8) {
|
||||
str.append(QString::fromUtf8(origingData));
|
||||
} else if (format == xToolsDataStructure::OutputFormatUtf16) {
|
||||
str.append(QString::fromUtf16(reinterpret_cast<const char16_t *>(origingData.constData()),
|
||||
origingData.length() / sizeof(char16_t)));
|
||||
} else if (format == xToolsDataStructure::OutputFormatUcs4) {
|
||||
str.append(QString::fromUcs4(reinterpret_cast<const char32_t *>(origingData.constData()),
|
||||
origingData.length() / sizeof(char32_t)));
|
||||
} else if (format == xToolsDataStructure::OutputFormatLocal) {
|
||||
str.append(QString::fromLocal8Bit(origingData));
|
||||
} else {
|
||||
str.append(QString::fromUtf8(origingData));
|
||||
Q_ASSERT_X(false, __FUNCTION__, "Unknown output mode!");
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::byteArrayToString(const QByteArray &origingData, int format)
|
||||
{
|
||||
auto cookedFormat = static_cast<xToolsDataStructure::SAKEnumTextFormatOutput>(format);
|
||||
return byteArrayToString(origingData, cookedFormat);
|
||||
}
|
||||
|
||||
void xToolsDataStructure::setLineEditTextFormat(QLineEdit *lineEdit, SAKEnumTextFormatInput format)
|
||||
void xToolsDataStructure::setLineEditTextFormat(QLineEdit *lineEdit, TextFormat format)
|
||||
{
|
||||
QMap<int, QRegularExpressionValidator *> regExpMap;
|
||||
QRegularExpression binRegExp = QRegularExpression("([01][01][01][01][01][01][01][01][ ])*");
|
||||
@ -248,13 +323,13 @@ void xToolsDataStructure::setLineEditTextFormat(QLineEdit *lineEdit, SAKEnumText
|
||||
QRegularExpression decRegExp = QRegularExpression("([0-9][0-9][ ])*");
|
||||
QRegularExpression hexRegExp = QRegularExpression("([0-9a-fA-F][0-9a-fA-F][ ])*");
|
||||
QRegularExpression asciiRegExp = QRegularExpression("([ -~])*");
|
||||
regExpMap.insert(xToolsDataStructure::InputFormatBin, new QRegularExpressionValidator(binRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::InputFormatOct, new QRegularExpressionValidator(otcRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::InputFormatDec, new QRegularExpressionValidator(decRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::InputFormatHex, new QRegularExpressionValidator(hexRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::InputFormatAscii,
|
||||
regExpMap.insert(xToolsDataStructure::TextFormatBin, new QRegularExpressionValidator(binRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::TextFormatOct, new QRegularExpressionValidator(otcRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::TextFormatDec, new QRegularExpressionValidator(decRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::TextFormatHex, new QRegularExpressionValidator(hexRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::TextFormatAscii,
|
||||
new QRegularExpressionValidator(asciiRegExp));
|
||||
regExpMap.insert(xToolsDataStructure::InputFormatLocal, Q_NULLPTR);
|
||||
regExpMap.insert(xToolsDataStructure::TextFormatSystem, Q_NULLPTR);
|
||||
|
||||
if (lineEdit) {
|
||||
if (lineEdit->validator()) {
|
||||
@ -273,7 +348,7 @@ void xToolsDataStructure::setLineEditTextFormat(QLineEdit *lineEdit, SAKEnumText
|
||||
|
||||
void xToolsDataStructure::setLineEditTextFormat(QLineEdit *lineEdit, int format)
|
||||
{
|
||||
auto cookedFormat = static_cast<SAKEnumTextFormatInput>(format);
|
||||
auto cookedFormat = static_cast<TextFormat>(format);
|
||||
xToolsDataStructure::setLineEditTextFormat(lineEdit, cookedFormat);
|
||||
}
|
||||
|
||||
@ -373,8 +448,8 @@ void xToolsDataStructure::formattingInputText(QTextEdit *textEdit, int model)
|
||||
textEdit->blockSignals(true);
|
||||
QString plaintext = textEdit->toPlainText();
|
||||
if (!plaintext.isEmpty()) {
|
||||
auto cookedModel = static_cast<xToolsDataStructure::SAKEnumTextFormatInput>(model);
|
||||
QString cookedString = xToolsDataStructure::formattingString(plaintext, cookedModel);
|
||||
auto cookedModel = static_cast<xToolsDataStructure::TextFormat>(model);
|
||||
QString cookedString = xToolsDataStructure::formatString(plaintext, cookedModel);
|
||||
textEdit->setText(cookedString);
|
||||
textEdit->moveCursor(QTextCursor::End);
|
||||
}
|
||||
@ -420,80 +495,3 @@ void xToolsDataStructure::setComboBoxItems(QComboBox *comboBox,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::affixesName(int affixes)
|
||||
{
|
||||
if (xToolsDataStructure::AffixesNone == affixes) {
|
||||
return "None";
|
||||
} else if (xToolsDataStructure::AffixesR == affixes) {
|
||||
return "//r";
|
||||
} else if (xToolsDataStructure::AffixesN == affixes) {
|
||||
return "//n";
|
||||
} else if (xToolsDataStructure::AffixesRN == affixes) {
|
||||
return "//r//n";
|
||||
} else if (xToolsDataStructure::AffixesNR == affixes) {
|
||||
return "//n//r";
|
||||
}
|
||||
|
||||
return "None";
|
||||
}
|
||||
|
||||
QByteArray xToolsDataStructure::affixesData(int affixes)
|
||||
{
|
||||
if (affixes == xToolsDataStructure::AffixesNone) {
|
||||
return QByteArray("");
|
||||
} else if (affixes == xToolsDataStructure::AffixesR) {
|
||||
return QByteArray("\r");
|
||||
} else if (affixes == xToolsDataStructure::AffixesN) {
|
||||
return QByteArray("\n");
|
||||
} else if (affixes == xToolsDataStructure::AffixesRN) {
|
||||
return QByteArray("\r\n");
|
||||
} else if (affixes == xToolsDataStructure::AffixesNR) {
|
||||
return QByteArray("\n\r");
|
||||
}
|
||||
|
||||
return QByteArray("");
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::cookedString(int escapeCharacter, const QString &str)
|
||||
{
|
||||
return xToolsDataStructure::cookEscapeCharacter(escapeCharacter, str);
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::textFormatName(int textFormat)
|
||||
{
|
||||
static QMap<int, QString> map;
|
||||
if (map.isEmpty()) {
|
||||
map.insert(TextFormatBin, tr("Bin"));
|
||||
map.insert(TextFormatOct, tr("Oct"));
|
||||
map.insert(TextFormatDec, tr("Dec"));
|
||||
map.insert(TextFormatHex, tr("Hex"));
|
||||
map.insert(TextFormatAscii, "Ascii");
|
||||
map.insert(TextFormatUtf8, "Utf8");
|
||||
}
|
||||
|
||||
if (map.contains(textFormat)) {
|
||||
return map.value(textFormat);
|
||||
}
|
||||
|
||||
return QString("Unknown");
|
||||
}
|
||||
|
||||
QString xToolsDataStructure::cookEscapeCharacter(int option, const QString &str)
|
||||
{
|
||||
QString newStr = str;
|
||||
if (option == EscapeCharacterOptionR) {
|
||||
newStr.replace("\\r", "\r");
|
||||
} else if (option == EscapeCharacterOptionN) {
|
||||
newStr.replace("\\n", "\n");
|
||||
} else if (option == EscapeCharacterOptionRN) {
|
||||
newStr.replace("\\r\\n", "\r\n");
|
||||
} else if (option == EscapeCharacterOptionNR) {
|
||||
newStr.replace("\\n\\r", "\n\\r");
|
||||
} else if (option == EscapeCharacterOptionRAndN) {
|
||||
newStr.replace("\\r", "\r");
|
||||
newStr.replace("\\n", "\n");
|
||||
}
|
||||
|
||||
return newStr;
|
||||
}
|
||||
|
||||
@ -20,7 +20,8 @@ public:
|
||||
xToolsDataStructure(QObject *parent = Q_NULLPTR);
|
||||
~xToolsDataStructure();
|
||||
|
||||
enum SAKEnumTextFormat {
|
||||
public:
|
||||
enum TextFormat {
|
||||
TextFormatBin,
|
||||
TextFormatOct,
|
||||
TextFormatDec,
|
||||
@ -29,76 +30,53 @@ public:
|
||||
TextFormatUtf8,
|
||||
TextFormatSystem
|
||||
};
|
||||
Q_ENUM(SAKEnumTextFormat)
|
||||
Q_ENUM(TextFormat)
|
||||
Q_INVOKABLE static QVariantList supportedTextFormats();
|
||||
Q_INVOKABLE static QString textFormatName(int textFormat);
|
||||
Q_INVOKABLE static QString byteArrayToString(const QByteArray &array, int format);
|
||||
Q_INVOKABLE static QByteArray stringToByteArray(const QString &str, int format);
|
||||
Q_INVOKABLE static QString formatString(const QString &str, int format);
|
||||
|
||||
enum SAKEnumEscapeCharacterOption {
|
||||
EscapeCharacterOptionNone,
|
||||
EscapeCharacterOptionR,
|
||||
EscapeCharacterOptionN,
|
||||
EscapeCharacterOptionRN,
|
||||
EscapeCharacterOptionNR,
|
||||
EscapeCharacterOptionRAndN
|
||||
public:
|
||||
enum EscapeCharacter {
|
||||
EscapeCharacterNone,
|
||||
EscapeCharacterR,
|
||||
EscapeCharacterN,
|
||||
EscapeCharacterRN,
|
||||
EscapeCharacterNR,
|
||||
EscapeCharacterRAndN
|
||||
};
|
||||
Q_ENUM(SAKEnumEscapeCharacterOption)
|
||||
Q_ENUM(EscapeCharacter)
|
||||
Q_INVOKABLE static QString cookedString(int escapeCharacter, const QString &str);
|
||||
Q_INVOKABLE static QString cookEscapeCharacter(int option, const QString &str);
|
||||
|
||||
public:
|
||||
enum SAKEnumAffixes { AffixesNone, AffixesR, AffixesN, AffixesRN, AffixesNR };
|
||||
Q_ENUM(SAKEnumAffixes)
|
||||
Q_INVOKABLE static QString cookedAffixes(int affixes);
|
||||
Q_INVOKABLE static QString affixesName(int affixes);
|
||||
Q_INVOKABLE static QByteArray affixesData(int affixes);
|
||||
|
||||
enum EDEnumResponseOptions {
|
||||
ResponseOptionDisable,
|
||||
ResponseOptionEcho,
|
||||
ResponseOptionAlways,
|
||||
ResponseOptionInputEqualReference,
|
||||
ResponseOptionInputContainReference,
|
||||
ResponseOptionInputDiscontainReference
|
||||
public:
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
enum HighDpiPolicy {
|
||||
HighDpiPolicyRound = int(Qt::HighDpiScaleFactorRoundingPolicy::Round),
|
||||
HighDpiPolicyCeil = int(Qt::HighDpiScaleFactorRoundingPolicy::Ceil),
|
||||
HighDpiPolicyFloor = int(Qt::HighDpiScaleFactorRoundingPolicy::Floor),
|
||||
HighDpiPolicyRoundPreferFloor = int(Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor),
|
||||
HighDpiPolicyPassThrough = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough),
|
||||
#ifdef Q_OS_WIN
|
||||
HighDpiPolicySystem,
|
||||
#endif
|
||||
};
|
||||
Q_ENUM(EDEnumResponseOptions)
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
enum SAKHdpiPolicy {
|
||||
HdpiPolicyRound = int(Qt::HighDpiScaleFactorRoundingPolicy::Round),
|
||||
HdpiPolicyCeil = int(Qt::HighDpiScaleFactorRoundingPolicy::Ceil),
|
||||
HdpiPolicyFloor = int(Qt::HighDpiScaleFactorRoundingPolicy::Floor),
|
||||
HdpiPolicyRoundPreferFloor = int(Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor),
|
||||
HdpiPolicyPassThrough = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough),
|
||||
HdpiPolicySystem = 999
|
||||
};
|
||||
Q_ENUM(SAKHdpiPolicy)
|
||||
Q_ENUM(HighDpiPolicy)
|
||||
Q_INVOKABLE static QVariantList supportedHighDpiPolicies();
|
||||
Q_INVOKABLE static QString highDpiPolicyName(int policy);
|
||||
Q_INVOKABLE static bool isValidHighDpiPolicy(int policy);
|
||||
#endif
|
||||
|
||||
public:
|
||||
static QString affixesName(int affixes);
|
||||
static QByteArray affixesData(int affixes);
|
||||
static QString cookedString(int escapeCharacter, const QString &str);
|
||||
static QString textFormatName(int textFormat);
|
||||
Q_INVOKABLE static QString cookEscapeCharacter(int option, const QString &str);
|
||||
|
||||
// Input text format
|
||||
enum SAKEnumTextFormatInput {
|
||||
InputFormatBin,
|
||||
InputFormatOct,
|
||||
InputFormatDec,
|
||||
InputFormatHex,
|
||||
InputFormatAscii,
|
||||
InputFormatLocal
|
||||
};
|
||||
Q_ENUM(SAKEnumTextFormatInput);
|
||||
|
||||
// Output text format
|
||||
enum SAKEnumTextFormatOutput {
|
||||
OutputFormatBin,
|
||||
OutputFormatOct,
|
||||
OutputFormatDec,
|
||||
OutputFormatHex,
|
||||
OutputFormatUcs4,
|
||||
OutputFormatUtf8,
|
||||
OutputFormatUtf16,
|
||||
OutputFormatAscii,
|
||||
OutputFormatLocal
|
||||
};
|
||||
Q_ENUM(SAKEnumTextFormatOutput);
|
||||
|
||||
public:
|
||||
// Web socket sending type
|
||||
enum SAKEnumWebSocketSendingType {
|
||||
WebSocketSendingTypeText,
|
||||
@ -106,6 +84,7 @@ public:
|
||||
};
|
||||
Q_ENUM(SAKEnumWebSocketSendingType);
|
||||
|
||||
public:
|
||||
enum SAKEmnuSuffixType {
|
||||
SuffixsTypeNone,
|
||||
SuffixsTypeR,
|
||||
@ -115,6 +94,7 @@ public:
|
||||
};
|
||||
Q_ENUM(SAKEmnuSuffixType);
|
||||
|
||||
public:
|
||||
enum SAKEnumPrefixType { PrefixTypeNone, PrefixTypeR, PrefixTypeN, PrefixTypeRN, PrefixTypeNR };
|
||||
Q_ENUM(SAKEnumPrefixType);
|
||||
|
||||
@ -137,37 +117,12 @@ public:
|
||||
*/
|
||||
static void setComboBoxTextWebSocketSendingType(QComboBox *comboBox);
|
||||
|
||||
/**
|
||||
* @brief formattingString: Formatting input text of text edit.
|
||||
* @param textEdit: Target text edit.
|
||||
* @param format: See SAKEnumTextInputFormat for more information.
|
||||
*/
|
||||
static QString formattingString(QString &origingString, SAKEnumTextFormatInput format);
|
||||
|
||||
/**
|
||||
* @brief stringToByteArray: Transmit a QString to a QByteArray.
|
||||
* @param origingString: Origin string.
|
||||
* @param format: See SAKEnumTextInputFormat for more information.
|
||||
* @return A QByteArray.
|
||||
*/
|
||||
static QByteArray stringToByteArray(QString &origingString, SAKEnumTextFormatInput format);
|
||||
static QByteArray stringToByteArray(QString &origingString, int format);
|
||||
|
||||
/**
|
||||
* @brief byteArrayToString: Transmit a QByteArray to a QString.
|
||||
* @param origingString: Origin byte array.
|
||||
* @param format: See SAKEnumTextOutputFormat for more information.
|
||||
* @return A QString.
|
||||
*/
|
||||
static QString byteArrayToString(const QByteArray &origingData, SAKEnumTextFormatOutput format);
|
||||
static QString byteArrayToString(const QByteArray &origingData, int format);
|
||||
|
||||
/**
|
||||
* @brief setLineEditTextFormat: Formating input
|
||||
* @param lineEdit: Target component
|
||||
* @param format: (SAKEnumTextInputFormat)
|
||||
*/
|
||||
static void setLineEditTextFormat(QLineEdit *lineEdit, SAKEnumTextFormatInput format);
|
||||
static void setLineEditTextFormat(QLineEdit *lineEdit, TextFormat format);
|
||||
static void setLineEditTextFormat(QLineEdit *lineEdit, int format);
|
||||
|
||||
static QString suffix(SAKEmnuSuffixType type);
|
||||
|
||||
@ -8,11 +8,10 @@
|
||||
**************************************************************************************************/
|
||||
#include "xToolsSettings.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "xToolsDataStructure.h"
|
||||
#include <QUrl>
|
||||
|
||||
static const QString fileName()
|
||||
{
|
||||
@ -51,27 +50,16 @@ QString xToolsSettings::settingsPath()
|
||||
|
||||
int xToolsSettings::hdpiPolicy()
|
||||
{
|
||||
int ret = value(mSettingsKey.hdpiPolicy).toInt();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
if ((ret < 1) || (ret > 5)) {
|
||||
if (ret != xToolsDataStructure::HdpiPolicySystem) {
|
||||
ret = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
}
|
||||
auto var = value(mSettingsKey.hdpiPolicy);
|
||||
if (var.isValid()) {
|
||||
return value(mSettingsKey.hdpiPolicy).toInt();
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
|
||||
return int(QGuiApplication::highDpiScaleFactorRoundingPolicy());
|
||||
}
|
||||
|
||||
void xToolsSettings::setHdpiPolicy(int policy)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
if ((policy < 1) || (policy > 5)) {
|
||||
if (policy != xToolsDataStructure::HdpiPolicySystem) {
|
||||
policy = int(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
setValue(mSettingsKey.hdpiPolicy, policy);
|
||||
emit hdpiPolicyChanged();
|
||||
}
|
||||
|
||||
@ -13,10 +13,10 @@
|
||||
xToolsEscapeCharacterComboBox::xToolsEscapeCharacterComboBox(QWidget* parent)
|
||||
: xToolsComboBox(parent)
|
||||
{
|
||||
addItem(tr("None"), xToolsDataStructure::EscapeCharacterOptionNone);
|
||||
addItem("\\r", xToolsDataStructure::EscapeCharacterOptionR);
|
||||
addItem("\\n", xToolsDataStructure::EscapeCharacterOptionN);
|
||||
addItem("\\r\\n", xToolsDataStructure::EscapeCharacterOptionRN);
|
||||
addItem("\\n\\r", xToolsDataStructure::EscapeCharacterOptionNR);
|
||||
addItem("\\r + \\n", xToolsDataStructure::EscapeCharacterOptionRAndN);
|
||||
addItem(tr("None"), xToolsDataStructure::EscapeCharacterNone);
|
||||
addItem("\\r", xToolsDataStructure::EscapeCharacterR);
|
||||
addItem("\\n", xToolsDataStructure::EscapeCharacterN);
|
||||
addItem("\\r\\n", xToolsDataStructure::EscapeCharacterRN);
|
||||
addItem("\\n\\r", xToolsDataStructure::EscapeCharacterNR);
|
||||
addItem("\\r + \\n", xToolsDataStructure::EscapeCharacterRAndN);
|
||||
}
|
||||
|
||||
@ -26,10 +26,6 @@
|
||||
#include <QStyleFactory>
|
||||
#include <QUrl>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
#include "xToolsDataStructure.h"
|
||||
#endif
|
||||
|
||||
#include "xToolsApplication.h"
|
||||
#include "xToolsInterface.h"
|
||||
#include "xToolsSettings.h"
|
||||
@ -248,56 +244,43 @@ void xToolsMainWindow::initOptionMenuSettingsMenu()
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
#include "xToolsDataStructure.h"
|
||||
#endif
|
||||
void xToolsMainWindow::initOptionMenuHdpiPolicy()
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
QMenu* menu = new QMenu(tr("HDPI Policy"));
|
||||
QActionGroup* action_group = new QActionGroup(this);
|
||||
int setting_policy = xToolsSettings::instance()->hdpiPolicy();
|
||||
QList<QPair<int, QString>> policy_list;
|
||||
typedef QPair<int, QString> policy_pair;
|
||||
policy_list << policy_pair(xToolsDataStructure::HdpiPolicyRound, tr("Round up for .5 and above"));
|
||||
policy_list << policy_pair(xToolsDataStructure::HdpiPolicyCeil, tr("Always round up"));
|
||||
policy_list << policy_pair(xToolsDataStructure::HdpiPolicyFloor, tr("Always round down"));
|
||||
policy_list << policy_pair(xToolsDataStructure::HdpiPolicyRoundPreferFloor,
|
||||
tr("Round up for .75 and above"));
|
||||
policy_list << policy_pair(xToolsDataStructure::HdpiPolicyPassThrough, tr("Don't round"));
|
||||
for (auto& policy : policy_list) {
|
||||
QAction* action = new QAction(policy.second, this);
|
||||
action_group->addAction(action);
|
||||
if (setting_policy == policy.first) {
|
||||
action->setCheckable(true);
|
||||
}
|
||||
|
||||
connect(action, &QAction::triggered, this, [=]() {
|
||||
onHdpiPolicyActionTriggered(policy.first);
|
||||
QActionGroup* actionGroup = new QActionGroup(this);
|
||||
int currentPolicy = xToolsSettings::instance()->hdpiPolicy();
|
||||
auto supportedPolicies = xToolsDataStructure::supportedHighDpiPolicies();
|
||||
for (auto& policy : supportedPolicies) {
|
||||
auto name = xToolsDataStructure::highDpiPolicyName(policy.toInt());
|
||||
auto action = menu->addAction(name, this, [=]() {
|
||||
onHdpiPolicyActionTriggered(policy.toInt());
|
||||
});
|
||||
action->setCheckable(true);
|
||||
actionGroup->addAction(action);
|
||||
if (policy.toInt() == currentPolicy) {
|
||||
action->setChecked(true);
|
||||
}
|
||||
}
|
||||
menu->addActions(action_group->actions());
|
||||
menu->addActions(actionGroup->actions());
|
||||
m_optionMenu->addMenu(menu);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QAction* system_action = new QAction(tr("System"), this);
|
||||
system_action->setCheckable(true);
|
||||
action_group->addAction(system_action);
|
||||
menu->addSeparator();
|
||||
menu->addAction(system_action);
|
||||
|
||||
if (setting_policy == xToolsDataStructure::HdpiPolicySystem) {
|
||||
system_action->setChecked(true);
|
||||
}
|
||||
|
||||
connect(system_action, &QAction::triggered, this, [=]() {
|
||||
xToolsSettings::instance()->setHdpiPolicy(xToolsDataStructure::HdpiPolicySystem);
|
||||
createQtConf();
|
||||
tryToReboot();
|
||||
});
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void xToolsMainWindow::onHdpiPolicyActionTriggered(int policy)
|
||||
{
|
||||
#ifdef X_TOOLS_ENABLE_HIGH_DPI_POLICY
|
||||
#ifdef Q_OS_WIN
|
||||
if (policy == xToolsDataStructure::HighDpiPolicySystem) {
|
||||
createQtConf();
|
||||
tryToReboot();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (QFile::remove(qtConfFileName())) {
|
||||
qInfo() << qtConfFileName() << "was removed!";
|
||||
} else {
|
||||
@ -306,6 +289,9 @@ void xToolsMainWindow::onHdpiPolicyActionTriggered(int policy)
|
||||
|
||||
xToolsSettings::instance()->setHdpiPolicy(int(policy));
|
||||
tryToReboot();
|
||||
#else
|
||||
Q_UNUSED(policy)
|
||||
#endif
|
||||
}
|
||||
|
||||
void xToolsMainWindow::onGithubActionTriggered()
|
||||
|
||||
@ -11,10 +11,10 @@
|
||||
|
||||
#include <QWidgetAction>
|
||||
|
||||
#include "xToolsCompatibility.h"
|
||||
#include "xToolsHighlighter.h"
|
||||
#include "xToolsSettings.h"
|
||||
|
||||
|
||||
xToolsToolBoxUiOutputMenu::xToolsToolBoxUiOutputMenu(const QString& settingsGroup,
|
||||
QTextDocument* doc,
|
||||
QWidget* parent)
|
||||
@ -35,11 +35,7 @@ xToolsToolBoxUiOutputMenu::xToolsToolBoxUiOutputMenu(const QString& settingsGrou
|
||||
xToolsHighlighter* highlighter = new xToolsHighlighter(this);
|
||||
auto updateDoc = [=]() {
|
||||
QString text = ui->keyword->text();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList list = text.split(";", Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList list = text.split(QString(";"), QString::SkipEmptyParts);
|
||||
#endif
|
||||
QStringList list = text.split(";", xToolsSkipEmptyParts);
|
||||
highlighter->removeKeyWord("");
|
||||
highlighter->setKeyWords(list);
|
||||
};
|
||||
|
||||
@ -47,7 +47,7 @@ QVariant xToolsEmitterTool::itemContext(int index)
|
||||
ctx.insert(itemEnable(), true);
|
||||
ctx.insert(itemDescription(), "Demo");
|
||||
ctx.insert(itemTextFormat(), xToolsDataStructure::TextFormatAscii);
|
||||
ctx.insert(itemEscapeCharacter(), xToolsDataStructure::EscapeCharacterOptionNone);
|
||||
ctx.insert(itemEscapeCharacter(), xToolsDataStructure::EscapeCharacterNone);
|
||||
ctx.insert(itemInterval(), 1000);
|
||||
ctx.insert(itemPrefix(), xToolsDataStructure::AffixesNone);
|
||||
ctx.insert(itemSuffix(), xToolsDataStructure::AffixesNone);
|
||||
|
||||
@ -250,7 +250,7 @@ QVariant xToolsPrestorerTool::itemContext(int index)
|
||||
} else {
|
||||
ctx.insert(itemDescription(), "Demo");
|
||||
ctx.insert(itemTextFormat(), xToolsDataStructure::TextFormatAscii);
|
||||
ctx.insert(itemEscapeCharacter(), xToolsDataStructure::EscapeCharacterOptionNone);
|
||||
ctx.insert(itemEscapeCharacter(), xToolsDataStructure::EscapeCharacterNone);
|
||||
ctx.insert(itemPrefix(), xToolsDataStructure::AffixesNone);
|
||||
ctx.insert(itemSuffix(), xToolsDataStructure::AffixesNone);
|
||||
ctx.insert(itemCrcEnable(), false);
|
||||
|
||||
@ -347,7 +347,7 @@ QVariant xToolsResponserTool::itemContext(int index)
|
||||
ctx.insert(itemOption(), 0);
|
||||
|
||||
ctx.insert(itemReferenceTextFormat(), xToolsDataStructure::TextFormatAscii);
|
||||
ctx.insert(itemReferenceEscapeCharacter(), xToolsDataStructure::EscapeCharacterOptionNone);
|
||||
ctx.insert(itemReferenceEscapeCharacter(), xToolsDataStructure::EscapeCharacterNone);
|
||||
ctx.insert(itemReferencePrefix(), xToolsDataStructure::AffixesNone);
|
||||
ctx.insert(itemReferenceSuffix(), xToolsDataStructure::AffixesNone);
|
||||
ctx.insert(itemReferenceCrcEnable(), false);
|
||||
@ -358,7 +358,7 @@ QVariant xToolsResponserTool::itemContext(int index)
|
||||
ctx.insert(itemReferenceText(), "Reference data.");
|
||||
|
||||
ctx.insert(itemResponseTextFormat(), xToolsDataStructure::TextFormatAscii);
|
||||
ctx.insert(itemResponseEscapeCharacter(), xToolsDataStructure::EscapeCharacterOptionNone);
|
||||
ctx.insert(itemResponseEscapeCharacter(), xToolsDataStructure::EscapeCharacterNone);
|
||||
ctx.insert(itemResponsePrefix(), xToolsDataStructure::AffixesNone);
|
||||
ctx.insert(itemResponseSuffix(), xToolsDataStructure::AffixesNone);
|
||||
ctx.insert(itemResponseCrcEnable(), false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user