Update for QT6 support
This makes some necessary changes to get qt-light working under QT6: • Replace QSound (deprecated) with QSoundEffect • Replace QVariant datatype enums with QMetaTypes’ • Use new constructor for QVariants in propsetters
This commit is contained in:
parent
6a87e2863f
commit
b80d43f031
88
main.cpp
88
main.cpp
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <QtGui>
|
||||
#include <QtUiTools>
|
||||
#include <QGLWidget>
|
||||
#include <QtMultimedia/QSound>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QtMultimedia/QSoundEffect>
|
||||
#include <chicken.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -38,18 +38,17 @@ public slots:
|
|||
};
|
||||
|
||||
|
||||
class GLWidget: public QGLWidget
|
||||
{
|
||||
class OpenGLWidget: public QOpenGLWidget {
|
||||
void *thunk;
|
||||
|
||||
public:
|
||||
GLWidget(char *name, QWidget *parent, C_word proc) : QGLWidget(parent) {
|
||||
OpenGLWidget(char *name, QWidget *parent, C_word proc) : QOpenGLWidget(parent) {
|
||||
setObjectName(name);
|
||||
thunk = CHICKEN_new_gc_root();
|
||||
CHICKEN_gc_root_set(thunk, proc);
|
||||
}
|
||||
|
||||
~GLWidget() { CHICKEN_delete_gc_root(thunk); }
|
||||
~OpenGLWidget() { CHICKEN_delete_gc_root(thunk); }
|
||||
|
||||
protected:
|
||||
// Set up the rendering context, define display lists etc.:
|
||||
|
@ -65,9 +64,9 @@ protected:
|
|||
#define qtapplication QApplication *
|
||||
#define qtreceiver SimpleReceiver *
|
||||
#define qtwidget QWidget *
|
||||
#define qtpixmap QPixmap *
|
||||
#define qtpixmap QPixmap *
|
||||
#define qttimer QTimer *
|
||||
#define qtsound QSound *
|
||||
#define qtsound QSoundEffect *
|
||||
#define qttextedit QTextEdit *
|
||||
#define qtaction QAction *
|
||||
|
||||
|
@ -174,21 +173,28 @@ int qt_message(char *caption, char *text, QWidget *parent, char *b0, char *b1, c
|
|||
}
|
||||
|
||||
|
||||
#define propsetter(name, type) \
|
||||
#define propsetter(name, type, metatype) \
|
||||
___bool qt_set ## name ## property(QWidget *w, char *prop, type val) \
|
||||
{ \
|
||||
const QMetaObject *mo = w->metaObject(); \
|
||||
int i = mo->indexOfProperty(prop); \
|
||||
if(i == -1) return 0; \
|
||||
else return mo->property(i).write(w, val); \
|
||||
else return mo->property(i).write(w, QVariant(QMetaType(metatype), &val)); \
|
||||
}
|
||||
|
||||
|
||||
propsetter(string, char *)
|
||||
propsetter(bool, ___bool)
|
||||
propsetter(int, int)
|
||||
propsetter(float, double)
|
||||
propsetter(char, char)
|
||||
propsetter(bool, ___bool, QMetaType::Bool)
|
||||
propsetter(int, int, QMetaType::Int)
|
||||
propsetter(float, double, QMetaType::Double)
|
||||
propsetter(char, char, QMetaType::Char)
|
||||
|
||||
___bool qt_setstringproperty(QWidget *w, char *prop, const char* val)
|
||||
{
|
||||
const QMetaObject *mo = w->metaObject();
|
||||
int i = mo->indexOfProperty(prop);
|
||||
if(i == -1) return 0;
|
||||
else return mo->property(i).write(w, QVariant(val));
|
||||
}
|
||||
|
||||
|
||||
___bool qt_setpixmapproperty(QWidget *w, char *prop, qtpixmap val)
|
||||
|
@ -206,9 +212,9 @@ ___bool qt_setpointproperty(QWidget *w, char *prop, int *val)
|
|||
int i = mo->indexOfProperty(prop);
|
||||
if(i == -1) return 0;
|
||||
else {
|
||||
switch(mo->property(i).type()) {
|
||||
case QVariant::Point: return mo->property(i).write(w, QPoint(val[ 0 ], val[ 1 ]));
|
||||
case QVariant::Size: return mo->property(i).write(w, QSize(val[ 0 ], val[ 1 ]));
|
||||
switch(mo->property(i).typeId()) {
|
||||
case QMetaType::QPoint: return mo->property(i).write(w, QPoint(val[ 0 ], val[ 1 ]));
|
||||
case QMetaType::QSize: return mo->property(i).write(w, QSize(val[ 0 ], val[ 1 ]));
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
@ -221,9 +227,9 @@ ___bool qt_setpointfproperty(QWidget *w, char *prop, double *val)
|
|||
int i = mo->indexOfProperty(prop);
|
||||
if(i == -1) return 0;
|
||||
else {
|
||||
switch(mo->property(i).type()) {
|
||||
case QVariant::PointF: return mo->property(i).write(w, QPointF(val[ 0 ], val[ 1 ]));
|
||||
case QVariant::SizeF: return mo->property(i).write(w, QSizeF(val[ 0 ], val[ 1 ]));
|
||||
switch(mo->property(i).typeId()) {
|
||||
case QMetaType::QPointF: return mo->property(i).write(w, QPointF(val[ 0 ], val[ 1 ]));
|
||||
case QMetaType::QSizeF: return mo->property(i).write(w, QSizeF(val[ 0 ], val[ 1 ]));
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
@ -373,22 +379,22 @@ int qt_propertytype(qtwidget w, char *prop)
|
|||
|
||||
if(i == -1) return 0;
|
||||
else {
|
||||
switch(mo->property(i).type()) {
|
||||
case QVariant::Bool: return 1;
|
||||
case QVariant::Char: return 2;
|
||||
case QVariant::Double: return 3;
|
||||
case QVariant::Int:
|
||||
case QVariant::UInt: return 4;
|
||||
case QVariant::LongLong:
|
||||
case QVariant::ULongLong: return 3;
|
||||
case QVariant::String: return 5;
|
||||
case QVariant::Pixmap: return 6;
|
||||
case QVariant::PointF: return 7;
|
||||
case QVariant::RectF: return 8;
|
||||
case QVariant::SizeF: return 9;
|
||||
case QVariant::Point: return 10;
|
||||
case QVariant::Size: return 11;
|
||||
case QVariant::Rect: return 12;
|
||||
switch(mo->property(i).typeId()) {
|
||||
case QMetaType::Bool: return 1;
|
||||
case QMetaType::Char: return 2;
|
||||
case QMetaType::Double: return 3;
|
||||
case QMetaType::Int:
|
||||
case QMetaType::UInt: return 4;
|
||||
case QMetaType::LongLong:
|
||||
case QMetaType::ULongLong: return 3;
|
||||
case QMetaType::QString: return 5;
|
||||
case QMetaType::QPixmap: return 6;
|
||||
case QMetaType::QPointF: return 7;
|
||||
case QMetaType::QRectF: return 8;
|
||||
case QMetaType::QSizeF: return 9;
|
||||
case QMetaType::QPoint: return 10;
|
||||
case QMetaType::QSize: return 11;
|
||||
case QMetaType::QRect: return 12;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +402,7 @@ int qt_propertytype(qtwidget w, char *prop)
|
|||
|
||||
|
||||
const char *qt_classname(qtobject w) { return w->metaObject()->className(); }
|
||||
qtwidget qt_gl(char *name, qtwidget parent, C_word proc) { return new GLWidget(name, parent, proc); }
|
||||
qtwidget qt_gl(char *name, qtwidget parent, C_word proc) { return new OpenGLWidget(name, parent, proc); }
|
||||
void qt_update(qtwidget w) { w->update(); }
|
||||
|
||||
|
||||
|
@ -425,7 +431,11 @@ char *qt_listwidgetitem(qtwidget w, int i) {
|
|||
return qstrdata(((QListWidget *)w)->item(i)->text());
|
||||
}
|
||||
|
||||
qtsound qt_sound(char *filename) { return new QSound(filename); }
|
||||
qtsound qt_sound(char *filename) {
|
||||
QSoundEffect* sound = new QSoundEffect();
|
||||
sound->setSource(QUrl::fromLocalFile(filename));
|
||||
return sound;
|
||||
}
|
||||
void qt_play(qtsound s) { s->play(); }
|
||||
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue