]> danny-edel.de - dspdfviewer.git/commitdiff
fix deprecated messages with qt-5.15
authorDanny Edel <mail@danny-edel.de>
Thu, 20 Oct 2022 10:59:37 +0000 (12:59 +0200)
committerDanny Edel <mail@danny-edel.de>
Thu, 20 Oct 2022 12:04:30 +0000 (14:04 +0200)
also adds fallback code for Qt5 below 5.15

CMakeLists.txt
dspdfviewer.cpp
hyperlinkarea.cpp
pdfviewerwindow.cpp
testing/testswapscreen.cc

index f1f23da6bbbb0c2dfca262ac4aa97d12a9664312..ce37ea2f809dd960cc1a1e92d314bbb96c1df025 100644 (file)
@@ -23,6 +23,12 @@ endif()
 if( NOT CMAKE_VERSION VERSION_LESS 3.1)
        cmake_policy(SET CMP0054 NEW) # dont expand quoted strings in if()s
 endif()
+if( NOT CMAKE_VERSION VERSION_LESS 3.10)
+       cmake_policy(SET CMP0071 NEW) # Also process generated source files with MOC
+endif()
+if( NOT CMAKE_VERSION VERSION_LESS 3.17)
+       cmake_policy(SET CMP0100 NEW) # Allow .hh extension
+endif()
 
 project(dspdfviewer)
 
