Back to index

scribus-ng  1.3.4.dfsg+svn20071115
oneclick.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 "oneclick.h"
00008 #include "oneclick.moc"
00009 extern QPixmap loadIcon(QString nam);
00010 
00011 #include <qtooltip.h>
00012 #include <qdialog.h>
00013 #include <qlayout.h>
00014 #include <qlabel.h>
00015 #include <qcheckbox.h>
00016 #include <qpushbutton.h>
00017 #include <qbuttongroup.h>
00018 #include <qgroupbox.h>
00019 #include <qradiobutton.h>
00020 #include <qframe.h>
00021 #include "mspinbox.h"
00022 #include "linkbutton.h"
00023 #include "units.h"
00024 #include "commonstrings.h"
00025 
00026 OneClick::OneClick( QWidget* parent, QString titel, int unitIndex, double defW, double defH, bool remember, int origin, int mode ) : QDialog( parent, "OneClick", true, 0 )
00027 {
00028        double m_unitRatio = unitGetRatioFromIndex(unitIndex);
00029        QString m_suffix = unitGetSuffixFromIndex(unitIndex);
00030        int decimals = unitGetDecimalsFromIndex(unitIndex);
00031        setCaption( titel );
00032        setIcon(loadIcon("AppIcon.png"));
00033        queryLayout = new QVBoxLayout( this, 10, 5 );
00034        editLayout = new QGridLayout;
00035        editLayout->setSpacing( 5 );
00036        editLayout->setMargin( 0 );
00037        RotationGroup = new QButtonGroup( tr("Origin"), this, "RotationGroup" );
00038        RotationGroup->setColumnLayout(0, Qt::Vertical );
00039        RotationGroup->layout()->setSpacing( 0 );
00040        RotationGroup->layout()->setMargin( 10 );
00041        Layout12a = new QGridLayout( RotationGroup->layout() );
00042        Layout12a->setAlignment( Qt::AlignTop );
00043        QSpacerItem* spacerT = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
00044        Layout12a->addItem( spacerT, 0, 1 );
00045        QSpacerItem* spacerL = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00046        Layout12a->addItem( spacerL, 1, 0 );
00047        Layout12 = new QGridLayout;
00048        Layout12->setSpacing( 0 );
00049        Layout12->setMargin( 0 );
00050        TopLeft = new QRadioButton( RotationGroup, "TopLeft" );
00051        TopLeft->setText( "" );
00052        TopLeft->setChecked( true );
00053        Layout12->addWidget( TopLeft, 0, 0, Qt::AlignCenter );
00054        if (mode == 0)
00055        {
00056               Line1 = new QFrame( RotationGroup, "Line1" );
00057               Line1->setMinimumSize( QSize( 20, 4 ) );
00058               Line1->setMaximumSize( QSize( 20, 4 ) );
00059               Line1->setFrameShape( QFrame::HLine );
00060               Line1->setFrameShadow( QFrame::Plain );
00061               Line1->setLineWidth( 3 );
00062               Layout12->addWidget( Line1, 0, 1, Qt::AlignCenter );
00063               TopRight = new QRadioButton( RotationGroup, "TopRight" );
00064               TopRight->setText( "" );
00065               Layout12->addWidget( TopRight, 0, 2, Qt::AlignCenter );
00066               Line2 = new QFrame( RotationGroup, "Line2" );
00067               Line2->setMinimumSize( QSize( 4, 20 ) );
00068               Line2->setMaximumSize( QSize( 4, 20 ) );
00069               Line2->setFrameShape( QFrame::VLine );
00070               Line2->setFrameShadow( QFrame::Plain );
00071               Line2->setLineWidth( 3 );
00072               Layout12->addWidget( Line2, 1, 0, Qt::AlignCenter );
00073               Center = new QRadioButton( RotationGroup, "Center" );
00074               Center->setText( "" );
00075               Layout12->addWidget( Center, 1, 1, Qt::AlignCenter );
00076               Line4 = new QFrame( RotationGroup, "Line4" );
00077               Line4->setMinimumSize( QSize( 4, 20 ) );
00078               Line4->setMaximumSize( QSize( 4, 20 ) );
00079               Line4->setFrameShadow( QFrame::Plain );
00080               Line4->setLineWidth( 3 );
00081               Line4->setFrameShape( QFrame::VLine );
00082               Layout12->addWidget( Line4, 1, 2, Qt::AlignCenter );
00083               BottomLeft = new QRadioButton( RotationGroup, "BottomLeft" );
00084               BottomLeft->setText( "" );
00085               Layout12->addWidget( BottomLeft, 2, 0, Qt::AlignCenter );
00086               Line5 = new QFrame( RotationGroup, "Line5" );
00087               Line5->setMinimumSize( QSize( 20, 4 ) );
00088               Line5->setMaximumSize( QSize( 20, 4 ) );
00089               Line5->setFrameShape( QFrame::HLine );
00090               Line5->setFrameShadow( QFrame::Plain );
00091               Line5->setLineWidth( 3 );
00092               Layout12->addWidget( Line5, 2, 1, Qt::AlignCenter );
00093               BottomRight = new QRadioButton( RotationGroup, "BottomRight" );
00094               BottomRight->setText( "" );
00095               Layout12->addWidget( BottomRight, 2, 2, Qt::AlignCenter );
00096        }
00097        else
00098        {
00099               Line1 = new QFrame( RotationGroup, "Line1" );
00100               Line1->setMinimumSize( QSize( 10, 4 ) );
00101               Line1->setMaximumSize( QSize( 10, 4 ) );
00102               Line1->setFrameShape( QFrame::HLine );
00103               Line1->setFrameShadow( QFrame::Plain );
00104               Line1->setLineWidth( 3 );
00105               Layout12->addWidget( Line1, 0, 1, Qt::AlignCenter );
00106               Center = new QRadioButton( RotationGroup, "Center" );
00107               Center->setText( "" );
00108               Layout12->addWidget( Center, 0, 2, Qt::AlignCenter );
00109               Line2 = new QFrame( RotationGroup, "Line1" );
00110               Line2->setMinimumSize( QSize( 10, 4 ) );
00111               Line2->setMaximumSize( QSize( 10, 4 ) );
00112               Line2->setFrameShape( QFrame::HLine );
00113               Line2->setFrameShadow( QFrame::Plain );
00114               Line2->setLineWidth( 3 );
00115               Layout12->addWidget( Line2, 0, 3, Qt::AlignCenter );
00116               TopRight = new QRadioButton( RotationGroup, "TopRight" );
00117               TopRight->setText( "" );
00118               Layout12->addWidget( TopRight, 0, 4, Qt::AlignCenter );
00119        }
00120        Layout12a->addLayout(Layout12, 1, 1);
00121        QSpacerItem* spacerR = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00122        Layout12a->addItem( spacerR, 1, 2 );
00123        QSpacerItem* spacerB = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
00124        Layout12a->addItem( spacerB, 2, 1 );
00125        editLayout->addWidget( RotationGroup, 0, 0 );
00126        RotationGroup->setButton(origin);
00127        SizeGroup = new QGroupBox( tr("Size"), this, "SizeGroup" );
00128        SizeGroup->setColumnLayout(0, Qt::Vertical );
00129        SizeGroup->layout()->setSpacing( 5 );
00130        SizeGroup->layout()->setMargin( 10 );
00131        SizeGroupLayout = new QGridLayout( SizeGroup->layout() );
00132        SizeGroupLayout->setAlignment( Qt::AlignTop );
00133        questionLabel = new QLabel( tr("Width:"), SizeGroup, "questionLabel" );
00134        if (mode == 1)
00135               questionLabel->setText( tr("Length:"));
00136        SizeGroupLayout->addWidget( questionLabel, 0, 0 );
00137        spinWidth = new MSpinBox( 0, 1000, SizeGroup, decimals );
00138        spinWidth->setSuffix( m_suffix );
00139        spinWidth->setMinValue(0.1*m_unitRatio);
00140        spinWidth->setMaxValue(30000.0*m_unitRatio);
00141        spinWidth->setValue(defW * m_unitRatio);
00142        SizeGroupLayout->addWidget( spinWidth, 0, 1 );
00143        questionLabel2 = new QLabel( tr("Height:"), SizeGroup, "questionLabel2" );
00144        if (mode == 1)
00145               questionLabel2->setText( tr("Angle:"));
00146        SizeGroupLayout->addWidget( questionLabel2, 1, 0 );
00147        spinHeight = new MSpinBox( 0, 1000, SizeGroup, decimals );
00148        if (mode == 0)
00149        {
00150               spinHeight->setSuffix( m_suffix );
00151               spinHeight->setMinValue(0.1*m_unitRatio);
00152               spinHeight->setMaxValue(30000.0*m_unitRatio);
00153               spinHeight->setValue(defH * m_unitRatio);
00154        }
00155        else
00156        {
00157               spinHeight->setWrapping( true );
00158               spinHeight->setValues( 0, 359.99, 100, 0);
00159               spinHeight->setValue(defH * m_unitRatio);
00160        }
00161        SizeGroupLayout->addWidget( spinHeight, 1, 1 );
00162        if (mode == 0)
00163        {
00164               linkSize = new LinkButton( SizeGroup );
00165               linkSize->setToggleButton( true );
00166               linkSize->setAutoRaise( true );
00167               linkSize->setMaximumSize( QSize( 15, 32767 ) );
00168               SizeGroupLayout->addMultiCellWidget( linkSize, 0, 1, 2, 2 );
00169        }
00170        editLayout->addWidget( SizeGroup, 0, 1 );
00171 
00172        checkRemember = new QCheckBox(this, "checkRemember");
00173        checkRemember->setText( tr("Remember Values"));
00174        checkRemember->setChecked(remember);
00175        editLayout->addMultiCellWidget( checkRemember, 1, 1, 0, 1 );
00176 
00177        queryLayout->addLayout( editLayout );
00178        okCancelLayout = new QHBoxLayout;
00179        okCancelLayout->setSpacing( 5 );
00180        okCancelLayout->setMargin( 0 );
00181        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
00182        okButton->setDefault( true );
00183        okCancelLayout->addWidget( okButton );
00184        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
00185        okCancelLayout->addWidget( cancelButton );
00186        queryLayout->addLayout( okCancelLayout );
00187        setMaximumSize(sizeHint());
00188 
00189        // signals and slots connections
00190        connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00191        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00192        if (mode == 0)
00193        {
00194               connect(linkSize, SIGNAL(clicked()), this, SLOT(ToggleKette()));
00195               connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changeSizesW()));
00196               connect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changeSizesH()));
00197        }
00198 }
00199 
00200 void OneClick::ToggleKette()
00201 {
00202        disconnect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changeSizesW()));
00203        disconnect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changeSizesH()));
00204        if (linkSize->isOn())
00205               spinHeight->setValue(spinWidth->value());
00206        connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changeSizesW()));
00207        connect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changeSizesH()));
00208 }
00209 
00210 void OneClick::changeSizesH()
00211 {
00212        disconnect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changeSizesW()));
00213        disconnect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changeSizesH()));
00214        if (linkSize->isOn())
00215               spinWidth->setValue(spinHeight->value());
00216        connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changeSizesW()));
00217        connect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changeSizesH()));
00218 }
00219 
00220 void OneClick::changeSizesW()
00221 {
00222        disconnect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changeSizesW()));
00223        disconnect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changeSizesH()));
00224        if (linkSize->isOn())
00225               spinHeight->setValue(spinWidth->value());
00226        connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changeSizesW()));
00227        connect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changeSizesH()));
00228 }