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 Q_ASSERT( fs );
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 m_frameViewManager->view(frameIt.current())->setSelected(false);
01384 }
01385
01386 KWTextFrameSetEdit* KWCanvas::currentTextEdit() const
01387 {
01388 if ( m_currentFrameSetEdit )
01389 return dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit->currentTextEdit());
01390 return 0;
01391 }
01392
01393 void KWCanvas::setMouseMode( MouseMode newMouseMode )
01394 {
01395 if ( m_mouseMode != newMouseMode )
01396 {
01397 selectAllFrames( false );
01398
01399 if ( newMouseMode != MM_EDIT )
01400 terminateCurrentEdit();
01401
01402 m_mouseMode = newMouseMode;
01403 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
01404 repaintContents( FALSE );
01405 }
01406 else
01407 m_mouseMode = newMouseMode;
01408 emit currentMouseModeChanged(m_mouseMode);
01409
01410 switch ( m_mouseMode ) {
01411 case MM_EDIT: {
01412 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01413 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01414 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01415 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, 0 ) );
01416 m_frameInline = false;
01417 } break;
01418 case MM_CREATE_TEXT:
01419 case MM_CREATE_PIX:
01420 case MM_CREATE_TABLE:
01421 case MM_CREATE_FORMULA:
01422 case MM_CREATE_PART:
01423 viewport()->setCursor( crossCursor );
01424 break;
01425 }
01426 }
01427
01428 void KWCanvas::insertPicture( const KoPicture& newPicture, QSize pixmapSize, bool _keepRatio )
01429 {
01430 setMouseMode( MM_CREATE_PIX );
01431 m_kopicture = newPicture;
01432 m_pixmapSize = pixmapSize;
01433 if ( pixmapSize.isEmpty() )
01434 m_pixmapSize = newPicture.getOriginalSize();
01435 m_keepRatio = _keepRatio;
01436 }
01437
01438 void KWCanvas::insertPictureDirect( const KoPicture& picture, const KoPoint& pos, const QSize& sz )
01439 {
01440
01441 m_pixmapSize = sz.isEmpty() ? picture.getOriginalSize() : sz;
01442 m_kopicture = picture;
01443 m_insRect = KoRect( pos.x(), pos.y(), m_doc->unzoomItX( m_pixmapSize.width() ), m_doc->unzoomItY( m_pixmapSize.height() ) );
01444 m_keepRatio = true;
01445 mrCreatePixmap();
01446 }
01447
01448 void KWCanvas::insertPart( const KoDocumentEntry &entry )
01449 {
01450 m_partEntry = entry;
01451 if ( m_partEntry.isEmpty() )
01452 {
01453 setMouseMode( MM_EDIT );
01454 return;
01455 }
01456 setMouseMode( MM_CREATE_PART );
01457 }
01458
01459 void KWCanvas::contentsDragEnterEvent( QDragEnterEvent *e )
01460 {
01461 int provides = KWView::checkClipboard( e );
01462 if ( ( provides & KWView::ProvidesImage ) || KURLDrag::canDecode( e ) )
01463 {
01464 m_imageDrag = true;
01465 e->acceptAction();
01466 }
01467 else
01468 {
01469 m_imageDrag = false;
01470 if ( m_currentFrameSetEdit )
01471 m_currentFrameSetEdit->dragEnterEvent( e );
01472 }
01473 }
01474
01475 void KWCanvas::contentsDragMoveEvent( QDragMoveEvent *e )
01476 {
01477 if ( !m_imageDrag )
01478 {
01479 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
01480 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01481 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
01482 KWFrame *frame = view ? view->frame() : 0;
01483 KWFrameSet * fs = frame ? frame->frameSet() : 0L;
01484 bool emitChanged = false;
01485 if ( fs )
01486 {
01487
01488 emitChanged = checkCurrentEdit( fs, true );
01489 }
01490 if ( m_currentFrameSetEdit )
01491 {
01492 m_currentFrameSetEdit->dragMoveEvent( e, normalPoint, docPoint );
01493
01494 if ( emitChanged )
01495 emit currentFrameSetEditChanged();
01496 }
01497 }
01498 }
01499
01500 void KWCanvas::contentsDragLeaveEvent( QDragLeaveEvent *e )
01501 {
01502 if ( !m_imageDrag && m_currentFrameSetEdit )
01503 m_currentFrameSetEdit->dragLeaveEvent( e );
01504 }
01505
01506 void KWCanvas::contentsDropEvent( QDropEvent *e )
01507 {
01508 QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
01509 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01510
01511 if ( QImageDrag::canDecode( e ) ) {
01512 pasteImage( e, docPoint );
01513 } else if ( KURLDrag::canDecode( e ) ) {
01514
01515
01516
01517
01518 KURL::List lst;
01519 KURLDrag::decode( e, lst );
01520
01521 KURL::List::ConstIterator it = lst.begin();
01522 for ( ; it != lst.end(); ++it ) {
01523 const KURL &url( *it );
01524
01525 QString filename;
01526 if ( !KIO::NetAccess::download( url, filename, this ) )
01527 continue;
01528
01529 KMimeType::Ptr res = KMimeType::findByFileContent( filename );
01530
01531 if ( res && res->isValid() ) {
01532 QString mimetype = res->name();
01533 if ( mimetype.contains( "image" ) ) {
01534 KoPictureKey key;
01535 key.setKeyFromFile( filename );
01536 KoPicture newKoPicture;
01537 newKoPicture.setKey( key );
01538 newKoPicture.loadFromFile( filename );
01539 insertPictureDirect( newKoPicture, docPoint );
01540 }
01541 }
01542 KIO::NetAccess::removeTempFile( filename );
01543 }
01544 }
01545 else
01546 {
01547 if ( m_currentFrameSetEdit )
01548 m_currentFrameSetEdit->dropEvent( e, normalPoint, docPoint, m_gui->getView() );
01549 else
01550 m_gui->getView()->pasteData( e, true );
01551 }
01552 m_mousePressed = false;
01553 m_imageDrag = false;
01554 }
01555
01556 void KWCanvas::pasteImage( QMimeSource *e, const KoPoint &docPoint )
01557 {
01558 QImage i;
01559 if ( !QImageDrag::decode(e, i) ) {
01560 kdWarning() << "Couldn't decode image" << endl;
01561 return;
01562 }
01563 KTempFile tmpFile( QString::null, ".png");
01564 tmpFile.setAutoDelete( true );
01565 if ( !i.save(tmpFile.name(), "PNG") ) {
01566 kdWarning() << "Couldn't save image to " << tmpFile.name() << endl;
01567 return;
01568 }
01569 m_pixmapSize = i.size();
01570
01571 KoPictureKey key;
01572 key.setKeyFromFile( tmpFile.name() );
01573 KoPicture newKoPicture;
01574 newKoPicture.setKey( key );
01575 newKoPicture.loadFromFile( tmpFile.name() );
01576 m_kopicture = newKoPicture;
01577 m_insRect = KoRect( docPoint.x(), docPoint.y(), m_doc->unzoomItX( i.width() ), m_doc->unzoomItY( i.height() ) );
01578 m_keepRatio = true;
01579 mrCreatePixmap();
01580 }
01581
01582 void KWCanvas::doAutoScroll()
01583 {
01584 if ( !m_mousePressed )
01585 {
01586 m_scrollTimer->stop();
01587 return;
01588 }
01589
01590
01591 QPoint pos( mapFromGlobal( QCursor::pos() ) );
01592
01593 pos = QPoint(pos.x() - viewport()->x(), pos.y() - viewport()->y());
01594 if ( (pos.y() < 0) || (pos.y() > visibleHeight()) ||
01595 (pos.x() < 0) || (pos.x() > visibleWidth()) )
01596 {
01597 int xm, ym;
01598 viewportToContents(pos.x(), pos.y(), xm, ym);
01599 if ( m_currentFrameSetEdit )
01600 m_currentFrameSetEdit->focusOutEvent();
01601 if ( m_deleteMovingRect )
01602 deleteMovingRect();
01603 ensureVisible( xm, ym, 0, 5 );
01604 if ( m_currentFrameSetEdit )
01605 m_currentFrameSetEdit->focusInEvent();
01606 }
01607 }
01608
01609 void KWCanvas::slotContentsMoving( int cx, int cy )
01610 {
01611
01612 QPoint nPointBottom = m_viewMode->viewToNormal( QPoint( cx + visibleWidth(), cy + visibleHeight() ) );
01613
01614
01615
01616 QPtrList<KWTextFrameSet> textFrameSets = m_doc->allTextFramesets( false );
01617 QPtrListIterator<KWTextFrameSet> fit( textFrameSets );
01618 for ( ; fit.current() ; ++fit )
01619 {
01620 if(! fit.current()->isVisible()) continue;
01621 fit.current()->updateViewArea( this, m_viewMode, nPointBottom );
01622 }
01623
01624
01625 updateRulerOffsets( cx, cy );
01626
01627
01628
01629
01630
01631 QTimer::singleShot( 0, this, SIGNAL( viewTransformationsChanged() ) );
01632 }
01633
01634 void KWCanvas::slotMainTextHeightChanged()
01635 {
01636
01637 if ( dynamic_cast<KWViewModeText *>(m_viewMode) && m_gui->getHorzRuler() )
01638 {
01639 slotNewContentsSize();
01640 m_viewMode->setPageLayout( m_gui->getHorzRuler(), m_gui->getVertRuler(), KoPageLayout() );
01641 emit updateRuler();
01642 }
01643 }
01644
01645 void KWCanvas::slotNewContentsSize()
01646 {
01647 QSize size = m_viewMode->contentsSize();
01648 if ( size != QSize( contentsWidth(), contentsHeight() ) )
01649 {
01650
01651 resizeContents( size.width(), size.height() );
01652 }
01653 }
01654
01655 void KWCanvas::resizeEvent( QResizeEvent *e )
01656 {
01657 slotContentsMoving( contentsX(), contentsY() );
01658 QScrollView::resizeEvent( e );
01659 }
01660
01661 void KWCanvas::scrollToOffset( const KoPoint & d )
01662 {
01663 kdDebug() << "KWCanvas::scrollToOffset " << d.x() << "," << d.y() << endl;
01664 #if 0
01665 bool blinking = blinkTimer.isActive();
01666 if ( blinking )
01667 stopBlinkCursor();
01668 #endif
01669 QPoint nPoint = m_doc->zoomPoint( d );
01670 QPoint cPoint = m_viewMode->normalToView( nPoint );
01671 setContentsPos( cPoint.x(), cPoint.y() );
01672
01673 #if 0
01674 if ( blinking )
01675 startBlinkCursor();
01676 #endif
01677 }
01678
01679 void KWCanvas::updateRulerOffsets( int cx, int cy )
01680 {
01681 if ( cx == -1 && cy == -1 )
01682 {
01683 cx = contentsX();
01684 cy = contentsY();
01685 }
01686
01687
01688 QPoint pc = m_viewMode->pageCorner();
01689
01690 m_gui->getHorzRuler()->setOffset( cx - pc.x(), 0 );
01691 m_gui->getVertRuler()->setOffset( 0, cy - pc.y() );
01692
01693 }
01694
01695 bool KWCanvas::eventFilter( QObject *o, QEvent *e )
01696 {
01697 if ( o == this || o == viewport() ) {
01698
01699 if(m_currentFrameSetEdit && o == this )
01700 {
01701
01702 KCursor::autoHideEventFilter( o, e );
01703 }
01704
01705 switch ( e->type() ) {
01706 case QEvent::FocusIn:
01707
01708 if ( m_currentFrameSetEdit && !m_printing )
01709 m_currentFrameSetEdit->focusInEvent();
01710 break;
01711 case QEvent::FocusOut:
01712
01713 if ( m_currentFrameSetEdit && !m_printing )
01714 m_currentFrameSetEdit->focusOutEvent();
01715 if ( m_scrollTimer->isActive() )
01716 m_scrollTimer->stop();
01717 m_mousePressed = false;
01718 break;
01719 case QEvent::AccelOverride:
01720 {
01721
01722
01723 QKeyEvent * keyev = static_cast<QKeyEvent *>(e);
01724 #ifndef NDEBUG
01725
01726 if ( ( keyev->state() & ControlButton ) && ( keyev->state() & ShiftButton ) )
01727 {
01728 switch ( keyev->key() ) {
01729 case Qt::Key_P:
01730 printRTDebug( 0 );
01731 keyev->accept();
01732 break;
01733 case Qt::Key_V:
01734 printRTDebug( 1 );
01735 keyev->accept();
01736 break;
01737 case Qt::Key_F:
01738 m_doc->printDebug();
01739 kdDebug(32002) << "Current framesetedit: " << m_currentFrameSetEdit << " " <<
01740 ( m_currentFrameSetEdit ? m_currentFrameSetEdit->frameSet()->className() : "" ) << endl;
01741 keyev->accept();
01742 break;
01743 case Qt::Key_S:
01744 m_doc->printStyleDebug();
01745 keyev->accept();
01746 break;
01747 case Qt::Key_M:
01748 {
01749 const QDateTime dtMark ( QDateTime::currentDateTime() );
01750 kdDebug(32002) << "Developer mark: " << dtMark.toString("yyyy-MM-dd hh:mm:ss,zzz") << endl;
01751 keyev->accept();
01752 break;
01753 }
01754 default:
01755 break;
01756 };
01757
01758 }
01759 #endif
01760 }
01761 break;
01762 case QEvent::KeyPress:
01763 {
01764
01765
01766 QKeyEvent * keyev = static_cast<QKeyEvent *>(e);
01767
01768 if ( !m_doc->pgUpDownMovesCaret() && ( (keyev->state() & ShiftButton) == 0 )
01769 && ( keyev->key() == Qt::Key_PageUp || keyev->key() == Key_PageDown ) )
01770 {
01771 viewportScroll( keyev->key() == Qt::Key_PageUp );
01772 }
01773
01774
01775
01776
01777 else if ( keyev->key() == KGlobalSettings::contextMenuKey() ) {
01778
01779 if(!m_doc->isReadWrite()) return TRUE;
01780 if (m_mouseMode != MM_EDIT) return TRUE;
01781 KoPoint docPoint = m_doc->unzoomPoint( QCursor::pos() );
01782
01783 if ( viewMode()->type()=="ModeText") {
01784 KWFrameView *view = m_frameViewManager->view(m_doc->frameSet( 0 )->frame(0));
01785 view->showPopup(docPoint, m_gui->getView(), QCursor::pos());
01786 }
01787 else {
01788 m_frameViewManager->showPopup( docPoint, m_gui->getView(), keyev->state(), pos());
01789 }
01790 return true;
01791 }
01792 else if ( keyev->key() == Qt::Key_Return && keyev->state() == 0
01793 && (m_mouseMode != MM_EDIT || m_frameInline )) {
01794
01795
01796
01797
01798
01799
01800 if (m_frameInline)
01801 m_lastCaretPos = caretPos();
01802 if (m_lastCaretPos.isNull()) return TRUE;
01803 int page = m_doc->pageManager()->pageNumber(m_lastCaretPos);
01804 if(page == -1) return TRUE;
01805 QPoint normalPoint = m_doc->zoomPoint(m_lastCaretPos);
01806
01807
01808
01809 if (m_frameInline)
01810 normalPoint += QPoint(2,2);
01811 QPoint vP = m_viewMode->normalToView(normalPoint);
01812 QPoint gP = mapToGlobal(vP);
01813 QMouseEvent mevPress(QEvent::MouseButtonPress, vP,
01814 gP, Qt::LeftButton, 0);
01815 contentsMousePressEvent(&mevPress);
01816 QMouseEvent mevRelease(QEvent::MouseButtonRelease, vP,
01817 gP, Qt::LeftButton, 0);
01818 contentsMouseReleaseEvent(&mevRelease);
01819 }
01820 else if ( keyev->key() == Qt::Key_Escape ) {
01821 if ( m_mouseMode != MM_EDIT )
01822 setMouseMode( MM_EDIT );
01823 else if(m_interactionPolicy) {
01824 m_interactionPolicy->cancelInteraction();
01825 delete(m_interactionPolicy);
01826 m_interactionPolicy = 0;
01827 m_mousePressed = false;
01828
01829
01830 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01831 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01832 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01833 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
01834 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
01835 repaintContents();
01836 }
01837 }
01838 else if ( keyev->key() == Key_Insert && keyev->state() == 0 ) {
01839 m_overwriteMode = !m_overwriteMode;
01840 KWTextFrameSetEdit *edit = currentTextEdit();
01841 if ( edit ) {
01842 edit->setOverwriteMode( m_overwriteMode );
01843 emit overwriteModeChanged( m_overwriteMode );
01844 }
01845 kdDebug()<<"Insert is pressed, overwrite mode: "<< m_overwriteMode << endl;
01846 }
01847 else
01848 if ( m_currentFrameSetEdit && m_mouseMode == MM_EDIT && m_doc->isReadWrite() && !m_printing )
01849 {
01850 KWTextFrameSetEdit *edit = dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit );
01851 if ( edit )
01852 {
01853 if ( !edit->textFrameSet()->textObject()->protectContent() || (keyev->text().length() == 0))
01854 m_currentFrameSetEdit->keyPressEvent( keyev );
01855 else if(keyev->text().length() > 0)
01856 KMessageBox::information(this, i18n("Read-only content cannot be changed. No modifications will be accepted."));
01857 }
01858 else
01859 m_currentFrameSetEdit->keyPressEvent( keyev );
01860 return TRUE;
01861 }
01862
01863
01864 if ( keyev->key() == Qt::Key_Control )
01865 {
01866 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01867 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01868 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01869 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
01870 }
01871 else if ( (keyev->key() == Qt::Key_Delete || keyev->key() ==Key_Backspace )
01872 && m_frameViewManager->selectedFrame() && !m_printing )
01873 m_gui->getView()->editDeleteFrame();
01874 } break;
01875 case QEvent::KeyRelease:
01876 {
01877 QKeyEvent * keyev = static_cast<QKeyEvent *>(e);
01878 if ( keyev->key() == Qt::Key_Control )
01879 {
01880 QPoint mousep = mapFromGlobal(QCursor::pos()) + QPoint( contentsX(), contentsY() );
01881 QPoint normalPoint = m_viewMode->viewToNormal( mousep );
01882 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
01883 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
01884 }
01885
01886 if ( m_currentFrameSetEdit && m_mouseMode == MM_EDIT && m_doc->isReadWrite() && !m_printing )
01887 {
01888 m_currentFrameSetEdit->keyReleaseEvent( keyev );
01889 return TRUE;
01890 }
01891 }
01892 break;
01893 case QEvent::IMStart:
01894 {
01895 QIMEvent * imev = static_cast<QIMEvent *>(e);
01896 m_currentFrameSetEdit->imStartEvent( imev );
01897 }
01898 break;
01899 case QEvent::IMCompose:
01900 {
01901 QIMEvent * imev = static_cast<QIMEvent *>(e);
01902 m_currentFrameSetEdit->imComposeEvent( imev );
01903 }
01904 break;
01905 case QEvent::IMEnd:
01906 {
01907 QIMEvent * imev = static_cast<QIMEvent *>(e);
01908 m_currentFrameSetEdit->imEndEvent( imev );
01909 }
01910 break;
01911 default:
01912 break;
01913 }
01914 }
01915 return QScrollView::eventFilter( o, e );
01916 }
01917
01918 bool KWCanvas::focusNextPrevChild( bool next)
01919 {
01920 Q_UNUSED(next);
01921 return TRUE;
01922
01923
01924
01925 }
01926
01927 void KWCanvas::updateCurrentFormat()
01928 {
01929 KWTextFrameSetEdit * edit = dynamic_cast<KWTextFrameSetEdit *>(m_currentFrameSetEdit);
01930 if ( edit )
01931 edit->updateUI( true, true );
01932 }
01933
01934 #ifndef NDEBUG
01935 void KWCanvas::printRTDebug( int info )
01936 {
01937 KWTextFrameSet * textfs = 0L;
01938 if ( m_currentFrameSetEdit ) {
01939 KWTextFrameSetEdit* edit = currentTextEdit();
01940 if ( edit ) {
01941 textfs = dynamic_cast<KWTextFrameSet *>( edit->frameSet() );
01942 Q_ASSERT( textfs );
01943 }
01944 }
01945 if ( !textfs )
01946 textfs = dynamic_cast<KWTextFrameSet *>(m_doc->frameSet( 0 ));
01947 if ( textfs )
01948 textfs->textObject()->printRTDebug( info );
01949 }
01950 #endif
01951
01952 void KWCanvas::setXimPosition( int x, int y, int w, int h )
01953 {
01954 QWidget::setMicroFocusHint( x - contentsX(), y - contentsY(), w, h );
01955 }
01956
01957 void KWCanvas::inlinePictureStarted()
01958 {
01959 m_frameInline=true;
01960 m_frameInlineType=FT_PICTURE;
01961 }
01962
01963 int KWCanvas::currentTableRow() const
01964 {
01965 if ( !m_currentFrameSetEdit )
01966 return -1;
01967 KWTextFrameSetEdit *edit = currentTextEdit();
01968 if ( !edit )
01969 return -1;
01970 KWTextFrameSet* textfs = edit->textFrameSet();
01971 if ( textfs && textfs->groupmanager() )
01972 return static_cast<KWTableFrameSet::Cell *>(textfs)->firstRow();
01973 return -1;
01974 }
01975
01976 int KWCanvas::currentTableCol() const
01977 {
01978 if ( !m_currentFrameSetEdit )
01979 return -1;
01980 KWTextFrameSetEdit *edit = currentTextEdit();
01981 if ( !edit )
01982 return -1;
01983 KWTextFrameSet* textfs = edit->textFrameSet();
01984 if ( textfs && textfs->groupmanager() )
01985 return static_cast<KWTableFrameSet::Cell *>(textfs)->firstColumn();
01986 return -1;
01987 }
01988
01989 void KWCanvas::viewportScroll( bool up )
01990 {
01991 if ( up )
01992 setContentsPos( contentsX(), contentsY() - visibleHeight() );
01993 else
01994 setContentsPos( contentsX(), contentsY() + visibleHeight() );
01995 }
01996
01997 void KWCanvas::resetStatusBarText()
01998 {
01999 if ( m_temporaryStatusBarTextShown )
02000 {
02001 gui()->getView()->updateFrameStatusBarItem();
02002 m_temporaryStatusBarTextShown = false;
02003 }
02004 }
02005
02006
02007
02008
02009 KoPoint KWCanvas::caretPos()
02010 {
02011 if (!m_currentFrameSetEdit) return KoPoint();
02012 KWTextFrameSetEdit* textEdit = currentTextEdit();
02013 if (!textEdit) return KoPoint();
02014 KoTextCursor* cursor = textEdit->cursor();
02015 if (!cursor) return KoPoint();
02016 KWTextFrameSet* textFrameset =
02017 dynamic_cast<KWTextFrameSet *>(m_currentFrameSetEdit->frameSet());
02018 if (!textFrameset) return KoPoint();
02019 KWFrame* currentFrame = m_currentFrameSetEdit->currentFrame();
02020 if (!currentFrame) return KoPoint();
02021
02022 QPoint viewP = textFrameset->cursorPos(cursor, this, currentFrame);
02023 viewP.rx() += contentsX();
02024 viewP.ry() += contentsY();
02025 QPoint normalP = m_viewMode->viewToNormal(viewP);
02026 KoPoint docP = m_doc->unzoomPoint(normalP);
02027 return docP;
02028 }
02029
02030
02031
02032 InteractionPolicy::InteractionPolicy(KWCanvas *parent, bool doInit, bool includeInlineFrames) {
02033 m_gotDragEvents = false;
02034 m_parent = parent;
02035 if(doInit) {
02036 QValueList<KWFrameView*> selectedFrames = m_parent->frameViewManager()->selectedFrames();
02037 QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
02038 for(;framesIterator != selectedFrames.end(); ++framesIterator) {
02039 KWFrame *frame = (*framesIterator)->frame();
02040 KWFrameSet *fs = frame->frameSet();
02041 if(! fs) continue;
02042 if(!fs->isVisible()) continue;
02043 if(fs->isMainFrameset() ) continue;
02044 if(fs->isFloating() && !includeInlineFrames) continue;
02045 if(fs->isProtectSize() ) continue;
02046 if(fs->type() == FT_TABLE ) continue;
02047 if(fs->type() == FT_TEXT && fs->frameSetInfo() != KWFrameSet::FI_BODY ) continue;
02048 m_frames.append( frame );
02049 m_indexFrame.append( FrameIndex( frame ) );
02050 }
02051 }
02052 }
02053
02054 InteractionPolicy* InteractionPolicy::createPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, Qt::ButtonState buttonState, Qt::ButtonState keyState) {
02055 if(buttonState & Qt::LeftButton || buttonState & Qt::RightButton) {
02056
02057 class Selector {
02058 public:
02059 Selector(KWCanvas *canvas, KoPoint &point, Qt::ButtonState buttonState, Qt::ButtonState keyState) :
02060 m_canvas(canvas), m_point(point), m_state(keyState) {
02061 m_leftClick = buttonState & Qt::LeftButton;
02062 KWFrameView *view = canvas->frameViewManager()->view(point,
02063 KWFrameViewManager::frameOnTop);
02064 m_doSomething = (view && !view->selected());
02065 }
02066
02067 void doSelect() {
02068 if(! m_doSomething) return;
02069 m_canvas->frameViewManager()->selectFrames(m_point, m_state, m_leftClick);
02070 }
02071 private:
02072 KWCanvas *m_canvas;
02073 KoPoint m_point;
02074 Qt::ButtonState m_state;
02075 bool m_leftClick, m_doSomething;
02076 };
02077
02078 Selector selector(parent, point, buttonState, keyState);
02079 switch(meaning) {
02080 case MEANING_MOUSE_MOVE:
02081 selector.doSelect();
02082 return new FrameMovePolicy(parent, point);
02083 case MEANING_TOPLEFT:
02084 case MEANING_TOP:
02085 case MEANING_TOPRIGHT:
02086 case MEANING_RIGHT:
02087 case MEANING_BOTTOMRIGHT:
02088 case MEANING_BOTTOM:
02089 case MEANING_BOTTOMLEFT:
02090 case MEANING_LEFT:
02091 selector.doSelect();
02092 return new FrameResizePolicy(parent, meaning, point);
02093 default:
02094 FrameSelectPolicy *fsp = new FrameSelectPolicy(parent, meaning, point, buttonState, keyState);
02095 if(fsp->isValid())
02096 return fsp;
02097 delete fsp;
02098 }
02099 }
02100 return 0;
02101 }
02102
02103 void InteractionPolicy::cancelInteraction() {
02104 KCommand *cmd = createCommand();
02105 if(cmd) {
02106 cmd->unexecute();
02107 delete cmd;
02108 }
02109 }
02110
02111
02112
02113 FrameResizePolicy::FrameResizePolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point) :
02114 InteractionPolicy (parent, true, true), m_boundingRect() {
02115
02116 if( meaning == MEANING_TOPLEFT) {
02117 m_top = true; m_bottom = false; m_left = true; m_right = false;
02118 }
02119 else if( meaning == MEANING_TOP) {
02120 m_top = true; m_bottom = false; m_left = false; m_right = false;
02121 }
02122 else if( meaning == MEANING_TOPRIGHT) {
02123 m_top = true; m_bottom = false; m_left = false; m_right = true;
02124 }
02125 else if( meaning == MEANING_RIGHT) {
02126 m_top = false; m_bottom = false; m_left = false; m_right = true;
02127 }
02128 else if( meaning == MEANING_BOTTOMRIGHT) {
02129 m_top = false; m_bottom = true; m_left = false; m_right = true;
02130 }
02131 else if( meaning == MEANING_BOTTOM) {
02132 m_top = false; m_bottom = true; m_left = false; m_right = false;
02133 }
02134 else if( meaning == MEANING_BOTTOMLEFT) {
02135 m_top = false; m_bottom = true; m_left = true; m_right = false;
02136 }
02137 else if( meaning == MEANING_LEFT) {
02138 m_top = false; m_bottom = false; m_left = true; m_right = false;
02139 }
02140
02141 QValueListConstIterator<KWFrame*> framesIterator = m_frames.begin();
02142 for(;framesIterator != m_frames.end(); ++framesIterator) {
02143 KWFrame *frame = *framesIterator;
02144 FrameResizeStruct frs(*frame, frame->minimumFrameHeight(), *frame);
02145 m_frameResize.append(frs);
02146 m_boundingRect |= frame->outerKoRect();
02147 }
02148 m_hotSpot = point - m_boundingRect.topLeft();
02149 }
02150
02151 void FrameResizePolicy::handleMouseMove(Qt::ButtonState keyState, const KoPoint &point) {
02152
02153
02154
02155
02156 bool keepAspect = keyState & Qt::AltButton;
02157 for(unsigned int i=0; !keepAspect && i < m_frames.count(); i++) {
02158 KWPictureFrameSet *picFs = dynamic_cast<KWPictureFrameSet*>(m_frames[i]->frameSet());
02159 if(picFs)
02160 keepAspect = picFs->keepAspectRatio();
02161 }
02162
02163 bool noGrid = keyState & Qt::ShiftButton;
02164 bool scaleFromCenter = keyState & Qt::ControlButton;
02165
02166 KoPoint p( point.x() - (m_hotSpot.x() + m_boundingRect.x()),
02167 point.y() - (m_hotSpot.y() + m_boundingRect.y()) );
02168
02169 if ( m_parent->kWordDocument()->snapToGrid() && !noGrid )
02170 m_parent->applyGrid( p );
02171
02172 KoRect sizeRect = m_boundingRect;
02173 if(m_top)
02174 sizeRect.setY(sizeRect.y() + p.y());
02175 if(m_bottom)
02176 sizeRect.setBottom(sizeRect.bottom() + p.y());
02177 if(m_left)
02178 sizeRect.setX(sizeRect.left() + p.x());
02179 if(m_right)
02180 sizeRect.setRight(sizeRect.right() + p.x());
02181 if(keepAspect) {
02182 double ratio = m_boundingRect.width() / m_boundingRect.height();
02183 double width = sizeRect.width();
02184 double height = sizeRect.height();
02185 int toLargestEdge = (m_bottom?1:0) + (m_top?1:0) +
02186 (m_left?1:0) + (m_right?1:0);
02187 bool horizontal = m_left || m_right;
02188
02189 if(toLargestEdge != 1) {
02190 if (width < height)
02191 width = height * ratio;
02192 else
02193 height = width / ratio;
02194 } else {
02195 if (horizontal)
02196 height = width / ratio;
02197 else
02198 width = height * ratio;
02199 }
02200 if(m_bottom)
02201 sizeRect.setBottom(sizeRect.top() + height);
02202 else
02203 sizeRect.setTop(sizeRect.bottom() - height);
02204
02205 if(m_left)
02206 sizeRect.setLeft(sizeRect.right() - width);
02207 else
02208 sizeRect.setRight(sizeRect.left() + width);
02209 }
02210 if(scaleFromCenter) {
02211 KoPoint origCenter(m_boundingRect.x() + m_boundingRect.width() / 2,
02212 m_boundingRect.y() + m_boundingRect.height() / 2);
02213 KoPoint newCenter(sizeRect.x() + sizeRect.width() / 2,
02214 sizeRect.y() + sizeRect.height() / 2);
02215 sizeRect.moveTopLeft(sizeRect.topLeft() + (origCenter - newCenter));
02216 }
02217 if(m_parent) {
02218 KWPageManager *pageManager = m_parent->kWordDocument()->pageManager();
02219 sizeRect.moveTopLeft(pageManager->clipToDocument(sizeRect.topLeft()));
02220 sizeRect.moveBottomRight(pageManager->clipToDocument(sizeRect.bottomRight()));
02221 sizeRect.setX( QMAX(0, sizeRect.x()) );
02222 }
02223
02224
02225
02226 class Converter {
02227 public:
02228 Converter(KoRect &from, KoRect &to, KWViewMode *viewMode) {
02229 m_from = from.topLeft();
02230 m_to = to.topLeft();
02231 m_viewMode = viewMode;
02232 m_diffX = to.width() / from.width();
02233 m_diffY = to.height() / from.height();
02234
02235 }
02236 void update(KWFrame *frame, KoRect &orig) {
02237 QRect oldRect( m_viewMode->normalToView( frame->outerRect(m_viewMode) ) );
02238 if(! frame->frameSet()->isFloating())
02239 frame->moveTopLeft( convert( orig.topLeft() ) );
02240 KoPoint bottomRight( convert( orig.bottomRight() ) );
02241 frame->setBottom( bottomRight.y() );
02242 frame->setRight( bottomRight.x() );
02243
02244 QRect newRect( frame->outerRect(m_viewMode) );
02245 QRect frameRect( m_viewMode->normalToView( newRect ) );
02246
02247 m_repaintRegion += QRegion(oldRect).unite(frameRect).boundingRect();
02248 }
02249
02250 QRegion repaintRegion() {
02251 return m_repaintRegion;
02252 }
02253
02254 private:
02255 KoPoint convert(KoPoint point) {
02256 double offsetX = point.x() - m_from.x();
02257 double offsetY = point.y() - m_from.y();
02258 KoPoint answer(m_to.x() + offsetX * m_diffX, m_to.y() + offsetY * m_diffY);
02259 return answer;
02260 }
02261 private:
02262 KoPoint m_from, m_to;
02263 KWViewMode *m_viewMode;
02264 QRegion m_repaintRegion;
02265 double m_diffX, m_diffY;
02266 };
02267
02268 Converter converter(m_boundingRect, sizeRect, m_parent->viewMode());
02269 for(unsigned int i=0; i < m_frames.count(); i++)
02270 converter.update(m_frames[i], m_frameResize[i].oldRect);
02271
02272 if ( !m_parent->kWordDocument()->showGrid() && m_parent->kWordDocument()->snapToGrid() )
02273 m_parent->repaintContents( false );
02274 else
02275 m_parent->repaintContents( converter.repaintRegion().boundingRect(), false );
02276 m_parent->gui()->getView()->updateFrameStatusBarItem();
02277 }
02278
02279 KCommand *FrameResizePolicy::createCommand() {
02280 for(unsigned int i=0; i < m_frames.count(); i++) {
02281 KWFrame *frame = m_frames[i];
02282 FrameResizeStruct frs = m_frameResize[i];
02283 frs.newRect = frame->rect();
02284 frs.newMinHeight = frame->height();
02285 m_frameResize[i] = frs;
02286 }
02287 return new KWFrameResizeCommand(i18n("Resize Frame"), m_indexFrame, m_frameResize);
02288 }
02289
02290 void FrameResizePolicy::finishInteraction() {
02291 KWFrameViewManager *frameViewManager = m_parent->frameViewManager();
02292 for(unsigned int i=0; i < m_frames.count(); i++) {
02293 KWFrame *frame = m_frames[i];
02294 frame->setMinimumFrameHeight(frame->height());
02295 frameViewManager->slotFrameResized(frame);
02296 }
02297 }
02298
02299
02300
02301 FrameMovePolicy::FrameMovePolicy(KWCanvas *parent, KoPoint &point) :
02302 InteractionPolicy (parent), m_boundingRect() {
02303
02304 QValueListConstIterator<KWFrame*> framesIterator = m_frames.begin();
02305 for(;framesIterator != m_frames.end(); ++framesIterator) {
02306 KWFrame *frame = *framesIterator;
02307 m_boundingRect |= frame->outerKoRect();
02308 FrameMoveStruct fms(frame->topLeft(), KoPoint(0,0));
02309 m_frameMove.append(fms);
02310 }
02311
02312 m_hotSpot = point - m_boundingRect.topLeft();
02313 m_startPoint = m_boundingRect.topLeft();
02314 }
02315
02316 void FrameMovePolicy::handleMouseMove(Qt::ButtonState keyState, const KoPoint &point) {
02317 bool noGrid = keyState & Qt::ShiftButton;
02318 bool linearMove = (keyState & Qt::AltButton) || (keyState & Qt::ControlButton);
02319
02320 KWPageManager *pageManager = m_parent->kWordDocument()->pageManager();
02321
02322 KoRect oldBoundingRect = m_boundingRect;
02323
02324
02325
02326 KoPoint p( point.x() - m_hotSpot.x(), point.y() - m_hotSpot.y() );
02327 if(linearMove) {
02328 if(QABS(p.x() - m_startPoint.x()) < QABS(p.y() - m_startPoint.y()))
02329 p.setX(m_startPoint.x());
02330 else
02331 p.setY(m_startPoint.y());
02332 }
02333 if ( m_parent->kWordDocument()->snapToGrid() && !noGrid )
02334 m_parent->applyGrid( p );
02335
02336 p = pageManager->clipToDocument(p);
02337 m_boundingRect.moveTopLeft( p );
02338 m_boundingRect.moveBottomRight( pageManager->clipToDocument(m_boundingRect.bottomRight()) );
02339
02340
02341 int topPage = pageManager->pageNumber( m_boundingRect.topLeft() );
02342 int bottomPage = pageManager->pageNumber( m_boundingRect.bottomRight() );
02343
02344 if ( topPage != bottomPage ) {
02345
02346 Q_ASSERT( bottomPage == -1 || topPage + 1 == bottomPage );
02347 double topPart = m_boundingRect.bottom() - pageManager->bottomOfPage(topPage);
02348 if ( topPart < m_boundingRect.height() / 2 )
02349 p.setY( pageManager->bottomOfPage(topPage) - m_boundingRect.height() - 1 );
02350 else
02351 p.setY( pageManager->topOfPage(bottomPage) );
02352 m_boundingRect.moveTopLeft( p );
02353 m_boundingRect.moveBottomRight( pageManager->clipToDocument(m_boundingRect.bottomRight()) );
02354 }
02355
02356 if( m_boundingRect.topLeft() == oldBoundingRect.topLeft() )
02357 return;
02358
02359
02360
02361
02362
02363
02364 QPtrList<KWTableFrameSet> tablesMoved;
02365 tablesMoved.setAutoDelete( FALSE );
02366 QRegion repaintRegion;
02367 KoPoint _move=m_boundingRect.topLeft() - oldBoundingRect.topLeft();
02368
02369 QValueListIterator<KWFrame*> framesIterator = m_frames.begin();
02370 for(; framesIterator != m_frames.end(); ++framesIterator) {
02371 KWFrame *frame = *framesIterator;
02372 KWFrameSet *fs = frame->frameSet();
02373
02374 if ( fs->type() == FT_TABLE ) {
02375 if ( tablesMoved.findRef( static_cast<KWTableFrameSet *> (fs) ) == -1 )
02376 tablesMoved.append( static_cast<KWTableFrameSet *> (fs));
02377 }
02378 else {
02379 QRect oldRect( m_parent->viewMode()->normalToView( frame->outerRect(m_parent->viewMode()) ) );
02380
02381 frame->moveTopLeft( frame->topLeft() + _move );
02382
02383 QRect newRect( frame->outerRect(m_parent->viewMode()) );
02384
02385 QRect frameRect( m_parent->viewMode()->normalToView( newRect ) );
02386
02387 repaintRegion += QRegion(oldRect).unite(frameRect).boundingRect();
02388 }
02389 }
02390
02391 if ( !tablesMoved.isEmpty() ) {
02392
02393 for ( unsigned int i = 0; i < tablesMoved.count(); i++ ) {
02394 KWTableFrameSet *table = tablesMoved.at( i );
02395 for ( KWTableFrameSet::TableIter k(table) ; k ; ++k ) {
02396 KWFrame * frame = k->frame( 0 );
02397 QRect oldRect( m_parent->viewMode()->normalToView( frame->outerRect(m_parent->viewMode()) ) );
02398 frame->moveTopLeft( frame->topLeft() + _move );
02399
02400 QRect newRect( frame->outerRect(m_parent->viewMode()) );
02401 QRect frameRect( m_parent->viewMode()->normalToView( newRect ) );
02402
02403 repaintRegion += QRegion(oldRect).unite(frameRect).boundingRect();
02404 }
02405 }
02406 }
02407
02408 if ( !m_parent->kWordDocument()->showGrid() && m_parent->kWordDocument()->snapToGrid() )
02409 m_parent->repaintContents( false );
02410 else
02411 m_parent->repaintContents( repaintRegion.boundingRect(), false );
02412 m_parent->gui()->getView()->updateFrameStatusBarItem();
02413 }
02414
02415 KCommand *FrameMovePolicy::createCommand() {
02416 for(unsigned int i=0; i < m_frames.count(); i++) {
02417 KWFrame *frame = m_frames[i];
02418 FrameMoveStruct fms = m_frameMove[i];
02419 fms.newPos = frame->topLeft();
02420 m_frameMove[i] = fms;
02421 }
02422 return new KWFrameMoveCommand( i18n("Move Frame"), m_indexFrame, m_frameMove );
02423 }
02424
02425 void FrameMovePolicy::finishInteraction() {
02426 KWFrameViewManager *frameViewManager = m_parent->frameViewManager();
02427 for(unsigned int i=0; i < m_frames.count(); i++) {
02428 KWFrame *frame = m_frames[i];
02429 frameViewManager->slotFrameMoved(frame, m_frameMove[i].oldPos.y());
02430 }
02431 }
02432
02433
02434
02435 FrameSelectPolicy::FrameSelectPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, Qt::ButtonState buttonState, Qt::ButtonState keyState)
02436 : InteractionPolicy(parent, false) {
02437
02438 bool leftButton = buttonState & Qt::LeftButton;
02439
02440
02441
02442
02443 KWFrameSetEdit *fse = parent->currentFrameSetEdit();
02444 if(leftButton && fse) {
02445 KWFrameView *view = m_parent->frameViewManager()->view(point,
02446 KWFrameViewManager::unselected, true);
02447 if(view && view->frame()->frameSet() == fse->frameSet()) {
02448
02449 point.setX(QMAX(point.x(), view->frame()->left()));
02450 point.setY(QMAX(point.y(), view->frame()->top()));
02451 point.setX(QMIN(point.x(), view->frame()->right()));
02452 point.setY(QMIN(point.y(), view->frame()->bottom()));
02453
02454
02455 QPoint normalPoint = parent->kWordDocument()->zoomPoint(point);
02456 QPoint mousePos = parent->viewMode()->normalToView(normalPoint);
02457 QMouseEvent *me = new QMouseEvent(QEvent::MouseButtonPress, mousePos,
02458 buttonState, keyState);
02459 fse->mousePressEvent(me, normalPoint, point );
02460 delete me;
02461
02462 m_validSelection = false;
02463 return;
02464 }
02465 }
02466
02467 m_validSelection = meaning != MEANING_NONE;
02468 m_parent->frameViewManager()->selectFrames(point, keyState, leftButton );
02469 }
02470
02471 void FrameSelectPolicy::handleMouseMove(Qt::ButtonState keyState, const KoPoint &point) {
02472 Q_UNUSED(keyState);
02473 Q_UNUSED(point);
02474 }
02475
02476 KCommand *FrameSelectPolicy::createCommand() {
02477 return 0;
02478 }
02479
02480 void FrameSelectPolicy::finishInteraction() {
02481 }
02482
02483 #include "KWCanvas.moc"