diff --git a/cfilebrowser.cpp b/cfilebrowser.cpp index 7de78eb..5059697 100644 --- a/cfilebrowser.cpp +++ b/cfilebrowser.cpp @@ -131,6 +131,8 @@ void cFileBrowser::onCountChanged(cFileViewer* fileViewer) } else m_lpSelectedListModel->removeRow(x); + + emit countChanged(); return; } } @@ -145,6 +147,8 @@ void cFileBrowser::onCountChanged(cFileViewer* fileViewer) m_lpSelectedList->setIndexWidget(m_lpSelectedListModel->index(m_lpSelectedListModel->rowCount()-1, 0), lpFileViewer1); connect(lpFileViewer1, &cFileViewer::countChanged, this, &cFileBrowser::onCountChangedSelected); + + emit countChanged(); } void cFileBrowser::onCountChangedSelected(cFileViewer* fileViewer) @@ -162,10 +166,13 @@ void cFileBrowser::onCountChangedSelected(cFileViewer* fileViewer) lpFileViewer->setCount(fileViewer->count()); connect(lpFileViewer, &cFileViewer::countChanged, this, &cFileBrowser::onCountChangedSelected); + emit countChanged(); return; } } } + + emit countChanged(); } void cFileBrowser::directorySelected(const QString& filePath) diff --git a/cfilebrowser.h b/cfilebrowser.h index f61c556..e09b20e 100644 --- a/cfilebrowser.h +++ b/cfilebrowser.h @@ -91,6 +91,9 @@ private: */ void addFile(const QFileInfo& fileInfo); +signals: + void countChanged(); + private slots: /*! \brief diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 3d1ab4c..0086920 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -31,7 +31,8 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) ui->m_lpMainTab->setCurrentIndex(1); - connect(m_lpLayout, &cLayout::layoutChanged, m_lpPrint, &cPrint::onLayoutChanged); + connect(m_lpLayout, &cLayout::layoutChanged, m_lpPrint, &cPrint::onLayoutChanged); + connect(m_lpFileBrowser, &cFileBrowser::countChanged, m_lpPrint, &cPrint::onCountChanged); } cMainWindow::~cMainWindow() diff --git a/cprint.cpp b/cprint.cpp index 33fdb44..27e2fa6 100644 --- a/cprint.cpp +++ b/cprint.cpp @@ -108,6 +108,11 @@ void cPrint::onLayoutChanged() ui->m_lpPrintPreview->setEnabled(true); } +void cPrint::onCountChanged() +{ + ui->m_lpPrintPreview->setEnabled(true); +} + void cPrint::onPrinterChanged(const QString& printer) { m_lpPrinter->setPrinterName(printer); @@ -146,12 +151,12 @@ void cPrint::onPrinterSettings() void cPrint::onPrintPreview() { - if(!m_lpSelectedListModel->rowCount()) - return; +// if(!m_lpSelectedListModel->rowCount()) +// return; - cFileViewer* lpFileViewer = static_cast(m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(0, 0))); - if(!lpFileViewer) - return; +// cFileViewer* lpFileViewer = static_cast(m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(0, 0))); +// if(!lpFileViewer) +// return; m_lpPrintPreviewWidget->updatePreview(); @@ -160,14 +165,8 @@ void cPrint::onPrintPreview() void cPrint::onPaintRequested(QPrinter* printer) { - if(!m_lpSelectedListModel->rowCount()) - return; - QPageSize pageSize = m_lpLayout->pageSize(); QPageSize::Unit unit = m_lpLayout->unit(); - QSizeF size = pageSize.size(unit); - qreal pageWidth = size.width(); - qreal pageHeight = size.height(); QMarginsF pageMargins = m_lpLayout->pageMargins(); qreal borderTop = m_lpLayout->borderTop(); qreal borderLeft = m_lpLayout->borderLeft(); @@ -177,6 +176,12 @@ void cPrint::onPaintRequested(QPrinter* printer) int tilesH = m_lpLayout->tilesH(); int tilesV = m_lpLayout->tilesV(); + printer->setPageSize(pageSize); + printer->setPageMargins(pageMargins, static_cast(unit)); + + QSizeF printerSize = printer->pageRect(QPrinter::DevicePixel).size(); + qreal pageWidth = printerSize.width(); + qreal pageHeight = printerSize.height(); qreal rectW = (pageWidth-borderLeft-borderRight-gutter*(tilesH-1)) / tilesH; qreal rectH = (pageHeight-borderTop-borderBottom-gutter*(tilesV-1)) / tilesV; bool portrait = true; @@ -184,56 +189,75 @@ void cPrint::onPaintRequested(QPrinter* printer) if(rectW > rectH) portrait = false; - printer->setPageSize(pageSize); - printer->setPageMargins(pageMargins, static_cast(unit)); - - int imageNr = 0; - printer->newPage(); - for(int x = 0;x < tilesH;x++) + QPainter painter(printer); + int listIndex = 0; + qint32 imageCount = 0; + cImage image; + + for(;;) { - for(int y = 0;y < tilesV;y++) + for(int x = 0;x < tilesH;x++) { - cFileViewer* lpFileViewer = static_cast(m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(imageNr, 0))); - if(!lpFileViewer) - return; - - QString fileName = lpFileViewer->fileName(); - cImage image(fileName); - - if(image.isNull()) - return; - - QPixmap pixmap; - - if((image.width() < image.height() && !portrait) || - (image.width() > image.height() && portrait)) + for(int y = 0;y < tilesV;y++) { - QPoint center = image.rect().center(); - QMatrix matrix; - matrix.translate(center.x(), center.y()); - matrix.rotate(90); - pixmap = QPixmap::fromImage(image.transformed(matrix)); + if(!imageCount) + { + cFileViewer* lpFileViewer = static_cast(m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(listIndex, 0))); + if(!lpFileViewer) + return; + + imageCount = lpFileViewer->count()-1; + listIndex++; + + QString fileName = lpFileViewer->fileName(); + image.load(fileName); + } + else + imageCount--; + + if(image.isNull()) + return; + + QPixmap pixmap; + + if((image.width() < image.height() && !portrait) || + (image.width() > image.height() && portrait)) + { + QPoint center = image.rect().center(); + QMatrix matrix; + matrix.translate(center.x(), center.y()); + matrix.rotate(90); + pixmap = QPixmap::fromImage(image.transformed(matrix)); + } + else + pixmap = QPixmap::fromImage(image); + + QRect rect = QRect(0, 0, static_cast(rectW), static_cast(rectH)); + QSize size = pixmap.size(); + + int t = static_cast(borderTop+static_cast(y)*(rectH+gutter)); + int l = static_cast(borderLeft+static_cast(x)*(rectW+gutter)); + +// size.scale(rect.size(), Qt::KeepAspectRatio); + size.scale(rect.size(), Qt::KeepAspectRatioByExpanding); + + if(size.width() > rect.width()) + size.setWidth(rect.width()); + if(size.height() > rect.height()) + size.setHeight(rect.height()); + + painter.setViewport(l, t, size.width(), size.height()); + + painter.setWindow(pixmap.rect()); + painter.drawPixmap(0, 0, pixmap); + + if(!imageCount && listIndex >= m_lpSelectedListModel->rowCount()) + return; } - else - pixmap = QPixmap::fromImage(image); - - QPainter painter(printer); -// QRect rectViewport = painter.viewport(); - QRect rect = QRect(0, 0, static_cast(rectW), static_cast(rectH)); - QSize size = pixmap.size(); - - int t = static_cast(borderTop+static_cast(y)*(rectH+gutter)); - int l = static_cast(borderLeft+static_cast(x)*(rectW+gutter)); - - size.scale(rect.size(), Qt::KeepAspectRatio); -// painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); - painter.setViewport(l, t, size.width(), size.height()); - painter.setWindow(pixmap.rect()); -// painter.drawPixmap(0, 0, pixmap); - painter.drawPixmap(l, t, pixmap); } + printer->newPage(); } } diff --git a/cprint.h b/cprint.h index 9a78e8a..be48a9c 100644 --- a/cprint.h +++ b/cprint.h @@ -65,9 +65,14 @@ public slots: \brief \fn onLayoutChanged - \param layout */ void onLayoutChanged(); + /*! + \brief + + \fn onCountChanged + */ + void onCountChanged(); private slots: