1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include "DictionaryTabWidget.h"
#include "MainWindow.h"
#include "DictTableModel.h"
#include "DictTableView.h"
#include "../dictionary/Dictionary.h"
DictionaryTabWidget::DictionaryTabWidget(MainWindow* aMainWin):
QTabWidget( aMainWin ), m_mainWin( aMainWin ), createdEditorsNum(0)
{
setDocumentMode( true );
setTabsClosable( true );
setMovable( true );
connect( this, SIGNAL(tabCloseRequested(int)), SLOT(closeTab(int)) );
m_undoGroup = new QUndoGroup( this );
m_continueLbl = new QLabel( this );
m_continueLbl->hide();
m_continueLbl->setPixmap(QPixmap(":/images/continue-search.png"));
}
/** The tab is removed automatically when the widget is destroyed.
The undo stack is removed from group automatically, when the stack is destroyed.
*/
void DictionaryTabWidget::closeTab( int aIndex )
{
if( aIndex == -1 )
aIndex = currentIndex();
bool canRemove = m_mainWin->proposeToSave( aIndex );
if( canRemove )
delete widget( aIndex );
}
int DictionaryTabWidget::addDictTab( DictTableModel* aDictModel )
{
DictTableView* dictView = new DictTableView( aDictModel );
int tabIx = addTab( dictView, "" );
setCurrentIndex( tabIx );
QUndoStack* undoStack = aDictModel->undoStack();
m_undoGroup->addStack( undoStack );
m_undoGroup->setActiveStack( undoStack );
connect( undoStack, SIGNAL(cleanChanged(bool)), aDictModel->dictionary(), SLOT(setContentClean(bool)) );
connect( dictView->itemDelegate(), SIGNAL(editorCreated()), SLOT(createEditor()) );
connect( dictView->itemDelegate(), SIGNAL(editorDestroyed()), SLOT(destroyEditor()) );
return tabIx;
}
const DictTableView* DictionaryTabWidget::curDictView() const
{
QWidget* curWidget = currentWidget();
if( !curWidget )
return NULL;
DictTableView* curView = static_cast<DictTableView*>( curWidget );
return curView;
}
void DictionaryTabWidget::setCurrentIndex( int aTabIx )
{
QTabWidget::setCurrentIndex( aTabIx );
const DictTableView* dictView = curDictView();
if( dictView )
{
const DictTableModel* dictModel = dictView->dicTableModel();
if( dictModel )
m_undoGroup->setActiveStack( dictModel->undoStack() );
}
}
void DictionaryTabWidget::goToDictionaryRecord( int aDictIx, int aRecordRow )
{
setCurrentIndex( aDictIx );
QWidget* curWidget = currentWidget();
Q_ASSERT( curWidget );
QAbstractItemView* curView = static_cast<QAbstractItemView*>( curWidget );
Q_ASSERT( curView );
curView->setFocus();
QModelIndex index = curView->model()->index( aRecordRow, 0 );
curView->setCurrentIndex( index );
}
void DictionaryTabWidget::cleanUndoStack()
{
m_undoGroup->activeStack()->setClean();
}
bool DictionaryTabWidget::undoStackIsClean() const
{
return m_undoGroup->isClean();
}
void DictionaryTabWidget::showContinueSearch()
{
m_continueLbl->move( rect().center() - m_continueLbl->rect().center() );
m_continueLbl->show();
QTimer::singleShot( 500, m_continueLbl, SLOT(hide()) );
}
void DictionaryTabWidget::createEditor()
{
createdEditorsNum++;
emit editingStateChanged();
}
void DictionaryTabWidget::destroyEditor()
{
createdEditorsNum--;
emit editingStateChanged();
}
|