-
Notifications
You must be signed in to change notification settings - Fork 2
/
qcocoawidget.mm
43 lines (32 loc) · 996 Bytes
/
qcocoawidget.mm
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
#include "qcocoawidget.h"
#import "Foundation/Foundation.h"
#import "AppKit/NSView.h"
#import "AppKit/NSControl.h"
QCocoaWidget::QCocoaWidget(QWidget *parent) :
QWidget(parent), view(0)
{
}
void QCocoaWidget::setupLayout(NSView *cocoaView)
{
view = cocoaView;
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
QWidget *nativeWidget = QWidget::createWindowContainer(QWindow::fromWinId((WId)cocoaView), this);
nativeWidget->setAttribute(Qt::WA_NativeWindow, true);
layout->addWidget(nativeWidget);
}
QWidget *QCocoaWidget::nativeWidget() const
{
QVBoxLayout *v = static_cast<QVBoxLayout *>(layout());
return static_cast<QWidget *>(v->itemAt(0) ? v->itemAt(0)->widget() : nullptr);
}
void QCocoaWidget::changeEvent(QEvent *event)
{
if ([view isKindOfClass:[NSControl class]])
[(NSControl *)view setEnabled: isEnabled() ? YES: NO];
else
{
// TODO ?
}
QWidget::changeEvent(event);
}