Skip to content

Commit

Permalink
feat: adapt for Qt 6.8 (#135)
Browse files Browse the repository at this point in the history
Adaptation work based on Qt 6.8, modified relevant

Co-authored-by: Tian Shilin <[email protected]>
  • Loading branch information
lzwind and JWWTSL authored Jan 20, 2025
1 parent cd58f92 commit a29fbf5
Show file tree
Hide file tree
Showing 35 changed files with 253 additions and 96 deletions.
3 changes: 3 additions & 0 deletions 3rdparty/deepin-pdfium/deepin-pdfium.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ TEMPLATE = subdirs
#QMAKE_CXX += -g -fsanitize=undefined,address -O2
#QMAKE_CXXFLAGS += -g -fsanitize=undefined,address -O2
#QMAKE_LFLAGS += -g -fsanitize=undefined,address -O2
# 添加库
LIBS += -ldjvulibre -ljpeg


SUBDIRS += src
9 changes: 5 additions & 4 deletions 3rdparty/deepin-pdfium/include/dpdfglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include <QtCore/qglobal.h>
#include <QMutexLocker>
#include <QDebug>
#include <QTime>
#include <QElapsedTimer>
#include <QRectF>
#include <QMutex>

#ifndef BUILD_DEEPDF_STATIC
# if defined(BUILD_DEEPDF_LIB)
Expand Down Expand Up @@ -45,14 +46,14 @@ class DPdfGlobal
};

//pdfium即使不同文档之间loadpage和renderpage也不是线程安全,需要加锁
class DPdfMutexLocker : public QMutexLocker
class DPdfMutexLocker : public QMutexLocker<QMutex>
{
public:
DPdfMutexLocker(const QString &tmpLog);
explicit DPdfMutexLocker(const QString &tmpLog);
~DPdfMutexLocker();

QString m_log;
QTime m_time;
QElapsedTimer m_timer;
};

#endif // DPDFGLOBAL_H
1 change: 0 additions & 1 deletion 3rdparty/deepin-pdfium/src/dpdfdoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ bool DPdfDoc::saveAs(const QString &filePath)
DPdfMutexLocker locker("DPdfDoc::saveAs");
bool result = FPDF_SaveAsCopy(reinterpret_cast<FPDF_DOCUMENT>(d_func()->m_docHandler), &write, FPDF_NO_INCREMENTAL);
locker.unlock();

saveWriter.close();

return result;
Expand Down
17 changes: 9 additions & 8 deletions 3rdparty/deepin-pdfium/src/dpdfglobal.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

#include <QtCore>
#include <QString>

#include <QMutex>
#include <QMutexLocker>
#include <QDebug>
#include "dpdfglobal.h"
#include "public/fpdfview.h"

Expand Down Expand Up @@ -46,16 +47,16 @@ QString DPdfGlobal::textCodeType(const char *text)
return encodeind;
}

Q_GLOBAL_STATIC_WITH_ARGS(QMutex, pdfMutex, (QMutex::Recursive));
Q_GLOBAL_STATIC_WITH_ARGS(QMutex, pdfMutex, ());

DPdfMutexLocker::DPdfMutexLocker(const QString &tmpLog): QMutexLocker(pdfMutex())
DPdfMutexLocker::DPdfMutexLocker(const QString &tmpLog): QMutexLocker<QMutex>(pdfMutex())
{
// m_log = tmpLog;
// qInfo() << m_log + " begin ";
// m_time.start();
m_log = tmpLog;
qInfo() << m_log + " begin ";
m_timer.start();
}

DPdfMutexLocker::~DPdfMutexLocker()
{
// qInfo() << m_log + " end time = " << m_time.elapsed();
qInfo() << m_log + " end time = " << m_timer.elapsed();
}
4 changes: 0 additions & 4 deletions 3rdparty/deepin-pdfium/src/dpdfpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,6 @@ QImage DPdfPage::image(int width, int height, QRect slice)

FPDF_ClosePage(page);

locker.unlock();

//bgr转rgb 如果image设置成Format_RGB888+FPDFBitmap_BGR则需要进行以下转换,此方法移除Alpha,节省25%的内存.
//如果使用Format_RGB32+FPDFBitmap_BGRA 此方法无需以下转换,可以提升部分效率,但是增加内存
// for (int i = 0; i < image.height(); i++) {
Expand Down Expand Up @@ -811,8 +809,6 @@ DPdfAnnot *DPdfPage::createTextAnnot(QPointF pos, QString text)

FPDFPage_CloseAnnot(annot);

locker.unlock();

DPdfTextAnnot *dAnnot = new DPdfTextAnnot;

