Skip to content

Commit

Permalink
Qt5/6 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gzotti committed Nov 27, 2023
1 parent b388475 commit 5d9ed12
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
21 changes: 14 additions & 7 deletions plugins/PrintSky/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INCLUDE_DIRECTORIES(. gui
# ${CMAKE_BINARY_DIR}/plugins/PrintSky/src
# ${CMAKE_BINARY_DIR}/plugins/PrintSky/src
)
LINK_DIRECTORIES(${BUILD_DIR}/src)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src)

SET(PrintSky_SRCS
PrintSky.hpp
Expand All @@ -14,13 +14,18 @@ SET(PrintSky_SRCS

################# compiles resources files ############
#SET(PrintSky_RES ../PrintSky.qrc)
#QT4_ADD_RESOURCES(PrintSky_RES_CXX ${PrintSky_RES})

################# compiles .ui files ############
SET(PrintSky_UIS
gui/printskyDialog.ui
)
QT5_WRAP_UI(PrintSky_UIS_H ${PrintSky_UIS})
IF (${QT_VERSION_MAJOR} EQUAL "5")
QT5_WRAP_UI(PrintSky_UIS_H ${PrintSky_UIS})
# QT5_ADD_RESOURCES(PrintSky_RES_CXX ${PrintSky_RES})
ELSE()
QT_WRAP_UI(PrintSky_UIS_H ${PrintSky_UIS})
# QT_ADD_RESOURCES(PrintSky_RES_CXX ${PrintSky_RES})
ENDIF()

## Add here all the files which require moc compilation
## that is, all the headers with SIGNAL/SLOTS/PLUGIN_INTERFACE etc..
Expand Down Expand Up @@ -57,12 +62,14 @@ SET(extLinkerOption ${FreeType2_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} ${
#ENDIF()
#
############### For building the static library ######################
FIND_PACKAGE(Qt${QT_VERSION_MAJOR} COMPONENTS PrintSupport)

#IF(BUILD_STATIC_PLUGINS)
# ADD_LIBRARY(PrintSky-static STATIC ${PrintSky_SRCS} ${PrintSky_MOC_SRCS} ${PrintSky_UIS_H})
ADD_LIBRARY(PrintSky-static STATIC ${PrintSky_SRCS} ${PrintSky_UIS_H})
ADD_LIBRARY(PrintSky-static STATIC ${PrintSky_SRCS} ${PrintSky_RES_CXX} ${PrintSky_UIS_H})
TARGET_LINK_LIBRARIES(PrintSky-static Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::PrintSupport ${extLinkerOption})
# The library target "PrintSky-static" has a default OUTPUT_NAME of "PrintSky-static", so change it.
SET_TARGET_PROPERTIES(PrintSky-static PROPERTIES OUTPUT_NAME "PrintSky")
TARGET_LINK_LIBRARIES(PrintSky-static Qt5::Core Qt5::Widgets Qt5::PrintSupport ${extLinkerOption})
SET_TARGET_PROPERTIES(PrintSky-static PROPERTIES OUTPUT_NAME "PrintSky")
# SET_TARGET_PROPERTIES(PrintSky-static PROPERTIES COMPILE_FLAGS "-fPIC -DQT_STATICPLUGIN")
SET_TARGET_PROPERTIES(PrintSky-static PROPERTIES COMPILE_FLAGS "-DQT_STATICPLUGIN")
ADD_DEPENDENCIES(AllStaticPlugins PrintSky-static)
Expand Down
27 changes: 13 additions & 14 deletions plugins/PrintSky/src/gui/PrintSkyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "PrintSky.hpp"
#include "StelApp.hpp"
#include "StelGui.hpp"
#include "StelFileMgr.hpp"
#include "StelModuleMgr.hpp"
#include "StelMainView.hpp"
#include "StelTranslator.hpp"
Expand Down Expand Up @@ -161,15 +160,15 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
return;
}
const int imageYPos=(plugin->getPrintData()? 400: 0);
QSize sizeReal=printer->pageRect().size();
QSize sizeReal=printer->pageLayout().paintRectPixels(printer->resolution()).size();
sizeReal.setHeight(sizeReal.height()-imageYPos);
if (plugin->getScaleToFit())
img=img.scaled(sizeReal, Qt::KeepAspectRatio, Qt::SmoothTransformation);
const int imageXPos=(printer->pageRect().width()-img.width())/2;
const int imageXPos=(printer->pageLayout().paintRectPixels(printer->resolution()).width()-img.width())/2;
painter.drawImage(imageXPos, 0, img);


//const int fontsize = static_cast<int>(printer->pageRect().width())/60;
//const int fontsize = static_cast<int>(printer->pageLayout().paintRectPixels(printer->resolution()).width())/60;
//const int fontsize = static_cast<int>(pageLayout.paintRectPixels(300).width())/75;
const int fontsize = static_cast<int>(pageLayout.paintRectPixels(300).width())/250;
font.setPixelSize(fontsize);
Expand All @@ -185,19 +184,19 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
//printer->setResolution(printer->supportedResolutions())
qDebug() << "Current printer resolution:" << printer->resolution();
qDebug() << "Supported printer resolutions:" << printer->supportedResolutions();
qDebug() << "Page size (size index, 0-30)" << printer->paperSize();
qDebug() << "Page size (size index, 0-30)" << printer->pageLayout().pageSize().id();
//For the paper size index, see http://doc.qt.nokia.com/qprinter.html#PaperSize-enum
qDebug() << "Font Pixel Size:" << font.pixelSize();
qDebug() << "Paper Rect (by obsolete functions): "<< printer->paperRect();
qDebug() << "Page Rect (by obsolete functions): "<< printer->pageRect();
qDebug() << "Paper Rect: "<< printer->pageLayout().fullRectPixels(printer->resolution());
qDebug() << "Page Rect: "<< printer->pageLayout().paintRectPixels(printer->resolution());


if (plugin->getPrintData()) // (1a) Basic info below image.
{
qDebug() << "PrintSky: Basic info";
int posY=img.height()+lineSpacing;

QRect surfaceData(printer->pageRect().left(), posY, printer->pageRect().width(), printer->pageRect().height()-posY);
QRect surfaceData(printer->pageLayout().paintRectPixels(printer->resolution()).left(), posY, printer->pageLayout().paintRectPixels(printer->resolution()).width(), printer->pageLayout().paintRectPixels(printer->resolution()).height()-posY);

painter.drawText(surfaceData.adjusted(0, 0, 0, -(surfaceData.height()-lineSpacing)), Qt::AlignCenter, q_("CHART INFORMATION"));

Expand Down Expand Up @@ -318,7 +317,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
QTextDocument info(GETSTELMODULE(StelObjectMgr)->getSelectedObject().at(0)->getInfoString(core).toHtmlEscaped());

int posY=img.height()+lineSpacing;
QRect surfaceData(printer->pageRect().left(), posY, printer->pageRect().width(), printer->pageRect().height()-posY);
QRect surfaceData(printer->pageLayout().paintRectPixels(printer->resolution()).left(), posY, printer->pageLayout().paintRectPixels(printer->resolution()).width(), printer->pageLayout().paintRectPixels(printer->resolution()).height()-posY);

// TODO: print selected object info
//painter.drawText(surfaceData.adjusted(0, 0, 0, -(surfaceData.height()-lineSpacing)),
Expand Down Expand Up @@ -361,14 +360,14 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
const double ratioWidth=(300.*static_cast<double>(fontsize)/45.);
if (doHeader)
{
double xPos=printer->pageRect().left()-ratioWidth/2;
double xPos=printer->pageLayout().paintRectPixels(printer->resolution()).left()-ratioWidth/2;
yPos=70+lineSpacing*2;
printer->newPage();
pageNumber++;
//printFooter(printer, &painter, pageNumber);
qDebug() << "PrintSky: Ephemerides " << pageNumber;

painter.drawText(QRectF(0, 0, printer->paperRect().width(), yPos), Qt::AlignCenter, q_("SOLAR SYSTEM EPHEMERIDES"));
painter.drawText(QRectF(0, 0, printer->pageLayout().fullRectPixels(printer->resolution()).width(), yPos), Qt::AlignCenter, q_("SOLAR SYSTEM EPHEMERIDES"));

yPos+=lineSpacing;

Expand All @@ -386,7 +385,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
}

oddLine=!oddLine;
double xPos=printer->pageRect().left()-ratioWidth/2;
double xPos=printer->pageLayout().paintRectPixels(printer->resolution()).left()-ratioWidth/2;

painter.setPen(Qt::NoPen);
painter.setBrush(oddLine? Qt::white: Qt::lightGray);
Expand All @@ -403,7 +402,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
painter.drawText(QRectF(xPos+= ratioWidth, yPos, ratioWidth, fontsize+lineSpacing), Qt::AlignRight, QString("%1 ").arg(p->getVMagnitude(core), 0, 'f', 1));

yPos+=lineSpacing;
if (yPos+((lineSpacing)*4)>=printer->pageRect().top()+printer->pageRect().height())
if (yPos+((lineSpacing)*4)>=printer->pageLayout().paintRectPixels(printer->resolution()).top()+printer->pageLayout().paintRectPixels(printer->resolution()).height())
{
doHeader=true;
}
Expand Down Expand Up @@ -445,7 +444,7 @@ void PrintSkyDialog::executePrinterOutputOption(bool previewOnly)
QPrinter printer(QPrinter::ScreenResolution);
printer.setResolution(300);
printer.setDocName("STELLARIUM REPORT");
printer.setOrientation(plugin->getOrientationPortrait() ? QPrinter::Portrait : QPrinter::Landscape);
printer.setPageOrientation(plugin->getOrientationPortrait() ? QPageLayout::Portrait : QPageLayout::Landscape);

if (previewOnly)
{
Expand Down
8 changes: 4 additions & 4 deletions plugins/PrintSky/src/gui/PrintSkyDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class PrintSkyDialog : public StelDialog // PrintSky

public:
PrintSkyDialog();
virtual ~PrintSkyDialog() Q_DECL_OVERRIDE;
virtual void retranslate() Q_DECL_OVERRIDE;
~PrintSkyDialog() override;
void retranslate() override;
void updateStyle();

//! Notify that the application style changed
void styleChanged();
void styleChanged() override;
void enableOutputOptions(bool enable);

public slots:
Expand All @@ -57,7 +57,7 @@ public slots:

protected:
//! Initialize the dialog widgets and connect the signals/slots
virtual void createDialogContent() Q_DECL_OVERRIDE;
void createDialogContent() override;
Ui_printskyDialogForm* ui;

private slots:
Expand Down

0 comments on commit 5d9ed12

Please sign in to comment.