Improve handling warning "Cannot create image. Size too big".
--HG-- branch : develop
This commit is contained in:
parent
aff0095d8d
commit
ec5b28fe0b
|
@ -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)
|
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);
|
ui->listWidget->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ protected:
|
||||||
virtual void closeEvent(QCloseEvent *event) override;
|
virtual void closeEvent(QCloseEvent *event) override;
|
||||||
virtual void customEvent(QEvent * event) override;
|
virtual void customEvent(QEvent * event) override;
|
||||||
virtual void CleanLayout() 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,
|
virtual void ExportToCSVData(const QString &fileName, bool withHeader, int mib,
|
||||||
const QChar &separator) final;
|
const QChar &separator) final;
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -322,7 +322,10 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
|
||||||
//Uncomment to debug, shows global contour
|
//Uncomment to debug, shows global contour
|
||||||
// gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging
|
// gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging
|
||||||
// InsertGlobalContours(scenes, gcontours); // uncomment for debugging
|
// InsertGlobalContours(scenes, gcontours); // uncomment for debugging
|
||||||
PrepareSceneList();
|
if (VApplication::IsGUIMode())
|
||||||
|
{
|
||||||
|
PrepareSceneList(PreviewQuatilty::Fast);
|
||||||
|
}
|
||||||
ignorePrinterFields = not lGenerator.IsUsePrinterFields();
|
ignorePrinterFields = not lGenerator.IsUsePrinterFields();
|
||||||
margins = lGenerator.GetPrinterFields();
|
margins = lGenerator.GetPrinterFields();
|
||||||
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
|
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
|
||||||
|
@ -377,6 +380,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
|
||||||
|
|
||||||
if (VApplication::IsGUIMode())
|
if (VApplication::IsGUIMode())
|
||||||
{
|
{
|
||||||
|
PrepareSceneList(PreviewQuatilty::Slow);
|
||||||
progress->Finished();
|
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;
|
QImage image;
|
||||||
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
|
||||||
if (paper)
|
if (paper)
|
||||||
{
|
{
|
||||||
const QRectF r = paper->rect();
|
if (quality == PreviewQuatilty::Fast)
|
||||||
// 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 = QImage(iconSize, QImage::Format_RGB32);
|
||||||
image.fill(Qt::white);
|
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
|
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
|
else
|
||||||
{
|
{
|
||||||
image = QImage(QSize(101, 146), QImage::Format_RGB32);
|
image = QImage(iconSize, QImage::Format_RGB32);
|
||||||
image.fill(Qt::white);
|
image.fill(Qt::white);
|
||||||
}
|
}
|
||||||
return QIcon(QBitmap::fromImage(image));
|
return QIcon(QBitmap::fromImage(image));
|
||||||
|
|
|
@ -66,6 +66,8 @@ struct DetailForLayout {
|
||||||
|
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
|
|
||||||
|
enum class PreviewQuatilty : bool {Fast = true, Slow = false};
|
||||||
|
|
||||||
class MainWindowsNoGUI : public VAbstractMainWindow
|
class MainWindowsNoGUI : public VAbstractMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -131,8 +133,8 @@ protected:
|
||||||
|
|
||||||
void InitTempLayoutScene();
|
void InitTempLayoutScene();
|
||||||
virtual void CleanLayout()=0;
|
virtual void CleanLayout()=0;
|
||||||
virtual void PrepareSceneList()=0;
|
virtual void PrepareSceneList(PreviewQuatilty quality)=0;
|
||||||
QIcon ScenePreview(int i) const;
|
QIcon ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const;
|
||||||
bool GenerateLayout(VLayoutGenerator& lGenerator);
|
bool GenerateLayout(VLayoutGenerator& lGenerator);
|
||||||
int ContinueIfLayoutStale();
|
int ContinueIfLayoutStale();
|
||||||
QString FileName() const;
|
QString FileName() const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user