kpresenter

KPrView.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2005-2006 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <kprinter.h>
00022 #include <kaccel.h>
00023 #include <kglobalsettings.h>
00024 #include <qpainter.h>
00025 #include <qscrollbar.h>
00026 #include <qpopupmenu.h>
00027 #include <qcursor.h>
00028 #include <qfileinfo.h>
00029 #include <qtextstream.h>
00030 #include <assert.h>
00031 #include <qtoolbutton.h>
00032 #include <qtooltip.h>
00033 #include <qdir.h>
00034 #include <qclipboard.h>
00035 #include <qradiobutton.h>
00036 #include <qdragobject.h>
00037 #include <qfile.h>
00038 
00039 #include "KPrPage.h"
00040 #include "KPrBackDia.h"
00041 #include "autoformEdit/AFChoose.h"
00042 #include "KPrPropertyEditor.h"
00043 #include "KPrPgConfDia.h"
00044 #include "KPrEffectDia.h"
00045 #include "KPrRotationDialogImpl.h"
00046 #include "KPrShadowDialogImpl.h"
00047 #include "KPrImageEffectDia.h"
00048 #include "KPrBackground.h"
00049 #include "KPrPenStyleWidget.h"
00050 #include "KPrObjectProperties.h"
00051 
00052 #include <KoAutoFormat.h>
00053 
00054 #include "KPrSlideTransitionDia.h"
00055 
00056 #include "KPrPresDurationDia.h"
00057 #include "KPrPartObject.h"
00058 #include "KPrSideBar.h"
00059 #include "KPrNoteBar.h"
00060 #include "insertpagedia.h"
00061 #include "KPrCustomSlideShowDia.h"
00062 
00063 #include <KoPictureFilePreview.h>
00064 #include <KoCreateStyleDia.h>
00065 
00066 #include <dcopclient.h>
00067 #include <kfiledialog.h>
00068 #include <kmessagebox.h>
00069 #include <kstdaction.h>
00070 #include <kapplication.h>
00071 #include <kio/netaccess.h>
00072 
00073 #include "KPrView.h"
00074 #include "KPrDocument.h"
00075 #include "KPrWebPresentation.h"
00076 #include "KPrMSPresentationSetup.h"
00077 #include "KPrTextObject.h"
00078 
00079 #include <klocale.h>
00080 #include <kcolordialog.h>
00081 #include <kconfig.h>
00082 #include <kfontdialog.h>
00083 #include <kglobal.h>
00084 #include <kimageio.h>
00085 #include <kparts/event.h>
00086 #include <kdebug.h>
00087 #include <ktempfile.h>
00088 #include <kcolorbutton.h>
00089 
00090 #include <KoMainWindow.h>
00091 #include <KoPartSelectDia.h>
00092 #include <KoQueryTrader.h>
00093 #include <KoPageLayoutDia.h>
00094 #include <KoRuler.h>
00095 #include <KoTemplateCreateDia.h>
00096 #include <kcoloractions.h>
00097 #include <tkcoloractions.h>
00098 #include <kaction.h>
00099 #include <qspinbox.h>
00100 #include <qcombobox.h>
00101 #include <KoPartSelectAction.h>
00102 #include <KoTextZoomHandler.h>
00103 #include <Kolinestyleaction.h>
00104 #include <Kolinewidthaction.h>
00105 
00106 #include <stdlib.h>
00107 #include <signal.h>
00108 
00109 #include <kstandarddirs.h>
00110 
00111 #include "KPrViewIface.h"
00112 #include "KPrConfig.h"
00113 
00114 #include <KoTextParag.h>
00115 #include <KoTextObject.h>
00116 #include "KPrCommand.h"
00117 #include <KoFontDia.h>
00118 #include <KoCharSelectDia.h>
00119 #include <KoInsertLink.h>
00120 #include <KoAutoFormatDia.h>
00121 #include <KoParagCounter.h>
00122 #include <KoParagDia.h>
00123 #include <KoVariable.h>
00124 #include <KoCustomVariablesDia.h>
00125 #include <KoGuideLineDia.h>
00126 #include <KoCompletionDia.h>
00127 
00128 #include <kspell.h>
00129 #include <kstatusbar.h>
00130 #include "KPrTextDocument.h"
00131 
00132 #include <KoChangeCaseDia.h>
00133 #include <qregexp.h>
00134 
00135 #include <KoSearchDia.h>
00136 #include "KPrFindReplace.h"
00137 #include "KPrVariableCollection.h"
00138 #include "KPrCanvas.h"
00139 #include <qpaintdevicemetrics.h>
00140 #include <KoStyleCollection.h>
00141 #include "KPrStyleManager.h"
00142 #include "KPrPixmapObject.h"
00143 #include <KoCommentDia.h>
00144 
00145 #include "KPrDuplicateObjDia.h"
00146 #include <kstdaccel.h>
00147 #include <KoDocumentInfo.h>
00148 #include <kaccelgen.h>
00149 #include "KPrImportStyleDia.h"
00150 #include <kurldrag.h>
00151 #include <config.h>
00152 #include <KoStore.h>
00153 #include <KoStoreDrag.h>
00154 
00155 #include <kspell2/broker.h>
00156 #include <kspell2/defaultdictionary.h>
00157 #include <kspell2/dialog.h>
00158 #include "KoSpell.h"
00159 #include "KPrPrinterDlg.h"
00160 using namespace KSpell2;
00161 
00162 #define COPYOASISFORMAT 0
00163 
00164 static const char * const pageup_xpm[] = {
00165     "    14    14        2            1",
00166     ". c #000000",
00167     "# c none",
00168     "##############",
00169     "##############",
00170     "######..######",
00171     "#####....#####",
00172     "####......####",
00173     "###........###",
00174     "##############",
00175     "######..######",
00176     "#####....#####",
00177     "####......####",
00178     "###........###",
00179     "##############",
00180     "##############",
00181     "##############"
00182 };
00183 
00184 static const char * const pagedown_xpm[] = {
00185     "    14    14        2            1",
00186     ". c #000000",
00187     "# c none",
00188     "##############",
00189     "##############",
00190     "##############",
00191     "###........###",
00192     "####......####",
00193     "#####....#####",
00194     "######..######",
00195     "##############",
00196     "###........###",
00197     "####......####",
00198     "#####....#####",
00199     "######..######",
00200     "##############",
00201     "##############"
00202 };
00203 
00204 KPrView::KPrView( KPrDocument* _doc, QWidget *_parent, const char *_name )
00205     : KoView( _doc, _parent, _name )
00206 {
00207 
00208     setInstance( KPrFactory::global() );
00209     if ( !_doc->isReadWrite() )
00210         setXMLFile( "kpresenter_readonly.rc" );
00211     else
00212         setXMLFile( "kpresenter.rc" );
00213 
00214     dcop = 0;
00215     dcopObject(); // build it
00216 
00217     m_bDisplayFieldCode=false;
00218     // init
00219     afChoose = 0;
00220     m_propertyEditor = 0;
00221     pgConfDia = 0;
00222     rotateDia = 0;
00223     shadowDia = 0;
00224     imageEffectDia = 0;
00225     presDurationDia = 0;
00226     v_ruler = 0;
00227     h_ruler = 0;
00228     pen = KoPen( black, 1.0, SolidLine );
00229     brush = QBrush( white, SolidPattern );
00230     lineBegin = L_NORMAL;
00231     lineEnd = L_NORMAL;
00232     gColor1 = red;
00233     gColor2 = green;
00234     gType = BCT_GHORZ;
00235     gUnbalanced = false;
00236     gXFactor = 100;
00237     gYFactor = 100;
00238     fillType = FT_BRUSH;
00239     pieType = PT_PIE;
00240     pieLength = 90 * 16;
00241     pieAngle = 45 * 16;
00242     setMouseTracking( true );
00243     m_bShowGUI = true;
00244     presStarted = false;
00245     m_autoPresRestart = false;
00246     m_autoPresStop = false;
00247     rndX = 0;
00248     rndY = 0;
00249     m_editMaster = false;
00250     allowWebPres = true;
00251     allowMSPres = true;
00252     currPg = 0;
00253     sidebar = 0;
00254     notebar = 0;
00255     splitter = 0;
00256     pageBase = 0;
00257     m_canvas = 0L;
00258     m_spell.kospell = 0;
00259     m_spell.textIterator = 0L;
00260     m_spell.macroCmdSpellCheck = 0L;
00261     m_spell.dlg = 0;
00262     m_broker = Broker::openBroker( KSharedConfig::openConfig( "kpresenterrc" ) );
00263 
00264     m_autoPresTimerConnected = false;
00265     m_actionList.setAutoDelete( true );
00266     checkConcavePolygon = false;
00267     cornersValue = 3;
00268     sharpnessValue = 0;
00269     tbAlign = Qt::AlignLeft;
00270     tbFont = font();
00271     tbColor = black;
00272 
00273     mirrorType = PM_NORMAL;
00274     depth = 0;
00275     swapRGB = false;
00276     grayscal = false;
00277     bright = 0;
00278 
00279     m_currentLineTool = LtLine;
00280     m_currentShapeTool = StRectangle;
00281     m_currentClosedLineTool = CltFreehand;
00282 
00283     m_searchEntry = 0L;
00284     m_replaceEntry = 0L;
00285     m_findReplace = 0L;
00286     m_switchPage=-1;
00287 
00288     m_fontDlg=0L;
00289     m_paragDlg=0L;
00290     m_pKPresenterDoc = _doc;
00291 
00292     createGUI();
00293 
00294     setKeyCompression( true );
00295     m_specialCharDlg=0L;
00296 
00297     if ( shell() )
00298         changeNbOfRecentFiles( m_pKPresenterDoc->maxRecentFiles() );
00299 
00300     connect(this, SIGNAL(embeddImage(const QString &)), SLOT(insertPicture(const QString &)));
00301     connect( m_pKPresenterDoc, SIGNAL( sig_refreshMenuCustomVariable()),
00302              this, SLOT( refreshCustomMenu()));
00303 
00304     // Cut and copy are directly connected to the selectionChanged signal
00305     if ( m_pKPresenterDoc->isReadWrite() )
00306         connect( m_canvas, SIGNAL(selectionChanged(bool)),
00307                  this, SLOT(slotChangeCutState(bool )/*setEnabled(bool)*/) );
00308     else
00309         actionEditCut->setEnabled( false );
00310 
00311     connect( m_canvas, SIGNAL(selectionChanged(bool)),
00312              actionEditCopy, SLOT(setEnabled(bool)) );
00313 
00314     connect (m_canvas, SIGNAL(selectionChanged(bool)),
00315              actionChangeCase, SLOT(setEnabled(bool)));
00316     //connect (m_canvas, SIGNAL(selectionChanged(bool)),
00317     //         actionCreateStyleFromSelection, SLOT(setEnabled(bool)));
00318 
00319     connect( m_canvas, SIGNAL( currentObjectEditChanged() ), this,  SLOT( slotObjectEditChanged()));
00320 
00321     connect( h_ruler, SIGNAL( tabListChanged( const KoTabulatorList & ) ), this,
00322              SLOT( tabListChanged( const KoTabulatorList & ) ) );
00323 
00324     //statusbar stuff
00325     connect( m_pKPresenterDoc, SIGNAL( pageNumChanged() ), this, SLOT( pageNumChanged()) );
00326     connect( this, SIGNAL( currentPageChanged(int) ), this, SLOT( pageNumChanged()) );
00327     connect( m_canvas, SIGNAL( objectSizeChanged() ), this, SLOT( updateObjectStatusBarItem() ));
00328     connect( m_canvas, SIGNAL( objectSelectedChanged() ), this, SLOT( updateObjectStatusBarItem() ));
00329     connect (m_pKPresenterDoc, SIGNAL(sig_updateRuler()),this, SLOT( slotUpdateRuler()));
00330     connect (m_pKPresenterDoc, SIGNAL(sig_updateRuler()),this, SLOT( slotUpdateScrollBarRanges()));
00331     connect (m_pKPresenterDoc, SIGNAL(sig_updateMenuBar()),this, SLOT(updateSideBarMenu()));
00332     connect (m_pKPresenterDoc, SIGNAL(unitChanged(KoUnit::Unit)),this, SLOT(slotUnitChanged(KoUnit::Unit)));
00333     connect( m_pKPresenterDoc, SIGNAL( modified( bool ) ), this, SLOT( documentModified( bool )) );
00334     connect( m_pKPresenterDoc, SIGNAL(completed()), this, SLOT(loadingFinished()));
00335 
00336     KStatusBar * sb = statusBar();
00337     m_sbPageLabel = 0L;
00338     m_sbObjectLabel = 0L;
00339     m_sbModifiedLabel = 0;
00340     m_sbZoomLabel = 0;
00341     m_sbUnitLabel = 0;
00342 
00343     if ( sb ) // No statusbar in e.g. konqueror
00344     {
00345         m_sbPageLabel = new KStatusBarLabel( QString::null, 0, sb );
00346         m_sbPageLabel->setAlignment( AlignLeft | AlignVCenter );
00347         addStatusBarItem( m_sbPageLabel, 0 );
00348 
00349         m_sbModifiedLabel = new KStatusBarLabel( "   ", 0, sb );
00350         m_sbModifiedLabel->setAlignment( AlignLeft | AlignVCenter );
00351         addStatusBarItem( m_sbModifiedLabel, 0 );
00352 
00353         m_sbObjectLabel = new KStatusBarLabel( QString::null, 0, sb );
00354         m_sbObjectLabel->setAlignment( AlignLeft | AlignVCenter );
00355         addStatusBarItem( m_sbObjectLabel, 1 );
00356 
00357         m_sbZoomLabel = new KStatusBarLabel( ' ' + QString::number( m_pKPresenterDoc->zoomHandler()->zoom() ) + "% ", 0, sb );
00358         m_sbZoomLabel->setAlignment( AlignHCenter | AlignVCenter );
00359         addStatusBarItem( m_sbZoomLabel, 0 );
00360 
00361         m_sbUnitLabel = new KStatusBarLabel( ' ' + KoUnit::unitDescription( m_pKPresenterDoc->unit() ) + ' ', 0, sb );
00362         m_sbUnitLabel->setAlignment( AlignHCenter | AlignVCenter );
00363         addStatusBarItem( m_sbUnitLabel, 0 );
00364     }
00365 
00366     //when kword is embedded into konqueror apply a zoom=100
00367     //in konqueror we can't change zoom -- ### TODO ?
00368     if(!m_pKPresenterDoc->isReadWrite())
00369     {
00370         setZoom( 100, true );
00371         slotUpdateRuler();
00372         initGui();
00373         m_pKPresenterDoc->updateZoomRuler();
00374     }
00375 
00376 
00377     setAcceptDrops( TRUE );
00378 }
00379 
00380 DCOPObject* KPrView::dcopObject()
00381 {
00382     if ( !dcop )
00383         dcop = new KPrViewIface( this );
00384 
00385     return dcop;
00386 }
00387 
00388 KPrView::~KPrView()
00389 {
00390     delete m_findReplace;
00391     m_findReplace = 0L;
00392     if(sidebar) {
00393         KConfig *config=KGlobal::config();
00394         config->setGroup("Global");
00395         config->writeEntry("Sidebar", sidebar->isVisible());
00396     }
00397     if(notebar) {
00398         KConfig *config=KGlobal::config();
00399         config->setGroup("Global");
00400         config->writeEntry("Notebar", notebar->isVisible());
00401     }
00402     clearSpellChecker();
00403 
00404     delete rb_lbegin;
00405     delete rb_lend;
00406     delete dcop;
00407 
00408     delete m_sbPageLabel;
00409     delete m_sbObjectLabel;
00410     delete notebar;
00411     delete m_searchEntry;
00412     m_searchEntry = 0L;
00413     delete m_replaceEntry;
00414     m_replaceEntry = 0L;
00415     delete m_specialCharDlg;
00416     delete m_propertyEditor;
00417     delete pgConfDia;
00418     delete rotateDia;
00419     delete shadowDia;
00420     delete afChoose;
00421     delete m_fontDlg;
00422     delete m_paragDlg;
00423     delete m_arrangeObjectsPopup;
00424     if ( m_specialCharDlg )
00425         m_specialCharDlg->closeDialog(); // will call slotSpecialCharDlgClosed
00426 }
00427 
00428 void KPrView::setupPrinter( KPrinter &prt )
00429 {
00430     deSelectAllObjects();
00431     m_pKPresenterDoc->recalcVariables( VT_TIME );
00432     m_pKPresenterDoc->recalcVariables( VT_DATE );
00433     prt.setMinMax( 1, m_pKPresenterDoc->getPageNums() );
00434     prt.setFromTo( 1, m_pKPresenterDoc->getPageNums() );
00435     prt.setOption( "kde-range", m_pKPresenterDoc->selectedForPrinting() );
00436     prt.setPageSelection(KPrinter::ApplicationSide);
00437     KoPageLayout layout = m_pKPresenterDoc->pageLayout();
00438     prt.setOption( "kde-margin-top", QString::number(layout.ptTop) );
00439     prt.setOption( "kde-margin-bottom", QString::number(layout.ptBottom) );
00440     prt.setOption( "kde-margin-left", QString::number(layout.ptLeft) );
00441     prt.setOption( "kde-margin-right", QString::number(layout.ptRight) );
00442     KoFormat pageFormat = layout.format;
00443     prt.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pageFormat ) ) );
00444 
00445     if ( m_pKPresenterDoc->pageLayout().orientation == PG_LANDSCAPE || pageFormat == PG_SCREEN )
00446         prt.setOrientation( KPrinter::Landscape );
00447     else
00448         prt.setOrientation( KPrinter::Portrait );
00449     if ( !prt.previewOnly() )
00450       prt.addDialogPage( new KPrPrinterDlg( 0, "KPresenter page" ) );
00451 }
00452 
00453 void KPrView::unZoomDocument(int &dpiX,int &dpiY)
00454 {
00455     // ### HACK: disable zooming-when-printing if embedded parts are used.
00456     // No koffice app supports zooming in paintContent currently.
00457     // Disable in ALL cases now
00458     bool doZoom=false;
00459     dpiX = doZoom ? 300 : KoGlobal::dpiX();
00460     dpiY = doZoom ? 300 : KoGlobal::dpiY();
00461     zoomHandler()->setZoomAndResolution( 100, dpiX, dpiY );
00462     m_pKPresenterDoc->newZoomAndResolution( false, true /* for printing*/ );
00463 }
00464 
00465 void KPrView::zoomDocument(int zoom)
00466 {
00467     zoomHandler()->setZoomAndResolution( zoom, KoGlobal::dpiX(), KoGlobal::dpiY() );
00468     m_pKPresenterDoc->newZoomAndResolution( false, false );
00469     updateRuler();
00470 }
00471 
00472 void KPrView::print( KPrinter &prt )
00473 {
00474     float left_margin = 0.0;
00475     float top_margin = 0.0;
00476     int dpiX=0;
00477     int dpiY=0;
00478     int oldZoom = zoomHandler()->zoom();
00479     bool displayFieldCode = m_pKPresenterDoc->getVariableCollection()->variableSetting()->displayFieldCode();
00480     if ( displayFieldCode )
00481     {
00482         m_pKPresenterDoc->getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
00483         m_pKPresenterDoc->recalcVariables( VT_ALL );
00484     }
00485 
00486     QPaintDeviceMetrics metrics( &prt );
00487     unZoomDocument(dpiX,dpiY);
00488     if ( m_pKPresenterDoc->pageLayout().format == PG_SCREEN )
00489     {
00490         left_margin = 28.5;
00491         top_margin = 15.0;
00492     }
00493 
00494     QPainter painter;
00495     painter.begin( &prt );
00496     QRect rect = m_pKPresenterDoc->pageList().at( 0 )->getZoomPageRect();
00497     double zoom = QMIN( double( metrics.width() ) / double( rect.width() ),
00498                         double( metrics.height() ) / double( rect.height() ) );
00499     double newZoom = zoom * m_pKPresenterDoc->zoomHandler()->zoom();
00500     kdDebug(33001) << "KPrView::print newZoom = " << newZoom << endl;
00501     setZoom( int( newZoom ), false );
00502     QRect paintingRect = m_pKPresenterDoc->pageList().at( 0 )->getZoomPageRect();
00503 
00504     m_canvas->print( &painter, &prt, left_margin, top_margin );
00505     painter.end();
00506 
00507     zoomDocument(oldZoom);
00508     if ( displayFieldCode )
00509     {
00510         m_pKPresenterDoc->getVariableCollection()->variableSetting()->setDisplayFieldCode(true);
00511         m_pKPresenterDoc->recalcVariables( VT_ALL );
00512     }
00513 
00514     m_canvas->repaint();
00515     kdDebug(33001) << "KPrView::print zoom&res reset" << endl;
00516     m_pKPresenterDoc->getVariableCollection()->variableSetting()->setLastPrintingDate(QDateTime::currentDateTime());
00517     m_pKPresenterDoc->recalcVariables( VT_DATE );
00518 }
00519 
00520 void KPrView::editCut()
00521 {
00522     if ( !m_canvas->currentTextObjectView() ) {
00523         m_canvas->setToolEditMode( TEM_MOUSE );
00524 #if COPYOASISFORMAT
00525         m_canvas->copyOasisObjs();
00526 #else
00527         m_canvas->copyObjs();
00528 #endif
00529         m_canvas->deleteObjs();
00530     } else {
00531         if ( !m_canvas->currentTextObjectView()->kpTextObject()->isProtectContent())
00532             m_canvas->currentTextObjectView()->cut();
00533     }
00534 }
00535 
00536 void KPrView::editCopy()
00537 {
00538     if ( !m_canvas->currentTextObjectView() ) {
00539         m_canvas->setToolEditMode( TEM_MOUSE );
00540 #if COPYOASISFORMAT
00541         m_canvas->copyOasisObjs();
00542 #else
00543         m_canvas->copyObjs();
00544 #endif
00545     }
00546     else
00547         m_canvas->currentTextObjectView()->copy();
00548 }
00549 
00550 void KPrView::editPaste()
00551 {
00552     if ( !m_canvas->currentTextObjectView() ) {
00553         m_canvas->setToolEditMode( TEM_MOUSE );
00554         deSelectAllObjects();
00555         QMimeSource *data = QApplication::clipboard()->data();
00556         if ( data->provides( "text/uri-list" ) )
00557         {
00558             m_pKPresenterDoc->pastePage( data, currPg );
00559             setRanges();
00560             skipToPage( currPg );
00561             updateSideBarMenu();
00562         }
00563         else if ( data->provides( KoStoreDrag::mimeType("application/x-kpresenter" ) ))
00564         {
00565             // TODO: it would be nice to have no offset when pasting onto a different page...
00566             m_canvas->activePage()->pasteObjs(
00567                 data->encodedData(KoStoreDrag::mimeType("application/x-kpresenter")),
00568                 1, 0.0, 0.0, 0.0, 20.0, 20.0);
00569 
00570             m_canvas->setMouseSelectedObject(true);
00571             emit objectSelectedChanged();
00572         }
00573 #if COPYOASISFORMAT
00574         else if ( data->provides( KoStoreDrag::mimeType("application/vnd.oasis.opendocument.presentation" ) ))
00575         {
00576             //TODO : fix me !!
00577             // TODO: it would be nice to have no offset when pasting onto a different page...
00578             //m_canvas->activePage()->pasteObjs(
00579             //data->encodedData(KoStoreDrag::mimeType("application/vnd.oasis.opendocument.presentation")),
00580             //1, 0.0, 0.0, 0.0, 20.0, 20.0);
00581 
00582             m_canvas->setMouseSelectedObject(true);
00583             emit objectSelectedChanged();
00584         }
00585 #endif
00586         else if (QImageDrag::canDecode (data)) {
00587             m_canvas->dropImage( data );
00588         }
00589     } else {
00590         if ( !m_canvas->currentTextObjectView()->kpTextObject()->isProtectContent())
00591             m_canvas->currentTextObjectView()->paste();
00592     }
00593 }
00594 
00595 void KPrView::editDelete()
00596 {
00597     m_canvas->setToolEditMode( TEM_MOUSE );
00598     m_canvas->deleteObjs();
00599 }
00600 
00601 void KPrView::editSelectAll()
00602 {
00603     KPrTextView *edit=m_canvas->currentTextObjectView();
00604     if ( !edit ) {
00605         m_canvas->setToolEditMode( TEM_MOUSE );
00606         m_canvas->selectAllObj();
00607     }
00608     else
00609         edit->selectAll();
00610 }
00611 
00612 void KPrView::editDeSelectAll()
00613 {
00614     KPrTextView *edit=m_canvas->currentTextObjectView();
00615     if ( !edit ) {
00616         m_canvas->setToolEditMode( TEM_MOUSE );
00617         deSelectAllObjects();
00618     }
00619     else
00620         edit->selectAll(false);
00621 }
00622 
00623 void KPrView::editCopyPage()
00624 {
00625     m_pKPresenterDoc->copyPageToClipboard( currPg );
00626 }
00627 
00628 void KPrView::editDuplicatePage()
00629 {
00630     m_pKPresenterDoc->copyPage( currPg );
00631     setRanges();
00632 }
00633 
00634 void KPrView::updateSideBarMenu()
00635 {
00636     actionEditDelPage->setEnabled( m_pKPresenterDoc->getPageNums() > 1 );
00637 }
00638 
00639 void KPrView::editDelPage()
00640 {
00641     if ( KMessageBox::warningContinueCancel( this,
00642                                      i18n( "Do you want to remove the current slide?"),i18n("Remove Slide"),KGuiItem(i18n("&Delete"),"editdelete") )
00643          != KMessageBox::Continue )
00644         return;
00645     m_canvas->exitEditMode();
00646     m_pKPresenterDoc->deletePage( currPg );
00647     setRanges();
00648 }
00649 
00650 void KPrView::insertPage()
00651 {
00652     InsertPageDia dia( this, 0, TRUE );
00653 #if COPYOASISFORMAT
00654     QString templ = locateLocal( "data", "kpresenter/default.oop" );
00655 #else
00656     QString templ = locateLocal( "data", "kpresenter/default.kpr" );
00657 #endif
00658     if ( !QFile::exists( templ ) ) {
00659         dia.radioDifferent->setChecked( TRUE );
00660         dia.radioDefault->setEnabled( FALSE );
00661     }
00662     if ( dia.exec() != QDialog::Accepted )
00663         return;
00664 
00665     if (dia.radioCurrentDefault->isChecked())
00666     {
00667 #if COPYOASISFORMAT
00668         QString file = locateLocal( "data", "kpresenter/default.oop" );
00669         m_pKPresenterDoc->savePage( file, currPg, true /*ignore stickies*/ );
00670 #else
00671         QString file = locateLocal( "data", "kpresenter/default.kpr" );
00672         m_pKPresenterDoc->savePage( file, currPg, true /*ignore stickies*/ );
00673 #endif
00674     }
00675 
00676     InsertPos pos = (InsertPos)dia.locationCombo->currentItem();
00677     m_pKPresenterDoc->insertNewPage( i18n("Insert new slide"), currPg, pos,
00678                                      dia.radioDifferent->isChecked(), QString::null );
00679     setRanges();
00680 }
00681 
00682 void KPrView::insertPicture()
00683 {
00684     m_canvas->setToolEditMode( INS_PICTURE );
00685     deSelectAllObjects();
00686 
00687     QStringList mimetypes;
00688     mimetypes += KImageIO::mimeTypes( KImageIO::Reading );
00689     mimetypes += KoPictureFilePreview::clipartMimeTypes();
00690 
00691     KFileDialog fd( m_pKPresenterDoc->picturePath(), QString::null, this, 0, true );
00692     fd.setCaption( i18n( "Insert Picture" ) );
00693     fd.setMimeFilter( mimetypes );
00694     fd.setPreviewWidget( new KoPictureFilePreview( &fd ) );
00695 
00696     KURL url;
00697     if ( fd.exec() == QDialog::Accepted )
00698         url = fd.selectedURL();
00699 
00700     if( url.isEmpty() || !url.isValid() )
00701     {
00702         m_canvas->setToolEditMode( TEM_MOUSE, false );
00703         return;
00704     }
00705     QString file;
00706     if ( !KIO::NetAccess::download( url, file, this ) )
00707     {
00708         m_canvas->setToolEditMode( TEM_MOUSE, false );
00709         return;
00710     }
00711 
00712     if ( !file.isEmpty() )
00713         m_canvas->activePage()->setInsPictureFile( file );
00714 }
00715 
00716 void KPrView::insertPicture(const QString &file)
00717 {
00718     m_canvas->setToolEditMode( INS_PICTURE );
00719     deSelectAllObjects();
00720 
00721     if ( !file.isEmpty() )
00722         m_canvas->activePage()->setInsPictureFile( file );
00723 }
00724 
00725 void KPrView::savePicture()
00726 {
00727     m_canvas->savePicture();
00728 }
00729 
00730 void KPrView::savePicture( const QString& oldName, KoPicture& picture)
00731 {
00732     QString oldFile(oldName);
00733     KURL url;
00734     url.setPath( oldFile );
00735     if (!QDir(url.directory()).exists())
00736         oldFile = url.fileName();
00737 
00738     QString mimetype=picture.getMimeType();
00739     kdDebug(33001) << "Picture has mime type: " << mimetype << endl;
00740     QStringList mimetypes;
00741     mimetypes << mimetype;
00742 
00743     KFileDialog fd( oldFile, QString::null, this, 0, TRUE );
00744     fd.setMimeFilter( mimetypes );
00745     fd.setCaption(i18n("Save Picture"));
00746     fd.setOperationMode(KFileDialog::Saving);
00747     if ( fd.exec() == QDialog::Accepted )
00748     {
00749         url = fd.selectedURL();
00750         if ( url.isValid() )
00751             {
00752                 if ( url.isLocalFile() )
00753                 {
00754                     QFile file( url.path() );
00755                     if ( file.open( IO_ReadWrite ) )
00756                     {
00757                         picture.save( &file );
00758                         file.close();
00759                     }
00760                     else
00761                     {
00762                         KMessageBox::error(this,
00763                                    i18n("Error during saving: could not open '%1' for writing.").arg ( url.path() ),
00764                                    i18n("Save Picture"));
00765                     }
00766                 }
00767                 else
00768                 {
00769                     KTempFile tempFile;
00770                     tempFile.setAutoDelete( true );
00771                     if ( tempFile.status() == 0 )
00772                     {
00773                         QFile file( tempFile.name() );
00774                         if ( file.open( IO_ReadWrite ) )
00775                         {
00776                             picture.save( &file );
00777                             file.close();
00778                             if ( !KIO::NetAccess::upload( tempFile.name(), url, this ) )
00779                             {
00780                                 KMessageBox::sorry( this, i18n(
00781                                    "Unable to save the file to '%1'. %2.").arg( url.prettyURL() ).arg( KIO::NetAccess::lastErrorString() ),
00782                                    i18n("Save Failed") );
00783                             }
00784                         }
00785                         else
00786                             KMessageBox::error(this,
00787                                    i18n("Error during saving: could not open '%1' temporary file for writing.").arg ( file.name() ),
00788                                    i18n("Save Picture"));
00789                     }
00790                     else
00791                         KMessageBox::sorry( this, i18n(
00792                             "Error during saving: could not create temporary file: %1.").arg( strerror( tempFile.status() ) ),
00793                             i18n("Save Picture") );
00794                 }
00795             }
00796     }
00797 }
00798 
00799 void KPrView::savePicture( KPrPixmapObject* obj )
00800 {
00801     QString oldFile=obj->getFileName();
00802     KoPicture picture(obj->picture());
00803     savePicture(oldFile, picture);
00804 }
00805 
00806 void KPrView::toolsMouse()
00807 {
00808     if ( actionToolsMouse->isChecked() )
00809         m_canvas->setToolEditMode( TEM_MOUSE, false );
00810     else
00811         actionToolsMouse->setChecked(true);
00812     //deSelectAllObjects();
00813 }
00814 
00815 void KPrView::toolsRotate()
00816 {
00817     if ( actionToolsRotate->isChecked() )
00818         m_canvas->setToolEditMode( TEM_ROTATE, false );
00819     else
00820         actionToolsRotate->setChecked(true);
00821 }
00822 
00823 void KPrView::toolsZoom()
00824 {
00825     if ( actionToolsZoom->isChecked() )
00826         m_canvas->setToolEditMode( TEM_ZOOM, false );
00827     else
00828         actionToolsZoom->setChecked(true);
00829 }
00830 
00831 void KPrView::toolsLinePopup()
00832 {
00833     switch (m_currentLineTool)
00834     {
00835     case LtLine:
00836         actionToolsLine->activate();
00837         break;
00838     case LtFreehand:
00839         actionToolsFreehand->activate();
00840         break;
00841     case LtPolyline:
00842         actionToolsPolyline->activate();
00843         break;
00844     case LtQuadricBezier:
00845         actionToolsQuadricBezierCurve->activate();
00846         break;
00847     case LtCubicBezier:
00848         actionToolsCubicBezierCurve->activate();
00849         break;
00850     }
00851 }
00852 
00853 void KPrView::toolsLine()
00854 {
00855     if ( actionToolsLine->isChecked() )
00856     {
00857         m_canvas->setToolEditMode( INS_LINE, false );
00858         deSelectAllObjects();
00859         m_currentLineTool = LtLine;
00860         actionToolsLinePopup->setIcon("line");
00861     }
00862     else
00863         actionToolsLine->setChecked(true);
00864 }
00865 
00866 void KPrView::toolsShapePopup()
00867 {
00868     switch (m_currentShapeTool)
00869     {
00870     case StRectangle:
00871         actionToolsRectangle->activate();
00872         break;
00873     case StCircle:
00874         actionToolsCircleOrEllipse->activate();
00875         break;
00876     case StPie:
00877         actionToolsPie->activate();
00878         break;
00879     case StPolygon:
00880         actionToolsConvexOrConcavePolygon->activate();
00881         break;
00882     }
00883 }
00884 
00885 void KPrView::toolsRectangle()
00886 {
00887     if ( actionToolsRectangle->isChecked() )
00888     {
00889         deSelectAllObjects();
00890         m_canvas->setToolEditMode( INS_RECT, false );
00891         m_currentShapeTool = StRectangle;
00892         actionToolsShapePopup->setIcon("rectangle");
00893     }
00894     else
00895         actionToolsRectangle->setChecked(true);
00896 }
00897 
00898 void KPrView::toolsCircleOrEllipse()
00899 {
00900     if ( actionToolsCircleOrEllipse->isChecked() )
00901     {
00902         deSelectAllObjects();
00903         m_canvas->setToolEditMode( INS_ELLIPSE, false );
00904         m_currentShapeTool = StCircle;
00905         actionToolsShapePopup->setIcon("circle");
00906     }
00907     else
00908         actionToolsCircleOrEllipse->setChecked(true);
00909 }
00910 
00911 void KPrView::toolsPie()
00912 {
00913     if ( actionToolsPie->isChecked() )
00914     {
00915         deSelectAllObjects();
00916         m_canvas->setToolEditMode( INS_PIE, false );
00917         m_currentShapeTool = StPie;
00918         actionToolsShapePopup->setIcon("pie");
00919     }
00920     else
00921         actionToolsPie->setChecked(true);
00922 }
00923 
00924 void KPrView::toolsDiagramm()
00925 {
00926     if ( actionToolsDiagramm->isChecked() )
00927     {
00928         deSelectAllObjects();
00929         m_canvas->setToolEditMode( INS_DIAGRAMM, false );
00930 
00931         KoDocumentEntry entry = KoDocumentEntry::queryByMimeType( "application/x-kchart" );
00932         if (entry.isEmpty())
00933         {
00934             KMessageBox::sorry( this, i18n( "No chart component registered" ) );
00935             m_canvas->setToolEditMode( TEM_MOUSE );
00936         }
00937         else
00938             m_canvas->setPartEntry( entry );
00939     }
00940     else
00941         actionToolsDiagramm->setChecked(true);
00942 }
00943 
00944 void KPrView::toolsTable()
00945 {
00946     if ( actionToolsTable->isChecked() )
00947     {
00948         deSelectAllObjects();
00949         m_canvas->setToolEditMode( INS_TABLE, false );
00950 
00951         KoDocumentEntry entry = KoDocumentEntry::queryByMimeType( "application/x-kspread" );
00952         if (entry.isEmpty())
00953         {
00954             KMessageBox::sorry( this, i18n( "No table component registered" ) );
00955             m_canvas->setToolEditMode( TEM_MOUSE );
00956         }
00957         else
00958             m_canvas->setPartEntry( entry );
00959     }
00960     else
00961         actionToolsTable->setChecked(true);
00962 }
00963 
00964 void KPrView::toolsFormula()
00965 {
00966     if ( actionToolsFormula->isChecked() )
00967     {
00968         deSelectAllObjects();
00969         m_canvas->setToolEditMode( INS_FORMULA, false );
00970 
00971         KoDocumentEntry entry = KoDocumentEntry::queryByMimeType( "application/x-kformula" );
00972         if (entry.isEmpty())
00973         {
00974             KMessageBox::sorry( this, i18n( "No formula component registered" ) );
00975             m_canvas->setToolEditMode( TEM_MOUSE );
00976         }
00977         else
00978             m_canvas->setPartEntry( entry );
00979     }
00980     else
00981         actionToolsFormula->setChecked(true);
00982 }
00983 
00984 void KPrView::toolsText()
00985 {
00986     if ( actionToolsText->isChecked() )
00987     {
00988         deSelectAllObjects();
00989         m_canvas->setToolEditMode( INS_TEXT, false );
00990     }
00991     else
00992         actionToolsText->setChecked(true);
00993 }
00994 
00995 void KPrView::toolsAutoform()
00996 {
00997     if ( actionToolsAutoform->isChecked() )
00998     {
00999         deSelectAllObjects();
01000         m_canvas->setToolEditMode( TEM_MOUSE, false );
01001         if ( afChoose ) {
01002             delete afChoose;
01003             afChoose = 0;
01004         }
01005         afChoose = new AFChoose( this, i18n( "Autoform-Choose" ) );
01006         afChoose->resize( 400, 300 );
01007         afChoose->setCaption( i18n( "Insert Autoform" ) );
01008 
01009         QObject::connect( afChoose, SIGNAL( formChosen( const QString & ) ),
01010                           this, SLOT( afChooseOk( const QString & ) ) );
01011         QObject::connect( afChoose, SIGNAL( afchooseCanceled()),
01012                           this,SLOT(slotAfchooseCanceled()));
01013         afChoose->exec();
01014 
01015         QObject::disconnect( afChoose, SIGNAL( formChosen( const QString & ) ),
01016                              this, SLOT( afChooseOk( const QString & ) ) );
01017         delete afChoose;
01018         afChoose = 0;
01019     }
01020     else
01021         actionToolsAutoform->setChecked(true);
01022 }
01023 
01024 void KPrView::toolsObject()
01025 {
01026     KoDocumentEntry pe = actionToolsObject->documentEntry();
01027     if ( pe.isEmpty() ) {
01028         m_canvas->setToolEditMode( TEM_MOUSE );
01029         return;
01030     }
01031 
01032     m_canvas->setToolEditMode( INS_OBJECT );
01033     m_canvas->setPartEntry( pe );
01034 }
01035 
01036 void KPrView::toolsFreehand()
01037 {
01038     if ( actionToolsFreehand->isChecked() ) {
01039         m_canvas->setToolEditMode( INS_FREEHAND, false );
01040         deSelectAllObjects();
01041         m_currentLineTool = LtFreehand;
01042         actionToolsLinePopup->setIcon("freehand");
01043     }
01044     else
01045         actionToolsFreehand->setChecked(true);
01046 }
01047 
01048 void KPrView::toolsPolyline()
01049 {
01050     if ( actionToolsPolyline->isChecked() ) {
01051         m_canvas->setToolEditMode( INS_POLYLINE, false );
01052         deSelectAllObjects();
01053         m_currentLineTool = LtPolyline;
01054         actionToolsLinePopup->setIcon("polyline");
01055     }
01056     else
01057         actionToolsPolyline->setChecked(true);
01058 }
01059 
01060 void KPrView::toolsQuadricBezierCurve()
01061 {
01062     if ( actionToolsQuadricBezierCurve->isChecked() ) {
01063         m_canvas->setToolEditMode( INS_QUADRICBEZIERCURVE, false );
01064         deSelectAllObjects();
01065         m_currentLineTool = LtQuadricBezier;
01066         actionToolsLinePopup->setIcon("quadricbeziercurve");
01067     }
01068     else
01069         actionToolsQuadricBezierCurve->setChecked(true);
01070 }
01071 
01072 void KPrView::toolsCubicBezierCurve()
01073 {
01074     if ( actionToolsCubicBezierCurve->isChecked() ) {
01075         m_canvas->setToolEditMode( INS_CUBICBEZIERCURVE, false );
01076         deSelectAllObjects();
01077         m_currentLineTool = LtCubicBezier;
01078         actionToolsLinePopup->setIcon("cubicbeziercurve");
01079     }
01080     else
01081         actionToolsCubicBezierCurve->setChecked(true);
01082 }
01083 
01084 void KPrView::toolsConvexOrConcavePolygon()
01085 {
01086     if ( actionToolsConvexOrConcavePolygon->isChecked() ) {
01087         m_canvas->setToolEditMode( INS_POLYGON, false );
01088         deSelectAllObjects();
01089         m_currentShapeTool = StPolygon;
01090         actionToolsShapePopup->setIcon("polygon");
01091     }
01092     else
01093         actionToolsConvexOrConcavePolygon->setChecked(true);
01094 }
01095 
01096 void KPrView::toolsClosedLinePopup()
01097 {
01098     switch (m_currentClosedLineTool)
01099     {
01100     case CltFreehand:
01101         actionToolsClosedFreehand->activate();
01102         break;
01103     case CltPolyline:
01104         actionToolsClosedPolyline->activate();
01105         break;
01106     case CltQuadricBezier:
01107         actionToolsClosedQuadricBezierCurve->activate();
01108         break;
01109     case CltCubicBezier:
01110         actionToolsClosedCubicBezierCurve->activate();
01111         break;
01112     }
01113 }
01114 
01115 void KPrView::toolsClosedFreehand()
01116 {
01117     if ( actionToolsClosedFreehand->isChecked() ) {
01118         m_canvas->setToolEditMode( INS_CLOSED_FREEHAND, false );
01119         deSelectAllObjects();
01120         m_currentClosedLineTool = CltFreehand;
01121         actionToolsClosedLinePopup->setIcon("closed_freehand");
01122     }
01123     else
01124         actionToolsClosedFreehand->setChecked( true );
01125 }
01126 
01127 void KPrView::toolsClosedPolyline()
01128 {
01129     if ( actionToolsClosedPolyline->isChecked() ) {
01130         m_canvas->setToolEditMode( INS_CLOSED_POLYLINE, false );
01131         deSelectAllObjects();
01132         m_currentClosedLineTool = CltPolyline;
01133         actionToolsClosedLinePopup->setIcon("closed_polyline");
01134     }
01135     else
01136         actionToolsClosedPolyline->setChecked( true );
01137 }
01138 
01139 void KPrView::toolsClosedQuadricBezierCurve()
01140 {
01141     if ( actionToolsClosedQuadricBezierCurve->isChecked() ) {
01142         m_canvas->setToolEditMode( INS_CLOSED_QUADRICBEZIERCURVE, false );
01143         deSelectAllObjects();
01144         m_currentClosedLineTool = CltQuadricBezier;
01145         actionToolsClosedLinePopup->setIcon("closed_quadricbeziercurve");
01146     }
01147     else
01148         actionToolsClosedQuadricBezierCurve->setChecked( true );
01149 }
01150 
01151 void KPrView::toolsClosedCubicBezierCurve()
01152 {
01153     if ( actionToolsClosedCubicBezierCurve->isChecked() ) {
01154         m_canvas->setToolEditMode( INS_CLOSED_CUBICBEZIERCURVE, false );
01155         deSelectAllObjects();
01156         m_currentClosedLineTool = CltCubicBezier;
01157         actionToolsClosedLinePopup->setIcon("closed_cubicbeziercurve");
01158     }
01159     else
01160         actionToolsClosedCubicBezierCurve->setChecked( true );
01161 }
01162 
01163 void KPrView::extraProperties()
01164 {
01165     m_canvas->setToolEditMode( TEM_MOUSE );
01166 
01167     m_propertyEditor = new KPrPropertyEditor( this, "KPrPropertyEditor", m_canvas->activePage(), m_pKPresenterDoc );
01168     m_propertyEditor->setCaption( i18n( "Properties" ) );
01169 
01170     connect( m_propertyEditor, SIGNAL( propertiesOk() ), this, SLOT( propertiesOk() ) );
01171     m_propertyEditor->exec();
01172     disconnect( m_propertyEditor, SIGNAL( propertiesOk() ), this, SLOT( propertiesOk() ) );
01173 
01174     delete m_propertyEditor;
01175     m_propertyEditor = 0;
01176 }
01177 
01178 void KPrView::extraRaise()
01179 {
01180     m_canvas->setToolEditMode( TEM_MOUSE );
01181     m_canvas->raiseObjs( true );
01182 }
01183 
01184 void KPrView::extraLower()
01185 {
01186     m_canvas->setToolEditMode( TEM_MOUSE );
01187     m_canvas->lowerObjs( true );
01188 }
01189 
01190 void KPrView::extraRotate()
01191 {
01192     if ( m_canvas->numberOfObjectSelected() > 0 ) {
01193         if ( !rotateDia ) {
01194             rotateDia = new KPrRotationDialogImpl( this );
01195             connect( rotateDia, SIGNAL( apply() ), this, SLOT( rotateOk() ) );
01196         }
01197         rotateDia->setAngle( m_canvas->getSelectedObj()->getAngle() );
01198         m_canvas->setToolEditMode( TEM_MOUSE );
01199         rotateDia->exec();
01200     }
01201 }
01202 
01203 void KPrView::extraShadow()
01204 {
01205     if ( m_canvas->numberOfObjectSelected() > 0 ) {
01206 
01207         if ( !shadowDia ) {
01208             shadowDia = new KPrShadowDialogImpl( this );
01209             shadowDia->resize( shadowDia->minimumSize() );
01210             connect( shadowDia, SIGNAL( apply() ), this, SLOT( shadowOk() ) );
01211         }
01212 
01213         KPrObject *object=m_canvas->getSelectedObj();
01214         shadowDia->setShadowDirection( object->getShadowDirection() );
01215         if ( object->getShadowDistance() != 0 )
01216             shadowDia->setShadowDistance( object->getShadowDistance() );
01217         else
01218             shadowDia->setShadowDistance( 3 );
01219 
01220         shadowDia->setShadowColor( object->getShadowColor() );
01221         m_canvas->setToolEditMode( TEM_MOUSE );
01222         shadowDia->exec();
01223     }
01224 }
01225 
01226 void KPrView::extraBackground()
01227 {
01228     KPrPage *page=m_canvas->activePage();
01229     KPrBackDialog* backDia = new KPrBackDialog( this, "InfoDia", page->getBackType(  ),
01230                                     page->getBackColor1(  ),
01231                                     page->getBackColor2(  ),
01232                                     page->getBackColorType(  ),
01233                                     page->getBackPicture(  ),
01234                                     page->getBackView(),
01235                                     page->getBackUnbalanced(),
01236                                     page->getBackXFactor(),
01237                                     page->getBackYFactor( ),
01238                                     page );
01239     backDia->setCaption( i18n( "Slide Background" ) );
01240     QObject::connect( backDia, SIGNAL( backOk( KPrBackDialog*, bool ) ), this, SLOT( backOk( KPrBackDialog*, bool ) ) ) ;
01241     backDia->exec();
01242 
01243     QObject::disconnect( backDia, SIGNAL( backOk( KPrBackDialog*, bool ) ), this, SLOT( backOk( KPrBackDialog*, bool ) ) );
01244     delete backDia;
01245 }
01246 
01247 void KPrView::extraLayout()
01248 {
01249     KoPageLayout pgLayout = m_pKPresenterDoc->pageLayout();
01250     KoPageLayout oldLayout = pgLayout;
01251     KoHeadFoot hf;
01252     KoUnit::Unit oldUnit = m_pKPresenterDoc->unit();
01253     KoUnit::Unit unit = oldUnit;
01254 
01255     if ( KoPageLayoutDia::pageLayout( pgLayout, hf, FORMAT_AND_BORDERS, unit, this ) ) {
01256         KPrPgLayoutCmd *pgLayoutCmd = new KPrPgLayoutCmd( i18n( "Set Page Layout" ),
01257                                                     pgLayout, oldLayout, oldUnit, unit,kPresenterDoc() );
01258         pgLayoutCmd->execute();
01259         kPresenterDoc()->addCommand( pgLayoutCmd );
01260         updateRuler();
01261     }
01262 }
01263 
01264 void KPrView::extraConfigure()
01265 {
01266     KPrConfig configDia( this );
01267     configDia.exec();
01268 }
01269 
01270 void KPrView::extraCreateTemplate()
01271 {
01272     int width = 60;
01273     int height = 60;
01274     QPixmap pix = m_pKPresenterDoc->generatePreview(QSize(width, height));
01275 #if COPYOASISFORMAT
01276     KTempFile tempFile( QString::null, ".otp" );
01277     tempFile.setAutoDelete( true );
01278     m_pKPresenterDoc->savePage( tempFile.name(), getCurrPgNum() - 1);
01279 #else
01280     KTempFile tempFile( QString::null, ".kpt" );
01281     tempFile.setAutoDelete( true );
01282     m_pKPresenterDoc->savePage( tempFile.name(), getCurrPgNum() - 1);
01283 #endif
01284 
01285     KoTemplateCreateDia::createTemplate( "kpresenter_template", KPrFactory::global(),
01286                                          tempFile.name(), pix, this);
01287     KPrFactory::global()->dirs()->addResourceType("kpresenter_template",
01288                                                          KStandardDirs::kde_default( "data" ) +
01289                                                          "kpresenter/templates/");
01290 }
01291 
01292 void KPrView::extraDefaultTemplate()
01293 {
01294 #if COPYOASISFORMAT
01295     QString file = locateLocal( "data", "kpresenter/default.oop" );
01296     m_pKPresenterDoc->savePage( file, currPg );
01297 #else
01298     QString file = locateLocal( "data", "kpresenter/default.kpr" );
01299     m_pKPresenterDoc->savePage( file, currPg );
01300 #endif
01301 }
01302 
01303 void KPrView::extraWebPres()
01304 {
01305     if ( !allowWebPres )
01306         return;
01307 
01308     KURL url;
01309     QString config = QString::null;
01310     int ret =KMessageBox::questionYesNoCancel( this,
01311                                                i18n( "Do you want to load a previously saved configuration"
01312                                                      " which will be used for this HTML Presentation?" ),
01313                                                i18n( "Create HTML Presentation" ) );
01314     if( ret == KMessageBox::Cancel )
01315         return;
01316     else if ( ret == KMessageBox::Yes )
01317     {
01318         url = KFileDialog::getOpenURL( QString::null, i18n("*.kpweb|KPresenter HTML Presentation (*.kpweb)"), this );
01319 
01320         if( url.isEmpty() )
01321             return;
01322 
01323         if( !url.isLocalFile() )
01324         {
01325             KMessageBox::sorry( this, i18n( "Only local files are currently supported." ) );
01326             return;
01327         }
01328 
01329         config = url.path();
01330     }
01331 
01332     KPrWebPresentationWizard::createWebPresentation( config, m_pKPresenterDoc, this );
01333 }
01334 
01335 void KPrView::extraMSPres()
01336 {
01337     if ( !allowMSPres )
01338         return;
01339 
01340     KPrMSPresentationSetup::createMSPresentation( m_pKPresenterDoc, this );
01341 }
01342 
01343 void KPrView::extraLineBegin()
01344 {
01345     m_canvas->setToolEditMode( TEM_MOUSE );
01346     QPoint pnt( QCursor::pos() );
01347     rb_lbegin->popup( pnt );
01348 }
01349 
01350 void KPrView::extraLineEnd()
01351 {
01352     m_canvas->setToolEditMode( TEM_MOUSE );
01353     QPoint pnt( QCursor::pos() );
01354     rb_lend->popup( pnt );
01355 }
01356 
01357 void KPrView::extraGroup()
01358 {
01359     m_canvas->setToolEditMode( TEM_MOUSE );
01360     m_canvas->groupObjects();
01361     objectSelectedChanged();
01362 }
01363 
01364 void KPrView::extraUnGroup()
01365 {
01366     m_canvas->setToolEditMode( TEM_MOUSE );
01367     m_canvas->ungroupObjects();
01368     objectSelectedChanged();
01369 }
01370 
01371 void KPrView::extraPenStyle( int newStyle )
01372 {
01373     m_canvas->setToolEditMode( TEM_MOUSE );
01374     setExtraPenStyle(static_cast<Qt::PenStyle>(newStyle));
01375 }
01376 
01377 void KPrView::extraPenWidth( double newWidth )
01378 {
01379     m_canvas->setToolEditMode( TEM_MOUSE );
01380     setExtraPenWidth( newWidth );
01381 }
01382 
01383 void KPrView::screenConfigPages()
01384 {
01385     delete pgConfDia;
01386     pgConfDia = new KPrPgConfDia( this, kPresenterDoc() );
01387     pgConfDia->setCaption( i18n( "Configure Slide Show" ) );
01388     QObject::connect( pgConfDia, SIGNAL( pgConfDiaOk() ), this, SLOT( pgConfOk() ) );
01389     pgConfDia->exec();
01390 
01391     QObject::disconnect( pgConfDia, SIGNAL( pgConfDiaOk() ), this, SLOT( pgConfOk() ) );
01392     delete pgConfDia;
01393     pgConfDia = 0;
01394 }
01395 
01396 
01397 void KPrView::screenTransEffect()
01398 {
01399     KPrSlideTransitionDia transitionDia( this, "slideTransitionDialog", this );
01400     transitionDia.exec();
01401 }
01402 
01403 void KPrView::screenAssignEffect()
01404 {
01405     m_canvas->setToolEditMode( TEM_MOUSE );
01406 
01407     QPtrList<KPrObject> objs;
01408     if ( m_canvas->canAssignEffect( objs ) ) {
01409         KPrEffectDia *effectDia = new KPrEffectDia( this, "Object Effect", objs, this );
01410         effectDia->setCaption( i18n( "Object Effect" ) );
01411         effectDia->exec(); //the dialog executes the command itself
01412         delete effectDia;
01413     }
01414 }
01415 
01416 void KPrView::screenStart()
01417 {
01418     startScreenPres( getCurrPgNum() );
01419 }
01420 
01421 void KPrView::screenStartFromFirst()
01422 {
01423     startScreenPres( 1 );
01424 }
01425 
01426 void KPrView::startScreenPres( int pgNum /*1-based*/ )
01427 {
01428     // no slide is selected ?
01429     if( !kPresenterDoc()->displaySelectedSlides().count() )
01430     {
01431         KMessageBox::sorry( this, i18n("You didn't select any slide." ),
01432                             i18n("No Slide") );
01433         return;
01434     }
01435 
01436     m_canvas->setToolEditMode( TEM_MOUSE );
01437 
01438     if ( m_canvas && !presStarted ) {
01439         QByteArray data;
01440         QByteArray replyData;
01441         QCString replyType;
01442         m_screenSaverWasEnabled = false;
01443         // is screensaver enabled?
01444         if (kapp->dcopClient()->call("kdesktop", "KScreensaverIface", "isEnabled()", data, replyType, replyData)
01445             && replyType=="bool")
01446         {
01447             QDataStream replyArg(replyData, IO_ReadOnly);
01448             replyArg >> m_screenSaverWasEnabled;
01449             if ( m_screenSaverWasEnabled )
01450             {
01451                 // disable screensaver
01452                 QDataStream arg(data, IO_WriteOnly);
01453                 arg << false;
01454                 if (!kapp->dcopClient()->send("kdesktop", "KScreensaverIface", "enable(bool)", data))
01455                     kdWarning(33001) << "Couldn't disable screensaver (using dcop to kdesktop)!" << endl;
01456                 else
01457                     kdDebug(33001) << "Screensaver successfully disabled" << endl;
01458             }
01459         }
01460 
01461         deSelectAllObjects();
01462         presStarted = true;
01463         m_autoPresRestart = false;
01464         QRect desk = KGlobalSettings::desktopGeometry(this);
01465         kdDebug(33001) << "KPrView::startScreenPres desk=" << desk << endl;
01466         QRect pgRect = kPresenterDoc()->pageList().at(0)->getZoomPageRect();
01467         kdDebug(33001) << "KPrView::startScreenPres pgRect=" << pgRect << endl;
01468 
01469         double zoomX = static_cast<double>( desk.width() ) / (double)pgRect.width();
01470         double zoomY = static_cast<double>( desk.height() ) / (double)pgRect.height();
01471         kdDebug(33001) << "KPrView::startScreenPres zoomX=" << zoomX << " zoomY=" << zoomY << endl;
01472 
01473         xOffsetSaved = canvasXOffset();
01474         yOffsetSaved = canvasYOffset();
01475         setCanvasXOffset( 0 );
01476         setCanvasYOffset( 0 );
01477 
01478         m_bDisplayFieldCode = m_pKPresenterDoc->getVariableCollection()->variableSetting()->displayFieldCode();
01479         if ( m_bDisplayFieldCode )
01480         {
01481             m_pKPresenterDoc->getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
01482             m_pKPresenterDoc->recalcVariables( VT_ALL );
01483         }
01484 
01485         vert->setEnabled( false );
01486         horz->setEnabled( false );
01487         m_bShowGUI = false;
01488         m_canvas->reparent( ( QWidget* )0L, 0, QPoint( 0, 0 ), FALSE );
01489         m_canvas->setPaletteBackgroundColor( Qt::white );
01490         m_canvas->showFullScreen();
01491         m_canvas->setFocusPolicy( QWidget::StrongFocus );
01492 
01493         if ( !kPresenterDoc()->spManualSwitch() )
01494         {
01495              m_autoPresStop = false;
01496              m_pKPresenterDoc->repaint( false );
01497 
01498              if ( ! m_autoPresTimerConnected ) {
01499                  connect( &m_autoPresTimer, SIGNAL( timeout() ), SLOT( doAutomaticScreenPres() ) );
01500                  m_autoPresTimerConnected = true;
01501              }
01502         }
01503 
01504         m_canvas->startScreenPresentation( zoomX, zoomY, pgNum );
01505 
01506         actionScreenStart->setEnabled( false );
01507 
01508         if ( kPresenterDoc()->presentationDuration() ) {
01509             m_duration.start();
01510 
01511             // ### make m_presentationDurationList a QMemArray or QValueVector
01512             for ( unsigned int i = 0; i < kPresenterDoc()->pageList().count(); ++i )
01513                 m_presentationDurationList.append( 0 ); // initialization
01514         }
01515     }
01516 }
01517 
01518 void KPrView::screenStop()
01519 {
01520     if ( presStarted ) {
01521         m_autoPresStop = true;
01522         m_canvas->stopSound();
01523         m_canvas->showNormal();
01524         m_canvas->hide();
01525         m_canvas->reparent( pageBase, 0, QPoint( 0, 0 ), true );
01526         m_canvas->lower();
01527         setCanvasXOffset( xOffsetSaved );
01528         setCanvasYOffset( yOffsetSaved );
01529 
01530         if ( m_bDisplayFieldCode )
01531         {
01532             m_pKPresenterDoc->getVariableCollection()->variableSetting()->setDisplayFieldCode(true);
01533             m_pKPresenterDoc->recalcVariables( VT_ALL );
01534         }
01535 
01536         m_canvas->stopScreenPresentation();
01537         presStarted = false;
01538         vert->setEnabled( true );
01539         horz->setEnabled( true );
01540         m_bShowGUI = true;
01541         m_canvas->setMouseTracking( true );
01542         m_canvas->setBackgroundMode( Qt::NoBackground );
01543 
01544         if ( m_screenSaverWasEnabled )
01545         {
01546             // start screensaver again
01547             QByteArray data;
01548             QDataStream arg(data, IO_WriteOnly);
01549             arg << true;
01550             if (!kapp->dcopClient()->send("kdesktop", "KScreensaverIface", "enable(bool)", data))
01551                 kdWarning(33001) << "Couldn't re-enabled screensaver (using dcop to kdesktop)" << endl;
01552         }
01553 
01554         actionScreenStart->setEnabled( true );
01555         pageBase->resizeEvent( 0 );
01556 
01557         if ( kPresenterDoc()->presentationDuration() && !m_presentationDurationList.isEmpty() ) {
01558             openThePresentationDurationDialog();
01559             m_presentationDurationList.clear();
01560         }
01561     }
01562     emit presentationFinished();
01563 }
01564 
01565 void KPrView::screenPause()
01566 {
01567 }
01568 
01569 void KPrView::screenFirst()
01570 {
01571     m_canvas->deSelectAllObj();
01572 
01573     if ( !presStarted )
01574         skipToPage( 0 );
01575     else
01576         gotoPresPage( 1 );
01577 }
01578 
01579 void KPrView::screenPrev( bool gotoPreviousPage )
01580 {
01581     if ( m_canvas->currentTextObjectView() )
01582         return;
01583 
01584     if ( presStarted ) {
01585         m_canvas->pPrev( gotoPreviousPage );
01586         m_canvas->setFocus();
01587     }
01588     else
01589         prevPage();
01590 }
01591 
01592 void KPrView::screenNext( bool gotoNextPage )
01593 {
01594     if ( m_canvas->currentTextObjectView() )
01595         return;
01596     if ( presStarted )
01597     {
01598         m_canvas->pNext( gotoNextPage );
01599         m_canvas->setFocus();
01600     }
01601     else
01602     {
01603         nextPage();
01604     }
01605 }
01606 
01607 void KPrView::screenLast()
01608 {
01609     m_canvas->deSelectAllObj();
01610 
01611     if ( !presStarted )
01612         skipToPage( m_pKPresenterDoc->getPageNums() - 1 );
01613     else
01614         gotoPresPage( getNumPresPages() );
01615 }
01616 
01617 void KPrView::screenSkip()
01618 {
01619 }
01620 
01621 void KPrView::sizeSelected( int size )
01622 {
01623     tbFont.setPointSize( size );
01624     m_canvas->setTextPointSize( size );
01625     m_canvas->setFocus();
01626 }
01627 
01628 void KPrView::fontSelected( const QString &fontFamily )
01629 {
01630     tbFont.setFamily( fontFamily );
01631     m_canvas->setTextFamily( fontFamily );
01632     m_canvas->setFocus();
01633 }
01634 
01635 void KPrView::textBold()
01636 {
01637     bool b=actionTextBold->isChecked();
01638     tbFont.setBold( b );
01639     m_canvas->setTextBold(b );
01640 }
01641 
01642 
01643 void KPrView::textStrikeOut()
01644 {
01645     bool b=actionFormatStrikeOut->isChecked();
01646     tbFont.setStrikeOut( b );
01647     m_canvas->setTextStrikeOut( b );
01648 }
01649 
01650 void KPrView::textItalic()
01651 {
01652     bool b=actionTextItalic->isChecked();
01653     tbFont.setItalic( b );
01654     m_canvas->setTextItalic( b );
01655 }
01656 
01657 void KPrView::textUnderline()
01658 {
01659     bool b=actionTextUnderline->isChecked();
01660     tbFont.setUnderline( b );
01661     m_canvas->setTextUnderline( b );
01662 }
01663 
01664 void KPrView::textColor()
01665 {
01666     tbColor = actionTextColor->color();
01667     m_canvas->setTextColor( tbColor );
01668 }
01669 
01670 void KPrView::textAlignLeft()
01671 {
01672     if ( actionTextAlignLeft->isChecked() )
01673     {
01674         tbAlign = Qt::AlignLeft;
01675         m_canvas->setTextAlign( tbAlign );
01676     }
01677     else
01678         actionTextAlignLeft->setChecked(true);
01679 }
01680 
01681 void KPrView::textAlignCenter()
01682 {
01683     if ( actionTextAlignCenter->isChecked() )
01684     {
01685         tbAlign = Qt::AlignHCenter;
01686         m_canvas->setTextAlign(tbAlign);
01687     }
01688     else
01689         actionTextAlignCenter->setChecked(true);
01690 }
01691 
01692 void KPrView::textAlignRight()
01693 {
01694     if ( actionTextAlignRight->isChecked() )
01695     {
01696         tbAlign = Qt::AlignRight;
01697         m_canvas->setTextAlign(tbAlign);
01698     }
01699     else
01700         actionTextAlignRight->setChecked(true);
01701 
01702 }
01703 
01704 void KPrView::textAlignBlock()
01705 {
01706     if ( actionTextAlignBlock->isChecked() )
01707     {
01708         tbAlign = Qt::AlignJustify;
01709         m_canvas->setTextAlign(tbAlign);
01710     }
01711     else
01712         actionTextAlignBlock->setChecked(true);
01713 
01714 }
01715 
01716 void KPrView::textInsertPageNum()
01717 {
01718     KPrTextView *edit=m_canvas->currentTextObjectView();
01719     if ( edit )
01720         edit->insertVariable( VT_PGNUM, KoPageVariable::VST_PGNUM_CURRENT );
01721 }
01722 
01723 void KPrView::mtextFont()
01724 {
01725     KoTextFormatInterface* textIface = m_canvas->applicableTextInterfaces().first();
01726     QColor col;
01727     if (textIface)
01728         col = textIface->textBackgroundColor();
01729     col = col.isValid() ? col : QApplication::palette().color( QPalette::Active, QColorGroup::Base );
01730 
01731     delete m_fontDlg;
01732 
01733     m_fontDlg = new KoFontDia( *textIface->currentFormat()
01734                                , m_broker
01735                                , this, 0 );
01736 
01737     connect( m_fontDlg, SIGNAL( applyFont() ),
01738              this, SLOT( slotApplyFont() ) );
01739     m_fontDlg->exec();
01740 
01741     delete m_fontDlg;
01742     m_fontDlg=0L;
01743 }
01744 
01745 void KPrView::slotApplyFont()
01746 {
01747     int flags = m_fontDlg->changedFlags();
01748     if ( flags )
01749     {
01750         m_canvas->setTextFormat(m_fontDlg->newFormat(), flags);
01751     }
01752 }
01753 
01754 void KPrView::slotCounterStyleSelected()
01755 {
01756     QString actionName = QString::fromLatin1(sender()->name());
01757     if ( actionName.startsWith( "counterstyle_" ) )
01758     {
01759         QString styleStr = actionName.mid(13);
01760         //kdDebug(33001) << "KWView::slotCounterStyleSelected styleStr=" << styleStr << endl;
01761         KoParagCounter::Style style = (KoParagCounter::Style)(styleStr.toInt());
01762         KoParagCounter c;
01763         if ( style == KoParagCounter::STYLE_NONE )
01764             c.setNumbering( KoParagCounter::NUM_NONE );
01765         else {
01766             c.setNumbering( KoParagCounter::NUM_LIST );
01767             c.setStyle( style );
01768             if ( c.isBullet() )
01769                 c.setSuffix( QString::null );
01770             // else the suffix remains the default, '.'
01771             // TODO save this setting, to use the last one selected in the dialog?
01772             // (same for custom bullet char etc.)
01773 
01774             // 68927: restart numbering, by default, if last parag wasn't numbered
01775             // (and if we're not applying this to a selection)
01776             KPrTextView *edit = m_canvas->currentTextObjectView();
01777             if ( edit && !edit->textObject()->hasSelection() ) {
01778                 KoTextParag* parag = edit->cursor()->parag();
01779                 if ( parag->prev() && !parag->prev()->counter() )
01780                     c.setRestartCounter(true);
01781             }
01782         }
01783 
01784         QPtrList<KoTextFormatInterface> lst = m_canvas->applicableTextInterfaces();
01785         QPtrListIterator<KoTextFormatInterface> it( lst );
01786         KMacroCommand* macroCmd = 0L;
01787         for ( ; it.current() ; ++it )
01788         {
01789             KCommand *cmd = it.current()->setCounterCommand( c );
01790             if ( cmd )
01791             {
01792                 if ( !macroCmd )
01793                     macroCmd = new KMacroCommand( i18n("Change List Type") );
01794                 macroCmd->addCommand( cmd );
01795             }
01796         }
01797         if( macroCmd)
01798             m_pKPresenterDoc->addCommand( macroCmd );
01799     }
01800 
01801 }
01802 
01803 void KPrView::textDepthPlus()
01804 {
01805     m_canvas->setTextDepthPlus();
01806 }
01807 
01808 void KPrView::textDepthMinus()
01809 {
01810     m_canvas->setTextDepthMinus();
01811 }
01812 
01813 void KPrView::textContentsToHeight()
01814 {
01815     m_canvas->textContentsToHeight();
01816 }
01817 
01818 void KPrView::textObjectToContents()
01819 {
01820     m_canvas->textObjectToContents();
01821 }
01822 
01823 void KPrView::penChosen()
01824 {
01825     QColor c = actionPenColor->color();
01826     if ( !m_canvas->currentTextObjectView() )
01827     {
01828         KCommand * cmd( getPenCmd( i18n( "Change Outline Color" ), KoPen(c),
01829                                    L_NORMAL, L_NORMAL, KoPenCmd::Color ) );
01830         if( cmd )
01831             m_pKPresenterDoc->addCommand( cmd );
01832         else
01833             pen.setColor( c );
01834     }
01835     else
01836     {
01837         tbColor = c;
01838         m_canvas->setTextColor( tbColor );
01839     }
01840 }
01841 
01842 void KPrView::brushChosen()
01843 {
01844     QColor c = actionBrushColor->color();
01845     KPrTextView *edit = m_canvas->currentTextObjectView();
01846     if ( !edit )
01847     {
01848         //tz TODO remove macro, add parameter for command name in setBrush()
01849         KMacroCommand * macro= NULL;
01850         KCommand * cmd = NULL;
01851         QBrush newBrush( c );
01852 
01853         cmd = m_canvas->activePage()->setBrush( newBrush, FT_BRUSH, QColor(), QColor(), BCT_PLAIN, false,
01854                                                 0, 0, KPrBrushCmd::BrushColor | KPrBrushCmd::BrushStyle |
01855                                                 KPrBrushCmd::BrushGradientSelect );
01856         if( cmd )
01857         {
01858             if ( !macro )
01859                 macro = new KMacroCommand( i18n( "Change Fill Color" ) );
01860             macro->addCommand( cmd );
01861         }
01862 
01863 
01864         if( macro )
01865             m_pKPresenterDoc->addCommand( macro );
01866         else
01867             brush.setColor( c );
01868     }
01869     else
01870     {
01871         tbColor = c;
01872         m_canvas->setTextBackgroundColor( c );
01873     }
01874 }
01875 
01876 void KPrView::extraAlignObjLeft()
01877 {
01878     m_canvas->alignObjects( AT_LEFT );
01879 }
01880 
01881 void KPrView::extraAlignObjCenterH()
01882 {
01883     m_canvas->alignObjects( AT_HCENTER );
01884 }
01885 
01886 void KPrView::extraAlignObjRight()
01887 {
01888     m_canvas->alignObjects( AT_RIGHT );
01889 }
01890 
01891 void KPrView::extraAlignObjTop()
01892 {
01893     m_canvas->alignObjects( AT_TOP );
01894 }
01895 
01896 void KPrView::extraAlignObjCenterV()
01897 {
01898     m_canvas->alignObjects( AT_VCENTER );
01899 }
01900 
01901 void KPrView::extraAlignObjBottom()
01902 {
01903     m_canvas->alignObjects( AT_BOTTOM );
01904 }
01905 
01906 void KPrView::extraLineBeginNormal()
01907 {
01908     setExtraLineBegin(L_NORMAL);
01909 }
01910 
01911 void KPrView::extraLineBeginArrow()
01912 {
01913     setExtraLineBegin(L_ARROW);
01914 }
01915 
01916 void KPrView::extraLineBeginRect()
01917 {
01918     setExtraLineBegin(L_SQUARE);
01919 }
01920 
01921 void KPrView::extraLineBeginCircle()
01922 {
01923     setExtraLineBegin(L_CIRCLE);
01924 }
01925 
01926 void KPrView::extraLineBeginLineArrow()
01927 {
01928     setExtraLineBegin( L_LINE_ARROW );
01929 }
01930 
01931 void KPrView::extraLineBeginDimensionLine()
01932 {
01933     setExtraLineBegin( L_DIMENSION_LINE );
01934 }
01935 
01936 void KPrView::extraLineBeginDoubleArrow()
01937 {
01938     setExtraLineBegin( L_DOUBLE_ARROW );
01939 }
01940 
01941 void KPrView::extraLineBeginDoubleLineArrow()
01942 {
01943     setExtraLineBegin( L_DOUBLE_LINE_ARROW );
01944 }
01945 
01946 void KPrView::setExtraLineBegin(LineEnd lb)
01947 {
01948     KCommand * cmd( getPenCmd( i18n("Change Line Begin"), KoPen(),
01949                                lb, L_NORMAL, KoPenCmd::LineBegin ) );
01950     if( cmd )
01951         kPresenterDoc()->addCommand( cmd );
01952     else
01953         lineBegin = lb;
01954 }
01955 
01956 void KPrView::extraLineEndNormal()
01957 {
01958     setExtraLineEnd(L_NORMAL);
01959 }
01960 
01961 void KPrView::extraLineEndArrow()
01962 {
01963     setExtraLineEnd(L_ARROW);
01964 }
01965 
01966 void KPrView::extraLineEndRect()
01967 {
01968     setExtraLineEnd(L_SQUARE);
01969 }
01970 
01971 void KPrView::extraLineEndCircle()
01972 {
01973     setExtraLineEnd(L_CIRCLE);
01974 }
01975 
01976 void KPrView::extraLineEndLineArrow()
01977 {
01978     setExtraLineEnd( L_LINE_ARROW );
01979 }
01980 
01981 void KPrView::extraLineEndDimensionLine()
01982 {
01983     setExtraLineEnd( L_DIMENSION_LINE );
01984 }
01985 
01986 void KPrView::extraLineEndDoubleArrow()
01987 {
01988     setExtraLineEnd( L_DOUBLE_ARROW );
01989 }
01990 
01991 void KPrView::extraLineEndDoubleLineArrow()
01992 {
01993     setExtraLineEnd( L_DOUBLE_LINE_ARROW );
01994 }
01995 
01996 void KPrView::setExtraLineEnd(LineEnd le)
01997 {
01998     KCommand * cmd( getPenCmd( i18n("Change Line End"), KoPen(),
01999                                L_NORMAL, le, KoPenCmd::LineEnd ) );
02000     if( cmd )
02001         kPresenterDoc()->addCommand( cmd );
02002     else
02003         lineEnd = le;
02004 }
02005 
02006 void KPrView::setExtraPenStyle( Qt::PenStyle style )
02007 {
02008     KoPen tmpPen;
02009     tmpPen.setStyle( style );
02010 
02011     KCommand * cmd( getPenCmd( i18n("Change Outline Style"), tmpPen,
02012                                L_NORMAL, L_NORMAL, KoPenCmd::Style ) );
02013     if( cmd )
02014         kPresenterDoc()->addCommand( cmd );
02015     else
02016         pen.setStyle( style );
02017 }
02018 
02019 void KPrView::setExtraPenWidth( double width )
02020 {
02021     KoPen tmpPen;
02022     tmpPen.setPointWidth( width );
02023     KCommand * cmd( getPenCmd( i18n("Change Outline Width"), tmpPen,
02024                                L_NORMAL, L_NORMAL, KoPenCmd::Width ) );
02025 
02026     if( cmd )
02027         kPresenterDoc()->addCommand( cmd );
02028     else
02029         pen.setPointWidth( width );
02030 }
02031 
02032 void KPrView::newPageLayout( const KoPageLayout &_layout )
02033 {
02034     KoPageLayout oldLayout = m_pKPresenterDoc->pageLayout();
02035     KoUnit::Unit unit = m_pKPresenterDoc->unit(); // unchanged
02036 
02037     KPrPgLayoutCmd *pgLayoutCmd = new KPrPgLayoutCmd( i18n( "Set Page Layout" ), _layout, oldLayout, unit, unit,kPresenterDoc() );
02038     pgLayoutCmd->execute();
02039     kPresenterDoc()->addCommand( pgLayoutCmd );
02040     updateRuler();
02041 }
02042 
02043 void KPrView::updateRuler()
02044 {
02045     //update koruler
02046     QRect r=m_canvas->activePage()->getZoomPageRect();
02047     getHRuler()->setFrameStartEnd( r.left(), r.right()/*+m_canvas->diffx()*/ );
02048     getVRuler()->setFrameStartEnd( r.top(), r.bottom()/*+m_canvas->diffy()*/ );
02049 }
02050 
02051 void KPrView::createGUI()
02052 {
02053     splitter = new QSplitter( this );
02054 
02055     if ( !m_pKPresenterDoc->isEmbedded()
02056          && !m_pKPresenterDoc->isSingleViewMode() ) // No sidebar if the document is embedded
02057     {
02058         sidebar = new KPrSideBar( splitter, m_pKPresenterDoc, this );
02059         connect( sidebar, SIGNAL( movePage( int, int ) ),
02060                  m_pKPresenterDoc, SLOT( movePage( int, int ) ) );
02061         connect( sidebar, SIGNAL( selectPage( int, bool ) ),
02062                  m_pKPresenterDoc, SLOT( selectPage( int, bool ) ) );
02063         connect( sidebar, SIGNAL( showPage( int ) ),
02064                  this, SLOT( skipToPage( int ) ) );
02065         // This sucks when resizing the window
02066         //splitter->setResizeMode( sidebar, QSplitter::FollowSizeHint );
02067         //splitter->setResizeMode( pageBase, QSplitter::Stretch );
02068         splitter->setResizeMode( sidebar, QSplitter::KeepSize );
02069     }
02070 
02071     QSplitter *splitterVertical = new QSplitter( QSplitter::Vertical, splitter );
02072 
02073     // setup page
02074     pageBase = new PageBase( splitterVertical, this );
02075     pageBase->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
02076 
02077     m_canvas=new KPrCanvas( pageBase, "Canvas", this );
02078 
02079     QObject::connect( m_canvas, SIGNAL( fontChanged( const QFont & ) ),
02080                       this, SLOT( fontChanged( const QFont & ) ) );
02081     QObject::connect( m_canvas, SIGNAL( colorChanged( const QColor & ) ),
02082                       this, SLOT( colorChanged( const QColor & ) ) );
02083     QObject::connect( m_canvas, SIGNAL( alignChanged( int ) ),
02084                       this, SLOT( alignChanged( int ) ) );
02085     QObject::connect( m_canvas, SIGNAL( objectSelectedChanged()),
02086                       this, SLOT( objectSelectedChanged()));
02087     QObject::connect( m_canvas, SIGNAL( sigMouseWheelEvent( QWheelEvent* ) ),
02088                       this, SLOT( getPageMouseWheelEvent( QWheelEvent* ) ) );
02089 
02090 
02091     // setup notebar.
02092     if ( !m_pKPresenterDoc->isEmbedded()
02093          && !m_pKPresenterDoc->isSingleViewMode() ) // No notebar if the document is embedded
02094     {
02095         notebar = new KPrNoteBar( splitterVertical, this );
02096     }
02097 
02098     // setup GUI
02099     setupActions();
02100     setupPopupMenus();
02101     setupScrollbars();
02102     setRanges();
02103     setupRulers();
02104 
02105     if ( m_pKPresenterDoc && m_canvas )
02106     {
02107         QObject::connect( m_canvas, SIGNAL( stopAutomaticPresentation() ), this, SLOT( stopAutomaticPresentation() ) );
02108         QObject::connect( m_canvas, SIGNAL( restartPresentation() ), this, SLOT( restartPresentation() ) );
02109 
02110         connect( getVRuler(), SIGNAL( addGuide( const QPoint &, bool, int ) ),
02111                  &( m_canvas->guideLines() ), SLOT( addGuide( const QPoint &, bool, int ) ) );
02112         connect( getVRuler(), SIGNAL( moveGuide( const QPoint &, bool, int ) ),
02113                  &( m_canvas->guideLines() ), SLOT( moveGuide( const QPoint &, bool, int ) ) );
02114         connect( getHRuler(), SIGNAL( addGuide( const QPoint &, bool, int ) ),
02115                  &( m_canvas->guideLines() ), SLOT( addGuide( const QPoint &, bool, int ) ) );
02116         connect( getHRuler(), SIGNAL( moveGuide( const QPoint &, bool, int ) ),
02117                  &( m_canvas->guideLines() ), SLOT( moveGuide( const QPoint &, bool, int ) ) );
02118         connect( &( m_canvas->guideLines() ), SIGNAL( moveGuides( bool ) ),
02119                  m_canvas, SLOT( setPaintGuides( bool ) ) );
02120         connect( &( m_canvas->guideLines() ), SIGNAL( paintGuides( bool ) ),
02121                  m_canvas, SLOT( setPaintGuides( bool ) ) );
02122         connect( &( m_canvas->guideLines() ), SIGNAL( guideLinesChanged( KoView * ) ),
02123                  m_pKPresenterDoc, SLOT( slotGuideLinesChanged( KoView * ) ) );
02124         m_canvas->guideLines().setGuideLines( m_pKPresenterDoc->horizontalGuideLines(), m_pKPresenterDoc->verticalGuideLines() );
02125     }
02126 
02127     if ( sidebar )
02128     {
02129         sidebar->outline()->setCurrentItem( sidebar->outline()->firstChild() );
02130         sidebar->outline()->setSelected( sidebar->outline()->firstChild(), TRUE );
02131         KConfig *config=KGlobal::config();
02132         config->setGroup("Global");
02133         if(!config->readBoolEntry("Sidebar", true)) {
02134             sidebar->hide();
02135             actionViewShowSideBar->setChecked(false);
02136         }
02137         else actionViewShowSideBar->setChecked(true);
02138     }
02139 
02140     if ( notebar )
02141     {
02142         KConfig *config=KGlobal::config();
02143         config->setGroup("Global");
02144         if(!config->readBoolEntry("Notebar", true)) {
02145             notebar->hide();
02146             actionViewShowNoteBar->setChecked(false);
02147         }
02148         else actionViewShowNoteBar->setChecked(true);
02149         // HACK This is needed to be able to calculate a good initial size for the notebar
02150         QTimer::singleShot( 0, this, SLOT( initialLayoutOfSplitter() ) );
02151     }
02152     KPrPage *initPage=m_pKPresenterDoc->initialActivePage();
02153     if ( !initPage )
02154         m_pKPresenterDoc->pageList().at( 0 ); // first page
02155     skipToPage( m_pKPresenterDoc->pageList().findRef( initPage ) );
02156 }
02157 
02158 void KPrView::initGui()
02159 {
02160     tbColor = Qt::black;
02161     actionTextColor->setCurrentColor( Qt::black );
02162     actionBrushColor->setCurrentColor( Qt::white );
02163     actionPenColor->setCurrentColor( Qt::black );
02164     updateSideBarMenu();
02165     objectSelectedChanged();
02166     refreshPageButton();
02167 
02168     KStatusBar * sb = statusBar();
02169     if ( sb )
02170         sb->show();
02171     showZoom( zoomHandler()->zoom() );
02172     updateHeaderFooterButton();
02173     updateDisplayObjectMasterPageButton();
02174     updateDisplayBackgroundButton();
02175 
02176     actionAllowAutoFormat->setChecked( m_pKPresenterDoc->allowAutoFormat() );
02177     actionViewFormattingChars->setChecked( m_pKPresenterDoc->viewFormattingChars() );
02178 
02179     updateGuideLineButton();
02180 
02181     updateGridButton();
02182 
02183     m_pKPresenterDoc->updateZoomRuler();
02184     updatePageInfo();
02185     actionAllowBgSpellCheck->setChecked( m_pKPresenterDoc->backgroundSpellCheckEnabled());
02186     updateDirectCursorButton();
02187     m_pKPresenterDoc->updatePresentationButton();
02188 }
02189 
02190 void KPrView::updateDisplayObjectMasterPageButton()
02191 {
02192     actionDisplayObjectFromMasterPage->setChecked( !m_canvas->activePage()->displayObjectFromMasterPage());
02193 }
02194 
02195 void KPrView::updateDisplayBackgroundButton()
02196 {
02197     actionDisplayBackgroundPage->setChecked( !m_canvas->activePage()->displayBackground() );
02198 }
02199 
02200 void KPrView::updateHeaderFooterButton()
02201 {
02202     m_actionExtraHeader->setChecked( m_canvas->activePage()->hasHeader() );
02203     m_actionExtraFooter->setChecked( m_canvas->activePage()->hasFooter() );
02204 }
02205 
02206 void KPrView::guiActivateEvent( KParts::GUIActivateEvent *ev )
02207 {
02208     if ( ev->activated() )
02209         initGui();
02210 
02211     KoView::guiActivateEvent( ev );
02212 }
02213 
02214 void KPrView::setupActions()
02215 {
02216     actionEditCut = KStdAction::cut( this, SLOT( editCut() ), actionCollection(), "edit_cut" );
02217     actionEditCopy = KStdAction::copy( this, SLOT( editCopy() ), actionCollection(), "edit_copy" );
02218     actionEditPaste = KStdAction::paste( this, SLOT( editPaste() ), actionCollection(), "edit_paste" );
02219     connect( m_pKPresenterDoc, SIGNAL( enablePaste( bool ) ),
02220              actionEditPaste, SLOT( setEnabled( bool ) ) );
02221     m_pKPresenterDoc->clipboardDataChanged(); // set paste's initial state
02222 
02223     actionEditDelete = new KAction( i18n( "&Delete" ), "editdelete", CTRL + Qt::Key_Delete,
02224                                     this, SLOT( editDelete() ),
02225                                     actionCollection(), "edit_delete" );
02226     actionEditSelectAll = KStdAction::selectAll( this, SLOT( editSelectAll() ), actionCollection(), "edit_selectall" );
02227     actionEditDeSelectAll= KStdAction::deselect( this, SLOT( editDeSelectAll()), actionCollection(), "edit_deselectall");
02228     actionEditCopyPage = new KAction( i18n( "Copy Slide" ), "editcopy",
02229                                       0, this, SLOT( editCopyPage() ),
02230                                       actionCollection(), "edit_copypage" );
02231     actionEditDuplicatePage = new KAction( i18n( "Duplicate Slide" ), "newslide",
02232                                       0, this, SLOT( editDuplicatePage() ),
02233                                       actionCollection(), "edit_duplicatepage" );
02234     actionEditDelPage = new KAction( i18n( "Delete Slide" ), "delslide", 0,
02235                                      this, SLOT( editDelPage() ),
02236                                      actionCollection(), "edit_delpage" );
02237 
02238     actionEditFind=KStdAction::find( this, SLOT( editFind() ), actionCollection(), "edit_find" );
02239     actionEditFindNext = KStdAction::findNext( this, SLOT( editFindNext() ), actionCollection(), "edit_findnext" );
02240     actionEditFindPrevious = KStdAction::findPrev( this, SLOT( editFindPrevious() ), actionCollection(), "edit_findprevious" );
02241     actionEditReplace=KStdAction::replace( this, SLOT( editReplace() ), actionCollection(), "edit_replace" );
02242 
02243     // ---------------- View actions
02244 
02245     if ( !m_pKPresenterDoc->isEmbedded() )
02246     {
02247         actionViewShowSideBar = new KToggleAction( i18n("Show Sidebar"), 0,
02248                                                    this, SLOT( viewShowSideBar() ),
02249                                                    actionCollection(), "view_showsidebar" );
02250         actionViewShowSideBar->setCheckedState(i18n("Hide Sidebar"));
02251 
02252         actionViewShowNoteBar = new KToggleAction( i18n("Show Notebar"), 0,
02253                                                    this, SLOT( viewShowNoteBar() ),
02254                                                    actionCollection(), "view_shownotebar" );
02255         actionViewShowNoteBar->setCheckedState(i18n("Hide Notebar"));
02256     }
02257 
02258     actionViewFormattingChars = new KToggleAction( i18n( "&Formatting Characters" ), 0,
02259                                                    this, SLOT( slotViewFormattingChars() ),
02260                                                    actionCollection(), "view_formattingchars" );
02261     actionViewFormattingChars->setToolTip( i18n( "Toggle the display of non-printing characters." ) );
02262     actionViewFormattingChars->setWhatsThis( i18n( "Toggle the display of non-printing characters.<br><br>When this is enabled, KPresenter shows you tabs, spaces, carriage returns and other non-printing characters." ) );
02263 
02264     actionViewSlideMaster = new KToggleAction( i18n( "Slide &Master" ), 0,
02265                                                this, SLOT( viewSlideMaster() ),
02266                                                actionCollection(), "view_master" );
02267 
02268     actionViewShowGuideLine= new KToggleAction( i18n( "Guide Lines" ), 0,
02269                                                this, SLOT( viewGuideLines() ),
02270                                                actionCollection(), "view_guidelines" );
02271 
02272     actionViewShowGrid = new KToggleAction( i18n( "Show &Grid" ), 0,
02273                                             this, SLOT( viewGrid() ),
02274                                             actionCollection(), "view_grid" );
02275     actionViewShowGrid->setCheckedState(i18n("Hide &Grid"));
02276 
02277     actionViewSnapToGrid= new KToggleAction( i18n( "Snap to Grid" ), 0,
02278                                              this, SLOT(viewSnapToGrid() ),
02279                                              actionCollection(), "view_snaptogrid" );
02280 
02281     // ---------------- insert actions
02282 
02283     actionInsertPage = new KAction( i18n( "&Slide..." ), "slide", Qt::Key_F2,
02284                                     this, SLOT( insertPage() ),
02285                                     actionCollection(), "insert_page" );
02286 
02287     new KAction( i18n( "Insert &Slide..." ), "newslide", 0,
02288                                     this, SLOT( insertPage() ),
02289                                     actionCollection(), "insert_page_popup" );
02290 
02291     actionInsertPicture = new KAction( i18n( "P&icture..." ), "frame_image", Qt::SHIFT+Qt::Key_F5,
02292                                        this, SLOT( insertPicture() ),
02293                                        actionCollection(), "insert_picture" );
02294 
02295     // ----------------- tools actions
02296 
02297     actionToolsMouse = new KToggleAction( i18n( "Select" ), "select", 0,
02298                                           this, SLOT( toolsMouse() ),
02299                                           actionCollection(), "tools_mouse" );
02300     actionToolsMouse->setExclusiveGroup( "tools" );
02301     actionToolsMouse->setChecked( true );
02302 
02303     actionToolsRotate = new KToggleAction( i18n( "&Rotate" ), "rotate", 0,
02304                                            this, SLOT( toolsRotate() ),
02305                                            actionCollection(), "tools_rotate" );
02306     actionToolsRotate->setExclusiveGroup( "tools" );
02307 
02308     actionToolsZoom = new KToggleAction( i18n( "&Zoom" ), "viewmag", 0,
02309                                          this, SLOT( toolsZoom() ),
02310                                          actionCollection(), "tools_zoom" );
02311     actionToolsZoom->setExclusiveGroup( "tools" );
02312 
02313     actionToolsShapePopup = new KActionMenu( i18n( "&Shape" ), "rectangle",
02314                                              actionCollection(), "tools_shapepopup" );
02315     actionToolsShapePopup->setDelayed(true);
02316     connect(actionToolsShapePopup, SIGNAL(activated()), this, SLOT(toolsShapePopup()));
02317 
02318     actionToolsRectangle = new KToggleAction( i18n( "&Rectangle" ), "rectangle",
02319                                               0, this, SLOT( toolsRectangle() ),
02320                                               actionCollection(), "tools_rectangle" );
02321     actionToolsRectangle->setExclusiveGroup( "tools" );
02322 
02323     actionToolsCircleOrEllipse = new KToggleAction( i18n( "&Circle/Ellipse" ), "circle",
02324                                                     0, this, SLOT( toolsCircleOrEllipse() ),
02325                                                     actionCollection(), "tools_circle" );
02326     actionToolsCircleOrEllipse->setExclusiveGroup( "tools" );
02327 
02328     actionToolsPie = new KToggleAction( i18n( "&Pie/Arc/Chord" ), "pie", 0,
02329                                         this, SLOT( toolsPie() ),
02330                                         actionCollection(), "tools_pie" );
02331     actionToolsPie->setExclusiveGroup( "tools" );
02332 
02333     actionToolsText = new KToggleAction( i18n( "&Text" ), "frame_text", Qt::Key_F10, // same shortcut as KWord
02334                                          this, SLOT( toolsText() ),
02335                                          actionCollection(), "tools_text" );
02336     actionToolsText->setExclusiveGroup( "tools" );
02337 
02338     actionToolsAutoform = new KToggleAction( i18n( "&Arrows && Connections" ), "autoform",
02339                                              0, this, SLOT( toolsAutoform() ),
02340                                              actionCollection(), "tools_autoform" );
02341     actionToolsAutoform->setExclusiveGroup( "tools" );
02342 
02343     actionToolsDiagramm = new KToggleAction( i18n( "&Chart" ), "frame_chart", 0,
02344                                              this, SLOT( toolsDiagramm() ),
02345                                              actionCollection(), "tools_diagramm" );
02346     actionToolsDiagramm->setExclusiveGroup( "tools" );
02347 
02348     actionToolsTable = new KToggleAction( i18n( "Ta&ble"), "frame_spreadsheet", Qt::Key_F5 /*same as kword*/,
02349                                           this, SLOT( toolsTable() ),
02350                                           actionCollection(), "tools_table" );
02351     actionToolsTable->setExclusiveGroup( "tools" );
02352 
02353     actionToolsObject = new KoPartSelectAction( i18n( "&Object" ), "frame_query",
02354                                                 this, SLOT( toolsObject() ),
02355                                                 actionCollection(), "tools_object" );
02356 
02357     actionToolsLinePopup = new KActionMenu( i18n( "&Line" ), "line",
02358                                             actionCollection(), "tools_linepopup" );
02359     actionToolsLinePopup->setDelayed(true);
02360     connect(actionToolsLinePopup, SIGNAL(activated()), this, SLOT(toolsLinePopup()));
02361 
02362     actionToolsLine = new KToggleAction( i18n( "&Line" ), "line", 0,
02363                                          this, SLOT( toolsLine() ),
02364                                          actionCollection(), "tools_line" );
02365     actionToolsLine->setExclusiveGroup( "tools" );
02366 
02367     actionToolsFreehand = new KToggleAction( i18n( "&Freehand" ), "freehand", 0,
02368                                              this, SLOT( toolsFreehand() ),
02369                                              actionCollection(), "tools_freehand" );
02370     actionToolsFreehand->setExclusiveGroup( "tools" );
02371 
02372     actionToolsPolyline = new KToggleAction( i18n( "Po&lyline" ), "polyline", 0,
02373                                              this, SLOT( toolsPolyline() ),
02374                                              actionCollection(), "tools_polyline" );
02375     actionToolsPolyline->setExclusiveGroup( "tools" );
02376 
02377     actionToolsQuadricBezierCurve = new KToggleAction( i18n( "&Quadric Bezier Curve" ), "quadricbeziercurve", 0,
02378                                                        this, SLOT( toolsQuadricBezierCurve() ),
02379                                                        actionCollection(), "tools_quadricbeziercurve" );
02380     actionToolsQuadricBezierCurve->setExclusiveGroup( "tools" );
02381 
02382     actionToolsCubicBezierCurve = new KToggleAction( i18n( "C&ubic Bezier Curve" ), "cubicbeziercurve", 0,
02383                                                      this, SLOT( toolsCubicBezierCurve() ),
02384                                                      actionCollection(), "tools_cubicbeziercurve" );
02385     actionToolsCubicBezierCurve->setExclusiveGroup( "tools" );
02386 
02387     actionToolsConvexOrConcavePolygon = new KToggleAction( i18n( "Co&nvex/Concave Polygon" ), "polygon", 0,
02388                                                            this, SLOT( toolsConvexOrConcavePolygon() ),
02389                                                            actionCollection(), "tools_polygon" );
02390     actionToolsConvexOrConcavePolygon->setExclusiveGroup( "tools" );
02391 
02392 
02393     actionToolsClosedLinePopup = new KActionMenu( i18n( "&Closed Line" ), "closed_freehand",
02394                                                   actionCollection(), "tools_closed_linepopup" );
02395     actionToolsClosedLinePopup->setDelayed(true);
02396     connect(actionToolsClosedLinePopup, SIGNAL(activated()), this, SLOT(toolsClosedLinePopup()));
02397 
02398     actionToolsClosedFreehand = new KToggleAction( i18n( "Closed &Freehand" ), "closed_freehand", 0,
02399                                                    this, SLOT( toolsClosedFreehand() ),
02400                                                    actionCollection(), "tools_closed_freehand" );
02401     actionToolsClosedFreehand->setExclusiveGroup( "tools" );
02402 
02403 
02404     actionToolsClosedPolyline = new KToggleAction( i18n( "Closed Po&lyline" ), "closed_polyline", 0,
02405                                                    this, SLOT( toolsClosedPolyline() ),
02406                                                    actionCollection(), "tools_closed_polyline" );
02407     actionToolsClosedPolyline->setExclusiveGroup( "tools" );
02408 
02409 
02410     actionToolsClosedQuadricBezierCurve = new KToggleAction( i18n( "Closed &Quadric Bezier Curve" ), "closed_quadricbeziercurve", 0,
02411                                                              this, SLOT( toolsClosedQuadricBezierCurve() ),
02412                                                              actionCollection(), "tools_closed_quadricbeziercurve" );
02413     actionToolsClosedQuadricBezierCurve->setExclusiveGroup( "tools" );
02414 
02415 
02416     actionToolsClosedCubicBezierCurve = new KToggleAction( i18n( "Closed C&ubic Bezier Curve" ), "closed_cubicbeziercurve", 0,
02417                                                            this, SLOT( toolsClosedCubicBezierCurve() ),
02418                                                            actionCollection(), "tools_closed_cubicbeziercurve" );
02419     actionToolsClosedCubicBezierCurve->setExclusiveGroup( "tools" );
02420 
02421     // ----------------- text actions
02422 
02423     actionTextFont = new KAction( i18n( "&Font..." ), 0, this, SLOT( mtextFont() ),
02424                                   actionCollection(), "text_font" );
02425 
02426     actionTextFontSize = new KFontSizeAction( i18n( "Font Size" ), 0, actionCollection(), "text_fontsize" );
02427     connect( actionTextFontSize, SIGNAL( fontSizeChanged( int ) ),
02428              this, SLOT( sizeSelected( int ) ) );
02429 
02430 #ifdef KFONTACTION_HAS_CRITERIA_ARG
02431     actionTextFontFamily = new KFontAction( KFontChooser::SmoothScalableFonts,
02432                                             i18n( "Font Family" ), 0,
02433                                             actionCollection(), "text_fontfamily" );
02434 #else
02435     actionTextFontFamily = new KFontAction( i18n( "Font Family" ), 0,
02436                                             actionCollection(), "text_fontfamily" );
02437 #endif
02438     connect( actionTextFontFamily , SIGNAL( activated( const QString & ) ),
02439              this, SLOT( fontSelected( const QString & ) ) );
02440 
02441     actionTextBold = new KToggleAction( i18n( "&Bold" ), "text_bold", CTRL + Qt::Key_B,
02442                                         this, SLOT( textBold() ),
02443                                         actionCollection(), "text_bold" );
02444 
02445     actionTextItalic = new KToggleAction( i18n( "&Italic" ), "text_italic", CTRL + Qt::Key_I,
02446                                           this, SLOT( textItalic() ),
02447                                           actionCollection(), "text_italic" );
02448 
02449     actionTextUnderline = new KToggleAction( i18n( "&Underline" ), "text_under", CTRL + Qt::Key_U,
02450                                              this, SLOT( textUnderline() ),
02451                                              actionCollection(), "text_underline" );
02452 
02453     actionFormatStrikeOut = new KToggleAction( i18n( "&Strike Out" ), "text_strike", 0 ,
02454                                                this, SLOT( textStrikeOut() ),
02455                                                actionCollection(), "format_strike" );
02456 
02457     actionTextColor = new TKSelectColorAction( i18n( "&Color..." ), TKSelectColorAction::TextColor,
02458                                                actionCollection(), "text_color" ,true);
02459     connect( actionTextColor, SIGNAL( activated() ), SLOT( textColor() ) );
02460     actionTextColor->setDefaultColor(QColor());
02461 
02462 
02463     actionTextAlignLeft = new KToggleAction( i18n( "Align &Left" ), "text_left", ALT + Qt::Key_L,
02464                                              this, SLOT( textAlignLeft() ),
02465                                              actionCollection(), "text_alignleft" );
02466     actionTextAlignLeft->setExclusiveGroup( "align" );
02467     actionTextAlignLeft->setChecked( true );
02468 
02469     actionTextAlignCenter = new KToggleAction( i18n( "Align &Center" ), "text_center", ALT + Qt::Key_C,
02470                                                this, SLOT( textAlignCenter() ),
02471                                                actionCollection(), "text_aligncenter" );
02472     actionTextAlignCenter->setExclusiveGroup( "align" );
02473 
02474     actionTextAlignRight = new KToggleAction( i18n( "Align &Right" ), "text_right", ALT + Qt::Key_R,
02475                                               this, SLOT( textAlignRight() ),
02476                                               actionCollection(), "text_alignright" );
02477     actionTextAlignRight->setExclusiveGroup( "align" );
02478 
02479     actionTextAlignBlock = new KToggleAction( i18n( "Align &Block" ), "text_block", CTRL + Qt::Key_J,
02480                                               this, SLOT( textAlignBlock() ),
02481                                               actionCollection(), "text_alignblock" );
02482     actionTextAlignBlock->setExclusiveGroup( "align" );
02483 
02484 
02485     actionFormatNumber = new KActionMenu( i18n( "Number" ), "enumList", actionCollection(), "format_number" );
02486     actionFormatNumber->setDelayed( false );
02487     actionFormatBullet = new KActionMenu( i18n( "Bullet" ), "unsortedList", actionCollection(), "format_bullet" );
02488     actionFormatBullet->setDelayed( false );
02489     QPtrList<KoCounterStyleWidget::StyleRepresenter> stylesList;
02490     KoCounterStyleWidget::makeCounterRepresenterList( stylesList );
02491     QPtrListIterator<KoCounterStyleWidget::StyleRepresenter> styleIt( stylesList );
02492     for ( ; styleIt.current() ; ++styleIt ) {
02493         // Dynamically create toggle-actions for each list style.
02494         // This approach allows to edit toolbars and extract separate actions from this menu
02495         KToggleAction* act = new KToggleAction( styleIt.current()->name(), /*TODO icon,*/
02496                                                 0, this, SLOT( slotCounterStyleSelected() ),
02497                                                 actionCollection(), QString("counterstyle_%1").arg( styleIt.current()->style() ).latin1() );
02498         act->setExclusiveGroup( "counterstyle" );
02499         // Add to the right menu: both for "none", bullet for bullets, numbers otherwise
02500         if ( styleIt.current()->style() == KoParagCounter::STYLE_NONE ) {
02501             actionFormatBullet->insert( act );
02502             actionFormatNumber->insert( act );
02503         } else if ( styleIt.current()->isBullet() )
02504             actionFormatBullet->insert( act );
02505         else
02506             actionFormatNumber->insert( act );
02507     }
02508     actionTextDepthPlus = new KAction( i18n( "&Increase Depth" ),  QApplication::reverseLayout() ?"format_decreaseindent" : "format_increaseindent",
02509                                        CTRL + Qt::Key_Plus, this, SLOT( textDepthPlus() ),
02510                                        actionCollection(), "text_depthPlus" );
02511 
02512     actionTextDepthMinus = new KAction( i18n( "&Decrease Depth" ), QApplication::reverseLayout() ?"format_increaseindent" : "format_decreaseindent",
02513                                         CTRL + Qt::Key_Minus, this, SLOT( textDepthMinus() ),
02514                                         actionCollection(), "text_depthMinus" );
02515 
02516     actionTextExtentCont2Height = new KAction( i18n( "Extend Contents to Object &Height" ), 0,
02517                                                this, SLOT( textContentsToHeight() ),
02518                                                actionCollection(), "text_con2hei" );
02519 
02520     actionTextExtendObj2Cont = new KAction( i18n( "&Extend Object to Fit Contents" ), 0,
02521                                             this, SLOT( textObjectToContents() ),
02522                                             actionCollection(), "text_obj2cont" );
02523 
02524     actionTextInsertPageNum = new KAction( i18n( "&Insert Slide Number" ), "pgnum", 0,
02525                                            this, SLOT( textInsertPageNum() ),
02526                                            actionCollection(), "text_inspgnum" );
02527 
02528     // ----------------- format actions
02529 
02530     actionExtraProperties = new KAction( i18n( "&Properties" ), "penbrush", 0,
02531                                          this, SLOT( extraProperties() ),
02532                                          actionCollection(), "extra_properties" );
02533 
02534     actionExtraArrangePopup = new KActionMenu( i18n( "Arra&nge Objects" ), "arrange",
02535                                                actionCollection(), "extra_arrangepopup" );
02536     actionExtraArrangePopup->setDelayed( false ); 
02537 
02538     actionExtraRaise = new KAction( i18n( "Ra&ise Objects" ), "raise",
02539                                     CTRL+Qt::SHIFT+Qt::Key_R, this, SLOT( extraRaise() ),
02540                                     actionCollection(), "extra_raise" );
02541 
02542     actionExtraLower = new KAction( i18n( "&Lower Objects" ), "lower", CTRL +Qt::SHIFT+ Qt::Key_L,
02543                                     this, SLOT( extraLower() ),
02544                                     actionCollection(), "extra_lower" );
02545 
02546     actionExtraBringForward= new KAction( i18n( "Bring to Front" ), "bring_forward",
02547                                           0, this, SLOT( extraBringForward() ),
02548                                           actionCollection(), "extra_bring_forward" );
02549 
02550     actionExtraSendBackward= new KAction( i18n( "Send to Back" ), "send_backward",
02551                                           0, this, SLOT( extraSendBackward() ),
02552                                           actionCollection(), "extra_send_backward" );
02553 
02554 
02555 
02556     actionExtraRotate = new KAction( i18n( "R&otate Objects..." ), "rotate_cw", 0,
02557                                      this, SLOT( extraRotate() ),
02558                                      actionCollection(), "extra_rotate" );
02559 
02560     actionExtraShadow = new KAction( i18n( "&Shadow Objects..." ), "shadow", 0,
02561                                      this, SLOT( extraShadow() ),
02562                                      actionCollection(), "extra_shadow" );
02563 
02564     actionExtraAlignObjLeft = new KAction( i18n( "Align &Left" ), "aoleft", 0,
02565                                            this, SLOT( extraAlignObjLeft() ),
02566                                            actionCollection(), "extra_alignleft" );
02567 
02568     actionExtraAlignObjCenterH = new KAction( i18n( "Align Center (&horizontally)" ),
02569                                               "aocenterh", 0,
02570                                               this, SLOT( extraAlignObjCenterH() ),
02571                                               actionCollection(), "extra_aligncenterh" );
02572 
02573     actionExtraAlignObjRight = new KAction( i18n( "Align &Right" ), "aoright", 0,
02574                                             this, SLOT( extraAlignObjRight() ),
02575                                             actionCollection(), "extra_alignright" );
02576 
02577     actionExtraAlignObjTop = new KAction( i18n( "Align &Top" ), "aotop", 0,
02578                                           this, SLOT( extraAlignObjTop() ),
02579                                           actionCollection(), "extra_aligntop" );
02580 
02581     actionExtraAlignObjCenterV = new KAction( i18n( "Align Center (&vertically)" ),
02582                                               "aocenterv", 0,
02583                                               this, SLOT( extraAlignObjCenterV() ),
02584                                               actionCollection(), "extra_aligncenterv" );
02585 
02586     actionExtraAlignObjBottom = new KAction( i18n( "Align &Bottom" ), "aobottom", 0,
02587                                              this, SLOT( extraAlignObjBottom() ),
02588                                              actionCollection(), "extra_alignbottom" );
02589 
02590 
02591     actionExtraBackground = new KAction( i18n( "Slide Bac&kground..." ), "background", 0,
02592                                          this, SLOT( extraBackground() ),
02593                                          actionCollection(), "extra_background" );
02594 
02595     actionExtraLayout = new KAction( i18n( "Page &Layout..." ), 0,
02596                                      this, SLOT( extraLayout() ),
02597                                      actionCollection(), "extra_layout" );
02598 
02599     m_actionExtraHeader = new KToggleAction( i18n( "Enable Document &Header" ), 0,
02600                                              this, SLOT( viewHeader() ),
02601                                              actionCollection(), "extra_header" );
02602     m_actionExtraHeader->setCheckedState( i18n( "Disable Document &Header" ) );
02603     m_actionExtraHeader->setToolTip( i18n( "Shows and hides header display for the current slide." ) );
02604 
02605     m_actionExtraFooter = new KToggleAction( i18n( "Enable Document Foo&ter" ), 0,
02606                                              this, SLOT( viewFooter() ),
02607                                              actionCollection(), "extra_footer" );
02608     m_actionExtraFooter->setCheckedState( i18n( "Disable Document Foo&ter" ) );
02609     m_actionExtraFooter->setToolTip( i18n( "Shows and hides footer display for the current slide." ) );
02610 
02611     actionExtraConfigure = new KAction( i18n( "Configure KPresenter..." ),
02612                                         "configure", 0,
02613                                         this, SLOT( extraConfigure() ),
02614                                         actionCollection(), "extra_configure" );
02615 
02616     actionExtraWebPres = new KAction( i18n( "Create &HTML Slideshow..." ),
02617                                       "webpres", 0,
02618                                       this, SLOT( extraWebPres() ),
02619                                       actionCollection(), "extra_webpres" );
02620 
02621     actionExtraMSPres = new KAction( i18n( "Create Memor&y Stick Slideshow..." ),
02622                      0, this, SLOT( extraMSPres() ),
02623                      actionCollection(), "extra_mspres" );
02624 
02625     actionExtraCreateTemplate = new KAction( i18n( "Template Manager" ), 0,
02626                                              this, SLOT( extraCreateTemplate() ),
02627                                              actionCollection(), "extra_template" );
02628 
02629     actionExtraDefaultTemplate = new KAction( i18n( "Use Current Slide as Default Template" ), 0,
02630                                               this, SLOT( extraDefaultTemplate() ),
02631                                               actionCollection(), "extra_defaulttemplate" );
02632 
02633     actionExtraAlignObjsPopup = new KActionMenu( i18n("Align O&bjects"), "alignobjs", 
02634                                             actionCollection(), "extra_alignobjs" );
02635     actionExtraAlignObjsPopup->setDelayed( false );
02636 
02637     actionExtraLineBegin = new KAction( i18n("Line Begin"), "line_begin", 0,
02638                                         this, SLOT( extraLineBegin() ),
02639                                         actionCollection(), "extra_linebegin" );
02640 
02641     actionExtraLineEnd = new KAction( i18n("Line End"), "line_end", 0,
02642                                       this, SLOT( extraLineEnd() ),
02643                                       actionCollection(), "extra_lineend" );
02644 
02645     actionExtraPenStyle = new KoLineStyleAction( i18n("Outline Style"), "pen_style",
02646                                        this, SLOT( extraPenStyle(int) ),
02647                                        actionCollection(), "extra_penstyle" );
02648     actionExtraPenStyle->setShowCurrentSelection(false);
02649 
02650     actionExtraPenWidth = new KoLineWidthAction( i18n("Outline Width"), "pen_width",
02651                                        this, SLOT( extraPenWidth(double) ),
02652                                        actionCollection(), "extra_penwidth" );
02653     actionExtraPenWidth->setUnit( kPresenterDoc()->unit() );
02654     actionExtraPenWidth->setShowCurrentSelection(false);
02655     connect( kPresenterDoc(), SIGNAL( unitChanged( KoUnit::Unit ) ),
02656              actionExtraPenWidth, SLOT( setUnit( KoUnit::Unit ) ) );
02657 
02658     actionExtraGroup = new KAction( i18n( "&Group Objects" ), "group", 
02659                                     QKeySequence( "Ctrl+G" ),
02660                                     this, SLOT( extraGroup() ),
02661                                     actionCollection(), "extra_group" );
02662 
02663     actionExtraUnGroup = new KAction( i18n( "&Ungroup Objects" ), "ungroup", 
02664                                       QKeySequence( "Ctrl+Shift+G" ),
02665                                       this, SLOT( extraUnGroup() ),
02666                                       actionCollection(), "extra_ungroup" );
02667 
02668     // ----------------- slideshow actions
02669 
02670     actionScreenConfigPages = new KAction( i18n( "&Configure Slide Show..." ),
02671                                            "configure", 0,
02672                                            this, SLOT( screenConfigPages() ),
02673                                            actionCollection(), "screen_configpages" );
02674 
02675     actionScreenAssignEffect = new KAction( i18n( "Edit &Object Effect..." ),
02676                                             "effect", 0,
02677                                             this, SLOT( screenAssignEffect() ),
02678                                             actionCollection(), "screen_assigneffect");
02679 
02680     actionScreenTransEffect = new KAction( i18n( "Edit Slide &Transition..." ),
02681                                            "slide_effect", 0,
02682                                            this, SLOT( screenTransEffect() ),
02683                                            actionCollection(), "screen_transeffect");
02684 
02685 
02686     actionScreenStart = new KAction( i18n( "&Start" ),
02687                                      "2rightarrow", Qt::Key_F12,
02688                                      this, SLOT( screenStart() ),
02689                                      actionCollection(), "screen_start" );
02690 
02691     actionScreenStartFromFirst = new KAction( i18n( "Start From &First Slide" ),
02692                                               "1rightarrow", 0,
02693                                               this, SLOT( screenStartFromFirst() ),
02694                                               actionCollection(), "screen_startfromfirst" );
02695 
02696     actionScreenFirst = new KAction( i18n( "&Go to Start" ),
02697                                      "start", 0,
02698                                      this, SLOT( screenFirst() ),
02699                                      actionCollection(), "screen_first" );
02700 
02701     actionScreenPrev = new KAction( i18n( "&Previous Slide" ),
02702                                     "back", Qt::Key_Prior,
02703                                     this, SLOT( screenPrev() ),
02704                                     actionCollection(), "screen_prev" );
02705 
02706     actionScreenNext = new KAction( i18n( "&Next Slide" ),
02707                                     "forward", Qt::Key_Next,
02708                                     this, SLOT( screenNext() ),
02709                                     actionCollection(), "screen_next" );
02710 
02711     actionScreenLast = new KAction( i18n( "Go to &End" ),
02712                                     "finish", 0,
02713                                     this, SLOT( screenLast() ),
02714                                     actionCollection(), "screen_last" );
02715 
02716     actionScreenSkip = new KAction( i18n( "Goto &Slide..." ),
02717                                     "goto", 0,
02718                                     this, SLOT( screenSkip() ),
02719                                     actionCollection(), "screen_skip" );
02720 
02721     // ----------------- colorbar(Brush and Pen) action
02722 
02723     actionBrushColor = new TKSelectColorAction( i18n( "Fill Color..." ), TKSelectColorAction::FillColor,
02724                                                 actionCollection(), "brush_color" ,true);
02725     connect( actionBrushColor, SIGNAL( activated() ), SLOT( brushChosen() ) );
02726     actionBrushColor->setDefaultColor(QColor());
02727 
02728     actionPenColor = new TKSelectColorAction( i18n( "Outline Color..." ), TKSelectColorAction::LineColor,
02729                                               actionCollection(), "pen_color" );
02730     connect( actionPenColor, SIGNAL( activated() ), SLOT( penChosen() ) );
02731     actionPenColor->setDefaultColor(QColor());
02732     actionExtendObjectHeight = new KAction( i18n( "&Extend Contents to Object Height" ),0, this, SLOT( textContentsToHeight() ),
02733                                             actionCollection(), "extendobjectheight" );
02734 
02735     actionResizeTextObject = new KAction( i18n( "&Resize Object to Fit Contents" ),0, this, SLOT( textObjectToContents() ),
02736                                           actionCollection(), "resizetextobject" );
02737 
02738     actionRenamePage=new KAction(i18n( "&Rename Slide..." ),0,this,
02739                                  SLOT( renamePageTitle() ),
02740                                  actionCollection(), "rename_page" );
02741 
02742     actionPicOriginalSize = new KAction( i18n( "Sca&le to Original Size" ), 0, this,
02743                                          SLOT( picViewOriginalSize() ),
02744                                          actionCollection(), "pic_original_size" );
02745 
02746     actionPic640x480=new KAction(i18n( "640x480" ),0,this,
02747                                  SLOT( picViewOrig640x480() ),
02748                                  actionCollection(), "pic_640_480" );
02749 
02750     actionPic800x600=new KAction(i18n( "800x600" ),0,this,
02751                                  SLOT( picViewOrig800x600() ),
02752                                  actionCollection(), "pic_800_600" );
02753 
02754     actionPic1024x768=new KAction(i18n( "1024x768" ),0,this,
02755                                   SLOT( picViewOrig1024x768() ),
02756                                   actionCollection(), "pic_1024_768" );
02757 
02758     actionPic1280x1024=new KAction(i18n( "1280x1024" ),0,this,
02759                                    SLOT( picViewOrig1280x1024() ),
02760                                    actionCollection(), "pic_1280_1024" );
02761 
02762     actionPic1600x1200=new KAction(i18n( "1600x1200" ),0,this,
02763                                    SLOT( picViewOrig1600x1200() ),
02764                                    actionCollection(), "pic_1600_1200" );
02765 
02766     actionChangePic=new KAction( i18n( "&Change Picture..." ),"frame_image",0,this,
02767                                  SLOT( chPic() ), actionCollection(), "change_picture" );
02768 
02769 
02770     actionImageEffect = new KAction( i18n("Image &Effect..."), 0, this,
02771                                      SLOT(imageEffect()), actionCollection(), "image_effect");
02772 
02773 
02774     actionFormatSuper = new KToggleAction( i18n( "Superscript" ), "super", 0,
02775                                            this, SLOT( textSuperScript() ),
02776                                            actionCollection(), "format_super" );
02777     actionFormatSuper->setExclusiveGroup( "valign" );
02778     actionFormatSub = new KToggleAction( i18n( "Subscript" ), "sub", 0,
02779                                          this, SLOT( textSubScript() ),
02780                                          actionCollection(), "format_sub" );
02781     actionFormatSub->setExclusiveGroup( "valign" );
02782 
02783 
02784     actionInsertSpecialChar = new KAction( i18n( "Sp&ecial Character..." ), "char",
02785                                            ALT + Qt::SHIFT + Qt::Key_C,
02786                                            this, SLOT( insertSpecialChar() ),
02787                                            actionCollection(), "insert_specialchar" );
02788 
02789     actionInsertLink = new KAction( i18n( "Link..." ), 0,
02790                                     this, SLOT( insertLink() ),
02791                                     actionCollection(), "insert_link" );
02792 
02793 #if 0
02794     //code from page.cc
02795     //not implemented
02796     picResizeMenu->insertSeparator();
02797     picResizeMenu->insertItem( i18n( "Enter Custom Factor..." ), this, SLOT( picViewOrigFactor() ) );
02798 #endif
02799     (void) new KAction( i18n( "Configure &Autocorrection..." ), 0,
02800                         this, SLOT( extraAutoFormat() ),
02801                         actionCollection(), "extra_autocorrection" );
02802     actionExtraSpellCheck = KStdAction::spelling( this, SLOT( slotSpellCheck() ), actionCollection(), "extra_spellcheck" );
02803 
02804     actionFormatParag = new KAction( i18n( "&Paragraph..." ), ALT + CTRL + Qt::Key_P,
02805                                      this, SLOT( formatParagraph() ),
02806                                      actionCollection(), "format_paragraph" );
02807 
02808     actionFormatDefault=new KAction( i18n( "Default Format" ), 0,
02809                                      this, SLOT( textDefaultFormat() ),
02810                                      actionCollection(), "text_default" );
02811 
02812     actionOpenLink = new KAction( i18n( "Open Link" ), 0,
02813                                   this, SLOT( openLink() ),
02814                                   actionCollection(), "open_link" );
02815 
02816     actionChangeLink=new KAction( i18n("Change Link..."), 0,
02817                                   this,SLOT(changeLink()),
02818                                   actionCollection(), "change_link");
02819 
02820     actionCopyLink = new KAction( i18n( "Copy Link" ), 0,
02821                                   this, SLOT( copyLink() ),
02822                                   actionCollection(), "copy_link" );
02823 
02824     actionRemoveLink = new KAction( i18n( "Remove Link" ), 0,
02825                                     this, SLOT( removeLink() ),
02826                                     actionCollection(), "remove_link" );
02827 
02828 
02829     actionAddLinkToBookmak = new KAction( i18n( "Add to Bookmark" ), 0,
02830                                           this, SLOT( addToBookmark() ),
02831                                           actionCollection(), "add_to_bookmark" );
02832 
02833     actionEditCustomVarsEdit = new KAction( i18n( "&Custom Variables..." ), 0,
02834                                             this, SLOT( editCustomVars() ),
02835                                             actionCollection(), "edit_vars" );
02836 
02837     actionEditCustomVars = new KAction( i18n( "Edit Variable..." ), 0,
02838                                         this, SLOT( editCustomVariable() ),
02839                                         actionCollection(), "edit_customvars" );
02840 
02841 
02842     m_variableDefMap.clear();
02843     actionInsertVariable = new KActionMenu( i18n( "&Variable" ),
02844                                             actionCollection(), "insert_variable" );
02845     // The last argument is only needed if a submenu is to be created
02846     addVariableActions( VT_FIELD, KoFieldVariable::actionTexts(), actionInsertVariable, i18n("&Property") );
02847     addVariableActions( VT_DATE, KoDateVariable::actionTexts(), actionInsertVariable, i18n("&Date") );
02848     addVariableActions( VT_TIME, KoTimeVariable::actionTexts(), actionInsertVariable, i18n("&Time") );
02849 
02850     actionInsertCustom = new KActionMenu( i18n( "&Custom" ),
02851                                           actionCollection(), "insert_custom" );
02852     actionInsertVariable->insert(actionInsertCustom);
02853     refreshCustomMenu();
02854 
02855     addVariableActions( VT_PGNUM, KoPageVariable::actionTexts(), actionInsertVariable, i18n("&Page") );
02856     addVariableActions( VT_STATISTIC, KPrStatisticVariable::actionTexts(), actionInsertVariable, i18n("&Statistic") );
02857 
02858     actionInsertVariable->popupMenu()->insertSeparator();
02859     actionRefreshAllVariable = new KAction( i18n( "&Refresh All Variables" ), 0,
02860                                             this, SLOT( refreshAllVariable() ),
02861                                             actionCollection(), "refresh_all_variable" );
02862     actionInsertVariable->insert(actionRefreshAllVariable);
02863 
02864     actionIncreaseFontSize = new KAction( i18n("Increase Font Size"),"fontsizeup", 0,
02865                                           this, SLOT( increaseFontSize() ),
02866                                           actionCollection(), "increaseFontSize" );
02867 
02868     actionDecreaseFontSize = new KAction( i18n("Decrease Font Size"),"fontsizedown", 0,
02869                                           this, SLOT( decreaseFontSize() ),
02870                                           actionCollection(), "decreaseFontSize" );
02871 
02872     actionChangeCase=new KAction( i18n( "Change Case..." ), 0,
02873                                   this, SLOT( changeCaseOfText() ),
02874                                   actionCollection(), "change_case" );
02875 
02876     actionViewZoom = new KSelectAction( i18n( "Zoom" ), "viewmag", 0,
02877                                         actionCollection(), "view_zoom" );
02878     connect( actionViewZoom, SIGNAL( activated( const QString & ) ),
02879              this, SLOT( viewZoom( const QString & ) ) );
02880     actionViewZoom->setEditable(true);
02881     changeZoomMenu( );
02882 
02883     actionFormatStylist = new KAction( i18n( "&Style Manager" ), ALT + CTRL + Qt::Key_S,
02884                                        this, SLOT( extraStylist() ),
02885                                        actionCollection(), "format_stylist" );
02886 
02887     actionFormatStyleMenu = new KActionMenu( i18n( "St&yle" ), 0,
02888                                              actionCollection(), "format_stylemenu" );
02889 
02890 
02891     actionFormatStyle = new KSelectAction( i18n( "St&yle" ), 0,
02892                                            actionCollection(), "format_style" );
02893     connect( actionFormatStyle, SIGNAL( activated( int ) ),
02894              this, SLOT( textStyleSelected( int ) ) );
02895     actionFormatStyle->setMenuAccelsEnabled( true );
02896     updateStyleList();
02897 
02898     actionAllowAutoFormat = new KToggleAction( i18n( "Enable Autocorrection" ), 0,
02899                                                this, SLOT( slotAllowAutoFormat() ),
02900                                                actionCollection(), "enable_autocorrection" );
02901     actionAllowAutoFormat->setCheckedState(i18n("Disable Autocorrection"));
02902 
02903     // ------------------- Actions with a key binding and no GUI item
02904     new KAction( i18n( "Insert Non-Breaking Space" ), CTRL+Qt::Key_Space,
02905                  this, SLOT( slotNonbreakingSpace() ), actionCollection(), "nonbreaking_space" );
02906     new KAction( i18n( "Insert Non-Breaking Hyphen" ), CTRL+Qt::SHIFT+Qt::Key_Minus,
02907                  this, SLOT( slotNonbreakingHyphen() ), actionCollection(), "nonbreaking_hyphen" );
02908     new KAction( i18n( "Insert Soft Hyphen" ), CTRL+Qt::Key_Minus,
02909                  this, SLOT( slotSoftHyphen() ), actionCollection(), "soft_hyphen" );
02910     new KAction( i18n( "Line Break" ), Qt::SHIFT+Qt::Key_Return,
02911                  this, SLOT( slotLineBreak() ), actionCollection(), "line_break" );
02912     new KAction( i18n( "Completion" ), KStdAccel::shortcut(KStdAccel::TextCompletion),
02913                  this, SLOT( slotCompletion() ), actionCollection(), "completion" );
02914 
02915     new KAction( i18n( "Increase Numbering Level" ), ALT+Qt::Key_Right,
02916                  this, SLOT( slotIncreaseNumberingLevel() ), actionCollection(), "increase_numbering_level" );
02917     new KAction( i18n( "Decrease Numbering Level" ), ALT+Qt::Key_Left,
02918                  this, SLOT( slotDecreaseNumberingLevel() ), actionCollection(), "decrease_numbering_level" );
02919 
02920 
02921     actionInsertComment = new KAction( i18n( "Comment..." ), 0,
02922                                        this, SLOT( insertComment() ),
02923                                        actionCollection(), "insert_comment" );
02924     actionEditComment = new KAction( i18n("Edit Comment..."), 0,
02925                                      this,SLOT(editComment()),
02926                                      actionCollection(), "edit_comment");
02927 
02928     actionAddGuideLine = new KAction( i18n( "Add Guide Line..."), 0,
02929                                       this, SLOT( addGuideLine()),
02930                                       actionCollection(), "add_guideline");
02931 
02932     actionRemoveComment = new KAction( i18n("Remove Comment"), 0,
02933                                        this,SLOT(removeComment()),
02934                                        actionCollection(), "remove_comment");
02935 
02936     actionCopyTextOfComment = new KAction( i18n("Copy Text of Comment..."), 0,
02937                                            this,SLOT(copyTextOfComment()),
02938                                            actionCollection(), "copy_text_comment");
02939 
02940     actionConfigureCompletion = new KAction( i18n( "&Configure Completion..." ), 0,
02941                                              this, SLOT( configureCompletion() ),
02942                                              actionCollection(), "configure_completion" );
02943 
02944     actionZoomMinus = new KAction( i18n( "Zoom Out" ), "viewmag-",0,
02945                                    this, SLOT( zoomMinus() ),
02946                                    actionCollection(), "zoom_minus" );
02947     actionZoomPlus = new KAction( i18n( "Zoom In" ), "viewmag+",0,
02948                                   this, SLOT( zoomPlus() ),
02949                                   actionCollection(), "zoom_plus" );
02950     actionZoomEntirePage = new KAction( i18n( "Zoom Entire Slide" ), 0,
02951                                         this, SLOT( zoomEntirePage() ),
02952                                         actionCollection(), "zoom_entire_page" );
02953 
02954     actionZoomMinus = new KAction( i18n( "Zoom Slide Width" ), 0,
02955                                    this, SLOT( zoomPageWidth() ),
02956                                    actionCollection(), "zoom_page_width" );
02957     actionZoomSelectedObject= new KAction( i18n( "Zoom Selected Objects" ), "viewmagfit",0,
02958                                            this, SLOT( zoomSelectedObject() ),
02959                                            actionCollection(), "zoom_selected_object" );
02960     actionZoomPageHeight= new KAction( i18n( "Zoom Slide Height" ), 0,
02961                                        this, SLOT( zoomPageHeight() ),
02962                                        actionCollection(), "zoom_page_height" );
02963 
02964     actionZoomAllObject= new KAction( i18n( "Zoom All Objects" ), 0,
02965                                       this, SLOT( zoomAllObject() ),
02966                                       actionCollection(), "zoom_all_object" );
02967 
02968     actionFlipHorizontal= new KAction( i18n( "Horizontal Flip" ), 0,
02969                                        this, SLOT( flipHorizontal() ),
02970                                        actionCollection(), "horizontal_flip" );
02971 
02972     actionFlipVertical= new KAction( i18n( "Vertical Flip" ), 0,
02973                                      this, SLOT( flipVertical() ),
02974                                      actionCollection(), "vertical_flip" );
02975 
02976     actionDuplicateObj = new KAction( i18n( "Duplicate Object..." ), 0,
02977                                       this, SLOT( duplicateObj() ),
02978                                       actionCollection(), "duplicate_obj" );
02979 
02980     actionApplyAutoFormat= new KAction( i18n( "Apply Autocorrection" ), 0,
02981                                         this, SLOT( applyAutoFormat() ),
02982                                         actionCollection(), "apply_autoformat" );
02983 
02984     actionCreateStyleFromSelection = new KAction( i18n( "Create Style From Selection..." ), 0,
02985                                                   this, SLOT( createStyleFromSelection()),
02986                                                   actionCollection(), "create_style" );
02987 
02988     actionCloseObject = new KAction( i18n( "Close Object" ), 0,
02989                                      this, SLOT( closeObject()),
02990                                      actionCollection(), "close_object" );
02991 
02992 
02993     actionAlignVerticalTop = new KToggleAction( i18n( "Align Top" ), 0,
02994                                                 this, SLOT( alignVerticalTop() ),
02995                                                 actionCollection(), "align_top" );
02996     actionAlignVerticalTop->setExclusiveGroup( "vertical_alignment" );
02997     actionAlignVerticalTop->setChecked( true );
02998 
02999 
03000     actionAlignVerticalBottom = new KToggleAction( i18n( "Align Bottom" ), 0,
03001                                                    this, SLOT( alignVerticalBottom() ),
03002                                                    actionCollection(), "align_bottom" );
03003     actionAlignVerticalBottom->setExclusiveGroup( "vertical_alignment" );
03004 
03005     actionAlignVerticalCenter = new KToggleAction( i18n( "Align Middle" ), 0,
03006                                                    this, SLOT( alignVerticalCenter() ),
03007                                                    actionCollection(), "align_center" );
03008     actionAlignVerticalCenter->setExclusiveGroup( "vertical_alignment" );
03009 
03010 
03011     actionSavePicture= new KAction( i18n("Save Picture..."), 0,
03012                                     this, SLOT( savePicture() ),
03013                                     actionCollection(), "save_picture");
03014 
03015     actionAllowBgSpellCheck = new KToggleAction( i18n( "Autospellcheck" ), 0,
03016                                                  this, SLOT( autoSpellCheck() ),
03017                                                  actionCollection(), "tool_auto_spellcheck" );
03018 
03019     actionInsertFile= new KAction( i18n( "File..." ), 0,
03020                                    this, SLOT( insertFile() ),
03021                                    actionCollection(), "insert_file" );
03022     actionImportStyle= new KAction( i18n( "Import Styles..." ), 0,
03023                                     this, SLOT( importStyle() ),
03024                                     actionCollection(), "import_style" );
03025 
03026     actionSaveBackgroundPicture= new KAction( i18n( "Save Background Picture..." ), 0,
03027                                               this, SLOT(backgroundPicture() ),
03028                                               actionCollection(), "save_bgpicture" );
03029 #if 0
03030     actionInsertDirectCursor = new KToggleAction( i18n( "Type Anywhere Cursor" ), 0,
03031                                                   this, SLOT( insertDirectCursor() ),
03032                                                   actionCollection(), "direct_cursor" );
03033 #endif
03034 
03035     actionSpellIgnoreAll = new KAction( i18n( "Ignore All" ), 0,
03036                                         this, SLOT( slotAddIgnoreAllWord() ),
03037                                         actionCollection(), "ignore_all" );
03038 
03039     actionAddWordToPersonalDictionary=new KAction( i18n( "Add Word to Dictionary" ),0,
03040                                                    this, SLOT( addWordToDictionary() ),
03041                                                    actionCollection(), "add_word_to_dictionary" );
03042     actionCustomSlideShow = new KAction( i18n( "Custom Slide Show..." ), 0,
03043                                          this, SLOT( customSlideShow() ),
03044                                          actionCollection(), "custom_slide_show" );
03045 
03046     actionDisplayObjectFromMasterPage = new KToggleAction( i18n( "Hide Object From Slide Master" ), 0,
03047                                          this, SLOT( displayObjectFromMasterPage() ),
03048                                          actionCollection(), "display_object_from_master_page" );
03049     actionDisplayObjectFromMasterPage->setCheckedState(i18n("Display Object From Slide Master"));
03050 
03051 
03052     actionDisplayBackgroundPage = new KToggleAction( i18n( "Hide Background" ), 0,
03053                                          this, SLOT( displayBackground() ),
03054                                          actionCollection(), "display_background" );
03055     actionDisplayBackgroundPage->setCheckedState(i18n("Display Background"));
03056 }
03057 
03058 void KPrView::displayObjectFromMasterPage()
03059 {
03060     bool state=actionDisplayObjectFromMasterPage->isChecked();
03061     m_canvas->activePage()->setDisplayObjectFromMasterPage( !state );
03062     KPrDisplayObjectFromMasterPage * cmd =new KPrDisplayObjectFromMasterPage( state ? i18n("Hide Object From Slide Master") : i18n("Display Object From Slide Master"), m_pKPresenterDoc, m_canvas->activePage(), !state);
03063     m_pKPresenterDoc->addCommand(cmd);
03064     m_pKPresenterDoc->updateSideBarItem( m_pKPresenterDoc->masterPage() );
03065 }
03066 
03067 void KPrView::displayBackground()
03068 {
03069     bool state=actionDisplayBackgroundPage->isChecked();
03070     m_canvas->activePage()->setDisplayBackground( !state );
03071     KPrDisplayBackgroundPage * cmd =new KPrDisplayBackgroundPage( state ? i18n("Hide Background") : i18n("Display Background"), m_pKPresenterDoc, m_canvas->activePage(), !state);
03072     m_pKPresenterDoc->addCommand(cmd);
03073     m_pKPresenterDoc->updateSideBarItem( m_pKPresenterDoc->masterPage() );
03074 }
03075 
03076 void KPrView::customSlideShow()
03077 {
03078     KPrCustomSlideShowDia *dlg = new KPrCustomSlideShowDia( this, m_pKPresenterDoc, "custom slide show" );
03079     dlg->exec();
03080     delete dlg;
03081     //clear element
03082     m_pKPresenterDoc->clearTestCustomSlideShow();
03083 }
03084 
03085 void KPrView::textSubScript()
03086 {
03087     m_canvas->setTextSubScript(actionFormatSub->isChecked());
03088 }
03089 
03090 void KPrView::textSuperScript()
03091 {
03092     m_canvas->setTextSuperScript(actionFormatSuper->isChecked());
03093 }
03094 
03095 void KPrView::decreaseFontSize()
03096 {
03097     m_canvas->setDecreaseFontSize();
03098 }
03099 
03100 void KPrView::increaseFontSize()
03101 {
03102     m_canvas->setIncreaseFontSize();
03103 }
03104 
03105 void KPrView::objectSelectedChanged()
03106 {
03107     
03108     bool state=m_canvas->isOneObjectSelected();
03109     bool headerfooterselected=false;
03110 
03111     if (m_canvas->numberOfObjectSelected()==1)
03112     {
03113         KPrObject *obj=m_canvas->getSelectedObj();
03114         //disable this action when we select a header/footer
03115         if (obj==m_pKPresenterDoc->header() || obj==m_pKPresenterDoc->footer())
03116             headerfooterselected=true;
03117         else
03118             headerfooterselected=false;
03119     }
03120     actionScreenAssignEffect->setEnabled(state && !headerfooterselected);
03121     actionEditDelete->setEnabled(state && !headerfooterselected);
03122     actionEditCut->setEnabled(state && !headerfooterselected);
03123 
03124     KPrObjectProperties objectProperties( m_canvas->activePage()->getSelectedObjects() );
03125     int flags = objectProperties.getPropertyFlags();
03126     // only button when object support them or none object is selected
03127     actionBrushColor->setEnabled( !state || ( flags & KPrObjectProperties::PtBrush ) ); 
03128     actionExtraLineBegin->setEnabled( !state || ( flags & KPrObjectProperties::PtLineEnds ) ); 
03129     actionExtraLineEnd->setEnabled( !state || ( flags & KPrObjectProperties::PtLineEnds ) ); 
03130     actionExtraPenWidth->setEnabled( !state || ( flags & KPrObjectProperties::PtPenWidth ) );
03131 
03132     actionExtraProperties->setEnabled(state && !headerfooterselected);
03133     actionExtraRotate->setEnabled(state && !headerfooterselected);
03134     actionExtraShadow->setEnabled(state && !m_canvas->haveASelectedPartObj() && !headerfooterselected);
03135 
03136     actionExtraAlignObjsPopup->setEnabled(state && !headerfooterselected);
03137     actionExtraGroup->setEnabled(state && m_canvas->numberOfObjectSelected()>1);
03138     actionExtraUnGroup->setEnabled(state && m_canvas->haveASelectedGroupObj());
03139 
03140     bool enableAlign = m_canvas->canMoveOneObject() && state && !headerfooterselected;
03141 
03142     actionExtraAlignObjLeft->setEnabled(enableAlign);
03143     actionExtraAlignObjCenterH->setEnabled(enableAlign);
03144     actionExtraAlignObjRight->setEnabled(enableAlign);
03145     actionExtraAlignObjTop->setEnabled(enableAlign);
03146     actionExtraAlignObjCenterV->setEnabled(enableAlign);
03147     actionExtraAlignObjBottom->setEnabled(enableAlign);
03148     //actionEditDelete->setEnabled(state);
03149     int nbobj=m_canvas->numberOfObjectSelected();
03150     actionDuplicateObj->setEnabled(state && (nbobj>=1));
03151 
03152     state = state && (nbobj==1);
03153     actionExtraArrangePopup->setEnabled(state);
03154 
03155     actionExtraRaise->setEnabled( nbobj > 0 );
03156     actionExtraLower->setEnabled( nbobj > 0 );
03157     actionExtraBringForward->setEnabled( nbobj > 0 );
03158     actionExtraSendBackward->setEnabled( nbobj > 0 );
03159 
03160     //actionExtraConfigPicture->setEnabled( state && m_canvas->haveASelectedPixmapObj() );
03161     //actionPenColor->setEnabled(state);
03162     //actionExtraPenStyle->setEnabled(state);
03163     //actionExtraPenWidth->setEnabled(state);
03164 
03165     actionApplyAutoFormat->setEnabled(m_canvas->oneObjectTextExist());
03166     slotObjectEditChanged();
03167 }
03168 
03169 void KPrView::backOk( KPrBackDialog* backDia, bool takeGlobal )
03170 {
03171     KPrPage *page=m_canvas->activePage();
03172     KPrSetBackCmd *setBackCmd = new KPrSetBackCmd( i18n( "Set Background" ),
03173                                              backDia->getBackGround(),
03174                                              page->background()->getBackGround(),
03175                                              backDia->useMasterBackground(),
03176                                              takeGlobal, m_pKPresenterDoc,page);
03177     setBackCmd->execute();
03178     m_pKPresenterDoc->addCommand( setBackCmd );
03179 }
03180 
03181 void KPrView::afChooseOk( const QString & c )
03182 {
03183     QFileInfo fileInfo( c );
03184     QString fileName = locate( "autoforms",
03185                                fileInfo.dirPath( false ) + "/" + fileInfo.baseName() + ".atf",
03186                                KPrFactory::global() );
03187 
03188     deSelectAllObjects();
03189     m_canvas->setToolEditMode( INS_AUTOFORM );
03190     m_canvas->setAutoForm( fileName );
03191 }
03192 
03193 void KPrView::slotAfchooseCanceled()
03194 {
03195     setTool( TEM_MOUSE );
03196 }
03197 
03198 void KPrView::propertiesOk()
03199 {
03200     KCommand *cmd = m_propertyEditor->getCommand();
03201 
03202     if ( cmd )
03203     {
03204         cmd->execute();
03205         kPresenterDoc()->addCommand( cmd );
03206     }
03207 }
03208 
03209 void KPrView::pgConfOk()
03210 {
03211     QValueList<bool> selectedSlides;
03212     for( unsigned i = 0; i < kPresenterDoc()->pageList().count(); i++ ) {
03213         selectedSlides.append( kPresenterDoc()->pageList().at( i )->isSlideSelected() );
03214     }
03215 
03216     KPrPgConfCmd *pgConfCmd = new KPrPgConfCmd( i18n( "Configure Slide Show" ),
03217                                           pgConfDia->getManualSwitch(), pgConfDia->getInfiniteLoop(),
03218                                           pgConfDia->getPresentationDuration(), pgConfDia->getPen(),
03219                                           pgConfDia->getSelectedSlides(),
03220                                           pgConfDia->presentationName(),
03221                                           kPresenterDoc()->spManualSwitch(),
03222                                           kPresenterDoc()->spInfiniteLoop(),
03223                                           kPresenterDoc()->presentationDuration(),
03224                                           kPresenterDoc()->presPen(),
03225                                           selectedSlides,
03226                                           kPresenterDoc()->presentationName(),
03227                                           kPresenterDoc() );
03228     pgConfCmd->execute();
03229     kPresenterDoc()->addCommand( pgConfCmd );
03230 
03231     QPtrListIterator<KPrPage> it( kPresenterDoc()->pageList() );
03232     for ( ; it.current(); ++it )
03233         updateSideBarItem( it.current() );
03234 }
03235 
03236 
03237 void KPrView::rotateOk()
03238 {
03239     float _newAngle=rotateDia->angle();
03240 
03241     KCommand *cmd=m_canvas->activePage()->rotateSelectedObjects(_newAngle);
03242     if( cmd )
03243         kPresenterDoc()->addCommand( cmd );
03244 }
03245 
03246 void KPrView::shadowOk()
03247 {
03248     KCommand *cmd=m_canvas->activePage()->shadowObj(shadowDia->shadowDirection(),
03249                                                     shadowDia->shadowDistance(),
03250                                                     shadowDia->shadowColor());
03251     if( cmd)
03252         kPresenterDoc()->addCommand( cmd );
03253 }
03254 
03255 unsigned int KPrView::getCurrPgNum() const
03256 {
03257     return currPg + 1;
03258 }
03259 
03260 
03261 void KPrView::recalcCurrentPageNum()
03262 {
03263     KPrPage *activePage = m_canvas->activePage();
03264 
03265     QPtrList<KPrPage> pageList( m_pKPresenterDoc->pageList() );
03266 
03267     int pos = pageList.findRef( activePage );
03268 
03269     if ( pos != -1 )
03270     {
03271         currPg = pos;
03272     }
03273     else
03274     {
03275         kdDebug(33001) << "KPrView::recalcCurrentPageNum: activePage not found" << endl;
03276         currPg = 0;
03277     }
03278 
03279     if( sidebar )
03280         sidebar->setCurrentPage( currPg );
03281 }
03282 
03283 
03284 void KPrView::scrollH( int value )
03285 {
03286     if ( !presStarted ) {
03287         m_canvas->scrollX( value );
03288         if ( h_ruler )
03289             h_ruler->setOffset( value, 0 );
03290     }
03291 }
03292 
03293 void KPrView::scrollV( int value )
03294 {
03295     if ( !presStarted ) {
03296         m_canvas->scrollY( value );
03297         if ( v_ruler )
03298             v_ruler->setOffset( 0, value );
03299     }
03300 }
03301 
03302 void KPrView::fontChanged( const QFont &font )
03303 {
03304     tbFont.setFamily( font.family() );
03305     tbFont.setBold( font.bold() );
03306     tbFont.setItalic( font.italic() );
03307     tbFont.setUnderline( font.underline() );
03308     tbFont.setPointSize( font.pointSize() );
03309 
03310     actionTextFontFamily->setFont( tbFont.family() );
03311     actionTextFontSize->setFontSize( tbFont.pointSize() );
03312     actionTextBold->setChecked( tbFont.bold() );
03313     actionTextItalic->setChecked( tbFont.italic() );
03314     actionTextUnderline->setChecked( tbFont.underline() );
03315 }
03316 
03317 void KPrView::colorChanged( const QColor &color )
03318 {
03319     tbColor = color;
03320     actionTextColor->setEnabled( true );
03321     actionTextColor->setCurrentColor( tbColor );
03322 }
03323 
03324 void KPrView::alignChanged( int align )
03325 {
03326     if ( align != tbAlign ) {
03327         tbAlign = align;
03328         if ( ( align & AlignLeft ) == AlignLeft ) {
03329             actionTextAlignLeft->blockSignals( true );
03330             actionTextAlignLeft->setChecked( true );
03331             actionTextAlignLeft->blockSignals( false );
03332         } else if ( ( align & AlignHCenter ) == AlignHCenter ||
03333                     ( align & AlignCenter ) == AlignCenter ) {
03334             actionTextAlignCenter->blockSignals( true );
03335             actionTextAlignCenter->setChecked( true );
03336             actionTextAlignCenter->blockSignals( false );
03337         } else if ( ( align & AlignRight ) == AlignRight ) {
03338             actionTextAlignRight->blockSignals( true );
03339             actionTextAlignRight->setChecked( true );
03340             actionTextAlignRight->blockSignals( false );
03341         } else if ( (align & AlignJustify ) == AlignJustify ) {
03342             actionTextAlignBlock->blockSignals( true );
03343             actionTextAlignBlock->setChecked( true );
03344             actionTextAlignBlock->blockSignals( false );
03345         }
03346     }
03347 }
03348 
03349 void KPrView::changePicture( const QString & filename )
03350 {
03351     QStringList mimetypes;
03352     mimetypes += KImageIO::mimeTypes( KImageIO::Reading );
03353     mimetypes += KoPictureFilePreview::clipartMimeTypes();
03354 
03355     KFileDialog fd( filename, QString::null, this, 0, true );
03356     fd.setCaption(i18n("Select New Picture"));
03357     fd.setMimeFilter( mimetypes );
03358     fd.setPreviewWidget( new KoPictureFilePreview( &fd ) );
03359 
03360     KURL url;
03361     if ( fd.exec() == QDialog::Accepted )
03362         url = fd.selectedURL();
03363 
03364     if( url.isEmpty() || !url.isValid())
03365         return;
03366 
03367     m_canvas->changePicture( url, m_canvas );
03368 }
03369 
03370 void KPrView::resizeEvent( QResizeEvent *e )
03371 {
03372     if ( !presStarted )
03373         QWidget::resizeEvent( e );
03374 
03375     QSize s = e ? e->size() : size();
03376     splitter->setGeometry( 0, 0, s.width(), s.height() );
03377 }
03378 
03379 void KPrView::reorganize()
03380 {
03381     if (m_bShowGUI ) {
03382 
03383         horz->show();
03384         vert->show();
03385         pgNext->show();
03386         pgPrev->show();
03387 
03388         if(kPresenterDoc()->showRuler())
03389         {
03390             int hSpace = v_ruler->minimumSizeHint().width();
03391             int vSpace = h_ruler->minimumSizeHint().height();
03392 
03393             m_canvas->move( hSpace, vSpace );
03394             if ( h_ruler )
03395             {
03396                 h_ruler->show();
03397                 h_ruler->setGeometry( hSpace, 0, m_canvas->width(), vSpace );
03398             }
03399             if (v_ruler )
03400             {
03401                 v_ruler->show();
03402                 v_ruler->setGeometry( 0, vSpace, hSpace, m_canvas->height() );
03403             }
03404             if(getTabChooser())
03405             {
03406                 getTabChooser()->setGeometry(0, 0, hSpace, vSpace);
03407                 getTabChooser()->show();
03408             }
03409         }
03410         else
03411         {
03412             m_canvas->move( 0, 0 );
03413             if ( h_ruler )
03414                 h_ruler->hide();
03415             if ( v_ruler )
03416                 v_ruler->hide();
03417             getTabChooser()->hide();
03418         }
03419 
03420         if( statusBar())
03421         {
03422             if(m_pKPresenterDoc->showStatusBar())
03423                 statusBar()->show();
03424             else
03425                 statusBar()->hide();
03426         }
03427 
03428         setRanges();
03429     }
03430     else
03431     {
03432         horz->hide();
03433         vert->hide();
03434         pgNext->hide();
03435         pgPrev->hide();
03436         h_ruler->hide();
03437         v_ruler->hide();
03438         getTabChooser()->hide();
03439         m_canvas->move( 0, 0 );
03440     }
03441 }
03442 
03443 void PageBase::resizeEvent( QResizeEvent *e )
03444 {
03445     if ( !view->presStarted )
03446         QWidget::resizeEvent( e );
03447 
03448     QSize s = e ? e->size() : size();
03449 
03450     if ( view->m_bShowGUI ) {
03451         int hSpace = view->getVRuler()->minimumSizeHint().width();
03452         int vSpace = view->getVRuler()->minimumSizeHint().height();
03453 
03454         view->m_canvas->resize( s.width() - ( hSpace + 16 ), s.height() - ( vSpace + 16 ) );
03455         view->vert->setGeometry( s.width() - 16, 0, 16, s.height() - 32 );
03456         view->pgPrev->setGeometry( s.width() - 15, s.height() - 32, 15, 16 );
03457         view->pgNext->setGeometry( s.width() - 15, s.height() - 16, 15, 16 );
03458         view->horz->setGeometry( 0, s.height() - 16, s.width() - 16, 16 );
03459     }
03460     else
03461     {
03462         view->m_canvas->move( 0, 0 );
03463         view->m_canvas->resize( s.width(), s.height() );
03464     }
03465     view->reorganize();
03466 }
03467 
03468 void KPrView::dragEnterEvent( QDragEnterEvent *e )
03469 {
03470     QApplication::sendEvent( m_canvas, e );
03471 }
03472 
03473 void KPrView::dragMoveEvent( QDragMoveEvent *e )
03474 {
03475     QApplication::sendEvent( m_canvas, e );
03476 }
03477 
03478 void KPrView::dragLeaveEvent( QDragLeaveEvent *e )
03479 {
03480     QApplication::sendEvent( m_canvas, e );
03481 }
03482 
03483 void KPrView::dropEvent( QDropEvent *e )
03484 {
03485     QApplication::sendEvent( m_canvas, e );
03486 }
03487 
03488 void KPrView::getPageMouseWheelEvent( QWheelEvent *e )
03489 {
03490     QApplication::sendEvent( vert, e );
03491 }
03492 
03493 void KPrView::keyPressEvent( QKeyEvent *e )
03494 {
03495     if ( e->key() == Qt::Key_Delete && !m_canvas->currentTextObjectView() )
03496         editDelete();
03497     else
03498         QApplication::sendEvent( m_canvas, e );
03499 }
03500 
03501 void KPrView::doAutomaticScreenPres()
03502 {
03503     if ( m_autoPresStop ) // A user pushed Escape key or clicked "Exit presentation" menu.
03504         return;
03505     else if ( m_autoPresRestart && kPresenterDoc()->spInfiniteLoop() ) {
03506         m_autoPresRestart = false;
03507         m_canvas->presGotoFirstPage(); // return to first page.
03508     }
03509     else
03510         screenNext();
03511 }
03512 
03513 void KPrView::updateReadWrite( bool readwrite )
03514 {
03515     // First disable or enable everything
03516     QValueList<KAction*> actions = actionCollection()->actions();
03517     // Also grab actions from the document
03518     actions += m_pKPresenterDoc->actionCollection()->actions();
03519     QValueList<KAction*>::ConstIterator aIt = actions.begin();
03520     QValueList<KAction*>::ConstIterator aEnd = actions.end();
03521     for (; aIt != aEnd; ++aIt )
03522         (*aIt)->setEnabled( readwrite );
03523 
03524 
03525     if ( !readwrite )
03526     {
03527         // Readonly -> re-enable a few harmless actions
03528         refreshPageButton();
03529         actionViewFormattingChars->setEnabled( true );
03530         actionViewZoom->setEnabled( true );
03531         actionEditFind->setEnabled( true );
03532         actionEditFindNext->setEnabled( true );
03533         actionEditFindPrevious->setEnabled( true );
03534         actionEditReplace->setEnabled( true );
03535         actionEditSelectAll->setEnabled( true );
03536         actionEditDeSelectAll->setEnabled( true );
03537     }
03538     else
03539     {
03540         refreshPageButton();
03541         objectSelectedChanged();
03542 
03543         refreshCustomMenu();
03544 
03545         // Correctly enable or disable undo/redo actions again
03546         m_pKPresenterDoc->commandHistory()->updateActions();
03547         updateSideBarMenu();
03548     }
03549 
03550 }
03551 
03552 void KPrView::setupPopupMenus()
03553 {
03554     // create right button line begin
03555     rb_lbegin = new QPopupMenu();
03556     Q_CHECK_PTR( rb_lbegin );
03557     rb_lbegin->insertItem( KPBarIcon("line_normal_begin" ), this, SLOT( extraLineBeginNormal() ) );
03558     rb_lbegin->insertSeparator();
03559     rb_lbegin->insertItem( KPBarIcon("line_arrow_begin" ), this, SLOT( extraLineBeginArrow() ) );
03560     rb_lbegin->insertSeparator();
03561     rb_lbegin->insertItem( KPBarIcon("line_rect_begin" ), this, SLOT( extraLineBeginRect() ) );
03562     rb_lbegin->insertSeparator();
03563     rb_lbegin->insertItem( KPBarIcon("line_circle_begin" ), this, SLOT( extraLineBeginCircle() ) );
03564     rb_lbegin->insertSeparator();
03565     rb_lbegin->insertItem( KPBarIcon("line_line_arrow_begin" ), this, SLOT( extraLineBeginLineArrow() ) );
03566     rb_lbegin->insertSeparator();
03567     rb_lbegin->insertItem( KPBarIcon("line_dimension_line_begin" ), this, SLOT( extraLineBeginDimensionLine() ) );
03568     rb_lbegin->insertSeparator();
03569     rb_lbegin->insertItem( KPBarIcon("line_double_arrow_begin" ), this, SLOT( extraLineBeginDoubleArrow() ) );
03570     rb_lbegin->insertSeparator();
03571     rb_lbegin->insertItem( KPBarIcon("line_double_line_arrow_begin" ), this, SLOT( extraLineBeginDoubleLineArrow() ) );
03572     rb_lbegin->setMouseTracking( true );
03573     rb_lbegin->setCheckable( false );
03574 
03575     // create right button line end
03576     rb_lend = new QPopupMenu();
03577     Q_CHECK_PTR( rb_lend );
03578     rb_lend->insertItem( KPBarIcon("line_normal_end" ), this, SLOT( extraLineEndNormal() ) );
03579     rb_lend->insertSeparator();
03580     rb_lend->insertItem( KPBarIcon("line_arrow_end" ), this, SLOT( extraLineEndArrow() ) );
03581     rb_lend->insertSeparator();
03582     rb_lend->insertItem( KPBarIcon("line_rect_end" ), this, SLOT( extraLineEndRect() ) );
03583     rb_lend->insertSeparator();
03584     rb_lend->insertItem( KPBarIcon("line_circle_end" ), this, SLOT( extraLineEndCircle() ) );
03585     rb_lend->insertSeparator();
03586     rb_lend->insertItem( KPBarIcon("line_line_arrow_end" ), this, SLOT( extraLineEndLineArrow() ) );
03587     rb_lend->insertSeparator();
03588     rb_lend->insertItem( KPBarIcon("line_dimension_line_end" ), this, SLOT( extraLineEndDimensionLine() ) );
03589     rb_lend->insertSeparator();
03590     rb_lend->insertItem( KPBarIcon("line_double_arrow_end" ), this, SLOT( extraLineEndDoubleArrow() ) );
03591     rb_lend->insertSeparator();
03592     rb_lend->insertItem( KPBarIcon("line_double_line_arrow_end" ), this, SLOT( extraLineEndDoubleLineArrow() ) );
03593     rb_lend->setMouseTracking( true );
03594     rb_lend->setCheckable( false );
03595 
03596     // create arrange-objects popup
03597     m_arrangeObjectsPopup = new QPopupMenu();
03598     Q_CHECK_PTR(m_arrangeObjectsPopup);
03599     m_arrangeObjectsPopup->insertItem(KPBarIcon("lower"), this, SLOT(extraLower()));
03600     m_arrangeObjectsPopup->insertSeparator();
03601     m_arrangeObjectsPopup->insertItem(KPBarIcon("send_backward"), this, SLOT(extraSendBackward()));
03602     m_arrangeObjectsPopup->insertSeparator();
03603     m_arrangeObjectsPopup->insertItem(KPBarIcon("bring_forward"), this, SLOT(extraBringForward()));
03604     m_arrangeObjectsPopup->insertSeparator();
03605     m_arrangeObjectsPopup->insertItem(KPBarIcon("raise"), this, SLOT(extraRaise()));
03606     m_arrangeObjectsPopup->setMouseTracking(true);
03607     m_arrangeObjectsPopup->setCheckable(false);
03608 
03609     // create insert-line popup
03610     actionToolsLinePopup->insert(actionToolsLine);
03611     actionToolsLinePopup->insert(actionToolsFreehand);
03612     actionToolsLinePopup->insert(actionToolsPolyline);
03613     actionToolsLinePopup->insert(actionToolsCubicBezierCurve);
03614     actionToolsLinePopup->insert(actionToolsQuadricBezierCurve);
03615 
03616     // create insert-shape popup
03617     actionToolsShapePopup->insert(actionToolsRectangle);
03618     actionToolsShapePopup->insert(actionToolsCircleOrEllipse);
03619     actionToolsShapePopup->insert(actionToolsPie);
03620     actionToolsShapePopup->insert(actionToolsConvexOrConcavePolygon);
03621 
03622     // create insert-closed-line popup
03623     actionToolsClosedLinePopup->insert(actionToolsClosedFreehand);
03624     actionToolsClosedLinePopup->insert(actionToolsClosedPolyline);
03625     actionToolsClosedLinePopup->insert(actionToolsClosedQuadricBezierCurve);
03626     actionToolsClosedLinePopup->insert(actionToolsClosedCubicBezierCurve);
03627 
03628     actionExtraAlignObjsPopup->insert( actionExtraAlignObjLeft );
03629     actionExtraAlignObjsPopup->insert( actionExtraAlignObjCenterV );
03630     actionExtraAlignObjsPopup->insert( actionExtraAlignObjRight );
03631     actionExtraAlignObjsPopup->insert( actionExtraAlignObjTop );
03632     actionExtraAlignObjsPopup->insert( actionExtraAlignObjCenterH );
03633     actionExtraAlignObjsPopup->insert( actionExtraAlignObjBottom );
03634 
03635     actionExtraArrangePopup->insert( actionExtraLower );
03636     actionExtraArrangePopup->insert( actionExtraSendBackward );
03637     actionExtraArrangePopup->insert( actionExtraBringForward );
03638     actionExtraArrangePopup->insert( actionExtraRaise );
03639 }
03640 
03641 void KPrView::setupScrollbars()
03642 {
03643     vert = new QScrollBar( QScrollBar::Vertical, pageBase );
03644     horz = new QScrollBar( QScrollBar::Horizontal, pageBase );
03645     vert->show();
03646     horz->show();
03647     QObject::connect( vert, SIGNAL( valueChanged( int ) ), this, SLOT( scrollV( int ) ) );
03648     QObject::connect( horz, SIGNAL( valueChanged( int ) ), this, SLOT( scrollH( int ) ) );
03649     vert->setValue(vert->maxValue());
03650     horz->setValue(horz->maxValue());
03651     vert->setValue(vert->minValue());
03652     horz->setValue(horz->minValue());
03653     pgNext = new QToolButton( pageBase );
03654     pgNext->setPixmap( QPixmap( pagedown_xpm ) );
03655     pgNext->setAutoRepeat( TRUE );
03656     QToolTip::add( pgNext, i18n( "Next slide" ) );
03657     connect( pgNext, SIGNAL( clicked() ), this, SLOT( nextPage() ) );
03658     pgPrev = new QToolButton( pageBase );
03659     pgPrev->setPixmap( QPixmap( pageup_xpm ) );
03660     pgPrev->setAutoRepeat( TRUE );
03661     QToolTip::add( pgPrev, i18n( "Previous slide" ) );
03662     connect( pgPrev, SIGNAL( clicked() ), this, SLOT( prevPage() ) );
03663 }
03664 
03665 void KPrView::setupRulers()
03666 {
03667     tabChooser = new KoTabChooser( pageBase, KoTabChooser::TAB_ALL );
03668     tabChooser->setReadWrite(kPresenterDoc()->isReadWrite());
03669     h_ruler = new KoRuler( pageBase, m_canvas, Qt::Horizontal, kPresenterDoc()->pageLayout(),
03670                            KoRuler::F_INDENTS | KoRuler::F_TABS, kPresenterDoc()->unit(), tabChooser );
03671     h_ruler->changeFlags(0);
03672 
03673     h_ruler->setReadWrite(kPresenterDoc()->isReadWrite());
03674     v_ruler = new KoRuler( pageBase, m_canvas, Qt::Vertical, kPresenterDoc()->pageLayout(), 0, kPresenterDoc()->unit() );
03675     v_ruler->setReadWrite(kPresenterDoc()->isReadWrite());
03676 
03677     int hSpace = v_ruler->minimumSizeHint().width();
03678     int vSpace = h_ruler->minimumSizeHint().height();
03679 
03680     m_canvas->resize( m_canvas->width() - hSpace, m_canvas->height() - vSpace );
03681     m_canvas->move( hSpace, vSpace );
03682     h_ruler->setGeometry( hSpace, 0, m_canvas->width(), vSpace );
03683     v_ruler->setGeometry( 0, vSpace, hSpace, m_canvas->height() );
03684 
03685     QObject::connect( h_ruler, SIGNAL( unitChanged( KoUnit::Unit ) ),
03686                       this, SLOT( unitChanged( KoUnit::Unit ) ) );
03687     QObject::connect( h_ruler, SIGNAL( newPageLayout( const KoPageLayout & ) ),
03688                       this, SLOT( newPageLayout( const KoPageLayout & ) ) );
03689 
03690     connect( h_ruler, SIGNAL( doubleClicked() ), this,
03691              SLOT( slotHRulerDoubleClicked() ) );
03692     connect( h_ruler, SIGNAL( doubleClicked(double) ), this,
03693              SLOT( slotHRulerDoubleClicked(double) ) );
03694 
03695     QObject::connect( v_ruler, SIGNAL( unitChanged( KoUnit::Unit ) ),
03696                       this, SLOT( unitChanged( KoUnit::Unit ) ) );
03697     QObject::connect( v_ruler, SIGNAL( newPageLayout( const KoPageLayout & ) ),
03698                       this, SLOT( newPageLayout( const KoPageLayout & ) ) );
03699     QObject::connect( v_ruler, SIGNAL( doubleClicked() ),
03700                       this, SLOT( openPageLayoutDia() ) );
03701 
03702     connect( h_ruler, SIGNAL( newLeftIndent( double ) ), this, SLOT( newLeftIndent( double ) ) );
03703     connect( h_ruler, SIGNAL( newFirstIndent( double ) ), this, SLOT( newFirstIndent( double ) ) );
03704     connect( h_ruler, SIGNAL( newRightIndent( double ) ), this, SLOT( newRightIndent( double ) ) );
03705 }
03706 
03707 void KPrView::unitChanged( KoUnit::Unit u )
03708 {
03709     m_pKPresenterDoc->setUnit( u );
03710 }
03711 
03712 void KPrView::setRanges()
03713 {
03714     if ( vert && horz && m_canvas && m_pKPresenterDoc ) {
03715         vert->setSteps( 10, m_canvas->height() );
03716         vert->setRange( 0, QMAX( 0, m_canvas->activePage()->getZoomPageRect().height()  - m_canvas->height() ) );
03717         horz->setSteps( 10, m_canvas->width() );
03718         horz->setRange( 0, QMAX( 0, m_canvas->activePage()->getZoomPageRect().width() + 16 - m_canvas->width() ) );
03719     }
03720 }
03721 
03722 void KPrView::skipToPage( int num )
03723 {
03724     setEditMaster( false );
03725     if ( num < 0 || num > static_cast<int>( m_pKPresenterDoc->getPageNums() ) - 1 || !m_canvas )
03726         return;
03727     m_canvas->exitEditMode();
03728     currPg = num;
03729     emit currentPageChanged( currPg );
03730     if( sidebar )
03731         sidebar->setCurrentPage( currPg );
03732     KPrPage* page = m_pKPresenterDoc->pageList().at( currPg );
03733     m_canvas->setActivePage( page );
03734     // don't scroll before new active page is set,
03735     // the page active until then might have been deleted
03736     vert->setValue( 0 );
03737     horz->setValue( 0 );
03738     if ( notebar ) {
03739         QString text = page->noteText( );
03740         notebar->setCurrentNoteText( text );
03741     }
03742     refreshPageButton();
03743     //(Laurent) deselect object when we change page.
03744     //otherwise you can change object properties on other page
03745     deSelectAllObjects();
03746     m_pKPresenterDoc->repaint( FALSE );
03747 
03748     m_pKPresenterDoc->displayActivePage( page );
03749 }
03750 
03751 void KPrView::refreshPageButton()
03752 {
03753     bool state = (currPg > 0);
03754     pgPrev->setEnabled( state );
03755     actionScreenFirst->setEnabled(state);
03756     actionScreenPrev->setEnabled(state);
03757     state=(currPg < (int)m_pKPresenterDoc->getPageNums() - 1);
03758     pgNext->setEnabled( state );
03759     actionScreenLast->setEnabled(state);
03760     actionScreenNext->setEnabled(state);
03761     updateHeaderFooterButton();
03762     updateDisplayObjectMasterPageButton();
03763     updateDisplayBackgroundButton();
03764 }
03765 
03766 void KPrView::showObjectRect( const KPrObject * object )
03767 {
03768     QRect r = zoomHandler()->zoomRect( object->getRealRect() );
03769     if ( ! QRect( getCanvas()->diffx(),
03770                   getCanvas()->diffy(),
03771                   getCanvas()->width(),
03772                   getCanvas()->height() ).contains( r ) )
03773     {
03774         int x = r.left() - 20;
03775         int y = r.top() - 20;
03776         if ( x < 0 )
03777         {
03778             x = 0;
03779         }
03780         if ( y < 0 )
03781         {
03782             y = 0;
03783         }
03784         horz->setValue( x );
03785         vert->setValue( y );
03786     }
03787 }
03788 
03789 void KPrView::setTool( ToolEditMode toolEditMode )
03790 {
03791     switch ( toolEditMode ) {
03792     case TEM_MOUSE:
03793         actionToolsMouse->setChecked( true );
03794         break;
03795     case TEM_ROTATE:
03796         actionToolsRotate->setChecked( true );
03797         break;
03798     case TEM_ZOOM:
03799         actionToolsZoom->setChecked( true );
03800         break;
03801     case INS_LINE:
03802         actionToolsLine->setChecked( true );
03803         break;
03804     case INS_RECT:
03805         actionToolsRectangle->setChecked( true );
03806         break;
03807     case INS_ELLIPSE:
03808         actionToolsCircleOrEllipse->setChecked( true );
03809         break;
03810     case INS_PIE:
03811         actionToolsPie->setChecked( true );
03812         break;
03813     case INS_DIAGRAMM:
03814         actionToolsDiagramm->setChecked( true );
03815         break;
03816     case INS_TABLE:
03817         actionToolsTable->setChecked( true );
03818         break;
03819     case INS_FORMULA:
03820         actionToolsFormula->setChecked( true );
03821         break;
03822     case INS_TEXT:
03823         actionToolsText->setChecked( true );
03824         break;
03825     case INS_AUTOFORM:
03826         actionToolsAutoform->setChecked( true );
03827         break;
03828     default: // Shut up gcc -Wall
03829         break; // Shut up gcc 3.x
03830     }
03831 }
03832 
03833 void KPrView::setRulerMouseShow( bool _show )
03834 {
03835     v_ruler->showMousePos( _show );
03836     h_ruler->showMousePos( _show );
03837 }
03838 
03839 void KPrView::setRulerMousePos( int mx, int my )
03840 {
03841     v_ruler->setMousePos( mx, my );
03842     h_ruler->setMousePos( mx, my );
03843 }
03844 
03845 void KPrView::enableWebPres()
03846 {
03847 }
03848 
03849 void KPrView::enableMSPres()
03850 {
03851 }
03852 
03853 bool KPrView::doubleClickActivation() const
03854 {
03855     return true;
03856 }
03857 
03858 QWidget* KPrView::canvas() const
03859 {
03860     return m_canvas;
03861 }
03862 
03863 int KPrView::canvasXOffset() const
03864 {
03865     return m_canvas->diffx();
03866 }
03867 
03868 int KPrView::canvasYOffset() const
03869 {
03870     return m_canvas->diffy();
03871 }
03872 
03873 void KPrView::setCanvasXOffset( int _x )
03874 {
03875     m_canvas->setDiffX( _x );
03876 }
03877 
03878 void KPrView::setCanvasYOffset( int _y )
03879 {
03880     m_canvas->setDiffY( _y );
03881 }
03882 
03883 int KPrView::getCurrentPresPage() const
03884 {
03885     if ( !presStarted )
03886         return -1;
03887 
03888     return m_canvas->presPage();
03889 }
03890 
03891 int KPrView::getCurrentPresStep() const
03892 {
03893     if ( !presStarted )
03894         return -1;
03895 
03896     return m_canvas->presStep();
03897 }
03898 
03899 int KPrView::getPresStepsOfPage() const
03900 {
03901     if ( !presStarted )
03902         return -1;
03903 
03904     return m_canvas->numPresSteps();
03905 }
03906 
03907 int KPrView::getNumPresPages() const
03908 {
03909     if ( !presStarted )
03910         return -1;
03911 
03912     return m_canvas->numPresPages();
03913 }
03914 
03915 bool KPrView::gotoPresPage( int pg )
03916 {
03917     if ( !presStarted )
03918         return false;
03919 
03920     m_canvas->gotoPage( pg );
03921     return true;
03922 }
03923 
03924 void KPrView::nextPage()
03925 {
03926     // don't move when on master
03927     if ( m_editMaster )
03928         return;
03929 
03930     if ( currPg >= (int)m_pKPresenterDoc->getPageNums() - 1 )
03931         return;
03932 
03933     //kdDebug(33001)<<"currPg :"<<currPg<<"m_pKPresenterDoc->getPageNums() :"<<m_pKPresenterDoc->getPageNums()<<endl;
03934     skipToPage( currPg+1 );
03935 }
03936 
03937 void KPrView::prevPage()
03938 {
03939     // don't move when on master
03940     if ( m_editMaster )
03941         return;
03942 
03943     if ( currPg == 0 )
03944         return;
03945     skipToPage( currPg-1 );
03946 }
03947 
03948 void KPrView::updateSideBar()
03949 {
03950     if ( sidebar )
03951     {
03952         sidebar->blockSignals( TRUE );
03953         sidebar->thumbBar()->uptodate = false;
03954         sidebar->outline()->rebuildItems();
03955         sidebar->thumbBar()->rebuildItems();
03956         sidebar->blockSignals( FALSE );
03957     }
03958 }
03959 
03960 void KPrView::updateSideBarItem( KPrPage * page )
03961 {
03962     if ( sidebar )
03963         sidebar->updateItem( page );
03964     m_pKPresenterDoc->recalcVariables( VT_STATISTIC );
03965 }
03966 
03967 void KPrView::addSideBarItem( int pos )
03968 {
03969     if ( sidebar )
03970     {
03971         sidebar->blockSignals( TRUE );
03972         sidebar->addItem( pos );
03973         sidebar->blockSignals( FALSE );
03974     }
03975 }
03976 
03977 void KPrView::moveSideBarItem( int oldPos, int newPos )
03978 {
03979     if ( sidebar )
03980     {
03981         sidebar->blockSignals( TRUE );
03982         sidebar->moveItem( oldPos, newPos );
03983         sidebar->blockSignals( FALSE );
03984     }
03985 }
03986 
03987 void KPrView::removeSideBarItem( int pos )
03988 {
03989     if ( sidebar )
03990     {
03991         sidebar->blockSignals( TRUE );
03992         sidebar->removeItem( pos );
03993         sidebar->blockSignals( FALSE );
03994     }
03995 }
03996 
03997 void KPrView::updatePageInfo()
03998 {
03999     if (m_sbPageLabel)
04000         m_sbPageLabel->setText( QString(" ") +
04001                                 i18n("Slide %1/%2").arg(getCurrPgNum()).arg(m_pKPresenterDoc->getPageNums())+
04002                                 QString(" ") );
04003 }
04004 
04005 void KPrView::updateObjectStatusBarItem()
04006 {
04007     KStatusBar * sb = statusBar();
04008     int nbObjects = m_canvas->objNums();
04009 
04010     if ( m_pKPresenterDoc->showStatusBar() && sb && nbObjects > 0 ) {
04011         int nbSelected = m_canvas->numberOfObjectSelected();
04012 
04013         if (nbSelected == 1) {
04014             KoUnit::Unit unit = m_pKPresenterDoc->unit();
04015             //QString unitName = m_pKPresenterDoc->unitName();
04016             KPrObject * obj = m_canvas->getSelectedObj();
04017             KoSize size = obj->getSize();
04018             m_sbObjectLabel->setText( ' ' + i18n( "Statusbar info", "%1: %2, %3 - %4, %5 (width: %6, height: %7)" )
04019                     .arg( /*frame->frameSet()->name()*/obj->getObjectName() )
04020                     .arg( KoUnit::toUserStringValue( obj->getOrig().x(), unit ) )
04021                     .arg( KoUnit::toUserStringValue( obj->getOrig().y() , unit) )
04022                     .arg( KoUnit::toUserStringValue( obj->getOrig().x() + size.width(), unit ) )
04023                     .arg( KoUnit::toUserStringValue( obj->getOrig().y() + size.height(), unit ) )
04024                     .arg( KoUnit::toUserStringValue( size.width(), unit ) )
04025                     .arg( KoUnit::toUserStringValue( size.height(), unit ) ) );
04026         }
04027         else
04028             m_sbObjectLabel->setText( i18n("1 object selected", "%n objects selected", nbSelected) );
04029     }
04030     else if ( sb && m_sbObjectLabel )
04031         m_sbObjectLabel->setText( QString::null );
04032 }
04033 
04034 void KPrView::pageNumChanged()
04035 {
04036     updatePageInfo();
04037 }
04038 
04039 void KPrView::viewShowSideBar()
04040 {
04041     if ( !sidebar )
04042         return;
04043     if ( sidebar->isVisible() )
04044         sidebar->hide();
04045     else
04046         sidebar->show();
04047 }
04048 
04049 void KPrView::viewShowNoteBar()
04050 {
04051     if ( !notebar )
04052         return;
04053     if ( notebar->isVisible() )
04054         notebar->hide();
04055     else
04056         notebar->show();
04057 }
04058 
04059 void KPrView::viewSlideMaster()
04060 {
04061     bool state =  actionViewSlideMaster->isChecked();
04062     setEditMaster( state );
04063     //not activate action when slide master is displaying
04064     state = !state;
04065     m_actionExtraHeader->setEnabled( state );
04066     m_actionExtraFooter->setEnabled( state );
04067     actionDisplayBackgroundPage->setEnabled( state );
04068     actionDisplayObjectFromMasterPage->setEnabled( state );
04069 
04070 }
04071 
04072 void KPrView::setEditMaster( bool editMaster )
04073 {
04074     if ( m_editMaster != editMaster )
04075     {
04076         m_canvas->exitEditMode();
04077         m_canvas->deSelectAllObj();
04078         m_editMaster = editMaster;
04079         if ( m_editMaster )
04080         {
04081             m_canvas->setActivePage( m_pKPresenterDoc->masterPage() );
04082             pgPrev->setEnabled( false );
04083             actionScreenFirst->setEnabled( false );
04084             actionScreenPrev->setEnabled( false );
04085             pgNext->setEnabled( false  );
04086             actionScreenLast->setEnabled( false );
04087             actionScreenNext->setEnabled( false );
04088             actionEditCopyPage->setEnabled( false );
04089             actionEditDuplicatePage->setEnabled( false );
04090             actionEditDelPage->setEnabled( false );
04091             actionViewSlideMaster->setChecked( true );
04092         }
04093         else
04094         {
04095             m_canvas->setActivePage( m_pKPresenterDoc->pageList().at( currPg ) );
04096             actionEditCopyPage->setEnabled( true );
04097             actionEditDuplicatePage->setEnabled( true );
04098             actionEditDelPage->setEnabled( m_pKPresenterDoc->getPageNums() > 1 );
04099             actionViewSlideMaster->setChecked( false );
04100             refreshPageButton();
04101         }
04102         if ( sidebar )
04103             sidebar->setViewMasterPage( m_editMaster );
04104         updateNoteBarText();
04105         m_canvas->repaint( false );
04106     }
04107 }
04108 
04109 void KPrView::updateNoteBarText()
04110 {
04111     if ( notebar ) {
04112         if ( m_editMaster )
04113         {
04114             QString text = m_pKPresenterDoc->masterPage()->noteText();
04115             notebar->setCurrentNoteText( text );
04116         }
04117         else
04118         {
04119             QString text = m_pKPresenterDoc->pageList().at( currPg )->noteText( );
04120             notebar->setCurrentNoteText( text );
04121         }
04122     }
04123 }
04124 
04125 void KPrView::openPopupMenuMenuPage( const QPoint & _point )
04126 {
04127     if(!koDocument()->isReadWrite() || !factory())
04128         return;
04129     QPtrList<KAction> actionList= QPtrList<KAction>();
04130     KActionSeparator *separator=new KActionSeparator();
04131     switch( m_canvas->activePage()->getBackType())
04132     {
04133     case BT_COLOR:
04134     case BT_BRUSH:
04135         break;
04136     case BT_PICTURE:
04137     case BT_CLIPART:
04138         actionList.append(separator);
04139         actionList.append(actionSaveBackgroundPicture);
04140         break;
04141     }
04142     if ( actionList.count()>0)
04143         plugActionList( "picture_action", actionList );
04144     m_mousePos = m_canvas->mapFromGlobal( _point );
04145     QPopupMenu* menu = dynamic_cast<QPopupMenu*>(factory()->container("menupage_popup",this));
04146     if ( menu )
04147         menu->exec(_point);
04148     m_mousePos = QPoint( 0, 0 );
04149     unplugActionList( "picture_action" );
04150     delete separator;
04151 }
04152 
04153 void KPrView::openPopupMenuObject( const QString & name, const QPoint & _point )
04154 {
04155     if(!koDocument()->isReadWrite() || !factory())
04156         return;
04157     dynamic_cast<QPopupMenu*>(factory()->container(name, this))->popup(_point);
04158 }
04159 
04160 void KPrView::openPopupMenuSideBar(const QPoint & _point)
04161 {
04162     if(!koDocument()->isReadWrite() || !factory())
04163         return;
04164     dynamic_cast<QPopupMenu*>(factory()->container("sidebarmenu_popup", this))->popup(_point);
04165 }
04166 
04167 void KPrView::renamePageTitle()
04168 {
04169     if(sidebar)
04170         sidebar->renamePageTitle();
04171 }
04172 
04173 void KPrView::picViewOriginalSize()
04174 {
04175     m_canvas->picViewOriginalSize();
04176 }
04177 
04178 void KPrView::picViewOrig640x480()
04179 {
04180     m_canvas->picViewOrig640x480();
04181 }
04182 
04183 void KPrView::picViewOrig800x600()
04184 {
04185     m_canvas->picViewOrig800x600();
04186 }
04187 
04188 void KPrView::picViewOrig1024x768()
04189 {
04190     m_canvas->picViewOrig1024x768();
04191 }
04192 
04193 void KPrView::picViewOrig1280x1024()
04194 {
04195     m_canvas->picViewOrig1280x1024();
04196 }
04197 
04198 void KPrView::picViewOrig1600x1200()
04199 {
04200     m_canvas->picViewOrig1600x1200();
04201 }
04202 
04203 void KPrView::chPic()
04204 {
04205     m_canvas->chPic();
04206 }
04207 
04208 void KPrView::penColorChanged( const KoPen & _pen )
04209 {
04210     //actionPenColor->setEnabled( true );
04211     actionPenColor->setCurrentColor( _pen.color() );
04212 }
04213 
04214 void KPrView::brushColorChanged( const QBrush & _brush )
04215 {
04216     //actionBrushColor->setEnabled( true );
04217     actionBrushColor->setCurrentColor(_brush.style ()==Qt::NoBrush ? Qt::white : _brush.color() );
04218 }
04219 
04220 void KPrView::restartAutoPresTimer()
04221 {
04222     m_autoPresTime.start();
04223     m_autoPresElapsedTime = 0;
04224     m_autoPresTimer.start( m_autoPresTimerValue, true );
04225 }
04226 
04227 void KPrView::continueAutoPresTimer()
04228 {
04229     m_autoPresTime.restart();
04230     //m_autoPresTimer.changeInterval( m_autoPresTimerValue - m_autoPresElapsedTime );
04231     m_autoPresTimer.start( m_autoPresTimerValue - m_autoPresElapsedTime, true );
04232 }
04233 
04234 void KPrView::stopAutoPresTimer()
04235 {
04236     m_autoPresTimer.stop();
04237     m_autoPresElapsedTime += m_autoPresTime.elapsed();
04238 }
04239 
04240 void KPrView::setAutoPresTimer( int sec )
04241 {
04242     m_autoPresTimerValue = sec * 1000;
04243     restartAutoPresTimer();
04244 }
04245 
04246 void KPrView::insertSpecialChar()
04247 {
04248     KPrTextView *edit=m_canvas->currentTextObjectView();
04249     if ( !edit )
04250         return;
04251     QString f = edit->textFontFamily();
04252     QChar c=' ';
04253     if (m_specialCharDlg==0)
04254     {
04255         m_specialCharDlg = new KoCharSelectDia( this, "insert special char", f, c, false );
04256         connect( m_specialCharDlg, SIGNAL(insertChar(QChar,const QString &)),
04257                  this, SLOT(slotSpecialChar(QChar,const QString &)));
04258         connect( m_specialCharDlg, SIGNAL( finished() ),
04259                  this, SLOT( slotSpecialCharDlgClosed() ) );
04260     }
04261     m_specialCharDlg->show();
04262 }
04263 
04264 void KPrView::slotSpecialCharDlgClosed()
04265 {
04266     if ( m_specialCharDlg)
04267     {
04268         disconnect( m_specialCharDlg, SIGNAL(insertChar(QChar,const QString &)),
04269                     this, SLOT(slotSpecialChar(QChar,const QString &)));
04270         disconnect( m_specialCharDlg, SIGNAL( finished() ),
04271                     this, SLOT( slotSpecialCharDlgClosed() ) );
04272         m_specialCharDlg->deleteLater();
04273         m_specialCharDlg = 0L;
04274     }
04275 }
04276 
04277 void KPrView::slotSpecialChar(QChar c, const QString &_font)
04278 {
04279     KPrTextView *edit=m_canvas->currentTextObjectView();
04280     if ( !edit )
04281         return;
04282     edit->insertSpecialChar(c, _font);
04283 }
04284 
04285 void KPrView::insertLink()
04286 {
04287     KPrTextView *edit=m_canvas->currentTextObjectView();
04288     if ( !edit )
04289         return;
04290     QString link;
04291     QString ref;
04292     if ( edit->textObject()->hasSelection() )
04293     {
04294         QString selectedText = edit->textObject()->selectedText();
04295         if ( edit->textObject()->selectionHasCustomItems() || selectedText.contains('\n') )
04296             return;
04297         if ( selectedText.startsWith( "mailto:/" ) ||
04298              selectedText.startsWith( "ftp:/" ) ||
04299              selectedText.startsWith( "http:/" ) )
04300         {
04301             link=selectedText;
04302             ref = selectedText;
04303         }
04304         else
04305         {
04306             //Just add text as link name and not url
04307             link = selectedText;
04308         }
04309     }
04310 
04311     if(KoInsertLinkDia::createLinkDia(link, ref, QStringList(), false, this))
04312     {
04313         if(!link.isEmpty() && !ref.isEmpty())
04314             edit->insertLink(link, ref);
04315     }
04316 }
04317 
04318 void KPrView::changeLink()
04319 {
04320     KPrTextView * edit = m_canvas->currentTextObjectView();
04321     if ( edit )
04322     {
04323         KoLinkVariable * var=edit->linkVariable();
04324         if(var)
04325         {
04326             QString oldhref= var->url();
04327             QString oldLinkName=var->value();
04328             QString link=oldLinkName;
04329             QString ref=oldhref;
04330             if(KoInsertLinkDia::createLinkDia(link, ref, QStringList(), false, this))
04331             {
04332                 if(!link.isEmpty() && !ref.isEmpty())
04333                 {
04334                     if( ref != oldhref || link!=oldLinkName)
04335                     {
04336                         KPrChangeLinkVariable*cmd=new KPrChangeLinkVariable( i18n("Change Link"),
04337                                                                              m_pKPresenterDoc, oldhref,
04338                                                                              ref, oldLinkName,link, var);
04339                         cmd->execute();
04340                         m_pKPresenterDoc->addCommand(cmd);
04341                     }
04342                 }
04343             }
04344         }
04345     }
04346 }
04347 
04348 void KPrView::showFormat( const KoTextFormat &currentFormat )
04349 {
04350     actionTextFontFamily->setFont( currentFormat.font().family() );
04351     actionTextFontSize->setFontSize( currentFormat.pointSize() );
04352     actionTextBold->setChecked( currentFormat.font().bold());
04353     actionTextItalic->setChecked( currentFormat.font().italic() );
04354     actionTextUnderline->setChecked( currentFormat.underline());
04355     actionFormatStrikeOut->setChecked( currentFormat.strikeOut());
04356 
04357     actionBrushColor->setEnabled(true);
04358     //actionBrushColor->setText(i18n("Text Background Color..."));
04359 
04360     switch(currentFormat.vAlign())
04361     {
04362     case KoTextFormat::AlignSuperScript:
04363     {
04364         actionFormatSub->setChecked( false );
04365         actionFormatSuper->setChecked( true );
04366         break;
04367     }
04368     case KoTextFormat::AlignSubScript:
04369     {
04370         actionFormatSub->setChecked( true );
04371         actionFormatSuper->setChecked( false );
04372         break;
04373     }
04374     case KoTextFormat::AlignNormal:
04375     default:
04376     {
04377         actionFormatSub->setChecked( false );
04378         actionFormatSuper->setChecked( false );
04379         break;
04380     }
04381     }
04382 }
04383 
04384 void KPrView::slotSoftHyphen()
04385 {
04386     KPrTextView *edit = m_canvas->currentTextObjectView();
04387     if ( edit )
04388         edit->insertSoftHyphen();
04389 }
04390 
04391 void KPrView::slotNonbreakingSpace()
04392 {
04393     KPrTextView *edit=m_canvas->currentTextObjectView();
04394     if ( edit )
04395         edit->insertNonbreakingSpace();
04396 }
04397 
04398 void KPrView::slotNonbreakingHyphen()
04399 {
04400     KPrTextView *edit=m_canvas->currentTextObjectView();
04401     if ( edit )
04402         edit->insertNonbreakingHyphen();
04403 }
04404 
04405 void KPrView::slotLineBreak()
04406 {
04407     KPrTextView *edit=m_canvas->currentTextObjectView();
04408     if ( edit )
04409         edit->insertLineBreak();
04410 }
04411 
04412 void KPrView::slotIncreaseNumberingLevel()
04413 {
04414     KPrTextView *edit=m_canvas->currentTextObjectView();
04415     if ( edit )
04416     {
04417         edit->increaseNumberingLevel( m_pKPresenterDoc->styleCollection() );
04418     }
04419 }
04420 
04421 void KPrView::slotDecreaseNumberingLevel()
04422 {
04423     KPrTextView *edit=m_canvas->currentTextObjectView();
04424     if ( edit )
04425         edit->decreaseNumberingLevel( m_pKPresenterDoc->styleCollection() );
04426 }
04427 
04428 void KPrView::extraAutoFormat()
04429 {
04430     m_pKPresenterDoc->getAutoFormat()->readConfig();
04431     KoAutoFormatDia dia( this, 0, m_pKPresenterDoc->getAutoFormat() );
04432     dia.exec();
04433     m_pKPresenterDoc->startBackgroundSpellCheck(); // will do so if enabled
04434 }
04435 
04436 void KPrView::slotSpellCheck()
04437 {
04438     if (m_spell.kospell) return; // Already in progress
04439     //m_doc->setReadWrite(false); // prevent editing text - not anymore
04440     m_spell.macroCmdSpellCheck = 0L;
04441     m_spell.replaceAll.clear();
04442     QValueList<KoTextObject *> objects;
04443     KPrTextView *edit=m_canvas->currentTextObjectView();
04444     int options = 0;
04445     if ( edit && edit->textObject()->hasSelection() )
04446     {
04447         objects.append(edit->kpTextObject()->textObject());
04448         options = KFindDialog::SelectedText;
04449     }
04450     else
04451     {
04452         objects = spellAddTextObject();
04453         QPtrList<KPrObject> lstObj;
04454     }
04455     if ( ! objects.empty() )
04456     {
04457         m_spell.textIterator = new KoTextIterator( objects, edit, options );
04458         startKSpell();
04459     }
04460 }
04461 
04462 QValueList<KoTextObject *> KPrView::spellAddTextObject() const
04463 {
04464     QValueList<KoTextObject *> lst;
04465     QPtrList<KPrObject> lstObj;
04466     m_canvas->activePage()->getAllObjectSelectedList(lstObj, true);
04467     QPtrListIterator<KPrObject> it( lstObj );
04468     for ( ; it.current() ; ++it )
04469     {
04470         if(it.current()->getType()==OT_TEXT)
04471         {
04472             KPrTextObject* tmp = dynamic_cast<KPrTextObject*>(it.current() );
04473             if ( tmp && !tmp->isProtectContent())
04474                 lst.append( tmp->textObject() );
04475         }
04476     }
04477     return lst;
04478 }
04479 
04480 
04481 
04482 void KPrView::startKSpell()
04483 {
04484     // m_spellCurrFrameSetNum is supposed to be set by the caller of this method
04485     if ( !m_spell.kospell )
04486         m_spell.kospell = new KoSpell( m_broker, this  );
04487     m_spell.kospell->check( m_spell.textIterator, true );
04488 
04489     delete m_spell.dlg;
04490     m_spell.dlg = new KSpell2::Dialog( m_spell.kospell, this );
04491     m_spell.dlg->activeAutoCorrect( true );
04492     QObject::connect( m_spell.dlg, SIGNAL(misspelling(const QString&, int)),
04493                       this, SLOT(spellCheckerMisspelling(const QString&, int)) );
04494     QObject::connect( m_spell.dlg, SIGNAL(replace(const QString&, int, const QString&)),
04495                       this, SLOT(spellCheckerCorrected(const QString&, int, const QString&)) );
04496     QObject::connect( m_spell.dlg, SIGNAL(done(const QString&) ),
04497                       this, SLOT(spellCheckerDone(const QString&)) );
04498     QObject::connect( m_spell.dlg, SIGNAL(cancel() ),
04499                       this, SLOT( spellCheckerCancel() ) );
04500     QObject::connect( m_spell.dlg, SIGNAL(autoCorrect(const QString &, const QString & ) ),
04501                       this, SLOT( spellAddAutoCorrect (const QString &, const QString &) ) );
04502 
04503     m_spell.dlg->show();
04504 }
04505 
04506 
04507 
04508 void KPrView::spellCheckerCancel()
04509 {
04510     kdDebug()<<"void KPrView::spellCheckerCancel() \n";
04511     spellCheckerRemoveHighlight();
04512     clearSpellChecker(true);
04513 }
04514 
04515 
04516 void KPrView::spellCheckerRemoveHighlight()
04517 {
04518     KoTextObject* textobj = m_spell.kospell->currentTextObject();
04519     if ( textobj ) {
04520         KPrTextDocument *textdoc=static_cast<KPrTextDocument *>( textobj->textDocument() );
04521         if ( textdoc )
04522             textdoc->textObject()->removeHighlight();
04523     }
04524     KPrTextView *edit=m_canvas->currentTextObjectView();
04525     if (edit)
04526         edit->drawCursor( TRUE );
04527 }
04528 
04529 
04530 void KPrView::clearSpellChecker(bool cancelSpellCheck)
04531 {
04532     kdDebug() << "KPrView::clearSpellChecker()" << endl;
04533     delete m_spell.textIterator;
04534     m_spell.textIterator = 0L;
04535 
04536 
04537     delete m_spell.kospell;
04538     m_spell.kospell = 0;
04539     m_initSwitchPage = -1;
04540     m_switchPage = -1;
04541 
04542     if ( m_spell.macroCmdSpellCheck )
04543     {
04544         if ( !cancelSpellCheck )
04545             m_pKPresenterDoc->addCommand(m_spell.macroCmdSpellCheck);
04546         else
04547         {
04548             //reverte all changes
04549             m_spell.macroCmdSpellCheck->unexecute();
04550             delete m_spell.macroCmdSpellCheck;
04551         }
04552     }
04553     m_spell.macroCmdSpellCheck=0L;
04554 
04555     m_spell.replaceAll.clear();
04556 
04557 }
04558 
04559 void KPrView::spellCheckerMisspelling( const QString &old, int pos )
04560 {
04561     //kdDebug(32001) << "KWView::spellCheckerMisspelling old=" << old << " pos=" << pos << endl;
04562     KoTextObject* textobj = m_spell.kospell->currentTextObject();
04563     KoTextParag* parag = m_spell.kospell->currentParag();
04564     Q_ASSERT( textobj );
04565     Q_ASSERT( parag );
04566     if ( !textobj || !parag ) return;
04567     KPrTextDocument *textdoc=static_cast<KPrTextDocument *>( textobj->textDocument() );
04568     Q_ASSERT( textdoc );
04569     if ( !textdoc ) return;
04570     pos += m_spell.kospell->currentStartIndex();
04571 
04572     kdDebug() << "KWView::spellCheckerMisspelling parag=" << parag->paragId() << " pos=" << pos << " length=" << old.length() << endl;
04573 
04574     textdoc->textObject()->highlightPortion( parag, pos, old.length(), m_canvas,true/*repaint*/ );
04575 }
04576 
04577 void KPrView::spellCheckerCorrected( const QString &old, int pos, const QString &corr )
04578 {
04579     //kdDebug(33001) << "KWView::spellCheckerCorrected old=" << old << " corr=" << corr << " pos=" << pos << endl;
04580 
04581     //kdDebug(32001) << "KWView::spellCheckerCorrected old=" << old << " corr=" << corr << " pos=" << pos << endl;
04582     KoTextObject* textobj = m_spell.kospell->currentTextObject();
04583     KoTextParag* parag = m_spell.kospell->currentParag();
04584     Q_ASSERT( textobj );
04585     Q_ASSERT( parag );
04586     if ( !textobj || !parag ) return;
04587 
04588     KPrTextDocument *textdoc=static_cast<KPrTextDocument *>( textobj->textDocument() );
04589     Q_ASSERT( textdoc );
04590     if ( !textdoc )
04591         return;
04592     pos += m_spell.kospell->currentStartIndex();
04593     textdoc->textObject()->highlightPortion( parag, pos, old.length(), m_canvas,true/*repaint*/ );
04594 
04595     KoTextCursor cursor( textdoc );
04596     cursor.setParag( parag );
04597     cursor.setIndex( pos );
04598     if(!m_spell.macroCmdSpellCheck)
04599         m_spell.macroCmdSpellCheck=new KMacroCommand(i18n("Correct Misspelled Word"));
04600     m_spell.macroCmdSpellCheck->addCommand(textobj->replaceSelectionCommand(&cursor, corr, QString::null, KoTextDocument::HighlightSelection));
04601 }
04602 
04603 void KPrView::spellCheckerDone( const QString & )
04604 {
04605     /* See also KWView::spellCheckerDone from KWord */
04606     kdDebug() << "KPrView::spellCheckerDone" << endl;
04607     KPrTextDocument *textdoc=static_cast<KPrTextDocument *>( m_spell.kospell->textDocument() );
04608     Q_ASSERT( textdoc );
04609     if ( textdoc )
04610         textdoc->textObject()->removeHighlight();
04611 
04612     clearSpellChecker();
04613 }
04614 
04615 void KPrView::showCounter( KoParagCounter &c )
04616 {
04617     QString styleStr("counterstyle_");
04618     styleStr += QString::number( c.style() );
04619     //kdDebug(33001) << "KWView::showCounter styleStr=" << styleStr << endl;
04620     KToggleAction* act = static_cast<KToggleAction *>( actionCollection()->action( styleStr.latin1() ) );
04621     Q_ASSERT( act );
04622     if ( act )
04623         act->setChecked( true );
04624 }
04625 
04626 void KPrView::formatParagraph()
04627 {
04628     showParagraphDialog();
04629 }
04630 
04631 void KPrView::showParagraphDialog(int initialPage, double initialTabPos)
04632 {
04633     QPtrList<KoTextFormatInterface> lst = m_canvas->applicableTextInterfaces();
04634     if ( lst.isEmpty() )
04635         return;
04636     QPtrList<KPrTextObject> lstObjects = m_canvas->applicableTextObjects();
04637     if ( lstObjects.isEmpty() )
04638         return;
04639 
04640     delete m_paragDlg;
04641     m_paragDlg = new KoParagDia( this, "",
04642                                  KoParagDia::PD_SPACING | KoParagDia::PD_ALIGN |
04643                                  KoParagDia::PD_DECORATION | KoParagDia::PD_NUMBERING |
04644                                  KoParagDia::PD_TABS,
04645                                  m_pKPresenterDoc->unit(),
04646                                  lstObjects.first()->getSize().width(),false );
04647     m_paragDlg->setCaption( i18n( "Paragraph Settings" ) );
04648 
04649     // Initialize the dialog from the current paragraph's settings
04650     m_paragDlg->setParagLayout( * lst.first()->currentParagLayoutFormat() );
04651     // Set initial page and initial tabpos if necessary
04652     if ( initialPage != -1 )
04653     {
04654         m_paragDlg->setCurrentPage( initialPage );
04655         if ( initialPage == KoParagDia::PD_TABS )
04656             m_paragDlg->tabulatorsWidget()->setCurrentTab( initialTabPos );
04657     }
04658     connect( m_paragDlg, SIGNAL( applyParagStyle() ), this, SLOT( slotApplyParag() ) );
04659 
04660     m_paragDlg->exec();
04661     delete m_paragDlg;
04662     m_paragDlg = 0;
04663 
04664 }
04665 
04666 void KPrView::slotApplyParag()
04667 {
04668     QPtrList<KoTextFormatInterface> lst = m_canvas->applicableTextInterfaces();
04669     Q_ASSERT( !lst.isEmpty() );
04670     if ( lst.isEmpty() ) return;
04671     QPtrListIterator<KoTextFormatInterface> it( lst );
04672     KMacroCommand * macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
04673     KoParagLayout newLayout = m_paragDlg->paragLayout();
04674     int flags = m_paragDlg->changedFlags();
04675     kdDebug() << k_funcinfo << "flags=" << flags << endl;
04676     if ( !flags )
04677         return;
04678     for ( ; it.current() ; ++it )
04679     {
04680         KCommand* cmd = it.current()->setParagLayoutFormatCommand( &newLayout, flags );
04681         Q_ASSERT( cmd );
04682         if(cmd)
04683         {
04684             macroCommand->addCommand(cmd);
04685         }
04686     }
04687 
04688     if(flags)
04689         m_pKPresenterDoc->addCommand(macroCommand);
04690     else
04691         delete macroCommand;
04692 
04693     // Set "oldLayout" in KoParagDia from the current paragraph's settings
04694     // Otherwise "isBlahChanged" will return wrong things when doing A -> B -> A
04695     m_paragDlg->setParagLayout( *lst.first()->currentParagLayoutFormat() );
04696 }
04697 
04698 void KPrView::textDefaultFormat()
04699 {
04700     m_canvas->setTextDefaultFormat( );
04701 }
04702 
04703 void KPrView::changeNbOfRecentFiles(int _nb)
04704 {
04705     if ( shell() ) // 0 when embedded into konq !
04706         shell()->setMaxRecentItems( _nb );
04707 }
04708 
04709 QPopupMenu * KPrView::popupMenu( const QString& name )
04710 {
04711     Q_ASSERT(factory());
04712     if ( factory() )
04713         return ((QPopupMenu*)factory()->container( name, this ));
04714     return 0L;
04715 }
04716 
04717 void KPrView::addVariableActions( int type, const QStringList & texts,
04718                                          KActionMenu * parentMenu, const QString & menuText )
04719 {
04720     // Single items go directly into parentMenu.
04721     // For multiple items we create a submenu.
04722     if ( texts.count() > 1 && !menuText.isEmpty() )
04723     {
04724         KActionMenu * subMenu = new KActionMenu( menuText, actionCollection() );
04725         parentMenu->insert( subMenu );
04726         parentMenu = subMenu;
04727     }
04728     QStringList::ConstIterator it = texts.begin();
04729     for ( int i = 0; it != texts.end() ; ++it, ++i )
04730     {
04731         if ( !(*it).isEmpty() ) // in case of removed subtypes or placeholders
04732         {
04733             VariableDef v;
04734             v.type = type;
04735             v.subtype = i;
04736             KAction * act = new KAction( (*it), 0, this, SLOT( insertVariable() ),
04737                                          actionCollection(), "var-action" );
04738             m_variableDefMap.insert( act, v );
04739             parentMenu->insert( act );
04740         }
04741     }
04742 }
04743 
04744 void KPrView::refreshCustomMenu()
04745 {
04746     KActionPtrList lst2 = actionCollection()->actions("custom-variable-action");
04747     QValueList<KAction *> actions = lst2;
04748     QValueList<KAction *>::ConstIterator it2 = lst2.begin();
04749     QValueList<KAction *>::ConstIterator end = lst2.end();
04750     QMap<QString, KShortcut> shortCuts;
04751 
04752     for (; it2 != end; ++it2 )
04753     {
04754         shortCuts.insert((*it2)->text(), (*it2)->shortcut());
04755         delete *it2;
04756     }
04757 
04758     delete actionInsertCustom;
04759     actionInsertCustom = new KActionMenu( i18n( "&Custom" ),
04760                                           actionCollection(), "insert_custom" );
04761 
04762     actionInsertVariable->insert(actionInsertCustom, 0);
04763 
04764 
04765     actionInsertCustom->popupMenu()->clear();
04766     QPtrListIterator<KoVariable> it( m_pKPresenterDoc->getVariableCollection()->getVariables() );
04767     KAction * act=0;
04768     QStringList lst;
04769     QString varName;
04770     int i = 0;
04771     for ( ; it.current() ; ++it )
04772     {
04773         KoVariable *var = it.current();
04774         if ( var->type() == VT_CUSTOM )
04775         {
04776             varName=( (KoCustomVariable*) var )->name();
04777             if ( !lst.contains( varName) )
04778             {
04779                 lst.append( varName );
04780                 QCString name = QString("custom-action_%1").arg(i).latin1();
04781                 act = new KAction( varName, shortCuts[varName], this,
04782                                    SLOT( insertCustomVariable() ), actionCollection(), name );
04783 
04784                 act->setGroup( "custom-variable-action" );
04785                 actionInsertCustom->insert( act );
04786                 i++;
04787             }
04788         }
04789     }
04790     bool state=!lst.isEmpty();
04791     if(state)
04792         actionInsertCustom->popupMenu()->insertSeparator();
04793 
04794     act = new KAction( i18n("New..."), 0, this, SLOT( insertNewCustomVariable() ), actionCollection(),
04795                        QString("custom-action_%1").arg(i).latin1() );
04796     act->setGroup( "custom-variable-action" );
04797     actionInsertCustom->insert( act );
04798 
04799     actionInsertCustom->popupMenu()->insertSeparator();
04800 
04801     actionEditCustomVars->setEnabled(state);
04802     actionEditCustomVarsEdit->setEnabled( state );
04803     actionInsertCustom->insert( actionEditCustomVarsEdit );
04804 }
04805 
04806 void KPrView::insertCustomVariable()
04807 {
04808     KPrTextView *edit=m_canvas->currentTextObjectView();
04809     if ( edit )
04810     {
04811         KAction * act = (KAction *)(sender());
04812         edit->insertCustomVariable(act->text());
04813     }
04814 }
04815 
04816 void KPrView::insertNewCustomVariable()
04817 {
04818     KPrTextView *edit=m_canvas->currentTextObjectView();
04819     if ( edit )
04820         edit->insertVariable( VT_CUSTOM, 0 );
04821 }
04822 
04823 void KPrView::editCustomVariable()
04824 {
04825     KPrTextView *edit=m_canvas->currentTextObjectView();
04826     if ( edit )
04827     {
04828         KoCustomVariable *var = static_cast<KoCustomVariable *>(edit->variable());
04829         if (var)
04830         {
04831             QString oldvalue = var->value();
04832             KoCustomVarDialog dia( this, var );
04833             if ( dia.exec() )
04834             {
04835                 if( var->value() != oldvalue )
04836                 {
04837                     KPrChangeCustomVariableValue *cmd=new KPrChangeCustomVariableValue(i18n( "Change Custom Variable" ),
04838                                                                                        m_pKPresenterDoc, oldvalue, var->value(), var );
04839                     m_pKPresenterDoc->addCommand(cmd);
04840                 }
04841                 m_pKPresenterDoc->recalcVariables( VT_CUSTOM );
04842             }
04843         }
04844     }
04845 }
04846 
04847 void KPrView::editCustomVars()
04848 {
04849     KoCustomVariablesDia dia( this, m_pKPresenterDoc->getVariableCollection()->getVariables() );
04850     QStringList listOldCustomValue;
04851     QPtrListIterator<KoVariable> oldIt( m_pKPresenterDoc->getVariableCollection()->getVariables() );
04852     for ( ; oldIt.current() ; ++oldIt )
04853     {
04854         if(oldIt.current()->type()==VT_CUSTOM)
04855             listOldCustomValue.append(((KoCustomVariable*)oldIt.current())->value());
04856     }
04857     if(dia.exec())
04858     {
04859         m_pKPresenterDoc->recalcVariables( VT_CUSTOM );
04860         QPtrListIterator<KoVariable> it( m_pKPresenterDoc->getVariableCollection()->getVariables() );
04861         KMacroCommand * macroCommand = 0L;
04862         int i=0;
04863         for ( ; it.current() ; ++it )
04864         {
04865             if(it.current()->type() == VT_CUSTOM )
04866             {
04867                 if(((KoCustomVariable*)it.current())->value()!=*(listOldCustomValue.at(i)))
04868                 {
04869                     if(!macroCommand)
04870                         macroCommand = new KMacroCommand( i18n( "Change Custom Variable" ) );
04871                     KPrChangeCustomVariableValue *cmd=
04872                         new KPrChangeCustomVariableValue(i18n( "Change Custom Variable" ), m_pKPresenterDoc,
04873                                                          *(listOldCustomValue.at(i)),
04874                                                          ((KoCustomVariable*)it.current())->value(),
04875                                                          ((KoCustomVariable*)it.current()));
04876                     macroCommand->addCommand(cmd);
04877                 }
04878                 i++;
04879             }
04880         }
04881         if(macroCommand)
04882             m_pKPresenterDoc->addCommand(macroCommand);
04883     }
04884 }
04885 
04886 void KPrView::insertVariable()
04887 {
04888     KPrTextView *edit=m_canvas->currentTextObjectView();
04889     if ( edit )
04890     {
04891         KAction * act = (KAction *)(sender());
04892         VariableDefMap::ConstIterator it = m_variableDefMap.find( act );
04893         if ( it == m_variableDefMap.end() )
04894             kdWarning(33001) << "Action not found in m_variableDefMap." << endl;
04895         else
04896         {
04897             if ( (*it).type == VT_FIELD )
04898                 edit->insertVariable( (*it).type, KoFieldVariable::fieldSubType( (*it).subtype ) );
04899             else
04900                 edit->insertVariable( (*it).type, (*it).subtype );
04901         }
04902     }
04903 }
04904 
04905 void KPrView::openLink()
04906 {
04907     KPrTextView *edit=m_canvas->currentTextObjectView();
04908     if ( edit )
04909         edit->openLink();
04910 }
04911 
04912 void KPrView::showRulerIndent( double _leftMargin, double _firstLine, double _rightMargin, bool rtl )
04913 {
04914     KoRuler * hRuler = getHRuler();
04915     if ( hRuler )
04916     {
04917         hRuler->setFirstIndent( KoUnit::toUserValue( _firstLine, m_pKPresenterDoc->unit() ) );
04918         hRuler->setLeftIndent( KoUnit::toUserValue( _leftMargin, m_pKPresenterDoc->unit() ) );
04919         hRuler->setRightIndent( KoUnit::toUserValue( _rightMargin, m_pKPresenterDoc->unit() ) );
04920         hRuler->setDirection( rtl );
04921         actionTextDepthMinus->setEnabled( _leftMargin>0);
04922     }
04923 }
04924 
04925 void KPrView::tabListChanged( const KoTabulatorList & tabList )
04926 {
04927     if(!m_pKPresenterDoc->isReadWrite())
04928         return;
04929 
04930     m_canvas->setTabList( tabList );
04931 }
04932 
04933 void KPrView::newFirstIndent( double _firstIndent )
04934 {
04935     m_canvas->setNewFirstIndent(_firstIndent);
04936 }
04937 
04938 void KPrView::newLeftIndent( double _leftIndent)
04939 {
04940     m_canvas->setNewLeftIndent(_leftIndent);
04941 }
04942 
04943 void KPrView::newRightIndent( double _rightIndent)
04944 {
04945     m_canvas->setNewRightIndent(_rightIndent);
04946 }
04947 
04948 void KPrView::slotUpdateRuler()
04949 {
04950     // Set the "frame start" in the ruler (tabs are relative to that position)
04951     bool isText=!m_canvas->applicableTextObjects().isEmpty();
04952     if ( isText )
04953     {
04954         KPrTextObject *txtobj= m_canvas->applicableTextObjects().first();
04955         if ( txtobj )
04956         {
04957             QRect r= zoomHandler()->zoomRect(txtobj->getRealRect());
04958             getHRuler()->setFrameStartEnd( r.left() /*+ m_canvas->diffx()*//*- pc.x()*/, r.right()/*+m_canvas->diffx()*/ /*- pc.x()*/ );
04959             getVRuler()->setFrameStartEnd( r.top()/*+ m_canvas->diffy()*//*- pc.y()*/, r.bottom()/*+m_canvas->diffy()*//*- pc.y()*/ );
04960             if( getHRuler())
04961             {
04962                 int flags = txtobj->isProtectContent() ? 0 : (KoRuler::F_INDENTS | KoRuler::F_TABS);
04963                 if( getHRuler()->flags()!= flags )
04964                 {
04965                     getHRuler()->changeFlags(flags);
04966                     getHRuler()->repaint();
04967                 }
04968             }
04969             if( getVRuler())
04970             {
04971                 if( getVRuler()->flags() != 0 )
04972                 {
04973                     getVRuler()->changeFlags(0);
04974                     getVRuler()->repaint();
04975                 }
04976             }
04977         }
04978     }
04979     else
04980     {
04981         refreshRuler( kPresenterDoc()->showGuideLines() );
04982         updateRuler();
04983     }
04984 }
04985 
04986 // This handles Tabulators _only_
04987 void KPrView::slotHRulerDoubleClicked( double ptpos )
04988 {
04989     showParagraphDialog( KoParagDia::PD_TABS, ptpos );
04990 }
04991 
04992 // This handles either:
04993 // - Indents
04994 // - Page Layout
04995 //
04996 // This does _not_ handle Tabulators!
04997 void KPrView::slotHRulerDoubleClicked()
04998 {
04999     KoRuler *ruler = getHRuler();
05000 
05001     if ( m_canvas && m_canvas->currentTextObjectView() && (ruler->flags() & KoRuler::F_INDENTS) && ruler->doubleClickedIndent() )
05002         formatParagraph();
05003     else
05004         openPageLayoutDia();
05005 }
05006 
05007 void KPrView::changeCaseOfText()
05008 {
05009     QPtrList<KoTextFormatInterface> lst = m_canvas->applicableTextInterfaces();
05010     if ( lst.isEmpty() ) return;
05011     QPtrListIterator<KoTextFormatInterface> it( lst );
05012     KoChangeCaseDia *caseDia=new KoChangeCaseDia( this,"change case" );
05013     if(caseDia->exec())
05014     {
05015         KMacroCommand* macroCmd = 0L;
05016         for ( ; it.current() ; ++it )
05017         {
05018             KCommand *cmd = it.current()->setChangeCaseOfTextCommand(caseDia->getTypeOfCase());
05019             if (cmd)
05020             {
05021                 if ( !macroCmd )
05022                     macroCmd = new KMacroCommand( i18n("Change Case of Text") );
05023                 macroCmd->addCommand(cmd);
05024             }
05025         }
05026         if( macroCmd )
05027             m_pKPresenterDoc->addCommand(macroCmd);
05028     }
05029     delete caseDia;
05030 }
05031 
05032 void KPrView::editFind()
05033 {
05034     if (!m_searchEntry)
05035         m_searchEntry = new KoSearchContext();
05036     KPrTextView * edit = m_canvas->currentTextObjectView();
05037     bool hasSelection = edit && (edit->kpTextObject())->textObject()->hasSelection();
05038     bool hasCursor = edit != 0;
05039     KoSearchDia dialog( m_canvas, "find", m_searchEntry, hasSelection, hasCursor );
05040 
05042     QValueList<KoTextObject *> list;
05043     QPtrList<KoTextObject> list2 = m_pKPresenterDoc->allTextObjects();
05044     QPtrListIterator<KoTextObject> it( list2 );
05045     for ( ; it.current() ; ++it )
05046         list.append(it.current());
05047 
05048     if( list.isEmpty() )
05049         return;
05050 
05051     if ( dialog.exec() == QDialog::Accepted )
05052     {
05053         delete m_findReplace;
05054         m_findReplace = new KPrFindReplace( this, m_canvas, &dialog, list, edit );
05055         editFindNext();
05056     }
05057 }
05058 
05059 void KPrView::editReplace()
05060 {
05061     if (!m_searchEntry)
05062         m_searchEntry = new KoSearchContext();
05063     if (!m_replaceEntry)
05064         m_replaceEntry = new KoSearchContext();
05065 
05066     KPrTextView * edit = m_canvas->currentTextObjectView();
05067     bool hasSelection = edit && (edit->kpTextObject())->textObject()->hasSelection();
05068     bool hasCursor = edit != 0;
05069     KoReplaceDia dialog( m_canvas, "replace", m_searchEntry, m_replaceEntry, hasSelection, hasCursor );
05070 
05072     QValueList<KoTextObject *> list;
05073     QPtrList<KoTextObject> list2 = m_pKPresenterDoc->allTextObjects();
05074     QPtrListIterator<KoTextObject> it( list2 );
05075     for ( ; it.current() ; ++it )
05076         list.append(it.current());
05077 
05078     if( list.isEmpty() )
05079         return;
05080 
05081     if ( dialog.exec() == QDialog::Accepted )
05082     {
05083         delete m_findReplace;
05084         m_findReplace = new KPrFindReplace( this, m_canvas, &dialog, list, edit );
05085         editFindNext();
05086     }
05087 }
05088 
05089 void KPrView::editFindPrevious()
05090 {
05091     if ( !m_findReplace ) // shouldn't be called before find or replace is activated
05092     {
05093         editFind();
05094         return;
05095     }
05096     (void) m_findReplace->findPrevious();
05097 }
05098 
05099 void KPrView::editFindNext()
05100 {
05101     if ( !m_findReplace ) // shouldn't be called before find or replace is activated
05102     {
05103         editFind();
05104         return;
05105     }
05106     (void) m_findReplace->findNext();
05107 }
05108 
05109 void KPrView::refreshAllVariable()
05110 {
05111     m_pKPresenterDoc->recalcVariables( VT_ALL );
05112 }
05113 
05114 void KPrView::changeZoomMenu( int zoom )
05115 {
05116     QStringList lst;
05117     lst << i18n( "Width" );
05118     lst << i18n( "Whole Slide" );
05119 
05120     if(zoom>0)
05121     {
05122         QValueList<int> list;
05123         bool ok;
05124         const QStringList itemsList ( actionViewZoom->items() );
05125         QRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
05126 
05127         for (QStringList::ConstIterator it = itemsList.begin() ; it != itemsList.end() ; ++it)
05128         {
05129             regexp.search(*it);
05130             const int val=regexp.cap(1).toInt(&ok);
05131             //zoom : limit inferior=10
05132             if(ok && val>9 && list.contains(val)==0)
05133                 list.append( val );
05134         }
05135         //necessary at the beginning when we read config
05136         //this value is not in combo list
05137         if(list.contains(zoom)==0)
05138             list.append( zoom );
05139 
05140         qHeapSort( list );
05141 
05142         for (QValueList<int>::Iterator it = list.begin() ; it != list.end() ; ++it)
05143             lst.append( i18n("%1%").arg(*it) );
05144     }
05145     else
05146     {
05147         lst << i18n("%1%").arg("33");
05148         lst << i18n("%1%").arg("50");
05149         lst << i18n("%1%").arg("75");
05150         lst << i18n("%1%").arg("100");
05151         lst << i18n("%1%").arg("125");
05152         lst << i18n("%1%").arg("150");
05153         lst << i18n("%1%").arg("200");
05154         lst << i18n("%1%").arg("250");
05155         lst << i18n("%1%").arg("350");
05156         lst << i18n("%1%").arg("400");
05157         lst << i18n("%1%").arg("450");
05158         lst << i18n("%1%").arg("500");
05159     }
05160     actionViewZoom->setItems( lst );
05161 }
05162 
05163 void KPrView::showZoom( int zoom )
05164 {
05165     QStringList list = actionViewZoom->items();
05166     QString zoomStr( i18n("%1%").arg( zoom ) );
05167     int pos = list.findIndex(zoomStr);
05168     if( pos == -1)
05169     {
05170         changeZoomMenu( zoom );
05171         list = actionViewZoom->items();
05172     }
05173     actionViewZoom->setCurrentItem( list.findIndex(zoomStr)  );
05174 }
05175 
05176 void KPrView::viewZoom( const QString &s )
05177 {
05178     bool ok=false;
05179     int zoom = 0;
05180     if ( s == i18n("Width") )
05181     {
05182         zoom = qRound( static_cast<double>(m_canvas->visibleRect().width() * 100 ) /
05183                        (zoomHandler()->resolutionX() * m_pKPresenterDoc->pageLayout().ptWidth ) );
05184         ok = true;
05185     }
05186     else if ( s == i18n("Whole Slide") )
05187     {
05188         zoom = getZoomEntirePage();
05189         ok = true;
05190     }
05191     else
05192     {
05193         QRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
05194         regexp.search(s);
05195         zoom=regexp.cap(1).toInt(&ok);
05196     }
05197     if( !ok || zoom<10 ) //zoom should be valid and >10
05198         zoom = zoomHandler()->zoom();
05199     zoom = QMIN( zoom, 4000);
05200     //refresh menu
05201     changeZoomMenu( zoom );
05202     //refresh menu item
05203     showZoom(zoom);
05204     //apply zoom if zoom!=m_doc->zoom()
05205     if( zoom != zoomHandler()->zoom() )
05206     {
05207         setZoom( zoom, true );
05208         KPrTextView *edit=m_canvas->currentTextObjectView();
05209         if ( edit )
05210             edit->ensureCursorVisible();
05211     }
05212 
05213     m_canvas->setFocus();
05214     m_canvas->repaint();
05215 }
05216 
05217 void KPrView::setZoomRect( const KoRect & rect )
05218 {
05219     double height = zoomHandler()->resolutionY() * rect.height();
05220     double width = zoomHandler()->resolutionX() * rect.width();
05221     int zoom = QMIN( qRound( static_cast<double>( m_canvas->visibleRect().height() * 100 ) / height ),
05222             qRound( static_cast<double>( m_canvas->visibleRect().width() * 100 ) / width ) );
05223 
05224     m_canvas->setUpdatesEnabled( false );
05225     viewZoom( QString::number( zoom ) );
05226 
05227     m_canvas->setToolEditMode( TEM_MOUSE );
05228     m_canvas->scrollTopLeftPoint( zoomHandler()->zoomPoint( rect.topLeft() ) );
05229     m_canvas->setUpdatesEnabled( true );
05230     m_canvas->repaint();
05231 }
05232 
05233 void KPrView::setZoom( int zoom, bool updateViews )
05234 {
05235     zoomHandler()->setZoomAndResolution( zoom, KoGlobal::dpiX(),
05236                                          KoGlobal::dpiY());
05237     m_pKPresenterDoc->newZoomAndResolution(updateViews,false);
05238     m_pKPresenterDoc->updateZoomRuler();
05239 
05240     setRanges();
05241 
05242     if ( statusBar() )
05243       m_sbZoomLabel->setText( ' ' + QString::number( zoom ) + "% " );
05244 }
05245 
05246 void KPrView::slotUpdateScrollBarRanges()
05247 {
05248     setRanges();
05249 }
05250 
05251 KoTextZoomHandler *KPrView::zoomHandler() const
05252 {
05253     return m_pKPresenterDoc->zoomHandler();
05254 }
05255 
05256 void KPrView::slotViewFormattingChars()
05257 {
05258     m_pKPresenterDoc->setViewFormattingChars(actionViewFormattingChars->isChecked());
05259     m_pKPresenterDoc->layout(); // Due to the different formatting when this option is activated
05260     m_pKPresenterDoc->repaint(false);
05261 }
05262 
05263 void KPrView::setPageDuration( int _pgNum )
05264 {
05265     if ( kPresenterDoc()->presentationDuration() )
05266     {
05267         // kdDebug(33001) << "KPrView::setPageDuration( " << _pgNum << " )" << endl;
05268         *m_presentationDurationList.at( _pgNum ) += m_duration.elapsed();
05269         m_duration.restart();
05270     }
05271 }
05272 
05273 void KPrView::openThePresentationDurationDialog()
05274 {
05275     int totalTime = 0;
05276     QStringList presentationDurationStringList;
05277     for ( QValueList<int>::Iterator it = m_presentationDurationList.begin();
05278           it != m_presentationDurationList.end(); ++it ) {
05279         int _time = *it;
05280         QString presentationDurationString = presentationDurationDataFormatChange( _time );
05281         presentationDurationStringList.append( presentationDurationString );
05282         totalTime += _time;
05283     }
05284 
05285     QString presentationTotalDurationString = presentationDurationDataFormatChange( totalTime );
05286 
05287     delete presDurationDia;
05288     presDurationDia = 0;
05289 
05290     presDurationDia = new KPrPresDurationDia( this, "presDurationDia", kPresenterDoc(),
05291                                              presentationDurationStringList, presentationTotalDurationString );
05292     presDurationDia->setCaption( i18n( "Presentation Duration" ) );
05293     QObject::connect( presDurationDia, SIGNAL( presDurationDiaClosed() ), this, SLOT( pddClosed() ) );
05294     presDurationDia->exec();
05295 
05296     delete presDurationDia;
05297     presDurationDia = 0;
05298 }
05299 
05300 void KPrView::pddClosed()
05301 {
05302     presDurationDia = 0;
05303 }
05304 
05305 // change from milliseconds to hh:mm:ss
05306 // in kdelibs 3.2.90, an additional method was added that basically
05307 // allows formatting of time as a duration. Before this, you can get
05308 // weirdness (such as a duration of 12:00:03 am) depending on how the
05309 // time format is set.
05310 QString KPrView::presentationDurationDataFormatChange( int _time )
05311 {
05312     QTime time( 0, 0, 0 );
05313     return KGlobal::locale()->formatTime( time.addMSecs( _time ), true, true );
05314 }
05315 
05316 
05317 void KPrView::viewFooter()
05318 {
05319     bool state = m_actionExtraFooter->isChecked();
05320     m_canvas->activePage()->setFooter( state );
05321     KPrHideShowHeaderFooter * cmd =new KPrHideShowHeaderFooter( state ? i18n("Enable Document Header") : i18n("Disable Document Header"),
05322                                                                 m_pKPresenterDoc, m_canvas->activePage(), state, m_pKPresenterDoc->footer());
05323     m_pKPresenterDoc->addCommand(cmd);
05324 
05325     m_pKPresenterDoc->updateSideBarItem( m_pKPresenterDoc->masterPage() );
05326 }
05327 
05328 void KPrView::viewHeader()
05329 {
05330     bool state = m_actionExtraHeader->isChecked();
05331     m_canvas->activePage()->setHeader( state );
05332     KPrHideShowHeaderFooter * cmd =new KPrHideShowHeaderFooter( state ? i18n("Enable Document Footer") : i18n("Disable Document Footer"),
05333                                                                 m_pKPresenterDoc, m_canvas->activePage(), state, m_pKPresenterDoc->header());
05334     m_pKPresenterDoc->addCommand(cmd);
05335 
05336     m_pKPresenterDoc->updateSideBarItem( m_pKPresenterDoc->masterPage() );
05337 }
05338 
05339 void KPrView::showStyle( const QString & styleName )
05340 {
05341     KoParagStyle* style = m_pKPresenterDoc->styleCollection()->findStyle( styleName );
05342     if ( style ) {
05343         int pos = m_pKPresenterDoc->styleCollection()->indexOf( style );
05344         // Select style in combo
05345         actionFormatStyle->setCurrentItem( pos );
05346     }
05347 }
05348 
05349 void KPrView::updateStyleList()
05350 {
05351     QString currentStyle = actionFormatStyle->currentText();
05352     // Generate list of styles
05353     const QStringList lst = m_pKPresenterDoc->styleCollection()->displayNameList();
05354     const int pos = lst.findIndex( currentStyle );
05355     // Fill the combo - using a KSelectAction
05356     actionFormatStyle->setItems( lst );
05357     if ( pos > -1 )
05358         actionFormatStyle->setCurrentItem( pos );
05359 
05360     // Fill the menu - using a KActionMenu, so that it's possible to bind keys
05361     // to individual actions
05362     QStringList lstWithAccels;
05363     // Generate unique accelerators for the menu items
05364     KAccelGen::generate( lst, lstWithAccels );
05365     QMap<QString, KShortcut> shortCuts;
05366 
05367     KActionPtrList lst2 = actionCollection()->actions("styleList");
05368     QValueList<KAction *> actions = lst2;
05369     QValueList<KAction *>::ConstIterator it = lst2.begin();
05370     QValueList<KAction *>::ConstIterator end = lst2.end();
05371     for (; it != end; ++it )
05372     {
05373         shortCuts.insert( QString::fromUtf8( (*it)->name() ), (*it)->shortcut() );
05374         actionFormatStyleMenu->remove( *it );
05375         delete *it;
05376     }
05377 
05378 
05379     uint i = 0;
05380     for ( QStringList::Iterator it = lstWithAccels.begin(); it != lstWithAccels.end(); ++it, ++i )
05381     {
05382         KoParagStyle *style = m_pKPresenterDoc->styleCollection()->styleAt( i );
05383         if ( style )
05384         {
05385             QString name = "paragstyle_" + style->name();
05386             KToggleAction* act = new KToggleAction( (*it),
05387                                      shortCuts[name], this, SLOT( slotStyleSelected() ),
05388                                      actionCollection(), name.utf8() );
05389             act->setGroup( "styleList" );
05390             act->setExclusiveGroup( "styleListAction" );
05391             act->setToolTip( i18n( "Apply a paragraph style" ) );
05392             actionFormatStyleMenu->insert( act );
05393         }
05394     }
05395     bool isText=!m_canvas->applicableTextInterfaces().isEmpty();
05396     actionFormatStyleMenu->setEnabled( isText );
05397     actionFormatStyle->setEnabled(isText);
05398 }
05399 
05400 void KPrView::extraStylist()
05401 {
05402     KPrTextView *edit=m_canvas->currentTextObjectView();
05403     QString activeStyleName  = QString::null;
05404     if ( edit )
05405     {
05406         edit->hideCursor();
05407         if (edit->cursor() && edit->cursor()->parag() && edit->cursor()->parag()->style())
05408             activeStyleName = edit->cursor()->parag()->style()->displayName();
05409     }
05410     KPrStyleManager * styleManager = new KPrStyleManager( this, m_pKPresenterDoc->unit(), m_pKPresenterDoc,
05411                                                           *m_pKPresenterDoc->styleCollection(), activeStyleName);
05412     styleManager->exec();
05413     delete styleManager;
05414     if ( edit )
05415         edit->showCursor();
05416 }
05417 
05418 // Called when selecting a style in the Format / Style menu
05419 void KPrView::slotStyleSelected()
05420 {
05421     QString actionName = QString::fromUtf8(sender()->name());
05422     kdDebug(33001) << "KPrView::slotStyleSelected " << actionName << endl;
05423     textStyleSelected( m_pKPresenterDoc->styleCollection()->findStyle( actionName ) );
05424 }
05425 
05426 void KPrView::textStyleSelected( int index )
05427 {
05428     textStyleSelected( m_pKPresenterDoc->styleCollection()->styleAt( index ) );
05429 }
05430 
05431 void KPrView::textStyleSelected( KoParagStyle *_sty )
05432 {
05433     if ( !_sty )
05434         return;
05435 
05436     KPrTextView *edit=m_canvas->currentTextObjectView();
05437     if(edit)
05438     {
05439         edit->applyStyle( _sty );
05440         m_canvas->setFocus();
05441     }
05442     else
05443     {
05444         QPtrList<KPrTextObject> selectedFrames = m_canvas->selectedTextObjs();
05445 
05446         if (selectedFrames.count() <= 0)
05447             return; // nope, no frames are selected.
05448         // yes, indeed frames are selected.
05449         QPtrListIterator<KPrTextObject> it( selectedFrames );
05450         KMacroCommand *globalCmd = 0L;
05451         for ( ; it.current() ; ++it )
05452         {
05453             KoTextObject *textObject = it.current()->textObject();
05454             textObject->textDocument()->selectAll( KoTextDocument::Temp );
05455             KCommand *cmd = textObject->applyStyleCommand( 0L, _sty,
05456                                                            KoTextDocument::Temp, KoParagLayout::All, KoTextFormat::Format,
05457                                                            true, true );
05458             textObject->textDocument()->removeSelection( KoTextDocument::Temp );
05459             if (cmd)
05460             {
05461                 if ( !globalCmd)
05462                     globalCmd = new KMacroCommand( selectedFrames.count() == 1 ? i18n("Apply Style to Frame") :
05463                                                    i18n("Apply Style to Frames"));
05464                 globalCmd->addCommand( cmd );
05465             }
05466         }
05467         if ( globalCmd )
05468             m_pKPresenterDoc->addCommand( globalCmd );
05469     }
05470 
05471 }
05472 
05473 void KPrView::slotAllowAutoFormat()
05474 {
05475     bool state = actionAllowAutoFormat->isChecked();
05476     m_pKPresenterDoc->setAllowAutoFormat( state );
05477 }
05478 
05479 void KPrView::slotCompletion()
05480 {
05481     KPrTextView *edit=m_canvas->currentTextObjectView();
05482     if(edit)
05483         edit->completion();
05484 }
05485 
05486 void KPrView::insertComment()
05487 {
05488     KPrTextView *edit=m_canvas->currentTextObjectView();
05489     if ( !edit )
05490         return;
05491     QString authorName;
05492     KoDocumentInfo * info = m_pKPresenterDoc->documentInfo();
05493     KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
05494     if ( !authorPage )
05495         kdWarning() << "Author information not found in documentInfo !" << endl;
05496     else
05497         authorName = authorPage->fullName();
05498 
05499     KoCommentDia *commentDia = new KoCommentDia( this, QString::null,authorName );
05500     if( commentDia->exec() )
05501         edit->insertComment(commentDia->commentText());
05502     delete commentDia;
05503 }
05504 
05505 void KPrView::editComment()
05506 {
05507     KPrTextView *edit=m_canvas->currentTextObjectView();
05508     if ( edit )
05509     {
05510         KoVariable * tmpVar=edit->variable();
05511         KoNoteVariable * var = dynamic_cast<KoNoteVariable *>(tmpVar);
05512         if(var)
05513         {
05514             QString authorName;
05515             KoDocumentInfo * info = m_pKPresenterDoc->documentInfo();
05516             KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
05517             if ( !authorPage )
05518                 kdWarning() << "Author information not found in documentInfo !" << endl;
05519             else
05520                 authorName = authorPage->fullName();
05521             QString oldValue = var->note();
05522             QString createDate = var->createdNote();
05523             KoCommentDia *commentDia = new KoCommentDia( this, oldValue, authorName, createDate);
05524 
05525             if( commentDia->exec() )
05526             {
05527                 if ( oldValue != commentDia->commentText())
05528                 {
05529                     KPrChangeVariableNoteText *cmd = new KPrChangeVariableNoteText( i18n("Change Note Text"), m_pKPresenterDoc, oldValue,commentDia->commentText(), var);
05530                     m_pKPresenterDoc->addCommand( cmd );
05531                     cmd->execute();
05532                 }
05533             }
05534             delete commentDia;
05535         }
05536     }
05537 }
05538 
05539 void KPrView::viewGuideLines()
05540 {
05541     bool state=actionViewShowGuideLine->isChecked();
05542     m_pKPresenterDoc->setShowGuideLines( state );
05543     m_pKPresenterDoc->updateGuideLineButton();
05544     deSelectAllObjects();
05545     refreshRuler( state );
05546     m_pKPresenterDoc->repaint(false);
05547 }
05548 
05549 
05550 void KPrView::viewGrid()
05551 {
05552     m_pKPresenterDoc->setShowGrid( actionViewShowGrid->isChecked() );
05553     m_pKPresenterDoc->setModified( true );
05554     m_pKPresenterDoc->updateGridButton();
05555     m_pKPresenterDoc->repaint(false);
05556 }
05557 
05558 
05559 void KPrView::updateGuideLineButton()
05560 {
05561     bool state = m_pKPresenterDoc->showGuideLines();
05562     actionViewShowGuideLine->setChecked( state );
05563     refreshRuler( state );
05564 }
05565 
05566 void KPrView::updateGridButton()
05567 {
05568     actionViewShowGrid->setChecked( m_pKPresenterDoc->showGrid() );
05569     actionViewSnapToGrid->setChecked ( m_pKPresenterDoc->snapToGrid() );
05570 }
05571 
05572 void KPrView::refreshRuler( bool state )
05573 {
05574     if( getHRuler() )
05575     {
05576 
05577         if ( !m_pKPresenterDoc->isReadWrite())
05578         {
05579             getHRuler()->changeFlags(KoRuler::F_NORESIZE);
05580             getHRuler()->repaint();
05581         }
05582         else
05583         {
05584             if( state )
05585             {
05586                 if( getHRuler()->flags() != KoRuler::F_HELPLINES )
05587                 {
05588                     getHRuler()->changeFlags(KoRuler::F_HELPLINES);
05589                     getHRuler()->repaint();
05590                 }
05591             }
05592             else
05593             {
05594                 if( getHRuler()->flags() != 0 )
05595                 {
05596                     getHRuler()->changeFlags( 0 );
05597                     getHRuler()->repaint();
05598                 }
05599             }
05600         }
05601     }
05602 
05603     if( getVRuler())
05604     {
05605         if ( !m_pKPresenterDoc->isReadWrite())
05606         {
05607             getVRuler()->changeFlags(KoRuler::F_NORESIZE);
05608             getVRuler()->repaint();
05609         }
05610         else
05611         {
05612             if( state )
05613             {
05614                 if( getVRuler()->flags() != KoRuler::F_HELPLINES )
05615                 {
05616                     getVRuler()->changeFlags(KoRuler::F_HELPLINES);
05617                     getVRuler()->repaint();
05618                 }
05619             }
05620             else
05621             {
05622                 if( getVRuler()->flags()!= 0)
05623                 {
05624                     getVRuler()->changeFlags(0);
05625                     getVRuler()->repaint();
05626                 }
05627             }
05628         }
05629     }
05630 
05631 }
05632 
05633 void KPrView::addGuideLine()
05634 {
05635     KoRect rect( m_canvas->activePage()->getPageRect() );
05636 
05637     KoPoint pos( zoomHandler()->unzoomPoint( m_mousePos + QPoint( m_canvas->diffx(), m_canvas->diffy() ) ) );
05638     KoGuideLineDia dia( 0, pos, rect, m_pKPresenterDoc->unit() );
05639     if ( dia.exec() == QDialog::Accepted )
05640     {
05641         m_pKPresenterDoc->addGuideLine( dia.orientation(), dia.pos() );
05642     }
05643 }
05644 
05645 void KPrView::removeComment()
05646 {
05647     KPrTextView *edit=m_canvas->currentTextObjectView();
05648     if ( edit )
05649         edit->removeComment();
05650 }
05651 
05652 void KPrView::configureCompletion()
05653 {
05654     m_pKPresenterDoc->getAutoFormat()->readConfig();
05655     KoCompletionDia dia( this, 0, m_pKPresenterDoc->getAutoFormat() );
05656     dia.exec();
05657 }
05658 
05659 void KPrView::openPopupMenuZoom( const QPoint & _point )
05660 {
05661     if(!koDocument()->isReadWrite() || !factory())
05662         return;
05663     actionZoomSelectedObject->setEnabled( m_canvas->isOneObjectSelected());
05664     int nbObj = m_canvas->activePage()->objectList().count();
05665     actionZoomAllObject->setEnabled( nbObj > 0);
05666     static_cast<QPopupMenu*>(factory()->container("zoom_popup",this))->popup(_point);
05667 }
05668 
05669 void KPrView::zoomMinus()
05670 {
05671     //unzoom from 25%
05672     int zoom = zoomHandler()->zoom() - (int)(zoomHandler()->zoom()*0.25);
05673     viewZoom( QString::number(zoom ) );
05674     m_canvas->setToolEditMode( TEM_MOUSE );
05675 }
05676 
05677 void KPrView::zoomPageWidth()
05678 {
05679     int zoom = qRound( static_cast<double>(m_canvas->visibleRect().width() * 100 ) /
05680                        (zoomHandler()->resolutionX() * m_pKPresenterDoc->pageLayout().ptWidth ) );
05681     viewZoom( QString::number(zoom ) );
05682     m_canvas->setToolEditMode( TEM_MOUSE );
05683 }
05684 
05685 void KPrView::zoomEntirePage()
05686 {
05687     viewZoom( QString::number(getZoomEntirePage() ) );
05688     m_canvas->setToolEditMode( TEM_MOUSE );
05689 }
05690 
05691 void KPrView::zoomPlus()
05692 {
05693     int zoom = zoomHandler()->zoom() + int( zoomHandler()->zoom() * 0.25 );
05694     viewZoom( QString::number( zoom ) );
05695     m_canvas->setToolEditMode( TEM_MOUSE );
05696 }
05697 
05698 int KPrView::getZoomEntirePage() const
05699 {
05700     double height = zoomHandler()->resolutionY() * m_pKPresenterDoc->pageLayout().ptHeight;
05701     double width = zoomHandler()->resolutionX() * m_pKPresenterDoc->pageLayout().ptWidth;
05702     int zoom = QMIN( qRound( static_cast<double>(m_canvas->visibleRect().height() * 100 ) / height ),
05703                      qRound( static_cast<double>(m_canvas->visibleRect().width() * 100 ) / width ) );
05704     return zoom;
05705 }
05706 
05707 void KPrView::zoomSelectedObject()
05708 {
05709     if( m_canvas->isOneObjectSelected() )
05710     {
05711         KoRect rect = m_canvas->objectRect( false );
05712         setZoomRect( rect );
05713     }
05714 }
05715 
05716 void KPrView::zoomPageHeight()
05717 {
05718     int zoom = qRound( static_cast<double>(m_canvas->visibleRect().height() * 100 ) /
05719                        (zoomHandler()->resolutionX() * m_pKPresenterDoc->pageLayout().ptHeight ) );
05720     viewZoom( QString::number(zoom ) );
05721     m_canvas->setToolEditMode( TEM_MOUSE );
05722 }
05723 
05724 void KPrView::zoomAllObject()
05725 {
05726     KoRect rect = m_canvas->objectRect( true );
05727     double height = zoomHandler()->resolutionY() * rect.height();
05728     double width = zoomHandler()->resolutionX() * rect.width();
05729     int zoom = QMIN( qRound( static_cast<double>(m_canvas->visibleRect().height() * 100 ) / height ),
05730                      qRound( static_cast<double>(m_canvas->visibleRect().width() * 100 ) / width ) );
05731     viewZoom( QString::number(zoom ) );
05732 
05733     m_canvas->setToolEditMode( TEM_MOUSE );
05734     m_canvas->scrollTopLeftPoint( zoomHandler()->zoomPoint( rect.topLeft()) );
05735 }
05736 
05737 void KPrView::flipHorizontal()
05738 {
05739     m_canvas->flipObject( true );
05740 }
05741 
05742 void KPrView::flipVertical()
05743 {
05744     m_canvas->flipObject( false );
05745 }
05746 
05747 void KPrView::slotObjectEditChanged()
05748 {
05749     bool state=m_canvas->isOneObjectSelected();
05750     bool rw = koDocument()->isReadWrite();
05751 
05752     bool isText=!m_canvas->applicableTextInterfaces().isEmpty();
05753     actionTextFont->setEnabled(isText);
05754     actionTextFontSize->setEnabled(isText);
05755     actionTextFontFamily->setEnabled(isText);
05756     actionTextColor->setEnabled(isText);
05757     actionTextAlignLeft->setEnabled(isText);
05758     actionTextAlignCenter->setEnabled(isText);
05759     actionTextAlignRight->setEnabled(isText);
05760     actionTextAlignBlock->setEnabled(isText);
05761 
05762     actionFormatBullet->setEnabled(rw && isText );
05763     actionFormatNumber->setEnabled(rw && isText );
05764 
05765     actionTextDepthPlus->setEnabled(isText);
05766     actionFormatDefault->setEnabled(isText);
05767     actionTextDepthMinus->setEnabled(isText);
05768 
05769     actionTextExtentCont2Height->setEnabled(isText);
05770     actionTextExtendObj2Cont->setEnabled(isText);
05771     actionTextBold->setEnabled(isText);
05772     actionTextItalic->setEnabled(isText);
05773     actionTextUnderline->setEnabled(isText);
05774     actionFormatStrikeOut->setEnabled(isText);
05775     actionFormatSuper->setEnabled(isText);
05776     actionFormatSub->setEnabled(isText);
05777     actionIncreaseFontSize->setEnabled(isText);
05778     actionDecreaseFontSize->setEnabled(isText);
05779 
05780     if ( isText )
05781     {
05782         KoTextFormat format =*(m_canvas->applicableTextInterfaces().first()->currentFormat());
05783         showFormat( format );
05784         const KoParagLayout * paragLayout=m_canvas->applicableTextInterfaces().first()->currentParagLayoutFormat();
05785         KoParagCounter counter;
05786         if(paragLayout->counter)
05787             counter = *(paragLayout->counter);
05788         int align = paragLayout->alignment;
05789         if ( align == Qt::AlignAuto )
05790             align = Qt::AlignLeft; // ## seems hard to detect RTL here
05791         alignChanged( align );
05792     }
05793 
05794     KPrTextView *edit=m_canvas->currentTextObjectView();
05795     bool val=(edit!=0) && isText && !edit->kpTextObject()->isProtectContent();
05796     actionInsertSpecialChar->setEnabled(val);
05797     actionInsertComment->setEnabled( val );
05798 
05799     actionInsertLink->setEnabled(val);
05800     actionFormatParag->setEnabled(isText);
05801     actionInsertVariable->setEnabled(val);
05802     actionTextInsertPageNum->setEnabled(val);
05803     if ( edit )
05804         actionBrushColor->setEnabled(val);
05805 
05806     bool hasSelection = false ;
05807     if(edit)
05808     {
05809         double leftMargin =edit->currentParagLayout().margins[QStyleSheetItem::MarginLeft];
05810         actionTextDepthMinus->setEnabled(val && leftMargin>0);
05811         hasSelection = edit->textObject()->hasSelection();
05812         actionEditCut->setEnabled(hasSelection);
05813     }
05814     actionCreateStyleFromSelection->setEnabled(edit!=0);
05815 
05816     actionChangeCase->setEnabled( (val && rw && hasSelection ) || (rw && !edit && isText) );
05817 
05818     if(!edit)
05819     {
05820         actionEditCopy->setEnabled(state);
05821         bool headerfooterselected = false;
05822         if(m_canvas->numberOfObjectSelected()==1)
05823         {
05824             KPrObject *obj=m_canvas->getSelectedObj();
05825             //disable this action when we select a header/footer
05826             if(obj==m_pKPresenterDoc->header() || obj==m_pKPresenterDoc->footer())
05827                 headerfooterselected=true;
05828             else
05829                 headerfooterselected=false;
05830         }
05831 
05832         actionEditCut->setEnabled(state&&!headerfooterselected);
05833     }
05834     actionFormatStyleMenu->setEnabled( isText );
05835     actionFormatStyle->setEnabled(isText);
05836 
05837     state=m_canvas->oneObjectTextExist();
05838     actionEditFind->setEnabled(state);
05839     actionEditFindNext->setEnabled( state );
05840     actionEditFindPrevious->setEnabled( state );
05841     actionEditReplace->setEnabled(state);
05842 
05843     slotUpdateRuler();
05844 }
05845 
05846 void KPrView::duplicateObj()
05847 {
05848     if (m_canvas->currentTextObjectView() && !m_canvas->isOneObjectSelected() )
05849         return;
05850 
05851     KPrDuplicatObjDia *dlg= new KPrDuplicatObjDia(this, m_pKPresenterDoc);
05852     if ( dlg->exec() )
05853     {
05854         int nbCopy= dlg->nbCopy();
05855         double angle = dlg->angle();
05856         double increaseX = dlg->increaseX();
05857         double increaseY = dlg->increaseY();
05858         double moveX = dlg->moveX();
05859         double moveY = dlg->moveY();
05860         m_canvas->copyObjs();
05861         m_canvas->setToolEditMode( TEM_MOUSE );
05862         deSelectAllObjects();
05863         QMimeSource *data = QApplication::clipboard()->data();
05864         QCString clip_str = KoStoreDrag::mimeType("application/x-kpresenter");
05865         if ( data->provides( clip_str ) )
05866         {
05867             m_canvas->activePage()->pasteObjs( data->encodedData(clip_str),
05868                                                nbCopy, angle, increaseX,increaseY, moveX, moveY );
05869             m_canvas->setMouseSelectedObject(true);
05870             emit objectSelectedChanged();
05871         }
05872     }
05873     delete dlg;
05874 }
05875 
05876 void KPrView::extraArrangePopup()
05877 {
05878     m_canvas->setToolEditMode( TEM_MOUSE );
05879     QPoint pnt( QCursor::pos() );
05880     m_arrangeObjectsPopup->popup( pnt );
05881 }
05882 
05883 void KPrView::extraSendBackward()
05884 {
05885     m_canvas->setToolEditMode( TEM_MOUSE );
05886     m_canvas->lowerObjs( false );
05887 }
05888 
05889 void KPrView::extraBringForward()
05890 {
05891     m_canvas->setToolEditMode( TEM_MOUSE );
05892     m_canvas->raiseObjs( false );
05893 }
05894 
05895 void KPrView::applyAutoFormat()
05896 {
05897     m_pKPresenterDoc->getAutoFormat()->readConfig();
05898     KMacroCommand *macro = 0L;
05899     m_switchPage=m_pKPresenterDoc->pageList().findRef(m_canvas->activePage());
05900     m_initSwitchPage=m_switchPage;
05901     QPtrList<KoTextObject> list=m_canvas->activePage()->allTextObjects();
05902 
05903     KCommand * cmd2 = applyAutoFormatToCurrentPage( list );
05904     if ( cmd2 )
05905     {
05906         if ( !macro )
05907             macro = new KMacroCommand( i18n("Apply Autoformat"));
05908         macro->addCommand( cmd2 );
05909     }
05910 
05911     while(switchInOtherPage(i18n( "Do you want to apply autoformat in new slide?")) )
05912     {
05913         KCommand * cmd = applyAutoFormatToCurrentPage(m_canvas->activePage()->allTextObjects());
05914         if ( cmd )
05915         {
05916             if ( !macro )
05917                 macro = new KMacroCommand( i18n("Apply Autoformat"));
05918             macro->addCommand( cmd );
05919         }
05920     }
05921     if ( macro )
05922         m_pKPresenterDoc->addCommand(macro);
05923     m_switchPage=-1;
05924     m_initSwitchPage=-1;
05925 }
05926 
05927 bool KPrView::switchInOtherPage( const QString & text )
05928 {
05929     //there is not other page
05930     if(m_pKPresenterDoc->pageList().count()==1)
05931         return false;
05932     m_switchPage++;
05933     if( m_switchPage>=(int)m_pKPresenterDoc->pageList().count())
05934         m_switchPage=0;
05935     if( m_switchPage==m_initSwitchPage)
05936         return false;
05937     if ( KMessageBox::questionYesNo( this, text) != KMessageBox::Yes )
05938         return false;
05939     skipToPage(m_switchPage);
05940     return true;
05941 }
05942 
05943 KCommand * KPrView::applyAutoFormatToCurrentPage( const QPtrList<KoTextObject> & lst)
05944 {
05945     KMacroCommand *macro = 0L;
05946     QPtrList<KoTextObject> list(lst);
05947     QPtrListIterator<KoTextObject> fit(list);
05948     for ( ; fit.current() ; ++fit )
05949     {
05950         KCommand *cmd = m_pKPresenterDoc->getAutoFormat()->applyAutoFormat( fit.current() );
05951         if ( cmd )
05952         {
05953             if ( !macro )
05954                 macro = new KMacroCommand( i18n("Apply Autoformat"));
05955             macro->addCommand( cmd );
05956         }
05957     }
05958     return macro;
05959 }
05960 
05961 void KPrView::createStyleFromSelection()
05962 {
05963     KPrTextView *edit=m_canvas->currentTextObjectView();
05964     if ( edit )
05965     {
05966         KoStyleCollection* coll = m_pKPresenterDoc->styleCollection();
05967         KoCreateStyleDia *dia = new KoCreateStyleDia( QStringList(), this, 0 );
05968         if ( dia->exec() )
05969         {
05970             QString name = dia->nameOfNewStyle();
05971             KoParagStyle* style = coll->findStyleByDisplayName( name );
05972             if ( style ) // update existing style
05973             {
05974                 // TODO confirmation message box
05975                 edit->updateStyleFromSelection( style );
05976             }
05977             else // create new style
05978             {
05979                 style = edit->createStyleFromSelection( name );
05980                 m_pKPresenterDoc->styleCollection()->addStyle( style );
05981                 m_pKPresenterDoc->updateAllStyleLists();
05982             }
05983             showStyle( name );
05984         }
05985         delete dia;
05986     }
05987 }
05988 
05989 void KPrView::closeObject()
05990 {
05991     m_canvas->closeObject(true);
05992 }
05993 
05994 void KPrView::viewSnapToGrid()
05995 {
05996     m_pKPresenterDoc->setSnapToGrid( actionViewSnapToGrid->isChecked() );
05997     m_pKPresenterDoc->setModified( true );
05998     m_pKPresenterDoc->updateGridButton();
05999 }
06000 
06001 void KPrView::alignVerticalTop()
06002 {
06003     if ( actionAlignVerticalTop->isChecked() )
06004         m_canvas->alignVertical(KP_TOP );
06005     else
06006         actionAlignVerticalTop->setChecked(true);
06007 }
06008 
06009 void KPrView::alignVerticalBottom()
06010 {
06011     if ( actionAlignVerticalBottom->isChecked() )
06012         m_canvas->alignVertical(KP_BOTTOM );
06013     else
06014         actionAlignVerticalBottom->setChecked(true);
06015 }
06016 
06017 void KPrView::alignVerticalCenter()
06018 {
06019     if ( actionAlignVerticalCenter->isChecked() )
06020         m_canvas->alignVertical(KP_CENTER );
06021     else
06022         actionAlignVerticalCenter->setChecked(true);
06023 }
06024 
06025 void KPrView::changeVerticalAlignmentStatus(VerticalAlignmentType _type )
06026 {
06027     switch( _type )
06028     {
06029     case KP_CENTER:
06030         actionAlignVerticalCenter->setChecked( true );
06031         break;
06032     case KP_TOP:
06033         actionAlignVerticalTop->setChecked( true );
06034         break;
06035     case KP_BOTTOM:
06036         actionAlignVerticalBottom->setChecked( true );
06037         break;
06038     }
06039 }
06040 
06041 void KPrView::autoSpellCheck()
06042 {
06043     m_pKPresenterDoc->changeBgSpellCheckingState( actionAllowBgSpellCheck->isChecked() );
06044 }
06045 
06046 void KPrView::insertFile(  )
06047 {
06048     KFileDialog fd( QString::null, QString::null, this, 0, TRUE );
06049     QStringList filter;
06050     filter<<"application/x-kpresenter";
06051     filter<<"application/vnd.oasis.opendocument.presentation";
06052     fd.setMimeFilter( filter );
06053     fd.setCaption(i18n("Insert File"));
06054 
06055     KURL url;
06056     if ( fd.exec() == QDialog::Accepted )
06057     {
06058         url = fd.selectedURL();
06059         if( url.isEmpty() )
06060         {
06061             KMessageBox::sorry( this,
06062                                 i18n("File name is empty."),
06063                                 i18n("Insert File"));
06064             return;
06065         }
06066         insertFile(url.path());
06067     }
06068 }
06069 
06070 void KPrView::insertFile(const QString &path)
06071 {
06072     m_pKPresenterDoc->insertFile(path);
06073 }
06074 
06075 void KPrView::importStyle()
06076 {
06077     KPrImportStyleDia dia( m_pKPresenterDoc, m_pKPresenterDoc->styleCollection(), this );
06078     if ( dia.exec() && !dia.importedStyles().isEmpty() ) {
06079         m_pKPresenterDoc->styleCollection()->importStyles( dia.importedStyles() );
06080         m_pKPresenterDoc->setModified( true );
06081         m_pKPresenterDoc->updateAllStyleLists();
06082     }
06083 }
06084 
06085 void KPrView::backgroundPicture()
06086 {
06087     switch( m_canvas->activePage()->getBackType())
06088     {
06089     case BT_COLOR:
06090     case BT_BRUSH:
06091         break;
06092     case BT_CLIPART:
06093     case BT_PICTURE:
06094         KoPicture picture=m_canvas->activePage()->background()->picture();
06095         savePicture(picture.getKey().filename(), picture);
06096         break;
06097     }
06098 }
06099 
06100 void KPrView::testAndCloseAllTextObjectProtectedContent()
06101 {
06102     KPrTextView *edit=m_canvas->currentTextObjectView();
06103     if ( edit && edit->kpTextObject()->isProtectContent())
06104     {
06105         m_canvas->setToolEditMode( TEM_MOUSE );
06106         deSelectAllObjects();
06107     }
06108 }
06109 
06110 void KPrView::updateBgSpellCheckingState()
06111 {
06112     actionAllowBgSpellCheck->setChecked( m_pKPresenterDoc->backgroundSpellCheckEnabled() );
06113 }
06114 
06115 void KPrView::updateRulerInProtectContentMode()
06116 {
06117     KPrTextView *edit=m_canvas->currentTextObjectView();
06118     if ( edit && getHRuler()) {
06119         if ( !edit->kpTextObject()->isProtectContent() )
06120             getHRuler()->changeFlags(KoRuler::F_INDENTS | KoRuler::F_TABS);
06121         else
06122             getHRuler()->changeFlags(0);
06123         getHRuler()->repaint();
06124     }
06125 }
06126 
06127 void KPrView::slotChangeCutState(bool b)
06128 {
06129     KPrTextView *edit=m_canvas->currentTextObjectView();
06130 
06131     if ( edit && edit->kpTextObject()->isProtectContent())
06132         actionEditCut->setEnabled( false );
06133     else
06134         actionEditCut->setEnabled( b );
06135 }
06136 
06137 void KPrView::updatePresentationButton(bool b)
06138 {
06139     actionScreenStart->setEnabled( b );
06140 }
06141 
06142 void KPrView::refreshGroupButton()
06143 {
06144     bool state=m_canvas->isOneObjectSelected();
06145     actionExtraGroup->setEnabled(state && m_canvas->numberOfObjectSelected()>1);
06146     actionExtraUnGroup->setEnabled(state && m_canvas->haveASelectedGroupObj());
06147 }
06148 
06149 void KPrView::closeTextObject()
06150 {
06151     KPrTextView *edit=m_canvas->currentTextObjectView();
06152     if ( edit)
06153     {
06154         m_canvas->setToolEditMode( TEM_MOUSE );
06155         deSelectAllObjects();
06156     }
06157 }
06158 
06159 void KPrView::deSelectAllObjects()
06160 {
06161     m_canvas->deSelectAllObj();
06162 }
06163 
06164 void KPrView::copyLink()
06165 {
06166     KPrTextView *edit=m_canvas->currentTextObjectView();
06167     if ( edit )
06168         edit->copyLink();
06169 }
06170 
06171 void KPrView::addToBookmark()
06172 {
06173     KPrTextView *edit=m_canvas->currentTextObjectView();
06174     if ( edit )
06175     {
06176         KoLinkVariable * var=edit->linkVariable();
06177         if(var)
06178             edit->addBookmarks(var->url());
06179     }
06180 }
06181 
06182 void KPrView::removeLink()
06183 {
06184     KPrTextView *edit=m_canvas->currentTextObjectView();
06185     if ( edit )
06186         edit->removeLink();
06187 }
06188 
06189 void KPrView::insertDirectCursor()
06190 {
06191 #if 0
06192     insertDirectCursor( actionInsertDirectCursor->isChecked());
06193 #endif
06194 }
06195 
06196 void KPrView::insertDirectCursor(bool b)
06197 {
06198     m_pKPresenterDoc->setInsertDirectCursor(b);
06199 }
06200 
06201 void KPrView::updateDirectCursorButton()
06202 {
06203 #if 0
06204     actionInsertDirectCursor->setChecked(m_pKPresenterDoc->insertDirectCursor());
06205 #endif
06206 }
06207 
06208 void KPrView::copyTextOfComment()
06209 {
06210     KPrTextView *edit=m_canvas->currentTextObjectView();
06211     if ( edit )
06212         edit->copyTextOfComment();
06213 }
06214 
06215 void KPrView::slotAddIgnoreAllWord()
06216 {
06217     KPrTextView *edit=m_canvas->currentTextObjectView();
06218     if ( edit )
06219         m_pKPresenterDoc->addSpellCheckIgnoreWord( edit->currentWordOrSelection() );
06220 }
06221 
06222 void KPrView::addWordToDictionary()
06223 {
06224     KPrTextView* edit = m_canvas->currentTextObjectView();
06225     if ( edit )
06226     {
06227         QString word = edit->wordUnderCursor( *edit->cursor() );
06228         if ( !word.isEmpty() )
06229             m_pKPresenterDoc->addWordToDictionary( word );
06230     }
06231 }
06232 
06233 void KPrView::imageEffect()
06234 {
06235     if (m_canvas->numberOfObjectSelected() > 0) {
06236         imageEffectDia = new KPrImageEffectDia(this);
06237 
06238         KPrPixmapObject *object=m_canvas->getSelectedImage();
06239 
06240         imageEffectDia->setPixmap(object->getOriginalPixmap());
06241         imageEffectDia->setEffect(object->getImageEffect(), object->getIEParam1(), object->getIEParam2(),
06242                                   object->getIEParam3());
06243 
06244         m_canvas->setToolEditMode(TEM_MOUSE);
06245 
06246         if (imageEffectDia->exec()==QDialog::Accepted) {
06247             KCommand *cmd=m_canvas->activePage()->setImageEffect(imageEffectDia->getEffect(), imageEffectDia->getParam1(),
06248                                                                  imageEffectDia->getParam2(), imageEffectDia->getParam3());
06249             if ( cmd )
06250                 kPresenterDoc()->addCommand( cmd );
06251         }
06252 
06253         delete imageEffectDia;
06254         imageEffectDia = 0L;
06255     }
06256 }
06257 
06258 void KPrView::spellAddAutoCorrect (const QString & originalword, const QString & newword)
06259 {
06260     m_pKPresenterDoc->getAutoFormat()->addAutoFormatEntry( originalword, newword );
06261 }
06262 
06263 QPtrList<KAction> KPrView::listOfResultOfCheckWord( const QString &word )
06264 {
06265     QPtrList<KAction> listAction;
06266     DefaultDictionary *dict = m_broker->defaultDictionary();
06267     QStringList lst = dict->suggest( word );
06268     if ( !lst.contains( word ))
06269     {
06270         QStringList::ConstIterator it = lst.begin();
06271         for ( int i = 0; it != lst.end() ; ++it, ++i )
06272         {
06273             if ( !(*it).isEmpty() ) // in case of removed subtypes or placeholders
06274             {
06275                 KAction * act = new KAction( (*it));
06276                 connect( act, SIGNAL(activated()), this, SLOT(slotCorrectWord()) );
06277                 listAction.append( act );
06278             }
06279         }
06280     }
06281 
06282     return listAction;
06283 }
06284 
06285 void KPrView::slotCorrectWord()
06286 {
06287     KAction * act = (KAction *)(sender());
06288     KPrTextView* edit = m_canvas->currentTextObjectView();
06289     if ( edit )
06290     {
06291         edit->selectWordUnderCursor( *(edit->cursor()) );
06292         m_pKPresenterDoc->addCommand(edit->textObject()->replaceSelectionCommand(
06293                                          edit->cursor(), act->text(),
06294                                          i18n("Replace Word"), KoTextDocument::Standard));
06295     }
06296 }
06297 
06298 KCommand * KPrView::getPenCmd( const QString &name, KoPen pen, LineEnd lb, LineEnd le, int flags )
06299 {
06300     KMacroCommand * macro = NULL;
06301 
06302     //tz TODO remove macro, add parameter for command name to setPen()
06303     KCommand * cmd = m_canvas->activePage()->setPen( pen, lb, le, flags );
06304     if( cmd )
06305     {
06306         macro = new KMacroCommand( name );
06307         macro->addCommand( cmd );
06308     }
06309 
06310     return macro;
06311 }
06312 
06313 void KPrView::initialLayoutOfSplitter()
06314 {
06315     if( !notebar )
06316     {
06317         return;
06318     }
06319 
06320     QSplitter* splitterVertical = static_cast<QSplitter*>( notebar->parent() );
06321     QValueList<int> tmpList;
06322     int noteHeight = height() / 25;
06323     tmpList << height() - noteHeight << noteHeight;
06324     splitterVertical->setSizes( tmpList );
06325 }
06326 
06327 void KPrView::slotChildActivated(bool a)
06328 {
06329   KoViewChild* ch = child( (KoView*)sender() );
06330   if ( !ch )
06331     return;
06332 
06333   if( !a ) {
06334     m_canvas->exitEditMode();
06335   }
06336 
06337   KoView::slotChildActivated( a );
06338 }
06339 
06340 Broker *KPrView::broker() const
06341 {
06342     return m_broker;
06343 }
06344 
06345 void KPrView::slotUnitChanged( KoUnit::Unit unit )
06346 {
06347     h_ruler->setUnit( unit );
06348     v_ruler->setUnit( unit );
06349     if ( statusBar() )
06350     {
06351         m_sbUnitLabel->setText( ' ' + KoUnit::unitDescription( unit ) + ' ' );
06352         updateObjectStatusBarItem();
06353     }
06354 }
06355 
06356 void KPrView::documentModified( bool b )
06357 {
06358     if ( !statusBar() )
06359         return;
06360 
06361     if ( b )
06362         m_sbModifiedLabel->setPixmap( KGlobal::iconLoader()->loadIcon( "action-modified", KIcon::Small ) );
06363     else
06364         m_sbModifiedLabel->setText( "   " );
06365 }
06366 
06367 void KPrView::loadingFinished()
06368 {
06369   setZoom( 100, true );
06370   h_ruler->setPageLayout(m_pKPresenterDoc->pageLayout());
06371   v_ruler->setPageLayout(m_pKPresenterDoc->pageLayout());
06372   slotUpdateRuler();
06373   m_pKPresenterDoc->updateZoomRuler();
06374   updateSideBar();
06375 }
06376 
06377 #include "KPrView.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys