diff --git a/libs/vtextedit b/libs/vtextedit index 398ec0f852..7fc093c14e 160000 --- a/libs/vtextedit +++ b/libs/vtextedit @@ -1 +1 @@ -Subproject commit 398ec0f8523d9c74a44cb746b5a1017741521e48 +Subproject commit 7fc093c14e8bc4b8f9203f81499ddd993b707906 diff --git a/src/core/notebook/notebookdatabaseaccess.cpp b/src/core/notebook/notebookdatabaseaccess.cpp index 610bb066f1..d37e831ad2 100644 --- a/src/core/notebook/notebookdatabaseaccess.cpp +++ b/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 tags; - for (auto &s : list) + for (const auto &s : tagsList) { tags.insert(s); } diff --git a/src/export/webviewexporter.cpp b/src/export/webviewexporter.cpp index 69291a3ee8..694b8c977c 100644 --- a/src/export/webviewexporter.cpp +++ b/src/export/webviewexporter.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include 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("").arg(reg.cap(1), dataURI, reg.cap(3)); - p_html.replace(idx, reg.matchedLength(), newUrl); + QString newUrl = QString("").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("").arg(reg.cap(1), getResourceRelativePath(targetFile), reg.cap(3)); - p_html.replace(idx, reg.matchedLength(), newUrl); + QString newUrl = QString("").arg(match.captured(1), getResourceRelativePath(targetFile), match.captured(3)); + p_html.replace(idx, match.capturedLength(), newUrl); pos = idx + newUrl.size(); altered = true; } diff --git a/src/main.cpp b/src/main.cpp index 4363903455..ee9a52d227 100644 --- a/src/main.cpp +++ b/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); { diff --git a/src/utils/iconutils.cpp b/src/utils/iconutils.cpp index 80ea617332..fb68207e07 100644 --- a/src/utils/iconutils.cpp +++ b/src/utils/iconutils.cpp @@ -1,6 +1,6 @@ #include "iconutils.h" -#include +#include #include #include #include @@ -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; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 076722a0dc..c93e5ded91 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -6,13 +6,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include @@ -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()) { diff --git a/src/widgets/editors/markdowneditor.cpp b/src/widgets/editors/markdowneditor.cpp index c9bb5c5f8a..c0b59b78ac 100644 --- a/src/widgets/editors/markdowneditor.cpp +++ b/src/widgets/editors/markdowneditor.cpp @@ -55,7 +55,6 @@ #include #include #include -#include #include "previewhelper.h" #include "../outlineprovider.h" @@ -546,8 +545,9 @@ bool MarkdownEditor::processHtmlFromMimeData(const QMimeData *p_source) const QString html(p_source->html()); // Process . - QRegExp reg("]*)src=\"([^\"]+)\"([^>]*)>"); - if (reg.indexIn(html) != -1 && HtmlUtils::hasOnlyImgTag(html)) { + QRegularExpression reg("]*)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 ® = 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); diff --git a/src/widgets/editors/markdownviewer.cpp b/src/widgets/editors/markdownviewer.cpp index a75a9a6827..0208e3a326 100644 --- a/src/widgets/editors/markdownviewer.cpp +++ b/src/widgets/editors/markdownviewer.cpp @@ -108,7 +108,7 @@ void MarkdownViewer::setPreviewHelper(PreviewHelper *p_previewHelper) void MarkdownViewer::contextMenuEvent(QContextMenuEvent *p_event) { - QScopedPointer menu(this->createStandardContextMenu()); + QScopedPointer menu(createStandardContextMenu()); const QList actions = menu->actions(); #if defined(Q_OS_WIN) diff --git a/src/widgets/markdownviewwindow.cpp b/src/widgets/markdownviewwindow.cpp index 3242bdcde9..0c352c9d1d 100644 --- a/src/widgets/markdownviewwindow.cpp +++ b/src/widgets/markdownviewwindow.cpp @@ -13,7 +13,7 @@ #include #include #include - #include +#include #include #include @@ -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; diff --git a/src/widgets/markdownviewwindow.h b/src/widgets/markdownviewwindow.h index 11d72db9d9..91cff47e3f 100644 --- a/src/widgets/markdownviewwindow.h +++ b/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 m_printer; }; } diff --git a/src/widgets/outlineprovider.h b/src/widgets/outlineprovider.h index 39dae2424d..bfe56ba40c 100644 --- a/src/widgets/outlineprovider.h +++ b/src/widgets/outlineprovider.h @@ -4,7 +4,9 @@ #include #include #include + #include + namespace vnotex { typedef QVector SectionNumber; diff --git a/src/widgets/viewsplit.cpp b/src/widgets/viewsplit.cpp index 8d6fced661..006d756f5f 100644 --- a/src/widgets/viewsplit.cpp +++ b/src/widgets/viewsplit.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "viewwindow.h" #include "viewarea.h" @@ -25,7 +26,6 @@ #include #include "propertydefs.h" #include "fileopenparameters.h" -#include "sessionconfig.h" using namespace vnotex;