From 231cfb59cf3da856ee951dcb978277ea4b13615c Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Mon, 1 Jan 2024 22:00:01 +0100 Subject: [PATCH] left click on lua status now opens scripts list --- client/src/mainwindow.cpp | 9 ++++++-- client/src/mainwindow.hpp | 4 +++- client/src/widget/status/luastatuswidget.cpp | 24 +++++++++++++++++++- client/src/widget/status/luastatuswidget.hpp | 5 +++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/client/src/mainwindow.cpp b/client/src/mainwindow.cpp index 13cad1b1..59e37889 100644 --- a/client/src/mainwindow.cpp +++ b/client/src/mainwindow.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2023 Reinder Feenstra + * Copyright (C) 2019-2024 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -391,7 +391,7 @@ MainWindow::MainWindow(QWidget* parent) : m_menuObjects->addAction(Theme::getIcon("clock"), Locale::tr("world:clock") + "...", [this](){ showObject("world.clock", Locale::tr("world:clock")); }); trainsAction = m_menuObjects->addAction(Theme::getIcon("train"), Locale::tr("world:trains") + "...", [this](){ showObject("world.trains", Locale::tr("world:trains")); }); m_menuObjects->addAction(Locale::tr("world:rail_vehicles") + "...", [this](){ showObject("world.rail_vehicles", Locale::tr("world:rail_vehicles")); }); - m_actionLuaScript = m_menuObjects->addAction(Theme::getIcon("lua"), Locale::tr("world:lua_scripts") + "...", [this](){ showObject("world.lua_scripts", Locale::tr("world:lua_scripts")); }); + m_actionLuaScript = m_menuObjects->addAction(Theme::getIcon("lua"), Locale::tr("world:lua_scripts") + "...", this, &MainWindow::showLuaScriptsList); menu = menuBar()->addMenu(Locale::tr("qtapp.mainmenu:tools")); menu->addAction(Locale::tr("qtapp.mainmenu:settings") + "...", @@ -571,6 +571,11 @@ const ObjectPtr& MainWindow::world() const return m_connection ? m_connection->world() : null; } +void MainWindow::showLuaScriptsList() +{ + showObject("world.lua_scripts", Locale::tr("world:lua_scripts")); +} + void MainWindow::connectToServer(const QString& url) { if(m_connection) diff --git a/client/src/mainwindow.hpp b/client/src/mainwindow.hpp index 17d7f656..b6fa22f3 100644 --- a/client/src/mainwindow.hpp +++ b/client/src/mainwindow.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2023 Reinder Feenstra + * Copyright (C) 2019-2024 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -129,6 +129,8 @@ class MainWindow : public QMainWindow const ObjectPtr& world() const; const ObjectPtr& worldClock() const { return m_clock; } + void showLuaScriptsList(); + public slots: void connectToServer(const QString& url = QString()); void showObject(const ObjectPtr& object, SubWindowType flags = SubWindowType::Object); diff --git a/client/src/widget/status/luastatuswidget.cpp b/client/src/widget/status/luastatuswidget.cpp index c493745f..00624756 100644 --- a/client/src/widget/status/luastatuswidget.cpp +++ b/client/src/widget/status/luastatuswidget.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2023 Reinder Feenstra + * Copyright (C) 2023-2024 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,6 +30,7 @@ #include "../../network/object.hpp" #include "../../network/property.hpp" #include "../../theme/theme.hpp" +#include "../../mainwindow.hpp" LuaStatusWidget::LuaStatusWidget(const ObjectPtr& object, QWidget* parent) : QWidget(parent) @@ -99,6 +100,27 @@ void LuaStatusWidget::errorChanged() labelChanged(); } +void LuaStatusWidget::mousePressEvent(QMouseEvent* event) +{ + if(event->button() == Qt::LeftButton) + { + m_mouseLeftButtonPressed = true; + } +} + +void LuaStatusWidget::mouseReleaseEvent(QMouseEvent* event) +{ + if(m_mouseLeftButtonPressed && event->button() == Qt::LeftButton) + { + m_mouseLeftButtonPressed = false; + + if(rect().contains(event->pos())) + { + MainWindow::instance->showLuaScriptsList(); + } + } +} + void LuaStatusWidget::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); diff --git a/client/src/widget/status/luastatuswidget.hpp b/client/src/widget/status/luastatuswidget.hpp index 5548612f..4f92d2f4 100644 --- a/client/src/widget/status/luastatuswidget.hpp +++ b/client/src/widget/status/luastatuswidget.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2023 Reinder Feenstra + * Copyright (C) 2023-2024 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -36,12 +36,15 @@ class LuaStatusWidget : public QWidget QSvgWidget* m_svg; QLabel* m_runningLabel; QLabel* m_errorLabel; + bool m_mouseLeftButtonPressed = false; void labelChanged(); void runningChanged(); void errorChanged(); protected: + void mousePressEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; void resizeEvent(QResizeEvent* event) override; public: