kivio

kivio_view.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2004 theKompany.com & Dave Marotti,
00004  *                         Peter Simonsson
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 #include <kprinter.h> // has to be first
00021 
00022 #include <iostream>
00023 #include <stdlib.h>
00024 #include <time.h>
00025 #include <assert.h>
00026 
00027 #include <qlayout.h>
00028 #include <qwidgetstack.h>
00029 #include <qsplitter.h>
00030 #include <qpushbutton.h>
00031 #include <qradiobutton.h>
00032 #include <qprintdialog.h>
00033 #include <qptrcollection.h>
00034 #include <qkeycode.h>
00035 #include <qcheckbox.h>
00036 #include <qmime.h>
00037 #include <qtoolbutton.h>
00038 #include <qtimer.h>
00039 #include <qbutton.h>
00040 #include <qclipboard.h>
00041 #include <qprogressbar.h>
00042 
00043 #include <qstringlist.h>
00044 #include <qstrlist.h>
00045 #include <qimage.h>
00046 #include <kfiledialog.h>
00047 
00048 #include <kdialogbase.h>
00049 #include <kaction.h>
00050 #include <kcolorbutton.h>
00051 #include <kapplication.h>
00052 #include <klocale.h>
00053 #include <kiconloader.h>
00054 #include <kstdaccel.h>
00055 #include <kstdaction.h>
00056 #include <kglobal.h>
00057 #include <kmessagebox.h>
00058 #include <kdebug.h>
00059 #include <kglobalsettings.h>
00060 #include <kstatusbar.h>
00061 #include <kinputdialog.h>
00062 #include <knotifyclient.h>
00063 
00064 #include <dcopclient.h>
00065 #include <dcopref.h>
00066 
00067 #include <kparts/event.h>
00068 #include <KoPartSelectDia.h>
00069 #include <KoQueryTrader.h>
00070 #include <KoPageLayoutDia.h>
00071 #include <KoRuler.h>
00072 #include <KoZoomHandler.h>
00073 #include <KoUnitWidgets.h>
00074 #include <KoApplication.h>
00075 #include <KoTabBar.h>
00076 #include <Kolinewidthaction.h>
00077 #include <Kolinestyleaction.h>
00078 #include <kopalettemanager.h>
00079 #include <KoGuideLineDia.h>
00080 
00081 #include "kivio_view.h"
00082 #include "kivio_dlg_pageshow.h"
00083 #include "kivio_factory.h"
00084 #include "kivio_map.h"
00085 #include "kivio_page.h"
00086 #include "kivio_doc.h"
00087 #include "kivio_canvas.h"
00088 #include "kivio_stencil_spawner.h"
00089 #include "kivio_grid_data.h"
00090 
00091 #include "tkcoloractions.h"
00092 
00093 #include "kivio_protection_panel.h"
00094 #include "kivio_stencil_geometry_panel.h"
00095 #include "kivio_layer_panel.h"
00096 #include "kivio_birdeye_panel.h"
00097 #include "export_page_dialog.h"
00098 
00099 #include "kivioaligndialog.h"
00100 #include "kiviooptionsdialog.h"
00101 
00102 #include "stencilbardockmanager.h"
00103 #include "kivio_common.h"
00104 #include "kivio_painter.h"
00105 #include "kivio_stencil.h"
00106 #include "kivio_stencil_spawner_set.h"
00107 #include "kivio_screen_painter.h"
00108 
00109 #include "kivio_pluginmanager.h"
00110 
00111 #include "kivio_stackbar.h"
00112 #include "kivio_icon_view.h"
00113 
00114 #include "KIvioViewIface.h"
00115 #include "kivio_command.h"
00116 #include "kiviostencilsetaction.h"
00117 #include <qiconview.h>
00118 #include "kivioarrowheadaction.h"
00119 #include "kiviotextformatdlg.h"
00120 #include "kiviostencilformatdlg.h"
00121 #include "kivioarrowheadformatdlg.h"
00122 #include "kiviodragobject.h"
00123 #include "kivioglobal.h"
00124 #include "kivio_config.h"
00125 #include "kivioaddstencilsetpanel.h"
00126 #include "kiviostencilsetinstaller.h"
00127 #include "addstenciltool.h"
00128 #include "objectlistpalette.h"
00129 #include "addstencilsetdialog.h"
00130 
00131 #define TOGGLE_ACTION(X) ((KToggleAction*)actionCollection()->action(X))
00132 #define MOUSEPOS_TEXT 1000
00133 #define PAGECOUNT_TEXT 0
00134 #define INFO_TEXT 1
00135 
00136 using namespace Kivio;
00137 
00138 KivioView::KivioView( QWidget *_parent, const char *_name, KivioDoc* doc )
00139 : KoView( doc, _parent, _name )
00140 {
00141   m_bShowGuides = true;
00142   m_bSnapGuides = true;
00143   m_addStencilSetDialog = 0;
00144   m_pluginManager = new PluginManager(this, "Kivio Plugin Manager");
00145   m_addStencilTool = new Kivio::AddStencilTool(this);
00146   m_pPaletteManager = new KoPaletteManager(this, actionCollection(), "kivio palette manager");
00147   m_zoomHandler = new KoZoomHandler();
00148   zoomHandler()->setZoomAndResolution(100, KoGlobal::dpiX(), KoGlobal::dpiY());
00149   m_pDoc = doc;
00150   m_pActivePage = 0;
00151   dcop = 0;
00152   dcopObject(); // build it
00153 
00154   if(KStatusBar* sb = statusBar()) { // No statusbar in e.g. konqueror
00155     m_pageCountSLbl = new KStatusBarLabel(i18n("%1 current page, %2 total number of pages",
00156                                           "Page %1/%2").arg(0).arg(0), PAGECOUNT_TEXT, sb);
00157     addStatusBarItem(m_pageCountSLbl, 0, false);
00158 
00159     m_infoSLbl = new KStatusBarLabel("", INFO_TEXT, sb);
00160     addStatusBarItem(m_infoSLbl, 10, false);
00161 
00162     // Add coords to the statusbar
00163     QString unit = KoUnit::unitName(m_pDoc->unit());
00164     KoPoint xy(0, 0);
00165     QString text = i18n("%1 x coord, %2 y coord, %3 and %4 the unit",
00166                         "X: %1 %3 Y: %2 %4").arg(KGlobal::_locale->formatNumber(xy.x(), 2))
00167                         .arg(KGlobal::_locale->formatNumber(xy.y(), 2)).arg(unit).arg(unit);
00168     m_coordSLbl = new KStatusBarLabel(text, MOUSEPOS_TEXT, sb);
00169     addStatusBarItem(m_coordSLbl, 0, true);
00170   }
00171 
00172   // Handle progress information from the doc
00173   m_statusBarProgress = 0;
00174 
00175   connect(m_pDoc, SIGNAL(initProgress()), this, SLOT(initStatusBarProgress()));
00176   connect(m_pDoc, SIGNAL(progress(int)), this, SLOT(setStatusBarProgress(int)));
00177   connect(m_pDoc, SIGNAL(endProgress()), this, SLOT(removeStatusBarProgress()));
00178 
00179   bool isModified = doc->isModified();
00180   m_pStencilBarDockManager = new StencilBarDockManager(this);
00181 
00182   // QGridLayout for the entire view
00183   QGridLayout *viewGrid = new QGridLayout(this);
00184 
00185   // A widget to hold the entire right side (old view)
00186   QWidget *pRightSide = new QWidget(this);
00187   viewGrid->addWidget(pRightSide, 0, 0);
00188 
00189   // Split tabbar and Horz. Scroll Bar
00190   QSplitter* tabSplit = new QSplitter(pRightSide);
00191 
00192   // Tab Bar
00193   m_pTabBar = new KoTabBar(tabSplit);
00194   connect( m_pTabBar,
00195            SIGNAL(tabChanged(const QString&)),
00196            SLOT( changePage(const QString&)));
00197   connect( m_pTabBar, SIGNAL( doubleClicked() ), SLOT( renamePage() ) );
00198   connect( m_pTabBar, SIGNAL( contextMenu( const QPoint& ) ),
00199       SLOT( popupTabBarMenu( const QPoint& ) ) );
00200   connect(m_pTabBar, SIGNAL(tabMoved(unsigned, unsigned)), this, SLOT(moveTab(unsigned, unsigned)));
00201   m_pTabBar->setReverseLayout( QApplication::reverseLayout() );
00202 
00203   // Scroll Bar
00204   m_vertScrollBar = new QScrollBar(QScrollBar::Vertical,pRightSide);
00205   m_horzScrollBar = new QScrollBar(QScrollBar::Horizontal,tabSplit);
00206 
00207   QValueList<int> sizes;
00208   sizes << tabSplit->width() / 2 << tabSplit->width() / 2;
00209   tabSplit->setSizes(sizes);
00210   QHBoxLayout* tabLayout = new QHBoxLayout();
00211   tabLayout->addWidget(tabSplit);
00212 
00213   // The widget on which we display the page
00214   QWidgetStack* canvasBase = new QWidgetStack(pRightSide);
00215   m_pCanvas = new KivioCanvas(canvasBase,this,doc,m_vertScrollBar,m_horzScrollBar);
00216   canvasBase->addWidget(m_pCanvas,0);
00217   canvasBase->raiseWidget(m_pCanvas);
00218   m_pCanvas->setFocusPolicy(QWidget::StrongFocus);
00219 
00220   // Rulers
00221   vRuler = new KoRuler(pRightSide, m_pCanvas, Qt::Vertical, Kivio::Config::defaultPageLayout(),
00222     KoRuler::F_HELPLINES, m_pDoc->unit());
00223   vRuler->showMousePos(true);
00224   vRuler->setZoom(zoomHandler()->zoomedResolutionY());
00225   hRuler = new KoRuler(pRightSide, m_pCanvas, Qt::Horizontal, Kivio::Config::defaultPageLayout(),
00226     KoRuler::F_HELPLINES, m_pDoc->unit());
00227   hRuler->showMousePos(true);
00228   hRuler->setZoom(zoomHandler()->zoomedResolutionX());
00229   connect(m_vertScrollBar, SIGNAL(valueChanged(int)), SLOT(setRulerVOffset(int)));
00230   connect(m_horzScrollBar, SIGNAL(valueChanged(int)), SLOT(setRulerHOffset(int)));
00231   connect(vRuler, SIGNAL(unitChanged(KoUnit::Unit)), SLOT(rulerChangedUnit(KoUnit::Unit)));
00232   connect(hRuler, SIGNAL(unitChanged(KoUnit::Unit)), SLOT(rulerChangedUnit(KoUnit::Unit)));
00233   connect(vRuler, SIGNAL(doubleClicked()), SLOT(paperLayoutDlg()));
00234   connect(hRuler, SIGNAL(doubleClicked()), SLOT(paperLayoutDlg()));
00235   connect(m_pDoc, SIGNAL(unitChanged(KoUnit::Unit)), SLOT(setRulerUnit(KoUnit::Unit)));
00236   connect(m_pCanvas, SIGNAL(visibleAreaChanged()), SLOT(updateRulers()));
00237 
00238   connect(vRuler, SIGNAL(addGuide(const QPoint&, bool, int)),
00239           &(m_pCanvas->guideLines()), SLOT(addGuide(const QPoint&, bool, int)));
00240   connect(vRuler, SIGNAL(moveGuide(const QPoint&, bool, int)),
00241           &(m_pCanvas->guideLines()), SLOT(moveGuide(const QPoint&, bool, int)));
00242   connect(hRuler, SIGNAL(addGuide(const QPoint&, bool, int)),
00243           &(m_pCanvas->guideLines()), SLOT(addGuide(const QPoint&, bool, int)));
00244   connect(hRuler, SIGNAL(moveGuide(const QPoint&, bool, int)),
00245           &(m_pCanvas->guideLines()), SLOT(moveGuide(const QPoint&, bool, int)));
00246   connect(&(m_pCanvas->guideLines()), SIGNAL(guideLinesChanged(KoView*)), m_pDoc, SLOT(updateGuideLines(KoView*)));
00247 
00248   QGridLayout* layout = new QGridLayout(pRightSide);
00249   layout->addWidget(hRuler, 0, 1);
00250   layout->addWidget(vRuler, 1, 0);
00251   layout->addWidget(canvasBase, 1, 1);
00252   layout->addMultiCellLayout(tabLayout, 2, 2, 0, 1);
00253   layout->addMultiCellWidget(m_vertScrollBar, 0, 1, 2, 2);
00254   layout->setRowStretch(1, 10);
00255   layout->setColStretch(1, 10);
00256 
00257   QWidget::setFocusPolicy( QWidget::StrongFocus );
00258   setFocusProxy( m_pCanvas );
00259 
00260   connect( this, SIGNAL( invalidated() ), m_pCanvas, SLOT( update() ) );
00261   connect( this, SIGNAL( regionInvalidated( const QRegion&, bool ) ), m_pCanvas, SLOT( repaint( const QRegion&, bool ) ) );
00262 
00263   setInstance(KivioFactory::global());
00264   if ( !m_pDoc->isReadWrite() )
00265     setXMLFile("kivio_readonly.rc");
00266   else
00267     setXMLFile("kivio.rc");
00268 
00269 
00270   // Must be executed before setActivePage() and before setupActions()
00271   createBirdEyeDock();
00272   createLayerDock();
00273   createObjectListPalette();
00274   createGeometryDock();
00275   createProtectionDock();
00276   paletteManager()->showWidget("birdseyepanel");
00277   paletteManager()->showWidget("stencilgeometrypanel");
00278 
00279   setupActions();
00280 
00281 
00282   KivioPage* page;
00283   for ( page = m_pDoc->map()->firstPage(); page; page = m_pDoc->map()->nextPage() )
00284     addPage(page);
00285 
00286   setActivePage(m_pDoc->map()->firstPage());
00287 
00288 
00289   connect( m_pDoc, SIGNAL( sig_selectionChanged() ), SLOT( updateToolBars() ) );
00290   connect( m_pDoc, SIGNAL( sig_addPage(KivioPage*) ), SLOT( addPage(KivioPage*) ) );
00291   connect( m_pDoc, SIGNAL( sig_addSpawnerSet(KivioStencilSpawnerSet*) ), SLOT(addSpawnerToStackBar(KivioStencilSpawnerSet*)) );
00292   connect( m_pDoc, SIGNAL( sig_updateView(KivioPage*) ), SLOT(slotUpdateView(KivioPage*)) );
00293   connect( m_pDoc, SIGNAL( sig_pageNameChanged(KivioPage*,const QString&)), SLOT(slotPageRenamed(KivioPage*,const QString&)) );
00294 
00295   connect( m_pDoc, SIGNAL( sig_updateGrid()),SLOT(slotUpdateGrid()));
00296 
00297   connect(m_pDoc, SIGNAL(loadingFinished()), this, SLOT(loadingFinished()));
00298 
00299   initActions();
00300 
00301   // Load any already-loaded stencils into the stencil dock
00302   if( m_pDoc->isReadWrite() ) // only if not embedded in Konqueror
00303   {
00304     KivioStencilSpawnerSet *pSet;
00305     pSet = m_pDoc->spawnerSets()->first();
00306     while( pSet )
00307     {
00308       addSpawnerToStackBar( pSet );
00309       pSet = m_pDoc->spawnerSets()->next();
00310     }
00311   }
00312 
00313   m_pDoc->setModified(isModified);
00314   pluginManager()->activateDefaultTool();
00315   clipboardDataChanged();  // Enable/disable the paste action
00316 }
00317 
00318 KivioView::~KivioView()
00319 {
00320   delete m_pluginManager;
00321   m_pluginManager = 0;
00322   delete dcop;
00323   dcop = 0;
00324   delete m_zoomHandler;
00325   m_zoomHandler = 0;
00326 }
00327 
00328 DCOPObject* KivioView::dcopObject()
00329 {
00330   if ( !dcop ) {
00331     dcop = new KIvioViewIface( this );
00332   }
00333 
00334   return dcop;
00335 }
00336 
00337 void KivioView::createGeometryDock()
00338 {
00339   m_pStencilGeometryPanel = new KivioStencilGeometryPanel(this);
00340   m_pStencilGeometryPanel->setCaption(i18n("Geometry"));
00341   m_pStencilGeometryPanel->setUnit(m_pDoc->unit());
00342   paletteManager()->addWidget(m_pStencilGeometryPanel, "stencilgeometrypanel", "geometrydocker");
00343 
00344   connect( m_pStencilGeometryPanel, SIGNAL(positionChanged(double, double)), this, SLOT(slotChangeStencilPosition(double, double)) );
00345   connect( m_pStencilGeometryPanel, SIGNAL(sizeChanged(double, double)), this, SLOT(slotChangeStencilSize(double, double)) );
00346 //   connect(m_pStencilGeometryPanel, SIGNAL(rotationChanged(int)), SLOT(slotChangeStencilRotation(int)));
00347 
00348   connect( m_pDoc, SIGNAL(unitChanged(KoUnit::Unit)), m_pStencilGeometryPanel, SLOT(setUnit(KoUnit::Unit)) );
00349 }
00350 
00351 void KivioView::createBirdEyeDock()
00352 {
00353   m_pBirdEyePanel = new KivioBirdEyePanel(this, this);
00354   m_pBirdEyePanel->setCaption(i18n("Overview"));
00355   paletteManager()->addWidget(m_pBirdEyePanel, "birdseyepanel", "birdeyedocker");
00356 }
00357 
00358 void KivioView::createLayerDock()
00359 {
00360   m_pLayersPanel = new KivioLayerPanel( this, this);
00361   m_pLayersPanel->setCaption(i18n("Layers"));
00362   paletteManager()->addWidget(m_pLayersPanel, "layerspanel", "birdeyedocker");
00363 }
00364 
00365 void KivioView::createProtectionDock()
00366 {
00367   m_pProtectionPanel = new KivioProtectionPanel(this,this);
00368   m_pProtectionPanel->setCaption(i18n("Protection"));
00369   paletteManager()->addWidget(m_pProtectionPanel, "protectionpanel", "geometrydocker");
00370 }
00371 
00372 void KivioView::createObjectListPalette()
00373 {
00374   m_objectListPalette = new Kivio::ObjectListPalette(this);
00375   m_objectListPalette->setCaption("Objects");
00376   paletteManager()->addWidget(m_objectListPalette, "objectlistpalette", "birdeyedocker");
00377 }
00378 
00379 void KivioView::setupActions()
00380 {
00381   KivioStencilSetAction* addStSet =  new KivioStencilSetAction( i18n("Add Stencil Set"),
00382     "open_stencilset", actionCollection(), "addStencilSet" );
00383   connect(addStSet,SIGNAL(activated(const QString&)),SLOT(addStencilSet(const QString&)));
00384   connect(this, SIGNAL(updateStencilSetList()), addStSet, SLOT(updateMenu()));
00385   connect(addStSet, SIGNAL(showDialog()), this, SLOT(showAddStencilSetDialog()));
00386 
00387   m_alignAndDistribute = new KAction( i18n("Align && Distribute..."), CTRL+ALT+Key_A, this,
00388     SLOT(alignStencilsDlg()), actionCollection(), "alignStencils" );
00389 
00390   m_editCut = KStdAction::cut( this, SLOT(cutStencil()), actionCollection(), "cutStencil" );
00391   m_editCopy = KStdAction::copy( this, SLOT(copyStencil()), actionCollection(), "copyStencil" );
00392   m_editPaste = KStdAction::paste( this, SLOT(pasteStencil()), actionCollection(), "pasteStencil" );
00393   connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
00394 
00395   m_selectAll = KStdAction::selectAll(this, SLOT(selectAllStencils()), actionCollection(), "selectAllStencils");
00396   m_selectNone = KStdAction::deselect(this, SLOT(unselectAllStencils()), actionCollection(), "unselectAllStencils");
00397 
00398   m_groupAction = new KAction( i18n("Group Selection"), "group", CTRL+Key_G, this, SLOT(groupStencils()), actionCollection(), "groupStencils" );
00399   m_groupAction->setWhatsThis(i18n("Group selected objects into a single stencil"));
00400   m_ungroupAction = new KAction( i18n("Ungroup"), "ungroup", CTRL+SHIFT+Key_G, this, SLOT(ungroupStencils()), actionCollection(), "ungroupStencils" );
00401   m_ungroupAction->setWhatsThis(i18n("Break up a selected group stencil"));
00402 
00403   m_stencilToFront = new KAction( i18n("Bring to Front"), "bring_forward", 0, this, SLOT(bringStencilToFront()), actionCollection(), "bringStencilToFront" );
00404   m_stencilToBack = new KAction( i18n("Send to Back"), "send_backward", 0, this, SLOT(sendStencilToBack()), actionCollection(), "sendStencilToBack" );
00405 
00406   m_menuTextFormatAction = new KAction(i18n("&Text..."), 0, 0, this, SLOT(textFormat()),
00407   actionCollection(), "textFormat");
00408 
00409   m_menuStencilConnectorsAction = new KAction(i18n("&Stencils && Connectors..."), 0, 0, this, SLOT(stencilFormat()),
00410   actionCollection(), "stencilFormat");
00411 
00412   m_arrowHeadsMenuAction = new KAction(i18n("&Arrowheads..."), 0, 0, this, SLOT(arrowHeadFormat()),
00413   actionCollection(), "arrowHeadFormat");
00414   m_arrowHeadsMenuAction->setWhatsThis(i18n("Arrowheads allow you to add an arrow to the beginning and/or end of a line."));
00415 
00416   /* Create the fg color button */
00417   m_setFGColor = new TKSelectColorAction( i18n("Line Color"), TKSelectColorAction::LineColor, actionCollection(), "setFGColor" );
00418   m_setFGColor->setWhatsThis(i18n("The line color allows you to choose a color for the lines of the stencils."));
00419   connect(m_setFGColor,SIGNAL(activated()),SLOT(setFGColor()));
00420   m_setBGColor = new TKSelectColorAction( i18n("Fill Color"), TKSelectColorAction::FillColor, actionCollection(), "setBGColor" );
00421   m_setBGColor->setWhatsThis(i18n("You can choose a color for the background of a stencil by using this button."));
00422   connect(m_setBGColor,SIGNAL(activated()),SLOT(setBGColor()));
00423 
00424   // Text bar
00425   m_setFontFamily = new KFontAction( i18n( "Font Family" ), 0, actionCollection(), "setFontFamily" );
00426   connect( m_setFontFamily, SIGNAL(activated(const QString&)), SLOT(setFontFamily(const QString&)) );
00427 
00428   m_setFontSize = new KFontSizeAction( i18n( "Font Size" ), 0, actionCollection(), "setFontSize" );
00429   connect( m_setFontSize, SIGNAL( fontSizeChanged( int ) ),
00430            this, SLOT( setFontSize(int ) ) );
00431 
00432 
00433   m_setTextColor = new TKSelectColorAction( i18n("Text Color"), TKSelectColorAction::TextColor, actionCollection(), "setTextColor" );
00434   connect( m_setTextColor, SIGNAL(activated()), SLOT(setTextColor()) );
00435 
00436   m_setBold = new KToggleAction( i18n("Toggle Bold Text"), "text_bold", 0, actionCollection(), "setFontBold" );
00437   connect( m_setBold, SIGNAL(toggled(bool)), SLOT(toggleFontBold(bool)) );
00438 
00439   m_setItalics = new KToggleAction( i18n("Toggle Italics Text"), "text_italic", 0, actionCollection(), "setFontItalics" );
00440   connect( m_setItalics, SIGNAL(toggled(bool)), SLOT(toggleFontItalics(bool)) );
00441 
00442   m_setUnderline = new KToggleAction( i18n("Toggle Underline Text"), "text_under", 0, actionCollection(), "setFontUnderline" );
00443   connect( m_setUnderline, SIGNAL(toggled(bool)), SLOT(toggleFontUnderline(bool)));
00444 
00445   m_textAlignLeft = new KToggleAction( i18n( "Align &Left" ), "text_left", CTRL + Key_L,
00446                                     this, SLOT( textAlignLeft() ),
00447                                     actionCollection(), "textAlignLeft" );
00448   m_textAlignLeft->setExclusiveGroup( "align" );
00449   m_textAlignCenter = new KToggleAction( i18n( "Align &Center" ), "text_center", CTRL + ALT + Key_C,
00450                                       this, SLOT( textAlignCenter() ),
00451                                       actionCollection(), "textAlignCenter" );
00452   m_textAlignCenter->setExclusiveGroup( "align" );
00453   m_textAlignCenter->setChecked( TRUE );
00454   m_textAlignRight = new KToggleAction( i18n( "Align &Right" ), "text_right", CTRL + ALT + Key_R,
00455                                       this, SLOT( textAlignRight() ),
00456                                       actionCollection(), "textAlignRight" );
00457   m_textAlignRight->setExclusiveGroup( "align" );
00458   m_textVAlignSuper = new KToggleAction( i18n( "Superscript" ), "super", 0,
00459                                             this, SLOT( textSuperScript() ),
00460                                             actionCollection(), "textVAlignSuper" );
00461   m_textVAlignSuper->setExclusiveGroup( "valign" );
00462   m_textVAlignSub = new KToggleAction( i18n( "Subscript" ), "sub", 0,
00463                                             this, SLOT( textSubScript() ),
00464                                             actionCollection(), "textVAlignSub" );
00465   m_textVAlignSub->setExclusiveGroup( "valign" );
00466 
00467   m_lineWidthAction = new KoLineWidthAction(i18n("Line Width"), "linewidth", this, SLOT(setLineWidth(double)),
00468     actionCollection(), "setLineWidth");
00469   m_lineWidthAction->setUnit(m_pDoc->unit());
00470   connect(m_pDoc, SIGNAL(unitChanged(KoUnit::Unit)), m_lineWidthAction, SLOT(setUnit(KoUnit::Unit)));
00471 
00472   m_lineStyleAction = new KoLineStyleAction(i18n("Line Style"), "linestyle", this, SLOT(setLineStyle(int)),
00473     actionCollection(), "setLineStyle");
00474 
00475   m_paperLayout = new KAction( i18n("Page Layout..."), 0, this, SLOT(paperLayoutDlg()), actionCollection(), "paperLayout" );
00476   m_insertPage = new KAction( i18n("Insert Page"),"item_add", 0, this, SLOT(insertPage()), actionCollection(), "insertPage" );
00477   m_removePage = new KAction( i18n("Remove Page"), "item_remove",0,this, SLOT(removePage()), actionCollection(), "removePage" );
00478 
00479   m_renamePage = new KAction( i18n("Rename Page..."), "item_rename",0,this, SLOT(renamePage()), actionCollection(), "renamePage" );
00480 
00481   m_showPage = new KAction( i18n("Show Page..."),0 ,this,SLOT(showPage()), actionCollection(), "showPage" );
00482   m_hidePage = new KAction( i18n("Hide Page"),0 ,this,SLOT(hidePage()), actionCollection(), "hidePage" );
00483 
00484   showPageMargins = new KToggleAction( i18n("Show Page Margins"), "view_margins", 0, actionCollection(), "showPageMargins" );
00485   connect( showPageMargins, SIGNAL(toggled(bool)), SLOT(togglePageMargins(bool)));
00486 #if KDE_IS_VERSION(3,2,90)
00487   showPageMargins->setCheckedState(i18n("Hide Page Margins"));
00488 #endif
00489 
00490   showRulers = new KToggleAction( i18n("Show Rulers"), "view_ruler", 0, actionCollection(), "showRulers" );
00491   connect( showRulers, SIGNAL(toggled(bool)), SLOT(toggleShowRulers(bool)));
00492 #if KDE_IS_VERSION(3,2,90)
00493   showRulers->setCheckedState(i18n("Hide Rulers"));
00494 #endif
00495 
00496   // Grid actions
00497   showGrid = new KToggleAction( i18n("Show Grid"), "view_grid", 0, actionCollection(), "showGrid" );
00498   connect( showGrid, SIGNAL(toggled(bool)), SLOT(toggleShowGrid(bool)));
00499 #if KDE_IS_VERSION(3,2,90)
00500   showGrid->setCheckedState(i18n("Hide Grid"));
00501 #endif
00502 
00503   KToggleAction* snapGrid = new KToggleAction( i18n("Snap Grid"), "view_grid", 0, actionCollection(), "snapGrid" );
00504   connect( snapGrid, SIGNAL(toggled(bool)), SLOT(toggleSnapGrid(bool)));
00505 
00506   // Guides actions
00507   showGuides = new KToggleAction( i18n("Guide Lines"), 0, actionCollection(), "showGuides" );
00508   connect( showGuides, SIGNAL(toggled(bool)), SLOT(toggleShowGuides(bool)));
00509   KAction* addGuide = new KAction(i18n("Add Guide Line..."), 0, this, SLOT(addGuideLine()),
00510     actionCollection(), "addGuideLine");
00511   connect(showGuides, SIGNAL(toggled(bool)), addGuide, SLOT(setEnabled(bool)));
00512   //--
00513 
00514   m_setArrowHeads = new KivioArrowHeadAction(i18n("Arrowheads"), "arrowheads", actionCollection(), "arrowHeads");
00515   m_setArrowHeads->setWhatsThis(i18n("Arrowheads allow you to add an arrow to the beginning and/or end of a line."));
00516   connect( m_setArrowHeads, SIGNAL(endChanged(int)), SLOT(slotSetEndArrow(int)));
00517   connect( m_setArrowHeads, SIGNAL(startChanged(int)), SLOT(slotSetStartArrow(int)));
00518 
00519   KStdAction::preferences(this, SLOT(optionsDialog()), actionCollection(), "options");
00520 
00521   (void) new KAction(i18n("Install Stencil Set..."), 0, this,
00522     SLOT(installStencilSet()), actionCollection(), "installStencilSet");
00523 
00524   m_editDelete = new KAction(i18n("Delete"), "editdelete", Key_Delete,
00525     this, SLOT(deleteObject()), actionCollection(), "deleteObject");
00526 }
00527 
00528 void KivioView::initActions()
00529 {
00530   togglePageMargins(true);
00531   toggleShowRulers(true);
00532 
00533   updateButton();
00534 
00535   m_setFontFamily->setFont( doc()->defaultFont().family() );
00536   m_setFontSize->setFontSize( doc()->defaultFont().pointSize() );
00537   m_setBold->setChecked( false );
00538   m_setItalics->setChecked( false );
00539   m_setUnderline->setChecked( false );
00540   m_lineWidthAction->setCurrentWidth(1.0);
00541   m_lineStyleAction->setCurrentSelection(Qt::SolidLine);
00542   showAlign(Qt::AlignHCenter);
00543   showVAlign(Qt::AlignVCenter);
00544 
00545   m_pStencilGeometryPanel->setSize(0.0,0.0);
00546   m_pStencilGeometryPanel->setPosition(0.0,0.0);
00547   m_pStencilGeometryPanel->setRotation(0);
00548 
00549   m_setArrowHeads->setCurrentStartArrow(0);
00550   m_setArrowHeads->setCurrentEndArrow(0);
00551 
00552   m_menuTextFormatAction->setEnabled( false );
00553   m_menuStencilConnectorsAction->setEnabled( false );
00554 
00555   m_setFGColor->setCurrentColor(QColor(0, 0, 0));
00556   m_setBGColor->setCurrentColor(QColor(255, 255, 255));
00557   m_setTextColor->setCurrentColor(QColor(0, 0, 0));
00558 
00559   viewZoom(zoomHandler()->zoom());
00560 }
00561 
00562 void KivioView::updateReadWrite( bool readwrite )
00563 {
00564   QValueList<KAction*> actions = actionCollection()->actions();
00565   QValueList<KAction*>::ConstIterator aIt = actions.begin();
00566   QValueList<KAction*>::ConstIterator aEnd = actions.end();
00567   for (; aIt != aEnd; ++aIt )
00568     (*aIt)->setEnabled( readwrite );
00569   if ( !readwrite )
00570   {
00571       showPageMargins->setEnabled( true );
00572       showRulers->setEnabled( true );
00573       showGrid->setEnabled( true );
00574       showGuides->setEnabled( true );
00575       m_selectAll->setEnabled( true );
00576       m_selectNone->setEnabled( true );
00577       m_editCopy->setEnabled( true );
00578   }
00579   m_showPage->setEnabled( true );
00580   m_hidePage->setEnabled( true );
00581   updateMenuPage();
00582 }
00583 
00584 
00585 void KivioView::addPage( KivioPage* page )
00586 {
00587   insertPage(  page );
00588 
00589   QObject::connect( page, SIGNAL( sig_PageHidden( KivioPage* ) ),
00590                     this, SLOT( slotPageHidden( KivioPage* ) ) );
00591   QObject::connect( page, SIGNAL( sig_PageShown( KivioPage* ) ),
00592                     this, SLOT( slotPageShown( KivioPage* ) ) );
00593 
00594   updatePageStatusLabel();
00595 }
00596 
00597 void KivioView::insertPage( KivioPage* page )
00598 {
00599   if(!page->isHidden()) {
00600     m_pTabBar->addTab(page->pageName());
00601     setActivePage(page);
00602     updateMenuPage();
00603   }
00604 }
00605 
00606 void KivioView::removePage( KivioPage *_t )
00607 {
00608   QString m_pageName=_t->pageName();
00609   m_pTabBar->removeTab( _t->pageName() );
00610   QString n = m_pDoc->map()->visiblePages().first();
00611   setActivePage( m_pDoc->map()->findPage( n ) );
00612 
00613   updatePageStatusLabel();
00614 }
00615 
00616 void KivioView::renamePage()
00617 {
00618     bool ok;
00619     QString activeName = m_pActivePage->pageName();
00620     QString newName = KInputDialog::getText( i18n("Rename Page"),
00621         i18n("Enter page name:"), activeName, &ok, this );
00622 
00623     // Have a different name ?
00624     if ( ok ) // User pushed an OK button.
00625     {
00626         if ( (newName.stripWhiteSpace()).isEmpty() ) // Page name is empty.
00627         {
00628             KNotifyClient::beep();
00629             KMessageBox::information( this, i18n("Page name cannot be empty."),
00630                 i18n("Change Page Name") );
00631             // Recursion
00632             renamePage();
00633         }
00634         else if ( newName != activeName ) // Page name changed.
00635         {
00636              // Is the name already used
00637              if ( !m_pActivePage->setPageName( newName ) )
00638              {
00639                 KNotifyClient::beep();
00640                 KMessageBox::information( this, i18n("This name is already used."),
00641                     i18n("Change Page Name") );
00642                 // Recursion
00643                 renamePage();
00644              }
00645              KivioChangePageNameCommand *cmd = new KivioChangePageNameCommand(i18n("Rename Page"), activeName, newName, m_pActivePage);
00646              m_pDoc->addCommand( cmd );
00647         }
00648     }
00649 }
00650 
00651 void KivioView::setActivePage( KivioPage* page )
00652 {
00653   if ( page == m_pActivePage )
00654     return;
00655 
00656   if(m_pActivePage) {
00657     disconnect(m_pActivePage, SIGNAL(sig_pageLayoutChanged(const KoPageLayout&)), this,
00658       SLOT(setRulerPageLayout(const KoPageLayout&)));
00659   }
00660 
00661   m_pActivePage = page;
00662 
00663   m_pTabBar->setActiveTab(m_pActivePage->pageName());
00664   updateToolBars();
00665 
00666   m_pLayersPanel->reset();
00667 
00668   m_pDoc->updateView(m_pActivePage);
00669   setRulerPageLayout(m_pActivePage->paperLayout());
00670   connect(m_pActivePage, SIGNAL(sig_pageLayoutChanged(const KoPageLayout&)),
00671     SLOT(setRulerPageLayout(const KoPageLayout&)));
00672 
00673   m_pCanvas->guideLines().setGuideLines(m_pActivePage->horizontalGuideLines(),
00674     m_pActivePage->verticalGuideLines());
00675   m_objectListPalette->updateObjectList();
00676 }
00677 
00678 void KivioView::setActiveSpawnerSet( KivioStencilSpawnerSet *set )
00679 {
00680     if( set == m_pActiveSpawnerSet )
00681         return;
00682 
00683     m_pActiveSpawnerSet = set;
00684 }
00685 
00686 void KivioView::slotPageRenamed( KivioPage* page, const QString& old_name )
00687 {
00688   m_pTabBar->renameTab( old_name, page->pageName() );
00689 }
00690 
00691 void KivioView::changePage( const QString& name )
00692 {
00693   if ( m_pActivePage->pageName() == name )
00694     return;
00695 
00696   KivioPage *t = m_pDoc->map()->findPage(name);
00697   if (!t)
00698     return;
00699 
00700   setActivePage(t);
00701   updatePageStatusLabel();
00702 }
00703 
00704 void KivioView::insertPage()
00705 {
00706   KivioPage * t =m_pDoc->createPage();
00707   m_pDoc->addPage(t);
00708   KivioAddPageCommand * cmd = new KivioAddPageCommand(i18n("Insert Page"), t);
00709   m_pDoc->addCommand( cmd );
00710 
00711   updatePageStatusLabel();
00712 }
00713 
00714 void KivioView::hidePage()
00715 {
00716   if (!m_pActivePage)
00717     return;
00718 
00719   if ( m_pDoc->map()->visiblePages().count() ==  1)
00720   {
00721       KMessageBox::error( this, i18n("You cannot hide the last visible page.") );
00722       return;
00723   }
00724 
00725   m_pActivePage->setHidden(true);
00726   QString activeName = m_pActivePage->pageName();
00727 
00728   m_pTabBar->removeTab( activeName );
00729 
00730   KivioHidePageCommand * cmd = new KivioHidePageCommand(i18n("Hide Page"), m_pActivePage);
00731   m_pDoc->addCommand( cmd );
00732 
00733   changePage( m_pDoc->map()->visiblePages().first() );
00734   updateMenuPage();
00735 }
00736 
00737 void KivioView::showPage()
00738 {
00739   KivioPageShow* dlg = new KivioPageShow(this,"Page show");
00740   if ( !dlg->exec() )
00741   {
00742       delete dlg;
00743       return;
00744   }
00745   m_pTabBar->setTabs( m_pDoc->map()->visiblePages() );
00746   updateMenuPage();
00747   delete dlg;
00748 }
00749 
00750 int KivioView::leftBorder() const
00751 {
00752   int retVal = 0;
00753 
00754   if(isShowRulers()) {
00755     retVal = vertRuler()->width();
00756   }
00757 
00758   return retVal;
00759 }
00760 
00761 int KivioView::rightBorder() const
00762 {
00763   return m_vertScrollBar->width();
00764 }
00765 
00766 int KivioView::topBorder() const
00767 {
00768   int retVal = 0;
00769 
00770   if(isShowRulers()) {
00771     retVal = horzRuler()->height();
00772   }
00773 
00774   return retVal;
00775 }
00776 
00777 int KivioView::bottomBorder() const
00778 {
00779   return m_horzScrollBar->height();
00780 }
00781 
00782 void KivioView::paperLayoutDlg()
00783 {
00784   KivioPage* page = activePage();
00785   KoPageLayout l = page->paperLayout();
00786   KoHeadFoot headfoot;
00787   int tabs = FORMAT_AND_BORDERS | DISABLE_UNIT;
00788   KoUnit::Unit unit = doc()->unit();
00789 
00790   if(KoPageLayoutDia::pageLayout(l, headfoot, tabs, unit))
00791   {
00792     KivioDoc* doc = page->doc();
00793     KivioChangeLayoutCommand * cmd = new KivioChangeLayoutCommand(
00794       i18n("Change Page Layout"),page ,page->paperLayout(), l);
00795     doc->addCommand( cmd );
00796     page->setPaperLayout(l);
00797   }
00798 }
00799 
00800 void KivioView::removePage()
00801 {
00802   if ( doc()->map()->count() <= 1 || doc()->map()->visiblePages().count()<=1 ) {
00803     QApplication::beep();
00804     KMessageBox::sorry( this, i18n("You cannot delete the only page of the document."), i18n("Remove Page") );
00805     return;
00806   }
00807   QApplication::beep();
00808   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"),"editdelete"));
00809 
00810   if ( ret == KMessageBox::Continue ) {
00811       KivioPage* tbl = m_pActivePage;
00812       KivioRemovePageCommand *cmd = new KivioRemovePageCommand(i18n("Remove Page"), tbl);
00813       cmd->execute();
00814       doc()->addCommand( cmd );
00815   }
00816 }
00817 
00818 void KivioView::slotUpdateView( KivioPage* page )
00819 {
00820   if (page && page != m_pActivePage)
00821     return;
00822 
00823   // global view updates (toolbar, statusbar.... actions...)
00824   updateToolBars();
00825 
00826   m_pCanvas->update();
00827   m_pCanvas->updateScrollBars();
00828   vRuler->update();
00829   hRuler->update();
00830   m_objectListPalette->updateObjectList();
00831 }
00832 
00833 QWidget *KivioView::canvas() const
00834 {
00835   return canvasWidget();
00836 }
00837 
00838 int KivioView::canvasXOffset() const
00839 {
00840   return canvasWidget()->xOffset();
00841 }
00842 
00843 int KivioView::canvasYOffset() const
00844 {
00845   return canvasWidget()->yOffset();
00846 }
00847 
00848 void KivioView::print(KPrinter& ptr)
00849 {
00850   ptr.setFullPage(TRUE);
00851   m_pDoc->printContent( ptr );
00852 }
00853 
00854 
00855 void KivioView::viewZoom(int zoom)
00856 {
00857   if(zoom < 10 || zoom > 2000 || zoom == zoomHandler()->zoom()) {
00858     return;
00859   }
00860 
00861   KoPoint centerPoint = m_pCanvas->visibleArea().center();
00862   zoomHandler()->setZoomAndResolution(zoom, KoGlobal::dpiX(),
00863     KoGlobal::dpiY());
00864   vRuler->setZoom(zoomHandler()->zoomedResolutionY());
00865   hRuler->setZoom(zoomHandler()->zoomedResolutionX());
00866   KoPageLayout l = activePage()->paperLayout();
00867   vRuler->setFrameStartEnd(zoomHandler()->zoomItY(l.ptTop), zoomHandler()->zoomItY(l.ptHeight - l.ptBottom));
00868   hRuler->setFrameStartEnd(zoomHandler()->zoomItX(l.ptLeft), zoomHandler()->zoomItX(l.ptWidth - l.ptRight));
00869   setRulerVOffset(m_vertScrollBar->value());
00870   setRulerHOffset(m_horzScrollBar->value());
00871   KoView::setZoom(zoomHandler()->zoomedResolutionY());
00872   m_pCanvas->setViewCenterPoint(centerPoint);
00873   m_pCanvas->update();
00874   m_pCanvas->updateScrollBars();
00875 
00876   emit zoomChanged(zoom);
00877 }
00878 
00879 KivioPage* KivioView::activePage() const
00880 {
00881   return m_pActivePage;
00882 }
00883 
00884 void KivioView::togglePageMargins(bool b)
00885 {
00886   TOGGLE_ACTION("showPageMargins")->setChecked(b);
00887   m_bShowPageMargins = b;
00888 
00889   m_pCanvas->update();
00890 }
00891 
00892 void KivioView::toggleShowRulers(bool b)
00893 {
00894   TOGGLE_ACTION("showRulers")->setChecked(b);
00895   m_bShowRulers = b;
00896 
00897   if(b) {
00898     hRuler->show();
00899     vRuler->show();
00900   } else {
00901     hRuler->hide();
00902     vRuler->hide();
00903   }
00904 }
00905 
00906 void KivioView::toggleShowGuides(bool b)
00907 {
00908   TOGGLE_ACTION("showGuides")->setChecked(b);
00909   m_bShowGuides = b;
00910   m_bSnapGuides = b;
00911 
00912   m_pCanvas->update();
00913 }
00914 
00915 void KivioView::toggleShowGrid(bool b)
00916 {
00917   TOGGLE_ACTION("showGrid")->setChecked(b);
00918 
00919   Kivio::Config::setShowGrid(b);
00920   m_pDoc->setModified( true );
00921 }
00922 
00923 void KivioView::slotUpdateGrid()
00924 {
00925   m_pCanvas->update();
00926 }
00927 
00928 void KivioView::toggleSnapGrid(bool b)
00929 {
00930   TOGGLE_ACTION("snapGrid")->setChecked(b);
00931 
00932   Kivio::Config::setSnapGrid(b);
00933   m_pDoc->setModified( true );
00934 }
00935 
00936 void KivioView::addStencilSet( const QString& name )
00937 {
00938   m_pDoc->addSpawnerSet(name);
00939 }
00940 
00941 void KivioView::addSpawnerToStackBar( KivioStencilSpawnerSet *pSpawner )
00942 {
00943   if(!pSpawner) {
00944     kdDebug(43000) << "KivioView::addSpawnerToStackBar() - NULL pSpawner" << endl;
00945     return;
00946   }
00947 
00948   if(pSpawner->hidden()) {
00949     return;
00950   }
00951 
00952   KivioIconView *pView = new KivioIconView(m_pDoc->isReadWrite());
00953   QObject::connect(pView, SIGNAL(createNewStencil(KivioStencilSpawner*)), this,
00954                    SLOT(addStencilFromSpawner(KivioStencilSpawner*)));
00955   connect(pView, SIGNAL(stencilSelected(KivioStencilSpawner*)),
00956           m_addStencilTool, SLOT(activateNewStencil(KivioStencilSpawner* )));
00957 
00958   pView->setStencilSpawnerSet(pSpawner);
00959   m_pStencilBarDockManager->insertStencilSet(pView, pSpawner->name());
00960 }
00961 
00962 void KivioView::setFGColor()
00963 {
00964   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
00965   if (!pStencil)
00966     return;
00967   KMacroCommand * macro = new KMacroCommand( i18n("Change Foreground Color"));
00968   bool createMacro = false;
00969   while( pStencil )
00970   {
00971     QColor col( m_setFGColor->color());
00972 
00973     if ( col != pStencil->fgColor() )
00974     {
00975       KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Fg Color"), m_pActivePage, pStencil, pStencil->fgColor(), col, KivioChangeStencilColorCommand::CT_FGCOLOR);
00976 
00977       pStencil->setFGColor( col );
00978       macro->addCommand( cmd );
00979       createMacro = true;
00980     }
00981 
00982     pStencil = m_pActivePage->selectedStencils()->next();
00983   }
00984 
00985   if ( createMacro )
00986     m_pDoc->addCommand( macro );
00987   else
00988     delete macro;
00989 
00990   m_pDoc->updateView(m_pActivePage);
00991 }
00992 
00993 void KivioView::setBGColor()
00994 {
00995   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
00996   if (!pStencil)
00997     return;
00998   KMacroCommand * macro = new KMacroCommand( i18n("Change Background Color"));
00999   bool createMacro = false;
01000 
01001   while( pStencil )
01002   {
01003     QColor col( m_setBGColor->color());
01004 
01005     if ( col != pStencil->bgColor() )
01006     {
01007       KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Bg Color"), m_pActivePage, pStencil, pStencil->bgColor(), col, KivioChangeStencilColorCommand::CT_BGCOLOR);
01008 
01009       pStencil->setBGColor( col );
01010       macro->addCommand( cmd );
01011       createMacro = true;
01012     }
01013 
01014     pStencil = m_pActivePage->selectedStencils()->next();
01015   }
01016 
01017   if ( createMacro )
01018     m_pDoc->addCommand( macro );
01019   else
01020     delete macro;
01021 
01022   m_pDoc->updateView(m_pActivePage);
01023 }
01024 
01025 void KivioView::setTextColor()
01026 {
01027   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01028 
01029   if (!pStencil)
01030     return;
01031 
01032   KMacroCommand * macro = new KMacroCommand( i18n("Change Text Color"));
01033   bool createMacro = false;
01034   while( pStencil )
01035   {
01036     QColor col(m_setTextColor->color());
01037 
01038     if ( col != pStencil->textColor() )
01039     {
01040       KivioChangeStencilColorCommand * cmd = new KivioChangeStencilColorCommand( i18n("Change Text Color"), m_pActivePage, pStencil, pStencil->textColor(), col, KivioChangeStencilColorCommand::CT_TEXTCOLOR);
01041       pStencil->setTextColor( col );
01042       macro->addCommand( cmd );
01043       createMacro = true;
01044     }
01045 
01046     pStencil = m_pActivePage->selectedStencils()->next();
01047   }
01048 
01049   if ( createMacro )
01050     m_pDoc->addCommand( macro );
01051   else
01052     delete macro;
01053 
01054   m_pDoc->updateView(m_pActivePage);
01055 }
01056 
01057 void KivioView::setLineWidth(double width)
01058 {
01059   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01060 
01061   if (!pStencil)
01062     return;
01063 
01064   KMacroCommand * macro = new KMacroCommand( i18n("Change Line Width") );
01065   bool createMacro = false ;
01066 
01067   while( pStencil )
01068   {
01069     if ( width != pStencil->lineWidth() )
01070     {
01071       KivioChangeLineWidthCommand * cmd = new KivioChangeLineWidthCommand( i18n("Change Line Width"),
01072         m_pActivePage, pStencil, pStencil->lineWidth(), width );
01073 
01074       pStencil->setLineWidth( width );
01075       macro->addCommand( cmd );
01076       createMacro = true;
01077     }
01078 
01079     pStencil = m_pActivePage->selectedStencils()->next();
01080   }
01081 
01082   if ( createMacro ) {
01083     m_pDoc->addCommand( macro );
01084   } else {
01085     delete macro;
01086   }
01087 
01088   m_pDoc->updateView(m_pActivePage);
01089 }
01090 
01091 void KivioView::setLineStyle(int style)
01092 {
01093   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01094 
01095   if(!pStencil)
01096     return;
01097 
01098   KMacroCommand * macro = new KMacroCommand( i18n("Change Line Style") );
01099   bool createMacro = false ;
01100 
01101   while(pStencil)
01102   {
01103     if(style != pStencil->linePattern())
01104     {
01105         KivioChangeLineStyleCommand * cmd = new KivioChangeLineStyleCommand( i18n("Change Line Style"),
01106         m_pActivePage, pStencil, pStencil->linePattern(), style );
01107         pStencil->setLinePattern(style);
01108         macro->addCommand( cmd );
01109         createMacro = true;
01110     }
01111 
01112     pStencil = m_pActivePage->selectedStencils()->next();
01113   }
01114 
01115     if ( createMacro ) {
01116     m_pDoc->addCommand( macro );
01117   } else {
01118     delete macro;
01119   }
01120 }
01121 
01122 void KivioView::groupStencils()
01123 {
01124     m_pActivePage->groupSelectedStencils();
01125     m_pDoc->updateView(m_pActivePage);
01126 }
01127 
01128 void KivioView::ungroupStencils()
01129 {
01130     m_pActivePage->ungroupSelectedStencils();
01131     m_pDoc->updateView(m_pActivePage);
01132 }
01133 
01134 void KivioView::selectAllStencils()
01135 {
01136     m_pActivePage->selectAllStencils();
01137     m_pCanvas->repaint();
01138 }
01139 
01140 void KivioView::unselectAllStencils()
01141 {
01142     m_pActivePage->unselectAllStencils();
01143     m_pCanvas->repaint();
01144 }
01145 
01146 QColor KivioView::fgColor() const
01147 {
01148     return m_setFGColor->color();
01149 }
01150 
01151 QColor KivioView::bgColor() const
01152 {
01153     return m_setBGColor->color();
01154 }
01155 
01156 double KivioView::lineWidth() const
01157 {
01158     return m_lineWidthAction->currentWidth();
01159 }
01160 
01161 int KivioView::lineStyle() const
01162 {
01163   return m_lineStyleAction->currentSelection();
01164 }
01165 
01166 
01167 void KivioView::setFontFamily( const QString &str )
01168 {
01169   canvasWidget()->setFocus();
01170   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01171   if (!pStencil)
01172     return;
01173 
01174   QFont f;
01175   KMacroCommand * macro = 0L;
01176   while( pStencil )
01177   {
01178       f = pStencil->textFont();
01179       f.setFamily( str );
01180       if ( pStencil->textFont() != f )
01181       {
01182           if ( !macro )
01183               macro = new KMacroCommand( i18n("Change Stencil Font"));
01184 
01185           KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(),  f);
01186           pStencil->setTextFont( f );
01187 
01188           macro->addCommand( cmd );
01189       }
01190       pStencil = m_pActivePage->selectedStencils()->next();
01191 
01192   }
01193   if ( macro )
01194       m_pDoc->addCommand( macro  );
01195   m_pDoc->updateView(m_pActivePage);
01196 }
01197 
01198 void KivioView::setFontSize(int size )
01199 {
01200   canvasWidget()->setFocus();
01201   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01202   if (!pStencil)
01203     return;
01204 
01205   QFont f;
01206   KMacroCommand * macro = 0L;
01207   while( pStencil )
01208   {
01209       f = pStencil->textFont();
01210       f.setPointSize( size );
01211       if ( pStencil->textFont() != f )
01212       {
01213           if ( !macro )
01214               macro = new KMacroCommand( i18n("Change Stencil Font"));
01215 
01216           KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(),  f);
01217 
01218           pStencil->setTextFont( f );
01219           macro->addCommand( cmd );
01220       }
01221       pStencil = m_pActivePage->selectedStencils()->next();
01222 
01223   }
01224   if ( macro )
01225       m_pDoc->addCommand( macro   );
01226   m_pDoc->updateView(m_pActivePage);
01227 }
01228 
01229 void KivioView::toggleFontBold(bool b)
01230 {
01231     KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01232     if (!pStencil)
01233       return;
01234 
01235     QFont f;
01236     KMacroCommand * macro = 0L;
01237     while( pStencil )
01238     {
01239         f = pStencil->textFont();
01240         f.setBold(b);
01241         if ( pStencil->textFont() != f )
01242         {
01243             if ( !macro )
01244                 macro = new KMacroCommand( i18n("Change Stencil Font"));
01245             KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(),  f);
01246 
01247             pStencil->setTextFont( f );
01248             macro->addCommand( cmd );
01249         }
01250         pStencil = m_pActivePage->selectedStencils()->next();
01251 
01252     }
01253     if ( macro )
01254         m_pDoc->addCommand( macro );
01255     m_pDoc->updateView(m_pActivePage);
01256 }
01257 
01258 void KivioView::toggleFontItalics(bool b)
01259 {
01260     KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01261     if (!pStencil)
01262         return;
01263 
01264     QFont f;
01265     KMacroCommand * macro = new KMacroCommand( i18n("Change Stencil Font"));
01266     while( pStencil )
01267     {
01268         f = pStencil->textFont();
01269         f.setItalic(b);
01270         if ( pStencil->textFont() != f )
01271         {
01272             if ( !macro )
01273                 macro = new KMacroCommand( i18n("Change Stencil Font"));
01274 
01275             KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(),  f);
01276 
01277             pStencil->setTextFont( f );
01278 
01279             macro->addCommand( cmd );
01280         }
01281         pStencil = m_pActivePage->selectedStencils()->next();
01282     }
01283     if ( macro )
01284         m_pDoc->addCommand( macro );
01285     m_pDoc->updateView(m_pActivePage);
01286 }
01287 
01288 void KivioView::toggleFontUnderline( bool b)
01289 {
01290     KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01291     if (!pStencil)
01292       return;
01293     KMacroCommand * macro = 0L;
01294     QFont f;
01295     while( pStencil )
01296     {
01297         f = pStencil->textFont();
01298         f.setUnderline(b);
01299         if ( pStencil->textFont() != f )
01300         {
01301             if ( !macro )
01302                 macro = new KMacroCommand( i18n("Change Stencil Font"));
01303 
01304             KivioChangeStencilFontCommand *cmd = new KivioChangeStencilFontCommand( i18n("Change Stencil Font"), m_pActivePage, pStencil,pStencil->textFont(),  f);
01305 
01306             pStencil->setTextFont( f );
01307 
01308             macro->addCommand( cmd );
01309         }
01310         pStencil = m_pActivePage->selectedStencils()->next();
01311     }
01312     if ( macro )
01313         m_pDoc->addCommand( macro );
01314     m_pDoc->updateView(m_pActivePage);
01315 }
01316 
01317 
01318 
01319 void KivioView::updateToolBars()
01320 {
01321     KivioStencil *pStencil;
01322     pStencil = m_pActivePage->selectedStencils()->first();
01323     m_pStencilGeometryPanel->setEmitSignals(false);
01324     m_setArrowHeads->setEmitSignals(false);
01325 
01326     if( !pStencil )
01327     {
01328         m_setFontFamily->setFont( doc()->defaultFont().family() );
01329         m_setFontSize->setFontSize( doc()->defaultFont().pointSize() );
01330         m_setBold->setChecked( false );
01331         m_setItalics->setChecked( false );
01332         m_setUnderline->setChecked( false );
01333         m_lineWidthAction->setCurrentWidth(1.0);
01334         m_lineStyleAction->setCurrentSelection(Qt::SolidLine);
01335         showAlign(Qt::AlignHCenter);
01336         showVAlign(Qt::AlignVCenter);
01337 
01338         m_pStencilGeometryPanel->setSize(0.0,0.0);
01339         m_pStencilGeometryPanel->setPosition(0.0,0.0);
01340         m_pStencilGeometryPanel->setRotation(0);
01341 
01342         m_setArrowHeads->setCurrentStartArrow(0);
01343         m_setArrowHeads->setCurrentEndArrow(0);
01344 
01345         m_menuTextFormatAction->setEnabled( false );
01346         m_menuStencilConnectorsAction->setEnabled( false );
01347     }
01348     else
01349     {
01350         QFont f = pStencil->textFont();
01351 
01352         m_setFontFamily->setFont( f.family() );
01353         m_setFontSize->setFontSize( f.pointSize() );
01354         m_setBold->setChecked( f.bold() );
01355         m_setItalics->setChecked( f.italic() );
01356         m_setUnderline->setChecked( f.underline() );
01357 
01358         m_setFGColor->setCurrentColor(pStencil->fgColor());
01359         m_setBGColor->setCurrentColor(pStencil->bgColor());
01360         m_setTextColor->setCurrentColor(pStencil->textColor());
01361 
01362         m_lineWidthAction->setCurrentWidth(pStencil->lineWidth());
01363         m_lineStyleAction->setCurrentSelection(pStencil->linePattern());
01364 
01365         showAlign(pStencil->hTextAlign());
01366         showVAlign(pStencil->vTextAlign());
01367 
01368         m_pStencilGeometryPanel->setSize( pStencil->w(), pStencil->h() );
01369         m_pStencilGeometryPanel->setPosition( pStencil->x(), pStencil->y() );
01370         m_pStencilGeometryPanel->setRotation(pStencil->rotation());
01371 
01372         m_menuTextFormatAction->setEnabled( true );
01373         m_menuStencilConnectorsAction->setEnabled( true );
01374 
01375         if ( pStencil->type() != kstConnector )
01376         {
01377            m_setArrowHeads->setEnabled (false);
01378            m_arrowHeadsMenuAction->setEnabled (false);
01379         }
01380         else
01381         {
01382             m_setArrowHeads->setEnabled (true);
01383             m_arrowHeadsMenuAction->setEnabled (true);
01384             m_setArrowHeads->setCurrentStartArrow( pStencil->startAHType() );
01385             m_setArrowHeads->setCurrentEndArrow( pStencil->endAHType() );
01386         }
01387 
01388         if ( pStencil->type() != kstText )
01389         {
01390             m_setFGColor->setEnabled (true);
01391             m_setBGColor->setEnabled (true);
01392         }
01393         else
01394         {
01395             m_setFGColor->setEnabled (false);
01396             m_setBGColor->setEnabled (false);
01397         }
01398     }
01399 
01400     m_pStencilGeometryPanel->setEmitSignals(true);
01401     m_setArrowHeads->setEmitSignals(true);
01402     m_pProtectionPanel->updateCheckBoxes();
01403 
01404     if(activePage()->selectedStencils()->count() > 1) {
01405       m_groupAction->setEnabled(true);
01406       m_alignAndDistribute->setEnabled(true);
01407     } else {
01408       m_groupAction->setEnabled(false);
01409       m_alignAndDistribute->setEnabled(false);
01410     }
01411 
01412     if(activePage()->selectedStencils()->count() > 0) {
01413       m_editCut->setEnabled(true);
01414       m_editCopy->setEnabled(true);
01415       m_editDelete->setEnabled(true);
01416 
01417       if(activePage()->checkForStencilTypeInSelection(kstGroup)) {
01418         m_ungroupAction->setEnabled(true);
01419       } else {
01420         m_ungroupAction->setEnabled(false);
01421       }
01422 
01423       m_stencilToBack->setEnabled(true);
01424       m_stencilToFront->setEnabled(true);
01425       m_pStencilGeometryPanel->setEnabled(true);
01426       m_pProtectionPanel->setEnabled(true);
01427     } else {
01428       m_editCut->setEnabled(false);
01429       m_editCopy->setEnabled(false);
01430       m_editDelete->setEnabled(false);
01431       m_ungroupAction->setEnabled(false);
01432       m_stencilToBack->setEnabled(false);
01433       m_stencilToFront->setEnabled(false);
01434       m_setArrowHeads->setEnabled(false);
01435       m_arrowHeadsMenuAction->setEnabled(false);
01436       m_pStencilGeometryPanel->setEnabled(false);
01437       m_pProtectionPanel->setEnabled(false);
01438     }
01439 }
01440 
01441 void KivioView::slotSetStartArrow( int i )
01442 {
01443   if(!m_pActivePage) {
01444     return;
01445   }
01446 
01447   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01448   if (!pStencil)
01449     return;
01450 
01451   KMacroCommand *macro = new KMacroCommand( i18n("Change Begin Arrow"));
01452   bool createMacro = false;
01453   while( pStencil )
01454   {
01455       if (pStencil->startAHType()!=i)
01456       {
01457           pStencil->setStartAHType(i);
01458           KivioChangeBeginEndArrowCommand *cmd=new KivioChangeBeginEndArrowCommand( i18n("Change Arrow"),
01459             m_pActivePage, pStencil,  pStencil->startAHType(),  i, true);
01460           pStencil->setStartAHType(i);
01461 
01462           macro->addCommand( cmd );
01463           createMacro= true;
01464       }
01465       pStencil = m_pActivePage->selectedStencils()->next();
01466   }
01467   if (createMacro )
01468       m_pDoc->addCommand( macro );
01469   else
01470       delete macro;
01471   m_pDoc->updateView(m_pActivePage);
01472 }
01473 
01474 void KivioView::slotSetEndArrow( int i )
01475 {
01476   if(!m_pActivePage) {
01477     return;
01478   }
01479 
01480   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01481   if (!pStencil)
01482     return;
01483   KMacroCommand *macro = new KMacroCommand( i18n("Change End Arrow"));
01484   bool createMacro = false;
01485 
01486   while( pStencil )
01487   {
01488       if (pStencil->endAHType()!=i)
01489       {
01490           KivioChangeBeginEndArrowCommand *cmd=new KivioChangeBeginEndArrowCommand( i18n("Change Arrow"),
01491             m_pActivePage, pStencil, pStencil->endAHType(),  i, false);
01492           pStencil->setEndAHType(i);
01493 
01494           macro->addCommand( cmd );
01495           createMacro= true;
01496       }
01497       pStencil = m_pActivePage->selectedStencils()->next();
01498   }
01499   if (createMacro )
01500       m_pDoc->addCommand( macro );
01501   else
01502       delete macro;
01503 
01504   m_pDoc->updateView(m_pActivePage);
01505 }
01506 
01507 void KivioView::slotSetStartArrowSize()
01508 {
01509     KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01510     if (!pStencil)
01511       return;
01512 
01513     float w = 0.0;
01514     float h = 0.0;
01515     KMacroCommand *macro = new KMacroCommand( i18n("Change Size of Begin Arrow"));
01516     bool createMacro = false;
01517     while( pStencil )
01518     {
01519         if (pStencil->startAHLength() != h || pStencil->startAHWidth()!=w)
01520         {
01521             KivioChangeBeginEndSizeArrowCommand * cmd = new KivioChangeBeginEndSizeArrowCommand( i18n("Change Size of End Arrow"), m_pActivePage, pStencil, pStencil->startAHLength(),pStencil->startAHWidth(), h,w, true);
01522 
01523             pStencil->setStartAHWidth(w);
01524             pStencil->setStartAHLength(h);
01525             macro->addCommand( cmd );
01526             createMacro= true;
01527         }
01528         pStencil = m_pActivePage->selectedStencils()->next();
01529     }
01530     if (createMacro )
01531         m_pDoc->addCommand( macro );
01532     else
01533         delete macro;
01534     m_pDoc->updateView(m_pActivePage);
01535 }
01536 
01537 void KivioView::slotSetEndArrowSize()
01538 {
01539     KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01540     if (!pStencil)
01541       return;
01542 
01543     float w = 0.0;
01544     float h = 0.0;
01545     KMacroCommand *macro = new KMacroCommand( i18n("Change Size of End Arrow"));
01546     bool createMacro = false;
01547     while( pStencil )
01548     {
01549         if ( pStencil->endAHLength() != h || pStencil->endAHWidth()!=w)
01550         {
01551             KivioChangeBeginEndSizeArrowCommand * cmd = new KivioChangeBeginEndSizeArrowCommand( i18n("Change Size of End Arrow"), m_pActivePage, pStencil, pStencil->endAHLength(),pStencil->endAHWidth(), h,w, false);
01552             pStencil->setEndAHWidth(w);
01553             pStencil->setEndAHLength(h);
01554             macro->addCommand( cmd );
01555             createMacro= true;
01556         }
01557         pStencil = m_pActivePage->selectedStencils()->next();
01558     }
01559     if ( createMacro )
01560         m_pDoc->addCommand( macro );
01561     else
01562         delete macro;
01563     m_pDoc->updateView(m_pActivePage);
01564 }
01565 
01566 void KivioView::setHParaAlign( int i )
01567 {
01568     KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01569     if (!pStencil)
01570       return;
01571     KMacroCommand *macro = new KMacroCommand( i18n("Change Stencil Horizontal Alignment"));
01572     bool createMacro = false;
01573     while( pStencil )
01574     {
01575         if ( pStencil->hTextAlign() != i)
01576         {
01577             KivioChangeStencilHAlignmentCommand * cmd = new KivioChangeStencilHAlignmentCommand( i18n("Change Stencil Horizontal Alignment"), m_pActivePage, pStencil, pStencil->hTextAlign(), i);
01578 
01579             pStencil->setHTextAlign(i);
01580             macro->addCommand( cmd );
01581             createMacro = true;
01582         }
01583         pStencil = m_pActivePage->selectedStencils()->next();
01584 
01585     }
01586     if (createMacro )
01587         m_pDoc->addCommand( macro );
01588     else
01589         delete macro;
01590     m_pDoc->updateView(m_pActivePage);
01591 }
01592 
01593 
01594 void KivioView::setVParaAlign( int i )
01595 {
01596     KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01597     if (!pStencil)
01598       return;
01599     KMacroCommand *macro = new KMacroCommand( i18n("Change Stencil Vertical Alignment"));
01600     bool createMacro = false;
01601     while( pStencil )
01602     {
01603         if ( pStencil->vTextAlign() != i )
01604         {
01605             KivioChangeStencilVAlignmentCommand * cmd = new KivioChangeStencilVAlignmentCommand( i18n("Change Stencil Vertical Alignment"), m_pActivePage, pStencil, pStencil->vTextAlign(), i);
01606             pStencil->setVTextAlign( i );
01607             macro->addCommand( cmd );
01608             createMacro = true;
01609         }
01610         pStencil =  m_pActivePage->selectedStencils()->next();
01611 
01612     }
01613     if ( createMacro )
01614         m_pDoc->addCommand( macro );
01615     else
01616         delete macro;
01617     m_pDoc->updateView(m_pActivePage);
01618 }
01619 
01620 void KivioView::bringStencilToFront()
01621 {
01622     m_pActivePage->bringToFront();
01623     m_pDoc->updateView(m_pActivePage);
01624 }
01625 
01626 void KivioView::sendStencilToBack()
01627 {
01628     m_pActivePage->sendToBack();
01629     m_pDoc->updateView(m_pActivePage);
01630 }
01631 
01632 void KivioView::cutStencil()
01633 {
01634     m_pActivePage->cut();
01635     m_pDoc->updateView(m_pActivePage);
01636 }
01637 
01638 void KivioView::copyStencil()
01639 {
01640     m_pActivePage->copy();
01641 }
01642 
01643 void KivioView::pasteStencil()
01644 {
01645     m_pActivePage->paste(this);
01646     m_pDoc->updateView(m_pActivePage);
01647     m_pCanvas->setFocus();
01648 }
01649 
01650 void KivioView::slotChangeStencilSize(double newW, double newH)
01651 {
01652   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01653 
01654   if ( pStencil )
01655   {
01656     KoRect oldPos(pStencil->rect());
01657     pStencil->setDimensions(newW, newH);
01658     if ((oldPos.width() != pStencil->rect().width()) || (oldPos.height() != pStencil->rect().height()))
01659     {
01660       KivioMoveStencilCommand * cmd = new KivioMoveStencilCommand( i18n("Resize Stencil"), pStencil, oldPos , pStencil->rect(), m_pCanvas->activePage());
01661       m_pDoc->updateView(m_pActivePage);
01662       m_pDoc->addCommand( cmd );
01663     }
01664   }
01665 }
01666 
01667 void KivioView::slotChangeStencilPosition(double newW, double newH)
01668 {
01669   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01670 
01671   if ( pStencil )
01672   {
01673     KoRect oldPos(pStencil->rect());
01674     pStencil->setPosition(newW, newH);
01675     if ((oldPos.x() != pStencil->rect().x()) || (oldPos.y() != pStencil->rect().y()))
01676     {
01677       KivioMoveStencilCommand * cmd = new KivioMoveStencilCommand( i18n("Move Stencil"), pStencil, oldPos , pStencil->rect(), m_pCanvas->activePage());
01678       m_pDoc->updateView(m_pActivePage);
01679       m_pDoc->addCommand( cmd );
01680     }
01681   }
01682 }
01683 
01684 void KivioView::slotChangeStencilRotation(int d)
01685 {
01686   KivioStencil *pStencil = m_pActivePage->selectedStencils()->first();
01687 
01688   if(pStencil && pStencil->rotation() != d) {
01689       pStencil->setRotation(d);
01690       KivioChangeRotationCommand * cmd = new KivioChangeRotationCommand( i18n("Change Stencil Rotation"), m_pCanvas->activePage(), pStencil, pStencil->rotation() , d);
01691       m_pDoc->updateView(m_pActivePage);
01692       m_pDoc->addCommand( cmd );
01693   }
01694 }
01695 
01699 void KivioView::addStencilFromSpawner( KivioStencilSpawner *pSpawner, double x, double y )
01700 {
01701     KivioStencil *pStencil;
01702 
01703     // Allocate the new stencil and set it's default size/style
01704     pStencil = pSpawner->newStencil();
01705 
01706     pStencil->setPosition( x, y );
01707 
01708     // Use default properties if we held ctrl down
01709 #if KDE_IS_VERSION(3, 4, 0)
01710     if(kapp->keyboardMouseState() & Qt::ControlButton) {
01711 #else
01712     if(KApplication::keyboardModifiers() & KApplication::ControlModifier) {
01713 #endif
01714       pStencil->setFGColor(m_setFGColor->color());
01715       pStencil->setBGColor(m_setBGColor->color());
01716       QFont f = m_setFontFamily->font();
01717       f.setPointSize(m_setFontSize->fontSize());
01718       f.setBold(m_setBold->isChecked());
01719       f.setItalic(m_setItalics->isChecked());
01720       f.setUnderline(m_setUnderline->isChecked());
01721       pStencil->setTextFont(f);
01722       pStencil->setTextColor(m_setTextColor->color());
01723       pStencil->setVTextAlign(vTextAlign());
01724       pStencil->setHTextAlign(hTextAlign());
01725       pStencil->setLinePattern(m_lineStyleAction->currentSelection());
01726       pStencil->setLineWidth(m_lineWidthAction->currentWidth());
01727     } else {
01728       pStencil->setTextFont(doc()->defaultFont());
01729     }
01730 
01731     // Unselect everything, then the stencil to the page, and select it
01732     m_pActivePage->unselectAllStencils();
01733     m_pActivePage->addStencil( pStencil );
01734     m_pActivePage->selectStencil( pStencil );
01735 
01736     // Mark the page as modified and repaint
01737     m_pDoc->updateView(m_pActivePage);
01738     pluginManager()->activateDefaultTool();
01739     m_pCanvas->updateAutoGuideLines();
01740 }
01741 
01742 void KivioView::alignStencilsDlg()
01743 {
01744   KivioAlignDialog* dlg = new KivioAlignDialog(this, "AlignDialog");
01745 
01746   if( dlg->exec() == QDialog::Accepted )
01747   {
01748     m_pActivePage->alignStencils(dlg->align());
01749     m_pActivePage->distributeStencils(dlg->distribute());
01750 
01751     m_pCanvas->repaint();
01752   }
01753 
01754   delete dlg;
01755 }
01756 
01757 void KivioView::optionsDialog()
01758 {
01759   KivioOptionsDialog dlg(this, "setupDialog");
01760   dlg.exec();
01761 }
01762 
01763 void KivioView::toggleStencilGeometry(bool b)
01764 {
01765     TOGGLE_ACTION("stencilGeometry")->setChecked(b);
01766 }
01767 
01768 void KivioView::toggleViewManager(bool b)
01769 {
01770     TOGGLE_ACTION("viewManager")->setChecked(b);
01771 }
01772 
01773 void KivioView::setupPrinter(KPrinter &p)
01774 {
01775   p.setMinMax(1, m_pDoc->map()->pageList().count());
01776   KoPageLayout pl = activePage()->paperLayout();
01777   p.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pl.format ) ) );
01778 
01779   if ( pl.orientation == PG_LANDSCAPE || pl.format == PG_SCREEN ) {
01780     p.setOrientation( KPrinter::Landscape );
01781   } else {
01782     p.setOrientation( KPrinter::Portrait );
01783   }
01784 }
01785 
01786 void KivioView::popupTabBarMenu( const QPoint & _point )
01787 {
01788     if(!koDocument()->isReadWrite() || !factory())
01789         return;
01790      static_cast<QPopupMenu*>(factory()->container("menupage_popup",this))->popup(_point);
01791 }
01792 
01793 void KivioView::updateMenuPage()
01794 {
01795     bool state = (doc()->map()->count() > 1 && doc()->map()->visiblePages().count()>1);
01796     m_removePage->setEnabled(state);
01797     m_hidePage->setEnabled( doc()->map()->visiblePages().count()>1 );
01798     m_showPage->setEnabled( doc()->map()->hiddenPages().count()>0 );
01799 }
01800 
01801 void KivioView::updateButton()
01802 {
01803   toggleShowGrid(Kivio::Config::showGrid());
01804   toggleSnapGrid(Kivio::Config::snapGrid());
01805 
01806   toggleShowGuides(koDocument()->isReadWrite());
01807 }
01808 
01809 void KivioView::slotPageHidden( KivioPage* /*page*/ )
01810 {
01811     //m_pTabBar->hidePage( page->pageName() );
01812 }
01813 
01814 void KivioView::slotPageShown( KivioPage* /*page*/ )
01815 {
01816     m_pTabBar->setTabs( m_pDoc->map()->visiblePages() );
01817 }
01818 
01819 void KivioView::resetLayerPanel()
01820 {
01821     if ( m_pLayersPanel )
01822     {
01823         m_pLayersPanel->reset();
01824     }
01825 }
01826 
01827 void KivioView::updateProtectPanelCheckBox()
01828 {
01829     if ( m_pProtectionPanel )
01830     {
01831         m_pProtectionPanel->updateCheckBoxes();
01832     }
01833 }
01834 
01835 void KivioView::setMousePos( int mx, int my )
01836 {
01837   vRuler->setMousePos(mx, my);
01838   hRuler->setMousePos(mx, my);
01839 
01840   if((mx >= 0) && (my >= 0)) {
01841     QString unit = KoUnit::unitName(m_pDoc->unit());
01842     KoPoint xy = m_pCanvas->mapFromScreen(QPoint(mx, my));
01843     xy.setX(KoUnit::toUserValue(xy.x(), m_pDoc->unit()));
01844     xy.setY(KoUnit::toUserValue(xy.y(), m_pDoc->unit()));
01845     QString text = i18n("X: %1 %3 Y: %2 %4").arg(KGlobal::_locale->formatNumber(xy.x(), 2))
01846       .arg(KGlobal::_locale->formatNumber(xy.y(), 2)).arg(unit).arg(unit);
01847     m_coordSLbl->setText(text);
01848   }
01849 }
01850 
01851 void KivioView::setRulerUnit(KoUnit::Unit u)
01852 {
01853   vRuler->setUnit(u);
01854   hRuler->setUnit(u);
01855 }
01856 
01857 void KivioView::setRulerHOffset(int h)
01858 {
01859   if(hRuler) {
01860     hRuler->setOffset(h - m_pCanvas->pageOffsetX(), 0);
01861   }
01862 }
01863 
01864 void KivioView::setRulerVOffset(int v)
01865 {
01866   if(vRuler) {
01867     vRuler->setOffset(0, v - m_pCanvas->pageOffsetY());
01868   }
01869 }
01870 
01871 void KivioView::rulerChangedUnit(KoUnit::Unit u)
01872 {
01873   m_pDoc->setUnit(u);
01874 }
01875 
01876 KoZoomHandler* KivioView::zoomHandler() const
01877 {
01878   return m_zoomHandler;
01879 }
01880 
01881 void KivioView::setRulerPageLayout(const KoPageLayout& l)
01882 {
01883   vRuler->setPageLayout(l);
01884   hRuler->setPageLayout(l);
01885   vRuler->setFrameStartEnd(zoomHandler()->zoomItY(l.ptTop), zoomHandler()->zoomItY(l.ptHeight - l.ptBottom));
01886   hRuler->setFrameStartEnd(zoomHandler()->zoomItX(l.ptLeft), zoomHandler()->zoomItX(l.ptWidth - l.ptRight));
01887   setRulerVOffset(m_vertScrollBar->value());
01888   setRulerHOffset(m_horzScrollBar->value());
01889   m_pStencilGeometryPanel->setPageLayout(l);
01890 }
01891 
01892 void KivioView::viewZoom(const QString& s)
01893 {
01894   QString z(s);
01895   z.remove('%');
01896   z.simplifyWhiteSpace();
01897   bool ok = false;
01898   int zoom = z.toInt(&ok);
01899 
01900   if(!ok || zoom < 10 || zoom > 2000) {
01901     zoom = zoomHandler()->zoom();
01902   }
01903 
01904   if(zoom != zoomHandler()->zoom()) {
01905     viewZoom(zoom);
01906   }
01907 
01908   canvasWidget()->setFocus();
01909 }
01910 
01911 void KivioView::textAlignLeft()
01912 {
01913   if ( m_textAlignLeft->isChecked() ) {
01914     setHParaAlign( Qt::AlignLeft );
01915   } else {
01916     m_textAlignLeft->setChecked( true );
01917   }
01918 }
01919 
01920 void KivioView::textAlignCenter()
01921 {
01922   if ( m_textAlignCenter->isChecked() ) {
01923     setHParaAlign( Qt::AlignHCenter );
01924   } else {
01925     m_textAlignCenter->setChecked( true );
01926   }
01927 }
01928 
01929 void KivioView::textAlignRight()
01930 {
01931   if ( m_textAlignRight->isChecked() ) {
01932     setHParaAlign( Qt::AlignRight );
01933   } else {
01934     m_textAlignRight->setChecked( true );
01935   }
01936 }
01937 
01938 void KivioView::textSuperScript()
01939 {
01940   if ( m_textVAlignSuper->isChecked() ) {
01941     setVParaAlign( Qt::AlignTop );
01942   } else {
01943     if ( !m_textVAlignSub->isChecked() ) {
01944       setVParaAlign( Qt::AlignVCenter );
01945     }
01946   }
01947 }
01948 
01949 void KivioView::textSubScript()
01950 {
01951   if ( m_textVAlignSub->isChecked() ) {
01952     setVParaAlign( Qt::AlignBottom );
01953   } else {
01954     if ( !m_textVAlignSuper->isChecked() ) {
01955       setVParaAlign( Qt::AlignVCenter );
01956     }
01957   }
01958 }
01959 
01960 void KivioView::showAlign( int align )
01961 {
01962   switch ( align ) {
01963     case Qt::AlignAuto: // In left-to-right mode it's align left. TODO: alignright if text->isRightToLeft()
01964       kdWarning(43000) << k_funcinfo << "shouldn't be called with AlignAuto" << endl;
01965       // fallthrough
01966     case Qt::AlignLeft:
01967       m_textAlignLeft->setChecked( true );
01968       break;
01969     case Qt::AlignHCenter:
01970       m_textAlignCenter->setChecked( true );
01971       break;
01972     case Qt::AlignRight:
01973       m_textAlignRight->setChecked( true );
01974       break;
01975   }
01976 }
01977 
01978 void KivioView::showVAlign( int align )
01979 {
01980   switch(align) {
01981     case Qt::AlignTop:
01982       m_textVAlignSuper->setChecked(true);
01983       break;
01984     case Qt::AlignVCenter:
01985       m_textVAlignSuper->setChecked(false);
01986       m_textVAlignSub->setChecked(false);
01987       break;
01988     case Qt::AlignBottom:
01989       m_textVAlignSub->setChecked(true);
01990       break;
01991   }
01992 }
01993 
01994 void KivioView::textFormat()
01995 {
01996   KivioTextFormatDlg dlg(this);
01997   KivioStencil* stencil = activePage()->selectedStencils()->getLast();
01998 
01999   if(stencil) {
02000     dlg.setFont(stencil->textFont());
02001     dlg.setTextColor(stencil->textColor());
02002     dlg.setHAlign(stencil->hTextAlign());
02003     dlg.setVAlign(stencil->vTextAlign());
02004   } else {
02005     dlg.setFont(doc()->defaultFont());
02006     dlg.setTextColor(QColor(0, 0, 0));
02007     dlg.setHAlign(Qt::AlignHCenter);
02008     dlg.setVAlign(Qt::AlignVCenter);
02009   }
02010 
02011   if(dlg.exec()) {
02012     QPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
02013 
02014     while((stencil = it.current()) != 0) {
02015       ++it;
02016       stencil->setTextFont(dlg.font());
02017       stencil->setTextColor(dlg.textColor());
02018       stencil->setVTextAlign(dlg.valign());
02019       stencil->setHTextAlign(dlg.halign());
02020     }
02021 
02022     updateToolBars();
02023   }
02024 }
02025 
02026 void KivioView::stencilFormat()
02027 {
02028   KivioStencilFormatDlg dlg(this);
02029   KivioStencil* stencil = activePage()->selectedStencils()->getLast();
02030   KivioLineStyle ls;
02031 
02032   if(stencil) {
02033     ls = stencil->lineStyle();
02034     dlg.setFillColor(stencil->bgColor());
02035     dlg.setFillPattern(stencil->fillPattern());
02036   } else {
02037     dlg.setLineWidth(1.0, m_pDoc->unit());
02038     dlg.setLineColor(QColor(0, 0, 0));
02039   }
02040 
02041   dlg.setLineWidth(ls.width(), m_pDoc->unit());
02042   dlg.setLineColor(ls.color());
02043   dlg.setLinePattern(ls.style());
02044   dlg.setLineEndStyle(ls.capStyle());
02045 
02046   if(dlg.exec()) {
02047     QPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
02048 
02049     while((stencil = it.current()) != 0) {
02050       ++it;
02051       stencil->setLineWidth(dlg.lineWidth());
02052       stencil->setFGColor(dlg.lineColor());
02053       stencil->setLinePattern(dlg.linePattern());
02054       stencil->setBGColor(dlg.fillColor());
02055       stencil->setFillPattern(dlg.fillPattern());
02056     }
02057 
02058     updateToolBars();
02059   }
02060 }
02061 
02062 void KivioView::arrowHeadFormat()
02063 {
02064   KivioArrowHeadFormatDlg dlg(this);
02065   dlg.setUnit(m_pDoc->unit());
02066   dlg.setStartAHType(0);
02067   dlg.setEndAHType(0);
02068   dlg.setStartAHWidth(10.0);
02069   dlg.setStartAHHeight(10.0);
02070   dlg.setEndAHWidth(10.0);
02071   dlg.setEndAHHeight(10.0);
02072 
02073   KivioStencil* stencil = activePage()->selectedStencils()->getLast();
02074 
02075   if(stencil) {
02076     if(stencil->type() == kstConnector) {
02077       dlg.setUnit(m_pDoc->unit());
02078       dlg.setStartAHType(stencil->startAHType());
02079       dlg.setEndAHType(stencil->endAHType());
02080       dlg.setStartAHWidth(stencil->startAHWidth());
02081       dlg.setStartAHHeight(stencil->startAHLength());
02082       dlg.setEndAHWidth(stencil->endAHWidth());
02083       dlg.setEndAHHeight(stencil->endAHLength());
02084     }
02085   }
02086 
02087   if(dlg.exec()) {
02088     QPtrListIterator<KivioStencil> it(*activePage()->selectedStencils());
02089 
02090     while((stencil = it.current()) != 0) {
02091       ++it;
02092 
02093       if(stencil->type() == kstConnector) {
02094         stencil->setStartAHType(dlg.startAHType());
02095         stencil->setEndAHType(dlg.endAHType());
02096         stencil->setStartAHWidth(dlg.startAHWidth());
02097         stencil->setStartAHLength(dlg.startAHHeight());
02098         stencil->setEndAHWidth(dlg.endAHWidth());
02099         stencil->setEndAHLength(dlg.endAHHeight());
02100       }
02101     }
02102 
02103     updateToolBars();
02104   }
02105 }
02106 
02107 Kivio::PluginManager* KivioView::pluginManager()
02108 {
02109   return m_pluginManager;
02110 }
02111 
02112 void KivioView::clipboardDataChanged()
02113 {
02114   QMimeSource* data = QApplication::clipboard()->data();
02115   KivioDragObject decoder(this);
02116   bool paste = decoder.canDecode(data);
02117   m_editPaste->setEnabled(paste);
02118 }
02119 
02120 void KivioView::partActivateEvent(KParts::PartActivateEvent* event)
02121 {
02122   if((event->widget() == this) && event->activated()) {
02123     updateToolBars();
02124     clipboardDataChanged();
02125   }
02126 
02127   if(event->widget() == this) {
02128     m_pluginManager->setEventDelegationEnabled(event->activated());
02129     m_pStencilBarDockManager->setAllStackBarsShown(event->activated());
02130   }
02131 
02132   KoView::partActivateEvent(event);
02133 }
02134 
02135 void KivioView::initStatusBarProgress()
02136 {
02137   if(!m_statusBarProgress) {
02138     m_statusBarProgress = new QProgressBar(100, this);
02139     addStatusBarItem(m_statusBarProgress);
02140   }
02141 
02142   m_statusBarProgress->reset();
02143 }
02144 
02145 void KivioView::setStatusBarProgress(int progress)
02146 {
02147   if(m_statusBarProgress) {
02148     m_statusBarProgress->setProgress(progress);
02149   }
02150 }
02151 
02152 void KivioView::removeStatusBarProgress()
02153 {
02154   if(m_statusBarProgress) {
02155     removeStatusBarItem(m_statusBarProgress);
02156     delete m_statusBarProgress;
02157     m_statusBarProgress = 0;
02158   }
02159 }
02160 
02161 void KivioView::installStencilSet()
02162 {
02163   Kivio::StencilSetInstaller dlg(this);
02164   dlg.exec();
02165   emit updateStencilSetList();
02166 }
02167 
02168 int KivioView::hTextAlign()
02169 {
02170   if(m_textAlignRight->isChecked()) {
02171     return Qt::AlignRight;
02172   } else if(m_textAlignLeft->isChecked()) {
02173     return Qt::AlignLeft;
02174   }
02175 
02176   return Qt::AlignHCenter;
02177 }
02178 
02179 int KivioView::vTextAlign()
02180 {
02181   if(m_textVAlignSub->isChecked() && !m_textVAlignSuper->isChecked()) {
02182     return Qt::AlignBottom;
02183   } else if(!m_textVAlignSub->isChecked() && m_textVAlignSuper->isChecked()) {
02184     return Qt::AlignTop;
02185   }
02186 
02187   return Qt::AlignVCenter;
02188 }
02189 
02190 void KivioView::updatePageStatusLabel()
02191 {
02192   QString text = i18n("Page %1/%2").arg(m_pDoc->map()->pageList().find(activePage()) + 1).arg(m_pDoc->map()->count());
02193   m_pageCountSLbl->setText(text);
02194 }
02195 
02196 void KivioView::setStatusBarInfo(const QString& text)
02197 {
02198   m_infoSLbl->setText(text);
02199 }
02200 
02201 void KivioView::loadingFinished()
02202 {
02203   m_pTabBar->clear();
02204   QPtrList<KivioPage> pages = m_pDoc->map()->pageList();
02205   QPtrListIterator<KivioPage> it(pages);
02206   KivioPage* page;
02207 
02208   while((page = it.current()) != 0) {
02209     ++it;
02210     addPage(page);
02211   }
02212 
02213   setActivePage(m_pDoc->map()->firstPage());
02214   m_pTabBar->setActiveTab(activePage()->pageName());
02215 
02216   if( m_pDoc->isReadWrite() ) // only if not embedded in Konqueror
02217   {
02218     KivioStencilSpawnerSet *pSet;
02219     pSet = m_pDoc->spawnerSets()->first();
02220     while( pSet )
02221     {
02222       addSpawnerToStackBar( pSet );
02223       pSet = m_pDoc->spawnerSets()->next();
02224     }
02225   }
02226 }
02227 
02228 void KivioView::moveTab(unsigned tab, unsigned target)
02229 {
02230   QStringList tabs = m_pTabBar->tabs();
02231   QString tabTitle = tabs[tab];
02232   QString targetTitle = tabs[target];
02233 
02234   if(target >= static_cast<unsigned>(m_pDoc->map()->count())) {
02235     targetTitle = m_pDoc->map()->lastPage()->pageName();
02236   }
02237 
02238   m_pDoc->map()->movePage(tabTitle, targetTitle, target < static_cast<unsigned>(m_pDoc->map()->count()));
02239   m_pTabBar->moveTab(tab, target);
02240 }
02241 
02242 void KivioView::deleteObject()
02243 {
02244   activePage()->deleteSelectedStencils();
02245   m_pDoc->updateView(activePage());
02246 }
02247 
02248 void KivioView::addGuideLine()
02249 {
02250   KoPageLayout pl = activePage()->paperLayout();
02251   KoRect pageRect(0.0, 0.0, pl.ptWidth, pl.ptHeight);
02252   KoPoint pos(0.0, 0.0);
02253   KoGuideLineDia dlg(this, pos, pageRect, m_pDoc->unit(), "addGuideDialog");
02254 
02255   if(dlg.exec() == QDialog::Accepted) {
02256     activePage()->addGuideLine(dlg.orientation(), dlg.pos());
02257     m_pDoc->updateGuideLines(activePage());
02258   }
02259 }
02260 
02261 void KivioView::showAddStencilSetDialog()
02262 {
02263   if(!m_addStencilSetDialog) {
02264     m_addStencilSetDialog = new Kivio::AddStencilSetDialog(this, "AddStencilSetDialog");
02265     connect(m_addStencilSetDialog, SIGNAL(addStencilSet(const QString&)), this, SLOT(addStencilSet(const QString&)));
02266     connect(this, SIGNAL(updateStencilSetList()), m_addStencilSetDialog, SLOT(updateList()));
02267   }
02268 
02269   m_addStencilSetDialog->show();
02270 }
02271 
02272 void KivioView::updateRulers()
02273 {
02274   m_pCanvas->updateScrollBars();
02275   setRulerVOffset(m_vertScrollBar->value());
02276   setRulerHOffset(m_horzScrollBar->value());
02277 }
02278 
02279 #include "kivio_view.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys