From 061f7ac20da390b47e3491c00d45232eda3f7c92 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 1 Apr 2020 13:19:18 +1100 Subject: [PATCH] mainwindow: show active project filename in the titlebar --- app/panel/project/project.cpp | 8 +++++--- app/panel/project/project.h | 5 ++++- app/project/project.cpp | 11 +++++++++++ app/project/project.h | 1 + app/window/mainwindow/mainwindow.cpp | 14 +++++++++++--- app/window/mainwindow/mainwindow.h | 4 ++-- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/panel/project/project.cpp b/app/panel/project/project.cpp index db24eed39..bf005bd82 100644 --- a/app/panel/project/project.cpp +++ b/app/panel/project/project.cpp @@ -78,16 +78,18 @@ Project *ProjectPanel::project() void ProjectPanel::set_project(Project *p) { if (project()) { + disconnect(project(), &Project::NameChanged, this, &ProjectPanel::UpdateSubtitle); disconnect(project(), &Project::NameChanged, this, &ProjectPanel::ProjectNameChanged); } explorer_->set_project(p); if (project()) { + connect(project(), &Project::NameChanged, this, &ProjectPanel::UpdateSubtitle); connect(project(), &Project::NameChanged, this, &ProjectPanel::ProjectNameChanged); } - ProjectNameChanged(); + UpdateSubtitle(); } QList ProjectPanel::SelectedItems() @@ -147,7 +149,7 @@ void ProjectPanel::Retranslate() { SetTitle(tr("Project")); - ProjectNameChanged(); + UpdateSubtitle(); } void ProjectPanel::ItemDoubleClickSlot(Item *item) @@ -173,7 +175,7 @@ void ProjectPanel::ShowNewMenu() new_menu.exec(QCursor::pos()); } -void ProjectPanel::ProjectNameChanged() +void ProjectPanel::UpdateSubtitle() { if (project() == nullptr) { SetSubtitle(tr("(none)")); diff --git a/app/panel/project/project.h b/app/panel/project/project.h index 23da1aea3..30fed2e92 100644 --- a/app/panel/project/project.h +++ b/app/panel/project/project.h @@ -57,6 +57,9 @@ public: public slots: void Edit(Item *item); +signals: + void ProjectNameChanged(); + private: virtual void Retranslate() override; @@ -67,7 +70,7 @@ private slots: void ShowNewMenu(); - void ProjectNameChanged(); + void UpdateSubtitle(); }; diff --git a/app/project/project.cpp b/app/project/project.cpp index 38fc3823c..16466dbe5 100644 --- a/app/project/project.cpp +++ b/app/project/project.cpp @@ -106,6 +106,17 @@ const QString &Project::filename() const return filename_; } +QString Project::pretty_filename() const +{ + QString fn = filename(); + + if (fn.isEmpty()) { + return tr("(untitled)"); + } else { + return fn; + } +} + void Project::set_filename(const QString &s) { filename_ = s; diff --git a/app/project/project.h b/app/project/project.h index 3a90bb6f3..fd2473899 100644 --- a/app/project/project.h +++ b/app/project/project.h @@ -53,6 +53,7 @@ public: QString name() const; const QString& filename() const; + QString pretty_filename() const; void set_filename(const QString& s); const QString& ocio_config() const; diff --git a/app/window/mainwindow/mainwindow.cpp b/app/window/mainwindow/mainwindow.cpp index 791766bd4..dfce3dc10 100644 --- a/app/window/mainwindow/mainwindow.cpp +++ b/app/window/mainwindow/mainwindow.cpp @@ -97,6 +97,7 @@ MainWindow::MainWindow(QWidget *parent) : sequence_viewer_panel_->ConnectTimeBasedPanel(param_panel_); sequence_viewer_panel_->ConnectTimeBasedPanel(curve_panel_); + connect(project_panel_, &ProjectPanel::ProjectNameChanged, this, &MainWindow::UpdateTitle); UpdateTitle(); } @@ -191,6 +192,8 @@ void MainWindow::ProjectOpen(Project* p) // FIXME Use settings data to create panels and restore state if they exist project_panel_->set_project(p); + UpdateTitle(); + SetDefaultLayout(); } @@ -231,9 +234,14 @@ void MainWindow::closeEvent(QCloseEvent *e) void MainWindow::UpdateTitle() { - setWindowTitle(QStringLiteral("%1 %2 - [*]%3").arg(QApplication::applicationName(), - QApplication::applicationVersion(), - tr("(untitled)"))); + if (project_panel_->project()) { + setWindowTitle(QStringLiteral("%1 %2 - [*]%3").arg(QApplication::applicationName(), + QApplication::applicationVersion(), + project_panel_->project()->pretty_filename())); + } else { + setWindowTitle(QStringLiteral("%1 %2").arg(QApplication::applicationName(), + QApplication::applicationVersion())); + } } TimelinePanel* MainWindow::AppendTimelinePanel() diff --git a/app/window/mainwindow/mainwindow.h b/app/window/mainwindow/mainwindow.h index 510c0e1f7..d0aba602a 100644 --- a/app/window/mainwindow/mainwindow.h +++ b/app/window/mainwindow/mainwindow.h @@ -59,8 +59,6 @@ protected: virtual void closeEvent(QCloseEvent* e) override; private: - void UpdateTitle(); - TimelinePanel* AppendTimelinePanel(); void TimelineFocused(TimelinePanel *panel); @@ -82,6 +80,8 @@ private: private slots: void FocusedPanelChanged(PanelWidget* panel); + void UpdateTitle(); + }; #endif