diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6513c6d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.vscode/ +/build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e5fefc..ba094de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,10 @@ endif() set(KTIKZ_VERSION "0.13.2") set(KTIKZ_USE_KTEXTEDITOR TRUE CACHE BOOL "Use KTextEditor framework") +set(QT_MIN_VERSION "6.5.0") +set(KF6_DEP_VERSION "6.0.0") +set(QT_MAJOR_VERSION "6") + add_definitions(-DORGNAME=\"Florian_Hackenberger\") add_definitions(-DAPPNAME=\"ktikz\") add_definitions(-DAPPVERSION=\"${KTIKZ_VERSION}\") @@ -32,16 +36,15 @@ include(KDECMakeSettings) include(FeatureSummary) find_package( - Qt5 - 5.15 - CONFIG - REQUIRED Core Gui Widgets Xml PrintSupport LinguistTools + Qt6 + REQUIRED + COMPONENTS Core Gui Widgets Xml PrintSupport LinguistTools Core5Compat ) find_package( - KF5 - 5.92 - REQUIRED DocTools XmlGui TextEditor Parts IconThemes + KF6 + REQUIRED + COMPONENTS DocTools XmlGui TextEditor Parts IconThemes KIO WidgetsAddons I18n ) if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -58,9 +61,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() endif() -find_package(Poppler "22.02" REQUIRED Qt5 Core) +find_package(Poppler "24.06" REQUIRED Qt6 Core) set_package_properties( - "Poppler-Qt5" + "Poppler-Qt6" PROPERTIES DESCRIPTION "A PDF rendering library" URL "http://poppler.freedesktop.org" diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f72ebee..6027b8f 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -75,8 +75,8 @@ ki18n_wrap_ui(ktikz_UI_FILES ../common/templatewidget.ui ) kconfig_add_kcfg_files(ktikz_SRCS ../common/settings.kcfgc) -qt5_add_resources(ktikz_SRCS ktikz.qrc) -qt5_add_resources(ktikz_SRCS qtikz.qrc) +qt_add_resources(ktikz_SRCS ktikz.qrc) +qt_add_resources(ktikz_SRCS qtikz.qrc) file(GLOB icons_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/icons/*-apps-ktikz.png") # add icons for win32 and mac; this command assumes that the first arg is of the @@ -86,23 +86,28 @@ ecm_add_app_icon(ktikz_SRCS ICONS ${icons_SRCS}) add_executable(ktikz ${ktikz_SRCS} ${ktikz_UI_FILES}) target_link_libraries( ktikz - KF5::XmlGui - KF5::TextEditor - KF5::IconThemes - Qt5::PrintSupport - Poppler::Qt5 + KF6::XmlGui + KF6::TextEditor + KF6::IconThemes + KF6::KIOWidgets + KF6::KIOFileWidgets + KF6::WidgetsAddons + KF6::I18n + Qt6::Core5Compat # QTextCodec + Qt6::PrintSupport + Poppler::Qt6 ) if(KTIKZ_USE_KTEXTEDITOR) - target_link_libraries(ktikz KF5::TextEditor) + target_link_libraries(ktikz KF6::TextEditor) endif() install(TARGETS ktikz DESTINATION ${KDE_INSTALL_BINDIR}) if(KTIKZ_USE_KTEXTEDITOR) - install(FILES ktikzui_frameworks.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/ktikz) + install(FILES kxmlgui5/ktikz/ktikzui_frameworks.rc DESTINATION ${KDE_INSTALL_KXMLGUIDIR}/ktikz) endif() -install(FILES ktikzui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/ktikz) +install(FILES kxmlgui5/ktikz/ktikzui.rc DESTINATION ${KDE_INSTALL_KXMLGUIDIR}/ktikz) install(FILES ../common/ktikz.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) add_subdirectory(icons) @@ -114,8 +119,8 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E remove_directory ${KTIKZ_TRANSLATIONS_INSTALL_DIR} COMMAND ${CMAKE_COMMAND} -E remove_directory ${KTIKZ_TEMPLATES_INSTALL_DIR} COMMAND ${CMAKE_COMMAND} -E remove_directory ${KTIKZ_DATA_INSTALL_DIR} - COMMAND ${CMAKE_COMMAND} -E remove_directory ${KXMLGUI_INSTALL_DIR}/ktikz + COMMAND ${CMAKE_COMMAND} -E remove_directory ${KDE_INSTALL_KXMLGUIDIR}/ktikz COMMENT - "Removing directories ${KTIKZ_TRANSLATIONS_INSTALL_DIR} ${KTIKZ_TEMPLATES_INSTALL_DIR} ${KTIKZ_DATA_INSTALL_DIR} ${KXMLGUI_INSTALL_DIR}/ktikz" + "Removing directories ${KTIKZ_TRANSLATIONS_INSTALL_DIR} ${KTIKZ_TEMPLATES_INSTALL_DIR} ${KTIKZ_DATA_INSTALL_DIR} ${KDE_INSTALL_KXMLGUIDIR}/ktikz" VERBATIM ) diff --git a/app/configeditorwidget.cpp b/app/configeditorwidget.cpp index db88b22..a8a75c4 100644 --- a/app/configeditorwidget.cpp +++ b/app/configeditorwidget.cpp @@ -22,7 +22,7 @@ #include "configeditorwidget.h" #include -#include +#include #include #include "../common/utils/fontdialog.h" diff --git a/app/editreplacecurrentwidget.cpp b/app/editreplacecurrentwidget.cpp index 3786514..ab76d7d 100644 --- a/app/editreplacecurrentwidget.cpp +++ b/app/editreplacecurrentwidget.cpp @@ -43,7 +43,7 @@ ReplaceCurrentWidget::ReplaceCurrentWidget(QWidget *parent) : QWidget(parent) buttonsLayout->addWidget(dontReplaceButton); buttonsLayout->addWidget(cancelButton); buttonsLayout->addStretch(); - buttonsLayout->setMargin(0); + buttonsLayout->setContentsMargins(0, 0, 0, 0); buttonsWidget->setLayout(buttonsLayout); mainLayout->addWidget(m_replaceLabel); mainLayout->addWidget(buttonsWidget); diff --git a/app/ktikzui.rc b/app/kxmlgui5/ktikz/ktikzui.rc similarity index 100% rename from app/ktikzui.rc rename to app/kxmlgui5/ktikz/ktikzui.rc diff --git a/app/ktikzui_frameworks.rc b/app/kxmlgui5/ktikz/ktikzui_frameworks.rc similarity index 100% rename from app/ktikzui_frameworks.rc rename to app/kxmlgui5/ktikz/ktikzui_frameworks.rc diff --git a/app/loghighlighter.cpp b/app/loghighlighter.cpp index a9b9dc6..203c0f9 100644 --- a/app/loghighlighter.cpp +++ b/app/loghighlighter.cpp @@ -38,7 +38,7 @@ LogHighlighter::LogHighlighter(QTextDocument *parent) : QSyntaxHighlighter(paren // TikzPreviewGenerator::getParsedLogText() << tr("This program will not work!"); for (const auto &pattern : keywordPatterns) { - rule.pattern = QRegExp(pattern); + rule.pattern = QRegularExpression(pattern); rule.format = keywordFormat; m_highlightingRules.append(rule); } @@ -46,7 +46,7 @@ LogHighlighter::LogHighlighter(QTextDocument *parent) : QSyntaxHighlighter(paren QTextCharFormat commandFormat; commandFormat.setForeground(Qt::darkBlue); commandFormat.setFontWeight(QFont::Bold); - rule.pattern = QRegExp(QLatin1String("^\\[[^\\]\\d][^\\]]*\\]")); + rule.pattern = QRegularExpression("^\\[[^\\]\\d][^\\]]*\\]"); rule.format = commandFormat; m_highlightingRules.append(rule); @@ -61,15 +61,12 @@ void LogHighlighter::highlightBlock(const QString &text) { // Try each highlighting pattern and apply formatting if it matches for (const auto &rule : m_highlightingRules) { - // const QRegExp expression(rule.pattern); - // int index = text.indexOf(expression); - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); - while (index >= 0) { - const int length = expression.matchedLength(); + auto m = rule.pattern.match(text); + while (m.hasMatch()) { + int index = m.capturedStart(); + const int length = m.capturedLength(); setFormat(index, length, rule.format); - // index = text.indexOf(expression, index + length); - index = expression.indexIn(text, index + length); + m = rule.pattern.match(text, m.capturedEnd()); } } diff --git a/app/loghighlighter.h b/app/loghighlighter.h index 901767d..f75e731 100644 --- a/app/loghighlighter.h +++ b/app/loghighlighter.h @@ -21,6 +21,7 @@ #ifndef LOGHIGHLIGHTER_H #define LOGHIGHLIGHTER_H +#include #include #include @@ -44,7 +45,7 @@ class LogHighlighter : public QSyntaxHighlighter private: struct LogHighlightingRule { - QRegExp pattern; /// The pattern to match for formatting + QRegularExpression pattern; /// The pattern to match for formatting QTextCharFormat format; /// The style of the formatting }; /// All highlighting rules with their formatting for easy iteration diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index e01f254..97ed0d9 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include @@ -140,7 +140,7 @@ MainWindow::MainWindow() QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); mainLayout->setSpacing(0); - mainLayout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(m_tikzPreviewController->templateWidget()); mainLayout->addWidget(m_tikzEditorView); @@ -1069,7 +1069,7 @@ void MainWindow::loadUrl(const QUrl &url) QApplication::setOverrideCursor(Qt::WaitCursor); this->configureStreamDecoding(in); m_tikzQtEditorView->editor()->setPlainText(in.readAll()); - setCurrentEncoding(in.codec()); + //setCurrentEncoding(in.codec()); } QApplication::restoreOverrideCursor(); @@ -1169,7 +1169,7 @@ void MainWindow::configureStreamEncoding(QTextStream &textStream) { QTextCodec *encoder = this->getEncoder(); if (Q_LIKELY(encoder)) // should be true - textStream.setCodec(encoder); + {}//textStream.setCodec(encoder); else qWarning("The encoder variable should not be null."); @@ -1179,7 +1179,7 @@ void MainWindow::configureStreamEncoding(QTextStream &textStream) void MainWindow::configureStreamDecoding(QTextStream &textStream) { if (m_overrideDecoder) { - textStream.setCodec(m_overrideDecoder); + //textStream.setCodec(m_overrideDecoder); } textStream.setAutoDetectUnicode(true); } diff --git a/app/mainwindow.h b/app/mainwindow.h index 02c7391..43d6ee3 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -35,6 +35,7 @@ class AssistantController; #include #include +#include #include "../common/mainwidget.h" class QAction; diff --git a/app/tikzcommandinserter.cpp b/app/tikzcommandinserter.cpp index 470c743..d08efe3 100644 --- a/app/tikzcommandinserter.cpp +++ b/app/tikzcommandinserter.cpp @@ -46,7 +46,7 @@ #include "tikzcommandwidget.h" #include "../common/utils/combobox.h" -static const QString s_completionPlaceHolder(0x2022); +static const QString s_completionPlaceHolder(QChar(0x2022)); TikzCommandList TikzCommandInserter::m_tikzSections; QList TikzCommandInserter::m_tikzCommandsList; @@ -93,7 +93,7 @@ static QString translateOptions(const QString &text) for (int pos = 0, oldPos = 0; pos >= 0;) { oldPos = pos; pos = text.indexOf(QLatin1Char('<'), pos); // option is between < and > - translatedText += text.midRef( + translatedText += QStringView(text).mid( oldPos, pos - oldPos + 1); // add text between the current option and the previous // option; this also adds the end of the original string, // except when there are no options @@ -326,15 +326,15 @@ QStringList TikzCommandInserter::getCommandWords() { QStringList words; - // QRegExp rx1(QLatin1String("^([^a-z\\\\<>]*<[^>]*>)*")); - // QRegExp rx2(QLatin1String("^[^a-z\\\\]*")); + // QRegularExpression rx1(QLatin1String("^([^a-z\\\\<>]*<[^>]*>)*")); + // QRegularExpression rx2(QLatin1String("^[^a-z\\\\]*")); // QString allowedLetters = QLatin1String("abcdefghijklmnopqrstuvwxyz\\"); for (int i = 0; i < m_tikzCommandsList.size(); ++i) { QString word = m_tikzCommandsList.at(i).description; // remove all special characters and at the beginning of the word /* if (!word.isEmpty() && !allowedLetters.contains(word.at(0))) // minimize the - number of uses of QRegExp + number of uses of QRegularExpression { word.remove(rx1); word.remove(rx2); @@ -346,7 +346,7 @@ QStringList TikzCommandInserter::getCommandWords() word = m_tikzCommandsList.at(i).command; // remove all special characters and at the beginning of the word if (!word.isEmpty() && !allowedLetters.contains(word.at(0))) // minimize the - number of uses of QRegExp + number of uses of QRegularExpression { word.remove(rx1); word.remove(rx2); @@ -574,7 +574,7 @@ QDockWidget *TikzCommandInserter::getDockWidget(QWidget *parent) tikzLayout->addWidget(commandsComboLabel, 0, 0); tikzLayout->addWidget(m_commandsCombo, 0, 1); tikzLayout->addWidget(m_commandsStack, 1, 0, 1, 2); - tikzLayout->setMargin(5); + tikzLayout->setContentsMargins(5, 5, 5, 5); TikzCommandWidget *tikzWidget = new TikzCommandWidget; tikzWidget->setLayout(tikzLayout); @@ -682,7 +682,7 @@ QVector TikzCommandInserter::getHighlightingRules() int end; rule.isRegExp = false; if (!m_tikzCommandsList.at(i).highlightString.isEmpty()) { - rule.pattern = QRegExp(m_tikzCommandsList.at(i).highlightString); + rule.pattern = QRegularExpression(m_tikzCommandsList.at(i).highlightString); rule.isRegExp = true; } switch (type) { @@ -700,7 +700,7 @@ QVector TikzCommandInserter::getHighlightingRules() // command = command.replace(QLatin1Char('\\'), // QLatin1String("\\\\")); rule.type = highlightTypeNames.at(0); - // rule.pattern = QRegExp(command); + // rule.pattern = QRegularExpression(command); // rule.pattern.setPattern(command); rule.matchString = command; highlightingRules.append(rule); @@ -716,7 +716,7 @@ QVector TikzCommandInserter::getHighlightingRules() command = command.remove(QLatin1String(" (:::)")); command = command.remove(QLatin1String(" {} ")); rule.type = highlightTypeNames.at(1); - // rule.pattern = QRegExp(command); + // rule.pattern = QRegularExpression(command); // rule.pattern.setPattern(command); rule.matchString = command; highlightingRules.append(rule); @@ -728,7 +728,7 @@ QVector TikzCommandInserter::getHighlightingRules() if (end > 0) command = command.left(end); rule.type = highlightTypeNames.at(2); - // rule.pattern = QRegExp(command); + // rule.pattern = QRegularExpression(command); // rule.pattern.setPattern(command); rule.matchString = command; highlightingRules.append(rule); @@ -801,7 +801,7 @@ void TikzCommandInserter::insertTag(const QString &tag, int dx, int dy) // replace all options (between <...>) by a place holder QString insertWord = tag; - const QRegExp rx(QLatin1String("<[^<>]*>")); + const QRegularExpression rx(QLatin1String("<[^<>]*>")); insertWord.replace(rx, s_completionPlaceHolder); QTextCursor cur = m_mainEdit->textCursor(); diff --git a/app/tikzeditor.cpp b/app/tikzeditor.cpp index aa7fa8d..ae590a4 100644 --- a/app/tikzeditor.cpp +++ b/app/tikzeditor.cpp @@ -47,10 +47,11 @@ #include #include #include +#include #include "linenumberwidget.h" -static const QString s_completionPlaceHolder(0x2022); +static const QString s_completionPlaceHolder(QChar(0x2022)); TikzEditor::TikzEditor(QWidget *parent) : QPlainTextEdit(parent), @@ -619,8 +620,9 @@ void TikzEditor::insertCompletion(const QString &completion) // remove all options (between <...>) and put cursor at the first option QString insertWord = completion.right(extra); - const QRegExp rx(QLatin1String("<[^<>]*>")); - const int offset = rx.indexIn(insertWord) - 1; // put cursor at the first option + const QRegularExpression rx("<[^<>]*>"); + const auto m = rx.match(insertWord); + const int offset = m.capturedStart() - 1; // put cursor at the first option insertWord.replace(rx, s_completionPlaceHolder); cursor.insertText(insertWord); diff --git a/app/tikzeditorhighlighter.cpp b/app/tikzeditorhighlighter.cpp index 7b1389f..88cca9b 100644 --- a/app/tikzeditorhighlighter.cpp +++ b/app/tikzeditorhighlighter.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include "tikzeditorhighlighter.h" @@ -43,13 +44,13 @@ void TikzHighlighter::setHighlightingRules(const QVector &high << QLatin1String("\\\\end\\{[^\\}]*\\}"); for (const auto &pattern : keywordPatterns) { rule.type = highlightTypeNames.at(currentIndex); - rule.pattern = QRegExp(pattern); + rule.pattern = QRegularExpression(pattern); rule.isRegExp = true; m_highlightingRules.append(rule); } // comments rule.type = highlightTypeNames.at(currentIndex + 1); - rule.pattern = QRegExp(QLatin1String("%[^\n]*")); + rule.pattern = QRegularExpression(QLatin1String("%[^\n]*")); rule.isRegExp = true; m_highlightingRules.append(rule); @@ -174,12 +175,13 @@ void TikzHighlighter::highlightBlock(const QString &text) } } else // match the pattern { - int index = rule.pattern.indexIn(text); - while (index >= 0) { - const int length = rule.pattern.matchedLength(); + auto m = rule.pattern.match(text); + while (m.hasMatch()) { + const int length = m.capturedLength(); + const int index = m.capturedStart(); if (index == 0 || text.at(index - 1) != QLatin1Char('\\')) setFormat(index, length, m_formatList[rule.type]); - index = rule.pattern.indexIn(text, index + length); + m = rule.pattern.match(text, m.capturedEnd()); } } } diff --git a/app/tikzeditorhighlighter.h b/app/tikzeditorhighlighter.h index 6db5ee3..98e129e 100644 --- a/app/tikzeditorhighlighter.h +++ b/app/tikzeditorhighlighter.h @@ -22,12 +22,13 @@ #define TIKZEDITORHIGHLIGHTER_H #include +#include struct HighlightingRule { QString type; /// The name of the formatting type QString matchString; /// The string to match for formatting; only used when pattern is empty - QRegExp pattern; /// The pattern to match for formatting; overrides usage of matchString + QRegularExpression pattern; /// The pattern to match for formatting; overrides usage of matchString bool isRegExp; }; diff --git a/app/tikzeditorview.cpp b/app/tikzeditorview.cpp index ffb79ef..e349edf 100644 --- a/app/tikzeditorview.cpp +++ b/app/tikzeditorview.cpp @@ -59,7 +59,7 @@ TikzEditorView::TikzEditorView(QWidget *parent) QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setSpacing(0); - mainLayout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(m_tikzEditor); createActions(); diff --git a/app/tikzktexteditorview.cpp b/app/tikzktexteditorview.cpp index d42bddd..8f5e962 100644 --- a/app/tikzktexteditorview.cpp +++ b/app/tikzktexteditorview.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -37,7 +36,7 @@ TikzKTextEditorView::TikzKTextEditorView(QWidget *parent) : TikzEditorViewAbstra QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setSpacing(0); - mainLayout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(m_documentView); m_currentDoc->setMode(QStringLiteral("LaTeX")); @@ -54,12 +53,8 @@ TikzKTextEditorView::TikzKTextEditorView(QWidget *parent) : TikzEditorViewAbstra connect(m_currentDoc, &KTextEditor::Document::urlChanged, this, &TikzKTextEditorView::documentUrlChanged); - KTextEditor::CodeCompletionInterface *cci = - qobject_cast(m_documentView); - if (cci) { - m_completion = new TikzKTextEditorCompletion(this); - cci->registerCompletionModel(m_completion); - } + m_completion = new TikzKTextEditorCompletion(this); + m_documentView->registerCompletionModel(m_completion); } TikzKTextEditorView::~TikzKTextEditorView() { } diff --git a/app/usercommandeditdialog.cpp b/app/usercommandeditdialog.cpp index 02d72d5..ca194af 100644 --- a/app/usercommandeditdialog.cpp +++ b/app/usercommandeditdialog.cpp @@ -20,7 +20,7 @@ #include -static const QString s_completionPlaceHolder(0x2022); +static const QString s_completionPlaceHolder(QChar(0x2022)); UserCommandEditDialog::UserCommandEditDialog(QWidget *parent) : QDialog(parent), m_oldIndex(-1) { diff --git a/app/usercommandinserter.cpp b/app/usercommandinserter.cpp index 42943c7..8151ca9 100644 --- a/app/usercommandinserter.cpp +++ b/app/usercommandinserter.cpp @@ -25,7 +25,7 @@ #include "tikzcommandinserter.h" #include "usercommandeditdialog.h" -static const QString s_completionPlaceHolder(0x2022); +static const QString s_completionPlaceHolder(QChar(0x2022)); UserCommandInserter::UserCommandInserter(QWidget *parent) : QObject(parent), m_userMenu(0) { diff --git a/common/tikzpreview.cpp b/common/tikzpreview.cpp index 8be3574..b17c181 100644 --- a/common/tikzpreview.cpp +++ b/common/tikzpreview.cpp @@ -18,11 +18,10 @@ #include "tikzpreview.h" -#include +#include #include #include -#include #include #include #include @@ -316,13 +315,12 @@ void TikzPreview::pixmapUpdated(Poppler::Document *tikzPdfDoc, const QListpage(pageNumber); + std::unique_ptr page = m_tikzPdfDoc->page(pageNumber); // const QSizeF pageSize = page->pageSizeF(); // const QImage image = pageSize.height() >= pageSize.width() // ? page->renderToImage(xres, yres) // : page->renderToImage(xres, yres, -1, -1, -1, -1, Poppler::Page::Rotate270); // slow const QImage image = page->renderToImage(xres, yres); // slow - delete page; return image; } diff --git a/common/tikzpreviewcontroller.cpp b/common/tikzpreviewcontroller.cpp index e6329f4..f4d090d 100644 --- a/common/tikzpreviewcontroller.cpp +++ b/common/tikzpreviewcontroller.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include "templatewidget.h" #include "tikzpreview.h" diff --git a/common/tikzpreviewgenerator.cpp b/common/tikzpreviewgenerator.cpp index 548d67e..ac6f4f4 100644 --- a/common/tikzpreviewgenerator.cpp +++ b/common/tikzpreviewgenerator.cpp @@ -31,8 +31,9 @@ #include #include #include +#include #include -#include +#include #include "tikzpreviewcontroller.h" #include "mainwidget.h" @@ -144,7 +145,7 @@ static QString getParsedLogText(QTextStream *logStream) { QString logText; - QRegExp errorPattern(QLatin1String("(\\S*):(\\d+): (.*$)")); + const QRegularExpression errorPattern("(\\S*):(\\d+): (.*$)"); QList errorMessageList; errorMessageList << QLatin1String("Undefined control sequence") << QLatin1String("LaTeX Warning:") << QLatin1String("LaTeX Error:") @@ -154,17 +155,19 @@ static QString getParsedLogText(QTextStream *logStream) QString logLine; while (!logStream->atEnd()) { logLine = logStream->readLine(); - if (errorPattern.indexIn(logLine) > -1) { + const auto errorMatch = errorPattern.match(logLine); + if (errorMatch.hasMatch()) { // show error message and correct line number - QString lineNum = QString::number(errorPattern.cap(2).toInt()); - const QString errorMsg = errorPattern.cap(3); + QString lineNum = QString::number(errorMatch.captured(2).toInt()); + const QString errorMsg = errorMatch.captured(3); logText += QLatin1String("[LaTeX] Line ") + lineNum + QLatin1String(": ") + errorMsg; // while we don't get a line starting with "l. ...", we have to add the line to // the first error message - QRegExp rx(QLatin1String("^l\\.(\\d+)(.*)")); + const QRegularExpression rx("^l\\.(\\d+)(.*)"); logLine = logStream->readLine(); - while (rx.indexIn(logLine) < 0 && !logStream->atEnd()) { + const auto m = rx.match(logLine); + while (m.hasMatch() && !logStream->atEnd()) { if (logLine.isEmpty()) logText += QLatin1String("\n[LaTeX] Line ") + lineNum + QLatin1String(": "); if (!logLine.startsWith( @@ -178,8 +181,8 @@ static QString getParsedLogText(QTextStream *logStream) break; // add the line starting with "l. ..." and the next line - lineNum = QString::number(rx.cap(1).toInt() - 7); - logLine = QLatin1String("l.") + lineNum + rx.cap(2); + lineNum = QString::number(m.captured(1).toInt() - 7); + logLine = QLatin1String("l.") + lineNum + m.captured(2); logText += logLine + QLatin1Char('\n'); logText += logStream->readLine() + QLatin1Char('\n'); } else { @@ -306,7 +309,7 @@ void TikzPreviewGenerator::createPreview() // Update widget if (m_tikzPdfDoc) delete m_tikzPdfDoc; - m_tikzPdfDoc = Poppler::Document::load(tikzPdfFileInfo.absoluteFilePath()); + m_tikzPdfDoc = Poppler::Document::load(tikzPdfFileInfo.absoluteFilePath()).release(); if (m_tikzPdfDoc) { m_shortLogText = QLatin1String("[LaTeX] ") + tr("Process finished successfully.", "info process"); diff --git a/common/tikzpreviewmessagewidget.cpp b/common/tikzpreviewmessagewidget.cpp index 432d818..8cbcbe0 100644 --- a/common/tikzpreviewmessagewidget.cpp +++ b/common/tikzpreviewmessagewidget.cpp @@ -55,7 +55,7 @@ TikzPreviewMessageWidget::TikzPreviewMessageWidget(QWidget *parent) : QFrame(par "}"))); QHBoxLayout *infoLayout = new QHBoxLayout(this); - infoLayout->setMargin(10); + infoLayout->setContentsMargins(10, 10, 10, 10); infoLayout->addWidget(m_infoPixmapLabel); infoLayout->addWidget(m_infoLabel); diff --git a/common/tikzpreviewrenderer.cpp b/common/tikzpreviewrenderer.cpp index 372bea4..14a8772 100644 --- a/common/tikzpreviewrenderer.cpp +++ b/common/tikzpreviewrenderer.cpp @@ -19,7 +19,7 @@ #include "tikzpreviewrenderer.h" #include -#include +#include TikzPreviewRenderer::TikzPreviewRenderer() { @@ -38,9 +38,8 @@ TikzPreviewRenderer::~TikzPreviewRenderer() void TikzPreviewRenderer::generatePreview(Poppler::Document *tikzPdfDoc, qreal zoomFactor, int currentPage) { - Poppler::Page *pdfPage = tikzPdfDoc->page(currentPage); + std::unique_ptr pdfPage = tikzPdfDoc->page(currentPage); const QImage tikzImage = pdfPage->renderToImage(zoomFactor * 72, zoomFactor * 72); - delete pdfPage; Q_EMIT showPreview(tikzImage, zoomFactor); } diff --git a/common/utils/file.cpp b/common/utils/file.cpp index ad78d4b..38e0630 100644 --- a/common/utils/file.cpp +++ b/common/utils/file.cpp @@ -21,6 +21,8 @@ #ifdef KTIKZ_USE_KDE # include +# include +# include # include // #include @@ -43,8 +45,8 @@ bool File::fileExists(const QUrl &url) if (!(url.isValid())) { return false; } - KIO::StatJob *existsJob = KIO::statDetails(url, KIO::StatJob::DestinationSide, KIO::StatBasic, - KIO::HideProgressInfo); + KIO::StatJob *existsJob = KIO::stat(url, KIO::StatJob::DestinationSide, KIO::StatBasic, + KIO::HideProgressInfo); existsJob->exec(); return (existsJob->error() == KJob::NoError); } diff --git a/common/utils/messagebox.cpp b/common/utils/messagebox.cpp index 1dd9de0..9970b11 100644 --- a/common/utils/messagebox.cpp +++ b/common/utils/messagebox.cpp @@ -26,7 +26,6 @@ int MessageBox::questionYesNo(QWidget *parent, const QString &text, const QStrin const QString &yesButtonText, const QString &noButtonText) { int result; -# if ((KWIDGETSADDONS_VERSION_MAJOR >= 5) && (KWIDGETSADDONS_VERSION_MINOR >= 100)) if (!yesButtonText.isEmpty()) { if (!noButtonText.isEmpty()) result = KMessageBox::questionTwoActions( @@ -41,20 +40,6 @@ int MessageBox::questionYesNo(QWidget *parent, const QString &text, const QStrin KStandardGuiItem::cancel()); return (result == KMessageBox::PrimaryAction) ? Yes : No; -# else - if (!yesButtonText.isEmpty()) { - if (!noButtonText.isEmpty()) - result = KMessageBox::questionYesNo( - parent, text, caption, KGuiItem(yesButtonText, QLatin1String("dialog-ok")), - KGuiItem(noButtonText, QLatin1String("process-stop"))); - else - result = KMessageBox::questionYesNo( - parent, text, caption, KGuiItem(yesButtonText, QLatin1String("dialog-ok"))); - } else - result = KMessageBox::questionYesNo(parent, text, caption); - - return (result == KMessageBox::Yes) ? Yes : No; -# endif } void MessageBox::error(QWidget *parent, const QString &text, const QString &caption) diff --git a/common/utils/zoomaction.cpp b/common/utils/zoomaction.cpp index 902674f..ce65bb8 100644 --- a/common/utils/zoomaction.cpp +++ b/common/utils/zoomaction.cpp @@ -18,6 +18,8 @@ #include "zoomaction.h" +#include + #include "globallocale.h" #include "icon.h" @@ -134,9 +136,8 @@ void ZoomAction::setZoomFactor(qreal zoomFactor) void ZoomAction::setZoomFactor(const QString &zoomFactorText) { - setZoomFactor(GlobalLocale::readNumber( - QString(zoomFactorText) - .remove(QRegExp(QString(QLatin1String("[^\\d\\%1]*")) - .arg(GlobalLocale::decimalSymbol())))) + const QRegularExpression rx(QString(QLatin1String("[^\\d\\%1]*")) + .arg(GlobalLocale::decimalSymbol())); + setZoomFactor(GlobalLocale::readNumber(QString(zoomFactorText).remove(rx)) / 100.0); } diff --git a/part/CMakeLists.txt b/part/CMakeLists.txt index d3b692a..8ea43f2 100644 --- a/part/CMakeLists.txt +++ b/part/CMakeLists.txt @@ -6,7 +6,6 @@ add_definitions(-DKTIKZ_TRANSLATIONS_INSTALL_DIR=\"${KTIKZ_TRANSLATIONS_INSTALL_ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common) set(ktikzpart_SRCS - browserextension.cpp configdialog.cpp configgeneralwidget.cpp part.cpp @@ -45,20 +44,20 @@ kconfig_add_kcfg_files(ktikzpart_SRCS ../common/settings.kcfgc) add_library(ktikzpart MODULE ${ktikzpart_SRCS}) target_link_libraries( ktikzpart - KF5::Parts - KF5::IconThemes - KF5::CoreAddons - KF5::KIOCore - KF5::KIOFileWidgets - KF5::KIOWidgets - KF5::KIONTLM - Qt5::PrintSupport - Poppler::Qt5 + KF6::Parts + KF6::IconThemes + KF6::CoreAddons + KF6::KIOCore + KF6::KIOFileWidgets + KF6::KIOWidgets + KF6::I18n + Qt6::PrintSupport + Poppler::Qt6 ) install(TARGETS ktikzpart DESTINATION ${KDE_INSTALL_PLUGINDIR}) install(FILES ktikzpart.rc DESTINATION ${KTIKZPART_DATA_INSTALL_DIR}) -install(FILES ktikzpart.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) +#install(FILES ktikzpart.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) add_custom_target(uninstalldirs_part) add_custom_command( diff --git a/part/browserextension.cpp b/part/browserextension.cpp deleted file mode 100644 index 8c3ccb4..0000000 --- a/part/browserextension.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2011 by Glad Deschrijver * - * * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see . * - ***************************************************************************/ - -#include "browserextension.h" - -#include -#include - -#include "../common/tikzpreviewcontroller.h" - -namespace KtikZ { - -BrowserExtension::BrowserExtension(KParts::ReadOnlyPart *part, - TikzPreviewController *tikzPreviewController) - : KParts::BrowserExtension(part) -{ - m_tikzPreviewController = tikzPreviewController; - emit enableAction("print", true); - QString iconPath = - KIconLoader::global()->iconPath(QStringLiteral("text-x-pgf"), KIconLoader::SizeSmall); - emit setIconUrl(QUrl::fromLocalFile(iconPath)); -} - -BrowserExtension::~BrowserExtension() { } - -void BrowserExtension::print() -{ - m_tikzPreviewController->printImage(); -} - -} // namespace KtikZ diff --git a/part/browserextension.h b/part/browserextension.h deleted file mode 100644 index 47e5bbf..0000000 --- a/part/browserextension.h +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2011 by Glad Deschrijver * - * * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see . * - ***************************************************************************/ - -#ifndef KTIKZ_BROWSER_EXTENSION_H -#define KTIKZ_BROWSER_EXTENSION_H - -#include - -class TikzPreviewController; - -namespace KtikZ { - -class BrowserExtension : public KParts::BrowserExtension -{ - Q_OBJECT -public: - BrowserExtension(KParts::ReadOnlyPart *, TikzPreviewController *tikzPreviewController); - ~BrowserExtension(); - -private Q_SLOTS: - void print(); - -private: - TikzPreviewController *m_tikzPreviewController; -}; - -} // namespace KtikZ - -#endif diff --git a/part/ktikzpart.desktop b/part/ktikzpart.desktop deleted file mode 100644 index 8187b58..0000000 --- a/part/ktikzpart.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Type=Service -Name=KtikZ - TikZ File Viewer -Name[es]=Visor de ficheros TikZ - KtikZ -Name[fr]=Visionneuse de fichiers TikZ - KtikZ -MimeType=text/x-pgf; -X-KDE-ServiceTypes=KParts/ReadOnlyPart -X-KDE-Library=ktikzpart -InitialPreference=12 -Icon=ktikz diff --git a/part/ktikzpart.json b/part/ktikzpart.json new file mode 100644 index 0000000..67c0b89 --- /dev/null +++ b/part/ktikzpart.json @@ -0,0 +1,16 @@ +{ + "KPlugin": { + "Icon": "ktikz", + "InitialPreference": 12, + "MimeTypes": [ + "text/x-pgf" + ], + "Name": "KtikZ - TikZ File Viewer", + "Name[es]": "Visor de ficheros TikZ - KtikZ", + "Name[fr]": "Visionneuse de fichiers TikZ - KtikZ", + "ServiceTypes": [ + "KParts/ReadOnlyPart" + ] + }, + "MimeType": "text/x-pgf;" +} diff --git a/part/part.cpp b/part/part.cpp index 44fed07..4fc936d 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -45,10 +45,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -60,12 +62,11 @@ #include "../common/tikzpreview.h" #include "../common/tikzpreviewcontroller.h" #include "../common/utils/action.h" -#include "browserextension.h" namespace KtikZ { -Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) - : KParts::ReadOnlyPart(parent) +Part::Part(QWidget *parentWidget, QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KParts::ReadOnlyPart(parent, data) { Q_UNUSED(args); @@ -83,7 +84,7 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) QWidget *mainWidget = new QWidget(parentWidget); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setSpacing(0); - mainLayout->setMargin(0); + mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(m_tikzPreviewController->templateWidget()); mainLayout->addWidget(m_tikzPreviewController->tikzPreview()); mainWidget->setLayout(mainLayout); @@ -98,9 +99,6 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) m_dirtyHandler->setSingleShot(true); connect(m_dirtyHandler, &QTimer::timeout, this, &Part::slotDoFileDirty); - new BrowserExtension( - this, m_tikzPreviewController); // needed to be able to use Konqueror's "Print" action - setXMLFile("ktikzpart/ktikzpart.rc"); applySettings(); @@ -346,7 +344,7 @@ QTranslator *Part::createTranslator(const QString &transName) return translator; } -K_PLUGIN_FACTORY(ktikzPartFactory, registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(ktikzPartFactory, "ktikzpart.json", registerPlugin();) #include "part.moc" diff --git a/part/part.h b/part/part.h index 2960c78..f879c0f 100644 --- a/part/part.h +++ b/part/part.h @@ -42,7 +42,7 @@ class Part : public KParts::ReadOnlyPart, public MainWidget Q_OBJECT public: - explicit Part(QWidget *parentWidget, QObject *parent, const QVariantList &args); + explicit Part(QWidget *parentWidget, QObject *parent, const KPluginMetaData &data, const QVariantList &args); virtual ~Part() override; static KAboutData *createAboutData(); diff --git a/translations/CMakeLists.txt b/translations/CMakeLists.txt index e8084bb..6e9ddfb 100644 --- a/translations/CMakeLists.txt +++ b/translations/CMakeLists.txt @@ -2,7 +2,7 @@ include(../KtikzConfig.cmake) ### Install qm files file(GLOB ktikz_TS_FILES */qtikz_*.ts) -qt5_add_translation(ktikz_QM_FILES ${ktikz_TS_FILES}) +qt_add_translation(ktikz_QM_FILES ${ktikz_TS_FILES}) add_custom_target(translations ALL DEPENDS ${ktikz_QM_FILES}) install(FILES ${ktikz_QM_FILES} DESTINATION ${KTIKZ_TRANSLATIONS_INSTALL_DIR})