//此处使用pixel坐标
Expand Down
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ Source: deepin-reader
Section: graphics
Priority: optional
Maintainer: deepin <[email protected]>
Build-Depends: debhelper (>= 11), pkg-config, qtbase5-dev, qtchooser, qttools5-dev-tools, libdtkwidget-dev, libspectre-dev, libdjvulibre-dev, libtiff-dev, libkf5archive-dev, libjpeg-dev, libicu-dev, libpng-dev, zlib1g-dev, liblcms2-dev, libopenjp2-7-dev, libfreetype6-dev, libgtest-dev, libchardet-dev, qtwebengine5-dev
Build-Depends: debhelper (>= 11), pkg-config, qt6-base-dev, qt6-base-dev-tools, qt6-tools-dev, libdtk6widget-dev, libspectre-dev, libdjvulibre-dev, libtiff-dev, libjpeg-dev, libicu-dev, libpng-dev, zlib1g-dev, liblcms2-dev, libopenjp2-7-dev, libfreetype6-dev, libgtest-dev, libchardet-dev, qt6-webengine-dev, qt6-5compat-dev, libdtk6gui-dev, libdtk6core-dev
Standards-Version: 4.5.0

Package: deepin-reader
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, pandoc
Description: a tool for reading document files.
Document Viewer is a tool for reading document files,supporting PDF, DJVU, DOCX etc

21 changes: 16 additions & 5 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/dpkg/default.mk
# 设置 Qt6 环境
export QT_SELECT=qt6
# 使用系统 PATH 中的 qmake6
export QMAKE=qmake6

export QT_SELECT := 5
include /usr/share/dpkg/default.mk

override_dh_auto_configure:
dh_auto_configure -- DAPP_VERSION=$(DEB_VERSION_UPSTREAM) DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)" LIB_INSTALL_DIR=/usr/lib/
# 指定使用 qmake 构建系统
export DH_OPTIONS := --buildsystem=qmake

%:
dh $@
dh $@ --buildsystem=qmake

override_dh_auto_configure:
$(QMAKE) \
VERSION=$(VERSION) \
PREFIX=/usr \
LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
VERSION_UPSTREAM=$(DEB_VERSION_UPSTREAM) \
DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)"
35 changes: 35 additions & 0 deletions deepin_reader.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
TEMPLATE = subdirs

#QMAKE_CXX = ccache $$QMAKE_CXX //linux使用ccache加速c++编译速度
#config
# 基础 Qt 模块
equals(QT_MAJOR_VERSION, 6) {
QT += core gui widgets network dbus sql svg webchannel webenginewidgets concurrent xml core5compat

# Qt6 specific configurations
PKGCONFIG += dtk6widget dtk6gui dtk6core

# Qt6 lrelease configuration
QMAKE_LRELEASE = /usr/lib/qt6/bin/lrelease

LIBS += -L$$PREFIX/lib/$$QMAKE_HOST.arch-linux-gnu/ -lKF6GlobalAccel -lKF6I18n
INCLUDEPATH += $$PREFIX/include/KF6/KGlobalAccel
INCLUDEPATH += $$PREFIX/include/KF6/KI18n

} else {
QT += core gui widgets network sql dbus svg webchannel webenginewidgets concurrent xml

# Qt5 specific configurations
PKGCONFIG += dtkwidget dframeworkdbus poppler-qt5

QMAKE_LRELEASE = lrelease

LIBS += -L$$PREFIX/lib/$$QMAKE_HOST.arch-linux-gnu/ -lKF5GlobalAccel -lKF5I18n
INCLUDEPATH += $$PREFIX/include/KF5/KGlobalAccel
INCLUDEPATH += $$PREFIX/include/KF5/KI18n
}

# 添加库
LIBS += `pkg-config --libs libjpeg`
LIBS += `pkg-config --libs ddjvu`

# 如果需要包含头文件的路径,可以添加
INCLUDEPATH += `pkg-config --cflags libjpeg`
INCLUDEPATH += `pkg-config --cflags ddjvu`

CONFIG += ordered

Expand Down
14 changes: 7 additions & 7 deletions reader/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <QStandardPaths>
#include <QSettings>
#include <QTimer>
#include <QDesktopWidget>
#include <QScreen>
#include <QPropertyAnimation>
#include <QJsonObject>
#include <QLibraryInfo>
Expand Down Expand Up @@ -303,15 +303,15 @@ void MainWindow::handleMainWindowFull()

m_docTabWidget->setVisible(tabbarVisible);

titlebar()->setGeometry(0, 0, dApp->primaryScreen()->size().width(), titlebar()->height());
titlebar()->setGeometry(0, 0, QGuiApplication::primaryScreen()->size().width(), titlebar()->height());

m_docTabWidget->setGeometry(0, titlebar()->height(), dApp->primaryScreen()->size().width(), 37);
m_docTabWidget->setGeometry(0, titlebar()->height(), QGuiApplication::primaryScreen()->size().width(), 37);

