/usr/include/okular/core/area.h is in okular-dev 4:4.13.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 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 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 | /***************************************************************************
* 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. *
***************************************************************************/
#ifndef _OKULAR_AREA_H_
#define _OKULAR_AREA_H_
#include <QtCore/QList>
#include <QtGui/QColor>
#include <QtGui/QPainterPath>
#include <QtGui/QTransform>
#include <kdebug.h>
#include <math.h>
#include "global.h"
#include "okular_export.h"
class QPolygonF;
class QRect;
namespace Okular {
class Annotation;
class Action;
class NormalizedShape;
/**
* 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.
*/
class OKULAR_EXPORT NormalizedPoint
{
public:
/**
* Creates a new empty normalized point.
*/
NormalizedPoint();
/**
* 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 );
/**
* @internal
*/
NormalizedPoint& operator=( const NormalizedPoint& );
/**
* Transforms the normalized point with the operations defined by @p matrix.
*/
void transform( const QTransform &matrix );
/**
* Returns squared distance to point @p x @p y @p xScale @p yScale
* @since 0.17 (KDE 4.11)
*/
double distanceSqr( double x, double y, double xScale, double yScale ) const;
/**
* @brief Calculates distance of the point @p x @p y @p xScale @p yScale to the line segment from @p start to @p end
* @since 0.17 (KDE 4.11)
*/
static double distanceSqr( double x, double y, double xScale, double yScale, const NormalizedPoint& start, const NormalizedPoint& end );
/**
* The normalized x coordinate.
*/
double x;
/**
* The normalized y coordinate.
*/
double y;
};
/**
* NormalizedRect is a helper class which stores the coordinates
* of a normalized rect, which is a rectangle of @see NormalizedPoints.
*/
class OKULAR_EXPORT NormalizedRect
{
public:
/**
* Creates a null normalized rectangle.
* @see isNull()
*/
NormalizedRect();
/**
* 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 );
/**
* @internal
*/
NormalizedRect( const NormalizedRect& );
/**
* @internal
*/
NormalizedRect& operator=( const NormalizedRect &other );
/**
* Build a normalized rect from a QRectF.
*/
static NormalizedRect fromQRectF( const QRectF &rect );
/**
* Returns whether this normalized rectangle is a null normalized rect.
*/
bool isNull() const;
/**
* Returns whether the normalized rectangle contains the normalized coordinates
* @p x and @p y.
*/
bool contains( double x, double y ) const;
/**
* 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.
*/
QRect geometry( int xScale, int yScale ) const;
/**
* Same functionality as geometry, but the output is now rounded before typecasting to int
* @since 0.14 (KDE 4.8)
*/
QRect roundedGeometry( int xScale, int yScale ) const;
/**
* 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 );
/**
* 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;
/**
* Returns whether the normalized rectangle is equal to the @p other
* normalized rectangle.
*/
bool operator==( const NormalizedRect &other ) const;
/**
* Returns the center of the rectangle
* @since 0.10 (KDE 4.4)
*/
NormalizedPoint center() const;
/**
* Transforms the normalized rectangle with the operations defined by @p matrix.
*/
void transform( const QTransform &matrix );
/**
* Returns true if the point pt is located to the bottom of the rectangle
* @since 0.14 (KDE 4.8)
*/
bool isBottom(const NormalizedPoint& pt) const
{
return bottom < pt.y;
}
/**
* Returns true if the point pt is located on the top of the rectangle
* @since 0.14 (KDE 4.8)
*/
bool isTop(const NormalizedPoint& pt) const
{
return top > pt.y;
}
/**
* Returns true if the point pt is located under the top of the rectangle
* @since 0.14 (KDE 4.8)
*/
bool isBottomOrLevel(const NormalizedPoint& pt) const
{
return top < pt.y;
}
/**
* Returns true if the point pt is located above the bottom of the rectangle
* @since 0.14 (KDE 4.8)
*/
bool isTopOrLevel(const NormalizedPoint& pt) const
{
return bottom > pt.y;
}
/**
* Returns true if the point pt is located to the right of the left arm of rectangle
* @since 0.14 (KDE 4.8)
*/
bool isLeft(const NormalizedPoint& pt) const
{
return left < pt.x;
}
/**
* Returns true if the point pt is located to the left of the right arm of rectangle
* @since 0.14 (KDE 4.8)
*/
bool isRight(const NormalizedPoint& pt) const
{
return right > pt.x;
}
/**
* Returns the distance of the point @p x @p y @p xScale @p yScale to the closest
* edge or 0 if the point is within the rectangle
* @since 0.17 (KDE 4.11)
*/
double distanceSqr(double x, double y, double xScale, double yScale) const
{
double distX = 0;
if ( x < left )
distX = left - x;
else if ( x > right )
distX = x - right;
double distY = 0;
if ( top > y )
distY = top - y;
else if (bottom < y)
distY = y - bottom;
return pow( distX * xScale, 2 ) + pow( distY * yScale, 2 );
}
/**
* The normalized left coordinate.
*/
double left;
/**
* The normalized top coordinate.
*/
double top;
/**
* The normalized right coordinate.
*/
double right;
/**
* The normalized bottom coordinate.
*/
double bottom;
};
KDE_DUMMY_QHASH_FUNCTION(NormalizedRect)
/**
* @short NormalizedRect that contains a reference to an object.
*
* These rects contains a pointer to a okular object (such as an action or something
* 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:
* - Action : class Action: description of an action
* - Image : class Image : description of an image (n/a)
* - Annotation: class Annotation: description of an annotation
*/
class OKULAR_EXPORT ObjectRect
{
public:
/**
* Describes the type of storable object.
*/
enum ObjectType
{
Action, ///< An action
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 );
/**
* Destroys the object rectangle.
*/
virtual ~ObjectRect();
/**
* 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.
*/
const QPainterPath ®ion() const;
/**
* Returns the bounding rect of the object rectangle for the
* scaling factor @p xScale and @p yScale.
*/
virtual QRect boundingRect( double xScale, double yScale ) const;
/**
* 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.
*/
virtual void transform( const QTransform &matrix );
/**
* 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;
protected:
ObjectType m_objectType;
void * m_object;
QPainterPath m_path;
QPainterPath m_transformedPath;
};
/**
* This class describes the object rectangle for an annotation.
*/
class OKULAR_EXPORT AnnotationObjectRect : public ObjectRect
{
public:
/**
* Creates a new annotation object rectangle with the
* given @p annotation.
*/
AnnotationObjectRect( Annotation *annotation );
/**
* Destroys the annotation object rectangle.
*/
virtual ~AnnotationObjectRect();
/**
* 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.
*/
virtual QRect boundingRect( double xScale, double yScale ) const;
/**
* Returns whether the annotation 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 annotation object rectangle with the operations defined by @p matrix.
*/
virtual void transform( const QTransform &matrix );
private:
Annotation * m_annotation;
};
/**
* This class describes the object rectangle for a source reference.
*/
class OKULAR_EXPORT SourceRefObjectRect : public ObjectRect
{
friend class ObjectRect;
public:
/**
* 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 );
/**
* Returns the bounding rect of the source reference object rectangle for the
* scaling factor @p xScale and @p yScale.
*/
virtual QRect boundingRect( double xScale, double yScale ) const;
/**
* Returns whether the source reference 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;
private:
NormalizedPoint m_point;
};
/// @cond PRIVATE
/** @internal */
template <typename T>
void doDelete( T& t )
{
(void)t;
}
/** @internal */
template <typename T>
T* givePtr( T& t )
{
return &t;
}
/** @internal */
template <typename T>
T& deref( T& t )
{
return t;
}
/** @internal */
template <typename T>
static void doDelete( T* t )
{
delete t;
}
/** @internal */
template <typename T>
static T* givePtr( T* t )
{
return t;
}
/** @internal */
template <typename T>
static T& deref( T* t )
{
return *t;
}
/// @endcond
/**
* @short A regular area of NormalizedShape which normalizes a Shape
*
* 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
*/
template <class NormalizedShape, class Shape> class RegularArea : public QList<NormalizedShape>
{
public:
/**
* Destroys a regular area.
*/
~RegularArea();
/**
* Returns whether the regular area contains the
* normalized point @p x, @p y.
*/
bool contains( double x, double y ) const;
/**
* Returns whether the regular area contains the
* given @p shape.
*/
bool contains( const NormalizedShape& shape ) const;
/**
* Returns whether the regular area intersects with the given @p area.
*/
bool intersects( const RegularArea<NormalizedShape,Shape> *area ) const;
/**
* Returns whether the regular area intersects with the given @p shape.
*/
bool intersects( const NormalizedShape& shape ) const;
/**
* Appends the given @p area to the regular area.
*/
void appendArea( const RegularArea<NormalizedShape,Shape> *area );
/**
* Appends the given @p shape to the regular area.
*/
void appendShape( const NormalizedShape& shape, MergeSide side = MergeAll );
/**
* Simplifies the regular area by merging its intersecting subareas.
*/
void simplify();
/**
* Returns whether the regular area is a null area.
*/
bool isNull() const;
/**
* 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.
*/
void transform( const QTransform &matrix );
};
template <class NormalizedShape, class Shape>
RegularArea<NormalizedShape, Shape>::~RegularArea()
{
int size = this->count();
for ( int i = 0; i < size; ++i )
doDelete( (*this)[i] );
}
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::simplify()
{
#ifdef DEBUG_REGULARAREA
int prev_end = this->count();
#endif
int end = this->count() - 1, x = 0;
for ( int i = 0; i < end; ++i )
{
if ( givePtr( (*this)[x] )->intersects( deref( (*this)[i+1] ) ) )
{
deref((*this)[x]) |= deref((*this)[i+1]);
NormalizedShape& tobedeleted = (*this)[i+1];
this->removeAt( i + 1 );
doDelete( tobedeleted );
--end;
--i;
}
else
{
x=i+1;
}
}
#ifdef DEBUG_REGULARAREA
kDebug() << "from" << prev_end << "to" << this->count();
#endif
}
template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::isNull() const
{
if ( !this )
return false;
if ( this->isEmpty() )
return false;
typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
for ( ; it != itEnd; ++it )
if ( !givePtr( *it )->isNull() )
return false;
return true;
}
template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::intersects( const NormalizedShape& rect ) const
{
if ( !this )
return false;
if ( this->isEmpty() )
return false;
typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
for ( ; it != itEnd; ++it )
if ( !givePtr( *it )->isNull() && givePtr( *it )->intersects( rect ) )
return true;
return false;
}
template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::intersects( const RegularArea<NormalizedShape,Shape> *area ) const
{
if ( !this )
return false;
if ( this->isEmpty() )
return false;
typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
for ( ; it != itEnd; ++it )
{
typename QList<NormalizedShape>::const_iterator areaIt = area->begin(), areaItEnd = area->end();
for ( ; areaIt != areaItEnd; ++areaIt )
{
if ( !( *it ).isNull() && ( *it ).intersects( *areaIt ) )
return true;
}
}
return false;
}
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::appendArea( const RegularArea<NormalizedShape, Shape> *area )
{
if ( !this )
return;
typename QList<NormalizedShape>::const_iterator areaIt = area->begin(), areaItEnd = area->end();
for ( ; areaIt != areaItEnd; ++areaIt )
this->append( *areaIt );
}
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::appendShape( const NormalizedShape& shape, MergeSide side )
{
if ( !this )
return;
int size = this->count();
// if the list is empty, adds the shape normally
if ( size == 0 )
{
this->append( shape );
}
else
{
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
// if the new shape intersects with the last shape in the list, then
// merge it with that and delete the shape
if ( intersection )
{
deref((*this)[size - 1]) |= deref( shape );
doDelete( const_cast<NormalizedShape&>( shape ) );
}
else
this->append( shape );
}
}
template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::contains( double x, double y ) const
{
if ( !this )
return false;
if ( this->isEmpty() )
return false;
typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
for ( ; it != itEnd; ++it )
if ( ( *it ).contains( x, y ) )
return true;
return false;
}
template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::contains( const NormalizedShape& shape ) const
{
if ( !this )
return false;
if ( this->isEmpty() )
return false;
return QList<NormalizedShape>::contains( shape );
}
template <class NormalizedShape, class Shape>
QList<Shape> RegularArea<NormalizedShape, Shape>::geometry( int xScale, int yScale, int dx, int dy ) const
{
if ( !this || this->isEmpty() )
return QList<Shape>();
QList<Shape> ret;
Shape t;
typename QList<NormalizedShape>::const_iterator it = this->begin(), itEnd = this->end();
for ( ; it != itEnd; ++it )
{
t = givePtr( *it )->geometry( xScale, yScale );
t.translate( dx, dy );
ret.append( t );
}
return ret;
}
template <class NormalizedShape, class Shape>
void RegularArea<NormalizedShape, Shape>::transform( const QTransform &matrix )
{
if ( !this )
return;
if ( this->isEmpty() )
return;
for ( int i = 0; i < this->count(); ++i )
givePtr( (*this)[i] )->transform( matrix );
}
class OKULAR_EXPORT RegularAreaRect : public RegularArea< NormalizedRect, QRect >
{
public:
RegularAreaRect();
RegularAreaRect( const RegularAreaRect& rar );
~RegularAreaRect();
RegularAreaRect& operator=( const RegularAreaRect& rar );
private:
class Private;
Private * const d;
};
/**
* This class stores the coordinates of a highlighting area
* together with the id of the highlight owner and the color.
*/
class HighlightAreaRect : public RegularAreaRect
{
public:
/**
* Creates a new highlight area rect with the coordinates of
* the given @p area.
*/
HighlightAreaRect( const RegularAreaRect *area = 0 );
/**
* The search ID of the highlight owner.
*/
int s_id;
/**
* The color of the highlight.
*/
QColor color;
};
}
#ifndef QT_NO_DEBUG_STREAM
/**
* Debug operator for normalized @p point.
*/
OKULAR_EXPORT QDebug operator<<( QDebug str, const Okular::NormalizedPoint &point );
/**
* Debug operator for normalized @p rect.
*/
OKULAR_EXPORT QDebug operator<<( QDebug str, const Okular::NormalizedRect &rect );
#endif
#endif
|