QPageSetupWidget::QPageSetupWidget(QWidget *parent)
    : QWidget(parent),
      m_pagePreview(0),
      m_printer(0),
      m_outputFormat(QPrinter::PdfFormat),
      m_units(QPageLayout::Point),
      m_blockSignals(false)
{
    m_ui.setupUi(this);

    QVBoxLayout *lay = new QVBoxLayout(m_ui.preview);
    m_ui.preview->setLayout(lay);
    m_pagePreview = new QPagePreview(m_ui.preview);
    m_pagePreview->setPagePreviewLayout(1, 1);

    lay->addWidget(m_pagePreview);

    setAttribute(Qt::WA_WState_Polished, false);

#ifdef PSD_ENABLE_PAPERSOURCE
    for (int i=0; paperSourceNames[i]; ++i)
        m_ui.paperSource->insertItem(paperSourceNames[i]);
#else
    m_ui.paperSourceLabel->setVisible(false);
    m_ui.paperSource->setVisible(false);
#endif

    m_ui.reverseLandscape->setVisible(false);
    m_ui.reversePortrait->setVisible(false);

    initUnits();
    initPagesPerSheet();

    connect(m_ui.unitCombo, SIGNAL(activated(int)), this, SLOT(unitChanged()));

    connect(m_ui.pageSizeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pageSizeChanged()));
    connect(m_ui.pageWidth, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged()));
    connect(m_ui.pageHeight, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged()));

    connect(m_ui.leftMargin, SIGNAL(valueChanged(double)), this, SLOT(leftMarginChanged(double)));
    connect(m_ui.topMargin, SIGNAL(valueChanged(double)), this, SLOT(topMarginChanged(double)));
    connect(m_ui.rightMargin, SIGNAL(valueChanged(double)), this, SLOT(rightMarginChanged(double)));
    connect(m_ui.bottomMargin, SIGNAL(valueChanged(double)), this, SLOT(bottomMarginChanged(double)));

    connect(m_ui.portrait, SIGNAL(clicked()), this, SLOT(pageOrientationChanged()));
    connect(m_ui.landscape, SIGNAL(clicked()), this, SLOT(pageOrientationChanged()));

    connect(m_ui.pagesPerSheetCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pagesPerSheetChanged()));
}
Ejemplo n.º 2
0
void QgsCompositionWidget::adjustOrientation()
{
    double width = size( mPaperWidthDoubleSpinBox );
    double height = size( mPaperHeightDoubleSpinBox );

    if ( width < 0 || height < 0 )
    {
        return;
    }

    if ( height > width ) //change values such that width > height
    {
        double tmp = width;
        width = height;
        height = tmp;
    }

    bool lineEditsEnabled = mPaperWidthDoubleSpinBox->isEnabled();

    mPaperWidthDoubleSpinBox->setEnabled( true );
    mPaperHeightDoubleSpinBox->setEnabled( true );
    if ( mPaperOrientationComboBox->currentText() == tr( "Landscape" ) )
    {
        setSize( mPaperWidthDoubleSpinBox, width );
        setSize( mPaperHeightDoubleSpinBox, height );
    }
    else
    {
        setSize( mPaperWidthDoubleSpinBox, height );
        setSize( mPaperHeightDoubleSpinBox, width );
    }

    mPaperWidthDoubleSpinBox->setEnabled( lineEditsEnabled );
    mPaperHeightDoubleSpinBox->setEnabled( lineEditsEnabled );

    emit pageOrientationChanged( mPaperOrientationComboBox->currentText() );
}