فهرست منبع

upgrade to Qt6

Le Tan 2 سال پیش
والد
کامیت
2f6afb2f97

+ 1 - 1
libs/vtextedit

@@ -1 +1 @@
-Subproject commit 398ec0f8523d9c74a44cb746b5a1017741521e48
+Subproject commit 7fc093c14e8bc4b8f9203f81499ddd993b707906

+ 2 - 2
src/core/notebook/notebookdatabaseaccess.cpp

@@ -560,9 +560,9 @@ bool NotebookDatabaseAccess::updateNodeTags(Node *p_node)
     const auto &nodeTags = p_node->getTags();
 
     {
-        QStringList list = queryNodeTags(p_node->getId());
+        QStringList tagsList = queryNodeTags(p_node->getId());
         QSet<QString> tags;
-        for (auto &s : list)
+        for (const auto &s : tagsList)
         {
             tags.insert(s);
         }

+ 25 - 22
src/export/webviewexporter.cpp

@@ -5,6 +5,7 @@
 #include <QFileInfo>
 #include <QTemporaryDir>
 #include <QProcess>
+#include <QRegularExpression>
 
 #include <widgets/editors/markdownviewer.h>
 #include <widgets/editors/markdownvieweradapter.h>
@@ -19,7 +20,6 @@
 #include <utils/processutils.h>
 #include <utils/htmlutils.h>
 #include <core/file.h>
-#include <QRegExp>
 
 using namespace vnotex;
 
@@ -359,22 +359,23 @@ void WebViewExporter::prepareWkhtmltopdfArguments(const ExportPdfOption &p_pdfOp
 bool WebViewExporter::embedStyleResources(QString &p_html) const
 {
     bool altered = false;
-    QRegExp reg("\\burl\\(\"((file|qrc):[^\"\\)]+)\"\\);");
+    QRegularExpression reg("\\burl\\(\"((file|qrc):[^\"\\)]+)\"\\);");
 
     int pos = 0;
     while (pos < p_html.size()) {
-        int idx = reg.indexIn(p_html, pos);
+        QRegularExpressionMatch match;
+        int idx = p_html.indexOf(reg, pos, &match);
         if (idx == -1) {
             break;
         }
 
-        QString dataURI = WebUtils::toDataUri(QUrl(reg.cap(1)), false);
+        QString dataURI = WebUtils::toDataUri(QUrl(match.captured(1)), false);
         if (dataURI.isEmpty()) {
-            pos = idx + reg.matchedLength();
+            pos = idx + match.capturedLength();
         } else {
             // Replace the url string in html.
             QString newUrl = QString("url('%1');").arg(dataURI);
-            p_html.replace(idx, reg.matchedLength(), newUrl);
+            p_html.replace(idx, match.capturedLength(), newUrl);
             pos = idx + newUrl.size();
             altered = true;
         }
@@ -390,28 +391,29 @@ bool WebViewExporter::embedBodyResources(const QUrl &p_baseUrl, QString &p_html)
         return altered;
     }
 
-    QRegExp reg(c_imgRegExp);
+    QRegularExpression reg(c_imgRegExp);
 
     int pos = 0;
     while (pos < p_html.size()) {
-        int idx = reg.indexIn(p_html, pos);
+        QRegularExpressionMatch match;
+        int idx = p_html.indexOf(reg, pos, &match);
         if (idx == -1) {
             break;
         }
 
-        if (reg.cap(2).isEmpty()) {
-            pos = idx + reg.matchedLength();
+        if (match.captured(2).isEmpty()) {
+            pos = idx + match.capturedLength();
             continue;
         }
 
-        QUrl srcUrl(p_baseUrl.resolved(reg.cap(2)));
+        QUrl srcUrl(p_baseUrl.resolved(match.captured(2)));
         const auto dataURI = WebUtils::toDataUri(srcUrl, true);
         if (dataURI.isEmpty()) {
-            pos = idx + reg.matchedLength();
+            pos = idx + match.capturedLength();
         } else {
             // Replace the url string in html.
-            QString newUrl = QString("<img %1src='%2'%3>").arg(reg.cap(1), dataURI, reg.cap(3));
-            p_html.replace(idx, reg.matchedLength(), newUrl);
+            QString newUrl = QString("<img %1src='%2'%3>").arg(match.captured(1), dataURI, match.captured(3));
+            p_html.replace(idx, match.capturedLength(), newUrl);
             pos = idx + newUrl.size();
             altered = true;
         }
@@ -437,28 +439,29 @@ bool WebViewExporter::fixBodyResources(const QUrl &p_baseUrl,
         return altered;
     }
 
-    QRegExp reg(c_imgRegExp);
+    QRegularExpression reg(c_imgRegExp);
 
     int pos = 0;
     while (pos < p_html.size()) {
-        int idx = reg.indexIn(p_html, pos);
+        QRegularExpressionMatch match;
+        int idx = p_html.indexOf(reg, pos, &match);
         if (idx == -1) {
             break;
         }
 
-        if (reg.cap(2).isEmpty()) {
-            pos = idx + reg.matchedLength();
+        if (match.captured(2).isEmpty()) {
+            pos = idx + match.capturedLength();
             continue;
         }
 
-        QUrl srcUrl(p_baseUrl.resolved(reg.cap(2)));
+        QUrl srcUrl(p_baseUrl.resolved(match.captured(2)));
         QString targetFile = WebUtils::copyResource(srcUrl, p_folder);
         if (targetFile.isEmpty()) {
-            pos = idx + reg.matchedLength();
+            pos = idx + match.capturedLength();
         } else {
             // Replace the url string in html.
-            QString newUrl = QString("<img %1src=\"%2\"%3>").arg(reg.cap(1), getResourceRelativePath(targetFile), reg.cap(3));
-            p_html.replace(idx, reg.matchedLength(), newUrl);
+            QString newUrl = QString("<img %1src=\"%2\"%3>").arg(match.captured(1), getResourceRelativePath(targetFile), match.captured(3));
+            p_html.replace(idx, match.capturedLength(), newUrl);
             pos = idx + newUrl.size();
             altered = true;
         }

+ 0 - 2
src/main.cpp

@@ -31,7 +31,6 @@ using namespace vnotex;
 
 void loadTranslators(QApplication &p_app);
 
-
 void showMessageOnCommandLineIfAvailable(const QString &p_msg);
 
 int main(int argc, char *argv[])
@@ -78,7 +77,6 @@ int main(int argc, char *argv[])
 
     Application app(argc, argv);
 
-
     QAccessible::installFactory(&FakeAccessible::accessibleFactory);
 
     {

+ 6 - 5
src/utils/iconutils.cpp

@@ -1,6 +1,6 @@
 #include "iconutils.h"
 
-#include <QRegExp>
+#include <QRegularExpression>
 #include <QFileInfo>
 #include <QPixmap>
 #include <QPainter>
@@ -80,17 +80,18 @@ QString IconUtils::replaceForegroundOfIcon(const QString &p_iconContent, const Q
 bool IconUtils::isMonochrome(const QString &p_iconContent)
 {
     // Match color-hex codes.
-    QRegExp monoRe("#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})");
+    QRegularExpression monoRe("#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})");
 
     QString lastColor = "";
     int pos = 0;
     while (pos < p_iconContent.size()) {
-        int idx = monoRe.indexIn(p_iconContent, pos);
+        QRegularExpressionMatch match;
+        int idx = p_iconContent.indexOf(monoRe, pos, &match);
         if (idx == -1) {
             break;
         }
 
-        auto curColor = monoRe.cap(1).toLower();
+        auto curColor = match.captured(1).toLower();
         if (curColor.size() == 3) {
             for (int i = curColor.size() - 1; i >= 0; --i) {
                 curColor.insert(i, curColor[i]);
@@ -105,7 +106,7 @@ bool IconUtils::isMonochrome(const QString &p_iconContent)
             }
         }
 
-        pos += monoRe.matchedLength();
+        pos += match.capturedLength();
     }
 
     return true;

+ 6 - 4
src/utils/utils.cpp

@@ -6,13 +6,13 @@
 #include <QWidget>
 #include <QFontDatabase>
 #include <QRegularExpression>
-#include <QRegularExpressionMatch>
 #include <QSvgRenderer>
 #include <QPainter>
 #include <QJsonObject>
 #include <QJsonArray>
 #include <QJsonDocument>
 #include <QDebug>
+#include <QLocale>
 
 #include <cmath>
 
@@ -42,7 +42,8 @@ void Utils::appendMsg(QString &p_msg, const QString &p_new)
 
 QString Utils::dateTimeString(const QDateTime &p_dateTime)
 {
-    return p_dateTime.date().toString(Qt::ISODate)
+    QLocale locale;
+    return locale.toString(p_dateTime.date())
            + " "
            + p_dateTime.time().toString(Qt::TextDate);
 }
@@ -69,15 +70,16 @@ QChar Utils::keyToChar(int p_key, bool p_lowerCase)
 
 QString Utils::pickAvailableFontFamily(const QStringList &p_families)
 {
-    auto availableFonts = QFontDatabase().families();
+    auto availableFonts = QFontDatabase::families();
     for (const auto& f : p_families) {
         auto family = f.trimmed();
         if (family.isEmpty()) {
             continue;
         }
 
+        QRegularExpression regExp("\\[.*\\]");
         for (auto availableFont : availableFonts) {
-            availableFont.remove(QRegularExpression("\\[.*\\]"));
+            availableFont.remove(regExp);
             availableFont = availableFont.trimmed();
             if (family == availableFont
                 || family.toLower() == availableFont.toLower()) {

+ 15 - 13
src/widgets/editors/markdowneditor.cpp

@@ -55,7 +55,6 @@
 #include <imagehost/imagehostutils.h>
 #include <imagehost/imagehost.h>
 #include <imagehost/imagehostmgr.h>
-#include <QRegExp>
 
 #include "previewhelper.h"
 #include "../outlineprovider.h"
@@ -546,8 +545,9 @@ bool MarkdownEditor::processHtmlFromMimeData(const QMimeData *p_source)
     const QString html(p_source->html());
 
     // Process <img>.
-    QRegExp reg("<img ([^>]*)src=\"([^\"]+)\"([^>]*)>");
-    if (reg.indexIn(html) != -1 && HtmlUtils::hasOnlyImgTag(html)) {
+    QRegularExpression reg("<img ([^>]*)src=\"([^\"]+)\"([^>]*)>");
+    QRegularExpressionMatch match;
+    if (html.indexOf(reg, 0, &match) != -1 && HtmlUtils::hasOnlyImgTag(html)) {
         if (p_source->hasImage()) {
             // Both image data and URL are embedded.
             SelectDialog dialog(tr("Insert From Clipboard"), this);
@@ -563,7 +563,7 @@ bool MarkdownEditor::processHtmlFromMimeData(const QMimeData *p_source)
                     return true;
                 } else if (selection == 2) {
                     // Insert as link.
-                    auto imageLink = vte::MarkdownUtils::generateImageLink("", reg.cap(2), "");
+                    auto imageLink = vte::MarkdownUtils::generateImageLink("", match.captured(2), "");
                     m_textEdit->insertPlainText(imageLink);
                     return true;
                 }
@@ -572,7 +572,7 @@ bool MarkdownEditor::processHtmlFromMimeData(const QMimeData *p_source)
             }
         }
 
-        insertImageFromUrl(reg.cap(2));
+        insertImageFromUrl(match.captured(2));
         return true;
     }
 
@@ -1220,9 +1220,9 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
     proDlg.setWindowModality(Qt::WindowModal);
     proDlg.setWindowTitle(tr("Fetch Images To Local"));
 
-    QRegExp zhihuRegExp("^https?://www\\.zhihu\\.com/equation\\?tex=(.+)$");
+    QRegularExpression zhihuRegExp("^https?://www\\.zhihu\\.com/equation\\?tex=(.+)$");
 
-    QRegExp regExp(vte::MarkdownUtils::c_imageLinkRegExp);
+    QRegularExpression regExp(vte::MarkdownUtils::c_imageLinkRegExp);
     for (int i = regs.size() - 1; i >= 0; --i) {
         proDlg.setValue(regs.size() - 1 - i);
         if (proDlg.wasCanceled()) {
@@ -1231,14 +1231,15 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
 
         const auto &reg = regs[i];
         QString linkText = p_text.mid(reg.m_startPos, reg.m_endPos - reg.m_startPos);
-        if (regExp.indexIn(linkText) == -1) {
+        QRegularExpressionMatch match;
+        if (linkText.indexOf(regExp, 0, &match) == -1) {
             continue;
         }
 
         qDebug() << "fetching image link" << linkText;
 
-        const QString imageTitle = purifyImageTitle(regExp.cap(1).trimmed());
-        QString imageUrl = regExp.cap(2).trimmed();
+        const QString imageTitle = purifyImageTitle(match.captured(1).trimmed());
+        QString imageUrl = match.captured(2).trimmed();
 
         const int maxUrlLength = 100;
         QString urlToDisplay(imageUrl);
@@ -1248,8 +1249,9 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
         proDlg.setLabelText(tr("Fetching image (%1)").arg(urlToDisplay));
 
         // Handle equation from zhihu.com like http://www.zhihu.com/equation?tex=P.
-        if (zhihuRegExp.indexIn(imageUrl) != -1) {
-            QString tex = zhihuRegExp.cap(1).trimmed();
+        QRegularExpressionMatch zhihuMatch;
+        if (imageUrl.indexOf(zhihuRegExp, 0, &zhihuMatch) != -1) {
+            QString tex = zhihuMatch.captured(1).trimmed();
 
             // Remove the +.
             tex.replace(QChar('+'), " ");
@@ -1322,7 +1324,7 @@ void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
 
         // Replace URL in link.
         QString newLink = QString("![%1](%2%3%4)")
-                                 .arg(imageTitle, urlInLink, regExp.cap(3), regExp.cap(6));
+                                 .arg(imageTitle, urlInLink, match.captured(3), match.captured(6));
         p_text.replace(reg.m_startPos,
                        reg.m_endPos - reg.m_startPos,
                        newLink);

+ 1 - 1
src/widgets/editors/markdownviewer.cpp

@@ -108,7 +108,7 @@ void MarkdownViewer::setPreviewHelper(PreviewHelper *p_previewHelper)
 
 void MarkdownViewer::contextMenuEvent(QContextMenuEvent *p_event)
 {
-    QScopedPointer<QMenu> menu(this->createStandardContextMenu());
+    QScopedPointer<QMenu> menu(createStandardContextMenu());
     const QList<QAction *> actions = menu->actions();
 
 #if defined(Q_OS_WIN)

+ 9 - 18
src/widgets/markdownviewwindow.cpp

@@ -13,7 +13,7 @@
 #include <QActionGroup>
 #include <QTimer>
 #include <QPrinter>
-  #include <QWebEngineSettings>
+#include <QWebEngineSettings>
 
 #include <core/fileopenparameters.h>
 #include <core/editorconfig.h>
@@ -395,7 +395,8 @@ void MarkdownViewWindow::setupTextEditor()
 
     connect(m_editor, &MarkdownEditor::applySnippetRequested,
             this, QOverload<>::of(&MarkdownViewWindow::applySnippet));
-    connect(m_viewer, &MarkdownViewer::printFinished, this, &MarkdownViewWindow::onPrintFinish);
+    connect(m_viewer, &MarkdownViewer::printFinished,
+            this, &MarkdownViewWindow::onPrintFinished);
 
 }
 
@@ -505,7 +506,8 @@ void MarkdownViewWindow::setupViewer()
                     setEditViewMode(m_editViewMode);
                 }
             });
-    m_viewer->settings()->resetAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls);
+
+    m_viewer->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
 }
 
 void MarkdownViewWindow::syncTextEditorFromBuffer(bool p_syncPositionFromReadMode)
@@ -1403,30 +1405,19 @@ void MarkdownViewWindow::print()
     }
 
     m_printer = PrintUtils::promptForPrint(m_viewer->hasSelection(), this);
-
     if (m_printer)
     {
         m_printer->setOutputFormat(QPrinter::PdfFormat);
         m_viewer->print(m_printer.get());
     }
 }
-void MarkdownViewWindow::onPrintFinish(bool isSeccess)
+
+void MarkdownViewWindow::onPrintFinished(bool succeeded)
 {
     m_printer.reset();
-    QString message;
-    if (isSeccess) {
-         message = "print to pdf suceess.";
-    } else {
-         message = "print to pdf failed.";
-    }
-    showMessage(message);
-
-//    MessageBoxHelper::notify(MessageBoxHelper::Information,
-//                             message,
-//                             QString(),
-//                             QString(),
-//                             this);
+    showMessage(succeeded ? tr("Printed to PDF") : tr("Failed to print to PDF"));
 }
+
 void MarkdownViewWindow::handleExternalCodeBlockHighlightRequest(int p_idx, quint64 p_timeStamp, const QString &p_text)
 {
     static bool stylesInitialized = false;

+ 4 - 1
src/widgets/markdownviewwindow.h

@@ -13,6 +13,7 @@ class QWebEngineView;
 class QActionGroup;
 class QTimer;
 class QPrinter;
+
 namespace vte
 {
     class MarkdownEditorConfig;
@@ -61,7 +62,8 @@ namespace vnotex
     public slots:
         void handleEditorConfigChange() Q_DECL_OVERRIDE;
 
-        void onPrintFinish(bool isSeccess);
+        void onPrintFinished(bool succeeded);
+
     protected slots:
         void setModified(bool p_modified) Q_DECL_OVERRIDE;
 
@@ -238,6 +240,7 @@ namespace vnotex
         MarkdownEditorConfig::EditViewMode m_editViewMode = MarkdownEditorConfig::EditViewMode::EditOnly;
 
         QTimer *m_syncPreviewTimer = nullptr;
+
         QSharedPointer<QPrinter> m_printer;
     };
 }

+ 2 - 0
src/widgets/outlineprovider.h

@@ -4,7 +4,9 @@
 #include <QObject>
 #include <QSharedPointer>
 #include <QVector>
+
 #include <limits.h>
+
 namespace vnotex
 {
     typedef QVector<int> SectionNumber;

+ 1 - 1
src/widgets/viewsplit.cpp

@@ -10,6 +10,7 @@
 #include <QMimeData>
 #include <QFileInfo>
 #include <QShortcut>
+#include <QActionGroup>
 
 #include "viewwindow.h"
 #include "viewarea.h"
@@ -25,7 +26,6 @@
 #include <core/coreconfig.h>
 #include "propertydefs.h"
 #include "fileopenparameters.h"
-#include "sessionconfig.h"
 
 using namespace vnotex;