diff --git a/FindPoppler.cmake b/FindPoppler.cmake deleted file mode 100644 index a9e8086..0000000 --- a/FindPoppler.cmake +++ /dev/null @@ -1,151 +0,0 @@ -#.rst: -# FindPoppler -# ----------- -# -# Try to find Poppler. -# -# This is a component-based find module, which makes use of the COMPONENTS -# and OPTIONAL_COMPONENTS arguments to find_module. The following components -# are available:: -# -# Core Cpp Qt5 Qt4 Glib -# -# If no components are specified, this module will act as though all components -# were passed to OPTIONAL_COMPONENTS. -# -# This module will define the following variables, independently of the -# components searched for or found: -# -# ``Poppler_FOUND`` -# TRUE if (the requested version of) Poppler is available -# ``Poppler_VERSION`` -# Found Poppler version -# ``Poppler_TARGETS`` -# A list of all targets imported by this module (note that there may be more -# than the components that were requested) -# ``Poppler_LIBRARIES`` -# This can be passed to target_link_libraries() instead of the imported -# targets -# ``Poppler_INCLUDE_DIRS`` -# This should be passed to target_include_directories() if the targets are -# not used for linking -# ``Poppler_DEFINITIONS`` -# This should be passed to target_compile_options() if the targets are not -# used for linking -# -# For each searched-for components, ``Poppler__FOUND`` will be set to -# TRUE if the corresponding Poppler library was found, and FALSE otherwise. If -# ``Poppler__FOUND`` is TRUE, the imported target -# ``Poppler::`` will be defined. This module will also attempt to -# determine ``Poppler_*_VERSION`` variables for each imported target, although -# ``Poppler_VERSION`` should normally be sufficient. -# -# In general we recommend using the imported targets, as they are easier to use -# and provide more control. Bear in mind, however, that if any target is in the -# link interface of an exported library, it must be made available by the -# package config file. -# -# Since 5.19 - -#============================================================================= -# Copyright 2015 Alex Richardson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#============================================================================= -include(/usr/share/ECM/modules/ECMFindModuleHelpers.cmake) - -ecm_find_package_version_check(Poppler) - -set(Poppler_known_components - Cpp - Qt4 - Qt5 - Glib -) -foreach(_comp ${Poppler_known_components}) - string(TOLOWER "${_comp}" _lc_comp) - set(Poppler_${_comp}_component_deps "Core") - set(Poppler_${_comp}_pkg_config "poppler-${_lc_comp}") - set(Poppler_${_comp}_lib "poppler-${_lc_comp}") - set(Poppler_${_comp}_header_subdir "poppler/${_lc_comp}") -endforeach() -set(Poppler_known_components Core ${Poppler_known_components}) - -set(Poppler_Core_component_deps "") -set(Poppler_Core_pkg_config "poppler") -# poppler-config.h header is only installed with --enable-xpdf-headers -# fall back to using any header from a submodule with a path to make it work in that case too -set(Poppler_Core_header "poppler-config.h" "cpp/poppler-version.h" "qt5/poppler-qt5.h" "qt4/poppler-qt4.h" "glib/poppler.h") -set(Poppler_Core_header_subdir "poppler") -set(Poppler_Core_lib "poppler") - -set(Poppler_Cpp_header "poppler-version.h") -set(Poppler_Qt5_header "poppler-qt5.h") -set(Poppler_Qt4_header "poppler-qt4.h") -set(Poppler_Glib_header "poppler.h") - -ecm_find_package_parse_components(Poppler - RESULT_VAR Poppler_components - KNOWN_COMPONENTS ${Poppler_known_components} -) -ecm_find_package_handle_library_components(Poppler - COMPONENTS ${Poppler_components} -) - -# If pkg-config didn't provide us with version information, -# try to extract it from poppler-version.h or poppler-config.h -if(NOT Poppler_VERSION) - find_file(Poppler_VERSION_HEADER - NAMES "poppler-config.h" "cpp/poppler-version.h" - HINTS ${Poppler_INCLUDE_DIRS} - PATH_SUFFIXES ${Poppler_Core_header_subdir} - ) - mark_as_advanced(Poppler_VERSION_HEADER) - if(Poppler_VERSION_HEADER) - file(READ ${Poppler_VERSION_HEADER} _poppler_version_header_contents) - string(REGEX REPLACE - "^.*[ \t]+POPPLER_VERSION[ \t]+\"([0-9d.]*)\".*$" - "\\1" - Poppler_VERSION - "${_poppler_version_header_contents}" - ) - unset(_poppler_version_header_contents) - endif() -endif() - -find_package_handle_standard_args(Poppler - FOUND_VAR - Poppler_FOUND - REQUIRED_VARS - Poppler_LIBRARIES - VERSION_VAR - Poppler_VERSION - HANDLE_COMPONENTS -) - -include(FeatureSummary) -set_package_properties(Poppler PROPERTIES - DESCRIPTION "A PDF rendering library" - URL "http://poppler.freedesktop.org" -) diff --git a/app/app.pri b/app/app.pri index c5b9d04..a24d55e 100644 --- a/app/app.pri +++ b/app/app.pri @@ -6,7 +6,7 @@ LANGUAGE = C++ CONFIG += qt warn_on thread QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -greaterThan(QT_MAJOR_VERSION, 6): QT += core5compat pdf +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat pdf DEFINES += QT_STL QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_BYTEARRAY QT_STRICT_ITERATORS QT_NO_URL_CAST_FROM_STRING QT_NO_KEYWORDS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050200 @@ -15,6 +15,7 @@ DEFINES += QT_STL QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_BYTE #QMAKE_CXXFLAGS += -Wall -Wextra -Wpedantic -Weffc++ -Wlogical-op -Wmissing-declarations -Wold-style-cast -Woverloaded-virtual -Wshadow -Wstrict-null-sentinel -Wswitch-default -Wuseless-cast -Wzero-as-null-pointer-constant -fmessage-length=0 -fdiagnostics-show-location=every-line #QMAKE_CXXFLAGS += -Wall -Wextra -Wpedantic -Wlogical-op -Wmissing-declarations -Wold-style-cast -Woverloaded-virtual #QMAKE_CXX = clang +QMAKE_CXXFLAGS += -Og -ggdb DEFINES += ORGNAME=\\\"$${ORGNAME}\\\" DEFINES += APPNAME=\\\"$${APPNAME}\\\" diff --git a/app/configappearancewidget.cpp b/app/configappearancewidget.cpp index 980893f..3a688e1 100644 --- a/app/configappearancewidget.cpp +++ b/app/configappearancewidget.cpp @@ -115,8 +115,12 @@ void ConfigAppearanceWidget::setItemToolTip(QTableWidgetItem *item, const QFont { const QFontMetrics metrics(font); ui.itemTable->setRowHeight(m_itemHighlighted, metrics.height() + m_itemMargin); - if (metrics.width(item->text()) >= ui.itemTable->contentsRect().width() - 30) - item->setToolTip(item->text()); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + if (metrics.horizontalAdvance(item->text()) >= ui.itemTable->contentsRect().width() - 30) +#else + if (metrics.width(item->text()) >= ui.itemTable->contentsRect().width() - 30) +#endif + item->setToolTip(item->text()); else item->setToolTip(QString()); } diff --git a/app/configeditorwidget.cpp b/app/configeditorwidget.cpp index 030d832..b376fbb 100644 --- a/app/configeditorwidget.cpp +++ b/app/configeditorwidget.cpp @@ -22,7 +22,11 @@ #include "configeditorwidget.h" #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else #include +#endif #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #include #else @@ -197,8 +201,12 @@ void ConfigEditorWidget::fillCodecComboBox(QComboBox *cb) QVector ciList; ciList.reserve(ca.length()); Q_FOREACH(const QByteArray &ba , ca) ciList.append(ComboItem(codecNameToString(ba), ba)); - qSort(ciList); - Q_FOREACH (const ComboItem& ci, ciList) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + std::sort(ciList.begin(), ciList.end()); +#else + qSort(ciList); +#endif + Q_FOREACH (const ComboItem& ci, ciList) { cb->addItem(ci.text, ci.data); } } diff --git a/app/editreplacecurrentwidget.cpp b/app/editreplacecurrentwidget.cpp index 8ff087a..c962035 100644 --- a/app/editreplacecurrentwidget.cpp +++ b/app/editreplacecurrentwidget.cpp @@ -50,7 +50,11 @@ ReplaceCurrentWidget::ReplaceCurrentWidget(QWidget *parent) : QWidget(parent) buttonsLayout->addWidget(dontReplaceButton); buttonsLayout->addWidget(cancelButton); buttonsLayout->addStretch(); - buttonsLayout->setMargin(0); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + buttonsLayout->setContentsMargins(0, 0, 0, 0); +#else + buttonsLayout->setMargin(0); +#endif buttonsWidget->setLayout(buttonsLayout); mainLayout->addWidget(m_replaceLabel); mainLayout->addWidget(buttonsWidget); diff --git a/app/editreplacewidget.cpp b/app/editreplacewidget.cpp index 8568b29..62796ef 100644 --- a/app/editreplacewidget.cpp +++ b/app/editreplacewidget.cpp @@ -100,7 +100,7 @@ void ReplaceWidget::doFind() if (ui.comboBoxFind->findText(currentText) < 0) ui.comboBoxFind->addItem(currentText); - QTextDocument::FindFlags flags = 0; + QTextDocument::FindFlags flags = (QTextDocument::FindFlags)0; if (ui.checkBoxCaseSensitive->isChecked()) flags |= QTextDocument::FindCaseSensitively; if (ui.checkBoxWholeWords->isChecked()) @@ -121,7 +121,7 @@ void ReplaceWidget::doReplace() if (ui.comboBoxReplace->findText(replacementText) < 0) ui.comboBoxReplace->addItem(replacementText); - QTextDocument::FindFlags flags = 0; + QTextDocument::FindFlags flags = (QTextDocument::FindFlags)0; if (ui.checkBoxCaseSensitive->isChecked()) flags |= QTextDocument::FindCaseSensitively; if (ui.checkBoxWholeWords->isChecked()) diff --git a/app/linenumberwidget.cpp b/app/linenumberwidget.cpp index f770f3f..43231a5 100644 --- a/app/linenumberwidget.cpp +++ b/app/linenumberwidget.cpp @@ -74,7 +74,11 @@ void LineNumberWidget::paintEvent(QPaintEvent *event) { if (userBookmarks.at(i) == lineNumber) { - painter.fillRect(2, top, fm.width(QLatin1Char('B')) + 4, lineHeight, m_highlightBrush); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + painter.fillRect(2, top, fm.horizontalAdvance(QLatin1Char('B')) + 4, lineHeight, m_highlightBrush); +#else + painter.fillRect(2, top, fm.width(QLatin1Char('B')) + 4, lineHeight, m_highlightBrush); +#endif painter.setPen(m_highlightedTextPen); painter.drawText(4, top, width() - 4, lineHeight, Qt::AlignLeft | Qt::AlignTop, QLatin1String("B")); painter.setPen(m_highlightPen); @@ -97,8 +101,12 @@ void LineNumberWidget::paintEvent(QPaintEvent *event) void LineNumberWidget::mousePressEvent(QMouseEvent *event) { event->accept(); - const QPoint p = m_editor->viewport()->mapFromGlobal(event->globalPos()); - const int lineNumber = m_editor->cursorForPosition(p).blockNumber() + 1; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const QPointF p = m_editor->viewport()->mapFromGlobal(event->globalPosition()); +#else + const QPoint p = m_editor->viewport()->mapFromGlobal(event->globalPos()); +#endif + const int lineNumber = m_editor->cursorForPosition(p.toPoint()).blockNumber() + 1; if (lineNumber <= 0) return; diff --git a/app/loghighlighter.cpp b/app/loghighlighter.cpp index 6b3bbf8..4d4b207 100644 --- a/app/loghighlighter.cpp +++ b/app/loghighlighter.cpp @@ -37,7 +37,11 @@ LogHighlighter::LogHighlighter(QTextDocument *parent) << tr("This program will not work!"); Q_FOREACH (const QString &pattern, keywordPatterns) { - rule.pattern = QRegExp(pattern); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + rule.pattern = QRegularExpression(pattern); +#else + rule.pattern = QRegExp(pattern); +#endif rule.format = keywordFormat; m_highlightingRules.append(rule); } @@ -45,7 +49,11 @@ LogHighlighter::LogHighlighter(QTextDocument *parent) QTextCharFormat commandFormat; commandFormat.setForeground(Qt::darkBlue); commandFormat.setFontWeight(QFont::Bold); - rule.pattern = QRegExp(QLatin1String("^\\[[^\\]\\d][^\\]]*\\]")); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + rule.pattern = QRegularExpression(QLatin1String("^\\[[^\\]\\d][^\\]]*\\]")); +#else + rule.pattern = QRegExp(QLatin1String("^\\[[^\\]\\d][^\\]]*\\]")); +#endif rule.format = commandFormat; m_highlightingRules.append(rule); @@ -65,8 +73,19 @@ void LogHighlighter::highlightBlock(const QString &text) { // const QRegExp expression(rule.pattern); // int index = text.indexOf(expression); - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + QRegularExpression expression(rule.pattern); + QRegularExpressionMatch match = expression.match(text); + while (match.hasMatch()) + { + const int length = match.capturedLength(); + setFormat(match.capturedStart(), length, rule.format); +// index = text.indexOf(expression, index + length); + match = expression.match(text, match.capturedEnd() + 1); + } +#else + QRegExp expression(rule.pattern); + int index = text.indexOf(expression); while (index >= 0) { const int length = expression.matchedLength(); @@ -74,7 +93,8 @@ void LogHighlighter::highlightBlock(const QString &text) // index = text.indexOf(expression, index + length); index = expression.indexIn(text, index + length); } - } +#endif + } // Highlight statistics (at the end of the log) setCurrentBlockState(0); // The current block state tracks multiline formatting diff --git a/app/loghighlighter.h b/app/loghighlighter.h index a3c7b70..d055050 100644 --- a/app/loghighlighter.h +++ b/app/loghighlighter.h @@ -23,6 +23,7 @@ #include #include +#include /** A simple, incomplete highlighter for LaTeX .log files * @author Florian Hackenberger @@ -44,7 +45,11 @@ class LogHighlighter : public QSyntaxHighlighter private: struct LogHighlightingRule { - QRegExp pattern; /// The pattern to match for formatting +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + QRegularExpression pattern; /// The pattern to match for formatting +#else + QRegExp pattern; /// The pattern to match for formatting +#endif QTextCharFormat format; /// The style of the formatting }; /// All highlighting rules with their formatting for easy iteration diff --git a/app/logtextedit.cpp b/app/logtextedit.cpp index 7a3c39c..50afc34 100644 --- a/app/logtextedit.cpp +++ b/app/logtextedit.cpp @@ -69,7 +69,11 @@ void LogTextEdit::setLogPalette(bool runFailed) if (runFailed) { QPalette failedPalette(QApplication::palette()); - failedPalette.setColor(QPalette::Background, QColor(255, 102, 102)); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + failedPalette.setColor(QPalette::Window, QColor(255, 102, 102)); +#else + failedPalette.setColor(QPalette::Background, QColor(255, 102, 102)); +#endif setAutoFillBackground(true); setPalette(failedPalette); } diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 89f72c6..a0d1345 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -37,7 +37,11 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else #include +#endif #include #include #include @@ -45,7 +49,9 @@ #include #include #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#endif #include #include #include @@ -94,7 +100,7 @@ QList MainWindow::s_mainWindowList; -MainWindow::MainWindow() +MainWindow::MainWindow() : m_doOverrideEncoder(false), m_doOverrideDecoder(false) { //QTime t = QTime::currentTime(); #ifndef KTIKZ_USE_KDE @@ -107,6 +113,9 @@ MainWindow::MainWindow() s_mainWindowList.append(this); + qRegisterMetaType(); + qRegisterMetaType(); + #ifndef KTIKZ_USE_KDE QStringList themeSearchPaths; themeSearchPaths << QDir::homePath() + QLatin1String("/.local/share/icons/"); @@ -154,7 +163,11 @@ MainWindow::MainWindow() QWidget *mainWidget = new QWidget(this); QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); mainLayout->setSpacing(0); - mainLayout->setMargin(0); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + mainLayout->setContentsMargins(0, 0, 0, 0); +#else + mainLayout->setMargin(0); +#endif mainLayout->addWidget(m_tikzPreviewController->templateWidget()); mainLayout->addWidget(m_tikzEditorView); @@ -911,11 +924,40 @@ void MainWindow::applySettings() updateCompleter(); settings.beginGroup(QLatin1String("encoding")); QVariant qv = settings.value(QLatin1String("default")); - setCurrentEncoding( qv.isNull() ? QTextCodec::codecForLocale() : QTextCodec::codecForName(qv.toByteArray())) ; - qv = settings.value(QLatin1String("encoder")); - m_overrideEncoder = qv.isNull() ? NULL : QTextCodec::codecForName(qv.toByteArray()) ; - qv = settings.value(QLatin1String("decoder")); - m_overrideDecoder = qv.isNull() ? NULL : QTextCodec::codecForName(qv.toByteArray()) ; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + if (qv.isNull()) + { + setCurrentEncoding( QStringConverter::System ) ; + } else { + std::optional currentEncoding = QStringConverter::encodingForName(qv.toString().toStdString().c_str()); + setCurrentEncoding( currentEncoding.value_or( QStringConverter::System ) ) ; + } + + qv = settings.value(QLatin1String("encoder")); + if (qv.isNull()) + { + m_doOverrideEncoder = false; + } else { + std::optional overrideEncoding = QStringConverter::encodingForName(qv.toString().toStdString().c_str()); + m_doOverrideEncoder = overrideEncoding.has_value(); + m_overrideEncoder = overrideEncoding.value_or( QStringConverter::System ) ; + } + qv = settings.value(QLatin1String("decoder")); + if (qv.isNull()) + { + m_doOverrideDecoder = false; + } else { + std::optional overrideDecoding = QStringConverter::encodingForName(qv.toString().toStdString().c_str()); + m_doOverrideDecoder = overrideDecoding.has_value(); + m_overrideDecoder = overrideDecoding.value_or( QStringConverter::System ) ; + } +#else + setCurrentEncoding( qv.isNull() ? QTextCodec::codecForLocale() : QTextCodec::codecForName(qv.toByteArray())) ; + qv = settings.value(QLatin1String("encoder")); + m_overrideEncoder = qv.isNull() ? NULL : QTextCodec::codecForName(qv.toByteArray()) ; + qv = settings.value(QLatin1String("decoder")); + m_overrideDecoder = qv.isNull() ? NULL : QTextCodec::codecForName(qv.toByteArray()) ; +#endif m_encoderBom = settings.value(QLatin1String("bom"), true).toBool(); settings.endGroup(); @@ -939,7 +981,11 @@ void MainWindow::readSettings() QSettings settings; settings.beginGroup(QLatin1String("MainWindow")); - const int screenWidth = QApplication::desktop()->availableGeometry().width(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const int screenWidth = screen()->availableGeometry().width(); +#else + const int screenWidth = QApplication::desktop()->availableGeometry().width(); +#endif QSize size; if (screenWidth > 1200) size = settings.value(QLatin1String("size"), QSize(1200, 600)).toSize(); @@ -1051,7 +1097,11 @@ void MainWindow::loadUrl(const QUrl &url) QApplication::setOverrideCursor(Qt::WaitCursor); this->configureStreamDecoding(in); m_tikzQtEditorView->editor()->setPlainText(in.readAll()); - setCurrentEncoding(in.codec()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + setCurrentEncoding(in.encoding()); +#else + setCurrentEncoding(in.codec()); +#endif } QApplication::restoreOverrideCursor(); @@ -1115,11 +1165,19 @@ bool MainWindow::saveUrl(const QUrl &url) return true; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) +void MainWindow::setCurrentEncoding(QStringConverter::Encoding codec ) +{ + m_currentEncoding = codec; + // TODO: implement user warning and suggestion to reload the file. +} +#else void MainWindow::setCurrentEncoding(QTextCodec *codec ) { - m_currentEncoding = codec; + m_currentEncoding = codec; // TODO: implement user warning and suggestion to reload the file. } +#endif QUrl MainWindow::url() const { @@ -1142,18 +1200,29 @@ QString MainWindow::strippedName(const QUrl &url) const return (fileName.isEmpty()) ? QLatin1String("untitled.txt") : fileName; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) +QStringConverter::Encoding MainWindow::getEncoder() const +{ + return this->m_doOverrideEncoder ? this->m_overrideEncoder : this->m_currentEncoding; +} +#else QTextCodec *MainWindow::getEncoder() const { - return this->m_overrideEncoder ? this->m_overrideEncoder : this->m_currentEncoding; + return this->m_overrideEncoder ? this->m_overrideEncoder : this->m_currentEncoding; } +#endif void MainWindow::configureStreamEncoding(QTextStream& textStream) { - QTextCodec* encoder = this->getEncoder(); - if(Q_LIKELY(encoder)) // should be true - textStream.setCodec(encoder); - else - qWarning("The encoder variable should not be null."); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + textStream.setEncoding(this->getEncoder()); +#else + QTextCodec* encoder = this->getEncoder(); + if(Q_LIKELY(encoder)) // should be true + textStream.setCodec(encoder); + else + qWarning("The encoder variable should not be null."); +#endif textStream.setGenerateByteOrderMark(this->m_encoderBom); @@ -1161,10 +1230,17 @@ void MainWindow::configureStreamEncoding(QTextStream& textStream) void MainWindow::configureStreamDecoding(QTextStream &textStream) { - if(m_overrideDecoder) - { - textStream.setCodec(m_overrideDecoder); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + if(m_doOverrideDecoder) + { + textStream.setEncoding(m_overrideDecoder); + } +#else + if(m_overrideDecoder) + { + textStream.setCodec(m_overrideDecoder); + } +#endif textStream.setAutoDetectUnicode(true); } diff --git a/app/mainwindow.h b/app/mainwindow.h index 1af1bba..7b64271 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -29,6 +29,7 @@ #include #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #include +#include #else #include #endif @@ -45,6 +46,7 @@ class QDockWidget; class QLabel; class QMenu; class QToolButton; +class QTextCodec; class Action; class ConfigDialog; @@ -58,6 +60,9 @@ class TikzHighlighter; class TikzPreviewController; class UserCommandInserter; +Q_DECLARE_METATYPE(QPdfDocument) +Q_DECLARE_METATYPE(QPdfDocument*) + /** Provides a tiny application for simple editing of TikZ graphics * @author Florian Hackenberger */ @@ -139,7 +144,11 @@ private Q_SLOTS: void updateCompleter(); /// Change the codec for the current document /// @param isUserRequest set to true if the user requested the changement (in this case, the application should warn the user -- not implemented yet.). - void setCurrentEncoding(QTextCodec* codec /*, bool isUserRequest = false */ ); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + void setCurrentEncoding(QStringConverter::Encoding codec ); +#else + void setCurrentEncoding(QTextCodec* codec /*, bool isUserRequest = false */ ); +#endif private: void createActions(); @@ -230,15 +239,29 @@ private Q_SLOTS: QPointer m_configDialog; QUrl m_currentUrl; - QTextCodec* m_currentEncoding; - /// If not null, override the encoder (rather than @ref m_currentEncoding) - QTextCodec* m_overrideEncoder; - /// If not null, override the decoder - QTextCodec* m_overrideDecoder; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + QStringConverter::Encoding m_currentEncoding; + /// If true, override the encoder (rather than @ref m_currentEncoding) + bool m_doOverrideEncoder; + QStringConverter::Encoding m_overrideEncoder; + /// If true, override the decoder + bool m_doOverrideDecoder; + QStringConverter::Encoding m_overrideDecoder; +#else + QTextCodec* m_currentEncoding; + /// If not null, override the encoder (rather than @ref m_currentEncoding) + QTextCodec* m_overrideEncoder; + /// If not null, override the decoder + QTextCodec* m_overrideDecoder; +#endif /// True if a BOM must be added to the PGF-file bool m_encoderBom; /// Return the current encoder (m_currentEncoding or another if encoder is overriden). - /*virtual*/ QTextCodec* getEncoder() const; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + /*virtual*/ QStringConverter::Encoding getEncoder() const; +#else + /*virtual*/ QTextCodec* getEncoder() const; +#endif QUrl m_lastUrl; QDateTime m_lastInternalModifiedDateTime; diff --git a/app/tikzcommandinserter.cpp b/app/tikzcommandinserter.cpp index 2c74e2d..fb84822 100644 --- a/app/tikzcommandinserter.cpp +++ b/app/tikzcommandinserter.cpp @@ -55,12 +55,15 @@ #include #include #endif +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif #include "tikzeditorhighlighter.h" #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; @@ -102,11 +105,15 @@ static TikzCommand newCommand(const QString &name, static QString translateOptions(const QString &text) { QString translatedText; - for (int pos = 0, oldPos = 0; pos >= 0;) + for (qsizetype pos = 0, oldPos = 0; pos >= 0;) { oldPos = pos; pos = text.indexOf(QLatin1Char('<'), pos); // option is between < and > - translatedText += text.midRef(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 +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + translatedText += 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 +#else + translatedText += text.midRef(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 +#endif if (pos >= 0) { oldPos = pos; @@ -504,8 +511,13 @@ void TikzCommandInserter::addListWidgetItems(QListWidget *listWidget, const QPal QString itemText = commandList.children.at(i).title; item->setText(itemText.remove(QLatin1Char('&'))); - item->setBackgroundColor(titleBg); - item->setTextColor(titleFg); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + item->setBackground(titleBg); + item->setForeground(titleFg); +#else + item->setBackgroundColor(titleBg); + item->setTextColor(titleFg); +#endif item->setFont(titleFont); addListWidgetItems(listWidget, standardPalette, commandList.children.at(i)); @@ -579,7 +591,11 @@ 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); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + tikzLayout->setContentsMargins(5, 5, 5, 5); +#else + tikzLayout->setMargin(5); +#endif TikzCommandWidget *tikzWidget = new TikzCommandWidget; tikzWidget->setLayout(tikzLayout); @@ -807,7 +823,11 @@ void TikzCommandInserter::insertTag(const QString &tag, int dx, int dy) // replace all options (between <...>) by a place holder QString insertWord = tag; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const QRegularExpression rx(QLatin1String("<[^<>]*>")); +#else const QRegExp rx(QLatin1String("<[^<>]*>")); +#endif insertWord.replace(rx, s_completionPlaceHolder); QTextCursor cur = m_mainEdit->textCursor(); diff --git a/app/tikzeditor.cpp b/app/tikzeditor.cpp index e6b1522..981368a 100644 --- a/app/tikzeditor.cpp +++ b/app/tikzeditor.cpp @@ -58,7 +58,7 @@ #include "linenumberwidget.h" -static const QString s_completionPlaceHolder(0x2022); +static const QString s_completionPlaceHolder(QChar(0x2022)); TikzEditor::TikzEditor(QWidget *parent) : QPlainTextEdit(parent) @@ -314,7 +314,11 @@ void TikzEditor::paintSpace(QPainter &painter, qreal x, qreal y, int spaceWidth) void TikzEditor::printWhiteSpaces(QPainter &painter) { const QFontMetrics fontMetrics = QFontMetrics(document()->defaultFont()); - const int spaceWidth = fontMetrics.width(QLatin1Char(' ')); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const int spaceWidth = fontMetrics.horizontalAdvance(QLatin1Char(' ')); +#else + const int spaceWidth = fontMetrics.width(QLatin1Char(' ')); +#endif const int fontHeight = fontMetrics.height(); QTextCursor cursor = textCursor(); @@ -511,7 +515,7 @@ void TikzEditor::keyPressEvent(QKeyEvent *event) { QTextCursor cursor = textCursor(); QTextBlock block = cursor.block(); - QTextDocument::FindFlags flags = 0; + QTextDocument::FindFlags flags = (QTextDocument::FindFlags)0; if (event->key() == Qt::Key_Backtab) flags = QTextDocument::FindBackward; if (cursor.hasSelection() && cursor.selectedText().contains(QChar::ParagraphSeparator)) @@ -634,8 +638,13 @@ 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 +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const QRegularExpression rx(QLatin1String("<[^<>]*>")); + const int offset = insertWord.indexOf(rx) - 1; // put cursor at the first option +#else + const QRegExp rx(QLatin1String("<[^<>]*>")); + const int offset = rx.indexIn(insertWord) - 1; // put cursor at the first option +#endif insertWord.replace(rx, s_completionPlaceHolder); cursor.insertText(insertWord); @@ -774,7 +783,7 @@ int TikzEditor::lineNumberAreaWidth() ++digits; digits = qMax(4, digits) + 1; - return m_showLineNumberArea ? 3 + fontMetrics().width(QLatin1Char('9')) * digits : 0; + return m_showLineNumberArea ? 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits : 0; } void TikzEditor::updateLineNumberAreaWidth() diff --git a/app/tikzeditorhighlighter.cpp b/app/tikzeditorhighlighter.cpp index cad105e..1fd1219 100644 --- a/app/tikzeditorhighlighter.cpp +++ b/app/tikzeditorhighlighter.cpp @@ -53,13 +53,13 @@ void TikzHighlighter::setHighlightingRules(const QVector &high Q_FOREACH (const QString &pattern, keywordPatterns) { rule.type = highlightTypeNames.at(currentIndex); - rule.pattern = QRegExp(pattern); + rule.pattern = QRegExp(pattern); rule.isRegExp = true; m_highlightingRules.append(rule); } // comments rule.type = highlightTypeNames.at(currentIndex + 1); - rule.pattern = QRegExp(QLatin1String("%[^\n]*")); + rule.pattern = QRegExp(QLatin1String("%[^\n]*")); rule.isRegExp = true; m_highlightingRules.append(rule); diff --git a/app/tikzeditorhighlighter.h b/app/tikzeditorhighlighter.h index 5e2109a..f1c32d8 100644 --- a/app/tikzeditorhighlighter.h +++ b/app/tikzeditorhighlighter.h @@ -22,12 +22,15 @@ #define TIKZEDITORHIGHLIGHTER_H #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) +#include +#endif 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 + QRegExp pattern; /// The pattern to match for formatting bool isRegExp; }; diff --git a/app/tikzeditorview.cpp b/app/tikzeditorview.cpp index d490f95..9eb1fbb 100644 --- a/app/tikzeditorview.cpp +++ b/app/tikzeditorview.cpp @@ -65,7 +65,11 @@ TikzEditorView::TikzEditorView(QWidget *parent) QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setSpacing(0); - mainLayout->setMargin(0); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + mainLayout->setContentsMargins(0, 0, 0, 0); +#else + mainLayout->setMargin(0); +#endif mainLayout->addWidget(m_tikzEditor); createActions(); @@ -147,7 +151,11 @@ void TikzEditorView::setFont(const QFont &editorFont) fm.setFontPointSize(editorFont.pointSize()); m_tikzEditor->setCurrentCharFormat(fm); - m_tikzEditor->setTabStopWidth(m_tikzEditor->fontMetrics().width(QLatin1String(" "))); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + m_tikzEditor->setTabStopDistance(m_tikzEditor->fontMetrics().horizontalAdvance(QLatin1String(" "))); +#else + m_tikzEditor->setTabStopWidth(m_tikzEditor->fontMetrics().width(QLatin1String(" "))); +#endif } void TikzEditorView::createActions() diff --git a/app/tikzeditorview.h b/app/tikzeditorview.h index fa78937..f9d4fdb 100644 --- a/app/tikzeditorview.h +++ b/app/tikzeditorview.h @@ -92,10 +92,10 @@ private Q_SLOTS: void editReplace(); void tabIndent(bool isUnindenting = false); void indent(QChar insertChar, int numOfInserts, bool isUnindenting = false); - bool search(const QString &text, QTextDocument::FindFlags flags = 0, bool startAtCursor = true, bool continueFromBeginning = false); + bool search(const QString &text, QTextDocument::FindFlags flags = (QTextDocument::FindFlags)0, bool startAtCursor = true, bool continueFromBeginning = false); void search(); void replace(const QString &replacement); - void replace(const QString &text, const QString &replacement, QTextDocument::FindFlags flags = 0, bool startAtCursor = true); + void replace(const QString &text, const QString &replacement, QTextDocument::FindFlags flags = (QTextDocument::FindFlags)0, bool startAtCursor = true); void replace(); void replaceAll(); diff --git a/app/usercommandeditdialog.cpp b/app/usercommandeditdialog.cpp index 4164ef3..60a46d4 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), diff --git a/app/usercommandinserter.cpp b/app/usercommandinserter.cpp index 814c5e3..590ca55 100644 --- a/app/usercommandinserter.cpp +++ b/app/usercommandinserter.cpp @@ -29,7 +29,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) diff --git a/common/common.pri b/common/common.pri index fa96837..5555a10 100644 --- a/common/common.pri +++ b/common/common.pri @@ -1,6 +1,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT *= widgets printsupport +greaterThan(QT_MAJOR_VERSION, 6): QT *= core5compat pdf -include($${_PRO_FILE_PWD_}/qmake/findpoppler.pri) + +#include($${_PRO_FILE_PWD_}/qmake/findpoppler.pri) DEFINES += KTIKZ_TEMPLATES_INSTALL_DIR=\\\"$${TEMPLATES_INSTALL_DIR}\\\" diff --git a/common/tikzpreview.cpp b/common/tikzpreview.cpp index de871f9..a10e4f4 100644 --- a/common/tikzpreview.cpp +++ b/common/tikzpreview.cpp @@ -69,7 +69,11 @@ TikzPreview::TikzPreview(QWidget *parent) createActions(); m_tikzPreviewRenderer = new TikzPreviewRenderer(); - connect(this, SIGNAL(generatePreview(Poppler::Document*,qreal,int)), m_tikzPreviewRenderer, SLOT(generatePreview(Poppler::Document*,qreal,int))); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + connect(this, SIGNAL(generatePreview(QPdfDocument*,qreal,int)), m_tikzPreviewRenderer, SLOT(generatePreview(QPdfDocument*,qreal,int))); +#else + connect(this, SIGNAL(generatePreview(Poppler::Document*,qreal,int)), m_tikzPreviewRenderer, SLOT(generatePreview(Poppler::Document*,qreal,int))); +#endif connect(m_tikzPreviewRenderer, SIGNAL(showPreview(QImage,qreal)), this, SLOT(showPreview(QImage,qreal))); } @@ -95,7 +99,11 @@ void TikzPreview::contextMenuEvent(QContextMenuEvent *event) QSize TikzPreview::sizeHint() const { - const int screenWidth = QApplication::desktop()->availableGeometry().width(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const int screenWidth = QApplication::primaryScreen()->availableGeometry().width(); +#else + const int screenWidth = QApplication::desktop()->availableGeometry().width(); +#endif if (screenWidth > 1200) return QSize(500, 400); else if (screenWidth > 1024) @@ -210,16 +218,28 @@ void TikzPreview::showPreviousPage() if (m_currentPage > 0) --m_currentPage; m_previousPageAction->setEnabled(m_currentPage > 0); - m_nextPageAction->setEnabled(m_currentPage < m_tikzPdfDoc->numPages() - 1); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + m_nextPageAction->setEnabled(m_currentPage < m_tikzPdfDoc->pageCount() - 1); +#else + m_nextPageAction->setEnabled(m_currentPage < m_tikzPdfDoc->numPages() - 1); +#endif showPdfPage(); } void TikzPreview::showNextPage() { - if (m_currentPage < m_tikzPdfDoc->numPages() - 1) +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + if (m_currentPage < m_tikzPdfDoc->pageCount() - 1) +#else + if (m_currentPage < m_tikzPdfDoc->numPages() - 1) +#endif ++m_currentPage; m_previousPageAction->setEnabled(m_currentPage > 0); - m_nextPageAction->setEnabled(m_currentPage < m_tikzPdfDoc->numPages() - 1); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + m_nextPageAction->setEnabled(m_currentPage < m_tikzPdfDoc->pageCount() - 1); +#else + m_nextPageAction->setEnabled(m_currentPage < m_tikzPdfDoc->numPages() - 1); +#endif showPdfPage(); } @@ -246,11 +266,19 @@ void TikzPreview::showPreview(const QImage &tikzImage, qreal zoomFactor) void TikzPreview::showPdfPage() { - if (!m_tikzPdfDoc || m_tikzPdfDoc->numPages() < 1) +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + if (!m_tikzPdfDoc || m_tikzPdfDoc->pageCount() < 1) +#else + if (!m_tikzPdfDoc || m_tikzPdfDoc->numPages() < 1) +#endif + { return; + } if (!m_processRunning) + { Q_EMIT generatePreview(m_tikzPdfDoc, m_zoomFactor, m_currentPage); // render the current pdf page to a QImage in TikzPreviewRenderer (in a different thread) + } } void TikzPreview::emptyPreview() @@ -268,7 +296,11 @@ void TikzPreview::emptyPreview() m_nextPageAction->setVisible(false); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) +void TikzPreview::pixmapUpdated(QPdfDocument *tikzPdfDoc, const QList &tikzCoordinates) +#else void TikzPreview::pixmapUpdated(Poppler::Document *tikzPdfDoc, const QList &tikzCoordinates) +#endif { m_tikzPdfDoc = tikzPdfDoc; m_tikzCoordinates = tikzCoordinates; @@ -279,11 +311,15 @@ void TikzPreview::pixmapUpdated(Poppler::Document *tikzPdfDoc, const QListsetRenderBackend(Poppler::Document::SplashBackend); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const int numOfPages = m_tikzPdfDoc->pageCount(); +#else + m_tikzPdfDoc->setRenderBackend(Poppler::Document::SplashBackend); // m_tikzPdfDoc->setRenderBackend(Poppler::Document::ArthurBackend); - m_tikzPdfDoc->setRenderHint(Poppler::Document::Antialiasing, true); - m_tikzPdfDoc->setRenderHint(Poppler::Document::TextAntialiasing, true); - const int numOfPages = m_tikzPdfDoc->numPages(); + m_tikzPdfDoc->setRenderHint(Poppler::Document::Antialiasing, true); + m_tikzPdfDoc->setRenderHint(Poppler::Document::TextAntialiasing, true); + const int numOfPages = m_tikzPdfDoc->numPages(); +#endif const bool visible = (numOfPages > 1); if (m_pageSeparator) @@ -305,13 +341,17 @@ void TikzPreview::pixmapUpdated(Poppler::Document *tikzPdfDoc, const QListpage(pageNumber); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + const QImage image = m_tikzPdfDoc->render(pageNumber, QSize(xres, yres)); +#else + Poppler::Page *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; + const QImage image = page->renderToImage(xres, yres); // slow + delete page; +#endif return image; } @@ -327,7 +367,11 @@ int TikzPreview::currentPage() const int TikzPreview::numberOfPages() const { - return m_tikzPdfDoc->numPages(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + return m_tikzPdfDoc->pageCount(); +#else + return m_tikzPdfDoc->numPages(); +#endif } /***************************************************************************/ @@ -393,7 +437,11 @@ void TikzPreview::wheelEvent(QWheelEvent *event) { if (event->modifiers() == Qt::ControlModifier) { - if (event->delta() > 0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + if (event->angleDelta().y() > 0) +#else + if (event->delta() > 0) +#endif zoomIn(); else zoomOut(); diff --git a/common/tikzpreview.h b/common/tikzpreview.h index 8d89018..ae91aab 100644 --- a/common/tikzpreview.h +++ b/common/tikzpreview.h @@ -29,10 +29,14 @@ class QToolBar; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) +class QPdfDocument; +#else namespace Poppler { class Document; } +#endif class Action; class ZoomAction; @@ -62,12 +66,20 @@ class TikzPreview : public QGraphicsView public Q_SLOTS: void showPreview(const QImage &tikzImage, qreal zoomFactor = 1.0); - void pixmapUpdated(Poppler::Document *tikzPdfDoc, const QList &tikzCoordinates = QList()); - void showErrorMessage(const QString &message); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + void pixmapUpdated(QPdfDocument *tikzPdfDoc, const QList &tikzCoordinates = QList()); +#else + void pixmapUpdated(Poppler::Document *tikzPdfDoc, const QList &tikzCoordinates = QList()); +#endif + void showErrorMessage(const QString &message); Q_SIGNALS: void showMouseCoordinates(qreal x, qreal y, int precisionX = 5, int precisionY = 5); - void generatePreview(Poppler::Document *tikzPdfDoc, qreal zoomFactor, int currentPage); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + void generatePreview(QPdfDocument *tikzPdfDoc, qreal zoomFactor, int currentPage); +#else + void generatePreview(Poppler::Document *tikzPdfDoc, qreal zoomFactor, int currentPage); +#endif protected: void contextMenuEvent(QContextMenuEvent *event); @@ -104,7 +116,11 @@ private Q_SLOTS: TikzPreviewMessageWidget *m_infoWidget; - Poppler::Document *m_tikzPdfDoc; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + QPdfDocument *m_tikzPdfDoc; +#else + Poppler::Document *m_tikzPdfDoc; +#endif int m_currentPage; qreal m_zoomFactor; qreal m_oldZoomFactor; diff --git a/common/tikzpreviewcontroller.cpp b/common/tikzpreviewcontroller.cpp index df6218d..ad04be0 100644 --- a/common/tikzpreviewcontroller.cpp +++ b/common/tikzpreviewcontroller.cpp @@ -74,8 +74,13 @@ TikzPreviewController::TikzPreviewController(MainWidget *mainWidget) createActions(); qRegisterMetaType >("QList"); - connect(m_tikzPreviewGenerator, SIGNAL(pixmapUpdated(Poppler::Document*,QList)), +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + connect(m_tikzPreviewGenerator, SIGNAL(pixmapUpdated(QPdfDocument*,QList)), + m_tikzPreview, SLOT(pixmapUpdated(QPdfDocument*,QList))); +#else + connect(m_tikzPreviewGenerator, SIGNAL(pixmapUpdated(Poppler::Document*,QList)), m_tikzPreview, SLOT(pixmapUpdated(Poppler::Document*,QList))); +#endif connect(m_tikzPreviewGenerator, SIGNAL(showErrorMessage(QString)), m_tikzPreview, SLOT(showErrorMessage(QString))); connect(m_tikzPreviewGenerator, SIGNAL(setExportActionsEnabled(bool)), diff --git a/common/tikzpreviewgenerator.cpp b/common/tikzpreviewgenerator.cpp index da600fa..9869827 100644 --- a/common/tikzpreviewgenerator.cpp +++ b/common/tikzpreviewgenerator.cpp @@ -35,6 +35,8 @@ #include #if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) #include +#include +#include #else #include #endif @@ -184,7 +186,7 @@ static QString getParsedLogText(QTextStream *logStream) { QString logText; - QRegExp errorPattern(QLatin1String("(\\S*):(\\d+): (.*$)")); + QRegExp errorPattern(QLatin1String("(\\S*):(\\d+): (.*$)")); QList errorMessageList; errorMessageList << QLatin1String("Undefined control sequence") << QLatin1String("LaTeX Warning:") << QLatin1String("LaTeX Error:") @@ -203,7 +205,7 @@ static QString getParsedLogText(QTextStream *logStream) 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+)(.*)")); + QRegExp rx(QLatin1String("^l\\.(\\d+)(.*)")); logLine = logStream->readLine(); while (rx.indexIn(logLine) < 0 && !logStream->atEnd()) { @@ -350,8 +352,13 @@ void TikzPreviewGenerator::createPreview() // Update widget if (m_tikzPdfDoc) delete m_tikzPdfDoc; - m_tikzPdfDoc = Poppler::Document::load(tikzPdfFileInfo.absoluteFilePath()); - if (m_tikzPdfDoc) +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + m_tikzPdfDoc = new QPdfDocument(); + if (m_tikzPdfDoc->load(tikzPdfFileInfo.absoluteFilePath()) == QPdfDocument::NoError) +#else + m_tikzPdfDoc = Poppler::Document::load(tikzPdfFileInfo.absoluteFilePath()); + if (m_tikzPdfDoc) +#endif { m_shortLogText = QLatin1String("[LaTeX] ") + tr("Process finished successfully.", "info process"); Q_EMIT pixmapUpdated(m_tikzPdfDoc, tikzCoordinates(m_tikzFileBaseName)); @@ -512,7 +519,7 @@ static QString createTempTikzFile(const QString &tikzFileBaseName, const QString QTextStream tikzStream(&tikzFile); codecProfile->configureStreamEncoding(tikzStream); - tikzStream << tikzCode << endl; + tikzStream << tikzCode << QLatin1String("\n"); tikzStream.flush(); tikzFile.close(); diff --git a/common/tikzpreviewgenerator.h b/common/tikzpreviewgenerator.h index 696b42c..471478c 100644 --- a/common/tikzpreviewgenerator.h +++ b/common/tikzpreviewgenerator.h @@ -33,11 +33,14 @@ class QProcess; class QPlainEdit; class QTextStream; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) +class QPdfDocument; +#else namespace Poppler { class Document; } - +#endif class TikzPreviewController; /** @@ -75,7 +78,11 @@ public Q_SLOTS: void abortProcess(); Q_SIGNALS: - void pixmapUpdated(Poppler::Document *tikzPdfDoc, const QList &tikzCoordinates = QList()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + void pixmapUpdated(QPdfDocument *tikzPdfDoc, const QList &tikzCoordinates = QList()); +#else + void pixmapUpdated(Poppler::Document *tikzPdfDoc, const QList &tikzCoordinates = QList()); +#endif void setExportActionsEnabled(bool enabled); void showErrorMessage(const QString &message); void updateLog(const QString &logText, bool runFailed); @@ -97,7 +104,11 @@ private Q_SLOTS: bool generatePdfFile(const QString &tikzFileBaseName, const QString &latexCommand, bool useShellEscaping); TikzPreviewController *m_parent; +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) + QPdfDocument *m_tikzPdfDoc; +#else Poppler::Document *m_tikzPdfDoc; +#endif QString m_tikzCode; QThread m_thread; diff --git a/common/tikzpreviewrenderer.cpp b/common/tikzpreviewrenderer.cpp index f8b88c1..3bec589 100644 --- a/common/tikzpreviewrenderer.cpp +++ b/common/tikzpreviewrenderer.cpp @@ -42,11 +42,20 @@ TikzPreviewRenderer::~TikzPreviewRenderer() } } -void TikzPreviewRenderer::generatePreview(Poppler::Document *tikzPdfDoc, qreal zoomFactor, int currentPage) +#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0) +void TikzPreviewRenderer::generatePreview(QPdfDocument *tikzPdfDoc, qreal zoomFactor, int currentPage) { - Poppler::Page *pdfPage = tikzPdfDoc->page(currentPage); - const QImage tikzImage = pdfPage->renderToImage(zoomFactor * 72, zoomFactor * 72); - delete pdfPage; + const QImage tikzImage = tikzPdfDoc->render(currentPage, QSize(zoomFactor * 72, zoomFactor * 72)); Q_EMIT showPreview(tikzImage, zoomFactor); } +#else +void TikzPreviewRenderer::generatePreview(Poppler::Document *tikzPdfDoc, qreal zoomFactor, int currentPage) +{ + Poppler::Page *pdfPage = tikzPdfDoc->page(currentPage); + const QImage tikzImage = pdfPage->renderToImage(zoomFactor * 72, zoomFactor * 72); + delete pdfPage; + + Q_EMIT showPreview(tikzImage, zoomFactor); +} +#endif diff --git a/doc/qtikz.qch b/doc/qtikz.qch new file mode 100644 index 0000000..c303b7b Binary files /dev/null and b/doc/qtikz.qch differ diff --git a/doc/qtikz.qhc b/doc/qtikz.qhc new file mode 100644 index 0000000..95309dc Binary files /dev/null and b/doc/qtikz.qhc differ diff --git a/qmake/findpoppler.pri b/qmake/findpoppler.pri deleted file mode 100644 index 8ad1103..0000000 --- a/qmake/findpoppler.pri +++ /dev/null @@ -1,25 +0,0 @@ -unix: { -# QMAKE_CXXFLAGS += `pkg-config --cflags poppler-qt4` -# QMAKE_LFLAGS += `pkg-config --libs poppler-qt4` # using this, qmake adds 3 times "--libs" to the LFLAGS, which is not recognized by g++ 4.6 - PKG_CONFIG = $$pkgConfigExecutable() - greaterThan(QT_MAJOR_VERSION, 4) { - POPPLERINCLUDES = $$system($$PKG_CONFIG --cflags poppler-qt5) - POPPLERLIBS = $$system($$PKG_CONFIG --libs poppler-qt5) - } else { - POPPLERINCLUDES = $$system($$PKG_CONFIG --cflags poppler-qt4) - POPPLERLIBS = $$system($$PKG_CONFIG --libs poppler-qt4) - } - QMAKE_CXXFLAGS += $$POPPLERINCLUDES - QMAKE_LFLAGS += $$POPPLERLIBS -} - -win32 { - INCLUDEPATH += $${_PRO_FILE_PWD_}/app $${_PRO_FILE_PWD_}/win32/poppler - LIBS += -L$${_PRO_FILE_PWD_}/win32/poppler/ -} - -greaterThan(QT_MAJOR_VERSION, 4) { - LIBS += -lpoppler-qt5 -} else { - LIBS += -lpoppler-qt4 -} diff --git a/qmake/qtikzconfig.pri b/qmake/qtikzconfig.pri index 5ee737b..d9bb058 100644 --- a/qmake/qtikzconfig.pri +++ b/qmake/qtikzconfig.pri @@ -40,10 +40,10 @@ #MAN_INSTALL_DIR = $${PREFIX}/share/man # compile in debug mode: -#CONFIG += debug +CONFIG += debug # compile in release mode: -CONFIG -= debug -CONFIG += release +#CONFIG -= debug +#CONFIG += release # Qt commands (uncomment if needed) # qmake command: diff --git a/qmake/qtikzmacros.pri b/qmake/qtikzmacros.pri index 1537fad..98ebe0b 100644 --- a/qmake/qtikzmacros.pri +++ b/qmake/qtikzmacros.pri @@ -4,15 +4,15 @@ unix:!macx { # QMAKE_CXXFLAGS += `pkg-config --cflags poppler-qt4` # QMAKE_LFLAGS += `pkg-config --libs poppler-qt4` # using this, qmake adds 3 times "--libs" to the LFLAGS, which is not recognized by g++ 4.6 PKG_CONFIG = $$pkgConfigExecutable() - greaterThan(QT_MAJOR_VERSION, 4) { - POPPLERINCLUDES = $$system($$PKG_CONFIG --cflags poppler-qt5) - POPPLERLIBS = $$system($$PKG_CONFIG --libs poppler-qt5) - } else { - POPPLERINCLUDES = $$system($$PKG_CONFIG --cflags poppler-qt4) - POPPLERLIBS = $$system($$PKG_CONFIG --libs poppler-qt4) - } - QMAKE_CXXFLAGS += $$POPPLERINCLUDES - QMAKE_LFLAGS += $$POPPLERLIBS +# greaterThan(QT_MAJOR_VERSION, 4) { +# POPPLERINCLUDES = $$system($$PKG_CONFIG --cflags poppler-qt5) +# POPPLERLIBS = $$system($$PKG_CONFIG --libs poppler-qt5) +# } else { +# POPPLERINCLUDES = $$system($$PKG_CONFIG --cflags poppler-qt4) +# POPPLERLIBS = $$system($$PKG_CONFIG --libs poppler-qt4) +# } +# QMAKE_CXXFLAGS += $$POPPLERINCLUDES +# QMAKE_LFLAGS += $$POPPLERLIBS } # Functions diff --git a/qtikz.pro b/qtikz.pro index 3dd09b5..f02f561 100644 --- a/qtikz.pro +++ b/qtikz.pro @@ -10,7 +10,6 @@ APPVERSION = 0.12 include(qmake/qtikzconfig.pri) include(qmake/qtikzdefaults.pri) include(qmake/qtikzmacros.pri) -include(qmake/findpoppler.pri) include(app/app.pri) include(translations/translations.pri) diff --git a/qtikz.pro.user b/qtikz.pro.user new file mode 100644 index 0000000..ef9ce76 --- /dev/null +++ b/qtikz.pro.user @@ -0,0 +1,270 @@ + + + + + + EnvironmentId + {e92ae61b-ee59-4440-808d-f6274b00be67} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.3.0 GCC 64bit + Desktop Qt 6.3.0 GCC 64bit + qt.qt6.630.gcc_64_kit + 0 + 0 + 0 + + 0 + /home/anovitsk/Projects/build-qtikz-Desktop_Qt_6_3_0_GCC_64bit-Debug + /home/anovitsk/Projects/build-qtikz-Desktop_Qt_6_3_0_GCC_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + PATH=/home/anovitsk/Qt/6.3.0/gcc_64/bin:/home/anovitsk/Qt/Tools/QtDesignStudio/qt5_design_studio_reduced_version/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Users/anovitsk/AppData/Roaming/MobaXterm/slash/bin:/mnt/c/windows/:/mnt/c/windows/system32/:/mnt/c/windows/system32:/mnt/c/windows:/mnt/c/windows/System32/Wbem:/mnt/c/windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Users/anovitsk/AppData/Local/Microsoft/WindowsApps:/mnt/c/windows/sysnative/:/snap/bin + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/anovitsk/Projects/build-qtikz-Desktop_Qt_6_3_0_GCC_64bit-Release + /home/anovitsk/Projects/build-qtikz-Desktop_Qt_6_3_0_GCC_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /home/anovitsk/Projects/build-qtikz-Desktop_Qt_6_3_0_GCC_64bit-Profile + /home/anovitsk/Projects/build-qtikz-Desktop_Qt_6_3_0_GCC_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/home/anovitsk/Projects/KTikz/qtikz.pro + /home/anovitsk/Projects/KTikz/qtikz.pro + false + true + true + false + true + /home/anovitsk/Projects/build-qtikz-Desktop_Qt_6_3_0_GCC_64bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + +