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#if KDE_IS_VERSION(3,2,90)
487 showPageMargins->setCheckedState(i18n("Hide Page Margins"));
488#endif
489
490 showRulers = new TDEToggleAction( i18n("Show Rulers"), "view_ruler", 0, actionCollection(), "showRulers" );
491 connect( showRulers, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleShowRulers(bool)));
492#if KDE_IS_VERSION(3,2,90)
493 showRulers->setCheckedState(i18n("Hide Rulers"));
494#endif
495
496 // Grid actions
497 showGrid = new TDEToggleAction( i18n("Show Grid"), "view_grid", 0, actionCollection(), "showGrid" );
498 connect( showGrid, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleShowGrid(bool)));
499#if KDE_IS_VERSION(3,2,90)
500 showGrid->setCheckedState(i18n("Hide Grid"));
501#endif
502
503 TDEToggleAction* snapGrid = new TDEToggleAction( i18n("Snap Grid"), "view_grid", 0, actionCollection(), "snapGrid" );
504 connect( snapGrid, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleSnapGrid(bool)));
505
506 // Guides actions
507 showGuides = new TDEToggleAction( i18n("Guide Lines"), 0, actionCollection(), "showGuides" );
508 connect( showGuides, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleShowGuides(bool)));
509 TDEAction* addGuide = new TDEAction(i18n("Add Guide Line..."), 0, this, TQ_SLOT(addGuideLine()),
510 actionCollection(), "addGuideLine");
511 connect(showGuides, TQ_SIGNAL(toggled(bool)), addGuide, TQ_SLOT(setEnabled(bool)));
512 //--
513
514 m_setArrowHeads = new KivioArrowHeadAction(i18n("Arrowheads"), "arrowheads", actionCollection(), "arrowHeads");
515 m_setArrowHeads->setWhatsThis(i18n("Arrowheads allow you to add an arrow to the beginning and/or end of a line."));
516 connect( m_setArrowHeads, TQ_SIGNAL(endChanged(int)), TQ_SLOT(slotSetEndArrow(int)));
517 connect( m_setArrowHeads, TQ_SIGNAL(startChanged(int)), TQ_SLOT(slotSetStartArrow(int)));
518
519 KStdAction::preferences(this, TQ_SLOT(optionsDialog()), actionCollection(), "options");
520
521 (void) new TDEAction(i18n("Install Stencil Set..."), 0, this,
522 TQ_SLOT(installStencilSet()), actionCollection(), "installStencilSet");
523
524 m_editDelete = new TDEAction(i18n("Delete"), "edit-delete", Key_Delete,
525 this, TQ_SLOT(deleteObject()), actionCollection(), "deleteObject");
526}
527
528void KivioView::initActions()
529{
530 togglePageMargins(true);
531 toggleShowRulers(true);
532
533 updateButton();
534
535 m_setFontFamily->setFont( doc()->defaultFont().family() );
536 m_setFontSize->setFontSize( doc()->defaultFont().pointSize() );
537 m_setBold->setChecked( false );
538 m_setItalics->setChecked( false );
539 m_setUnderline->setChecked( false );
540 m_lineWidthAction->setCurrentWidth(1.0);
541 m_lineStyleAction->setCurrentSelection(TQt::SolidLine);
542 showAlign(TQt::AlignHCenter);
543 showVAlign(TQt::AlignVCenter);
544
545 m_pStencilGeometryPanel->setSize(0.0,0.0);
546 m_pStencilGeometryPanel->setPosition(0.0,0.0);
547 m_pStencilGeometryPanel->setRotation(0);
548
549 m_setArrowHeads->setCurrentStartArrow(0);
550 m_setArrowHeads->setCurrentEndArrow(0);
551
552 m_menuTextFormatAction->setEnabled( false );
553 m_menuStencilConnectorsAction->setEnabled( false );
554
555 m_setFGColor->setCurrentColor(TQColor(0, 0, 0));
556 m_setBGColor->setCurrentColor(TQColor(255, 255, 255));
557 m_setTextColor->setCurrentColor(TQColor(0, 0, 0));
558
559 viewZoom(zoomHandler()->zoom());
560}
561
562void KivioView::updateReadWrite( bool readwrite )
563{
564 TQValueList<TDEAction*> actions = actionCollection()->actions();
565 TQValueList<TDEAction*>::ConstIterator aIt = actions.begin();
566 TQValueList<TDEAction*>::ConstIterator aEnd = actions.end();
567 for (; aIt != aEnd; ++aIt )
568 (*aIt)->setEnabled( readwrite );
569 if ( !readwrite )
570 {
571 showPageMargins->setEnabled( true );
572 showRulers->setEnabled( true );
573 showGrid->setEnabled( true );
574 showGuides->setEnabled( true );
575 m_selectAll->setEnabled( true );
576 m_selectNone->setEnabled( true );
577 m_editCopy->setEnabled( true );
578 }
579 m_showPage->setEnabled( true );
580 m_hidePage->setEnabled( true );
581 updateMenuPage();
582}
583
584
585void KivioView::addPage( KivioPage* page )
586{
587 insertPage( page );
588
589 TQObject::connect( page, TQ_SIGNAL( sig_PageHidden( KivioPage* ) ),
590 this, TQ_SLOT( slotPageHidden( KivioPage* ) ) );
591 TQObject::connect( page, TQ_SIGNAL( sig_PageShown( KivioPage* ) ),
592 this, TQ_SLOT( slotPageShown( KivioPage* ) ) );
593
594 updatePageStatusLabel();
595}
596
597void KivioView::insertPage( KivioPage* page )
598{
599 if(!page->isHidden()) {
600 m_pTabBar->addTab(page->pageName());
601 setActivePage(page);
602 updateMenuPage();
603 }
604}
605
606void KivioView::removePage( KivioPage *_t )
607{
608 TQString m_pageName=_t->pageName();
609 m_pTabBar->removeTab( _t->pageName() );
610 TQString n = m_pDoc->map()->visiblePages().first();
611 setActivePage( m_pDoc->map()->findPage( n ) );
612
613 updatePageStatusLabel();
614}
615
616void KivioView::renamePage()
617{
618 bool ok;
619 TQString activeName = m_pActivePage->pageName();
620 TQString newName = KInputDialog::getText( i18n("Rename Page"),
621 i18n("Enter page name:"), activeName, &ok, this );
622
623 // Have a different name ?
624 if ( ok ) // User pushed an OK button.
625 {
626 if ( (newName.stripWhiteSpace()).isEmpty() ) // Page name is empty.
627 {
628 KNotifyClient::beep();
629 KMessageBox::information( this, i18n("Page name cannot be empty."),
630 i18n("Change Page Name") );
631 // Recursion
632 renamePage();
633 }
634 else if ( newName != activeName ) // Page name changed.
635 {
636 // Is the name already used
637 if ( !m_pActivePage->setPageName( newName ) )
638 {
639 KNotifyClient::beep();
640 KMessageBox::information( this, i18n("This name is already used."),
641 i18n("Change Page Name") );
642 // Recursion
643 renamePage();
644 }
645 KivioChangePageNameCommand *cmd = new KivioChangePageNameCommand(i18n("Rename Page"), activeName, newName, m_pActivePage);
646 m_pDoc->addCommand( cmd );
647 }
648 }
649}
650
651void KivioView::setActivePage( KivioPage* page )
652{
653 if ( page == m_pActivePage )
654 return;
655
656 if(m_pActivePage) {
657 disconnect(m_pActivePage, TQ_SIGNAL(sig_pageLayoutChanged(const KoPageLayout&)), this,
658 TQ_SLOT(setRulerPageLayout(const KoPageLayout&)));
659 }
660
661 m_pActivePage = page;
662
663 m_pTabBar->setActiveTab(m_pActivePage->pageName());
664 updateToolBars();
665
666 m_pLayersPanel->reset();
667
668 m_pDoc->updateView(m_pActivePage);
669 setRulerPageLayout(m_pActivePage->paperLayout());
670 connect(m_pActivePage, TQ_SIGNAL(sig_pageLayoutChanged(const KoPageLayout&)),
671 TQ_SLOT(setRulerPageLayout(const KoPageLayout&)));
672
673 m_pCanvas->guideLines().setGuideLines(m_pActivePage->horizontalGuideLines(),
674 m_pActivePage->verticalGuideLines());
675 m_objectListPalette->updateObjectList();
676}
677
678void KivioView::setActiveSpawnerSet( KivioStencilSpawnerSet *set )
679{
680 if( set == m_pActiveSpawnerSet )
681 return;
682
683 m_pActiveSpawnerSet = set;
684}
685
686void KivioView::slotPageRenamed( KivioPage* page, const TQString& old_name )
687{
688 m_pTabBar->renameTab( old_name, page->pageName() );
689}
690
691void KivioView::changePage( const TQString& name )
692{
693 if ( m_pActivePage->pageName() == name )
694 return;
695
696 KivioPage *t = m_pDoc->map()->findPage(name);
697 if (!t)
698 return;
699
700 setActivePage(t);
701 updatePageStatusLabel();
702}
703
704void KivioView::insertPage()
705{
706 KivioPage * t =m_pDoc->createPage();
707 m_pDoc->addPage(t);
708 KivioAddPageCommand * cmd = new KivioAddPageCommand(i18n("Insert Page"), t);
709 m_pDoc->addCommand( cmd );
710
711 updatePageStatusLabel();
712}
713
714void KivioView::hidePage()
715{
716 if (!m_pActivePage)
717 return;
718
719 if ( m_pDoc->map()->visiblePages().count() == 1)
720 {
721 KMessageBox::error( this, i18n("You cannot hide the last visible page.") );
722 return;
723 }
724
725 m_pActivePage->setHidden(true);
726 TQString activeName = m_pActivePage->pageName();
727
728 m_pTabBar->removeTab( activeName );
729
730 KivioHidePageCommand * cmd = new KivioHidePageCommand(i18n("Hide Page"), m_pActivePage);
731 m_pDoc->addCommand( cmd );
732
733 changePage( m_pDoc->map()->visiblePages().first() );
734 updateMenuPage();
735}
736
737void KivioView::showPage()
738{
739 KivioPageShow* dlg = new KivioPageShow(this,"Page show");
740 if ( !dlg->exec() )
741 {
742 delete dlg;
743 return;
744 }
745 m_pTabBar->setTabs( m_pDoc->map()->visiblePages() );
746 updateMenuPage();
747 delete dlg;
748}
749
750int KivioView::leftBorder() const
751{
752 int retVal = 0;
753
754 if(isShowRulers()) {
755 retVal = vertRuler()->width();
756 }
757
758 return retVal;
759}
760
761int KivioView::rightBorder() const
762{
763 return m_vertScrollBar->width();
764}
765
766int KivioView::topBorder() const
767{
768 int retVal = 0;
769
770 if(isShowRulers()) {
771 retVal = horzRuler()->height();
772 }
773
774 return retVal;
775}
776
777int KivioView::bottomBorder() const
778{
779 return m_horzScrollBar->height();
780}
781
782void KivioView::paperLayoutDlg()
783{
784 KivioPage* page = activePage();
785 KoPageLayout l = page->paperLayout();
786 KoHeadFoot headfoot;
787 int tabs = FORMAT_AND_BORDERS | DISABLE_UNIT;
788 KoUnit::Unit unit = doc()->unit();
789
790 if(KoPageLayoutDia::pageLayout(l, headfoot, tabs, unit))
791 {
792 KivioDoc* doc = page->doc();
793 KivioChangeLayoutCommand * cmd = new KivioChangeLayoutCommand(
794 i18n("Change Page Layout"),page ,page->paperLayout(), l);
795 doc->addCommand( cmd );
796 page->setPaperLayout(l);
797 }
798}
799
800void KivioView::removePage()
801{
802 if ( doc()->map()->count() <= 1 || doc()->map()->visiblePages().count()<=1 ) {
803 TQApplication::beep();
804 KMessageBox::sorry( this, i18n("You cannot delete the only page of the document."), i18n("Remove Page") );
805 return;
806 }
807 TQApplication::beep();
808 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"));
809
810 if ( ret == KMessageBox::Continue ) {
811 KivioPage* tbl = m_pActivePage;
812 KivioRemovePageCommand *cmd = new KivioRemovePageCommand(i18n("Remove Page"), tbl);
813 cmd->execute();
814 doc()->addCommand( cmd );
815 }
816}
817
818void KivioView::slotUpdateView( KivioPage* page )
819{
820 if (page && page != m_pActivePage)
821 return;
822
823 // global view updates (toolbar, statusbar.... actions...)
824 updateToolBars();
825
826 m_pCanvas->update();
827 m_pCanvas->updateScrollBars();
828 vRuler->update();
829 hRuler->update();
830 m_objectListPalette->updateObjectList();
831}
832
833TQWidget *KivioView::canvas() const
834{
835 return canvasWidget();
836}
837
838int KivioView::canvasXOffset() const
839{
840 return canvasWidget()->xOffset();
841}
842
843int KivioView::canvasYOffset() const
844{
845 return canvasWidget()->yOffset();
846}
847
848void KivioView::print(KPrinter& ptr)
849{
850 ptr.setFullPage(true);
851 m_pDoc->printContent( ptr );
852}
853
854
855void KivioView::viewZoom(int zoom)
856{
857 if(zoom < 10 || zoom > 2000 || zoom == zoomHandler()->zoom()) {
858 return;
859 }
860
861 KoPoint centerPoint = m_pCanvas->visibleArea().center();
862 zoomHandler()->setZoomAndResolution(zoom, KoGlobal::dpiX(),
863 KoGlobal::dpiY());
864 vRuler->setZoom(zoomHandler()->zoomedResolutionY());
865 hRuler->setZoom(zoomHandler()->zoomedResolutionX());
866 KoPageLayout l = activePage()->paperLayout();
867 vRuler->setFrameStartEnd(zoomHandler()->zoomItY(l.ptTop), zoomHandler()->zoomItY(l.ptHeight - l.ptBottom));
868 hRuler->setFrameStartEnd(zoomHandler()->zoomItX(l.ptLeft), zoomHandler()->zoomItX(l.ptWidth - l.ptRight));
869 setRulerVOffset(m_vertScrollBar->value());
870 setRulerHOffset(m_horzScrollBar->value());
871 KoView::setZoom(zoomHandler()->zoomedResolutionY());
872 m_pCanvas->setViewCenterPoint(centerPoint);
873 m_pCanvas->update();
874 m_pCanvas->updateScrollBars();
875
876 emit zoomChanged(zoom);
877}
878
879KivioPage* KivioView::activePage() const
880{
881 return m_pActivePage;
882}
883
884void KivioView::togglePageMargins(bool b)
885{
886 TOGGLE_ACTION("showPageMargins")->setChecked(b);
887 m_bShowPageMargins = b;
888
889 m_pCanvas->update();
890}
891
892void KivioView::toggleShowRulers(bool b)
893{
894 TOGGLE_ACTION("showRulers")->setChecked(b);
895 m_bShowRulers = b;
896
897 if(b) {
898 hRuler->show();
899 vRuler->show();
900 } else {
901 hRuler->hide();
902 vRuler->hide();
903 }
904}
905
906void KivioView::toggleShowGuides(bool b)
907{
908 TOGGLE_ACTION("showGuides")->setChecked(b);
909 m_bShowGuides = b;
910 m_bSnapGuides = b;
911
912 m_pCanvas->update();
913}
914
915void KivioView::toggleShowGrid(bool b)
916{
917 TOGGLE_ACTION("showGrid")->setChecked(b);
918
919 Kivio::Config::setShowGrid(b);
920 m_pDoc->setModified( true );
921}
922
923void KivioView::slotUpdateGrid()
924{
925 m_pCanvas->update();
926}
927
928void KivioView::toggleSnapGrid(bool b)
929{
930 TOGGLE_ACTION("snapGrid")->setChecked(b);
931
932 Kivio::Config::setSnapGrid(b);
933 m_pDoc->setModified( true );
934}
935
936void KivioView::addStencilSet( const TQString& name )
937{
938 m_pDoc->addSpawnerSet(name);
939}
940
941void KivioView::addSpawnerToStackBar( KivioStencilSpawnerSet *pSpawner )
942{
943 if(!pSpawner) {
944 kdDebug(43000) << "KivioView::addSpawnerToStackBar() - NULL pSpawner" << endl;
945 return;
946 }
947
948 if(pSpawner->hidden()) {
949 return;
950 }
951
952 KivioIconView *pView = new KivioIconView(m_pDoc->isReadWrite());
953 TQObject::connect(pView, TQ_SIGNAL(createNewStencil(KivioStencilSpawner*)), this,
954 TQ_SLOT(addStencilFromSpawner(KivioStencilSpawner*)));
955 connect(pView, TQ_SIGNAL(stencilSelected(KivioStencilSpawner*)),
956 m_addStencilTool, TQ_SLOT(activateNewStencil(KivioStencilSpawner* )));
957
958 pView->setStencilSpawnerSet(pSpawner);
959 m_pStencilBarDockManager->insertStencilSet(pView, pSpawner->name());
960}
961
962void KivioView::setFGColor()
963{
964 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
965 if (!pStencil)
966 return;
967 KMacroCommand * macro = new KMacroCommand( i18n("Change Foreground Color"));
968 bool createMacro = false;
969 while( pStencil )
970 {
971 TQColor col( m_setFGColor->color());
972
973 if ( col != pStencil->fgColor() )
974 {
975 KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Fg Color"), m_pActivePage, pStencil, pStencil->fgColor(), col, KivioChangeStencilColorCommand::CT_FGCOLOR);
976
977 pStencil->setFGColor( col );
978 macro->addCommand( cmd );
979 createMacro = true;
980 }
981
982 pStencil = m_pActivePage->selectedStencils()->next();
983 }
984
985 if ( createMacro )
986 m_pDoc->addCommand( macro );
987 else
988 delete macro;
989
990 m_pDoc->updateView(m_pActivePage);
991}
992
993void KivioView::setBGColor()
994{
995 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
996 if (!pStencil)
997 return;
998 KMacroCommand * macro = new KMacroCommand( i18n("Change Background Color"));
999 bool createMacro = false;
1000
1001 while( pStencil )
1002 {
1003 TQColor col( m_setBGColor->color());
1004
1005 if ( col != pStencil->bgColor() )
1006 {
1007 KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Bg Color"), m_pActivePage, pStencil, pStencil->bgColor(), col, KivioChangeStencilColorCommand::CT_BGCOLOR);
1008
1009 pStencil->setBGColor( col );
1010 macro->addCommand( cmd );
1011 createMacro = true;
1012 }
1013
1014 pStencil = m_pActivePage->selectedStencils()->next();
1015 }
1016
1017 if ( createMacro )
1018 m_pDoc->addCommand( macro );
1019 else
1020 delete macro;
1021
1022 m_pDoc->updateView(m_pActivePage);
1023}
1024
1025void KivioView::setTextColor()
1026{
1027 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1028
1029 if (!pStencil)
1030 return;
1031
1032 KMacroCommand * macro = new KMacroCommand( i18n("Change Text Color"));
1033 bool createMacro = false;
1034 while( pStencil )
1035 {
1036 TQColor col(m_setTextColor->color());
1037
1038 if ( col != pStencil->textColor() )
1039 {
1040 KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Text Color"), m_pActivePage, pStencil, pStencil->textColor(), col, KivioChangeStencilColorCommand::CT_TEXTCOLOR);
1041 pStencil->setTextColor( col );
1042 macro->addCommand( cmd );
1043 createMacro = true;
1044 }
1045
1046 pStencil = m_pActivePage->selectedStencils()->next();
1047 }
1048
1049 if ( createMacro )
1050 m_pDoc->addCommand( macro );
1051 else
1052 delete macro;
1053
1054 m_pDoc->updateView(m_pActivePage);
1055}
1056
1057void KivioView::setLineWidth(double width)
1058{
1059 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1060
1061 if (!pStencil)
1062 return;
1063
1064 KMacroCommand * macro = new KMacroCommand( i18n("Change Line Width") );
1065 bool createMacro = false ;
1066
1067 while( pStencil )
1068 {
1069 if ( width != pStencil->lineWidth() )
1070 {
1071 KivioChangeLineWidthCommand * cmd = new KivioChangeLineWidthCommand( i18n("Change Line Width"),
1072 m_pActivePage, pStencil, pStencil->lineWidth(), width );
1073
1074 pStencil->setLineWidth( width );
1075 macro->addCommand( cmd );
1076 createMacro = true;
1077 }
1078
1079 pStencil = m_pActivePage->selectedStencils()->next();
1080 }
1081
1082 if ( createMacro ) {
1083 m_pDoc->addCommand( macro );
1084 } else {
1085 delete macro;
1086 }
1087
1088 m_pDoc->updateView(m_pActivePage);
1089}
1090
1091void KivioView::setLineStyle(int style)
1092{
1093 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1094
1095 if(!pStencil)
1096 return;
1097
1098 KMacroCommand * macro = new KMacroCommand( i18n("Change Line Style") );
1099 bool createMacro = false ;
1100
1101 while(pStencil)
1102 {
1103 if(style != pStencil->linePattern())
1104 {
1105 KivioChangeLineStyleCommand * cmd = new KivioChangeLineStyleCommand( i18n("Change Line Style"),
1106 m_pActivePage, pStencil, pStencil->linePattern(), style );
1107 pStencil->setLinePattern(style);
1108 macro->addCommand( cmd );
1109 createMacro = true;
1110 }
1111
1112 pStencil = m_pActivePage->selectedStencils()->next();
1113 }
1114
1115 if ( createMacro ) {
1116 m_pDoc->addCommand( macro );
1117 } else {
1118 delete macro;
1119 }
1120}
1121
1122void KivioView::groupStencils()
1123{
1124 m_pActivePage->groupSelectedStencils();
1125 m_pDoc->updateView(m_pActivePage);
1126}
1127
1128void KivioView::ungroupStencils()
1129{
1130 m_pActivePage->ungroupSelectedStencils();
1131 m_pDoc->updateView(m_pActivePage);
1132}
1133
1134void KivioView::selectAllStencils()
1135{
1136 m_pActivePage->selectAllStencils();
1137 m_pCanvas->repaint();
1138}
1139
1140void KivioView::unselectAllStencils()
1141{
1142 m_pActivePage->unselectAllStencils();
1143 m_pCanvas->repaint();
1144}
1145
1146TQColor KivioView::fgColor() const
1147{
1148 return m_setFGColor->color();
1149}
1150
1151TQColor KivioView::bgColor() const
1152{
1153 return m_setBGColor->color();
1154}
1155
1156double KivioView::lineWidth() const
1157{
1158 return m_lineWidthAction->currentWidth();
1159}
1160
1161int KivioView::lineStyle() const
1162{
1163 return m_lineStyleAction->currentSelection();
1164}
1165
1166
1167void KivioView::setFontFamily( const TQString &str )
1168{
1169 canvasWidget()->setFocus();
1170 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1171 if (!pStencil)
1172 return;
1173
1174 TQFont f;
1175 KMacroCommand * macro = 0L;
1176 while( pStencil )
1177 {
1178 f = pStencil->textFont();
1179 f.setFamily( str );
1180 if ( pStencil->textFont() != f )
1181 {
1182 if ( !macro )
1183 macro = new KMacroCommand( i18n("Change Stencil Font"));
1184
1185 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1186 pStencil->setTextFont( f );
1187
1188 macro->addCommand( cmd );
1189 }
1190 pStencil = m_pActivePage->selectedStencils()->next();
1191
1192 }
1193 if ( macro )
1194 m_pDoc->addCommand( macro );
1195 m_pDoc->updateView(m_pActivePage);
1196}
1197
1198void KivioView::setFontSize(int size )
1199{
1200 canvasWidget()->setFocus();
1201 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1202 if (!pStencil)
1203 return;
1204
1205 TQFont f;
1206 KMacroCommand * macro = 0L;
1207 while( pStencil )
1208 {
1209 f = pStencil->textFont();
1210 f.setPointSize( size );
1211 if ( pStencil->textFont() != f )
1212 {
1213 if ( !macro )
1214 macro = new KMacroCommand( i18n("Change Stencil Font"));
1215
1216 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1217
1218 pStencil->setTextFont( f );
1219 macro->addCommand( cmd );
1220 }
1221 pStencil = m_pActivePage->selectedStencils()->next();
1222
1223 }
1224 if ( macro )
1225 m_pDoc->addCommand( macro );
1226 m_pDoc->updateView(m_pActivePage);
1227}
1228
1229void KivioView::toggleFontBold(bool b)
1230{
1231 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1232 if (!pStencil)
1233 return;
1234
1235 TQFont f;
1236 KMacroCommand * macro = 0L;
1237 while( pStencil )
1238 {
1239 f = pStencil->textFont();
1240 f.setBold(b);
1241 if ( pStencil->textFont() != f )
1242 {
1243 if ( !macro )
1244 macro = new KMacroCommand( i18n("Change Stencil Font"));
1245 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1246
1247 pStencil->setTextFont( f );
1248 macro->addCommand( cmd );
1249 }
1250 pStencil = m_pActivePage->selectedStencils()->next();
1251
1252 }
1253 if ( macro )
1254 m_pDoc->addCommand( macro );
1255 m_pDoc->updateView(m_pActivePage);
1256}
1257
1258void KivioView::toggleFontItalics(bool b)
1259{
1260 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1261 if (!pStencil)
1262 return;
1263
1264 TQFont f;
1265 KMacroCommand * macro = new KMacroCommand( i18n("Change Stencil Font"));
1266 while( pStencil )
1267 {
1268 f = pStencil->textFont();
1269 f.setItalic(b);
1270 if ( pStencil->textFont() != f )
1271 {
1272 if ( !macro )
1273 macro = new KMacroCommand( i18n("Change Stencil Font"));
1274
1275 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1276
1277 pStencil->setTextFont( f );
1278
1279 macro->addCommand( cmd );
1280 }
1281 pStencil = m_pActivePage->selectedStencils()->next();
1282 }
1283 if ( macro )
1284 m_pDoc->addCommand( macro );
1285 m_pDoc->updateView(m_pActivePage);
1286}
1287
1288void KivioView::toggleFontUnderline( bool b)
1289{
1290 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1291 if (!pStencil)
1292 return;
1293 KMacroCommand * macro = 0L;
1294 TQFont f;
1295 while( pStencil )
1296 {
1297 f = pStencil->textFont();
1298 f.setUnderline(b);
1299 if ( pStencil->textFont() != f )
1300 {
1301 if ( !macro )
1302 macro = new KMacroCommand( i18n("Change Stencil Font"));
1303
1304 KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(), f);
1305
1306 pStencil->setTextFont( f );
1307
1308 macro->addCommand( cmd );
1309 }
1310 pStencil = m_pActivePage->selectedStencils()->next();
1311 }
1312 if ( macro )
1313 m_pDoc->addCommand( macro );
1314 m_pDoc->updateView(m_pActivePage);
1315}
1316
1317
1318
1319void KivioView::updateToolBars()
1320{
1321 KivioStencil *pStencil;
1322 pStencil = m_pActivePage->selectedStencils()->first();
1323 m_pStencilGeometryPanel->setEmitSignals(false);
1324 m_setArrowHeads->setEmitSignals(false);
1325
1326 if( !pStencil )
1327 {
1328 m_setFontFamily->setFont( doc()->defaultFont().family() );
1329 m_setFontSize->setFontSize( doc()->defaultFont().pointSize() );
1330 m_setBold->setChecked( false );
1331 m_setItalics->setChecked( false );
1332 m_setUnderline->setChecked( false );
1333 m_lineWidthAction->setCurrentWidth(1.0);
1334 m_lineStyleAction->setCurrentSelection(TQt::SolidLine);
1335 showAlign(TQt::AlignHCenter);
1336 showVAlign(TQt::AlignVCenter);
1337
1338 m_pStencilGeometryPanel->setSize(0.0,0.0);
1339 m_pStencilGeometryPanel->setPosition(0.0,0.0);
1340 m_pStencilGeometryPanel->setRotation(0);
1341
1342 m_setArrowHeads->setCurrentStartArrow(0);
1343 m_setArrowHeads->setCurrentEndArrow(0);
1344
1345 m_menuTextFormatAction->setEnabled( false );
1346 m_menuStencilConnectorsAction->setEnabled( false );
1347 }
1348 else
1349 {
1350 TQFont f = pStencil->textFont();
1351
1352 m_setFontFamily->setFont( f.family() );
1353 m_setFontSize->setFontSize( f.pointSize() );
1354 m_setBold->setChecked( f.bold() );
1355 m_setItalics->setChecked( f.italic() );
1356 m_setUnderline->setChecked( f.underline() );
1357
1358 m_setFGColor->setCurrentColor(pStencil->fgColor());
1359 m_setBGColor->setCurrentColor(pStencil->bgColor());
1360 m_setTextColor->setCurrentColor(pStencil->textColor());
1361
1362 m_lineWidthAction->setCurrentWidth(pStencil->lineWidth());
1363 m_lineStyleAction->setCurrentSelection(pStencil->linePattern());
1364
1365 showAlign(pStencil->hTextAlign());
1366 showVAlign(pStencil->vTextAlign());
1367
1368 m_pStencilGeometryPanel->setSize( pStencil->w(), pStencil->h() );
1369 m_pStencilGeometryPanel->setPosition( pStencil->x(), pStencil->y() );
1370 m_pStencilGeometryPanel->setRotation(pStencil->rotation());
1371
1372 m_menuTextFormatAction->setEnabled( true );
1373 m_menuStencilConnectorsAction->setEnabled( true );
1374
1375 if ( pStencil->type() != kstConnector )
1376 {
1377 m_setArrowHeads->setEnabled (false);
1378 m_arrowHeadsMenuAction->setEnabled (false);
1379 }
1380 else
1381 {
1382 m_setArrowHeads->setEnabled (true);
1383 m_arrowHeadsMenuAction->setEnabled (true);
1384 m_setArrowHeads->setCurrentStartArrow( pStencil->startAHType() );
1385 m_setArrowHeads->setCurrentEndArrow( pStencil->endAHType() );
1386 }
1387
1388 if ( pStencil->type() != kstText )
1389 {
1390 m_setFGColor->setEnabled (true);
1391 m_setBGColor->setEnabled (true);
1392 }
1393 else
1394 {
1395 m_setFGColor->setEnabled (false);
1396 m_setBGColor->setEnabled (false);
1397 }
1398 }
1399
1400 m_pStencilGeometryPanel->setEmitSignals(true);
1401 m_setArrowHeads->setEmitSignals(true);
1402 m_pProtectionPanel->updateCheckBoxes();
1403
1404 if(activePage()->selectedStencils()->count() > 1) {
1405 m_groupAction->setEnabled(true);
1406 m_alignAndDistribute->setEnabled(true);
1407 } else {
1408 m_groupAction->setEnabled(false);
1409 m_alignAndDistribute->setEnabled(false);
1410 }
1411
1412 if(activePage()->selectedStencils()->count() > 0) {
1413 m_editCut->setEnabled(true);
1414 m_editCopy->setEnabled(true);
1415 m_editDelete->setEnabled(true);
1416
1417 if(activePage()->checkForStencilTypeInSelection(kstGroup)) {
1418 m_ungroupAction->setEnabled(true);
1419 } else {
1420 m_ungroupAction->setEnabled(false);
1421 }
1422
1423 m_stencilToBack->setEnabled(true);
1424 m_stencilToFront->setEnabled(true);
1425 m_pStencilGeometryPanel->setEnabled(true);
1426 m_pProtectionPanel->setEnabled(true);
1427 } else {
1428 m_editCut->setEnabled(false);
1429 m_editCopy->setEnabled(false);
1430 m_editDelete->setEnabled(false);
1431 m_ungroupAction->setEnabled(false);
1432 m_stencilToBack->setEnabled(false);
1433 m_stencilToFront->setEnabled(false);
1434 m_setArrowHeads->setEnabled(false);
1435 m_arrowHeadsMenuAction->setEnabled(false);
1436 m_pStencilGeometryPanel->setEnabled(false);
1437 m_pProtectionPanel->setEnabled(false);
1438 }
1439}
1440
1441void KivioView::slotSetStartArrow( int i )
1442{
1443 if(!m_pActivePage) {
1444 return;
1445 }
1446
1447 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1448 if (!pStencil)
1449 return;
1450
1451 KMacroCommand *macro = new KMacroCommand( i18n("Change Begin Arrow"));
1452 bool createMacro = false;
1453 while( pStencil )
1454 {
1455 if (pStencil->startAHType()!=i)
1456 {
1457 pStencil->setStartAHType(i);
1458 KivioChangeBeginEndArrowCommand *cmd=new KivioChangeBeginEndArrowCommand( i18n("Change Arrow"),
1459 m_pActivePage, pStencil, pStencil->startAHType(), i, true);
1460 pStencil->setStartAHType(i);
1461
1462 macro->addCommand( cmd );
1463 createMacro= true;
1464 }
1465 pStencil = m_pActivePage->selectedStencils()->next();
1466 }
1467 if (createMacro )
1468 m_pDoc->addCommand( macro );
1469 else
1470 delete macro;
1471 m_pDoc->updateView(m_pActivePage);
1472}
1473
1474void KivioView::slotSetEndArrow( int i )
1475{
1476 if(!m_pActivePage) {
1477 return;
1478 }
1479
1480 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1481 if (!pStencil)
1482 return;
1483 KMacroCommand *macro = new KMacroCommand( i18n("Change End Arrow"));
1484 bool createMacro = false;
1485
1486 while( pStencil )
1487 {
1488 if (pStencil->endAHType()!=i)
1489 {
1490 KivioChangeBeginEndArrowCommand *cmd=new KivioChangeBeginEndArrowCommand( i18n("Change Arrow"),
1491 m_pActivePage, pStencil, pStencil->endAHType(), i, false);
1492 pStencil->setEndAHType(i);
1493
1494 macro->addCommand( cmd );
1495 createMacro= true;
1496 }
1497 pStencil = m_pActivePage->selectedStencils()->next();
1498 }
1499 if (createMacro )
1500 m_pDoc->addCommand( macro );
1501 else
1502 delete macro;
1503
1504 m_pDoc->updateView(m_pActivePage);
1505}
1506
1507void KivioView::slotSetStartArrowSize()
1508{
1509 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1510 if (!pStencil)
1511 return;
1512
1513 float w = 0.0;
1514 float h = 0.0;
1515 KMacroCommand *macro = new KMacroCommand( i18n("Change Size of Begin Arrow"));
1516 bool createMacro = false;
1517 while( pStencil )
1518 {
1519 if (pStencil->startAHLength() != h || pStencil->startAHWidth()!=w)
1520 {
1521 KivioChangeBeginEndSizeArrowCommand * cmd = new KivioChangeBeginEndSizeArrowCommand( i18n("Change Size of End Arrow"), m_pActivePage, pStencil, pStencil->startAHLength(),pStencil->startAHWidth(), h,w, true);
1522
1523 pStencil->setStartAHWidth(w);
1524 pStencil->setStartAHLength(h);
1525 macro->addCommand( cmd );
1526 createMacro= true;
1527 }
1528 pStencil = m_pActivePage->selectedStencils()->next();
1529 }
1530 if (createMacro )
1531 m_pDoc->addCommand( macro );
1532 else
1533 delete macro;
1534 m_pDoc->updateView(m_pActivePage);
1535}
1536
1537void KivioView::slotSetEndArrowSize()
1538{
1539 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1540 if (!pStencil)
1541 return;
1542
1543 float w = 0.0;
1544 float h = 0.0;
1545 KMacroCommand *macro = new KMacroCommand( i18n("Change Size of End Arrow"));
1546 bool createMacro = false;
1547 while( pStencil )
1548 {
1549 if ( pStencil->endAHLength() != h || pStencil->endAHWidth()!=w)
1550 {
1551 KivioChangeBeginEndSizeArrowCommand * cmd = new KivioChangeBeginEndSizeArrowCommand( i18n("Change Size of End Arrow"), m_pActivePage, pStencil, pStencil->endAHLength(),pStencil->endAHWidth(), h,w, false);
1552 pStencil->setEndAHWidth(w);
1553 pStencil->setEndAHLength(h);
1554 macro->addCommand( cmd );
1555 createMacro= true;
1556 }
1557 pStencil = m_pActivePage->selectedStencils()->next();
1558 }
1559 if ( createMacro )
1560 m_pDoc->addCommand( macro );
1561 else
1562 delete macro;
1563 m_pDoc->updateView(m_pActivePage);
1564}
1565
1566void KivioView::setHParaAlign( int i )
1567{
1568 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1569 if (!pStencil)
1570 return;
1571 KMacroCommand *macro = new KMacroCommand( i18n("Change Stencil Horizontal Alignment"));
1572 bool createMacro = false;
1573 while( pStencil )
1574 {
1575 if ( pStencil->hTextAlign() != i)
1576 {
1577 KivioChangeStencilHAlignmentCommand * cmd = new KivioChangeStencilHAlignmentCommand( i18n("Change Stencil Horizontal Alignment"), m_pActivePage, pStencil, pStencil->hTextAlign(), i);
1578
1579 pStencil->setHTextAlign(i);
1580 macro->addCommand( cmd );
1581 createMacro = true;
1582 }
1583 pStencil = m_pActivePage->selectedStencils()->next();
1584
1585 }
1586 if (createMacro )
1587 m_pDoc->addCommand( macro );
1588 else
1589 delete macro;
1590 m_pDoc->updateView(m_pActivePage);
1591}
1592
1593
1594void KivioView::setVParaAlign( int i )
1595{
1596 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1597 if (!pStencil)
1598 return;
1599 KMacroCommand *macro = new KMacroCommand( i18n("Change Stencil Vertical Alignment"));
1600 bool createMacro = false;
1601 while( pStencil )
1602 {
1603 if ( pStencil->vTextAlign() != i )
1604 {
1605 KivioChangeStencilVAlignmentCommand * cmd = new KivioChangeStencilVAlignmentCommand( i18n("Change Stencil Vertical Alignment"), m_pActivePage, pStencil, pStencil->vTextAlign(), i);
1606 pStencil->setVTextAlign( i );
1607 macro->addCommand( cmd );
1608 createMacro = true;
1609 }
1610 pStencil = m_pActivePage->selectedStencils()->next();
1611
1612 }
1613 if ( createMacro )
1614 m_pDoc->addCommand( macro );
1615 else
1616 delete macro;
1617 m_pDoc->updateView(m_pActivePage);
1618}
1619
1620void KivioView::bringStencilToFront()
1621{
1622 m_pActivePage->bringToFront();
1623 m_pDoc->updateView(m_pActivePage);
1624}
1625
1626void KivioView::sendStencilToBack()
1627{
1628 m_pActivePage->sendToBack();
1629 m_pDoc->updateView(m_pActivePage);
1630}
1631
1632void KivioView::cutStencil()
1633{
1634 m_pActivePage->cut();
1635 m_pDoc->updateView(m_pActivePage);
1636}
1637
1638void KivioView::copyStencil()
1639{
1640 m_pActivePage->copy();
1641}
1642
1643void KivioView::pasteStencil()
1644{
1645 m_pActivePage->paste(this);
1646 m_pDoc->updateView(m_pActivePage);
1647 m_pCanvas->setFocus();
1648}
1649
1650void KivioView::slotChangeStencilSize(double newW, double newH)
1651{
1652 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1653
1654 if ( pStencil )
1655 {
1656 KoRect oldPos(pStencil->rect());
1657 pStencil->setDimensions(newW, newH);
1658 if ((oldPos.width() != pStencil->rect().width()) || (oldPos.height() != pStencil->rect().height()))
1659 {
1660 KivioMoveStencilCommand * cmd = new KivioMoveStencilCommand( i18n("Resize Stencil"), pStencil, oldPos , pStencil->rect(), m_pCanvas->activePage());
1661 m_pDoc->updateView(m_pActivePage);
1662 m_pDoc->addCommand( cmd );
1663 }
1664 }
1665}
1666
1667void KivioView::slotChangeStencilPosition(double newW, double newH)
1668{
1669 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1670
1671 if ( pStencil )
1672 {
1673 KoRect oldPos(pStencil->rect());
1674 pStencil->setPosition(newW, newH);
1675 if ((oldPos.x() != pStencil->rect().x()) || (oldPos.y() != pStencil->rect().y()))
1676 {
1677 KivioMoveStencilCommand * cmd = new KivioMoveStencilCommand( i18n("Move Stencil"), pStencil, oldPos , pStencil->rect(), m_pCanvas->activePage());
1678 m_pDoc->updateView(m_pActivePage);
1679 m_pDoc->addCommand( cmd );
1680 }
1681 }
1682}
1683
1684void KivioView::slotChangeStencilRotation(int d)
1685{
1686 KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
1687
1688 if(pStencil && pStencil->rotation() != d) {
1689 pStencil->setRotation(d);
1690 KivioChangeRotationCommand * cmd = new KivioChangeRotationCommand( i18n("Change Stencil Rotation"), m_pCanvas->activePage(), pStencil, pStencil->rotation() , d);
1691 m_pDoc->updateView(m_pActivePage);
1692 m_pDoc->addCommand( cmd );
1693 }
1694}
1695
1699void KivioView::addStencilFromSpawner( KivioStencilSpawner *pSpawner, double x, double y )
1700{
1701 KivioStencil *pStencil;
1702
1703 // Allocate the new stencil and set it's default size/style
1704 pStencil = pSpawner->newStencil();
1705
1706 pStencil->setPosition( x, y );
1707
1708 // Use default properties if we held ctrl down
1709#if KDE_IS_VERSION(3, 4, 0)
1710 if(kapp->keyboardMouseState() & TQt::ControlButton) {
1711#else
1712 if(TDEApplication::keyboardModifiers() & TDEApplication::ControlModifier) {
1713#endif
1714 pStencil->setFGColor(m_setFGColor->color());
1715 pStencil->setBGColor(m_setBGColor->color());
1716 TQFont f = m_setFontFamily->font();
1717 f.setPointSize(m_setFontSize->fontSize());
1718 f.setBold(m_setBold->isChecked());
1719 f.setItalic(m_setItalics->isChecked());
1720 f.setUnderline(m_setUnderline->isChecked());
1721 pStencil->setTextFont(f);
1722 pStencil->setTextColor(m_setTextColor->color());
1723 pStencil->setVTextAlign(vTextAlign());
1724 pStencil->setHTextAlign(hTextAlign());
1725 pStencil->setLinePattern(m_lineStyleAction->currentSelection());
1726 pStencil->setLineWidth(m_lineWidthAction->currentWidth());
1727 } else {
1728 pStencil->setTextFont(doc()->defaultFont());
1729 }
1730
1731 // Unselect everything, then the stencil to the page, and select it
1732 m_pActivePage->unselectAllStencils();
1733 m_pActivePage->addStencil( pStencil );
1734 m_pActivePage->selectStencil( pStencil );
1735
1736 // Mark the page as modified and repaint
1737 m_pDoc->updateView(m_pActivePage);
1738 pluginManager()->activateDefaultTool();
1739 m_pCanvas->updateAutoGuideLines();
1740}
1741
1742void KivioView::alignStencilsDlg()
1743{
1744 KivioAlignDialog* dlg = new KivioAlignDialog(this, "AlignDialog");
1745
1746 if( dlg->exec() == TQDialog::Accepted )
1747 {
1748 m_pActivePage->alignStencils(dlg->align());
1749 m_pActivePage->distributeStencils(dlg->distribute());
1750
1751 m_pCanvas->repaint();
1752 }
1753
1754 delete dlg;
1755}
1756
1757void KivioView::optionsDialog()
1758{
1759 KivioOptionsDialog dlg(this, "setupDialog");
1760 dlg.exec();
1761}
1762
1763void KivioView::toggleStencilGeometry(bool b)
1764{
1765 TOGGLE_ACTION("stencilGeometry")->setChecked(b);
1766}
1767
1768void KivioView::toggleViewManager(bool b)
1769{
1770 TOGGLE_ACTION("viewManager")->setChecked(b);
1771}
1772
1773void KivioView::setupPrinter(KPrinter &p)
1774{
1775 p.setMinMax(1, m_pDoc->map()->pageList().count());
1776 KoPageLayout pl = activePage()->paperLayout();
1777 p.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pl.format ) ) );
1778
1779 if ( pl.orientation == PG_LANDSCAPE || pl.format == PG_SCREEN ) {
1780 p.setOrientation( KPrinter::Landscape );
1781 } else {
1782 p.setOrientation( KPrinter::Portrait );
1783 }
1784}
1785
1786void KivioView::popupTabBarMenu( const TQPoint & _point )
1787{
1788 if(!koDocument()->isReadWrite() || !factory())
1789 return;
1790 static_cast<TQPopupMenu*>(factory()->container("menupage_popup",this))->popup(_point);
1791}
1792
1793void KivioView::updateMenuPage()
1794{
1795 bool state = (doc()->map()->count() > 1 && doc()->map()->visiblePages().count()>1);
1796 m_removePage->setEnabled(state);
1797 m_hidePage->setEnabled( doc()->map()->visiblePages().count()>1 );
1798 m_showPage->setEnabled( doc()->map()->hiddenPages().count()>0 );
1799}
1800
1801void KivioView::updateButton()
1802{
1803 toggleShowGrid(Kivio::Config::showGrid());
1804 toggleSnapGrid(Kivio::Config::snapGrid());
1805
1806 toggleShowGuides(koDocument()->isReadWrite());
1807}
1808
1809void KivioView::slotPageHidden( KivioPage* /*page*/ )
1810{
1811 //m_pTabBar->hidePage( page->pageName() );
1812}
1813
1814void KivioView::slotPageShown( KivioPage* /*page*/ )
1815{
1816 m_pTabBar->setTabs( m_pDoc->map()->visiblePages() );
1817}
1818
1819void KivioView::resetLayerPanel()
1820{
1821 if ( m_pLayersPanel )
1822 {
1823 m_pLayersPanel->reset();
1824 }
1825}
1826
1827void KivioView::updateProtectPanelCheckBox()
1828{
1829 if ( m_pProtectionPanel )
1830 {
1831 m_pProtectionPanel->updateCheckBoxes();
1832 }
1833}
1834
1835void KivioView::setMousePos( int mx, int my )
1836{
1837 vRuler->setMousePos(mx, my);
1838 hRuler->setMousePos(mx, my);
1839
1840 if((mx >= 0) && (my >= 0)) {
1841 TQString unit = KoUnit::unitName(m_pDoc->unit());
1842 KoPoint xy = m_pCanvas->mapFromScreen(TQPoint(mx, my));
1843 xy.setX(KoUnit::toUserValue(xy.x(), m_pDoc->unit()));
1844 xy.setY(KoUnit::toUserValue(xy.y(), m_pDoc->unit()));
1845 TQString text = i18n("X: %1 %3 Y: %2 %4").arg(TDEGlobal::_locale->formatNumber(xy.x(), 2))
1846 .arg(TDEGlobal::_locale->formatNumber(xy.y(), 2)).arg(unit).arg(unit);
1847 m_coordSLbl->setText(text);
1848 }
1849}
1850
1851void KivioView::setRulerUnit(KoUnit::Unit u)
1852{
1853 vRuler->setUnit(u);
1854 hRuler->setUnit(u);
1855}
1856
1857void KivioView::setRulerHOffset(int h)
1858{
1859 if(hRuler) {
1860 hRuler->setOffset(h - m_pCanvas->pageOffsetX(), 0);
1861 }
1862}
1863
1864void KivioView::setRulerVOffset(int v)
1865{
1866 if(vRuler) {
1867 vRuler->setOffset(0, v - m_pCanvas->pageOffsetY());
1868 }
1869}
1870
1871void KivioView::rulerChangedUnit(KoUnit::Unit u)
1872{
1873 m_pDoc->setUnit(u);
1874}
1875
1876KoZoomHandler* KivioView::zoomHandler() const
1877{
1878 return m_zoomHandler;
1879}
1880
1881void KivioView::setRulerPageLayout(const KoPageLayout& l)
1882{
1883 vRuler->setPageLayout(l);
1884 hRuler->setPageLayout(l);
1885 vRuler->setFrameStartEnd(zoomHandler()->zoomItY(l.ptTop), zoomHandler()->zoomItY(l.ptHeight - l.ptBottom));
1886 hRuler->setFrameStartEnd(zoomHandler()->zoomItX(l.ptLeft), zoomHandler()->zoomItX(l.ptWidth - l.ptRight));
1887 setRulerVOffset(m_vertScrollBar->value());
1888 setRulerHOffset(m_horzScrollBar->value());
1889 m_pStencilGeometryPanel->setPageLayout(l);
1890}
1891
1892void KivioView::viewZoom(const TQString& s)
1893{
1894 TQString z(s);
1895 z.remove('%');
1896 z.simplifyWhiteSpace();
1897 bool ok = false;
1898 int zoom = z.toInt(&ok);
1899
1900 if(!ok || zoom < 10 || zoom > 2000) {
1901 zoom = zoomHandler()->zoom();
1902 }
1903
1904 if(zoom != zoomHandler()->zoom()) {
1905 viewZoom(zoom);
1906 }
1907
1908 canvasWidget()->setFocus();
1909}
1910
1911void KivioView::textAlignLeft()
1912{
1913 if ( m_textAlignLeft->isChecked() ) {
1914 setHParaAlign( TQt::AlignLeft );
1915 } else {
1916 m_textAlignLeft->setChecked( true );
1917 }
1918}
1919
1920void KivioView::textAlignCenter()
1921{
1922 if ( m_textAlignCenter->isChecked() ) {
1923 setHParaAlign( TQt::AlignHCenter );
1924 } else {
1925 m_textAlignCenter->setChecked( true );
1926 }
1927}
1928
1929void KivioView::textAlignRight()
1930{
1931 if ( m_textAlignRight->isChecked() ) {
1932 setHParaAlign( TQt::AlignRight );
1933 } else {
1934 m_textAlignRight->setChecked( true );
1935 }
1936}
1937
1938void KivioView::textSuperScript()
1939{
1940 if ( m_textVAlignSuper->isChecked() ) {
1941 setVParaAlign( TQt::AlignTop );
1942 } else {
1943 if ( !m_textVAlignSub->isChecked() ) {
1944 setVParaAlign( TQt::AlignVCenter );
1945 }
1946 }
1947}
1948
1949void KivioView::textSubScript()
1950{
1951 if ( m_textVAlignSub->isChecked() ) {
1952 setVParaAlign( TQt::AlignBottom );
1953 } else {
1954 if ( !m_textVAlignSuper->isChecked() ) {
1955 setVParaAlign( TQt::AlignVCenter );
1956 }
1957 }
1958}
1959
1960void KivioView::showAlign( int align )
1961{
1962 switch ( align ) {
1963 case TQt::AlignAuto: // In left-to-right mode it's align left. TODO: alignright if text->isRightToLeft()
1964 kdWarning(43000) << k_funcinfo << "shouldn't be called with AlignAuto" << endl;
1965 // fallthrough
1966 case TQt::AlignLeft:
1967 m_textAlignLeft->setChecked( true );
1968 break;
1969 case TQt::AlignHCenter:
1970 m_textAlignCenter->setChecked( true );
1971 break;
1972 case TQt::AlignRight:
1973 m_textAlignRight->setChecked( true );
1974 break;
1975 }
1976}
1977
1978void KivioView::showVAlign( int align )
1979{
1980 switch(align) {
1981 case TQt::AlignTop:
1982 m_textVAlignSuper->setChecked(true);
1983 break;
1984 case TQt::AlignVCenter:
1985 m_textVAlignSuper->setChecked(false);
1986 m_textVAlignSub->setChecked(false);
1987 break;
1988 case TQt::AlignBottom:
1989 m_textVAlignSub->setChecked(true);
1990 break;
1991 }
1992}
1993
1994void KivioView::textFormat()
1995{
1996 KivioTextFormatDlg dlg(this);
1997 KivioStencil* stencil = activePage()->selectedStencils()->getLast();
1998
1999 if(stencil) {
2000 dlg.setFont(stencil->textFont());
2001 dlg.setTextColor(stencil->textColor());
2002 dlg.setHAlign(stencil->hTextAlign());
2003 dlg.setVAlign(stencil->vTextAlign());
2004 } else {
2005 dlg.setFont(doc()->defaultFont());
2006 dlg.setTextColor(TQColor(0, 0, 0));
2007 dlg.setHAlign(TQt::AlignHCenter);
2008 dlg.setVAlign(TQt::AlignVCenter);
2009 }
2010
2011 if(dlg.exec()) {
2012 TQPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
2013
2014 while((stencil = it.current()) != 0) {
2015 ++it;
2016 stencil->setTextFont(dlg.font());
2017 stencil->setTextColor(dlg.textColor());
2018 stencil->setVTextAlign(dlg.valign());
2019 stencil->setHTextAlign(dlg.halign());
2020 }
2021
2022 updateToolBars();
2023 }
2024}
2025
2026void KivioView::stencilFormat()
2027{
2028 KivioStencilFormatDlg dlg(this);
2029 KivioStencil* stencil = activePage()->selectedStencils()->getLast();
2030 KivioLineStyle ls;
2031
2032 if(stencil) {
2033 ls = stencil->lineStyle();
2034 dlg.setFillColor(stencil->bgColor());
2035 dlg.setFillPattern(stencil->fillPattern());
2036 } else {
2037 dlg.setLineWidth(1.0, m_pDoc->unit());
2038 dlg.setLineColor(TQColor(0, 0, 0));
2039 }
2040
2041 dlg.setLineWidth(ls.width(), m_pDoc->unit());
2042 dlg.setLineColor(ls.color());
2043 dlg.setLinePattern(ls.style());
2044 dlg.setLineEndStyle(ls.capStyle());
2045
2046 if(dlg.exec()) {
2047 TQPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
2048
2049 while((stencil = it.current()) != 0) {
2050 ++it;
2051 stencil->setLineWidth(dlg.lineWidth());
2052 stencil->setFGColor(dlg.lineColor());
2053 stencil->setLinePattern(dlg.linePattern());
2054 stencil->setBGColor(dlg.fillColor());
2055 stencil->setFillPattern(dlg.fillPattern());
2056 }
2057
2058 updateToolBars();
2059 }
2060}
2061
2062void KivioView::arrowHeadFormat()
2063{
2064 KivioArrowHeadFormatDlg dlg(this);
2065 dlg.setUnit(m_pDoc->unit());
2066 dlg.setStartAHType(0);
2067 dlg.setEndAHType(0);
2068 dlg.setStartAHWidth(10.0);
2069 dlg.setStartAHHeight(10.0);
2070 dlg.setEndAHWidth(10.0);
2071 dlg.setEndAHHeight(10.0);
2072
2073 KivioStencil* stencil = activePage()->selectedStencils()->getLast();
2074
2075 if(stencil) {
2076 if(stencil->type() == kstConnector) {
2077 dlg.setUnit(m_pDoc->unit());
2078 dlg.setStartAHType(stencil->startAHType());
2079 dlg.setEndAHType(stencil->endAHType());
2080 dlg.setStartAHWidth(stencil->startAHWidth());
2081 dlg.setStartAHHeight(stencil->startAHLength());
2082 dlg.setEndAHWidth(stencil->endAHWidth());
2083 dlg.setEndAHHeight(stencil->endAHLength());
2084 }
2085 }
2086
2087 if(dlg.exec()) {
2088 TQPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
2089
2090 while((stencil = it.current()) != 0) {
2091 ++it;
2092
2093 if(stencil->type() == kstConnector) {
2094 stencil->setStartAHType(dlg.startAHType());
2095 stencil->setEndAHType(dlg.endAHType());
2096 stencil->setStartAHWidth(dlg.startAHWidth());
2097 stencil->setStartAHLength(dlg.startAHHeight());
2098 stencil->setEndAHWidth(dlg.endAHWidth());
2099 stencil->setEndAHLength(dlg.endAHHeight());
2100 }
2101 }
2102
2103 updateToolBars();
2104 }
2105}
2106
2107Kivio::PluginManager* KivioView::pluginManager()
2108{
2109 return m_pluginManager;
2110}
2111
2112void KivioView::clipboardDataChanged()
2113{
2114 TQMimeSource* data = TQApplication::clipboard()->data();
2115 KivioDragObject decoder(this);
2116 bool paste = decoder.canDecode(data);
2117 m_editPaste->setEnabled(paste);
2118}
2119
2120void KivioView::partActivateEvent(KParts::PartActivateEvent* event)
2121{
2122 if((event->widget() == this) && event->activated()) {
2123 updateToolBars();
2124 clipboardDataChanged();
2125 }
2126
2127 if(event->widget() == this) {
2128 m_pluginManager->setEventDelegationEnabled(event->activated());
2129 m_pStencilBarDockManager->setAllStackBarsShown(event->activated());
2130 }
2131
2132 KoView::partActivateEvent(event);
2133}
2134
2135void KivioView::initStatusBarProgress()
2136{
2137 if(!m_statusBarProgress) {
2138 m_statusBarProgress = new TQProgressBar(100, this);
2139 addStatusBarItem(m_statusBarProgress);
2140 }
2141
2142 m_statusBarProgress->reset();
2143}
2144
2145void KivioView::setStatusBarProgress(int progress)
2146{
2147 if(m_statusBarProgress) {
2148 m_statusBarProgress->setProgress(progress);
2149 }
2150}
2151
2152void KivioView::removeStatusBarProgress()
2153{
2154 if(m_statusBarProgress) {
2155 removeStatusBarItem(m_statusBarProgress);
2156 delete m_statusBarProgress;
2157 m_statusBarProgress = 0;
2158 }
2159}
2160
2161void KivioView::installStencilSet()
2162{
2163 Kivio::StencilSetInstaller dlg(this);
2164 dlg.exec();
2165 emit updateStencilSetList();
2166}
2167
2168int KivioView::hTextAlign()
2169{
2170 if(m_textAlignRight->isChecked()) {
2171 return TQt::AlignRight;
2172 } else if(m_textAlignLeft->isChecked()) {
2173 return TQt::AlignLeft;
2174 }
2175
2176 return TQt::AlignHCenter;
2177}
2178
2179int KivioView::vTextAlign()
2180{
2181 if(m_textVAlignSub->isChecked() && !m_textVAlignSuper->isChecked()) {
2182 return TQt::AlignBottom;
2183 } else if(!m_textVAlignSub->isChecked() && m_textVAlignSuper->isChecked()) {
2184 return TQt::AlignTop;
2185 }
2186
2187 return TQt::AlignVCenter;
2188}
2189
2190void KivioView::updatePageStatusLabel()
2191{
2192 TQString text = i18n("Page %1/%2").arg(m_pDoc->map()->pageList().find(activePage()) + 1).arg(m_pDoc->map()->count());
2193 m_pageCountSLbl->setText(text);
2194}
2195
2196void KivioView::setStatusBarInfo(const TQString& text)
2197{
2198 m_infoSLbl->setText(text);
2199}
2200
2201void KivioView::loadingFinished()
2202{
2203 m_pTabBar->clear();
2204 TQPtrList<KivioPage> pages = m_pDoc->map()->pageList();
2205 TQPtrListIterator<KivioPage> it(pages);
2206 KivioPage* page;
2207
2208 while((page = it.current()) != 0) {
2209 ++it;
2210 addPage(page);
2211 }
2212
2213 setActivePage(m_pDoc->map()->firstPage());
2214 m_pTabBar->setActiveTab(activePage()->pageName());
2215
2216 if( m_pDoc->isReadWrite() ) // only if not embedded in Konqueror
2217 {
2218 KivioStencilSpawnerSet *pSet;
2219 pSet = m_pDoc->spawnerSets()->first();
2220 while( pSet )
2221 {
2222 addSpawnerToStackBar( pSet );
2223 pSet = m_pDoc->spawnerSets()->next();
2224 }
2225 }
2226}
2227
2228void KivioView::moveTab(unsigned tab, unsigned target)
2229{
2230 TQStringList tabs = m_pTabBar->tabs();
2231 TQString tabTitle = tabs[tab];
2232 TQString targetTitle = tabs[target];
2233
2234 if(target >= static_cast<unsigned>(m_pDoc->map()->count())) {
2235 targetTitle = m_pDoc->map()->lastPage()->pageName();
2236 }
2237
2238 m_pDoc->map()->movePage(tabTitle, targetTitle, target < static_cast<unsigned>(m_pDoc->map()->count()));
2239 m_pTabBar->moveTab(tab, target);
2240}
2241
2242void KivioView::deleteObject()
2243{
2244 activePage()->deleteSelectedStencils();
2245 m_pDoc->updateView(activePage());
2246}
2247
2248void KivioView::addGuideLine()
2249{
2250 KoPageLayout pl = activePage()->paperLayout();
2251 KoRect pageRect(0.0, 0.0, pl.ptWidth, pl.ptHeight);
2252 KoPoint pos(0.0, 0.0);
2253 KoGuideLineDia dlg(this, pos, pageRect, m_pDoc->unit(), "addGuideDialog");
2254
2255 if(dlg.exec() == TQDialog::Accepted) {
2256 activePage()->addGuideLine(dlg.orientation(), dlg.pos());
2257 m_pDoc->updateGuideLines(activePage());
2258 }
2259}
2260
2261void KivioView::showAddStencilSetDialog()
2262{
2263 if(!m_addStencilSetDialog) {
2264 m_addStencilSetDialog = new Kivio::AddStencilSetDialog(this, "AddStencilSetDialog");
2265 connect(m_addStencilSetDialog, TQ_SIGNAL(addStencilSet(const TQString&)), this, TQ_SLOT(addStencilSet(const TQString&)));
2266 connect(this, TQ_SIGNAL(updateStencilSetList()), m_addStencilSetDialog, TQ_SLOT(updateList()));
2267 }
2268
2269 m_addStencilSetDialog->show();
2270}
2271
2272void KivioView::updateRulers()
2273{
2274 m_pCanvas->updateScrollBars();
2275 setRulerVOffset(m_vertScrollBar->value());
2276 setRulerHOffset(m_horzScrollBar->value());
2277}
2278
2279#include "kivio_view.moc"
Tool used to add new stencils to the canvas.
static KoPageLayout defaultPageLayout()
Get the default page layout.
Palette showing a list of all objects on the page.
This class manages the plugins.