area.h 25.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
/***************************************************************************
 *   Copyright (C) 2004-05 by Enrico Ros <eros.kde@email.it>               *
 *   Copyright (C) 2005 by Piotr Szymanski <niedakh@gmail.com>             *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

10
11
12
13
14
15
#ifndef _OKULAR_AREA_H_
#define _OKULAR_AREA_H_

#include <QtCore/QList>
#include <QtGui/QColor>
#include <QtGui/QPainterPath>
16
#include <kdebug.h>
17

18
19
#include "global.h"
#include "okular_export.h"
20

Pino Toscano's avatar
Pino Toscano committed
21
class QPolygonF;
22
23
class QRect;

24
25
26
namespace Okular {

class Annotation;
Pino Toscano's avatar
Pino Toscano committed
27
class Action;
28
29
class NormalizedShape;

30
/**
31
32
33
34
35
36
37
38
39
40
41
42
43
 * NormalizedPoint is a helper class which stores the coordinates
 * of a normalized point. Normalized means that the coordinates are
 * between 0 and 1 so that it is page size independent.
 *
 * Example:
 *    The normalized point is (0.5, 0.3)
 *
 *    If you want to draw it on a 800x600 page, just multiply the x coordinate (0.5) with
 *    the page width (800) and the y coordinate (0.3) with the page height (600), so
 *    the point will be drawn on the page at (400, 180).
 *
 *    That allows you to zoom the page by just multiplying the normalized points with the
 *    zoomed page size.
44
 */
45
class OKULAR_EXPORT NormalizedPoint
46
47
{
    public:
48
49
50
        /**
         * Creates a new empty normalized point.
         */
51
        NormalizedPoint();
52

53
54
55
56
57
58
59
60
61
62
63
        /**
         * Creates a new normalized point with the normalized coordinates (@p x, @p y ).
         */
        NormalizedPoint( double x, double y );

        /**
         * Creates a new normalized point with the coordinates (@p x, @p y) which are normalized
         * by the scaling factors @p xScale and @p yScale.
         */
        NormalizedPoint( int x, int y, int xScale, int yScale );

64
65
66
        /**
         * @internal
         */
67
68
69
70
71
        NormalizedPoint& operator=( const NormalizedPoint& );

        /**
         * Transforms the normalized point with the operations defined by @p matrix.
         */
72
        void transform( const QMatrix &matrix );
73
74
75
76
77
78
79
80
81
82

        /**
         * The normalized x coordinate.
         */
        double x;

        /**
         * The normalized y coordinate.
         */
        double y;
83
84
85
};

/**
86
87
 * NormalizedRect is a helper class which stores the coordinates
 * of a normalized rect, which is a rectangle of @see NormalizedPoints.
88
 */
89
class OKULAR_EXPORT NormalizedRect
90
91
{
    public:
92
93
94
95
        /**
         * Creates a null normalized rectangle.
         * @see isNull()
         */
96
        NormalizedRect();
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

        /**
         * Creates a normalized rectangle with the normalized coordinates
         * @p left, @p top, @p right, @p bottom.
         *
         * If you need the x, y, width and height coordinates use the
         * following formulas:
         *
         * @li x = left
         * @li y = top
         * @li width = right - left
         * @li height = bottom - top
         */
        NormalizedRect( double left, double top, double right, double bottom );

        /**
         * Creates a normalized rectangle of the given @p rectangle which is normalized
         * by the scaling factors @p xScale and @p yScale.
         */
        NormalizedRect( const QRect &rectangle, double xScale, double yScale );

118
119
120
        /**
         * @internal
         */
121
        NormalizedRect( const NormalizedRect& );
122
123
124
125

        /**
         * @internal
         */
126
127
        NormalizedRect& operator=( const NormalizedRect &other );

Pino Toscano's avatar
Pino Toscano committed
128
129
130
131
132
        /**
         * Build a normalized rect from a QRectF.
         */
        static NormalizedRect fromQRectF( const QRectF &rect );

133
134
135
        /**
         * Returns whether this normalized rectangle is a null normalized rect.
         */
136
        bool isNull() const;
137
138
139
140
141

        /**
         * Returns whether the normalized rectangle contains the normalized coordinates
         * @p x and @p y.
         */
142
        bool contains( double x, double y ) const;
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

        /**
         * Returns whether the normalized rectangle intersects the @p other normalized
         * rectangle.
         */
        bool intersects( const NormalizedRect &other ) const;

        /**
         * This is an overloaded member function, provided for convenience. It behaves essentially
         * like the above function.
         */
        bool intersects( const NormalizedRect *other ) const;

        /**
         * Returns whether the normalized rectangle intersects an other normalized
         * rectangle, which is defined by @p left, @p top, @p right and @p bottom.
         */
        bool intersects( double left, double top, double right, double bottom ) const;

        /**
         * Returns the rectangle that accrues when the normalized rectangle is multiplyed
         * with the scaling @p xScale and @p yScale.
         */
166
        QRect geometry( int xScale, int yScale ) const;
167

168
        /**
169
         * Same functionality as geometry, but the output is now rounded before typecasting to int
Albert Astals Cid's avatar
Albert Astals Cid committed
170
         * @since 0.14 (KDE 4.8)
171
         */
172
173
        QRect roundedGeometry( int xScale, int yScale ) const;

174
175
176
177
178
179
180
181
182
183
184
185
        /**
         * Returns the normalized bounding rectangle of the normalized rectangle
         * combined with the @p other normalized rectangle.
         */
        NormalizedRect operator|( const NormalizedRect &other ) const;

        /**
         * Sets the normalized rectangle to the normalized bounding rectangle
         * of itself combined with the @p other normalized rectangle.
         */
        NormalizedRect& operator|=( const NormalizedRect &other );

186
187
188
189
190
191
192
193
        /**
         * Returns the intersection of this normalized rectangle with the specified
         * @p other. If the rects do not intersect then the result is null.
         *
         * @since 0.7 (KDE 4.1)
         */
        NormalizedRect operator&( const NormalizedRect &other ) const;

194
195
196
197
198
199
        /**
         * Returns whether the normalized rectangle is equal to the @p other
         * normalized rectangle.
         */
        bool operator==( const NormalizedRect &other ) const;

200
201
202
203
204
205
        /**
         * Returns the center of the rectangle
         * @since 0.10 (KDE 4.4)
         */
        NormalizedPoint center() const;

206
207
208
        /**
         * Transforms the normalized rectangle with the operations defined by @p matrix.
         */
209
        void transform( const QMatrix &matrix );
210

211
        /**
212
         * Returns true if the point pt is located to the bottom of the rectangle
Albert Astals Cid's avatar
Albert Astals Cid committed
213
         * @since 0.14 (KDE 4.8)
214
         */
215
        bool isBottom(const NormalizedPoint& pt) const
216
        {
217
218
219
            return bottom < pt.y;
        }

220
221
        /**
         * Returns true if the point pt is located on the top of the rectangle
Albert Astals Cid's avatar
Albert Astals Cid committed
222
         * @since 0.14 (KDE 4.8)
223
         */
224
        bool isTop(const NormalizedPoint& pt) const
225
        {
226
227
228
            return top > pt.y;
        }

229
230
        /**
         * Returns true if the point pt is located under the top of the rectangle
Albert Astals Cid's avatar
Albert Astals Cid committed
231
         * @since 0.14 (KDE 4.8)
232
         */
233
        bool isBottomOrLevel(const NormalizedPoint& pt) const
234
        {
235
236
237
            return top < pt.y;
        }

238
239
        /**
         * Returns true if the point pt is located above the bottom of the rectangle
Albert Astals Cid's avatar
Albert Astals Cid committed
240
         * @since 0.14 (KDE 4.8)
241
         */
242
        bool isTopOrLevel(const NormalizedPoint& pt) const
243
        {
244
245
246
            return bottom > pt.y;
        }

247
248
        /**
         * Returns true if the point pt is located to the right of the left arm of rectangle
Albert Astals Cid's avatar
Albert Astals Cid committed
249
         * @since 0.14 (KDE 4.8)
250
         */
251
        bool isLeft(const NormalizedPoint& pt) const
252
        {
253
            return left < pt.x;
254
255
        }

256
257
        /**
         * Returns true if the point pt is located to the left of the right arm of rectangle
Albert Astals Cid's avatar
Albert Astals Cid committed
258
         * @since 0.14 (KDE 4.8)
259
         */
260
        bool isRight(const NormalizedPoint& pt) const
261
        {
262
            return right > pt.x;
263
264
        }

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
        /**
         * The normalized left coordinate.
         */
        double left;

        /**
         * The normalized top coordinate.
         */
        double top;

        /**
         * The normalized right coordinate.
         */
        double right;

        /**
         * The normalized bottom coordinate.
         */
        double bottom;
};
Christian Ehrlicher's avatar
Christian Ehrlicher committed
285
KDE_DUMMY_QHASH_FUNCTION(NormalizedRect)
286
287
288
289

/**
 * @short NormalizedRect that contains a reference to an object.
 *
Pino Toscano's avatar
Pino Toscano committed
290
 * These rects contains a pointer to a okular object (such as an action or something
291
292
293
294
295
 * like that). The pointer is read and stored as 'void pointer' so cast is
 * performed by accessors based on the value returned by objectType(). Objects
 * are reparented to this class.
 *
 * Type / Class correspondency tab:
Pino Toscano's avatar
Pino Toscano committed
296
 *  - Action    : class Action: description of an action
297
 *  - Image     : class Image : description of an image (n/a)
298
 *  - Annotation: class Annotation: description of an annotation
299
 */
300
class OKULAR_EXPORT ObjectRect
301
302
{
    public:
303
304
305
306
307
        /**
         * Describes the type of storable object.
         */
        enum ObjectType
        {
Pino Toscano's avatar
Pino Toscano committed
308
            Action,      ///< An action
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
            Image,       ///< An image
            OAnnotation, ///< An annotation
            SourceRef    ///< A source reference
        };

        /**
         * Creates a new object rectangle.
         *
         * @param left The left coordinate of the rectangle.
         * @param top The top coordinate of the rectangle.
         * @param right The right coordinate of the rectangle.
         * @param bottom The bottom coordinate of the rectangle.
         * @param ellipse If true the rectangle describes an ellipse.
         * @param type The type of the storable object @see ObjectType.
         * @param object The pointer to the storable object.
         */
        ObjectRect( double left, double top, double right, double bottom, bool ellipse, ObjectType type, void *object );

        /**
         * This is an overloaded member function, provided for convenience.
         */
        ObjectRect( const NormalizedRect &rect, bool ellipse, ObjectType type, void *object );

        /**
         * This is an overloaded member function, provided for convenience.
         */
        ObjectRect( const QPolygonF &poly, ObjectType type, void *object );
336

337
338
339
        /**
         * Destroys the object rectangle.
         */
340
        virtual ~ObjectRect();
341

342
343
344
345
346
347
348
349
350
351
352
353
354
355
        /**
         * Returns the object type of the object rectangle.
         * @see ObjectType
         */
        ObjectType objectType() const;

        /**
         * Returns the storable object of the object rectangle.
         */
        const void *object() const;

        /**
         * Returns the region that is covered by the object rectangle.
         */
356
        const QPainterPath &region() const;
357
358
359
360
361

        /**
         * Returns the bounding rect of the object rectangle for the
         * scaling factor @p xScale and @p yScale.
         */
362
        virtual QRect boundingRect( double xScale, double yScale ) const;
363
364
365
366
367
368
369
370
371
372

        /**
         * Returns whether the object rectangle contains the point @p x, @p y for the
         * scaling factor @p xScale and @p yScale.
         */
        virtual bool contains( double x, double y, double xScale, double yScale ) const;

        /**
         * Transforms the object rectangle with the operations defined by @p matrix.
         */
373
        virtual void transform( const QMatrix &matrix );
374

375
376
377
378
379
380
381
382
383
        /**
         * Returns the square of the distance between the object and the point @p x, @p y
         * for the scaling factor @p xScale and @p yScale.
         *
         * @since 0.8.2 (KDE 4.2.2)
         */
        // FIXME this should most probably be a virtual method
        double distanceSqr( double x, double y, double xScale, double yScale ) const;

384
    protected:
385
        ObjectType m_objectType;
386
        void * m_object;
387
        QPainterPath m_path;
388
        QPainterPath m_transformedPath;
389
390
};

