21#include "KWViewMode.h"
24#include "KWDocument.h"
25#include "KWTextFrameSet.h"
26#include "KWFrameSet.h"
27#include "KWTableFrameSet.h"
28#include "KWPageManager.h"
30#include "KWFrameViewManager.h"
31#include "KWFrameView.h"
32#include <tqapplication.h>
35const unsigned short KWViewMode::s_shadowOffset = 3;
40 return m_doc->zoomSize( KoSize( frame->innerWidth(), frame->internalY() + frame->innerHeight() ) );
45 const TQRegion & emptySpaceRegion )
47 if ( !crect.intersects( _pageRect ) )
50 TQRect pageRect( _pageRect );
52 painter->drawRect( pageRect );
54 pageRect.rLeft() += 1;
56 pageRect.rRight() -= 1;
57 pageRect.rBottom() -= 1;
59 TQRect pagecrect = pageRect.intersect( crect );
60 if ( !pagecrect.isEmpty() )
63 TQRegion pageEmptyRegion = emptySpaceRegion.intersect( pagecrect );
65 if ( !pageEmptyRegion.isEmpty() )
66 m_doc->eraseEmptySpace( painter, pageEmptyRegion, TQApplication::palette().active().brush( TQColorGroup::Base ) );
70TQRect KWViewMode::drawRightShadow( TQPainter * painter,
const TQRect & crect,
const TQRect & pageRect,
int topOffset )
72 TQRect shadowRect( pageRect.right() + 1, pageRect.top() + topOffset, s_shadowOffset, pageRect.height() - topOffset );
74 if ( !shadowRect.isEmpty() )
76 painter->fillRect( shadowRect,
77 TQApplication::palette().active().brush( TQColorGroup::Shadow ) );
82TQRect KWViewMode::drawBottomShadow( TQPainter * painter,
const TQRect & crect,
const TQRect & pageRect,
int leftOffset )
84 TQRect shadowRect( pageRect.left() + leftOffset, pageRect.bottom() + 1, pageRect.width(), s_shadowOffset );
86 if ( !shadowRect.isEmpty() )
87 painter->fillRect( shadowRect,
88 TQApplication::palette().active().brush( TQColorGroup::Shadow ) );
97 if( m_canvas->currentFrameSetEdit() && m_canvas->currentFrameSetEdit()->currentFrame() )
98 frame = m_canvas->currentFrameSetEdit()->currentFrame();
101 frame = view == 0 ? 0 : view->
frame();
107 TQPoint nPoint( 0, m_doc->pageTop(pageNum) + 1 );
121 if ( edit && edit->currentFrame() )
122 frame = edit->currentFrame();
125 frame = view == 0 ? 0 : view->
frame();
129 if(fs) frame=fs->
frame(0);
133 TQRect r =
normalToView( m_doc->zoomRect( frame->innerRect() ) );
137 TQPoint nPoint( 0, m_doc->pageTop(pageNum) + 1 );
141 r.moveBy( -cPoint.x(), -cPoint.y() );
149 hRuler->setPageLayout( layout );
150 vRuler->setPageLayout( layout );
154KWViewMode * KWViewMode::create(
const TQString & viewModeType, KWDocument *doc,
KWCanvas* canvas )
157 if(viewModeType==
"ModeNormal")
161 else if(viewModeType==
"ModeEmbedded")
165 else if(viewModeType==
"ModePreview")
167 return new KWViewModePreview( doc, canvas, doc->viewFrameBorders(), doc->nbPagePerRow() );
169 else if(viewModeType==
"ModeText")
176 kdDebug() << viewModeType <<
" mode type is unknown\n";
185 return TQSize( m_doc->paperWidth(m_doc->startPage()),
186 m_doc->zoomItY( m_doc->pageManager()->bottomOfPage(m_doc->lastPage()) ) );
191 KWPage* page = m_doc->pageManager()->page( pgNum );
193 r.moveBy( xOffset( page ), 0 );
199 double unzoomedY = m_doc->unzoomItY( nPoint.y() );
200 KWPage *page = m_doc->pageManager()->page(unzoomedY);
202 kdWarning(31001) <<
"KWViewModeNormal::normalToView request for conversion out of the document! Check your input data.. ("<< nPoint <<
")" << endl;
206 return TQPoint( xOffset(page) + nPoint.x(), nPoint.y() );
213 double unzoomedY = m_doc->unzoomItY( vPoint.y() );
214 KWPage *page = m_doc->pageManager()->page(unzoomedY);
216 kdWarning(31001) <<
"KWViewModeNormal::normalToView request for conversion out of the document! Check your input data.. ("<< vPoint <<
")" << endl;
217 return TQPoint(-1,-1);
220 return TQPoint( vPoint.x() - xOffset(page), vPoint.y() );
223int KWViewModeNormal::xOffset(
KWPage *page,
int canvasWidth ) {
226 canvasWidth = canvas()->visibleWidth();
227 return kMax( 0, ( canvasWidth - m_doc->zoomItX( page->
width() ) ) / 2 );
230void KWViewModeNormal::drawPageBorders( TQPainter * painter,
const TQRect & crect,
const TQRegion & emptySpaceRegion )
233 painter->setPen( TQApplication::palette().active().color( TQColorGroup::Dark ) );
234 painter->setBrush( TQt::NoBrush );
237 int lastPage = m_doc->lastPage();
239 const int canvasWidth = canvas()->visibleWidth();
240 double pagePosPt = 0;
242 for (
int pageNr = m_doc->startPage(); pageNr <= lastPage; pageNr++ )
244 KWPage *page = m_doc->pageManager()->page(pageNr);
246 int pageWidth = m_doc->zoomItX( page->
width() );
247 int pageHeight = m_doc->zoomItY( pagePosPt + page->
height() ) - topOfPage;
248 if ( crect.bottom() < topOfPage )
251 int x = xOffset(page, canvasWidth);
253 pageRect = TQRect( x, topOfPage, pageWidth, pageHeight );
257 TQRect leftArea( 0, topOfPage, x, pageHeight );
259 if ( !leftArea.isEmpty() ) {
260 painter->fillRect( leftArea,
261 TQApplication::palette().active().brush( TQColorGroup::Mid ) );
265 TQRect rightArea( x + pageWidth, topOfPage, crect.right() - pageWidth + 1, pageHeight );
267 if ( !rightArea.isEmpty() )
269 painter->fillRect( rightArea,
270 TQApplication::palette().active().brush( TQColorGroup::Mid ) );
273 int topOffset = ( page==0 ) ? s_shadowOffset : 0;
274 drawRightShadow( painter, crect, pageRect, topOffset );
276 pagePosPt += page->
height();
277 topOfPage += pageHeight;
280 if ( crect.bottom() > topOfPage )
282 TQRect bottomArea( 0, topOfPage, crect.right() + 1, crect.bottom() - topOfPage + 1 );
283 TQRect repaintRect = bottomArea.intersect( crect );
284 if ( !repaintRect.isEmpty() )
286 painter->fillRect( repaintRect,
287 TQApplication::palette().active().brush( TQColorGroup::Mid ) );
289 drawBottomShadow( painter, crect, pageRect, s_shadowOffset );
300 return m_doc->pageManager()->page( pgNum )->zoomedRect( m_doc );
305KWViewModePreview::KWViewModePreview( KWDocument * doc,
KWCanvas* canvas,
306 bool drawFrameBorders,
int _nbPagePerRow )
307 :
KWViewMode( doc, canvas, drawFrameBorders ),
308 m_pagesPerRow(_nbPagePerRow),
317 if ( m_doc->pageCount() < m_pagesPerRow )
318 pagesPerRow = m_doc->pageCount();
320 pagesPerRow = m_pagesPerRow;
322 int pagesWidth = ( m_spacing + ( m_doc->paperWidth(m_doc->startPage()) + m_spacing ) * pagesPerRow );
323 if ( pagesWidth < canvas()->visibleWidth() )
324 return ( m_spacing + ( canvas()->visibleWidth() / 2 ) - ( pagesWidth / 2 ) );
333 int pagesHeight = ( m_spacing + ( m_doc->paperHeight(m_doc->startPage()) + m_spacing ) * numRows() );
334 if ( pagesHeight < canvas()->visibleHeight() )
335 return ( m_spacing + ( canvas()->visibleHeight() / 2 ) - ( pagesHeight / 2 ) );
340int KWViewModePreview::numRows()
const
342 return ( m_doc->pageCount() ) / m_pagesPerRow + 1;
347 int pages = m_doc->pageCount();
348 int rows = (pages-1) / m_pagesPerRow + 1;
349 int hPages = rows > 1 ? m_pagesPerRow : pages;
350 return TQSize( m_spacing + hPages * ( m_doc->paperWidth(m_doc->startPage()) + m_spacing ),
351 m_spacing + rows * ( m_doc->paperHeight(m_doc->startPage()) + m_spacing ) );
357 double unzoomedY = m_doc->unzoomItY( nPoint.y() );
358 KWPage *page = m_doc->pageManager()->page(unzoomedY);
360 kdWarning(31001) <<
"KWViewModePreview::normalToView request for conversion out of the document! Check your input data.. ("<< nPoint <<
")" << endl;
365 int row = (page->
pageNumber() - m_doc->startPage()) / m_pagesPerRow;
366 int col = (page->
pageNumber() - m_doc->startPage()) % m_pagesPerRow;
372 m_spacing ) + nPoint.x(),
374 m_spacing ) + m_doc->zoomItY( yInPagePt ) );
379 int row = (pgNum - m_doc->startPage()) / m_pagesPerRow;
380 int col = (pgNum - m_doc->startPage()) % m_pagesPerRow;
381 const int paperWidth = m_doc->paperWidth( pgNum );
382 const int paperHeight = m_doc->paperHeight( pgNum );
383 return TQRect(
leftSpacing() + col * ( paperWidth + m_spacing ),
384 topSpacing() + row * ( paperHeight + m_spacing ),
392 int paperWidth = m_doc->paperWidth(m_doc->startPage());
393 int paperHeight = m_doc->paperHeight(m_doc->startPage());
395 int col =
static_cast<int>( p.x() / ( paperWidth + m_spacing ) );
396 int xInPage = p.x() - col * ( paperWidth + m_spacing );
397 int row =
static_cast<int>( p.y() / ( paperHeight + m_spacing ) );
398 int yInPage = p.y() - row * ( paperHeight + m_spacing );
399 int page = row * m_pagesPerRow + col + m_doc->startPage();
400 if ( page > m_doc->lastPage() )
401 return TQPoint( paperWidth, m_doc->pageTop( m_doc->lastPage() ) );
403 return TQPoint( xInPage, yInPage + m_doc->pageTop( page ) );
406void KWViewModePreview::drawPageBorders( TQPainter * painter,
const TQRect & crect,
const TQRegion & emptySpaceRegion )
409 painter->setPen( TQApplication::palette().active().color( TQColorGroup::Dark ) );
410 painter->setBrush( TQt::NoBrush );
412 TQRegion grayRegion( crect );
413 int pageCount = m_doc->pageCount();
414 for (
int counter = 0; counter < pageCount; counter++ )
416 int row = counter / m_pagesPerRow;
417 int col = counter % m_pagesPerRow;
418 int page = m_doc->startPage() + counter;
419 int paperWidth = m_doc->paperWidth(page);
420 int paperHeight = m_doc->paperHeight(page);
421 TQRect pageRect(
leftSpacing() + col * ( paperWidth + m_spacing ),
422 topSpacing() + row * ( paperHeight + m_spacing ),
423 paperWidth, paperHeight );
425 if( pageRect.top() > crect.bottom())
427 if ( pageRect.intersects( crect ) )
428 grayRegion -= pageRect;
429 TQRect rightShadow = drawRightShadow( painter, crect, pageRect, s_shadowOffset );
430 if ( !rightShadow.isEmpty() )
431 grayRegion -= rightShadow;
432 TQRect bottomShadow = drawBottomShadow( painter, crect, pageRect, s_shadowOffset );
433 if ( !bottomShadow.isEmpty() )
434 grayRegion -= bottomShadow;
439 if ( !grayRegion.isEmpty() )
442 m_doc->eraseEmptySpace( painter, grayRegion, TQApplication::palette().active().brush( TQColorGroup::Mid ) );
457 if ( !m_textFrameSet )
459 return m_textFrameSet;
466 if(!doc->getAllViews().empty()) {
467 KWView *view = doc->getAllViews()[0];
468 KWFrameView *fv = view->getGUI()->canvasWidget()->frameViewManager()->selectedFrame();
474 KWFrameSetEdit *fse = view->getGUI()->canvasWidget()->currentFrameSetEdit();
480 if (!fs || fs->isHeaderOrFooter() || fs->isFootEndNote())
482 if ( doc->frameSetCount() > 0 && doc->frameSet( 0 )->isVisible() )
511 int width = m_doc->layoutUnitToPixelX( m_textFrameSet->textDocument()->width() );
513 int height = TQMAX((
int)m_doc->paperHeight(m_doc->startPage()),
514 m_doc->layoutUnitToPixelY( m_textFrameSet->textDocument()->height() ) );
516 return TQSize( width, height );
526 if(fs==NULL)
return false;
527 if(fs==textFrameSet())
return true;
532 if ( parentFrameset == m_textFrameSet )
538void KWViewModeText::drawPageBorders( TQPainter * painter,
const TQRect & crect,
542 TQRegion grayRegion( crect );
544 painter->setPen( TQApplication::palette().active().color( TQColorGroup::Dark ) );
548 TQRect frameRect(
OFFSET, 0, cSize.width() + 2, cSize.height() );
550 painter->drawLine( frameRect.topRight(), frameRect.bottomRight() );
551 if ( frameRect.intersects( crect ) )
552 grayRegion -= frameRect;
555 if ( crect.bottom() >= cSize.height() )
558 painter->drawLine( 0, cSize.height(),
559 cSize.width(), cSize.height() );
560 grayRegion -= TQRect( 0, cSize.height(),
561 cSize.width(), cSize.height() );
564 if ( !grayRegion.isEmpty() )
565 m_doc->eraseEmptySpace( painter, grayRegion, TQApplication::palette().active().brush( TQColorGroup::Mid ) );
578 layout.format = PG_CUSTOM;
579 layout.orientation = PG_PORTRAIT;
581 layout.ptWidth = m_doc->unzoomItX( cSize.width() );
582 layout.ptHeight = m_doc->unzoomItY( cSize.height() );
588 layout.ptBindingSide = 0;
589 layout.ptPageEdge = 0;
590 hRuler->setPageLayout( layout );
591 vRuler->setPageLayout( layout );
595 return fs == textFrameSet();
599int KWViewModePrint::xOffset(
KWPage *page,
int canvasWidth) {
601 Q_UNUSED(canvasWidth);
Class: KWCanvas This class is responsible for the rendering of the frames to the screen as well as th...
This object is created to edit a particular frameset in a particular view The view's canvas creates i...
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
const TQPtrList< KWFrame > & frameIterator() const
Iterator over the child frames.
bool isFloating() const
Return true if this frameset is floating (inline), false if it's fixed.
KWTableFrameSet * groupmanager() const
returns the groupManager this frameset belongs to.
KWTextFrameSet * anchorFrameset() const
Return the frameset in which our anchor is - assuming isFloating()
KWFrame * frame(unsigned int _num) const
get a frame by number
KWFrameView * selectedFrame() const
Returns the first selected frame.
an instance of a KWFrameView represents the view in the MVC model of a frame; there can be multiple K...
KWFrame * frame() const
returns the frame this frameView represents
This class represents a single frame.
KWFrameSet * frameSet() const
Data stucture methods.
int pageNumber() const
The page on which this frame is.
This class represents a printed page of the document.
double height() const
return the height of this page (in pt)
int pageNumber() const
returns the number of this page as it will be shown to the user.
double width() const
return the width of this page (in pt)
double offsetInDocument() const
All Pages are in a document-wide coordinate system that simply puts every page under the next page an...
TQRect zoomedRect(KoZoomHandler *zoomHandler)
return a TQRect with the size of this page in pixels.
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
The 'embedded' view mode (usually a single page, no selections)
virtual TQRect viewPageRect(int pgNum)
Return view coord for page rect.
The 'normal' view mode (pages below one another)
virtual TQPoint viewToNormal(const TQPoint &vPoint)
View coord -> normal coord.
virtual TQSize contentsSize()
Size of the contents area, in pixels.
virtual TQRect viewPageRect(int pgNum)
Return view coord for page rect.
virtual TQPoint normalToView(const TQPoint &nPoint)
Normal coord -> view coord.
A mode for previewing the overall document Pages are organized in a grid (mostly useful when zooming ...
int leftSpacing()
Return the spacing between the left border of the canvas and the page.
virtual TQRect viewPageRect(int pgNum)
Return view coord for page rect.
int topSpacing()
Return the spacing between the top border of the canvas and the page.
virtual TQPoint normalToView(const TQPoint &nPoint)
Normal coord -> view coord.
virtual TQPoint viewToNormal(const TQPoint &vPoint)
View coord -> normal coord.
virtual TQSize contentsSize()
Size of the contents area, in pixels.
The 'edit only one text frameset' view mode.
virtual TQSize contentsSize()
Size of the contents area, in pixels.
virtual TQRect rulerFrameRect()
The result of this is passed to setFrameStartEnd for both rulers (after adjustement with pageCorner()...
static KWTextFrameSet * determineTextFrameSet(KWDocument *doc)
Return a text frameset that the user has either selected or is currently editing, returning the main ...
virtual bool isFrameSetVisible(const KWFrameSet *fs)
Should this frameset be visible in this viewmode? True by default, all are shown.
virtual void setPageLayout(KoRuler *hRuler, KoRuler *vRuler, const KoPageLayout &layout)
Called when the page layout is set, or changes.
virtual TQPoint viewToNormal(const TQPoint &vPoint)
View coord -> normal coord.
virtual TQPoint normalToView(const TQPoint &nPoint)
Normal coord -> view coord.
static const int OFFSET
hardcoded distance from the left side this viewmode starts its rendering
virtual TQSize availableSizeForText(KWTextFrameSet *textfs)
Size (in pixels) of the total area available for text in a given textframeset This is used by KWTextF...
virtual bool isTextModeFrameset(KWFrameSet *fs) const
Answers the question if argument frameset has to be drawn as a text-mode text area if true,...
Abstract base class for KWCanvas's view modes.
virtual void setPageLayout(KoRuler *hRuler, KoRuler *vRuler, const KoPageLayout &layout)
Called when the page layout is set, or changes.
virtual TQRect rulerFrameRect()
The result of this is passed to setFrameStartEnd for both rulers (after adjustement with pageCorner()...
virtual TQPoint pageCorner()
"Topleft of current page" - concept used by the rulers.
virtual TQSize availableSizeForText(KWTextFrameSet *textfs)
Size (in pixels) of the total area available for text in a given textframeset This is used by KWTextF...
virtual TQPoint normalToView(const TQPoint &nPoint)=0
Normal coord -> view coord.
void drawOnePageBorder(TQPainter *painter, const TQRect &crect, const TQRect &pageRect, const TQRegion &emptySpaceRegion)
Draw the border around one page, and clear up the empty space in that page.