Display current tab name in window title.

This commit is contained in:
Florian Geyer 2012-04-21 22:02:12 +02:00 committed by Felix Geyer
parent e7d0dfbd26
commit 9726046e24
4 changed files with 19 additions and 3 deletions

View File

@ -351,6 +351,7 @@ void DatabaseTabWidget::updateTabName(Database* db)
tabName.append("*");
}
setTabText(index, tabName);
Q_EMIT tabNameChanged();
}
int DatabaseTabWidget::databaseIndex(Database* db)

View File

@ -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);

View File

@ -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();
}
}

View File

@ -37,10 +37,12 @@ protected:
private Q_SLOTS:
void setMenuActionState(int index = -1);
void updateWindowTitle();
private:
QScopedPointer<Ui::MainWindow> m_ui;
static const QString m_baseWindowTitle;
Q_DISABLE_COPY(MainWindow)
};