+ createListItem, createListView, getObjectParent, LEListWidgetItem,

setParent -> setObjectParent
This commit is contained in:
Syping 2020-05-19 20:50:03 +02:00
parent ff28849d90
commit fcabd1685d
7 changed files with 216 additions and 33 deletions

View file

@ -31,9 +31,10 @@ LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent)
pushVariant("DeleteInstant", 0);
pushVariant("DeleteLater", 1);
pushFunction("delete", luaObjectDelete_p);
pushFunction("getParent", luaObjectParent_p);
pushFunction("connect", luaTriggerConnect_p);
pushFunction("disconnect", luaTriggerDisconnect_p);
pushFunction("getObjectParent", luaObjectGetParent_p);
pushFunction("setObjectParent", luaObjectSetParent_p);
pushFunction("luaEngineVersion", luaEngineVersion_p);
pushFunction("luaEnginePlatform", luaEnginePlatform_p);
}
@ -427,7 +428,7 @@ int LuaEngine::luaObjectDelete_p(lua_State *L_p)
return 0;
}
int LuaEngine::luaObjectParent_p(lua_State *L_p)
int LuaEngine::luaObjectGetParent_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
@ -439,6 +440,18 @@ int LuaEngine::luaObjectParent_p(lua_State *L_p)
return 0;
}
int LuaEngine::luaObjectSetParent_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *o_pointer = getPointer(L_p, 1);
void *p_pointer = getPointer(L_p, 2);
if (o_pointer != NULL && p_pointer != NULL && ((QObject*)o_pointer)->inherits("QObject") && ((QObject*)p_pointer)->inherits("QObject")) {
((QObject*)o_pointer)->setParent((QObject*)p_pointer);
}
}
return 0;
}
int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 3) {
@ -455,7 +468,7 @@ int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), getVariant(L_p, 3).toString());
engine->setProperty(funcStorage.toUtf8().data(), getVariant(L_p, 3));
QObject::connect(object, signal, engine, slot);
}
}
@ -480,7 +493,7 @@ int LuaEngine::luaTriggerDisconnect_p(lua_State *L_p)
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), QVariant());
engine->setProperty(funcStorage.toUtf8().data(), QVariant());
QObject::disconnect(object, signal, engine, slot);
}
}
@ -494,6 +507,6 @@ void LuaEngine::luaTriggerSlot_p()
QMetaMethod signal = sender()->metaObject()->method(senderSignalIndex());
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << sender() << "_" << signal.name();
QString luaConnectFunc = getVariant(funcStorage.toUtf8().data()).toString();
QString luaConnectFunc = property(funcStorage.toUtf8().data()).toString();
executeLuaFunction(luaConnectFunc.toUtf8().data(), QVariant::fromValue((void*)sender()));
}

View file

@ -82,7 +82,8 @@ private:
static int luaEngineVersion_p(lua_State *L_p);
static int luaEnginePlatform_p(lua_State *L_p);
static int luaObjectDelete_p(lua_State *L_p);
static int luaObjectParent_p(lua_State *L_p);
static int luaObjectGetParent_p(lua_State *L_p);
static int luaObjectSetParent_p(lua_State *L_p);
static int luaTriggerConnect_p(lua_State *L_p);
static int luaTriggerDisconnect_p(lua_State *L_p);

View file

@ -0,0 +1,38 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2020 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "LEListWidgetItem.h"
LEListWidgetItem::LEListWidgetItem(const QString &text, QListWidget *parent)
{
item_p.setText(text);
parent->addItem(&item_p);
QObject::connect(parent, &QListWidget::currentItemChanged, this, &LEListWidgetItem::listWidgetItemChanged);
}
QListWidgetItem* LEListWidgetItem::item()
{
return &item_p;
}
void LEListWidgetItem::listWidgetItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
Q_UNUSED(previous)
if (current == &item_p) {
emit selected();
}
}

View file