index f41b065ab81e522ca59b40fbd818087e603f5c94..b963bec25ddbed0836264caeb1b98d65205d2a3c 100644 (file)
@@ -271,13 +271,11 @@ QTime DSPDFViewer::slideClock() const
 void DSPDFViewer::resetSlideClock()
 {
   /* Always resets the slide clock. */
-  slideStart.start();
+  slideStart = QTime::currentTime();
   if ( ! presentationClockRunning ) {
     /* If this starts a presentation, also reset the presentation clock. */
-    presentationStart.start();
+    presentationStart = QTime::currentTime();
   }
-  /* and make sure they'll get refreshed a second later aswell. */
-  slideStart.start();
 
   presentationClockRunning=true;
 
@@ -295,7 +293,8 @@ void DSPDFViewer::sendAllClockSignals() const
 QTime DSPDFViewer::timeSince(const QTime& startPoint) const
 {
   QTime result(0,0);
-  result = result.addMSecs(startPoint.elapsed());
+  result = result.addMSecs(
+    startPoint.msecsTo( QTime::currentTime() ) );
   return result;
 }
 
index 4dfafcb2152d645960e8837686515a53dbd4d3e5..ea581e4e94ef3842f3416438c02ea16ec4bc026c 100644 (file)
@@ -23,6 +23,7 @@
 #include <cmath>
 #include <boost/math/special_functions/round.hpp>
 #include "debug.h"
+#include <QtGlobal>
 
 using boost::math::iround;
 
@@ -31,17 +32,28 @@ HyperlinkArea::HyperlinkArea(QLabel* imageLabel, const AdjustedLink& link): QLab
   if ( link.linkType() != Poppler::Link::Goto )
     throw WrongLinkType();
   QRect mySize;
-  const QPixmap* pixmap = imageLabel->pixmap();
-  if ( pixmap == 0 )
+#if QT_VERSION < QT_VERSION_CHECK(5,15,0)
+  // QT Version is below 5.15, which added the Return-By-Value overload.
+  // Handle the copy ourselves.
+  // FIXME: Delete this code at some point
+  const QPixmap *ppixmap = imageLabel->pixmap();
+  if ( ppixmap == nullptr)
+    throw std::runtime_error("imageLabel with nullptr pixmap()");
+  const QPixmap pixmap = QPixmap{ *ppixmap }; //copy
+#else
+  // Qt version is at least 5.15, use Qt's own copy function.
+  const QPixmap pixmap = imageLabel->pixmap(Qt::ReturnByValue);
+#endif
+  if ( pixmap.isNull() )
     throw /** FIXME Exception **/ std::runtime_error("Tried to construct a HyperlinkArea from an image label without a pixmap");
   
   QRectF sizeWithinImageLabel = link.linkArea();
   
-  mySize.setTop( iround(sizeWithinImageLabel.top() * pixmap->height()) );
-  mySize.setLeft( iround(sizeWithinImageLabel.left() * pixmap->width()) );
+  mySize.setTop( iround(sizeWithinImageLabel.top() * pixmap.height()) );
+  mySize.setLeft( iround(sizeWithinImageLabel.left() * pixmap.width()) );
   
-  mySize.setHeight(std::abs( iround(sizeWithinImageLabel.height() * pixmap->height())) );
-  mySize.setWidth( iround(sizeWithinImageLabel.width() * pixmap->width()) ); 
+  mySize.setHeight(std::abs( iround(sizeWithinImageLabel.height() * pixmap.height())) );
+  mySize.setWidth( iround(sizeWithinImageLabel.width() * pixmap.width()) );
   
   setParent(imageLabel);
   setGeometry(mySize);
index 4a5bcaf0d5eba41a0e891daa15534d868e469e49..94ead3e0fa1afffdc97ec60cb5b2583c12ba745c 100644 (file)
@@ -24,9 +24,8 @@
 #include <QHBoxLayout>
 #include <QLabel>
 #include <QMouseEvent>
-#if defined(POPPLER_QT5) && defined(_WIN32)
 #include <QWindow>
-#endif
+#include <QScreen>
 #include "debug.h"
 #include <QInputDialog>
 #include <QMessageBox>
@@ -108,16 +107,18 @@ void PDFViewerWindow::reposition()
     return;
   this->setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
   this->showNormal();
-#if defined(POPPLER_QT5) && defined(_WIN32)
-  static QList<QScreen *> screens = QApplication::screens();
+
+  /* This works on Windows */
+#ifdef _WIN32
+  QList<QScreen *> screens = QApplication::screens();
   if ( m_monitor < numeric_cast<unsigned>(screens.count()) )
     this->windowHandle()->setScreen(screens[m_monitor]);
   else
     this->windowHandle()->setScreen(0);
   this->showFullScreen();
 #else
-  QRect rect = QApplication::desktop()->screenGeometry( numeric_cast<int>(getMonitor()) );
-  move(rect.topLeft());
+  QRect rect = QGuiApplication::screens().at(m_monitor)->geometry();
+  move( rect.topLeft() );
   resize( rect.size() );
   this->showFullScreen();
 #endif
@@ -158,7 +159,7 @@ void PDFViewerWindow::wheelEvent(QWheelEvent* e)
 {
     // QWidget::wheelEvent(e);
 
-    if ( e->delta() > 0 )
+    if ( e->angleDelta().y() > 0 )
     {
       DEBUGOUT << "Back";
       emit previousPageRequested();
@@ -381,7 +382,9 @@ void PDFViewerWindow::resizeEvent(QResizeEvent* resizeEvent)
                ! i3shellcode_executed
                // Make sure to do this only once
                ) {
-               QApplication::flush(); // Make sure the window has been painted
+               /* FIXME this is deprecated */
+               // QCoreApplication::flush(); // Make sure the window has been painted
+
                // This is the second screen. It has now been created.
                // so we should call the i3 shellcode now
                const std::string shellcode = runtimeConfiguration.i3workaround_shellcode();
index 084027ab1c1c6f2cdb569d80669ae0fee38e4b1b..6870ff3dde08ca0b3c30b4cb616b00ae03a79981 100644 (file)
@@ -2,6 +2,7 @@
 #include "testhelpers.hh"
 
 #include <QDesktopWidget>
+#include <QScreen>
 #include <QRect>
 
 using namespace std;
@@ -9,17 +10,17 @@ using namespace TestHelpers;
 
 SwapScreensAndCheckAlign::SwapScreensAndCheckAlign(DSPDFViewer& d):
        dspdfviewer(d),
-       screenPrimary( QApplication::desktop()->screenGeometry( 0 ) ),
-       screenSecondary( QApplication::desktop()->screenGeometry( 1 ) ),
+       screenPrimary( QApplication::screens().at(0)->geometry() ),
+       screenSecondary( QApplication::screens().at(1)->geometry() ),
        verify(true)
 {
-       DEBUGOUT << "Number of screens:" << QApplication::desktop()->numScreens() ;
+       DEBUGOUT << "Number of screens:" << QApplication::screens().size();
 
        DEBUGOUT << "screen 0 [pri]:" << screenPrimary;
        DEBUGOUT << "screen 1 [sec]:" << screenSecondary;
 
 
-       if ( QApplication::desktop()->numScreens() != 2 ) {
+       if ( QApplication::screens().size() != 2 ) {
                WARNINGOUT << "Not running in a dual-screen environment";
                verify = false;
        } else if ( screenPrimary == screenSecondary ) {