Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Port Qocoa to Qt5
Browse files Browse the repository at this point in the history
Makes Qocoa compile against Qt 5, tested with
Qt 5.2.0 and OS X 10.9. It requires QtMacExtras for
QtMac::toCGImageRef(). CMake changes are excluded.
  • Loading branch information
frankosterfeld committed Jan 10, 2014
1 parent 0f5ee25 commit f7f5a07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main.cpp
@@ -1,4 +1,5 @@
#include <QtGui/QApplication>
#include <QApplication>

#include "gallery.h"

int main(int argc, char *argv[])
Expand Down
11 changes: 10 additions & 1 deletion qocoa_mac.h
Expand Up @@ -20,11 +20,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include <AppKit/NSImage.h>
#include <Foundation/NSString.h>
#include <QString>
#include <QVBoxLayout>
#include <QMacCocoaViewContainer>

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
#include <qmacfunctions.h>
#endif

static inline NSString* fromQString(const QString &string)
{
const QByteArray utf8 = string.toUtf8();
Expand All @@ -41,11 +46,15 @@ static inline QString toQString(NSString *string)

static inline NSImage* fromQPixmap(const QPixmap &pixmap)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
CGImageRef cgImage = pixmap.toMacCGImageRef();
#else
CGImageRef cgImage = QtMac::toCGImageRef(pixmap);
#endif
return [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
}

static inline void setupLayout(void *cocoaView, QWidget *parent)
static inline void setupLayout(NSView *cocoaView, QWidget *parent)
{
parent->setAttribute(Qt::WA_NativeWindow);
QVBoxLayout *layout = new QVBoxLayout(parent);
Expand Down
5 changes: 5 additions & 0 deletions qsearchfield_mac.mm
Expand Up @@ -156,7 +156,12 @@ -(BOOL)performKeyEquivalent:(NSEvent*)event {
if (!pimpl)
return;

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
NSMenu *nsMenu = menu->macMenu();
#else
NSMenu *nsMenu = menu->toNSMenu();
#endif

[[pimpl->nsSearchField cell] setSearchMenuTemplate:nsMenu];
}

Expand Down

0 comments on commit f7f5a07

Please sign in to comment.