Qt 4.8
Public Functions | Protected Variables | List of all members
QNSView Class Reference

#import <qnsview.h>

Inheritance diagram for QNSView:

Public Functions

(void) - drawRect:
 
(void) - handleMouseEvent:
 
(id) - init
 
(id) - initWithWidget:
 
(BOOL) - isFlipped
 
(void) - mouseDown:
 
(void) - mouseDragged:
 
(void) - mouseEntered:
 
(void) - mouseExited:
 
(void) - mouseMoved:
 
(void) - mouseUp:
 
(void) - otherMouseDown:
 
(void) - otherMouseDragged:
 
(void) - otherMouseUp:
 
(void) - rightMouseDown:
 
(void) - rightMouseDragged:
 
(void) - rightMouseUp:
 
(void) - setImage:
 

Protected Variables

Qt::MouseButtons m_buttons
 
CGImageRef m_cgImage
 
QWidgetm_widget
 

Detailed Description

Definition at line 49 of file qnsview.h.

Functions

◆ drawRect:()

- (void) drawRect: (NSRect)  dirtyRect

Definition at line 104 of file qnsview.mm.

104  :(NSRect)dirtyRect
105 {
106  if (!m_cgImage)
107  return;
108 
109  CGRect dirtyCGRect = NSRectToCGRect(dirtyRect);
110 
111  NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext currentContext];
112  CGContextRef cgContext = (CGContextRef) [nsGraphicsContext graphicsPort];
113 
114  CGContextSaveGState( cgContext );
115  int dy = dirtyCGRect.origin.y + CGRectGetMaxY(dirtyCGRect);
116  CGContextTranslateCTM(cgContext, 0, dy);
117  CGContextScaleCTM(cgContext, 1, -1);
118 
119  CGImageRef subImage = CGImageCreateWithImageInRect(m_cgImage, dirtyCGRect);
120  CGContextDrawImage(cgContext,dirtyCGRect,subImage);
121 
122  CGContextRestoreGState(cgContext);
123 
124  CGImageRelease(subImage);
125 
126 }
struct CGImage * CGImageRef
CGImageRef m_cgImage
Definition: qnsview.h:50
struct CGRect CGRect
struct CGContext * CGContextRef

◆ handleMouseEvent:()

- (void) handleMouseEvent: (NSEvent *)  theEvent

Definition at line 133 of file qnsview.mm.

133  :(NSEvent *)theEvent;
134 {
135  NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil];
136  QPoint qt_localPoint(point.x,point.y);
137 
138  NSTimeInterval timestamp = [theEvent timestamp];
139  ulong qt_timestamp = timestamp * 1000;
140 
142 
143 }
static void handleMouseEvent(QWidget *w, const QPoint &local, const QPoint &global, Qt::MouseButtons b)
tlw == 0 means that ev is in global coords only
unsigned long ulong
Definition: qglobal.h:997
Qt::MouseButtons m_buttons
Definition: qnsview.h:52
struct CGPoint NSPoint
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QWidget * m_widget
Definition: qnsview.h:51

◆ init()

- (id) init

Definition at line 50 of file qnsview.mm.

Referenced by initWithWidget:.

51 {
52  self = [super init];
53  if (self) {
54  m_cgImage = 0;
55  m_widget = 0;
57  }
58  return self;
59 }
CGImageRef m_cgImage
Definition: qnsview.h:50
Qt::MouseButtons m_buttons
Definition: qnsview.h:52
QWidget * m_widget
Definition: qnsview.h:51

◆ initWithWidget:()

- (id) initWithWidget: (QWidget *)  widget

Definition at line 61 of file qnsview.mm.

61  :(QWidget *)widget {
62  self = [self init];
63  if (self) {
64  m_widget = widget;
65  }
66  return self;
67 }
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QWidget * m_widget
Definition: qnsview.h:51

◆ isFlipped()

- (BOOL) isFlipped

Definition at line 128 of file qnsview.mm.

129 {
130  return YES;
131 }

◆ mouseDown:()

- (void) mouseDown: (NSEvent *)  theEvent

Definition at line 144 of file qnsview.mm.

144  :(NSEvent *)theEvent
145  {
147  [self handleMouseEvent:theEvent];
148  }
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ mouseDragged:()

- (void) mouseDragged: (NSEvent *)  theEvent

Definition at line 149 of file qnsview.mm.

149  :(NSEvent *)theEvent
150  {
151  if (!(m_buttons & Qt::LeftButton))
152  qWarning("Internal Mousebutton tracking invalid(missing Qt::LeftButton");
153  [self handleMouseEvent:theEvent];
154  }
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ mouseEntered:()

- (void) mouseEntered: (NSEvent *)  theEvent

Definition at line 166 of file qnsview.mm.

166  :(NSEvent *)theEvent
167 {
168  Q_UNUSED(theEvent);
170 }
static void handleEnterEvent(QWidget *w)
#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
QWidget * m_widget
Definition: qnsview.h:51

