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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
* Kivio - Visual Modelling and Flowcharting
* Copyright (C) 2000-2001 theKompany.com & Dave Marotti
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kivio_stackbar.h"
#include "stencilbarbutton.h"
#include <tqlayout.h>
#include <tqpushbutton.h>
#include <tqapplication.h>
#include <kdebug.h>
KivioStackBar::KivioStackBar(KivioView* view, TQWidget* parent, const char* name)
: TQDockWindow(parent, name), m_view(view)
{
TQDockWindow::boxLayout()->setSpacing(0);
TQDockWindow::boxLayout()->setMargin(0);
setResizeEnabled(true);
setNewLine(true);
m_visiblePage = 0;
connect(this, TQT_SIGNAL(placeChanged(TQDockWindow::Place)), this, TQT_SLOT(newPlace(TQDockWindow::Place)));
}
KivioStackBar::~KivioStackBar()
{
kdDebug(43000) << "KivioStackBar::~KivioStackBar()" << endl;
}
void KivioStackBar::insertPage( TQWidget* w, const TQString& title )
{
if (TQT_BASE_OBJECT(w->parent()) != TQT_BASE_OBJECT(this)) {
w->reparent(this,TQPoint(0,0));
}
w->hide();
w->setFocusPolicy(TQ_NoFocus);
setMinimumWidth( TQMAX(tqminimumSize().width(),w->tqminimumSize().width() ) );
setMaximumWidth( TQMAX(tqmaximumSize().width(),w->tqmaximumSize().width() ) );
DragBarButton* b = new DragBarButton( title, this );
b->setOrientation(orientation());
connect( b, TQT_SIGNAL(clicked()), TQT_SLOT(showButtonPage()) );
connect( b, TQT_SIGNAL(beginDrag()), TQT_SLOT(buttonBeginDrag()) );
connect( b, TQT_SIGNAL(finishDrag()), TQT_SLOT(buttonFinishDrag()) );
connect( b, TQT_SIGNAL(closeRequired(DragBarButton*)), TQT_SLOT(slotDeleteButton(DragBarButton*)) );
connect(this, TQT_SIGNAL(orientationChanged(Qt::Orientation)), b, TQT_SLOT(setOrientation(Qt::Orientation)));
boxLayout()->addWidget(b);
boxLayout()->addWidget(w, 1);
m_data.insert(b, w);
b->show();
if (m_data.count() == 1) {
showPage(w);
}
}
void KivioStackBar::slotDeleteButton( DragBarButton *b )
{
TQWidget *pWidget = m_data[b];
kdDebug(43000) << "Emitting deleteButton" << endl;
emit deleteButton(b, pWidget, this);
}
void KivioStackBar::showPage( TQWidget* w )
{
emit aboutToShow( w );
if(w == m_visiblePage) {
return;
}
if ( m_visiblePage ) {
m_visiblePage->hide();
w->show();
} else {
w->show();
}
m_visiblePage = w;
}
void KivioStackBar::showButtonPage()
{
DragBarButton* b = (DragBarButton*)sender();
showPage(findPage(b));
}
TQWidget* KivioStackBar::findPage( DragBarButton* w )
{
return m_data[w];
}
/*
* This does *NOT* delete the widget
*/
void KivioStackBar::removePage( TQWidget* widget )
{
TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
DragBarButton* pBtn;
while ( it.current() ) {
if ( it.current() == widget ) {
widget->hide();
pBtn = (DragBarButton*)it.currentKey();
it.current()->reparent(0, TQPoint(0,0));
m_data.remove( it.currentKey() );
delete pBtn;
break;
}
++it;
}
if ( it.toFirst() ) {
showPage( it.current() );
} else {
m_visiblePage = 0L;
}
}
void KivioStackBar::deletePageAndButton( DragBarButton *pBtn )
{
TQWidget *pPage;
if( !pBtn ) {
kdDebug(43000) << "KivioStackBar::deletePageAndButton() - pBtn is NULL!" << endl;
return;
}
pPage = m_data[pBtn];
if( !pPage ) {
kdDebug(43000) << "KivioStackBar::deletePageAndButton() - failed to find the key/value pair" << endl;
return;
}
if( m_data.remove( pBtn )==false ) {
kdDebug(43000) << "KivioStackBar::deletePageAndButton() - remove failed" << endl;
return;
}
if(pPage == m_visiblePage) {
m_visiblePage = 0L;
}
delete pBtn;
delete pPage;
// Set the next current page, or set it to nothing
TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
if ( it.toFirst() ) {
showPage( it.current() );
}
}
TQWidget* KivioStackBar::findPage( const TQString& name )
{
TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
while ( it.current() ) {
if ( it.current()->name() == name )
return it.current();
++it;
}
return 0L;
}
void KivioStackBar::buttonBeginDrag()
{
emit beginDragPage((DragBarButton*)sender());
}
void KivioStackBar::buttonFinishDrag()
{
emit finishDragPage((DragBarButton*)sender());
}
void KivioStackBar::closeEvent(TQCloseEvent* ev)
{
TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
while ( it.current() ) {
slotDeleteButton((DragBarButton*)it.currentKey());
if (it.current())
++it;
}
ev->ignore();
}
void KivioStackBar::newPlace(TQDockWindow::Place place)
{
if((place == OutsideDock) && (orientation() == Qt::Horizontal)) {
setOrientation(Qt::Vertical);
}
}
#include "kivio_stackbar.moc"
|