menuEntry have now shortcut included

This commit is contained in:
Syping 2019-09-24 16:10:56 +02:00
parent ba59a81d68
commit 98fb0529cf
4 changed files with 89 additions and 14 deletions

View file

@ -26,12 +26,10 @@ function main()
local menuBar = createMenuBar(mainWindow) local menuBar = createMenuBar(mainWindow)
local menuFile = createMenu("File", menuBar) local menuFile = createMenu("File", menuBar)
local menuEntryExit = createMenuEntry("Exit", menuFile) local menuEntryExit = createMenuEntry("Exit", menuFile, "Alt+F4")
setMenuShortcut(menuEntryExit, "Alt+F4")
connect(menuEntryExit, "triggered()", "closeWindow") connect(menuEntryExit, "triggered()", "closeWindow")
local menuHelp = createMenu("Help", menuBar) local menuHelp = createMenu("Help", menuBar)
local menuEntryAbout = createMenuEntry("About LuaEngine", menuHelp) local menuEntryAbout = createMenuEntry("About LuaEngine", menuHelp, "Ctrl+P")
setMenuShortcut(menuEntryAbout, "Ctrl+P")
connect(menuEntryAbout, "triggered()", "showAboutBox") connect(menuEntryAbout, "triggered()", "showAboutBox")
local labelLayout = createLayout(HorizontalLayout, mainLayout) local labelLayout = createLayout(HorizontalLayout, mainLayout)

View file

@ -28,24 +28,19 @@ function main()
local menuBar = createMenuBar(mainWindow) local menuBar = createMenuBar(mainWindow)
local menuFile = createMenu("&File", menuBar) local menuFile = createMenu("&File", menuBar)
local menuEntryNew = createMenuEntry("&New", menuFile) local menuEntryNew = createMenuEntry("&New", menuFile, "Ctrl+N")
setMenuShortcut(menuEntryNew, "Ctrl+N")
connect(menuEntryNew, "triggered()", "editorNew") connect(menuEntryNew, "triggered()", "editorNew")
local menuEntryOpen = createMenuEntry("&Open...", menuFile) local menuEntryOpen = createMenuEntry("&Open...", menuFile, "Ctrl+O")
setMenuShortcut(menuEntryOpen, "Ctrl+O")
connect(menuEntryOpen, "triggered()", "editorOpen") connect(menuEntryOpen, "triggered()", "editorOpen")
local menuEntrySave = createMenuEntry("&Save...", menuFile) local menuEntrySave = createMenuEntry("&Save...", menuFile, "Ctrl+S")
setMenuShortcut(menuEntrySave, "Ctrl+S")
connect(menuEntrySave, "triggered()", "editorSave") connect(menuEntrySave, "triggered()", "editorSave")
local menuEntrySaveAs = createMenuEntry("Save &as...", menuFile) local menuEntrySaveAs = createMenuEntry("Save &as...", menuFile)
connect(menuEntrySaveAs, "triggered()", "editorSaveAs") connect(menuEntrySaveAs, "triggered()", "editorSaveAs")
createMenuSeparator(menuFile) createMenuSeparator(menuFile)
local menuEntryExit = createMenuEntry("&Exit", menuFile) local menuEntryExit = createMenuEntry("&Exit", menuFile, "Alt+F4")
setMenuShortcut(menuEntryExit, "Alt+F4")
connect(menuEntryExit, "triggered()", "editorClose") connect(menuEntryExit, "triggered()", "editorClose")
local menuHelp = createMenu("&Help", menuBar) local menuHelp = createMenu("&Help", menuBar)
local menuEntryAbout = createMenuEntry("&About LE Text Editor", menuHelp) local menuEntryAbout = createMenuEntry("&About LE Text Editor", menuHelp, "Ctrl+P")
setMenuShortcut(menuEntryAbout, "Ctrl+P")
connect(menuEntryAbout, "triggered()", "editorAboutBox") connect(menuEntryAbout, "triggered()", "editorAboutBox")
textEditor = createPlainTextEdit("", mainWindow) textEditor = createPlainTextEdit("", mainWindow)

