KHtml

imagepainter.cpp
1 /*
2  Progressive image displaying library.
3 
4  Copyright (C) 2004,2005 Maks Orlovich ([email protected])
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 
23 */
24 
25 #include "imagepainter.h"
26 #include "image.h"
27 #include "pixmapplane.h"
28 #include "imagemanager.h"
29 
30 namespace khtmlImLoad
31 {
32 
33 ImagePainter::ImagePainter(Image *_image): image(_image), sizeRefd(false)
34 {
35  //No need to ref, default size.
36  size = image->size();
37 }
38 
39 ImagePainter::ImagePainter(Image *_image, QSize _size): image(_image), size(_size), sizeRefd(false)
40 {
41  if (!ImageManager::isAcceptableScaleSize(_size.width(), _size.height())) {
43  }
44 }
45 
47 {
48  if (sizeRefd) {
49  image->derefSize(size);
50  }
51 }
52 
54 {
55  image = src.image;
56  size = src.size;
57  sizeRefd = false;
58 }
59 
60 ImagePainter &ImagePainter::operator=(const ImagePainter &src)
61 {
62  if (sizeRefd) {
63  image->derefSize(size);
64  }
65  image = src.image;
66  size = src.size;
67  sizeRefd = false;
68  return *this;
69 }
70 
72 {
73  if (!ImageManager::isAcceptableScaleSize(_size.width(), _size.height())) {
75  return;
76  }
77 
78  // Don't do anything if size didn't change,
79  // to avoid dropping the image..
80  if (size == _size) {
81  return;
82  }
83 
84  if (sizeRefd) {
85  image->derefSize(size);
86  }
87  size = _size;
88  sizeRefd = false;
89 }
90 
92 {
93  if (sizeRefd) {
94  image->derefSize(size);
95  }
96  size = image->size();
97  sizeRefd = false;
98 }
99 
100 void ImagePainter::paint(int dx, int dy, QPainter *p, int sx, int sy,
101  int width, int height)
102 {
103  if (!image->mayPaint())
104  // ### fallback painting in case bg?
105  {
106  return;
107  }
108 
109  // Do our lazy ref if needed. Safe due to above
110  if (!sizeRefd && size != image->size()) {
111  image->refSize(size);
112  sizeRefd = true;
113  }
114 
115  PixmapPlane *plane = image->getSize(size);
116 
117  if (plane->animProvider) {
118  // Clip the request ourselves when animating..
119 
120  if (width == -1) {
121  width = size.width();
122  }
123  if (height == -1) {
124  height = size.height();
125  }
126 
127  QRect clippedRect = QRect(0, 0, size.width(), size.height())
128  & QRect(sx, sy, width, height);
129  plane->animProvider->paint(dx, dy, p, clippedRect.x(), clippedRect.y(),
130  clippedRect.width(), clippedRect.height());
131  return;
132  }
133 
134  // non-animated, go straight to PixmapPlane; it clips itself
135  plane->paint(dx, dy, p, sx, sy, width, height);
136 }
137 
138 }
139 
An image represents a static picture or an animation, that may be incrementally loaded.
Definition: image.h:51
int width() const const
A pixmap plane is responsible for drawing data of an image plane.
Definition: pixmapplane.h:41
QSize size() const
Returns the image's size.
Definition: image.cpp:353
int height() const const
int x() const const
int y() const const
An image painter let's one paint an image at the given size.
Definition: imagepainter.h:40
void paint(int dx, int dy, QPainter *p, int sx=0, int sy=0, int width=-1, int height=-1)
Paints a portion of the image frame on the painter 'p' at dx and dy.
ImagePainter(Image *image)
Creates an image painter for the given image...
void setDefaultSize()
Sets the image to the default size.
void paint(int dx, int dy, QPainter *p, int sx, int sy, int width=-1, int height=-1)
Paints a portion of the frame on the painter 'p' at dx and dy.
Definition: pixmapplane.cpp:32
void setSize(QSize size)
Sets the size of the image.
int width() const const
int height() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Oct 24 2021 22:48:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.