diff --git a/src/core/iconfig.h b/src/core/iconfig.h index d10701fa0c..d7dad076e4 100644 --- a/src/core/iconfig.h +++ b/src/core/iconfig.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace vnotex { diff --git a/src/core/notebook/node.cpp b/src/core/notebook/node.cpp index 9f8686e821..06de7f1ab4 100644 --- a/src/core/notebook/node.cpp +++ b/src/core/notebook/node.cpp @@ -8,6 +8,7 @@ #include #include "notebook.h" #include "nodeparameters.h" +#include using namespace vnotex; @@ -483,7 +484,7 @@ QList> Node::collectFiles() ID Node::generateSignature() { - return static_cast(QDateTime::currentDateTime().toSecsSinceEpoch() + (static_cast(qrand()) << 32)); + return static_cast(QDateTime::currentDateTime().toSecsSinceEpoch() + (static_cast(QRandomGenerator::global()->generate()) << 32)); } void Node::checkSignature() diff --git a/src/core/notebook/notebookdatabaseaccess.cpp b/src/core/notebook/notebookdatabaseaccess.cpp index a6bac152d5..610bb066f1 100644 --- a/src/core/notebook/notebookdatabaseaccess.cpp +++ b/src/core/notebook/notebookdatabaseaccess.cpp @@ -560,7 +560,12 @@ bool NotebookDatabaseAccess::updateNodeTags(Node *p_node) const auto &nodeTags = p_node->getTags(); { - const auto tags = QSet::fromList(queryNodeTags(p_node->getId())); + QStringList list = queryNodeTags(p_node->getId()); + QSet tags; + for (auto &s : list) + { + tags.insert(s); + } if (tags.isEmpty() && nodeTags.isEmpty()) { return true; } @@ -691,7 +696,7 @@ QList NotebookDatabaseAccess::queryTagNodesRecursive(const QString &p_tag) } } - return allIds.toList(); + return allIds.values(); } QStringList NotebookDatabaseAccess::queryTagAndChildren(const QString &p_tag) @@ -742,7 +747,7 @@ QStringList NotebookDatabaseAccess::getNodesOfTags(const QStringList &p_tags) allIds.insert(id); } } - nodeIds = allIds.toList(); + nodeIds = allIds.values(); } for (const auto &id : nodeIds) { diff --git a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp index ac1f86da61..f42db84d73 100644 --- a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp +++ b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp @@ -461,7 +461,7 @@ void VXNotebookConfigMgr::addChildNode(Node *p_parent, const QSharedPointer VXNotebookConfigMgr::loadNodeByPath(const QSharedPointer &p_root, const QString &p_relativePath) { auto p = PathUtils::cleanPath(p_relativePath); - auto paths = p.split('/', QString::SkipEmptyParts); + auto paths = p.split('/', Qt::SkipEmptyParts); auto node = p_root; for (auto &pa : paths) { // Find child @pa in @node. diff --git a/src/export/webviewexporter.cpp b/src/export/webviewexporter.cpp index 486f2bc229..69291a3ee8 100644 --- a/src/export/webviewexporter.cpp +++ b/src/export/webviewexporter.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace vnotex; @@ -362,7 +363,7 @@ bool WebViewExporter::embedStyleResources(QString &p_html) const int pos = 0; while (pos < p_html.size()) { - int idx = p_html.indexOf(reg, pos); + int idx = reg.indexIn(p_html, pos); if (idx == -1) { break; } @@ -393,7 +394,7 @@ bool WebViewExporter::embedBodyResources(const QUrl &p_baseUrl, QString &p_html) int pos = 0; while (pos < p_html.size()) { - int idx = p_html.indexOf(reg, pos); + int idx = reg.indexIn(p_html, pos); if (idx == -1) { break; } @@ -440,7 +441,7 @@ bool WebViewExporter::fixBodyResources(const QUrl &p_baseUrl, int pos = 0; while (pos < p_html.size()) { - int idx = p_html.indexOf(reg, pos); + int idx = reg.indexIn(p_html, pos); if (idx == -1) { break; } diff --git a/src/main.cpp b/src/main.cpp index a28607cf96..4363903455 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,6 @@ using namespace vnotex; void loadTranslators(QApplication &p_app); -void initWebEngineSettings(); void showMessageOnCommandLineIfAvailable(const QString &p_msg); @@ -79,7 +78,6 @@ int main(int argc, char *argv[]) Application app(argc, argv); - initWebEngineSettings(); QAccessible::installFactory(&FakeAccessible::accessibleFactory); @@ -253,12 +251,6 @@ void loadTranslators(QApplication &p_app) } } -void initWebEngineSettings() -{ - auto settings = QWebEngineSettings::defaultSettings(); - settings->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true); -} - void showMessageOnCommandLineIfAvailable(const QString &p_msg) { #if defined(Q_OS_WIN) diff --git a/src/src.pro b/src/src.pro index 14595123cf..e3e1dd1f9c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -2,7 +2,7 @@ lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5 and above") equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 12): error("requires Qt 5.12 and above") -QT += core gui widgets webenginewidgets webchannel network svg printsupport +QT += core gui widgets webenginewidgets webchannel network svg printsupport core5compat QT += sql CONFIG -= qtquickcompiler diff --git a/src/unitedentry/iunitedentry.cpp b/src/unitedentry/iunitedentry.cpp index b97e6ef335..7abbad8131 100644 --- a/src/unitedentry/iunitedentry.cpp +++ b/src/unitedentry/iunitedentry.cpp @@ -41,19 +41,19 @@ void IUnitedEntry::process(const QString &p_args, initOnFirstProcess(); } - m_askedToStop.store(0); + m_askedToStop.storeRelaxed(0); return processInternal(p_args, p_popupWidgetFunc); } void IUnitedEntry::stop() { - m_askedToStop.store(1); + m_askedToStop.storeRelaxed(1); } bool IUnitedEntry::isAskedToStop() const { - return m_askedToStop.load() == 1; + return m_askedToStop.loadAcquire() == 1; } void IUnitedEntry::setOngoing(bool p_ongoing) diff --git a/src/utils/asyncworker.cpp b/src/utils/asyncworker.cpp index b4b59c6de7..7fc550746a 100644 --- a/src/utils/asyncworker.cpp +++ b/src/utils/asyncworker.cpp @@ -9,12 +9,12 @@ AsyncWorker::AsyncWorker(QObject *p_parent) void AsyncWorker::stop() { - m_askedToStop.store(1); + m_askedToStop.fetchAndStoreAcquire(1); } bool AsyncWorker::isAskedToStop() const { - return m_askedToStop.load() == 1; + return m_askedToStop.loadAcquire() == 1; } diff --git a/src/utils/fileutils.cpp b/src/utils/fileutils.cpp index cf62d38551..435bf30277 100644 --- a/src/utils/fileutils.cpp +++ b/src/utils/fileutils.cpp @@ -10,6 +10,7 @@ #include #include "pathutils.h" +#include using namespace vnotex; @@ -313,7 +314,7 @@ QString FileUtils::generateRandomFileName(const QString &p_hints, const QString // Do not use toSecsSinceEpoch() here since we want a short name. const QString timeStamp(QDateTime::currentDateTime().toString(QStringLiteral("sszzzmmHHyyMMdd"))); - const QString baseName(QString::number(timeStamp.toLongLong() + qrand())); + const QString baseName(QString::number(timeStamp.toLongLong() + QRandomGenerator::global()->generate())); QString suffix; if (!p_suffix.isEmpty()) { diff --git a/src/utils/htmlutils.cpp b/src/utils/htmlutils.cpp index f1c439b8d1..935512c4df 100644 --- a/src/utils/htmlutils.cpp +++ b/src/utils/htmlutils.cpp @@ -1,13 +1,13 @@ #include "htmlutils.h" -#include +#include using namespace vnotex; bool HtmlUtils::hasOnlyImgTag(const QString &p_html) { // Tricky. - QRegExp reg(QStringLiteral("<(?:p|span|div) ")); + QRegularExpression reg(QStringLiteral("<(?:p|span|div) ")); return !p_html.contains(reg); } diff --git a/src/utils/iconutils.cpp b/src/utils/iconutils.cpp index 90627de5bd..80ea617332 100644 --- a/src/utils/iconutils.cpp +++ b/src/utils/iconutils.cpp @@ -67,7 +67,7 @@ QString IconUtils::replaceForegroundOfIcon(const QString &p_iconContent, const Q } // Negative lookahead to avoid fill="none". - QRegExp styleRe(R"((\s|"|;)(fill|stroke)(:|(="))(?!none)[^;"]*)"); + QRegularExpression styleRe(R"((\s|"|;)(fill|stroke)(:|(="))(?!none)[^;"]*)"); if (p_iconContent.indexOf(styleRe) > -1) { auto newContent(p_iconContent); newContent.replace(styleRe, QString("\\1\\2\\3%1").arg(p_foreground)); @@ -85,7 +85,7 @@ bool IconUtils::isMonochrome(const QString &p_iconContent) QString lastColor = ""; int pos = 0; while (pos < p_iconContent.size()) { - int idx = p_iconContent.indexOf(monoRe, pos); + int idx = monoRe.indexIn(p_iconContent, pos); if (idx == -1) { break; } diff --git a/src/utils/printutils.cpp b/src/utils/printutils.cpp index 72e48a13c7..0a1e9813e1 100644 --- a/src/utils/printutils.cpp +++ b/src/utils/printutils.cpp @@ -11,7 +11,7 @@ QSharedPointer PrintUtils::promptForPrint(bool p_printSelectionEnabled QPrintDialog dialog(printer.data(), p_parent); if (p_printSelectionEnabled) { - dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection); + dialog.setOption(QAbstractPrintDialog::PrintSelection); } if (dialog.exec() == QDialog::Accepted) { diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index e2c9155312..076722a0dc 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -42,7 +42,7 @@ void Utils::appendMsg(QString &p_msg, const QString &p_new) QString Utils::dateTimeString(const QDateTime &p_dateTime) { - return p_dateTime.date().toString(Qt::DefaultLocaleLongDate) + return p_dateTime.date().toString(Qt::ISODate) + " " + p_dateTime.time().toString(Qt::TextDate); } diff --git a/src/utils/utils.pri b/src/utils/utils.pri index a072a928df..b53ebf30f9 100644 --- a/src/utils/utils.pri +++ b/src/utils/utils.pri @@ -1,4 +1,4 @@ -QT += widgets svg +QT += widgets svg core5compat SOURCES += \ $$PWD/asyncworker.cpp \ diff --git a/src/utils/webutils.cpp b/src/utils/webutils.cpp index 7069936b8b..46b1822156 100644 --- a/src/utils/webutils.cpp +++ b/src/utils/webutils.cpp @@ -58,7 +58,8 @@ QString WebUtils::toDataUri(const QUrl &p_url, bool p_keepTitle) if (!p_keepTitle) { // Remove .... - QRegExp reg(".*", Qt::CaseInsensitive); + QRegularExpression reg(".*"); + reg.setPatternOptions(QRegularExpression::CaseInsensitiveOption); uri.remove(reg); } } else { diff --git a/src/utils/widgetutils.cpp b/src/utils/widgetutils.cpp index e9af368065..b9974b1e8b 100644 --- a/src/utils/widgetutils.cpp +++ b/src/utils/widgetutils.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -71,8 +70,7 @@ bool WidgetUtils::isScrollBarVisible(QAbstractScrollArea *p_widget, bool p_horiz QSize WidgetUtils::availableScreenSize(QWidget *p_widget) { - auto geo = QApplication::desktop()->availableGeometry(p_widget); - return geo.size(); + return p_widget->screen()->availableGeometry().size(); } void WidgetUtils::openUrlByDesktop(const QUrl &p_url) @@ -374,7 +372,7 @@ QString WidgetUtils::getMonospaceFont() for (const auto &candidate : candidates) { QString family = candidate.trimmed().toLower(); for (auto availFamily : availFamilies) { - availFamily.remove(QRegExp("\\[.*\\]")); + availFamily.remove(QRegularExpression("\\[.*\\]")); if (family == availFamily.trimmed().toLower()) { font = availFamily; return font; diff --git a/src/widgets/dialogs/dialog.cpp b/src/widgets/dialogs/dialog.cpp index a28524f33a..6c8cc1146f 100644 --- a/src/widgets/dialogs/dialog.cpp +++ b/src/widgets/dialogs/dialog.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/src/widgets/dialogs/imageinsertdialog.cpp b/src/widgets/dialogs/imageinsertdialog.cpp index 95b7e3189a..c75d2f09a5 100644 --- a/src/widgets/dialogs/imageinsertdialog.cpp +++ b/src/widgets/dialogs/imageinsertdialog.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -88,7 +88,7 @@ void ImageInsertDialog::setupUI(const QString &p_title, // Image Title. m_imageTitleEdit = WidgetsFactory::createLineEdit(p_imageTitle, mainWidget); - auto titleValidator = new QRegExpValidator(QRegExp(vte::MarkdownUtils::c_imageTitleRegExp), m_imageTitleEdit); + auto titleValidator = new QRegularExpressionValidator(QRegularExpression(vte::MarkdownUtils::c_imageTitleRegExp), m_imageTitleEdit); m_imageTitleEdit->setValidator(titleValidator); gridLayout->addWidget(new QLabel(tr("Title:"), mainWidget), 1, 0, 1, 1); gridLayout->addWidget(m_imageTitleEdit, 1, 1, 1, 3); @@ -97,7 +97,7 @@ void ImageInsertDialog::setupUI(const QString &p_title, // Image Alt. m_imageAltEdit = WidgetsFactory::createLineEdit(p_imageAlt, mainWidget); - auto altValidator = new QRegExpValidator(QRegExp(vte::MarkdownUtils::c_imageAltRegExp), m_imageAltEdit); + auto altValidator = new QRegularExpressionValidator(QRegularExpression(vte::MarkdownUtils::c_imageAltRegExp), m_imageAltEdit); m_imageAltEdit->setValidator(altValidator); gridLayout->addWidget(new QLabel(tr("Alt text:"), mainWidget), 2, 0, 1, 1); gridLayout->addWidget(m_imageAltEdit, 2, 1, 1, 3); diff --git a/src/widgets/dialogs/scrolldialog.cpp b/src/widgets/dialogs/scrolldialog.cpp index f4921fd497..d668871960 100644 --- a/src/widgets/dialogs/scrolldialog.cpp +++ b/src/widgets/dialogs/scrolldialog.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/src/widgets/dialogs/selectdialog.cpp b/src/widgets/dialogs/selectdialog.cpp index c1846ca2a9..62d5f88c62 100644 --- a/src/widgets/dialogs/selectdialog.cpp +++ b/src/widgets/dialogs/selectdialog.cpp @@ -73,7 +73,7 @@ void SelectDialog::addSelection(const QString &p_selectStr, int p_selectID) QChar shortcut; if (m_nextShortcut < c_cancelShortcut) { shortcut = m_nextShortcut; - m_nextShortcut = m_nextShortcut.toLatin1() + 1; + m_nextShortcut = QChar(m_nextShortcut.toLatin1() + 1); } const auto icon = IconUtils::drawTextIcon(shortcut, m_shortcutIconForeground, m_shortcutIconBorder); QListWidgetItem *item = new QListWidgetItem(icon, p_selectStr); diff --git a/src/widgets/dialogs/settings/fileassociationpage.cpp b/src/widgets/dialogs/settings/fileassociationpage.cpp index a19e7e899d..0ea114b016 100644 --- a/src/widgets/dialogs/settings/fileassociationpage.cpp +++ b/src/widgets/dialogs/settings/fileassociationpage.cpp @@ -62,7 +62,7 @@ bool FileAssociationPage::saveInternal() if (name.isEmpty()) { continue; } - auto suffixes = lineEdit->text().split(c_suffixSeparator, QString::SkipEmptyParts); + auto suffixes = lineEdit->text().split(c_suffixSeparator, Qt::SkipEmptyParts); fileTypeSuffixes.push_back(CoreConfig::FileTypeSuffix(name, Utils::toLower(suffixes))); } diff --git a/src/widgets/dialogs/sortdialog.cpp b/src/widgets/dialogs/sortdialog.cpp index 3deac97706..2836021841 100644 --- a/src/widgets/dialogs/sortdialog.cpp +++ b/src/widgets/dialogs/sortdialog.cpp @@ -110,7 +110,7 @@ void SortDialog::updateTreeWidget() item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled); } - m_treeWidget->sortByColumn(-1); + m_treeWidget->sortByColumn(-1, Qt::AscendingOrder); m_treeWidget->setSortingEnabled(true); } @@ -151,7 +151,7 @@ void SortDialog::handleMoveOperation(MoveOperation p_op) Q_ASSERT(first <= last && (last - first + 1) == selectedItems.size()); QTreeWidgetItem *firstItem = nullptr; - m_treeWidget->sortByColumn(-1); + m_treeWidget->sortByColumn(-1, Qt::AscendingOrder); switch (p_op) { case MoveOperation::Top: diff --git a/src/widgets/dialogs/tableinsertdialog.cpp b/src/widgets/dialogs/tableinsertdialog.cpp index 92ac28dfbc..fc653fd9db 100644 --- a/src/widgets/dialogs/tableinsertdialog.cpp +++ b/src/widgets/dialogs/tableinsertdialog.cpp @@ -63,7 +63,9 @@ void TableInsertDialog::setupUI(const QString &p_title) buttonGroup->addButton(rightBtn, static_cast(Alignment::Right)); noneBtn->setChecked(true); - connect(buttonGroup, static_cast(&QButtonGroup::buttonToggled), + connect(buttonGroup, (void(QButtonGroup::*)(int, bool))(&QButtonGroup::buttonToggled), + + this, [this](int p_id, bool p_checked){ if (p_checked) { m_alignment = static_cast(p_id); diff --git a/src/widgets/editors/markdowneditor.cpp b/src/widgets/editors/markdowneditor.cpp index 0a39593cd0..11d938152c 100644 --- a/src/widgets/editors/markdowneditor.cpp +++ b/src/widgets/editors/markdowneditor.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include "previewhelper.h" #include "../outlineprovider.h" @@ -1198,7 +1199,7 @@ void MarkdownEditor::handleHtmlToMarkdownData(quint64 p_id, TimeStamp p_timeStam static QString purifyImageTitle(QString p_title) { - return p_title.remove(QRegExp("[\\r\\n\\[\\]]")); + return p_title.remove(QRegularExpression("[\\r\\n\\[\\]]")); } void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text) diff --git a/src/widgets/editors/markdowntable.cpp b/src/widgets/editors/markdowntable.cpp index c789b750b9..93c9b05127 100644 --- a/src/widgets/editors/markdowntable.cpp +++ b/src/widgets/editors/markdowntable.cpp @@ -214,10 +214,10 @@ void MarkdownTable::initWidths(const QTextBlock &p_block, int p_borderPos) } QFontMetricsF fmf(font); - s_spaceWidth = fmf.width(' '); - s_minusWidth = fmf.width('-'); - s_colonWidth = fmf.width(':'); - s_defaultDelimiterWidth = fmf.width(c_defaultDelimiter); + s_spaceWidth = fmf.horizontalAdvance(' '); + s_minusWidth = fmf.horizontalAdvance('-'); + s_colonWidth = fmf.horizontalAdvance(':'); + s_defaultDelimiterWidth = fmf.horizontalAdvance(c_defaultDelimiter); qDebug() << "smart table widths" << font.family() << s_spaceWidth << s_minusWidth << s_colonWidth << s_defaultDelimiterWidth; } diff --git a/src/widgets/editors/markdownviewer.cpp b/src/widgets/editors/markdownviewer.cpp index 2a5412d3f4..a75a9a6827 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(page()->createStandardContextMenu()); + QScopedPointer menu(this->createStandardContextMenu()); const QList actions = menu->actions(); #if defined(Q_OS_WIN) diff --git a/src/widgets/editors/previewhelper.cpp b/src/widgets/editors/previewhelper.cpp index dc061d88e5..1447a48bce 100644 --- a/src/widgets/editors/previewhelper.cpp +++ b/src/widgets/editors/previewhelper.cpp @@ -338,7 +338,7 @@ void PreviewHelper::updateEditorInplacePreviewCodeBlock() m_previousInplacePreviewCodeBlockSize = previewItems.size(); if (!obsoleteBlocks.isEmpty()) { - emit potentialObsoletePreviewBlocksUpdated(obsoleteBlocks.toList()); + emit potentialObsoletePreviewBlocksUpdated(obsoleteBlocks.values()); } m_codeBlockCache.setCapacityHint(m_codeBlocksData.size()); @@ -434,7 +434,7 @@ void PreviewHelper::updateEditorInplacePreviewMathBlock() m_previousInplacePreviewMathBlockSize = previewItems.size(); if (!obsoleteBlocks.isEmpty()) { - emit potentialObsoletePreviewBlocksUpdated(obsoleteBlocks.toList()); + emit potentialObsoletePreviewBlocksUpdated(obsoleteBlocks.values()); } m_mathBlockCache.setCapacityHint(m_mathBlocksData.size()); diff --git a/src/widgets/fullscreentoggleaction.cpp b/src/widgets/fullscreentoggleaction.cpp index 7ab356fa88..b84bcf6b45 100644 --- a/src/widgets/fullscreentoggleaction.cpp +++ b/src/widgets/fullscreentoggleaction.cpp @@ -1,6 +1,7 @@ #include "fullscreentoggleaction.h" #include +#include using namespace vnotex; diff --git a/src/widgets/labelwithbuttonswidget.cpp b/src/widgets/labelwithbuttonswidget.cpp index 8f23eff8e1..918763d0aa 100644 --- a/src/widgets/labelwithbuttonswidget.cpp +++ b/src/widgets/labelwithbuttonswidget.cpp @@ -45,7 +45,7 @@ void LabelWithButtonsWidget::paintEvent(QPaintEvent *p_event) Q_UNUSED(p_event); QStyleOption opt; - opt.init(this); + opt.initFrom(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } diff --git a/src/widgets/markdownviewwindow.cpp b/src/widgets/markdownviewwindow.cpp index 584af6db2d..3242bdcde9 100644 --- a/src/widgets/markdownviewwindow.cpp +++ b/src/widgets/markdownviewwindow.cpp @@ -13,6 +13,7 @@ #include #include #include + #include #include #include @@ -394,6 +395,8 @@ void MarkdownViewWindow::setupTextEditor() connect(m_editor, &MarkdownEditor::applySnippetRequested, this, QOverload<>::of(&MarkdownViewWindow::applySnippet)); + connect(m_viewer, &MarkdownViewer::printFinished, this, &MarkdownViewWindow::onPrintFinish); + } QStackedWidget *MarkdownViewWindow::getMainStatusWidget() const @@ -502,6 +505,7 @@ void MarkdownViewWindow::setupViewer() setEditViewMode(m_editViewMode); } }); + m_viewer->settings()->resetAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls); } void MarkdownViewWindow::syncTextEditorFromBuffer(bool p_syncPositionFromReadMode) @@ -1398,15 +1402,31 @@ void MarkdownViewWindow::print() return; } - auto printer = PrintUtils::promptForPrint(m_viewer->hasSelection(), this); - if (printer) { - m_viewer->page()->print(printer.data(), [printer](bool p_succeeded) mutable { - Q_UNUSED(p_succeeded); - printer.reset(); - }); + 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) +{ + 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); +} 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 eecbbe72ce..11d72db9d9 100644 --- a/src/widgets/markdownviewwindow.h +++ b/src/widgets/markdownviewwindow.h @@ -12,7 +12,7 @@ class QStackedWidget; class QWebEngineView; class QActionGroup; class QTimer; - +class QPrinter; namespace vte { class MarkdownEditorConfig; @@ -61,6 +61,7 @@ namespace vnotex public slots: void handleEditorConfigChange() Q_DECL_OVERRIDE; + void onPrintFinish(bool isSeccess); protected slots: void setModified(bool p_modified) Q_DECL_OVERRIDE; @@ -237,6 +238,7 @@ namespace vnotex MarkdownEditorConfig::EditViewMode m_editViewMode = MarkdownEditorConfig::EditViewMode::EditOnly; QTimer *m_syncPreviewTimer = nullptr; + QSharedPointer m_printer; }; } diff --git a/src/widgets/navigationmode.cpp b/src/widgets/navigationmode.cpp index 4fdc13aafa..353561e59c 100644 --- a/src/widgets/navigationmode.cpp +++ b/src/widgets/navigationmode.cpp @@ -74,7 +74,7 @@ static QString generateNavigationLabelStyle(const QString &p_str, bool p_tiny) QFont font(fontFamily, fontPt); font.setBold(true); QFontMetrics fm(font); - pxWidth = fm.width(p_str) + 5; + pxWidth = fm.horizontalAdvance(p_str) + 5; pxHeight = fm.capHeight() + 5; lastLen = p_str.size(); } diff --git a/src/widgets/notebookexplorersession.cpp b/src/widgets/notebookexplorersession.cpp index 7c1cf16f5f..546c35048c 100644 --- a/src/widgets/notebookexplorersession.cpp +++ b/src/widgets/notebookexplorersession.cpp @@ -1,4 +1,5 @@ #include "notebookexplorersession.h" +#include using namespace vnotex; diff --git a/src/widgets/outlineprovider.h b/src/widgets/outlineprovider.h index 7719b54e4f..39dae2424d 100644 --- a/src/widgets/outlineprovider.h +++ b/src/widgets/outlineprovider.h @@ -4,7 +4,7 @@ #include #include #include - +#include namespace vnotex { typedef QVector SectionNumber; diff --git a/src/widgets/quickselector.cpp b/src/widgets/quickselector.cpp index 0ac4657dfe..785e9c3680 100644 --- a/src/widgets/quickselector.cpp +++ b/src/widgets/quickselector.cpp @@ -194,7 +194,7 @@ void QuickSelector::searchAndFilter(const QString &p_text) } // Check name. - auto parts = text.split(QLatin1Char(' '), QString::SkipEmptyParts); + auto parts = text.split(QLatin1Char(' '), Qt::SkipEmptyParts); Q_ASSERT(!parts.isEmpty()); QRegularExpression regExp; regExp.setPatternOptions(regExp.patternOptions() | QRegularExpression::CaseInsensitiveOption); diff --git a/src/widgets/titlebar.cpp b/src/widgets/titlebar.cpp index 5077624e42..124e7ff0c5 100644 --- a/src/widgets/titlebar.cpp +++ b/src/widgets/titlebar.cpp @@ -99,9 +99,9 @@ void TitleBar::setupActionButtons(TitleBar::Actions p_actionFlags) } } -void TitleBar::enterEvent(QEvent *p_event) +void TitleBar::enterEvent(QEnterEvent *p_event) { - QWidget::enterEvent(p_event); + QFrame::enterEvent(p_event); setActionButtonsVisible(true); } diff --git a/src/widgets/titlebar.h b/src/widgets/titlebar.h index 6dc71fb6be..258f6baf0a 100644 --- a/src/widgets/titlebar.h +++ b/src/widgets/titlebar.h @@ -53,7 +53,7 @@ namespace vnotex void setActionButtonsAlwaysShown(bool p_shown); protected: - void enterEvent(QEvent *p_event) Q_DECL_OVERRIDE; + void enterEvent(QEnterEvent *p_event) Q_DECL_OVERRIDE; void leaveEvent(QEvent *p_event) Q_DECL_OVERRIDE; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 9ad4e14011..9945e54dda 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -13,6 +13,7 @@ #include #include "thememgr.h" #include "vnotex.h" +#include using namespace vnotex; diff --git a/src/widgets/viewsplit.cpp b/src/widgets/viewsplit.cpp index d400e7140a..3fc0528f8b 100644 --- a/src/widgets/viewsplit.cpp +++ b/src/widgets/viewsplit.cpp @@ -25,6 +25,7 @@ #include #include "propertydefs.h" #include "fileopenparameters.h" +#include using namespace vnotex;