View file

@ -17,6 +17,7 @@
#include "LuaEngineGui.h" #include "LuaEngineGui.h"
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QRadioButton>
#include <QMainWindow> #include <QMainWindow>
#include <QPushButton> #include <QPushButton>
#include <QMessageBox> #include <QMessageBox>
@ -69,7 +70,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
pushFunction(L_p, "closeWidget", closeWidget); pushFunction(L_p, "closeWidget", closeWidget);
pushFunction(L_p, "executeWidget", executeWidget); pushFunction(L_p, "executeWidget", executeWidget);
pushFunction(L_p, "showWidget", showWidget); pushFunction(L_p, "showWidget", showWidget);
pushFunction(L_p, "isWidgetChecked", isWidgetChecked);
pushFunction(L_p, "getWidgetText", getWidgetText); pushFunction(L_p, "getWidgetText", getWidgetText);
pushFunction(L_p, "setWidgetChecked", setWidgetChecked);
pushFunction(L_p, "setWidgetFixed", setWidgetFixed); pushFunction(L_p, "setWidgetFixed", setWidgetFixed);
pushFunction(L_p, "setWidgetLayout", setWidgetLayout); pushFunction(L_p, "setWidgetLayout", setWidgetLayout);
pushFunction(L_p, "setWidgetText", setWidgetText); pushFunction(L_p, "setWidgetText", setWidgetText);
@ -118,6 +121,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
// Push Button // Push Button
pushFunction(L_p, "createPushButton", createPushButton); pushFunction(L_p, "createPushButton", createPushButton);
// Check Box
pushFunction(L_p, "createRadioButton", createRadioButton);
// Spacer Item // Spacer Item
pushFunction(L_p, "createSpacerItem", createSpacerItem); pushFunction(L_p, "createSpacerItem", createSpacerItem);
@ -360,6 +366,27 @@ int LuaEngineGui::setMenuShortcut(lua_State *L_p)
return 0; return 0;
} }
int LuaEngineGui::setWidgetChecked(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
bool isChecked = true;
if (getArgumentCount(L_p) >= 2) {
isChecked = getVariant(L_p, 2).toBool();
}
if (((QObject*)pointer)->inherits("QCheckBox")) {
((QCheckBox*)pointer)->setChecked(isChecked);
}
else if (((QObject*)pointer)->inherits("QRadioButton")) {
((QRadioButton*)pointer)->setChecked(isChecked);
}
return 0;
}
}
return 0;
}
int LuaEngineGui::setWidgetFixed(lua_State *L_p) int LuaEngineGui::setWidgetFixed(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 1) { if (getArgumentCount(L_p) >= 1) {
@ -443,6 +470,9 @@ int LuaEngineGui::setWidgetText(lua_State *L_p)
else if (((QObject*)pointer)->inherits("QPlainTextEdit")) { else if (((QObject*)pointer)->inherits("QPlainTextEdit")) {
((QPlainTextEdit*)pointer)->setPlainText(getVariant(L_p, 2).toString()); ((QPlainTextEdit*)pointer)->setPlainText(getVariant(L_p, 2).toString());
} }
else if (((QObject*)pointer)->inherits("QRadioButton")) {
((QRadioButton*)pointer)->setText(getVariant(L_p, 2).toString());
}
else if (((QObject*)pointer)->inherits("QTextEdit")) { else if (((QObject*)pointer)->inherits("QTextEdit")) {
((QTextEdit*)pointer)->setHtml(getVariant(L_p, 2).toString()); ((QTextEdit*)pointer)->setHtml(getVariant(L_p, 2).toString());
} }
@ -716,6 +746,10 @@ int LuaEngineGui::createMenuEntry(lua_State *L_p)
QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer); QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer);
action->setObjectName(nameForPointer(action)); action->setObjectName(nameForPointer(action));
((QMenu*)pointer)->addAction(action); ((QMenu*)pointer)->addAction(action);
if (getArgumentCount(L_p) >= 3) {
action->setShortcut(QKeySequence::fromString(getVariant(L_p, 3).toString()));
action->setShortcutContext(Qt::ApplicationShortcut);
}
pushPointer(L_p, action); pushPointer(L_p, action);
return 1; return 1;
} }
@ -782,6 +816,29 @@ int LuaEngineGui::createPushButton(lua_State *L_p)
return 1; return 1;
} }
int LuaEngineGui::createRadioButton(lua_State *L_p)
{
QWidget *parent = nullptr;
QString labelText = "LuaEngine";
if (getArgumentCount(L_p) >= 1) {
labelText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
}
QRadioButton *radioButton = new QRadioButton(parent);
radioButton->setObjectName(nameForPointer(radioButton));
radioButton->setText(labelText);
pushPointer(L_p, radioButton);
return 1;
}
int LuaEngineGui::createSpacerItem(lua_State *L_p) int LuaEngineGui::createSpacerItem(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 3) { if (getArgumentCount(L_p) >= 3) {
@ -829,6 +886,24 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
return 1; return 1;
} }
int LuaEngineGui::isWidgetChecked(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QCheckBox")) {
pushVariant(L_p, ((QCheckBox*)pointer)->isChecked());
return 1;
}
else if (((QObject*)pointer)->inherits("QRadioButton")) {
pushVariant(L_p, ((QRadioButton*)pointer)->isChecked());
return 1;
}
}
}
return 0;
}
int LuaEngineGui::getWindow(lua_State *L_p) int LuaEngineGui::getWindow(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 1) { if (getArgumentCount(L_p) >= 1) {
@ -880,6 +955,10 @@ int LuaEngineGui::getWidgetText(lua_State *L_p)
pushVariant(L_p, ((QPlainTextEdit*)pointer)->toPlainText()); pushVariant(L_p, ((QPlainTextEdit*)pointer)->toPlainText());
return 1; return 1;
} }
else if (((QObject*)pointer)->inherits("QRadioButton")) {
pushVariant(L_p, ((QRadioButton*)pointer)->text());
return 1;
}
else if (((QObject*)pointer)->inherits("QTextEdit")) { else if (((QObject*)pointer)->inherits("QTextEdit")) {
pushVariant(L_p, ((QTextEdit*)pointer)->toHtml()); pushVariant(L_p, ((QTextEdit*)pointer)->toHtml());
return 1; return 1;

View file

@ -37,6 +37,7 @@ public:
static int showWidget(lua_State *L_p); static int showWidget(lua_State *L_p);
static int setLayoutMargins(lua_State *L_p); static int setLayoutMargins(lua_State *L_p);
static int setMenuShortcut(lua_State *L_p); static int setMenuShortcut(lua_State *L_p);
static int setWidgetChecked(lua_State *L_p);
static int setWidgetFixed(lua_State *L_p); static int setWidgetFixed(lua_State *L_p);
static int setWidgetLayout(lua_State *L_p); static int setWidgetLayout(lua_State *L_p);
static int setWidgetSize(lua_State *L_p); static int setWidgetSize(lua_State *L_p);
@ -56,8 +57,10 @@ public:
static int createMenuSeparator(lua_State *L_p); static int createMenuSeparator(lua_State *L_p);
static int createPlainTextEdit(lua_State *L_p); static int createPlainTextEdit(lua_State *L_p);
static int createPushButton(lua_State *L_p); static int createPushButton(lua_State *L_p);
static int createRadioButton(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 createTextEdit(lua_State *L_p);
static int isWidgetChecked(lua_State *L_p);
static int getWidgetText(lua_State *L_p); static int getWidgetText(lua_State *L_p);
static int getWindow(lua_State *L_p); static int getWindow(lua_State *L_p);