diff --git a/clayout.cpp b/clayout.cpp index 6a776e5..e95943b 100644 --- a/clayout.cpp +++ b/clayout.cpp @@ -3,9 +3,10 @@ #include "common.h" -#include #include #include +#include +#include #include @@ -17,6 +18,9 @@ cLayout::cLayout(QWidget *parent) : { ui->setupUi(this); + QGraphicsScene* lpScene = new QGraphicsScene; + ui->m_lpLayoutPreview->setScene(lpScene); + for(int id = 0;id < QPageSize::LastPageSize;id++) ui->m_lpPageSize->addItem(QPageSize::name(static_cast(id)), QVariant::fromValue(static_cast(id))); @@ -136,6 +140,51 @@ void cLayout::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } +QPageSize cLayout::pageSize() +{ + return(QPageSize(ui->m_lpPageSize->currentData().value())); +} + +qreal cLayout::borderTop() +{ + return(ui->m_lpBorderTop->value()); +} + +qreal cLayout::borderLeft() +{ + return(ui->m_lpBorderLeft->value()); +} + +qreal cLayout::borderRight() +{ + return(ui->m_lpBorderRight->value()); +} + +qreal cLayout::borderBottom() +{ + return(ui->m_lpBorderBottom->value()); +} + +qreal cLayout::gutter() +{ + return(ui->m_lpGutterWidth->value()); +} + +int cLayout::tilesH() +{ + return(ui->m_lpTilesH->value()); +} + +int cLayout::tilesV() +{ + return(ui->m_lpTilesV->value()); +} + +QPageSize::Unit cLayout::unit() +{ + return(ui->m_lpUnit->currentData().value()); +} + void cLayout::redrawPreview() { QSize widgetSize = ui->m_lpLayoutPreview->size(); @@ -150,8 +199,8 @@ void cLayout::redrawPreview() qreal gutter = ui->m_lpGutterWidth->value(); qreal tilesH = static_cast(ui->m_lpTilesH->value()); qreal tilesV = static_cast(ui->m_lpTilesV->value()); - qreal scaleFactor = static_cast(widgetSize.width()-10) / pageWidth; - qreal tmp = static_cast(widgetSize.height()-10) / pageHeight; + qreal scaleFactor = static_cast(widgetSize.width()-40) / pageWidth; + qreal tmp = static_cast(widgetSize.height()-40) / pageHeight; QString unit; @@ -188,19 +237,19 @@ void cLayout::redrawPreview() if(tmp < scaleFactor) scaleFactor = tmp; - QPixmap pixmap(scale(size, scaleFactor)); - pixmap.fill(Qt::white); - QPainter painter(&pixmap); + QGraphicsScene* lpScene = ui->m_lpLayoutPreview->scene(); + + lpScene->clear(); + + lpScene->setSceneRect(0, 0, scale(size, scaleFactor).width(), scale(size, scaleFactor).height()); + QGraphicsRectItem* paperRect = new QGraphicsRectItem(0, 0, scale(size, scaleFactor).width(), scale(size, scaleFactor).height()); + paperRect->setBrush(QBrush(Qt::white)); + lpScene->addItem(paperRect); QRectF rect; qreal rectW = (pageWidth-borderLeft-borderRight-gutter*(tilesH-1)) / tilesH; qreal rectH = (pageHeight-borderTop-borderBottom-gutter*(tilesV-1)) / tilesV; -// borderTop = scale(borderTop, scaleFactor); -// borderLeft = scale(borderLeft, scaleFactor); - - painter.setPen(Qt::black); - for(qreal x = 0;x < tilesH;x++) { for(qreal y = 0;y < tilesV;y++) @@ -210,11 +259,12 @@ void cLayout::redrawPreview() rect.setTopLeft(scale(QPointF(l, t), scaleFactor)); rect.setSize(scale(QSizeF(rectW, rectH), scaleFactor)); -// rect.setTopLeft(QPoint(borderLeft+x*(rectW+gutter), borderTop+y*(rectH+gutter))); -// rect.setSize(QSizeF(rectW, rectH)); - painter.drawRect(rect); + + QGraphicsRectItem* lpRect = new QGraphicsRectItem(rect); + lpRect->setPen(QPen(Qt::black)); + lpScene->addItem(lpRect); } } - ui->m_lpLayoutPreview->setPixmap(pixmap); + emit layoutChanged(); } diff --git a/clayout.h b/clayout.h index 264e004..f5a3948 100644 --- a/clayout.h +++ b/clayout.h @@ -8,6 +8,7 @@ #include +#include namespace Ui { @@ -38,6 +39,16 @@ public: */ ~cLayout(); + QPageSize pageSize(); + qreal borderTop(); + qreal borderLeft(); + qreal borderRight(); + qreal borderBottom(); + qreal gutter(); + int tilesH(); + int tilesV(); + QPageSize::Unit unit(); + private: Ui::cLayout* ui; /*!< TODO: describe */ bool m_initializing; /*!< TODO: describe */ @@ -125,6 +136,16 @@ private slots: */ void onGutterChanged(double value); +signals: + /*! + \brief + + \fn layoutChanged + \param layout + \param i + */ + void layoutChanged(); + protected: /*! \brief diff --git a/clayout.ui b/clayout.ui index 9bce5d9..115bda5 100644 --- a/clayout.ui +++ b/clayout.ui @@ -15,7 +15,7 @@ - + @@ -347,11 +347,7 @@ - - - - - + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 9cdba2e..3d1ab4c 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -30,6 +30,8 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) createActions(); ui->m_lpMainTab->setCurrentIndex(1); + + connect(m_lpLayout, &cLayout::layoutChanged, m_lpPrint, &cPrint::onLayoutChanged); } cMainWindow::~cMainWindow() @@ -87,7 +89,7 @@ void cMainWindow::initUI() m_lpLayout = new cLayout(this); ui->m_lpMainTab->addTab(m_lpLayout, "Layout"); - m_lpPrint = new cPrint(m_lpProgressBar, ui->m_lpSelectedList, m_lpSelectedListModel, this); + m_lpPrint = new cPrint(m_lpProgressBar, ui->m_lpSelectedList, m_lpSelectedListModel, m_lpLayout, this); ui->m_lpMainTab->addTab(m_lpPrint, "Print"); if(!settings.value("main/maximized").toBool()) @@ -102,20 +104,10 @@ void cMainWindow::initUI() if(iX != -1 && iY != -1) move(iX, iY); } - -// QStringList headerLabels = QStringList() << tr("icon") << tr("path") << tr("file") << tr("size") << tr("date") << tr("width") << tr("height") << (""); -// m_lpFileListModel->setHorizontalHeaderLabels(headerLabels); } void cMainWindow::createActions() { -// setToolButtonStyle(Qt::ToolButtonFollowStyle); - -// createFileActions(); -// createContextActions(); - -// connect(ui->m_lpFileList, &cTreeView::deleteEntrys, this, &cMainWindow::onDeleteEntrys); -// connect(ui->m_lpThumbnailSize, &QSlider::valueChanged, this, &cMainWindow::onThumbnailSize); } void cMainWindow::createContextActions() @@ -124,34 +116,6 @@ void cMainWindow::createContextActions() void cMainWindow::createFileActions() { -// m_lpFileToolBar = addToolBar("file"); - -// const QIcon openIcon = QIcon::fromTheme("document-open"); -// m_lpOpenFileAction = m_lpFileToolBar->addAction(openIcon, tr("&Open..."), this, &cMainWindow::onAddFile); -// m_lpOpenFileAction->setShortcut(QKeySequence::Open); - -// const QIcon openDirectoryIcon = QIcon::fromTheme("folder"); -// m_lpOpenDirectoryAction = m_lpFileToolBar->addAction(openIcon, tr("&Open Folder..."), this, &cMainWindow::onAddFolder); - - -// m_lpListToolBar = addToolBar("list"); - -// const QIcon deleteIcon = QIcon::fromTheme("edit-delete"); -// m_lpDeleteAction = m_lpListToolBar->addAction(deleteIcon, tr("&Delete"), this, &cMainWindow::onDeleteEntrys); -// m_lpDeleteAction->setShortcut(QKeySequence::Delete); - -// const QIcon clearIcon = QIcon::fromTheme("edit-clear"); -// m_lpClearAction = m_lpListToolBar->addAction(clearIcon, tr("&Clear"), this, &cMainWindow::onClearList); - - -// m_lpActionToolBar = addToolBar("action"); - -// const QIcon convertIcon = QIcon::fromTheme("system-run"); -// m_lpConvertAction = m_lpActionToolBar->addAction(convertIcon, tr("&Convert"), this, &cMainWindow::onConvert); -// m_lpConvertAction->setShortcut(QKeySequence::Delete); - -// const QIcon stopIcon = QIcon::fromTheme("process-stop"); -// m_lpStopAction = m_lpActionToolBar->addAction(stopIcon, tr("&Stop"), this, &cMainWindow::onStop); } void cMainWindow::setImageFormats() diff --git a/cprint.cpp b/cprint.cpp index c44a760..701ec02 100644 --- a/cprint.cpp +++ b/cprint.cpp @@ -20,15 +20,19 @@ #include -cPrint::cPrint(QProgressBar* lpProgressBar, QListView* lpSelectedList, QStandardItemModel* lpSelectedListModel, QWidget *parent) : +cPrint::cPrint(QProgressBar* lpProgressBar, QListView* lpSelectedList, QStandardItemModel* lpSelectedListModel, cLayout* lpLayout, QWidget *parent) : QWidget(parent), ui(new Ui::cPrint), m_lpProgressBar(lpProgressBar), m_lpSelectedList(lpSelectedList), - m_lpSelectedListModel(lpSelectedListModel) + m_lpSelectedListModel(lpSelectedListModel), + m_lpLayout(lpLayout) { ui->setupUi(this); + ui->m_lpPaperSourceLabel->setVisible(false); + ui->m_lpPaperSource->setVisible(false); + m_printerStateText.insert(QPrinter::Idle, tr("idle")); m_printerStateText.insert(QPrinter::Active, tr("Active")); m_printerStateText.insert(QPrinter::Aborted, tr("Aborted")); @@ -72,6 +76,9 @@ cPrint::cPrint(QProgressBar* lpProgressBar, QListView* lpSelectedList, QStandard ui->m_lpZoomOriginal->setIcon(QIcon::fromTheme("zoom-original")); ui->m_lpZoomIn->setIcon(QIcon::fromTheme("zoom-in")); + ui->m_lpPrintPreview->setIcon(QIcon::fromTheme("document-print-preview")); + ui->m_lpPrint->setIcon(QIcon::fromTheme("document-print")); + connect(ui->m_lpPrinterSelect, &QComboBox::currentTextChanged, this, &cPrint::onPrinterChanged); connect(ui->m_lpPrinterProperties, &QPushButton::clicked, this, &cPrint::onPrinterSettings); connect(ui->m_lpPrintPreview, &QPushButton::clicked, this, &cPrint::onPrintPreview); @@ -96,6 +103,11 @@ cPrint::~cPrint() delete ui; } +void cPrint::onLayoutChanged() +{ + ui->m_lpPrintPreview->setEnabled(true); +} + void cPrint::onPrinterChanged(const QString& printer) { m_lpPrinter->setPrinterName(printer); @@ -120,12 +132,16 @@ void cPrint::onPrinterChanged(const QString& printer) for(int x = 0;x < paperSources.count();x++) ui->m_lpPaperSource->addItem(m_printerPaperSource[paperSources[x]]); ui->m_lpPaperSource->setCurrentText(m_printerPaperSource[m_lpPrinter->paperSource()]); + + ui->m_lpPrintPreview->setEnabled(true); } void cPrint::onPrinterSettings() { QPrintDialog printDialog(m_lpPrinter); printDialog.exec(); + + ui->m_lpPrintPreview->setEnabled(true); } void cPrint::onPrintPreview() @@ -138,6 +154,8 @@ void cPrint::onPrintPreview() return; m_lpPrintPreviewWidget->updatePreview(); + + ui->m_lpPrintPreview->setEnabled(false); } void cPrint::onPaintRequested(QPrinter* printer) @@ -155,6 +173,17 @@ void cPrint::onPaintRequested(QPrinter* printer) if(image.isNull()) return; + QPageSize pageSize = m_lpLayout->pageSize(); + qreal borderTop = m_lpLayout->borderTop(); + qreal borderLeft = m_lpLayout->borderLeft(); + qreal borderRight = m_lpLayout->borderRight(); + qreal borderBottom = m_lpLayout->borderBottom(); + qreal gutter = m_lpLayout->gutter(); + int tilesH = m_lpLayout->tilesH(); + int tilesV = m_lpLayout->tilesV(); + QPageSize::Unit unit = m_lpLayout->unit(); + + printer->setPageSize(pageSize); printer->newPage(); QPixmap pixmap = QPixmap::fromImage(image); diff --git a/cprint.h b/cprint.h index 898e528..9a78e8a 100644 --- a/cprint.h +++ b/cprint.h @@ -7,6 +7,8 @@ #define CPRINT_H +#include "clayout.h" + #include #include @@ -37,7 +39,7 @@ public: \fn cPrint \param parent */ - explicit cPrint(QProgressBar* lpProgressBar, QListView* lpSelectedList, QStandardItemModel* lpSelectedListModel, QWidget *parent = nullptr); + explicit cPrint(QProgressBar* lpProgressBar, QListView* lpSelectedList, QStandardItemModel* lpSelectedListModel, cLayout* lpLayout, QWidget *parent = nullptr); /*! \brief @@ -50,6 +52,7 @@ private: QProgressBar* m_lpProgressBar; /*!< TODO: describe */ QListView* m_lpSelectedList; /*!< TODO: describe */ QStandardItemModel* m_lpSelectedListModel; /*!< TODO: describe */ + cLayout* m_lpLayout; /*!< TODO: describe */ QPrinter* m_lpPrinter; /*!< TODO: describe */ QPrintPreviewWidget* m_lpPrintPreviewWidget; /*!< TODO: describe */ @@ -57,7 +60,17 @@ private: QMap m_printerStateText; /*!< TODO: describe */ QMap m_printerPaperSource; /*!< TODO: describe */ +public slots: + /*! + \brief + + \fn onLayoutChanged + \param layout + */ + void onLayoutChanged(); + private slots: + /*! \brief diff --git a/cprint.ui b/cprint.ui index 1b61328..c05e40c 100644 --- a/cprint.ui +++ b/cprint.ui @@ -39,7 +39,7 @@ - + Name: @@ -86,7 +86,7 @@ - + Printer Model: @@ -96,7 +96,7 @@ - + Status: @@ -113,7 +113,7 @@ - + Location: @@ -136,7 +136,7 @@ - + Paper Size: @@ -162,7 +162,7 @@ - + Paper Source: @@ -225,6 +225,12 @@ zoom to fit + + + 24 + 24 + + @@ -238,6 +244,12 @@ zoom original + + + 24 + 24 + + @@ -251,6 +263,50 @@ zoom in + + + 24 + 24 + + + + + + + + print preview + + + print preview + + + print preview + + + + 24 + 24 + + + + + + + + print + + + print + + + print + + + + 24 + 24 + + @@ -266,20 +322,6 @@ - - - - preview - - - - - - - print - - - diff --git a/pictureprint.qrc b/pictureprint.qrc index e047c37..53a7da1 100644 --- a/pictureprint.qrc +++ b/pictureprint.qrc @@ -16,5 +16,11 @@ images/arc/24x24/actions/zoom-in.png images/arc/24x24/actions/zoom-original.png images/arc/24x24/actions/zoom-out.png + images/arc/16x16/actions/document-print.png + images/arc/16x16/actions/document-print-preview.png + images/arc/22x22/actions/document-print.png + images/arc/22x22/actions/document-print-preview.png + images/arc/24x24/actions/document-print.png + images/arc/24x24/actions/document-print-preview.png