Index: ObjQt.pro ================================================================== --- ObjQt.pro +++ ObjQt.pro @@ -17,10 +17,11 @@ 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 \ @@ -28,14 +29,15 @@ QtCore/QtEvent.mm \ QtCore/QtObject.mm \ QtCore/QtThread.mm \ QtGui/QtGuiApplication.mm \ QtGui/QtPaintDevice.mm \ + QtWidgets/QtAction.mm \ QtWidgets/QtApplication.mm \ QtWidgets/QtWidget.mm QMAKE_CXXFLAGS += $$system("objfw-config --cppflags --objcflags --cxxflags") QMAKE_CXXFLAGS_WARN_ON = -Wall \ -Werror \ -Wsemicolon-before-method-body \ -Wobjc-missing-property-synthesis LIBS += $$system("objfw-config --ldflags --libs") Index: QtCore/QtEvent.mm ================================================================== --- QtCore/QtEvent.mm +++ QtCore/QtEvent.mm @@ -21,11 +21,11 @@ */ #import "QtEvent.h" @implementation QtEvent -@synthesize qEvent = _eEvent; +@synthesize qEvent = _qEvent; + (int)registerEventType: (int)hint { return QEvent::registerEventType(hint); } Index: QtCore/QtObject.mm ================================================================== --- QtCore/QtObject.mm +++ QtCore/QtObject.mm @@ -88,10 +88,12 @@ void *pool = objc_autoreleasePoolPush(); for (QObject *qChild: qChildren) [children addObject: [[[QtObject alloc] initWithQObject: qChild] autorelease]]; + + [children makeImmutable]; objc_autoreleasePoolPop(pool); return children; } @@ -141,10 +143,12 @@ OFDataArray *dynamicPropertyName = [OFDataArray dataArray]; [dynamicPropertyName addItems: qDynamicPropertyName.data() count: qDynamicPropertyName.count()]; [dynamicPropertyNames addObject: dynamicPropertyName]; } + + [dynamicPropertyNames makeImmutable]; objc_autoreleasePoolPop(pool); return dynamicPropertyNames; } ADDED QtWidgets/QtAction.h Index: QtWidgets/QtAction.h ================================================================== --- QtWidgets/QtAction.h +++ QtWidgets/QtAction.h @@ -0,0 +1,65 @@ +/* + * 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 "QtObject.h" + +#include + +@class QtWidget; + +@interface QtAction: QtObject +@property (readonly) QAction *qAction; +@property bool autoRepeat; +@property (getter=isCheckable) bool checkable; +@property (getter=isChecked) bool checked; +@property (getter=isEnabled) bool enabled; +@property QFont font; +@property QIcon icon; +@property (copy) OFString *iconText; +@property (getter=isIconVisibleInMenu) bool iconVisibleInMenu; +@property QAction::MenuRole menuRole; +@property QAction::Priority priority; +@property QKeySequence shortcut; +@property Qt::ShortcutContext shortcutContext; +@property (copy) OFString *statusTip; +@property (copy) OFString *text; +@property (copy) OFString *toolTip; +@property (getter=isVisible) bool visible; +@property (copy) OFString *whatsThis; + +- initWithQAction: (QAction*)qAction; +- (QActionGroup*)actionGroup; +- (void)activate: (QAction::ActionEvent)event; +- (QList)associatedGraphicsWidgets; +- (OFArray OF_GENERIC(QtWidget*)*)associatedWidgets; +- (QVariant)data; +- (bool)isSeparator; +- (QMenu*)menu; +- (QtWidget*)parentWidget; +- (void)setActionGroup: (QActionGroup*)group; +- (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 ADDED QtWidgets/QtAction.mm Index: QtWidgets/QtAction.mm ================================================================== --- QtWidgets/QtAction.mm +++ QtWidgets/QtAction.mm @@ -0,0 +1,302 @@ +/* + * 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 "QtAction.h" +#import "QtWidget.h" + +#import "helpers.h" + +@implementation QtAction +- initWithQObject: (QObject*)qObject +{ + OF_INVALID_INIT_METHOD +} + +- initWithQAction: (QAction*)qAction +{ + return [super initWithQObject: qAction]; +} + +- (QAction*)qAction +{ + return qobject_cast(_qObject); +} + +- (bool)autoRepeat +{ + return [self qAction]->autoRepeat(); +} + +- (void)setAutoRepeat: (bool)autoRepeat +{ + [self qAction]->setAutoRepeat(autoRepeat); +} + +- (bool)isCheckable +{ + return [self qAction]->isCheckable(); +} + +- (void)setCheckable: (bool)checkable +{ + [self qAction]->setCheckable(checkable); +} + +- (bool)isChecked +{ + return [self qAction]->isChecked(); +} + +- (void)setChecked: (bool)checked +{ + [self qAction]->setChecked(checked); +} + +- (bool)isEnabled +{ + return [self qAction]->isEnabled(); +} + +- (void)setEnabled: (bool)enabled +{ + [self qAction]->setEnabled(enabled); +} + +- (QFont)font +{ + return [self qAction]->font(); +} + +- (void)setFont: (QFont)font +{ + [self qAction]->setFont(font); +} + +- (QIcon)icon +{ + return [self qAction]->icon(); +} + +- (void)setIcon: (QIcon)icon +{ + [self qAction]->setIcon(icon); +} + +- (OFString*)iconText +{ + return toOF([self qAction]->iconText()); +} + +- (void)setIconText: (OFString*)iconText +{ + [self qAction]->setIconText(toQt(iconText)); +} + +- (bool)isIconVisibleInMenu +{ + return [self qAction]->isIconVisibleInMenu(); +} + +- (void)setIconVisibleInMenu: (bool)iconVisibleInMenu +{ + [self qAction]->setIconVisibleInMenu(iconVisibleInMenu); +} + +- (QAction::MenuRole)menuRole +{ + return [self qAction]->menuRole(); +} + +- (void)setMenuRole: (QAction::MenuRole)menuRole +{ + [self qAction]->setMenuRole(menuRole); +} + +- (QAction::Priority)priority +{ + return [self qAction]->priority(); +} + +- (void)setPriority: (QAction::Priority)priority +{ + [self qAction]->setPriority(priority); +} + +- (QKeySequence)shortcut +{ + return [self qAction]->shortcut(); +} + +- (void)setShortcut: (QKeySequence)shortcut +{ + [self qAction]->setShortcut(shortcut); +} + +- (Qt::ShortcutContext)shortcutContext +{ + return [self qAction]->shortcutContext(); +} + +- (void)setShortcutContext: (Qt::ShortcutContext)shortcutContext +{ + [self qAction]->setShortcutContext(shortcutContext); +} + +- (OFString*)statusTip +{ + return toOF([self qAction]->statusTip()); +} + +- (void)setStatusTip: (OFString*)statusTip +{ + [self qAction]->setStatusTip(toQt(statusTip)); +} + +- (OFString*)text +{ + return toOF([self qAction]->text()); +} + +- (void)setText: (OFString*)text +{ + [self qAction]->setText(toQt(text)); +} + +- (OFString*)toolTip +{ + return toOF([self qAction]->toolTip()); +} + +- (void)setToolTip: (OFString*)toolTip +{ + [self qAction]->setToolTip(toQt(toolTip)); +} + +- (bool)isVisible +{ + return [self qAction]->isVisible(); +} + +- (void)setVisible: (bool)visible +{ + [self qAction]->setVisible(visible); +} + +- (OFString*)whatsThis +{ + return toOF([self qAction]->whatsThis()); +} + +- (void)setWhatsThis: (OFString*)whatsThis +{ + [self qAction]->setWhatsThis(toQt(whatsThis)); +} + +- (QActionGroup*)actionGroup +{ + return [self qAction]->actionGroup(); +} + +- (void)activate: (QAction::ActionEvent)event +{ + [self qAction]->activate(event); +} + +- (QList)associatedGraphicsWidgets +{ + return [self qAction]->associatedGraphicsWidgets(); +} + +- (OFArray OF_GENERIC(QtWidget*)*)associatedWidgets +{ + const QList &widgets = [self qAction]->associatedWidgets(); + OFMutableArray *ret = + [OFMutableArray arrayWithCapacity: widgets.count()]; + void *pool = objc_autoreleasePoolPush(); + + for (QWidget *widget: widgets) + [ret addObject: + [[[QtWidget alloc] initWithQWidget: widget] autorelease]]; + + [ret makeImmutable]; + + objc_autoreleasePoolPop(pool); + + return ret; +} + +- (QVariant)data +{ + return [self qAction]->data(); +} + +- (bool)isSeparator +{ + return [self qAction]->isSeparator(); +} + +- (QMenu*)menu +{ + return [self qAction]->menu(); +} + +- (QtWidget*)parentWidget +{ + return [[[QtWidget alloc] initWithQWidget: + [self qAction]->parentWidget()] autorelease]; +} + +- (void)setActionGroup: (QActionGroup*)group +{ + [self qAction]->setActionGroup(group); +} + +- (void)setMenu: (QMenu*)menu +{ + [self qAction]->setMenu(menu); +} + +- (void)setSeparator: (bool)isSeparator +{ + [self qAction]->setSeparator(isSeparator); +} + +- (void)setShortcuts: (const QList&)shortcuts +{ + [self qAction]->setShortcuts(shortcuts); +} + +- (void)setShortcutsWithStandardKey: (QKeySequence::StandardKey)key +{ + [self qAction]->setShortcuts(key); +} + +- (QList)shortcuts +{ + return [self qAction]->shortcuts(); +} + +- (bool)showStatusText: (QtWidget*)widget +{ + return [self qAction]->showStatusText([widget qWidget]); +} +@end Index: QtWidgets/QtWidget.h ================================================================== --- QtWidgets/QtWidget.h +++ QtWidgets/QtWidget.h @@ -22,10 +22,12 @@ #import "QtObject.h" #import "QtPaintDevice.h" #include + +@class QtAction; @interface QtWidget: QtObject @property (readonly) QWidget *qWidget; @property bool acceptDrops; @property (copy) OFString *accessibleDescription; @@ -84,15 +86,68 @@ @property double windowOpacity; @property (copy) OFString *windowTitle; @property (readonly) int x; @property (readonly) int y; -// TODO: Member functions - - initWithQWidget: (QWidget*)qWidget; +- (OFArray OF_GENERIC(QtAction*)*)actions; +- (void)activateWindow; +- (void)addAction: (QtAction*)action; +- (void)addActions: (OFArray OF_GENERIC(QtAction*)*)actions; +- (void)adjustSize; +- (QPalette::ColorRole)backgroundRole; +- (QBackingStore*)backingStore; +- (QtWidget*)childAt: (of_point_t)point; +- (void)clearFocus; +- (void)clearMask; +- (QMargins)contentsMargins; +- (of_rectangle_t)contentsRect; +- (WId)effectiveWinId; +- (void)ensurePolished; +- (QtWidget*)focusProxy; +- (QtWidget*)focusWidget; +- (QFontInfo)fontInfo; +- (QFontMetrics)fontMetrics; +- (QPalette::ColorRole)foregroundRole; +- (QPixmap)grabRectangle: (of_rectangle_t)rectangle; +- (void)grabGesture: (Qt::GestureType)gesture; +- (void)grabGesture: (Qt::GestureType)gesture + flags: (Qt::GestureFlags)flags; +- (void)grabKeyboard; +- (void)grabMouse; +- (void)grabMouseWithCursor: (const QCursor&)cursor; +- (int)grabShortcutWithKey: (const QKeySequence&)key; +- (int)grabShortcutWithKey: (const QKeySequence&)key + context: (Qt::ShortcutContext)context; +- (QGraphicsEffect*)graphicsEffect; +- (QGraphicsProxyWidget*)graphicsProxyWidget; +#ifdef QT_KEYPAD_NAVIGATION +- (bool)hasEditFocus; +#endif +- (bool)hasHeightForWidth; +- (int)heightForWidth: (int)w; +- (QVariant)queryInputMethod: (Qt::InputMethodQuery)query; +- (void)insertAction: (QtAction*)action + before: (QtAction*)before; +- (void)insertActions: (OFArray OF_GENERIC(QtAction*)*)actions + before: (QtAction*)before; +- (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 +// ... + - (void)unsetCursor; - (void)unsetLayoutDirection; - (void)unsetLocale; @end @interface QtWidget (QtPaintDevice) @end Index: QtWidgets/QtWidget.mm ================================================================== --- QtWidgets/QtWidget.mm +++ QtWidgets/QtWidget.mm @@ -19,10 +19,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import "QtWidget.h" +#import "QtAction.h" #import "helpers.h" #include #include @@ -31,10 +32,15 @@ + (void)initialize { if (self == [QtWidget class]) [self inheritMethodsFromClass: [QtPaintDevice class]]; } + +- initWithQObject: (QObject*)qObject +{ + OF_INVALID_INIT_METHOD +} - initWithQWidget: (QWidget*)qWidget { return [super initWithQObject: qWidget]; } @@ -546,6 +552,238 @@ - (int)y { return [self qWidget]->y(); } + +- (OFArray OF_GENERIC(QtAction*)*)actions +{ + const QList &actions = [self qWidget]->actions(); + OFMutableArray *ret = + [OFMutableArray arrayWithCapacity: actions.count()]; + void *pool = objc_autoreleasePoolPush(); + + for (QAction *action: actions) + [ret addObject: + [[[QtAction alloc] initWithQAction: action] autorelease]]; + + [ret makeImmutable]; + + objc_autoreleasePoolPop(pool); + + return ret; +} + +- (void)activateWindow +{ + [self qWidget]->activateWindow(); +} + +- (void)addAction: (QtAction*)action +{ + [self qWidget]->addAction([action qAction]); +} + +- (void)addActions: (OFArray OF_GENERIC(QtAction*)*)actions +{ + QList list; + + for (QtAction *action in actions) + list.append([action qAction]); + + [self qWidget]->addActions(list); +} + +- (void)adjustSize +{ + [self qWidget]->adjustSize(); +} + +- (QPalette::ColorRole)backgroundRole +{ + return [self qWidget]->backgroundRole(); +} + +- (QBackingStore*)backingStore +{ + return [self qWidget]->backingStore(); +} + +- (QtWidget*)childAt: (of_point_t)point +{ + return [[[QtWidget alloc] initWithQWidget: + [self qWidget]->childAt(toQt(point))] autorelease]; +} + +- (void)clearFocus +{ + return [self qWidget]->clearFocus(); +} + +- (void)clearMask +{ + [self qWidget]->clearMask(); +} + +- (QMargins)contentsMargins +{ + return [self qWidget]->contentsMargins(); +} + +- (of_rectangle_t)contentsRect +{ + return toOF([self qWidget]->contentsRect()); +} + +- (WId)effectiveWinId +{ + return [self qWidget]->effectiveWinId(); +} + +- (void)ensurePolished +{ + [self qWidget]->ensurePolished(); +} + +- (QtWidget*)focusProxy +{ + return [[[QtWidget alloc] initWithQWidget: + [self qWidget]->focusProxy()] autorelease]; +} + +- (QtWidget*)focusWidget +{ + return [[[QtWidget alloc] initWithQWidget: + [self qWidget]->focusWidget()] autorelease]; +} + +- (QFontInfo)fontInfo +{ + return [self qWidget]->fontInfo(); +} + +- (QFontMetrics)fontMetrics +{ + return [self qWidget]->fontMetrics(); +} + +- (QPalette::ColorRole)foregroundRole +{ + return [self qWidget]->foregroundRole(); +} + +- (QPixmap)grabRectangle: (of_rectangle_t)rectangle +{ + return [self qWidget]->grab(toQt(rectangle)); +} + +- (void)grabGesture: (Qt::GestureType)gesture +{ + [self qWidget]->grabGesture(gesture); +} + +- (void)grabGesture: (Qt::GestureType)gesture + flags: (Qt::GestureFlags)flags +{ + [self qWidget]->grabGesture(gesture, flags); +} + +- (void)grabKeyboard +{ + [self qWidget]->grabKeyboard(); +} + +- (void)grabMouse +{ + [self qWidget]->grabMouse(); +} + +- (void)grabMouseWithCursor: (const QCursor&)cursor +{ + [self qWidget]->grabMouse(cursor); +} + +- (int)grabShortcutWithKey: (const QKeySequence&)key +{ + return [self qWidget]->grabShortcut(key); +} + +- (int)grabShortcutWithKey: (const QKeySequence&)key + context: (Qt::ShortcutContext)context +{ + return [self qWidget]->grabShortcut(key, context); +} + +- (QGraphicsEffect*)graphicsEffect +{ + return [self qWidget]->graphicsEffect(); +} + +- (QGraphicsProxyWidget*)graphicsProxyWidget +{ + return [self qWidget]->graphicsProxyWidget(); +} + +#ifdef QT_KEYPAD_NAVIGATION +- (bool)hasEditFocus +{ + return [self qWidget]->hasEditFocus(); +} +#endif + +- (bool)hasHeightForWidth +{ + return [self qWidget]->hasHeightForWidth(); +} + +- (int)heightForWidth: (int)w +{ + return [self qWidget]->heightForWidth(w); +} + +- (QVariant)queryInputMethod: (Qt::InputMethodQuery)query +{ + return [self qWidget]->inputMethodQuery(query); +} + +- (void)insertAction: (QtAction*)action + before: (QtAction*)before +{ + [self qWidget]->insertAction([before qAction], [action qAction]); +} + +- (void)insertActions: (OFArray OF_GENERIC(QtAction*)*)actions + before: (QtAction*)before +{ + QList list; + + for (QtAction *action in actions) + list.append([action qAction]); + + [self qWidget]->insertActions([before qAction], list); +} + +- (bool)isAncestorOf: (QtWidget*)child +{ + return [self qWidget]->isAncestorOf([child qWidget]); +} + +- (bool)isEnabledTo: (QtWidget*)ancestor +{ + return [self qWidget]->isEnabledTo([ancestor qWidget]); +} + +- (bool)isHidden +{ + return [self qWidget]->isHidden(); +} + +- (bool)isVisibleTo: (QtWidget*)ancestor +{ + return [self qWidget]->isVisibleTo([ancestor qWidget]); +} + +- (bool)isWindow +{ + return [self qWidget]->isWindow(); +} @end