kivio

kivio_view.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2004 theKompany.com & Dave Marotti,
4 * Peter Simonsson
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20#include <kprinter.h> // has to be first
21
22#include <iostream>
23#include <stdlib.h>
24#include <time.h>
25#include <assert.h>
26
27#include <tqlayout.h>
28#include <tqwidgetstack.h>
29#include <tqsplitter.h>
30#include <tqpushbutton.h>
31#include <tqradiobutton.h>
32#include <tqprintdialog.h>
33#include <tqptrcollection.h>
34#include <tqkeycode.h>
35#include <tqcheckbox.h>
36#include <tqmime.h>
37#include <tqtoolbutton.h>
38#include <tqtimer.h>
39#include <tqbutton.h>
40#include <tqclipboard.h>
41#include <tqprogressbar.h>
42
43#include <tqstringlist.h>
44#include <tqstrlist.h>
45#include <tqimage.h>
46#include <tdefiledialog.h>
47
48#include <kdialogbase.h>
49#include <tdeaction.h>
50#include <kcolorbutton.h>
51#include <tdeapplication.h>
52#include <tdelocale.h>
53#include <kiconloader.h>
54#include <tdestdaccel.h>
55#include <kstdaction.h>
56#include <tdeglobal.h>
57#include <tdemessagebox.h>
58#include <kdebug.h>
59#include <tdeglobalsettings.h>
60#include <kstatusbar.h>
61#include <kinputdialog.h>
62#include <knotifyclient.h>
63
64#include <dcopclient.h>
65#include <dcopref.h>
66
67#include <tdeparts/event.h>
68#include <KoPartSelectDia.h>
69#include <KoQueryTrader.h>
70#include <KoPageLayoutDia.h>
71#include <KoRuler.h>
72#include <KoZoomHandler.h>
73#include <KoUnitWidgets.h>
74#include <KoApplication.h>
75#include <KoTabBar.h>
76#include <Kolinewidthaction.h>
77#include <Kolinestyleaction.h>
78#include <kopalettemanager.h>
79#include <KoGuideLineDia.h>
80
81#include "kivio_view.h"
82#include "kivio_dlg_pageshow.h"
83#include "kivio_factory.h"
84#include "kivio_map.h"
85#include "kivio_page.h"
86#include "kivio_doc.h"
87#include "kivio_canvas.h"
88#include "kivio_stencil_spawner.h"
89#include "kivio_grid_data.h"
90
91#include "tkcoloractions.h"
92
93#include "kivio_protection_panel.h"
94#include "kivio_stencil_geometry_panel.h"
95#include "kivio_layer_panel.h"
96#include "kivio_birdeye_panel.h"
97#include "export_page_dialog.h"
98
99#include "kivioaligndialog.h"
100#include "kiviooptionsdialog.h"
101
102#include "stencilbardockmanager.h"
103#include "kivio_common.h"
104#include "kivio_painter.h"
105#include "kivio_stencil.h"
106#include "kivio_stencil_spawner_set.h"
107#include "kivio_screen_painter.h"
108
109#include "kivio_pluginmanager.h"
110
111#include "kivio_stackbar.h"
112#include "kivio_icon_view.h"
113
114#include "KIvioViewIface.h"
115#include "kivio_command.h"
116#include "kiviostencilsetaction.h"
117#include <tqiconview.h>
118#include "kivioarrowheadaction.h"
119#include "kiviotextformatdlg.h"
120#include "kiviostencilformatdlg.h"
121#include "kivioarrowheadformatdlg.h"
122#include "kiviodragobject.h"
123#include "kivioglobal.h"
124#include "kivio_config.h"
125#include "kivioaddstencilsetpanel.h"
126#include "kiviostencilsetinstaller.h"
127#include "addstenciltool.h"
128#include "objectlistpalette.h"
129#include "addstencilsetdialog.h"
130
131#define TOGGLE_ACTION(X) ((TDEToggleAction*)actionCollection()->action(X))
132#define MOUSEPOS_TEXT 1000
133#define PAGECOUNT_TEXT 0
134#define INFO_TEXT 1
135
136using namespace Kivio;
137
138KivioView::KivioView( TQWidget *_parent, const char *_name, KivioDoc* doc )
139: KoView( doc, _parent, _name )
140{
141 m_bShowGuides = true;
142 m_bSnapGuides = true;
143 m_addStencilSetDialog = 0;
144 m_pluginManager = new PluginManager(this, "Kivio Plugin Manager");
145 m_addStencilTool = new Kivio::AddStencilTool(this);
146 m_pPaletteManager = new KoPaletteManager(this, actionCollection(), "kivio palette manager");
147 m_zoomHandler = new KoZoomHandler();
148 zoomHandler()->setZoomAndResolution(100, KoGlobal::dpiX(), KoGlobal::dpiY());
149 m_pDoc = doc;
150 m_pActivePage = 0;
151 dcop = 0;
152 dcopObject(); // build it
153
154 if(KStatusBar* sb = statusBar()) { // No statusbar in e.g. konqueror
155 m_pageCountSLbl = new KStatusBarLabel(i18n("%1 current page, %2 total number of pages",
156 "Page %1/%2").arg(0).arg(0), PAGECOUNT_TEXT, sb);
157 addStatusBarItem(m_pageCountSLbl, 0, false);
158
159 m_infoSLbl = new KStatusBarLabel("", INFO_TEXT, sb);
160 addStatusBarItem(m_infoSLbl, 10, false);
161
162 // Add coords to the statusbar
163 TQString unit = KoUnit::unitName(m_pDoc->unit());
164 KoPoint xy(0, 0);
165 TQString text = i18n("%1 x coord, %2 y coord, %3 and %4 the unit",
166 "X: %1 %3 Y: %2 %4").arg(TDEGlobal::_locale->formatNumber(xy.x(), 2))
167 .arg(TDEGlobal::_locale->formatNumber(xy.y(), 2)).arg(unit).arg(unit);
168 m_coordSLbl = new KStatusBarLabel(text, MOUSEPOS_TEXT, sb);
169 addStatusBarItem(m_coordSLbl, 0, true);
170 }
171
172 // Handle progress information from the doc
173 m_statusBarProgress = 0;
174
175 connect(m_pDoc, TQ_SIGNAL(initProgress()), this, TQ_SLOT(initStatusBarProgress()));
176 connect(m_pDoc, TQ_SIGNAL(progress(int)), this, TQ_SLOT(setStatusBarProgress(int)));
177 connect(m_pDoc, TQ_SIGNAL(endProgress()), this, TQ_SLOT(removeStatusBarProgress()));
178
179 bool isModified = doc->isModified();
180 m_pStencilBarDockManager = new StencilBarDockManager(this);
181
182 // TQGridLayout for the entire view
183 TQGridLayout *viewGrid = new TQGridLayout(this);
184
185 // A widget to hold the entire right side (old view)
186 TQWidget *pRightSide = new TQWidget(this);
187 viewGrid->addWidget(pRightSide, 0, 0);
188
189 // Split tabbar and Horz. Scroll Bar
190 TQSplitter* tabSplit = new TQSplitter(pRightSide);
191
192 // Tab Bar
193 m_pTabBar = new KoTabBar(tabSplit);
194 connect( m_pTabBar,
195 TQ_SIGNAL(tabChanged(const TQString&)),
196 TQ_SLOT( changePage(const TQString&)));
197 connect( m_pTabBar, TQ_SIGNAL( doubleClicked() ), TQ_SLOT( renamePage() ) );
198 connect( m_pTabBar, TQ_SIGNAL( contextMenu( const TQPoint& ) ),
199 TQ_SLOT( popupTabBarMenu( const TQPoint& ) ) );
200 connect(m_pTabBar, TQ_SIGNAL(tabMoved(unsigned, unsigned)), this, TQ_SLOT(moveTab(unsigned, unsigned)));
201 m_pTabBar->setReverseLayout( TQApplication::reverseLayout() );
202
203 // Scroll Bar
204 m_vertScrollBar = new TQScrollBar(TQt::Vertical,pRightSide);
205 m_horzScrollBar = new TQScrollBar(TQt::Horizontal,tabSplit);
206
207 TQValueList<int> sizes;
208 sizes << tabSplit->width() / 2 << tabSplit->width() / 2;
209 tabSplit->setSizes(sizes);
210 TQHBoxLayout* tabLayout = new TQHBoxLayout();
211 tabLayout->addWidget(tabSplit);
212
213 // The widget on which we display the page
214 TQWidgetStack* canvasBase = new TQWidgetStack(pRightSide);
215 m_pCanvas = new KivioCanvas(canvasBase,this,doc,m_vertScrollBar,m_horzScrollBar);
216 canvasBase->addWidget(m_pCanvas,0);
217 canvasBase->raiseWidget(m_pCanvas);
218 m_pCanvas->setFocusPolicy(TQWidget::StrongFocus);
219
220 // Rulers
221 vRuler = new KoRuler(pRightSide, m_pCanvas, TQt::Vertical, Kivio::Config::defaultPageLayout(),
222 KoRuler::F_HELPLINES, m_pDoc->unit());
223 vRuler->showMousePos(true);
224 vRuler->setZoom(zoomHandler()->zoomedResolutionY());
225 hRuler = new KoRuler(pRightSide, m_pCanvas, TQt::Horizontal, Kivio::Config::defaultPageLayout(),
226 KoRuler::F_HELPLINES, m_pDoc->unit());
227 hRuler->showMousePos(true);
228 hRuler->setZoom(zoomHandler()->zoomedResolutionX());
229 connect(m_vertScrollBar, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(setRulerVOffset(int)));
230 connect(m_horzScrollBar, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(setRulerHOffset(int)));
231 connect(vRuler, TQ_SIGNAL(unitChanged(KoUnit::Unit)), TQ_SLOT(rulerChangedUnit(KoUnit::Unit)));
232 connect(hRuler, TQ_SIGNAL(unitChanged(KoUnit::Unit)), TQ_SLOT(rulerChangedUnit(KoUnit::Unit)));
233 connect(vRuler, TQ_SIGNAL(doubleClicked()), TQ_SLOT(paperLayoutDlg()));
234 connect(hRuler, TQ_SIGNAL(doubleClicked()), TQ_SLOT(paperLayoutDlg()));
235 connect(m_pDoc, TQ_SIGNAL(unitChanged(KoUnit::Unit)), TQ_SLOT(setRulerUnit(KoUnit::Unit)));
236 connect(m_pCanvas, TQ_SIGNAL(visibleAreaChanged()), TQ_SLOT(updateRulers()));
237
238 connect(vRuler, TQ_SIGNAL(addGuide(const TQPoint&, bool, int)),
239 &(m_pCanvas->guideLines()), TQ_SLOT(addGuide(const TQPoint&, bool, int)));
240 connect(vRuler, TQ_SIGNAL(moveGuide(const TQPoint&, bool, int)),
241 &(m_pCanvas->guideLines()), TQ_SLOT(moveGuide(const TQPoint&, bool, int)));
242 connect(hRuler, TQ_SIGNAL(addGuide(const TQPoint&, bool, int)),
243 &(m_pCanvas->guideLines()), TQ_SLOT(addGuide(const TQPoint&, bool, int)));
244 connect(hRuler, TQ_SIGNAL(moveGuide(const TQPoint&, bool, int)),
245 &(m_pCanvas->guideLines()), TQ_SLOT(moveGuide(const TQPoint&, bool, int)));
246 connect(&(m_pCanvas->guideLines()), TQ_SIGNAL(guideLinesChanged(KoView*)), m_pDoc, TQ_SLOT(updateGuideLines(KoView*)));
247
248 TQGridLayout* layout = new TQGridLayout(pRightSide);
249 layout->addWidget(hRuler, 0, 1);
250 layout->addWidget(vRuler, 1, 0);
251 layout->addWidget(canvasBase, 1, 1);
252 layout->addMultiCellLayout(tabLayout, 2, 2, 0, 1);
253 layout->addMultiCellWidget(m_vertScrollBar, 0, 1, 2, 2);
254 layout->setRowStretch(1, 10);
255 layout->setColStretch(1, 10);
256
257 TQWidget::setFocusPolicy( TQWidget::StrongFocus );
258 setFocusProxy( m_pCanvas );
259
260 connect( this, TQ_SIGNAL( invalidated() ), m_pCanvas, TQ_SLOT( update() ) );
261 connect( this, TQ_SIGNAL( regionInvalidated( const TQRegion&, bool ) ), m_pCanvas, TQ_SLOT( repaint( const TQRegion&, bool ) ) );
262
263 setInstance(KivioFactory::global());
264 if ( !m_pDoc->isReadWrite() )
265 setXMLFile("kivio_readonly.rc");
266 else
267 setXMLFile("kivio.rc");
268
269
270 // Must be executed before setActivePage() and before setupActions()
271 createBirdEyeDock();
272 createLayerDock();
273 createObjectListPalette();
274 createGeometryDock();
275 createProtectionDock();
276 paletteManager()->showWidget("birdseyepanel");
277 paletteManager()->showWidget("stencilgeometrypanel");
278
279 setupActions();
280
281
282 KivioPage* page;
283 for ( page = m_pDoc->map()->firstPage(); page; page = m_pDoc->map()->nextPage() )
284 addPage(page);
285
286 setActivePage(m_pDoc->map()->firstPage());
287
288
289 connect( m_pDoc, TQ_SIGNAL( sig_selectionChanged() ), TQ_SLOT( updateToolBars() ) );
290 connect( m_pDoc, TQ_SIGNAL( sig_addPage(KivioPage*) ), TQ_SLOT( addPage(KivioPage*) ) );
291 connect( m_pDoc, TQ_SIGNAL( sig_addSpawnerSet(KivioStencilSpawnerSet*) ), TQ_SLOT(addSpawnerToStackBar(KivioStencilSpawnerSet*)) );
292 connect( m_pDoc, TQ_SIGNAL( sig_updateView(KivioPage*) ), TQ_SLOT(slotUpdateView(KivioPage*)) );
293 connect( m_pDoc, TQ_SIGNAL( sig_pageNameChanged(KivioPage*,const TQString&)), TQ_SLOT(slotPageRenamed(KivioPage*,const TQString&)) );
294
295 connect( m_pDoc, TQ_SIGNAL( sig_updateGrid()),TQ_SLOT(slotUpdateGrid()));
296
297 connect(m_pDoc, TQ_SIGNAL(loadingFinished()), this, TQ_SLOT(loadingFinished()));
298
299 initActions();
300
301 // Load any already-loaded stencils into the stencil dock
302 if( m_pDoc->isReadWrite() ) // only if not embedded in Konqueror
303 {
304 KivioStencilSpawnerSet *pSet;
305 pSet = m_pDoc->spawnerSets()->first();
306 while( pSet )
307 {
308 addSpawnerToStackBar( pSet );
309 pSet = m_pDoc->spawnerSets()->next();
310 }
311 }
312
313 m_pDoc->setModified(isModified);
314 pluginManager()->activateDefaultTool();
315 clipboardDataChanged(); // Enable/disable the paste action
316}
317
318KivioView::~KivioView()
319{
320 delete m_pluginManager;
321 m_pluginManager = 0;
322 delete dcop;
323 dcop = 0;
324 delete m_zoomHandler;
325 m_zoomHandler = 0;
326}
327
328DCOPObject* KivioView::dcopObject()
329{
330 if ( !dcop ) {
331 dcop = new KIvioViewIface( this );
332 }
333
334 return dcop;
335}
336
337void KivioView::createGeometryDock()
338{
339 m_pStencilGeometryPanel = new KivioStencilGeometryPanel(this);
340 m_pStencilGeometryPanel->setCaption(i18n("Geometry"));
341 m_pStencilGeometryPanel->setUnit(m_pDoc->unit());
342 paletteManager()->addWidget(m_pStencilGeometryPanel, "stencilgeometrypanel", "geometrydocker");
343
344 connect( m_pStencilGeometryPanel, TQ_SIGNAL(positionChanged(double, double)), this, TQ_SLOT(slotChangeStencilPosition(double, double)) );
345 connect( m_pStencilGeometryPanel, TQ_SIGNAL(sizeChanged(double, double)), this, TQ_SLOT(slotChangeStencilSize(double, double)) );
346// connect(m_pStencilGeometryPanel, TQ_SIGNAL(rotationChanged(int)), TQ_SLOT(slotChangeStencilRotation(int)));
347
348 connect( m_pDoc, TQ_SIGNAL(unitChanged(KoUnit::Unit)), m_pStencilGeometryPanel, TQ_SLOT(setUnit(KoUnit::Unit)) );
349}
350
351void KivioView::createBirdEyeDock()
352{
353 m_pBirdEyePanel = new KivioBirdEyePanel(this, this);
354 m_pBirdEyePanel->setCaption(i18n("Overview"));
355 paletteManager()->addWidget(m_pBirdEyePanel, "birdseyepanel", "birdeyedocker");
356}
357
358void KivioView::createLayerDock()
359{
360 m_pLayersPanel = new KivioLayerPanel( this, this);
361 m_pLayersPanel->setCaption(i18n("Layers"));
362 paletteManager()->addWidget(m_pLayersPanel, "layerspanel", "birdeyedocker");
363}
364
365void KivioView::createProtectionDock()
366{
367 m_pProtectionPanel = new KivioProtectionPanel(this,this);
368 m_pProtectionPanel->setCaption(i18n("Protection"));
369 paletteManager()->addWidget(m_pProtectionPanel, "protectionpanel", "geometrydocker");
370}
371
372void KivioView::createObjectListPalette()
373{
374 m_objectListPalette = new Kivio::ObjectListPalette(this);
375 m_objectListPalette->setCaption(i18n("Objects"));
376 paletteManager()->addWidget(m_objectListPalette, "objectlistpalette", "birdeyedocker");
377}
378
379void KivioView::setupActions()
380{
381 KivioStencilSetAction* addStSet = new KivioStencilSetAction( i18n("Add Stencil Set"),
382 "open_stencilset", actionCollection(), "addStencilSet" );
383 connect(addStSet,TQ_SIGNAL(activated(const TQString&)),TQ_SLOT(addStencilSet(const TQString&)));
384 connect(this, TQ_SIGNAL(updateStencilSetList()), addStSet, TQ_SLOT(updateMenu()));
385 connect(addStSet, TQ_SIGNAL(showDialog()), this, TQ_SLOT(showAddStencilSetDialog()));
386
387 m_alignAndDistribute = new TDEAction( i18n("Align && Distribute..."), CTRL+ALT+Key_A, this,
388 TQ_SLOT(alignStencilsDlg()), actionCollection(), "alignStencils" );
389
390 m_editCut = KStdAction::cut( this, TQ_SLOT(cutStencil()), actionCollection(), "cutStencil" );
391 m_editCopy = KStdAction::copy( this, TQ_SLOT(copyStencil()), actionCollection(), "copyStencil" );
392 m_editPaste = KStdAction::paste( this, TQ_SLOT(pasteStencil()), actionCollection(), "pasteStencil" );
393 connect(TQApplication::clipboard(), TQ_SIGNAL(dataChanged()), this, TQ_SLOT(clipboardDataChanged()));
394
395 m_selectAll = KStdAction::selectAll(this, TQ_SLOT(selectAllStencils()), actionCollection(), "selectAllStencils");
396 m_selectNone = KStdAction::deselect(this, TQ_SLOT(unselectAllStencils()), actionCollection(), "unselectAllStencils");
397
398 m_groupAction = new TDEAction( i18n("Group Selection"), "group", CTRL+Key_G, this, TQ_SLOT(groupStencils()), actionCollection(), "groupStencils" );
399 m_groupAction->setWhatsThis(i18n("Group selected objects into a single stencil"));
400 m_ungroupAction = new TDEAction( i18n("Ungroup"), "ungroup", CTRL+SHIFT+Key_G, this, TQ_SLOT(ungroupStencils()), actionCollection(), "ungroupStencils" );
401 m_ungroupAction->setWhatsThis(i18n("Break up a selected group stencil"));
402
403 m_stencilToFront = new TDEAction( i18n("Bring to Front"), "bring_forward", 0, this, TQ_SLOT(bringStencilToFront()), actionCollection(), "bringStencilToFront" );
404 m_stencilToBack = new TDEAction( i18n("Send to Back"), "send_backward", 0, this, TQ_SLOT(sendStencilToBack()), actionCollection(), "sendStencilToBack" );
405
406 m_menuTextFormatAction = new TDEAction(i18n("&Text..."), 0, 0, this, TQ_SLOT(textFormat()),
407 actionCollection(), "textFormat");
408
409 m_menuStencilConnectorsAction = new TDEAction(i18n("&Stencils && Connectors..."), 0, 0, this, TQ_SLOT(stencilFormat()),
410 actionCollection(), "stencilFormat");
411
412 m_arrowHeadsMenuAction = new TDEAction(i18n("&Arrowheads..."), 0, 0, this, TQ_SLOT(arrowHeadFormat()),
413 actionCollection(), "arrowHeadFormat");
414 m_arrowHeadsMenuAction->setWhatsThis(i18n("Arrowheads allow you to add an arrow to the beginning and/or end of a line."));
415
416 /* Create the fg color button */
417 m_setFGColor = new TTDESelectColorAction( i18n("Line Color"), TTDESelectColorAction::LineColor, actionCollection(), "setFGColor" );
418 m_setFGColor->setWhatsThis(i18n("The line color allows you to choose a color for the lines of the stencils."));
419 connect(m_setFGColor,TQ_SIGNAL(activated()),TQ_SLOT(setFGColor()));
420 m_setBGColor = new TTDESelectColorAction( i18n("Fill Color"), TTDESelectColorAction::FillColor, actionCollection(), "setBGColor" );
421 m_setBGColor->setWhatsThis(i18n("You can choose a color for the background of a stencil by using this button."));
422 connect(m_setBGColor,TQ_SIGNAL(activated()),TQ_SLOT(setBGColor()));
423
424 // Text bar
425 m_setFontFamily = new TDEFontAction( i18n( "Font Family" ), 0, actionCollection(), "setFontFamily" );
426 connect( m_setFontFamily, TQ_SIGNAL(activated(const TQString&)), TQ_SLOT(setFontFamily(const TQString&)) );
427
428 m_setFontSize = new TDEFontSizeAction( i18n( "Font Size" ), 0, actionCollection(), "setFontSize" );
429 connect( m_setFontSize, TQ_SIGNAL( fontSizeChanged( int ) ),
430 this, TQ_SLOT( setFontSize(int ) ) );
431
432
433 m_setTextColor = new TTDESelectColorAction( i18n("Text Color"), TTDESelectColorAction::TextColor, actionCollection(), "setTextColor" );
434 connect( m_setTextColor, TQ_SIGNAL(activated()), TQ_SLOT(setTextColor()) );
435
436 m_setBold = new TDEToggleAction( i18n("Toggle Bold Text"), "format-text-bold", 0, actionCollection(), "setFontBold" );
437 connect( m_setBold, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleFontBold(bool)) );
438
439 m_setItalics = new TDEToggleAction( i18n("Toggle Italics Text"), "format-text-italic", 0, actionCollection(), "setFontItalics" );
440 connect( m_setItalics, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleFontItalics(bool)) );
441
442 m_setUnderline = new TDEToggleAction( i18n("Toggle Underline Text"), "format-text-underline", 0, actionCollection(), "setFontUnderline" );
443 connect( m_setUnderline, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleFontUnderline(bool)));
444
445 m_textAlignLeft = new TDEToggleAction( i18n( "Align &Left" ), "format-text-direction-ltr", CTRL + Key_L,
446 this, TQ_SLOT( textAlignLeft() ),
447 actionCollection(), "textAlignLeft" );
448 m_textAlignLeft->setExclusiveGroup( "align" );
449 m_textAlignCenter = new TDEToggleAction( i18n( "Align &Center" ), "text_center", CTRL + ALT + Key_C,
450 this, TQ_SLOT( textAlignCenter() ),
451 actionCollection(), "textAlignCenter" );
452 m_textAlignCenter->setExclusiveGroup( "align" );
453 m_textAlignCenter->setChecked( true );
454 m_textAlignRight = new TDEToggleAction( i18n( "Align &Right" ), "format-text-direction-rtl", CTRL + ALT + Key_R,
455 this, TQ_SLOT( textAlignRight() ),
456 actionCollection(), "textAlignRight" );
457 m_textAlignRight->setExclusiveGroup( "align" );
458 m_textVAlignSuper = new TDEToggleAction( i18n( "Superscript" ), "super", 0,
459 this, TQ_SLOT( textSuperScript() ),
460 actionCollection(), "textVAlignSuper" );
461 m_textVAlignSuper->setExclusiveGroup( "valign" );
462 m_textVAlignSub = new TDEToggleAction( i18n( "Subscript" ), "sub", 0,
463 this, TQ_SLOT( textSubScript() ),
464 actionCollection(), "textVAlignSub" );
465 m_textVAlignSub->setExclusiveGroup( "valign" );
466
467 m_lineWidthAction = new KoLineWidthAction(i18n("Line Width"), "linewidth", this, TQ_SLOT(setLineWidth(double)),
468 actionCollection(), "setLineWidth");
469 m_lineWidthAction->setUnit(m_pDoc->unit());
470 connect(m_pDoc, TQ_SIGNAL(unitChanged(KoUnit::Unit)), m_lineWidthAction, TQ_SLOT(setUnit(KoUnit::Unit)));
471
472 m_lineStyleAction = new KoLineStyleAction(i18n("Line Style"), "linestyle", this, TQ_SLOT(setLineStyle(int)),
473 actionCollection(), "setLineStyle");
474
475 m_paperLayout = new TDEAction( i18n("Page Layout..."), 0, this, TQ_SLOT(paperLayoutDlg()), actionCollection(), "paperLayout" );
476 m_insertPage = new TDEAction( i18n("Insert Page"),"item_add", 0, this, TQ_SLOT(insertPage()), actionCollection(), "insertPage" );
477 m_removePage = new TDEAction( i18n("Remove Page"), "item_remove",0,this, TQ_SLOT(removePage()), actionCollection(), "removePage" );
478
479 m_renamePage = new TDEAction( i18n("Rename Page..."), "item_rename",0,this, TQ_SLOT(renamePage()), actionCollection(), "renamePage" );
480
481 m_showPage = new TDEAction( i18n("Show Page..."),0 ,this,TQ_SLOT(showPage()), actionCollection(), "showPage" );
482 m_hidePage = new TDEAction( i18n("Hide Page"),0 ,this,TQ_SLOT(hidePage()), actionCollection(), "hidePage" );
483
484 showPageMargins = new TDEToggleAction( i18n("Show Page Margins"), "view_margins", 0, actionCollection(), "showPageMargins" );
485 connect( showPageMargins, TQ_SIGNAL(toggled(bool)), TQ_SLOT(togglePageMargins(bool)));
486 showPageMargins->setCheckedState(i18n("Hide Page Margins"));
487
488 showRulers = new TDEToggleAction( i18n("Show Rulers"), "view_ruler", 0, actionCollection(), "showRulers" );
489 connect( showRulers, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleShowRulers(bool)));
490 showRulers->setCheckedState(i18n("Hide Rulers"));
491
492 // Grid actions
493 showGrid = new TDEToggleAction( i18n("Show Grid"), "view_grid", 0, actionCollection(), "showGrid" );
494 connect( showGrid, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleShowGrid(bool)));
495 showGrid->setCheckedState(i18n("Hide Grid"));
496
497 TDEToggleAction* snapGrid = new TDEToggleAction( i18n("Snap Grid"), "view_grid", 0, actionCollection(), "snapGrid" );
498 connect( snapGrid, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleSnapGrid(bool)));
499
500 // Guides actions
501 showGuides = new TDEToggleAction( i18n("Guide Lines"), 0, actionCollection(), "showGuides" );
502 connect( showGuides, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleShowGuides(bool)));
503 TDEAction* addGuide = new TDEAction(i18n("Add Guide Line..."), 0, this, TQ_SLOT(addGuideLine()),
504 actionCollection(), "addGuideLine");
505 connect(showGuides, TQ_SIGNAL(toggled(bool)), addGuide, TQ_SLOT(setEnabled(bool)));
506 //--
507
508 m_setArrowHeads = new KivioArrowHeadAction(i18n("Arrowheads"), "arrowheads", actionCollection(), "arrowHeads");
509 m_setArrowHeads->setWhatsThis(i18n("Arrowheads allow you to add an arrow to the beginning and/or end of a line."));
510 connect( m_setArrowHeads, TQ_SIGNAL(endChanged(int)), TQ_SLOT(slotSetEndArrow(int)));
511 connect( m_setArrowHeads, TQ_SIGNAL(startChanged(int)), TQ_SLOT(slotSetStartArrow(int)));
512
513 KStdAction::preferences(this, TQ_SLOT(optionsDialog()), actionCollection(), "options");
514
515 (void) new TDEAction(i18n("Install Stencil Set..."), 0, this,
516 TQ_SLOT(installStencilSet()), actionCollection(), "installStencilSet");
517
518 m_editDelete = new TDEAction(i18n("Delete"), "edit-delete", Key_Delete,
519 this, TQ_SLOT(deleteObject()), actionCollection(), "deleteObject");
520}
521
522void KivioView::initActions()
523{
524 togglePageMargins(true);
525 toggleShowRulers(true);
526
527 updateButton();
528
529 m_setFontFamily->setFont( doc()->defaultFont().family() );
530 m_setFontSize->setFontSize( doc()->defaultFont().pointSize() );
531 m_setBold->setChecked( false );
532 m_setItalics->setChecked( false );
533 m_setUnderline->setChecked( false );
534 m_lineWidthAction->setCurrentWidth(1.0);
535 m_lineStyleAction->setCurrentSelection(TQt::SolidLine);
536 showAlign(TQt::AlignHCenter);
537 showVAlign(TQt::AlignVCenter);
538
539 m_pStencilGeometryPanel->setSize(0.0,0.0);
540 m_pStencilGeometryPanel->setPosition(0.0,0.0);
541 m_pStencilGeometryPanel->setRotation(0);
542
543 m_setArrowHeads->setCurrentStartArrow(0);
544 m_setArrowHeads->setCurrentEndArrow(0);
545
546 m_menuTextFormatAction->setEnabled( false );
547 m_menuStencilConnectorsAction->setEnabled( false );
548
549 m_setFGColor->setCurrentColor(TQColor(0, 0, 0));
550 m_setBGColor->setCurrentColor(TQColor(255, 255, 255));
551 m_setTextColor->setCurrentColor(TQColor(0, 0, 0));
552
553 viewZoom(zoomHandler()->zoom());
554}
555
556void KivioView::updateReadWrite( bool readwrite )
557{
558 TQValueList<TDEAction*> actions = actionCollection()->actions();
559 TQValueList<TDEAction*>::ConstIterator aIt = actions.begin();
560 TQValueList<TDEAction*>::ConstIterator aEnd = actions.end();
561 for (; aIt != aEnd; ++aIt )
562 (*aIt)->setEnabled( readwrite );
563 if ( !readwrite )
564 {
565 showPageMargins->setEnabled( true );
566 showRulers->setEnabled( true );
567 showGrid->setEnabled( true );
568 showGuides->setEnabled( true );
569 m_selectAll->setEnabled( true );
570 m_selectNone->setEnabled( true );
571 m_editCopy->setEnabled( true );
572 }
573 m_showPage->setEnabled( true );
574 m_hidePage->setEnabled( true );
575 updateMenuPage();
576}
577
578
579void KivioView::addPage( KivioPage* page )
580{
581 insertPage( page );
582
583 TQObject::connect( page, TQ_SIGNAL( sig_PageHidden( KivioPage* ) ),
584 this, TQ_SLOT( slotPageHidden( KivioPage* ) ) );
585 TQObject::connect( page, TQ_SIGNAL( sig_PageShown( KivioPage* ) ),
586 this, TQ_SLOT( slotPageShown( KivioPage* ) ) );
587
588 updatePageStatusLabel();
589}
590
591void KivioView::insertPage( KivioPage* page )
592{
593 if(!page->isHidden()) {
594 m_pTabBar->addTab(page->pageName());
595 setActivePage(page);
596 updateMenuPage();
597 }
598}
599
600void KivioView::removePage( KivioPage *_t )
601{
602 TQString m_pageName=_t->pageName();
603 m_pTabBar->removeTab( _t->pageName() );
604 TQString n = m_pDoc->map()->visiblePages().first();
605 setActivePage( m_pDoc->map()->findPage( n ) );
606
607 updatePageStatusLabel();
608}
609
610void KivioView::renamePage()
611{
612 bool ok;
613 TQString activeName = m_pActivePage->pageName();
614 TQString newName = KInputDialog::getText( i18n("Rename Page"),
615 i18n("Enter page name:"), activeName, &ok, this );
616
617 // Have a different name ?
618 if ( ok ) // User pushed an OK button.
619 {
620 if ( (newName.stripWhiteSpace()).isEmpty() ) // Page name is empty.
621 {
622 KNotifyClient::beep();
623 KMessageBox::information( this, i18n("Page name cannot be empty."),
624 i18n("Change Page Name") );
625 // Recursion
626 renamePage();
627 }
628 else if ( newName != activeName ) // Page name changed.
629 {
630 // Is the name already used
631 if ( !m_pActivePage->setPageName( newName ) )
632 {
633 KNotifyClient::beep();
634 KMessageBox::information( this, i18n("This name is already used."),
635 i18n("Change Page Name") );
636 // Recursion
637 renamePage();
638 }
639 KivioChangePageNameCommand *cmd = new KivioChangePageNameCommand(i18n("Rename Page"), activeName, newName, m_pActivePage);
640 m_pDoc->addCommand( cmd );
641 }
642 }
643}
644
645void KivioView::setActivePage( KivioPage* page )
646{
647 if ( page == m_pActivePage )
648 return;
649
650 if(m_pActivePage) {
651 disconnect(m_pActivePage, TQ_SIGNAL(sig_pageLayoutChanged(const KoPageLayout&)), this,
652 TQ_SLOT(setRulerPageLayout(const KoPageLayout&)));
653 }
654
655 m_pActivePage = page;
656
657 m_pTabBar->setActiveTab(m_pActivePage->pageName());
658 updateToolBars();
659
660 m_pLayersPanel->reset();
661
662 m_pDoc->updateView(m_pActivePage);
663 setRulerPageLayout(m_pActivePage->paperLayout());
664 connect(m_pActivePage, TQ_SIGNAL(sig_pageLayoutChanged(const KoPageLayout&)),
665 TQ_SLOT(setRulerPageLayout(const KoPageLayout&)));
666
667 m_pCanvas->guideLines().setGuideLines(m_pActivePage->horizontalGuideLines(),
668 m_pActivePage->verticalGuideLines());
669 m_objectListPalette->updateObjectList();
670}
671
672void KivioView::setActiveSpawnerSet( KivioStencilSpawnerSet *set )
673{
674 if( set == m_pActiveSpawnerSet )
675 return;
676
677 m_pActiveSpawnerSet = set;
678}
679
680void KivioView::slotPageRenamed( KivioPage* page, const TQString& old_name )
681{
682 m_pTabBar->renameTab( old_name, page->pageName() );
683}
684
685void KivioView::changePage( const TQString& name )
686{
687 if ( m_pActivePage->pageName() == name )
688 return;
689
690 KivioPage *t = m_pDoc->map()->findPage(name);
691 if (!t)
692 return;
693
694 setActivePage(t);
695 updatePageStatusLabel();
696}
697
698void KivioView::insertPage()
699{
700 KivioPage * t =m_pDoc->createPage();
701 m_pDoc->addPage(t);
702 KivioAddPageCommand * cmd = new KivioAddPageCommand(i18n("Insert Page"), t);
703 m_pDoc->addCommand( cmd );
704
705 updatePageStatusLabel();
706}
707
708void KivioView::hidePage()
709{
710 if (!m_pActivePage)
711 return;
712
713 if ( m_pDoc->map()->visiblePages().count() == 1)
714 {
715 KMessageBox::error( this, i18n("You cannot hide the last visible page.") );
716 return;
717 }
718
719 m_pActivePage->setHidden(true);
720 TQString activeName = m_pActivePage->pageName();
721
722 m_pTabBar->removeTab( activeName );
723
724 KivioHidePageCommand * cmd = new KivioHidePageCommand(i18n("Hide Page"), m_pActivePage);
725 m_pDoc->addCommand( cmd );
726
727 changePage( m_pDoc->map()->visiblePages().first() );
728 updateMenuPage();
729}
730
731void KivioView::showPage()
732{
733 KivioPageShow* dlg = new KivioPageShow(this,"Page show");
734 if ( !dlg->exec() )
735 {
736 delete dlg;
737 return;
738 }
739 m_pTabBar->setTabs( m_pDoc->map()->visiblePages() );
740 updateMenuPage();
741 delete dlg;
742}
743
744int KivioView::leftBorder() const
745{
746 int retVal = 0;
747
748 if(isShowRulers()) {
749 retVal = vertRuler()->width();
750 }
751
752 return retVal;
753}
754
755int KivioView::rightBorder() const
756{
757 return m_vertScrollBar->width();
758}
759
760int KivioView::topBorder() const
761{
762 int retVal = 0;
763
764 if(isShowRulers()) {
765 retVal = horzRuler()->height();
766 }
767
768 return retVal;
769}
770
771int KivioView::bottomBorder() const
772{
773 return m_horzScrollBar->height();
774}
775
776void KivioView::paperLayoutDlg()
777{
778 KivioPage* page = activePage();
779 KoPageLayout l = page->paperLayout();
780 KoHeadFoot headfoot;
781 int tabs = FORMAT_AND_BORDERS | DISABLE_UNIT;
782 KoUnit::Unit unit = doc()->unit();
783
784 if(KoPageLayoutDia::pageLayout(l, headfoot, tabs, unit))
785 {
786 KivioDoc* doc = page->doc();
787 KivioChangeLayoutCommand * cmd = new KivioChangeLayoutCommand(
788 i18n("Change Page Layout"),page ,page->paperLayout(), l);
789 doc->addCommand( cmd );
790 page->setPaperLayout(l);
791 }
792}
793
794void KivioView::removePage()
795{
796 if ( doc()->map()->count() <= 1 || doc()->map()->visiblePages().count()<=1 ) {
797 TQApplication::beep();
798 KMessageBox::sorry( this, i18n("You cannot delete the only page of the document."), i18n("Remove Page") );
799 return;
800 }
801 TQApplication::beep();
802 int ret = KMessageBox::warningContinueCancel(this,i18n("You are going to remove the active page.\nDo you want to continue?"),i18n("Remove Page"),KGuiItem(i18n("&Delete"),"edit-delete"));
803
804 if ( ret == KMessageBox::Continue ) {
805 KivioPage* tbl = m_pActivePage;
806 KivioRemovePageCommand *cmd = new KivioRemovePageCommand(i18n("Remove Page"), tbl);
807 cmd->execute();
808 doc()->addCommand( cmd );
809 }
810}
811
812void KivioView::slotUpdateView( KivioPage* page )
813{
814 if (page && page != m_pActivePage)
815 return;
816
817 // global view updates (toolbar, statusbar.... actions...)
818 updateToolBars();
819
820 m_pCanvas->update();
821 m_pCanvas->updateScrollBars();
822 vRuler->update();
823 hRuler->update();
824 m_objectListPalette->updateObjectList();
825}
826
827TQWidget *KivioView::canvas() const
828{
829 return canvasWidget();
830}
831
832int KivioView::canvasXOffset() const
833{
834 return canvasWidget()->xOffset();
835}
836
837int KivioView::canvasYOffset() const
838{
839 return canvasWidget()->yOffset();
840}
841
842void KivioView::print(KPrinter& ptr)
843{
844 ptr.setFullPage(true);
845 m_pDoc->printContent( ptr );
846}
847
848
849void KivioView::viewZoom(int zoom)
850{
851 if(zoom < 10 || zoom > 2000 || zoom == zoomHandler()->zoom()) {
852 return;
853 }
854
855 KoPoint centerPoint = m_pCanvas->visibleArea().center();
856 zoomHandler()->setZoomAndResolution(zoom, KoGlobal::dpiX(),
857 KoGlobal::dpiY());
858 vRuler->setZoom(zoomHandler()->zoomedResolutionY());
859 hRuler->setZoom(zoomHandler()->zoomedResolutionX());
860 KoPageLayout l = activePage()->paperLayout();
861 vRuler->setFrameStartEnd(zoomHandler()->zoomItY(l.ptTop), zoomHandler()->zoomItY(l.ptHeight - l.ptBottom));
862 hRuler->setFrameStartEnd(zoomHandler()->zoomItX(l.ptLeft), zoomHandler()->zoomItX(l.ptWidth - l.ptRight));
863 setRulerVOffset(m_vertScrollBar->value());
864 setRulerHOffset(m_horzScrollBar->value());
865 KoView::setZoom(zoomHandler()->zoomedResolutionY());
866 m_pCanvas->setViewCenterPoint(centerPoint);
867 m_pCanvas->update();
868 m_pCanvas->updateScrollBars();
869
870 emit zoomChanged(zoom);
871}
872
873KivioPage* KivioView::activePage() const
874{
875 return m_pActivePage;
876}
877
878void KivioView::togglePageMargins(bool b)
879{
880 TOGGLE_ACTION("showPageMargins")->setChecked(b);
881 m_bShowPageMargins = b;
882
883 m_pCanvas->update();
884}
885
886void KivioView::toggleShowRulers(bool b)
887{
888 TOGGLE_ACTION("showRulers")->setChecked(b);
889 m_bShowRulers = b;
890
891 if(b) {
892 hRuler->show();
893 vRuler->show();
894 } else {
895 hRuler->hide();
896 vRuler->hide();
897 }
898}
899
900void KivioView::toggleShowGuides(bool b)
901{
902 TOGGLE_ACTION("showGuides")->setChecked(b);
903 m_bShowGuides = b;
904 m_bSnapGuides = b;
905
906 m_pCanvas->update();
907}
908
909void KivioView::toggleShowGrid(bool b)
910{
911 TOGGLE_ACTION("showGrid")->setChecked(b);
912
913 Kivio::Config::setShowGrid(b);
914 m_pDoc->setModified( true );
915}
916
917void KivioView::slotUpdateGrid()
918{
919 m_pCanvas->update();
920}
921
922void KivioView::toggleSnapGrid(bool b)
923{
924 TOGGLE_ACTION("snapGrid")->setChecked(b);
925
926 Kivio::Config::setSnapGrid(b);
927 m_pDoc->setModified( true );
928}
929
930void KivioView::addStencilSet( const TQString& name )
931{
932 m_pDoc->addSpawnerSet(name);
933}
934
935void KivioView::addSpawnerToStackBar( KivioStencilSpawnerSet *pSpawner )
936{
937 if(!pSpawner) {
938 kdDebug(43000) << "KivioView::addSpawnerToStackBar() - NULL pSpawner" << endl;
939 return;
940 }
941
942 if(pSpawner->hidden()) {
943 return;
944 }
945
946 KivioIconView *pView = new KivioIconView(m_pDoc->isReadWrite());
947 TQObject::connect(pView, TQ_SIGNAL(createNewStencil(KivioStencilSpawner*)), this,
948 TQ_SLOT(addStencilFromSpawner(KivioStencilSpawner*)));
949 connect(pView, TQ_SIGNAL(stencilSelected(KivioStencilSpawner*)),
950 m_addStencilTool, TQ_SLOT(activateNewStencil(KivioStencilSpawner* )));
951
952 pView->setStencilSpawnerSet(pSpawner);
953 m_pStencilBarDockManager->insertStencilSet(pView, pSpawner->name());
954}
955
956void KivioView::setFGColor()
957{
958 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
959 if (!pStencil)
960 return;
961 KMacroCommand * macro = new KMacroCommand( i18n("Change Foreground Color"));
962 bool createMacro = false;
963 while( pStencil )
964 {
965 TQColor col( m_setFGColor->color());
966
967 if ( col != pStencil->fgColor() )
968 {
969 KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Fg Color"), m_pActivePage, pStencil, pStencil->fgColor(), col, KivioChangeStencilColorCommand::CT_FGCOLOR);
970
971 pStencil->setFGColor( col );
972 macro->addCommand( cmd );
973 createMacro = true;
974 }
975
976 pStencil = m_pActivePage->selectedStencils()->next();
977 }
978
979 if ( createMacro )
980 m_pDoc->addCommand( macro );
981 else
982 delete macro;
983
984 m_pDoc->updateView(m_pActivePage);
985}
986
987void KivioView::setBGColor()
988{
989 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
990 if (!pStencil)
991 return;
992 KMacroCommand * macro = new KMacroCommand( i18n("Change Background Color"));
993 bool createMacro = false;
994
995 while( pStencil )
996 {
997 TQColor col( m_setBGColor->color());
998
999 if ( col != pStencil->bgColor() )
1000 {
1001 KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Bg Color"), m_pActivePage, pStencil, pStencil->bgColor(), col, KivioChangeStencilColorCommand::CT_BGCOLOR);
1002
1003 pStencil->setBGColor( col );
1004 macro->addCommand( cmd );
1005 createMacro = true;
1006 }
1007
1008 pStencil = m_pActivePage->selectedStencils()->next();
1009 }
1010
1011 if ( createMacro )
1012 m_pDoc->addCommand( macro );
1013 else
1014 delete macro;
1015
1016 m_pDoc->updateView(m_pActivePage);
1017}
1018
1019void KivioView::setTextColor()
1020{
1021 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1022
1023 if (!pStencil)
1024 return;
1025
1026 KMacroCommand * macro = new KMacroCommand( i18n("Change Text Color"));
1027 bool createMacro = false;
1028 while( pStencil )
1029 {
1030 TQColor col(m_setTextColor->color());
1031
1032 if ( col != pStencil->textColor() )
1033 {
1034 KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Text Color"), m_pActivePage, pStencil, pStencil->textColor(), col, KivioChangeStencilColorCommand::CT_TEXTCOLOR);
1035 pStencil->setTextColor( col );
1036 macro->addCommand( cmd );
1037 createMacro = true;
1038 }
1039
1040 pStencil = m_pActivePage->selectedStencils()->next();
1041 }
1042
1043 if ( createMacro )
1044 m_pDoc->addCommand( macro );
1045 else
1046 delete macro;
1047
1048 m_pDoc->updateView(m_pActivePage);
1049}
1050
1051void KivioView::setLineWidth(double width)
1052{
1053 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1054
1055 if (!pStencil)
1056 return;
1057
1058 KMacroCommand * macro = new KMacroCommand( i18n("Change Line Width") );
1059 bool createMacro = false ;
1060
1061 while( pStencil )
1062 {
1063 if ( width != pStencil->lineWidth() )
1064 {
1065 KivioChangeLineWidthCommand * cmd = new KivioChangeLineWidthCommand( i18n("Change Line Width"),
1066 m_pActivePage, pStencil, pStencil->lineWidth(), width );
1067
1068 pStencil->setLineWidth( width );
1069 macro->addCommand( cmd );
1070 createMacro = true;
1071 }
1072
1073 pStencil = m_pActivePage->selectedStencils()->next();
1074 }
1075
1076 if ( createMacro ) {
1077 m_pDoc->addCommand( macro );
1078 } else {
1079 delete macro;
1080 }
1081
1082 m_pDoc->updateView(m_pActivePage);
1083}
1084
1085void KivioView::setLineStyle(int style)
1086{
1087 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1088
1089 if(!pStencil)
1090 return;
1091
1092 KMacroCommand * macro = new KMacroCommand( i18n("Change Line Style") );
1093 bool createMacro = false ;
1094
1095 while(pStencil)
1096 {
1097 if(style != pStencil->linePattern())
1098 {
1099 KivioChangeLineStyleCommand * cmd = new KivioChangeLineStyleCommand( i18n("Change Line Style"),
1100 m_pActivePage, pStencil, pStencil->linePattern(), style );
1101 pStencil->setLinePattern(style);
1102 macro->addCommand( cmd );
1103 createMacro = true;
1104 }
1105
1106 pStencil = m_pActivePage->selectedStencils()->next();
1107 }
1108
1109 if ( createMacro ) {
1110 m_pDoc->addCommand( macro );
1111 } else {
1112 delete macro;
1113 }
1114}
1115
1116void KivioView::groupStencils()
1117{
1118 m_pActivePage->groupSelectedStencils();
1119 m_pDoc->updateView(m_pActivePage);
1120}
1121
1122void KivioView::ungroupStencils()
1123{
1124 m_pActivePage->ungroupSelectedStencils();
1125 m_pDoc->updateView(m_pActivePage);
1126}
1127
1128void KivioView::selectAllStencils()
1129{
1130 m_pActivePage->selectAllStencils();
1131 m_pCanvas->repaint();
1132}
1133
1134void KivioView::unselectAllStencils()
1135{
1136 m_pActivePage->unselectAllStencils();
1137 m_pCanvas->repaint();
1138}
1139
1140TQColor KivioView::fgColor() const
1141{
1142 return m_setFGColor->color();
1143}
1144
1145TQColor KivioView::bgColor() const
1146{
1147 return m_setBGColor->color();
1148}
1149
1150double KivioView::lineWidth() const
1151{
1152 return m_lineWidthAction->currentWidth();
1153}
1154
1155int KivioView::lineStyle() const
1156{
1157 return m_lineStyleAction->currentSelection();
1158}
1159
1160
1161void KivioView::setFontFamily( const TQString &str )
1162{
1163 canvasWidget()->setFocus();
1164 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1165 if (!pStencil)
1166 return;
1167
1168 TQFont f;
1169 KMacroCommand * macro = 0L;
1170 while( pStencil )
1171 {
1172 f = pStencil->textFont();
1173 f.setFamily( str );
1174 if ( pStencil->textFont() != f )
1175 {
1176 if ( !macro )
1177 macro = new KMacroCommand( i18n("Change Stencil Font"));
1178
1179 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1180 pStencil->setTextFont( f );
1181
1182 macro->addCommand( cmd );
1183 }
1184 pStencil = m_pActivePage->selectedStencils()->next();
1185
1186 }
1187 if ( macro )
1188 m_pDoc->addCommand( macro );
1189 m_pDoc->updateView(m_pActivePage);
1190}
1191
1192void KivioView::setFontSize(int size )
1193{
1194 canvasWidget()->setFocus();
1195 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1196 if (!pStencil)
1197 return;
1198
1199 TQFont f;
1200 KMacroCommand * macro = 0L;
1201 while( pStencil )
1202 {
1203 f = pStencil->textFont();
1204 f.setPointSize( size );
1205 if ( pStencil->textFont() != f )
1206 {
1207 if ( !macro )
1208 macro = new KMacroCommand( i18n("Change Stencil Font"));
1209
1210 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1211
1212 pStencil->setTextFont( f );
1213 macro->addCommand( cmd );
1214 }
1215 pStencil = m_pActivePage->selectedStencils()->next();
1216
1217 }
1218 if ( macro )
1219 m_pDoc->addCommand( macro );
1220 m_pDoc->updateView(m_pActivePage);
1221}
1222
1223void KivioView::toggleFontBold(bool b)
1224{
1225 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1226 if (!pStencil)
1227 return;
1228
1229 TQFont f;
1230 KMacroCommand * macro = 0L;
1231 while( pStencil )
1232 {
1233 f = pStencil->textFont();
1234 f.setBold(b);
1235 if ( pStencil->textFont() != f )
1236 {
1237 if ( !macro )
1238 macro = new KMacroCommand( i18n("Change Stencil Font"));
1239 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1240
1241 pStencil->setTextFont( f );
1242 macro->addCommand( cmd );
1243 }
1244 pStencil = m_pActivePage->selectedStencils()->next();
1245
1246 }
1247 if ( macro )
1248 m_pDoc->addCommand( macro );
1249 m_pDoc->updateView(m_pActivePage);
1250}
1251
1252void KivioView::toggleFontItalics(bool b)
1253{
1254 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1255 if (!pStencil)
1256 return;
1257
1258 TQFont f;
1259 KMacroCommand * macro = new KMacroCommand( i18n("Change Stencil Font"));
1260 while( pStencil )
1261 {
1262 f = pStencil->textFont();
1263 f.setItalic(b);
1264 if ( pStencil->textFont() != f )
1265 {
1266 if ( !macro )
1267 macro = new KMacroCommand( i18n("Change Stencil Font"));
1268
1269 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1270
1271 pStencil->setTextFont( f );
1272
1273 macro->addCommand( cmd );
1274 }
1275 pStencil = m_pActivePage->selectedStencils()->next();
1276 }
1277 if ( macro )
1278 m_pDoc->addCommand( macro );
1279 m_pDoc->updateView(m_pActivePage);
1280}
1281
1282void KivioView::toggleFontUnderline( bool b)
1283{
1284 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1285 if (!pStencil)
1286 return;
1287 KMacroCommand * macro = 0L;
1288 TQFont f;
1289 while( pStencil )
1290 {
1291 f = pStencil->textFont();
1292 f.setUnderline(b);
1293 if ( pStencil->textFont() != f )
1294 {
1295 if ( !macro )
1296 macro = new KMacroCommand( i18n("Change Stencil Font"));
1297
1298 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1299
1300 pStencil->setTextFont( f );
1301
1302 macro->addCommand( cmd );
1303 }
1304 pStencil = m_pActivePage->selectedStencils()->next();
1305 }
1306 if ( macro )
1307 m_pDoc->addCommand( macro );
1308 m_pDoc->updateView(m_pActivePage);
1309}
1310
1311
1312
1313void KivioView::updateToolBars()
1314{
1315 KivioStencil *pStencil;
1316 pStencil = m_pActivePage->selectedStencils()->first();
1317 m_pStencilGeometryPanel->setEmitSignals(false);
1318 m_setArrowHeads->setEmitSignals(false);
1319
1320 if( !pStencil )
1321 {
1322 m_setFontFamily->setFont( doc()->defaultFont().family() );
1323 m_setFontSize->setFontSize( doc()->defaultFont().pointSize() );
1324 m_setBold->setChecked( false );
1325 m_setItalics->setChecked( false );
1326 m_setUnderline->setChecked( false );
1327 m_lineWidthAction->setCurrentWidth(1.0);
1328 m_lineStyleAction->setCurrentSelection(TQt::SolidLine);
1329 showAlign(TQt::AlignHCenter);
1330 showVAlign(TQt::AlignVCenter);
1331
1332 m_pStencilGeometryPanel->setSize(0.0,0.0);
1333 m_pStencilGeometryPanel->setPosition(0.0,0.0);
1334 m_pStencilGeometryPanel->setRotation(0);
1335
1336 m_setArrowHeads->setCurrentStartArrow(0);
1337 m_setArrowHeads->setCurrentEndArrow(0);
1338
1339 m_menuTextFormatAction->setEnabled( false );
1340 m_menuStencilConnectorsAction->setEnabled( false );
1341 }
1342 else
1343 {
1344 TQFont f = pStencil->textFont();
1345
1346 m_setFontFamily->setFont( f.family() );
1347 m_setFontSize->setFontSize( f.pointSize() );
1348 m_setBold->setChecked( f.bold() );
1349 m_setItalics->setChecked( f.italic() );
1350 m_setUnderline->setChecked( f.underline() );
1351
1352 m_setFGColor->setCurrentColor(pStencil->fgColor());
1353 m_setBGColor->setCurrentColor(pStencil->bgColor());
1354 m_setTextColor->setCurrentColor(pStencil->textColor());
1355
1356 m_lineWidthAction->setCurrentWidth(pStencil->lineWidth());
1357 m_lineStyleAction->setCurrentSelection(pStencil->linePattern());
1358
1359 showAlign(pStencil->hTextAlign());
1360 showVAlign(pStencil->vTextAlign());
1361
1362 m_pStencilGeometryPanel->setSize( pStencil->w(), pStencil->h() );
1363 m_pStencilGeometryPanel->setPosition( pStencil->x(), pStencil->y() );
1364 m_pStencilGeometryPanel->setRotation(pStencil->rotation());
1365
1366 m_menuTextFormatAction->setEnabled( true );
1367 m_menuStencilConnectorsAction->setEnabled( true );
1368
1369 if ( pStencil->type() != kstConnector )
1370 {
1371 m_setArrowHeads->setEnabled (false);
1372 m_arrowHeadsMenuAction->setEnabled (false);
1373 }
1374 else
1375 {
1376 m_setArrowHeads->setEnabled (true);
1377 m_arrowHeadsMenuAction->setEnabled (true);
1378 m_setArrowHeads->setCurrentStartArrow( pStencil->startAHType() );
1379 m_setArrowHeads->setCurrentEndArrow( pStencil->endAHType() );
1380 }
1381
1382 if ( pStencil->type() != kstText )
1383 {
1384 m_setFGColor->setEnabled (true);
1385 m_setBGColor->setEnabled (true);
1386 }
1387 else
1388 {
1389 m_setFGColor->setEnabled (false);
1390 m_setBGColor->setEnabled (false);
1391 }
1392 }
1393
1394 m_pStencilGeometryPanel->setEmitSignals(true);
1395 m_setArrowHeads->setEmitSignals(true);
1396 m_pProtectionPanel->updateCheckBoxes();
1397
1398 if(activePage()->selectedStencils()->count() > 1) {
1399 m_groupAction->setEnabled(true);
1400 m_alignAndDistribute->setEnabled(true);
1401 } else {
1402 m_groupAction->setEnabled(false);
1403 m_alignAndDistribute->setEnabled(false);
1404 }
1405
1406 if(activePage()->selectedStencils()->count() > 0) {
1407 m_editCut->setEnabled(true);
1408 m_editCopy->setEnabled(true);
1409 m_editDelete->setEnabled(true);
1410
1411 if(activePage()->checkForStencilTypeInSelection(kstGroup)) {
1412 m_ungroupAction->setEnabled(true);
1413 } else {
1414 m_ungroupAction->setEnabled(false);
1415 }
1416
1417 m_stencilToBack->setEnabled(true);
1418 m_stencilToFront->setEnabled(true);
1419 m_pStencilGeometryPanel->setEnabled(true);
1420 m_pProtectionPanel->setEnabled(true);
1421 } else {
1422 m_editCut->setEnabled(false);
1423 m_editCopy->setEnabled(false);
1424 m_editDelete->setEnabled(false);
1425 m_ungroupAction->setEnabled(false);
1426 m_stencilToBack->setEnabled(false);
1427 m_stencilToFront->setEnabled(false);
1428 m_setArrowHeads->setEnabled(false);
1429 m_arrowHeadsMenuAction->setEnabled(false);
1430 m_pStencilGeometryPanel->setEnabled(false);
1431 m_pProtectionPanel->setEnabled(false);
1432 }
1433}
1434
1435void KivioView::slotSetStartArrow( int i )
1436{
1437 if(!m_pActivePage) {
1438 return;
1439 }
1440
1441 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1442 if (!pStencil)
1443 return;
1444
1445 KMacroCommand *macro = new KMacroCommand( i18n("Change Begin Arrow"));
1446 bool createMacro = false;
1447 while( pStencil )
1448 {
1449 if (pStencil->startAHType()!=i)
1450 {
1451 pStencil->setStartAHType(i);
1452 KivioChangeBeginEndArrowCommand *cmd=new KivioChangeBeginEndArrowCommand( i18n("Change Arrow"),
1453 m_pActivePage, pStencil, pStencil->startAHType(), i, true);
1454 pStencil->setStartAHType(i);
1455
1456 macro->addCommand( cmd );
1457 createMacro= true;
1458 }
1459 pStencil = m_pActivePage->selectedStencils()->next();
1460 }
1461 if (createMacro )
1462 m_pDoc->addCommand( macro );
1463 else
1464 delete macro;
1465 m_pDoc->updateView(m_pActivePage);
1466}
1467
1468void KivioView::slotSetEndArrow( int i )
1469{
1470 if(!m_pActivePage) {
1471 return;
1472 }
1473
1474 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1475 if (!pStencil)
1476 return;
1477 KMacroCommand *macro = new KMacroCommand( i18n("Change End Arrow"));
1478 bool createMacro = false;
1479
1480 while( pStencil )
1481 {
1482 if (pStencil->endAHType()!=i)
1483 {
1484 KivioChangeBeginEndArrowCommand *cmd=new KivioChangeBeginEndArrowCommand( i18n("Change Arrow"),
1485 m_pActivePage, pStencil, pStencil->endAHType(), i, false);
1486 pStencil->setEndAHType(i);
1487
1488 macro->addCommand( cmd );
1489 createMacro= true;
1490 }
1491 pStencil = m_pActivePage->selectedStencils()->next();
1492 }
1493 if (createMacro )
1494 m_pDoc->addCommand( macro );
1495 else
1496 delete macro;
1497
1498 m_pDoc->updateView(m_pActivePage);
1499}
1500
1501void KivioView::slotSetStartArrowSize()
1502{
1503 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1504 if (!pStencil)
1505 return;
1506
1507 float w = 0.0;
1508 float h = 0.0;
1509 KMacroCommand *macro = new KMacroCommand( i18n("Change Size of Begin Arrow"));
1510 bool createMacro = false;
1511 while( pStencil )
1512 {
1513 if (pStencil->startAHLength() != h || pStencil->startAHWidth()!=w)
1514 {
1515 KivioChangeBeginEndSizeArrowCommand * cmd = new KivioChangeBeginEndSizeArrowCommand( i18n("Change Size of End Arrow"), m_pActivePage, pStencil, pStencil->startAHLength(),pStencil->startAHWidth(), h,w, true);
1516
1517 pStencil->setStartAHWidth(w);
1518 pStencil->setStartAHLength(h);
1519 macro->addCommand( cmd );
1520 createMacro= true;
1521 }
1522 pStencil = m_pActivePage->selectedStencils()->next();
1523 }
1524 if (createMacro )
1525 m_pDoc->addCommand( macro );
1526 else
1527 delete macro;
1528 m_pDoc->updateView(m_pActivePage);
1529}
1530
1531void KivioView::slotSetEndArrowSize()
1532{
1533 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1534 if (!pStencil)
1535 return;
1536
1537 float w = 0.0;
1538 float h = 0.0;
1539 KMacroCommand *macro = new KMacroCommand( i18n("Change Size of End Arrow"));
1540 bool createMacro = false;
1541 while( pStencil )
1542 {
1543 if ( pStencil->endAHLength() != h || pStencil->endAHWidth()!=w)
1544 {
1545 KivioChangeBeginEndSizeArrowCommand * cmd = new KivioChangeBeginEndSizeArrowCommand( i18n("Change Size of End Arrow"), m_pActivePage, pStencil, pStencil->endAHLength(),pStencil->endAHWidth(), h,w, false);
1546 pStencil->setEndAHWidth(w);
1547 pStencil->setEndAHLength(h);
1548 macro->addCommand( cmd );
1549 createMacro= true;
1550 }
1551 pStencil = m_pActivePage->selectedStencils()->next();
1552 }
1553 if ( createMacro )
1554 m_pDoc->addCommand( macro );
1555 else
1556 delete macro;
1557 m_pDoc->updateView(m_pActivePage);
1558}
1559
1560void KivioView::setHParaAlign( int i )
1561{
1562 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1563 if (!pStencil)
1564 return;
1565 KMacroCommand *macro = new KMacroCommand( i18n("Change Stencil Horizontal Alignment"));
1566 bool createMacro = false;
1567 while( pStencil )
1568 {
1569 if ( pStencil->hTextAlign() != i)
1570 {
1571 KivioChangeStencilHAlignmentCommand * cmd = new KivioChangeStencilHAlignmentCommand( i18n("Change Stencil Horizontal Alignment"), m_pActivePage, pStencil, pStencil->hTextAlign(), i);
1572
1573 pStencil->setHTextAlign(i);
1574 macro->addCommand( cmd );
1575 createMacro = true;
1576 }
1577 pStencil = m_pActivePage->selectedStencils()->next();
1578
1579 }
1580 if (createMacro )
1581 m_pDoc->addCommand( macro );
1582 else
1583 delete macro;
1584 m_pDoc->updateView(m_pActivePage);
1585}
1586
1587
1588void KivioView::setVParaAlign( int i )
1589{
1590 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1591 if (!pStencil)
1592 return;
1593 KMacroCommand *macro = new KMacroCommand( i18n("Change Stencil Vertical Alignment"));
1594 bool createMacro = false;
1595 while( pStencil )
1596 {
1597 if ( pStencil->vTextAlign() != i )
1598 {
1599 KivioChangeStencilVAlignmentCommand * cmd = new KivioChangeStencilVAlignmentCommand( i18n("Change Stencil Vertical Alignment"), m_pActivePage, pStencil, pStencil->vTextAlign(), i);
1600 pStencil->setVTextAlign( i );
1601 macro->addCommand( cmd );
1602 createMacro = true;
1603 }
1604 pStencil = m_pActivePage->selectedStencils()->next();
1605
1606 }
1607 if ( createMacro )
1608 m_pDoc->addCommand( macro );
1609 else
1610 delete macro;
1611 m_pDoc->updateView(m_pActivePage);
1612}
1613
1614void KivioView::bringStencilToFront()
1615{
1616 m_pActivePage->bringToFront();
1617 m_pDoc->updateView(m_pActivePage);
1618}
1619
1620void KivioView::sendStencilToBack()
1621{
1622 m_pActivePage->sendToBack();
1623 m_pDoc->updateView(m_pActivePage);
1624}
1625
1626void KivioView::cutStencil()
1627{
1628 m_pActivePage->cut();
1629 m_pDoc->updateView(m_pActivePage);
1630}
1631
1632void KivioView::copyStencil()
1633{
1634 m_pActivePage->copy();
1635}
1636
1637void KivioView::pasteStencil()
1638{
1639 m_pActivePage->paste(this);
1640 m_pDoc->updateView(m_pActivePage);
1641 m_pCanvas->setFocus();
1642}
1643
1644void KivioView::slotChangeStencilSize(double newW, double newH)
1645{
1646 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1647
1648 if ( pStencil )
1649 {
1650 KoRect oldPos(pStencil->rect());
1651 pStencil->setDimensions(newW, newH);
1652 if ((oldPos.width() != pStencil->rect().width()) || (oldPos.height() != pStencil->rect().height()))
1653 {
1654 KivioMoveStencilCommand * cmd = new KivioMoveStencilCommand( i18n("Resize Stencil"), pStencil, oldPos , pStencil->rect(), m_pCanvas->activePage());
1655 m_pDoc->updateView(m_pActivePage);
1656 m_pDoc->addCommand( cmd );
1657 }
1658 }
1659}
1660
1661void KivioView::slotChangeStencilPosition(double newW, double newH)
1662{
1663 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1664
1665 if ( pStencil )
1666 {
1667 KoRect oldPos(pStencil->rect());
1668 pStencil->setPosition(newW, newH);
1669 if ((oldPos.x() != pStencil->rect().x()) || (oldPos.y() != pStencil->rect().y()))
1670 {
1671 KivioMoveStencilCommand * cmd = new KivioMoveStencilCommand( i18n("Move Stencil"), pStencil, oldPos , pStencil->rect(), m_pCanvas->activePage());
1672 m_pDoc->updateView(m_pActivePage);
1673 m_pDoc->addCommand( cmd );
1674 }
1675 }
1676}
1677
1678void KivioView::slotChangeStencilRotation(int d)
1679{
1680 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1681
1682 if(pStencil && pStencil->rotation() != d) {
1683 pStencil->setRotation(d);
1684 KivioChangeRotationCommand * cmd = new KivioChangeRotationCommand( i18n("Change Stencil Rotation"), m_pCanvas->activePage(), pStencil, pStencil->rotation() , d);
1685 m_pDoc->updateView(m_pActivePage);
1686 m_pDoc->addCommand( cmd );
1687 }
1688}
1689
1693void KivioView::addStencilFromSpawner( KivioStencilSpawner *pSpawner, double x, double y )
1694{
1695 KivioStencil *pStencil;
1696
1697 // Allocate the new stencil and set it's default size/style
1698 pStencil = pSpawner->newStencil();
1699
1700 pStencil->setPosition( x, y );
1701
1702 // Use default properties if we held ctrl down
1703 if(kapp->keyboardMouseState() & TQt::ControlButton) {
1704 pStencil->setFGColor(m_setFGColor->color());
1705 pStencil->setBGColor(m_setBGColor->color());
1706 TQFont f = m_setFontFamily->font();
1707 f.setPointSize(m_setFontSize->fontSize());
1708 f.setBold(m_setBold->isChecked());
1709 f.setItalic(m_setItalics->isChecked());
1710 f.setUnderline(m_setUnderline->isChecked());
1711 pStencil->setTextFont(f);
1712 pStencil->setTextColor(m_setTextColor->color());
1713 pStencil->setVTextAlign(vTextAlign());
1714 pStencil->setHTextAlign(hTextAlign());
1715 pStencil->setLinePattern(m_lineStyleAction->currentSelection());
1716 pStencil->setLineWidth(m_lineWidthAction->currentWidth());
1717 } else {
1718 pStencil->setTextFont(doc()->defaultFont());
1719 }
1720
1721 // Unselect everything, then the stencil to the page, and select it
1722 m_pActivePage->unselectAllStencils();
1723 m_pActivePage->addStencil( pStencil );
1724 m_pActivePage->selectStencil( pStencil );
1725
1726 // Mark the page as modified and repaint
1727 m_pDoc->updateView(m_pActivePage);
1728 pluginManager()->activateDefaultTool();
1729 m_pCanvas->updateAutoGuideLines();
1730}
1731
1732void KivioView::alignStencilsDlg()
1733{
1734 KivioAlignDialog* dlg = new KivioAlignDialog(this, "AlignDialog");
1735
1736 if( dlg->exec() == TQDialog::Accepted )
1737 {
1738 m_pActivePage->alignStencils(dlg->align());
1739 m_pActivePage->distributeStencils(dlg->distribute());
1740
1741 m_pCanvas->repaint();
1742 }
1743
1744 delete dlg;
1745}
1746
1747void KivioView::optionsDialog()
1748{
1749 KivioOptionsDialog dlg(this, "setupDialog");
1750 dlg.exec();
1751}
1752
1753void KivioView::toggleStencilGeometry(bool b)
1754{
1755 TOGGLE_ACTION("stencilGeometry")->setChecked(b);
1756}
1757
1758void KivioView::toggleViewManager(bool b)
1759{
1760 TOGGLE_ACTION("viewManager")->setChecked(b);
1761}
1762
1763void KivioView::setupPrinter(KPrinter &p)
1764{
1765 p.setMinMax(1, m_pDoc->map()->pageList().count());
1766 KoPageLayout pl = activePage()->paperLayout();
1767 p.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pl.format ) ) );
1768
1769 if ( pl.orientation == PG_LANDSCAPE || pl.format == PG_SCREEN ) {
1770 p.setOrientation( KPrinter::Landscape );
1771 } else {
1772 p.setOrientation( KPrinter::Portrait );
1773 }
1774}
1775
1776void KivioView::popupTabBarMenu( const TQPoint & _point )
1777{
1778 if(!koDocument()->isReadWrite() || !factory())
1779 return;
1780 static_cast<TQPopupMenu*>(factory()->container("menupage_popup",this))->popup(_point);
1781}
1782
1783void KivioView::updateMenuPage()
1784{
1785 bool state = (doc()->map()->count() > 1 && doc()->map()->visiblePages().count()>1);
1786 m_removePage->setEnabled(state);
1787 m_hidePage->setEnabled( doc()->map()->visiblePages().count()>1 );
1788 m_showPage->setEnabled( doc()->map()->hiddenPages().count()>0 );
1789}
1790
1791void KivioView::updateButton()
1792{
1793 toggleShowGrid(Kivio::Config::showGrid());
1794 toggleSnapGrid(Kivio::Config::snapGrid());
1795
1796 toggleShowGuides(koDocument()->isReadWrite());
1797}
1798
1799void KivioView::slotPageHidden( KivioPage* /*page*/ )
1800{
1801 //m_pTabBar->hidePage( page->pageName() );
1802}
1803
1804void KivioView::slotPageShown( KivioPage* /*page*/ )
1805{
1806 m_pTabBar->setTabs( m_pDoc->map()->visiblePages() );
1807}
1808
1809void KivioView::resetLayerPanel()
1810{
1811 if ( m_pLayersPanel )
1812 {
1813 m_pLayersPanel->reset();
1814 }
1815}
1816
1817void KivioView::updateProtectPanelCheckBox()
1818{
1819 if ( m_pProtectionPanel )
1820 {
1821 m_pProtectionPanel->updateCheckBoxes();
1822 }
1823}
1824
1825void KivioView::setMousePos( int mx, int my )
1826{
1827 vRuler->setMousePos(mx, my);
1828 hRuler->setMousePos(mx, my);
1829
1830 if((mx >= 0) && (my >= 0)) {
1831 TQString unit = KoUnit::unitName(m_pDoc->unit());
1832 KoPoint xy = m_pCanvas->mapFromScreen(TQPoint(mx, my));
1833 xy.setX(KoUnit::toUserValue(xy.x(), m_pDoc->unit()));
1834 xy.setY(KoUnit::toUserValue(xy.y(), m_pDoc->unit()));
1835 TQString text = i18n("X: %1 %3 Y: %2 %4").arg(TDEGlobal::_locale->formatNumber(xy.x(), 2))
1836 .arg(TDEGlobal::_locale->formatNumber(xy.y(), 2)).arg(unit).arg(unit);
1837 m_coordSLbl->setText(text);
1838 }
1839}
1840
1841void KivioView::setRulerUnit(KoUnit::Unit u)
1842{
1843 vRuler->setUnit(u);
1844 hRuler->setUnit(u);
1845}
1846
1847void KivioView::setRulerHOffset(int h)
1848{
1849 if(hRuler) {
1850 hRuler->setOffset(h - m_pCanvas->pageOffsetX(), 0);
1851 }
1852}
1853
1854void KivioView::setRulerVOffset(int v)
1855{
1856 if(vRuler) {
1857 vRuler->setOffset(0, v - m_pCanvas->pageOffsetY());
1858 }
1859}
1860
1861void KivioView::rulerChangedUnit(KoUnit::Unit u)
1862{
1863 m_pDoc->setUnit(u);
1864}
1865
1866KoZoomHandler* KivioView::zoomHandler() const
1867{
1868 return m_zoomHandler;
1869}
1870
1871void KivioView::setRulerPageLayout(const KoPageLayout& l)
1872{
1873 vRuler->setPageLayout(l);
1874 hRuler->setPageLayout(l);
1875 vRuler->setFrameStartEnd(zoomHandler()->zoomItY(l.ptTop), zoomHandler()->zoomItY(l.ptHeight - l.ptBottom));
1876 hRuler->setFrameStartEnd(zoomHandler()->zoomItX(l.ptLeft), zoomHandler()->zoomItX(l.ptWidth - l.ptRight));
1877 setRulerVOffset(m_vertScrollBar->value());
1878 setRulerHOffset(m_horzScrollBar->value());
1879 m_pStencilGeometryPanel->setPageLayout(l);
1880}
1881
1882void KivioView::viewZoom(const TQString& s)
1883{
1884 TQString z(s);
1885 z.remove('%');
1886 z.simplifyWhiteSpace();
1887 bool ok = false;
1888 int zoom = z.toInt(&ok);
1889
1890 if(!ok || zoom < 10 || zoom > 2000) {
1891 zoom = zoomHandler()->zoom();
1892 }
1893
1894 if(zoom != zoomHandler()->zoom()) {
1895 viewZoom(zoom);
1896 }
1897
1898 canvasWidget()->setFocus();
1899}
1900
1901void KivioView::textAlignLeft()
1902{
1903 if ( m_textAlignLeft->isChecked() ) {
1904 setHParaAlign( TQt::AlignLeft );
1905 } else {
1906 m_textAlignLeft->setChecked( true );
1907 }
1908}
1909
1910void KivioView::textAlignCenter()
1911{
1912 if ( m_textAlignCenter->isChecked() ) {
1913 setHParaAlign( TQt::AlignHCenter );
1914 } else {
1915 m_textAlignCenter->setChecked( true );
1916 }
1917}
1918
1919void KivioView::textAlignRight()
1920{
1921 if ( m_textAlignRight->isChecked() ) {
1922 setHParaAlign( TQt::AlignRight );
1923 } else {
1924 m_textAlignRight->setChecked( true );
1925 }
1926}
1927
1928void KivioView::textSuperScript()
1929{
1930 if ( m_textVAlignSuper->isChecked() ) {
1931 setVParaAlign( TQt::AlignTop );
1932 } else {
1933 if ( !m_textVAlignSub->isChecked() ) {
1934 setVParaAlign( TQt::AlignVCenter );
1935 }
1936 }
1937}
1938
1939void KivioView::textSubScript()
1940{
1941 if ( m_textVAlignSub->isChecked() ) {
1942 setVParaAlign( TQt::AlignBottom );
1943 } else {
1944 if ( !m_textVAlignSuper->isChecked() ) {
1945 setVParaAlign( TQt::AlignVCenter );
1946 }
1947 }
1948}
1949
1950void KivioView::showAlign( int align )
1951{
1952 switch ( align ) {
1953 case TQt::AlignAuto: // In left-to-right mode it's align left. TODO: alignright if text->isRightToLeft()
1954 kdWarning(43000) << k_funcinfo << "shouldn't be called with AlignAuto" << endl;
1955 // fallthrough
1956 case TQt::AlignLeft:
1957 m_textAlignLeft->setChecked( true );
1958 break;
1959 case TQt::AlignHCenter:
1960 m_textAlignCenter->setChecked( true );
1961 break;
1962 case TQt::AlignRight:
1963 m_textAlignRight->setChecked( true );
1964 break;
1965 }
1966}
1967
1968void KivioView::showVAlign( int align )
1969{
1970 switch(align) {
1971 case TQt::AlignTop:
1972 m_textVAlignSuper->setChecked(true);
1973 break;
1974 case TQt::AlignVCenter:
1975 m_textVAlignSuper->setChecked(false);
1976 m_textVAlignSub->setChecked(false);
1977 break;
1978 case TQt::AlignBottom:
1979 m_textVAlignSub->setChecked(true);
1980 break;
1981 }
1982}
1983
1984void KivioView::textFormat()
1985{
1986 KivioTextFormatDlg dlg(this);
1987 KivioStencil* stencil = activePage()->selectedStencils()->getLast();
1988
1989 if(stencil) {
1990 dlg.setFont(stencil->textFont());
1991 dlg.setTextColor(stencil->textColor());
1992 dlg.setHAlign(stencil->hTextAlign());
1993 dlg.setVAlign(stencil->vTextAlign());
1994 } else {
1995 dlg.setFont(doc()->defaultFont());
1996 dlg.setTextColor(TQColor(0, 0, 0));
1997 dlg.setHAlign(TQt::AlignHCenter);
1998 dlg.setVAlign(TQt::AlignVCenter);
1999 }
2000
2001 if(dlg.exec()) {
2002 TQPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
2003
2004 while((stencil = it.current()) != 0) {
2005 ++it;
2006 stencil->setTextFont(dlg.font());
2007 stencil->setTextColor(dlg.textColor());
2008 stencil->setVTextAlign(dlg.valign());
2009 stencil->setHTextAlign(dlg.halign());
2010 }
2011
2012 updateToolBars();
2013 }
2014}
2015
2016void KivioView::stencilFormat()
2017{
2018 KivioStencilFormatDlg dlg(this);
2019 KivioStencil* stencil = activePage()->selectedStencils()->getLast();
2020 KivioLineStyle ls;
2021
2022 if(stencil) {
2023 ls = stencil->lineStyle();
2024 dlg.setFillColor(stencil->bgColor());
2025 dlg.setFillPattern(stencil->fillPattern());
2026 } else {
2027 dlg.setLineWidth(1.0, m_pDoc->unit());
2028 dlg.setLineColor(TQColor(0, 0, 0));
2029 }
2030
2031 dlg.setLineWidth(ls.width(), m_pDoc->unit());
2032 dlg.setLineColor(ls.color());
2033 dlg.setLinePattern(ls.style());
2034 dlg.setLineEndStyle(ls.capStyle());
2035
2036 if(dlg.exec()) {
2037 TQPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
2038
2039 while((stencil = it.current()) != 0) {
2040 ++it;
2041 stencil->setLineWidth(dlg.lineWidth());
2042 stencil->setFGColor(dlg.lineColor());
2043 stencil->setLinePattern(dlg.linePattern());
2044 stencil->setBGColor(dlg.fillColor());
2045 stencil->setFillPattern(dlg.fillPattern());
2046 }
2047
2048 updateToolBars();
2049 }
2050}
2051
2052void KivioView::arrowHeadFormat()
2053{
2054 KivioArrowHeadFormatDlg dlg(this);
2055 dlg.setUnit(m_pDoc->unit());
2056 dlg.setStartAHType(0);
2057 dlg.setEndAHType(0);
2058 dlg.setStartAHWidth(10.0);
2059 dlg.setStartAHHeight(10.0);
2060 dlg.setEndAHWidth(10.0);
2061 dlg.setEndAHHeight(10.0);
2062
2063 KivioStencil* stencil = activePage()->selectedStencils()->getLast();
2064
2065 if(stencil) {
2066 if(stencil->type() == kstConnector) {
2067 dlg.setUnit(m_pDoc->unit());
2068 dlg.setStartAHType(stencil->startAHType());
2069 dlg.setEndAHType(stencil->endAHType());
2070 dlg.setStartAHWidth(stencil->startAHWidth());
2071 dlg.setStartAHHeight(stencil->startAHLength());
2072 dlg.setEndAHWidth(stencil->endAHWidth());
2073 dlg.setEndAHHeight(stencil->endAHLength());
2074 }
2075 }
2076
2077 if(dlg.exec()) {
2078 TQPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
2079
2080 while((stencil = it.current()) != 0) {
2081 ++it;
2082
2083 if(stencil->type() == kstConnector) {
2084 stencil->setStartAHType(dlg.startAHType());
2085 stencil->setEndAHType(dlg.endAHType());
2086 stencil->setStartAHWidth(dlg.startAHWidth());
2087 stencil->setStartAHLength(dlg.startAHHeight());
2088 stencil->setEndAHWidth(dlg.endAHWidth());
2089 stencil->setEndAHLength(dlg.endAHHeight());
2090 }
2091 }
2092
2093 updateToolBars();
2094 }
2095}
2096
2097Kivio::PluginManager* KivioView::pluginManager()
2098{
2099 return m_pluginManager;
2100}
2101
2102void KivioView::clipboardDataChanged()
2103{
2104 TQMimeSource* data = TQApplication::clipboard()->data();
2105 KivioDragObject decoder(this);
2106 bool paste = decoder.canDecode(data);
2107 m_editPaste->setEnabled(paste);
2108}
2109
2110void KivioView::partActivateEvent(KParts::PartActivateEvent* event)
2111{
2112 if((event->widget() == this) && event->activated()) {
2113 updateToolBars();
2114 clipboardDataChanged();
2115 }
2116
2117 if(event->widget() == this) {
2118 m_pluginManager->setEventDelegationEnabled(event->activated());
2119 m_pStencilBarDockManager->setAllStackBarsShown(event->activated());
2120 }
2121
2122 KoView::partActivateEvent(event);
2123}
2124
2125void KivioView::initStatusBarProgress()
2126{
2127 if(!m_statusBarProgress) {
2128 m_statusBarProgress = new TQProgressBar(100, this);
2129 addStatusBarItem(m_statusBarProgress);
2130 }
2131
2132 m_statusBarProgress->reset();
2133}
2134
2135void KivioView::setStatusBarProgress(int progress)
2136{
2137 if(m_statusBarProgress) {
2138 m_statusBarProgress->setProgress(progress);
2139 }
2140}
2141
2142void KivioView::removeStatusBarProgress()
2143{
2144 if(m_statusBarProgress) {
2145 removeStatusBarItem(m_statusBarProgress);
2146 delete m_statusBarProgress;
2147 m_statusBarProgress = 0;
2148 }
2149}
2150
2151void KivioView::installStencilSet()
2152{
2153 Kivio::StencilSetInstaller dlg(this);
2154 dlg.exec();
2155 emit updateStencilSetList();
2156}
2157
2158int KivioView::hTextAlign()
2159{
2160 if(m_textAlignRight->isChecked()) {
2161 return TQt::AlignRight;
2162 } else if(m_textAlignLeft->isChecked()) {
2163 return TQt::AlignLeft;
2164 }
2165
2166 return TQt::AlignHCenter;
2167}
2168
2169int KivioView::vTextAlign()
2170{
2171 if(m_textVAlignSub->isChecked() && !m_textVAlignSuper->isChecked()) {
2172 return TQt::AlignBottom;
2173 } else if(!m_textVAlignSub->isChecked() && m_textVAlignSuper->isChecked()) {
2174 return TQt::AlignTop;
2175 }
2176
2177 return TQt::AlignVCenter;
2178}
2179
2180void KivioView::updatePageStatusLabel()
2181{
2182 TQString text = i18n("Page %1/%2").arg(m_pDoc->map()->pageList().find(activePage()) + 1).arg(m_pDoc->map()->count());
2183 m_pageCountSLbl->setText(text);
2184}
2185
2186void KivioView::setStatusBarInfo(const TQString& text)
2187{
2188 m_infoSLbl->setText(text);
2189}
2190
2191void KivioView::loadingFinished()
2192{
2193 m_pTabBar->clear();
2194 TQPtrList<KivioPage> pages = m_pDoc->map()->pageList();
2195 TQPtrListIterator<KivioPage> it(pages);
2196 KivioPage* page;
2197
2198 while((page = it.current()) != 0) {
2199 ++it;
2200 addPage(page);
2201 }
2202
2203 setActivePage(m_pDoc->map()->firstPage());
2204 m_pTabBar->setActiveTab(activePage()->pageName());
2205
2206 if( m_pDoc->isReadWrite() ) // only if not embedded in Konqueror
2207 {
2208 KivioStencilSpawnerSet *pSet;
2209 pSet = m_pDoc->spawnerSets()->first();
2210 while( pSet )
2211 {
2212 addSpawnerToStackBar( pSet );
2213 pSet = m_pDoc->spawnerSets()->next();
2214 }
2215 }
2216}
2217
2218void KivioView::moveTab(unsigned tab, unsigned target)
2219{
2220 TQStringList tabs = m_pTabBar->tabs();
2221 TQString tabTitle = tabs[tab];
2222 TQString targetTitle = tabs[target];
2223
2224 if(target >= static_cast<unsigned>(m_pDoc->map()->count())) {
2225 targetTitle = m_pDoc->map()->lastPage()->pageName();
2226 }
2227
2228 m_pDoc->map()->movePage(tabTitle, targetTitle, target < static_cast<unsigned>(m_pDoc->map()->count()));
2229 m_pTabBar->moveTab(tab, target);
2230}
2231
2232void KivioView::deleteObject()
2233{
2234 activePage()->deleteSelectedStencils();
2235 m_pDoc->updateView(activePage());
2236}
2237
2238void KivioView::addGuideLine()
2239{
2240 KoPageLayout pl = activePage()->paperLayout();
2241 KoRect pageRect(0.0, 0.0, pl.ptWidth, pl.ptHeight);
2242 KoPoint pos(0.0, 0.0);
2243 KoGuideLineDia dlg(this, pos, pageRect, m_pDoc->unit(), "addGuideDialog");
2244
2245 if(dlg.exec() == TQDialog::Accepted) {
2246 activePage()->addGuideLine(dlg.orientation(), dlg.pos());
2247 m_pDoc->updateGuideLines(activePage());
2248 }
2249}
2250
2251void KivioView::showAddStencilSetDialog()
2252{
2253 if(!m_addStencilSetDialog) {
2254 m_addStencilSetDialog = new Kivio::AddStencilSetDialog(this, "AddStencilSetDialog");
2255 connect(m_addStencilSetDialog, TQ_SIGNAL(addStencilSet(const TQString&)), this, TQ_SLOT(addStencilSet(const TQString&)));
2256 connect(this, TQ_SIGNAL(updateStencilSetList()), m_addStencilSetDialog, TQ_SLOT(updateList()));
2257 }
2258
2259 m_addStencilSetDialog->show();
2260}
2261
2262void KivioView::updateRulers()
2263{
2264 m_pCanvas->updateScrollBars();
2265 setRulerVOffset(m_vertScrollBar->value());
2266 setRulerHOffset(m_horzScrollBar->value());
2267}
2268
2269#include "kivio_view.moc"
Tool used to add new stencils to the canvas.
static KoPageLayout defaultPageLayout()
Get the default page layout.
This class manages the plugins.