improvements

This commit is contained in:
Syping 2018-08-25 00:55:55 +02:00
parent ec4fb13212
commit b8a5843464
7 changed files with 96 additions and 1 deletions

View file

@ -46,6 +46,7 @@ function main()
layoutAddWidget(mainLayout, pushButton1) layoutAddWidget(mainLayout, pushButton1)
connect(pushButton1, "clicked()", "showDialog") connect(pushButton1, "clicked()", "showDialog")
setWidgetFixedSize(mainWindow)
showWidget(mainWindow, ShowNormal) showWidget(mainWindow, ShowNormal)
return GuiExecuted return GuiExecuted
end end
@ -70,6 +71,7 @@ function showDialog(pushButton)
local dialogButton = createPushButton("Close", dialog) local dialogButton = createPushButton("Close", dialog)
layoutAddWidget(buttonLayout, dialogButton) layoutAddWidget(buttonLayout, dialogButton)
connect(dialogButton, "clicked()", "closeDialog") connect(dialogButton, "clicked()", "closeDialog")
setWidgetFixedSize(dialog)
executeWidget(dialog) executeWidget(dialog)
delete(dialog, DeleteInstant) delete(dialog, DeleteInstant)
end end

49
src/luaengineapp/edit.lua Normal file
View file

@ -0,0 +1,49 @@
--[[
******************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018 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.
******************************************************************************
--]]
local currentFile
local mainWindow
local textEditor
function main()
mainWindow = createMainWindow()
local mainWidget = createCentralWidget(mainWindow)
local mainLayout = createLayout(VerticalLayout, mainWidget)
local menuBar = createMenuBar(mainWindow)
local menuFile = createMenu("File", menuBar)
local menuEntryNew = createMenuEntry("New", menuFile)
local menuEntryOpen = createMenuEntry("Open...", menuFile)
connect(menuEntrySave, "triggered()", "editorOpen")
local menuEntrySave = createMenuEntry("Save...", menuFile)
connect(menuEntrySave, "triggered()", "editorSave")
local menuEntrySaveAs = createMenuEntry("Save as...", menuFile)
connect(menuEntrySaveAs, "triggered()", "editorSaveAs")
local menuEntryExit = createMenuEntry("Exit", menuFile)
connect(menuEntryExit, "triggered()", "editorClose")
local menuHelp = createMenu("Help", menuBar)
local menuEntryAbout = createMenuEntry("About LE Text Editor", menuHelp)
connect(menuEntryAbout, "triggered()", "editorAboutBox")
textEditor = createTextEdit("", mainWidget)
layoutAddWidget(mainLayout, textEditor)
showWidget(mainWindow, ShowNormal)
return GuiExecuted
end

View file

@ -1,5 +1,6 @@
<RCC> <RCC>
<qresource prefix="/lua"> <qresource prefix="/lua">
<file>app.lua</file> <file>app.lua</file>
<file>edit.lua</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -132,3 +132,10 @@ QPushButton:focus:pressed {
color: rgb(215, 70, 25); color: rgb(215, 70, 25);
border-style: inset; border-style: inset;
} }
QTextEdit {
background-color: rgb(215, 120, 50);
color: rgb(255, 255, 255);
selection-background-color: rgb(255, 255, 255);
selection-color: rgb(215, 90, 0);
border: 1px solid white;
}

View file

@ -52,7 +52,7 @@ int main(int argc, char *argv[])
} }
delete luaEngineStyleFile; delete luaEngineStyleFile;
QFile luaScript(":/lua/app.lua"); QFile luaScript(":/lua/edit.lua");
LuaEngineGui luaEngineGui; LuaEngineGui luaEngineGui;
luaEngineGui.executeLuaScript(&luaScript); luaEngineGui.executeLuaScript(&luaScript);

View file

