1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
/* This file is part of the KDE project
Copyright (C) 2001-2005 David Faure <faure@kde.org>
Copyright (C) 2005 Thomas Zander <zander@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KWViewMode.h"
#include "KWCanvas.h"
#include "KWView.h"
#include "KWDocument.h"
#include "KWTextFrameSet.h"
#include "KWFrameSet.h"
#include "KWTableFrameSet.h"
#include "KWPageManager.h"
#include "KWPage.h"
#include "KWFrameViewManager.h"
#include "KWFrameView.h"
#include <tqapplication.h>
#include <kdebug.h>
const unsigned short KWViewMode::s_shadowOffset = 3;
TQSize KWViewMode::availableSizeForText( KWTextFrameSet* textfs )
{
KWFrame* frame = textfs->frameIterator().getLast();
return m_doc->zoomSize( KoSize( frame->innerWidth(), frame->internalY() + frame->innerHeight() ) );
}
void KWViewMode::drawOnePageBorder( TQPainter * painter, const TQRect & crect, const TQRect & _pageRect,
const TQRegion & emptySpaceRegion )
{
if ( !crect.intersects( _pageRect ) )
return;
TQRect pageRect( _pageRect );
//kdDebug() << "KWViewMode::drawOnePageBorder drawing page rect " << pageRect << endl;
painter->drawRect( pageRect );
// Exclude page border line, to get the page contents rect (avoids flicker)
pageRect.rLeft() += 1;
pageRect.rTop() += 1;
pageRect.rRight() -= 1;
pageRect.rBottom() -= 1;
// The empty space to clear up inside this page
TQRect pagecrect = pageRect.intersect( crect );
if ( !pagecrect.isEmpty() )
{
//kdDebug() << "KWViewMode::drawOnePageBorder : pagecrect=" << pagecrect << " emptySpaceRegion: " << emptySpaceRegion << endl;
TQRegion pageEmptyRegion = emptySpaceRegion.intersect( pagecrect );
//kdDebug() << "RESULT: pageEmptyRegion: " << pageEmptyRegion << endl;
if ( !pageEmptyRegion.isEmpty() )
m_doc->eraseEmptySpace( painter, pageEmptyRegion, TQApplication::palette().active().brush( TQColorGroup::Base ) );
}
}
TQRect KWViewMode::drawRightShadow( TQPainter * painter, const TQRect & crect, const TQRect & pageRect, int topOffset )
{
TQRect shadowRect( pageRect.right() + 1, pageRect.top() + topOffset, s_shadowOffset, pageRect.height() - topOffset );
shadowRect &= crect; // intersect
if ( !shadowRect.isEmpty() )
{
painter->fillRect( shadowRect,
TQApplication::palette().active().brush( TQColorGroup::Shadow ) );
}
return shadowRect;
}
TQRect KWViewMode::drawBottomShadow( TQPainter * painter, const TQRect & crect, const TQRect & pageRect, int leftOffset )
{
TQRect shadowRect( pageRect.left() + leftOffset, pageRect.bottom() + 1, pageRect.width(), s_shadowOffset );
shadowRect &= crect; // intersect
if ( !shadowRect.isEmpty() )
painter->fillRect( shadowRect,
TQApplication::palette().active().brush( TQColorGroup::Shadow ) );
return shadowRect;
}
TQPoint KWViewMode::pageCorner()
{
// Same code as KWView::slotUpdateRuler
KWFrame * frame = 0L;
// Use the currently edited (fallback: the first selected) frame
if( m_canvas->currentFrameSetEdit() && m_canvas->currentFrameSetEdit()->currentFrame() )
frame = m_canvas->currentFrameSetEdit()->currentFrame();
else {
KWFrameView *view = m_canvas->frameViewManager()->selectedFrame();
frame = view == 0 ? 0 : view->frame();
}
int pageNum = 0;
if ( frame )
pageNum = frame->pageNumber();
TQPoint nPoint( 0, m_doc->pageTop(pageNum) + 1 );
TQPoint cPoint( normalToView( nPoint ) );
/*kdDebug() << "KWViewMode::pageCorner frame=" << frame << " pagenum=" << pageNum
<< " nPoint=" << nPoint.x() << "," << nPoint.y()
<< " cPoint=" << cPoint.x() << "," << cPoint.y() << endl;*/
return cPoint;
}
TQRect KWViewMode::rulerFrameRect()
{
// Set the "frame start" in the ruler (tabs are relative to that position)
KWFrameSetEdit * edit = m_canvas->currentFrameSetEdit();
KWFrame * frame = 0L;
// Use the currently edited (fallback: the first selected) frame
if ( edit && edit->currentFrame() )
frame = edit->currentFrame();
else {
KWFrameView *view = m_canvas->frameViewManager()->selectedFrame();
frame = view == 0 ? 0 : view->frame();
}
if( !frame) {
KWFrameSet *fs= m_doc->frameSet(0);
if(fs) frame=fs->frame(0);
}
if ( frame )
{
TQRect r = normalToView( m_doc->zoomRect( frame->innerRect() ) );
// Calculate page corner (see pageCorner above)
int pageNum = frame->pageNumber();
TQPoint nPoint( 0, m_doc->pageTop(pageNum) + 1 );
TQPoint cPoint( normalToView( nPoint ) );
// Frame start/end is relative to page corner.
r.moveBy( -cPoint.x(), -cPoint.y() );
return r;
}
return TQRect();
}
void KWViewMode::setPageLayout( KoRuler* hRuler, KoRuler* vRuler, const KoPageLayout& layout )
{
hRuler->setPageLayout( layout );
vRuler->setPageLayout( layout );
}
// static
KWViewMode * KWViewMode::create( const TQString & viewModeType, KWDocument *doc, KWCanvas* canvas )
{
Q_ASSERT(doc);
if(viewModeType=="ModeNormal")
{
return new KWViewModeNormal( doc, canvas, doc->viewFrameBorders() );
}
else if(viewModeType=="ModeEmbedded")
{
return new KWViewModeEmbedded( doc, canvas );
}
else if(viewModeType=="ModePreview")
{
return new KWViewModePreview( doc, canvas, doc->viewFrameBorders(), doc->nbPagePerRow() );
}
else if(viewModeType=="ModeText")
{
KWTextFrameSet* fs = KWViewModeText::determineTextFrameSet( doc ); // could be 0
return new KWViewModeText( doc, canvas, fs );
}
else
{
kdDebug() << viewModeType << " mode type is unknown\n";
return 0;
}
}
////
TQSize KWViewModeNormal::contentsSize()
{
return TQSize( m_doc->paperWidth(m_doc->startPage()),
m_doc->zoomItY( m_doc->pageManager()->bottomOfPage(m_doc->lastPage()) ) );
}
TQRect KWViewModeNormal::viewPageRect( int pgNum )
{
KWPage* page = m_doc->pageManager()->page( pgNum );
TQRect r = page->zoomedRect( m_doc );
r.moveBy( xOffset( page ), 0 );
return r;
}
TQPoint KWViewModeNormal::normalToView( const TQPoint & nPoint )
{
double unzoomedY = m_doc->unzoomItY( nPoint.y() );
KWPage *page = m_doc->pageManager()->page(unzoomedY); // quotient
if( !page) {
kdWarning(31001) << "KWViewModeNormal::normalToView request for conversion out of the document! Check your input data.. ("<< nPoint << ")" << endl;
return TQPoint(0,0);
}
Q_ASSERT(canvas());
return TQPoint( xOffset(page) + nPoint.x(), nPoint.y() );
}
TQPoint KWViewModeNormal::viewToNormal( const TQPoint & vPoint )
{
// Opposite of the above
// The Y is unchanged by the centering so we can use it to get the page.
double unzoomedY = m_doc->unzoomItY( vPoint.y() );
KWPage *page = m_doc->pageManager()->page(unzoomedY); // quotient
if( !page) {
kdWarning(31001) << "KWViewModeNormal::normalToView request for conversion out of the document! Check your input data.. ("<< vPoint << ")" << endl;
return TQPoint(-1,-1); // yes this is an ugly way to mark this as an excetional state...
}
Q_ASSERT(canvas());
return TQPoint( vPoint.x() - xOffset(page), vPoint.y() );
}
int KWViewModeNormal::xOffset(KWPage *page, int canvasWidth /* = -1 */) {
// Center horizontally
if(canvasWidth < 0)
canvasWidth = canvas()->visibleWidth();
return kMax( 0, ( canvasWidth - m_doc->zoomItX( page->width() ) ) / 2 );
}
void KWViewModeNormal::drawPageBorders( TQPainter * painter, const TQRect & crect, const TQRegion & emptySpaceRegion )
{
painter->save();
painter->setPen( TQApplication::palette().active().color( TQColorGroup::Dark ) );
painter->setBrush( TQt::NoBrush );
TQRect pageRect;
int lastPage = m_doc->lastPage();
Q_ASSERT(canvas());
const int canvasWidth = canvas()->visibleWidth();
double pagePosPt = 0;
int topOfPage = 0; // in pixels
for ( int pageNr = m_doc->startPage(); pageNr <= lastPage; pageNr++ )
{
KWPage *page = m_doc->pageManager()->page(pageNr);
int pageWidth = m_doc->zoomItX( page->width() );
int pageHeight = m_doc->zoomItY( pagePosPt + page->height() ) - topOfPage;
if ( crect.bottom() < topOfPage )
break;
// Center horizontally
int x = xOffset(page, canvasWidth);
// Draw page border (and erase empty area inside page)
pageRect = TQRect( x, topOfPage, pageWidth, pageHeight );
drawOnePageBorder( painter, crect, pageRect, emptySpaceRegion );
// The area on the left of the page
TQRect leftArea( 0, topOfPage, x, pageHeight );
leftArea &= crect;
if ( !leftArea.isEmpty() ) {
painter->fillRect( leftArea,
TQApplication::palette().active().brush( TQColorGroup::Mid ) );
}
// The area on the right of the page
TQRect rightArea( x + pageWidth, topOfPage, crect.right() - pageWidth + 1, pageHeight );
rightArea &= crect;
if ( !rightArea.isEmpty() )
{
painter->fillRect( rightArea,
TQApplication::palette().active().brush( TQColorGroup::Mid ) );
// Draw a shadow
int topOffset = ( page==0 ) ? s_shadowOffset : 0; // leave a few pixels on top, only for first page
drawRightShadow( painter, crect, pageRect, topOffset );
}
pagePosPt += page->height(); // for next page already..
topOfPage += pageHeight;
}
// Take care of the area at the bottom of the last page
if ( crect.bottom() > topOfPage )
{
TQRect bottomArea( 0, topOfPage, crect.right() + 1, crect.bottom() - topOfPage + 1 );
TQRect repaintRect = bottomArea.intersect( crect );
if ( !repaintRect.isEmpty() )
{
painter->fillRect( repaintRect,
TQApplication::palette().active().brush( TQColorGroup::Mid ) );
// Draw a shadow
drawBottomShadow( painter, crect, pageRect, s_shadowOffset );
}
}
painter->restore();
}
////
TQRect KWViewModeEmbedded::viewPageRect( int pgNum )
{
// Only one page makes sense in embedded mode though
return m_doc->pageManager()->page( pgNum )->zoomedRect( m_doc );
}
//////////////////////// Preview mode ////////////////////////////////
KWViewModePreview::KWViewModePreview( KWDocument * doc, KWCanvas* canvas,
bool drawFrameBorders, int _nbPagePerRow )
: KWViewMode( doc, canvas, drawFrameBorders ),
m_pagesPerRow(_nbPagePerRow),
m_spacing(10)
{}
int KWViewModePreview::leftSpacing()
{
if ( canvas() )
{
int pagesPerRow;
if ( m_doc->pageCount() < m_pagesPerRow )
pagesPerRow = m_doc->pageCount();
else
pagesPerRow = m_pagesPerRow;
int pagesWidth = ( m_spacing + ( m_doc->paperWidth(m_doc->startPage()) + m_spacing ) * pagesPerRow );
if ( pagesWidth < canvas()->visibleWidth() )
return ( m_spacing + ( canvas()->visibleWidth() / 2 ) - ( pagesWidth / 2 ) );
}
return m_spacing;
}
int KWViewModePreview::topSpacing()
{
if ( canvas() )
{
int pagesHeight = ( m_spacing + ( m_doc->paperHeight(m_doc->startPage()) + m_spacing ) * numRows() );
if ( pagesHeight < canvas()->visibleHeight() )
return ( m_spacing + ( canvas()->visibleHeight() / 2 ) - ( pagesHeight / 2 ) );
}
return m_spacing;
}
int KWViewModePreview::numRows() const
{
return ( m_doc->pageCount() ) / m_pagesPerRow + 1;
}
TQSize KWViewModePreview::contentsSize()
{
int pages = m_doc->pageCount();
int rows = (pages-1) / m_pagesPerRow + 1;
int hPages = rows > 1 ? m_pagesPerRow : pages;
return TQSize( m_spacing + hPages * ( m_doc->paperWidth(m_doc->startPage()) + m_spacing ),
m_spacing + rows * ( m_doc->paperHeight(m_doc->startPage()) + m_spacing ) /* bottom of last row */ );
}
TQPoint KWViewModePreview::normalToView( const TQPoint & nPoint )
{
// Can't use nPoint.y() / m_doc->paperHeight() since this would be a rounding problem
double unzoomedY = m_doc->unzoomItY( nPoint.y() );
KWPage *page = m_doc->pageManager()->page(unzoomedY); // quotient
if( !page) {
kdWarning(31001) << "KWViewModePreview::normalToView request for conversion out of the document! Check your input data.. ("<< nPoint << ")" << endl;
return TQPoint(0,0);
}
double yInPagePt = unzoomedY - page->offsetInDocument();// and rest
int row = (page->pageNumber() - m_doc->startPage()) / m_pagesPerRow;
int col = (page->pageNumber() - m_doc->startPage()) % m_pagesPerRow;
/*kdDebug() << "KWViewModePreview::normalToView nPoint=" << nPoint
<< " unzoomedY=" << unzoomedY
<< " page=" << page->pageNumber() << " row=" << row << " col=" << col
<< " yInPagePt=" << yInPagePt << endl;*/
return TQPoint( leftSpacing() + col * ( m_doc->paperWidth(page->pageNumber()) +
m_spacing ) + nPoint.x(),
topSpacing() + row * ( m_doc->paperHeight(page->pageNumber()) +
m_spacing ) + m_doc->zoomItY( yInPagePt ) );
}
TQRect KWViewModePreview::viewPageRect( int pgNum )
{
int row = (pgNum - m_doc->startPage()) / m_pagesPerRow;
int col = (pgNum - m_doc->startPage()) % m_pagesPerRow;
const int paperWidth = m_doc->paperWidth( pgNum );
const int paperHeight = m_doc->paperHeight( pgNum );
return TQRect( leftSpacing() + col * ( paperWidth + m_spacing ),
topSpacing() + row * ( paperHeight + m_spacing ),
paperWidth,
paperHeight );
}
TQPoint KWViewModePreview::viewToNormal( const TQPoint & vPoint )
{
// Well, just the opposite of the above.... hmm.... headache....
int paperWidth = m_doc->paperWidth(m_doc->startPage());
int paperHeight = m_doc->paperHeight(m_doc->startPage());
TQPoint p( vPoint.x() - leftSpacing(), vPoint.y() - topSpacing() );
int col = static_cast<int>( p.x() / ( paperWidth + m_spacing ) );
int xInPage = p.x() - col * ( paperWidth + m_spacing );
int row = static_cast<int>( p.y() / ( paperHeight + m_spacing ) );
int yInPage = p.y() - row * ( paperHeight + m_spacing );
int page = row * m_pagesPerRow + col + m_doc->startPage();
if ( page > m_doc->lastPage() ) // [this happens when moving frames around and going out of the pages]
return TQPoint( paperWidth, m_doc->pageTop( m_doc->lastPage() ) );
else // normal case
return TQPoint( xInPage, yInPage + m_doc->pageTop( page ) );
}
void KWViewModePreview::drawPageBorders( TQPainter * painter, const TQRect & crect, const TQRegion & emptySpaceRegion )
{
painter->save();
painter->setPen( TQApplication::palette().active().color( TQColorGroup::Dark ) );
painter->setBrush( TQt::NoBrush );
//kdDebug() << "KWViewModePreview::drawPageBorders crect=" << DEBUGRECT( crect ) << endl;
TQRegion grayRegion( crect );
int pageCount = m_doc->pageCount();
for ( int counter = 0; counter < pageCount; counter++ )
{
int row = counter / m_pagesPerRow;
int col = counter % m_pagesPerRow;
int page = m_doc->startPage() + counter;
int paperWidth = m_doc->paperWidth(page);
int paperHeight = m_doc->paperHeight(page);
TQRect pageRect( leftSpacing() + col * ( paperWidth + m_spacing ),
topSpacing() + row * ( paperHeight + m_spacing ),
paperWidth, paperHeight );
drawOnePageBorder( painter, crect, pageRect, emptySpaceRegion );
if( pageRect.top() > crect.bottom())
break;
if ( pageRect.intersects( crect ) )
grayRegion -= pageRect;
TQRect rightShadow = drawRightShadow( painter, crect, pageRect, s_shadowOffset );
if ( !rightShadow.isEmpty() )
grayRegion -= rightShadow;
TQRect bottomShadow = drawBottomShadow( painter, crect, pageRect, s_shadowOffset );
if ( !bottomShadow.isEmpty() )
grayRegion -= bottomShadow;
//kdDebug() << "KWViewModePreview::drawPageBorders grayRegion is now : " << endl;
//DEBUGREGION( grayRegion );
}
if ( !grayRegion.isEmpty() )
{
//kdDebug() << "KWViewModePreview::drawPageBorders grayRegion's bounding Rect = " << DEBUGRECT( grayRegion.boundingRect() ) << endl;
m_doc->eraseEmptySpace( painter, grayRegion, TQApplication::palette().active().brush( TQColorGroup::Mid ) );
}
painter->restore();
}
//////////////////
KWViewModeText::KWViewModeText( KWDocument * doc, KWCanvas* canvas, KWTextFrameSet* fs )
: KWViewMode( doc, canvas, false )
{
m_textFrameSet = fs;
}
KWTextFrameSet * KWViewModeText::textFrameSet() const
{
if ( !m_textFrameSet ) // e.g. when we set this mode before we had any frames (doc not loaded yet)
m_textFrameSet = determineTextFrameSet( m_doc );
return m_textFrameSet;
}
KWTextFrameSet * KWViewModeText::determineTextFrameSet( KWDocument* doc ) // static
{
KWTextFrameSet* fs = 0L;
if(!doc->getAllViews().empty()) { // try the one that is selected
KWView *view = doc->getAllViews()[0];
KWFrameView *fv = view->getGUI()->canvasWidget()->frameViewManager()->selectedFrame();
KWFrame *f = fv == 0 ? 0 : fv->frame();
if(f)
fs = dynamic_cast<KWTextFrameSet *>( f->frameSet() );
if (!fs) { // try the one I am editing
KWFrameSetEdit *fse = view->getGUI()->canvasWidget()->currentFrameSetEdit();
if(fse)
fs = dynamic_cast<KWTextFrameSet *>( fse->frameSet() );
}
}
if (!fs || fs->isHeaderOrFooter() || fs->isFootEndNote())
// if not a textFS, or header/footer/footnote: fallback to fs 0
if ( doc->frameSetCount() > 0 && doc->frameSet( 0 )->isVisible() )
fs = dynamic_cast<KWTextFrameSet *>( doc->frameSet( 0 ) );
return fs;
}
TQPoint KWViewModeText::normalToView( const TQPoint & nPoint )
{
TQPoint r (nPoint);
r.setX(r.x() + OFFSET);
return r;
}
TQPoint KWViewModeText::viewToNormal( const TQPoint & vPoint )
{
TQPoint r (vPoint);
r.setX(r.x() - OFFSET);
return r;
}
TQSize KWViewModeText::contentsSize()
{
if (!textFrameSet())
return TQSize();
// The actual contents only depend on the amount of text.
// The width is the one from the text, so that the placement of tabs makes a bit of sense, etc.
// The minimum height is the one of a normal page though.
int width = m_doc->layoutUnitToPixelX( m_textFrameSet->textDocument()->width() );
int height = TQMAX((int)m_doc->paperHeight(m_doc->startPage()),
m_doc->layoutUnitToPixelY( m_textFrameSet->textDocument()->height() ) );
//kdDebug() << "KWViewModeText::contentsSize " << width << "x" << height << endl;
return TQSize( width, height );
}
TQSize KWViewModeText::availableSizeForText( KWTextFrameSet* /*textfs*/ )
{
return contentsSize();
}
bool KWViewModeText::isFrameSetVisible( const KWFrameSet *fs )
{
if(fs==NULL) return false; // assertion
if(fs==textFrameSet()) return true;
const KWFrameSet* parentFrameset = fs->groupmanager() ? fs->groupmanager() : fs;
while ( parentFrameset->isFloating() ) {
parentFrameset = parentFrameset->anchorFrameset();
if ( parentFrameset == m_textFrameSet )
return true;
}
return false;
}
void KWViewModeText::drawPageBorders( TQPainter * painter, const TQRect & crect,
const TQRegion & /*emptySpaceRegion*/ )
{
painter->save();
TQRegion grayRegion( crect );
//kdDebug() << "KWViewModeText::drawPageBorders crect=" << grayRegion << endl;
painter->setPen( TQApplication::palette().active().color( TQColorGroup::Dark ) );
TQSize cSize = contentsSize();
// Draw a line on the right -- ## or a shadow?
// +1 to be out of the contents, and +1 for TQRect
TQRect frameRect( OFFSET, 0, cSize.width() + 2, cSize.height() );
//kdDebug() << "KWViewModeText::drawPageBorders right line: " << frameRect.topRight() << " " << frameRect.bottomRight()<< endl;
painter->drawLine( frameRect.topRight(), frameRect.bottomRight() );
if ( frameRect.intersects( crect ) )
grayRegion -= frameRect;
//kdDebug() << "KWViewModeText::drawPageBorders grayRegion is now " << grayRegion << endl;
if ( crect.bottom() >= cSize.height() )
{
// And draw a line at the bottom -- ## or a shadow?
painter->drawLine( 0, cSize.height(),
cSize.width(), cSize.height() );
grayRegion -= TQRect( 0, cSize.height(),
cSize.width(), cSize.height() );
}
//kdDebug() << "KWViewModeText::drawPageBorders erasing grayRegion " << grayRegion << endl;
if ( !grayRegion.isEmpty() )
m_doc->eraseEmptySpace( painter, grayRegion, TQApplication::palette().active().brush( TQColorGroup::Mid ) );
painter->restore();
}
TQRect KWViewModeText::rulerFrameRect()
{
return TQRect( TQPoint(OFFSET, 0), contentsSize() );
}
void KWViewModeText::setPageLayout( KoRuler* hRuler, KoRuler* vRuler, const KoPageLayout& /*layout*/ )
{
// Create a dummy page-layout, as if we had a single page englobing the whole text.
KoPageLayout layout;
layout.format = PG_CUSTOM;
layout.orientation = PG_PORTRAIT;
TQSize cSize = contentsSize();
layout.ptWidth = m_doc->unzoomItX( cSize.width() );
layout.ptHeight = m_doc->unzoomItY( cSize.height() );
//kdDebug() << "KWViewModeText::setPageLayout layout size " << layout.ptWidth << "x" << layout.ptHeight << endl;
layout.ptLeft = OFFSET;
layout.ptRight = 0;
layout.ptTop = 0;
layout.ptBottom = 0;
layout.ptBindingSide = 0;
layout.ptPageEdge = 0;
hRuler->setPageLayout( layout );
vRuler->setPageLayout( layout );
}
bool KWViewModeText::isTextModeFrameset(KWFrameSet *fs) const {
return fs == textFrameSet();
}
int KWViewModePrint::xOffset(KWPage *page, int canvasWidth) {
Q_UNUSED(page);
Q_UNUSED(canvasWidth);
return 0;
}
|