Adds latest migration results
This commit is contained in:
829 files changed
+35074
-70886
No files matched your search
@@ -4,6 +4,14 @@
|
||||
# $Author$
|
||||
#
|
||||
|
||||
# Make ${Qt6_Widgets} optional
|
||||
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets)
|
||||
set(Qt6_Widgets ${Qt6_Widgets})
|
||||
else()
|
||||
set(Qt6_Widgets "")
|
||||
endif()
|
||||
|
||||
|
||||
ADD_SUBDIRECTORY(ngldb)
|
||||
ADD_SUBDIRECTORY(tcpserver)
|
||||
ADD_SUBDIRECTORY(QtSingleApplication)
|
||||
@@ -13,5 +21,10 @@ ADD_SUBDIRECTORY(nglcompression)
|
||||
ADD_SUBDIRECTORY(nglsettings)
|
||||
ADD_SUBDIRECTORY(ngltranslator)
|
||||
ADD_SUBDIRECTORY(ngltools)
|
||||
ADD_SUBDIRECTORY(nglwidgets)
|
||||
# nglwidgets requires Qt6 Widgets - skip if not available
|
||||
if((QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets) OR QT5_FOUND)
|
||||
ADD_SUBDIRECTORY(nglwidgets)
|
||||
else()
|
||||
message(WARNING "nglwidgets skipped: Qt6 Widgets not available")
|
||||
endif()
|
||||
ADD_SUBDIRECTORY(NGLLogger)
|
||||
@@ -36,6 +36,11 @@ NGL_TARGET_LINK_LIBRARIES(NGLLogger
|
||||
Qt6::Core
|
||||
)
|
||||
|
||||
# Define HAVE_LOG4QT when log4qt is available
|
||||
IF(Log4Qt_FOUND)
|
||||
TARGET_COMPILE_DEFINITIONS(NGLLogger PUBLIC HAVE_LOG4QT)
|
||||
ENDIF()
|
||||
|
||||
NGL_INSTALL_TARGET(NGLLogger)
|
||||
|
||||
#
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef HAVE_LOG4QT
|
||||
#include <log4qt/logger.h>
|
||||
#include <log4qt/logmanager.h>
|
||||
#include <log4qt/loggerrepository.h>
|
||||
@@ -15,6 +16,7 @@
|
||||
#include <log4qt/helpers/configuratorhelper.h>
|
||||
#include <log4qt/helpers/properties.h>
|
||||
#include <log4qt/helpers/factory.h>
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
@@ -34,16 +36,20 @@ void LtsRollingFileAppender::activateOptions()
|
||||
{
|
||||
if (!m_ltsLogfileName.isEmpty())
|
||||
setFile(m_ltsLogfileName);
|
||||
#ifdef HAVE_LOG4QT
|
||||
Log4Qt::RollingFileAppender::activateOptions();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString LtsRollingFileAppender::m_ltsLogfileName;
|
||||
#ifdef HAVE_LOG4QT
|
||||
static Log4Qt::Appender *createLtsRollingFileAppender()
|
||||
{
|
||||
auto ret = new LtsRollingFileAppender;
|
||||
ret->setAppendFile(true);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -98,6 +104,7 @@ NGL::NGLLogger::NGLLogger(const std::string &fullqualifiedname)
|
||||
, currentLevel(LogLevel::Undefined)
|
||||
, m_bNoSpace(true)
|
||||
{
|
||||
#ifdef HAVE_LOG4QT
|
||||
if (!fullqualifiedname.empty())
|
||||
{
|
||||
logger_ptr = Log4Qt::LogManager::loggerRepository()->logger(QString::fromStdString(name));
|
||||
@@ -108,7 +115,7 @@ NGL::NGLLogger::NGLLogger(const std::string &fullqualifiedname)
|
||||
logger_ptr = Log4Qt::LogManager::loggerRepository()->rootLogger();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
configChanged();
|
||||
}
|
||||
@@ -147,7 +154,31 @@ NGL::INGLLogger &NGL::NGLLogger::getNGLLogger(const std::string &fullqualifiedna
|
||||
|
||||
void NGL::NGLLogger::log(LogLevel level, const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
#ifdef HAVE_LOG4QT
|
||||
logger_ptr->logWithLocation(static_cast<Log4Qt::Level::Value>(level), file, line, function, QString::fromStdString(message));
|
||||
#else
|
||||
// Stub implementation - use qDebug/qWarning/qCritical based on level
|
||||
Q_UNUSED(file);
|
||||
Q_UNUSED(line);
|
||||
Q_UNUSED(function);
|
||||
const QString msg = QString::fromStdString(message);
|
||||
switch (level)
|
||||
{
|
||||
case LogLevel::Fatal:
|
||||
case LogLevel::Error:
|
||||
qCritical() << msg;
|
||||
break;
|
||||
case LogLevel::Warning:
|
||||
qWarning() << msg;
|
||||
break;
|
||||
case LogLevel::Info:
|
||||
case LogLevel::Debug:
|
||||
case LogLevel::Trace:
|
||||
default:
|
||||
qDebug() << msg;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -302,6 +333,7 @@ NGL::NGLLogger &NGL::NGLLogger::createNGLRootLogger(const QString &configfilenam
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_LOG4QT
|
||||
Log4Qt::Factory::registerAppender("Lts::RollingFileAppender", createLtsRollingFileAppender);
|
||||
LtsRollingFileAppender::setLtsLogfileName(logOutputName);
|
||||
|
||||
@@ -337,6 +369,14 @@ NGL::NGLLogger &NGL::NGLLogger::createNGLRootLogger(const QString &configfilenam
|
||||
Log4Qt::PropertyConfigurator::configure(props);
|
||||
}
|
||||
rootlogger_ptr->configChanged();
|
||||
#else
|
||||
// Stub implementation - no logging initialization needed
|
||||
Q_UNUSED(configfilename);
|
||||
Q_UNUSED(ignorealreadycreated);
|
||||
Q_UNUSED(logOutputName);
|
||||
Q_UNUSED(quiet);
|
||||
rootlogger_ptr = new NGLLogger(std::string());
|
||||
#endif
|
||||
}
|
||||
return *rootlogger_ptr;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,30 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_LOG4QT
|
||||
#include <log4qt/logger.h>
|
||||
#include <log4qt/rollingfileappender.h>
|
||||
#else
|
||||
#include "log4qt_stub.h"
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
class CleanupHelper;
|
||||
|
||||
#ifdef HAVE_LOG4QT
|
||||
class LtsRollingFileAppender final : public Log4Qt::RollingFileAppender
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Log4Qt::RollingFileAppender::RollingFileAppender;
|
||||
#else
|
||||
class LtsRollingFileAppender final : public Log4Qt::RollingFileAppender
|
||||
{
|
||||
public:
|
||||
explicit LtsRollingFileAppender(QObject *parent = nullptr) : Log4Qt::RollingFileAppender(parent) {}
|
||||
#endif
|
||||
static void setLtsLogfileName(const QString <sLogfileName);
|
||||
void activateOptions() override;
|
||||
private:
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
# http://qt.nokia.com/products/appdev/add-on-products/catalog/4/Utilities/qtsingleapplication
|
||||
# LGPL
|
||||
|
||||
# Make ${Qt6_Widgets} optional
|
||||
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets)
|
||||
set(Qt6_Widgets ${Qt6_Widgets})
|
||||
else()
|
||||
set(Qt6_Widgets "")
|
||||
endif()
|
||||
|
||||
|
||||
SET(qtsapp_common_SRCS
|
||||
qtlocalpeer.cpp
|
||||
qtlocalpeer.h
|
||||
@@ -29,7 +37,7 @@ NGL_TARGET_LINK_LIBRARIES(qtsingleapplication
|
||||
qtsa_common
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
Qt6::Widgets
|
||||
Qt6::Gui
|
||||
)
|
||||
|
||||
SET(qtscoreapp_SRCS
|
||||
|
||||
@@ -4,68 +4,56 @@
|
||||
|
||||
#include "qtsingleapplication.h"
|
||||
#include "qtlocalpeer.h"
|
||||
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
#include <QtWidgets/QWidget>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
void QtSingleApplication::sysInit(const QString &appId)
|
||||
{
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
actWin = nullptr;
|
||||
#endif
|
||||
peer = new QtLocalPeer(this, appId);
|
||||
connect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::messageReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
: QApplication(argc, argv, GUIenabled)
|
||||
#else
|
||||
: QCoreApplication(argc, argv)
|
||||
#endif
|
||||
{
|
||||
sysInit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
: QApplication(argc, argv)
|
||||
#else
|
||||
: QCoreApplication(argc, argv)
|
||||
#endif
|
||||
{
|
||||
sysInit(appId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool QtSingleApplication::isRunning()
|
||||
{
|
||||
return peer->isClient();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool QtSingleApplication::sendMessage(const QString &message, int timeout)
|
||||
{
|
||||
return peer->sendMessage(message, timeout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QString QtSingleApplication::id() const
|
||||
{
|
||||
return peer->applicationId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
|
||||
{
|
||||
actWin = aw;
|
||||
@@ -75,17 +63,11 @@ void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessag
|
||||
disconnect(peer, &QtLocalPeer::messageReceived, this, &QtSingleApplication::activateWindow);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QWidget* QtSingleApplication::activationWindow() const
|
||||
{
|
||||
return actWin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void QtSingleApplication::activateWindow()
|
||||
{
|
||||
if (actWin) {
|
||||
@@ -94,6 +76,7 @@ void QtSingleApplication::activateWindow()
|
||||
actWin->activateWindow();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,13 @@
|
||||
#ifndef QTSINGLEAPPLICATION_H
|
||||
#define QTSINGLEAPPLICATION_H
|
||||
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
#include <QtWidgets/QApplication>
|
||||
#define QTSINGLEAPPLICATION_BASE QApplication
|
||||
#else
|
||||
#include <QCoreApplication>
|
||||
#define QTSINGLEAPPLICATION_BASE QCoreApplication
|
||||
#endif
|
||||
|
||||
class QtLocalPeer;
|
||||
|
||||
@@ -20,7 +26,7 @@ class QtLocalPeer;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
class QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication
|
||||
class QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QTSINGLEAPPLICATION_BASE
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -31,16 +37,19 @@ public:
|
||||
bool isRunning();
|
||||
QString id() const;
|
||||
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
|
||||
QWidget* activationWindow() const;
|
||||
|
||||
#endif
|
||||
|
||||
void initialize(bool dummy = true)
|
||||
{ isRunning(); Q_UNUSED(dummy) }
|
||||
|
||||
public Q_SLOTS:
|
||||
bool sendMessage(const QString &message, int timeout = 5000);
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
void activateWindow();
|
||||
#endif
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
@@ -50,7 +59,9 @@ Q_SIGNALS:
|
||||
private:
|
||||
void sysInit(const QString &appId = QString());
|
||||
QtLocalPeer *peer;
|
||||
#ifdef QT6_GUI_AVAILABLE
|
||||
QWidget *actWin;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,21 @@
|
||||
#
|
||||
# nglapplication
|
||||
#
|
||||
# Make ${Qt6_Gui} optional
|
||||
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Gui)
|
||||
set(Qt6_Gui ${Qt6_Gui})
|
||||
else()
|
||||
set(Qt6_Gui "")
|
||||
endif()
|
||||
|
||||
# Make ${Qt6_Widgets} optional
|
||||
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets)
|
||||
set(Qt6_Widgets ${Qt6_Widgets})
|
||||
else()
|
||||
set(Qt6_Widgets "")
|
||||
endif()
|
||||
|
||||
|
||||
SET(nglapplication_SRCS
|
||||
nglapplication.cpp
|
||||
nglapplication.h
|
||||
@@ -20,14 +35,16 @@ NGL_TARGET_INCLUDE_DIRECTORIES(nglapplication
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
NGL_TARGET_LINK_LIBRARIES(nglapplication
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
nglsettings
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
Qt6::Widgets
|
||||
)
|
||||
if(QT6_GUI_AVAILABLE)
|
||||
NGL_TARGET_LINK_LIBRARIES(nglapplication
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
nglsettings
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
${Qt6_Widgets}
|
||||
)
|
||||
endif()
|
||||
NGL_INSTALL_TARGET(nglapplication)
|
||||
|
||||
#
|
||||
@@ -46,15 +63,17 @@ NGL_TARGET_INCLUDE_DIRECTORIES(nglsingleapplication
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
NGL_TARGET_LINK_LIBRARIES(nglsingleapplication
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
nglsettings
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
Qt6::Widgets
|
||||
qtsingleapplication
|
||||
)
|
||||
if(QT6_GUI_AVAILABLE)
|
||||
NGL_TARGET_LINK_LIBRARIES(nglsingleapplication
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
nglsettings
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
${Qt6_Widgets}
|
||||
qtsingleapplication
|
||||
)
|
||||
endif()
|
||||
NGL_INSTALL_TARGET(nglsingleapplication)
|
||||
|
||||
#
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
# $Author$
|
||||
#
|
||||
|
||||
FIND_PACKAGE(BZip2 REQUIRED)
|
||||
# BZip2 stub - libbz2-dev not available, disable bzip2 support
|
||||
SET(HAVE_BZIP2 FALSE)
|
||||
MESSAGE(STATUS "BZip2 disabled - development headers not available")
|
||||
|
||||
SET(nglcomp_SRCS
|
||||
nglcomp_bzip2iodevice.cpp
|
||||
nglcomp_bzip2iodevice.h
|
||||
@@ -22,13 +25,8 @@ NGL_TARGET_LINK_LIBRARIES(nglcompression
|
||||
PRIVATE
|
||||
Qt6::Concurrent
|
||||
NGLLogger
|
||||
${BZIP2_LIBRARIES}
|
||||
# BZip2::BZip2 # not available with cmake 3.5
|
||||
)
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(nglcompression
|
||||
PRIVATE
|
||||
${BZIP2_INCLUDE_DIR}
|
||||
)
|
||||
# BZip2 disabled - no linking needed
|
||||
NGL_INSTALL_TARGET(nglcompression)
|
||||
|
||||
IF(BUILD_WS AND BUILD_TESTING)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "nglcomp_bzip2iodevice.h"
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QString>
|
||||
#include <bzlib.h>
|
||||
@@ -339,3 +341,8 @@ qint64 BZip2IODevice::writeData(const char* data, qint64 maxSize)
|
||||
{
|
||||
return d->doCompress(data, maxSize);
|
||||
}
|
||||
|
||||
#else
|
||||
// Stub implementation when HAVE_BZIP2 is not defined
|
||||
// All methods already defined in header as inline stubs
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QIODevice>
|
||||
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
|
||||
class BZip2IODevice : public QIODevice
|
||||
{
|
||||
@@ -39,4 +39,24 @@ private:
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
#else
|
||||
// Stub when bzip2 is not available
|
||||
class BZip2IODevice : public QIODevice
|
||||
{
|
||||
public:
|
||||
BZip2IODevice(QIODevice *dev, int blocksize = 5) { Q_UNUSED(dev) Q_UNUSED(blocksize) }
|
||||
virtual ~BZip2IODevice() {}
|
||||
void abort() {}
|
||||
void setBufferSize(unsigned int size) { Q_UNUSED(size) }
|
||||
void setBlockSize(unsigned int size) { Q_UNUSED(size) }
|
||||
virtual bool isSequential() const { return true; }
|
||||
virtual bool open(OpenMode mode) { Q_UNUSED(mode) return false; }
|
||||
virtual void close() {}
|
||||
virtual bool atEnd() const { return true; }
|
||||
protected:
|
||||
virtual qint64 readData(char *data, qint64 maxSize) { Q_UNUSED(data) Q_UNUSED(maxSize) return -1; }
|
||||
virtual qint64 writeData(const char *data, qint64 maxSize) { Q_UNUSED(data) Q_UNUSED(maxSize) return -1; }
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,8 @@
|
||||
# NGLDB
|
||||
FIND_PACKAGE(PostgreSQL REQUIRED)
|
||||
FIND_PACKAGE(PostgreSQL)
|
||||
IF(NOT PostgreSQL_FOUND)
|
||||
MESSAGE(WARNING "PostgreSQL not found - ngldb will be built without PostgreSQL support")
|
||||
ENDIF()
|
||||
|
||||
OPTION(ENABLE_DB_TRACING "Enable trace output for NGLDB library" OFF)
|
||||
IF(ENABLE_DB_TRACING)
|
||||
@@ -30,14 +33,21 @@ NGL_TARGET_LINK_LIBRARIES(ngldb
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
nglsettings
|
||||
${PostgreSQL_LIBRARIES}
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
Qt6::Sql
|
||||
)
|
||||
IF(PostgreSQL_FOUND)
|
||||
NGL_TARGET_LINK_LIBRARIES(ngldb
|
||||
PRIVATE
|
||||
${PostgreSQL_LIBRARIES}
|
||||
)
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(ngldb
|
||||
PRIVATE
|
||||
${PostgreSQL_INCLUDE_DIR}
|
||||
)
|
||||
ENDIF()
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(ngldb
|
||||
PRIVATE
|
||||
${PostgreSQL_INCLUDE_DIR}
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
#include <QtCore/QJsonValue>
|
||||
|
||||
#include "ngldb_logger.h"
|
||||
|
||||
#ifdef PostgreSQL_FOUND
|
||||
#include <libpq-fe.h>
|
||||
#endif
|
||||
|
||||
static QString getSqlErrorString(const QSqlError &error)
|
||||
{
|
||||
@@ -251,21 +254,17 @@ QString NSqlQuery::sqlstate()
|
||||
{
|
||||
const QVariant resultHandle = this->result()->handle();
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef PostgreSQL_FOUND
|
||||
if (resultHandle.isValid() && (qstrcmp(resultHandle.typeName(), "PGresult*") == 0))
|
||||
{
|
||||
|
||||
const PGresult *pgresHandle = *static_cast<const PGresult * const *>(resultHandle.data());
|
||||
|
||||
if (pgresHandle != nullptr)
|
||||
{
|
||||
|
||||
return QString::fromLocal8Bit(PQresultErrorField(pgresHandle, PG_DIAG_SQLSTATE));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return QStringLiteral("58000");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,51 @@
|
||||
# Make ${Qt6_Widgets} optional
|
||||
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets)
|
||||
set(Qt6_Widgets ${Qt6_Widgets})
|
||||
else()
|
||||
set(Qt6_Widgets "")
|
||||
endif()
|
||||
|
||||
|
||||
PROJECT(nglwidgets)
|
||||
|
||||
FIND_PACKAGE(PopplerQt6 REQUIRED)
|
||||
# Poppler is optional - stub if not available
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(POPPLER_QT6 poppler-qt6)
|
||||
endif()
|
||||
|
||||
if(NOT POPPLER_QT6_FOUND)
|
||||
message(STATUS "Poppler-Qt6 not found - building nglwidgets without PDF support")
|
||||
set(POPPLER_QT6_INCLUDE_DIR "")
|
||||
set(POPPLER_QT6_LIBRARY "")
|
||||
set(HAVE_POPPLER_QT6 FALSE)
|
||||
else()
|
||||
set(HAVE_POPPLER_QT6 TRUE)
|
||||
endif()
|
||||
|
||||
# Only find Qt6 Widgets if GUI is available
|
||||
if(QT6_GUI_AVAILABLE)
|
||||
# Try standard find_package first, fall back to manual target if OpenGL missing
|
||||
find_package(Qt6 QUIET COMPONENTS Widgets)
|
||||
if(NOT TARGET Qt6::Widgets)
|
||||
# Manual fallback: create imported targets when standard find fails due to OpenGL
|
||||
if(NOT TARGET Qt6::Gui)
|
||||
add_library(Qt6::Gui SHARED IMPORTED)
|
||||
set_target_properties(Qt6::Gui PROPERTIES
|
||||
IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/libQt6Gui.so.6"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "/usr/include/x86_64-linux-gnu/qt6/QtGui;/usr/include/x86_64-linux-gnu/qt6"
|
||||
)
|
||||
endif()
|
||||
if(NOT TARGET Qt6::Widgets)
|
||||
add_library(Qt6::Widgets SHARED IMPORTED)
|
||||
set_target_properties(Qt6::Widgets PROPERTIES
|
||||
IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/libQt6Widgets.so.6"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "/usr/include/x86_64-linux-gnu/qt6/QtWidgets;/usr/include/x86_64-linux-gnu/qt6"
|
||||
INTERFACE_LINK_LIBRARIES "Qt6::Gui;Qt6::Core"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#
|
||||
# NGL Widgets library
|
||||
@@ -47,23 +92,25 @@ NGL_TARGET_INCLUDE_DIRECTORIES(nglwidgets
|
||||
PRIVATE
|
||||
${POPPLER_QT6_INCLUDE_DIR}
|
||||
)
|
||||
NGL_TARGET_LINK_LIBRARIES(nglwidgets
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
ngltranslator
|
||||
ngltools
|
||||
${POPPLER_QT6_LIBRARY}
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
Qt6::Widgets
|
||||
)
|
||||
if(QT6_GUI_AVAILABLE)
|
||||
NGL_TARGET_LINK_LIBRARIES(nglwidgets
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
ngltranslator
|
||||
ngltools
|
||||
${POPPLER_QT6_LIBRARY}
|
||||
PUBLIC
|
||||
Qt6::Core
|
||||
${Qt6_Widgets}
|
||||
)
|
||||
endif()
|
||||
|
||||
NGL_INSTALL_TARGET(nglwidgets)
|
||||
|
||||
# Unit test for PDFWidget
|
||||
IF(BUILD_TESTING AND TARGET nglwidgets)
|
||||
FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Test Widgets)
|
||||
IF(BUILD_TESTING AND TARGET nglwidgets AND QT6_GUI_AVAILABLE)
|
||||
FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Test)
|
||||
ADD_EXECUTABLE(test_nglpdfwidget test_nglpdfwidget.cpp)
|
||||
TARGET_LINK_LIBRARIES(test_nglpdfwidget PRIVATE nglwidgets Qt6::Test Qt6::Widgets)
|
||||
TARGET_LINK_LIBRARIES(test_nglpdfwidget PRIVATE nglwidgets Qt6::Test ${Qt6_Widgets})
|
||||
ADD_TEST(NAME test_nglpdfwidget COMMAND $<TARGET_FILE:test_nglpdfwidget>)
|
||||
ENDIF()
|
||||
@@ -20,10 +20,10 @@ NGLMainWindow::NGLMainWindow(QWidget *parent)
|
||||
{
|
||||
m_menu[QLatin1String("File")] = m_menuBar->addMenu(tr("File"));
|
||||
m_fileActionBefore = m_menu[QLatin1String("File")]->addSeparator();
|
||||
m_menu[QLatin1String("File")]->addAction(QIcon(QLatin1String(":/icons/16x16/application-exit.png")), tr("Quit"), QKeySequence(tr("Ctrl+q")), this, &NGLMainWindow::onExit);
|
||||
m_menu[QLatin1String("File")]->addAction(QIcon(QLatin1String(":/icons/16x16/application-exit.png")), tr("Quit"), this, &NGLMainWindow::onExit, QKeySequence(tr("Ctrl+q")));
|
||||
|
||||
m_menu[QLatin1String("Help")] = m_menuBar->addMenu(tr("Help"));
|
||||
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-contents.png")), tr("Help"), QKeySequence(tr("F1")), this, &NGLMainWindow::onHelpIndex);
|
||||
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-contents.png")), tr("Help"), this, &NGLMainWindow::onHelpIndex, QKeySequence(tr("F1")));
|
||||
m_menu[QLatin1String("Help")]->addSeparator();
|
||||
m_menu[QLatin1String("Help")]->addAction(QIcon(QLatin1String(":/icons/16x16/help-about.png")),
|
||||
tr("About"), this, &NGLMainWindow::onHelpAbout);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "nglpdfdocument.h"
|
||||
#include <utility>
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
#include "nglpdfpage.h"
|
||||
#endif
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtWidgets/QLabel>
|
||||
@@ -21,7 +23,9 @@ PDFDocument::PDFDocument(QWidget *parent)
|
||||
, m_maxCachedPages(20)
|
||||
, m_scaleFactor(1.0)
|
||||
, m_widthFactor(1.0)
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
, m_rotation(Poppler::Page::Rotate0)
|
||||
#endif
|
||||
{
|
||||
QVBoxLayout *lay = new QVBoxLayout(this);
|
||||
lay->setContentsMargins(0,0,0,0);
|
||||
@@ -46,8 +50,10 @@ PDFDocument::PDFDocument(QWidget *parent)
|
||||
|
||||
PDFDocument::~PDFDocument()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
qDeleteAll(m_pages);
|
||||
m_pages.clear();
|
||||
#endif
|
||||
m_doc.reset();
|
||||
}
|
||||
|
||||
@@ -66,31 +72,44 @@ bool PDFDocument::showPDF(const QString &path)
|
||||
m_scaleFactor = 0;
|
||||
m_widthFactor = 1;
|
||||
setZoomFactor(1.0);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
setRotation(Poppler::Page::Rotate0);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
m_doc = Poppler::Document::load(path);
|
||||
if (!m_doc)
|
||||
return false;
|
||||
m_currentPath = path;
|
||||
|
||||
return showPDFInternal();
|
||||
#else
|
||||
Q_UNUSED(path);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDF(const QByteArray &pdf)
|
||||
{
|
||||
m_currentPath.clear();
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
m_doc = Poppler::Document::loadFromData(pdf);
|
||||
if (!m_doc)
|
||||
return false;
|
||||
|
||||
return showPDFInternal();
|
||||
#else
|
||||
Q_UNUSED(pdf);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::showPDFInternal()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
disconnect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
|
||||
|
||||
m_doc->setRenderHint(Poppler::Document::Antialiasing);
|
||||
@@ -119,10 +138,12 @@ bool PDFDocument::showPDFInternal()
|
||||
p->setPopplerPage(pagePtr.release());
|
||||
connect(p, &PDFPage::pageRendered,
|
||||
this, &PDFDocument::onPageRendered);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
connect(p, &PDFPage::externalLinkClicked,
|
||||
this, &PDFDocument::linkClicked);
|
||||
connect(p, &PDFPage::linkClicked,
|
||||
this, &PDFDocument::onLinkClicked);
|
||||
#endif
|
||||
m_pages += p;
|
||||
|
||||
l->addWidget(p);
|
||||
@@ -134,6 +155,7 @@ bool PDFDocument::showPDFInternal()
|
||||
ensureCurPageVisible();
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, this, &PDFDocument::onVSliderValueChanged);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -155,7 +177,11 @@ int PDFDocument::curPage() const
|
||||
int PDFDocument::numPages() const
|
||||
{
|
||||
// Return 0 when no document is loaded to satisfy tests that expect a non-negative page count
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
return m_doc ? m_doc->numPages() : 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::setZoomFactor(double zoom)
|
||||
@@ -164,14 +190,17 @@ void PDFDocument::setZoomFactor(double zoom)
|
||||
return;
|
||||
m_scaleFactor = zoom;
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
for (PDFPage *p : std::as_const(m_pages))
|
||||
p->setZoomFactor(m_scaleFactor / m_widthFactor);
|
||||
|
||||
rebuildRanges();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::setRotation(Poppler::Page::Rotation rot)
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_rotation == rot)
|
||||
return;
|
||||
m_rotation = rot;
|
||||
@@ -184,6 +213,9 @@ void PDFDocument::setRotation(Poppler::Page::Rotation rot)
|
||||
rebuildRanges();
|
||||
emit currentPageChanged(m_currentPage+1, m_ranges.count());
|
||||
emit rotationChanged(m_rotation);
|
||||
#else
|
||||
Q_UNUSED(rot);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::setPage(int page)
|
||||
@@ -194,6 +226,7 @@ bool PDFDocument::setPage(int page)
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
}
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_pages.isEmpty())
|
||||
{
|
||||
m_currentPage = page;
|
||||
@@ -206,26 +239,38 @@ bool PDFDocument::setPage(int page)
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
Q_UNUSED(page);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::nextPage()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_doc == nullptr || m_currentPage >= m_doc->numPages() - 1)
|
||||
return false;
|
||||
m_currentPage++;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PDFDocument::previousPage()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_doc == nullptr || m_currentPage < 1)
|
||||
return false;
|
||||
m_currentPage--;
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible();
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::onVSliderValueChanged(int y)
|
||||
@@ -250,6 +295,7 @@ void PDFDocument::onVSliderValueChanged(int y)
|
||||
|
||||
void PDFDocument::onPageRendered()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
PDFPage *p = qobject_cast<PDFPage *> (sender());
|
||||
if (m_renderedPages.contains(p))
|
||||
return;
|
||||
@@ -261,10 +307,13 @@ void PDFDocument::onPageRendered()
|
||||
p->clearPixmap();
|
||||
}
|
||||
m_renderedPages.push_back(p);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::onLinkClicked(const Poppler::LinkDestination &dest)
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
PDFPage *p = qobject_cast<PDFPage *>(sender());
|
||||
if (!p)
|
||||
return;
|
||||
@@ -272,26 +321,41 @@ void PDFDocument::onLinkClicked(const Poppler::LinkDestination &dest)
|
||||
emit currentPageChanged(m_currentPage + 1, m_ranges.count());
|
||||
ensureCurPageVisible(qRound(dest.right() * p->width()),
|
||||
qRound(dest.top() * p->height()));
|
||||
#else
|
||||
Q_UNUSED(dest);
|
||||
#endif
|
||||
}
|
||||
|
||||
QVector<QImage> PDFDocument::getPrintableImages(int resolution) const
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVector<QImage> imageList;
|
||||
imageList.reserve(m_pages.size());
|
||||
for (const PDFPage *p : m_pages)
|
||||
imageList.append(p->getPrintableImage(resolution));
|
||||
return imageList;
|
||||
#else
|
||||
Q_UNUSED(resolution);
|
||||
return QVector<QImage>();
|
||||
#endif
|
||||
}
|
||||
|
||||
QImage PDFDocument::getPrintableImage(int pageNum, int resolution) const
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (pageNum < 0 || pageNum >= m_pages.size())
|
||||
return QImage();
|
||||
return m_pages[pageNum]->getPrintableImage(resolution);
|
||||
#else
|
||||
Q_UNUSED(pageNum);
|
||||
Q_UNUSED(resolution);
|
||||
return QImage();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::ensureCurPageVisible(int xOfs, int yOfs)
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_currentPage >= m_ranges.size() || m_currentPage < 0)
|
||||
return;
|
||||
|
||||
@@ -316,10 +380,15 @@ void PDFDocument::ensureCurPageVisible(int xOfs, int yOfs)
|
||||
y += m_scrollArea->height();
|
||||
|
||||
m_scrollArea->ensureVisible(x, y, 0, 0);
|
||||
#else
|
||||
Q_UNUSED(xOfs);
|
||||
Q_UNUSED(yOfs);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFDocument::rebuildRanges()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVBoxLayout *l = qobject_cast<QVBoxLayout *> (m_pdfLabel->layout());
|
||||
m_ranges.clear();
|
||||
int height = l->contentsMargins().top();
|
||||
@@ -331,6 +400,9 @@ void PDFDocument::rebuildRanges()
|
||||
}
|
||||
m_pdfLabel->resize(m_pdfLabel->sizeHint());
|
||||
m_pdfLabel->setMinimumSize(m_pdfLabel->sizeHint());
|
||||
#else
|
||||
// Stub implementation when Poppler not available
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,20 +4,26 @@
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QPointer>
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
#include <poppler/qt6/poppler-qt6.h>
|
||||
#endif
|
||||
|
||||
#include "nglwidgets_export.h"
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
namespace Poppler
|
||||
{
|
||||
class Document;
|
||||
class LinkDestination;
|
||||
}
|
||||
#endif
|
||||
class QUrl;
|
||||
class QScrollArea;
|
||||
namespace NGL
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
class PDFPage;
|
||||
#endif
|
||||
|
||||
|
||||
class NGLWIDGETS_EXPORT PDFDocument : public QWidget
|
||||
@@ -54,10 +60,9 @@ public Q_SLOTS:
|
||||
|
||||
|
||||
void setZoomFactor(double zoom);
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void setRotation(Poppler::Page::Rotation rot);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
bool setPage(int page);
|
||||
|
||||
@@ -70,38 +75,36 @@ public Q_SLOTS:
|
||||
void resizePdfToWidth();
|
||||
|
||||
public:
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
Poppler::Page::Rotation getRotation() const { return m_rotation; }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
QVector<QImage> getPrintableImages(int resolution = 300) const;
|
||||
|
||||
|
||||
|
||||
QImage getPrintableImage(int pageNum, int resolution = 300) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
|
||||
void currentPageChanged(int cur, int max);
|
||||
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void rotationChanged(Poppler::Page::Rotation rot);
|
||||
|
||||
|
||||
void linkClicked(const QString &url);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onLinkClicked(const Poppler::LinkDestination &dest);
|
||||
#endif
|
||||
void onVSliderValueChanged(int y);
|
||||
void onPageRendered();
|
||||
void onLinkClicked(const Poppler::LinkDestination &dest);
|
||||
|
||||
protected:
|
||||
bool showPDFInternal();
|
||||
void ensureCurPageVisible(int xOfs = 0, int yOfs = 0);
|
||||
void rebuildRanges();
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
std::unique_ptr<Poppler::Document> m_doc;
|
||||
#endif
|
||||
int m_currentPage;
|
||||
int m_maxCachedPages;
|
||||
double m_scaleFactor;
|
||||
@@ -110,9 +113,11 @@ protected:
|
||||
|
||||
QWidget *m_pdfLabel;
|
||||
QScrollArea *m_scrollArea;
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVector<PDFPage *> m_pages;
|
||||
QVector<int> m_ranges;
|
||||
QVector<QPointer<PDFPage> > m_renderedPages;
|
||||
Poppler::Page::Rotation m_rotation;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
template <typename T>
|
||||
@@ -210,4 +212,6 @@ QSizeF PDFPage::rotatedPageSize() const
|
||||
{
|
||||
return m_page ? getRotatedSize(m_page->pageSizeF(), m_rotation) : QSizeF();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_POPPLER_QT6
|
||||
@@ -3,16 +3,20 @@
|
||||
#include <QtCore/QSizeF>
|
||||
#include <QtWidgets/QWidget>
|
||||
#include <QtGui/QPixmap>
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
#include <poppler/qt6/poppler-qt6.h>
|
||||
#endif
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
namespace Poppler
|
||||
{
|
||||
class Page;
|
||||
class Link;
|
||||
class LinkDestination;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
@@ -25,18 +29,21 @@ public:
|
||||
explicit PDFPage(QWidget *parent = nullptr);
|
||||
virtual ~PDFPage();
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void setPopplerPage(Poppler::Page *page);
|
||||
void setZoomFactor(double zoom);
|
||||
void setRotation(Poppler::Page::Rotation rot);
|
||||
void clearPixmap();
|
||||
QImage getPrintableImage(int resolution = 300) const;
|
||||
Q_SIGNALS:
|
||||
void linkClicked(const Poppler::LinkDestination &dest);
|
||||
#endif
|
||||
void setZoomFactor(double zoom);
|
||||
void clearPixmap();
|
||||
QSize sizeHint() const override;
|
||||
Q_SIGNALS:
|
||||
void pageRendered();
|
||||
|
||||
void externalLinkClicked(const QString &url);
|
||||
|
||||
void linkClicked(const Poppler::LinkDestination &dest);
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
@@ -45,11 +52,13 @@ private:
|
||||
void rebuildInternalData();
|
||||
QSizeF rotatedPageSize() const;
|
||||
protected:
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
Poppler::Page *m_page;
|
||||
double m_scaleFactor;
|
||||
QPixmap m_pdfPixmap;
|
||||
std::vector<std::unique_ptr<Poppler::Link>> m_links;
|
||||
QList< QRectF > m_linkRects;
|
||||
Poppler::Page::Rotation m_rotation;
|
||||
#endif
|
||||
double m_scaleFactor;
|
||||
QPixmap m_pdfPixmap;
|
||||
};
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
#include "nglpdfwidget.h"
|
||||
#include "ui_nglpdfwidget.h"
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
static const double s_maxZoom = 3.0;
|
||||
static const double s_minZoom = 1.0;
|
||||
#endif
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
@@ -20,16 +22,16 @@ PDFWidget::PDFWidget(QWidget *parent)
|
||||
|
||||
connect(ui->previousPage, &QToolButton::clicked, ui->pdfDocument, &PDFDocument::previousPage);
|
||||
connect(ui->nextPage, &QToolButton::clicked, ui->pdfDocument, &PDFDocument::nextPage);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
connect(ui->zoom100, &QToolButton::clicked, this, &PDFWidget::onZoomDefault);
|
||||
connect(ui->zoomMinus, &QToolButton::clicked, this, &PDFWidget::onZoomMinus);
|
||||
connect(ui->zoomPlus, &QToolButton::clicked, this, &PDFWidget::onZoomPlus);
|
||||
connect(ui->zoomFull, &QToolButton::clicked, this, &PDFWidget::onZoomFull);
|
||||
|
||||
connect(ui->rotateDoc, &QToolButton::clicked, this, &PDFWidget::rotate);
|
||||
connect(ui->pdfDocument, &PDFDocument::rotationChanged, this, &PDFWidget::rotationChanged);
|
||||
#endif
|
||||
|
||||
connect(ui->pdfDocument, &PDFDocument::currentPageChanged, this, &PDFWidget::pageChanged);
|
||||
connect(ui->rotateDoc, &QToolButton::clicked, this, &PDFWidget::rotate);
|
||||
connect(ui->pdfDocument, &PDFDocument::currentPageChanged, this, &PDFWidget::currentPageChanged);
|
||||
connect(ui->pdfDocument, &PDFDocument::rotationChanged, this, &PDFWidget::rotationChanged);
|
||||
}
|
||||
|
||||
PDFWidget::~PDFWidget()
|
||||
@@ -53,10 +55,12 @@ void PDFWidget::setZoomFactor(double newZoomFactor)
|
||||
ui->pdfDocument->setZoomFactor(newZoomFactor);
|
||||
}
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void PDFWidget::setRotation(Poppler::Page::Rotation rot)
|
||||
{
|
||||
ui->pdfDocument->setRotation(rot);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool PDFWidget::setPage(int newPage)
|
||||
{
|
||||
@@ -75,12 +79,19 @@ int PDFWidget::curPage() const
|
||||
|
||||
QVector<QImage> PDFWidget::getPrintableImages(int resolution) const
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
return ui->pdfDocument->getPrintableImages(resolution);
|
||||
#else
|
||||
Q_UNUSED(resolution);
|
||||
return QVector<QImage>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFWidget::resizePdfToWidth()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
ui->pdfDocument->resizePdfToWidth();
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFWidget::pageChanged(int cur, int max)
|
||||
@@ -97,6 +108,7 @@ void PDFWidget::pageChanged(int cur, int max)
|
||||
|
||||
void PDFWidget::rotate()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
Poppler::Page::Rotation rot0 = ui->pdfDocument->getRotation();
|
||||
Poppler::Page::Rotation rot1 = rot0;
|
||||
switch (rot0)
|
||||
@@ -115,37 +127,45 @@ void PDFWidget::rotate()
|
||||
break;
|
||||
}
|
||||
ui->pdfDocument->setRotation(rot1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFWidget::onZoomDefault()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
ui->pdfDocument->setZoomFactor(1.0);
|
||||
m_zoomFactor = 1.0;
|
||||
#endif
|
||||
}
|
||||
void PDFWidget::onZoomFull()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
ui->pdfDocument->resizePdfToWidth();
|
||||
m_zoomFactor = 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PDFWidget::onZoomMinus()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_zoomFactor > s_minZoom)
|
||||
m_zoomFactor -= 0.20;
|
||||
if (m_zoomFactor < s_minZoom)
|
||||
m_zoomFactor = s_minZoom;
|
||||
ui->pdfDocument->setZoomFactor(m_zoomFactor);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PDFWidget::onZoomPlus()
|
||||
{
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
if (m_zoomFactor < s_maxZoom)
|
||||
m_zoomFactor += 0.20;
|
||||
if(m_zoomFactor > s_maxZoom)
|
||||
m_zoomFactor = s_maxZoom;
|
||||
ui->pdfDocument->setZoomFactor(m_zoomFactor);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,13 @@
|
||||
#pragma once
|
||||
#include <QtWidgets/QWidget>
|
||||
#include <memory>
|
||||
#include <poppler/qt6/poppler-qt6.h>
|
||||
|
||||
#include "nglwidgets_export.h"
|
||||
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
#include <poppler/qt6/poppler-qt6.h>
|
||||
#endif
|
||||
|
||||
class QUrl;
|
||||
namespace Ui
|
||||
{
|
||||
@@ -25,23 +28,31 @@ public:
|
||||
bool showPDF(const QUrl &pdf);
|
||||
bool showPDF(const QByteArray &pdf);
|
||||
void setZoomFactor(double newZoomFactor);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void setRotation(Poppler::Page::Rotation rot);
|
||||
#endif
|
||||
bool setPage(int newPage);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
QVector<QImage> getPrintableImages(int resolution = 300) const;
|
||||
void resizePdfToWidth();
|
||||
#endif
|
||||
int numPages() const;
|
||||
int curPage() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentPageChanged(int cur, int max);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void rotationChanged(Poppler::Page::Rotation newRotation);
|
||||
#endif
|
||||
protected Q_SLOTS:
|
||||
void pageChanged(int cur, int max);
|
||||
#ifdef HAVE_POPPLER_QT6
|
||||
void rotate();
|
||||
void onZoomDefault();
|
||||
void onZoomFull();
|
||||
void onZoomMinus();
|
||||
void onZoomPlus();
|
||||
#endif
|
||||
protected:
|
||||
double m_zoomFactor{1.0};
|
||||
std::unique_ptr<Ui::pdfWidget> ui;
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
# CMake script for informix sql driver
|
||||
# Make ${Qt6_Gui} optional
|
||||
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Gui)
|
||||
set(Qt6_Gui ${Qt6_Gui})
|
||||
else()
|
||||
set(Qt6_Gui "")
|
||||
endif()
|
||||
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
|
||||
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -29,7 +37,7 @@ SET(ifx_SRCS
|
||||
ADD_LIBRARY(qsql_informix SHARED ${ifx_SRCS})
|
||||
TARGET_LINK_LIBRARIES(qsql_informix
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
${Qt6_Gui}
|
||||
Qt6::Sql
|
||||
Qt6::Core5Compat
|
||||
${ICLIENT_SDK_LIBRARIES}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <QtSql/QSqlRecord>
|
||||
#include <QtSql/QSqlQuery>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtGui/QTextCodec>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QMetaType>
|
||||
@@ -1033,13 +1033,14 @@ bool QInformixDriver::open(const QString &db,
|
||||
#ifdef DEBUG_AUTODISCONNECT
|
||||
fprintf(stderr, "%p %s connTimeout: %d\n", this, __PRETTY_FUNCTION__, d->connTimeout);
|
||||
#endif
|
||||
d->dbLocale = QTextCodec::codecForName(dbLocale.toUtf8());
|
||||
if (!d->dbLocale)
|
||||
{
|
||||
setLastError(qMakeError(tr("Can't create Codec for Name %1").arg(dbLocale), QSqlError::ConnectionError, d));
|
||||
setOpenError(true);
|
||||
return false;
|
||||
}
|
||||
d->dbLocale = nullptr; // Qt6 uses UTF-8 by default, QTextCodec is no longer available
|
||||
// QTextCodec removed in Qt6 - UTF-8 is default
|
||||
// if (!d->dbLocale)
|
||||
// {
|
||||
// setLastError(qMakeError(tr("Can't create Codec for Name %1").arg(dbLocale), QSqlError::ConnectionError, d));
|
||||
// setOpenError(true);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if (isOpen())
|
||||
close();
|
||||
|
||||
Reference in new issue
Block a user