Skip to content

Commit

Permalink
Rebased and runs "somewhat" again.
Browse files Browse the repository at this point in the history
- crashes on second run
- preview fontsize smaller than print fontsize
  • Loading branch information
gzotti committed Nov 27, 2023
1 parent 45fd6c6 commit b388475
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions plugins/PrintSky/src/gui/PrintSkyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void PrintSkyDialog::createDialogContent()

void PrintSkyDialog::printFooter(QPrinter * printer, QPainter *painter, int pageNumber)
{
Q_ASSERT(painter);
Q_ASSERT(printer);
const double jd=StelUtils::getJDFromSystem();
QString stelVersion = q_("Stellarium %1").arg(StelUtils::getApplicationVersion());
StelLocaleMgr lMgr=StelApp::getInstance().getLocaleMgr();
Expand All @@ -130,6 +132,7 @@ void PrintSkyDialog::printFooter(QPrinter * printer, QPainter *painter, int page

painter->drawText(QRectF(marginLeft, yPos, fullRect.width()-marginLeft-marginRight, 2*fontSize), Qt::AlignLeft, footerText);
painter->drawText(QRectF(marginLeft, yPos, fullRect.width()-marginLeft-marginRight, 2*fontSize), Qt::AlignRight, QString("%1 %2").arg(q_("Page")).arg(QString::number(pageNumber)));
qDebug() << "printFooter done";
}

// Draw contents report
Expand All @@ -141,6 +144,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
const double jd = core->getJD();

PrintSky *plugin=GETSTELMODULE(PrintSky);
Q_ASSERT(printer);
Q_ASSERT(plugin);
QPainter painter(printer);
const QPageLayout pageLayout=printer->pageLayout();
Expand All @@ -166,7 +170,8 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)


//const int fontsize = static_cast<int>(printer->pageRect().width())/60;
const int fontsize = static_cast<int>(pageLayout.paintRectPixels(300).width())/75;
//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);
painter.setFont(font);
//int lineSpacing=fontsize+8;
Expand Down Expand Up @@ -210,6 +215,8 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
.arg(qc_("m", "altitude, metres"));
painter.drawText(surfaceData.adjusted(50, lineSpacing, 0, 0), Qt::AlignLeft, locationStr);

qDebug() << "PrintSky: Basic info 1 ";

// It seems when initializing this as non-pointer, the object gets deleted at end on this clause, causing a crash.
StelLocaleMgr *lmgr = &StelApp::getInstance().getLocaleMgr();
Q_ASSERT(lmgr);
Expand All @@ -220,6 +227,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
.arg(lmgr->getPrintableTimeZoneLocal(jd));
painter.drawText(surfaceData.adjusted(50, (lineSpacing)*2, 0, 0), Qt::AlignLeft, datetime);

qDebug() << "PrintSky: Basic info 2";
QString fov = QString("%1: %2%3").arg(q_("Vertical field of view")).arg(QString::number(core->getMovementMgr()->getCurrentFov(), 'f', 1)).arg(QChar(0x00B0));
painter.drawText(surfaceData.adjusted(50, (lineSpacing)*3, 0, 0), Qt::AlignLeft, fov);

Expand All @@ -242,6 +250,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
yPos=lineSpacing+10;
}
}
qDebug() << "PrintSky: Basic info 3";

// Twilight table. TODO: Make a nice table from these badly structured lines.
SolarSystem* ssmgr = GETSTELMODULE(SolarSystem);
Expand Down Expand Up @@ -287,12 +296,15 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
.arg(q_("Moonset"))
.arg(printableRTSTime(moonRTS, 2));
painter.drawText(surfaceData.adjusted(50, (lineSpacing)*9, 0, 0), Qt::AlignLeft, rtsStr);
qDebug() << "PrintSky: Basic info 3j";

// TODO: lunar phase or similar general information?
// TODO: active meteor showers (check plugin state, get info)
printFooter(printer, &painter, pageNumber);
// FIXME: printFooter crashes!
//printFooter(printer, &painter, pageNumber++);
qDebug() << "RTS7";


}

// (2) Print selected object information
Expand Down Expand Up @@ -342,6 +354,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
StelUtils::rectToSphe(&ra,&dec, p->getEquinoxEquatorialPos(core));
Vec4d RTS=p.data()->getRTSTime(core);

qDebug() << "PrintSky: Ephemerides a";
if ((!plugin->getFlagLimitMagnitude() || p->getVMagnitude(core) <= static_cast<float>(plugin->getLimitMagnitude()))
&& englishName!=location.planetName)
{
Expand All @@ -352,7 +365,8 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
yPos=70+lineSpacing*2;
printer->newPage();
pageNumber++;
printFooter(printer, &painter, pageNumber);
//printFooter(printer, &painter, pageNumber);
qDebug() << "PrintSky: Ephemerides " << pageNumber;

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

Expand Down Expand Up @@ -396,6 +410,7 @@ void PrintSkyDialog::printDataSky(QPrinter * printer)
}
}
}

QApplication::restoreOverrideCursor();
}

Expand Down

0 comments on commit b388475

Please sign in to comment.