Improve handling warning "Cannot create image. Size too big".

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-04-28 18:32:09 +03:00
parent aff0095d8d
commit ec5b28fe0b
4 changed files with 42 additions and 22 deletions

View File

@ -1544,11 +1544,13 @@ void MainWindow::CleanLayout()
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::PrepareSceneList()
void MainWindow::PrepareSceneList(PreviewQuatilty quality)
{
ui->listWidget->clear();
for (int i=1; i<=scenes.size(); ++i)
{
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1), QString::number(i));
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1, ui->listWidget->iconSize(), quality),
QString::number(i));
ui->listWidget->addItem(item);
}

View File

@ -106,7 +106,7 @@ protected:
virtual void closeEvent(QCloseEvent *event) override;
virtual void customEvent(QEvent * event) override;
virtual void CleanLayout() override;
virtual void PrepareSceneList() override;
virtual void PrepareSceneList(PreviewQuatilty quality) override;
virtual void ExportToCSVData(const QString &fileName, bool withHeader, int mib,
const QChar &separator) final;
private slots:

View File

@ -322,7 +322,10 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
//Uncomment to debug, shows global contour
// gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging
// InsertGlobalContours(scenes, gcontours); // uncomment for debugging
PrepareSceneList();
if (VApplication::IsGUIMode())
{
PrepareSceneList(PreviewQuatilty::Fast);
}
ignorePrinterFields = not lGenerator.IsUsePrinterFields();
margins = lGenerator.GetPrinterFields();
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
@ -377,6 +380,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
if (VApplication::IsGUIMode())
{
PrepareSceneList(PreviewQuatilty::Slow);
progress->Finished();
}
@ -1005,36 +1009,48 @@ void MainWindowsNoGUI::InitTempLayoutScene()
}
//---------------------------------------------------------------------------------------------------------------------
QIcon MainWindowsNoGUI::ScenePreview(int i) const
QIcon MainWindowsNoGUI::ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const
{
QImage image;
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
{
const QRectF r = paper->rect();
// Create the image with the exact size of the shrunk scene
image = QImage(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_RGB32);
if (not image.isNull())
if (quality == PreviewQuatilty::Fast)
{
image = QImage(iconSize, QImage::Format_RGB32);
image.fill(Qt::white);
QPainter painter(&image);
painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio);
painter.end();
}
else
{
qWarning()<<"Cannot create image. Size too big";
const QRectF r = paper->rect();
// Create the image with the exact size of the shrunk scene
image = QImage(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())),
QImage::Format_RGB32);
if (not image.isNull())
{
image.fill(Qt::white);
QPainter painter(&image);
painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio);
painter.end();
}
else
{
qDebug()<<"Cannot create image. Size " << r.size() << "too big";
image = QImage(iconSize, QImage::Format_RGB32);
image.fill(Qt::white);
}
}
}
else
{
image = QImage(QSize(101, 146), QImage::Format_RGB32);
image = QImage(iconSize, QImage::Format_RGB32);
image.fill(Qt::white);
}
return QIcon(QBitmap::fromImage(image));

View File

@ -66,6 +66,8 @@ struct DetailForLayout {
QT_WARNING_POP
enum class PreviewQuatilty : bool {Fast = true, Slow = false};
class MainWindowsNoGUI : public VAbstractMainWindow
{
Q_OBJECT
@ -131,8 +133,8 @@ protected:
void InitTempLayoutScene();
virtual void CleanLayout()=0;
virtual void PrepareSceneList()=0;
QIcon ScenePreview(int i) const;
virtual void PrepareSceneList(PreviewQuatilty quality)=0;
QIcon ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const;
bool GenerateLayout(VLayoutGenerator& lGenerator);
int ContinueIfLayoutStale();
QString FileName() const;