"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "scribus-1.3.3.12/scribus/annota.cpp" of archive scribus-1.3.3.12.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2 For general Scribus (>=1.3.2) copyright and licensing information please refer
    3 to the COPYING file provided with the program. Following this notice may exist
    4 a copyright and/or license notice that predates the release of Scribus 1.3.2
    5 for which a new license (GPL+exception) is in place.
    6 */
    7 /***************************************************************************
    8  *                                                                         *
    9  *   This program is free software; you can redistribute it and/or modify  *
   10  *   it under the terms of the GNU General Public License as published by  *
   11  *   the Free Software Foundation; either version 2 of the License, or     *
   12  *   (at your option) any later version.                                   *
   13  *                                                                         *
   14  ***************************************************************************/
   15 
   16 #include <qstringlist.h>
   17 
   18 #include "scfonts.h"
   19 #include "annota.h"
   20 #include "annota.moc"
   21 #include "customfdialog.h"
   22 #include "prefsmanager.h"
   23 #include "prefsfile.h"
   24 #include "commonstrings.h"
   25 #include "pageitem.h"
   26 #include "navigator.h"
   27 #include "scribusview.h"
   28 
   29 extern QPixmap loadIcon(QString nam);
   30 
   31 Annota::Annota(QWidget* parent, PageItem *it, int Seite, int b, int h, ScribusView* vie)
   32 		: QDialog( parent, "AN", true, 0 )
   33 {
   34 	setCaption( tr( "Annotation Properties" ) );
   35 	setIcon(loadIcon("AppIcon.png"));
   36 	item = it;
   37 	Breite = b;
   38 	Hoehe = h;
   39 	OriBreite = b;
   40 	OriHoehe = h;
   41 	view = vie;
   42 	MaxSeite = Seite;
   43 	QStringList tl;
   44 	if ((item->annotation().ActionType() == 2) || (item->annotation().ActionType() == 7))
   45 	{
   46 		QString tm = item->annotation().Action();
   47 		tl = tl.split(" ", tm);
   48 	}
   49 	else
   50 	{
   51 		tl.append("0");
   52 		tl.append("0");
   53 	}
   54 
   55 	AnnotLayout = new QVBoxLayout( this );
   56 	AnnotLayout->setSpacing( 6 );
   57 	AnnotLayout->setMargin( 11 );
   58 
   59 	Layout1 = new QHBoxLayout;
   60 	Layout1->setSpacing( 6 );
   61 	Layout1->setMargin( 0 );
   62 
   63 	ComboBox1 = new QComboBox( true, this, "ComboBox1" );
   64 	/* PFJ - 28/02/04 - Changed to QString/size_t/for style */
   65 	QString combo[] = { tr("Text"), tr("Link"), tr("External Link"),
   66 	                    tr("External Web-Link")};
   67 	size_t comboArray = sizeof(combo)/sizeof(*combo);
   68 	for (uint prop = 0; prop < comboArray; ++prop)
   69 		ComboBox1->insertItem(combo[prop]);
   70 	ComboBox1->setEditable(false);
   71 	TextLabel1 = new QLabel( ComboBox1, tr("&Type:"), this, "TextLabel1" );
   72 	Layout1->addWidget( TextLabel1 );
   73 	Layout1->addWidget( ComboBox1 );
   74 	AnnotLayout->addLayout( Layout1 );
   75 	item->annotation().Type() < 2 ? ComboBox1->setCurrentItem(item->annotation().Type()):
   76 	ComboBox1->setCurrentItem(item->annotation().Type()-10);
   77 	if ((item->annotation().ActionType() == 7) || (item->annotation().ActionType() == 8))
   78 		ComboBox1->setCurrentItem(item->annotation().ActionType() - 5);
   79 	Fram = new QWidgetStack(this);
   80 	AnnotLayout->addWidget( Fram );
   81 
   82 	GroupBox1 = new QGroupBox( this, "GroupBox1" );
   83 	GroupBox1->setTitle( tr( "Destination" ) );
   84 	GroupBox1->setColumnLayout(0, Qt::Vertical );
   85 	GroupBox1->layout()->setSpacing( 0 );
   86 	GroupBox1->layout()->setMargin( 0 );
   87 	GroupBox1Layout = new QGridLayout( GroupBox1->layout() );
   88 	GroupBox1Layout->setAlignment( Qt::AlignTop );
   89 	GroupBox1Layout->setSpacing( 6 );
   90 	GroupBox1Layout->setMargin( 11 );
   91 
   92 	Destfile = new QLineEdit(GroupBox1, "File");
   93 	Destfile->setText(item->annotation().Extern());
   94 	Destfile->setReadOnly(true);
   95 	GroupBox1Layout->addMultiCellWidget( Destfile, 0, 0, 0, 1 );
   96 	ChFile = new QPushButton(GroupBox1, "Change");
   97 	ChFile->setText( tr("C&hange..."));
   98 	GroupBox1Layout->addWidget( ChFile, 0, 2 );
   99 	if ((item->annotation().ActionType() != 7) && (item->annotation().ActionType() != 8))
  100 	{
  101 		Destfile->hide();
  102 		ChFile->hide();
  103 	}
  104 
  105 	SpinBox1 = new QSpinBox( GroupBox1, "SpinBox1" );
  106 	SpinBox1->setMinValue(1);
  107 	SpinBox1->setMaxValue(item->annotation().ActionType() == 7 ? 1000 : Seite);
  108 	SpinBox1->setValue(item->annotation().Ziel()+1);
  109 	TextLabel3 = new QLabel( SpinBox1, tr("&Page:"), GroupBox1, "TextLabel3" );
  110 	GroupBox1Layout->addWidget( TextLabel3, 1, 0 );
  111 	GroupBox1Layout->addWidget( SpinBox1, 1, 1 );
  112 	if ((!Destfile->text().isEmpty()) && (item->annotation().ActionType() == 7))
  113 		Pg = new Navigator( GroupBox1, 100, item->annotation().Ziel()+1, view, item->annotation().Extern());
  114 	else
  115 	{
  116 		if (static_cast<uint>(item->annotation().Ziel()) < view->Doc->Pages->count())
  117 			Pg = new Navigator( GroupBox1, 100, item->annotation().Ziel(), view);
  118 		else
  119 		{
  120 			item->annotation().setZiel(view->Doc->currentPageNumber());
  121 			Pg = new Navigator( GroupBox1, 100, item->annotation().Ziel(), view);
  122 		}
  123 	}
  124 	Pg->setMinimumSize(QSize(Pg->pmx.width(), Pg->pmx.height()));
  125 	GroupBox1Layout->addMultiCellWidget(Pg, 1, 3, 2, 2);
  126 
  127 	SpinBox2 = new QSpinBox( GroupBox1, "SpinBox2" );
  128 	SpinBox2->setSuffix( tr( " pt" ) );
  129 	SpinBox2->setMaxValue(Breite);
  130 	SpinBox2->setValue(tl[0].toInt());
  131 	TextLabel4 = new QLabel( SpinBox2, tr("&X-Pos"), GroupBox1, "TextLabel4" );
  132 	GroupBox1Layout->addWidget( TextLabel4, 2, 0 );
  133 	GroupBox1Layout->addWidget( SpinBox2, 2, 1 );
  134 	SpinBox3 = new QSpinBox( GroupBox1, "SpinBox3" );
  135 	SpinBox3->setMaxValue(Hoehe);
  136 	SpinBox3->setSuffix( tr( " pt" ) );
  137 	SpinBox3->setValue(Hoehe-tl[1].toInt());
  138 	TextLabel5 = new QLabel( SpinBox3, tr("&Y-Pos:"), GroupBox1, "TextLabel5" );
  139 	GroupBox1Layout->addWidget( TextLabel5, 3, 0 );
  140 	GroupBox1Layout->addWidget( SpinBox3, 3, 1 );
  141 	Fram->addWidget(GroupBox1, 1);
  142 
  143 	Frame9 = new QFrame( this, "Frame7" );
  144 	Frame9->setFrameShape( QFrame::NoFrame );
  145 	Frame9->setFrameShadow( QFrame::Plain );
  146 	Fram->addWidget(Frame9, 2);
  147 
  148 	Layout1_2 = new QHBoxLayout;
  149 	Layout1_2->setSpacing( 6 );
  150 	Layout1_2->setMargin( 0 );
  151 
  152 	QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
  153 	Layout1_2->addItem( spacer );
  154 	PushButton1 = new QPushButton( CommonStrings::tr_OK, this, "PushButton1" );
  155 	PushButton1->setDefault( true );
  156 	Layout1_2->addWidget( PushButton1 );
  157 	PushButton2 = new QPushButton( CommonStrings::tr_Cancel, this, "PushButton2" );
  158 	Layout1_2->addWidget( PushButton2 );
  159 	AnnotLayout->addLayout( Layout1_2 );
  160 
  161 	connect(PushButton1, SIGNAL(clicked()), this, SLOT(SetVals()));
  162 	connect(PushButton2, SIGNAL(clicked()), this, SLOT(reject()));
  163 	connect(ComboBox1, SIGNAL(activated(int)), this, SLOT(SetZiel(int)));
  164 	connect(SpinBox1, SIGNAL(valueChanged(int)), this, SLOT(SetPg(int)));
  165 	connect(Pg, SIGNAL(Coords(double, double)), this, SLOT(SetCo(double, double)));
  166 	connect(SpinBox2, SIGNAL(valueChanged(int)), this, SLOT(SetCross()));
  167 	connect(SpinBox3, SIGNAL(valueChanged(int)), this, SLOT(SetCross()));
  168 	connect(ChFile, SIGNAL(clicked()), this, SLOT(GetFile()));
  169 	SetZiel(item->annotation().Type());
  170 	SetCross();
  171 }
  172 
  173 void Annota::SetCo(double x, double y)
  174 {
  175 	SpinBox2->setValue(static_cast<int>(x*Breite));
  176 	SpinBox3->setValue(static_cast<int>(y*Hoehe));
  177 }
  178 
  179 void Annota::SetPg(int v)
  180 {
  181 	disconnect(SpinBox1, SIGNAL(valueChanged(int)), this, SLOT(SetPg(int)));
  182 	if (ComboBox1->currentItem() == 2)
  183 	{
  184 		if (!Pg->SetSeite(v, 100, Destfile->text()))
  185 		{
  186 			SpinBox1->setValue(1);
  187 			Pg->SetSeite(1, 100, Destfile->text());
  188 		}
  189 		Breite = Pg->Breite;
  190 		Hoehe = Pg->Hoehe;
  191 	}
  192 	else
  193 	{
  194 		Pg->SetSeite(QMIN(v-1, MaxSeite-1), 100);
  195 		SpinBox1->setValue(QMIN(v, MaxSeite));
  196 		Breite = OriBreite;
  197 		Hoehe = OriHoehe;
  198 	}
  199 	SpinBox2->setMaxValue(Breite);
  200 	SpinBox3->setMaxValue(Hoehe);
  201 	connect(SpinBox1, SIGNAL(valueChanged(int)), this, SLOT(SetPg(int)));
  202 }
  203 
  204 void Annota::SetCross()
  205 {
  206 	int x,y;
  207 	disconnect(Pg, SIGNAL(Coords(double, double)), this, SLOT(SetCo(double, double)));
  208 	x = static_cast<int>(static_cast<double>(SpinBox2->value())/static_cast<double>(Breite)*Pg->pmx.width());
  209 	y = static_cast<int>(static_cast<double>(SpinBox3->value())/static_cast<double>(Hoehe)*Pg->pmx.height());
  210 	Pg->drawMark(x, y);
  211 	connect(Pg, SIGNAL(Coords(double, double)), this, SLOT(SetCo(double, double)));
  212 }
  213 
  214 void Annota::SetVals()
  215 {
  216 	QString tmp, tmp2;
  217 	item->annotation().setZiel(SpinBox1->value()-1);
  218 	item->annotation().setType(ComboBox1->currentItem()+10);
  219 	switch (item->annotation().Type())
  220 	{
  221 	case 10:
  222 		item->annotation().setActionType(0);
  223 		break;
  224 	case 11:
  225 		item->annotation().setAction(tmp.setNum(SpinBox2->value())+" "+ tmp2.setNum(Hoehe-SpinBox3->value())+" 0");
  226 		item->annotation().setExtern("");
  227 		item->annotation().setActionType(2);
  228 		break;
  229 	case 12:
  230 		item->annotation().setAction(tmp.setNum(SpinBox2->value())+" "+ tmp2.setNum(Hoehe-SpinBox3->value())+" 0");
  231 		if (!Destfile->text().isEmpty())
  232 		{
  233 			item->annotation().setExtern(Destfile->text());
  234 			item->annotation().setActionType(7);
  235 		}
  236 		item->annotation().setType(11);
  237 		break;
  238 	case 13:
  239 		item->annotation().setAction("");
  240 		if (!Destfile->text().isEmpty())
  241 		{
  242 			item->annotation().setExtern(Destfile->text());
  243 			item->annotation().setActionType(8);
  244 		}
  245 		item->annotation().setType(11);
  246 		break;
  247 	}
  248 	accept();
  249 }
  250 
  251 void Annota::SetZiel(int it)
  252 {
  253 	disconnect(ComboBox1, SIGNAL(activated(int)), this, SLOT(SetZiel(int)));
  254 	Pg->show();
  255 	TextLabel3->show();
  256 	TextLabel4->show();
  257 	TextLabel5->show();
  258 	SpinBox1->show();
  259 	SpinBox2->show();
  260 	SpinBox3->show();
  261 	switch (it)
  262 	{
  263 	case 1:
  264 		Fram->raiseWidget(1);
  265 		Destfile->setText("");
  266 		Destfile->hide();
  267 		ChFile->hide();
  268 		item->annotation().setActionType(2);
  269 		SetPg(QMIN(SpinBox1->value(), MaxSeite));
  270 		break;
  271 	case 2:
  272 		Fram->raiseWidget(1);
  273 		Destfile->show();
  274 		ChFile->show();
  275 		Destfile->setReadOnly(true);
  276 		if ((Destfile->text().isEmpty())  || (item->annotation().ActionType() == 8))
  277 		{
  278 			Destfile->setText("");
  279 			GetFile();
  280 		}
  281 		if (Destfile->text().isEmpty())
  282 		{
  283 			item->annotation().setActionType(2);
  284 			Destfile->setText("");
  285 			Destfile->hide();
  286 			ChFile->hide();
  287 			ComboBox1->setCurrentItem(1);
  288 		}
  289 		else
  290 			item->annotation().setActionType(7);
  291 		SetPg(QMIN(SpinBox1->value(), MaxSeite));
  292 		break;
  293 	case 3:
  294 		Fram->raiseWidget(1);
  295 		Destfile->show();
  296 		Destfile->setReadOnly(false);
  297 		ChFile->hide();
  298 		Pg->hide();
  299 		TextLabel3->hide();
  300 		TextLabel4->hide();
  301 		TextLabel5->hide();
  302 		SpinBox1->hide();
  303 		SpinBox2->hide();
  304 		SpinBox3->hide();
  305 		item->annotation().setActionType(8);
  306 		break;
  307 	case 11:
  308 		Fram->raiseWidget(1);
  309 		if (item->annotation().ActionType() == 7)
  310 		{
  311 			Destfile->show();
  312 			ChFile->show();
  313 			Destfile->setReadOnly(true);
  314 		}
  315 		if (item->annotation().ActionType() == 8)
  316 		{
  317 			Destfile->show();
  318 			Destfile->setReadOnly(false);
  319 			ChFile->hide();
  320 			Pg->hide();
  321 			TextLabel3->hide();
  322 			TextLabel4->hide();
  323 			TextLabel5->hide();
  324 			SpinBox1->hide();
  325 			SpinBox2->hide();
  326 			SpinBox3->hide();
  327 		}
  328 		if (Pg->isVisible())
  329 			SetPg(QMIN(SpinBox1->value(), MaxSeite));
  330 		break;
  331 	default:
  332 		Fram->raiseWidget(2);
  333 		break;
  334 	}
  335 	connect(ComboBox1, SIGNAL(activated(int)), this, SLOT(SetZiel(int)));
  336 }
  337 
  338 void Annota::GetFile()
  339 {
  340 	QString fn;
  341 	PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
  342 	QString wdir = dirs->get("annot_getfile", ".");
  343 	CustomFDialog dia(this, wdir, tr("Open"), tr("PDF-Documents (*.pdf);;All Files (*)"));
  344 	if (!Destfile->text().isEmpty())
  345 		dia.setSelection(Destfile->text());
  346 	if (dia.exec() == QDialog::Accepted)
  347 	{
  348 		fn = dia.selectedFile();
  349 		if (!fn.isEmpty())
  350 		{
  351 			dirs->set("annot_getfile", fn.left(fn.findRev("/")));
  352 			Destfile->setText(fn);
  353 			SpinBox1->setValue(1);
  354 			SpinBox1->setMaxValue(1000);
  355 			SetPg(1);
  356 		}
  357 	}
  358 }