391
392
393
/**
 * This class describes the object rectangle for an annotation.
 */
394
395
396
class OKULAR_EXPORT AnnotationObjectRect : public ObjectRect
{
    public:
397
398
399
400
401
402
403
404
405
        /**
         * Creates a new annotation object rectangle with the
         * given @p annotation.
         */
        AnnotationObjectRect( Annotation *annotation );

        /**
         * Destroys the annotation object rectangle.
         */
406
407
        virtual ~AnnotationObjectRect();

408
409
410
411
412
413
414
415
416
        /**
         * Returns the annotation object of the annotation object rectangle.
         */
        Annotation *annotation() const;

        /**
         * Returns the bounding rect of the annotation object rectangle for the
         * scaling factor @p xScale and @p yScale.
         */
417
        virtual QRect boundingRect( double xScale, double yScale ) const;
418
419
420
421
422

        /**
         * Returns whether the annotation object rectangle contains the point @p x, @p y for the
         * scaling factor @p xScale and @p yScale.
         */
423
        virtual bool contains( double x, double y, double xScale, double yScale ) const;
424
425
426
427

        /**
         * Transforms the annotation object rectangle with the operations defined by @p matrix.
         */
428
        virtual void transform( const QMatrix &matrix );
429
430

    private:
431
        Annotation * m_annotation;
432
433
};

434
435
436
/**
 * This class describes the object rectangle for a source reference.
 */
437
438
class OKULAR_EXPORT SourceRefObjectRect : public ObjectRect
{
439
440
    friend class ObjectRect;

441
    public:
442
443
444
445
446
447
448
        /**
         * Creates a new source reference object rectangle.
         *
         * @param point The point of the source reference.
         * @param reference The storable source reference object.
         */
        SourceRefObjectRect( const NormalizedPoint& point, void *reference );
449

450
451
452
453
        /**
         * Returns the bounding rect of the source reference object rectangle for the
         * scaling factor @p xScale and @p yScale.
         */
454
        virtual QRect boundingRect( double xScale, double yScale ) const;
455
456
457
458
459

        /**
         * Returns whether the source reference object rectangle contains the point @p x, @p y for the
         * scaling factor @p xScale and @p yScale.
         */
460
461
462
463
464
465
        virtual bool contains( double x, double y, double xScale, double yScale ) const;

    private:
        NormalizedPoint m_point;
};

466
/// @cond PRIVATE
467
468
/** @internal */
template <typename T>
469
void doDelete( T& t )
470
{
471
472
    (void)t;
}
473
474
475

/** @internal */
template <typename T>
476
T* givePtr( T& t )
477
{
478
479
    return &t;
}
480

481
482
483
484
485
486
/** @internal */
template <typename T>
T& deref( T& t )
{
    return t;
}
487

488
489
490
491
492
493
/** @internal */
template <typename T>
static void doDelete( T* t )
{
    delete t;
}
494

495
496
497
498
499
500
/** @internal */
template <typename T>
static T* givePtr( T* t )
{
    return t;
}
501

502
503
504
505
506
507
/** @internal */
template <typename T>
static T& deref( T* t )
{
    return *t;
}
508
/// @endcond
509

510
511
/**
 * @short A regular area of NormalizedShape which normalizes a Shape
Pino Toscano's avatar
Pino Toscano committed
512
513
514
515
516
517
518
 *
 * Class NormalizedShape \b must have the following functions/operators defined:
 * - bool contains( double, double )
 * - bool intersects( NormalizedShape )
 * - bool isNull()
 * - Shape geometry( int, int )
 * - operator|=( NormalizedShape ) which unite two NormalizedShape's
519
 */
