00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "KWCanvas.h"
00024 #include "KWTableFrameSet.h"
00025 #include "KWPartFrameSet.h"
00026 #include "KWFormulaFrameSet.h"
00027 #include "KWDocument.h"
00028 #include "KWView.h"
00029 #include "KWViewMode.h"
00030 #include "KWFrameDia.h"
00031 #include "KWCommand.h"
00032 #include "KWTableTemplate.h"
00033 #include "KWTextDocument.h"
00034 #include "KWFrameList.h"
00035 #include "KWPageManager.h"
00036 #include "KWPage.h"
00037 #include "KWPictureFrameSet.h"
00038 #include "KWFrameView.h"
00039 #include "KWFrameViewManager.h"
00040
00041 #include <qbuffer.h>
00042 #include <qtimer.h>
00043 #include <qclipboard.h>
00044 #include <qprogressdialog.h>
00045 #include <qobjectlist.h>
00046 #include <qapplication.h>
00047 #include <qwhatsthis.h>
00048
00049 #include <KoStore.h>
00050 #include <KoStoreDrag.h>
00051 #include <KoPictureCollection.h>
00052
00053 #include <ktempfile.h>
00054 #include <klocale.h>
00055 #include <kcursor.h>
00056 #include <kdebug.h>
00057 #include <kmessagebox.h>
00058 #include <kmultipledrag.h>
00059 #include <kurl.h>
00060 #include <kurldrag.h>
00061 #include <kio/netaccess.h>
00062 #include <kmimetype.h>
00063
00064 #include <assert.h>
00065
00066 KWCanvas::KWCanvas(const QString& viewMode, QWidget *parent, KWDocument *d, KWGUI *lGui)
00067 : QScrollView( parent, "canvas", WStaticContents| WResizeNoErase | WRepaintNoErase ), m_doc( d )
00068 {
00069 m_frameViewManager = new KWFrameViewManager(d);
00070 m_gui = lGui;
00071 m_currentFrameSetEdit = 0L;
00072 m_mouseMeaning = MEANING_NONE;
00073 m_mousePressed = false;
00074 m_imageDrag = false;
00075 m_frameInline = false;
00076 m_overwriteMode = false;
00077
00078
00079 m_picture.pictureInline = false;
00080 m_picture.keepRatio = true;
00081
00082
00083
00084 m_frameInlineType = FT_TABLE;
00085 m_viewMode = KWViewMode::create( viewMode, m_doc, this );
00086 m_interactionPolicy = 0;
00087
00088
00089 m_table.rows = 3;
00090 m_table.cols = 2;
00091 m_table.width = KWTableFrameSet::TblAuto;
00092 m_table.height = KWTableFrameSet::TblAuto;
00093 m_table.floating = true;
00094 m_table.tableTemplateName=QString::null;
00095 m_table.format=31;
00096
00097 m_footEndNote.noteType = FootNote;
00098 m_footEndNote.numberingType = KWFootNoteVariable::Auto;
00099
00100
00101 m_currentTable = 0L;
00102 m_printing = false;
00103 m_deleteMovingRect = false;
00104 m_resizedFrameInitialMinHeight = 0;
00105 m_temporaryStatusBarTextShown = false;
00106
00107 viewport()->setBackgroundMode( PaletteBase );
00108 viewport()->setAcceptDrops( TRUE );
00109
00110 setKeyCompression( TRUE );
00111 viewport()->setMouseTracking( TRUE );
00112
00113 m_scrollTimer = new QTimer( this );
00114 connect( m_scrollTimer, SIGNAL( timeout() ),
00115 this, SLOT( doAutoScroll() ) );
00116
00117 viewport()->setFocusProxy( this );
00118 viewport()->setFocusPolicy( WheelFocus );
00119 setInputMethodEnabled( true );
00120 setFocus();
00121 viewport()->installEventFilter( this );
00122 installEventFilter( this );
00123 KCursor::setAutoHideCursor( this, true, true );
00124
00125 connect( this, SIGNAL(contentsMoving( int, int )),
00126 this, SLOT(slotContentsMoving( int, int )) );
00127
00128 connect( m_doc, SIGNAL( newContentsSize() ),
00129 this, SLOT( slotNewContentsSize() ) );
00130
00131 connect( m_doc, SIGNAL( mainTextHeightChanged() ),
00132 this, SLOT( slotMainTextHeightChanged() ) );
00133
00134 connect( m_doc, SIGNAL( sig_terminateEditing( KWFrameSet * ) ),
00135 this, SLOT( terminateEditing( KWFrameSet * ) ) );
00136
00137 slotNewContentsSize();
00138
00139 m_mouseMode = MM_EDIT;
00140 setMouseMode( MM_EDIT );
00141
00142
00143 KWFrameSet * fs = 0L;
00144 QString fsName = m_doc->initialFrameSet();
00145 if ( !fsName.isEmpty() )
00146 fs = m_doc->frameSetByName( fsName );
00147 if ( !fs )
00148 fs = m_doc->frameSet( 0 );
00149
00150 if ( fs && fs->isVisible( m_viewMode ) ) {
00151 checkCurrentEdit( fs );
00152 KWTextFrameSetEdit* textedit = dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit);
00153 if ( textedit ) {
00154 int paragId = m_doc->initialCursorParag();
00155 int index = m_doc->initialCursorIndex();
00156 if ( paragId != 0 || index != 0 ) {
00157 KoTextParag* parag = textedit->textDocument()->paragAt( paragId );
00158 if ( parag )
00159 textedit->setCursor( parag, index );
00160 }
00161 }
00162 }
00163 m_doc->deleteInitialEditingInfo();
00164
00165 connect(frameViewManager(), SIGNAL(sigFrameResized(const QValueList<KWFrame*>&)),
00166 m_doc, SLOT(framesChanged(const QValueList<KWFrame*>&)));
00167 connect(frameViewManager(), SIGNAL(sigFrameMoved(const QValueList<KWFrame*>&)),
00168 m_doc, SLOT(framesChanged(const QValueList<KWFrame*>&)));
00169 }
00170
00171 KWCanvas::~KWCanvas()
00172 {
00173 delete m_interactionPolicy;
00174 delete m_currentFrameSetEdit;
00175 m_currentFrameSetEdit = 0;
00176 delete m_viewMode;
00177 m_viewMode = 0;
00178 disconnect(frameViewManager(), SIGNAL(sigFrameResized(const QValueList<KWFrame*>&)),
00179 m_doc, SLOT(framesChanged(const QValueList<KWFrame*>&)));
00180 disconnect(frameViewManager(), SIGNAL(sigFrameMoved(const QValueList<KWFrame*>&)),
00181 m_doc, SLOT(framesChanged(const QValueList<KWFrame*>&)));
00182 delete m_frameViewManager;
00183 m_frameViewManager = 0;
00184 }
00185
00186 void KWCanvas::repaintChanged( KWFrameSet * fs, bool resetChanged )
00187 {
00188 assert(fs);
00189
00190 QPainter p( viewport() );
00191 p.translate( -contentsX(), -contentsY() );
00192 p.setBrushOrigin( -contentsX(), -contentsY() );
00193 QRect crect( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
00194 drawFrameSet( fs, &p, crect, true, resetChanged, m_viewMode );
00195
00196
00197 if ( m_doc->showGrid() )
00198 drawGrid( p, crect );
00199 }
00200
00201 void KWCanvas::repaintAll( bool erase )
00202 {
00203
00204 viewport()->repaint( erase );
00205 }
00206
00207 void KWCanvas::viewportResizeEvent( QResizeEvent * )
00208 {
00209 viewport()->update();
00210 }
00211
00212 void KWCanvas::print( QPainter *painter, KPrinter *printer )
00213 {
00214
00215 if ( m_currentFrameSetEdit )
00216 m_currentFrameSetEdit->focusOutEvent();
00217 m_printing = true;
00218 KWViewMode *viewMode = new KWViewModePrint( m_doc, this );
00219
00220 QValueList<int> pageList = printer->pageList();
00221 QProgressDialog progress( i18n( "Printing..." ), i18n( "Cancel" ),
00222 pageList.count() + 1, this );
00223 int j = 0;
00224 progress.setProgress( 0 );
00225 QValueList<int>::Iterator it = pageList.begin();
00226 for ( ; it != pageList.end(); ++it )
00227 {
00228 progress.setProgress( ++j );
00229 qApp->processEvents();
00230
00231 if ( progress.wasCancelled() )
00232 break;
00233
00234 if ( it != pageList.begin() )
00235 printer->newPage();
00236
00237 painter->save();
00238 int pgNum = (*it);
00239 int yOffset = m_doc->zoomItY( m_doc->pageManager()->topOfPage( pgNum ) );
00240 kdDebug(32001) << "printing page " << pgNum << " yOffset=" << yOffset << endl;
00241 QRect pageRect = m_doc->pageManager()->page(pgNum)->zoomedRect(m_doc);
00242 painter->fillRect( pageRect, white );
00243
00244 painter->translate( 0, -yOffset );
00245 painter->setBrushOrigin( 0, -yOffset );
00246 drawDocument( painter, pageRect, viewMode );
00247 qApp->processEvents();
00248 painter->restore();
00249 }
00250 if ( m_currentFrameSetEdit )
00251 m_currentFrameSetEdit->focusInEvent();
00252 m_printing = false;
00253 delete viewMode;
00254 }
00255
00256 void KWCanvas::drawContents( QPainter *painter, int cx, int cy, int cw, int ch )
00257 {
00258 if ( isUpdatesEnabled() )
00259 {
00260
00261 painter->setBrushOrigin( -contentsX(), -contentsY() );
00262 drawDocument( painter, QRect( cx, cy, cw, ch ), m_viewMode );
00263 if ( m_doc->showGrid() )
00264 drawGrid( *painter, QRect( cx, cy, cw, ch ) );
00265 else if ( m_doc->snapToGrid() && ( m_interactionPolicy && m_interactionPolicy->gotDragEvents()
00266 || m_mouseMode != MM_EDIT ) )
00267 drawGrid( *painter, QRect(contentsX(), contentsY(), visibleWidth(), visibleHeight()) );
00268 }
00269 }
00270
00271 void KWCanvas::drawDocument( QPainter *painter, const QRect &crect, KWViewMode* viewMode )
00272 {
00273
00274
00275
00276
00277 if ( painter->device()->devType() != QInternal::Printer )
00278 {
00279 QRegion emptySpaceRegion( crect );
00280 m_doc->createEmptyRegion( crect, emptySpaceRegion, viewMode );
00281 viewMode->drawPageBorders( painter, crect, emptySpaceRegion );
00282 }
00283
00284
00285 QPtrListIterator<KWFrameSet> fit = m_doc->framesetsIterator();
00286 for ( ; fit.current() ; ++fit )
00287 {
00288 KWFrameSet * frameset = fit.current();
00289 if(! frameset->isVisible()) continue;
00290 drawFrameSet( frameset, painter, crect, false, true, viewMode );
00291 }
00292
00293 m_doc->maybeDeleteDoubleBufferPixmap();
00294 }
00295
00296 void KWCanvas::drawFrameSet( KWFrameSet * frameset, QPainter * painter,
00297 const QRect & crect, bool onlyChanged, bool resetChanged, KWViewMode* viewMode )
00298 {
00299 if ( !frameset->isVisible( viewMode ) )
00300 return;
00301 if ( !onlyChanged && frameset->isFloating() )
00302 return;
00303
00304 bool focus = hasFocus() || viewport()->hasFocus();
00305 if ( painter->device()->devType() == QInternal::Printer )
00306 focus = false;
00307
00308 QColorGroup gb = QApplication::palette().active();
00309 if ( focus && m_currentFrameSetEdit && frameset == m_currentFrameSetEdit->frameSet() )
00310
00311 m_currentFrameSetEdit->drawContents( painter, crect, gb, onlyChanged, resetChanged, viewMode, m_frameViewManager );
00312 else
00313 frameset->drawContents( painter, crect, gb, onlyChanged, resetChanged, 0L, viewMode, m_frameViewManager );
00314 }
00315
00316 void KWCanvas::keyPressEvent( QKeyEvent *e )
00317 {
00318 if( !m_doc->isReadWrite()) {
00319 switch( e->key() ) {
00320 case Qt::Key_Down:
00321 setContentsPos( contentsX(), contentsY() + 10 );
00322 break;
00323 case Qt::Key_Up:
00324 setContentsPos( contentsX(), contentsY() - 10 );
00325 break;
00326 case Qt::Key_Left:
00327 setContentsPos( contentsX() - 10, contentsY() );
00328 break;
00329 case Qt::Key_Right:
00330 setContentsPos( contentsX() + 10, contentsY() );
00331 break;
00332 case Qt::Key_PageUp:
00333 setContentsPos( contentsX(), contentsY() - visibleHeight() );
00334 break;
00335 case Qt::Key_PageDown:
00336 setContentsPos( contentsX(), contentsY() + visibleHeight() );
00337 break;
00338 case Qt::Key_Home:
00339 setContentsPos( contentsX(), 0 );
00340 break;
00341 case Qt::Key_End:
00342 setContentsPos( contentsX(), contentsHeight() - visibleHeight() );
00343 break;
00344 default:
00345 break;
00346 }
00347 }
00348
00349
00350 }
00351
00352 void KWCanvas::switchViewMode( const QString& newViewMode )
00353 {
00354 delete m_viewMode;
00355 m_viewMode = KWViewMode::create( newViewMode, m_doc, this );
00356 }
00357
00358 void KWCanvas::mpCreate( const QPoint& normalPoint, bool noGrid )
00359 {
00360 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
00361 if ( m_doc->snapToGrid() && !noGrid )
00362 applyGrid( docPoint );
00363 m_insRect.setCoords( docPoint.x(), docPoint.y(), 0, 0 );
00364 m_deleteMovingRect = false;
00365 }
00366
00367 void KWCanvas::mpCreatePixmap( const QPoint& normalPoint, bool noGrid )
00368 {
00369 if ( !m_kopicture.isNull() )
00370 {
00371
00372 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
00373 if ( m_doc->snapToGrid() && ! noGrid )
00374 applyGrid( docPoint );
00375 int pageNum = m_doc->pageManager()->pageNumber( docPoint );
00376 m_insRect.setRect( docPoint.x(), docPoint.y(), 0, 0 );
00377 m_deleteMovingRect = false;
00378
00379 if ( !m_pixmapSize.isEmpty() )
00380 {
00381
00382 uint width = qRound( (double)m_pixmapSize.width() * m_doc->zoomedResolutionX() / POINT_TO_INCH( KoGlobal::dpiX() ) );
00383 uint height = qRound( (double)m_pixmapSize.height() * m_doc->zoomedResolutionY() / POINT_TO_INCH( KoGlobal::dpiY() ) );
00384 m_insRect.setWidth( m_doc->unzoomItX( width ) );
00385 m_insRect.setHeight( m_doc->unzoomItY( height ) );
00386
00387 width = kMin( width, m_doc->paperWidth(pageNum) - normalPoint.x() - 5 );
00388 height = kMin( height, m_doc->paperHeight(pageNum) - normalPoint.y() - 5 );
00389
00390 if ( m_keepRatio )
00391 {
00392 double ratio = ((double) m_pixmapSize.width()) / ((double) m_pixmapSize.height());
00393 applyAspectRatio( ratio, m_insRect );
00394 }
00395
00396 QPoint nPoint( normalPoint.x() + m_doc->zoomItX( m_insRect.width() ),
00397 normalPoint.y() + m_doc->zoomItY( m_insRect.height() ) );
00398 QPoint vPoint = m_viewMode->normalToView( nPoint );
00399 vPoint = contentsToViewport( vPoint );
00400 QRect viewportRect( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
00401 if ( viewportRect.contains( vPoint ) )
00402 QCursor::setPos( viewport()->mapToGlobal( vPoint ) );
00403 }
00404 emit docStructChanged(Pictures);
00405 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
00406 repaintContents( FALSE );
00407 }
00408 }
00409
00410 void KWCanvas::contentsMousePressEvent( QMouseEvent *e )
00411 {
00412 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
00413 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
00414
00415
00416 if ( e->button() == LeftButton )
00417 {
00418 m_mousePressed = true;
00419 }
00420
00421
00422 if ( !m_doc->isReadWrite() && ( m_mouseMode != MM_EDIT || e->button() != LeftButton ) )
00423 return;
00424 if ( m_printing )
00425 return;
00426
00427
00428 switch ( m_mouseMode ) {
00429 case MM_EDIT:
00430 {
00431 if(! viewMode()->hasFrames() ) {
00432
00433 docPoint = KoPoint(QMAX(0, docPoint.x()), QMAX(0, docPoint.y()));
00434 if ( m_currentFrameSetEdit )
00435 m_currentFrameSetEdit->mousePressEvent( e, normalPoint, docPoint );
00436 break;
00437 }
00438
00439 m_mouseMeaning = m_frameViewManager->mouseMeaning( docPoint, e->state());
00440
00441
00442 switch ( m_mouseMeaning ) {
00443 case MEANING_MOUSE_INSIDE:
00444 case MEANING_MOUSE_OVER_LINK:
00445 case MEANING_MOUSE_OVER_FOOTNOTE:
00446 case MEANING_MOUSE_INSIDE_TEXT:
00447 case MEANING_ACTIVATE_PART:
00448 {
00449
00450
00451
00452 KWFrameView *view = m_frameViewManager->view( docPoint, KWFrameViewManager::frameOnTop );
00453 if ( ! ( e->button() == RightButton && view && view->selected() ) )
00454 selectAllFrames( false );
00455
00456 KWFrame * frame = view ? view->frame() : 0L;
00457 KWFrameSet * fs = frame ? frame->frameSet() : 0L;
00458 if ( fs && fs->groupmanager() )
00459 fs = fs->groupmanager();
00460 bool emitChanged = false;
00461 if ( fs )
00462 {
00463
00464 emitChanged = checkCurrentEdit( fs );
00465 }
00466
00467 if ( m_currentFrameSetEdit )
00468 m_currentFrameSetEdit->mousePressEvent( e, normalPoint, docPoint );
00469
00470 if ( emitChanged ) {
00471 emit currentFrameSetEditChanged();
00472 emit updateRuler();
00473 }
00474
00475 if ( m_frameInline )
00476 {
00477 bool inlineCreated = true;
00478 if(m_frameInlineType == FT_TABLE)
00479 inlineCreated = insertInlineTable();
00480 else if(m_frameInlineType == FT_PICTURE)
00481 inlineCreated = insertInlinePicture();
00482 if (!inlineCreated)
00483 KMessageBox::information(0L, i18n("Read-only content cannot be changed. No modifications will be accepted."));
00484 }
00485 break;
00486 }
00487 case MEANING_RESIZE_COLUMN:
00488 case MEANING_RESIZE_ROW:
00489 {
00490 terminateCurrentEdit();
00491
00492
00493
00494
00495 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
00496 if (view)
00497 {
00498 KWTableFrameSet::Cell* cell = dynamic_cast<KWTableFrameSet::Cell *>(view->frame()->frameSet());
00499 if ( cell )
00500 {
00501 KWTableFrameSet* table = cell->groupmanager();
00502 if ( m_mouseMeaning == MEANING_RESIZE_COLUMN )
00503 {
00504 m_rowColResized = table->columnEdgeAt( docPoint.x() );
00505 m_previousTableSize = table->columnSize( m_rowColResized );
00506 }
00507 else
00508 {
00509 m_rowColResized = table->rowEdgeAt( docPoint.y() );
00510 m_previousTableSize = table->rowSize( m_rowColResized );
00511 }
00512 m_currentTable = table;
00513 kdDebug(32002) << "resizing row/col edge. m_rowColResized=" << m_rowColResized << endl;
00514 }
00515 }
00516 break;
00517 }
00518 default:
00519 m_mousePressed = true;
00520 m_deleteMovingRect = false;
00521
00522 delete m_interactionPolicy;
00523 m_interactionPolicy = InteractionPolicy::createPolicy(this, m_mouseMeaning, docPoint, e->button(), e->state());
00524 if(m_interactionPolicy)
00525 terminateCurrentEdit();
00526 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, e->state() ) );
00527 }
00528 }
00529 break;
00530 case MM_CREATE_TEXT: case MM_CREATE_PART: case MM_CREATE_TABLE:
00531 case MM_CREATE_FORMULA:
00532 if ( e->button() == LeftButton )
00533 mpCreate( normalPoint, e->state() & Qt::ShiftButton);
00534 break;
00535 case MM_CREATE_PIX:
00536 if ( e->button() == LeftButton )
00537 mpCreatePixmap( normalPoint, e->state() & Qt::ShiftButton );
00538 break;
00539 default: break;
00540 }
00541 m_scrollTimer->start( 50 );
00542
00543 if ( e->button() == MidButton ) {
00544 if ( m_doc->isReadWrite() && m_currentFrameSetEdit && m_mouseMode == MM_EDIT )
00545 {
00546 QApplication::clipboard()->setSelectionMode( true );
00547 m_currentFrameSetEdit->paste();
00548 QApplication::clipboard()->setSelectionMode( false );
00549 }
00550 }
00551 else if ( e->button() == RightButton ) {
00552 if(!m_doc->isReadWrite())
00553 return;
00554 if ( m_deleteMovingRect )
00555 deleteMovingRect();
00556
00557 switch ( m_mouseMode )
00558 {
00559 case MM_EDIT:
00560 if ( !viewMode()->hasFrames() ) {
00561 KWFrameView *view = m_frameViewManager->view(m_doc->frameSet( 0 )->frame(0));
00562 view->showPopup(docPoint, m_gui->getView(), QCursor::pos());
00563 }
00564 else
00565 m_frameViewManager->showPopup(docPoint, m_gui->getView(), e->state(), QCursor::pos());
00566 break;
00567 case MM_CREATE_TEXT:
00568 case MM_CREATE_PART:
00569 case MM_CREATE_TABLE:
00570 case MM_CREATE_FORMULA:
00571 case MM_CREATE_PIX:
00572 setMouseMode( MM_EDIT );
00573 default: break;
00574 }
00575 m_mousePressed = false;
00576 }
00577 }
00578
00579
00580 void KWCanvas::createTable( unsigned int rows, unsigned int cols,
00581 int wid, int hei,
00582 bool isFloating,
00583 KWTableTemplate *tt, int format )
00584 {
00585
00586 m_table.rows = rows;
00587 m_table.cols = cols;
00588 m_table.width = wid;
00589 m_table.height = hei;
00590 m_table.floating = isFloating;
00591 m_table.format = format;
00592
00593 m_table.tableTemplateName = tt ? tt->displayName():QString::null;
00594 m_table.tt = tt;
00595
00596 if ( isFloating )
00597 {
00598 m_frameInline=true;
00599 m_frameInlineType=FT_TABLE;
00600 m_gui->getView()->displayFrameInlineInfo();
00601 }
00602 else
00603 {
00604 m_frameInline=false;
00605 setMouseMode( MM_CREATE_TABLE );
00606 }
00607 }
00608
00609 bool KWCanvas::insertInlinePicture()
00610 {
00611 bool inserted = m_gui->getView()->insertInlinePicture();
00612 if ( inserted )
00613 m_frameInline = false;
00614 return inserted;
00615 }
00616
00617 bool KWCanvas::insertInlineTable()
00618 {
00619 KWTextFrameSetEdit * edit = dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit);
00620 if(edit)
00621 {
00622 if ( edit->textFrameSet()->textObject()->protectContent() )
00623 return false;
00624 m_insRect = KoRect( 0, 0, edit->frameSet()->frame(0)->width(), 10 );
00625
00626 KWTableFrameSet * table = createTable();
00627 m_doc->addFrameSet( table, false );
00628 edit->insertFloatingFrameSet( table, i18n("Insert Inline Table") );
00629 table->finalize();
00630
00631 if (m_table.tt) {
00632 KWTableTemplateCommand *ttCmd=new KWTableTemplateCommand( "Apply template to inline table", table, m_table.tt );
00633 m_doc->addCommand(ttCmd);
00634 ttCmd->execute();
00635 }
00636
00637 m_doc->updateAllFrames();
00638 m_doc->refreshDocStructure(Tables);
00639 }
00640 m_gui->getView()->updateFrameStatusBarItem();
00641 m_frameInline = false;
00642 return true;
00643 }
00644
00645 void KWCanvas::applyGrid( KoPoint &p )
00646 {
00647 if ( m_viewMode->type() != "ModeNormal" )
00648 return;
00649
00650
00651
00652
00653
00654 p.setX( static_cast<int>( p.x() / m_doc->gridX() + 1e-10 ) * m_doc->gridX() );
00655 p.setY( static_cast<int>( p.y() / m_doc->gridY() + 1e-10 ) * m_doc->gridY() );
00656
00657
00658 }
00659
00660 void KWCanvas::drawGrid( QPainter &p, const QRect& rect )
00661 {
00662
00663 if ( !m_viewMode->hasFrames() )
00664 return;
00665 QPen pen = QPen( Qt::black, 6, Qt::DotLine );
00666 QPen oldPen = p.pen();
00667 p.setPen( pen );
00668
00669 const double offsetX = m_doc->gridX();
00670 const double offsetY = m_doc->gridY();
00671
00672
00673
00674 for ( int pgNum = m_doc->startPage() ; pgNum <= m_doc->lastPage() ; ++pgNum) {
00675 const QRect pageRect = m_viewMode->viewPageRect( pgNum );
00676 const QRect crect = pageRect & rect;
00677 if ( crect.isEmpty() )
00678 continue;
00679
00680
00681
00682 KoPoint pageTopLeft (0, m_doc->pageManager()->topOfPage(pgNum) + 2);
00683 QPoint pageTopLeftView = m_viewMode->normalToView( m_doc->zoomPoint(pageTopLeft) );
00684
00685
00686 const KoRect docRect = m_doc->unzoomRect( m_viewMode->viewToNormal( crect ) );
00687
00688
00689
00690 const double firstOffsetY = pageTopLeft.y() - offsetY * static_cast<int>( docRect.y() / offsetY );
00691 const double bottom = docRect.bottom() - pageTopLeft.y();
00692
00693 for ( double x = 0; x <= docRect.right(); x += offsetX ) {
00694 const int zoomedX = m_doc->zoomItX( x ) + pageTopLeftView.x();
00695 for ( double y = firstOffsetY; y <= bottom; y += offsetY ) {
00696 const int zoomedY = m_doc->zoomItY( y ) + pageTopLeftView.y();
00697 p.drawPoint( zoomedX, zoomedY );
00698 }
00699 }
00700 }
00701
00702 p.setPen( oldPen );
00703 }
00704
00705 void KWCanvas::applyAspectRatio( double ratio, KoRect& insRect )
00706 {
00707 double width = insRect.width();
00708 double height = insRect.height();
00709 if ( width < height )
00710 width = height * ratio;
00711 else
00712 height = width / ratio;
00713 insRect.setRight( insRect.left() + width );
00714 insRect.setBottom( insRect.top() + height );
00715
00716 }
00717
00718 void KWCanvas::mmCreate( const QPoint& normalPoint, bool noGrid )
00719 {
00720 QPainter p;
00721 p.begin( viewport() );
00722 p.translate( -contentsX(), -contentsY() );
00723 p.setRasterOp( NotROP );
00724 p.setPen( black );
00725 p.setBrush( NoBrush );
00726
00727 if ( m_deleteMovingRect )
00728 drawMovingRect( p );
00729
00730 int page = m_doc->pageManager()->pageNumber( m_insRect );
00731 if( page == -1) {
00732 return;
00733 }
00734 KoRect oldRect = m_insRect;
00735
00736
00737 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
00738 if ( m_doc->snapToGrid() && m_mouseMode != MM_CREATE_PIX && !noGrid )
00739 applyGrid( docPoint );
00740
00741 m_insRect.setRight( docPoint.x() );
00742 m_insRect.setBottom( docPoint.y() );
00743
00744
00745 KoRect r = m_insRect.normalize();
00746 if ( !m_doc->pageManager()->page(page)->rect().contains(r) )
00747 {
00748
00749
00750 m_insRect = oldRect;
00751
00752 }
00753
00754
00755 if ( m_mouseMode == MM_CREATE_PIX && m_keepRatio )
00756 {
00757 double ratio = (double)m_pixmapSize.width() / (double)m_pixmapSize.height();
00758 applyAspectRatio( ratio, m_insRect );
00759 }
00760
00761 drawMovingRect( p );
00762 p.end();
00763 m_deleteMovingRect = true;
00764 }
00765
00766 void KWCanvas::drawMovingRect( QPainter & p )
00767 {
00768 p.setPen( black );
00769 p.drawRect( m_viewMode->normalToView( m_doc->zoomRect( m_insRect ) ) );
00770 }
00771
00772 void KWCanvas::deleteMovingRect()
00773 {
00774 Q_ASSERT( m_deleteMovingRect );
00775 QPainter p;
00776 p.begin( viewport() );
00777 p.translate( -contentsX(), -contentsY() );
00778 p.setRasterOp( NotROP );
00779 p.setPen( black );
00780 p.setBrush( NoBrush );
00781 drawMovingRect( p );
00782 m_deleteMovingRect = false;
00783 p.end();
00784 }
00785
00786 void KWCanvas::contentsMouseMoveEvent( QMouseEvent *e )
00787 {
00788 if ( m_printing )
00789 return;
00790 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
00791 if(normalPoint.x() == -1)
00792 return;
00793 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
00794
00795 if ( m_mousePressed ) {
00796
00797
00798 switch ( m_mouseMode ) {
00799 case MM_EDIT:
00800 {
00801 if ( m_currentFrameSetEdit )
00802 m_currentFrameSetEdit->mouseMoveEvent( e, normalPoint, docPoint );
00803 if( ! m_doc->isReadWrite() )
00804 break;
00805 if ( m_mouseMeaning == MEANING_RESIZE_COLUMN || m_mouseMeaning == MEANING_RESIZE_ROW )
00806 {
00807
00808 QRect oldRect( m_viewMode->normalToView( m_doc->zoomRect( m_currentTable->boundingRect() ) ) );
00809 if ( m_mouseMeaning == MEANING_RESIZE_ROW )
00810 m_currentTable->resizeRow( m_rowColResized, docPoint.y() );
00811 else
00812 m_currentTable->resizeColumn( m_rowColResized, docPoint.x() );
00813
00814 QRect newRect( m_viewMode->normalToView( m_doc->zoomRect( m_currentTable->boundingRect() ) ) );
00815 repaintContents( QRegion(oldRect).unite(newRect).boundingRect(), FALSE );
00816 }
00817 else if (m_interactionPolicy) {
00818 m_interactionPolicy->handleMouseMove(e->state(),
00819 m_doc->unzoomPoint( normalPoint ));
00820 m_interactionPolicy->hadDragEvents();
00821 }
00822 } break;
00823 case MM_CREATE_TEXT: case MM_CREATE_PIX: case MM_CREATE_PART:
00824 case MM_CREATE_TABLE: case MM_CREATE_FORMULA:
00825 mmCreate( normalPoint, e->state() & ShiftButton );
00826 default:
00827 break;
00828 }
00829 }
00830 else {
00831 if ( m_mouseMode == MM_EDIT )
00832 {
00833 MouseMeaning meaning = m_frameViewManager->mouseMeaning( docPoint, e->state() );
00834 switch ( meaning ) {
00835 case MEANING_MOUSE_OVER_FOOTNOTE:
00836 {
00837 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
00838 KWFrame* frame = view ? view->frame() : 0;
00839 KWFrameSet * fs = frame ? frame->frameSet() : 0;
00840 if (fs && fs->type() == FT_TEXT)
00841 {
00842 KoVariable* var = static_cast<KWTextFrameSet *>(fs)->variableUnderMouse(docPoint);
00843 if ( var )
00844 {
00845 KWFootNoteVariable * footNoteVar = dynamic_cast<KWFootNoteVariable *>( var );
00846 if ( footNoteVar )
00847 {
00848
00849 gui()->getView()->setTemporaryStatusBarText( footNoteVar->frameSet()->textDocument()->firstParag()->string()->toString() );
00850 m_temporaryStatusBarTextShown = true;
00851 }
00852 }
00853
00854 }
00855 break;
00856 }
00857 case MEANING_MOUSE_OVER_LINK:
00858 {
00859 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
00860 KWFrame* frame = view ? view->frame() : 0;
00861 KWFrameSet * fs = frame ? frame->frameSet() : 0L;
00862 if (fs && fs->type() == FT_TEXT)
00863 {
00864 KWTextFrameSet *frameset = static_cast<KWTextFrameSet *>(fs);
00865
00866 QString link = frameset->linkVariableUnderMouse(docPoint)->url();
00867 if ( link.startsWith("bkm://") )
00868 link.replace( 0, 6, i18n("Bookmark target: ") );
00869 gui()->getView()->setTemporaryStatusBarText( link );
00870 m_temporaryStatusBarTextShown = true;
00871 }
00872 break;
00873 }
00874 default:
00875 resetStatusBarText();
00876 break;
00877 }
00878 if(viewMode()->hasFrames())
00879 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, e->state() ) );
00880 else
00881 viewport()->setCursor( Qt::ibeamCursor );
00882 }
00883 }
00884 }
00885
00886 void KWCanvas::mrEditFrame() {
00887
00888 if(m_interactionPolicy) {
00889 m_interactionPolicy->finishInteraction();
00890 KCommand *cmd = m_interactionPolicy->createCommand();
00891 if(cmd)
00892 m_doc->addCommand(cmd);
00893 delete(m_interactionPolicy);
00894 m_interactionPolicy = 0;
00895 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
00896 repaintContents();
00897 }
00898 m_mousePressed = false;
00899 }
00900
00901 KCommand *KWCanvas::createTextBox( const KoRect & rect )
00902 {
00903 if ( !m_doc->snapToGrid() || ( rect.width() > m_doc->gridX() && rect.height() > m_doc->gridY() ) ) {
00904 KWFrame *frame = new KWFrame(0L, rect.x(), rect.y(), rect.width(), rect.height() );
00905 frame->setNewFrameBehavior(KWFrame::Reconnect);
00906 frame->setZOrder( m_doc->maxZOrder( frame->pageNumber(m_doc) ) + 1 );
00907
00908 QString name = m_doc->generateFramesetName( i18n( "Text Frameset %1" ) );
00909 KWTextFrameSet *_frameSet = new KWTextFrameSet(m_doc, name );
00910 _frameSet->addFrame( frame );
00911 m_doc->addFrameSet( _frameSet );
00912 KWCreateFrameCommand *cmd=new KWCreateFrameCommand( i18n("Create Text Frame"), frame );
00913 if ( checkCurrentEdit(frame->frameSet(), true) )
00914 emit currentFrameSetEditChanged();
00915 return cmd;
00916 }
00917 return 0L;
00918 }
00919
00920 void KWCanvas::mrCreateText()
00921 {
00922 m_insRect = m_insRect.normalize();
00923 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
00924 KWFrame *frame = new KWFrame(0L, m_insRect.x(), m_insRect.y(), m_insRect.width(), m_insRect.height() );
00925 frame->setMinimumFrameHeight( frame->height() );
00926 frame->setNewFrameBehavior(KWFrame::Reconnect);
00927 frame->setZOrder( m_doc->maxZOrder( frame->pageNumber(m_doc) ) + 1 );
00928 KWFrameDia frameDia( this, frame, m_doc, FT_TEXT );
00929 frameDia.setCaption(i18n("Connect Frame"));
00930 frameDia.exec();
00931 if ( checkCurrentEdit(frame->frameSet(), true) )
00932 emit currentFrameSetEditChanged();
00933 }
00934 setMouseMode( MM_EDIT );
00935 m_doc->repaintAllViews();
00936 emit docStructChanged(TextFrames);
00937 emit currentFrameSetEditChanged();
00938 }
00939
00940 void KWCanvas::mrCreatePixmap()
00941 {
00942
00943 Q_ASSERT(m_insRect.width() > 0 && m_insRect.height() > 0);
00944
00945 double ratio = m_insRect.width() / m_insRect.height();
00946 KoRect picRect(m_doc->pageManager()->clipToDocument(m_insRect.topLeft()),
00947 m_doc->pageManager()->clipToDocument(m_insRect.bottomRight()) );
00948 picRect = picRect.normalize();
00949
00950
00951 KWPage *page = m_doc->pageManager()->page( picRect.bottom() );
00952 KoRect pageRect = page->rect();
00953 picRect = pageRect.intersect(picRect);
00954
00955
00956 double height = picRect.width() / ratio ;
00957 if(picRect.height() > height)
00958 picRect.setBottom(picRect.top() + height);
00959 else
00960 picRect.setRight(picRect.left() + ratio * picRect.height());
00961
00962 setMouseMode( MM_EDIT );
00963 if ( !m_kopicture.isNull() ) {
00964 KWPictureFrameSet *fs = new KWPictureFrameSet( m_doc, QString::null );
00965 fs->insertPicture( m_kopicture );
00966 fs->setKeepAspectRatio( m_keepRatio );
00967 KWFrame *frame = new KWFrame(fs, picRect.x(), picRect.y(), picRect.width(),
00968 picRect.height() );
00969 frame->setZOrder( m_doc->maxZOrder( page->pageNumber() ) +1 );
00970 fs->addFrame( frame, false );
00971 m_doc->addFrameSet( fs );
00972 KWCreateFrameCommand *cmd=new KWCreateFrameCommand( i18n("Insert Picture"), frame );
00973 m_doc->addCommand(cmd);
00974 m_doc->frameChanged( frame );
00975 frameViewManager()->view(frame)->setSelected(true);
00976 }
00977 emit docStructChanged(Pictures);
00978 }
00979
00980 void KWCanvas::mrCreatePart()
00981 {
00982 m_insRect = m_insRect.normalize();
00983 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
00984 KWPartFrameSet *fs = m_doc->insertObject( m_insRect, m_partEntry, this );
00985 Q_ASSERT(viewMode()->canvas());
00986 if(fs)
00987 fs->updateChildGeometry();
00988 }
00989 setMouseMode( MM_EDIT );
00990 emit docStructChanged(Embedded);
00991 }
00992
00993 void KWCanvas::mrCreateFormula()
00994 {
00995 m_insRect = m_insRect.normalize();
00996 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
00997 KWFormulaFrameSet *frameset = new KWFormulaFrameSet( m_doc, QString::null );
00998 KWFrame *frame = new KWFrame(frameset, m_insRect.x(), m_insRect.y(), m_insRect.width(), m_insRect.height() );
00999 frame->setZOrder( m_doc->maxZOrder( frame->pageNumber(m_doc) ) + 1 );
01000 frameset->addFrame( frame, false );
01001 m_doc->addFrameSet( frameset );
01002 KWCreateFrameCommand *cmd=new KWCreateFrameCommand( i18n("Create Formula Frame"), frame );
01003 m_doc->addCommand(cmd);
01004 m_doc->frameChanged( frame );
01005 }
01006 setMouseMode( MM_EDIT );
01007 emit docStructChanged(FormulaFrames);
01008 }
01009
01010 void KWCanvas::mrCreateTable()
01011 {
01012 m_insRect = m_insRect.normalize();
01013 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
01014 if ( m_table.cols * s_minFrameWidth + m_insRect.x() > m_doc->pageManager()->pageLayout(0).ptWidth )
01015 {
01016 KMessageBox::sorry(0, i18n("KWord is unable to insert the table because there "
01017 "is not enough space available."));
01018 }
01019 else {
01020 KWTableFrameSet * table = createTable();
01021 KMacroCommand *macroCmd = new KMacroCommand( i18n("Create Table") );
01022
01023 KWCreateTableCommand *cmd=new KWCreateTableCommand( "Create table", table );
01024 macroCmd->addCommand(cmd);
01025 if (m_table.tt) {
01026 KWTableTemplateCommand *ttCmd=new KWTableTemplateCommand( "Apply template to table", table, m_table.tt );
01027 macroCmd->addCommand(ttCmd);
01028 }
01029 m_doc->addCommand(macroCmd);
01030 macroCmd->execute();
01031
01032 emit docStructChanged(Tables);
01033 }
01034 m_doc->updateAllFrames();
01035 m_doc->layout();
01036 repaintAll();
01037
01038 }
01039 setMouseMode( MM_EDIT );
01040 }
01041
01042 KWTableFrameSet * KWCanvas::createTable()
01043 {
01044 KWTableFrameSet *table = new KWTableFrameSet( m_doc, QString::null );
01045 int pageNum = m_doc->pageManager()->pageNumber(m_insRect.topLeft());
01046
01047
01048 for ( unsigned int i = 0; i < m_table.rows; i++ ) {
01049 for ( unsigned int j = 0; j < m_table.cols; j++ ) {
01050 KWTableFrameSet::Cell *cell = new KWTableFrameSet::Cell( table, i, j, QString::null );
01051 KWFrame *frame = new KWFrame(cell, 0, 0, 0, 0, KWFrame::RA_BOUNDINGRECT );
01052 frame->setZOrder( m_doc->maxZOrder( pageNum ) + 1 );
01053 cell->addFrame( frame, false );
01054 frame->setFrameBehavior(KWFrame::AutoExtendFrame);
01055 frame->setNewFrameBehavior(KWFrame::NoFollowup);
01056 }
01057 }
01058 KWTableFrameSet::CellSize w;
01059 w=static_cast<KWTableFrameSet::CellSize>( m_table.width );
01060 if(m_frameInline) w=KWTableFrameSet::TblManual;
01061 table->setBoundingRect( m_insRect , w, static_cast<KWTableFrameSet::CellSize>( m_table.height ));
01062 return table;
01063 }
01064
01065 void KWCanvas::contentsMouseReleaseEvent( QMouseEvent * e )
01066 {
01067 if ( m_printing )
01068 return;
01069 if ( m_scrollTimer->isActive() )
01070 m_scrollTimer->stop();
01071 if ( m_mousePressed ) {
01072 if ( m_deleteMovingRect )
01073 deleteMovingRect();
01074
01075 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
01076 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01077
01078 if(m_insRect.bottom()==0 && m_insRect.right()==0) {
01079
01080 int page = m_doc->pageManager()->pageNumber(docPoint);
01081 if(page == -1)
01082 return;
01083 KoPageLayout pageLayout = m_doc->pageManager()->pageLayout(page);
01084 m_insRect.setLeft(QMIN(m_insRect.left(), pageLayout.ptWidth - 200));
01085 m_insRect.setTop(QMIN(m_insRect.top(), pageLayout.ptHeight - 150));
01086 m_insRect.setBottom(m_insRect.top()+150);
01087 m_insRect.setRight(m_insRect.left()+200);
01088 }
01089 MouseMode old_mouseMove = m_mouseMode;
01090 switch ( m_mouseMode ) {
01091 case MM_EDIT:
01092 if ( m_currentFrameSetEdit )
01093 m_currentFrameSetEdit->mouseReleaseEvent( e, normalPoint, docPoint );
01094 else {
01095 if ( m_mouseMeaning == MEANING_RESIZE_COLUMN )
01096 {
01097 KWResizeColumnCommand *cmd = new KWResizeColumnCommand( m_currentTable, m_rowColResized, m_previousTableSize, docPoint.x() );
01098 m_doc->addCommand(cmd);
01099 cmd->execute();
01100 }
01101 else if ( m_mouseMeaning == MEANING_RESIZE_ROW )
01102 {
01103 KWResizeRowCommand *cmd = new KWResizeRowCommand( m_currentTable, m_rowColResized, m_previousTableSize, docPoint.y() );
01104 m_doc->addCommand(cmd);
01105 cmd->execute();
01106 }
01107 else
01108 mrEditFrame();
01109 m_mouseMeaning = MEANING_NONE;
01110 }
01111 break;
01112 case MM_CREATE_TEXT:
01113 mrCreateText();
01114 break;
01115 case MM_CREATE_PIX:
01116 mrCreatePixmap();
01117 break;
01118 case MM_CREATE_PART:
01119 mrCreatePart();
01120 break;
01121 case MM_CREATE_TABLE:
01122 mrCreateTable();
01123 break;
01124 case MM_CREATE_FORMULA:
01125 mrCreateFormula();
01126 break;
01127 }
01128
01129 if ( old_mouseMove != MM_EDIT && !m_doc->showGrid() && m_doc->snapToGrid() )
01130 repaintContents( FALSE );
01131 m_mousePressed = false;
01132 }
01133 }
01134
01135 void KWCanvas::contentsMouseDoubleClickEvent( QMouseEvent * e )
01136 {
01137 if ( m_printing )
01138 return;
01139 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
01140 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01141 switch ( m_mouseMode ) {
01142 case MM_EDIT:
01143 if ( m_currentFrameSetEdit )
01144 {
01145 m_mousePressed = true;
01146 m_scrollTimer->start( 50 );
01147 m_currentFrameSetEdit->mouseDoubleClickEvent( e, normalPoint, docPoint );
01148 }
01149 else
01150 {
01151
01152
01153 KWFrameView *view = m_frameViewManager->selectedFrame();
01154 bool isPartFrameSet = view && dynamic_cast<KWPartFrameSet*>(view->frame()->frameSet());
01155 if ( !isPartFrameSet )
01156 editFrameProperties();
01157
01158 m_mousePressed = false;
01159 }
01160 break;
01161 default:
01162 break;
01163 }
01164 }
01165
01166 void KWCanvas::setFrameBackgroundColor( const QBrush &_backColor )
01167 {
01168 QValueList<KWFrameView*> selectedFrames = m_frameViewManager->selectedFrames();
01169 if (selectedFrames.isEmpty())
01170 return;
01171 bool colorChanged=false;
01172 QPtrList<FrameIndex> frameindexList;
01173 QPtrList<QBrush> oldColor;
01174
01175 QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
01176 while(framesIterator != selectedFrames.end()) {
01177 KWFrame *frame = KWFrameSet::settingsFrame( (*framesIterator)->frame() );
01178 FrameIndex *index=new FrameIndex( frame );
01179 frameindexList.append(index);
01180
01181 QBrush *_color=new QBrush(frame->backgroundColor());
01182 oldColor.append(_color);
01183
01184 if (frame->frameSet() && frame->frameSet()->type()!=FT_PICTURE && frame->frameSet()->type()!=FT_PART && _backColor!=frame->backgroundColor())
01185 {
01186 colorChanged=true;
01187 frame->setBackgroundColor(_backColor);
01188 }
01189 ++framesIterator;
01190 }
01191 if(colorChanged)
01192 {
01193 KWFrameBackGroundColorCommand *cmd=new KWFrameBackGroundColorCommand(i18n("Change Frame Background Color"),frameindexList,oldColor,_backColor);
01194 m_doc->addCommand(cmd);
01195 m_doc->repaintAllViews();
01196 }
01197 else
01198 {
01199 frameindexList.setAutoDelete(true);
01200 oldColor.setAutoDelete(true);
01201 }
01202 }
01203
01204 void KWCanvas::editFrameProperties( KWFrameSet * frameset )
01205 {
01206 KWFrameDia *frameDia;
01207 KWFrame *frame = frameset->frame(0);
01208 frameDia = new KWFrameDia( this, frame );
01209 frameDia->exec();
01210 delete frameDia;
01211 }
01212
01213 void KWCanvas::editFrameProperties()
01214 {
01215 QValueList<KWFrameView*> selectedFrames = m_frameViewManager->selectedFrames();
01216 if(selectedFrames.count()==0) return;
01217
01218 KWFrameDia *frameDia;
01219 if(selectedFrames.count()==1)
01220 frameDia = new KWFrameDia( this, selectedFrames[0]->frame());
01221 else {
01222 QPtrList<KWFrame> frames;
01223 QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
01224 for(;framesIterator != selectedFrames.end(); ++framesIterator)
01225 frames.append( (*framesIterator)->frame() );
01226 frameDia = new KWFrameDia( this, frames );
01227 }
01228 frameDia->exec();
01229 delete frameDia;
01230 }
01231
01232 void KWCanvas::selectAllFrames( bool select ) {
01233 QValueList<KWFrameView*> frameViews = m_frameViewManager->frameViewsIterator();
01234 QValueList<KWFrameView*>::iterator frames = frameViews.begin();
01235 for(; frames != frameViews.end(); ++frames ) {
01236 KWFrameSet *fs = (*frames)->frame()->frameSet();
01237 if ( !fs->isVisible() ) continue;
01238 if ( select && fs->isMainFrameset() )
01239 continue;
01240 (*frames)->setSelected(select);
01241 }
01242 }
01243
01244 void KWCanvas::tableSelectCell(KWTableFrameSet *table, KWFrameSet *cell)
01245 {
01246 terminateCurrentEdit();
01247 m_frameViewManager->view(cell->frame(0))->setSelected(true);
01248 m_currentTable = table;
01249 }
01250
01251 void KWCanvas::editFrameSet( KWFrameSet * frameSet, bool onlyText )
01252 {
01253 selectAllFrames( false );
01254 bool emitChanged = checkCurrentEdit( frameSet, onlyText );
01255
01256 if ( emitChanged )
01257 emit currentFrameSetEditChanged();
01258 emit updateRuler();
01259 }
01260
01261 void KWCanvas::editTextFrameSet( KWFrameSet * fs, KoTextParag* parag, int index )
01262 {
01263 selectAllFrames( false );
01264
01265 #if 0
01266
01267
01268 if ( fs->isAHeader() && !m_doc->isHeaderVisible() && !(viewMode()->type()=="ModeText"))
01269 m_doc->setHeaderVisible( true );
01270 if ( fs->isAFooter() && !m_doc->isFooterVisible() && !(viewMode()->type()=="ModeText"))
01271 m_doc->setFooterVisible( true );
01272 #endif
01273
01274 if ( !fs->isVisible( viewMode() ) )
01275 return;
01276 setMouseMode( MM_EDIT );
01277 bool emitChanged = checkCurrentEdit( fs );
01278
01279 if ( m_currentFrameSetEdit && m_currentFrameSetEdit->frameSet()->type()==FT_TEXT ) {
01280 if ( !parag )
01281 {
01282 KWTextDocument *tmp = static_cast<KWTextFrameSet*>(m_currentFrameSetEdit->frameSet())->kwTextDocument();
01283 parag = tmp->firstParag();
01284 }
01285
01286 KWTextFrameSetEdit *textedit = currentTextEdit();
01287 if ( textedit ) {
01288 textedit->hideCursor();
01289 textedit->setCursor( parag, index );
01290 textedit->showCursor();
01291 textedit->ensureCursorVisible();
01292 }
01293 }
01294 if ( emitChanged )
01295 emit currentFrameSetEditChanged();
01296 emit updateRuler();
01297 }
01298
01299 void KWCanvas::ensureCursorVisible()
01300 {
01301 Q_ASSERT( m_currentFrameSetEdit );
01302 KWTextFrameSetEdit *textedit = currentTextEdit();
01303 if ( textedit )
01304 textedit->ensureCursorVisible();
01305 }
01306
01307 bool KWCanvas::checkCurrentEdit( KWFrameSet * fs , bool onlyText )
01308 {
01309 bool emitChanged = false;
01310 if ( fs && m_currentFrameSetEdit && m_currentFrameSetEdit->frameSet() != fs )
01311 {
01312 KWTextFrameSet * tmp = dynamic_cast<KWTextFrameSet *>(fs );
01313 if ( tmp && tmp->protectContent() && !m_doc->cursorInProtectedArea() )
01314 return false;
01315
01316 KWTextFrameSetEdit *edit = currentTextEdit();
01317 if(edit && onlyText)
01318 {
01319
01320
01321 m_currentFrameSetEdit->terminate(false);
01322 }
01323 else
01324 m_currentFrameSetEdit->terminate();
01325 delete m_currentFrameSetEdit;
01326 m_currentFrameSetEdit = 0L;
01327 emitChanged = true;
01328
01329 }
01330
01331
01332 if ( fs && !m_currentFrameSetEdit )
01333 {
01334 KWTextFrameSet * tmp = dynamic_cast<KWTextFrameSet *>(fs );
01335 if ( tmp && tmp->protectContent() && !m_doc->cursorInProtectedArea() )
01336 return false;
01337
01338 if(fs->type()==FT_TABLE || fs->type()==FT_TEXT || !onlyText)
01339 {
01340 if ( fs->type() == FT_TABLE )
01341 m_currentTable = static_cast<KWTableFrameSet *>(fs);
01342 else if ( fs->type() == FT_TEXT )
01343 m_currentTable = static_cast<KWTextFrameSet *>(fs)->groupmanager();
01344 else
01345 m_currentTable = 0L;
01346 if ( m_currentTable ) {
01347 m_currentFrameSetEdit = m_currentTable->createFrameSetEdit( this );
01348 static_cast<KWTableFrameSetEdit *>( m_currentFrameSetEdit )->setCurrentCell( fs );
01349 }
01350 else
01351 m_currentFrameSetEdit = fs->createFrameSetEdit( this );
01352
01353 if ( m_currentFrameSetEdit ) {
01354 KWTextFrameSetEdit *edit = currentTextEdit();
01355 if ( edit )
01356 edit->setOverwriteMode( m_overwriteMode );
01357 }
01358 }
01359 emitChanged = true;
01360 }
01361 return emitChanged;
01362 }
01363
01364 void KWCanvas::terminateCurrentEdit()
01365 {
01366 if(m_currentFrameSetEdit == 0)
01367 return;
01368 m_lastCaretPos = caretPos();
01369 m_currentFrameSetEdit->terminate();
01370 delete m_currentFrameSetEdit;
01371 m_currentFrameSetEdit = 0L;
01372 emit currentFrameSetEditChanged();
01373 repaintAll();
01374 }
01375
01376 void KWCanvas::terminateEditing( KWFrameSet *fs )
01377 {
01378 if ( m_currentFrameSetEdit && m_currentFrameSetEdit->frameSet() == fs )
01379 terminateCurrentEdit();
01380
01381 QPtrListIterator<KWFrame> frameIt = fs->frameIterator();
01382 for ( ; frameIt.current(); ++frameIt ) {
01383 KWFrameView* view = m_frameViewManager->view(frameIt.current());
01384 Q_ASSERT(view);
01385 if(view) view->setSelected(false);
01386 }
01387 }
01388
01389 KWTextFrameSetEdit* KWCanvas::currentTextEdit() const
01390 {
01391 if ( m_currentFrameSetEdit )
01392 return dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit->currentTextEdit());
01393 return 0;
01394 }
01395
01396 void KWCanvas::setMouseMode( MouseMode newMouseMode )
01397 {
01398 if ( m_mouseMode != newMouseMode )
01399 {
01400 selectAllFrames( false );
01401
01402 if ( newMouseMode != MM_EDIT )
01403 terminateCurrentEdit();
01404
01405 m_mouseMode = newMouseMode;
01406 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
01407 repaintContents( FALSE );
01408 }
01409 else
01410 m_mouseMode = newMouseMode;
01411 emit currentMouseModeChanged(m_mouseMode);
01412
01413 switch ( m_mouseMode ) {
01414 case MM_EDIT: {
01415 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01416 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01417 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01418 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, 0 ) );
01419 m_frameInline = false;
01420 } break;
01421 case MM_CREATE_TEXT:
01422 case MM_CREATE_PIX:
01423 case MM_CREATE_TABLE:
01424 case MM_CREATE_FORMULA:
01425 case MM_CREATE_PART:
01426 viewport()->setCursor( crossCursor );
01427 break;
01428 }
01429 }
01430
01431 void KWCanvas::insertPicture( const KoPicture& newPicture, QSize pixmapSize, bool _keepRatio )
01432 {
01433 setMouseMode( MM_CREATE_PIX );
01434 m_kopicture = newPicture;
01435 m_pixmapSize = pixmapSize;
01436 if ( pixmapSize.isEmpty() )
01437 m_pixmapSize = newPicture.getOriginalSize();
01438 m_keepRatio = _keepRatio;
01439 }
01440
01441 void KWCanvas::insertPictureDirect( const KoPicture& picture, const KoPoint& pos, const QSize& sz )
01442 {
01443
01444 m_pixmapSize = sz.isEmpty() ? picture.getOriginalSize() : sz;
01445 m_kopicture = picture;
01446 m_insRect = KoRect( pos.x(), pos.y(), m_doc->unzoomItX( m_pixmapSize.width() ), m_doc->unzoomItY( m_pixmapSize.height() ) );
01447 m_keepRatio = true;
01448 mrCreatePixmap();
01449 }
01450
01451 void KWCanvas::insertPart( const KoDocumentEntry &entry )
01452 {
01453 m_partEntry = entry;
01454 if ( m_partEntry.isEmpty() )
01455 {
01456 setMouseMode( MM_EDIT );
01457 return;
01458 }
01459 setMouseMode( MM_CREATE_PART );
01460 }
01461
01462 void KWCanvas::contentsDragEnterEvent( QDragEnterEvent *e )
01463 {
01464 int provides = KWView::checkClipboard( e );
01465 if ( ( provides & KWView::ProvidesImage ) || KURLDrag::canDecode( e ) )
01466 {
01467 m_imageDrag = true;
01468 e->acceptAction();
01469 }
01470 else
01471 {
01472 m_imageDrag = false;
01473 if ( m_currentFrameSetEdit )
01474 m_currentFrameSetEdit->dragEnterEvent( e );
01475 }
01476 }
01477
01478 void KWCanvas::contentsDragMoveEvent( QDragMoveEvent *e )
01479 {
01480 if ( !m_imageDrag )
01481 {
01482 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
01483 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01484 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
01485 KWFrame *frame = view ? view->frame() : 0;
01486 KWFrameSet * fs = frame ? frame->frameSet() : 0L;
01487 bool emitChanged = false;
01488 if ( fs )
01489 {
01490
01491 emitChanged = checkCurrentEdit( fs, true );
01492 }
01493 if ( m_currentFrameSetEdit )
01494 {
01495 m_currentFrameSetEdit->dragMoveEvent( e, normalPoint, docPoint );
01496
01497 if ( emitChanged )
01498 emit currentFrameSetEditChanged();
01499 }
01500 }
01501 }
01502
01503 void KWCanvas::contentsDragLeaveEvent( QDragLeaveEvent *e )
01504 {
01505 if ( !m_imageDrag && m_currentFrameSetEdit )
01506 m_currentFrameSetEdit->dragLeaveEvent( e );
01507 }
01508
01509 void KWCanvas::contentsDropEvent( QDropEvent *e )
01510 {
01511 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
01512 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01513
01514 if ( QImageDrag::canDecode( e ) ) {
01515 pasteImage( e, docPoint );
01516 } else if ( KURLDrag::canDecode( e ) ) {
01517
01518
01519
01520
01521 KURL::List lst;
01522 KURLDrag::decode( e, lst );
01523
01524 KURL::List::ConstIterator it = lst.begin();
01525 for ( ; it != lst.end(); ++it ) {
01526 const KURL &url( *it );
01527
01528 QString filename;
01529 if ( !KIO::NetAccess::download( url, filename, this ) )
01530 continue;
01531
01532 KMimeType::Ptr res = KMimeType::findByFileContent( filename );
01533
01534 if ( res && res->isValid() ) {
01535 QString mimetype = res->name();
01536 if ( mimetype.contains( "image" ) ) {
01537 KoPictureKey key;
01538 key.setKeyFromFile( filename );
01539 KoPicture newKoPicture;
01540 newKoPicture.setKey( key );
01541 newKoPicture.loadFromFile( filename );
01542 insertPictureDirect( newKoPicture, docPoint );
01543 }
01544 }
01545 KIO::NetAccess::removeTempFile( filename );
01546 }
01547 }
01548 else
01549 {
01550 if ( m_currentFrameSetEdit )
01551 m_currentFrameSetEdit->dropEvent( e, normalPoint, docPoint, m_gui->getView() );
01552 else
01553 m_gui->getView()->pasteData( e, true );
01554 }
01555 m_mousePressed = false;
01556 m_imageDrag = false;
01557 }
01558
01559 void KWCanvas::pasteImage( QMimeSource *e, const KoPoint &docPoint )
01560 {
01561 QImage i;
01562 if ( !QImageDrag::decode(e, i) ) {
01563 kdWarning() << "Couldn't decode image" << endl;
01564 return;
01565 }
01566 KTempFile tmpFile( QString::null, ".png");
01567 tmpFile.setAutoDelete( true );
01568 if ( !i.save(tmpFile.name(), "PNG") ) {
01569 kdWarning() << "Couldn't save image to " << tmpFile.name() << endl;
01570 return;
01571 }
01572 m_pixmapSize = i.size();
01573
01574 KoPictureKey key;
01575 key.setKeyFromFile( tmpFile.name() );
01576 KoPicture newKoPicture;
01577 newKoPicture.setKey( key );
01578 newKoPicture.loadFromFile( tmpFile.name() );
01579 m_kopicture = newKoPicture;
01580 m_insRect = KoRect( docPoint.x(), docPoint.y(), m_doc->unzoomItX( i.width() ), m_doc->unzoomItY( i.height() ) );
01581 m_keepRatio = true;
01582 mrCreatePixmap();
01583 }
01584
01585 void KWCanvas::doAutoScroll()
01586 {
01587 if ( !m_mousePressed )
01588 {
01589 m_scrollTimer->stop();
01590 return;
01591 }
01592
01593
01594 QPoint pos( mapFromGlobal( QCursor::pos() ) );
01595
01596 pos = QPoint(pos.x() - viewport()->x(), pos.y() - viewport()->y());
01597 if ( (pos.y() < 0) || (pos.y() > visibleHeight()) ||
01598 (pos.x() < 0) || (pos.x() > visibleWidth()) )
01599 {
01600 int xm, ym;
01601 viewportToContents(pos.x(), pos.y(), xm, ym);
01602 if ( m_currentFrameSetEdit )
01603 m_currentFrameSetEdit->focusOutEvent();
01604 if ( m_deleteMovingRect )
01605 deleteMovingRect();
01606 ensureVisible( xm, ym, 0, 5 );
01607 if ( m_currentFrameSetEdit )
01608 m_currentFrameSetEdit->focusInEvent();
01609 }
01610 }
01611
01612 void KWCanvas::slotContentsMoving( int cx, int cy )
01613 {
01614
01615 QPoint nPointBottom = m_viewMode->viewToNormal( QPoint( cx + visibleWidth(), cy + visibleHeight() ) );
01616
01617
01618
01619 QPtrList<KWTextFrameSet> textFrameSets = m_doc->allTextFramesets( false );
01620 QPtrListIterator<KWTextFrameSet> fit( textFrameSets );
01621 for ( ; fit.current() ; ++fit )
01622 {
01623 if(! fit.current()->isVisible()) continue;
01624 fit.current()->updateViewArea( this, m_viewMode, nPointBottom );
01625 }
01626
01627
01628 updateRulerOffsets( cx, cy );
01629
01630
01631
01632
01633
01634 QTimer::singleShot( 0, this, SIGNAL( viewTransformationsChanged() ) );
01635 }
01636
01637 void KWCanvas::slotMainTextHeightChanged()
01638 {
01639
01640 if ( dynamic_cast<KWViewModeText *>(m_viewMode) && m_gui->getHorzRuler() )
01641 {
01642 slotNewContentsSize();
01643 m_viewMode->setPageLayout( m_gui->getHorzRuler(), m_gui->getVertRuler(), KoPageLayout() );
01644 emit updateRuler();
01645 }
01646 }
01647
01648 void KWCanvas::slotNewContentsSize()
01649 {
01650 QSize size = m_viewMode->contentsSize();
01651 if ( size != QSize( contentsWidth(), contentsHeight() ) )
01652 {
01653
01654 resizeContents( size.width(), size.height() );
01655 }
01656 }
01657
01658 void KWCanvas::resizeEvent( QResizeEvent *e )
01659 {
01660 slotContentsMoving( contentsX(), contentsY() );
01661 QScrollView::resizeEvent( e );
01662 }
01663
01664 void KWCanvas::scrollToOffset( const KoPoint & d )
01665 {
01666 kdDebug() << "KWCanvas::scrollToOffset " << d.x() << "," << d.y() << endl;
01667 #if 0
01668 bool blinking = blinkTimer.isActive();
01669 if ( blinking )
01670 stopBlinkCursor();
01671 #endif
01672 QPoint nPoint = m_doc->zoomPoint( d );
01673 QPoint cPoint = m_viewMode->normalToView( nPoint );
01674 setContentsPos( cPoint.x(), cPoint.y() );
01675
01676 #if 0
01677 if ( blinking )
01678 startBlinkCursor();
01679 #endif
01680 }
01681
01682 void KWCanvas::updateRulerOffsets( int cx, int cy )
01683 {
01684 if ( cx == -1 && cy == -1 )
01685 {
01686 cx = contentsX();
01687 cy = contentsY();
01688 }
01689
01690
01691 QPoint pc = m_viewMode->pageCorner();
01692
01693 m_gui->getHorzRuler()->setOffset( cx - pc.x(), 0 );
01694 m_gui->getVertRuler()->setOffset( 0, cy - pc.y() );
01695
01696 }
01697
01698 bool KWCanvas::eventFilter( QObject *o, QEvent *e )
01699 {
01700 if ( o == this || o == viewport() ) {
01701
01702 if(m_currentFrameSetEdit && o == this )
01703 {
01704
01705 KCursor::autoHideEventFilter( o, e );
01706 }
01707
01708 switch ( e->type() ) {
01709 case QEvent::FocusIn:
01710
01711 if ( m_currentFrameSetEdit && !m_printing )
01712 m_currentFrameSetEdit->focusInEvent();
01713 break;
01714 case QEvent::FocusOut:
01715
01716 if ( m_currentFrameSetEdit && !m_printing )
01717 m_currentFrameSetEdit->focusOutEvent();
01718 if ( m_scrollTimer->isActive() )
01719 m_scrollTimer->stop();
01720 m_mousePressed = false;
01721 break;
01722 case QEvent::AccelOverride:
01723 {
01724
01725
01726 QKeyEvent * keyev = static_cast<QKeyEvent *>(e);
01727 #ifndef NDEBUG
01728
01729 if ( ( keyev->state() & ControlButton ) && ( keyev->state() & ShiftButton ) )
01730 {
01731 switch ( keyev->key() ) {
01732 case Qt::Key_P:
01733 printRTDebug( 0 );
01734 keyev->accept();
01735 break;
01736 case Qt::Key_V:
01737 printRTDebug( 1 );
01738 keyev->accept();
01739 break;
01740 case Qt::Key_F:
01741 m_doc->printDebug();
01742 kdDebug(32002) << "Current framesetedit: " << m_currentFrameSetEdit << " " <<
01743 ( m_currentFrameSetEdit ? m_currentFrameSetEdit->frameSet()->className() : "" ) << endl;
01744 keyev->accept();
01745 break;
01746 case Qt::Key_S:
01747 m_doc->printStyleDebug();
01748 keyev->accept();
01749 break;
01750 case Qt::Key_M:
01751 {
01752 const QDateTime dtMark ( QDateTime::currentDateTime() );
01753 kdDebug(32002) << "Developer mark: " << dtMark.toString("yyyy-MM-dd hh:mm:ss,zzz") << endl;
01754 keyev->accept();
01755 break;
01756 }
01757 default:
01758 break;
01759 };
01760
01761 }
01762 #endif
01763 }
01764 break;
01765 case QEvent::KeyPress:
01766 {
01767
01768
01769 QKeyEvent * keyev = static_cast<QKeyEvent *>(e);
01770
01771 if ( !m_doc->pgUpDownMovesCaret() && ( (keyev->state() & ShiftButton) == 0 )
01772 && ( keyev->key() == Qt::Key_PageUp || keyev->key() == Key_PageDown ) )
01773 {
01774 viewportScroll( keyev->key() == Qt::Key_PageUp );
01775 }
01776
01777
01778
01779
01780 else if ( keyev->key() == KGlobalSettings::contextMenuKey() ) {
01781
01782 if(!m_doc->isReadWrite()) return TRUE;
01783 if (m_mouseMode != MM_EDIT) return TRUE;
01784 KoPoint docPoint = m_doc->unzoomPoint( QCursor::pos() );
01785
01786 if ( viewMode()->type()=="ModeText") {
01787 KWFrameView *view = m_frameViewManager->view(m_doc->frameSet( 0 )->frame(0));
01788 view->showPopup(docPoint, m_gui->getView(), QCursor::pos());
01789 }
01790 else {
01791 m_frameViewManager->showPopup( docPoint, m_gui->getView(), keyev->state(), pos());
01792 }
01793 return true;
01794 }
01795 else if ( keyev->key() == Qt::Key_Return && keyev->state() == 0
01796 && (m_mouseMode != MM_EDIT || m_frameInline )) {
01797
01798
01799
01800
01801
01802
01803 if (m_frameInline)
01804 m_lastCaretPos = caretPos();
01805 if (m_lastCaretPos.isNull()) return TRUE;
01806 int page = m_doc->pageManager()->pageNumber(m_lastCaretPos);
01807 if(page == -1) return TRUE;
01808 QPoint normalPoint = m_doc->zoomPoint(m_lastCaretPos);
01809
01810
01811
01812 if (m_frameInline)
01813 normalPoint += QPoint(2,2);
01814 QPoint vP = m_viewMode->normalToView(normalPoint);
01815 QPoint gP = mapToGlobal(vP);
01816 QMouseEvent mevPress(QEvent::MouseButtonPress, vP,
01817 gP, Qt::LeftButton, 0);
01818 contentsMousePressEvent(&mevPress);
01819 QMouseEvent mevRelease(QEvent::MouseButtonRelease, vP,
01820 gP, Qt::LeftButton, 0);
01821 contentsMouseReleaseEvent(&mevRelease);
01822 }
01823 else if ( keyev->key() == Qt::Key_Escape ) {
01824 if ( m_mouseMode != MM_EDIT )
01825 setMouseMode( MM_EDIT );
01826 else if(m_interactionPolicy) {
01827 m_interactionPolicy->cancelInteraction();
01828 delete(m_interactionPolicy);
01829 m_interactionPolicy = 0;
01830 m_mousePressed = false;
01831
01832
01833 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01834 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01835 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01836 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
01837 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
01838 repaintContents();
01839 }
01840 }
01841 else if ( keyev->key() == Key_Insert && keyev->state() == 0 ) {
01842 m_overwriteMode = !m_overwriteMode;
01843 KWTextFrameSetEdit *edit = currentTextEdit();
01844 if ( edit ) {
01845 edit->setOverwriteMode( m_overwriteMode );
01846 emit overwriteModeChanged( m_overwriteMode );
01847 }
01848 kdDebug()<<"Insert is pressed, overwrite mode: "<< m_overwriteMode << endl;
01849 }
01850 else
01851 if ( m_currentFrameSetEdit && m_mouseMode == MM_EDIT && m_doc->isReadWrite() && !m_printing )
01852 {
01853 KWTextFrameSetEdit *edit = dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit );
01854 if ( edit )
01855 {
01856 if ( !edit->textFrameSet()->textObject()->protectContent() || (keyev->text().length() == 0))
01857 m_currentFrameSetEdit->keyPressEvent( keyev );
01858 else if(keyev->text().length() > 0)
01859 KMessageBox::information(this, i18n("Read-only content cannot be changed. No modifications will be accepted."));
01860 }
01861 else
01862 m_currentFrameSetEdit->keyPressEvent( keyev );
01863 return TRUE;
01864 }
01865
01866
01867 if ( keyev->key() == Qt::Key_Control )
01868 {
01869 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01870 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01871 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01872 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
01873 }
01874 else if ( (keyev->key() == Qt::Key_Delete || keyev->key() ==Key_Backspace )
01875 && m_frameViewManager->selectedFrame() && !m_printing )
01876 m_gui->getView()->editDeleteFrame();
01877 } break;
01878 case QEvent::KeyRelease:
01879 {
01880 QKeyEvent * keyev = static_cast<QKeyEvent *>(e);
01881 if ( keyev->key() == Qt::Key_Control )
01882 {
01883 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01884 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01885 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01886 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
01887 }
01888
01889 if ( m_currentFrameSetEdit && m_mouseMode == MM_EDIT && m_doc->isReadWrite() && !m_printing )
01890 {
01891 m_currentFrameSetEdit->keyReleaseEvent( keyev );
01892 return TRUE;
01893 }
01894 }
01895 break;
01896 case QEvent::IMStart:
01897 {
01898 QIMEvent * imev = static_cast<QIMEvent *>(e);
01899 m_currentFrameSetEdit->imStartEvent( imev );
01900 }
01901 break;
01902 case QEvent::IMCompose:
01903 {
01904 QIMEvent * imev = static_cast<QIMEvent *>(e);
01905 m_currentFrameSetEdit->imComposeEvent( imev );
01906 }
01907 break;
01908 case QEvent::IMEnd:
01909 {
01910 QIMEvent * imev = static_cast<QIMEvent *>(e);
01911 m_currentFrameSetEdit->imEndEvent( imev );
01912 }
01913 break;
01914 default:
01915 break;
01916 }
01917 }
01918 return QScrollView::eventFilter( o, e );
01919 }
01920
01921 bool KWCanvas::focusNextPrevChild( bool next)
01922 {
01923 Q_UNUSED(next);
01924 return TRUE;
01925
01926
01927
01928 }
01929
01930 void KWCanvas::updateCurrentFormat()
01931 {
01932 KWTextFrameSetEdit * edit = dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit);
01933 if ( edit )
01934 edit->updateUI( true, true );
01935 }
01936
01937 #ifndef NDEBUG
01938 void KWCanvas::printRTDebug( int info )
01939 {
01940 KWTextFrameSet * textfs = 0L;
01941 if ( m_currentFrameSetEdit ) {
01942 KWTextFrameSetEdit* edit = currentTextEdit();
01943 if ( edit ) {
01944 textfs = dynamic_cast<KWTextFrameSet *>( edit->frameSet() );
01945 Q_ASSERT( textfs );
01946 }
01947 }
01948 if ( !textfs )
01949 textfs = dynamic_cast<KWTextFrameSet *>(m_doc->frameSet( 0 ));
01950 if ( textfs )
01951 textfs->textObject()->printRTDebug( info );
01952 }
01953 #endif
01954
01955 void KWCanvas::setXimPosition( int x, int y, int w, int h )
01956 {
01957
01958
01959
01960
01961 if (hasFocus())
01962 QWidget::setMicroFocusHint( x - contentsX(), y - contentsY(), w, h );
01963 }
01964
01965 void KWCanvas::inlinePictureStarted()
01966 {
01967 m_frameInline=true;
01968 m_frameInlineType=FT_PICTURE;
01969 }
01970
01971 int KWCanvas::currentTableRow() const
01972 {
01973 if ( !m_currentFrameSetEdit )
01974 return -1;
01975 KWTextFrameSetEdit *edit = currentTextEdit();
01976 if ( !edit )
01977 return -1;
01978 KWTextFrameSet* textfs = edit->textFrameSet();
01979 if ( textfs && textfs->groupmanager() )
01980 return static_cast<KWTableFrameSet::Cell *>(textfs)->firstRow();
01981 return -1;
01982 }
01983
01984 int KWCanvas::currentTableCol() const
01985 {
01986 if ( !m_currentFrameSetEdit )
01987 return -1;
01988 KWTextFrameSetEdit *edit = currentTextEdit();
01989 if ( !edit )
01990 return -1;
01991 KWTextFrameSet* textfs = edit->textFrameSet();
01992 if ( textfs && textfs->groupmanager() )
01993 return static_cast<KWTableFrameSet::Cell *>(textfs)->firstColumn();
01994 return -1;
01995 }
01996
01997 void KWCanvas::viewportScroll( bool up )
01998 {
01999 if ( up )
02000 setContentsPos( contentsX(), contentsY() - visibleHeight() );
02001 else
02002 setContentsPos( contentsX(), contentsY() + visibleHeight() );
02003 }
02004
02005 void KWCanvas::resetStatusBarText()
02006 {
02007 if ( m_temporaryStatusBarTextShown )
02008 {
02009 gui()->getView()->updateFrameStatusBarItem();
02010 m_temporaryStatusBarTextShown = false;
02011 }
02012 }
02013
02014
02015
02016
02017 KoPoint KWCanvas::caretPos()
02018 {
02019 if (!m_currentFrameSetEdit) return KoPoint();
02020 KWTextFrameSetEdit* textEdit = currentTextEdit();
02021 if (!textEdit) return KoPoint();
02022 KoTextCursor* cursor = textEdit->cursor();
02023 if (!cursor) return KoPoint();
02024 KWTextFrameSet* textFrameset =
02025 dynamic_cast<KWTextFrameSet *>(m_currentFrameSetEdit->frameSet());
02026 if (!textFrameset) return KoPoint();
02027 KWFrame* currentFrame = m_currentFrameSetEdit->currentFrame();
02028 if (!currentFrame) return KoPoint();
02029
02030 QPoint viewP = textFrameset->cursorPos(cursor, this, currentFrame);
02031 viewP.rx() += contentsX();
02032 viewP.ry() += contentsY();
02033 QPoint normalP = m_viewMode->viewToNormal(viewP);
02034 KoPoint docP = m_doc->unzoomPoint(normalP);
02035 return docP;
02036 }
02037
02038
02039
02040 InteractionPolicy::InteractionPolicy(KWCanvas *parent, bool doInit, bool includeInlineFrames) {
02041 m_gotDragEvents = false;
02042 m_parent = parent;
02043 if(doInit) {
02044 QValueList<KWFrameView*> selectedFrames = m_parent->frameViewManager()->selectedFrames();
02045 QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
02046 for(;framesIterator != selectedFrames.end(); ++framesIterator) {
02047 KWFrame *frame = (*framesIterator)->frame();
02048 KWFrameSet *fs = frame->frameSet();
02049 if(! fs) continue;
02050 if(!fs->isVisible()) continue;
02051 if(fs->isMainFrameset() ) continue;
02052 if(fs->isFloating() && !includeInlineFrames) continue;
02053 if(fs->isProtectSize() ) continue;
02054 if(fs->type() == FT_TABLE ) continue;
02055 if(fs->type() == FT_TEXT && fs->frameSetInfo() != KWFrameSet::FI_BODY ) continue;
02056 m_frames.append( frame );
02057 m_indexFrame.append( FrameIndex( frame ) );
02058 }
02059 }
02060 }
02061
02062 InteractionPolicy* InteractionPolicy::createPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, Qt::ButtonState buttonState, Qt::ButtonState keyState) {
02063 if(buttonState & Qt::LeftButton || buttonState & Qt::RightButton) {
02064
02065 class Selector {
02066 public:
02067 Selector(KWCanvas *canvas, KoPoint &point, Qt::ButtonState buttonState, Qt::ButtonState keyState) :
02068 m_canvas(canvas), m_point(point), m_state(keyState) {
02069 m_leftClick = buttonState & Qt::LeftButton;
02070 KWFrameView *view = canvas->frameViewManager()->view(point,
02071 KWFrameViewManager::frameOnTop);
02072 m_doSomething = (view && !view->selected());
02073 }
02074
02075 void doSelect() {
02076 if(! m_doSomething) return;
02077 m_canvas->frameViewManager()->selectFrames(m_point, m_state, m_leftClick);
02078 }
02079 private:
02080 KWCanvas *m_canvas;
02081 KoPoint m_point;
02082 Qt::ButtonState m_state;
02083 bool m_leftClick, m_doSomething;
02084 };
02085
02086 Selector selector(parent, point, buttonState, keyState);
02087 switch(meaning) {
02088 case MEANING_MOUSE_MOVE:
02089 selector.doSelect();
02090 return new FrameMovePolicy(parent, point);
02091 case MEANING_TOPLEFT:
02092 case MEANING_TOP:
02093 case MEANING_TOPRIGHT:
02094 case MEANING_RIGHT:
02095 case MEANING_BOTTOMRIGHT:
02096 case MEANING_BOTTOM:
02097 case MEANING_BOTTOMLEFT:
02098 case MEANING_LEFT:
02099 selector.doSelect();
02100 return new FrameResizePolicy(parent, meaning, point);
02101 default:
02102 FrameSelectPolicy *fsp = new FrameSelectPolicy(parent, meaning, point, buttonState, keyState);
02103 if(fsp->isValid())
02104 return fsp;
02105 delete fsp;
02106 }
02107 }
02108 return 0;
02109 }
02110
02111 void InteractionPolicy::cancelInteraction() {
02112 KCommand *cmd = createCommand();
02113 if(cmd) {
02114 cmd->unexecute();
02115 delete cmd;
02116 }
02117 }
02118
02119
02120
02121 FrameResizePolicy::FrameResizePolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point) :
02122 InteractionPolicy (parent, true, true), m_boundingRect() {
02123
02124 if( meaning == MEANING_TOPLEFT) {
02125 m_top = true; m_bottom = false; m_left = true; m_right = false;
02126 }
02127 else if( meaning == MEANING_TOP) {
02128 m_top = true; m_bottom = false; m_left = false; m_right = false;
02129 }
02130 else if( meaning == MEANING_TOPRIGHT) {
02131 m_top = true; m_bottom = false; m_left = false; m_right = true;
02132 }
02133 else if( meaning == MEANING_RIGHT) {
02134 m_top = false; m_bottom = false; m_left = false; m_right = true;
02135 }
02136 else if( meaning == MEANING_BOTTOMRIGHT) {
02137 m_top = false; m_bottom = true; m_left = false; m_right = true;
02138 }
02139 else if( meaning == MEANING_BOTTOM) {
02140 m_top = false; m_bottom = true; m_left = false; m_right = false;
02141 }
02142 else if( meaning == MEANING_BOTTOMLEFT) {
02143 m_top = false; m_bottom = true; m_left = true; m_right = false;
02144 }
02145 else if( meaning == MEANING_LEFT) {
02146 m_top = false; m_bottom = false; m_left = true; m_right = false;
02147 }
02148
02149 QValueListConstIterator<KWFrame*> framesIterator = m_frames.begin();
02150 for(;framesIterator != m_frames.end(); ++framesIterator) {
02151 KWFrame *frame = *framesIterator;
02152 FrameResizeStruct frs(*frame, frame->minimumFrameHeight(), *frame);
02153 m_frameResize.append(frs);
02154 m_boundingRect |= frame->outerKoRect();
02155 }
02156 m_hotSpot = point - m_boundingRect.topLeft();
02157 }
02158
02159 void FrameResizePolicy::handleMouseMove(Qt::ButtonState keyState, const KoPoint &point) {
02160
02161
02162
02163
02164 bool keepAspect = keyState & Qt::AltButton;
02165 for(unsigned int i=0; !keepAspect && i < m_frames.count(); i++) {
02166 KWPictureFrameSet *picFs = dynamic_cast<KWPictureFrameSet*>(m_frames[i]->frameSet());
02167 if(picFs)
02168 keepAspect = picFs->keepAspectRatio();
02169 }
02170
02171 bool noGrid = keyState & Qt::ShiftButton;
02172 bool scaleFromCenter = keyState & Qt::ControlButton;
02173
02174 KoPoint p( point.x() - (m_hotSpot.x() + m_boundingRect.x()),
02175 point.y() - (m_hotSpot.y() + m_boundingRect.y()) );
02176
02177 if ( m_parent->kWordDocument()->snapToGrid() && !noGrid )
02178 m_parent->applyGrid( p );
02179
02180 KoRect sizeRect = m_boundingRect;
02181 if(m_top)
02182 sizeRect.setY(sizeRect.y() + p.y());
02183 if(m_bottom)
02184 sizeRect.setBottom(sizeRect.bottom() + p.y());
02185 if(m_left)
02186 sizeRect.setX(sizeRect.left() + p.x());
02187 if(m_right)
02188 sizeRect.setRight(sizeRect.right() + p.x());
02189 if(keepAspect) {
02190 double ratio = m_boundingRect.width() / m_boundingRect.height();
02191 double width = sizeRect.width();
02192 double height = sizeRect.height();
02193 int toLargestEdge = (m_bottom?1:0) + (m_top?1:0) +
02194 (m_left?1:0) + (m_right?1:0);
02195 bool horizontal = m_left || m_right;
02196
02197 if(toLargestEdge != 1) {
02198 if (width < height)
02199 width = height * ratio;
02200 else
02201 height = width / ratio;
02202 } else {
02203 if (horizontal)
02204 height = width / ratio;
02205 else
02206 width = height * ratio;
02207 }
02208 if(m_bottom)
02209 sizeRect.setBottom(sizeRect.top() + height);
02210 else
02211 sizeRect.setTop(sizeRect.bottom() - height);
02212
02213 if(m_left)
02214 sizeRect.setLeft(sizeRect.right() - width);
02215 else
02216 sizeRect.setRight(sizeRect.left() + width);
02217 }
02218 if(scaleFromCenter) {
02219 KoPoint origCenter(m_boundingRect.x() + m_boundingRect.width() / 2,
02220 m_boundingRect.y() + m_boundingRect.height() / 2);
02221 KoPoint newCenter(sizeRect.x() + sizeRect.width() / 2,
02222 sizeRect.y() + sizeRect.height() / 2);
02223 sizeRect.moveTopLeft(sizeRect.topLeft() + (origCenter - newCenter));
02224 }
02225 if(m_parent) {
02226 KWPageManager *pageManager = m_parent->kWordDocument()->pageManager();
02227 sizeRect.moveTopLeft(pageManager->clipToDocument(sizeRect.topLeft()));
02228 sizeRect.moveBottomRight(pageManager->clipToDocument(sizeRect.bottomRight()));
02229 sizeRect.setX( QMAX(0, sizeRect.x()) );
02230 }
02231
02232
02233
02234 class Converter {
02235 public:
02236 Converter(KoRect &from, KoRect &to, KWViewMode *viewMode) {
02237 m_from = from.topLeft();
02238 m_to = to.topLeft();
02239 m_viewMode = viewMode;
02240 m_diffX = to.width() / from.width();
02241 m_diffY = to.height() / from.height();
02242
02243 }
02244 void update(KWFrame *frame, KoRect &orig) {
02245 QRect oldRect( m_viewMode->normalToView( frame->outerRect(m_viewMode) ) );
02246 if(! frame->frameSet()->isFloating())
02247 frame->moveTopLeft( convert( orig.topLeft() ) );
02248 KoPoint bottomRight( convert( orig.bottomRight() ) );
02249 frame->setBottom( bottomRight.y() );
02250 frame->setRight( bottomRight.x() );
02251
02252 QRect newRect( frame->outerRect(m_viewMode) );
02253 QRect frameRect( m_viewMode->normalToView( newRect ) );
02254
02255 m_repaintRegion += QRegion(oldRect).unite(frameRect).boundingRect();
02256 }
02257
02258 QRegion repaintRegion() {
02259 return m_repaintRegion;
02260 }
02261
02262 private:
02263 KoPoint convert(KoPoint point) {
02264 double offsetX = point.x() - m_from.x();
02265 double offsetY = point.y() - m_from.y();
02266 KoPoint answer(m_to.x() + offsetX * m_diffX, m_to.y() + offsetY * m_diffY);
02267 return answer;
02268 }
02269 private:
02270 KoPoint m_from, m_to;
02271 KWViewMode *m_viewMode;
02272 QRegion m_repaintRegion;
02273 double m_diffX, m_diffY;
02274 };
02275
02276 Converter converter(m_boundingRect, sizeRect, m_parent->viewMode());
02277 for(unsigned int i=0; i < m_frames.count(); i++)
02278 converter.update(m_frames[i], m_frameResize[i].oldRect);
02279
02280 if ( !m_parent->kWordDocument()->showGrid() && m_parent->kWordDocument()->snapToGrid() )
02281 m_parent->repaintContents( false );
02282 else
02283 m_parent->repaintContents( converter.repaintRegion().boundingRect(), false );
02284 m_parent->gui()->getView()->updateFrameStatusBarItem();
02285 }
02286
02287 KCommand *FrameResizePolicy::createCommand() {
02288 for(unsigned int i=0; i < m_frames.count(); i++) {
02289 KWFrame *frame = m_frames[i];
02290 FrameResizeStruct frs = m_frameResize[i];
02291 frs.newRect = frame->rect();
02292 frs.newMinHeight = frame->height();
02293 m_frameResize[i] = frs;
02294 }
02295 return new KWFrameResizeCommand(i18n("Resize Frame"), m_indexFrame, m_frameResize);
02296 }
02297
02298 void FrameResizePolicy::finishInteraction() {
02299 KWFrameViewManager *frameViewManager = m_parent->frameViewManager();
02300 for(unsigned int i=0; i < m_frames.count(); i++) {
02301 KWFrame *frame = m_frames[i];
02302 frame->setMinimumFrameHeight(frame->height());
02303 frameViewManager->slotFrameResized(frame);
02304 }
02305 }
02306
02307
02308
02309 FrameMovePolicy::FrameMovePolicy(KWCanvas *parent, KoPoint &point) :
02310 InteractionPolicy (parent), m_boundingRect() {
02311
02312 QValueListConstIterator<KWFrame*> framesIterator = m_frames.begin();
02313 for(;framesIterator != m_frames.end(); ++framesIterator) {
02314 KWFrame *frame = *framesIterator;
02315 m_boundingRect |= frame->outerKoRect();
02316 FrameMoveStruct fms(frame->topLeft(), KoPoint(0,0));
02317 m_frameMove.append(fms);
02318 }
02319
02320 m_hotSpot = point - m_boundingRect.topLeft();
02321 m_startPoint = m_boundingRect.topLeft();
02322 }
02323
02324 void FrameMovePolicy::handleMouseMove(Qt::ButtonState keyState, const KoPoint &point) {
02325 bool noGrid = keyState & Qt::ShiftButton;
02326 bool linearMove = (keyState & Qt::AltButton) || (keyState & Qt::ControlButton);
02327
02328 KWPageManager *pageManager = m_parent->kWordDocument()->pageManager();
02329
02330 KoRect oldBoundingRect = m_boundingRect;
02331
02332
02333
02334 KoPoint p( point.x() - m_hotSpot.x(), point.y() - m_hotSpot.y() );
02335 if(linearMove) {
02336 if(QABS(p.x() - m_startPoint.x()) < QABS(p.y() - m_startPoint.y()))
02337 p.setX(m_startPoint.x());
02338 else
02339 p.setY(m_startPoint.y());
02340 }
02341 if ( m_parent->kWordDocument()->snapToGrid() && !noGrid )
02342 m_parent->applyGrid( p );
02343
02344 p = pageManager->clipToDocument(p);
02345 m_boundingRect.moveTopLeft( p );
02346 m_boundingRect.moveBottomRight( pageManager->clipToDocument(m_boundingRect.bottomRight()) );
02347
02348
02349 int topPage = pageManager->pageNumber( m_boundingRect.topLeft() );
02350 int bottomPage = pageManager->pageNumber( m_boundingRect.bottomRight() );
02351
02352 if ( topPage != bottomPage ) {
02353
02354 Q_ASSERT( bottomPage == -1 || topPage + 1 == bottomPage );
02355 double topPart = m_boundingRect.bottom() - pageManager->bottomOfPage(topPage);
02356 if ( topPart < m_boundingRect.height() / 2 )
02357 p.setY( pageManager->bottomOfPage(topPage) - m_boundingRect.height() - 1 );
02358 else
02359 p.setY( pageManager->topOfPage(bottomPage) );
02360 m_boundingRect.moveTopLeft( p );
02361 m_boundingRect.moveBottomRight( pageManager->clipToDocument(m_boundingRect.bottomRight()) );
02362 }
02363
02364 if( m_boundingRect.topLeft() == oldBoundingRect.topLeft() )
02365 return;
02366
02367
02368
02369
02370
02371
02372 QPtrList<KWTableFrameSet> tablesMoved;
02373 tablesMoved.setAutoDelete( FALSE );
02374 QRegion repaintRegion;
02375 KoPoint _move=m_boundingRect.topLeft() - oldBoundingRect.topLeft();
02376
02377 QValueListIterator<KWFrame*> framesIterator = m_frames.begin();
02378 for(; framesIterator != m_frames.end(); ++framesIterator) {
02379 KWFrame *frame = *framesIterator;
02380 KWFrameSet *fs = frame->frameSet();
02381
02382 if ( fs->type() == FT_TABLE ) {
02383 if ( tablesMoved.findRef( static_cast<KWTableFrameSet *> (fs) ) == -1 )
02384 tablesMoved.append( static_cast<KWTableFrameSet *> (fs));
02385 }
02386 else {
02387 QRect oldRect( m_parent->viewMode()->normalToView( frame->outerRect(m_parent->viewMode()) ) );
02388
02389 frame->moveTopLeft( frame->topLeft() + _move );
02390
02391 QRect newRect( frame->outerRect(m_parent->viewMode()) );
02392
02393 QRect frameRect( m_parent->viewMode()->normalToView( newRect ) );
02394
02395 repaintRegion += QRegion(oldRect).unite(frameRect).boundingRect();
02396 }
02397 }
02398
02399 if ( !tablesMoved.isEmpty() ) {
02400
02401 for ( unsigned int i = 0; i < tablesMoved.count(); i++ ) {
02402 KWTableFrameSet *table = tablesMoved.at( i );
02403 for ( KWTableFrameSet::TableIter k(table) ; k ; ++k ) {
02404 KWFrame * frame = k->frame( 0 );
02405 QRect oldRect( m_parent->viewMode()->normalToView( frame->outerRect(m_parent->viewMode()) ) );
02406 frame->moveTopLeft( frame->topLeft() + _move );
02407
02408 QRect newRect( frame->outerRect(m_parent->viewMode()) );
02409 QRect frameRect( m_parent->viewMode()->normalToView( newRect ) );
02410
02411 repaintRegion += QRegion(oldRect).unite(frameRect).boundingRect();
02412 }
02413 }
02414 }
02415
02416 if ( !m_parent->kWordDocument()->showGrid() && m_parent->kWordDocument()->snapToGrid() )
02417 m_parent->repaintContents( false );
02418 else
02419 m_parent->repaintContents( repaintRegion.boundingRect(), false );
02420 m_parent->gui()->getView()->updateFrameStatusBarItem();
02421 }
02422
02423 KCommand *FrameMovePolicy::createCommand() {
02424 for(unsigned int i=0; i < m_frames.count(); i++) {
02425 KWFrame *frame = m_frames[i];
02426 FrameMoveStruct fms = m_frameMove[i];
02427 fms.newPos = frame->topLeft();
02428 m_frameMove[i] = fms;
02429 }
02430 return new KWFrameMoveCommand( i18n("Move Frame"), m_indexFrame, m_frameMove );
02431 }
02432
02433 void FrameMovePolicy::finishInteraction() {
02434 KWFrameViewManager *frameViewManager = m_parent->frameViewManager();
02435 for(unsigned int i=0; i < m_frames.count(); i++) {
02436 KWFrame *frame = m_frames[i];
02437 frameViewManager->slotFrameMoved(frame, m_frameMove[i].oldPos.y());
02438 }
02439 }
02440
02441
02442
02443 FrameSelectPolicy::FrameSelectPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, Qt::ButtonState buttonState, Qt::ButtonState keyState)
02444 : InteractionPolicy(parent, false) {
02445
02446 bool leftButton = buttonState & Qt::LeftButton;
02447
02448
02449
02450
02451 KWFrameSetEdit *fse = parent->currentFrameSetEdit();
02452 if(leftButton && fse) {
02453 KWFrameView *view = m_parent->frameViewManager()->view(point,
02454 KWFrameViewManager::unselected, true);
02455 if(view && view->frame()->frameSet() == fse->frameSet()) {
02456
02457 point.setX(QMAX(point.x(), view->frame()->left()));
02458 point.setY(QMAX(point.y(), view->frame()->top()));
02459 point.setX(QMIN(point.x(), view->frame()->right()));
02460 point.setY(QMIN(point.y(), view->frame()->bottom()));
02461
02462
02463 QPoint normalPoint = parent->kWordDocument()->zoomPoint(point);
02464 QPoint mousePos = parent->viewMode()->normalToView(normalPoint);
02465 QMouseEvent *me = new QMouseEvent(QEvent::MouseButtonPress, mousePos,
02466 buttonState, keyState);
02467 fse->mousePressEvent(me, normalPoint, point );
02468 delete me;
02469
02470 m_validSelection = false;
02471 return;
02472 }
02473 }
02474
02475 m_validSelection = meaning != MEANING_NONE;
02476 m_parent->frameViewManager()->selectFrames(point, keyState, leftButton );
02477 }
02478
02479 void FrameSelectPolicy::handleMouseMove(Qt::ButtonState keyState, const KoPoint &point) {
02480 Q_UNUSED(keyState);
02481 Q_UNUSED(point);
02482 }
02483
02484 KCommand *FrameSelectPolicy::createCommand() {
02485 return 0;
02486 }
02487
02488 void FrameSelectPolicy::finishInteraction() {
02489 }
02490
02491 #include "KWCanvas.moc"