Back to index

scribus-ng  1.3.4.dfsg+svn20071115
buttonicon.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 
00008 #include "scfonts.h"
00009 #include "buttonicon.h"
00010 #include "buttonicon.moc"
00011 #include "scribusstructs.h"
00012 #include "pageitem.h"
00013 
00014 extern QPixmap loadIcon(QString nam);
00015 
00016 ButtonIcon::ButtonIcon(QWidget* parent, PageItem* ite)
00017               : QDialog( parent, "bu", true, 0 )
00018 {
00019        Item = ite;
00020        setCaption( tr( "Icon Placement" ) );
00021        setIcon(loadIcon("AppIcon.png"));
00022        ButtonIconLayout = new QVBoxLayout( this, 11, 6, "ButtonIconLayout");
00023        Layout1 = new QGridLayout( 0, 0, 6, "Layout6");
00024        TextLabel1_2 = new QLabel( this, "TextLabel1_2" );
00025        TextLabel1_2->setText( tr( "Layout:" ) );
00026        Layout1->addWidget( TextLabel1_2, 0, 0 );
00027        Place = new QComboBox( true, this, "Place" );
00028        QString tmp_pla[] = { tr("Caption only"), tr("Icon only"), tr("Caption below Icon"), tr("Caption above Icon"),
00029                              tr("Caption right to Icon"), tr("Caption left to Icon"), tr("Caption overlays Icon")};
00030        size_t array_pla = sizeof(tmp_pla) / sizeof(*tmp_pla);
00031        /* PFJ - 29/02/04 - Changed from uint to int and var name */
00032        for (uint prop = 0; prop < array_pla; ++prop)
00033               Place->insertItem(tmp_pla[prop]);
00034        Place->setEditable(false);
00035        Layout1->addWidget( Place, 0, 1 );
00036        TextLabel1 = new QLabel( this, "TextLabel1" );
00037        TextLabel1->setText( tr( "Scale:" ) );
00038        Layout1->addWidget( TextLabel1, 1, 0 );
00039        ScaleW = new QComboBox( true, this, "ScaleW" );
00040        /* PFJ - 29/02/04 - Changed to QString/size_t/for style. It saves a small
00041                                           of time during the setup */
00042        QString scalew[] = { tr("Always"), tr("When Icon is too small"),
00043                            tr("When Icon is too big"), tr("Never")};
00044        size_t scalewArray = sizeof(scalew) / sizeof(*scalew);
00045        for (uint prop = 0; prop < scalewArray; ++prop)
00046               ScaleW->insertItem(scalew[prop]);
00047        ScaleW->setEditable(false);
00048        Layout1->addWidget( ScaleW, 1, 1 );
00049        TextLabel2 = new QLabel( this, "TextLabel2" );
00050        TextLabel2->setText( tr( "Scale How:" ) );
00051        Layout1->addWidget( TextLabel2, 2, 0 );
00052        ScaleH = new QComboBox( true, this, "ScaleH" );
00053        ScaleH->insertItem( tr( "Proportional" ) );
00054        ScaleH->insertItem( tr( "Non Proportional" ) );
00055        ScaleH->setEditable(false);
00056        Layout1->addWidget( ScaleH, 2, 1 );
00057        ButtonIconLayout->addLayout( Layout1 );
00058        QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
00059        ButtonIconLayout->addItem( spacer );
00060        Layout5 = new QHBoxLayout( 0, 0, 6, "Layout5");
00061        QSpacerItem* spacer_2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00062        Layout5->addItem( spacer_2 );
00063        Layout3 = new QGridLayout( 0, 1, 1, 0, 6, "Layout3");
00064        GroupButton = new QGroupBox( this, "GroupButton" );
00065        GroupButton->setMinimumSize( QSize( 150, 150 ) );
00066        GroupButton->setMaximumSize( QSize( 150, 150 ) );
00067        GroupButton->setTitle( "" );
00068        TextLabel3 = new QLabel( GroupButton, "TextLabel3" );
00069        TextLabel3->setGeometry( QRect( 50, 50, 48, 48 ) );
00070        TextLabel3->setFrameShape( QLabel::Box );
00071        TextLabel3->setFrameShadow( QLabel::Raised );
00072        TextLabel3->setLineWidth( 1 );
00073        TextLabel3->setText( tr( "Icon" ) );
00074        Layout3->addWidget( GroupButton, 0, 0 );
00075        SliderX = new QSlider( this, "SliderX" );
00076        SliderX->setMaxValue( 1000 );
00077        SliderX->setValue( 500 );
00078        SliderX->setOrientation( QSlider::Horizontal );
00079        SliderX->setTickmarks( QSlider::Left );
00080        SliderX->setTickInterval( 100 );
00081        Layout3->addWidget( SliderX, 1, 0 );
00082        SliderY = new QSlider( this, "SliderY" );
00083        SliderY->setMaxValue( 1000 );
00084        SliderY->setValue( 500 );
00085        SliderY->setOrientation( QSlider::Vertical );
00086        SliderY->setTickmarks( QSlider::Left );
00087        SliderY->setTickInterval( 100 );
00088        Layout3->addWidget( SliderY, 0, 1 );
00089        Layout5->addLayout( Layout3 );
00090        QSpacerItem* spacer_3 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00091        Layout5->addItem( spacer_3 );
00092        ButtonIconLayout->addLayout( Layout5 );
00093        QSpacerItem* spacer_4 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
00094        ButtonIconLayout->addItem( spacer_4 );
00095        Layout4 = new QHBoxLayout( 0, 0, 6, "Layout4");
00096        OK = new QPushButton( this, "OK" );
00097        OK->setText( tr( "OK" ) );
00098        OK->setDefault( true );
00099        Layout4->addWidget( OK );
00100        Cancel = new QPushButton( this, "Cancel" );
00101        Cancel->setText( tr( "Cancel" ) );
00102        Layout4->addWidget( Cancel );
00103        Reset = new QPushButton( this, "Reset" );
00104        Reset->setText( tr( "Reset" ) );
00105        Layout4->addWidget( Reset );
00106        ButtonIconLayout->addLayout( Layout4 );
00107 
00108        SetAllVals();
00109 
00110        connect(ScaleW, SIGNAL(activated(int)), this, SLOT(SetScaleHow(int)));
00111        connect(SliderX, SIGNAL(valueChanged(int)), this, SLOT(MoveIconX(int)));
00112        connect(SliderY, SIGNAL(valueChanged(int)), this, SLOT(MoveIconY(int)));
00113        connect(Cancel, SIGNAL(clicked()), this, SLOT(reject()));
00114        connect(OK, SIGNAL(clicked()), this, SLOT(accept()));
00115        connect(Reset, SIGNAL(clicked()), this, SLOT(SetAllVals()));
00116 }
00117 
00118 void ButtonIcon::MoveIconY(int y)
00119 {
00120        TextLabel3->setGeometry(QRect(static_cast<int>(SliderX->value() / 1000.0 * 100),
00121                                      static_cast<int>(y / 1000.0 * 100), 48, 48));
00122        IcPlaceY = y / 1000.0;
00123 }
00124 
00125 void ButtonIcon::MoveIconX(int x)
00126 {
00127        TextLabel3->setGeometry(QRect(static_cast<int>(x / 1000.0 * 100),
00128                                      static_cast<int>(SliderY->value() / 1000.0 * 100), 48, 48));
00129        IcPlaceX = x / 1000.0;
00130 }
00131 
00132 void ButtonIcon::SetAllVals()
00133 {
00134        Place->setCurrentItem(Item->annotation().IPlace());
00135        ScaleW->setCurrentItem(Item->annotation().ScaleW());
00136        ScaleH->setCurrentItem(Item->imageXScale() != Item->imageYScale() ? 1 : 0);
00137        SetScaleHow(ScaleW->currentItem());
00138        SliderX->setValue(static_cast<int>(Item->imageXOffset() / (Item->width() - Item->pixm.width()) * 1000));
00139        SliderY->setValue(static_cast<int>(Item->imageYOffset() / (Item->height() - Item->pixm.height()) * 1000));
00140        TextLabel3->setGeometry(QRect(static_cast<int>(SliderX->value() / 1000.0 * 100),
00141                                      static_cast<int>(SliderY->value() / 1000.0 * 100), 48, 48));
00142 }
00143 
00144 void ButtonIcon::SetScaleHow(int s)
00145 {
00146        bool setter = (s == 3) ? true : false;
00147        GroupButton->setEnabled(setter);
00148        TextLabel3->setEnabled(setter);
00149        SliderX->setEnabled(setter);
00150        SliderY->setEnabled(setter);
00151        IcScaleH = s;
00152 }