Back to index

scribus-ng  1.3.4.dfsg+svn20071115
dialog.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "dialog.h"
00008 #include "dialog.moc"
00009 #include <qvariant.h>
00010 #include <qpushbutton.h>
00011 #include <qlabel.h>
00012 #include <qlineedit.h>
00013 #include <qcombobox.h>
00014 #include <qspinbox.h>
00015 #include <qbuttongroup.h>
00016 #include <qgroupbox.h>
00017 #include <qlayout.h>
00018 #include <qtooltip.h>
00019 #include <qwhatsthis.h>
00020 #include <qimage.h>
00021 #include <qdir.h>
00022 #include <qfiledialog.h>
00023 #include "scribusdoc.h"
00024 #include "createrange.h"
00025 #include "prefsmanager.h"
00026 #include "prefsfile.h"
00027 #include "prefscontext.h"
00028 #include "mspinbox.h"
00029 #include "usertaskstructs.h"
00030 #include "util.h"
00031 
00032 #include "commonstrings.h"
00033 
00034 /*
00035  *  Constructs a ExportForm as a child of 'parent', with the
00036  *  name 'name' and widget flags set to 'f'.
00037  *
00038  *  The dialog will by default be modeless, unless you set 'modal' to
00039  *  true to construct a modal dialog.
00040  */
00041 ExportForm::ExportForm(QWidget* parent, ScribusDoc* doc, int size, int quality, QString type)
00042        : QDialog(parent, "ExportForm", true, 0), m_doc(doc), m_PageCount(doc->DocPages.count())
00043 {
00044        prefs = PrefsManager::instance()->prefsFile->getPluginContext("pixmapexport");
00045        ExportFormLayout = new QVBoxLayout( this, 10, 5, "ExportFormLayout");
00046        layout1 = new QHBoxLayout( 0, 0, 5, "layout1");
00047        TextLabel1 = new QLabel( this, "TextLabel1" );
00048        layout1->addWidget( TextLabel1 );
00049        OutputDirectory = new QLineEdit( this, "OutputDirectory" );
00050        OutputDirectory->setText( QDir::convertSeparators(prefs->get("wdir", QDir::currentDirPath())) );
00051        layout1->addWidget( OutputDirectory );
00052        OutputDirectoryButton = new QPushButton( this, "OutputDirectoryButton" );
00053        OutputDirectoryButton->setDefault( true );
00054        layout1->addWidget( OutputDirectoryButton );
00055        ExportFormLayout->addLayout( layout1 );
00056 
00057        layout3 = new QHBoxLayout( 0, 0, 5, "layout3");
00058        groupBox1 = new QGroupBox( this, "groupBox1" );
00059        groupBox1->setColumnLayout(0, Qt::Vertical );
00060        groupBox1->layout()->setSpacing( 5 );
00061        groupBox1->layout()->setMargin( 10 );
00062        groupBox1Layout = new QGridLayout( groupBox1->layout() );
00063        groupBox1Layout->setAlignment( Qt::AlignTop );
00064        TextLabel2 = new QLabel( groupBox1, "TextLabel2" );
00065        groupBox1Layout->addWidget( TextLabel2, 0, 0 );
00066        textLabel1 = new QLabel( groupBox1, "textLabel1" );
00067        groupBox1Layout->addWidget( textLabel1, 1, 0 );
00068        textLabel3 = new QLabel( groupBox1, "textLabel3" );
00069        groupBox1Layout->addWidget( textLabel3, 2, 0 );
00070        textLabel4 = new QLabel( groupBox1, "textLabel4" );
00071        groupBox1Layout->addWidget( textLabel4, 3, 0 );
00072        BitmapType = new QComboBox( false, groupBox1, "BitmapType" );
00073     BitmapType->clear();
00074        BitmapType->insertStrList(QImageIO::outputFormats());
00075        BitmapType->setCurrentText(type);
00076        BitmapType->setEditable(false);
00077        groupBox1Layout->addMultiCellWidget( BitmapType, 0, 0, 1, 2 );
00078        QualityBox = new QSpinBox( groupBox1, "QualityBox" );
00079        QualityBox->setMaxValue( 100 );
00080        QualityBox->setMinValue( 1 );
00081        QualityBox->setValue(quality);
00082        groupBox1Layout->addWidget( QualityBox, 1, 1 );
00083        DPIBox = new QSpinBox( groupBox1, "DPIBox" );
00084        DPIBox->setMaxValue( 2400 );
00085        DPIBox->setMinValue( 72 );
00086        DPIBox->setValue(size);
00087        groupBox1Layout->addWidget( DPIBox, 2, 1 );
00088        EnlargementBox = new MSpinBox( groupBox1, 1 );
00089        EnlargementBox->setMaxValue( 2400 );
00090        EnlargementBox->setMinValue( 1 );
00091        EnlargementBox->setValue(size);
00092        groupBox1Layout->addWidget( EnlargementBox, 3, 1 );
00093        textLabel5 = new QLabel( groupBox1, "textLabel5" );
00094        groupBox1Layout->addMultiCellWidget( textLabel5, 4, 4, 0, 2 );
00095        textLabel6 = new QLabel( groupBox1, "textLabel6" );
00096        groupBox1Layout->addMultiCellWidget( textLabel6, 5, 5, 0, 2 );
00097        layout3->addWidget( groupBox1 );
00098 
00099        ButtonGroup1 = new QButtonGroup( this, "ButtonGroup1" );
00100        ButtonGroup1->setColumnLayout(0, Qt::Vertical );
00101        ButtonGroup1->layout()->setSpacing( 5 );
00102        ButtonGroup1->layout()->setMargin( 10 );
00103        ButtonGroup1Layout = new QVBoxLayout( ButtonGroup1->layout() );
00104        ButtonGroup1Layout->setAlignment( Qt::AlignTop );
00105        OnePageRadio = new QRadioButton( ButtonGroup1, "OnePageRadio" );
00106        OnePageRadio->setChecked( true );
00107        ButtonGroup1Layout->addWidget( OnePageRadio );
00108        AllPagesRadio = new QRadioButton( ButtonGroup1, "AllPagesRadio" );
00109        ButtonGroup1Layout->addWidget( AllPagesRadio );
00110        layout2 = new QHBoxLayout( 0, 0, 5, "layout2");
00111        IntervalPagesRadio = new QRadioButton( ButtonGroup1, "IntervalPagesRadio" );
00112        layout2->addWidget( IntervalPagesRadio );
00113 
00114 //     pageNumberSelectorLayout = new QHBoxLayout( 0, 0, 5, "pageNumberSelectorLayout" );
00115        RangeVal = new QLineEdit( ButtonGroup1, "RangeVal" );
00116 //     pageNumberSelectorLayout->addWidget( RangeVal );
00117        layout2->addWidget( RangeVal );
00118        pageNrButton = new QPushButton( QString::fromUtf8("…"), ButtonGroup1, "pageNrButton" );
00119        pageNrButton->setPixmap(loadIcon("ellipsis.png"));
00120        layout2->addWidget( pageNrButton );
00121 //     layout2->addLayout( pageNumberSelectorLayout, 2, 1 );
00122        RangeVal->setEnabled(false);
00123        pageNrButton->setEnabled(false);
00124        ButtonGroup1Layout->addLayout( layout2 );
00125        layout3->addWidget( ButtonGroup1 );
00126        ExportFormLayout->addLayout( layout3 );
00127 
00128        layout4 = new QHBoxLayout( 0, 0, 5, "layout4");
00129        QSpacerItem* spacer = new QSpacerItem( 111, 21, QSizePolicy::Expanding, QSizePolicy::Minimum );
00130        layout4->addItem( spacer );
00131        OkButton = new QPushButton( this, "OkButton" );
00132        layout4->addWidget( OkButton );
00133        CancelButton = new QPushButton( this, "CancelButton" );
00134        layout4->addWidget( CancelButton );
00135        ExportFormLayout->addLayout( layout4 );
00136        languageChange();
00137        readConfig();
00138        computeSize();
00139        resize( QSize(447, 206).expandedTo(minimumSizeHint()) );
00140 
00141     // buddies
00142        TextLabel1->setBuddy( OutputDirectory );
00143        TextLabel2->setBuddy( BitmapType );
00144        textLabel1->setBuddy( QualityBox );
00145        textLabel3->setBuddy( DPIBox );
00146        textLabel4->setBuddy( EnlargementBox );
00147        connect(OutputDirectoryButton, SIGNAL(clicked()), this, SLOT(OutputDirectoryButton_pressed()));
00148        connect(OkButton, SIGNAL(clicked()), this, SLOT(OkButton_pressed()));
00149        connect(CancelButton, SIGNAL(clicked()), this, SLOT(reject()));
00150        connect(IntervalPagesRadio, SIGNAL(stateChanged(int)), this, SLOT(IntervalPagesRadio_stateChanged(int)));
00151        connect(AllPagesRadio, SIGNAL(stateChanged(int)), this, SLOT(AllPagesRadio_stateChanged(int)));
00152        connect(OnePageRadio, SIGNAL(stateChanged(int)), this, SLOT(OnePageRadio_stateChanged(int)));
00153        connect(EnlargementBox, SIGNAL(valueChanged(int)), this, SLOT(computeSize()));
00154        connect(DPIBox, SIGNAL(valueChanged(int)), this, SLOT(computeSize()));
00155        connect(pageNrButton, SIGNAL(clicked()), this, SLOT(createPageNumberRange()));
00156 }
00157 
00158 void ExportForm::computeSize()
00159 {
00160        double pixmapSize;
00161        double pw = (OnePageRadio->isOn() && m_doc->currentPage()) ? m_doc->currentPage()->width() : m_doc->pageWidth;
00162        double ph = (OnePageRadio->isOn() && m_doc->currentPage()) ? m_doc->currentPage()->height() : m_doc->pageHeight;
00163        (ph > pw) ? pixmapSize = ph : pixmapSize = pw;
00164        int maxGr = qRound(pixmapSize * EnlargementBox->value() * (DPIBox->value() / 72.0) / 100.0);
00165        double sc = QMIN(maxGr / pw, maxGr / ph);
00166        textLabel6->setText(QString("%1 x %2 px").arg(qRound(pw * sc)).arg(qRound(ph * sc)));
00167 }
00168 
00169 void ExportForm::OutputDirectoryButton_pressed()
00170 {
00171        QString lastDir = prefs->get("wdir", ".");
00172        QString d = QFileDialog::getExistingDirectory(lastDir, this, "d", tr("Choose a Export Directory"), true);
00173        if (d.length()>0)
00174        {
00175               d = QDir::convertSeparators(d);
00176               OutputDirectory->setText(d);
00177               prefs->set("wdir", d);
00178        }
00179 }
00180 
00181 void ExportForm::OkButton_pressed()
00182 {
00183        bitmapType = BitmapType->currentText();
00184        writeConfig();
00185        accept();
00186 }
00187 
00188 void ExportForm::IntervalPagesRadio_stateChanged(int)
00189 {
00190        RangeVal->setEnabled(true);
00191        pageNrButton->setEnabled(true);
00192        computeSize();
00193 }
00194 
00195 void ExportForm::AllPagesRadio_stateChanged(int)
00196 {
00197        RangeVal->setEnabled(false);
00198        pageNrButton->setEnabled(false);
00199        computeSize();
00200 }
00201 
00202 void ExportForm::OnePageRadio_stateChanged(int)
00203 {
00204        RangeVal->setEnabled(false);
00205        pageNrButton->setEnabled(false);
00206        computeSize();
00207 }
00208 
00209 /*
00210  *  Destroys the object and frees any allocated resources
00211  */
00212 ExportForm::~ExportForm()
00213 {
00214        // no need to delete child widgets, Qt does it all for us
00215 }
00216 
00217 /*
00218  *  Sets the strings of the subwidgets using the current
00219  *  language.
00220  */
00221 void ExportForm::languageChange()
00222 {
00223        setCaption( tr( "Export as Image(s)" ) );
00224        TextLabel1->setText( tr( "&Export to Directory:" ) );
00225        OutputDirectoryButton->setText( tr( "C&hange..." ) );
00226        groupBox1->setTitle( tr( "Options" ) );
00227        TextLabel2->setText( tr( "Image &Type:" ) );
00228        textLabel1->setText( tr( "&Quality:" ) );
00229        textLabel3->setText( tr( "&Resolution:" ) );
00230        textLabel4->setText( tr( "&Size:" ) );
00231        QualityBox->setSuffix( tr( " %" ) );
00232        DPIBox->setSuffix( tr( " dpi" ) );
00233        EnlargementBox->setSuffix( tr( " %" ) );
00234        ButtonGroup1->setTitle( tr( "Range" ) );
00235        OnePageRadio->setText( tr( "&Current page" ) );
00236        AllPagesRadio->setText( tr( "&All pages" ) );
00237        IntervalPagesRadio->setText( tr( "&Range" ) );
00238        OkButton->setText( CommonStrings::tr_OK );
00239        CancelButton->setText( CommonStrings::tr_Cancel );
00240        CancelButton->setAccel( QKeySequence( tr( "C" ) ) );
00241        textLabel5->setText( tr("Image size in Pixels"));
00242        QToolTip::add( IntervalPagesRadio, tr( "Export a range of pages" ) );
00243        QToolTip::add( RangeVal, tr( "Insert a comma separated list of tokens where\na token can be * for all the pages, 1-5 for\na range of pages or a single page number." ) );
00244        QToolTip::add( AllPagesRadio, tr( "Export all pages" ) );
00245        QToolTip::add( OnePageRadio, tr( "Export only the current page" ) );
00246        QToolTip::add( DPIBox, tr( "Resolution of the Images\nUse 72 dpi for Images intended for the Screen" ) );
00247        QToolTip::add( EnlargementBox, tr( "Size of the images. 100% for no changes, 200% for two times larger etc." ));
00248        QToolTip::add( QualityBox, tr( "The quality of your images - 100% is the best, 1% the lowest quality" ) );
00249        QToolTip::add( BitmapType, tr( "Available export formats" ) );
00250        QToolTip::add( OutputDirectory, tr( "The output directory - the place to store your images.\nName of the export file will be 'documentname-pagenumber.filetype'" ) );
00251        QToolTip::add( OutputDirectoryButton, tr( "Change the output directory" ) );
00252 }
00253 
00254 
00255 void ExportForm::readConfig()
00256 {
00257        DPIBox->setValue(prefs->getUInt("DPIBox", 72));
00258        EnlargementBox->setValue(prefs->getDouble("EnlargementBox", 100));
00259        QualityBox->setValue(prefs->getUInt("QualityBox", 100));
00260        ButtonGroup1->setButton(prefs->getUInt("ButtonGroup1", 0));
00261        if (prefs->getInt("ButtonGroup1")==2)
00262               RangeVal->setEnabled(true);
00263        else
00264               RangeVal->setEnabled(false);
00265        BitmapType->setCurrentItem(prefs->getInt("BitmapType", 4));
00266        RangeVal->setText(prefs->get("RangeVal", ""));
00267 }
00268 
00269 void ExportForm::writeConfig()
00270 {
00271        prefs->set("DPIBox", DPIBox->value());
00272        prefs->set("EnlargementBox", EnlargementBox->value());
00273        prefs->set("QualityBox", QualityBox->value());
00274        prefs->set("ButtonGroup1", ButtonGroup1->id(ButtonGroup1->selected()));
00275        prefs->set("BitmapType",BitmapType->currentItem());
00276        prefs->set("RangeVal", RangeVal->text());
00277 }
00278 
00279 void ExportForm::createPageNumberRange( )
00280 {
00281        CreateRange cr(RangeVal->text(), m_PageCount, this);
00282        if (cr.exec())
00283        {
00284               CreateRangeData crData;
00285               cr.getCreateRangeData(crData);
00286               RangeVal->setText(crData.pageRange);
00287        }
00288 }