@ -0,0 +1,45 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2020 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifndef LELISTWIDGETITEM_H
#define LELISTWIDGETITEM_H
#include "LuaEngineGui_global.h"
#include "LuaEngine.h"
#include <QListWidgetItem>
#include <QListWidget>
#include <QObject>
#include <QString>
class LUAENGINEGUISHARED_EXPORT LEListWidgetItem : public QObject
{
Q_OBJECT
public:
LEListWidgetItem(const QString &text, QListWidget *parent = nullptr);
QListWidgetItem* item();
private slots:
void listWidgetItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
private:
QListWidgetItem item_p;
signals:
void selected();
};
#endif // LELISTWIDGETITEM_H

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018-2019 Syping
* Copyright (C) 2018-2020 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
*****************************************************************************/
#include "LuaEngineRegistry.h"
#include "LEListWidgetItem.h"
#include "LuaEngineGui.h"
#include <QPlainTextEdit>
#include <QStackedWidget>
@ -34,6 +35,7 @@
#include <QVBoxLayout>
#include <QFileDialog>
#include <QSizePolicy>
#include <QListWidget>
#include <QTabWidget>
#include <QEventLoop>
#include <QTextEdit>
@ -102,6 +104,7 @@ void LuaEngineGui::pushClass(lua_State *L_p)
pushFunction(L_p, "setWidgetLayout", setWidgetLayout);
pushFunction(L_p, "setWidgetMaximum", setWidgetMaximum);
pushFunction(L_p, "setWidgetMinimum", setWidgetMinimum);
pushFunction(L_p, "setWidgetParent", setWidgetParent);
pushFunction(L_p, "setWidgetReadOnly", setWidgetReadOnly);
pushFunction(L_p, "setWidgetSize", setWidgetSize);
pushFunction(L_p, "setWidgetValue", setWidgetValue);
@ -137,6 +140,10 @@ void LuaEngineGui::pushClass(lua_State *L_p)
// Line Edit
pushFunction(L_p, "createLineEdit", createLineEdit);
// List View
pushFunction(L_p, "createListItem", createListItem);
pushFunction(L_p, "createListView", createListView);
// Main Window
pushFunction(L_p, "createMainWindow", createMainWindow);
pushFunction(L_p, "createCentralWidget", createCentralWidget);
@ -484,7 +491,14 @@ int LuaEngineGui::setObjectImage(lua_State *L_p)
pixelRatio = newPixelRatio;
}
}
if (((QObject*)pointer)->inherits("QAction")) {
if (((QObject*)pointer)->inherits("LEListWidgetItem")) {
QPixmap objectImage(imagePath);
objectImage.setDevicePixelRatio(pixelRatio);
QIcon objectIcon;
objectIcon.addPixmap(objectImage);
((LEListWidgetItem*)pointer)->item()->setIcon(objectIcon);
}
else if (((QObject*)pointer)->inherits("QAction")) {
QPixmap objectImage(imagePath);
objectImage.setDevicePixelRatio(pixelRatio);
QIcon objectIcon;
@ -535,7 +549,10 @@ int LuaEngineGui::setObjectText(lua_State *L_p)
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QAction")) {
if (((QObject*)pointer)->inherits("LEListWidgetItem")) {
((LEListWidgetItem*)pointer)->item()->setText(getVariant(L_p, 2).toString());
}
else if (((QObject*)pointer)->inherits("QAction")) {
((QAction*)pointer)->setText(getVariant(L_p, 2).toString());
}
else if (((QObject*)pointer)->inherits("QCheckBox")) {
@ -621,26 +638,35 @@ int LuaEngineGui::setWidgetFixed(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
bool isFixed = true;
if (getArgumentCount(L_p) >= 2) {
isFixed = getVariant(L_p, 2).toBool();
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QToolBar")) {
bool isFixed = true;
if (getArgumentCount(L_p) >= 2) {
isFixed = getVariant(L_p, 2).toBool();
}
((QToolBar*)pointer)->setMovable(!isFixed);
}
((QObject*)pointer)->setProperty("isFixed", isFixed);
QVariant isSizeSet = ((QObject*)pointer)->property("isSizeSet");
if (isFixed && ((QWidget*)pointer)->isVisible()) {
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint());
else if (((QObject*)pointer)->inherits("QWidget")) {
bool isFixed = true;
if (getArgumentCount(L_p) >= 2) {
isFixed = getVariant(L_p, 2).toBool();
}
((QObject*)pointer)->setProperty("isFixed", isFixed);
QVariant isSizeSet = ((QObject*)pointer)->property("isSizeSet");
if (isFixed && ((QWidget*)pointer)->isVisible()) {
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint());
}
else if (isFixed && (isSizeSet.type() == QVariant::Bool && isSizeSet.toBool())) {
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->size());
((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->size());
}
else if (((QWidget*)pointer)->isVisible()) {
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
}
return 0;
}
else if (isFixed && (isSizeSet.type() == QVariant::Bool && isSizeSet.toBool())) {
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->size());
((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->size());
}
else if (((QWidget*)pointer)->isVisible()) {
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
}
return 0;
}
}
return 0;
@ -651,7 +677,10 @@ int LuaEngineGui::setWidgetImageSize(lua_State *L_p)
if (getArgumentCount(L_p) >= 3) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QPushButton")) {
if (((QObject*)pointer)->inherits("QListWidget")) {
((QListWidget*)pointer)->setIconSize(QSize(getVariant(L_p, 2).toInt(), getVariant(L_p, 3).toInt()));
}
else if (((QObject*)pointer)->inherits("QPushButton")) {
((QPushButton*)pointer)->setIconSize(QSize(getVariant(L_p, 2).toInt(), getVariant(L_p, 3).toInt()));
}
else if (((QObject*)pointer)->inherits("QToolBar")) {
@ -704,6 +733,18 @@ int LuaEngineGui::setWidgetMinimum(lua_State *L_p)
return 0;
}
int LuaEngineGui::setWidgetParent(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *o_pointer = getPointer(L_p, 1);
void *p_pointer = getPointer(L_p, 2);
if (o_pointer != NULL && p_pointer != NULL && ((QObject*)o_pointer)->inherits("QWidget") && ((QObject*)p_pointer)->inherits("QWidget")) {
((QWidget*)o_pointer)->setParent((QWidget*)p_pointer);
}
}
return 0;
}
int LuaEngineGui::setWidgetReadOnly(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
@ -1022,6 +1063,43 @@ int LuaEngineGui::createLineEdit(lua_State *L_p)
return 1;
}
int LuaEngineGui::createListItem(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QListWidget")) {
LEListWidgetItem *listWidgetItem = new LEListWidgetItem(getVariant(L_p, 1).toString(), (QListWidget*)pointer);
listWidgetItem->setObjectName(nameForPointer(listWidgetItem));
pushPointer(L_p, listWidgetItem);
return 1;
}
}
}
return 0;
}
int LuaEngineGui::createListView(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QListWidget::SelectionMode selectionMode = QListWidget::SingleSelection;
if (getArgumentCount(L_p) >= 1) {
lpForPointer(getPointer(L_p, 1), &layout, &parent);
if (getArgumentCount(L_p) >= 2) {
selectionMode = (QListWidget::SelectionMode)getVariant(L_p, 2).toInt();
}
}
QListWidget *listWidget = new QListWidget(parent);
listWidget->setObjectName(nameForPointer(listWidget));
listWidget->setSelectionMode(selectionMode);
if (layout != nullptr) {
layout->addWidget(listWidget);
}
pushPointer(L_p, listWidget);
return 1;
}
int LuaEngineGui::createMainWindow(lua_State *L_p)
{
QWidget *parent = nullptr;
@ -1311,15 +1389,18 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
int LuaEngineGui::createToolBar(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
Qt::ToolBarArea toolBarArea = Qt::TopToolBarArea;
if (getArgumentCount(L_p) >= 2) {
toolBarArea = (Qt::ToolBarArea)getVariant(L_p, 2).toInt();
if (getArgumentCount(L_p) >= 3) {
toolBarArea = (Qt::ToolBarArea)getVariant(L_p, 3).toInt();
}
QToolBar *toolBar = new QToolBar((QWidget*)pointer);
toolBar->setObjectName(nameForPointer(toolBar));
toolBar->setWindowTitle(getVariant(L_p, 1).toString());
toolBar->setFloatable(false);
toolBar->setMovable(false);
((QMainWindow*)pointer)->addToolBar(toolBarArea, toolBar);
pushPointer(L_p, toolBar);
return 1;

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018-2019 Syping
* Copyright (C) 2018-2020 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -50,6 +50,7 @@ public:
static int setWidgetLayout(lua_State *L_p);
static int setWidgetMaximum(lua_State *L_p);
static int setWidgetMinimum(lua_State *L_p);
static int setWidgetParent(lua_State *L_p);
static int setWidgetReadOnly(lua_State *L_p);
static int setWidgetSize(lua_State *L_p);
static int setWidgetValue(lua_State *L_p);
@ -66,6 +67,8 @@ public:
static int createLabel(lua_State *L_p);
static int createLayout(lua_State *L_p);
static int createLineEdit(lua_State *L_p);
static int createListItem(lua_State *L_p);
static int createListView(lua_State *L_p);
static int createMainWindow(lua_State *L_p);
static int createMenu(lua_State *L_p);
static int createMenuBar(lua_State *L_p);

View file

@ -40,9 +40,11 @@ INCLUDEPATH += \
../luaenginecore/luaengine
SOURCES += \
luaengine/LEListWidgetItem.cpp \
luaengine/LuaEngineGui.cpp
HEADERS += \
luaengine/LEListWidgetItem.h \
luaengine/LuaEngineGui.h \
luaengine/LuaEngineGui_global.h