Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scinputdialog.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 "scinputdialog.h"
00008 #include "scinputdialog.moc"
00009 
00010 #include <qvariant.h>
00011 #include <qlabel.h>
00012 #include <qpushbutton.h>
00013 #include <qlayout.h>
00014 #include <qtooltip.h>
00015 #include <qwhatsthis.h>
00016 #include "mspinbox.h"
00017 
00018 
00019 ScInputDialog::ScInputDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
00020        : QDialog( parent, name, modal, fl )
00021 {
00022        if ( !name )
00023               setName( "ScInputDialog" );
00024        setSizeGripEnabled( TRUE );
00025        ScInputDialogLayout = new QGridLayout( this, 1, 1, 11, 6, "ScInputDialogLayout");
00026 
00027        labelEntryLayout = new QHBoxLayout( 0, 0, 6, "labelEntryLayout");
00028 
00029        entryLabel = new QLabel( this, "entryLabel" );
00030        labelEntryLayout->addWidget( entryLabel );
00031 
00032        entrySpin = new MSpinBox( this, "entrySpin" );
00033        entrySpin->setMinimumSize( QSize( 0, 10 ) );
00034        labelEntryLayout->addWidget( entrySpin );
00035 
00036        buttonLayout = new QHBoxLayout(0, 0, 6, "buttonLayout");
00037        QSpacerItem* hspacing = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
00038        buttonLayout->addItem(hspacing);
00039 
00040        buttonOk = new QPushButton( this, "buttonOk" );
00041        buttonOk->setAutoDefault( TRUE );
00042        buttonOk->setDefault( TRUE );
00043        buttonLayout->addWidget( buttonOk );
00044 
00045        buttonCancel = new QPushButton( this, "buttonCancel" );
00046        buttonCancel->setAutoDefault( TRUE );
00047        buttonLayout->addWidget( buttonCancel );
00048 
00049        mainLayout = new QVBoxLayout(0, 0, 6, "mainLayout");
00050        mainLayout->addLayout(labelEntryLayout);
00051        mainLayout->addLayout(buttonLayout);
00052 
00053        ScInputDialogLayout->addLayout( mainLayout, 0, 0 );
00054        languageChange();
00055        //resize( QSize(283, 60).expandedTo(minimumSizeHint()) );
00056        clearWState( WState_Polished );
00057 
00058        // signals and slots connections
00059        connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
00060        connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00061 }
00062 
00063 void ScInputDialog::languageChange()
00064 {
00065        setCaption( tr( "Input Dialog" ) );
00066        entryLabel->setText( tr( "InputDialog" ) );
00067        buttonOk->setText( tr( "&OK" ) );
00068        buttonOk->setAccel( QKeySequence( QString::null ) );
00069        buttonCancel->setText( tr( "&Cancel" ) );
00070        buttonCancel->setAccel( QKeySequence( QString::null ) );
00071 }
00072 
00073 double ScInputDialog::getDouble( const QString &caption, const QString &label, double num,
00074                                                         double from, double to, int decimals,
00075                                                         QString suffix, bool *ok,
00076                                                         QWidget *parent, const char *name )
00077 {
00078        ScInputDialog *dlg = new ScInputDialog(parent, name, TRUE);
00079        dlg->setCaption( caption );
00080        dlg->entryLabel->setText(label);
00081        dlg->entrySpin->setValues(0.0, 1000.0, decimals, num);
00082        dlg->entrySpin->setSuffix(suffix);
00083        dlg->entrySpin->selectAll();
00084 
00085        bool accepted = ( dlg->exec() == QDialog::Accepted );
00086        if ( ok )
00087               *ok = accepted;
00088 
00089        double result = dlg->entrySpin->value();
00090 
00091        delete dlg;
00092        return result;
00093 }