diff --git a/clayout.cpp b/clayout.cpp new file mode 100644 index 0000000..6a776e5 --- /dev/null +++ b/clayout.cpp @@ -0,0 +1,220 @@ +#include "clayout.h" +#include "ui_clayout.h" + +#include "common.h" + +#include +#include +#include + +#include + + +cLayout::cLayout(QWidget *parent) : + QWidget(parent), + ui(new Ui::cLayout), + m_initializing(true) +{ + ui->setupUi(this); + + for(int id = 0;id < QPageSize::LastPageSize;id++) + ui->m_lpPageSize->addItem(QPageSize::name(static_cast(id)), QVariant::fromValue(static_cast(id))); + + ui->m_lpUnit->addItem("Millimeter", QVariant::fromValue(QPageSize::Millimeter)); + ui->m_lpUnit->addItem("Point", QVariant::fromValue(QPageSize::Point)); + ui->m_lpUnit->addItem("Inch", QVariant::fromValue(QPageSize::Inch)); + ui->m_lpUnit->addItem("Pica", QVariant::fromValue(QPageSize::Pica)); + ui->m_lpUnit->addItem("Didot", QVariant::fromValue(QPageSize::Didot)); + ui->m_lpUnit->addItem("Cicero", QVariant::fromValue(QPageSize::Cicero)); + + connect(ui->m_lpPageSize, QOverload::of(&QComboBox::currentIndexChanged), this, &cLayout::onPageSizeChanged); + connect(ui->m_lpUnit, QOverload::of(&QComboBox::currentIndexChanged), this, &cLayout::onUnitChanged); + connect(ui->m_lpBorderAllTheSame, &QCheckBox::stateChanged, this, &cLayout::onAllTheSameChanged); + connect(ui->m_lpTilesH, QOverload::of(&QSpinBox::valueChanged), this, &cLayout::onTileHChanged); + connect(ui->m_lpTilesV, QOverload::of(&QSpinBox::valueChanged), this, &cLayout::onTileVChanged); + connect(ui->m_lpBorderTop, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderTopChanged); + connect(ui->m_lpBorderLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderLeftChanged); + connect(ui->m_lpBorderRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderRightChanged); + connect(ui->m_lpBorderBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderBottomChanged); + connect(ui->m_lpGutterWidth, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onGutterChanged); + + m_initializing = false; +} + +cLayout::~cLayout() +{ + delete ui; +} + +void cLayout::onPageSizeChanged(int /*index*/) +{ + redrawPreview(); +} + +void cLayout::onUnitChanged(int /*index*/) +{ + redrawPreview(); +} + +void cLayout::onAllTheSameChanged(int /*state*/) +{ + if(ui->m_lpBorderAllTheSame->isChecked()) + { + disconnect(ui->m_lpBorderLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderLeftChanged); + disconnect(ui->m_lpBorderRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderRightChanged); + disconnect(ui->m_lpBorderBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderBottomChanged); + + ui->m_lpBorderLeft->setValue(ui->m_lpBorderTop->value()); + ui->m_lpBorderRight->setValue(ui->m_lpBorderTop->value()); + ui->m_lpBorderBottom->setValue(ui->m_lpBorderTop->value()); + + ui->m_lpBorderLeft->setEnabled(false); + ui->m_lpBorderRight->setEnabled(false); + ui->m_lpBorderBottom->setEnabled(false); + + redrawPreview(); + } + else + { + ui->m_lpBorderLeft->setEnabled(true); + ui->m_lpBorderRight->setEnabled(true); + ui->m_lpBorderBottom->setEnabled(true); + + connect(ui->m_lpBorderLeft, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderLeftChanged); + connect(ui->m_lpBorderRight, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderRightChanged); + connect(ui->m_lpBorderBottom, QOverload::of(&QDoubleSpinBox::valueChanged), this, &cLayout::onBorderBottomChanged); + } +} + +void cLayout::onTileHChanged(int /*value*/) +{ + redrawPreview(); +} + +void cLayout::onTileVChanged(int /*value*/) +{ + redrawPreview(); +} + +void cLayout::onBorderTopChanged(double /*value*/) +{ + if(ui->m_lpBorderAllTheSame->isChecked()) + { + ui->m_lpBorderLeft->setValue(ui->m_lpBorderTop->value()); + ui->m_lpBorderRight->setValue(ui->m_lpBorderTop->value()); + ui->m_lpBorderBottom->setValue(ui->m_lpBorderTop->value()); + } + + redrawPreview(); +} + +void cLayout::onBorderLeftChanged(double /*value*/) +{ + redrawPreview(); +} + +void cLayout::onBorderRightChanged(double /*value*/) +{ + redrawPreview(); +} + +void cLayout::onBorderBottomChanged(double /*value*/) +{ + redrawPreview(); +} + +void cLayout::onGutterChanged(double /*value*/) +{ + redrawPreview(); +} + +void cLayout::resizeEvent(QResizeEvent *event) +{ + if(!m_initializing) + redrawPreview(); + + QWidget::resizeEvent(event); +} + +void cLayout::redrawPreview() +{ + QSize widgetSize = ui->m_lpLayoutPreview->size(); + QPageSize pageSize(ui->m_lpPageSize->currentData().value()); + QSizeF size = pageSize.size(ui->m_lpUnit->currentData().value()); + qreal pageWidth = size.width(); + qreal pageHeight = size.height(); + qreal borderTop = ui->m_lpBorderTop->value(); + qreal borderLeft = ui->m_lpBorderLeft->value(); + qreal borderRight = ui->m_lpBorderRight->value(); + qreal borderBottom = ui->m_lpBorderBottom->value(); + 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; + + QString unit; + + switch(ui->m_lpUnit->currentData().value()) + { + case QPageSize::Millimeter: + unit = tr("Millimeter"); + break; + case QPageSize::Point: + unit = tr("Point(s)"); + break; + case QPageSize::Inch: + unit = tr("Inch"); + break; + case QPageSize::Pica: + unit = tr("Pica"); + break; + case QPageSize::Didot: + unit = tr("Didot"); + break; + case QPageSize::Cicero: + unit = tr("Cicero"); + break; + } + + ui->m_lpPaperSizeText->setText(QString::number(pageWidth) + " " + unit + " x " + QString::number(pageHeight) + " " + unit); + + ui->m_lpBorderTop->setSuffix(QString(" ") + unit); + ui->m_lpBorderLeft->setSuffix(QString(" ") + unit); + ui->m_lpBorderRight->setSuffix(QString(" ") + unit); + ui->m_lpBorderBottom->setSuffix(QString(" ") + unit); + ui->m_lpGutterWidth->setSuffix(QString(" ") + unit); + + if(tmp < scaleFactor) + scaleFactor = tmp; + + QPixmap pixmap(scale(size, scaleFactor)); + pixmap.fill(Qt::white); + QPainter painter(&pixmap); + + 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++) + { + qreal t = borderTop+y*(rectH+gutter); + qreal l = borderLeft+x*(rectW+gutter); + + 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); + } + } + + ui->m_lpLayoutPreview->setPixmap(pixmap); +} diff --git a/clayout.h b/clayout.h new file mode 100644 index 0000000..264e004 --- /dev/null +++ b/clayout.h @@ -0,0 +1,138 @@ +/*! + \file clayout.h + +*/ + +#ifndef CLAYOUT_H +#define CLAYOUT_H + + +#include + + +namespace Ui { +class cLayout; +} + +/*! + \brief + + \class cLayout clayout.h "clayout.h" +*/ +class cLayout : public QWidget +{ + Q_OBJECT + +public: + /*! + \brief + + \fn cLayout + \param parent + */ + explicit cLayout(QWidget *parent = nullptr); + /*! + \brief + + \fn ~cLayout + */ + ~cLayout(); + +private: + Ui::cLayout* ui; /*!< TODO: describe */ + bool m_initializing; /*!< TODO: describe */ + + /*! + \brief + + \fn redrawPreview + */ + void redrawPreview(); + +private slots: + /*! + \brief + + \fn onPageSizeChanged + \param index + */ + void onPageSizeChanged(int index); + + /*! + \brief + + \fn onUnitChanged + \param index + */ + void onUnitChanged(int index); + + /*! + \brief + + \fn onAllTheSameChanged + \param state + */ + void onAllTheSameChanged(int state); + + /*! + \brief + + \fn onTileHChanged + \param value + */ + void onTileHChanged(int value); + /*! + \brief + + \fn onTileVChanged + \param value + */ + void onTileVChanged(int value); + + /*! + \brief + + \fn onBorderTopChanged + \param value + */ + void onBorderTopChanged(double value); + /*! + \brief + + \fn onBorderLeftChanged + \param value + */ + void onBorderLeftChanged(double value); + /*! + \brief + + \fn onBorderRightChanged + \param value + */ + void onBorderRightChanged(double value); + /*! + \brief + + \fn onBorderBottomChanged + \param value + */ + void onBorderBottomChanged(double value); + /*! + \brief + + \fn onGutterChanged + \param value + */ + void onGutterChanged(double value); + +protected: + /*! + \brief + + \fn resizeEvent + \param event + */ + void resizeEvent(QResizeEvent *event) override; +}; + +#endif // CLAYOUT_H diff --git a/clayout.ui b/clayout.ui new file mode 100644 index 0000000..9bce5d9 --- /dev/null +++ b/clayout.ui @@ -0,0 +1,362 @@ + + + cLayout + + + + 0 + 0 + 493 + 440 + + + + Form + + + + + + + + + + + + Unit: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Paper Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + Paper Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Tiles + + + + + + + + 1 + + + + + + + Horizontal: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 1 + + + + + + + Vertical: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Border + + + + + + + + Left: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Right: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + TextLabel + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 9999.000000000000000 + + + + + + + TextLabel + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 9999.000000000000000 + + + + + + + Top: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 9999.000000000000000 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 9999.000000000000000 + + + + + + + Bottom: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + all the same + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Gutter + + + + + + + + Gutter Width: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 9999.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 6590b40..9cdba2e 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -81,10 +81,13 @@ void cMainWindow::initUI() m_lpSelectedListModel = new QStandardItemModel(0, 0); ui->m_lpSelectedList->setModel(m_lpSelectedListModel); - m_lpFileBrowser = new cFileBrowser(m_lpProgressBar, &m_imageFormats, ui->m_lpSelectedList, m_lpSelectedListModel, this); + m_lpFileBrowser = new cFileBrowser(m_lpProgressBar, &m_imageFormats, ui->m_lpSelectedList, m_lpSelectedListModel, this); ui->m_lpMainTab->addTab(m_lpFileBrowser, "Files"); - m_lpPrint = new cPrint(m_lpProgressBar, ui->m_lpSelectedList, m_lpSelectedListModel, this); + m_lpLayout = new cLayout(this); + ui->m_lpMainTab->addTab(m_lpLayout, "Layout"); + + m_lpPrint = new cPrint(m_lpProgressBar, ui->m_lpSelectedList, m_lpSelectedListModel, this); ui->m_lpMainTab->addTab(m_lpPrint, "Print"); if(!settings.value("main/maximized").toBool()) diff --git a/cmainwindow.h b/cmainwindow.h index 121e69b..8a16e1f 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -11,6 +11,7 @@ #include "common.h" #include "cfilebrowser.h" +#include "clayout.h" #include "cprint.h" #include @@ -42,11 +43,12 @@ public: ~cMainWindow(); private: - Ui::cMainWindow* ui; /*!< TODO: describe */ + Ui::cMainWindow* ui; /*!< TODO: describe */ cSplashScreen* m_lpSplashScreen; /*!< TODO: describe */ QProgressBar* m_lpProgressBar; /*!< TODO: describe */ cFileBrowser* m_lpFileBrowser; /*!< TODO: describe */ + cLayout* m_lpLayout; /*!< TODO: describe */ cPrint* m_lpPrint; /*!< TODO: describe */ QStandardItemModel* m_lpSelectedListModel; /*!< TODO: describe */ diff --git a/common.cpp b/common.cpp index f8e0311..eea51ac 100644 --- a/common.cpp +++ b/common.cpp @@ -1,6 +1,5 @@ /*! \file common.cpp - */ #include "common.h" @@ -68,3 +67,33 @@ QString userDir() { return(QDir::homePath() + QDir::separator() + ".picturePrint" + QDir::separator()); } + +int scale(int v, qreal s) +{ + return(static_cast(static_cast(v)*s)); +} + +qreal scale(qreal v, qreal s) +{ + return(v*s); +} + +QSize scale(const QSize& size, qreal s) +{ + return(QSize(scale(size.width(), s), scale(size.height(), s))); +} + +QSize scale(const QSizeF& size, qreal s) +{ + return(QSize(scale(size.width(), s), scale(size.height(), s))); +} + +QPoint scale(const QPoint& point, qreal s) +{ + return(QPoint(scale(point.x(), s), scale(point.y(), s))); +} + +QPoint scale(const QPointF& point, qreal s) +{ + return(QPoint(scale(point.x(), s), scale(point.y(), s))); +} diff --git a/common.h b/common.h index c66eb88..7acd456 100644 --- a/common.h +++ b/common.h @@ -1,12 +1,16 @@ /*! \file common.h - */ #ifndef COMMON_H #define COMMON_H +#include +#include +#include +#include + #include @@ -25,7 +29,6 @@ /*! \brief - \class tagIMAGEFORMAT common.h "common.h" */ typedef struct tagIMAGEFORMAT @@ -37,14 +40,12 @@ typedef struct tagIMAGEFORMAT bool write; /*!< TODO: describe */ /*! \brief - \typedef IMAGEFORMAT*/ } IMAGEFORMAT; /*! \brief - \fn generateReadList \param imageFormats \return QStringList @@ -52,7 +53,6 @@ typedef struct tagIMAGEFORMAT QStringList generateReadList(const QList& imageFormats); /*! \brief - \fn generateWriteList \param imageFormats \return QStringList @@ -61,7 +61,6 @@ QStringList generateWriteList(const QList& imageFormats); /*! \brief - \fn blob2Image \param ba \return QImage @@ -69,7 +68,6 @@ QStringList generateWriteList(const QList& imageFormats); QImage blob2Image(const QByteArray& ba); /*! \brief - \fn image2Blob \param image \return QByteArray @@ -78,11 +76,17 @@ QByteArray image2Blob(const QImage& image); /*! \brief - \fn userDir \return QString */ QString userDir(); +int scale(int v, qreal s); +qreal scale(qreal v, qreal s); +QSize scale(const QSize& size, qreal s); +QSize scale(const QSizeF& size, qreal s); +QPoint scale(const QPoint& point, qreal s); +QPoint scale(const QPointF& point, qreal s); + #endif // COMMON_H diff --git a/picturePrint.pro b/picturePrint.pro index efc7d91..66bfc30 100644 --- a/picturePrint.pro +++ b/picturePrint.pro @@ -49,6 +49,7 @@ SOURCES += \ cfilebrowser.cpp \ cfileviewer.cpp \ cimage.cpp \ + clayout.cpp \ common.cpp \ cprint.cpp \ csplashscreen.cpp \ @@ -60,6 +61,7 @@ HEADERS += \ cfilebrowser.h \ cfileviewer.h \ cimage.h \ + clayout.h \ cmainwindow.h \ common.h \ cprint.h \ @@ -68,6 +70,7 @@ HEADERS += \ FORMS += \ cfilebrowser.ui \ cfileviewer.ui \ + clayout.ui \ cmainwindow.ui \ cprint.ui