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