Back to index

scribus-ng  1.3.4.dfsg+svn20071115
selfield.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 "selfield.h"
00010 #include "selfield.moc"
00011 #include <qstringlist.h>
00012 
00013 #include "commonstrings.h"
00014 
00015 extern QPixmap loadIcon(QString nam);
00016 
00017 SelectFields::SelectFields( QWidget* parent, QString Felder, QString Own, ScribusDoc *Doc, int Art )
00018               : QDialog( parent, "sef", true, 0 )
00019 {
00020        setCaption( tr( "Select Fields" ) );
00021        setIcon(loadIcon("AppIcon.png"));
00022        FTyp = Art;
00023        SelectFieldsLayout = new QVBoxLayout( this, 11, 6, "SelectFieldsLayout");
00024        Layout5 = new QHBoxLayout( 0, 0, 6, "Layout5");
00025        Layout1 = new QVBoxLayout( 0, 0, 6, "Layout1");
00026 
00027        Text1 = new QLabel( tr( "Available Fields" ), this, "Text1" );
00028        Layout1->addWidget( Text1 );
00029        AvailFields = new QListBox( this, "AvailFields" );
00030        AvailFields->setMinimumSize( QSize( 130, 180 ) );
00031        for (uint se = 0; se < Doc->Items->count(); ++se)
00032        {
00033               PageItem* item = Doc->Items->at(se);
00034               if (Art < 2)
00035               {
00036                      if ((item->isAnnotation()) && (item->annotation().Type() > 1))
00037                             AvailFields->insertItem(item->itemName());
00038               }
00039               else
00040               {
00041                      if ((item->isAnnotation()) && (item->annotation().Type() == Art) && (item->itemName() != Own))
00042                             AvailFields->insertItem(item->itemName());
00043               }
00044        }
00045        Layout1->addWidget( AvailFields );
00046        Layout5->addLayout( Layout1 );
00047 
00048        if (Art > 1)
00049        {
00050               Layout2 = new QVBoxLayout( 0, 0, 6, "Layout2");
00051               QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
00052               Layout2->addItem( spacer );
00053               ToSel = new QPushButton( tr( "&>>" ), this, "ToSel" );
00054               Layout2->addWidget( ToSel );
00055               FromSel = new QPushButton( tr( "&<<" ), this, "FromSel" );
00056               Layout2->addWidget( FromSel );
00057               QSpacerItem* spacer_2 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
00058               Layout2->addItem( spacer_2 );
00059               Layout5->addLayout( Layout2 );
00060               Layout3 = new QVBoxLayout( 0, 0, 6, "Layout3");
00061               Text2 = new QLabel( tr( "Selected Fields" ), this, "Text2" );
00062               Layout3->addWidget( Text2 );
00063               SelFields = new QListBox( this, "SelFields" );
00064               SelFields->setMinimumSize( QSize( 130, 180 ) );
00065               QStringList pfol;
00066               pfol = pfol.split(",", Felder);
00067               if (pfol.count() > 0)
00068               {
00069                      for (uint cfx = 0; cfx < pfol.count(); ++cfx)
00070                             SelFields->insertItem(pfol[cfx].stripWhiteSpace());
00071               }
00072               FromSel->setEnabled(false);
00073               ToSel->setEnabled(false);
00074               Layout3->addWidget( SelFields );
00075               Layout5->addLayout( Layout3 );
00076               connect(SelFields, SIGNAL(clicked(QListBoxItem*)), this, SLOT(SelEField(QListBoxItem*)));
00077               connect(ToSel, SIGNAL(clicked()), this, SLOT(PutToSel()));
00078               connect(FromSel, SIGNAL(clicked()), this, SLOT(RemoveSel()));
00079        }
00080        SelectFieldsLayout->addLayout( Layout5 );
00081        S_Fields = "";
00082        Layout4 = new QHBoxLayout( 0, 0, 6, "Layout4");
00083        QSpacerItem* spacer_3 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00084        Layout4->addItem( spacer_3 );
00085        OK = new QPushButton( CommonStrings::tr_OK, this, "OK" );
00086        OK->setDefault( true );
00087        Layout4->addWidget( OK );
00088        Cancel = new QPushButton( CommonStrings::tr_Cancel, this, "Cancel" );
00089        Layout4->addWidget( Cancel );
00090        QSpacerItem* spacer_4 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
00091        Layout4->addItem( spacer_4 );
00092        SelectFieldsLayout->addLayout( Layout4 );
00093        connect(OK, SIGNAL(clicked()), this, SLOT(SetRetVal()));
00094        connect(Cancel, SIGNAL(clicked()), this, SLOT(reject()));
00095        connect(AvailFields, SIGNAL(clicked(QListBoxItem*)), this, SLOT(SelAField(QListBoxItem*)));
00096 }
00097 
00098 void SelectFields::SetRetVal()
00099 {
00100        S_Fields = "";
00101        if (FTyp > 1)
00102        {
00103               if (SelFields->count() > 0)
00104                      S_Fields = SelFields->text(0);
00105               for (uint r = 1; r < SelFields->count(); ++r)
00106                      S_Fields += ", "+SelFields->text(r);
00107        }
00108        else
00109               S_Fields = AvailFields->currentText();
00110        accept();
00111 }
00112 
00113 void SelectFields::RemoveSel()
00114 {
00115        SelFields->removeItem(SelFields->currentItem());
00116        SelFields->clearSelection();
00117        if (SelFields->count() == 0)
00118               FromSel->setEnabled(false);
00119 }
00120 
00121 void SelectFields::PutToSel()
00122 {
00123        if (SelFields->count() != 0)
00124        {
00125               if (SelFields->findItem(AvailFields->currentText()) == NULL)
00126                      SelFields->insertItem(AvailFields->currentText());
00127        }
00128        else
00129               SelFields->insertItem(AvailFields->currentText());
00130 }
00131 
00132 void SelectFields::SelAField(QListBoxItem *c)
00133 {
00134        if ((c != NULL) && (FTyp > 1))
00135        {
00136               FromSel->setEnabled(false);
00137               ToSel->setEnabled(true);
00138               SelFields->clearSelection();
00139        }
00140 }
00141 
00142 void SelectFields::SelEField(QListBoxItem *c)
00143 {
00144        if (c != NULL)
00145        {
00146               FromSel->setEnabled(true);
00147               ToSel->setEnabled(false);
00148               AvailFields->clearSelection();
00149        }
00150 }