Qt 4.8
qwindowsurface.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <private/qwindowsurface_p.h>
43 #include <qwidget.h>
44 #include <private/qwidget_p.h>
45 #include <private/qbackingstore_p.h>
46 #include <private/qapplication_p.h>
47 
49 
51 {
52 public:
54  : window(w)
55  {
56  }
57 
59 #if !defined(Q_WS_QPA)
61 #else
62  QSize size;
63 #endif //Q_WS_QPA
66 };
67 
127  : d_ptr(new QWindowSurfacePrivate(window))
128 {
130  if(setDefaultSurface && window)
131  window->setWindowSurface(this);
132  }
133 }
134 
139 {
140  if (d_ptr->window)
141  d_ptr->window->d_func()->extra->topextra->windowSurface = 0;
142  delete d_ptr;
143 }
144 
150 {
151  return d_ptr->window;
152 }
153 
155 {
156 }
157 
159 {
160 // QApplication::syncX();
163 }
164 
165 #if !defined(Q_WS_QPA)
166 
175 {
176  d_ptr->geometry = rect;
177 }
178 
183 {
184  return d_ptr->geometry;
185 }
186 #else
187 
193 void QWindowSurface::resize(const QSize &size)
194 {
195  d_ptr->size = size;
196 }
197 
201 QSize QWindowSurface::size() const
202 {
203  return d_ptr->size;
204 }
205 #endif //Q_WS_QPA
206 
213 bool QWindowSurface::scroll(const QRegion &area, int dx, int dy)
214 {
215  Q_UNUSED(area);
216  Q_UNUSED(dx);
217  Q_UNUSED(dy);
218 
219  return false;
220 }
221 
230 {
231  if (widget->window() != window())
232  return 0;
233 
234  QPaintDevice *pdev = paintDevice();
235  if (!pdev || pdev->devType() != QInternal::Image)
236  return 0;
237 
238  const QPoint off = offset(widget);
239  QImage *img = static_cast<QImage*>(pdev);
240 
241  QRect rect(off, widget->size());
242  rect &= QRect(QPoint(), img->size());
243 
244  if (rect.isEmpty())
245  return 0;
246 
247  img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8,
248  rect.width(), rect.height(),
249  img->bytesPerLine(), img->format());
250  d_ptr->bufferImages.append(img);
251 
252  return img;
253 }
254 
269 QPixmap QWindowSurface::grabWidget(const QWidget *widget, const QRect &rectangle) const
270 {
271  QPixmap result;
272 
273  if (widget->window() != window())
274  return result;
275 
276  const QImage *img = const_cast<QWindowSurface *>(this)->buffer(widget->window());
277 
278  if (!img || img->isNull())
279  return result;
280 
281  QRect rect = rectangle.isEmpty() ? widget->rect() : (widget->rect() & rectangle);
282 
283  rect.translate(offset(widget) - offset(widget->window()));
284  rect &= QRect(QPoint(), img->size());
285 
286  if (rect.isEmpty())
287  return result;
288 
289  QImage subimg(img->scanLine(rect.y()) + rect.x() * img->depth() / 8,
290  rect.width(), rect.height(),
291  img->bytesPerLine(), img->format());
292  subimg.detach(); //### expensive -- maybe we should have a real SubImage that shares reference count
293 
294  result = QPixmap::fromImage(subimg);
295  return result;
296 }
297 
303 {
305  QPoint offset = widget->mapTo(window, QPoint());
306 #ifdef Q_WS_QWS
307  offset += window->geometry().topLeft() - window->frameGeometry().topLeft();
308 #endif
309  return offset;
310 }
311 
320 {
321  d_ptr->staticContents = region;
322 }
323 
325 {
326  return d_ptr->staticContents;
327 }
328 
330 {
332 }
333 
334 QWindowSurface::WindowSurfaceFeatures QWindowSurface::features() const
335 {
337 }
338 
339 #ifdef Q_WS_QPA
340 #define Q_EXPORT_SCROLLRECT Q_GUI_EXPORT
341 #else
342 #define Q_EXPORT_SCROLLRECT
343 #endif
344 
346 {
347  // make sure we don't detach
348  uchar *mem = const_cast<uchar*>(const_cast<const QImage &>(img).bits());
349 
350  int lineskip = img.bytesPerLine();
351  int depth = img.depth() >> 3;
352 
353  const QRect imageRect(0, 0, img.width(), img.height());
354  const QRect r = rect & imageRect & imageRect.translated(-offset);
355  const QPoint p = rect.topLeft() + offset;
356 
357  if (r.isEmpty())
358  return;
359 
360  const uchar *src;
361  uchar *dest;
362 
363  if (r.top() < p.y()) {
364  src = mem + r.bottom() * lineskip + r.left() * depth;
365  dest = mem + (p.y() + r.height() - 1) * lineskip + p.x() * depth;
366  lineskip = -lineskip;
367  } else {
368  src = mem + r.top() * lineskip + r.left() * depth;
369  dest = mem + p.y() * lineskip + p.x() * depth;
370  }
371 
372  const int w = r.width();
373  int h = r.height();
374  const int bytes = w * depth;
375 
376  // overlapping segments?
377  if (offset.y() == 0 && qAbs(offset.x()) < w) {
378  do {
379  ::memmove(dest, src, bytes);
380  dest += lineskip;
381  src += lineskip;
382  } while (--h);
383  } else {
384  do {
385  ::memcpy(dest, src, bytes);
386  dest += lineskip;
387  src += lineskip;
388  } while (--h);
389  }
390 }
391 
QRect geometry() const
Returns the currently allocated area on the screen.
void setWindowSurface(QWindowSurface *surface)
Sets the window surface to be the surface specified.
Definition: qwidget.cpp:12774
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
void Q_EXPORT_SCROLLRECT qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect frameGeometry
geometry of the widget relative to its parent including any window frame
Definition: qwidget.h:159
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
virtual QPoint offset(const QWidget *widget) const
Returns the offset of widget in the coordinates of this window surface.
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
virtual WindowSurfaceFeatures features() const
virtual int devType() const
Definition: qpaintdevice.h:167
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
virtual void beginPaint(const QRegion &)
This function is called before painting onto the surface begins, with the region in which the paintin...
virtual QPixmap grabWidget(const QWidget *widget, const QRect &rectangle=QRect()) const
Returns a QPixmap generated from the part of the backing store corresponding to widget.
unsigned char uchar
Definition: qglobal.h:994
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool hasStaticContents() const
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QWindowSurface * windowSurface() const
Returns the QWindowSurface this widget will be drawn into.
Definition: qwidget.cpp:12819
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
void clear()
Removes all items from the list.
Definition: qlist.h:764
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
static bool runtime_graphics_system
QWindowSurfacePrivate(QWidget *w)
The QWindowSurface class provides the drawing area for top-level windows.
QRegion staticContents() const
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
void setStaticContents(const QRegion &region)
QWindowSurface(QWidget *window, bool setDefaultSurface=true)
Constructs an empty surface for the given top-level window.
virtual void endPaint(const QRegion &)
This function is called after painting onto the surface has ended, with the region in which the paint...
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
#define Q_EXPORT_SCROLLRECT
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual QImage * buffer(const QWidget *widget)
Returns a QImage pointer which represents the actual buffer the widget is drawn into or 0 if this is ...
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
bool hasFeature(WindowSurfaceFeature feature) const
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QList< QImage * > bufferImages
virtual ~QWindowSurface()
Destroys this surface.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QWindowSurfacePrivate * d_ptr
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
virtual bool scroll(const QRegion &area, int dx, int dy)
Scrolls the given area dx pixels to the right and dy downward; both dx and dy may be negative...
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
virtual QPaintDevice * paintDevice()=0
Implement this function to return the appropriate paint device.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int area(const QSize &s)
Definition: qicon.cpp:155
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288