From 92e9d25879b6b11a9bb7c0d9e468e3104cbe5a86 Mon Sep 17 00:00:00 2001 From: Syping Date: Tue, 24 Sep 2019 17:21:33 +0200 Subject: [PATCH] load script as resource --- src/luaengineapp/app.lua | 117 +++----------- src/luaengineapp/edit.lua | 127 --------------- src/luaengineapp/luaengineapp.pro | 15 +- src/luaengineapp/luaengineapp.qrc | 6 - .../luaenginestyle/LuaEngineStyle.h | 40 ----- .../luaenginestyle/down-arrow.png | Bin 173 -> 0 bytes .../luaenginestyle/down-arrow_o.png | Bin 169 -> 0 bytes .../luaenginestyle/luaenginestyle.qrc | 7 - .../luaenginestyle/luaenginestyle.qss | 148 ------------------ src/luaengineapp/main.cpp | 29 +++- src/luaengineapp/resource.h | 2 + 11 files changed, 54 insertions(+), 437 deletions(-) delete mode 100644 src/luaengineapp/edit.lua delete mode 100644 src/luaengineapp/luaengineapp.qrc delete mode 100644 src/luaengineapp/luaenginestyle/LuaEngineStyle.h delete mode 100644 src/luaengineapp/luaenginestyle/down-arrow.png delete mode 100644 src/luaengineapp/luaenginestyle/down-arrow_o.png delete mode 100644 src/luaengineapp/luaenginestyle/luaenginestyle.qrc delete mode 100644 src/luaengineapp/luaenginestyle/luaenginestyle.qss create mode 100644 src/luaengineapp/resource.h diff --git a/src/luaengineapp/app.lua b/src/luaengineapp/app.lua index ffde2df..c72abc5 100644 --- a/src/luaengineapp/app.lua +++ b/src/luaengineapp/app.lua @@ -1,94 +1,23 @@ ---[[ -****************************************************************************** -* 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 mainWindow -local dialogLineEdit - -function main() - mainWindow = createMainWindow() - local mainLayout = createLayout(VerticalLayout, mainWindow) - - local menuBar = createMenuBar(mainWindow) - local menuFile = createMenu("File", menuBar) - local menuEntryExit = createMenuEntry("Exit", menuFile, "Alt+F4") - connect(menuEntryExit, "triggered()", "closeWindow") - local menuHelp = createMenu("Help", menuBar) - local menuEntryAbout = createMenuEntry("About LuaEngine", menuHelp, "Ctrl+P") - connect(menuEntryAbout, "triggered()", "showAboutBox") - - local labelLayout = createLayout(HorizontalLayout, mainLayout) - local appLabel1 = createLabel("LuaEngine greets!", mainWindow) - layoutAddWidget(labelLayout, appLabel1) - local appLabel2 = createLabel("..and not only one time!", mainWindow) - layoutAddWidget(labelLayout, appLabel2) - - local checkBox1 = createCheckBox("Want to check me?", mainWindow) - layoutAddWidget(mainLayout, checkBox1) - - local pushButton1 = createPushButton("Press me hard please!", mainWindow) - layoutAddWidget(mainLayout, pushButton1) - connect(pushButton1, "clicked()", "showDialog") - - setWidgetFixed(mainWindow) - showWidget(mainWindow, ShowNormal) - return GuiExecuted -end - -function closeWindow() - closeWidget(mainWindow) -end - -function showAboutBox(menuEntry) - showMessageBox(InfoMessageBox, "You triggered the About Box!", "LuaEngine", mainWindow) -end - -function showDialog(pushButton) - local dialog = createDialog("LuaEngine", mainWindow) - local dialogLayout = createLayout(VerticalLayout, dialog) - local dialogLabel = createLabel("Yes, you have open a Dialog!", dialog) - layoutAddWidget(dialogLayout, dialogLabel) - dialogLineEdit = createLineEdit("", dialog) - layoutAddWidget(dialogLayout, dialogLineEdit) - local buttonLayout = createLayout(HorizontalLayout, dialogLayout) - createSpacerItem(SizePolicyExpanding, SizePolicyMinimum, buttonLayout) - local dialogButton = createPushButton("Close", dialog) - layoutAddWidget(buttonLayout, dialogButton) - connect(dialogButton, "clicked()", "closeDialog") - setWidgetFixed(dialog) - executeWidget(dialog) - delete(dialog, DeleteInstant) -end - -function closeDialog(pushButton) - disconnect(pushButton, "clicked()") - if not (getWidgetText(dialogLineEdit) == "") then - showMessageBox(InfoMessageBox, "You typed: " .. getWidgetText(dialogLineEdit), "LuaEngine", getParent(pushButton)) - end - closeWidget(getParent(pushButton)) -end - -function testMessageBoxes() - showMessageBox(InfoMessageBox, "LuaEngine Test") - local returnCode = showMessageBox(QuestionMessageBox, "Do you press Yes or No?") - if (returnCode == true) then - showMessageBox(InfoMessageBox, "You have pressed Yes!") - else - showMessageBox(InfoMessageBox, "You have pressed No!") - end -end +--[[ +****************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2019 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. +****************************************************************************** +--]] + +function main() + showMessageBox(InfoMessageBox, "Lua Engine is working!", "Lua Engine") + return 0 +end diff --git a/src/luaengineapp/edit.lua b/src/luaengineapp/edit.lua deleted file mode 100644 index cfeb800..0000000 --- a/src/luaengineapp/edit.lua +++ /dev/null @@ -1,127 +0,0 @@ ---[[ -****************************************************************************** -* 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("LE Text Editor") - local mainLayout = createLayout(VerticalLayout, mainWindow) - setLayoutMargins(mainLayout, 0, 0, 0, 0) - - local menuBar = createMenuBar(mainWindow) - local menuFile = createMenu("&File", menuBar) - local menuEntryNew = createMenuEntry("&New", menuFile, "Ctrl+N") - connect(menuEntryNew, "triggered()", "editorNew") - local menuEntryOpen = createMenuEntry("&Open...", menuFile, "Ctrl+O") - connect(menuEntryOpen, "triggered()", "editorOpen") - local menuEntrySave = createMenuEntry("&Save...", menuFile, "Ctrl+S") - connect(menuEntrySave, "triggered()", "editorSave") - local menuEntrySaveAs = createMenuEntry("Save &as...", menuFile) - connect(menuEntrySaveAs, "triggered()", "editorSaveAs") - createMenuSeparator(menuFile) - local menuEntryExit = createMenuEntry("&Exit", menuFile, "Alt+F4") - connect(menuEntryExit, "triggered()", "editorClose") - local menuHelp = createMenu("&Help", menuBar) - local menuEntryAbout = createMenuEntry("&About LE Text Editor", menuHelp, "Ctrl+P") - connect(menuEntryAbout, "triggered()", "editorAboutBox") - - textEditor = createPlainTextEdit("", mainWindow) - layoutAddWidget(mainLayout, textEditor) - - setWidgetSize(mainWindow, 650, 450) - showWidget(mainWindow, ShowDefault) - return GuiExecuted -end - -function editorNew() - setWidgetText(textEditor, "") - currentFile = nil -end - -function editorOpen() - local selectedFile = showFileDialog(OpenFileDialog, "Open...", "All files (*)", mainWindow) - if not (selectedFile == nil) then - local file = io.open(selectedFile, "r") - if not (file == nil) then - local content = file:read("*a") - setWidgetText(textEditor, content) - file:close() - currentFile = selectedFile - else - showMessageBox(WarningMessageBox, "Failed to open file " .. selectedFile .. "!", "Open...", mainWindow) - end - end -end - -function editorSave() - if not (currentFile == nil) then - local file = io.open(currentFile, "w") - if not (file == nil) then - editorSaveFile(file) - else - showMessageBox(WarningMessageBox, "Failed to save file " .. currentFile .. "!", "Save...", mainWindow) - end - else - editorSaveAs() - end -end - -function editorSaveAs() - local selectedFile = showFileDialog(SaveFileDialog, "Save as...", "All files (*)", mainWindow) - if not (selectedFile == nil) then - local file = io.open(selectedFile, "w") - if not (file == nil) then - editorSaveFile(file) - currentFile = selectedFile - else - showMessageBox(WarningMessageBox, "Failed to save file " .. selectedFile .. "!", "Save as...", mainWindow) - end - end -end - -function editorSaveFile(file) - file:write(getWidgetText(textEditor)) - file:close() -end - -function editorAboutBox() - local dialog = createDialog("About LE Text Editor", mainWindow) - local dialogLayout = createLayout(VerticalLayout, dialog) - local dialogLabel = createLabel("

LE Text Editor

A simple Text Editor made in Lua Engine", dialog) - layoutAddWidget(dialogLayout, dialogLabel) - local buttonLayout = createLayout(HorizontalLayout, dialogLayout) - createSpacerItem(SizePolicyExpanding, SizePolicyMinimum, buttonLayout) - local dialogButton = createPushButton("&OK", dialog) - layoutAddWidget(buttonLayout, dialogButton) - connect(dialogButton, "clicked()", "closeDialog") - setWidgetFixed(dialog) - executeWidget(dialog) - delete(dialog, DeleteInstant) -end - -function editorClose() - closeWidget(mainWindow) -end - -function closeDialog(pushButton) - disconnect(pushButton, "clicked()") - closeWidget(getWindow(pushButton)) -end diff --git a/src/luaengineapp/luaengineapp.pro b/src/luaengineapp/luaengineapp.pro index 26cb4f8..f439859 100644 --- a/src/luaengineapp/luaengineapp.pro +++ b/src/luaengineapp/luaengineapp.pro @@ -1,6 +1,6 @@ #/***************************************************************************** #* luaEngine Lua Engine for Qt -#* Copyright (C) 2018 Syping +#* Copyright (C) 2018-2019 Syping #* #* Licensed under the Apache License, Version 2.0 (the "License"); #* you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine -L$$OUT_PWD/../luaenginegui - win32: LIBS += -luser32 INCLUDEPATH += \ - ./luaenginestyle \ ../luaengine/lua \ ../luaengine/luaengine \ ../luaenginegui/luaengine @@ -35,11 +34,8 @@ INCLUDEPATH += \ SOURCES += \ main.cpp -HEADERS += \ - luaenginestyle/LuaEngineStyle.h - -RESOURCES += \ - luaengineapp.qrc +win32: HEADERS += \ + resource.h DISTFILES += \ android/AndroidManifest.xml \ @@ -57,5 +53,10 @@ DISTFILES += \ android/gradle/wrapper/gradle-wrapper.properties \ android/gradlew.bat +OTHER_FILES += \ + app.lua + +win32: RC_FILE = app.rc + ANDROID_EXTRA_LIBS += $$OUT_PWD/../luaengine/libluaengine.so $$OUT_PWD/../luaenginegui/libluaenginegui.so ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android diff --git a/src/luaengineapp/luaengineapp.qrc b/src/luaengineapp/luaengineapp.qrc deleted file mode 100644 index bb17d2b..0000000 --- a/src/luaengineapp/luaengineapp.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - app.lua - edit.lua - - diff --git a/src/luaengineapp/luaenginestyle/LuaEngineStyle.h b/src/luaengineapp/luaenginestyle/LuaEngineStyle.h deleted file mode 100644 index 674e8b7..0000000 --- a/src/luaengineapp/luaenginestyle/LuaEngineStyle.h +++ /dev/null @@ -1,40 +0,0 @@ -/***************************************************************************** -* luaEngine Lua Engine for Qt -* Copyright (C) 2015-2019 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 LUAENGINESTYLE -#define LUAENGINESTYLE - -#include -#include - -class LuaEngineStyle : public QProxyStyle -{ - -public: - explicit LuaEngineStyle(QStyle *style = nullptr) - { - setBaseStyle(style); - } - void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const - { - if (element == QStyle::PE_FrameFocusRect) - return; - QProxyStyle::drawPrimitive(element, option, painter, widget); - } -}; - -#endif // LUAENGINESTYLE diff --git a/src/luaengineapp/luaenginestyle/down-arrow.png b/src/luaengineapp/luaenginestyle/down-arrow.png deleted file mode 100644 index f14a77760a283ce4ebeb337d1fa5c8a5b5f69cf0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)I!3HFqj;YoHDaPU;cPEB*=VV@jWYQgd9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt33 zJ=4@yqg0?8IZqeI5Q*^QAN}kNDutQ}4W5g%8M+m{4~aP3{4dFH^keeepa+XXfGQb0 MUHx3vIVCg!0H9$nd;kCd diff --git a/src/luaengineapp/luaenginestyle/down-arrow_o.png b/src/luaengineapp/luaenginestyle/down-arrow_o.png deleted file mode 100644 index fd81d6490ce8e0b6d08f3403aff0f6def3ac68df..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 169 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)I!3HFqj;YpyIO&eQjtmSN`?>!lvI6;>1s;*b z3=DjSK$uZf!>a)(C{f}XQ4*Y=R#Ki=l*&+$n3-3imzP?iV4`QBXPVk-lnPX%?&;zf zA`zavL+ - - luaenginestyle.qss - down-arrow.png - down-arrow_o.png - - diff --git a/src/luaengineapp/luaenginestyle/luaenginestyle.qss b/src/luaengineapp/luaenginestyle/luaenginestyle.qss deleted file mode 100644 index b945560..0000000 --- a/src/luaengineapp/luaenginestyle/luaenginestyle.qss +++ /dev/null @@ -1,148 +0,0 @@ -QDialog { - background-color: rgb(215, 90, 0); -} -QMainWindow { - background-color: rgb(215, 90, 0); -} -QMessageBox { - background-color: rgb(215, 90, 0); -} -QCheckBox { - background-color: rgb(215, 90, 0); - color: rgb(255, 255, 255); - selection-background-color: rgb(255, 255, 255); - selection-color: rgb(215, 90, 0); - border: 0px; -} -QComboBox { - font-size: 10pt; - 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; -} -QComboBox::drop-down { - subcontrol-origin: padding; - subcontrol-position: top right; - width: 15px; - background-color: rgb(215, 70, 25); - border-left-width: 1px; - border-left-color: white; - border-left-style: solid; -} -QComboBox::drop-down:hover { - background-color: rgb(255, 255, 255); -} -QComboBox::drop-down:on { - background-color: rgb(255, 255, 255); -} -QComboBox::down-arrow { - image: url(:/luaenginestyle/down-arrow.png); -} -QComboBox::down-arrow:hover { - image: url(:/luaenginestyle/down-arrow_o.png); -} -QComboBox::down-arrow:on { - image: url(:/luaenginestyle/down-arrow_o.png); - top: 1px; - left: 1px; -} -QComboBox QAbstractItemView { - background-color: rgb(215, 120, 50); - color: rgb(255, 255, 255); - selection-background-color: rgb(255, 255, 255); - selection-color: rgb(215, 90, 0); - outline: none; -} -QFrame { - background-color: rgb(215, 90, 0); - color: rgb(255, 255, 255); - selection-background-color: rgb(255, 255, 255); - selection-color: rgb(215, 90, 0); -} -QInputBox { - background-color: rgb(215, 90, 0); - color: rgb(255, 255, 255); - selection-background-color: rgb(255, 255, 255); - selection-color: rgb(215, 90, 0); -} -QLabel { - background-color: rgb(215, 90, 0); - color: rgb(255, 255, 255); - selection-background-color: rgb(255, 255, 255); - selection-color: rgb(215, 90, 0); - border: 0px; -} -QLineEdit { - 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; -} -QListWidget { - 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-color: rgb(166, 92, 38); - border-style: solid; - border-width: 1px; -} -QListWidget::item { - background-color: rgb(215, 120, 50); - color: rgb(255, 255, 255); -} -QListWidget::item:hover { - background-color: rgb(234, 187, 152); -} -QListWidget::item:selected { - background-color: rgb(255, 255, 255); - color: rgb(215, 90, 0); -} -QPlainTextEdit { - 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; -} -QPushButton { - border-style: ridge; - background-color: rgb(215, 70, 25); - color: rgb(255, 255, 255); - border-width: 1px; - border-radius: 0px; - border-color: rgb(215, 120, 50); - min-width: 5em; - padding: 4px; -} -QPushButton:pressed { - background-color: rgb(255, 255, 255); - color: rgb(215, 70, 25); - border-style: inset; -} -QPushButton:hover { - background-color: rgb(255, 255, 255); - color: rgb(215, 70, 25); -} -QPushButton:focus { - background-color: rgb(218, 86, 45); -} -QPushButton:focus:hover { - background-color: rgb(255, 255, 255); - color: rgb(215, 70, 25); -} -QPushButton:focus:pressed { - background-color: rgb(255, 255, 255); - color: rgb(215, 70, 25); - 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; -} diff --git a/src/luaengineapp/main.cpp b/src/luaengineapp/main.cpp index d7c0533..ad89c16 100644 --- a/src/luaengineapp/main.cpp +++ b/src/luaengineapp/main.cpp @@ -15,22 +15,22 @@ * limitations under the License. *****************************************************************************/ -#include "LuaEngineStyle.h" #include "LuaEngineGui.h" #include #include #include +#ifdef Q_OS_WIN +#include "windows.h" +#include "resource.h" +#endif int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); QApplication a(argc, argv); -#ifdef Q_OS_WIN - QApplication::setStyle(new LuaEngineStyle()); -#endif #ifdef Q_OS_WIN -#if QT_VERSION >= 0x050400 +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) if (QSysInfo::windowsVersion() >= 0x0080) { a.setFont(QApplication::font("QMenu")); @@ -38,10 +38,23 @@ int main(int argc, char *argv[]) #endif #endif - QFile luaScript(":/lua/edit.lua"); + QByteArray luaScript; +#ifdef Q_OS_WIN + { + HMODULE handle = GetModuleHandle(NULL); + HRSRC resource = FindResource(handle, MAKEINTRESOURCE(IDR_RC_TEXT1), MAKEINTRESOURCE(RC_TEXT)); + HGLOBAL resourceData = LoadResource(handle, resource); + DWORD size = SizeofResource(handle, resource); + const char *data = static_cast(LockResource(resourceData)); + char* buffer = new char[size + 1]; + memcpy(buffer, data, size); + buffer[size] = 0; + luaScript = QByteArray(buffer); + } +#endif LuaEngineGui luaEngineGui; - luaEngineGui.executeLuaScript(&luaScript); + luaEngineGui.executeLuaScript(luaScript); QVariantList arguments; for (const QString &argument : a.arguments()) { @@ -50,7 +63,7 @@ int main(int argc, char *argv[]) if (luaEngineGui.executeLuaFunction("main", arguments, true)) { QVariant variant = luaEngineGui.returnVariant(); - if (variant.type() == QVariant::Int) { + if (variant.type() == QVariant::Int || variant.type() == QVariant::LongLong) { return variant.toInt(); } else if (variant.type() == QVariant::String) { diff --git a/src/luaengineapp/resource.h b/src/luaengineapp/resource.h new file mode 100644 index 0000000..bd16694 --- /dev/null +++ b/src/luaengineapp/resource.h @@ -0,0 +1,2 @@ +#define IDR_RC_TEXT1 201 +#define RC_TEXT 256