kword

KWViewMode.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2005 David Faure <faure@kde.org>
00003    Copyright (C) 2005 Thomas Zander <zander@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KWViewMode.h"
00022 #include "KWCanvas.h"
00023 #include "KWView.h"
00024 #include "KWDocument.h"
00025 #include "KWTextFrameSet.h"
00026 #include "KWFrameSet.h"
00027 #include "KWTableFrameSet.h"
00028 #include "KWPageManager.h"
00029 #include "KWPage.h"
00030 #include "KWFrameViewManager.h"
00031 #include "KWFrameView.h"
00032 #include <qapplication.h>
00033 #include <kdebug.h>
00034 
00035 const unsigned short KWViewMode::s_shadowOffset = 3;
00036 
00037 QSize KWViewMode::availableSizeForText( KWTextFrameSet* textfs )
00038 {
00039     KWFrame* frame = textfs->frameIterator().getLast();
00040     return m_doc->zoomSize( KoSize( frame->innerWidth(), frame->internalY() + frame->innerHeight() ) );
00041 
00042 }
00043 
00044 void KWViewMode::drawOnePageBorder( QPainter * painter, const QRect & crect, const QRect & _pageRect,
00045                                     const QRegion & emptySpaceRegion )
00046 {
00047     if ( !crect.intersects( _pageRect ) )
00048         return;
00049 
00050     QRect pageRect( _pageRect );
00051     //kdDebug() << "KWViewMode::drawOnePageBorder drawing page rect " << pageRect << endl;
00052     painter->drawRect( pageRect );
00053     // Exclude page border line, to get the page contents rect (avoids flicker)
00054     pageRect.rLeft() += 1;
00055     pageRect.rTop() += 1;
00056     pageRect.rRight() -= 1;
00057     pageRect.rBottom() -= 1;
00058     // The empty space to clear up inside this page
00059     QRect pagecrect = pageRect.intersect( crect );
00060     if ( !pagecrect.isEmpty() )
00061     {
00062         //kdDebug() << "KWViewMode::drawOnePageBorder : pagecrect=" << pagecrect << " emptySpaceRegion: " << emptySpaceRegion << endl;
00063         QRegion pageEmptyRegion = emptySpaceRegion.intersect( pagecrect );
00064         //kdDebug() << "RESULT: pageEmptyRegion: " << pageEmptyRegion << endl;
00065         if ( !pageEmptyRegion.isEmpty() )
00066             m_doc->eraseEmptySpace( painter, pageEmptyRegion, QApplication::palette().active().brush( QColorGroup::Base ) );
00067     }
00068 }
00069 
00070 QRect KWViewMode::drawRightShadow( QPainter * painter, const QRect & crect, const QRect & pageRect, int topOffset )
00071 {
00072     QRect shadowRect( pageRect.right() + 1, pageRect.top() + topOffset, s_shadowOffset, pageRect.height() - topOffset );
00073     shadowRect &= crect; // intersect
00074     if ( !shadowRect.isEmpty() )
00075     {
00076         painter->fillRect( shadowRect,
00077                            QApplication::palette().active().brush( QColorGroup::Shadow ) );
00078     }
00079     return shadowRect;
00080 }
00081 
00082 QRect KWViewMode::drawBottomShadow( QPainter * painter, const QRect & crect, const QRect & pageRect, int leftOffset )
00083 {
00084     QRect shadowRect( pageRect.left() + leftOffset, pageRect.bottom() + 1, pageRect.width(), s_shadowOffset );
00085     shadowRect &= crect; // intersect
00086     if ( !shadowRect.isEmpty() )
00087         painter->fillRect( shadowRect,
00088                            QApplication::palette().active().brush( QColorGroup::Shadow ) );
00089     return shadowRect;
00090 }
00091 
00092 QPoint KWViewMode::pageCorner()
00093 {
00094     // Same code as KWView::slotUpdateRuler
00095     KWFrame * frame = 0L;
00096     // Use the currently edited (fallback: the first selected) frame
00097     if( m_canvas->currentFrameSetEdit() && m_canvas->currentFrameSetEdit()->currentFrame() )
00098         frame = m_canvas->currentFrameSetEdit()->currentFrame();
00099     else {
00100         KWFrameView *view = m_canvas->frameViewManager()->selectedFrame();
00101         frame = view == 0 ? 0 : view->frame();
00102     }
00103 
00104     int pageNum = 0;
00105     if ( frame )
00106         pageNum = frame->pageNumber();
00107     QPoint nPoint( 0, m_doc->pageTop(pageNum) + 1 );
00108     QPoint cPoint( normalToView( nPoint ) );
00109     /*kdDebug() << "KWViewMode::pageCorner frame=" << frame << " pagenum=" << pageNum
00110               << " nPoint=" << nPoint.x() << "," << nPoint.y()
00111               << " cPoint=" << cPoint.x() << "," << cPoint.y() << endl;*/
00112     return cPoint;
00113 }
00114 
00115 QRect KWViewMode::rulerFrameRect()
00116 {
00117     // Set the "frame start" in the ruler (tabs are relative to that position)
00118     KWFrameSetEdit * edit = m_canvas->currentFrameSetEdit();
00119     KWFrame * frame = 0L;
00120     // Use the currently edited (fallback: the first selected) frame
00121     if ( edit && edit->currentFrame() )
00122         frame = edit->currentFrame();
00123     else {
00124         KWFrameView *view = m_canvas->frameViewManager()->selectedFrame();
00125         frame = view == 0 ? 0 : view->frame();
00126     }
00127     if( !frame) {
00128         KWFrameSet *fs= m_doc->frameSet(0);
00129         if(fs) frame=fs->frame(0);
00130     }
00131     if ( frame )
00132     {
00133         QRect r = normalToView( m_doc->zoomRect( frame->innerRect() ) );
00134 
00135         // Calculate page corner (see pageCorner above)
00136         int pageNum = frame->pageNumber();
00137         QPoint nPoint( 0, m_doc->pageTop(pageNum) + 1 );
00138         QPoint cPoint( normalToView( nPoint ) );
00139 
00140         // Frame start/end is relative to page corner.
00141         r.moveBy( -cPoint.x(), -cPoint.y() );
00142         return r;
00143     }
00144     return QRect();
00145 }
00146 
00147 void KWViewMode::setPageLayout( KoRuler* hRuler, KoRuler* vRuler, const KoPageLayout& layout )
00148 {
00149     hRuler->setPageLayout( layout );
00150     vRuler->setPageLayout( layout );
00151 }
00152 
00153 // static
00154 KWViewMode * KWViewMode::create( const QString & viewModeType, KWDocument *doc, KWCanvas* canvas )
00155 {
00156     Q_ASSERT(doc);
00157     if(viewModeType=="ModeNormal")
00158     {
00159         return new KWViewModeNormal( doc, canvas, doc->viewFrameBorders() );
00160     }
00161     else if(viewModeType=="ModeEmbedded")
00162     {
00163         return new KWViewModeEmbedded( doc, canvas );
00164     }
00165     else if(viewModeType=="ModePreview")
00166     {
00167         return new KWViewModePreview( doc, canvas, doc->viewFrameBorders(), doc->nbPagePerRow() );
00168     }
00169     else if(viewModeType=="ModeText")
00170     {
00171         KWTextFrameSet* fs = KWViewModeText::determineTextFrameSet( doc ); // could be 0
00172         return new KWViewModeText( doc, canvas, fs );
00173     }
00174     else
00175     {
00176         kdDebug() << viewModeType << " mode type is unknown\n";
00177         return 0;
00178     }
00179 }
00180 
00182 
00183 QSize KWViewModeNormal::contentsSize()
00184 {
00185     return QSize( m_doc->paperWidth(m_doc->startPage()),
00186                   m_doc->zoomItY( m_doc->pageManager()->bottomOfPage(m_doc->lastPage()) ) );
00187 }
00188 
00189 QRect KWViewModeNormal::viewPageRect( int pgNum )
00190 {
00191     KWPage* page = m_doc->pageManager()->page( pgNum );
00192     QRect r = page->zoomedRect( m_doc );
00193     r.moveBy( xOffset( page ), 0 );
00194     return r;
00195 }
00196 
00197 QPoint KWViewModeNormal::normalToView( const QPoint & nPoint )
00198 {
00199     double unzoomedY = m_doc->unzoomItY( nPoint.y() );
00200     KWPage *page = m_doc->pageManager()->page(unzoomedY);   // quotient
00201     if( !page) {
00202         kdWarning(31001) << "KWViewModeNormal::normalToView request for conversion out of the document! Check your input data.. ("<< nPoint << ")" << endl;
00203         return QPoint(0,0);
00204     }
00205     Q_ASSERT(canvas());
00206     return QPoint( xOffset(page) + nPoint.x(), nPoint.y() );
00207 }
00208 
00209 QPoint KWViewModeNormal::viewToNormal( const QPoint & vPoint )
00210 {
00211     // Opposite of the above
00212     // The Y is unchanged by the centering so we can use it to get the page.
00213     double unzoomedY = m_doc->unzoomItY( vPoint.y() );
00214     KWPage *page = m_doc->pageManager()->page(unzoomedY);   // quotient
00215     if( !page) {
00216         kdWarning(31001) << "KWViewModeNormal::normalToView request for conversion out of the document! Check your input data.. ("<< vPoint << ")" << endl;
00217         return QPoint(-1,-1); // yes this is an ugly way to mark this as an excetional state...
00218     }
00219     Q_ASSERT(canvas());
00220     return QPoint( vPoint.x() - xOffset(page), vPoint.y() );
00221 }
00222 
00223 int KWViewModeNormal::xOffset(KWPage *page, int canvasWidth /* = -1 */) {
00224     // Center horizontally
00225     if(canvasWidth < 0)
00226         canvasWidth = canvas()->visibleWidth();
00227     return kMax( 0, ( canvasWidth - m_doc->zoomItX( page->width() ) ) / 2 );
00228 }
00229 
00230 void KWViewModeNormal::drawPageBorders( QPainter * painter, const QRect & crect, const QRegion & emptySpaceRegion )
00231 {
00232     painter->save();
00233     painter->setPen( QApplication::palette().active().color( QColorGroup::Dark ) );
00234     painter->setBrush( Qt::NoBrush );
00235     QRect pageRect;
00236 
00237     int lastPage = m_doc->lastPage();
00238     Q_ASSERT(canvas());
00239     const int canvasWidth = canvas()->visibleWidth();
00240     double pagePosPt = 0;
00241     int topOfPage = 0; // in pixels
00242     for ( int pageNr = m_doc->startPage(); pageNr <= lastPage; pageNr++ )
00243     {
00244         KWPage *page = m_doc->pageManager()->page(pageNr);
00245 
00246         int pageWidth = m_doc->zoomItX( page->width() );
00247         int pageHeight = m_doc->zoomItY( pagePosPt + page->height() ) - topOfPage;
00248         if ( crect.bottom() < topOfPage )
00249             break;
00250         // Center horizontally
00251         int x = xOffset(page, canvasWidth);
00252         // Draw page border (and erase empty area inside page)
00253         pageRect = QRect( x, topOfPage, pageWidth, pageHeight );
00254         drawOnePageBorder( painter, crect, pageRect, emptySpaceRegion );
00255 
00256         // The area on the left of the page
00257         QRect leftArea( 0, topOfPage, x, pageHeight );
00258         leftArea &= crect;
00259         if ( !leftArea.isEmpty() ) {
00260             painter->fillRect( leftArea,
00261                                QApplication::palette().active().brush( QColorGroup::Mid ) );
00262         }
00263 
00264         // The area on the right of the page
00265         QRect rightArea( x + pageWidth, topOfPage, crect.right() - pageWidth + 1, pageHeight );
00266         rightArea &= crect;
00267         if ( !rightArea.isEmpty() )
00268         {
00269             painter->fillRect( rightArea,
00270                                QApplication::palette().active().brush( QColorGroup::Mid ) );
00271 
00272             // Draw a shadow
00273             int topOffset = ( page==0 ) ? s_shadowOffset : 0; // leave a few pixels on top, only for first page
00274             drawRightShadow( painter, crect, pageRect, topOffset );
00275         }
00276         pagePosPt += page->height(); // for next page already..
00277         topOfPage += pageHeight;
00278     }
00279     // Take care of the area at the bottom of the last page
00280     if ( crect.bottom() > topOfPage )
00281     {
00282         QRect bottomArea( 0, topOfPage, crect.right() + 1, crect.bottom() - topOfPage + 1 );
00283         QRect repaintRect = bottomArea.intersect( crect );
00284         if ( !repaintRect.isEmpty() )
00285         {
00286             painter->fillRect( repaintRect,
00287                     QApplication::palette().active().brush( QColorGroup::Mid ) );
00288             // Draw a shadow
00289             drawBottomShadow( painter, crect, pageRect, s_shadowOffset );
00290         }
00291     }
00292     painter->restore();
00293 }
00294 
00296 
00297 QRect KWViewModeEmbedded::viewPageRect( int pgNum )
00298 {
00299     // Only one page makes sense in embedded mode though
00300     return m_doc->pageManager()->page( pgNum )->zoomedRect( m_doc );
00301 }
00302 
00304 
00305 KWViewModePreview::KWViewModePreview( KWDocument * doc, KWCanvas* canvas,
00306                                       bool drawFrameBorders, int _nbPagePerRow )
00307     : KWViewMode( doc, canvas, drawFrameBorders ),
00308       m_pagesPerRow(_nbPagePerRow),
00309       m_spacing(10)
00310 {}
00311 
00312 int KWViewModePreview::leftSpacing()
00313 {
00314     if ( canvas() )
00315     {
00316         int pagesPerRow;
00317         if ( m_doc->pageCount() < m_pagesPerRow )
00318             pagesPerRow = m_doc->pageCount();
00319         else
00320             pagesPerRow = m_pagesPerRow;
00321 
00322         int pagesWidth = ( m_spacing + ( m_doc->paperWidth(m_doc->startPage()) + m_spacing ) * pagesPerRow );
00323         if ( pagesWidth < canvas()->visibleWidth() )
00324             return ( m_spacing + ( canvas()->visibleWidth() / 2 ) - ( pagesWidth / 2 ) );
00325     }
00326     return m_spacing;
00327 }
00328 
00329 int KWViewModePreview::topSpacing()
00330 {
00331     if ( canvas() )
00332     {
00333         int pagesHeight = ( m_spacing + ( m_doc->paperHeight(m_doc->startPage()) + m_spacing ) * numRows() );
00334         if ( pagesHeight < canvas()->visibleHeight() )
00335             return ( m_spacing + ( canvas()->visibleHeight() / 2 ) - ( pagesHeight / 2 ) );
00336     }
00337     return m_spacing;
00338 }
00339 
00340 int KWViewModePreview::numRows() const
00341 {
00342     return ( m_doc->pageCount() ) / m_pagesPerRow + 1;
00343 }
00344 
00345 QSize KWViewModePreview::contentsSize()
00346 {
00347     int pages = m_doc->pageCount();
00348     int rows = (pages-1) / m_pagesPerRow + 1;
00349     int hPages = rows > 1 ? m_pagesPerRow : pages;
00350     return QSize( m_spacing + hPages * ( m_doc->paperWidth(m_doc->startPage()) + m_spacing ),
00351                   m_spacing + rows * ( m_doc->paperHeight(m_doc->startPage()) + m_spacing ) /* bottom of last row */ );
00352 }
00353 
00354 QPoint KWViewModePreview::normalToView( const QPoint & nPoint )
00355 {
00356     // Can't use nPoint.y() / m_doc->paperHeight() since this would be a rounding problem
00357     double unzoomedY = m_doc->unzoomItY( nPoint.y() );
00358     KWPage *page = m_doc->pageManager()->page(unzoomedY);   // quotient
00359     if( !page) {
00360         kdWarning(31001) << "KWViewModePreview::normalToView request for conversion out of the document! Check your input data.. ("<< nPoint << ")" << endl;
00361         return QPoint(0,0);
00362     }
00363 
00364     double yInPagePt = unzoomedY - page->offsetInDocument();// and rest
00365     int row = (page->pageNumber() - m_doc->startPage()) / m_pagesPerRow;
00366     int col = (page->pageNumber() - m_doc->startPage()) % m_pagesPerRow;
00367     /*kdDebug() << "KWViewModePreview::normalToView nPoint=" << nPoint
00368                 << " unzoomedY=" << unzoomedY
00369                 << " page=" << page->pageNumber() << " row=" << row << " col=" << col
00370                 << " yInPagePt=" << yInPagePt << endl;*/
00371     return QPoint( leftSpacing() + col * ( m_doc->paperWidth(page->pageNumber()) +
00372                                            m_spacing ) + nPoint.x(),
00373                    topSpacing() + row * ( m_doc->paperHeight(page->pageNumber()) +
00374                                           m_spacing ) + m_doc->zoomItY( yInPagePt ) );
00375 }
00376 
00377 QRect KWViewModePreview::viewPageRect( int pgNum )
00378 {
00379     int row = (pgNum - m_doc->startPage()) / m_pagesPerRow;
00380     int col = (pgNum - m_doc->startPage()) % m_pagesPerRow;
00381     const int paperWidth = m_doc->paperWidth( pgNum );
00382     const int paperHeight = m_doc->paperHeight( pgNum );
00383     return QRect( leftSpacing() + col * ( paperWidth + m_spacing ),
00384                   topSpacing() + row * ( paperHeight + m_spacing ),
00385                   paperWidth,
00386                   paperHeight );
00387 }
00388 
00389 QPoint KWViewModePreview::viewToNormal( const QPoint & vPoint )
00390 {
00391     // Well, just the opposite of the above.... hmm.... headache....
00392     int paperWidth = m_doc->paperWidth(m_doc->startPage());
00393     int paperHeight = m_doc->paperHeight(m_doc->startPage());
00394     QPoint p( vPoint.x() - leftSpacing(), vPoint.y() - topSpacing() );
00395     int col = static_cast<int>( p.x() / ( paperWidth + m_spacing ) );
00396     int xInPage = p.x() - col * ( paperWidth + m_spacing );
00397     int row = static_cast<int>( p.y() / ( paperHeight + m_spacing ) );
00398     int yInPage = p.y() - row * ( paperHeight + m_spacing );
00399     int page = row * m_pagesPerRow + col + m_doc->startPage();
00400     if ( page > m_doc->lastPage() ) // [this happens when moving frames around and going out of the pages]
00401         return QPoint( paperWidth, m_doc->pageTop( m_doc->lastPage() ) );
00402     else // normal case
00403         return QPoint( xInPage, yInPage + m_doc->pageTop( page ) );
00404 }
00405 
00406 void KWViewModePreview::drawPageBorders( QPainter * painter, const QRect & crect, const QRegion & emptySpaceRegion )
00407 {
00408     painter->save();
00409     painter->setPen( QApplication::palette().active().color( QColorGroup::Dark ) );
00410     painter->setBrush( Qt::NoBrush );
00411     //kdDebug() << "KWViewModePreview::drawPageBorders crect=" << DEBUGRECT( crect ) << endl;
00412     QRegion grayRegion( crect );
00413     int pageCount = m_doc->pageCount();
00414     for ( int counter = 0; counter < pageCount; counter++ )
00415     {
00416         int row = counter / m_pagesPerRow;
00417         int col = counter % m_pagesPerRow;
00418         int page = m_doc->startPage() + counter;
00419         int paperWidth = m_doc->paperWidth(page);
00420         int paperHeight = m_doc->paperHeight(page);
00421         QRect pageRect( leftSpacing() + col * ( paperWidth + m_spacing ),
00422                         topSpacing() + row * ( paperHeight + m_spacing ),
00423                         paperWidth, paperHeight );
00424         drawOnePageBorder( painter, crect, pageRect, emptySpaceRegion );
00425         if( pageRect.top() > crect.bottom())
00426             break;
00427         if ( pageRect.intersects( crect ) )
00428             grayRegion -= pageRect;
00429         QRect rightShadow = drawRightShadow( painter, crect, pageRect, s_shadowOffset );
00430         if ( !rightShadow.isEmpty() )
00431             grayRegion -= rightShadow;
00432         QRect bottomShadow = drawBottomShadow( painter, crect, pageRect, s_shadowOffset );
00433         if ( !bottomShadow.isEmpty() )
00434             grayRegion -= bottomShadow;
00435 
00436         //kdDebug() << "KWViewModePreview::drawPageBorders grayRegion is now : " << endl;
00437         //DEBUGREGION( grayRegion );
00438     }
00439     if ( !grayRegion.isEmpty() )
00440     {
00441         //kdDebug() << "KWViewModePreview::drawPageBorders grayRegion's bounding Rect = " << DEBUGRECT( grayRegion.boundingRect() ) << endl;
00442         m_doc->eraseEmptySpace( painter, grayRegion, QApplication::palette().active().brush( QColorGroup::Mid ) );
00443     }
00444     painter->restore();
00445 }
00446 
00448 
00449 KWViewModeText::KWViewModeText( KWDocument * doc, KWCanvas* canvas, KWTextFrameSet* fs )
00450     : KWViewMode( doc, canvas, false )
00451 {
00452     m_textFrameSet = fs;
00453 }
00454 
00455 KWTextFrameSet * KWViewModeText::textFrameSet() const
00456 {
00457     if ( !m_textFrameSet ) // e.g. when we set this mode before we had any frames (doc not loaded yet)
00458         m_textFrameSet = determineTextFrameSet( m_doc );
00459     return m_textFrameSet;
00460 }
00461 
00462 KWTextFrameSet * KWViewModeText::determineTextFrameSet( KWDocument* doc ) // static
00463 {
00464     KWTextFrameSet* fs = 0L;
00465 
00466     if(!doc->getAllViews().empty()) { // try the one that is selected
00467         KWView *view = doc->getAllViews()[0];
00468         KWFrameView *fv = view->getGUI()->canvasWidget()->frameViewManager()->selectedFrame();
00469         KWFrame *f = fv == 0 ? 0 : fv->frame();
00470         if(f)
00471             fs = dynamic_cast<KWTextFrameSet *>( f->frameSet() );
00472 
00473         if (!fs) { // try the one I am editing
00474             KWFrameSetEdit *fse = view->getGUI()->canvasWidget()->currentFrameSetEdit();
00475             if(fse)
00476                 fs = dynamic_cast<KWTextFrameSet *>( fse->frameSet() );
00477         }
00478     }
00479 
00480     if (!fs || fs->isHeaderOrFooter() || fs->isFootEndNote())
00481         // if not a textFS, or header/footer/footnote: fallback to fs 0
00482         if ( doc->frameSetCount() > 0 && doc->frameSet( 0 )->isVisible() )
00483             fs = dynamic_cast<KWTextFrameSet *>( doc->frameSet( 0 ) );
00484 
00485     return fs;
00486 }
00487 
00488 QPoint KWViewModeText::normalToView( const QPoint & nPoint )
00489 {
00490     QPoint r (nPoint);
00491     r.setX(r.x() + OFFSET);
00492     return r;
00493 }
00494 
00495 QPoint KWViewModeText::viewToNormal( const QPoint & vPoint )
00496 {
00497     QPoint r (vPoint);
00498     r.setX(r.x() - OFFSET);
00499     return r;
00500 }
00501 
00502 QSize KWViewModeText::contentsSize()
00503 {
00504     if (!textFrameSet())
00505         return QSize();
00506 
00507     // The actual contents only depend on the amount of text.
00508     // The width is the one from the text, so that the placement of tabs makes a bit of sense, etc.
00509     // The minimum height is the one of a normal page though.
00510 
00511     int width = m_doc->layoutUnitToPixelX( m_textFrameSet->textDocument()->width() );
00512 
00513     int height = QMAX((int)m_doc->paperHeight(m_doc->startPage()),
00514                       m_doc->layoutUnitToPixelY( m_textFrameSet->textDocument()->height() ) );
00515     //kdDebug() << "KWViewModeText::contentsSize " << width << "x" << height << endl;
00516     return QSize( width, height );
00517 }
00518 
00519 QSize KWViewModeText::availableSizeForText( KWTextFrameSet* /*textfs*/ )
00520 {
00521     return contentsSize();
00522 }
00523 
00524 bool KWViewModeText::isFrameSetVisible( const KWFrameSet *fs )
00525 {
00526     if(fs==NULL) return false; // assertion
00527     if(fs==textFrameSet()) return true;
00528 
00529     const KWFrameSet* parentFrameset = fs->groupmanager() ? fs->groupmanager() : fs;
00530     while ( parentFrameset->isFloating() ) {
00531         parentFrameset = parentFrameset->anchorFrameset();
00532         if ( parentFrameset == m_textFrameSet )
00533             return true;
00534     }
00535     return false;
00536 }
00537 
00538 void KWViewModeText::drawPageBorders( QPainter * painter, const QRect & crect,
00539                                       const QRegion & /*emptySpaceRegion*/ )
00540 {
00541     painter->save();
00542     QRegion grayRegion( crect );
00543     //kdDebug() << "KWViewModeText::drawPageBorders crect=" << grayRegion << endl;
00544     painter->setPen( QApplication::palette().active().color( QColorGroup::Dark ) );
00545     QSize cSize = contentsSize();
00546     // Draw a line on the right -- ## or a shadow?
00547     // +1 to be out of the contents, and +1 for QRect
00548     QRect frameRect( OFFSET, 0, cSize.width() + 2, cSize.height() );
00549     //kdDebug() << "KWViewModeText::drawPageBorders right line: "  << frameRect.topRight() << "   " << frameRect.bottomRight()<< endl;
00550     painter->drawLine( frameRect.topRight(), frameRect.bottomRight() );
00551     if ( frameRect.intersects( crect ) )
00552         grayRegion -= frameRect;
00553 
00554     //kdDebug() << "KWViewModeText::drawPageBorders grayRegion is now " << grayRegion << endl;
00555     if ( crect.bottom() >= cSize.height() )
00556     {
00557         // And draw a line at the bottom -- ## or a shadow?
00558         painter->drawLine( 0, cSize.height(),
00559                            cSize.width(), cSize.height() );
00560         grayRegion -= QRect( 0, cSize.height(),
00561                              cSize.width(), cSize.height() );
00562     }
00563     //kdDebug() << "KWViewModeText::drawPageBorders erasing grayRegion " << grayRegion << endl;
00564     if ( !grayRegion.isEmpty() )
00565         m_doc->eraseEmptySpace( painter, grayRegion, QApplication::palette().active().brush( QColorGroup::Mid ) );
00566     painter->restore();
00567 }
00568 
00569 QRect KWViewModeText::rulerFrameRect()
00570 {
00571     return QRect( QPoint(OFFSET, 0), contentsSize() );
00572 }
00573 
00574 void KWViewModeText::setPageLayout( KoRuler* hRuler, KoRuler* vRuler, const KoPageLayout& /*layout*/ )
00575 {
00576     // Create a dummy page-layout, as if we had a single page englobing the whole text.
00577     KoPageLayout layout;
00578     layout.format = PG_CUSTOM;
00579     layout.orientation = PG_PORTRAIT;
00580     QSize cSize = contentsSize();
00581     layout.ptWidth = m_doc->unzoomItX( cSize.width() );
00582     layout.ptHeight = m_doc->unzoomItY( cSize.height() );
00583     //kdDebug() << "KWViewModeText::setPageLayout layout size " << layout.ptWidth << "x" << layout.ptHeight << endl;
00584     layout.ptLeft = OFFSET;
00585     layout.ptRight = 0;
00586     layout.ptTop = 0;
00587     layout.ptBottom = 0;
00588     layout.ptBindingSide = 0;
00589     layout.ptPageEdge = 0;
00590     hRuler->setPageLayout( layout );
00591     vRuler->setPageLayout( layout );
00592 }
00593 
00594 bool KWViewModeText::isTextModeFrameset(KWFrameSet *fs) const {
00595     return fs == textFrameSet();
00596 }
00597 
00598 
00599 int KWViewModePrint::xOffset(KWPage *page, int canvasWidth) {
00600     Q_UNUSED(page);
00601     Q_UNUSED(canvasWidth);
00602     return 0;
00603 }
KDE Home | KDE Accessibility Home | Description of Access Keys