int fulltitleH = tabbarVisible ? titlebar()->height() + 37 : titlebar()->height();

m_FullTitleWidget->setMinimumHeight(fulltitleH);

m_FullTitleWidget->setGeometry(0, -fulltitleH, dApp->primaryScreen()->size().width(), fulltitleH);
m_FullTitleWidget->setGeometry(0, -fulltitleH, QGuiApplication::primaryScreen()->size().width(), fulltitleH);

updateOrderWidgets(this->property("orderlist").value<QList<QWidget *>>());
}
Expand All @@ -331,7 +331,7 @@ void MainWindow::handleMainWindowExitFull()

setTitleBarFocusEnable(true);

m_FullTitleWidget->setGeometry(0, -m_FullTitleWidget->height(), dApp->primaryScreen()->size().width(), m_FullTitleWidget->height());
m_FullTitleWidget->setGeometry(0, -m_FullTitleWidget->height(), QGuiApplication::primaryScreen()->size().width(), m_FullTitleWidget->height());

updateOrderWidgets(this->property("orderlist").value<QList<QWidget *>>());
}
Expand Down Expand Up @@ -370,7 +370,7 @@ void MainWindow::resizeFullTitleWidget()

m_FullTitleWidget->setMinimumHeight(fulltitleH);

m_FullTitleWidget->resize(dApp->primaryScreen()->size().width(), fulltitleH);
m_FullTitleWidget->resize(QGuiApplication::primaryScreen()->size().width(), fulltitleH);
}

MainWindow *MainWindow::windowContainSheet(DocSheet *sheet)
Expand Down Expand Up @@ -415,7 +415,7 @@ MainWindow *MainWindow::createWindow(QStringList filePathList)
// 现有数目大于0时,新创建的文档查看器对话框按照一定的规律偏移显示,每次向右、向下偏移50个像素,达到错开显示的效果,防止一直显示在桌面中间
if (iCount > 0) {
int windowOffset = iCount * 50;
QRect screenGeometry = qApp->desktop()->screenGeometry(QCursor::pos());
QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
pMainWindow->move(screenGeometry.x() + windowOffset, screenGeometry.y() + windowOffset);
}
qDebug() << __FUNCTION__ << "主窗口已创建并显示";
Expand Down
2 changes: 1 addition & 1 deletion reader/browser/BrowserAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "BrowserAnnotation.h"
#include "BrowserPage.h"

#include <DApplicationHelper>
#include <DGuiApplicationHelper>

#include <QPainter>
#include <QStyleOptionGraphicsItem>
Expand Down
2 changes: 1 addition & 1 deletion reader/browser/BrowserPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Global.h"
#include "SheetRenderer.h"

#include <DApplicationHelper>
#include <DGuiApplicationHelper>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneMouseEvent>
Expand Down
3 changes: 2 additions & 1 deletion reader/browser/SheetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ void SheetBrowser::wheelEvent(QWheelEvent *event)
if (nullptr == m_sheet)
return;

if (event->delta() > 0) {
// Use angleDelta() instead of delta()
if (event->angleDelta().y() > 0) {
m_sheet->zoomin();
} else {
m_sheet->zoomout();
Expand Down
5 changes: 3 additions & 2 deletions reader/document/DjVuModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <libdjvu/ddjvuapi.h>
#include <libdjvu/miniexp.h>

#include <QRegularExpression>
#include <qmath.h>
#include <cstdio>
#include <unistd.h>
Expand Down Expand Up @@ -624,7 +624,8 @@ QVector<PageSection> DjVuPage::search(const QString &text, bool matchCase, bool

const QTransform transform = QTransform::fromScale(72.0 / m_resolution, 72.0 / m_resolution);

const QStringList words = text.split(QRegExp(QLatin1String("\\W+")), QString::SkipEmptyParts);
QStringList words = text.split(QRegularExpression(QLatin1String("\\W+")));
words.removeAll(QString());

const QVector< QRectF > results = findText(pageTextExp, m_size, transform, words, matchCase, wholeWords);

Expand Down
7 changes: 6 additions & 1 deletion reader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
#include "DBusObject.h"

#include <DLog>

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <DApplicationSettings>
#endif

#include <QCommandLineParser>
#include <QDesktopWidget>
#include <QScreen>
#include <QAccessible>
#include <QDebug>
#include <QFontDatabase>
Expand Down Expand Up @@ -76,8 +79,10 @@ int main(int argc, char *argv[])
QAccessible::installFactory(accessibleFactory);

//Dtk自动保存主题
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
DApplicationSettings savetheme;
Q_UNUSED(savetheme)
#endif

Dtk::Core::DLogManager::registerConsoleAppender();
Dtk::Core::DLogManager::registerFileAppender();
Expand Down
Loading

0 comments on commit a29fbf5

Please sign in to comment.