520
template <class NormalizedShape, class Shape> class RegularArea : public  QList<NormalizedShape>
521
{
522
    public:
523
524
525
        /**
         * Destroys a regular area.
         */
526
        ~RegularArea();
527
528
529
530
531

        /**
         * Returns whether the regular area contains the
         * normalized point @p x, @p y.
         */
532
        bool contains( double x, double y ) const;
533
534
535
536
537

        /**
         * Returns whether the regular area contains the
         * given @p shape.
         */
538
        bool contains( const NormalizedShape& shape ) const;
539
540
541
542

        /**
         * Returns whether the regular area intersects with the given @p area.
         */
543
        bool intersects( const RegularArea<NormalizedShape,Shape> *area ) const;
544
545
546
547

        /**
         * Returns whether the regular area intersects with the given @p shape.
         */
548
        bool intersects( const NormalizedShape& shape ) const;
549
550
551
552

        /**
         * Appends the given @p area to the regular area.
         */
553
        void appendArea( const RegularArea<NormalizedShape,Shape> *area );
554
555
556
557

        /**
         * Appends the given @p shape to the regular area.
         */
558
        void appendShape( const NormalizedShape& shape, MergeSide side = MergeAll );
559
560
561
562

        /**
         * Simplifies the regular area by merging its intersecting subareas.
         */
563
        void simplify();
564
565
566
567

        /**
         * Returns whether the regular area is a null area.
         */
568
        bool isNull() const;
569
570
571
572
573
574
575
576
577
578

        /**
         * Returns the subareas of the regular areas as shapes for the given scaling factor
         * @p xScale and @p yScale, translated by @p dx and @p dy.
         */
        QList<Shape> geometry( int xScale, int yScale, int dx = 0, int dy = 0 ) const;

        /**
         * Transforms the regular area with the operations defined by @p matrix.
         */
579
        void transform( const QMatrix &matrix );
580
581
};

582
template <class NormalizedShape, class Shape>
Christian Ehrlicher's avatar
Christian Ehrlicher committed
583
RegularArea<NormalizedShape, Shape>::~RegularArea()
584
585
586
{
    int size = this->count();
    for ( int i = 0; i < size; ++i )
587
        doDelete( (*this)[i] );
588
589
}

590
591
592
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::simplify()
{
593
594
595
596
597
#ifdef DEBUG_REGULARAREA
            int prev_end = this->count();
#endif
            int end = this->count() - 1, x = 0;
            for ( int i = 0; i < end; ++i )
598
            {
599
                    if ( givePtr( (*this)[x] )->intersects( deref( (*this)[i+1] ) ) )
600
                    {
601
                        deref((*this)[x]) |= deref((*this)[i+1]);
602
                        NormalizedShape& tobedeleted = (*this)[i+1];
603
                        this->removeAt( i + 1 );
604
                        doDelete( tobedeleted );
605
606
                        --end;
                        --i;
607
608
609
610
611
612
                    }
                    else
                    {
                        x=i+1;
                   }
            }
Pino Toscano's avatar
Pino Toscano committed
613
#ifdef DEBUG_REGULARAREA
614
    kDebug() << "from" << prev_end << "to" << this->count();
Pino Toscano's avatar
Pino Toscano committed
615
#endif
616
617
}

618
619
620
template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::isNull() const
{
621
622
    if ( !this )
        return false;
623

624
625
    if ( this->isEmpty() )
        return false;
626

627
628
629
    typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
    for ( ; it != itEnd; ++it )
        if ( !givePtr( *it )->isNull() )
630
            return false;
631

632
    return true;
633
634
635
}

