Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

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