qeditor: rework modified indicator, register tab names depend on content

Because Qt doesn't support QObject multiple inherance, it is a bit tricky
to have a base class which interact with the UI. The register tab name
now display:
- file dump name (for dumps)
- hwstub device path (for hwstub)
And the register editor display the filename
Change-Id: If2579992098c02627c67d560c824f1668e73bc45
Reviewed-on: http://gerrit.rockbox.org/979
Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
This commit is contained in:
Amaury Pouly 2014-09-18 21:36:17 +02:00
parent dbb59291e7
commit 970c2482dd
7 changed files with 129 additions and 48 deletions

View file

@ -14,6 +14,25 @@
#include "regtab.h"
#include "regedit.h"
/**
* DocumentTab
*/
void DocumentTab::OnModified(bool modified)
{
if(m_tab)
m_tab->SetTabModified(this, modified);
}
void DocumentTab::SetTabName(const QString& name)
{
if(m_tab)
m_tab->SetTabName(this, name);
}
/**
* MyTabWidget
*/
MyTabWidget::MyTabWidget()
{
setMovable(true);
@ -21,6 +40,20 @@ MyTabWidget::MyTabWidget()
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(OnCloseTab(int)));
}
void MyTabWidget::SetTabModified(DocumentTab *doc, bool modified)
{
int index = indexOf(doc->GetWidget());
if(modified)
setTabIcon(index, QIcon::fromTheme("document-save"));
else
setTabIcon(index, QIcon());
}
void MyTabWidget::SetTabName(DocumentTab *doc, const QString& name)
{
setTabText(indexOf(doc->GetWidget()), name);
}
bool MyTabWidget::CloseTab(int index)
{
QWidget *w = this->widget(index);
@ -40,6 +73,10 @@ void MyTabWidget::OnCloseTab(int index)
CloseTab(index);
}
/**
* MainWindow
*/
MainWindow::MainWindow(Backend *backend)
:m_backend(backend)
{
@ -144,20 +181,10 @@ void MainWindow::OnLoadDesc()
}
}
void MainWindow::OnTabModified(bool modified)
void MainWindow::AddTab(DocumentTab *doc, const QString& title)
{
QWidget *sender = qobject_cast< QWidget* >(QObject::sender());
int index = m_tab->indexOf(sender);
if(modified)
m_tab->setTabIcon(index, QIcon::fromTheme("document-save"));
else
m_tab->setTabIcon(index, QIcon());
}
void MainWindow::AddTab(QWidget *tab, const QString& title)
{
connect(tab, SIGNAL(OnModified(bool)), this, SLOT(OnTabModified(bool)));
m_tab->setCurrentIndex(m_tab->addTab(tab, title));
m_tab->setCurrentIndex(m_tab->addTab(doc->GetWidget(), title));
doc->SetTabWidget(m_tab);
}
void MainWindow::OnNewRegTab()