Skip to content

Commit 745432d

Browse files
committed
Program panel name
1 parent 4608520 commit 745432d

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/gpilot/core/gcode/gcode.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ class GCode : public QObject
168168

169169
QString name() const { return m_name; }
170170
GCodeType type() const { return m_type; }
171-
void setName(const QString &name) { m_name = name; }
171+
void setName(const QString &name) {
172+
if (m_name == name) return;
173+
m_name = name;
174+
emit nameChanged(m_name);
175+
}
172176
void setType(GCodeType type) { m_type = type; }
173177

174178
// Response storage. Kept in a sparse hash indexed by position to avoid
@@ -210,6 +214,7 @@ class GCode : public QObject
210214
void loaded();
211215
// Emitted when execution enters or leaves an overlay (overlayId 0 = main program)
212216
void activeOverlayChanged(int overlayId);
217+
void nameChanged(const QString &name);
213218

214219
private slots:
215220
void onLinesUpdatedTimer();

src/gpilot/ui/forms/frmmain.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ void FrmMain::initializeProgramPanel()
485485
// });
486486
bindActiveProgram(&program());
487487

488+
connect(ui->program, &PartMainProgram::viewChanged, this,
489+
[this](PartMainProgram::View) { updateProgramTitle(); });
490+
488491
connect(ui->program, &PartMainProgram::clearRecentFiles, this, [this]() {
489492
Core::instance().clearRecentFiles(m_heightmapMode);
490493
});
@@ -2023,7 +2026,7 @@ void FrmMain::bindActiveProgram(GCode *target)
20232026
}
20242027

20252028
if (m_activeProgram) {
2026-
disconnect(m_activeProgram.data(), &GCode::lastSentCommandChanged, this, nullptr);
2029+
disconnect(m_activeProgram.data(), nullptr, this, nullptr);
20272030
}
20282031

20292032
ui->program->setProgram(target);
@@ -2033,6 +2036,42 @@ void FrmMain::bindActiveProgram(GCode *target)
20332036
connect(target, &GCode::lastSentCommandChanged, this, [this](int index) {
20342037
ui->program->scrollToIndex(index);
20352038
});
2039+
connect(target, &GCode::nameChanged, this, [this] {
2040+
updateProgramTitle();
2041+
});
2042+
}
2043+
2044+
updateProgramTitle();
2045+
}
2046+
2047+
bool FrmMain::programIsCentralWidget() const
2048+
{
2049+
return ui->program->parentWidget() == ui->centralWidget;
2050+
}
2051+
2052+
void FrmMain::updateProgramTitle()
2053+
{
2054+
QString title;
2055+
2056+
if (ui->program->view() == PartMainProgram::View::Heightmap) {
2057+
title = tr("Heightmap");
2058+
} else {
2059+
const GCode *p = m_activeProgram;
2060+
if (p && p->type() == GCodeType::Macro) {
2061+
title = tr("Program - macro `%1`").arg(p->name());
2062+
} else if (p && p->type() == GCodeType::MainProgram && !p->name().isEmpty()) {
2063+
title = tr("Program - main `%1`").arg(p->name());
2064+
} else {
2065+
title = tr("Program - main");
2066+
}
2067+
}
2068+
2069+
// Dock path: DockableTitle reacts to windowTitleChanged automatically.
2070+
ui->dockProgram->setWindowTitle(title);
2071+
2072+
// Central widget path: refresh the centralWidgetTitle label too.
2073+
if (programIsCentralWidget()) {
2074+
ui->centralWidgetTitle->setTitle(title);
20362075
}
20372076
}
20382077

src/gpilot/ui/forms/frmmain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ private slots:
274274
void applyUpdaterGCode(GCodeLoaderData *data);
275275

276276
void bindActiveProgram(GCode *target);
277+
void updateProgramTitle();
278+
bool programIsCentralWidget() const;
277279
QPointer<GCode> m_activeProgram;
278280
bool saveChanges(bool heightmapMode);
279281
void testConverter(int converterIndex = 0);

src/gpilot/ui/forms/frmmain_centralwidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ void FrmMain::switchCentralWidget(CentralWidgetConfig* requestedConfig)
8282
ui->centralWidget->layout()->addWidget(requestedConfig->widget);
8383
ui->centralWidgetTitle->setTitle(requestedConfig->title);
8484

85+
// For the program widget the title is dynamic (program name, type, view).
86+
if (requestedConfig->widget == ui->program) {
87+
updateProgramTitle();
88+
}
89+
8590
UiConfigs::instance().ui().setCentralWidget(requestedConfig->name);
8691
const QSignalBlocker blocker(requestedConfig->action);
8792
requestedConfig->action->setChecked(true);

0 commit comments

Comments
 (0)