~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/thirdparty/Qocoa/qocoa_mac.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

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