minor refactor

This commit is contained in:
arm64v8a
2023-05-22 11:07:14 +09:00
parent 1b050dd3fb
commit c5122b77e4
98 changed files with 1173 additions and 1142 deletions

View File

@@ -60,7 +60,7 @@ uint WinCommander::runProcessElevated(const QString &path,
LPCTSTR pszParameters = (LPCTSTR)params.utf16();
QString dir;
if (workingDir.isEmpty())
if (workingDir.count() == 0)
dir = QDir::toNativeSeparators(QDir::currentPath());
else
dir = QDir::toNativeSeparators(workingDir);

4
3rdparty/base64.cpp vendored
View File

@@ -1,5 +1,9 @@
#include "base64.h"
#ifndef qsizetype
#define qsizetype size_t
#endif
namespace Qt515Base64 {
namespace {
struct fromBase64_helper_result {

11
3rdparty/fix_old_qt.h vendored Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include <QString>
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
inline QString qEnvironmentVariable(const char *varName) {
return qgetenv(varName);
}
#endif

View File

@@ -16,9 +16,10 @@
#include <QStandardPaths>
#include <QProcess>
#include "3rdparty/fix_old_qt.h"
#include "3rdparty/qv2ray/wrapper.hpp"
#include "fmt/Preset.hpp"
#include "main/NekoRay.hpp"
#include "main/NekoGui.hpp"
#define QV_MODULE_NAME "SystemProxy"
@@ -253,7 +254,7 @@ namespace Qv2ray::components::proxy {
#endif
#ifdef Q_OS_WIN
QString str = NekoRay::dataStore->system_proxy_format;
QString str = NekoGui::dataStore->system_proxy_format;
if (str.isEmpty()) str = Preset::Windows::system_proxy_format[0];
str = str.replace("{ip}", address)
.replace("{http_port}", Int2String(httpPort))

View File

@@ -118,7 +118,7 @@ namespace Qv2ray::ui {
}
void SyntaxHighlighter::highlightBlock(const QString &text) {
for (const HighlightingRule &rule: qAsConst(highlightingRules)) {
for (const HighlightingRule &rule: highlightingRules) {
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
while (matchIterator.hasNext()) {

View File

@@ -55,36 +55,38 @@
#include <QTextCharFormat>
#include <QTextDocument>
namespace Qv2ray::ui {
class SyntaxHighlighter : public QSyntaxHighlighter {
Q_OBJECT
namespace Qv2ray {
namespace ui {
class SyntaxHighlighter : public QSyntaxHighlighter {
Q_OBJECT
public:
explicit SyntaxHighlighter(bool darkMode, QTextDocument *parent = nullptr);
public:
explicit SyntaxHighlighter(bool darkMode, QTextDocument *parent = nullptr);
protected:
void highlightBlock(const QString &text) override;
protected:
void highlightBlock(const QString &text) override;
private:
struct HighlightingRule {
QRegularExpression pattern;
QTextCharFormat format;
private:
struct HighlightingRule {
QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules;
QTextCharFormat tcpudpFormat;
QTextCharFormat dateFormat;
QTextCharFormat acceptedFormat;
QTextCharFormat rejectedFormat;
QTextCharFormat failedFormat;
QTextCharFormat warningFormat;
QTextCharFormat warningFormat2;
QTextCharFormat infoFormat;
QTextCharFormat debugFormat;
QTextCharFormat timeFormat;
QTextCharFormat ipHostFormat;
QTextCharFormat v2rayComponentFormat;
};
QVector<HighlightingRule> highlightingRules;
QTextCharFormat tcpudpFormat;
QTextCharFormat dateFormat;
QTextCharFormat acceptedFormat;
QTextCharFormat rejectedFormat;
QTextCharFormat failedFormat;
QTextCharFormat warningFormat;
QTextCharFormat warningFormat2;
QTextCharFormat infoFormat;
QTextCharFormat debugFormat;
QTextCharFormat timeFormat;
QTextCharFormat ipHostFormat;
QTextCharFormat v2rayComponentFormat;
};
} // namespace Qv2ray::ui
} // namespace ui
} // namespace Qv2ray
using namespace Qv2ray::ui;

View File

@@ -70,7 +70,7 @@ namespace Qv2ray::ui::widgets {
c->setWidget(this);
c->setCompletionMode(QCompleter::PopupCompletion);
c->setCaseSensitivity(Qt::CaseInsensitive);
QObject::connect(c, QOverload<const QString &>::of(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion);
QObject::connect(c, static_cast<void (QCompleter::*)(const QString &)>(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion);
}
AutoCompleteTextEdit::~AutoCompleteTextEdit() {

View File

@@ -55,27 +55,31 @@ QT_BEGIN_NAMESPACE
class QCompleter;
QT_END_NAMESPACE
namespace Qv2ray::ui::widgets {
class AutoCompleteTextEdit : public QPlainTextEdit {
Q_OBJECT
namespace Qv2ray {
namespace ui {
namespace widgets {
class AutoCompleteTextEdit : public QPlainTextEdit {
Q_OBJECT
public:
AutoCompleteTextEdit(const QString &prefix, const QStringList &sourceStrings, QWidget *parent = nullptr);
~AutoCompleteTextEdit();
public:
AutoCompleteTextEdit(const QString &prefix, const QStringList &sourceStrings, QWidget *parent = nullptr);
~AutoCompleteTextEdit();
protected:
void keyPressEvent(QKeyEvent *e) override;
void focusInEvent(QFocusEvent *e) override;
protected:
void keyPressEvent(QKeyEvent *e) override;
void focusInEvent(QFocusEvent *e) override;
private slots:
void insertCompletion(const QString &completion);
private slots:
void insertCompletion(const QString &completion);
private:
QString lineUnderCursor() const;
QString wordUnderCursor() const;
private:
QString lineUnderCursor() const;
QString wordUnderCursor() const;
QString prefix;
QCompleter *c = nullptr;
};
} // namespace Qv2ray::ui::widgets
QString prefix;
QCompleter *c = nullptr;
};
} // namespace widgets
} // namespace ui
} // namespace Qv2ray
using namespace Qv2ray::ui::widgets;

View File

@@ -1,6 +1,6 @@
#include "w_JsonEditor.hpp"
#include "main/NekoRay.hpp"
#include "main/NekoGui.hpp"
JsonEditor::JsonEditor(const QJsonObject& rootObject, QWidget* parent) : QDialog(parent) {
setupUi(this);

View File

@@ -7,10 +7,12 @@
#define LOG(...) Qv2ray::base::log_internal(__VA_ARGS__)
#define DEBUG(...) Qv2ray::base::log_internal(__VA_ARGS__)
namespace Qv2ray::base {
template<typename... T>
inline void log_internal(T... v) {}
} // namespace Qv2ray::base
namespace Qv2ray {
namespace base {
template<typename... T>
inline void log_internal(T... v) {}
} // namespace base
} // namespace Qv2ray
#define JsonToString(a) QJsonObject2QString(a, false)
#define JsonFromString(a) QString2QJsonObject(a)