Index: ObjQt.pro ================================================================== --- ObjQt.pro +++ ObjQt.pro @@ -7,34 +7,36 @@ INCLUDEPATH += common \ QtCore \ QtGui \ QtWidgets -HEADERS += common/helpers.h \ - common/OFString+QString.h \ - common/QtOwnershipManaging.h \ - QtCore/QtChildEvent.h \ - QtCore/QtCoreApplication.h \ - QtCore/QtEvent.h \ - QtCore/QtObject.h \ - QtCore/QtThread.h \ - QtGui/QtGuiApplication.h \ - QtGui/QtPaintDevice.h \ - QtWidgets/QtAction.h \ - QtWidgets/QtApplication.h \ +HEADERS += common/helpers.h \ + common/OFDataArray+QByteArray.h \ + common/OFString+QString.h \ + common/QtOwnershipManaging.h \ + QtCore/QtChildEvent.h \ + QtCore/QtCoreApplication.h \ + QtCore/QtEvent.h \ + QtCore/QtObject.h \ + QtCore/QtThread.h \ + QtGui/QtGUIApplication.h \ + QtGui/QtPaintDevice.h \ + QtWidgets/QtAction.h \ + QtWidgets/QtApplication.h \ QtWidgets/QtWidget.h -SOURCES += common/OFString+QString.mm \ - QtCore/QtChildEvent.mm \ - QtCore/QtCoreApplication.mm \ - QtCore/QtEvent.mm \ - QtCore/QtObject.mm \ - QtCore/QtThread.mm \ - QtGui/QtGuiApplication.mm \ - QtGui/QtPaintDevice.mm \ - QtWidgets/QtAction.mm \ - QtWidgets/QtApplication.mm \ +SOURCES += common/OFDataArray+QByteArray.mm \ + common/OFString+QString.mm \ + QtCore/QtChildEvent.mm \ + QtCore/QtCoreApplication.mm \ + QtCore/QtEvent.mm \ + QtCore/QtObject.mm \ + QtCore/QtThread.mm \ + QtGui/QtGUIApplication.mm \ + QtGui/QtPaintDevice.mm \ + QtWidgets/QtAction.mm \ + QtWidgets/QtApplication.mm \ QtWidgets/QtWidget.mm OBJCFLAGS += $$system("objfw-config --cppflags --objcflags --cxxflags") OBJCFLAGS_WARN_ON = -Wall \ -Werror \ Index: QtCore/QtChildEvent.h ================================================================== --- QtCore/QtChildEvent.h +++ QtCore/QtChildEvent.h @@ -33,5 +33,22 @@ - initWithQChildEvent: (QChildEvent*)qChildEvent; - initWithType: (QChildEvent::Type)type child: (QtObject*)child; @end + +namespace ObjQt { + +static OF_INLINE QtChildEvent* +toOF(QChildEvent *qChildEvent) +{ + return [[[QtChildEvent alloc] + initWithQChildEvent: qChildEvent] autorelease]; +} + +static OF_INLINE QChildEvent* +toQt(QtChildEvent *childEvent) +{ + return [childEvent qChildEvent]; +} + +} Index: QtCore/QtChildEvent.mm ================================================================== --- QtCore/QtChildEvent.mm +++ QtCore/QtChildEvent.mm @@ -20,10 +20,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ #import "QtChildEvent.h" #import "QtObject.h" + +using ObjQt::toOF; +using ObjQt::toQt; @implementation QtChildEvent - initWithQEvent: (QEvent*)event { OF_INVALID_INIT_METHOD @@ -37,11 +40,11 @@ - initWithType: (QChildEvent::Type)type child: (QtObject*)child { try { self = [self initWithQChildEvent: - new QChildEvent(type, [child qObject])]; + new QChildEvent(type, toQt(child))]; [self takeOwnership]; return self; } catch (const std::bad_alloc &e) { @@ -56,24 +59,23 @@ return dynamic_cast(_qEvent); } - (bool)isAdded { - return [self qChildEvent]->added(); + return toQt(self)->added(); } - (QtObject*)child { - return [[[QtObject alloc] - initWithQObject: [self qChildEvent]->child()] autorelease]; + return toOF(toQt(self)->child()); } - (bool)isPolished { - return [self qChildEvent]->polished(); + return toQt(self)->polished(); } - (bool)isRemoved { - return [self qChildEvent]->removed(); + return toQt(self)->removed(); } @end Index: QtCore/QtCoreApplication.h ================================================================== --- QtCore/QtCoreApplication.h +++ QtCore/QtCoreApplication.h @@ -35,5 +35,22 @@ - (void)quit; - (void)removeNativeEventFilter: (QAbstractNativeEventFilter*)filterObject; - (bool)sendEvent: (QtEvent*)event receiver: (QtObject*)receiver; @end + +namespace ObjQt { + +static OF_INLINE QtCoreApplication* +toOF(QCoreApplication *qCoreApplication) +{ + return [[[QtCoreApplication alloc] + initWithQCoreApplication: qCoreApplication] autorelease]; +} + +static OF_INLINE QCoreApplication* +toQt(QtCoreApplication *coreApplication) +{ + return [coreApplication qCoreApplication]; +} + +} Index: QtCore/QtCoreApplication.mm ================================================================== --- QtCore/QtCoreApplication.mm +++ QtCore/QtCoreApplication.mm @@ -20,12 +20,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ #import "QtCoreApplication.h" #import "QtEvent.h" +#import "OFString+QString.h" -#import "helpers.h" +using ObjQt::toOF; +using ObjQt::toQt; @implementation QtCoreApplication - initWithQObject: (QObject*)qObject { OF_INVALID_INIT_METHOD @@ -41,77 +43,74 @@ return qobject_cast(_qObject); } - (OFString*)applicationName { - return toOF([self qCoreApplication]->applicationName()); + return toOF(toQt(self)->applicationName()); } - (void)setApplicationName: (OFString*)applicationName { - [self qCoreApplication]->setApplicationName(toQt(applicationName)); + toQt(self)->setApplicationName(toQt(applicationName)); } - (OFString*)applicationVersion { - return toOF([self qCoreApplication]->applicationVersion()); + return toOF(toQt(self)->applicationVersion()); } - (void)installNativeEventFilter: (QAbstractNativeEventFilter*)filterObject { - [self qCoreApplication]->installNativeEventFilter(filterObject); + toQt(self)->installNativeEventFilter(filterObject); } - (void)setApplicationVersion: (OFString*)applicationVersion { - [self qCoreApplication]->setApplicationVersion( - toQt(applicationVersion)); + toQt(self)->setApplicationVersion(toQt(applicationVersion)); } - (OFString*)organizationDomain { - return toOF([self qCoreApplication]->organizationDomain()); + return toOF(toQt(self)->organizationDomain()); } - (void)setOrganizationDomain: (OFString*)organizationDomain { - [self qCoreApplication]->setOrganizationDomain( - toQt(organizationDomain)); + toQt(self)->setOrganizationDomain(toQt(organizationDomain)); } - (OFString*)organizationName { - return toOF([self qCoreApplication]->organizationName()); + return toOF(toQt(self)->organizationName()); } - (void)setOrganizationName: (OFString*)organizationName { - [self qCoreApplication]->setOrganizationName(toQt(organizationName)); + toQt(self)->setOrganizationName(toQt(organizationName)); } - (void)quit { - [self qCoreApplication]->quit(); + toQt(self)->quit(); } - (bool)isQuitLockEnabled { - return [self qCoreApplication]->isQuitLockEnabled(); + return toQt(self)->isQuitLockEnabled(); } - (void)setQuitLockEnabled: (bool)quitLockEnabled { - [self qCoreApplication]->setQuitLockEnabled(quitLockEnabled); + toQt(self)->setQuitLockEnabled(quitLockEnabled); } - (void)removeNativeEventFilter: (QAbstractNativeEventFilter*)filterObject { - [self qCoreApplication]->removeNativeEventFilter(filterObject); + toQt(self)->removeNativeEventFilter(filterObject); } - (bool)sendEvent: (QtEvent*)event receiver: (QtObject*)receiver { - return [self qCoreApplication]->notify( - [receiver qObject], [event qEvent]); + return toQt(self)->notify(toQt(receiver), toQt(event)); } @end Index: QtCore/QtEvent.h ================================================================== --- QtCore/QtEvent.h +++ QtCore/QtEvent.h @@ -40,5 +40,21 @@ + (int)registerEventType: (int)hint; - initWithQEvent: (QEvent*)qEvent; - (void)accept; - (void)ignore; @end + +namespace ObjQt { + +static OF_INLINE QtEvent* +toOF(QEvent *qEvent) +{ + return [[[QtEvent alloc] initWithQEvent: qEvent] autorelease]; +} + +static OF_INLINE QEvent* +toQt(QtEvent *event) +{ + return [event qEvent]; +} + +} Index: QtCore/QtObject.h ================================================================== --- QtCore/QtObject.h +++ QtCore/QtObject.h @@ -78,5 +78,21 @@ - (int)startTimerWithInterval: (int)interval type: (Qt::TimerType)type; - (QtThread*)thread; - (void)deleteLater; @end + +namespace ObjQt { + +static OF_INLINE QtObject* +toOF(QObject *qObject) +{ + return [[[QtObject alloc] initWithQObject: qObject] autorelease]; +} + +static OF_INLINE QObject* +toQt(QtObject *object) +{ + return [object qObject]; +} + +} Index: QtCore/QtObject.mm ================================================================== --- QtCore/QtObject.mm +++ QtCore/QtObject.mm @@ -21,14 +21,17 @@ */ #import "QtObject.h" #import "QtEvent.h" #import "QtThread.h" - -#import "helpers.h" +#import "OFString+QString.h" +#import "OFDataArray+QByteArray.h" #include + +using ObjQt::toOF; +using ObjQt::toQt; @implementation QtObject @synthesize qObject = _qObject; - init @@ -86,12 +89,11 @@ OFMutableArray *children = [OFMutableArray arrayWithCapacity: qChildren.count()]; void *pool = objc_autoreleasePoolPush(); for (QObject *qChild: qChildren) - [children addObject: - [[[QtObject alloc] initWithQObject: qChild] autorelease]]; + [children addObject: toOF(qChild)]; [children makeImmutable]; objc_autoreleasePoolPop(pool); @@ -101,26 +103,26 @@ - (QMetaObject::Connection)connectSignal: (OFString*)signal sender: (QtObject*)sender method: (OFString*)method type: (Qt::ConnectionType)type { - return _qObject->connect([sender qObject], + return _qObject->connect(toQt(sender), [signal UTF8String], [method UTF8String], type); } - (bool)disconnectSignal: (OFString*)signal receiver: (QtObject*)receiver method: (OFString*)method { - return _qObject->disconnect([signal UTF8String], [receiver qObject], + return _qObject->disconnect([signal UTF8String], toQt(receiver), [method UTF8String]); } - (bool)disconnectAllSignalsForReceiver: (QtObject*)receiver method: (OFString*)method { - return _qObject->disconnect([receiver qObject], [method UTF8String]); + return _qObject->disconnect(toQt(receiver), [method UTF8String]); } - (void)dumpObjectInfo { _qObject->dumpObjectInfo(); @@ -131,49 +133,45 @@ _qObject->dumpObjectTree(); } - (OFArray OF_GENERIC(OFDataArray*)*)dynamicPropertyNames { - const QList &qDynamicPropertyNames = + const QList &dynamicPropertyNames = _qObject->dynamicPropertyNames(); - OFMutableArray *dynamicPropertyNames = - [OFMutableArray arrayWithCapacity: qDynamicPropertyNames.count()]; + OFMutableArray *ret = + [OFMutableArray arrayWithCapacity: dynamicPropertyNames.count()]; void *pool = objc_autoreleasePoolPush(); - for (const QByteArray &qDynamicPropertyName: qDynamicPropertyNames) { - OFDataArray *dynamicPropertyName = [OFDataArray dataArray]; - [dynamicPropertyName addItems: qDynamicPropertyName.data() - count: qDynamicPropertyName.count()]; - [dynamicPropertyNames addObject: dynamicPropertyName]; - } - - [dynamicPropertyNames makeImmutable]; + for (const QByteArray &dynamicPropertyName: dynamicPropertyNames) + [ret addObject: toOF(dynamicPropertyName)]; + + [ret makeImmutable]; objc_autoreleasePoolPop(pool); - return dynamicPropertyNames; + return ret; } - (bool)handleEvent: (QtEvent*)event { - return _qObject->event([event qEvent]); + return _qObject->event(toQt(event)); } - (bool)filterEvent: (QtEvent*)event forObject: (QtObject*)watched { - return _qObject->eventFilter([watched qObject], [event qEvent]); + return _qObject->eventFilter(toQt(watched), toQt(event)); } - (bool)inheritsClassWithName: (OFString*)className { return _qObject->inherits([className UTF8String]); } - (void)installEventFilter: (QtObject*)filterObj { - _qObject->installEventFilter([filterObj qObject]); + _qObject->installEventFilter(toQt(filterObj)); } - (bool)isWidgetType { return _qObject->isWidgetType(); @@ -194,32 +192,31 @@ return _qObject->metaObject(); } - (void)moveToThread: (QtThread*)targetThread { - _qObject->moveToThread([targetThread qThread]); + _qObject->moveToThread(toQt(targetThread)); } - (QtObject*)parent { - return [[[QtObject alloc] - initWithQObject: _qObject->parent()] autorelease]; + return toOF(_qObject->parent()); } - (void)setParent: (QtObject*)parent { - _qObject->setParent([parent qObject]); + _qObject->setParent(toQt(parent)); } - (QVariant)propertyForName: (OFString*)name { return _qObject->property([name UTF8String]); } - (void)removeEventFilter: (QtObject*)obj { - _qObject->removeEventFilter([obj qObject]); + _qObject->removeEventFilter(toQt(obj)); } - (bool)setProperty: (QVariant&)value forName: (OFString*)name { @@ -237,15 +234,14 @@ return _qObject->startTimer(interval, type); } - (QtThread*)thread { - return [[[QtThread alloc] - initWithQThread: _qObject->thread()] autorelease]; + return toOF(_qObject->thread()); } - (void)deleteLater { OF_ENSURE(!_ownsObject); _qObject->deleteLater(); } @end Index: QtCore/QtThread.h ================================================================== --- QtCore/QtThread.h +++ QtCore/QtThread.h @@ -40,5 +40,21 @@ - (bool)waitForMilliseconds: (unsigned long)time; - (void)quit; - (void)startWithPriority: (QThread::Priority)priority; - (void)terminate; @end + +namespace ObjQt { + +static OF_INLINE QtThread* +toOF(QThread *qThread) +{ + return [[[QtThread alloc] initWithQThread: qThread] autorelease]; +} + +static OF_INLINE QThread* +toQt(QtThread *thread) +{ + return [thread qThread]; +} + +} Index: QtCore/QtThread.mm ================================================================== --- QtCore/QtThread.mm +++ QtCore/QtThread.mm @@ -19,10 +19,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import "QtThread.h" + +using ObjQt::toQt; @implementation QtThread: QtObject - initWithQObject: (QObject*)qObject { OF_INVALID_INIT_METHOD @@ -38,83 +40,83 @@ return qobject_cast(_qObject); } - (QAbstractEventDispatcher*)eventDispatcher { - return [self qThread]->eventDispatcher(); + return toQt(self)->eventDispatcher(); } - (void)setEventDispatcher: (QAbstractEventDispatcher*)eventDispatcher { - [self qThread]->setEventDispatcher(eventDispatcher); + toQt(self)->setEventDispatcher(eventDispatcher); } - (void)exitWithReturnCode: (int)returnCode { - [self qThread]->exit(returnCode); + toQt(self)->exit(returnCode); } - (bool)isFinished { - return [self qThread]->isFinished(); + return toQt(self)->isFinished(); } - (bool)isInterruptionRequested { - return [self qThread]->isInterruptionRequested(); + return toQt(self)->isInterruptionRequested(); } - (bool)isRunning { - return [self qThread]->isRunning(); + return toQt(self)->isRunning(); } - (int)loopLevel { - return [self qThread]->loopLevel(); + return toQt(self)->loopLevel(); } - (QThread::Priority)priority { - return [self qThread]->priority(); + return toQt(self)->priority(); } - (void)setPriority: (QThread::Priority)priority { - [self qThread]->setPriority(priority); + toQt(self)->setPriority(priority); } - (void)requestInterruption { - [self qThread]->requestInterruption(); + toQt(self)->requestInterruption(); } - (unsigned int)stackSize { - return [self qThread]->stackSize(); + return toQt(self)->stackSize(); } - (void)setStackSize: (unsigned int)stackSize { - [self qThread]->setStackSize(stackSize); + toQt(self)->setStackSize(stackSize); } - (bool)waitForMilliseconds: (unsigned long)time { - return [self qThread]->wait(time); + return toQt(self)->wait(time); } - (void)quit { - [self qThread]->quit(); + toQt(self)->quit(); } - (void)startWithPriority: (QThread::Priority)priority { - [self qThread]->start(priority); + toQt(self)->start(priority); } - (void)terminate { - [self qThread]->terminate(); + toQt(self)->terminate(); } @end ADDED QtGui/QtGUIApplication.h Index: QtGui/QtGUIApplication.h ================================================================== --- QtGui/QtGUIApplication.h +++ QtGui/QtGUIApplication.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, Jonathan Schleifer + * + * https://heap.zone/git/objqt.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import "QtCoreApplication.h" + +#include + +@interface QtGUIApplication: QtCoreApplication +@property (readonly) QGuiApplication *qGuiApplication; +@property (copy) OFString *applicationDisplayName; +@property (copy) OFString *desktopFileName; +@property Qt::LayoutDirection layoutDirection; +@property (readonly, copy) OFString *platformName; +@property (readonly) QScreen *primaryScreen; +@property bool quitsOnLastWindowClosed; +@property QIcon windowIcon; + +- initWithQGuiApplication: (QGuiApplication*)qGuiApplication; +- (double)devicePixelRatio; +- (bool)isSavingSession; +- (bool)isSessionRestored; +- (OFString*)sessionID; +- (OFString*)sessionKey; +@end + +namespace ObjQt { + +static OF_INLINE QtGUIApplication* +toOF(QGuiApplication *qGuiApplication) +{ + return [[[QtGUIApplication alloc] + initWithQGuiApplication: qGuiApplication] autorelease]; +} + +static OF_INLINE QGuiApplication* +toQt(QtGUIApplication *GUIApplication) +{ + return [GUIApplication qGuiApplication]; +} + +} ADDED QtGui/QtGUIApplication.mm Index: QtGui/QtGUIApplication.mm ================================================================== --- QtGui/QtGUIApplication.mm +++ QtGui/QtGUIApplication.mm @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2017, Jonathan Schleifer + * + * https://heap.zone/git/objqt.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import "QtGUIApplication.h" +#import "OFString+QString.h" + +#include + +using ObjQt::toOF; +using ObjQt::toQt; + +@implementation QtGUIApplication +- initWithQCoreApplication: (QCoreApplication*)qCoreApplication +{ + OF_INVALID_INIT_METHOD +} + +- initWithQGuiApplication: (QGuiApplication*)qGuiApplication +{ + return [super initWithQCoreApplication: qGuiApplication]; +} + +- (QGuiApplication*)qGuiApplication +{ + return qobject_cast(_qObject); +} + +- (OFString*)applicationDisplayName +{ + return toOF(toQt(self)->applicationDisplayName()); +} + +- (void)setApplicationDisplayName: (OFString*)applicationDisplayName +{ + toQt(self)->setApplicationDisplayName(toQt(applicationDisplayName)); +} + +- (OFString*)desktopFileName +{ + return toOF(toQt(self)->desktopFileName()); +} + +- (void)setDesktopFileName: (OFString*)desktopFileName +{ + toQt(self)->setDesktopFileName(toQt(desktopFileName)); +} + +- (double)devicePixelRatio +{ + return toQt(self)->devicePixelRatio(); +} + +- (bool)isSavingSession +{ + return toQt(self)->isSavingSession(); +} + +- (bool)isSessionRestored +{ + return toQt(self)->isSessionRestored(); +} + +- (Qt::LayoutDirection)layoutDirection +{ + return toQt(self)->layoutDirection(); +} + +- (void)setLayoutDirection: (Qt::LayoutDirection)layoutDirection +{ + toQt(self)->setLayoutDirection(layoutDirection); +} + +- (OFString*)platformName +{ + return toOF(toQt(self)->platformName()); +} + +- (QScreen*)primaryScreen +{ + return toQt(self)->primaryScreen(); +} + +- (bool)quitsOnLastWindowClosed +{ + return toQt(self)->quitOnLastWindowClosed(); +} + +- (void)setQuitsOnLastWindowClosed: (bool)quitsOnLastWindowClosed +{ + toQt(self)->setQuitOnLastWindowClosed(quitsOnLastWindowClosed); +} + +- (OFString*)sessionID +{ + return toOF(toQt(self)->sessionId()); +} + +- (OFString*)sessionKey +{ + return toOF(toQt(self)->sessionKey()); +} + +- (QIcon)windowIcon +{ + return toQt(self)->windowIcon(); +} + +- (void)setWindowIcon: (QIcon)windowIcon +{ + toQt(self)->setWindowIcon(windowIcon); +} +@end DELETED QtGui/QtGuiApplication.h Index: QtGui/QtGuiApplication.h ================================================================== --- QtGui/QtGuiApplication.h +++ QtGui/QtGuiApplication.h @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017, Jonathan Schleifer - * - * https://heap.zone/git/objqt.git - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#import "QtCoreApplication.h" - -#include - -@interface QtGuiApplication: QtCoreApplication -@property (readonly) QGuiApplication *qGuiApplication; -@property (copy) OFString *applicationDisplayName; -@property (copy) OFString *desktopFileName; -@property Qt::LayoutDirection layoutDirection; -@property (readonly, copy) OFString *platformName; -@property (readonly) QScreen *primaryScreen; -@property bool quitOnLastWindowClosed; -@property QIcon windowIcon; - -- initWithQGuiApplication: (QGuiApplication*)qGuiApplication; -- (double)devicePixelRatio; -- (bool)isSavingSession; -- (bool)isSessionRestored; -- (OFString*)sessionID; -- (OFString*)sessionKey; -@end DELETED QtGui/QtGuiApplication.mm Index: QtGui/QtGuiApplication.mm ================================================================== --- QtGui/QtGuiApplication.mm +++ QtGui/QtGuiApplication.mm @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2017, Jonathan Schleifer - * - * https://heap.zone/git/objqt.git - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#import "QtGuiApplication.h" - -#import "helpers.h" - -#include - -@implementation QtGuiApplication -- initWithQCoreApplication: (QCoreApplication*)qCoreApplication -{ - OF_INVALID_INIT_METHOD -} - -- initWithQGuiApplication: (QGuiApplication*)qGuiApplication -{ - return [super initWithQCoreApplication: qGuiApplication]; -} - -- (QGuiApplication*)qGuiApplication -{ - return qobject_cast(_qObject); -} - -- (OFString*)applicationDisplayName -{ - return toOF([self qGuiApplication]->applicationDisplayName()); -} - -- (void)setApplicationDisplayName: (OFString*)applicationDisplayName -{ - [self qGuiApplication]->setApplicationDisplayName( - toQt(applicationDisplayName)); -} - -- (OFString*)desktopFileName -{ - return toOF([self qGuiApplication]->desktopFileName()); -} - -- (void)setDesktopFileName: (OFString*)desktopFileName -{ - [self qGuiApplication]->setDesktopFileName(toQt(desktopFileName)); -} - -- (double)devicePixelRatio -{ - return [self qGuiApplication]->devicePixelRatio(); -} - -- (bool)isSavingSession -{ - return [self qGuiApplication]->isSavingSession(); -} - -- (bool)isSessionRestored -{ - return [self qGuiApplication]->isSessionRestored(); -} - -- (Qt::LayoutDirection)layoutDirection -{ - return [self qGuiApplication]->layoutDirection(); -} - -- (void)setLayoutDirection: (Qt::LayoutDirection)layoutDirection -{ - [self qGuiApplication]->setLayoutDirection(layoutDirection); -} - -- (OFString*)platformName -{ - return toOF([self qGuiApplication]->platformName()); -} - -- (QScreen*)primaryScreen -{ - return [self qGuiApplication]->primaryScreen(); -} - -- (bool)quitOnLastWindowClosed -{ - return [self qGuiApplication]->quitOnLastWindowClosed(); -} - -- (void)setQuitOnLastWindowClosed: (bool)quitOnLastWindowClosed -{ - [self qGuiApplication]->setQuitOnLastWindowClosed( - quitOnLastWindowClosed); -} - -- (OFString*)sessionID -{ - return toOF([self qGuiApplication]->sessionId()); -} - -- (OFString*)sessionKey -{ - return toOF([self qGuiApplication]->sessionKey()); -} - -- (QIcon)windowIcon -{ - return [self qGuiApplication]->windowIcon(); -} - -- (void)setWindowIcon: (QIcon)windowIcon -{ - [self qGuiApplication]->setWindowIcon(windowIcon); -} -@end Index: QtGui/QtPaintDevice.h ================================================================== --- QtGui/QtPaintDevice.h +++ QtGui/QtPaintDevice.h @@ -43,5 +43,15 @@ @end @interface QtPaintDevice: OFObject @property (readonly) QObject *qObject; @end + +namespace ObjQt { + +static OF_INLINE QPaintDevice* +toQt(QtPaintDevice *paintDevice) +{ + return [paintDevice qPaintDevice]; +} + +} Index: QtGui/QtPaintDevice.mm ================================================================== --- QtGui/QtPaintDevice.mm +++ QtGui/QtPaintDevice.mm @@ -21,10 +21,12 @@ */ #import "QtPaintDevice.h" #include + +using ObjQt::toQt; @implementation QtPaintDevice @dynamic qObject; - (QPaintDevice*)qPaintDevice @@ -32,73 +34,73 @@ return dynamic_cast([self qObject]); } - (int)colorCount { - return [self qPaintDevice]->colorCount(); + return toQt(self)->colorCount(); } - (int)depth { - return [self qPaintDevice]->depth(); + return toQt(self)->depth(); } - (int)devicePixelRatio { - return [self qPaintDevice]->devicePixelRatio(); + return toQt(self)->devicePixelRatio(); } - (double)devicePixelRatioF { - return [self qPaintDevice]->devicePixelRatioF(); + return toQt(self)->devicePixelRatioF(); } - (int)height { - return [self qPaintDevice]->height(); + return toQt(self)->height(); } - (int)heightMM { - return [self qPaintDevice]->heightMM(); + return toQt(self)->heightMM(); } - (int)logicalDPIX { - return [self qPaintDevice]->logicalDpiX(); + return toQt(self)->logicalDpiX(); } - (int)logicalDPIY { - return [self qPaintDevice]->logicalDpiY(); + return toQt(self)->logicalDpiY(); } - (QPaintEngine*)paintEngine { - return [self qPaintDevice]->paintEngine(); + return toQt(self)->paintEngine(); } - (bool)paintingActive { - return [self qPaintDevice]->paintingActive(); + return toQt(self)->paintingActive(); } - (int)physicalDPIX { - return [self qPaintDevice]->physicalDpiX(); + return toQt(self)->physicalDpiX(); } - (int)physicalDPIY { - return [self qPaintDevice]->physicalDpiY(); + return toQt(self)->physicalDpiY(); } - (int)width { - return [self qPaintDevice]->width(); + return toQt(self)->width(); } - (int)widthMM { - return [self qPaintDevice]->widthMM(); + return toQt(self)->widthMM(); } @end Index: QtWidgets/QtAction.h ================================================================== --- QtWidgets/QtAction.h +++ QtWidgets/QtAction.h @@ -54,12 +54,29 @@ - (QVariant)data; - (bool)isSeparator; - (QMenu*)menu; - (QtWidget*)parentWidget; - (void)setActionGroup: (QActionGroup*)group; +- (void)setData: (const QVariant&)data; - (void)setMenu: (QMenu*)menu; - (void)setSeparator: (bool)isSeparator; - (void)setShortcuts: (const QList&)shortcuts; - (void)setShortcutsWithStandardKey: (QKeySequence::StandardKey)key; - (QList)shortcuts; - (bool)showStatusText: (QtWidget*)widget; @end + +namespace ObjQt { + +static OF_INLINE QtAction* +toOF(QAction *qAction) +{ + return [[[QtAction alloc] initWithQAction: qAction] autorelease]; +} + +static OF_INLINE QAction* +toQt(QtAction *action) +{ + return [action qAction]; +} + +} Index: QtWidgets/QtAction.mm ================================================================== --- QtWidgets/QtAction.mm +++ QtWidgets/QtAction.mm @@ -20,12 +20,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ #import "QtAction.h" #import "QtWidget.h" +#import "OFString+QString.h" -#import "helpers.h" +using ObjQt::toOF; +using ObjQt::toQt; @implementation QtAction - initWithQObject: (QObject*)qObject { OF_INVALID_INIT_METHOD @@ -41,203 +43,202 @@ return qobject_cast(_qObject); } - (bool)autoRepeat { - return [self qAction]->autoRepeat(); + return toQt(self)->autoRepeat(); } - (void)setAutoRepeat: (bool)autoRepeat { - [self qAction]->setAutoRepeat(autoRepeat); + toQt(self)->setAutoRepeat(autoRepeat); } - (bool)isCheckable { - return [self qAction]->isCheckable(); + return toQt(self)->isCheckable(); } - (void)setCheckable: (bool)checkable { - [self qAction]->setCheckable(checkable); + toQt(self)->setCheckable(checkable); } - (bool)isChecked { - return [self qAction]->isChecked(); + return toQt(self)->isChecked(); } - (void)setChecked: (bool)checked { - [self qAction]->setChecked(checked); + toQt(self)->setChecked(checked); } - (bool)isEnabled { - return [self qAction]->isEnabled(); + return toQt(self)->isEnabled(); } - (void)setEnabled: (bool)enabled { - [self qAction]->setEnabled(enabled); + toQt(self)->setEnabled(enabled); } - (QFont)font { - return [self qAction]->font(); + return toQt(self)->font(); } - (void)setFont: (QFont)font { - [self qAction]->setFont(font); + toQt(self)->setFont(font); } - (QIcon)icon { - return [self qAction]->icon(); + return toQt(self)->icon(); } - (void)setIcon: (QIcon)icon { - [self qAction]->setIcon(icon); + toQt(self)->setIcon(icon); } - (OFString*)iconText { - return toOF([self qAction]->iconText()); + return toOF(toQt(self)->iconText()); } - (void)setIconText: (OFString*)iconText { - [self qAction]->setIconText(toQt(iconText)); + toQt(self)->setIconText(toQt(iconText)); } - (bool)isIconVisibleInMenu { - return [self qAction]->isIconVisibleInMenu(); + return toQt(self)->isIconVisibleInMenu(); } - (void)setIconVisibleInMenu: (bool)iconVisibleInMenu { - [self qAction]->setIconVisibleInMenu(iconVisibleInMenu); + toQt(self)->setIconVisibleInMenu(iconVisibleInMenu); } - (QAction::MenuRole)menuRole { - return [self qAction]->menuRole(); + return toQt(self)->menuRole(); } - (void)setMenuRole: (QAction::MenuRole)menuRole { - [self qAction]->setMenuRole(menuRole); + toQt(self)->setMenuRole(menuRole); } - (QAction::Priority)priority { - return [self qAction]->priority(); + return toQt(self)->priority(); } - (void)setPriority: (QAction::Priority)priority { - [self qAction]->setPriority(priority); + toQt(self)->setPriority(priority); } - (QKeySequence)shortcut { - return [self qAction]->shortcut(); + return toQt(self)->shortcut(); } - (void)setShortcut: (QKeySequence)shortcut { - [self qAction]->setShortcut(shortcut); + toQt(self)->setShortcut(shortcut); } - (Qt::ShortcutContext)shortcutContext { - return [self qAction]->shortcutContext(); + return toQt(self)->shortcutContext(); } - (void)setShortcutContext: (Qt::ShortcutContext)shortcutContext { - [self qAction]->setShortcutContext(shortcutContext); + toQt(self)->setShortcutContext(shortcutContext); } - (OFString*)statusTip { - return toOF([self qAction]->statusTip()); + return toOF(toQt(self)->statusTip()); } - (void)setStatusTip: (OFString*)statusTip { - [self qAction]->setStatusTip(toQt(statusTip)); + toQt(self)->setStatusTip(toQt(statusTip)); } - (OFString*)text { - return toOF([self qAction]->text()); + return toOF(toQt(self)->text()); } - (void)setText: (OFString*)text { - [self qAction]->setText(toQt(text)); + toQt(self)->setText(toQt(text)); } - (OFString*)toolTip { - return toOF([self qAction]->toolTip()); + return toOF(toQt(self)->toolTip()); } - (void)setToolTip: (OFString*)toolTip { - [self qAction]->setToolTip(toQt(toolTip)); + toQt(self)->setToolTip(toQt(toolTip)); } - (bool)isVisible { - return [self qAction]->isVisible(); + return toQt(self)->isVisible(); } - (void)setVisible: (bool)visible { - [self qAction]->setVisible(visible); + toQt(self)->setVisible(visible); } - (OFString*)whatsThis { - return toOF([self qAction]->whatsThis()); + return toOF(toQt(self)->whatsThis()); } - (void)setWhatsThis: (OFString*)whatsThis { - [self qAction]->setWhatsThis(toQt(whatsThis)); + toQt(self)->setWhatsThis(toQt(whatsThis)); } - (QActionGroup*)actionGroup { - return [self qAction]->actionGroup(); + return toQt(self)->actionGroup(); } - (void)activate: (QAction::ActionEvent)event { - [self qAction]->activate(event); + toQt(self)->activate(event); } - (QList)associatedGraphicsWidgets { - return [self qAction]->associatedGraphicsWidgets(); + return toQt(self)->associatedGraphicsWidgets(); } - (OFArray OF_GENERIC(QtWidget*)*)associatedWidgets { - const QList &widgets = [self qAction]->associatedWidgets(); + const QList &widgets = toQt(self)->associatedWidgets(); OFMutableArray *ret = [OFMutableArray arrayWithCapacity: widgets.count()]; void *pool = objc_autoreleasePoolPush(); for (QWidget *widget: widgets) - [ret addObject: - [[[QtWidget alloc] initWithQWidget: widget] autorelease]]; + [ret addObject: toOF(widget)]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); @@ -244,59 +245,63 @@ return ret; } - (QVariant)data { - return [self qAction]->data(); + return toQt(self)->data(); } - (bool)isSeparator { - return [self qAction]->isSeparator(); + return toQt(self)->isSeparator(); } - (QMenu*)menu { - return [self qAction]->menu(); + return toQt(self)->menu(); } - (QtWidget*)parentWidget { - return [[[QtWidget alloc] initWithQWidget: - [self qAction]->parentWidget()] autorelease]; + return toOF(toQt(self)->parentWidget()); } - (void)setActionGroup: (QActionGroup*)group { - [self qAction]->setActionGroup(group); + toQt(self)->setActionGroup(group); +} + +- (void)setData: (const QVariant&)userData +{ + toQt(self)->setData(userData); } - (void)setMenu: (QMenu*)menu { - [self qAction]->setMenu(menu); + toQt(self)->setMenu(menu); } - (void)setSeparator: (bool)isSeparator { - [self qAction]->setSeparator(isSeparator); + toQt(self)->setSeparator(isSeparator); } - (void)setShortcuts: (const QList&)shortcuts { - [self qAction]->setShortcuts(shortcuts); + toQt(self)->setShortcuts(shortcuts); } - (void)setShortcutsWithStandardKey: (QKeySequence::StandardKey)key { - [self qAction]->setShortcuts(key); + toQt(self)->setShortcuts(key); } - (QList)shortcuts { - return [self qAction]->shortcuts(); + return toQt(self)->shortcuts(); } - (bool)showStatusText: (QtWidget*)widget { - return [self qAction]->showStatusText([widget qWidget]); + return toQt(self)->showStatusText(toQt(widget)); } @end Index: QtWidgets/QtApplication.h ================================================================== --- QtWidgets/QtApplication.h +++ QtWidgets/QtApplication.h @@ -18,17 +18,17 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#import "QtGuiApplication.h" +#import "QtGUIApplication.h" #include -@interface QtApplication: QtGuiApplication +@interface QtApplication: QtGUIApplication @property (readonly) QApplication *qApplication; -@property bool autoSipEnabled; +@property bool autoSIPEnabled; @property int cursorFlashTime; @property int doubleClickInterval; @property of_dimension_t globalStrut; @property int keyboardInputInterval; @property int startDragDistance; @@ -36,9 +36,24 @@ @property (copy) OFString *styleSheet; @property int wheelScrollLines; - initWithQApplication: (QApplication*)qApplication; - (void)aboutQt; -- (bool)autoSipEnabled; - (void)closeAllWindows; -- (void)setAutoSipEnabled: (bool)enabled; @end + +namespace ObjQt { + +static OF_INLINE QtApplication* +toOF(QApplication *qApplication) +{ + return [[[QtApplication alloc] + initWithQApplication: qApplication] autorelease]; +} + +static OF_INLINE QApplication* +toQt(QtApplication *application) +{ + return [application qApplication]; +} + +} Index: QtWidgets/QtApplication.mm ================================================================== --- QtWidgets/QtApplication.mm +++ QtWidgets/QtApplication.mm @@ -19,12 +19,16 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import "QtApplication.h" +#import "OFString+QString.h" #import "helpers.h" + +using ObjQt::toOF; +using ObjQt::toQt; @implementation QtApplication - initWithQGuiApplication: (QGuiApplication*)qGuiApplication { OF_INVALID_INIT_METHOD @@ -38,105 +42,105 @@ - (QApplication*)qApplication { return qobject_cast(_qObject); } -- (bool)autoSipEnabled +- (bool)autoSIPEnabled { - return [self qApplication]->autoSipEnabled(); + return toQt(self)->autoSipEnabled(); } -- (void)setAutoSipEnabled: (bool)autoSipEnabled +- (void)setAutoSIPEnabled: (bool)autoSIPEnabled { - [self qApplication]->setAutoSipEnabled(autoSipEnabled); + toQt(self)->setAutoSipEnabled(autoSIPEnabled); } - (int)cursorFlashTime { - return [self qApplication]->cursorFlashTime(); + return toQt(self)->cursorFlashTime(); } - (void)setCursorFlashTime: (int)cursorFlashTime { - [self qApplication]->setCursorFlashTime(cursorFlashTime); + toQt(self)->setCursorFlashTime(cursorFlashTime); } - (int)doubleClickInterval { - return [self qApplication]->doubleClickInterval(); + return toQt(self)->doubleClickInterval(); } - (void)setDoubleClickInterval: (int)doubleClickInterval { - [self qApplication]->setDoubleClickInterval(doubleClickInterval); + toQt(self)->setDoubleClickInterval(doubleClickInterval); } - (of_dimension_t)globalStrut { - return toOF([self qApplication]->globalStrut()); + return toOF(toQt(self)->globalStrut()); } - (void)setGlobalStrut: (of_dimension_t)globalStrut { - [self qApplication]->setGlobalStrut(toQt(globalStrut)); + toQt(self)->setGlobalStrut(toQt(globalStrut)); } - (int)keyboardInputInterval { - return [self qApplication]->keyboardInputInterval(); + return toQt(self)->keyboardInputInterval(); } - (void)setKeyboardInputInterval: (int)keyboardInputInterval { - [self qApplication]->setKeyboardInputInterval(keyboardInputInterval); + toQt(self)->setKeyboardInputInterval(keyboardInputInterval); } - (int)startDragDistance { - return [self qApplication]->startDragDistance(); + return toQt(self)->startDragDistance(); } - (void)setStartDragDistance: (int)startDragDistance { - [self qApplication]->setStartDragDistance(startDragDistance); + toQt(self)->setStartDragDistance(startDragDistance); } - (int)startDragTime { - return [self qApplication]->startDragTime(); + return toQt(self)->startDragTime(); } - (void)setStartDragTime: (int)startDragTime { - [self qApplication]->setStartDragTime(startDragTime); + toQt(self)->setStartDragTime(startDragTime); } - (OFString*)styleSheet { - return toOF([self qApplication]->styleSheet()); + return toOF(toQt(self)->styleSheet()); } - (void)setStyleSheet: (OFString*)styleSheet { - [self qApplication]->setStyleSheet(toQt(styleSheet)); + toQt(self)->setStyleSheet(toQt(styleSheet)); } - (int)wheelScrollLines { - return [self qApplication]->wheelScrollLines(); + return toQt(self)->wheelScrollLines(); } - (void)setWheelScrollLines: (int)wheelScrollLines { - [self qApplication]->setWheelScrollLines(wheelScrollLines); + toQt(self)->setWheelScrollLines(wheelScrollLines); } - (void)aboutQt { - [self qApplication]->aboutQt(); + toQt(self)->aboutQt(); } - (void)closeAllWindows { - [self qApplication]->closeAllWindows(); + toQt(self)->closeAllWindows(); } @end Index: QtWidgets/QtWidget.h ================================================================== --- QtWidgets/QtWidget.h +++ QtWidgets/QtWidget.h @@ -37,11 +37,10 @@ @property (readonly) of_rectangle_t childrenRect; @property (readonly) QRegion childrenRegion; @property Qt::ContextMenuPolicy contextMenuPolicy; @property QCursor cursor; @property (getter=isEnabled) bool enabled; -@property (readonly, getter=hasFocus) bool focus; @property Qt::FocusPolicy focusPolicy; @property const QFont &font; @property (readonly) of_rectangle_t frameGeometry; @property (readonly) of_dimension_t frameSize; @property (readonly, getter=isFullScreen) bool fullScreen; @@ -76,11 +75,10 @@ @property int toolTipDuration; @property bool updatesEnabled; @property (getter=isVisible) bool visible; @property (copy) OFString *whatsThis; @property (readonly) int width; -@property (copy) OFString *windowFilePath; @property Qt::WindowFlags windowFlags; @property QIcon windowIcon; @property Qt::WindowModality windowModality; @property (getter=isWindowModified) bool windowModified; @property double windowOpacity; @@ -99,11 +97,11 @@ - (QtWidget*)childAt: (of_point_t)point; - (void)clearFocus; - (void)clearMask; - (QMargins)contentsMargins; - (of_rectangle_t)contentsRect; -- (WId)effectiveWinId; +- (WId)effectiveWinID; - (void)ensurePolished; - (QtWidget*)focusProxy; - (QtWidget*)focusWidget; - (QFontInfo)fontInfo; - (QFontMetrics)fontMetrics; @@ -121,10 +119,11 @@ - (QGraphicsEffect*)graphicsEffect; - (QGraphicsProxyWidget*)graphicsProxyWidget; #ifdef QT_KEYPAD_NAVIGATION - (bool)hasEditFocus; #endif +- (bool)hasFocus; - (bool)hasHeightForWidth; - (int)heightForWidth: (int)w; - (QVariant)queryInputMethod: (Qt::InputMethodQuery)query; - (void)insertAction: (QtAction*)action before: (QtAction*)before; @@ -133,21 +132,109 @@ - (bool)isAncestorOf: (QtWidget*)child; - (bool)isEnabledTo: (QtWidget*)ancestor; - (bool)isHidden; - (bool)isVisibleTo: (QtWidget*)ancestor; - (bool)isWindow; -// QPoint mapFrom(const QWidget *parent, const QPoint &pos) const -// QPoint mapFromGlobal(const QPoint &pos) const -// QPoint mapFromParent(const QPoint &pos) const -// QPoint mapTo(const QWidget *parent, const QPoint &pos) const -// QPoint mapToGlobal(const QPoint &pos) const -// QPoint mapToParent(const QPoint &pos) const -// QRegion mask() const -// ... - +- (of_point_t)mapPosition: (of_point_t)pos + from: (QtWidget*)parent; +- (of_point_t)mapPositionFromGlobal: (of_point_t)pos; +- (of_point_t)mapPositionFromParent: (of_point_t)pos; +- (of_point_t)mapPosition: (of_point_t)pos + to: (QtWidget*)parent; +- (of_point_t)mapPositionToGlobal: (of_point_t)pos; +- (of_point_t)mapPositionToParent: (of_point_t)pos; +- (QRegion)mask; +- (QtWidget*)nativeParentWidget; +- (QtWidget*)nextInFocusChain; +- (void)overrideWindowFlags: (Qt::WindowFlags)flags; +- (QtWidget*)parentWidget; +- (QtWidget*)previousInFocusChain; +- (void)releaseKeyboard; +- (void)releaseMouse; +- (void)releaseShortcut: (int)ID; +- (void)removeAction: (QtAction*)action; +- (void)renderIntoPaintDevice: (QtObject *)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion; +- (void)renderIntoPaintDevice: (QtObject *)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion + flags: (QWidget::RenderFlags)renderFlags; +- (void)renderIntoPainter: (QPainter*)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion; +- (void)renderIntoPainter: (QPainter*)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion + flags: (QWidget::RenderFlags)renderFlags; +- (void)repaintInRectangle: (of_rectangle_t)rect; +- (void)repaintInRegion: (const QRegion&)region; +- (bool)restoreGeometry: (OFDataArray*)geometry; +- (OFDataArray*)saveGeometry; +- (void)scrollRight: (int)dx + down: (int)dy; +- (void)scrollRight: (int)dx + down: (int)dy + inRectangle: (of_rectangle_t)rect; +- (void)setAttribute: (Qt::WidgetAttribute)attribute + to: (bool)on; +#ifdef QT_KEYPAD_NAVIGATION +- (void)setEditFocus: (bool)enable; +#endif +- (void)setFixedHeight: (int)height; +- (void)setFixedSize: (of_dimension_t)size; +- (void)setFixedWidth: (int)width; +- (void)setFocus: (Qt::FocusReason)reason; +- (void)setFocusProxy: (QtWidget*)widget; +- (void)setForegroundRole: (QPalette::ColorRole)role; +- (void)setGraphicsEffect: (QGraphicsEffect*)effect; +- (void)setLayout: (QLayout*)layout; +- (void)setMaskFromBitmap: (const QBitmap&)bitmap; +- (void)setMask: (const QRegion&)region; +- (void)setParent: (QtWidget*)parent; +- (void)setParent: (QtWidget*)parent + flags: (Qt::WindowFlags)flags; +- (void)setAutoRepeat: (bool)enable + forShortcut: (int)ID; +- (void)setEnabled: (bool)enable + forShortcut: (int)ID; +- (void)setStyle: (QStyle*)style; +- (void)setWindowRole: (OFString*)role; +- (void)setWindowState: (Qt::WindowStates)windowState; +- (void)stackUnder: (QtWidget*)widget; +- (QStyle*)style; +- (bool)testAttribute: (Qt::WidgetAttribute)attribute; +- (bool)isUnderMouse; +- (void)ungrabGesture: (Qt::GestureType)gesture; - (void)unsetCursor; - (void)unsetLayoutDirection; - (void)unsetLocale; +- (void)updateInRectangle: (of_rectangle_t)rect; +- (void)updateInRegion: (const QRegion&)region; +- (void)updateGeometry; +- (QRegion)visibleRegion; +- (WId)winID; +- (QtWidget*)window; +- (QWindow*)windowHandle; +- (OFString*)windowRole; +- (Qt::WindowStates)windowState; +- (Qt::WindowType)windowType; @end @interface QtWidget (QtPaintDevice) @end + +namespace ObjQt { + +static OF_INLINE QtWidget* +toOF(QWidget *qWidget) +{ + return [[[QtWidget alloc] initWithQWidget: qWidget] autorelease]; +} + +static OF_INLINE QWidget* +toQt(QtWidget *widget) +{ + return [widget qWidget]; +} + +} Index: QtWidgets/QtWidget.mm ================================================================== --- QtWidgets/QtWidget.mm +++ QtWidgets/QtWidget.mm @@ -20,15 +20,20 @@ * POSSIBILITY OF SUCH DAMAGE. */ #import "QtWidget.h" #import "QtAction.h" +#import "OFString+QString.h" +#import "OFDataArray+QByteArray.h" #import "helpers.h" #include #include + +using ObjQt::toOF; +using ObjQt::toQt; @implementation QtWidget + (void)initialize { if (self == [QtWidget class]) @@ -50,523 +55,522 @@ return qobject_cast(_qObject); } - (bool)acceptDrops { - return [self qWidget]->acceptDrops(); + return toQt(self)->acceptDrops(); } - (void)setAcceptDrops: (bool)acceptDrops { - [self qWidget]->setAcceptDrops(acceptDrops); + toQt(self)->setAcceptDrops(acceptDrops); } - (OFString*)accessibleDescription { - return toOF([self qWidget]->accessibleDescription()); + return toOF(toQt(self)->accessibleDescription()); } - (void)setAccessibleDescription: (OFString*)accessibleDescription { - [self qWidget]->setAccessibleDescription(toQt(accessibleDescription)); + toQt(self)->setAccessibleDescription(toQt(accessibleDescription)); } - (OFString*)accessibleName { - return toOF([self qWidget]->accessibleName()); + return toOF(toQt(self)->accessibleName()); } - (void)setAccessibleName: (OFString*)accessibleName { - [self qWidget]->setAccessibleName(toQt(accessibleName)); + toQt(self)->setAccessibleName(toQt(accessibleName)); } - (bool)autoFillBackground { - return [self qWidget]->autoFillBackground(); + return toQt(self)->autoFillBackground(); } - (void)setAutoFillBackground: (bool)autoFillBackground { - [self qWidget]->setAutoFillBackground(autoFillBackground); + toQt(self)->setAutoFillBackground(autoFillBackground); } - (of_dimension_t)baseSize { - return toOF([self qWidget]->baseSize()); + return toOF(toQt(self)->baseSize()); } - (void)setBaseSize: (of_dimension_t)baseSize { - [self qWidget]->setBaseSize(toQt(baseSize)); + toQt(self)->setBaseSize(toQt(baseSize)); } - (of_rectangle_t)childrenRect { - return toOF([self qWidget]->childrenRect()); + return toOF(toQt(self)->childrenRect()); } - (QRegion)childrenRegion { - return [self qWidget]->childrenRegion(); + return toQt(self)->childrenRegion(); } - (Qt::ContextMenuPolicy)contextMenuPolicy { - return [self qWidget]->contextMenuPolicy(); + return toQt(self)->contextMenuPolicy(); } - (void)setContextMenuPolicy: (Qt::ContextMenuPolicy)contextMenuPolicy { - [self qWidget]->setContextMenuPolicy(contextMenuPolicy); + toQt(self)->setContextMenuPolicy(contextMenuPolicy); } - (QCursor)cursor { - return [self qWidget]->cursor(); + return toQt(self)->cursor(); } - (void)setCursor: (QCursor)cursor { - [self qWidget]->setCursor(cursor); + toQt(self)->setCursor(cursor); } - (void)unsetCursor { - [self qWidget]->unsetCursor(); + toQt(self)->unsetCursor(); } - (bool)isEnabled { - return [self qWidget]->isEnabled(); + return toQt(self)->isEnabled(); } - (void)setEnabled: (bool)enabled { - [self qWidget]->setEnabled(enabled); + toQt(self)->setEnabled(enabled); } - (bool)hasFocus { - return [self qWidget]->hasFocus(); + return toQt(self)->hasFocus(); } - (Qt::FocusPolicy)focusPolicy { - return [self qWidget]->focusPolicy(); + return toQt(self)->focusPolicy(); } - (void)setFocusPolicy: (Qt::FocusPolicy)focusPolicy { - [self qWidget]->setFocusPolicy(focusPolicy); + toQt(self)->setFocusPolicy(focusPolicy); } - (const QFont&)font { - return [self qWidget]->font(); + return toQt(self)->font(); } - (void)setFont: (const QFont&)font { - [self qWidget]->setFont(font); + toQt(self)->setFont(font); } - (of_rectangle_t)frameGeometry { - return toOF([self qWidget]->frameGeometry()); + return toOF(toQt(self)->frameGeometry()); } - (of_dimension_t)frameSize { - return toOF([self qWidget]->frameSize()); + return toOF(toQt(self)->frameSize()); } - (bool)isFullScreen { - return [self qWidget]->isFullScreen(); + return toQt(self)->isFullScreen(); } - (of_rectangle_t)geometry { - return toOF([self qWidget]->geometry()); + return toOF(toQt(self)->geometry()); } - (void)setGeometry: (of_rectangle_t)geometry { - [self qWidget]->setGeometry(toQt(geometry)); + toQt(self)->setGeometry(toQt(geometry)); } - (int)height { - return [self qWidget]->height(); + return toQt(self)->height(); } - (Qt::InputMethodHints)inputMethodHints { - return [self qWidget]->inputMethodHints(); + return toQt(self)->inputMethodHints(); } - (void)setInputMethodHints: (Qt::InputMethodHints)inputMethodHints { - [self qWidget]->setInputMethodHints(inputMethodHints); + toQt(self)->setInputMethodHints(inputMethodHints); } - (bool)isActiveWindow { - return [self qWidget]->isActiveWindow(); + return toQt(self)->isActiveWindow(); } - (Qt::LayoutDirection)layoutDirection { - return [self qWidget]->layoutDirection(); + return toQt(self)->layoutDirection(); } - (void)setLayoutDirection: (Qt::LayoutDirection)layoutDirection { - [self qWidget]->setLayoutDirection(layoutDirection); + toQt(self)->setLayoutDirection(layoutDirection); } - (void)unsetLayoutDirection { - [self qWidget]->unsetLayoutDirection(); + toQt(self)->unsetLayoutDirection(); } - (QLocale)locale { - return [self qWidget]->locale(); + return toQt(self)->locale(); } - (void)setLocale: (QLocale)locale { - [self qWidget]->setLocale(locale); + toQt(self)->setLocale(locale); } - (void)unsetLocale { - [self qWidget]->unsetLocale(); + toQt(self)->unsetLocale(); } - (bool)isMaximized { - return [self qWidget]->isMaximized(); + return toQt(self)->isMaximized(); } - (int)maximumHeight { - return [self qWidget]->maximumHeight(); + return toQt(self)->maximumHeight(); } - (void)setMaximumHeight: (int)maximumHeight { - [self qWidget]->setMaximumHeight(maximumHeight); + toQt(self)->setMaximumHeight(maximumHeight); } - (of_dimension_t)maximumSize { - return toOF([self qWidget]->maximumSize()); + return toOF(toQt(self)->maximumSize()); } - (void)setMaximumSize: (of_dimension_t)maximumSize { - [self qWidget]->setMaximumSize(toQt(maximumSize)); + toQt(self)->setMaximumSize(toQt(maximumSize)); } - (int)maximumWidth { - return [self qWidget]->maximumWidth(); + return toQt(self)->maximumWidth(); } - (void)setMaximumWidth: (int)maximumWidth { - [self qWidget]->setMaximumWidth(maximumWidth); + toQt(self)->setMaximumWidth(maximumWidth); } - (bool)isMinimized { - return [self qWidget]->isMinimized(); + return toQt(self)->isMinimized(); } - (int)minimumHeight { - return [self qWidget]->minimumHeight(); + return toQt(self)->minimumHeight(); } - (void)setMinimumHeight: (int)minimumHeight { - [self qWidget]->setMinimumHeight(minimumHeight); + toQt(self)->setMinimumHeight(minimumHeight); } - (of_dimension_t)minimumSize { - return toOF([self qWidget]->minimumSize()); + return toOF(toQt(self)->minimumSize()); } - (void)setMinimumSize: (of_dimension_t)minimumSize { - [self qWidget]->setMinimumSize(toQt(minimumSize)); + toQt(self)->setMinimumSize(toQt(minimumSize)); } - (of_dimension_t)minimumSizeHint { - return toOF([self qWidget]->minimumSizeHint()); + return toOF(toQt(self)->minimumSizeHint()); } - (int)minimumWidth { - return [self qWidget]->minimumWidth(); + return toQt(self)->minimumWidth(); } - (void)setMinimumWidth: (int)minimumWidth { - [self qWidget]->setMinimumWidth(minimumWidth); + toQt(self)->setMinimumWidth(minimumWidth); } - (bool)isModal { - return [self qWidget]->isModal(); + return toQt(self)->isModal(); } - (bool)hasMouseTracking { - return [self qWidget]->hasMouseTracking(); + return toQt(self)->hasMouseTracking(); } - (void)setMouseTracking: (bool)mouseTracking { - [self qWidget]->setMouseTracking(mouseTracking); + toQt(self)->setMouseTracking(mouseTracking); } - (of_rectangle_t)normalGeometry { - return toOF([self qWidget]->normalGeometry()); + return toOF(toQt(self)->normalGeometry()); } - (const QPalette&)palette { - return [self qWidget]->palette(); + return toQt(self)->palette(); } - (void)setPalette: (const QPalette&)palette { - [self qWidget]->setPalette(palette); + toQt(self)->setPalette(palette); } - (of_point_t)pos { - return toOF([self qWidget]->pos()); + return toOF(toQt(self)->pos()); } - (void)moveToPosition: (of_point_t)pos { - [self qWidget]->move(toQt(pos)); + toQt(self)->move(toQt(pos)); } - (of_rectangle_t)rect { - return toOF([self qWidget]->rect()); + return toOF(toQt(self)->rect()); } - (of_dimension_t)size { - return toOF([self qWidget]->size()); + return toOF(toQt(self)->size()); } - (void)resizeTo: (of_dimension_t)size { - [self qWidget]->resize(toQt(size)); + toQt(self)->resize(toQt(size)); } - (of_dimension_t)sizeHint { - return toOF([self qWidget]->sizeHint()); + return toOF(toQt(self)->sizeHint()); } - (of_dimension_t)sizeIncrement { - return toOF([self qWidget]->sizeIncrement()); + return toOF(toQt(self)->sizeIncrement()); } - (void)setSizeIncrement: (of_dimension_t)sizeIncrement { - [self qWidget]->setSizeIncrement(toQt(sizeIncrement)); + toQt(self)->setSizeIncrement(toQt(sizeIncrement)); } - (QSizePolicy)sizePolicy { - return [self qWidget]->sizePolicy(); + return toQt(self)->sizePolicy(); } - (void)setSizePolicy: (QSizePolicy)sizePolicy { - [self qWidget]->setSizePolicy(sizePolicy); + toQt(self)->setSizePolicy(sizePolicy); } - (OFString*)statusTip { - return toOF([self qWidget]->statusTip()); + return toOF(toQt(self)->statusTip()); } - (void)setStatusTip: (OFString*)statusTip { - [self qWidget]->setStatusTip(toQt(statusTip)); + toQt(self)->setStatusTip(toQt(statusTip)); } - (OFString*)styleSheet { - return toOF([self qWidget]->styleSheet()); + return toOF(toQt(self)->styleSheet()); } - (void)setStyleSheet: (OFString*)styleSheet { - [self qWidget]->setStyleSheet(toQt(styleSheet)); + toQt(self)->setStyleSheet(toQt(styleSheet)); } - (OFString*)toolTip { - return toOF([self qWidget]->toolTip()); + return toOF(toQt(self)->toolTip()); } - (void)setToolTip: (OFString*)toolTip { - [self qWidget]->setToolTip(toQt(toolTip)); + toQt(self)->setToolTip(toQt(toolTip)); } - (int)toolTipDuration { - return [self qWidget]->toolTipDuration(); + return toQt(self)->toolTipDuration(); } - (void)setToolTipDuration: (int)toolTipDuration { - [self qWidget]->setToolTipDuration(toolTipDuration); + toQt(self)->setToolTipDuration(toolTipDuration); } - (bool)updatesEnabled { - return [self qWidget]->updatesEnabled(); + return toQt(self)->updatesEnabled(); } - (void)setUpdatesEnabled: (bool)updatesEnabled { - [self qWidget]->setUpdatesEnabled(updatesEnabled); + toQt(self)->setUpdatesEnabled(updatesEnabled); } - (bool)isVisible { - return [self qWidget]->isVisible(); + return toQt(self)->isVisible(); } - (void)setVisible: (bool)visible { - [self qWidget]->setVisible(visible); + toQt(self)->setVisible(visible); } - (OFString*)whatsThis { - return toOF([self qWidget]->whatsThis()); + return toOF(toQt(self)->whatsThis()); } - (void)setWhatsThis: (OFString*)whatsThis { - [self qWidget]->setWhatsThis(toQt(whatsThis)); + toQt(self)->setWhatsThis(toQt(whatsThis)); } - (int)width { - return [self qWidget]->width(); + return toQt(self)->width(); } - (OFString*)windowFilePath { - return toOF([self qWidget]->windowFilePath()); + return toOF(toQt(self)->windowFilePath()); } - (void)setWindowFilePath: (OFString*)windowFilePath { - [self qWidget]->setWindowFilePath(toQt(windowFilePath)); + toQt(self)->setWindowFilePath(toQt(windowFilePath)); } - (Qt::WindowFlags)windowFlags { - return [self qWidget]->windowFlags(); + return toQt(self)->windowFlags(); } - (void)setWindowFlags: (Qt::WindowFlags)windowFlags { - [self qWidget]->setWindowFlags(windowFlags); + toQt(self)->setWindowFlags(windowFlags); } - (QIcon)windowIcon { - return [self qWidget]->windowIcon(); + return toQt(self)->windowIcon(); } - (void)setWindowIcon: (QIcon)windowIcon { - [self qWidget]->setWindowIcon(windowIcon); + toQt(self)->setWindowIcon(windowIcon); } - (Qt::WindowModality)windowModality { - return [self qWidget]->windowModality(); + return toQt(self)->windowModality(); } - (void)setWindowModality: (Qt::WindowModality)windowModality { - [self qWidget]->setWindowModality(windowModality); + toQt(self)->setWindowModality(windowModality); } - (bool)isWindowModified { - return [self qWidget]->isWindowModified(); + return toQt(self)->isWindowModified(); } - (void)setWindowModified: (bool)windowModified { - [self qWidget]->setWindowModified(windowModified); + toQt(self)->setWindowModified(windowModified); } - (double)windowOpacity { - return [self qWidget]->windowOpacity(); + return toQt(self)->windowOpacity(); } - (void)setWindowOpacity: (double)windowOpacity { - [self qWidget]->setWindowOpacity(windowOpacity); + toQt(self)->setWindowOpacity(windowOpacity); } - (OFString*)windowTitle { - return toOF([self qWidget]->windowTitle()); + return toOF(toQt(self)->windowTitle()); } - (void)setWindowTitle: (OFString*)windowTitle { - [self qWidget]->setWindowTitle(toQt(windowTitle)); + toQt(self)->setWindowTitle(toQt(windowTitle)); } - (int)x { - return [self qWidget]->x(); + return toQt(self)->x(); } - (int)y { - return [self qWidget]->y(); + return toQt(self)->y(); } - (OFArray OF_GENERIC(QtAction*)*)actions { - const QList &actions = [self qWidget]->actions(); + const QList &actions = toQt(self)->actions(); OFMutableArray *ret = [OFMutableArray arrayWithCapacity: actions.count()]; void *pool = objc_autoreleasePoolPush(); for (QAction *action: actions) - [ret addObject: - [[[QtAction alloc] initWithQAction: action] autorelease]]; + [ret addObject: toOF(action)]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); @@ -573,217 +577,538 @@ return ret; } - (void)activateWindow { - [self qWidget]->activateWindow(); + toQt(self)->activateWindow(); } - (void)addAction: (QtAction*)action { - [self qWidget]->addAction([action qAction]); + toQt(self)->addAction(toQt(action)); } - (void)addActions: (OFArray OF_GENERIC(QtAction*)*)actions { QList list; for (QtAction *action in actions) - list.append([action qAction]); + list.append(toQt(action)); - [self qWidget]->addActions(list); + toQt(self)->addActions(list); } - (void)adjustSize { - [self qWidget]->adjustSize(); + toQt(self)->adjustSize(); } - (QPalette::ColorRole)backgroundRole { - return [self qWidget]->backgroundRole(); + return toQt(self)->backgroundRole(); } - (QBackingStore*)backingStore { - return [self qWidget]->backingStore(); + return toQt(self)->backingStore(); } - (QtWidget*)childAt: (of_point_t)point { - return [[[QtWidget alloc] initWithQWidget: - [self qWidget]->childAt(toQt(point))] autorelease]; + return toOF(toQt(self)->childAt(toQt(point))); } - (void)clearFocus { - return [self qWidget]->clearFocus(); + return toQt(self)->clearFocus(); } - (void)clearMask { - [self qWidget]->clearMask(); + toQt(self)->clearMask(); } - (QMargins)contentsMargins { - return [self qWidget]->contentsMargins(); + return toQt(self)->contentsMargins(); } - (of_rectangle_t)contentsRect { - return toOF([self qWidget]->contentsRect()); + return toOF(toQt(self)->contentsRect()); } -- (WId)effectiveWinId +- (WId)effectiveWinID { - return [self qWidget]->effectiveWinId(); + return toQt(self)->effectiveWinId(); } - (void)ensurePolished { - [self qWidget]->ensurePolished(); + toQt(self)->ensurePolished(); } - (QtWidget*)focusProxy { - return [[[QtWidget alloc] initWithQWidget: - [self qWidget]->focusProxy()] autorelease]; + return toOF(toQt(self)->focusProxy()); } - (QtWidget*)focusWidget { - return [[[QtWidget alloc] initWithQWidget: - [self qWidget]->focusWidget()] autorelease]; + return toOF(toQt(self)->focusWidget()); } - (QFontInfo)fontInfo { - return [self qWidget]->fontInfo(); + return toQt(self)->fontInfo(); } - (QFontMetrics)fontMetrics { - return [self qWidget]->fontMetrics(); + return toQt(self)->fontMetrics(); } - (QPalette::ColorRole)foregroundRole { - return [self qWidget]->foregroundRole(); + return toQt(self)->foregroundRole(); } - (QPixmap)grabRectangle: (of_rectangle_t)rectangle { - return [self qWidget]->grab(toQt(rectangle)); + return toQt(self)->grab(toQt(rectangle)); } - (void)grabGesture: (Qt::GestureType)gesture { - [self qWidget]->grabGesture(gesture); + toQt(self)->grabGesture(gesture); } - (void)grabGesture: (Qt::GestureType)gesture flags: (Qt::GestureFlags)flags { - [self qWidget]->grabGesture(gesture, flags); + toQt(self)->grabGesture(gesture, flags); } - (void)grabKeyboard { - [self qWidget]->grabKeyboard(); + toQt(self)->grabKeyboard(); } - (void)grabMouse { - [self qWidget]->grabMouse(); + toQt(self)->grabMouse(); } - (void)grabMouseWithCursor: (const QCursor&)cursor { - [self qWidget]->grabMouse(cursor); + toQt(self)->grabMouse(cursor); } - (int)grabShortcutWithKey: (const QKeySequence&)key { - return [self qWidget]->grabShortcut(key); + return toQt(self)->grabShortcut(key); } - (int)grabShortcutWithKey: (const QKeySequence&)key context: (Qt::ShortcutContext)context { - return [self qWidget]->grabShortcut(key, context); + return toQt(self)->grabShortcut(key, context); } - (QGraphicsEffect*)graphicsEffect { - return [self qWidget]->graphicsEffect(); + return toQt(self)->graphicsEffect(); } - (QGraphicsProxyWidget*)graphicsProxyWidget { - return [self qWidget]->graphicsProxyWidget(); + return toQt(self)->graphicsProxyWidget(); } #ifdef QT_KEYPAD_NAVIGATION - (bool)hasEditFocus { - return [self qWidget]->hasEditFocus(); + return toQt(self)->hasEditFocus(); } #endif - (bool)hasHeightForWidth { - return [self qWidget]->hasHeightForWidth(); + return toQt(self)->hasHeightForWidth(); } - (int)heightForWidth: (int)w { - return [self qWidget]->heightForWidth(w); + return toQt(self)->heightForWidth(w); } - (QVariant)queryInputMethod: (Qt::InputMethodQuery)query { - return [self qWidget]->inputMethodQuery(query); + return toQt(self)->inputMethodQuery(query); } - (void)insertAction: (QtAction*)action before: (QtAction*)before { - [self qWidget]->insertAction([before qAction], [action qAction]); + toQt(self)->insertAction(toQt(before), toQt(action)); } - (void)insertActions: (OFArray OF_GENERIC(QtAction*)*)actions before: (QtAction*)before { QList list; for (QtAction *action in actions) - list.append([action qAction]); + list.append(toQt(action)); - [self qWidget]->insertActions([before qAction], list); + toQt(self)->insertActions(toQt(before), list); } - (bool)isAncestorOf: (QtWidget*)child { - return [self qWidget]->isAncestorOf([child qWidget]); + return toQt(self)->isAncestorOf(toQt(child)); } - (bool)isEnabledTo: (QtWidget*)ancestor { - return [self qWidget]->isEnabledTo([ancestor qWidget]); + return toQt(self)->isEnabledTo(toQt(ancestor)); } - (bool)isHidden { - return [self qWidget]->isHidden(); + return toQt(self)->isHidden(); } - (bool)isVisibleTo: (QtWidget*)ancestor { - return [self qWidget]->isVisibleTo([ancestor qWidget]); + return toQt(self)->isVisibleTo(toQt(ancestor)); } - (bool)isWindow { - return [self qWidget]->isWindow(); + return toQt(self)->isWindow(); +} + +- (of_point_t)mapPosition: (of_point_t)pos + from: (QtWidget*)parent +{ + return toOF(toQt(self)->mapFrom(toQt(parent), toQt(pos))); +} + +- (of_point_t)mapPositionFromGlobal: (of_point_t)pos +{ + return toOF(toQt(self)->mapFromGlobal(toQt(pos))); +} + +- (of_point_t)mapPositionFromParent: (of_point_t)pos +{ + return toOF(toQt(self)->mapFromParent(toQt(pos))); +} + +- (of_point_t)mapPosition: (of_point_t)pos + to: (QtWidget*)parent +{ + return toOF(toQt(self)->mapTo(toQt(parent), toQt(pos))); +} + +- (of_point_t)mapPositionToGlobal: (of_point_t)pos +{ + return toOF(toQt(self)->mapToGlobal(toQt(pos))); +} + +- (of_point_t)mapPositionToParent: (of_point_t)pos +{ + return toOF(toQt(self)->mapToParent(toQt(pos))); +} + +- (QRegion)mask +{ + return toQt(self)->mask(); +} + +- (QtWidget*)nativeParentWidget +{ + return toOF(toQt(self)->nativeParentWidget()); +} + +- (QtWidget*)nextInFocusChain +{ + return toOF(toQt(self)->nextInFocusChain()); +} + +- (void)overrideWindowFlags: (Qt::WindowFlags)flags +{ + toQt(self)->overrideWindowFlags(flags); +} + +- (QtWidget*)parentWidget +{ + return toOF(toQt(self)->parentWidget()); +} + +- (QtWidget*)previousInFocusChain +{ + return toOF(toQt(self)->previousInFocusChain()); +} + +- (void)releaseKeyboard +{ + toQt(self)->releaseKeyboard(); +} + +- (void)releaseMouse +{ + toQt(self)->releaseMouse(); +} + +- (void)releaseShortcut: (int)ID +{ + toQt(self)->releaseShortcut(ID); +} + +- (void)removeAction: (QtAction*)action +{ + toQt(self)->removeAction(toQt(action)); +} + +- (void)renderIntoPaintDevice: (QtObject *)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion +{ + toQt(self)->render([target qPaintDevice], toQt(targetOffset), + sourceRegion); +} + +- (void)renderIntoPaintDevice: (QtObject *)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion + flags: (QWidget::RenderFlags)renderFlags +{ + toQt(self)->render([target qPaintDevice], toQt(targetOffset), + sourceRegion, renderFlags); +} + +- (void)renderIntoPainter: (QPainter*)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion +{ + toQt(self)->render(target, toQt(targetOffset), sourceRegion); +} + +- (void)renderIntoPainter: (QPainter*)target + targetOffset: (of_point_t)targetOffset + sourceRegion: (QRegion)sourceRegion + flags: (QWidget::RenderFlags)renderFlags +{ + toQt(self)->render(target, toQt(targetOffset), sourceRegion, + renderFlags); +} + +- (void)repaintInRectangle: (of_rectangle_t)rect +{ + toQt(self)->repaint(toQt(rect)); +} + +- (void)repaintInRegion: (const QRegion&)region +{ + toQt(self)->repaint(region); +} + +- (bool)restoreGeometry: (OFDataArray*)geometry +{ + return toQt(self)->restoreGeometry(toQt(geometry)); +} + +- (OFDataArray*)saveGeometry +{ + return toOF(toQt(self)->saveGeometry()); +} + +- (void)scrollRight: (int)dx + down: (int)dy +{ + toQt(self)->scroll(dx, dy); +} + +- (void)scrollRight: (int)dx + down: (int)dy + inRectangle: (of_rectangle_t)rect +{ + toQt(self)->scroll(dx, dy, toQt(rect)); +} + +- (void)setAttribute: (Qt::WidgetAttribute)attribute + to: (bool)on +{ + toQt(self)->setAttribute(attribute, on); +} + +#ifdef QT_KEYPAD_NAVIGATION +- (void)setEditFocus: (bool)enable +{ + toQt(self)->setEditFocus(enable); +} +#endif + +- (void)setFixedHeight: (int)height +{ + toQt(self)->setFixedHeight(height); +} + +- (void)setFixedSize: (of_dimension_t)size +{ + toQt(self)->setFixedSize(toQt(size)); +} + +- (void)setFixedWidth: (int)width +{ + toQt(self)->setFixedWidth(width); +} + +- (void)setFocus: (Qt::FocusReason)reason +{ + toQt(self)->setFocus(reason); +} + +- (void)setFocusProxy: (QtWidget*)widget +{ + toQt(self)->setFocusProxy(toQt(widget)); +} + +- (void)setForegroundRole: (QPalette::ColorRole)role +{ + toQt(self)->setForegroundRole(role); +} + +- (void)setGraphicsEffect: (QGraphicsEffect*)effect +{ + toQt(self)->setGraphicsEffect(effect); +} + +- (void)setLayout: (QLayout*)layout +{ + toQt(self)->setLayout(layout); +} + +- (void)setMaskFromBitmap: (const QBitmap&)bitmap +{ + toQt(self)->setMask(bitmap); +} + +- (void)setMask: (const QRegion&)region +{ + toQt(self)->setMask(region); +} + +- (void)setParent: (QtWidget*)parent +{ + toQt(self)->setParent(toQt(parent)); +} + +- (void)setParent: (QtWidget*)parent + flags: (Qt::WindowFlags)flags +{ + toQt(self)->setParent(toQt(parent), flags); +} + +- (void)setAutoRepeat: (bool)enable + forShortcut: (int)ID +{ + toQt(self)->setShortcutAutoRepeat(ID, enable); +} + +- (void)setEnabled: (bool)enable + forShortcut: (int)ID +{ + toQt(self)->setShortcutEnabled(ID, enable); +} + +- (void)setStyle: (QStyle*)style +{ + toQt(self)->setStyle(style); +} + +- (void)setWindowRole: (OFString*)role +{ + toQt(self)->setWindowRole(toQt(role)); +} + +- (void)setWindowState: (Qt::WindowStates)windowState +{ + toQt(self)->setWindowState(windowState); +} + +- (void)stackUnder: (QtWidget*)widget +{ + toQt(self)->stackUnder(toQt(widget)); +} + +- (QStyle*)style +{ + return toQt(self)->style(); +} + +- (bool)testAttribute: (Qt::WidgetAttribute)attribute +{ + return toQt(self)->testAttribute(attribute); +} + +- (bool)isUnderMouse +{ + return toQt(self)->underMouse(); +} + +- (void)ungrabGesture: (Qt::GestureType)gesture +{ + toQt(self)->ungrabGesture(gesture); +} + +- (void)updateInRectangle: (of_rectangle_t)rect +{ + toQt(self)->update(toQt(rect)); +} + +- (void)updateInRegion: (const QRegion&)region +{ + toQt(self)->update(region); +} + +- (void)updateGeometry +{ + toQt(self)->updateGeometry(); +} + +- (QRegion)visibleRegion +{ + return toQt(self)->visibleRegion(); +} + +- (WId)winID +{ + return toQt(self)->winId(); +} + +- (QtWidget*)window +{ + return toOF(toQt(self)->window()); +} + +- (QWindow*)windowHandle +{ + return toQt(self)->windowHandle(); +} + +- (OFString*)windowRole +{ + return toOF(toQt(self)->windowRole()); +} + +- (Qt::WindowStates)windowState +{ + return toQt(self)->windowState(); +} + +- (Qt::WindowType)windowType +{ + return toQt(self)->windowType(); } @end ADDED common/OFDataArray+QByteArray.h Index: common/OFDataArray+QByteArray.h ================================================================== --- common/OFDataArray+QByteArray.h +++ common/OFDataArray+QByteArray.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017, Jonathan Schleifer + * + * https://heap.zone/git/objqt.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import + +#include + +@interface OFDataArray (QByteArray) ++ (instancetype)dataArrayWithQByteArray: (const QByteArray&)qByteArray; +- (QByteArray)qByteArray; +@end + +namespace ObjQt { + +static OF_INLINE OFDataArray* +toOF(const QByteArray &qByteArray) +{ + return [OFDataArray dataArrayWithQByteArray: qByteArray]; +} + +static OF_INLINE QByteArray +toQt(OFDataArray *dataArray) +{ + return [dataArray qByteArray]; +} + +} ADDED common/OFDataArray+QByteArray.mm Index: common/OFDataArray+QByteArray.mm ================================================================== --- common/OFDataArray+QByteArray.mm +++ common/OFDataArray+QByteArray.mm @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, Jonathan Schleifer + * + * https://heap.zone/git/objqt.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#import "OFDataArray+QByteArray.h" + +@implementation OFDataArray (QByteArray) ++ (instancetype)dataArrayWithQByteArray: (const QByteArray&)qByteArray +{ + OFDataArray *ret = [OFDataArray dataArray]; + [ret addItems: qByteArray.data() + count: qByteArray.count()]; + + return ret; +} + +- (QByteArray)qByteArray +{ + return QByteArray((char*)[self items], [self count] * [self itemSize]); +} +@end Index: common/OFString+QString.h ================================================================== --- common/OFString+QString.h +++ common/OFString+QString.h @@ -27,5 +27,21 @@ @interface OFString (QString) + (instancetype)stringWithQString: (const QString&)qString; - initWithQString: (const QString&)qString; - (QString)qString; @end + +namespace ObjQt { + +static OF_INLINE OFString* +toOF(const QString &qString) +{ + return [OFString stringWithQString: qString]; +} + +static OF_INLINE QString +toQt(OFString *string) +{ + return [string qString]; +} + +} Index: common/helpers.h ================================================================== --- common/helpers.h +++ common/helpers.h @@ -20,27 +20,21 @@ * POSSIBILITY OF SUCH DAMAGE. */ #import -#include #include #include -#import "OFString+QString.h" - -static OF_INLINE OFString* -toOF(const QString &qString) -{ - return [OFString stringWithQString: qString]; -} - -static OF_INLINE QString -toQt(OFString *string) -{ - return [string qString]; -} +#import "QtObject.h" +#import "QtAction.h" +#import "QtEvent.h" +#import "QtChildEvent.h" +#import "QtThread.h" +#import "QtWidget.h" + +namespace ObjQt { static OF_INLINE of_point_t toOF(const QPoint &qPoint) { return of_point(qPoint.x(), qPoint.y()); @@ -74,6 +68,8 @@ static OF_INLINE QRect toQt(of_rectangle_t rectangle) { return QRect(rectangle.origin.x, rectangle.origin.y, rectangle.size.width, rectangle.size.height); +} + }