Rev 18499 | Rev 18590 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 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 | */ |
||
3 | paul | 7 | /*************************************************************************** |
8 | scribusview.cpp - description |
||
9 | ------------------- |
||
10 | begin : Fre Apr 6 21:47:55 CEST 2001 |
||
11 | copyright : (C) 2001 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
13 | ***************************************************************************/ |
||
14 | |||
15 | /*************************************************************************** |
||
16 | * * |
||
17 | * This program is free software; you can redistribute it and/or modify * |
||
18 | * it under the terms of the GNU General Public License as published by * |
||
19 | * the Free Software Foundation; either version 2 of the License, or * |
||
20 | * (at your option) any later version. * |
||
21 | * * |
||
22 | ***************************************************************************/ |
||
23 | |||
24 | #include "scribusview.h" |
||
128 | Franz | 25 | |
2688 | craig | 26 | #include "scconfig.h" |
17796 | fschmid | 27 | #include "sclimits.h" |
128 | Franz | 28 | |
10220 | cbradney | 29 | #include <QColor> |
16673 | craig | 30 | #include <QDebug> |
10859 | cbradney | 31 | #include <QDrag> |
32 | #include <QDragEnterEvent> |
||
33 | #include <QDragLeaveEvent> |
||
34 | #include <QDragMoveEvent> |
||
35 | #include <QDropEvent> |
||
36 | #include <QEvent> |
||
37 | #include <QFile> |
||
38 | #include <QFileInfo> |
||
10220 | cbradney | 39 | #include <QFont> |
40 | #include <QFontMetrics> |
||
10859 | cbradney | 41 | #include <QImage> |
42 | #include <QImageReader> |
||
43 | #include <QLabel> |
||
44 | #include <QList> |
||
45 | #include <QMenu> |
||
17941 | jghali | 46 | #include <QMessageBox> |
10859 | cbradney | 47 | #include <QMimeData> |
48 | #include <QMouseEvent> |
||
49 | #include <QPaintEvent> |
||
10220 | cbradney | 50 | #include <QPixmap> |
10284 | fschmid | 51 | #include <QPolygon> |
10859 | cbradney | 52 | #include <QStack> |
10220 | cbradney | 53 | #include <QStringList> |
8501 | cbradney | 54 | #include <QWheelEvent> |
9514 | fschmid | 55 | #include <QWidgetAction> |
18438 | craig | 56 | #include <QStyleOptionRubberBand> |
10859 | cbradney | 57 | |
456 | fschmid | 58 | #include <cstdio> |
59 | #include <cstdlib> |
||
2702 | craig | 60 | |
61 | #ifdef HAVE_UNISTD_H |
||
456 | fschmid | 62 | #include <unistd.h> |
2702 | craig | 63 | #endif |
64 | |||
10281 | jghali | 65 | #include <QUrl> |
10220 | cbradney | 66 | #include <QDir> |
67 | #include <QSizeGrip> |
||
18454 | craig | 68 | |
181 | Franz | 69 | #include "scribus.h" |
10121 | cbradney | 70 | |
10532 | avox | 71 | #include "canvas.h" |
10701 | avox | 72 | #include "canvasgesture.h" |
10532 | avox | 73 | #include "canvasmode.h" |
12971 | jghali | 74 | #include "canvasmode_objimport.h" |
17735 | craig | 75 | #include "canvasmode_imageimport.h" |
10212 | cbradney | 76 | #include "actionmanager.h" |
77 | #include "commonstrings.h" |
||
78 | #include "filewatcher.h" |
||
79 | #include "hyphenator.h" |
||
17519 | craig | 80 | #include "pageitem.h" |
17130 | fschmid | 81 | #include "pageitem_group.h" |
3625 | avox | 82 | #include "pageitem_imageframe.h" |
83 | #include "pageitem_line.h" |
||
84 | #include "pageitem_pathtext.h" |
||
85 | #include "pageitem_polygon.h" |
||
86 | #include "pageitem_polyline.h" |
||
16856 | craig | 87 | #include "pageitem_table.h" |
3625 | avox | 88 | #include "pageitem_textframe.h" |
10228 | avox | 89 | #include "pageitem_latexframe.h" |
7284 | fschmid | 90 | #include "prefscontext.h" |
91 | #include "prefsfile.h" |
||
10212 | cbradney | 92 | #include "prefsmanager.h" |
13466 | cbradney | 93 | #include "scclocale.h" |
12841 | jghali | 94 | #include "scmimedata.h" |
16736 | jghali | 95 | #include "scpage.h" |
10601 | mrdocs | 96 | #include "scpainter.h" |
10212 | cbradney | 97 | #include "scpaths.h" |
13516 | jghali | 98 | #include "scribuscore.h" |
13950 | fschmid | 99 | #include "scribuswin.h" |
10212 | cbradney | 100 | #include "scribusXml.h" |
101 | #include "selection.h" |
||
18438 | craig | 102 | #include "selectionrubberband.h" |
10212 | cbradney | 103 | #include "serializer.h" |
16546 | jghali | 104 | #include "ui/adjustcmsdialog.h" |
105 | #include "ui/extimageprops.h" |
||
106 | #include "ui/guidemanager.h" |
||
107 | #include "ui/hruler.h" |
||
108 | #include "ui/insertTable.h" |
||
109 | #include "ui/oneclick.h" |
||
110 | #include "ui/pageitemattributes.h" |
||
111 | #include "ui/pageselector.h" |
||
112 | #include "ui/propertiespalette.h" |
||
113 | #include "ui/propertiespalette_image.h" |
||
114 | #include "ui/propertiespalette_line.h" |
||
115 | #include "ui/propertiespalette_text.h" |
||
116 | #include "ui/rulermover.h" |
||
117 | #include "ui/scrapbookpalette.h" |
||
13576 | cbradney | 118 | #include "ui/storyeditor.h" |
15060 | fschmid | 119 | #include "ui/symbolpalette.h" |
16546 | jghali | 120 | #include "ui/vruler.h" |
10212 | cbradney | 121 | #include "undomanager.h" |
122 | #include "units.h" |
||
123 | #include "util.h" |
||
124 | #include "util_color.h" |
||
125 | #include "util_formats.h" |
||
10200 | cbradney | 126 | #include "util_icon.h" |
10203 | cbradney | 127 | #include "util_math.h" |
10878 | fschmid | 128 | #include "loadsaveplugin.h" |
129 | #include "fileloader.h" |
||
130 | #include "plugins/formatidlist.h" |
||
2495 | cbradney | 131 | |
504 | cbradney | 132 | using namespace std; |
133 | |||
5781 | cbradney | 134 | ScribusView::ScribusView(QWidget* win, ScribusMainWindow* mw, ScribusDoc *doc) : |
10532 | avox | 135 | QScrollArea(win), |
3981 | craig | 136 | Doc(doc), |
10532 | avox | 137 | m_canvas(new Canvas(doc, this)), |
3981 | craig | 138 | Prefs(&(PrefsManager::instance()->appPrefs)), |
3982 | craig | 139 | undoManager(UndoManager::instance()), |
11814 | fschmid | 140 | m_ScMW(mw), |
3982 | craig | 141 | OldScale(0), |
7575 | cbradney | 142 | dragX(0), dragY(0), dragW(0), dragH(0), |
10560 | avox | 143 | oldW(-1), // oldCp(-1), |
3982 | craig | 144 | RotMode(0), |
145 | DrHY(-1), DrVX(-1), |
||
146 | HaveSelRect(false), |
||
147 | DraggedGroup(false), |
||
148 | DraggedGroupFirst(false), |
||
149 | MidButt(false), |
||
150 | updateOn(true), |
||
151 | FirstPoly(true), |
||
152 | Magnify(false), |
||
153 | RCenter(-1,-1), |
||
154 | Ready(false), |
||
155 | oldX(0), oldY(0), |
||
11490 | avox | 156 | m_groupTransactions(0), |
11576 | avox | 157 | m_groupTransaction(NULL), |
3982 | craig | 158 | _isGlobalMode(true), |
17533 | fschmid | 159 | linkAfterDraw(false), |
17735 | craig | 160 | ImageAfterDraw(false), |
17533 | fschmid | 161 | m_vhRulerHW(17) |
3 | paul | 162 | { |
10585 | fschmid | 163 | setObjectName("s"); |
15139 | cbradney | 164 | QPalette p=palette(); |
165 | p.setBrush(QPalette::Window, PrefsManager::instance()->appPrefs.displayPrefs.scratchColor); |
||
166 | setPalette(p); |
||
10575 | cbradney | 167 | setAttribute(Qt::WA_StaticContents); |
16546 | jghali | 168 | setAttribute(Qt::WA_InputMethodEnabled, true); |
10532 | avox | 169 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
170 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
||
171 | setViewportMargins(m_vhRulerHW, m_vhRulerHW, 0, 0); |
||
172 | setWidgetResizable(false); |
||
173 | m_canvasMode = CanvasMode::createForAppMode(this, Doc->appMode); |
||
174 | setWidget(m_canvas); |
||
175 | //already done by QScrollArea: widget()->installEventFilter(this); |
||
10550 | avox | 176 | installEventFilter(this); // FIXME:av |
10585 | fschmid | 177 | // viewport()->setBackgroundMode(Qt::PaletteBackground); |
11158 | avox | 178 | setFocusPolicy(Qt::ClickFocus); |
3 | paul | 179 | QFont fo = QFont(font()); |
13516 | jghali | 180 | // #8058: Better not use too small font size on Windows |
181 | // in case ClearType is not enabled |
||
182 | int posi = fo.pointSize() - (ScCore->isWinGUI() ? 1 : 2); |
||
2887 | fschmid | 183 | fo.setPointSize(posi); |
10575 | cbradney | 184 | unitSwitcher = new QComboBox( this ); |
8573 | jghali | 185 | unitSwitcher->setFocusPolicy(Qt::NoFocus); |
2887 | fschmid | 186 | unitSwitcher->setFont(fo); |
8700 | fschmid | 187 | int maxUindex = unitGetMaxIndex() - 2; |
188 | for (int i = 0; i <= maxUindex; ++i) |
||
10585 | fschmid | 189 | unitSwitcher->addItem(unitGetStrFromIndex(i)); |
13075 | subik | 190 | previewQualitySwitcher = new QComboBox( this ); |
191 | previewQualitySwitcher->setFocusPolicy(Qt::NoFocus); |
||
192 | previewQualitySwitcher->setFont(fo); |
||
193 | previewQualitySwitcher->addItem(tr("High")); |
||
194 | previewQualitySwitcher->addItem(tr("Normal")); |
||
195 | previewQualitySwitcher->addItem(tr("Low")); |
||
196 | // setCurrentComboItem(previewQualitySwitcher, tr("Normal")); |
||
13996 | cbradney | 197 | previewQualitySwitcher->setCurrentIndex(Prefs->itemToolPrefs.imageLowResType); |
13075 | subik | 198 | |
14730 | fschmid | 199 | zoomSpinBox = new ScrSpinBox( 1, 3200, this, 6 ); |
7884 | fschmid | 200 | zoomSpinBox->setTabAdvance(false); |
3309 | cbradney | 201 | zoomSpinBox->setFont(fo); |
202 | zoomSpinBox->setValue( 100 ); |
||
10500 | cbradney | 203 | zoomSpinBox->setSingleStep(10); |
8573 | jghali | 204 | zoomSpinBox->setFocusPolicy(Qt::ClickFocus); |
3309 | cbradney | 205 | zoomSpinBox->setSuffix( tr( " %" ) ); |
3053 | avox | 206 | #if OPTION_USE_QTOOLBUTTON |
207 | zoomOutToolbarButton = new QToolButton(this); |
||
3274 | fschmid | 208 | zoomDefaultToolbarButton = new QToolButton(this); |
3053 | avox | 209 | zoomInToolbarButton = new QToolButton(this); |
6726 | fschmid | 210 | cmsToolbarButton = new QToolButton(this); |
6549 | fschmid | 211 | previewToolbarButton = new QToolButton(this); |
3274 | fschmid | 212 | zoomDefaultToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON); |
3053 | avox | 213 | zoomOutToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON); |
214 | zoomInToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON); |
||
15839 | fschmid | 215 | zoomInToolbarButton->setDefaultAction(m_ScMW->scrActions["toolsZoomIn"]); |
216 | zoomOutToolbarButton->setDefaultAction(m_ScMW->scrActions["toolsZoomOut"]); |
||
6726 | fschmid | 217 | cmsToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON); |
10575 | cbradney | 218 | cmsToolbarButton->setCheckable(true); |
8501 | cbradney | 219 | QIcon ic2; |
8700 | fschmid | 220 | ic2.addPixmap(loadIcon("cmsOff.png"), QIcon::Normal, QIcon::Off); |
221 | ic2.addPixmap(loadIcon("cmsOn.png"), QIcon::Normal, QIcon::On); |
||
222 | cmsToolbarButton->setIcon(ic2); |
||
6549 | fschmid | 223 | previewToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON); |
10575 | cbradney | 224 | previewToolbarButton->setCheckable(true); |
8501 | cbradney | 225 | QIcon ic; |
8700 | fschmid | 226 | ic.addPixmap(loadIcon("previewOff.png"), QIcon::Normal, QIcon::Off); |
227 | ic.addPixmap(loadIcon("previewOn.png"), QIcon::Normal, QIcon::On); |
||
228 | previewToolbarButton->setIcon(ic); |
||
17915 | fschmid | 229 | editOnPreviewToolbarButton = new QToolButton(this); |
230 | editOnPreviewToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON); |
||
231 | editOnPreviewToolbarButton->setCheckable(true); |
||
232 | QIcon ic3; |
||
17931 | fschmid | 233 | ic3.addPixmap(loadIcon("16/editdoc.png"), QIcon::Normal, QIcon::Off); |
234 | ic3.addPixmap(loadIcon("16/editdoc.png"), QIcon::Normal, QIcon::On); |
||
17915 | fschmid | 235 | editOnPreviewToolbarButton->setIcon(ic3); |
3053 | avox | 236 | #else |
3274 | fschmid | 237 | zoomDefaultToolbarButton = new QPushButton(this); |
8501 | cbradney | 238 | zoomDefaultToolbarButton->setFocusPolicy(Qt::NoFocus); |
3274 | fschmid | 239 | zoomDefaultToolbarButton->setDefault( false ); |
240 | zoomDefaultToolbarButton->setAutoDefault( false ); |
||
241 | zoomDefaultToolbarButton->setFlat(OPTION_FLAT_BUTTON); |
||
1822 | cbradney | 242 | zoomOutToolbarButton = new QPushButton(this); |
8501 | cbradney | 243 | zoomOutToolbarButton->setFocusPolicy(Qt::NoFocus); |
3053 | avox | 244 | zoomOutToolbarButton->setDefault( false ); |
245 | zoomOutToolbarButton->setAutoDefault( false ); |
||
246 | zoomOutToolbarButton->setFlat(OPTION_FLAT_BUTTON); |
||
3274 | fschmid | 247 | zoomInToolbarButton = new QPushButton(this); |
8501 | cbradney | 248 | zoomInToolbarButton->setFocusPolicy(Qt::NoFocus); |
3053 | avox | 249 | zoomInToolbarButton->setDefault( false ); |
250 | zoomInToolbarButton->setAutoDefault( false ); |
||
251 | zoomInToolbarButton->setFlat(OPTION_FLAT_BUTTON); |
||
15839 | fschmid | 252 | zoomInToolbarButton->addAction(m_ScMW->scrActions["toolsZoomIn"]); |
253 | zoomOutToolbarButton->addAction(m_ScMW->scrActions["toolsZoomOut"]); |
||
13186 | cbradney | 254 | cmsToolbarButton = new QPushButton(this); |
8501 | cbradney | 255 | cmsToolbarButton->setFocusPolicy(Qt::NoFocus); |
6726 | fschmid | 256 | cmsToolbarButton->setDefault( false ); |
257 | cmsToolbarButton->setAutoDefault( false ); |
||
258 | cmsToolbarButton->setFlat(OPTION_FLAT_BUTTON); |
||
13186 | cbradney | 259 | cmsToolbarButton->setIcon(loadIcon("cmsOn.png")); |
6726 | fschmid | 260 | previewToolbarButton = new QPushButton(this); |
8501 | cbradney | 261 | previewToolbarButton->setFocusPolicy(Qt::NoFocus); |
6549 | fschmid | 262 | previewToolbarButton->setDefault( false ); |
263 | previewToolbarButton->setAutoDefault( false ); |
||
264 | previewToolbarButton->setFlat(OPTION_FLAT_BUTTON); |
||
13186 | cbradney | 265 | previewToolbarButton->setIcon(loadIcon("previewOn.png")); |
17915 | fschmid | 266 | editOnPreviewToolbarButton = new QPushButton(this); |
267 | editOnPreviewToolbarButton->setFocusPolicy(Qt::NoFocus); |
||
268 | editOnPreviewToolbarButton->setDefault( false ); |
||
269 | editOnPreviewToolbarButton->setAutoDefault( false ); |
||
270 | editOnPreviewToolbarButton->setFlat(OPTION_FLAT_BUTTON); |
||
17931 | fschmid | 271 | editOnPreviewToolbarButton->setIcon(loadIcon("16/editdoc.png")); |
3053 | avox | 272 | #endif |
12362 | fschmid | 273 | cmsAdjustMenu = new QMenu(); |
274 | idCmsAdjustMenu = cmsAdjustMenu->addAction( "Configure CMS...", this, SLOT(adjustCMS())); |
||
275 | cmsToolbarButton->setMenu(cmsAdjustMenu); |
||
276 | #if OPTION_USE_QTOOLBUTTON |
||
277 | cmsToolbarButton->setPopupMode(QToolButton::DelayedPopup); |
||
278 | #endif |
||
5287 | cbradney | 279 | //zoomDefaultToolbarButton->setText("1:1"); |
10575 | cbradney | 280 | zoomDefaultToolbarButton->setIcon(QIcon(loadIcon("16/zoom-original.png"))); |
281 | zoomOutToolbarButton->setIcon(QIcon(loadIcon("16/zoom-out.png"))); |
||
282 | zoomInToolbarButton->setIcon(QIcon(loadIcon("16/zoom-in.png"))); |
||
7651 | cbradney | 283 | pageSelector = new PageSelector(this, Doc->Pages->count()); |
3309 | cbradney | 284 | pageSelector->setFont(fo); |
8573 | jghali | 285 | pageSelector->setFocusPolicy(Qt::ClickFocus); |
10575 | cbradney | 286 | layerMenu = new QComboBox( this ); |
3309 | cbradney | 287 | layerMenu->setEditable(false); |
288 | layerMenu->setFont(fo); |
||
8573 | jghali | 289 | layerMenu->setFocusPolicy(Qt::NoFocus); |
17953 | fschmid | 290 | layerMenu->setSizeAdjustPolicy(QComboBox::AdjustToContents); |
10575 | cbradney | 291 | visualMenu = new QComboBox( this ); |
8573 | jghali | 292 | visualMenu->setFocusPolicy(Qt::NoFocus); |
6549 | fschmid | 293 | visualMenu->setFont(fo); |
294 | visualMenu->setEnabled(false); |
||
17953 | fschmid | 295 | visualMenu->setSizeAdjustPolicy(QComboBox::AdjustToContents); |
1612 | cbradney | 296 | horizRuler = new Hruler(this, Doc); |
297 | vertRuler = new Vruler(this, Doc); |
||
10532 | avox | 298 | horizRuler->installEventFilter(this); |
299 | vertRuler->installEventFilter(this); |
||
3309 | cbradney | 300 | rulerMover = new RulerMover(this); |
8573 | jghali | 301 | rulerMover->setFocusPolicy(Qt::NoFocus); |
10532 | avox | 302 | horizRuler->setGeometry(m_vhRulerHW, 1, width()-m_vhRulerHW-1, m_vhRulerHW); |
303 | vertRuler->setGeometry(1, m_vhRulerHW, m_vhRulerHW, height()-m_vhRulerHW-1); |
||
304 | rulerMover->setGeometry(1, 1, m_vhRulerHW, m_vhRulerHW); |
||
3 | paul | 305 | Ready = true; |
10560 | avox | 306 | m_canvas->setMouseTracking(true); |
456 | fschmid | 307 | setAcceptDrops(true); |
10560 | avox | 308 | m_canvas->setAcceptDrops(true); |
10532 | avox | 309 | // FIXME setDragAutoScroll(false); |
456 | fschmid | 310 | Doc->DragP = false; |
311 | Doc->leaveDrag = false; |
||
1330 | fschmid | 312 | Doc->SubMode = -1; |
14932 | cbradney | 313 | storedFramesShown = Doc->guidesPrefs().framesShown; |
314 | storedShowControls = Doc->guidesPrefs().showControls; |
||
315 | setRulersShown(Doc->guidesPrefs().rulersShown); |
||
10532 | avox | 316 | m_canvas->m_viewMode.viewAsPreview = false; |
17913 | fschmid | 317 | m_canvas->setPreviewVisual(-1); |
10560 | avox | 318 | // shiftSelItems = false; |
319 | // inItemCreation = false; |
||
10532 | avox | 320 | m_previousMode = -1; |
8720 | fschmid | 321 | redrawMode = 0; |
322 | redrawCount = 0; |
||
18438 | craig | 323 | redrawMarker = new SelectionRubberBand(QRubberBand::Rectangle, this); |
8720 | fschmid | 324 | redrawMarker->hide(); |
10532 | avox | 325 | m_canvas->newRedrawPolygon(); |
326 | m_canvas->resetRenderMode(); |
||
17665 | craig | 327 | m_ScMW->scrActions["viewPreviewMode"]->setChecked(m_canvas->m_viewMode.viewAsPreview); |
10560 | avox | 328 | // m_SnapCounter = 0; |
11960 | subik | 329 | |
10532 | avox | 330 | Doc->regionsChanged()->connectObserver(this); |
15724 | fschmid | 331 | // connect(zoomOutToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoomOut())); |
332 | // connect(zoomInToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoomIn())); |
||
3274 | fschmid | 333 | connect(zoomDefaultToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoom100())); |
8705 | fschmid | 334 | connect(zoomSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setZoom())); |
3309 | cbradney | 335 | connect(pageSelector, SIGNAL(GotoPage(int)), this, SLOT(GotoPa(int))); |
336 | connect(layerMenu, SIGNAL(activated(int)), this, SLOT(GotoLa(int))); |
||
2966 | fschmid | 337 | connect(unitSwitcher, SIGNAL(activated(int)), this, SLOT(ChgUnit(int))); |
13075 | subik | 338 | connect(previewQualitySwitcher, SIGNAL(activated(int)), this, SLOT(changePreviewQuality(int))); |
6549 | fschmid | 339 | connect(previewToolbarButton, SIGNAL(clicked()), this, SLOT(togglePreview())); |
17915 | fschmid | 340 | connect(editOnPreviewToolbarButton, SIGNAL(clicked()), this, SLOT(togglePreviewEdit())); |
6726 | fschmid | 341 | connect(cmsToolbarButton, SIGNAL(clicked()), this, SLOT(toggleCMS())); |
6549 | fschmid | 342 | connect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int))); |
16016 | fschmid | 343 | connect(this, SIGNAL(HaveSel(int)), Doc, SLOT(selectionChanged())); |
13285 | fschmid | 344 | // Commented out to fix bug #7865 |
345 | // m_dragTimer = new QTimer(this); |
||
346 | // connect(m_dragTimer, SIGNAL(timeout()), this, SLOT(dragTimerTimeOut())); |
||
347 | // m_dragTimer->stop(); |
||
10978 | avox | 348 | m_dragTimerFired = false; |
17797 | fschmid | 349 | clockLabel = new ClockWidget(this, Doc); |
350 | clockLabel->setGeometry(m_vhRulerHW + 1, height() - m_vhRulerHW - 61, 60, 60); |
||
351 | clockLabel->setVisible(false); |
||
17971 | fschmid | 352 | endEditButton = new QPushButton(loadIcon("22/exit.png"), tr("End Edit"), this); |
353 | endEditButton->setGeometry(m_vhRulerHW + 1, height() - m_vhRulerHW - endEditButton->minimumSizeHint().height() - 1, endEditButton->minimumSizeHint().width(), endEditButton->minimumSizeHint().height()); |
||
354 | endEditButton->setVisible(false); |
||
355 | connect(endEditButton, SIGNAL(clicked()), m_ScMW, SLOT(slotFileClose())); |
||
17915 | fschmid | 356 | editOnPreviewToolbarButton->hide(); |
17971 | fschmid | 357 | languageChange(); |
3 | paul | 358 | } |
359 | |||
11190 | avox | 360 | ScribusView::~ScribusView() |
361 | { |
||
362 | while (m_canvasMode) |
||
363 | { |
||
364 | m_canvasMode->deactivate(false); |
||
365 | m_canvasMode = m_canvasMode->delegate(); |
||
366 | } |
||
367 | } |
||
368 | |||
10859 | cbradney | 369 | void ScribusView::changeEvent(QEvent *e) |
370 | { |
||
371 | if (e->type() == QEvent::LanguageChange) |
||
372 | { |
||
373 | languageChange(); |
||
374 | } |
||
10903 | cbradney | 375 | else |
376 | QWidget::changeEvent(e); |
||
10859 | cbradney | 377 | } |
378 | |||
2199 | cbradney | 379 | void ScribusView::languageChange() |
380 | { |
||
12655 | fschmid | 381 | zoomDefaultToolbarButton->setToolTip( tr("Zoom to 100%")); |
382 | zoomOutToolbarButton->setToolTip( tr("Zoom out by the stepping value in Tools preferences")); |
||
383 | zoomInToolbarButton->setToolTip( tr("Zoom in by the stepping value in Tools preferences")); |
||
384 | zoomSpinBox->setToolTip( tr("Current zoom level")); |
||
10397 | cbradney | 385 | cmsToolbarButton->setToolTip(""); |
386 | previewToolbarButton->setToolTip(""); |
||
12655 | fschmid | 387 | layerMenu->setToolTip( tr("Select the current layer")); |
388 | unitSwitcher->setToolTip( tr("Select the current unit")); |
||
13075 | subik | 389 | previewQualitySwitcher->setToolTip( tr("Select the image preview quality")); |
10397 | cbradney | 390 | visualMenu->setToolTip(""); |
11996 | cbradney | 391 | cmsToolbarButton->setToolTip( tr("Enable/disable Color Management")); |
12362 | fschmid | 392 | idCmsAdjustMenu->setText( tr("Configure CMS...")); |
11996 | cbradney | 393 | previewToolbarButton->setToolTip( tr("Enable/disable the Preview Mode")); |
17915 | fschmid | 394 | editOnPreviewToolbarButton->setToolTip( tr("Enable/disable editing the Preview Mode")); |
11996 | cbradney | 395 | visualMenu->setToolTip( tr("Select the visual appearance of the display. You can choose between normal and several color blindness forms")); |
17971 | fschmid | 396 | endEditButton->setToolTip( tr("Click here to leave this special edit mode.")); |
6549 | fschmid | 397 | disconnect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int))); |
398 | visualMenu->clear(); |
||
10585 | fschmid | 399 | visualMenu->addItem(CommonStrings::trVisionNormal); |
400 | visualMenu->addItem(CommonStrings::trVisionProtanopia); |
||
401 | visualMenu->addItem(CommonStrings::trVisionDeuteranopia); |
||
402 | visualMenu->addItem(CommonStrings::trVisionTritanopia); |
||
403 | visualMenu->addItem(CommonStrings::trVisionFullColorBlind); |
||
404 | visualMenu->setCurrentIndex(m_canvas->previewVisual()); |
||
6549 | fschmid | 405 | connect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int))); |
2199 | cbradney | 406 | } |
407 | |||
6726 | fschmid | 408 | void ScribusView::toggleCMS() |
409 | { |
||
410 | Doc->enableCMS(!Doc->HasCMS); |
||
16546 | jghali | 411 | m_ScMW->requestUpdate(reqCmsOptionsUpdate); |
10867 | fschmid | 412 | DrawNew(); |
6726 | fschmid | 413 | } |
414 | |||
12362 | fschmid | 415 | void ScribusView::adjustCMS() |
416 | { |
||
417 | AdjustCmsDialog* dia = new AdjustCmsDialog(this, Doc); |
||
418 | if (dia->exec()) |
||
419 | { |
||
420 | dia->tabColorManagement->updateDocSettings(Doc); |
||
421 | if (dia->tabColorManagement->changed) |
||
422 | { |
||
15001 | cbradney | 423 | Doc->enableCMS(Doc->cmsSettings().CMSinUse); |
12362 | fschmid | 424 | cmsToolbarButton->setChecked(Doc->HasCMS); |
17375 | fschmid | 425 | m_ScMW->requestUpdate(reqCmsOptionsUpdate); |
12362 | fschmid | 426 | DrawNew(); |
427 | } |
||
428 | } |
||
429 | delete dia; |
||
430 | } |
||
431 | |||
6549 | fschmid | 432 | void ScribusView::switchPreviewVisual(int vis) |
433 | { |
||
10532 | avox | 434 | m_canvas->setPreviewVisual(vis); |
16241 | fschmid | 435 | Doc->viewAsPreview = m_canvas->usePreviewVisual(); |
436 | Doc->previewVisual = m_canvas->previewVisual(); |
||
6549 | fschmid | 437 | Doc->recalculateColors(); |
438 | Doc->recalcPicturesRes(); |
||
10867 | fschmid | 439 | DrawNew(); |
6549 | fschmid | 440 | } |
441 | |||
17915 | fschmid | 442 | void ScribusView::togglePreviewEdit() |
443 | { |
||
444 | Doc->editOnPreview = !Doc->editOnPreview; |
||
445 | m_ScMW->setPreviewToolbar(); |
||
17999 | fschmid | 446 | DrawNew(); |
17915 | fschmid | 447 | } |
448 | |||
5235 | fschmid | 449 | void ScribusView::togglePreview() |
450 | { |
||
17909 | fschmid | 451 | this->requestMode(modeNormal); |
452 | Deselect(true); |
||
17744 | craig | 453 | undoManager->setUndoEnabled(false); |
10532 | avox | 454 | m_canvas->m_viewMode.viewAsPreview = !m_canvas->m_viewMode.viewAsPreview; |
16177 | fschmid | 455 | Doc->drawAsPreview = m_canvas->m_viewMode.viewAsPreview; |
17910 | fschmid | 456 | bool recalc = false; |
17915 | fschmid | 457 | Doc->editOnPreview = false; |
458 | editOnPreviewToolbarButton->setChecked(false); |
||
10532 | avox | 459 | if (m_canvas->m_viewMode.viewAsPreview) |
5237 | fschmid | 460 | { |
17915 | fschmid | 461 | editOnPreviewToolbarButton->show(); |
14932 | cbradney | 462 | storedFramesShown = Doc->guidesPrefs().framesShown; |
463 | Doc->guidesPrefs().framesShown = false; |
||
464 | storedShowControls = Doc->guidesPrefs().showControls; |
||
465 | Doc->guidesPrefs().showControls = false; |
||
17915 | fschmid | 466 | m_canvas->m_viewMode.previewVisual = 0; |
467 | Doc->previewVisual = 0; |
||
6802 | subik | 468 | // warning popping up in case colour management and out-of-gamut-display are active |
469 | // as from #4346: Add a preview for daltonian - PV |
||
7141 | fschmid | 470 | if (Doc->HasCMS && Doc->Gamut) |
7400 | cbradney | 471 | QMessageBox::information(m_ScMW, tr("Preview Mode"), |
472 | "<qt>" + tr("CMS is active. Therefore the color display may not match the perception by visually impaired") + "</qt>", |
||
473 | QMessageBox::Ok); |
||
5237 | fschmid | 474 | } |
475 | else |
||
7624 | fschmid | 476 | { |
17988 | fschmid | 477 | Doc->ResetFormFields(); |
17915 | fschmid | 478 | editOnPreviewToolbarButton->hide(); |
14932 | cbradney | 479 | Doc->guidesPrefs().framesShown = storedFramesShown; |
480 | Doc->guidesPrefs().showControls = storedShowControls; |
||
17375 | fschmid | 481 | disconnect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int))); |
17910 | fschmid | 482 | if (visualMenu->currentIndex() != Doc->previewVisual) |
483 | recalc = true; |
||
17375 | fschmid | 484 | m_canvas->m_viewMode.previewVisual = 0; |
485 | Doc->previewVisual = 0; |
||
486 | visualMenu->setCurrentIndex(0); |
||
487 | connect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int))); |
||
7624 | fschmid | 488 | } |
17665 | craig | 489 | m_ScMW->scrActions["viewPreviewMode"]->setChecked(m_canvas->m_viewMode.viewAsPreview); |
10532 | avox | 490 | m_ScMW->scrActions["viewShowMargins"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
491 | m_ScMW->scrActions["viewShowFrames"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
492 | m_ScMW->scrActions["viewShowLayerMarkers"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
493 | m_ScMW->scrActions["viewShowGrid"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
494 | m_ScMW->scrActions["viewShowGuides"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
495 | m_ScMW->scrActions["viewShowColumnBorders"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
496 | m_ScMW->scrActions["viewShowBaseline"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
497 | m_ScMW->scrActions["viewShowTextChain"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
498 | m_ScMW->scrActions["viewShowTextControls"]->setEnabled(!m_canvas->m_viewMode.viewAsPreview); |
||
17909 | fschmid | 499 | m_ScMW->setPreviewToolbar(); |
6549 | fschmid | 500 | #if OPTION_USE_QTOOLBUTTON |
10575 | cbradney | 501 | previewToolbarButton->setChecked(m_canvas->m_viewMode.viewAsPreview); |
6549 | fschmid | 502 | #endif |
10532 | avox | 503 | visualMenu->setEnabled(m_canvas->m_viewMode.viewAsPreview); |
13909 | jghali | 504 | ScGuardedPtr<ScribusDoc> docPtr = Doc->guardedPtr(); |
17910 | fschmid | 505 | if (recalc) |
506 | { |
||
507 | Doc->recalculateColors(); |
||
508 | Doc->recalcPicturesRes(); |
||
509 | } |
||
10867 | fschmid | 510 | // repaintContents(QRect()); |
13909 | jghali | 511 | if (docPtr) // document may have been destroyed in-between |
512 | { |
||
513 | DrawNew(); |
||
514 | } |
||
17744 | craig | 515 | undoManager->setUndoEnabled(true); |
5235 | fschmid | 516 | } |
517 | |||
16639 | jghali | 518 | void ScribusView::changed(QRectF re, bool) |
2171 | fschmid | 519 | { |
12079 | avox | 520 | double scale = m_canvas->scale(); |
521 | int newCanvasWidth = qRound((Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()) * scale); |
||
522 | int newCanvasHeight = qRound((Doc->maxCanvasCoordinate.y() - Doc->minCanvasCoordinate.y()) * scale); |
||
523 | if (!re.isValid() && // dont check this all the time |
||
524 | ( m_oldCanvasWidth != newCanvasWidth || m_oldCanvasHeight != newCanvasHeight)) |
||
525 | { |
||
526 | QSize maxViewport = maximumViewportSize(); |
||
527 | horizontalScrollBar()->setRange(qRound(Doc->minCanvasCoordinate.x() * scale), |
||
528 | qRound(Doc->maxCanvasCoordinate.x() * scale) - maxViewport.width()); |
||
529 | verticalScrollBar()->setRange(qRound(Doc->minCanvasCoordinate.y() * scale), |
||
530 | qRound(Doc->maxCanvasCoordinate.y() * scale) - maxViewport.height()); |
||
531 | /* qDebug() << "adjustCanvas [" << m_oldCanvasWidth << m_oldCanvasHeight << " ] -> [" << newCanvasWidth << newCanvasHeight |
||
532 | << "] (" << Doc->minCanvasCoordinate.x() << Doc->minCanvasCoordinate.y() << ") - (" |
||
533 | << Doc->maxCanvasCoordinate.x() << Doc->maxCanvasCoordinate.y() << ") @" << scale << maxViewport; |
||
534 | */ |
||
535 | widget()->resize(newCanvasWidth, newCanvasHeight); |
||
536 | m_oldCanvasWidth = newCanvasWidth; |
||
537 | m_oldCanvasHeight = newCanvasHeight; |
||
538 | } |
||
14754 | jghali | 539 | if (!Doc->isLoading() && !m_ScMW->scriptIsRunning()) |
11509 | fschmid | 540 | { |
12820 | pierre | 541 | // qDebug() << "ScribusView-changed(): changed region:" << re; |
18499 | craig | 542 | m_canvas->setForcedRedraw(true); |
11509 | fschmid | 543 | updateCanvas(re); |
544 | } |
||
2171 | fschmid | 545 | } |
546 | |||
13371 | jghali | 547 | bool ScribusView::handleObjectImport(QMimeData* mimeData, TransactionSettings* trSettings) |
12971 | jghali | 548 | { |
549 | requestMode(modeImportObject); |
||
550 | CanvasMode_ObjImport* objImport = dynamic_cast<CanvasMode_ObjImport*>(m_canvasMode); |
||
551 | if (objImport) |
||
552 | { |
||
553 | objImport->setMimeData(mimeData); |
||
13371 | jghali | 554 | objImport->setTransactionSettings(trSettings); |
12971 | jghali | 555 | return true; |
556 | } |
||
13371 | jghali | 557 | delete trSettings; |
12971 | jghali | 558 | delete mimeData; |
559 | return false; |
||
560 | } |
||
561 | |||
10701 | avox | 562 | void ScribusView::startGesture(CanvasGesture* gesture) |
563 | { |
||
11960 | subik | 564 | // qDebug() << "start gesture" << typeid(*m_canvasMode).name() |
565 | // << "---->" |
||
11645 | fschmid | 566 | // << typeid(*gesture).name(); |
13220 | jghali | 567 | if (m_canvasMode != gesture) |
568 | { |
||
569 | m_canvasMode->deactivate(true); |
||
570 | gesture->setDelegate(m_canvasMode); |
||
571 | m_canvasMode = gesture; |
||
572 | m_canvasMode->activate(false); |
||
573 | if (Doc->appMode != modeEditClip) |
||
574 | m_canvas->repaint(); |
||
575 | } |
||
10701 | avox | 576 | } |
577 | |||
578 | void ScribusView::stopGesture() |
||
579 | { |
||
12820 | pierre | 580 | // qDebug() << "stop gesture" << typeid(*m_canvasMode).name() << (m_canvasMode->delegate() != 0); |
10701 | avox | 581 | if (m_canvasMode->delegate()) |
582 | { |
||
583 | m_canvasMode->deactivate(false); |
||
584 | m_canvasMode = m_canvasMode->delegate(); |
||
585 | m_canvasMode->activate(true); |
||
13955 | cbradney | 586 | if (PrefsManager::instance()->appPrefs.uiPrefs.stickyTools) |
11531 | fschmid | 587 | { |
18499 | craig | 588 | m_canvas->setForcedRedraw(true); |
11704 | fschmid | 589 | // Doc->m_Selection->clear(); |
590 | // emit HaveSel(-1); |
||
11531 | fschmid | 591 | m_canvas->resetRenderMode(); |
592 | updateContents(); |
||
593 | } |
||
594 | else |
||
595 | m_canvas->repaint(); |
||
10701 | avox | 596 | } |
597 | } |
||
598 | |||
10532 | avox | 599 | /** |
600 | switches between appmodes: |
||
601 | - for submodes, activate the appropiate dialog or palette |
||
602 | - set a new CanvasMode if necessary |
||
603 | - call ScribusMainWindow::setAppMode(), which de/activates actions |
||
604 | */ |
||
605 | void ScribusView::requestMode(int appMode) |
||
456 | fschmid | 606 | { |
10532 | avox | 607 | bool updateNecessary = false; |
11645 | fschmid | 608 | // qDebug() << "request mode:" << appMode; |
10532 | avox | 609 | switch(appMode) // filter submodes |
456 | fschmid | 610 | { |
10532 | avox | 611 | case submodePaintingDone: // return to normal mode |
11171 | fschmid | 612 | appMode = modeNormal; |
10532 | avox | 613 | m_previousMode = -1; |
614 | updateNecessary = true; |
||
11960 | subik | 615 | break; |
10532 | avox | 616 | case submodeEndNodeEdit: // return from node/shape editing |
11171 | fschmid | 617 | appMode = modeNormal; |
10532 | avox | 618 | m_previousMode = -1; |
619 | updateNecessary = true; |
||
10560 | avox | 620 | break; |
10532 | avox | 621 | case submodeLoadPic: // open GetImage dialog |
17735 | craig | 622 | m_ScMW->slotGetContent(); |
10532 | avox | 623 | appMode = Doc->appMode; |
624 | m_previousMode = appMode; |
||
625 | break; |
||
626 | case submodeStatusPic: // open ManageImages dialog |
||
627 | appMode = Doc->appMode; |
||
628 | m_previousMode = appMode; |
||
629 | m_ScMW->StatusPic(); |
||
630 | break; |
||
631 | case submodeEditExternal: // open external image editor |
||
632 | appMode = Doc->appMode; |
||
633 | m_previousMode = appMode; |
||
634 | m_ScMW->callImageEditor(); |
||
635 | break; |
||
11960 | subik | 636 | case submodeAnnotProps: |
10532 | avox | 637 | appMode = Doc->appMode; |
638 | m_previousMode = appMode; |
||
639 | m_ScMW->ModifyAnnot(); |
||
640 | break; |
||
16029 | fschmid | 641 | case submodeEditSymbol: |
642 | appMode = Doc->appMode; |
||
643 | m_previousMode = appMode; |
||
644 | m_ScMW->editSelectedSymbolStart(); |
||
645 | break; |
||
10532 | avox | 646 | default: |
647 | if (appMode < 0 || appMode > submodeFirstSubmode) |
||
7221 | fschmid | 648 | { |
11645 | fschmid | 649 | // qDebug() << "request mode: UNKNOWN" << appMode; |
10532 | avox | 650 | appMode = modeNormal; |
7221 | fschmid | 651 | } |
11960 | subik | 652 | m_previousMode = appMode; |
10532 | avox | 653 | break; |
654 | } |
||
6922 | fschmid | 655 | |
11645 | fschmid | 656 | // qDebug() << "request mode" << Doc->appMode << "-->" << appMode; |
10532 | avox | 657 | if (Doc->appMode != appMode) |
456 | fschmid | 658 | { |
10532 | avox | 659 | m_ScMW->setAppMode(appMode); |
660 | CanvasMode* newCanvasMode = modeInstances.value(appMode); |
||
661 | if (!newCanvasMode) |
||
2934 | fschmid | 662 | { |
10532 | avox | 663 | newCanvasMode = CanvasMode::createForAppMode(this, appMode); |
664 | modeInstances[appMode] = newCanvasMode; |
||
8994 | fschmid | 665 | } |
10532 | avox | 666 | if (newCanvasMode) |
8994 | fschmid | 667 | { |
11645 | fschmid | 668 | // qDebug() << "request canvas mode" << typeid(*newCanvasMode).name(); |
10701 | avox | 669 | m_canvasMode->deactivate(false); |
10532 | avox | 670 | m_canvasMode = newCanvasMode; |
10701 | avox | 671 | m_canvasMode->activate(false); |
2934 | fschmid | 672 | } |
10532 | avox | 673 | updateNecessary = true; |
8770 | fschmid | 674 | } |
10604 | fschmid | 675 | else |
676 | m_ScMW->setAppMode(appMode); |
||
10532 | avox | 677 | if (updateNecessary) |
10869 | avox | 678 | updateCanvas(); |
456 | fschmid | 679 | } |
680 | |||
681 | |||
10532 | avox | 682 | |
10701 | avox | 683 | /* |
10532 | avox | 684 | void ScribusView::paintEvent ( QPaintEvent * p ) |
456 | fschmid | 685 | { |
10532 | avox | 686 | #ifndef _WIN32 |
687 | if (p->spontaneous()) |
||
688 | evSpon = true; |
||
689 | #endif |
||
690 | QScrollArea::paintEvent(p); |
||
691 | // QPainter qp(viewport()); |
||
692 | // drawContents(&qp, p->rect().x(), p->rect().y(), p->rect().width(), p->rect().height()); |
||
456 | fschmid | 693 | } |
10701 | avox | 694 | */ |
456 | fschmid | 695 | |
10532 | avox | 696 | void ScribusView::enterEvent(QEvent * e) |
6583 | fschmid | 697 | { |
10532 | avox | 698 | m_canvasMode->enterEvent(e); |
699 | return; |
||
6583 | fschmid | 700 | } |
701 | |||
10532 | avox | 702 | void ScribusView::leaveEvent(QEvent *e) |
456 | fschmid | 703 | { |
10532 | avox | 704 | m_canvasMode->leaveEvent(e); |
705 | return; |
||
456 | fschmid | 706 | } |
707 | |||
708 | void ScribusView::contentsDragEnterEvent(QDragEnterEvent *e) |
||
709 | { |
||
710 | QString text; |
||
12973 | fschmid | 711 | bool /* dataFound = false, */ fromFile = false; |
12841 | jghali | 712 | const ScElemMimeData* elemData = dynamic_cast<const ScElemMimeData*>(e->mimeData()); |
9745 | fschmid | 713 | e->accept(); |
12841 | jghali | 714 | if (elemData) |
715 | text = elemData->scribusElem(); |
||
716 | else if (e->mimeData()->hasUrls()) |
||
456 | fschmid | 717 | { |
12841 | jghali | 718 | QUrl url = e->mimeData()->urls().at(0); |
719 | QFileInfo fi(url.toLocalFile()); |
||
720 | if (fi.exists()) |
||
721 | { |
||
722 | fromFile = true; |
||
723 | text = url.toLocalFile(); |
||
724 | } |
||
725 | } |
||
726 | if (!text.isEmpty()) |
||
727 | { |
||
9745 | fschmid | 728 | e->acceptProposedAction(); |
456 | fschmid | 729 | double gx, gy, gw, gh; |
18028 | jghali | 730 | ScriXmlDoc ss; |
731 | if(ss.ReadElemHeader(text, fromFile, &gx, &gy, &gw, &gh)) |
||
456 | fschmid | 732 | { |
11477 | avox | 733 | FPoint dragPosDoc = m_canvas->globalToCanvas(widget()->mapToGlobal(e->pos())); |
734 | dragX = dragPosDoc.x(); //e->pos().x() / m_canvas->scale(); |
||
735 | dragY = dragPosDoc.y(); //e->pos().y() / m_canvas->scale(); |
||
7575 | cbradney | 736 | dragW = gw; |
737 | dragH = gh; |
||
456 | fschmid | 738 | DraggedGroup = true; |
739 | DraggedGroupFirst = true; |
||
9745 | fschmid | 740 | getDragRectScreen(&gx, &gy, &gw, &gh); |
11126 | fschmid | 741 | // QPoint evP = viewport()->mapToGlobal(e->pos()); |
742 | // evP -= QPoint(contentsX(), contentsY()); |
||
743 | // redrawMarker->setGeometry(QRect(evP.x() + 1, evP.y() + 1, qRound(gw), qRound(gh)).normalized()); |
||
744 | // if (!redrawMarker->isVisible()) |
||
745 | // redrawMarker->show(); |
||
16546 | jghali | 746 | emit ItemGeom(); |
456 | fschmid | 747 | } |
748 | } |
||
749 | } |
||
750 | |||
751 | void ScribusView::contentsDragMoveEvent(QDragMoveEvent *e) |
||
752 | { |
||
753 | QString text; |
||
9745 | fschmid | 754 | e->accept(); |
9764 | jghali | 755 | if (e->mimeData()->hasText()) |
456 | fschmid | 756 | { |
9745 | fschmid | 757 | e->acceptProposedAction(); |
9764 | jghali | 758 | text = e->mimeData()->text(); |
456 | fschmid | 759 | if (DraggedGroup) |
760 | { |
||
11126 | fschmid | 761 | // double gx, gy, gw, gh; |
11477 | avox | 762 | FPoint dragPosDoc = m_canvas->globalToCanvas(widget()->mapToGlobal(e->pos())); |
763 | dragX = dragPosDoc.x(); //e->pos().x() / m_canvas->scale(); |
||
764 | dragY = dragPosDoc.y(); //e->pos().y() / m_canvas->scale(); |
||
11126 | fschmid | 765 | // getDragRectScreen(&gx, &gy, &gw, &gh); |
766 | // QPoint evP = viewport()->mapToGlobal(e->pos()); |
||
767 | // evP -= QPoint(contentsX(), contentsY()); |
||
768 | // redrawMarker->setGeometry(QRect(evP.x() + 2, evP.y() + 2, qRound(gw - 2), qRound(gh - 2)).normalized()); |
||
769 | // if (!redrawMarker->isVisible()) |
||
770 | // redrawMarker->show(); |
||
456 | fschmid | 771 | DraggedGroupFirst = false; |
10532 | avox | 772 | emit MousePos(dragX, dragY); //+Doc->minCanvasCoordinate.x(), dragY+Doc->minCanvasCoordinate.y()); |
11477 | avox | 773 | QPoint pos = m_canvas->canvasToLocal(dragPosDoc); |
774 | horizRuler->Draw(pos.x()); |
||
775 | vertRuler->Draw(pos.y()); |
||
9745 | fschmid | 776 | // return; |
456 | fschmid | 777 | } |
778 | /* QUrl ur(text); |
||
12838 | jghali | 779 | QFileInfo fi = QFileInfo(ur.toLocalFile()); |
10398 | cbradney | 780 | QString ext = fi.extension(false).toUpper(); |
456 | fschmid | 781 | QStrList imfo = QImageIO::inputFormats(); |
782 | if (ext == "JPG") |
||
783 | ext = "JPEG"; |
||
784 | img = ((imfo.contains(ext))||(ext=="PS")||(ext=="EPS")||(ext=="TIF")); |
||
785 | if (!SeleItemPos(e->pos())) |
||
786 | { |
||
787 | if (SelItem.count() != 0) |
||
788 | Deselect(true); |
||
789 | } |
||
790 | else |
||
791 | { |
||
792 | b = SelItem.at(0); |
||
793 | if (img) |
||
794 | { |
||
795 | if (b->PType != 2) |
||
796 | Deselect(true); |
||
797 | } |
||
798 | else |
||
799 | { |
||
800 | if (b->PType != 4) |
||
801 | Deselect(true); |
||
802 | } |
||
803 | } */ |
||
804 | } |
||
805 | } |
||
806 | |||
632 | fschmid | 807 | void ScribusView::contentsDragLeaveEvent(QDragLeaveEvent *) |
456 | fschmid | 808 | { |
809 | if (DraggedGroup) |
||
810 | { |
||
811 | DraggedGroup = false; |
||
812 | DraggedGroupFirst = false; |
||
10532 | avox | 813 | m_canvas->resetRenderMode(); |
11126 | fschmid | 814 | // redrawMarker->hide(); |
9745 | fschmid | 815 | updateContents(); |
456 | fschmid | 816 | } |
817 | } |
||
818 | |||
819 | void ScribusView::contentsDropEvent(QDropEvent *e) |
||
820 | { |
||
821 | QString text; |
||
11486 | avox | 822 | QUrl url; |
1957 | cbradney | 823 | PageItem *currItem; |
11576 | avox | 824 | UndoTransaction* activeTransaction = NULL; |
456 | fschmid | 825 | bool img = false; |
10532 | avox | 826 | m_canvas->resetRenderMode(); |
9745 | fschmid | 827 | redrawMode = 0; |
11126 | fschmid | 828 | // redrawMarker->hide(); |
1065 | cbradney | 829 | // struct ScText *hg; |
456 | fschmid | 830 | // uint a; |
693 | fschmid | 831 | int re = 0; |
9745 | fschmid | 832 | // e->accept(Q3TextDrag::canDecode(e)); |
833 | e->accept(); |
||
456 | fschmid | 834 | DraggedGroupFirst = false; |
15060 | fschmid | 835 | bool selectedItemByDrag=false; |
11477 | avox | 836 | FPoint dropPosDoc = m_canvas->globalToCanvas(widget()->mapToGlobal(e->pos())); |
11475 | avox | 837 | QPointF dropPosDocQ(dropPosDoc.x(), dropPosDoc.y()); |
838 | // int ex = qRound(e->pos().x()/m_canvas->scale());// + Doc->minCanvasCoordinate.x()); |
||
839 | // int ey = qRound(e->pos().y()/m_canvas->scale());// + Doc->minCanvasCoordinate.y()); |
||
11486 | avox | 840 | |
17962 | fschmid | 841 | // Commented out to fix Bug #11254 (fs) |
842 | /* if (ScMimeData::clipboardHasScribusElem() && (Doc->DraggedElem == 0)) |
||
456 | fschmid | 843 | { |
12841 | jghali | 844 | text = ScMimeData::clipboardScribusElem(); |
845 | url = QUrl(text); |
||
846 | } |
||
17962 | fschmid | 847 | else*/ |
848 | if (e->mimeData()->hasText()) |
||
12841 | jghali | 849 | { |
11486 | avox | 850 | text = e->mimeData()->text(); |
851 | url = QUrl(text); |
||
852 | } |
||
853 | else if (e->mimeData()->hasUrls()) |
||
854 | { |
||
855 | url = e->mimeData()->urls().at(0); |
||
856 | text = ""; |
||
857 | } |
||
15060 | fschmid | 858 | else if (e->mimeData()->hasFormat("text/symbol")) |
859 | { |
||
860 | e->acceptProposedAction(); |
||
861 | activateWindow(); |
||
862 | if (!m_ScMW->scriptIsRunning()) |
||
863 | raise(); |
||
864 | m_ScMW->newActWin(((ScribusWin*)(Doc->WinHan))->getSubWin()); |
||
865 | updateContents(); |
||
866 | QString patternVal = e->mimeData()->data("text/symbol"); |
||
867 | Doc->m_Selection->delaySignalsOn(); |
||
868 | for (int i = Doc->Items->count() - 1; i >= 0 ; --i) |
||
869 | { |
||
870 | if (Doc->Items->at(i)->LayerID==Doc->activeLayer()) |
||
871 | { |
||
15063 | fschmid | 872 | if ((m_canvas->frameHitTest(dropPosDocQ, Doc->Items->at(i)) >= Canvas::INSIDE) && (Doc->Items->at(i)->itemType() == PageItem::Symbol)) |
15060 | fschmid | 873 | { |
874 | Deselect(false); |
||
875 | Doc->m_Selection->addItem(Doc->Items->at(i)); |
||
876 | Doc->Items->at(i)->setPattern(patternVal); |
||
877 | selectedItemByDrag=true; |
||
878 | break; |
||
879 | } |
||
880 | } |
||
881 | } |
||
882 | Doc->m_Selection->delaySignalsOff(); |
||
883 | if (!selectedItemByDrag) |
||
884 | { |
||
885 | int z = Doc->itemAdd(PageItem::Symbol, PageItem::Unspecified, dropPosDoc.x(), dropPosDoc.y(), 1, 1, 0, CommonStrings::None, CommonStrings::None, true); |
||
886 | PageItem *b = Doc->Items->at(z); |
||
887 | b->LayerID = Doc->activeLayer(); |
||
888 | ScPattern pat = Doc->docPatterns[patternVal]; |
||
889 | b->setWidth(pat.width); |
||
890 | b->setHeight(pat.height); |
||
891 | b->OldB2 = b->width(); |
||
892 | b->OldH2 = b->height(); |
||
893 | b->setPattern(patternVal); |
||
894 | b->updateClip(); |
||
895 | Deselect(false); |
||
896 | Doc->m_Selection->addItem(b); |
||
897 | } |
||
898 | emit DocChanged(); |
||
899 | update(); |
||
900 | return; |
||
901 | } |
||
17799 | fschmid | 902 | else if (e->mimeData()->hasFormat("text/inline")) |
903 | { |
||
904 | if (((Doc->appMode == modeEditTable) || (Doc->appMode == modeEdit)) && (!Doc->m_Selection->isEmpty())) |
||
905 | { |
||
906 | PageItem *b = Doc->m_Selection->itemAt(0); |
||
907 | if (b->isTextFrame() || b->isTable()) |
||
908 | { |
||
909 | e->acceptProposedAction(); |
||
910 | activateWindow(); |
||
911 | if (!m_ScMW->scriptIsRunning()) |
||
912 | raise(); |
||
913 | m_ScMW->newActWin(((ScribusWin*)(Doc->WinHan))->getSubWin()); |
||
914 | updateContents(); |
||
915 | QString patternVal = e->mimeData()->data("text/inline"); |
||
916 | int id = patternVal.toInt(); |
||
917 | PageItem_TextFrame *cItem; |
||
918 | if (Doc->appMode == modeEditTable) |
||
919 | cItem = b->asTable()->activeCell().textFrame(); |
||
920 | else |
||
921 | cItem = b->asTextFrame(); |
||
922 | if (cItem->HasSel) |
||
923 | cItem->deleteSelectedTextFromFrame(); |
||
17826 | craig | 924 | cItem->invalidateLayout(false); |
17799 | fschmid | 925 | cItem->itemText.insertObject(id); |
926 | if (b->isTable()) |
||
927 | b->asTable()->update(); |
||
928 | else |
||
929 | b->update(); |
||
930 | emit DocChanged(); |
||
931 | update(); |
||
932 | return; |
||
933 | } |
||
934 | } |
||
935 | } |
||
11645 | fschmid | 936 | // qDebug() << "ScribusView::contentsDropEvent" << e->mimeData()->formats() << url; |
11486 | avox | 937 | if (!url.isEmpty()) |
938 | { |
||
9745 | fschmid | 939 | e->acceptProposedAction(); |
5055 | cbradney | 940 | //<<#3524 |
10585 | fschmid | 941 | activateWindow(); |
14754 | jghali | 942 | if (!m_ScMW->scriptIsRunning()) |
11960 | subik | 943 | raise(); |
13950 | fschmid | 944 | m_ScMW->newActWin(((ScribusWin*)(Doc->WinHan))->getSubWin()); |
5055 | cbradney | 945 | updateContents(); |
946 | //>> |
||
15556 | fschmid | 947 | QFileInfo fi; |
948 | QString ext = ""; |
||
949 | if (!e->mimeData()->formats().contains("application/x-scribus-elem")) |
||
950 | { |
||
951 | fi.setFile(url.toLocalFile()); |
||
952 | ext = fi.suffix().toUpper(); |
||
953 | } |
||
954 | // QFileInfo fi(url.toLocalFile()); |
||
955 | // QString ext = fi.suffix().toUpper(); |
||
9380 | fschmid | 956 | QStringList imfo; |
957 | QList<QByteArray> imgs = QImageReader::supportedImageFormats(); |
||
958 | for (int i = 0; i < imgs.count(); ++i ) |
||
959 | { |
||
11486 | avox | 960 | imfo.append(QString(imgs.at(i)).toUpper()); |
9380 | fschmid | 961 | } |
456 | fschmid | 962 | if (ext == "JPG") |
963 | ext = "JPEG"; |
||
4020 | cbradney | 964 | //CB Need to handle this ugly file extension list elsewhere... some capabilities class perhaps |
11486 | avox | 965 | img = ((imfo.contains(ext)) || extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext) || extensionIndicatesTIFF(ext) || extensionIndicatesJPEG(ext) || extensionIndicatesPSD(ext)); |
11475 | avox | 966 | // int pscx=qRound(e->pos().x()/m_canvas->scale()), pscy=qRound(e->pos().y()/m_canvas->scale()); |
4019 | cbradney | 967 | //Loop through all items and see which one(s) were under the drop point on the current layer |
968 | //Should make a nice function for this. |
||
15007 | jghali | 969 | //#9051 : loop in reverse order so that items in front of others are prioritized |
13920 | fschmid | 970 | Doc->m_Selection->delaySignalsOn(); |
15007 | jghali | 971 | for (int i = Doc->Items->count() - 1; i >= 0 ; --i) |
4019 | cbradney | 972 | { |
13875 | jghali | 973 | if (Doc->Items->at(i)->LayerID==Doc->activeLayer()) |
4019 | cbradney | 974 | { |
11509 | fschmid | 975 | if (m_canvas->frameHitTest(dropPosDocQ, Doc->Items->at(i)) >= Canvas::INSIDE) |
4019 | cbradney | 976 | { |
977 | Deselect(false); |
||
13278 | fschmid | 978 | Doc->m_Selection->addItem(Doc->Items->at(i)); |
979 | // SelectItem(Doc->Items->at(i)); |
||
4019 | cbradney | 980 | selectedItemByDrag=true; |
981 | break; |
||
982 | } |
||
983 | } |
||
984 | } |
||
13920 | fschmid | 985 | Doc->m_Selection->delaySignalsOff(); |
12061 | fschmid | 986 | bool vectorFile = false; |
987 | if (fi.exists()) |
||
988 | { |
||
16171 | fschmid | 989 | if (fi.suffix().toLower() == "sce") |
12061 | fschmid | 990 | vectorFile = true; |
991 | else |
||
992 | { |
||
993 | FileLoader *fileLoader = new FileLoader(url.toLocalFile()); |
||
17326 | jghali | 994 | int testResult = fileLoader->testFile(); |
12061 | fschmid | 995 | delete fileLoader; |
18297 | fschmid | 996 | if ((testResult != -1) && (testResult >= FORMATID_FIRSTUSER)) |
12061 | fschmid | 997 | vectorFile = true; |
998 | } |
||
999 | } |
||
1000 | else |
||
1001 | { |
||
1002 | if ((text.startsWith("<SCRIBUSELEM")) || (text.startsWith("SCRIBUSFRAGMENT"))) |
||
1003 | vectorFile = true; |
||
1004 | } |
||
12110 | fschmid | 1005 | // qDebug() << "drop - img:" << img << "file:" << fi.exists() << "suffix:" << fi.suffix() << "select by drag:" << selectedItemByDrag; |
1006 | //CB When we drag an image to a page from outside |
||
1007 | //SeleItemPos is from 1.2.x. Needs reenabling for dragging *TO* a frame |
||
1008 | if ((fi.exists()) && (img) && !selectedItemByDrag && !vectorFile)// && (!SeleItemPos(e->pos()))) |
||
1009 | { |
||
17054 | fschmid | 1010 | int z = Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, dropPosDoc.x(), dropPosDoc.y(), 1, 1, Doc->itemToolPrefs().shapeLineWidth, Doc->itemToolPrefs().imageFillColor, Doc->itemToolPrefs().imageStrokeColor, true); |
12110 | fschmid | 1011 | PageItem *b = Doc->Items->at(z); |
13875 | jghali | 1012 | b->LayerID = Doc->activeLayer(); |
16943 | fschmid | 1013 | Doc->loadPict(url.toLocalFile(), b); |
12110 | fschmid | 1014 | b->setWidth(static_cast<double>(b->OrigW * 72.0 / b->pixm.imgInfo.xres)); |
1015 | b->setHeight(static_cast<double>(b->OrigH * 72.0 / b->pixm.imgInfo.yres)); |
||
1016 | b->OldB2 = b->width(); |
||
1017 | b->OldH2 = b->height(); |
||
1018 | b->updateClip(); |
||
18238 | fschmid | 1019 | b->AdjustPictScale(); |
12110 | fschmid | 1020 | emit DocChanged(); |
1021 | update(); |
||
1022 | return; |
||
1023 | } |
||
4019 | cbradney | 1024 | //if ((SeleItemPos(e->pos())) && (!text.startsWith("<SCRIBUSELEM"))) |
12505 | fschmid | 1025 | // if (Doc->m_Selection->count()>0 && (m_canvas->frameHitTest(dropPosDocQ, Doc->m_Selection->itemAt(0)) >= Canvas::INSIDE) && !vectorFile) // && (img)) |
1026 | if (selectedItemByDrag && (m_canvas->frameHitTest(dropPosDocQ, Doc->m_Selection->itemAt(0)) >= Canvas::INSIDE) && ((!vectorFile) || (img))) |
||
456 | fschmid | 1027 | { |
4847 | cbradney | 1028 | PageItem *b = Doc->m_Selection->itemAt(0); |
4494 | cbradney | 1029 | if (b->itemType() == PageItem::ImageFrame) |
456 | fschmid | 1030 | { |
4494 | cbradney | 1031 | if ((fi.exists()) && (img)) |
16943 | fschmid | 1032 | Doc->loadPict(url.toLocalFile(), b); |
4494 | cbradney | 1033 | } |
11806 | fschmid | 1034 | else if (b->itemType() == PageItem::TextFrame) |
4494 | cbradney | 1035 | { |
11806 | fschmid | 1036 | if ((fi.exists()) && (!img)) |
4494 | cbradney | 1037 | { |
11806 | fschmid | 1038 | QByteArray file; |
1039 | QTextCodec *codec = QTextCodec::codecForLocale(); |
||
1040 | // TODO create a Dialog for selecting the codec |
||
12838 | jghali | 1041 | if (loadRawText(url.toLocalFile(), file)) |
456 | fschmid | 1042 | { |
11806 | fschmid | 1043 | QString txt = codec->toUnicode( file.data() ); |
1044 | txt.replace(QRegExp("\r"), QChar(13)); |
||
1045 | txt.replace(QRegExp("\n"), QChar(13)); |
||
1046 | txt.replace(QRegExp("\t"), QChar(9)); |
||
16626 | jghali | 1047 | b->itemText.insertChars(txt, true); |
11806 | fschmid | 1048 | if (Doc->docHyphenator->AutoCheck) |
1049 | Doc->docHyphenator->slotHyphenate(b); |
||
1050 | b->invalidateLayout(); |
||
1051 | b->update(); |
||
456 | fschmid | 1052 | } |
1053 | } |
||
11806 | fschmid | 1054 | } |
1055 | emit DocChanged(); |
||
1056 | update(); |
||
456 | fschmid | 1057 | } |
1058 | else |
||
4042 | subik | 1059 | { |
9820 | fschmid | 1060 | Deselect(true); |
3934 | cbradney | 1061 | uint oldDocItemCount = Doc->Items->count(); |
12110 | fschmid | 1062 | if (((!img) || (vectorFile)) && (Doc->DraggedElem == 0)) |
1163 | fschmid | 1063 | { |
11576 | avox | 1064 | activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::Create,"",Um::ICreate)); |
12110 | fschmid | 1065 | if (fi.exists()) |
7289 | fschmid | 1066 | { |
1067 | QString data; |
||
16171 | fschmid | 1068 | if (fi.suffix().toLower() == "sce") |
7289 | fschmid | 1069 | { |
12045 | jghali | 1070 | emit LoadElem(url.toLocalFile(), dropPosDoc.x(), dropPosDoc.y(), true, false, Doc, this); |
10878 | fschmid | 1071 | } |
7289 | fschmid | 1072 | else |
10878 | fschmid | 1073 | { |
12045 | jghali | 1074 | FileLoader *fileLoader = new FileLoader(url.toLocalFile()); |
17326 | jghali | 1075 | int testResult = fileLoader->testFile(); |
10878 | fschmid | 1076 | delete fileLoader; |
18297 | fschmid | 1077 | if ((testResult != -1) && (testResult >= FORMATID_FIRSTUSER)) |
10878 | fschmid | 1078 | { |
1079 | const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult); |
||
1080 | if( fmt ) |
||
1081 | { |
||
13384 | jghali | 1082 | // We disable undo here as we are only interested by the item creation undo actions |
1083 | // We create them manually after import |
||
1084 | undoManager->setUndoEnabled(false); |
||
17245 | fschmid | 1085 | Doc->dontResize = true; |
12045 | jghali | 1086 | fmt->loadFile(url.toLocalFile(), LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted); |
13384 | jghali | 1087 | undoManager->setUndoEnabled(true); |
12110 | fschmid | 1088 | if (Doc->m_Selection->count() > 0) |
10878 | fschmid | 1089 | { |
13384 | jghali | 1090 | if (UndoManager::undoEnabled()) |
1091 | { |
||
1092 | // Create undo actions for created items |
||
1093 | for (int i = 0; i < Doc->m_Selection->count(); ++i) |
||
1094 | { |
||
1095 | PageItem* newItem = Doc->m_Selection->itemAt(i); |
||
16729 | fschmid | 1096 | ScItemState<PageItem*> *is = new ScItemState<PageItem*>("Create PageItem"); |
13384 | jghali | 1097 | is->set("CREATE_ITEM", "create_item"); |
1098 | is->setItem(newItem); |
||
1099 | //Undo target rests with the Page for object specific undo |
||
1100 | int pindex = (newItem->OwnPage > -1) ? newItem->OwnPage : 0; |
||
1101 | UndoObject *target = Doc->Pages->at(pindex); |
||
1102 | undoManager->action(target, is); |
||
1103 | } |
||
1104 | } |
||
10878 | fschmid | 1105 | double x2, y2, w, h; |
13384 | jghali | 1106 | // We disable undo temporarily as move actions are not necessary |
1107 | // to perform undo correctly here |
||
1108 | undoManager->setUndoEnabled(false); |
||
10878 | fschmid | 1109 | Doc->m_Selection->getGroupRect(&x2, &y2, &w, &h); |
11490 | avox | 1110 | Doc->moveGroup(dropPosDoc.x() - x2, dropPosDoc.y() - y2); |
16546 | jghali | 1111 | m_ScMW->requestUpdate(reqColorsUpdate | reqSymbolsUpdate | reqTextStylesUpdate | reqLineStylesUpdate); |
13384 | jghali | 1112 | undoManager->setUndoEnabled(true); |
10878 | fschmid | 1113 | } |
17245 | fschmid | 1114 | Doc->dontResize = false; |
10878 | fschmid | 1115 | } |
1116 | } |
||
1117 | } |
||
7289 | fschmid | 1118 | } |
11960 | subik | 1119 | else |
11486 | avox | 1120 | { |
11475 | avox | 1121 | emit LoadElem(QString(text), dropPosDoc.x(), dropPosDoc.y(), false, false, Doc, this); |
11486 | avox | 1122 | } |
9764 | jghali | 1123 | Selection tmpSelection(this, false); |
11729 | jghali | 1124 | tmpSelection.copy(*Doc->m_Selection, true); |
9856 | fschmid | 1125 | for (int as = oldDocItemCount; as < Doc->Items->count(); ++as) |
2233 | fschmid | 1126 | { |
3727 | cbradney | 1127 | currItem = Doc->Items->at(as); |
6431 | fschmid | 1128 | Doc->setRedrawBounding(currItem); |
9764 | jghali | 1129 | tmpSelection.addItem(currItem, true); |
2233 | fschmid | 1130 | if (currItem->isBookmark) |
1131 | emit AddBM(currItem); |
||
1132 | } |
||
11729 | jghali | 1133 | Doc->m_Selection->copy(tmpSelection, false); |
11576 | avox | 1134 | activeTransaction->commit(); |
1135 | delete activeTransaction; |
||
1136 | activeTransaction = NULL; |
||
1163 | fschmid | 1137 | } |
456 | fschmid | 1138 | else |
1139 | { |
||
1140 | if (Doc->DraggedElem != 0) |
||
1141 | { |
||
1142 | if (!Doc->leaveDrag) |
||
1143 | { |
||
9800 | cbradney | 1144 | QMenu *pmen = new QMenu(); |
10585 | fschmid | 1145 | pmen->addAction( tr("Copy Here")); |
1146 | QAction* mov = pmen->addAction( tr("Move Here")); |
||
1147 | pmen->addAction( tr("Cancel")); |
||
8573 | jghali | 1148 | for (int dre=0; dre<Doc->DragElements.count(); ++dre) |
6271 | fschmid | 1149 | { |
16943 | fschmid | 1150 | if (Doc->DragElements[dre]->locked()) |
6271 | fschmid | 1151 | { |
10585 | fschmid | 1152 | mov->setEnabled(false); |
6271 | fschmid | 1153 | break; |
1154 | } |
||
1155 | } |
||
9800 | cbradney | 1156 | re = pmen->actions().indexOf(pmen->exec(QCursor::pos())); |
456 | fschmid | 1157 | delete pmen; |
3708 | cbradney | 1158 | pmen=NULL; |
456 | fschmid | 1159 | } |
1160 | else |
||
1161 | re = 1; |
||
1162 | if ((re == 2) || (re == -1)) |
||
1163 | { |
||
1164 | updateContents(); |
||
1165 | return; |
||
1166 | } |
||
1167 | if ((re == 1) || (Doc->leaveDrag)) |
||
1168 | { |
||
9856 | fschmid | 1169 | QList<PageItem*> pasted; |
11475 | avox | 1170 | emit LoadElem(QString(text), dropPosDoc.x(), dropPosDoc.y(), false, false, Doc, this); |
9856 | fschmid | 1171 | for (int as = oldDocItemCount; as < Doc->Items->count(); ++as) |
456 | fschmid | 1172 | { |
3727 | cbradney | 1173 | pasted.append(Doc->Items->at(as)); |
456 | fschmid | 1174 | } |
9764 | jghali | 1175 | Selection tmpSelection(this, false); |
11729 | jghali | 1176 | tmpSelection.copy(*Doc->m_Selection, true); |
8573 | jghali | 1177 | for (int dre=0; dre<Doc->DragElements.count(); ++dre) |
456 | fschmid | 1178 | { |
16943 | fschmid | 1179 | tmpSelection.addItem(Doc->DragElements[dre], true); |
456 | fschmid | 1180 | } |
11729 | jghali | 1181 | Doc->m_Selection->copy(tmpSelection, false); |
456 | fschmid | 1182 | PageItem* bb; |
1183 | int fin; |
||
8573 | jghali | 1184 | for (int dre=0; dre<Doc->DragElements.count(); ++dre) |
456 | fschmid | 1185 | { |
1186 | bb = pasted.at(dre); |
||
4847 | cbradney | 1187 | currItem = Doc->m_Selection->itemAt(dre); |
7994 | avox | 1188 | if ((currItem->asTextFrame()) && ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0))) |
456 | fschmid | 1189 | { |
7994 | avox | 1190 | PageItem* before = currItem->prevInChain(); |
1191 | PageItem* after = currItem->nextInChain(); |
||
1192 | currItem->unlink(); |
||
1193 | if (before != 0) |
||
456 | fschmid | 1194 | { |
7994 | avox | 1195 | fin = Doc->m_Selection->findItem(before); |
456 | fschmid | 1196 | if (fin != -1) |
7994 | avox | 1197 | before = pasted.at(fin); |
1198 | before->unlink(); |
||
1199 | before->link(bb); |
||
456 | fschmid | 1200 | } |
7994 | avox | 1201 | if (after != 0) |
456 | fschmid | 1202 | { |
7994 | avox | 1203 | fin = Doc->m_Selection->findItem(after); |
456 | fschmid | 1204 | if (fin != -1) |
11960 | subik | 1205 | after = pasted.at(fin); |
7994 | avox | 1206 | bb->link(after); |
456 | fschmid | 1207 | } |
1208 | } |
||
1209 | } |
||
1210 | pasted.clear(); |
||
4707 | cbradney | 1211 | Doc->itemSelection_DeleteItem(); |
456 | fschmid | 1212 | } |
1213 | } |
||
1214 | if ((!img) && ((re == 0))) |
||
11475 | avox | 1215 | emit LoadElem(QString(text), dropPosDoc.x(), dropPosDoc.y(), false, false, Doc, this); |
456 | fschmid | 1216 | Doc->DraggedElem = 0; |
1217 | Doc->DragElements.clear(); |
||
9764 | jghali | 1218 | Selection tmpSelection(this, false); |
11729 | jghali | 1219 | tmpSelection.copy(*Doc->m_Selection, true); |
9856 | fschmid | 1220 | for (int as = oldDocItemCount; as < Doc->Items->count(); ++as) |
456 | fschmid | 1221 | { |
3727 | cbradney | 1222 | currItem = Doc->Items->at(as); |
6431 | fschmid | 1223 | Doc->setRedrawBounding(currItem); |
9764 | jghali | 1224 | tmpSelection.addItem(currItem, true); |
2193 | fschmid | 1225 | if (currItem->isBookmark) |
1226 | emit AddBM(currItem); |
||
456 | fschmid | 1227 | } |
11729 | jghali | 1228 | Doc->m_Selection->copy(tmpSelection, false); |
456 | fschmid | 1229 | } |
4847 | cbradney | 1230 | if (Doc->m_Selection->count() > 1) |
3640 | fschmid | 1231 | { |
6593 | fschmid | 1232 | Doc->m_Selection->connectItemToGUI(); |
7575 | cbradney | 1233 | Doc->m_Selection->setGroupRect(); |
6289 | fschmid | 1234 | double gx, gy, gh, gw; |
7575 | cbradney | 1235 | Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
6289 | fschmid | 1236 | double nx = gx; |
1237 | double ny = gy; |
||
17744 | craig | 1238 | if (!Doc->ApplyGuides(&nx, &ny) && !Doc->ApplyGuides(&nx, &ny,true)) |
6289 | fschmid | 1239 | { |
1240 | FPoint npx; |
||
1241 | npx = Doc->ApplyGridF(FPoint(nx, ny)); |
||
1242 | nx = npx.x(); |
||
1243 | ny = npx.y(); |
||
1244 | } |
||
11576 | avox | 1245 | activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::Move,"",Um::IMove)); |
11490 | avox | 1246 | Doc->moveGroup(nx-gx, ny-gy, false); |
7575 | cbradney | 1247 | Doc->m_Selection->setGroupRect(); |
1248 | Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
||
6289 | fschmid | 1249 | nx = gx+gw; |
1250 | ny = gy+gh; |
||
7736 | cbradney | 1251 | Doc->ApplyGuides(&nx, &ny); |
17744 | craig | 1252 | Doc->ApplyGuides(&nx, &ny,true); |
11490 | avox | 1253 | Doc->moveGroup(nx-(gx+gw), ny-(gy+gh), false); |
7575 | cbradney | 1254 | Doc->m_Selection->setGroupRect(); |
1255 | Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
||
10390 | cbradney | 1256 | for (int a = 0; a < Doc->m_Selection->count(); ++a) |
6368 | fschmid | 1257 | { |
1258 | PageItem *currItem = Doc->m_Selection->itemAt(a); |
||
13875 | jghali | 1259 | currItem->LayerID = Doc->activeLayer(); |
6368 | fschmid | 1260 | currItem->gXpos = currItem->xPos() - gx; |
1261 | currItem->gYpos = currItem->yPos() - gy; |
||
1262 | currItem->gWidth = gw; |
||
1263 | currItem->gHeight = gh; |
||
1264 | } |
||
11576 | avox | 1265 | activeTransaction->commit(); |
1266 | delete activeTransaction; |
||
1267 | activeTransaction = NULL; |
||
16546 | jghali | 1268 | emit ItemGeom(); |
3640 | fschmid | 1269 | } |
11806 | fschmid | 1270 | else if (Doc->m_Selection->count() == 1) |
6289 | fschmid | 1271 | { |
6593 | fschmid | 1272 | Doc->m_Selection->connectItemToGUI(); |
6289 | fschmid | 1273 | currItem = Doc->m_Selection->itemAt(0); |
13875 | jghali | 1274 | currItem->LayerID = Doc->activeLayer(); |
18027 | jghali | 1275 | if (Doc->SnapGrid) |
6289 | fschmid | 1276 | { |
1277 | double nx = currItem->xPos(); |
||
1278 | double ny = currItem->yPos(); |
||
17744 | craig | 1279 | if (!Doc->ApplyGuides(&nx, &ny) && !Doc->ApplyGuides(&nx, &ny,true)) |
6289 | fschmid | 1280 | { |
1281 | FPoint npx; |
||
1282 | npx = Doc->ApplyGridF(FPoint(nx, ny)); |
||
1283 | nx = npx.x(); |
||
1284 | ny = npx.y(); |
||
1285 | } |
||
7736 | cbradney | 1286 | Doc->MoveItem(nx-currItem->xPos(), ny-currItem->yPos(), currItem); |
6289 | fschmid | 1287 | } |
1288 | } |
||
16939 | jghali | 1289 | if ((Doc->m_Selection->count() > 0) && (Doc->appMode != modeNormal)) |
1290 | this->requestMode(modeNormal); |
||
3941 | cbradney | 1291 | updateContents(); |
4019 | cbradney | 1292 | } |
6236 | fschmid | 1293 | if (!Doc->masterPageMode()) |
1294 | { |
||
1295 | uint docPagesCount=Doc->Pages->count(); |
||
1296 | uint docCurrPageNo=Doc->currentPageNumber(); |
||
1297 | for (uint i = 0; i < docPagesCount; ++i) |
||
1298 | { |
||
11484 | fschmid | 1299 | double x = Doc->Pages->at(i)->xOffset(); |
1300 | double y = Doc->Pages->at(i)->yOffset(); |
||
1301 | double w = Doc->Pages->at(i)->width(); |
||
1302 | double h = Doc->Pages->at(i)->height(); |
||
1303 | if (QRectF(x, y, w, h).contains(dropPosDocQ)) |
||
6236 | fschmid | 1304 | { |
1305 | if (docCurrPageNo != i) |
||
1306 | { |
||
1307 | Doc->setCurrentPage(Doc->Pages->at(i)); |
||
1308 | setMenTxt(i); |
||
1309 | DrawNew(); |
||
1310 | } |
||
1311 | break; |
||
1312 | } |
||
1313 | } |
||
1314 | setRulerPos(contentsX(), contentsY()); |
||
1315 | } |
||
456 | fschmid | 1316 | } |
1317 | } |
||
1318 | |||
10532 | avox | 1319 | |
10560 | avox | 1320 | /* |
10532 | avox | 1321 | void ScribusView::normalizeSelectionRect() // unsused |
7618 | fschmid | 1322 | { |
1323 | if(Mxp > SeRx) |
||
1324 | { |
||
1325 | int tmp = SeRx; |
||
1326 | SeRx = Mxp; |
||
1327 | Mxp = tmp; |
||
1328 | } |
||
1329 | if(Myp > SeRy) |
||
1330 | { |
||
1331 | int tmp = SeRy; |
||
1332 | SeRy = Myp; |
||
1333 | Myp = tmp; |
||
1334 | } |
||
1335 | } |
||
10560 | avox | 1336 | */ |
7618 | fschmid | 1337 | |
6142 | tsoots | 1338 | |
7575 | cbradney | 1339 | void ScribusView::getDragRectScreen(double *x, double *y, double *w, double *h) |
456 | fschmid | 1340 | { |
10532 | avox | 1341 | QPoint in(qRound(dragX*m_canvas->scale()), qRound(dragY*m_canvas->scale())); |
1342 | // in -= QPoint(qRound(Doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(Doc->minCanvasCoordinate.y() * m_canvas->scale())); |
||
7575 | cbradney | 1343 | QPoint out = contentsToViewport(in); |
1344 | *x = static_cast<double>(out.x()); |
||
1345 | *y = static_cast<double>(out.y()); |
||
10532 | avox | 1346 | *w = dragW*m_canvas->scale(); |
1347 | *h = dragH*m_canvas->scale(); |
||
456 | fschmid | 1348 | } |
1349 | |||
1350 | void ScribusView::getGroupRectScreen(double *x, double *y, double *w, double *h) |
||
1351 | { |
||
7575 | cbradney | 1352 | double gx, gy, gh, gw; |
1353 | Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
||
10532 | avox | 1354 | QPoint in(qRound(gx*m_canvas->scale()), qRound(gy*m_canvas->scale())); |
1355 | // in -= QPoint(qRound(Doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(Doc->minCanvasCoordinate.y() * m_canvas->scale())); |
||
456 | fschmid | 1356 | QPoint out = contentsToViewport(in); |
1357 | *x = static_cast<double>(out.x()); |
||
1358 | *y = static_cast<double>(out.y()); |
||
10532 | avox | 1359 | *w = gw*m_canvas->scale(); |
1360 | *h = gh*m_canvas->scale(); |
||
456 | fschmid | 1361 | } |
1362 | |||
10701 | avox | 1363 | |
456 | fschmid | 1364 | |
6344 | jghali | 1365 | void ScribusView::RefreshGradient(PageItem *currItem, double dx, double dy) |
1366 | { |
||
13951 | fschmid | 1367 | QTransform matrix; |
10532 | avox | 1368 | QRect rect = currItem->getRedrawBounding(m_canvas->scale()); |
1369 | m_canvas->Transform(currItem, matrix); |
||
6344 | jghali | 1370 | FPointArray fpNew; |
14197 | fschmid | 1371 | if (editStrokeGradient) |
1372 | fpNew.setPoints(2, currItem->GrStrokeStartX, currItem->GrStrokeStartY, currItem->GrStrokeEndX, currItem->GrStrokeEndY); |
||
1373 | else |
||
1374 | fpNew.setPoints(2, currItem->GrStartX, currItem->GrStartY, currItem->GrEndX, currItem->GrEndY); |
||
6344 | jghali | 1375 | fpNew.map(matrix); |
1376 | if (dx < 8.0) dx = 8.0; |
||
1377 | if (dy < 8.0) dy = 8.0; |
||
8562 | jghali | 1378 | int grl = (int) floor( qMin(fpNew.point(0).x(), fpNew.point(1).x()) - dx ); |
1379 | int grr = (int) ceil ( qMax(fpNew.point(0).x(), fpNew.point(1).x()) + dx ); |
||
1380 | int grb = (int) ceil ( qMax(fpNew.point(0).y(), fpNew.point(1).y()) + dy ); |
||
1381 | int grt = (int) floor( qMin(fpNew.point(0).y(), fpNew.point(1).y()) - dy ); |
||
6344 | jghali | 1382 | rect |= QRect(grl, grt, grr-grl, grb-grt); |
1383 | updateContents(rect); |
||
1384 | } |
||
1385 | |||
456 | fschmid | 1386 | |
7571 | cbradney | 1387 | //CB-->elsewhere, util, however, only used in the view for now |
1388 | bool ScribusView::PointOnLine(QPoint Start, QPoint End, QRect MArea) |
||
456 | fschmid | 1389 | { |
1390 | QPoint an, en; |
||
7571 | cbradney | 1391 | if (Start.x() == End.x()) |
456 | fschmid | 1392 | { |
7571 | cbradney | 1393 | an = Start.y() > End.y() ? End : Start; |
1394 | en = an == End ? Start : End; |
||
456 | fschmid | 1395 | for (int a=an.y(); a<en.y(); ++a) |
1396 | { |
||
7571 | cbradney | 1397 | if (MArea.contains(an.x(), a)) |
456 | fschmid | 1398 | return true; |
1399 | } |
||
1400 | } |
||
7571 | cbradney | 1401 | if (Start.y() == End.y()) |
456 | fschmid | 1402 | { |
7571 | cbradney | 1403 | an = Start.x() > End.x() ? End : Start; |
1404 | en = an == End ? Start : End; |
||
456 | fschmid | 1405 | for (int a=an.x(); a<en.x(); ++a) |
1406 | { |
||
7571 | cbradney | 1407 | if (MArea.contains(a, an.y())) |
456 | fschmid | 1408 | return true; |
1409 | } |
||
1410 | } |
||
7571 | cbradney | 1411 | if (abs(Start.x() - End.x()) > abs(Start.y() - End.y())) |
456 | fschmid | 1412 | { |
7571 | cbradney | 1413 | an = Start.x() > End.x() ? End : Start; |
1414 | en = an == End ? Start : End; |
||
6046 | fschmid | 1415 | double stg = (en.y() - an.y()) / static_cast<double>((en.x() - an.x())); |
1416 | for (int a = an.x(); a < en.x(); ++a) |
||
1417 | { |
||
7571 | cbradney | 1418 | if (MArea.contains(a, an.y()+qRound((a-an.x())*stg))) |
6046 | fschmid | 1419 | return true; |
1420 | } |
||
456 | fschmid | 1421 | } |
6046 | fschmid | 1422 | else |
1423 | { |
||
7571 | cbradney | 1424 | an = Start.y() > End.y() ? End : Start; |
1425 | en = an == End ? Start : End; |
||
6046 | fschmid | 1426 | double stg = (en.x() - an.x()) / static_cast<double>((en.y() - an.y())); |
1427 | for (int a = an.y(); a < en.y(); ++a) |
||
1428 | { |
||
7571 | cbradney | 1429 | if (MArea.contains(an.x()+qRound((a-an.y())*stg), a)) |
6046 | fschmid | 1430 | return true; |
1431 | } |
||
1432 | } |
||
456 | fschmid | 1433 | return false; |
1434 | } |
||
1435 | |||
4704 | cbradney | 1436 | //CB-->Doc?? |
1510 | tsoots | 1437 | void ScribusView::TransformPoly(int mode, int rot, double scaling) |
456 | fschmid | 1438 | { |
4847 | cbradney | 1439 | PageItem *currItem = Doc->m_Selection->itemAt(0); |
1957 | cbradney | 1440 | currItem->ClipEdited = true; |
13951 | fschmid | 1441 | QTransform ma; |
17640 | craig | 1442 | undoManager->setUndoEnabled(false); |
10532 | avox | 1443 | if (Doc->nodeEdit.isContourLine) |
456 | fschmid | 1444 | { |
3993 | cbradney | 1445 | FPoint tp2(getMinClipF(&currItem->ContourLine)); |
1446 | FPoint tp(getMaxClipF(&currItem->ContourLine)); |
||
1957 | cbradney | 1447 | currItem->ContourLine.translate(-qRound((tp.x() + tp2.x()) / 2.0), -qRound((tp.y() + tp2.y()) / 2.0)); |
456 | fschmid | 1448 | switch (mode) |
1449 | { |
||
1450 | case 0: |
||
1451 | ma.rotate(-rot); |
||
1452 | break; |
||
1453 | case 1: |
||
1454 | ma.rotate(rot); |
||
1455 | break; |
||
1456 | case 2: |
||
1457 | ma.scale(1.0 - (scaling / 100.0), 1.0 - (scaling / 100.0)); |
||
1458 | break; |
||
1459 | case 3: |
||
1460 | ma.scale(1.0 + (scaling / 100.0), 1.0 + (scaling / 100.0)); |
||
1461 | break; |
||
1462 | case 4: |
||
1463 | ma.shear(0.017455, 0); |
||
1464 | break; |
||
1465 | case 5: |
||
1466 | ma.shear(-0.017455, 0); |
||
1467 | break; |
||
1468 | case 6: |
||
1469 | ma.shear(0, -0.017455); |
||
1470 | break; |
||
1471 | case 7: |
||
1472 | ma.shear(0, 0.017455); |
||
1473 | break; |
||
4619 | cbradney | 1474 | case 8: |
16673 | craig | 1475 | { |
1476 | double sx=(tp.x() - tp2.x() - scaling) / (tp.x() - tp2.x()); |
||
1477 | double sy=(tp.y() - tp2.y() - scaling) / (tp.y() - tp2.y()); |
||
1478 | ma.scale(sx, sy); |
||
1479 | } |
||
4619 | cbradney | 1480 | break; |
1481 | case 9: |
||
16673 | craig | 1482 | { |
1483 | double sx=(tp.x() - tp2.x() + scaling) / (tp.x() - tp2.x()); |
||
1484 | double sy=(tp.y() - tp2.y() + scaling) / (tp.y() - tp2.y()); |
||
1485 | ma.scale(sx, sy); |
||
1486 | } |
||
4619 | cbradney | 1487 | break; |
5429 | cbradney | 1488 | //10-13 are for scaling the contour line in shape edit mode |
1489 | case 10: |
||
1490 | { |
||
1491 | double s=1.0 - (scaling/(tp2.x() - tp.x())); |
||
1492 | ma.scale(s, 1); |
||
1493 | ma.translate(-scaling/s/2,0); |
||
1494 | } |
||
5287 | cbradney | 1495 | break; |
1496 | case 11: |
||
5429 | cbradney | 1497 | { |
1498 | double s=1.0 - (scaling/(tp2.x() - tp.x())); |
||
1499 | ma.scale(s, 1); |
||
1500 | ma.translate(scaling/s/2,0); |
||
1501 | } |
||
1502 | break; |
||
1503 | case 12: |
||
1504 | { |
||
1505 | double s=1.0 - (scaling/(tp2.y() - tp.y())); |
||
1506 | ma.scale(1, s); |
||
1507 | ma.translate(0,-scaling/s/2); |
||
1508 | } |
||
1509 | break; |
||
1510 | case 13: |
||
1511 | { |
||
1512 | double s=1.0 - (scaling/(tp2.y() - tp.y())); |
||
1513 | ma.scale(1, s); |
||
1514 | ma.translate(0,scaling/s/2); |
||
1515 | } |
||
1516 | break; |
||
456 | fschmid | 1517 | } |
1957 | cbradney | 1518 | currItem->ContourLine.map(ma); |
1519 | currItem->ContourLine.translate(qRound((tp.x() + tp2.x()) / 2.0), qRound((tp.y() + tp2.y()) / 2.0)); |
||
2183 | fschmid | 1520 | updateContents(); |
8179 | fschmid | 1521 | currItem->FrameOnly = true; |
10532 | avox | 1522 | updateContents(currItem->getRedrawBounding(m_canvas->scale())); |
17640 | craig | 1523 | undoManager->setUndoEnabled(true); |
1509 | tsoots | 1524 | if (UndoManager::undoEnabled()) |
1525 | { |
||
1526 | undoManager->setUndoEnabled(false); |
||
1957 | cbradney | 1527 | currItem->checkChanges(true); |
1509 | tsoots | 1528 | undoManager->setUndoEnabled(true); |
1529 | SimpleState *ss = new SimpleState(Um::EditContourLine, "", Um::IBorder); |
||
1530 | ss->set("EDIT_CONTOUR", "edit_contour"); |
||
1531 | ss->set("MODE", mode); |
||
1532 | ss->set("ROT", rot); |
||
1533 | ss->set("SCALING", scaling); |
||
1957 | cbradney | 1534 | undoManager->action(currItem, ss); |
1509 | tsoots | 1535 | } |
4078 | fschmid | 1536 | emit DocChanged(); |
456 | fschmid | 1537 | return; |
1538 | } |
||
3942 | cbradney | 1539 | FPoint oldPos(currItem->xyPos()); |
3934 | cbradney | 1540 | double offsX = currItem->width() / 2.0; |
1541 | double offsY = currItem->height() / 2.0; |
||
14815 | fschmid | 1542 | double oldWidth = currItem->width(); |
1543 | double oldHeight = currItem->height(); |
||
456 | fschmid | 1544 | ma.translate(-offsX, -offsY); |
1545 | switch (mode) |
||
1546 | { |
||
1547 | case 0: |
||
1548 | ma.rotate(-rot); |
||
1549 | break; |
||
1550 | case 1: |
||
1551 | ma.rotate(rot); |
||
1552 | break; |
||
1553 | case 2: |
||
1554 | ma.scale(1.0 - (scaling / 100.0), 1.0 - (scaling / 100.0)); |
||
1555 | break; |
||
1556 | case 3: |
||
1557 | ma.scale(1.0 + (scaling / 100.0), 1.0 + (scaling / 100.0)); |
||
1558 | break; |
||
1559 | case 4: |
||
1560 | ma.shear(0.017455, 0); |
||
1561 | break; |
||
1562 | case 5: |
||
1563 | ma.shear(-0.017455, 0); |
||
1564 | break; |
||
1565 | case 6: |
||
1566 | ma.shear(0, -0.017455); |
||
1567 | break; |
||
1568 | case 7: |
||
1569 | ma.shear(0, 0.017455); |
||
1570 | break; |
||
4619 | cbradney | 1571 | case 8: |
14815 | fschmid | 1572 | ma.scale(1.0 - (scaling / oldWidth),1.0 - (scaling / oldHeight)); |
4619 | cbradney | 1573 | break; |
1574 | case 9: |
||
14815 | fschmid | 1575 | ma.scale(1.0 + (scaling / oldWidth),1.0 + (scaling / oldHeight)); |
4619 | cbradney | 1576 | break; |
456 | fschmid | 1577 | } |
1957 | cbradney | 1578 | currItem->PoLine.map(ma); |
1579 | currItem->PoLine.translate(offsX, offsY); |
||
7736 | cbradney | 1580 | Doc->AdjustItemSize(currItem); |
13951 | fschmid | 1581 | QTransform ma2; |
456 | fschmid | 1582 | ma2.translate(oldPos.x(), oldPos.y()); |
1583 | ma2.scale(1, 1); |
||
1584 | ma2.translate(offsX, offsY); |
||
3993 | cbradney | 1585 | FPoint n(-offsX, -offsY); |
456 | fschmid | 1586 | switch (mode) |
1587 | { |
||
1588 | case 0: |
||
1589 | ma2.rotate(-rot); |
||
1590 | break; |
||
1591 | case 1: |
||
1592 | ma2.rotate(rot); |
||
1593 | break; |
||
1594 | case 2: |
||
1595 | ma2.scale(1.0 - (scaling / 100.0), 1.0 - (scaling / 100.0)); |
||
1596 | break; |
||
1597 | case 3: |
||
1598 | ma2.scale(1.0 + (scaling / 100.0), 1.0 + (scaling / 100.0)); |
||
1599 | break; |
||
1600 | case 4: |
||
1601 | ma2.shear(0.017455, 0); |
||
1602 | break; |
||
1603 | case 5: |
||
1604 | ma2.shear(-0.017455, 0); |
||
1605 | break; |
||
1606 | case 6: |
||
1607 | ma2.shear(0, -0.017455); |
||
1608 | break; |
||
1609 | case 7: |
||
1610 | ma2.shear(0, 0.017455); |
||
1611 | break; |
||
4619 | cbradney | 1612 | case 8: |
14815 | fschmid | 1613 | ma2.scale(1.0 - (scaling / oldWidth),1.0 - (scaling / oldHeight)); |
4619 | cbradney | 1614 | break; |
1615 | case 9: |
||
14815 | fschmid | 1616 | ma2.scale(1.0 + (scaling / oldWidth),1.0 + (scaling / oldHeight)); |
4619 | cbradney | 1617 | break; |
456 | fschmid | 1618 | } |
1619 | double x = ma2.m11() * n.x() + ma2.m21() * n.y() + ma2.dx(); |
||
1620 | double y = ma2.m22() * n.y() + ma2.m12() * n.x() + ma2.dy(); |
||
7736 | cbradney | 1621 | Doc->MoveItem(x-oldPos.x(), y-oldPos.y(), currItem); |
3625 | avox | 1622 | if (currItem->asPathText()) |
4688 | cbradney | 1623 | currItem->updatePolyClip(); |
4672 | cbradney | 1624 | Doc->setRedrawBounding(currItem); |
10701 | avox | 1625 | currItem->update(); |
9041 | fschmid | 1626 | // MarkClip(currItem, currItem->PoLine, true); |
1957 | cbradney | 1627 | currItem->FrameType = 3; |
17640 | craig | 1628 | undoManager->setUndoEnabled(true); |
1509 | tsoots | 1629 | if (UndoManager::undoEnabled()) |
1630 | { |
||
1631 | undoManager->setUndoEnabled(false); |
||
1957 | cbradney | 1632 | currItem->checkChanges(true); |
1509 | tsoots | 1633 | undoManager->setUndoEnabled(true); |
1634 | SimpleState *ss = new SimpleState(Um::EditShape, "", Um::IBorder); |
||
1635 | ss->set("EDIT_SHAPE", "edit_shape"); |
||
1636 | ss->set("MODE", mode); |
||
1637 | ss->set("ROT", rot); |
||
1638 | ss->set("SCALING", scaling); |
||
1957 | cbradney | 1639 | undoManager->action(currItem, ss); |
1509 | tsoots | 1640 | } |
4078 | fschmid | 1641 | emit DocChanged(); |
456 | fschmid | 1642 | } |
1643 | |||
1644 | bool ScribusView::slotSetCurs(int x, int y) |
||
1645 | { |
||
16856 | craig | 1646 | PageItem *item; |
1647 | if (!GetItem(&item)) |
||
1648 | return false; |
||
1649 | |||
1650 | PageItem_TextFrame *textFrame; |
||
1651 | QPointF canvasPoint; |
||
17119 | fschmid | 1652 | QTransform mm = item->getTransform(); |
1653 | QPointF textFramePoint = mm.map(QPointF(0, 0)); |
||
16856 | craig | 1654 | if (item->isTextFrame()) |
456 | fschmid | 1655 | { |
16856 | craig | 1656 | textFrame = item->asTextFrame(); |
1657 | canvasPoint = m_canvas->globalToCanvas(QPoint(x,y)).toQPointF(); |
||
1658 | } |
||
1659 | else if (item->isTable()) |
||
1660 | { |
||
1661 | // Move to cell under cursor and position the text cursor. |
||
1662 | PageItem_Table *table = item->asTable(); |
||
1663 | table->moveTo(table->cellAt(m_canvas->globalToCanvas(QPoint(x,y)).toQPointF())); |
||
1664 | textFrame = table->activeCell().textFrame(); |
||
1665 | canvasPoint = table->getTransform().inverted().map(m_canvas->globalToCanvas(QPoint(x, y)).toQPointF()) - table->gridOffset(); |
||
1666 | } |
||
1667 | else if (item->isImageFrame()) |
||
1668 | return true; |
||
1669 | else |
||
1670 | return false; |
||
16738 | jghali | 1671 | |
11960 | subik | 1672 | |
16856 | craig | 1673 | if (m_canvas->frameHitTest(canvasPoint, textFrame) == Canvas::INSIDE) |
1674 | { |
||
1675 | // #9592 : layout must be valid here, or screenToPosition() may crash |
||
1676 | if (textFrame->invalid) |
||
1677 | textFrame->layout(); |
||
17119 | fschmid | 1678 | double sx, sy; |
1679 | getScaleFromMatrix(mm, sx, sy); |
||
1680 | QTransform ms; |
||
1681 | ms.scale(sx, sy); |
||
16856 | craig | 1682 | if(textFrame->reversed()) |
1683 | { //handle Right to Left writing |
||
17119 | fschmid | 1684 | FPoint point(textFrame->width() * mm.m11() - (canvasPoint.x() - textFramePoint.x()), canvasPoint.y() - textFramePoint.y()); |
1685 | point = point.transformPoint(ms, true); |
||
16856 | craig | 1686 | textFrame->itemText.setCursorPosition(textFrame->itemText.length() == 0 ? 0 : |
1687 | textFrame->itemText.screenToPosition(point)); |
||
456 | fschmid | 1688 | } |
16856 | craig | 1689 | else |
1690 | { |
||
17119 | fschmid | 1691 | FPoint point(canvasPoint.x() - textFramePoint.x(), canvasPoint.y() - textFramePoint.y()); |
1692 | point = point.transformPoint(ms, true); |
||
16856 | craig | 1693 | textFrame->itemText.setCursorPosition(textFrame->itemText.length() == 0 ? 0 : |
1694 | textFrame->itemText.screenToPosition(point)); |
||
1695 | } |
||
1696 | |||
1697 | if (textFrame->itemText.length() > 0) |
||
1698 | { |
||
1699 | int pos = qMax(qMin(textFrame->itemText.cursorPosition() - 1, textFrame->itemText.length()), 0); |
||
1700 | Doc->currentStyle.charStyle() = textFrame->itemText.charStyle(pos); |
||
1701 | emit ItemCharStyle(Doc->currentStyle.charStyle()); |
||
1702 | emit ItemTextEffects(Doc->currentStyle.charStyle().effects()); |
||
1703 | emit ItemTextAlign(textFrame->itemText.paragraphStyle(pos).alignment()); |
||
1704 | return true; |
||
1705 | } |
||
1706 | else |
||
1707 | { |
||
1708 | Doc->currentStyle.charStyle() = textFrame->itemText.defaultStyle().charStyle(); |
||
1709 | emit ItemCharStyle(textFrame->itemText.defaultStyle().charStyle()); |
||
1710 | emit ItemTextEffects(textFrame->itemText.defaultStyle().charStyle().effects()); |
||
1711 | emit ItemTextAlign(0); |
||
1712 | return true; |
||
1713 | } |
||
456 | fschmid | 1714 | } |
1715 | return false; |
||
1716 | } |
||
1717 | |||
9391 | fschmid | 1718 | |
9668 | fschmid | 1719 | void ScribusView::dragTimerTimeOut() |
1720 | { |
||
10978 | avox | 1721 | m_dragTimerFired = true; |
13282 | pierre | 1722 | // #0007865 |
1723 | // qApp->changeOverrideCursor(QCursor(loadIcon("DragPix.xpm"))); |
||
9668 | fschmid | 1724 | } |
1725 | |||
9380 | fschmid | 1726 | void ScribusView::HandleCurs(PageItem *currItem, QRect mpo) |
456 | fschmid | 1727 | { |
1728 | QPoint tx, tx2; |
||
13951 | fschmid | 1729 | QTransform ma; |
10532 | avox | 1730 | // ma.translate(-Doc->minCanvasCoordinate.x()*m_canvas->scale(), -Doc->minCanvasCoordinate.y()*m_canvas->scale()); |
1731 | m_canvas->Transform(currItem, ma); |
||
9380 | fschmid | 1732 | tx = ma.map(QPoint(static_cast<int>(currItem->width()), 0)); |
1733 | tx2 = ma.map(QPoint(0, static_cast<int>(currItem->height()))); |
||
456 | fschmid | 1734 | if (mpo.contains(tx) || mpo.contains(tx2)) |
1735 | { |
||
2603 | cbradney | 1736 | if (Doc->appMode == modeRotation) |
18181 | fschmid | 1737 | setCursor(QCursor(loadIcon("Rotieren2.png"))); |
456 | fschmid | 1738 | else |
1739 | { |
||
3934 | cbradney | 1740 | double rr = fabs(currItem->rotation()); |
456 | fschmid | 1741 | if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) || ((rr >=315.0) && (rr <= 360.0))) |
18181 | fschmid | 1742 | setCursor(QCursor(Qt::SizeBDiagCursor)); |
456 | fschmid | 1743 | if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0))) |
18181 | fschmid | 1744 | setCursor(QCursor(Qt::SizeFDiagCursor)); |
456 | fschmid | 1745 | } |
1746 | } |
||
9380 | fschmid | 1747 | tx = ma.map(QPoint(static_cast<int>(currItem->width()), static_cast<int>(currItem->height())/2)); |
1748 | tx2 = ma.map(QPoint(0, static_cast<int>(currItem->height())/2)); |
||
456 | fschmid | 1749 | if (mpo.contains(tx) || mpo.contains(tx2)) |
1750 | { |
||
3934 | cbradney | 1751 | double rr = fabs(currItem->rotation()); |
456 | fschmid | 1752 | if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) || ((rr >= 315.0) && (rr <= 360.0))) |
18181 | fschmid | 1753 | setCursor(QCursor(Qt::SizeHorCursor)); |
456 | fschmid | 1754 | if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0))) |
18181 | fschmid | 1755 | setCursor(QCursor(Qt::SizeVerCursor)); |
456 | fschmid | 1756 | } |
9380 | fschmid | 1757 | tx = ma.map(QPoint(static_cast<int>(currItem->width())/2, 0)); |
1758 | tx2 = ma.map(QPoint(static_cast<int>(currItem->width())/2, static_cast<int>(currItem->height()))); |
||
456 | fschmid | 1759 | if (mpo.contains(tx) || mpo.contains(tx2)) |
1760 | { |
||
3934 | cbradney | 1761 | double rr = fabs(currItem->rotation()); |
456 | fschmid | 1762 | if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) || ((rr >= 315.0) && (rr <= 360.0))) |
18181 | fschmid | 1763 | setCursor(QCursor(Qt::SizeVerCursor)); |
456 | fschmid | 1764 | if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0))) |
18181 | fschmid | 1765 | setCursor(QCursor(Qt::SizeHorCursor)); |
456 | fschmid | 1766 | } |
9380 | fschmid | 1767 | tx = ma.map(QPoint(static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))); |
1768 | tx2 = ma.map(QPoint(0, 0)); |
||
456 | fschmid | 1769 | if (mpo.contains(tx) || mpo.contains(tx2)) |
1770 | { |
||
2603 | cbradney | 1771 | if (Doc->appMode == modeRotation) |
18181 | fschmid | 1772 | setCursor(QCursor(loadIcon("Rotieren2.png"))); |
17826 | craig | 1773 | else if (!currItem->sizeHLocked() && ! currItem->sizeVLocked()) |
456 | fschmid | 1774 | { |
3934 | cbradney | 1775 | double rr = fabs(currItem->rotation()); |
456 | fschmid | 1776 | if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) || |
1777 | ((rr >= 315.0) && (rr <= 360.0))) |
||
18181 | fschmid | 1778 | setCursor(QCursor(Qt::SizeFDiagCursor)); |
456 | fschmid | 1779 | if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0))) |
18181 | fschmid | 1780 | setCursor(QCursor(Qt::SizeBDiagCursor)); |
456 | fschmid | 1781 | } |
1782 | } |
||
10532 | avox | 1783 | if (Doc->appMode == modeEditClip) |
18181 | fschmid | 1784 | setCursor(QCursor(Qt::CrossCursor)); |
456 | fschmid | 1785 | } |
1786 | |||
6802 | subik | 1787 | void ScribusView::SelectItemNr(uint nr, bool draw, bool single) |
456 | fschmid | 1788 | { |
9856 | fschmid | 1789 | if (nr < static_cast<uint>(Doc->Items->count())) |
6587 | fschmid | 1790 | SelectItem(Doc->Items->at(nr), draw, single); |
1292 | tsoots | 1791 | } |
1792 | |||
4704 | cbradney | 1793 | //CB-->Doc/Fix |
3676 | cbradney | 1794 | void ScribusView::SelectItem(PageItem *currItem, bool draw, bool single) |
1292 | tsoots | 1795 | { |
3934 | cbradney | 1796 | if (!currItem->isSelected()) |
456 | fschmid | 1797 | { |
1427 | fschmid | 1798 | if (single) |
456 | fschmid | 1799 | { |
4847 | cbradney | 1800 | Doc->m_Selection->addItem(currItem); |
1957 | cbradney | 1801 | currItem->isSingleSel = true; |
16961 | fschmid | 1802 | updateContents(); |
1803 | // updateContents(currItem->getRedrawBounding(m_canvas->scale())); |
||
1427 | fschmid | 1804 | } |
1805 | else |
||
1806 | { |
||
16118 | fschmid | 1807 | Doc->m_Selection->addItem(currItem); |
1808 | if (draw) |
||
456 | fschmid | 1809 | { |
16118 | fschmid | 1810 | updateContents(currItem->getRedrawBounding(m_canvas->scale())); |
456 | fschmid | 1811 | } |
11960 | subik | 1812 | //CB FIXME/TODO We are surely prepending here and we have turned off |
4632 | cbradney | 1813 | //emitting in prepend below so do it here. |
4847 | cbradney | 1814 | //Doc->m_Selection->itemAt(0)->emitAllToGUI(); |
456 | fschmid | 1815 | } |
1816 | } |
||
1817 | if (draw) |
||
1818 | { |
||
16192 | fschmid | 1819 | if (Doc->m_Selection->count() > 0) |
456 | fschmid | 1820 | { |
7575 | cbradney | 1821 | Doc->m_Selection->setGroupRect(); |
456 | fschmid | 1822 | double x, y, w, h; |
7575 | cbradney | 1823 | Doc->m_Selection->getGroupRect(&x, &y, &w, &h); |
8704 | fschmid | 1824 | getGroupRectScreen(&x, &y, &w, &h); |
16961 | fschmid | 1825 | updateContents(); |
1826 | // updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10))); |
||
3946 | cbradney | 1827 | //CB move in here as the emitAllToGUI will do it otherwise |
16546 | jghali | 1828 | emit ItemGeom(); |
3946 | cbradney | 1829 | emit HaveSel(currItem->itemType()); |
456 | fschmid | 1830 | } |
3962 | cbradney | 1831 | //CB done by addItem for single selection or the frame data is already there |
1832 | //else |
||
3941 | cbradney | 1833 | //EmitValues(currItem); |
3962 | cbradney | 1834 | //currItem->emitAllToGUI(); |
456 | fschmid | 1835 | } |
1836 | } |
||
1837 | |||
1957 | cbradney | 1838 | bool ScribusView::GetItem(PageItem **currItem, int nr) |
456 | fschmid | 1839 | { |
4593 | cbradney | 1840 | int n=nr; |
1841 | if (n == -1) |
||
1842 | n=0; |
||
4847 | cbradney | 1843 | *(currItem) = Doc->m_Selection->itemAt(n); |
4593 | cbradney | 1844 | return (*(currItem)!=NULL); |
456 | fschmid | 1845 | } |
1846 | |||
4704 | cbradney | 1847 | //CB Remove bookmark interaction here, item/doc should do it |
456 | fschmid | 1848 | void ScribusView::Deselect(bool prop) |
1849 | { |
||
4847 | cbradney | 1850 | if (!Doc->m_Selection->isEmpty()) |
456 | fschmid | 1851 | { |
11086 | avox | 1852 | const double scale = m_canvas->scale(); |
4704 | cbradney | 1853 | PageItem* currItem=NULL; |
10390 | cbradney | 1854 | for (int a = 0; a < Doc->m_Selection->count(); ++a) |
456 | fschmid | 1855 | { |
4847 | cbradney | 1856 | currItem = Doc->m_Selection->itemAt(a); |
3625 | avox | 1857 | if ((currItem->asTextFrame()) && (currItem->isBookmark)) |
1957 | cbradney | 1858 | emit ChBMText(currItem); |
456 | fschmid | 1859 | } |
4847 | cbradney | 1860 | if (Doc->m_Selection->isMultipleSelection()) |
456 | fschmid | 1861 | { |
3445 | cbradney | 1862 | double x, y, w, h; |
7575 | cbradney | 1863 | Doc->m_Selection->getGroupRect(&x, &y, &w, &h); |
4847 | cbradney | 1864 | Doc->m_Selection->clear(); |
11086 | avox | 1865 | updateCanvas(x - 5/scale, y - 5/scale, w + 10/scale, h + 10/scale); |
456 | fschmid | 1866 | } |
1867 | else |
||
1291 | fschmid | 1868 | { |
11831 | fschmid | 1869 | currItem = Doc->m_Selection->itemAt(0); |
12848 | cbradney | 1870 | if (currItem != NULL) |
1871 | { |
||
1872 | currItem->itemText.deselectAll(); |
||
1873 | currItem->HasSel = false; |
||
1874 | } |
||
4847 | cbradney | 1875 | Doc->m_Selection->clear(); |
11831 | fschmid | 1876 | if (currItem != NULL) |
11086 | avox | 1877 | updateContents(currItem->getRedrawBounding(scale)); |
1291 | fschmid | 1878 | } |
456 | fschmid | 1879 | } |
13451 | jghali | 1880 | if (prop && !Doc->m_Selection->signalsDelayed()) |
456 | fschmid | 1881 | emit HaveSel(-1); |
1882 | } |
||
1883 | |||
1884 | |||
4704 | cbradney | 1885 | //CB-->Doc/Fix |
456 | fschmid | 1886 | void ScribusView::ToggleBookmark() |
1887 | { |
||
4847 | cbradney | 1888 | uint docSelectionCount=Doc->m_Selection->count(); |
3934 | cbradney | 1889 | if (docSelectionCount != 0) |
456 | fschmid | 1890 | { |
3934 | cbradney | 1891 | for (uint a = 0; a < docSelectionCount; ++a) |
456 | fschmid | 1892 | { |
17644 | craig | 1893 | UndoTransaction* activeTransaction = NULL; |
1894 | if (UndoManager::undoEnabled()) |
||
1895 | activeTransaction = new UndoTransaction(undoManager->beginTransaction()); |
||
4847 | cbradney | 1896 | PageItem* currItem = Doc->m_Selection->itemAt(a); |
3625 | avox | 1897 | if (currItem->asTextFrame()) |
456 | fschmid | 1898 | { |
1981 | cbradney | 1899 | if (currItem->OwnPage != -1) |
1904 | fschmid | 1900 | { |
1981 | cbradney | 1901 | bool old = currItem->isBookmark; |
17644 | craig | 1902 | currItem->setIsBookMark(!currItem->isBookmark); |
1981 | cbradney | 1903 | if (currItem->isBookmark) |
1904 | { |
||
4084 | cbradney | 1905 | currItem->setIsAnnotation(false); |
1981 | cbradney | 1906 | emit AddBM(currItem& |