chore: update files of project

This commit is contained in:
wuhai 2024-03-30 08:49:41 +08:00
parent 33c0db19cf
commit 5a4fb46c88
7 changed files with 35 additions and 34 deletions

View File

@ -23,6 +23,7 @@
#include <QLocale>
#include <QPainter>
#include <QRegularExpressionValidator>
#include <QScreen>
#include <QSettings>
#include <QStandardItemModel>
#include <QTextDocument>
@ -141,23 +142,24 @@ void xToolsApplication::setValidator(QLineEdit *target, int validatorType, int m
static QMap<int, QRegularExpressionValidator *> regularExpressionMap;
if (regularExpressionMap.isEmpty()) {
typedef QRegularExpressionValidator REV;
auto noneRE = nullptr;
QRegularExpressionValidator *noneRE = nullptr;
auto binRE = new REV(QRegularExpression("([01][01][01][01][01][01][01][01][ ])*"));
auto otcRE = new REV(QRegularExpression("([0-7][0-7][ ])*"));
auto decRE = new REV(QRegularExpression("([-+.e0-9])*"));
auto decRE = new REV(QRegularExpression("([0-9])*"));
auto hexRE = new REV(QRegularExpression("([0-9a-fA-F][0-9a-fA-F][ ])*"));
auto asciiRE = new REV(QRegularExpression("([ -~])*"));
auto floatRE = new REV(QRegularExpression("^[-+]?[0-9]*\\.?[0-9]+$"));
auto urf8RE = nullptr;
auto systemRE = nullptr;
QRegularExpressionValidator *urf8RE = nullptr;
QRegularExpressionValidator *systemRE = nullptr;
Q_UNUSED(floatRE)
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatBin), noneRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatOct), binRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatDec), otcRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatHex), decRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatAscii), hexRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatUtf8), asciiRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatSystem), floatRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatBin), binRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatOct), otcRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatDec), decRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatHex), hexRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatAscii), asciiRE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatUtf8), urf8RE);
regularExpressionMap.insert(int(xToolsDataStructure::TextFormatSystem), systemRE);
}
if (!target || !regularExpressionMap.contains(validatorType) || maxLength < 0) {
@ -191,6 +193,20 @@ QMainWindow *xToolsApplication::mainWindow()
return nullptr;
}
void xToolsApplication::moveToScreenCenter(QWidget *widget)
{
QRect screenRect = QApplication::primaryScreen()->geometry();
bool tooWidth = (widget->width() > screenRect.width());
bool tooHeight = (widget->height() > screenRect.height());
if (tooWidth || tooHeight) {
widget->showMaximized();
qInfo() << "The screen is too small.";
} else {
widget->move((screenRect.width() - widget->width()) / 2,
(screenRect.height() - widget->height()) / 2);
}
}
QString xToolsApplication::clipboardText()
{
return QGuiApplication::clipboard()->text();

View File

@ -39,6 +39,7 @@ public:
static void setValidator(QLineEdit *target, int validatorType, int maxLength = INT_MAX);
static QIcon cookedIcon(const QIcon &icon);
static QMainWindow *mainWindow();
static void moveToScreenCenter(QWidget *widget);
Q_INVOKABLE static QString clipboardText();
Q_INVOKABLE static void setClipboardText(const QString &text);

View File

@ -202,13 +202,14 @@ int xToolsExec(int argc, char* argv[], const QString& appName, bool usingCommonM
mainWindow->setCentralWidget(centralWidget);
mainWindow->show();
mainWindow->resize(int(qreal(mainWindow->height()) * 1.732), mainWindow->height());
mainWindow->moveToCenter();
xToolsApplication::moveToScreenCenter(mainWindow);
qInfo() << "The size of window is" << mainWindow->size();
} else {
CentralWidgetT* widget = new CentralWidgetT();
splashScreen.finish(widget);
widget->show();
widget->resize(int(qreal(widget->height()) * 1.732), widget->height());
xToolsApplication::moveToScreenCenter(widget);
qInfo() << "The size of window is" << widget->size();
}

View File

@ -42,19 +42,6 @@ xToolsMainWindow::xToolsMainWindow(QWidget* parent)
init();
}
void xToolsMainWindow::moveToCenter()
{
QRect screenRect = QApplication::primaryScreen()->geometry();
bool tooWidth = (width() > screenRect.width());
bool tooHeight = (height() > screenRect.height());
if (tooWidth || tooHeight) {
showMaximized();
qInfo() << "The screen is too small.";
} else {
move((screenRect.width() - width()) / 2, (screenRect.height() - height()) / 2);
}
}
QString xToolsMainWindow::qtConfFileName()
{
return qApp->applicationDirPath() + "/qt.conf";

View File

@ -22,8 +22,6 @@ class xToolsMainWindow : public QMainWindow
public:
explicit xToolsMainWindow(QWidget* parent = Q_NULLPTR);
void moveToCenter();
protected:
xToolsApplication* m_xToolsApp;

View File

@ -13,12 +13,10 @@
xToolsTextFormatComboBox::xToolsTextFormatComboBox(QWidget* parent)
: xToolsComboBox(parent)
{
addItem("Bin", xToolsDataStructure::TextFormatBin);
addItem("Oct", xToolsDataStructure::TextFormatOct);
addItem("Dec", xToolsDataStructure::TextFormatDec);
addItem("Hex", xToolsDataStructure::TextFormatHex);
addItem("Ascii", xToolsDataStructure::TextFormatAscii);
addItem("Utf8", xToolsDataStructure::TextFormatUtf8);
auto formats = xToolsDataStructure::supportedTextFormats();
for (auto &format : formats) {
addItem(xToolsDataStructure::textFormatName(format.toInt()), format.toInt());
}
blockSignals(true);
setCurrentIndex(5);

View File

@ -735,7 +735,7 @@ void xToolsToolBoxUi::onComboBoxInputFormatActivated()
{
int format = ui->comboBoxInputFormat->currentData().toInt();
auto lineEdit = ui->comboBoxInputText->lineEdit();
ui->comboBoxInputText->clear();
ui->comboBoxInputText->lineEdit()->clear();
xToolsApplication::setValidator(lineEdit, format);
}