Back to index

scribus-ng  1.3.4.dfsg+svn20071115
annota.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  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015  
00016 #include <qstringlist.h>
00017 
00018 #include "scfonts.h"
00019 #include "annota.h"
00020 #include "annota.moc"
00021 #include "customfdialog.h"
00022 #include "prefsmanager.h"
00023 #include "prefsfile.h"
00024 #include "commonstrings.h"
00025 #include "pageitem.h"
00026 #include "navigator.h"
00027 #include "scribusview.h"
00028 
00029 extern QPixmap loadIcon(QString nam);
00030 
00031 Annota::Annota(QWidget* parent, PageItem *it, int Seite, int b, int h, ScribusView* vie)
00032               : QDialog( parent, "AN", true, 0 )
00033 {
00034        setCaption( tr( "Annotation Properties" ) );
00035        setIcon(loadIcon("AppIcon.png"));
00036        item = it;
00037        Breite = b;
00038        Hoehe = h;
00039        OriBreite = b;
00040        OriHoehe = h;
00041        view = vie;
00042        MaxSeite = Seite;
00043        QStringList tl;
00044        if ((item->annotation().ActionType() == 2) || (item->annotation().ActionType() == 7))
00045        {
00046               QString tm = item->annotation().Action();
00047               tl = tl.split(" ", tm);
00048        }
00049        else
00050        {
00051               tl.append("0");
00052               tl.append("0");
00053        }
00054 
00055        AnnotLayout = new QVBoxLayout( this );
00056        AnnotLayout->setSpacing( 6 );
00057        AnnotLayout->setMargin( 11 );
00058 
00059        Layout1 = new QHBoxLayout;
00060        Layout1->setSpacing( 6 );
00061        Layout1->setMargin( 0 );
00062 
00063        ComboBox1 = new QComboBox( true, this, "ComboBox1" );
00064        /* PFJ - 28/02/04 - Changed to QString/size_t/for style */
00065        QString combo[] = { tr("Text"), tr("Link"), tr("External Link"),
00066                            tr("External Web-Link")};
00067        size_t comboArray = sizeof(combo)/sizeof(*combo);
00068        for (uint prop = 0; prop < comboArray; ++prop)
00069               ComboBox1->insertItem(combo[prop]);
00070        ComboBox1->setEditable(false);
00071        TextLabel1 = new QLabel( ComboBox1, tr("&Type:"), this, "TextLabel1" );
00072        Layout1->addWidget( TextLabel1 );
00073        Layout1->addWidget( ComboBox1 );
00074        AnnotLayout->addLayout( Layout1 );
00075        item->annotation().Type() < 2 ? ComboBox1->setCurrentItem(item->annotation().Type()):
00076        ComboBox1->setCurrentItem(item->annotation().Type()-10);
00077        if ((item->annotation().ActionType() == 7) || (item->annotation().ActionType() == 8))
00078               ComboBox1->setCurrentItem(item->annotation().ActionType() - 5);
00079        Fram = new QWidgetStack(this);
00080        AnnotLayout->addWidget( Fram );
00081 
00082        GroupBox1 = new QGroupBox( this, "GroupBox1" );
00083        GroupBox1->setTitle( tr( "Destination" ) );
00084        GroupBox1->setColumnLayout(0, Qt::Vertical );
00085        GroupBox1->layout()->setSpacing( 0 );
00086        GroupBox1->layout()->setMargin( 0 );
00087        GroupBox1Layout = new QGridLayout( GroupBox1->layout() );
00088        GroupBox1Layout->setAlignment( Qt::AlignTop );
00089        GroupBox1Layout->setSpacing( 6 );
00090        GroupBox1Layout->setMargin( 11 );
00091 
00092        Destfile = new QLineEdit(GroupBox1, "File");
00093        Destfile->setText(item->annotation().Extern());
00094        Destfile->setReadOnly(true);
00095        GroupBox1Layout->addMultiCellWidget( Destfile, 0, 0, 0, 1 );
00096        ChFile = new QPushButton(GroupBox1, "Change");
00097        ChFile->setText( tr("C&hange..."));
00098        GroupBox1Layout->addWidget( ChFile, 0, 2 );
00099        if ((item->annotation().ActionType() != 7) && (item->annotation().ActionType() != 8))
00100        {
00101               Destfile->hide();
00102               ChFile->hide();
00103        }
00104 
00105        SpinBox1 = new QSpinBox( GroupBox1, "SpinBox1" );
00106        SpinBox1->setMinValue(1);
00107        SpinBox1->setMaxValue(item->annotation().ActionType() == 7 ? 1000 : Seite);
00108        TextLabel3 = new QLabel( SpinBox1, tr("&Page:"), GroupBox1, "TextLabel3" );
00109        GroupBox1Layout->addWidget( TextLabel3, 1, 0 );
00110        GroupBox1Layout->addWidget( SpinBox1, 1, 1 );
00111        if ((!Destfile->text().isEmpty()) && (item->annotation().ActionType() == 7))
00112               Pg = new Navigator( GroupBox1, 100, item->annotation().Ziel()+1, view, item->annotation().Extern());
00113        else
00114        {
00115               if (static_cast<uint>(item->annotation().Ziel()) < view->Doc->Pages->count())
00116                      Pg = new Navigator( GroupBox1, 100, item->annotation().Ziel(), view);
00117               else
00118               {
00119                      item->annotation().setZiel(view->Doc->currentPageNumber());
00120                      Pg = new Navigator( GroupBox1, 100, item->annotation().Ziel(), view);
00121               }
00122        }
00123        SpinBox1->setValue(item->annotation().Ziel()+1);
00124        Pg->setMinimumSize(QSize(Pg->pmx.width(), Pg->pmx.height()));
00125        GroupBox1Layout->addMultiCellWidget(Pg, 1, 3, 2, 2);
00126 
00127        SpinBox2 = new QSpinBox( GroupBox1, "SpinBox2" );
00128        SpinBox2->setSuffix( tr( " pt" ) );
00129        SpinBox2->setMaxValue(Breite);
00130        SpinBox2->setValue(tl[0].toInt());
00131        TextLabel4 = new QLabel( SpinBox2, tr("&X-Pos"), GroupBox1, "TextLabel4" );
00132        GroupBox1Layout->addWidget( TextLabel4, 2, 0 );
00133        GroupBox1Layout->addWidget( SpinBox2, 2, 1 );
00134        SpinBox3 = new QSpinBox( GroupBox1, "SpinBox3" );
00135        SpinBox3->setMaxValue(Hoehe);
00136        SpinBox3->setSuffix( tr( " pt" ) );
00137        SpinBox3->setValue(Hoehe-tl[1].toInt());
00138        TextLabel5 = new QLabel( SpinBox3, tr("&Y-Pos:"), GroupBox1, "TextLabel5" );
00139        GroupBox1Layout->addWidget( TextLabel5, 3, 0 );
00140        GroupBox1Layout->addWidget( SpinBox3, 3, 1 );
00141        Fram->addWidget(GroupBox1, 1);
00142 
00143        Frame9 = new QFrame( this, "Frame7" );
00144        Frame9->setFrameShape( QFrame::NoFrame );
00145        Frame9->setFrameShadow( QFrame::Plain );
00146        Fram->addWidget(Frame9, 2);
00147 
00148        Layout1_2 = new QHBoxLayout;
00149        Layout1_2->setSpacing( 6 );
00150        Layout1_2->setMargin( 0 );
00151 
00152        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00153        Layout1_2->addItem( spacer );
00154        PushButton1 = new QPushButton( CommonStrings::tr_OK, this, "PushButton1" );
00155        PushButton1->setDefault( true );
00156        Layout1_2->addWidget( PushButton1 );
00157        PushButton2 = new QPushButton( CommonStrings::tr_Cancel, this, "PushButton2" );
00158        Layout1_2->addWidget( PushButton2 );
00159        AnnotLayout->addLayout( Layout1_2 );
00160 
00161        connect(PushButton1, SIGNAL(clicked()), this, SLOT(SetVals()));
00162        connect(PushButton2, SIGNAL(clicked()), this, SLOT(reject()));
00163        connect(ComboBox1, SIGNAL(activated(int)), this, SLOT(SetZiel(int)));
00164        connect(SpinBox1, SIGNAL(valueChanged(int)), this, SLOT(SetPg(int)));
00165        connect(Pg, SIGNAL(Coords(double, double)), this, SLOT(SetCo(double, double)));
00166        connect(SpinBox2, SIGNAL(valueChanged(int)), this, SLOT(SetCross()));
00167        connect(SpinBox3, SIGNAL(valueChanged(int)), this, SLOT(SetCross()));
00168        connect(ChFile, SIGNAL(clicked()), this, SLOT(GetFile()));
00169        SetZiel(item->annotation().Type());
00170        SetCross();
00171 }
00172 
00173 void Annota::SetCo(double x, double y)
00174 {
00175        SpinBox2->setValue(static_cast<int>(x*Breite));
00176        SpinBox3->setValue(static_cast<int>(y*Hoehe));
00177 }
00178 
00179 void Annota::SetPg(int v)
00180 {
00181        disconnect(SpinBox1, SIGNAL(valueChanged(int)), this, SLOT(SetPg(int)));
00182        if (ComboBox1->currentItem() == 2)
00183        {
00184               if (!Pg->SetSeite(v, 100, Destfile->text()))
00185               {
00186                      SpinBox1->setValue(1);
00187                      Pg->SetSeite(1, 100, Destfile->text());
00188               }
00189               Breite = Pg->Breite;
00190               Hoehe = Pg->Hoehe;
00191        }
00192        else
00193        {
00194               Pg->SetSeite(QMIN(v-1, MaxSeite-1), 100);
00195               SpinBox1->setValue(QMIN(v, MaxSeite));
00196               Breite = OriBreite;
00197               Hoehe = OriHoehe;
00198        }
00199        SpinBox2->setMaxValue(Breite);
00200        SpinBox3->setMaxValue(Hoehe);
00201        connect(SpinBox1, SIGNAL(valueChanged(int)), this, SLOT(SetPg(int)));
00202 }
00203 
00204 void Annota::SetCross()
00205 {
00206        int x,y;
00207        disconnect(Pg, SIGNAL(Coords(double, double)), this, SLOT(SetCo(double, double)));
00208        x = static_cast<int>(static_cast<double>(SpinBox2->value())/static_cast<double>(Breite)*Pg->pmx.width());
00209        y = static_cast<int>(static_cast<double>(SpinBox3->value())/static_cast<double>(Hoehe)*Pg->pmx.height());
00210        Pg->drawMark(x, y);
00211        connect(Pg, SIGNAL(Coords(double, double)), this, SLOT(SetCo(double, double)));
00212 }
00213 
00214 void Annota::SetVals()
00215 {
00216        QString tmp, tmp2;
00217        item->annotation().setZiel(SpinBox1->value()-1);
00218        item->annotation().setType(ComboBox1->currentItem()+10);
00219        switch (item->annotation().Type())
00220        {
00221        case 10:
00222               item->annotation().setActionType(0);
00223               break;
00224        case 11:
00225               item->annotation().setAction(tmp.setNum(SpinBox2->value())+" "+ tmp2.setNum(Hoehe-SpinBox3->value())+" 0");
00226               item->annotation().setExtern("");
00227               item->annotation().setActionType(2);
00228               break;
00229        case 12:
00230               item->annotation().setAction(tmp.setNum(SpinBox2->value())+" "+ tmp2.setNum(Hoehe-SpinBox3->value())+" 0");
00231               if (!Destfile->text().isEmpty())
00232               {
00233                      item->annotation().setExtern(Destfile->text());
00234                      item->annotation().setActionType(7);
00235               }
00236               item->annotation().setType(11);
00237               break;
00238        case 13:
00239               item->annotation().setAction("");
00240               if (!Destfile->text().isEmpty())
00241               {
00242                      item->annotation().setExtern(Destfile->text());
00243                      item->annotation().setActionType(8);
00244               }
00245               item->annotation().setType(11);
00246               break;
00247        }
00248        accept();
00249 }
00250 
00251 void Annota::SetZiel(int it)
00252 {
00253        disconnect(ComboBox1, SIGNAL(activated(int)), this, SLOT(SetZiel(int)));
00254        Pg->show();
00255        TextLabel3->show();
00256        TextLabel4->show();
00257        TextLabel5->show();
00258        SpinBox1->show();
00259        SpinBox2->show();
00260        SpinBox3->show();
00261        switch (it)
00262        {
00263        case 1:
00264               Fram->raiseWidget(1);
00265               Destfile->setText("");
00266               Destfile->hide();
00267               ChFile->hide();
00268               item->annotation().setActionType(2);
00269               SetPg(QMIN(SpinBox1->value(), MaxSeite));
00270               break;
00271        case 2:
00272               Fram->raiseWidget(1);
00273               Destfile->show();
00274               ChFile->show();
00275               Destfile->setReadOnly(true);
00276               if ((Destfile->text().isEmpty())  || (item->annotation().ActionType() == 8))
00277               {
00278                      Destfile->setText("");
00279                      GetFile();
00280               }
00281               if (Destfile->text().isEmpty())
00282               {
00283                      item->annotation().setActionType(2);
00284                      Destfile->setText("");
00285                      Destfile->hide();
00286                      ChFile->hide();
00287                      ComboBox1->setCurrentItem(1);
00288               }
00289               else
00290                      item->annotation().setActionType(7);
00291               SetPg(QMIN(SpinBox1->value(), MaxSeite));
00292               break;
00293        case 3:
00294               Fram->raiseWidget(1);
00295               Destfile->show();
00296               Destfile->setReadOnly(false);
00297               ChFile->hide();
00298               Pg->hide();
00299               TextLabel3->hide();
00300               TextLabel4->hide();
00301               TextLabel5->hide();
00302               SpinBox1->hide();
00303               SpinBox2->hide();
00304               SpinBox3->hide();
00305               item->annotation().setActionType(8);
00306               break;
00307        case 11:
00308               Fram->raiseWidget(1);
00309               if (item->annotation().ActionType() == 7)
00310               {
00311                      Destfile->show();
00312                      ChFile->show();
00313                      Destfile->setReadOnly(true);
00314               }
00315               if (item->annotation().ActionType() == 8)
00316               {
00317                      Destfile->show();
00318                      Destfile->setReadOnly(false);
00319                      ChFile->hide();
00320                      Pg->hide();
00321                      TextLabel3->hide();
00322                      TextLabel4->hide();
00323                      TextLabel5->hide();
00324                      SpinBox1->hide();
00325                      SpinBox2->hide();
00326                      SpinBox3->hide();
00327               }
00328               if (Pg->isVisible())
00329                      SetPg(QMIN(SpinBox1->value(), MaxSeite));
00330               break;
00331        default:
00332               Fram->raiseWidget(2);
00333               break;
00334        }
00335        connect(ComboBox1, SIGNAL(activated(int)), this, SLOT(SetZiel(int)));
00336 }
00337 
00338 void Annota::GetFile()
00339 {
00340        QString fn;
00341        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00342        QString wdir = dirs->get("annot_getfile", ".");
00343        CustomFDialog dia(this, wdir, tr("Open"), tr("PDF-Documents (*.pdf);;All Files (*)"));
00344        if (!Destfile->text().isEmpty())
00345               dia.setSelection(Destfile->text());
00346        if (dia.exec() == QDialog::Accepted)
00347        {
00348               fn = dia.selectedFile();
00349               if (!fn.isEmpty())
00350               {
00351                      dirs->set("annot_getfile", fn.left(fn.findRev("/")));
00352                      Destfile->setText(fn);
00353                      SpinBox1->setValue(1);
00354                      SpinBox1->setMaxValue(1000);
00355                      SetPg(1);
00356               }
00357        }
00358 }