PageRenderTime 187ms CodeModel.GetById 90ms app.highlight 14ms RepoModel.GetById 77ms app.codeStats 0ms

/src/libtomahawk/thirdparty/Qocoa/qocoa_mac.h

http://github.com/tomahawk-player/tomahawk
C Header | 63 lines | 33 code | 9 blank | 21 comment | 1 complexity | dc13e8a7e4fee3d441ac500455ad5775 MD5 | raw file
 1/*
 2Copyright (C) 2011 by Mike McQuaid
 3
 4Permission is hereby granted, free of charge, to any person obtaining a copy
 5of this software and associated documentation files (the "Software"), to deal
 6in the Software without restriction, including without limitation the rights
 7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 8copies of the Software, and to permit persons to whom the Software is
 9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22
23#ifndef QCOCOA_MAC_H
24#define QCOCOA_MAC_H
25
26#import <Cocoa/Cocoa.h>
27#include <AppKit/NSImage.h>
28#include <QString>
29#include <QVBoxLayout>
30#include <QMacCocoaViewContainer>
31
32#include <qmacfunctions.h>
33
34static inline NSString* fromQString(const QString &string)
35{
36    const QByteArray utf8 = string.toUtf8();
37    const char* cString = utf8.constData();
38    return [[[NSString alloc] initWithUTF8String:cString] autorelease];
39}
40
41static inline QString toQString(NSString *string)
42{
43    if (!string)
44        return QString();
45    return QString::fromUtf8([string UTF8String]);
46}
47
48static inline NSImage* fromQPixmap(const QPixmap &pixmap)
49{
50    CGImageRef cgImage = QtMac::toCGImageRef(pixmap);
51
52    return [[[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize] autorelease];
53}
54
55static inline void setupLayout(NSView *cocoaView, QWidget *parent)
56{
57    parent->setAttribute(Qt::WA_NativeWindow);
58    QVBoxLayout *layout = new QVBoxLayout(parent);
59    layout->setMargin(0);
60    layout->addWidget(new QMacCocoaViewContainer(cocoaView, parent));
61}
62
63#endif