Index: src/QtGui/QtPaintDevice.h ================================================================== --- src/QtGui/QtPaintDevice.h +++ src/QtGui/QtPaintDevice.h @@ -49,11 +49,11 @@ @end namespace ObjQt { static OF_INLINE QPaintDevice * -toQt(QtPaintDevice *paintDevice) +toQt(id paintDevice) { return [paintDevice qPaintDevice]; } } Index: src/QtWidgets/Makefile ================================================================== --- src/QtWidgets/Makefile +++ src/QtWidgets/Makefile @@ -4,11 +4,12 @@ STATIC_LIB_NOINST = ${QTWIDGETS_A} SRCS = QtAbstractButton.mm \ QtAction.mm \ QtApplication.mm \ - QtPushButton.mm \ + QtGraphicsWidget.mm \ + QtPushButton.mm \ QtWidget.mm include ../../buildsys.mk CPPFLAGS += -I. -I../QtCore -I../QtGui -I../common Index: src/QtWidgets/QtAbstractButton.mm ================================================================== --- src/QtWidgets/QtAbstractButton.mm +++ src/QtWidgets/QtAbstractButton.mm @@ -129,11 +129,11 @@ return toOF(toQt(self)->iconSize()); } - (void)setIconSize: (of_dimension_t)iconSize { - toQt(self)->setIconSize(toQt(iconSize)); + toQt(self)->setIconSize(toQt(iconSize).toSize()); } - (QKeySequence)shortcut { return toQt(self)->shortcut(); Index: src/QtWidgets/QtApplication.mm ================================================================== --- src/QtWidgets/QtApplication.mm +++ src/QtWidgets/QtApplication.mm @@ -79,11 +79,11 @@ return toOF(toQt(self)->globalStrut()); } - (void)setGlobalStrut: (of_dimension_t)globalStrut { - toQt(self)->setGlobalStrut(toQt(globalStrut)); + toQt(self)->setGlobalStrut(toQt(globalStrut).toSize()); } - (int)keyboardInputInterval { return toQt(self)->keyboardInputInterval(); ADDED src/QtWidgets/QtGraphicsWidget.h Index: src/QtWidgets/QtGraphicsWidget.h ================================================================== --- /dev/null +++ src/QtWidgets/QtGraphicsWidget.h @@ -0,0 +1,113 @@ +/* + * 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 + +#import "QtAction.h" +#import "QtObject.h" // TODO: Remove + +// TODO: Remove once QtGraphicsObject is bound +@interface QtGraphicsObject: QtObject +@end + +@interface QtGraphicsWidget: QtGraphicsObject +@property (readonly, nonatomic) QGraphicsWidget *qGraphicsWidget; +@property (nonatomic) bool autoFillBackground; +@property (nonatomic) Qt::FocusPolicy focusPolicy; +@property (nonatomic) of_rectangle_t geometry; +@property (nonatomic) QGraphicsLayout *layout; +@property (nonatomic) Qt::LayoutDirection layoutDirection; +@property (nonatomic) of_dimension_t maximumSize; +@property (nonatomic) of_dimension_t minimumSize; +@property (nonatomic) QPalette palette; +@property (nonatomic) of_dimension_t preferredSize; +@property (readonly, nonatomic) of_dimension_t size; +@property (nonatomic) QSizePolicy sizePolicy; +@property (nonatomic) Qt::WindowFlags windowFlags; +@property (copy, nonatomic) OFString *windowTitle; +@property (readonly, nonatomic) OFArray OF_GENERIC(QtAction *) *actions; +@property (readonly, nonatomic) bool isActiveWindow; +@property (nonatomic) QStyle *style; +@property (readonly, nonatomic) of_rectangle_t windowFrameGeometry; +@property (readonly, nonatomic) of_rectangle_t windowFrameRect; + +- initWithQObject: (QObject *)qObject OF_UNAVAILABLE; +- initWithQGraphicsWidget: (QGraphicsWidget *)qGraphicsWidget + OF_DESIGNATED_INITIALIZER; +- (void)addAction: (QtAction *)action; +- (void)addActions: (OFArray OF_GENERIC(QtAction *) *)actions; +- (void)adjustSize; +- (QtGraphicsWidget *)focusWidget; +- (void)getWindowFrameMarginsWithLeft: (qreal *)left + top: (qreal *)top + right: (qreal *)right + bottom: (qreal *)bottom; +- (void)setWindowFrameMarginsWithLeft: (qreal)left + top: (qreal)top + right: (qreal)right + bottom: (qreal)bottom; +- (void)insertAction: (QtAction *)action + before: (QtAction *)before; +- (void)insertActions: (OFArray OF_GENERIC(QtAction *) *)actions + before: (QtAction *)before; +- (void)paintWindowFrameWithPainter: (QPainter *)painter + option: (const QStyleOptionGraphicsItem *)option + widget: (QtWidget *)widget; +- (void)releaseShortcut: (int)ID; +- (void)removeAction: (QtAction *)action; +- (void)resizeTo: (of_dimension_t)size; +- (void)setAttribute: (Qt::WidgetAttribute)attribute + to: (bool)on; +- (void)setContentsMarginsWithLeft: (qreal)left + top: (qreal)top + right: (qreal)right + bottom: (qreal)bottom; +- (void)setAutoRepeat: (bool)enabled + forShortcut: (int)ID; +- (void)setEnabled: (bool)enabled + forShortcut: (int)ID; +- (bool)testAttribute: (Qt::WidgetAttribute)attribute; +- (void)unsetLayoutDirection; +- (void)unsetWindowFrameMargins; +@end + +namespace ObjQt { + +static OF_INLINE QtGraphicsWidget * +toOF(QGraphicsWidget *qGraphicsWidget) +{ + if (qGraphicsWidget == NULL) + return nil; + + return [[[QtGraphicsWidget alloc] + initWithQGraphicsWidget: qGraphicsWidget] autorelease]; +} + +static OF_INLINE QGraphicsWidget * +toQt(QtGraphicsWidget *graphicsWidget) +{ + return [graphicsWidget qGraphicsWidget]; +} + +} ADDED src/QtWidgets/QtGraphicsWidget.mm Index: src/QtWidgets/QtGraphicsWidget.mm ================================================================== --- /dev/null +++ src/QtWidgets/QtGraphicsWidget.mm @@ -0,0 +1,338 @@ +/* + * 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. + */ + +#include "QtGraphicsWidget.h" +#import "OFString+QString.h" + +#import "helpers.h" + +using ObjQt::toOF; +using ObjQt::toQt; + +@implementation QtGraphicsObject +@end + +@implementation QtGraphicsWidget + +- initWithQObject: (QObject *)qObject +{ + OF_INVALID_INIT_METHOD +} + +- initWithQGraphicsWidget: (QGraphicsWidget *)qGraphicsWidget +{ + return [super initWithQObject: qGraphicsWidget]; +} + +- (QGraphicsWidget *)qGraphicsWidget +{ + return dynamic_cast([self qObject]); +} + +- (bool)autoFillBackground +{ + return toQt(self)->autoFillBackground(); +} + +- (void)setAutoFillBackground: (bool)autoFillBackground +{ + toQt(self)->setAutoFillBackground(autoFillBackground); +} + +- (Qt::FocusPolicy)focusPolicy +{ + return toQt(self)->focusPolicy(); +} + +- (void)setFocusPolicy: (Qt::FocusPolicy)focusPolicy +{ + toQt(self)->setFocusPolicy(focusPolicy); +} + +- (of_rectangle_t)geometry +{ + return toOF(toQt(self)->geometry()); +} + +- (void)setGeometry: (of_rectangle_t)geometry +{ + toQt(self)->setGeometry(toQt(geometry)); +} + +- (QGraphicsLayout *)layout +{ + return toQt(self)->layout(); +} + +- (void)setLayout: (QGraphicsLayout *)layout +{ + toQt(self)->setLayout(layout); +} + +- (Qt::LayoutDirection)layoutDirection +{ + return toQt(self)->layoutDirection(); +} + +- (void)setLayoutDirection: (Qt::LayoutDirection)layoutDirection +{ + toQt(self)->setLayoutDirection(layoutDirection); +} + +- (of_dimension_t)maximumSize +{ + return toOF(toQt(self)->maximumSize()); +} + +- (void)setMaximumSize: (of_dimension_t)maximumSize +{ + toQt(self)->setMaximumSize(toQt(maximumSize)); +} + +- (of_dimension_t)minimumSize +{ + return toOF(toQt(self)->minimumSize()); +} + +- (void)setMinimumSize: (of_dimension_t)minimumSize +{ + toQt(self)->setMinimumSize(toQt(minimumSize)); +} + +- (QPalette)palette +{ + return toQt(self)->palette(); +} + +- (void)setPalette: (QPalette)palette +{ + toQt(self)->setPalette(palette); +} + +- (of_dimension_t)preferredSize +{ + return toOF(toQt(self)->preferredSize()); +} + +- (void)setPreferredSize: (of_dimension_t)preferredSize +{ + toQt(self)->setPreferredSize(toQt(preferredSize)); +} + +- (of_dimension_t)size +{ + return toOF(toQt(self)->size()); +} + +- (QSizePolicy)sizePolicy +{ + return toQt(self)->sizePolicy(); +} + +- (void)setSizePolicy: (QSizePolicy)sizePolicy +{ + toQt(self)->setSizePolicy(sizePolicy); +} + +- (Qt::WindowFlags)windowFlags +{ + return toQt(self)->windowFlags(); +} + +- (void)setWindowFlags: (Qt::WindowFlags)windowFlags +{ + toQt(self)->setWindowFlags(windowFlags); +} + +- (OFString *)windowTitle +{ + return toOF(toQt(self)->windowTitle()); +} + +- (void)setWindowTitle: (OFString *)windowTitle +{ + toQt(self)->setWindowTitle(toQt(windowTitle)); +} + +- (OFArray OF_GENERIC(QtAction *) *)actions +{ + const QList &actions = toQt(self)->actions(); + OFMutableArray *ret = + [OFMutableArray arrayWithCapacity: actions.count()]; + void *pool = objc_autoreleasePoolPush(); + + for (QAction *action: actions) + [ret addObject: toOF(action)]; + + [ret makeImmutable]; + + objc_autoreleasePoolPop(pool); + + return ret; +} + +- (bool)isActiveWindow +{ + return toQt(self)->isActiveWindow(); +} + +- (QStyle *)style +{ + return toQt(self)->style(); +} + +- (void)setStyle: (QStyle *)style +{ + toQt(self)->setStyle(style); +} + +- (of_rectangle_t)windowFrameGeometry +{ + return toOF(toQt(self)->windowFrameGeometry()); +} + +- (of_rectangle_t)windowFrameRect +{ + return toOF(toQt(self)->windowFrameRect()); +} + +- (void)addAction: (QtAction *)action +{ + toQt(self)->addAction(toQt(action)); +} + +- (void)addActions: (OFArray OF_GENERIC(QtAction *) *)actions +{ + QList list; + + for (QtAction *action in actions) + list.append(toQt(action)); + + toQt(self)->addActions(list); +} + +- (void)adjustSize +{ + toQt(self)->adjustSize(); +} + +- (QtGraphicsWidget *)focusWidget +{ + return toOF(toQt(self)->focusWidget()); +} + +- (void)getWindowFrameMarginsWithLeft: (qreal *)left + top: (qreal *)top + right: (qreal *)right + bottom: (qreal *)bottom +{ + toQt(self)->getWindowFrameMargins(left, top, right, bottom); +} + +- (void)setWindowFrameMarginsWithLeft: (qreal)left + top: (qreal)top + right: (qreal)right + bottom: (qreal)bottom +{ + toQt(self)->setWindowFrameMargins(left, top, right, bottom); +} + +- (void)insertAction: (QtAction *)action + before: (QtAction *)before +{ + 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(toQt(action)); + + toQt(self)->insertActions(toQt(before), list); +} + +- (void)paintWindowFrameWithPainter: (QPainter *)painter + option: (const QStyleOptionGraphicsItem *)option + widget: (QtWidget *)widget +{ + toQt(self)->paintWindowFrame(painter, option, toQt(widget)); +} + +- (void)releaseShortcut: (int)ID +{ + toQt(self)->releaseShortcut(ID); +} + +- (void)removeAction: (QtAction *)action +{ + toQt(self)->removeAction(toQt(action)); +} + +- (void)resizeTo: (of_dimension_t)size +{ + toQt(self)->resize(toQt(size)); +} + +- (void)setAttribute: (Qt::WidgetAttribute)attribute + to: (bool)on +{ + toQt(self)->setAttribute(attribute, on); +} + +- (void)setContentsMarginsWithLeft: (qreal)left + top: (qreal)top + right: (qreal)right + bottom: (qreal)bottom +{ + toQt(self)->setContentsMargins(left, top, right, bottom); +} + +- (void)setAutoRepeat: (bool)enabled + forShortcut: (int)ID +{ + toQt(self)->setShortcutAutoRepeat(ID, enabled); +} + +- (void)setEnabled: (bool)enabled + forShortcut: (int)ID +{ + toQt(self)->setShortcutEnabled(ID, enabled); +} + +- (bool)testAttribute: (Qt::WidgetAttribute)attribute +{ + return toQt(self)->testAttribute(attribute); +} + +- (void)unsetLayoutDirection +{ + toQt(self)->unsetLayoutDirection(); +} + +- (void)unsetWindowFrameMargins +{ + toQt(self)->unsetWindowFrameMargins(); +} +@end Index: src/QtWidgets/QtWidget.mm ================================================================== --- src/QtWidgets/QtWidget.mm +++ src/QtWidgets/QtWidget.mm @@ -100,11 +100,11 @@ return toOF(toQt(self)->baseSize()); } - (void)setBaseSize: (of_dimension_t)baseSize { - toQt(self)->setBaseSize(toQt(baseSize)); + toQt(self)->setBaseSize(toQt(baseSize).toSize()); } - (of_rectangle_t)childrenRect { return toOF(toQt(self)->childrenRect()); @@ -195,11 +195,11 @@ return toOF(toQt(self)->geometry()); } - (void)setGeometry: (of_rectangle_t)geometry { - toQt(self)->setGeometry(toQt(geometry)); + toQt(self)->setGeometry(toQt(geometry).toRect()); } - (int)height { return toQt(self)->height(); @@ -270,11 +270,11 @@ return toOF(toQt(self)->maximumSize()); } - (void)setMaximumSize: (of_dimension_t)maximumSize { - toQt(self)->setMaximumSize(toQt(maximumSize)); + toQt(self)->setMaximumSize(toQt(maximumSize).toSize()); } - (int)maximumWidth { return toQt(self)->maximumWidth(); @@ -305,11 +305,11 @@ return toOF(toQt(self)->minimumSize()); } - (void)setMinimumSize: (of_dimension_t)minimumSize { - toQt(self)->setMinimumSize(toQt(minimumSize)); + toQt(self)->setMinimumSize(toQt(minimumSize).toSize()); } - (of_dimension_t)minimumSizeHint { return toOF(toQt(self)->minimumSizeHint()); @@ -375,11 +375,11 @@ return toOF(toQt(self)->size()); } - (void)resizeTo: (of_dimension_t)size { - toQt(self)->resize(toQt(size)); + toQt(self)->resize(toQt(size).toSize()); } - (of_dimension_t)sizeHint { return toOF(toQt(self)->sizeHint()); @@ -390,11 +390,11 @@ return toOF(toQt(self)->sizeIncrement()); } - (void)setSizeIncrement: (of_dimension_t)sizeIncrement { - toQt(self)->setSizeIncrement(toQt(sizeIncrement)); + toQt(self)->setSizeIncrement(toQt(sizeIncrement).toSize()); } - (QSizePolicy)sizePolicy { return toQt(self)->sizePolicy(); @@ -672,11 +672,11 @@ return toQt(self)->foregroundRole(); } - (QPixmap)grabRectangle: (of_rectangle_t)rectangle { - return toQt(self)->grab(toQt(rectangle)); + return toQt(self)->grab(toQt(rectangle).toRect()); } - (void)grabGesture: (Qt::GestureType)gesture { toQt(self)->grabGesture(gesture); @@ -903,11 +903,11 @@ renderFlags); } - (void)repaintInRectangle: (of_rectangle_t)rect { - toQt(self)->repaint(toQt(rect)); + toQt(self)->repaint(toQt(rect).toRect()); } - (void)repaintInRegion: (const QRegion &)region { toQt(self)->repaint(region); @@ -931,11 +931,11 @@ - (void)scrollRight: (int)dx down: (int)dy inRectangle: (of_rectangle_t)rect { - toQt(self)->scroll(dx, dy, toQt(rect)); + toQt(self)->scroll(dx, dy, toQt(rect).toRect()); } - (void)setAttribute: (Qt::WidgetAttribute)attribute to: (bool)on { @@ -954,11 +954,11 @@ toQt(self)->setFixedHeight(height); } - (void)setFixedSize: (of_dimension_t)size { - toQt(self)->setFixedSize(toQt(size)); + toQt(self)->setFixedSize(toQt(size).toSize()); } - (void)setFixedWidth: (int)width { toQt(self)->setFixedWidth(width); @@ -1062,11 +1062,11 @@ toQt(self)->ungrabGesture(gesture); } - (void)updateInRectangle: (of_rectangle_t)rect { - toQt(self)->update(toQt(rect)); + toQt(self)->update(toQt(rect).toRect()); } - (void)updateInRegion: (const QRegion &)region { toQt(self)->update(region); Index: src/common/helpers.h ================================================================== --- src/common/helpers.h +++ src/common/helpers.h @@ -50,26 +50,39 @@ toOF(const QSize &qSize) { return of_dimension(qSize.width(), qSize.height()); } -static OF_INLINE QSize +static OF_INLINE of_dimension_t +toOF(const QSizeF &qSizeF) +{ + return of_dimension(qSizeF.width(), qSizeF.height()); +} + +static OF_INLINE QSizeF toQt(const of_dimension_t &dimension) { - return QSize(dimension.width, dimension.height); + return QSizeF(dimension.width, dimension.height); } static OF_INLINE of_rectangle_t toOF(const QRect &qRect) { return of_rectangle(qRect.x(), qRect.y(), qRect.width(), qRect.height()); } -static OF_INLINE QRect +static OF_INLINE of_rectangle_t +toOF(const QRectF &qRectF) +{ + return of_rectangle(qRectF.x(), qRectF.y(), + qRectF.width(), qRectF.height()); +} + +static OF_INLINE QRectF toQt(const of_rectangle_t &rectangle) { - return QRect(rectangle.origin.x, rectangle.origin.y, + return QRectF(rectangle.origin.x, rectangle.origin.y, rectangle.size.width, rectangle.size.height); } }