From 9726046e24151d4628913e1d09f902d50db10788 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sat, 21 Apr 2012 22:02:12 +0200 Subject: [PATCH] Display current tab name in window title. --- src/gui/DatabaseTabWidget.cpp | 1 + src/gui/DatabaseTabWidget.h | 1 + src/gui/MainWindow.cpp | 18 +++++++++++++++--- src/gui/MainWindow.h | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 04dff83f4..b9a71a2a2 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -351,6 +351,7 @@ void DatabaseTabWidget::updateTabName(Database* db) tabName.append("*"); } setTabText(index, tabName); + Q_EMIT tabNameChanged(); } int DatabaseTabWidget::databaseIndex(Database* db) diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index cef09ce6a..ccf2fb72a 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -71,6 +71,7 @@ public Q_SLOTS: Q_SIGNALS: void entrySelectionChanged(bool singleEntrySelected); void currentWidgetIndexChanged(int index); + void tabNameChanged(); private Q_SLOTS: void updateTabName(Database* db); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index cb71ca5d5..df4861856 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -35,6 +35,8 @@ MainWindow::MainWindow() connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), SLOT(setMenuActionState())); connect(m_ui->tabWidget, SIGNAL(currentWidgetIndexChanged(int)), SLOT(setMenuActionState(int))); + connect(m_ui->tabWidget, SIGNAL(tabNameChanged()), SLOT(updateWindowTitle())); + connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateWindowTitle())); connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(newDatabase())); connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_ui->tabWidget, SLOT(openDatabase())); @@ -56,6 +58,8 @@ MainWindow::~MainWindow() { } +const QString MainWindow::m_baseWindowTitle = "KeePassX"; + void MainWindow::setMenuActionState(int index) { if (m_ui->tabWidget->currentIndex() != -1) { @@ -128,6 +132,17 @@ void MainWindow::setMenuActionState(int index) } } +void MainWindow::updateWindowTitle() +{ + int index = m_ui->tabWidget->currentIndex(); + if (index == -1) { + setWindowTitle(m_baseWindowTitle); + } + else { + setWindowTitle(m_ui->tabWidget->tabText(index).append(" - ").append(m_baseWindowTitle)); + } +} + void MainWindow::closeEvent(QCloseEvent *event) { if (!m_ui->tabWidget->closeAllDatabases()) { event->ignore(); @@ -136,6 +151,3 @@ void MainWindow::closeEvent(QCloseEvent *event) { event->accept(); } } - - - diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index b19067c36..0b6381a85 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -37,10 +37,12 @@ protected: private Q_SLOTS: void setMenuActionState(int index = -1); + void updateWindowTitle(); private: QScopedPointer m_ui; + static const QString m_baseWindowTitle; Q_DISABLE_COPY(MainWindow) };