From cc523c7c41d20e537b3aea8a46fc1c24d6d29320 Mon Sep 17 00:00:00 2001 From: Lana Black Date: Sat, 4 Apr 2015 23:38:24 +0000 Subject: [PATCH] Quick and dirty Qt5 port. Yes we can. --- CMakeLists.txt | 20 ++++++++++++++++---- README | 4 ++-- i18n/CMakeLists.txt | 2 +- src/CMakeLists.txt | 8 ++++---- src/ComicBookSettings.cpp | 6 +++--- src/ComicMainWindow.cpp | 1 + src/ImgCache.cpp | 10 +++++----- src/Sink/ImgPdfSink.cpp | 2 +- src/Sink/ImgPdfSink.h | 2 +- src/StatusBar.cpp | 8 ++++++++ src/StatusBar.h | 1 + src/Thumbnail.cpp | 2 +- src/main.cpp | 4 ++-- 13 files changed, 46 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa3a6a7..2400cc5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,13 +15,25 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Release") ADD_DEFINITIONS( -DQT_NO_DEBUG_OUTPUT ) ENDIF() -SET(QT_MIN_VERSION "4.5.0") -FIND_PACKAGE(Qt4 REQUIRED) +#set(CMAKE_AUTOMOC ON) + +SET(QT_MIN_VERSION "5.4.0") +FIND_PACKAGE(Qt5Core REQUIRED) +FIND_PACKAGE(Qt5Widgets REQUIRED) +FIND_PACKAGE(Qt5LinguistTools REQUIRED) +FIND_PACKAGE(Qt5PrintSupport REQUIRED) +FIND_PACKAGE(Qt5X11Extras) #SET(QT_USE_QTOPENGL TRUE) -INCLUDE(${QT_USE_FILE}) +#INCLUDE(${QT_USE_FILE}) +include_directories(${Qt5Core_INCLUDE_DIRS}) +include_directories(${Qt5Widgets_INCLUDE_DIRS}) +include_directories(${Qt5PrintSupport_INCLUDE_DIRS}) +include_directories(${Qt5X11Extras_INCLUDE_DIRS}) +add_definitions(${Qt5Widgets_DEFINITIONS}) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(POPPLER poppler-qt4>=0.12.4 REQUIRED) +PKG_CHECK_MODULES(POPPLER poppler-qt5>=0.12.4 REQUIRED) SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE}-${VERSION}") SET(CPACK_SOURCE_GENERATOR "TGZ") diff --git a/README b/README index fcca3ca..6313023 100644 --- a/README +++ b/README @@ -12,8 +12,8 @@ mouse or keyboard navigation etc. 2. Requirements --------------- -QComicBook requires Qt library version >=4.5.0 (including moc, uic and -lrelease tools), poppler-qt4 library and cmake. +QComicBook requires Qt libraries version >=5.4.0 (qtcore, qtwidgets, qtprintsupport, +qtx11extras, qtprintsupport), poppler-qt5 library and cmake. You will also need unzip, rar (or unrar), unace, p7zip and tar (with gzip and bzip2 support compiled in) somewhere in your PATH to handle archives. If one of diff --git a/i18n/CMakeLists.txt b/i18n/CMakeLists.txt index 3a6f1ed..3ad4116 100755 --- a/i18n/CMakeLists.txt +++ b/i18n/CMakeLists.txt @@ -1,6 +1,6 @@ file (GLOB translation_src *.ts) -QT4_CREATE_TRANSLATION(qcomicbook_qm ${FILES_TO_TRANSLATE} ${translation_src}) +qt5_create_translation(qcomicbook_qm ${FILES_TO_TRANSLATE} ${translation_src}) SET_PROPERTY(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY CLEAN_NO_CUSTOM ON) ADD_CUSTOM_TARGET(translations DEPENDS ${qcomicbook_qm}) INSTALL(FILES ${qcomicbook_qm} DESTINATION share/${PACKAGE}/i18n) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 350488a..7cc1057 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,13 +50,13 @@ file (GLOB_RECURSE qcomicbook_ui *.ui) SET(FILES_TO_TRANSLATE ${FILES_TO_TRANSLATE} ${qcomicbook_src} ${qcomicbook_ui} ${qcomicbook_hdr} PARENT_SCOPE) -QT4_ADD_RESOURCES(qcomicbook_res ../data/qcomicbook.qrc) -QT4_WRAP_CPP(qcomicbook_moc_src ${qcomicbook_moc_hdrs}) -QT4_WRAP_UI(qcomicbook_ui_src ${qcomicbook_ui}) +qt5_add_resources(qcomicbook_res ../data/qcomicbook.qrc) +qt5_wrap_cpp(qcomicbook_moc_src ${qcomicbook_moc_hdrs}) +qt5_wrap_ui(qcomicbook_ui_src ${qcomicbook_ui}) ADD_EXECUTABLE(qcomicbook ${qcomicbook_src} ${qcomicbook_moc_src} ${qcomicbook_ui_src} ${qcomicbook_res}) ADD_DEPENDENCIES(qcomicbook translations) -TARGET_LINK_LIBRARIES(qcomicbook ${QT_LIBRARIES}) +TARGET_LINK_LIBRARIES(qcomicbook Qt5::Widgets Qt5::PrintSupport Qt5::X11Extras) TARGET_LINK_LIBRARIES(qcomicbook ${POPPLER_LIBRARIES}) INSTALL(TARGETS qcomicbook DESTINATION bin) diff --git a/src/ComicBookSettings.cpp b/src/ComicBookSettings.cpp index 789f337..d800631 100644 --- a/src/ComicBookSettings.cpp +++ b/src/ComicBookSettings.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #define GRP_VIEW "/View" @@ -104,7 +104,7 @@ ComicBookSettings::~ComicBookSettings() bool ComicBookSettings::checkDirs() { m_dirsok = false; - m_bkpath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + m_bkpath = QStandardPaths::writableLocation(QStandardPaths::DataLocation); QDir dir(m_bkpath); if (!dir.exists()) @@ -115,7 +115,7 @@ bool ComicBookSettings::checkDirs() } } - m_thpath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + QDir::separator() + "thumbs"; + m_thpath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QDir::separator() + "thumbs"; dir.setPath(m_thpath); if (!dir.exists()) diff --git a/src/ComicMainWindow.cpp b/src/ComicMainWindow.cpp index acf8716..f9c70c6 100644 --- a/src/ComicMainWindow.cpp +++ b/src/ComicMainWindow.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/src/ImgCache.cpp b/src/ImgCache.cpp index 03161a3..47a5737 100644 --- a/src/ImgCache.cpp +++ b/src/ImgCache.cpp @@ -36,13 +36,13 @@ void ImgCache::setSize(int size, bool autoAdjust) void ImgCache::insertImage(int page, const QImage &img) { mtx.lock(); - if (autoAdjust && (img.numBytes() + maxItemSizeSoFar > cache.maxCost())) + if (autoAdjust && (img.byteCount() + maxItemSizeSoFar > cache.maxCost())) { - cache.setMaxCost(img.numBytes() + maxItemSizeSoFar); - if (img.numBytes() > maxItemSizeSoFar) - maxItemSizeSoFar = img.numBytes(); + cache.setMaxCost(img.byteCount() + maxItemSizeSoFar); + if (img.byteCount() > maxItemSizeSoFar) + maxItemSizeSoFar = img.byteCount(); } - cache.insert(page, new QImage(img), img.numBytes()); + cache.insert(page, new QImage(img), img.byteCount()); mtx.unlock(); } diff --git a/src/Sink/ImgPdfSink.cpp b/src/Sink/ImgPdfSink.cpp index 5ea8564..5d68fb9 100644 --- a/src/Sink/ImgPdfSink.cpp +++ b/src/Sink/ImgPdfSink.cpp @@ -63,7 +63,7 @@ QImage ImgPdfSink::image(unsigned int num, int &result) Poppler::Page* pdfpage = pdfdoc->page(num); if (pdfpage) { - QImage img = pdfpage->renderToImage(QX11Info::appDpiX(), QX11Info::appDpiY()); //TODO use defaults if not using X11 (e.g. MS Win) + QImage img = pdfpage->renderToImage(QX11Info::appDpiX(), QX11Info::appDpiY()); //TODO: use QScreen delete pdfpage; result = 0; return img; diff --git a/src/Sink/ImgPdfSink.h b/src/Sink/ImgPdfSink.h index 80d2122..03f2f69 100644 --- a/src/Sink/ImgPdfSink.h +++ b/src/Sink/ImgPdfSink.h @@ -16,7 +16,7 @@ #include "ImgSink.h" #include #include -#include +#include namespace QComicBook { diff --git a/src/StatusBar.cpp b/src/StatusBar.cpp index 49c39a6..edca93c 100644 --- a/src/StatusBar.cpp +++ b/src/StatusBar.cpp @@ -98,6 +98,14 @@ void StatusBar::removeProgressBar() } } +void StatusBar::setShown(bool v) +{ + if(v) + show(); + else + hide(); +} + void StatusBar::clear() { setPage(0, 0); diff --git a/src/StatusBar.h b/src/StatusBar.h index 13d27e6..5f33f9c 100644 --- a/src/StatusBar.h +++ b/src/StatusBar.h @@ -37,6 +37,7 @@ namespace QComicBook void setName(const QString &n); void setImageInfo(const Page *img1, const Page *img2 = NULL); void setProgress(int n, int total); + void setShown(bool); void clear(); protected: diff --git a/src/Thumbnail.cpp b/src/Thumbnail.cpp index 0242ada..61c216b 100644 --- a/src/Thumbnail.cpp +++ b/src/Thumbnail.cpp @@ -109,5 +109,5 @@ QString Thumbnail::getFullPath() const QByteArray Thumbnail::getScrambledName(const QString &in) { - return QCryptographicHash::hash( in.toAscii(), QCryptographicHash::Sha1 ); + return QCryptographicHash::hash( in.toLatin1(), QCryptographicHash::Sha1 ); } diff --git a/src/main.cpp b/src/main.cpp index 0298191..c85d350 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,9 +85,9 @@ int main(int argc, char *argv[]) // // command line argument - if (app.argc() > 1) + if (app.arguments().size() > 1) { - win->open(QString::fromLocal8Bit(app.argv()[1])); + win->open(app.arguments().at(1)); } else {