Added Page Setup Dialog.

This commit is contained in:
Leonardo Zide 2021-01-07 10:46:57 -08:00
parent 1abc81e02f
commit ea83db6987
9 changed files with 366 additions and 54 deletions

View file

@ -77,6 +77,7 @@ struct lcModelPartsEntry;
struct lcMinifig;
enum class lcViewpoint;
class lcInstructions;
struct lcInstructionsPageSetup;
struct lcObjectRayTest;
struct lcObjectBoxTest;

View file

@ -5,9 +5,18 @@
#include "piece.h"
#include "pieceinf.h"
const float lcInstructions::mDisplayDPI = 72.0f;
lcInstructions::lcInstructions(Project* Project)
: mProject(Project)
{
mPageSetup.Width = 8.5f * mDisplayDPI;
mPageSetup.Height = 11.0f * mDisplayDPI;
mPageSetup.MarginLeft = 0.5 * mDisplayDPI;
mPageSetup.MarginRight = 0.5 * mDisplayDPI;
mPageSetup.MarginTop = 0.5 * mDisplayDPI;
mPageSetup.MarginBottom = 0.5 * mDisplayDPI;
mPageSettings.Rows = 1;
mPageSettings.Columns = 1;
mPageSettings.Direction = lcInstructionsDirection::Horizontal;

View file

@ -1,5 +1,15 @@
#pragma once
struct lcInstructionsPageSetup
{
float Width;
float Height;
float MarginLeft;
float MarginRight;
float MarginTop;
float MarginBottom;
};
enum class lcInstructionsDirection
{
Horizontal,
@ -35,10 +45,13 @@ public:
std::vector<lcInstructionsPage> mPages;
lcInstructionsPageSettings mPageSettings;
lcInstructionsPageSetup mPageSetup;
protected:
void CreatePages();
void AddDefaultPages(lcModel* Model, std::vector<const lcModel*>& AddedModels);
Project* mProject = nullptr;
static const float mDisplayDPI;
};

View file

@ -4,6 +4,7 @@
#include "project.h"
#include "lc_model.h"
#include "lc_qutils.h"
#include "lc_pagesetupdialog.h"
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent)
: QGraphicsView(Parent)
@ -38,8 +39,8 @@ void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page)
}
}
lcInstructionsPageListWidget::lcInstructionsPageListWidget(QWidget* Parent)
: QDockWidget(Parent)
lcInstructionsPageListWidget::lcInstructionsPageListWidget(QWidget* Parent, lcInstructions* Instructions)
: QDockWidget(Parent), mInstructions(Instructions)
{
QWidget* CentralWidget = new QWidget(this);
setWidget(CentralWidget);
@ -48,20 +49,36 @@ lcInstructionsPageListWidget::lcInstructionsPageListWidget(QWidget* Parent)
QVBoxLayout* Layout = new QVBoxLayout(CentralWidget);
Layout->setContentsMargins(0, 0, 0, 0);
QHBoxLayout* ButtonsLayout = new QHBoxLayout();
ButtonsLayout->setContentsMargins(0, 0, 0, 0);
Layout->addLayout(ButtonsLayout);
QToolButton* PageSetupButton = new QToolButton();
PageSetupButton->setText("Page Setup");
ButtonsLayout->addWidget(PageSetupButton);
connect(PageSetupButton, SIGNAL(clicked()), this, SLOT(ShowPageSetupDialog()));
ButtonsLayout->addStretch(1);
/*
lcCollapsibleWidget* SetupWidget = new lcCollapsibleWidget(tr("Page Setup"), CentralWidget);
Layout->addWidget(SetupWidget);
QVBoxLayout* SetupLayout = new QVBoxLayout();
// QVBoxLayout* SetupLayout = new QVBoxLayout();
// SetupWidget->SetChildLayout(SetupLayout);
QGridLayout* SetupLayout = new QGridLayout();
SetupWidget->SetChildLayout(SetupLayout);
lcCollapsibleWidget* SizeWidget = new lcCollapsibleWidget(tr("Size"));
// lcCollapsibleWidget* SizeWidget = new lcCollapsibleWidget(tr("Size"));
QGroupBox* SizeWidget = new QGroupBox(tr("Size"));
SetupLayout->addWidget(SizeWidget);
QGridLayout* SizeLayout = new QGridLayout();
SizeWidget->SetChildLayout(SizeLayout);
mSizeComboBox = new QComboBox();
SizeLayout->addWidget(mSizeComboBox, 0, 0, 1, -1);
// SizeWidget->SetChildLayout(SizeLayout);
SizeWidget->setLayout(SizeLayout);
mWidthEdit = new lcSmallLineEdit();
SizeLayout->addWidget(new QLabel(tr("Width:")), 1, 0);
@ -71,69 +88,85 @@ lcInstructionsPageListWidget::lcInstructionsPageListWidget(QWidget* Parent)
SizeLayout->addWidget(new QLabel(tr("Height:")), 1, 2);
SizeLayout->addWidget(mHeightEdit, 1, 3);
lcCollapsibleWidget* OrientationWidget = new lcCollapsibleWidget(tr("Orientation"));
SetupLayout->addWidget(OrientationWidget);
mUnitsComboBox = new QComboBox();
mUnitsComboBox->addItems(QStringList() << tr("Pixels") << tr("Centimeters") << tr("Inches"));
SizeLayout->addWidget(new QLabel(tr("Units:")), 4, 0);
SizeLayout->addWidget(mUnitsComboBox, 4, 1, 1, -1);
QVBoxLayout* OrientationLayout = new QVBoxLayout();
OrientationWidget->SetChildLayout(OrientationLayout);
mSizeComboBox = new QComboBox();
SizeLayout->addWidget(new QLabel(tr("Preset:")), 5, 0);
SizeLayout->addWidget(mSizeComboBox, 5, 1, 1, -1);
mPortraitButton = new QRadioButton(tr("Portrait"));
OrientationLayout->addWidget(mPortraitButton);
mLandscapeButton = new QRadioButton(tr("Landscape"));
OrientationLayout->addWidget(mLandscapeButton);
lcCollapsibleWidget* MarginsWidget = new lcCollapsibleWidget(tr("Margins"));
// lcCollapsibleWidget* OrientationWidget = new lcCollapsibleWidget(tr("Orientation"));
// SetupLayout->addWidget(OrientationWidget);
//
// QVBoxLayout* OrientationLayout = new QVBoxLayout();
// OrientationWidget->SetChildLayout(OrientationLayout);
//
// mPortraitButton = new QRadioButton(tr("Portrait"));
// OrientationLayout->addWidget(mPortraitButton);
// mLandscapeButton = new QRadioButton(tr("Landscape"));
// OrientationLayout->addWidget(mLandscapeButton);
QGroupBox* MarginsWidget = new QGroupBox(tr("Margins"));
// lcCollapsibleWidget* MarginsWidget = new lcCollapsibleWidget(tr("Margins"));
SetupLayout->addWidget(MarginsWidget);
QGridLayout* MarginsLayout = new QGridLayout();
MarginsWidget->SetChildLayout(MarginsLayout);
// MarginsWidget->SetChildLayout(MarginsLayout);
MarginsWidget->setLayout(MarginsLayout);
mLeftMarginEdit = new lcSmallLineEdit();
MarginsLayout->addWidget(new QLabel(tr("Left:")), 0, 0);
MarginsLayout->addWidget(mLeftMarginEdit, 0, 1);
MarginsLayout->addWidget(new QLabel(tr("Left:")), 2, 0);
MarginsLayout->addWidget(mLeftMarginEdit, 2, 1);
mRightMarginEdit = new lcSmallLineEdit();
MarginsLayout->addWidget(new QLabel(tr("Right:")), 0, 2);
MarginsLayout->addWidget(mRightMarginEdit, 0, 3);
MarginsLayout->addWidget(new QLabel(tr("Right:")), 2, 2);
MarginsLayout->addWidget(mRightMarginEdit, 2, 3);
mTopMarginEdit = new lcSmallLineEdit();
MarginsLayout->addWidget(new QLabel(tr("Top:")), 1, 0);
MarginsLayout->addWidget(mTopMarginEdit, 1, 1);
MarginsLayout->addWidget(new QLabel(tr("Top:")), 3, 0);
MarginsLayout->addWidget(mTopMarginEdit, 3, 1);
mBottomMarginEdit = new lcSmallLineEdit();
MarginsLayout->addWidget(new QLabel(tr("Bottom:")), 1, 2);
MarginsLayout->addWidget(mBottomMarginEdit, 1, 3);
MarginsLayout->addWidget(new QLabel(tr("Bottom:")), 3, 2);
MarginsLayout->addWidget(mBottomMarginEdit, 3, 3);
lcCollapsibleWidget* UnitsWidget = new lcCollapsibleWidget(tr("Units"));
SetupLayout->addWidget(UnitsWidget);
QVBoxLayout* UnitsLayout = new QVBoxLayout();
UnitsWidget->SetChildLayout(UnitsLayout);
mUnitsComboBox = new QComboBox();
mUnitsComboBox->addItems(QStringList() << tr("Pixels") << tr("Centimeters") << tr("Inches"));
UnitsLayout->addWidget(mUnitsComboBox);
SetupWidget->Collapse();
// lcCollapsibleWidget* UnitsWidget = new lcCollapsibleWidget(tr("Units"));
// SetupLayout->addWidget(UnitsWidget);
//
// QVBoxLayout* UnitsLayout = new QVBoxLayout();
// UnitsWidget->SetChildLayout(UnitsLayout);
// SetupWidget->Collapse();
*/
mThumbnailsWidget = new QListWidget(CentralWidget);
Layout->addWidget(mThumbnailsWidget);
}
void lcInstructionsPageListWidget::ShowPageSetupDialog()
{
lcPageSetupDialog Dialog(this, &mInstructions->mPageSetup);
if (Dialog.exec() != QDialog::Accepted)
return;
}
lcInstructionsDialog::lcInstructionsDialog(QWidget* Parent, Project* Project)
: QMainWindow(Parent), mProject(Project)
{
setWindowTitle(tr("Instructions"));
mInstructions = mProject->GetInstructions();
mPageWidget = new lcInstructionsPageWidget(this);
setCentralWidget(mPageWidget);
mPageListWidget = new lcInstructionsPageListWidget(this);
mPageListWidget = new lcInstructionsPageListWidget(this, &mInstructions);
mPageListWidget->setObjectName("PageList");
addDockWidget(Qt::LeftDockWidgetArea, mPageListWidget);
mInstructions = mProject->GetInstructions();
mPageSettingsToolBar = addToolBar(tr("Page Settings"));
mPageSettingsToolBar->setObjectName("PageSettings");
mPageSettingsToolBar->setFloatable(false);

View file

@ -17,24 +17,31 @@ class lcInstructionsPageListWidget : public QDockWidget
Q_OBJECT
public:
lcInstructionsPageListWidget(QWidget* Parent);
lcInstructionsPageListWidget(QWidget* Parent, lcInstructions* Instructions);
protected slots:
void ShowPageSetupDialog();
public:
//protected:
QComboBox* mSizeComboBox = nullptr;
QLineEdit* mWidthEdit = nullptr;
QLineEdit* mHeightEdit = nullptr;
QRadioButton* mPortraitButton = nullptr;
QRadioButton* mLandscapeButton = nullptr;
QLineEdit* mLeftMarginEdit = nullptr;
QLineEdit* mRightMarginEdit = nullptr;
QLineEdit* mTopMarginEdit = nullptr;
QLineEdit* mBottomMarginEdit = nullptr;
QComboBox* mUnitsComboBox = nullptr;
// QComboBox* mSizeComboBox = nullptr;
// QLineEdit* mWidthEdit = nullptr;
// QLineEdit* mHeightEdit = nullptr;
//
// QRadioButton* mPortraitButton = nullptr;
// QRadioButton* mLandscapeButton = nullptr;
//
// QLineEdit* mLeftMarginEdit = nullptr;
// QLineEdit* mRightMarginEdit = nullptr;
// QLineEdit* mTopMarginEdit = nullptr;
// QLineEdit* mBottomMarginEdit = nullptr;
//
// QComboBox* mUnitsComboBox = nullptr;
QListWidget* mThumbnailsWidget = nullptr;
protected:
lcInstructions* mInstructions;
};
class lcInstructionsDialog : public QMainWindow