template <class NormalizedShape, class Shape>
636
bool RegularArea<NormalizedShape, Shape>::intersects( const NormalizedShape& rect ) const
637
{
638
639
640
641
642
643
    if ( !this )
        return false;

    if ( this->isEmpty() )
        return false;

644
645
646
    typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
    for ( ; it != itEnd; ++it )
        if ( !givePtr( *it )->isNull() && givePtr( *it )->intersects( rect ) )
647
648
649
            return true;

    return false;
650
651
652
}

template <class NormalizedShape, class Shape>
653
bool RegularArea<NormalizedShape, Shape>::intersects( const RegularArea<NormalizedShape,Shape> *area ) const
654
{
655
656
657
658
659
660
    if ( !this )
        return false;

    if ( this->isEmpty() )
        return false;

661
662
    typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
    for ( ; it != itEnd; ++it )
663
    {
664
665
        typename QList<NormalizedShape>::const_iterator areaIt = area->begin(), areaItEnd = area->end();
        for ( ; areaIt != areaItEnd; ++areaIt )
666
        {
Christian Ehrlicher's avatar
Christian Ehrlicher committed
667
            if ( !( *it ).isNull() && ( *it ).intersects( *areaIt ) )
668
669
670
671
672
                return true;
        }
    }

    return false;
673
674
675
}

template <class NormalizedShape, class Shape>
676
void RegularArea<NormalizedShape, Shape>::appendArea( const RegularArea<NormalizedShape, Shape> *area )
677
{
678
    if ( !this )
679
        return;
680

681
682
683
    typename QList<NormalizedShape>::const_iterator areaIt = area->begin(), areaItEnd = area->end();
    for ( ; areaIt != areaItEnd; ++areaIt )
        this->append( *areaIt );
684
685
686
}


687
template <class NormalizedShape, class Shape>
688
void RegularArea<NormalizedShape, Shape>::appendShape( const NormalizedShape& shape, MergeSide side )
689
690
691
692
693
694
695
696
697
698
699
700
{
    if ( !this )
        return;

    int size = this->count();
    // if the list is empty, adds the shape normally
    if ( size == 0 )
    {
        this->append( shape );
    }
    else
    {
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
        bool intersection = false;
        NormalizedShape& last = (*this)[size - 1];
#define O_LAST givePtr( last )
#  define O_LAST_R O_LAST->right
#  define O_LAST_L O_LAST->left
#  define O_LAST_T O_LAST->top
#  define O_LAST_B O_LAST->bottom
#define O_NEW givePtr( shape )
#  define O_NEW_R O_NEW->right
#  define O_NEW_L O_NEW->left
#  define O_NEW_T O_NEW->top
#  define O_NEW_B O_NEW->bottom
        switch ( side )
        {
            case MergeRight:
                intersection = ( O_LAST_R >= O_NEW_L ) && ( O_LAST_L <= O_NEW_R )
                               && ( ( O_LAST_T <= O_NEW_T && O_LAST_B >= O_NEW_B )
                                  || ( O_LAST_T >= O_NEW_T && O_LAST_B <= O_NEW_B ) );
                break;
            case MergeBottom:
                intersection = ( O_LAST_B >= O_NEW_T ) && ( O_LAST_T <= O_NEW_B )
                               && ( ( O_LAST_R <= O_NEW_R && O_LAST_L >= O_NEW_L )
                                  || ( O_LAST_R >= O_NEW_R && O_LAST_L <= O_NEW_L ) );
                break;
            case MergeLeft:
                intersection = ( O_LAST_L <= O_NEW_R ) && ( O_LAST_R >= O_NEW_L )
                               && ( ( O_LAST_T <= O_NEW_T && O_LAST_B >= O_NEW_B )
                                  || ( O_LAST_T >= O_NEW_T && O_LAST_B <= O_NEW_B ) );
                break;
            case MergeTop:
                intersection = ( O_LAST_T <= O_NEW_B ) && ( O_LAST_B >= O_NEW_T )
                               && ( ( O_LAST_R <= O_NEW_R && O_LAST_L >= O_NEW_L )
                                  || ( O_LAST_R >= O_NEW_R && O_LAST_L <= O_NEW_L ) );
                break;
            case MergeAll:
                intersection = O_LAST->intersects( shape );
                break;
        }
#undef O_LAST
#  undef O_LAST_R
#  undef O_LAST_L
#  undef O_LAST_T
#  undef O_LAST_B
#undef O_NEW
#  undef O_NEW_R
#  undef O_NEW_L
#  undef O_NEW_T
#  undef O_NEW_B
749
750
        // if the new shape intersects with the last shape in the list, then
        // merge it with that and delete the shape
751
        if ( intersection )
752
        {
753
754
            deref((*this)[size - 1]) |= deref( shape );
            doDelete( const_cast<NormalizedShape&>( shape ) );
755
756
757
758
759
760
761
        }
        else
            this->append( shape );
    }
}


