Index: scribus/ui/inspage.cpp =================================================================== --- scribus/ui/inspage.cpp (revision 27829) +++ scribus/ui/inspage.cpp (working copy) @@ -7,13 +7,26 @@ #include "inspage.h" -#include -#include -#include -#include +#include +#include + +#include #include +#include +#include +#include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "commonstrings.h" #include "iconmanager.h" @@ -21,338 +34,525 @@ #include "scpage.h" #include "scribusdoc.h" #include "scrspinbox.h" -#include "util.h" +#include "widgets/form_widget.h" + +namespace +{ +constexpr int listVisibleRows = 4; + +// Keep the full numeric range without reserving space for its longest value. +// The native editor scrolls horizontally for unusually large dimensions. +class CompactDimensionSpinBox final : public ScrSpinBox +{ +public: + using ScrSpinBox::ScrSpinBox; + + QSize sizeHint() const override + { + QStyleOptionSpinBox option; + initStyleOption(&option); + const QString sample = prefix() + locale().toString(999.0, 'f', decimals()) + suffix(); + const QSize contents(fontMetrics().horizontalAdvance(sample + QLatin1Char(' ')), fontMetrics().height()); + QSize hint = style()->sizeFromContents(QStyle::CT_SpinBox, &option, contents, this); + hint.setHeight(ScrSpinBox::sizeHint().height()); + return hint; + } -InsPage::InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages) - : QDialog(parent, Qt::WindowFlags()) + QSize minimumSizeHint() const override { return sizeHint(); } +}; + +class ElidedTextToolTipDelegate final : public QStyledItemDelegate { - m_doc = currentDoc; - masterPageCombos.clear(); +public: + using QStyledItemDelegate::QStyledItemDelegate; + + bool helpEvent(QHelpEvent* event, QAbstractItemView* view, + const QStyleOptionViewItem& option, const QModelIndex& index) override + { + if (!event || !view || !index.isValid()) + return false; + if (event->type() != QEvent::ToolTip) + return QStyledItemDelegate::helpEvent(event, view, option, index); + + if (sizeHint(option, index).width() <= option.rect.width()) + { + QToolTip::hideText(); + event->ignore(); + return false; + } + QToolTip::showText(event->globalPos(), index.data(Qt::DisplayRole).toString(), view); + return true; + } +}; +} + +InsPage::InsPage(QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages) + : QDialog(parent, Qt::WindowFlags()), + m_doc(currentDoc), + m_unitRatio(currentDoc->unitRatio()), + m_orientation(currentDoc->pageOrientation() == 1 ? 1 : 0) +{ setModal(true); - setWindowTitle( tr( "Insert Page" ) ); + setWindowTitle(tr("Insert Pages")); setWindowIcon(IconManager::instance().loadIcon("app-icon")); - dialogLayout = new QVBoxLayout(this); - dialogLayout->setSpacing(4); - dialogLayout->setContentsMargins(8, 8, 8, 8); - - whereLayout = new QGridLayout(); - whereLayout->setSpacing(4); - whereLayout->setContentsMargins(0, 0, 0, 0); - - insCountData = new QSpinBox(this); - insCountData->setMinimum(1); - insCountData->setMaximum(999); + auto* dialogLayout = new QVBoxLayout(this); + dialogLayout->setSpacing(12); + dialogLayout->setContentsMargins(9, 9, 9, 9); + + auto* insertLayout = new QHBoxLayout; + insertLayout->setContentsMargins(0, 0, 0, 0); + insertLayout->setSpacing(18); + insertLayout->setAlignment(Qt::AlignTop); + + auto* countControl = new FormWidget(this); + countControl->setText(tr("Quantity")); + insCountData = new QSpinBox(countControl); + insCountData->setRange(1, 999); insCountData->setValue(1); - insCountLabel = new QLabel(tr( "&Insert" ), this ); - insCountLabel->setBuddy(insCountData); - whereLayout->addWidget(insCountLabel, 0, 0); - whereLayout->addWidget(insCountData, 0, 1); - - pagesLabel = new QLabel( tr( "Page(s)" ), this); - whereLayout->addWidget(pagesLabel, 0, 2); - - insWhereData = new QComboBox( this ); - insWhereData->addItem( tr("before Page")); - insWhereData->addItem( tr("after Page")); - insWhereData->addItem( tr("at End")); - insWhereData->setCurrentIndex(2); - whereLayout->addWidget(insWhereData, 1, 0, 1, 2); - - insWherePageData = new QSpinBox(this); - insWherePageData->setMinimum(1); - insWherePageData->setMaximum(maxPages); + insCountData->setToolTip(tr("Number of pages to insert.")); + insCountData->setAccessibleName(tr("Quantity")); + insCountData->setMinimumWidth(insCountData->fontMetrics().horizontalAdvance(QLatin1String("999")) + 36); + countControl->addWidget(insCountData); + insertLayout->addWidget(countControl); + + placementButtonGroup = new QButtonGroup(this); + placementButtonGroup->setExclusive(true); + + auto createPlacementButton = [this](QWidget* parent, const QString& text, + const QString& toolTip, InsertPosition position) + { + auto* button = new QToolButton(parent); + button->setText(text); + button->setToolButtonStyle(Qt::ToolButtonTextOnly); + button->setToolTip(toolTip); + button->setCheckable(true); + placementButtonGroup->addButton(button, static_cast(position)); + return button; + }; + + auto* relativeControl = new FormWidget(this); + relativeControl->setText(tr("Relative to page number")); + auto* relativeWidget = new QWidget(relativeControl); + auto* relativeLayout = new QHBoxLayout(relativeWidget); + relativeLayout->setContentsMargins(0, 0, 0, 0); + relativeLayout->setSpacing(0); + beforeButton = createPlacementButton(relativeWidget, tr("Before"), + tr("Insert pages before the specified page."), InsertPosition::Before); + afterButton = createPlacementButton(relativeWidget, tr("After"), + tr("Insert pages after the specified page."), InsertPosition::After); + afterButton->setChecked(true); + relativeLayout->addWidget(beforeButton); + relativeLayout->addWidget(afterButton); + insWherePageData = new QSpinBox(relativeWidget); + insWherePageData->setRange(1, maxPages); insWherePageData->setValue(currentPage + 1); - insWherePageData->setDisabled(true); + insWherePageData->setToolTip(tr("Reference page number for the Before and After options.")); + insWherePageData->setAccessibleName(tr("Reference page number")); + const int pageDigits = QString::number(maxPages).length(); + insWherePageData->setMinimumWidth(insWherePageData->fontMetrics().horizontalAdvance(QString(pageDigits, QLatin1Char('9'))) + 36); + const int relativeButtonWidth = std::max(beforeButton->sizeHint().width(), afterButton->sizeHint().width()); + beforeButton->setMinimumWidth(relativeButtonWidth); + afterButton->setMinimumWidth(relativeButtonWidth); + relativeLayout->addSpacing(4); + relativeLayout->addWidget(insWherePageData); + relativeControl->addWidget(relativeWidget); + insertLayout->addWidget(relativeControl); + + auto* edgeControl = new FormWidget(this); + edgeControl->setText(tr("Document edge")); + auto* edgeWidget = new QWidget(edgeControl); + auto* edgeLayout = new QHBoxLayout(edgeWidget); + edgeLayout->setContentsMargins(0, 0, 0, 0); + edgeLayout->setSpacing(0); + startButton = createPlacementButton(edgeWidget, tr("Start"), + tr("Insert pages at the start of the document."), InsertPosition::Start); + endButton = createPlacementButton(edgeWidget, tr("End"), + tr("Insert pages at the end of the document."), InsertPosition::End); + const int edgeButtonWidth = std::max(startButton->sizeHint().width(), endButton->sizeHint().width()); + startButton->setMinimumWidth(edgeButtonWidth); + endButton->setMinimumWidth(edgeButtonWidth); + const int controlHeight = insWherePageData->sizeHint().height(); + beforeButton->setMinimumHeight(controlHeight); + afterButton->setMinimumHeight(controlHeight); + startButton->setMinimumHeight(controlHeight); + endButton->setMinimumHeight(controlHeight); + edgeLayout->addWidget(startButton); + edgeLayout->addWidget(endButton); + edgeControl->addWidget(edgeWidget); + insertLayout->addWidget(edgeControl); + insertLayout->addStretch(); + dialogLayout->addLayout(insertLayout); + + moveObjectsCheckBox = new QCheckBox(tr("Keep objects with their pages"), this); + moveObjectsCheckBox->setToolTip(tr("Keep existing objects with their pages when insertion shifts page positions.")); + moveObjectsCheckBox->setChecked(true); + dialogLayout->addWidget(moveObjectsCheckBox, 0, Qt::AlignLeading); - whereLayout->addWidget(insWherePageData, 1, 2); - whereLayout->addItem(new QSpacerItem(insCountLabel->fontMetrics().horizontalAdvance( tr( "&Insert" )), 0), 0, 0); - dialogLayout->addLayout(whereLayout); - - masterPageLabel = nullptr; - masterPageGroup = new QGroupBox( this); - masterPageGroup->setTitle( tr( "Master Pages" ) ); - masterPageLayout = new QGridLayout( masterPageGroup ); + const PageSet& currentPageSet = m_doc->pageSets()[m_doc->pagePositioning()]; + const int positionCount = std::max(1, static_cast(currentPageSet.pageNames.count())); + auto* masterPageGroup = new QGroupBox(positionCount == 1 ? tr("Master page") : tr("Master pages"), this); + masterPageGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + auto* masterPageLayout = new QGridLayout(masterPageGroup); + masterPageLayout->setContentsMargins(9, 9, 9, 9); + masterPageLayout->setHorizontalSpacing(9); + masterPageLayout->setVerticalSpacing(6); masterPageLayout->setAlignment(Qt::AlignTop); - masterPageLayout->setSpacing(4); - masterPageLayout->setContentsMargins(8, 8, 8, 8); - if (m_doc->pagePositioning() == 0) + masterPageLayout->setColumnStretch(0, 1); + masterPageLayout->setColumnStretch(1, 1); + + for (int position = 0; position < positionCount; ++position) { - QComboBox* pageData = new QComboBox(masterPageGroup); - for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) - { - pageData->addItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key(), it.key()); - } - if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormal)) - setCurrentComboItem(pageData, CommonStrings::trMasterPageNormal); - masterPageLabel = new QLabel(tr("&Master Page:"), masterPageGroup); - masterPageLabel->setBuddy(pageData); - masterPageLayout->addWidget(masterPageLabel, 0, 0); - masterPageLayout->addWidget(pageData, 0, 1); - masterPageCombos.append(pageData); - } - else - { - int row = 0; - const PageSet& currentPageSet = m_doc->pageSets()[m_doc->pagePositioning()]; - for (int mp = 0; mp < currentPageSet.pageNames.count(); ++mp) - { - QComboBox* pageData = new QComboBox(masterPageGroup); -// for (QMap::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it) -// pageData->insertItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key()); - if (mp == 0) - { - bool conNam = m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalLeft); - for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) - { - if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else - { - if (m_doc->MasterPages.at(it.value())->LeftPg == 1) - pageData->addItem(it.key(), it.key()); - } - } - if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalLeft)) - setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalLeft); - } - else if (mp == 1) - { - if (currentPageSet.pageNames.count() > 2) - { - bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle); - for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) - { - if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else - { - if ((m_doc->MasterPages.at(it.value())->LeftPg != 0) && (m_doc->MasterPages.at(it.value())->LeftPg != 1)) - pageData->addItem(it.key(), it.key()); - } - } - if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalMiddle)) - setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle); - } - else - { - bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight); - for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) - { - if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else - { - if (m_doc->MasterPages.at(it.value())->LeftPg == 0) - pageData->addItem(it.key(), it.key()); - } - } - if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalRight)) - setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight); - } - } - else if (mp == 2) - { - if (currentPageSet.pageNames.count() > 3) - { - bool conNam = m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalMiddle); - for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) - { - if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else - { - if ((m_doc->MasterPages.at(it.value())->LeftPg != 0) && (m_doc->MasterPages.at(it.value())->LeftPg != 1)) - pageData->addItem(it.key(), it.key()); - } - } - if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalMiddle)) - setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle); - } - else - { - bool conNam = m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalRight); - for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) - { - if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else - { - if (m_doc->MasterPages.at(it.value())->LeftPg == 0) - pageData->addItem(it.key(), it.key()); - } - } - if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight)) - setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight); - } - } - else if (mp == 3) - { - bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight); - for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) - { - if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) - pageData->addItem(CommonStrings::trMasterPageNormal, it.key()); - else - { - if (m_doc->MasterPages.at(it.value())->LeftPg == 0) - pageData->addItem(it.key(), it.key()); - } - } - if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight)) - setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight); - } - QString transLabel = currentPageSet.pageNames[mp]; - QLabel* pageLabel = new QLabel(CommonStrings::translatePageSetLocString(transLabel), masterPageGroup); - pageLabel->setBuddy(pageData); - masterPageLayout->addWidget(pageLabel, row, 0 ); - masterPageLayout->addWidget(pageData, row, 1); - row++; - masterPageCombos.append(pageData); - } + QString positionLabel; + if (positionCount == 2) + positionLabel = position == 0 ? tr("Left page") : tr("Right page"); + else if (positionCount > 1) + positionLabel = CommonStrings::translatePageSetLocString(currentPageSet.pageNames.at(position)); + MasterPageChoice choice = createMasterPageChoice(position, positionLabel); + const int row = position / 2; + const int column = position % 2; + const int columnSpan = (positionCount == 1) ? 2 : 1; + masterPageLayout->addWidget(choice.widget, row, column, 1, columnSpan); + m_masterPageChoices.append(choice); } - - PageSizeInfo psi = PagePresetManager::instance().pageInfoByDimensions(QSize(m_doc->pageWidth(), m_doc->pageHeight())); - prefsPageSizeName = psi.id; - dialogLayout->addWidget(masterPageGroup); - overrideMPSizingCheckBox = new QCheckBox( tr("Override Master Page Sizing")); - dialogLayout->addWidget(overrideMPSizingCheckBox); - dsGroupBox7 = new QGroupBox( this ); - dsGroupBox7->setTitle( tr( "Page Size" ) ); - dsGroupBox7Layout = new QGridLayout(dsGroupBox7); - dsGroupBox7Layout->setSpacing(4); - dsGroupBox7Layout->setContentsMargins(8, 8, 8, 8); - textLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7); - dsGroupBox7Layout->addWidget(textLabel1, 0, 0, Qt::AlignTop | Qt::AlignRight); - pageSizeSelector = new PageSizeSelector(dsGroupBox7); - pageSizeSelector->setPageSize(m_doc->pageWidth(), m_doc->pageHeight()); - textLabel1->setBuddy(pageSizeSelector); - dsGroupBox7Layout->addWidget(pageSizeSelector, 0, 1); - textLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7); - dsGroupBox7Layout->addWidget(textLabel2, 1, 0, Qt::AlignRight); - - orientationQComboBox = new QComboBox(dsGroupBox7); - orientationQComboBox->addItem( tr( "Portrait" ) ); - orientationQComboBox->addItem( tr( "Landscape" ) ); - orientationQComboBox->setCurrentIndex(m_doc->pageOrientation() ); - textLabel2->setBuddy(orientationQComboBox); - dsGroupBox7Layout->addWidget(orientationQComboBox, 1, 1); - - widthSpinBox = new ScrSpinBox(1, 10000, dsGroupBox7, m_doc->unitIndex()); - widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7); - widthSpinBox->setValue(m_doc->pageWidth() * m_doc->unitRatio()); - widthQLabel->setBuddy(widthSpinBox); - dsGroupBox7Layout->addWidget(widthQLabel, 2, 0, Qt::AlignRight); - dsGroupBox7Layout->addWidget(widthSpinBox, 2, 1); - - heightSpinBox = new ScrSpinBox(1, 10000, dsGroupBox7, m_doc->unitIndex()); - heightSpinBox->setValue(m_doc->pageHeight() * m_doc->unitRatio()); - heightQLabel = new QLabel( tr( "&Height:" ), dsGroupBox7); - heightQLabel->setBuddy(heightSpinBox); - dsGroupBox7Layout->addWidget(heightQLabel, 3, 0, Qt::AlignRight); - dsGroupBox7Layout->addWidget(heightSpinBox, 3, 1); - moveObjectsCheckBox = new QCheckBox( dsGroupBox7); - moveObjectsCheckBox->setText( tr( "Move Objects with their Page" ) ); - moveObjectsCheckBox->setChecked(true); - dsGroupBox7Layout->addWidget(moveObjectsCheckBox, 4, 0, 1, 2); - dialogLayout->addWidget(dsGroupBox7); + PageSizeInfo pageSizeInfo = PagePresetManager::instance().pageInfoByDimensions(QSize(m_doc->pageWidth(), m_doc->pageHeight())); + prefsPageSizeName = pageSizeInfo.id; - dsGroupBox7->setEnabled(false); - bool b = (pageSizeSelector->pageSize() == CommonStrings::customPageSize); - heightSpinBox->setEnabled(b); - widthSpinBox->setEnabled(b); + overrideMPSizingCheckBox = new QCheckBox(tr("Override master page size"), this); + overrideMPSizingCheckBox->setToolTip(tr("Set page dimensions independently of master pages.")); + dialogLayout->addWidget(overrideMPSizingCheckBox, 0, Qt::AlignLeading); + + pageSizeGroup = new QGroupBox(tr("Page size"), this); + pageSizeGroup->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + auto* pageSizeLayout = new QVBoxLayout(pageSizeGroup); + pageSizeLayout->setSpacing(9); + pageSizeLayout->setContentsMargins(9, 9, 9, 9); + + auto* presetWidget = new QWidget(pageSizeGroup); + auto* presetLayout = new QHBoxLayout(presetWidget); + presetLayout->setContentsMargins(0, 0, 0, 0); + presetLayout->setSpacing(9); + pageSizeSelector = new PageSizeSelector(presetWidget); + pageSizeSelector->setCompactMode(tr("Category"), tr("Size")); + pageSizeSelector->setPageSize(m_doc->pageWidth(), m_doc->pageHeight()); + presetLayout->addWidget(pageSizeSelector); + presetLayout->addStretch(); - buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + auto* dimensionsWidget = new QWidget(pageSizeGroup); + auto* dimensionsLayout = new QHBoxLayout(dimensionsWidget); + dimensionsLayout->setContentsMargins(0, 0, 0, 0); + dimensionsLayout->setSpacing(9); + auto* orientationControl = new FormWidget(dimensionsWidget); + orientationControl->setText(tr("Orientation")); + auto* orientationWidget = new QWidget(orientationControl); + auto* orientationLayout = new QHBoxLayout(orientationWidget); + orientationLayout->setContentsMargins(0, 0, 0, 0); + orientationLayout->setSpacing(0); + orientationButtonGroup = new QButtonGroup(this); + orientationButtonGroup->setExclusive(true); + portraitButton = new QToolButton(orientationWidget); + portraitButton->setIcon(IconManager::instance().loadIcon("page-orientation-vertical")); + portraitButton->setToolTip(tr("Portrait orientation")); + portraitButton->setAccessibleName(tr("Portrait orientation")); + portraitButton->setCheckable(true); + orientationButtonGroup->addButton(portraitButton, 0); + landscapeButton = new QToolButton(orientationWidget); + landscapeButton->setIcon(IconManager::instance().loadIcon("page-orientation-horizontal")); + landscapeButton->setToolTip(tr("Landscape orientation")); + landscapeButton->setAccessibleName(tr("Landscape orientation")); + landscapeButton->setCheckable(true); + orientationButtonGroup->addButton(landscapeButton, 1); + (m_orientation == 0 ? portraitButton : landscapeButton)->setChecked(true); + orientationLayout->addWidget(portraitButton); + orientationLayout->addWidget(landscapeButton); + orientationControl->addWidget(orientationWidget); + dimensionsLayout->addWidget(orientationControl); + dimensionsLayout->addSpacing(9); + widthControl = new FormWidget(dimensionsWidget); + widthControl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); + widthControl->setText(tr("Width")); + widthSpinBox = new CompactDimensionSpinBox(1, 10000, widthControl, m_doc->unitIndex()); + widthSpinBox->setValue(m_doc->pageWidth() * m_unitRatio); + widthSpinBox->setAccessibleName(tr("Width")); + widthSpinBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + widthControl->addWidget(widthSpinBox); + dimensionsLayout->addWidget(widthControl); + heightControl = new FormWidget(dimensionsWidget); + heightControl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); + heightControl->setText(tr("Height")); + heightSpinBox = new CompactDimensionSpinBox(1, 10000, heightControl, m_doc->unitIndex()); + heightSpinBox->setValue(m_doc->pageHeight() * m_unitRatio); + heightSpinBox->setAccessibleName(tr("Height")); + heightSpinBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + const int dimensionWidth = std::max(widthSpinBox->sizeHint().width(), heightSpinBox->sizeHint().width()); + widthSpinBox->setMinimumWidth(dimensionWidth); + heightSpinBox->setMinimumWidth(dimensionWidth); + heightControl->addWidget(heightSpinBox); + dimensionsLayout->addWidget(heightControl); + dimensionsLayout->addStretch(); + + const int pageControlHeight = widthSpinBox->sizeHint().height(); + portraitButton->setMinimumSize(pageControlHeight, pageControlHeight); + landscapeButton->setMinimumSize(pageControlHeight, pageControlHeight); + pageSizeLayout->addWidget(presetWidget); + pageSizeLayout->addWidget(dimensionsWidget); + dialogLayout->addWidget(pageSizeGroup); + + dialogLayout->addStretch(1); + buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + buttonBox->button(QDialogButtonBox::Ok)->setText(tr("&Insert")); + buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); dialogLayout->addWidget(buttonBox); - setMaximumSize(sizeHint()); - m_unitRatio = m_doc->unitRatio(); - // signals and slots connections - connect(insWhereData, SIGNAL( activated(int) ), this, SLOT( insWherePageDataDisable(int) ) ); + connect(placementButtonGroup, &QButtonGroup::idClicked, this, &InsPage::updatePlacementControls); connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); - connect(orientationQComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setOrientation(int))); - connect(pageSizeSelector, SIGNAL(pageSizeChanged(QString)), this, SLOT(setSize(QString))); - connect(overrideMPSizingCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableSizingControls(int))); -} - -void InsPage::setSize(const QString & gr) -{ - PageSizeInfo psi = PagePresetManager::instance().pageInfoByName(gr); - prefsPageSizeName = psi.id; - if (psi.id == CommonStrings::customPageSize) + connect(orientationButtonGroup, &QButtonGroup::idClicked, this, &InsPage::setOrientation); + connect(pageSizeSelector, &PageSizeSelector::pageSizeChanged, this, &InsPage::setSize); + connect(overrideMPSizingCheckBox, &QCheckBox::toggled, this, &InsPage::updateSizeControls); + + QWidget::setTabOrder(insCountData, beforeButton); + QWidget::setTabOrder(beforeButton, afterButton); + QWidget::setTabOrder(afterButton, insWherePageData); + QWidget::setTabOrder(insWherePageData, startButton); + QWidget::setTabOrder(startButton, endButton); + QWidget::setTabOrder(endButton, moveObjectsCheckBox); + QWidget* previousWidget = moveObjectsCheckBox; + for (const MasterPageChoice& choice : std::as_const(m_masterPageChoices)) { - widthSpinBox->setEnabled(true); - heightSpinBox->setEnabled(true); + if (!choice.list) + continue; + QWidget::setTabOrder(previousWidget, choice.list); + previousWidget = choice.list; } - else + QWidget::setTabOrder(previousWidget, overrideMPSizingCheckBox); + QWidget::setTabOrder(overrideMPSizingCheckBox, pageSizeSelector); + QWidget::setTabOrder(pageSizeSelector, portraitButton); + QWidget::setTabOrder(portraitButton, landscapeButton); + QWidget::setTabOrder(landscapeButton, widthSpinBox); + QWidget::setTabOrder(widthSpinBox, heightSpinBox); + + updatePlacementControls(); + updateSizeControls(); + insCountData->setFocus(); + insCountData->selectAll(); +} + +QSize InsPage::sizeHint() const +{ + QSize hint = QDialog::sizeHint(); + // Leave a little breathing room without increasing the minimum width. + hint.setWidth(minimumSizeHint().width() + fontMetrics().horizontalAdvance(QLatin1String("0000"))); + return hint; +} + +InsPage::MasterPageChoice InsPage::createMasterPageChoice(int position, const QString& positionLabel) +{ + MasterPageChoice choice; + auto* control = new FormWidget(this); + control->setDirection(FormWidget::Top); + control->setText(positionLabel); + choice.widget = control; + choice.widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + const int positionCount = std::max(1, static_cast(m_doc->pageSets()[m_doc->pagePositioning()].pageNames.count())); + const QString preferredName = preferredMasterPage(position, positionCount); + const bool hasPositionDefault = m_doc->MasterNames.contains(preferredName); + QStringList masterPageNames; + + for (auto it = m_doc->MasterNames.cbegin(); it != m_doc->MasterNames.cend(); ++it) { - widthSpinBox->setEnabled(false); - heightSpinBox->setEnabled(false); - double w = psi.width * m_unitRatio; - double h = psi.height * m_unitRatio; - if (orientationQComboBox->currentIndex() == 1) + const QString& masterPageName = it.key(); + const bool isNormal = masterPageName == CommonStrings::masterPageNormal + || masterPageName == CommonStrings::trMasterPageNormal; + if ((isNormal && !hasPositionDefault) + || masterPageMatchesPosition(it.value(), position, positionCount)) { - double t = h; - h = w; - w = t; + masterPageNames.append(masterPageName); } - widthSpinBox->setValue(w); - heightSpinBox->setValue(h); } + + choice.list = new QListWidget(choice.widget); + choice.list->setSelectionMode(QAbstractItemView::SingleSelection); + choice.list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + choice.list->setTextElideMode(Qt::ElideMiddle); + choice.list->setItemDelegate(new ElidedTextToolTipDelegate(choice.list)); + choice.list->setAccessibleName(positionLabel.isEmpty() + ? tr("Master pages") : tr("Master pages for %1").arg(positionLabel)); + for (const QString& masterPageName : std::as_const(masterPageNames)) + { + auto* item = new QListWidgetItem(masterPageDisplayName(masterPageName), choice.list); + item->setData(Qt::UserRole, masterPageName); + } + + int selectedRow = masterPageNames.indexOf(preferredName); + if (selectedRow < 0) + { + selectedRow = masterPageNames.indexOf(CommonStrings::trMasterPageNormal); + if (selectedRow < 0) + selectedRow = masterPageNames.indexOf(CommonStrings::masterPageNormal); + } + if (selectedRow < 0 && !masterPageNames.isEmpty()) + selectedRow = 0; + if (selectedRow >= 0) + choice.list->setCurrentRow(selectedRow); + + const int visibleRows = std::min(listVisibleRows, std::max(1, choice.list->count())); + const int rowHeight = choice.list->sizeHintForRow(0) > 0 ? choice.list->sizeHintForRow(0) : fontMetrics().height() + 4; + choice.list->setFixedHeight(rowHeight * visibleRows + choice.list->frameWidth() * 2 + 2); + control->addWidget(choice.list); + return choice; +} + +bool InsPage::masterPageMatchesPosition(int masterPageIndex, int position, int positionCount) const +{ + if (positionCount == 1) + return true; + + const int pageType = m_doc->MasterPages.at(masterPageIndex)->LeftPg; + if (position == 0) + return pageType == 1; + if (position == positionCount - 1) + return pageType == 0; + return pageType != 0 && pageType != 1; +} + +QString InsPage::preferredMasterPage(int position, int positionCount) const +{ + if (positionCount == 1) + return m_doc->MasterNames.contains(CommonStrings::trMasterPageNormal) + ? CommonStrings::trMasterPageNormal : CommonStrings::masterPageNormal; + if (position == 0) + return m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalLeft) + ? CommonStrings::trMasterPageNormalLeft : CommonStrings::masterPageNormalLeft; + if (position == positionCount - 1) + return m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalRight) + ? CommonStrings::trMasterPageNormalRight : CommonStrings::masterPageNormalRight; + return m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalMiddle) + ? CommonStrings::trMasterPageNormalMiddle : CommonStrings::masterPageNormalMiddle; +} + +QString InsPage::masterPageDisplayName(const QString& masterPageName) const +{ + if (masterPageName == CommonStrings::masterPageNormal) + return CommonStrings::trMasterPageNormal; + if (masterPageName == CommonStrings::masterPageNormalLeft) + return CommonStrings::trMasterPageNormalLeft; + if (masterPageName == CommonStrings::masterPageNormalMiddle) + return CommonStrings::trMasterPageNormalMiddle; + if (masterPageName == CommonStrings::masterPageNormalRight) + return CommonStrings::trMasterPageNormalRight; + return masterPageName; +} + +InsPage::InsertPosition InsPage::insertPosition() const +{ + return static_cast(placementButtonGroup->checkedId()); +} + +void InsPage::updatePlacementControls() +{ + const InsertPosition position = insertPosition(); + const bool needsPage = position == InsertPosition::Before || position == InsertPosition::After; + insWherePageData->setEnabled(needsPage); + moveObjectsCheckBox->setEnabled(position != InsertPosition::End); +} + +void InsPage::updateSizeControls() +{ + const bool overrideSize = overrideMPSizingCheckBox->isChecked(); + const bool visibilityChanged = pageSizeGroup->isHidden() == overrideSize; + const int previousWidth = width(); + pageSizeGroup->setVisible(overrideSize); + const bool customSize = pageSizeSelector->pageSize() == CommonStrings::customPageSize; + widthControl->setEnabled(overrideSize && customSize); + heightControl->setEnabled(overrideSize && customSize); + if (layout()) + layout()->activate(); + if (!isVisible()) + adjustSize(); + else if (visibilityChanged) + resize(std::max(previousWidth, minimumSizeHint().width()), sizeHint().height()); +} + +void InsPage::setSize(const QString& pageSizeName) +{ + const PageSizeInfo pageSizeInfo = PagePresetManager::instance().pageInfoByName(pageSizeName); + prefsPageSizeName = pageSizeInfo.id; + if (pageSizeInfo.id != CommonStrings::customPageSize) + { + double width = pageSizeInfo.width * m_unitRatio; + double height = pageSizeInfo.height * m_unitRatio; + if (m_orientation == 1) + std::swap(width, height); + widthSpinBox->setValue(width); + heightSpinBox->setValue(height); + } + updateSizeControls(); } -void InsPage::setOrientation(int ori) +void InsPage::setOrientation(int orientation) { - double t = widthSpinBox->value(); + if (orientation == m_orientation) + return; + m_orientation = orientation; + double width = widthSpinBox->value(); widthSpinBox->setValue(heightSpinBox->value()); - heightSpinBox->setValue(t); + heightSpinBox->setValue(width); } QStringList InsPage::getMasterPages() const { - QStringList ret; - for (int i = 0; i < masterPageCombos.count(); ++i) + QStringList masterPages; + for (const MasterPageChoice& choice : m_masterPageChoices) { - int currentIndex = masterPageCombos.at(i)->currentIndex(); - QVariant pageVar = masterPageCombos.at(i)->itemData(currentIndex); - ret.append(pageVar.toString()); + if (choice.list && choice.list->currentItem()) + masterPages.append(choice.list->currentItem()->data(Qt::UserRole).toString()); + else + masterPages.append(QString()); } - return ret; + return masterPages; } QString InsPage::getMasterPageN(uint n) const { - QComboBox* comboBox = masterPageCombos.at(n); - int currentIndex = comboBox->currentIndex(); - return comboBox->itemData(currentIndex).toString(); + const MasterPageChoice& choice = m_masterPageChoices.at(n); + if (choice.list && choice.list->currentItem()) + return choice.list->currentItem()->data(Qt::UserRole).toString(); + return QString(); } int InsPage::getWhere() const { - return insWhereData->currentIndex(); + switch (insertPosition()) + { + case InsertPosition::Start: + case InsertPosition::Before: + return 0; + case InsertPosition::After: + return 1; + case InsertPosition::End: + return 2; + } + return 2; } int InsPage::getWherePage() const { - if (insWhereData->currentIndex() == 2) - return m_doc->Pages->count(); - return insWherePageData->value(); + switch (insertPosition()) + { + case InsertPosition::Start: + return 1; + case InsertPosition::End: + return m_doc->Pages->count(); + case InsertPosition::Before: + case InsertPosition::After: + return insWherePageData->value(); + } + return m_doc->Pages->count(); } int InsPage::getCount() const @@ -372,25 +572,15 @@ int InsPage::orientation() const { - return orientationQComboBox->currentIndex(); + return m_orientation; } bool InsPage::overrideMasterPageSizing() const { - return (overrideMPSizingCheckBox->checkState() == Qt::Checked); + return overrideMPSizingCheckBox->isChecked(); } bool InsPage::moveObjects() const { return moveObjectsCheckBox->isChecked(); } - -void InsPage::insWherePageDataDisable(int index) -{ - insWherePageData->setDisabled((index == 2)); -} - -void InsPage::enableSizingControls(int state) -{ - dsGroupBox7->setEnabled(state == Qt::Checked); -} Index: scribus/ui/inspage.h =================================================================== --- scribus/ui/inspage.h (revision 27829) +++ scribus/ui/inspage.h (working copy) @@ -10,19 +10,17 @@ #include "scribusapi.h" #include "widgets/pagesizeselector.h" #include -#include #include #include -#include -#include -#include -class QLabel; -class QPushButton; -class QSpinBox; -class QGroupBox; +class QButtonGroup; class QCheckBox; -class QComboBox; +class QDialogButtonBox; +class QGroupBox; +class QListWidget; +class QSpinBox; +class QToolButton; +class FormWidget; class ScrSpinBox; class ScribusDoc; @@ -32,7 +30,8 @@ public: InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages ); - ~InsPage() {}; + ~InsPage() override = default; + QSize sizeHint() const override; QString prefsPageSizeName; @@ -49,42 +48,58 @@ bool moveObjects() const; private: + enum class InsertPosition + { + Start, + End, + Before, + After + }; + + struct MasterPageChoice + { + QWidget* widget { nullptr }; + QListWidget* list { nullptr }; + }; + + MasterPageChoice createMasterPageChoice(int position, const QString& positionLabel); + bool masterPageMatchesPosition(int masterPageIndex, int position, int positionCount) const; + QString preferredMasterPage(int position, int positionCount) const; + QString masterPageDisplayName(const QString& masterPageName) const; + InsertPosition insertPosition() const; + void updatePlacementControls(); + void updateSizeControls(); + ScribusDoc* m_doc { nullptr }; - QLabel* insCountLabel { nullptr }; - QLabel* masterPageLabel { nullptr }; - QLabel* pagesLabel { nullptr }; QDialogButtonBox* buttonBox { nullptr }; - QComboBox* insWhereData { nullptr }; + QButtonGroup* placementButtonGroup { nullptr }; + QButtonGroup* orientationButtonGroup { nullptr }; + QToolButton* startButton { nullptr }; + QToolButton* endButton { nullptr }; + QToolButton* beforeButton { nullptr }; + QToolButton* afterButton { nullptr }; QSpinBox* insWherePageData { nullptr }; QSpinBox* insCountData { nullptr }; - QVBoxLayout* dialogLayout { nullptr }; - QGridLayout* whereLayout { nullptr }; - QGridLayout* masterPageLayout { nullptr }; - QHBoxLayout* okCancelLayout { nullptr }; - QGridLayout* dsGroupBox7Layout { nullptr }; - QGroupBox* dsGroupBox7 { nullptr }; - QGroupBox* masterPageGroup { nullptr }; + QGroupBox* pageSizeGroup { nullptr }; + FormWidget* widthControl { nullptr }; + FormWidget* heightControl { nullptr }; ScrSpinBox* widthSpinBox { nullptr }; ScrSpinBox* heightSpinBox { nullptr }; - QLabel* widthQLabel { nullptr }; - QLabel* heightQLabel { nullptr }; - QLabel* textLabel1 { nullptr }; - QLabel* textLabel2 { nullptr }; PageSizeSelector* pageSizeSelector { nullptr }; - QComboBox* orientationQComboBox { nullptr }; + QToolButton* portraitButton { nullptr }; + QToolButton* landscapeButton { nullptr }; QCheckBox* moveObjectsCheckBox { nullptr }; QCheckBox* overrideMPSizingCheckBox { nullptr }; - + double m_unitRatio { 1.0 }; - QList masterPageCombos; + int m_orientation { 0 }; + QList m_masterPageChoices; private slots: - void insWherePageDataDisable (int index); void setSize(const QString &); - void setOrientation(int ori); - void enableSizingControls(int); + void setOrientation(int orientation); }; #endif // INSPAGE_H Index: scribus/ui/widgets/pagesizeselector.cpp =================================================================== --- scribus/ui/widgets/pagesizeselector.cpp (revision 27829) +++ scribus/ui/widgets/pagesizeselector.cpp (working copy) @@ -14,22 +14,32 @@ * * ***************************************************************************/ -#include +#include +#include "form_widget.h" #include "pagesizeselector.h" PageSizeSelector::PageSizeSelector(QWidget *parent) : QWidget{parent} { - comboCategory = new QComboBox(); - comboFormat = new QComboBox(); + categoryControl = new FormWidget(this); + categoryControl->setText(QString()); + comboCategory = new QComboBox(categoryControl); + categoryControl->addWidget(comboCategory); + + formatControl = new FormWidget(this); + formatControl->setText(QString()); + comboFormat = new QComboBox(formatControl); + formatControl->addWidget(comboFormat); + + selectorLayout = new QBoxLayout(QBoxLayout::TopToBottom, this); + selectorLayout->setContentsMargins(0, 0, 0, 0); + selectorLayout->setSpacing(4); + selectorLayout->addWidget(categoryControl); + selectorLayout->addWidget(formatControl); - QVBoxLayout* lytMain = new QVBoxLayout(); - lytMain->setContentsMargins(0, 0, 0, 0); - lytMain->setSpacing(4); - lytMain->addWidget(comboCategory); - lytMain->addWidget(comboFormat); - this->setLayout(lytMain); + setFocusProxy(comboCategory); + QWidget::setTabOrder(comboCategory, comboFormat); connect(comboCategory, &QComboBox::currentIndexChanged, this, &PageSizeSelector::categorySelected); connect(comboFormat, &QComboBox::currentIndexChanged, this, &PageSizeSelector::formatSelected); @@ -39,7 +49,17 @@ void PageSizeSelector::setHasFormatSelector(bool isVisble) { m_hasFormatSelector = isVisble; - comboFormat->setVisible(isVisble); + formatControl->setVisible(isVisble); +} + +void PageSizeSelector::setCompactMode(const QString& categoryLabel, const QString& formatLabel) +{ + categoryControl->setText(categoryLabel); + formatControl->setText(formatLabel); + comboCategory->setAccessibleName(categoryLabel); + comboFormat->setAccessibleName(formatLabel); + selectorLayout->setDirection(QBoxLayout::LeftToRight); + selectorLayout->setSpacing(9); } void PageSizeSelector::setHasCustom(bool hasCustom) @@ -124,14 +144,14 @@ if (categoryId == pciCustom.id) { - comboFormat->setEnabled(false); + formatControl->setEnabled(false); m_sizeName = pciCustom.id; m_trSizeName = pciCustom.displayName; return; } else { - comboFormat->setEnabled(true); + formatControl->setEnabled(true); } // PageSize ps(name); Index: scribus/ui/widgets/pagesizeselector.h =================================================================== --- scribus/ui/widgets/pagesizeselector.h (revision 27829) +++ scribus/ui/widgets/pagesizeselector.h (working copy) @@ -22,6 +22,9 @@ #include "manager/pagepreset_manager.h" +class FormWidget; +class QBoxLayout; + class PageSizeSelector : public QWidget { Q_OBJECT @@ -32,6 +35,7 @@ void setPageSize(double width, double height); void setHasFormatSelector(bool isVisble ); void setHasCustom(bool hasCustom); + void setCompactMode(const QString& categoryLabel, const QString& formatLabel); bool hasCustom() const { return m_hasCustom; }; bool hasFormatSelector() const { return m_hasFormatSelector; }; void setCurrentCategory(const QString& categoryId); @@ -41,6 +45,9 @@ QString pageSizeTR() const { return m_trSizeName; }; private: + FormWidget* categoryControl { nullptr }; + FormWidget* formatControl { nullptr }; + QBoxLayout* selectorLayout { nullptr }; QComboBox* comboCategory { nullptr }; QComboBox* comboFormat { nullptr };