View file

@ -0,0 +1,34 @@
#include "lc_global.h"
#include "lc_pagesetupdialog.h"
#include "ui_lc_pagesetupdialog.h"
#include "lc_instructions.h"
lcPageSetupDialog::lcPageSetupDialog(QWidget* Parent, lcInstructionsPageSetup* PageSetup)
: QDialog(Parent), ui(new Ui::lcPageSetupDialog), mPageSetup(PageSetup)
{
ui->setupUi(this);
ui->WidthEdit->setText(QString::number(PageSetup->Width));
ui->HeightEdit->setText(QString::number(PageSetup->Height));
ui->LeftEdit->setText(QString::number(PageSetup->MarginLeft));
ui->RightEdit->setText(QString::number(PageSetup->MarginRight));
ui->TopEdit->setText(QString::number(PageSetup->MarginTop));
ui->BottomEdit->setText(QString::number(PageSetup->MarginBottom));
}
lcPageSetupDialog::~lcPageSetupDialog()
{
delete ui;
}
void lcPageSetupDialog::accept()
{
mPageSetup->Width = ui->WidthEdit->text().toFloat();
mPageSetup->Height = ui->HeightEdit->text().toFloat();
mPageSetup->MarginLeft = ui->LeftEdit->text().toFloat();
mPageSetup->MarginRight = ui->RightEdit->text().toFloat();
mPageSetup->MarginTop = ui->TopEdit->text().toFloat();
mPageSetup->MarginBottom = ui->BottomEdit->text().toFloat();
QDialog::accept();
}

View file

@ -0,0 +1,22 @@
#pragma once
namespace Ui
{
class lcPageSetupDialog;
}
class lcPageSetupDialog : public QDialog
{
Q_OBJECT
public:
lcPageSetupDialog(QWidget* Parent, lcInstructionsPageSetup* PageSetup);
~lcPageSetupDialog();
public slots:
void accept() override;
private:
lcInstructionsPageSetup* mPageSetup;
Ui::lcPageSetupDialog *ui;
};

View file

@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>lcPageSetupDialog</class>
<widget class="QDialog" name="lcPageSetupDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Page Setup</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Size</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="3">
<widget class="QLineEdit" name="HeightEdit"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="WidthEdit"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Width:</string>
</property>
<property name="buddy">
<cstring>WidthEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Height:</string>
</property>
<property name="buddy">
<cstring>HeightEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Preset:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QComboBox" name="comboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Units:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QComboBox" name="comboBox_2"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Margins</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Left:</string>
</property>
<property name="buddy">
<cstring>LeftEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="LeftEdit"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Right:</string>
</property>
<property name="buddy">
<cstring>RightEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="RightEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Top:</string>
</property>
<property name="buddy">
<cstring>TopEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="TopEdit"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Bottom:</string>
</property>
<property name="buddy">
<cstring>BottomEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="BottomEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>WidthEdit</tabstop>
<tabstop>HeightEdit</tabstop>
<tabstop>comboBox_2</tabstop>
<tabstop>comboBox</tabstop>
<tabstop>LeftEdit</tabstop>
<tabstop>RightEdit</tabstop>
<tabstop>TopEdit</tabstop>
<tabstop>BottomEdit</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>lcPageSetupDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>227</x>
<y>282</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>lcPageSetupDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>295</x>
<y>288</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -196,6 +196,7 @@ SOURCES += \
common/lc_meshloader.cpp \
common/lc_minifigdialog.cpp \
common/lc_model.cpp \
common/lc_pagesetupdialog.cpp \
common/lc_partselectionwidget.cpp \
common/lc_previewwidget.cpp \
common/lc_profile.cpp \
@ -265,6 +266,7 @@ HEADERS += \
common/lc_meshloader.h \
common/lc_minifigdialog.h \
common/lc_model.h \
common/lc_pagesetupdialog.h \
common/lc_previewwidget.h \
common/lc_profile.h \
common/lc_scene.h \
@ -319,6 +321,7 @@ FORMS += \
qt/lc_renderdialog.ui \
qt/lc_setsdatabasedialog.ui \
common/lc_minifigdialog.ui \
common/lc_pagesetupdialog.ui \
common/lc_partpalettedialog.ui
OTHER_FILES +=
RESOURCES += leocad.qrc resources/stylesheet/stylesheet.qrc