Skip to content

Commit

Permalink
upgrade to Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed Sep 17, 2023
1 parent cbd3956 commit 2f6afb2
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 70 deletions.
2 changes: 1 addition & 1 deletion libs/vtextedit
Submodule vtextedit updated 39 files
+1 −1 src/editor/editor.pro
+2 −2 src/editor/include/vtextedit/pegmarkdownhighlighter.h
+2 −2 src/editor/include/vtextedit/vtextedit.h
+1 −1 src/editor/markdowneditor/peghighlighterresult.cpp
+8 −8 src/editor/markdowneditor/pegparser.cpp
+1 −1 src/editor/markdowneditor/pegparser.h
+1 −1 src/editor/markdowneditor/textdocumentlayout.cpp
+1 −1 src/editor/textedit/theme.cpp
+1 −1 src/editor/textedit/vtextedit.cpp
+3 −3 src/editor/texteditor/completer.cpp
+1 −1 src/editor/texteditor/completer.h
+1 −1 src/editor/texteditor/editorextraselection.cpp
+3 −3 src/editor/texteditor/indicatorsborder.cpp
+2 −3 src/editor/texteditor/textfolding.h
+41 −40 src/editor/utils/markdownutils.cpp
+1 −1 src/editor/utils/networkutils.cpp
+1 −1 src/editor/utils/texteditutils.cpp
+1 −1 src/libs/katevi/katevi.pro
+3 −3 src/libs/katevi/src/emulatedcommandbar/completer.cpp
+1 −1 src/libs/katevi/src/emulatedcommandbar/emulatedcommandbar.cpp
+0 −2 src/libs/katevi/src/include/katevi/interface/command.h
+1 −1 src/libs/katevi/src/include/katevi/interface/kateviconfig.h
+6 −8 src/libs/katevi/src/keyparser.cpp
+12 −11 src/libs/katevi/src/lastchangerecorder.cpp
+3 −2 src/libs/katevi/src/lastchangerecorder.h
+1 −1 src/libs/katevi/src/macrorecorder.cpp
+2 −1 src/libs/katevi/src/macrorecorder.h
+14 −6 src/libs/katevi/src/macros.cpp
+15 −1 src/libs/katevi/src/macros.h
+3 −1 src/libs/katevi/src/modes/insertvimode.cpp
+1 −1 src/libs/katevi/src/modes/modebase.cpp
+2 −0 src/libs/katevi/src/modes/modebase.h
+20 −20 src/libs/katevi/src/modes/normalvimode.cpp
+3 −3 src/libs/katevi/src/modes/normalvimode.h
+1 −1 src/libs/sonnet
+1 −1 src/libs/syntax-highlighting
+1 −1 tests/test_textfolding/test_textfolding.h
+1 −1 tests/test_utils/test_utils.pro
+1 −1 tests/utils/utils.cpp
4 changes: 2 additions & 2 deletions src/core/notebook/notebookdatabaseaccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
47 changes: 25 additions & 22 deletions src/export/webviewexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QFileInfo>
#include <QTemporaryDir>
#include <QProcess>
#include <QRegularExpression>

#include <widgets/editors/markdownviewer.h>
#include <widgets/editors/markdownvieweradapter.h>
Expand All @@ -19,7 +20,6 @@
#include <utils/processutils.h>
#include <utils/htmlutils.h>
#include <core/file.h>
#include <QRegExp>

using namespace vnotex;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ using namespace vnotex;

void loadTranslators(QApplication &p_app);


void showMessageOnCommandLineIfAvailable(const QString &p_msg);

int main(int argc, char *argv[])
Expand Down Expand Up @@ -78,7 +77,6 @@ int main(int argc, char *argv[])

Application app(argc, argv);


QAccessible::installFactory(&FakeAccessible::accessibleFactory);

{
Expand Down
11 changes: 6 additions & 5 deletions src/utils/iconutils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "iconutils.h"

#include <QRegExp>
#include <QRegularExpression>
#include <QFileInfo>
#include <QPixmap>
#include <QPainter>
Expand Down Expand Up @@ -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]);
Expand All @@ -105,7 +106,7 @@ bool IconUtils::isMonochrome(const QString &p_iconContent)
}
}

pos += monoRe.matchedLength();
pos += match.capturedLength();
}

return true;
Expand Down
10 changes: 6 additions & 4 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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);
}
Expand All @@ -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()) {
Expand Down
28 changes: 15 additions & 13 deletions src/widgets/editors/markdowneditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include <imagehost/imagehostutils.h>
#include <imagehost/imagehost.h>
#include <imagehost/imagehostmgr.h>
#include <QRegExp>

#include "previewhelper.h"
#include "../outlineprovider.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -572,7 +572,7 @@ bool MarkdownEditor::processHtmlFromMimeData(const QMimeData *p_source)
}
}

insertImageFromUrl(reg.cap(2));
insertImageFromUrl(match.captured(2));
return true;
}

Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
Expand All @@ -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('+'), " ");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/editors/markdownviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 9 additions & 18 deletions src/widgets/markdownviewwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <QActionGroup>
#include <QTimer>
#include <QPrinter>
#include <QWebEngineSettings>
#include <QWebEngineSettings>

#include <core/fileopenparameters.h>
#include <core/editorconfig.h>
Expand Down Expand Up @@ -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);

}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 2f6afb2

Please sign in to comment.