@ -27,6 +27,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QSizePolicy> #include <QSizePolicy>
#include <QEventLoop> #include <QEventLoop>
#include <QTextEdit>
#include <QLineEdit> #include <QLineEdit>
#include <QCheckBox> #include <QCheckBox>
#include <QMenuBar> #include <QMenuBar>
@ -36,6 +37,7 @@
#include <QDialog> #include <QDialog>
#include <QTimer> #include <QTimer>
#include <QLabel> #include <QLabel>
#include <QDebug>
LuaEngineGui::LuaEngineGui(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries) LuaEngineGui::LuaEngineGui(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries)
{ {
@ -103,6 +105,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
// Spacer Item // Spacer Item
pushFunction(L_p, "createSpacerItem", createSpacerItem); pushFunction(L_p, "createSpacerItem", createSpacerItem);
// Line Edit
pushFunction(L_p, "createTextEdit", createTextEdit);
// Size Policy // Size Policy
pushVariant(L_p, "SizePolicyFixed", (int)QSizePolicy::Fixed); pushVariant(L_p, "SizePolicyFixed", (int)QSizePolicy::Fixed);
pushVariant(L_p, "SizePolicyMinimum", (int)QSizePolicy::Minimum); pushVariant(L_p, "SizePolicyMinimum", (int)QSizePolicy::Minimum);
@ -302,6 +307,9 @@ int LuaEngineGui::setWidgetText(lua_State *L_p)
else if (((QObject*)pointer)->inherits("QLineEdit")) { else if (((QObject*)pointer)->inherits("QLineEdit")) {
((QLineEdit*)pointer)->setText(getVariant(L_p, 2).toString()); ((QLineEdit*)pointer)->setText(getVariant(L_p, 2).toString());
} }
else if (((QObject*)pointer)->inherits("QTextEdit")) {
((QTextEdit*)pointer)->setText(getVariant(L_p, 2).toString());
}
else if (((QObject*)pointer)->inherits("QWidget")) { else if (((QObject*)pointer)->inherits("QWidget")) {
((QWidget*)pointer)->setWindowTitle(getVariant(L_p, 2).toString()); ((QWidget*)pointer)->setWindowTitle(getVariant(L_p, 2).toString());
} }
@ -609,6 +617,28 @@ int LuaEngineGui::createSpacerItem(lua_State *L_p)
return 0; return 0;
} }
int LuaEngineGui::createTextEdit(lua_State *L_p)
{
QVariantList args = getArguments(L_p);
QWidget *parent = nullptr;
QString editText = "LuaEngine";
if (args.length() >= 1) {
editText = args.at(0).toString();
if (args.length() >= 2) {
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
}
}
}
}
QTextEdit *textEdit = new QTextEdit(parent);
textEdit->setObjectName(nameForPointer(textEdit));
textEdit->setText(editText);
pushPointer(L_p, textEdit);
return 1;
}
int LuaEngineGui::getParent(lua_State *L_p) int LuaEngineGui::getParent(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 1) { if (getArgumentCount(L_p) >= 1) {
@ -638,6 +668,10 @@ int LuaEngineGui::getWidgetText(lua_State *L_p)
pushVariant(L_p, ((QLineEdit*)pointer)->text()); pushVariant(L_p, ((QLineEdit*)pointer)->text());
return 1; return 1;
} }
else if (((QObject*)pointer)->inherits("QTextEdit")) {
pushVariant(L_p, ((QTextEdit*)pointer)->toPlainText());
return 1;
}
else if (((QObject*)pointer)->inherits("QWidget")) { else if (((QObject*)pointer)->inherits("QWidget")) {
pushVariant(L_p, ((QWidget*)pointer)->windowTitle()); pushVariant(L_p, ((QWidget*)pointer)->windowTitle());
return 1; return 1;

View file

@ -36,6 +36,7 @@ public:
static int showWidget(lua_State *L_p); static int showWidget(lua_State *L_p);
static int setWidgetFixedSize(lua_State *L_p); static int setWidgetFixedSize(lua_State *L_p);
static int setWidgetLayout(lua_State *L_p); static int setWidgetLayout(lua_State *L_p);
static int setWidgetMargins(lua_State *L_p);
static int setWidgetText(lua_State *L_p); static int setWidgetText(lua_State *L_p);
static int layoutAddLayout(lua_State *L_p); static int layoutAddLayout(lua_State *L_p);
static int layoutAddWidget(lua_State *L_p); static int layoutAddWidget(lua_State *L_p);
@ -51,6 +52,7 @@ public:
static int createMenuEntry(lua_State *L_p); static int createMenuEntry(lua_State *L_p);
static int createPushButton(lua_State *L_p); static int createPushButton(lua_State *L_p);
static int createSpacerItem(lua_State *L_p); static int createSpacerItem(lua_State *L_p);
static int createTextEdit(lua_State *L_p);
static int getParent(lua_State *L_p); static int getParent(lua_State *L_p);
static int getWidgetText(lua_State *L_p); static int getWidgetText(lua_State *L_p);