From 30eea2bf6d26c5f19556c2bb644156d09a5b4a4e Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Fri, 21 Nov 2025 22:52:11 +0100 Subject: [PATCH] [client] replaced Qt dialog icons by traintastic icon --- client/src/board/boardwidget.cpp | 2 +- client/src/programming/lncv/lncvprogrammer.cpp | 3 ++- client/src/subwindow/subwindow.cpp | 3 ++- client/src/theme/theme.cpp | 15 ++++++++++++++- client/src/theme/theme.hpp | 4 +++- client/src/widget/list/listwidget.cpp | 4 ++-- client/src/widget/object/itemseditwidget.cpp | 4 ++-- client/src/widget/object/luascripteditwidget.cpp | 4 ++-- client/src/widget/object/objecteditwidget.cpp | 2 +- client/src/widget/tile/tilewidget.cpp | 3 +++ 10 files changed, 32 insertions(+), 12 deletions(-) diff --git a/client/src/board/boardwidget.cpp b/client/src/board/boardwidget.cpp index c9c37a78..ba5127d6 100644 --- a/client/src/board/boardwidget.cpp +++ b/client/src/board/boardwidget.cpp @@ -94,7 +94,7 @@ BoardWidget::BoardWidget(std::shared_ptr object, QWidget* parent) : , m_tileResizeStarted{false} , m_nxButtonTimerId(0) { - setWindowIcon(Theme::getIconForClassId(object->classId)); + Theme::setWindowIcon(*this, object->classId); setFocusPolicy(Qt::StrongFocus); if(AbstractProperty* name = m_object->getProperty("name")) diff --git a/client/src/programming/lncv/lncvprogrammer.cpp b/client/src/programming/lncv/lncvprogrammer.cpp index 4ded8996..228c27db 100644 --- a/client/src/programming/lncv/lncvprogrammer.cpp +++ b/client/src/programming/lncv/lncvprogrammer.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2022-2023 Reinder Feenstra + * Copyright (C) 2022-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -116,6 +116,7 @@ LNCVProgrammer::LNCVProgrammer(std::shared_ptr connection, QWidget* , m_stop{new QPushButton(Locale::tr("lncv_programmer:stop"))} { setWindowTitle(Locale::tr("lncv_programmer:lncv_programmer")); + Theme::setWindowIcon(*this, "lncv_programmer"); loadInterfaces(); connect(m_interface, QOverload::of(&QComboBox::currentIndexChanged), this, &LNCVProgrammer::updateStartEnabled); diff --git a/client/src/subwindow/subwindow.cpp b/client/src/subwindow/subwindow.cpp index a93f7803..a4a92775 100644 --- a/client/src/subwindow/subwindow.cpp +++ b/client/src/subwindow/subwindow.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2024 Reinder Feenstra + * Copyright (C) 2019-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -103,6 +103,7 @@ void SubWindow::setObject(const ObjectPtr& object) else m_id = object->classId(); setWidget(createWidget(object)); + connect(widget(), &QWidget::windowIconChanged, this, &SubWindow::setWindowIcon); connect(widget(), &QWidget::windowTitleChanged, this, &SubWindow::setWindowTitle); if(!widget()->windowTitle().isEmpty()) setWindowTitle(widget()->windowTitle()); diff --git a/client/src/theme/theme.cpp b/client/src/theme/theme.cpp index 8430837d..042fc6ae 100644 --- a/client/src/theme/theme.cpp +++ b/client/src/theme/theme.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2021,2023-2024 Reinder Feenstra + * Copyright (C) 2021-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,6 +24,7 @@ #include #include #include +#include const QString iconPathDefault = QStringLiteral(":/"); const QString iconPathDark = QStringLiteral(":/dark/"); @@ -75,6 +76,18 @@ QIcon Theme::getIconForClassId(const QString& classId) return QIcon(); } +void Theme::setWindowIcon(QWidget& widget, const QString& classId) +{ + if(auto icon = Theme::getIconForClassId(classId); !icon.isNull()) + { + widget.setWindowIcon(icon); + } + else + { + widget.setWindowIcon(QIcon(":/appicon.svg")); + } +} + const std::array& Theme::getIconPaths() { switch(s_iconSet) diff --git a/client/src/theme/theme.hpp b/client/src/theme/theme.hpp index ac432064..f0c19311 100644 --- a/client/src/theme/theme.hpp +++ b/client/src/theme/theme.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2021,2024 Reinder Feenstra + * Copyright (C) 2021-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -55,6 +55,8 @@ class Theme inline static QIcon getIcon(const QString& id) { return QIcon(getIconFile(id)); } static QIcon getIcon(const QString& idOff, const QString& idOn); static QIcon getIconForClassId(const QString& classId); + + static void setWindowIcon(QWidget& widget, const QString& classId); }; #endif diff --git a/client/src/widget/list/listwidget.cpp b/client/src/widget/list/listwidget.cpp index 2c2faa4d..2aeb59ef 100644 --- a/client/src/widget/list/listwidget.cpp +++ b/client/src/widget/list/listwidget.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2024 Reinder Feenstra + * Copyright (C) 2019-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,7 +35,7 @@ ListWidget::ListWidget(const ObjectPtr& object, QWidget* parent) , m_object{object} , m_tableWidget{new TableWidget(this)} { - setWindowIcon(Theme::getIconForClassId(m_object->classId())); + Theme::setWindowIcon(*this, m_object->classId()); m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); diff --git a/client/src/widget/object/itemseditwidget.cpp b/client/src/widget/object/itemseditwidget.cpp index ee9805c4..e622c3b2 100644 --- a/client/src/widget/object/itemseditwidget.cpp +++ b/client/src/widget/object/itemseditwidget.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2021,2023-2024 Reinder Feenstra + * Copyright (C) 2021-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -68,7 +68,7 @@ ItemsEditWidget::ItemsEditWidget(const QString& id, QWidget* parent) : void ItemsEditWidget::buildForm() { setObjectWindowTitle(); - setWindowIcon(Theme::getIconForClassId(m_object->classId())); + Theme::setWindowIcon(*this, m_object->classId()); m_propertyItems = dynamic_cast(m_object->getVectorProperty("items")); m_methodCreate = m_object->getMethod("create"); diff --git a/client/src/widget/object/luascripteditwidget.cpp b/client/src/widget/object/luascripteditwidget.cpp index 7cc52274..d5fe2c58 100644 --- a/client/src/widget/object/luascripteditwidget.cpp +++ b/client/src/widget/object/luascripteditwidget.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2020,2022,2024 Reinder Feenstra + * Copyright (C) 2019-2025 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -62,7 +62,7 @@ LuaScriptEditWidget::LuaScriptEditWidget(const QString& id, QWidget* parent) : void LuaScriptEditWidget::buildForm() { setObjectWindowTitle(); - setWindowIcon(Theme::getIconForClassId(m_object->classId())); + Theme::setWindowIcon(*this, m_object->classId()); m_propertyState = dynamic_cast(m_object->getProperty("state")); m_methodStart = m_object->getMethod("start"); diff --git a/client/src/widget/object/objecteditwidget.cpp b/client/src/widget/object/objecteditwidget.cpp index a38c4dde..9b2f9388 100644 --- a/client/src/widget/object/objecteditwidget.cpp +++ b/client/src/widget/object/objecteditwidget.cpp @@ -69,7 +69,7 @@ ObjectEditWidget::ObjectEditWidget(ObjectProperty& property, QWidget* parent) void ObjectEditWidget::buildForm() { setObjectWindowTitle(); - setWindowIcon(Theme::getIconForClassId(m_object->classId())); + Theme::setWindowIcon(*this, m_object->classId()); if(QWidget* widget = createWidgetIfCustom(m_object)) { diff --git a/client/src/widget/tile/tilewidget.cpp b/client/src/widget/tile/tilewidget.cpp index 76983bff..ef6d0bd1 100644 --- a/client/src/widget/tile/tilewidget.cpp +++ b/client/src/widget/tile/tilewidget.cpp @@ -24,6 +24,7 @@ #include #include "../../network/object.hpp" #include "../../network/property.hpp" +#include "../../theme/theme.hpp" #include "../interfaceitemnamelabel.hpp" #include "../createwidget.hpp" #include "tileimagewidget.hpp" @@ -34,6 +35,8 @@ TileWidget::TileWidget(ObjectPtr object, QWidget* parent) , m_tabs{new QTabWidget(this)} , m_image{new TileImageWidget(this)} { + Theme::setWindowIcon(*this, m_object->classId()); + auto* grid = new QGridLayout(); grid->setContentsMargins(2, 2, 2, 2);