762
template <class NormalizedShape, class Shape>
763
bool RegularArea<NormalizedShape, Shape>::contains( double x, double y ) const
764
{
765
766
767
768
769
770
    if ( !this )
        return false;

    if ( this->isEmpty() )
        return false;

771
772
    typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
    for ( ; it != itEnd; ++it )
Christian Ehrlicher's avatar
Christian Ehrlicher committed
773
        if ( ( *it ).contains( x, y ) )
774
775
776
            return true;

    return false;
777
778
}

779
template <class NormalizedShape, class Shape>
780
bool RegularArea<NormalizedShape, Shape>::contains( const NormalizedShape& shape ) const
781
{
782
783
    if ( !this )
        return false;
784

785
786
787
    if ( this->isEmpty() )
        return false;

Pino Toscano's avatar
Pino Toscano committed
788
    return QList<NormalizedShape>::contains( shape );
789
790
}

791
template <class NormalizedShape, class Shape>
792
QList<Shape> RegularArea<NormalizedShape, Shape>::geometry( int xScale, int yScale, int dx, int dy ) const
793
{
794
795
    if ( !this || this->isEmpty() )
        return QList<Shape>();
796

797
    QList<Shape> ret;
798
    Shape t;
799
800
    typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
    for ( ; it != itEnd; ++it )
801
    {
802
        t = givePtr( *it )->geometry( xScale, yScale );
803
        t.translate( dx, dy );
804
        ret.append( t );
805
806
807
    }

    return ret;
808
809
}

810
811
812
813
814
815
816
817
818
819
820
821
822
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::transform( const QMatrix &matrix )
{
    if ( !this )
        return;

    if ( this->isEmpty() )
        return;

    for ( int i = 0; i < this->count(); ++i )
        givePtr( (*this)[i] )->transform( matrix );
}

823
class OKULAR_EXPORT RegularAreaRect : public RegularArea< NormalizedRect, QRect >
824
825
826
827
828
829
830
831
832
833
834
835
{
    public:
        RegularAreaRect();
        RegularAreaRect( const RegularAreaRect& rar );
        ~RegularAreaRect();

        RegularAreaRect& operator=( const RegularAreaRect& rar );

    private:
        class Private;
        Private * const d;
};
836

837
838
839
840
/**
 * This class stores the coordinates of a highlighting area
 * together with the id of the highlight owner and the color.
 */
841
842
843
class HighlightAreaRect : public RegularAreaRect
{
    public:
844
845
846
847
        /**
         * Creates a new highlight area rect with the coordinates of
         * the given @p area.
         */
848
        HighlightAreaRect( const RegularAreaRect *area = 0 );
849

850
851
852
        /**
         * The search ID of the highlight owner.
         */
853
        int s_id;
854
855
856
857

        /**
         * The color of the highlight.
         */
858
        QColor color;
859
860
};

861
862
}

863
#ifndef QT_NO_DEBUG_STREAM
864
865
866
/**
 * Debug operator for normalized @p point.
 */
867
OKULAR_EXPORT QDebug operator<<( QDebug str, const Okular::NormalizedPoint &point );
868
869
870
871

/**
 * Debug operator for normalized @p rect.
 */
872
873
OKULAR_EXPORT QDebug operator<<( QDebug str, const Okular::NormalizedRect &rect );
#endif
874

875
#endif