◆ mouseExited:()

- (void) mouseExited: (NSEvent *)  theEvent

Definition at line 171 of file qnsview.mm.

171  :(NSEvent *)theEvent
172 {
173  Q_UNUSED(theEvent);
175 }
#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
static void handleLeaveEvent(QWidget *w)
QWidget * m_widget
Definition: qnsview.h:51

◆ mouseMoved:()

- (void) mouseMoved: (NSEvent *)  theEvent

Definition at line 161 of file qnsview.mm.

161  :(NSEvent *)theEvent
162 {
163  qDebug() << "mouseMove";
164  [self handleMouseEvent:theEvent];
165 }
Q_CORE_EXPORT void qDebug(const char *,...)

◆ mouseUp:()

- (void) mouseUp: (NSEvent *)  theEvent

Definition at line 155 of file qnsview.mm.

155  :(NSEvent *)theEvent
156  {
157  m_buttons &= QFlag(~int(Qt::LeftButton));
158  [self handleMouseEvent:theEvent];
159  }
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ otherMouseDown:()

- (void) otherMouseDown: (NSEvent *)  theEvent

Definition at line 192 of file qnsview.mm.

192  :(NSEvent *)theEvent
193 {
195  [self handleMouseEvent:theEvent];
196 }
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ otherMouseDragged:()

- (void) otherMouseDragged: (NSEvent *)  theEvent

Definition at line 197 of file qnsview.mm.

197  :(NSEvent *)theEvent
198 {
199  if (!(m_buttons & Qt::LeftButton))
200  qWarning("Internal Mousebutton tracking invalid(missing Qt::LeftButton");
201  [self handleMouseEvent:theEvent];
202 }
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ otherMouseUp:()

- (void) otherMouseUp: (NSEvent *)  theEvent

Definition at line 203 of file qnsview.mm.

203  :(NSEvent *)theEvent
204 {
205  m_buttons &= QFlag(~int(Qt::MiddleButton));
206  [self handleMouseEvent:theEvent];
207 }
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ rightMouseDown:()

- (void) rightMouseDown: (NSEvent *)  theEvent

Definition at line 176 of file qnsview.mm.

176  :(NSEvent *)theEvent
177 {
179  [self handleMouseEvent:theEvent];
180 }
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ rightMouseDragged:()

- (void) rightMouseDragged: (NSEvent *)  theEvent

Definition at line 181 of file qnsview.mm.

181  :(NSEvent *)theEvent
182 {
183  if (!(m_buttons & Qt::LeftButton))
184  qWarning("Internal Mousebutton tracking invalid(missing Qt::LeftButton");
185  [self handleMouseEvent:theEvent];
186 }
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ rightMouseUp:()

- (void) rightMouseUp: (NSEvent *)  theEvent

Definition at line 187 of file qnsview.mm.

187  :(NSEvent *)theEvent
188 {
189  m_buttons &= QFlag(~int(Qt::RightButton));
190  [self handleMouseEvent:theEvent];
191 }
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
Qt::MouseButtons m_buttons
Definition: qnsview.h:52

◆ setImage:()

- (void) setImage: (QImage *)  image

Definition at line 69 of file qnsview.mm.

69  :(QImage *)image
70 {
71  CGImageRelease(m_cgImage);
72 
73  const uchar *imageData = image->bits();
74  int bitDepth = image->depth();
75  int colorBufferSize = 8;
76  int bytesPrLine = image->bytesPerLine();
77  int width = image->width();
78  int height = image->height();
79 
80  CGColorSpaceRef cgColourSpaceRef = CGColorSpaceCreateDeviceRGB();
81 
82  CGDataProviderRef cgDataProviderRef = CGDataProviderCreateWithData(
83  NULL,
84  imageData,
85  image->byteCount(),
86  NULL);
87 
88  m_cgImage = CGImageCreate(width,
89  height,
90  colorBufferSize,
91  bitDepth,
92  bytesPrLine,
93  cgColourSpaceRef,
94  kCGImageAlphaNone,
95  cgDataProviderRef,
96  NULL,
97  false,
98  kCGRenderingIntentDefault);
99 
100  CGColorSpaceRelease(cgColourSpaceRef);
101 
102 }
int byteCount() const
Returns the number of bytes occupied by the image data.
Definition: qimage.cpp:1800
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
unsigned char uchar
Definition: qglobal.h:994
CGImageRef m_cgImage
Definition: qnsview.h:50
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
struct CGColorSpace * CGColorSpaceRef
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

Properties

◆ m_buttons

- (MouseButtons) QNSView:
protected

Definition at line 52 of file qnsview.h.

Referenced by init.

◆ m_cgImage

- (CGImageRef) m_cgImage
protected

Definition at line 50 of file qnsview.h.

Referenced by init.

◆ m_widget

- (QWidget*) m_widget
protected

Definition at line 51 of file qnsview.h.

Referenced by init, and initWithWidget:.


The documentation for this class was generated from the following files: