Qt 4.8
qcocoawindowsurface.mm
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 plugins 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 "qcocoawindowsurface.h"
43 
44 #include <QtCore/qdebug.h>
45 
46 #include <QtGui/QPainter>
47 
49 
50 QRect flipedRect(const QRect &sourceRect,int height)
51 {
52  if (!sourceRect.isValid())
53  return QRect();
54  QRect flippedRect = sourceRect;
55  flippedRect.moveTop(height - sourceRect.y());
56  return flippedRect;
57 }
58 
60  : QWindowSurface(window)
61 {
62  m_cocoaWindow = static_cast<QCocoaWindow *>(window->platformWindow());
63 
64  const QRect geo = window->geometry();
65  NSRect rect = NSMakeRect(geo.x(),geo.y(),geo.width(),geo.height());
66  m_contentView = [[QNSView alloc] initWithWidget:window];
67  m_cocoaWindow->setContentView(m_contentView);
68 
69  m_image = new QImage(window->size(),QImage::Format_ARGB32);
70 }
71 
73 {
74  delete m_image;
75 }
76 
78 {
79  return m_image;
80 }
81 
83 {
84  Q_UNUSED(widget);
85  Q_UNUSED(offset);
86 
87  QRect geo = region.boundingRect();
88 
89  NSRect rect = NSMakeRect(geo.x(), geo.y(), geo.width(), geo.height());
90  [m_contentView displayRect:rect];
91 }
92 
94 {
95  QWindowSurface::resize(size);
96  delete m_image;
98  NSSize newSize = NSMakeSize(size.width(),size.height());
99  [m_contentView setImage:m_image];
100 
101 }
102 
unsigned long WId
Definition: qwindowdefs.h:119
QPaintDevice * paintDevice()
Implement this function to return the appropriate paint device.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
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.
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
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
QRect flipedRect(const QRect &sourceRect, int height)
QCocoaWindow * m_cocoaWindow
The QWindowSurface class provides the drawing area for top-level windows.
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
void flush(QWidget *widget, const QRegion &region, const QPoint &offset)
Flushes the given region from the specified widget onto the screen.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QCocoaWindowSurface(QWidget *window, WId wid)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
#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
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
void setContentView(NSView *contentView)
void resize(const QSize &size)