kivio

kivio_stackbar.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_stackbar.h"
20#include "stencilbarbutton.h"
21
22#include <tqlayout.h>
23#include <tqpushbutton.h>
24#include <tqapplication.h>
25
26#include <kdebug.h>
27
28
29KivioStackBar::KivioStackBar(KivioView* view, TQWidget* parent, const char* name)
30 : TQDockWindow(parent, name), m_view(view)
31{
32 TQDockWindow::boxLayout()->setSpacing(0);
33 TQDockWindow::boxLayout()->setMargin(0);
34 setResizeEnabled(true);
35 setNewLine(true);
36 m_visiblePage = 0;
37
38 connect(this, TQ_SIGNAL(placeChanged(TQDockWindow::Place)), this, TQ_SLOT(newPlace(TQDockWindow::Place)));
39}
40
41KivioStackBar::~KivioStackBar()
42{
43 kdDebug(43000) << "KivioStackBar::~KivioStackBar()" << endl;
44}
45
46void KivioStackBar::insertPage( TQWidget* w, const TQString& title )
47{
48 if (w->parent() != this) {
49 w->reparent(this,TQPoint(0,0));
50 }
51
52 w->hide();
53 w->setFocusPolicy(TQWidget::NoFocus);
54
55 setMinimumWidth( TQMAX(minimumSize().width(),w->minimumSize().width() ) );
56 setMaximumWidth( TQMAX(maximumSize().width(),w->maximumSize().width() ) );
57
58 DragBarButton* b = new DragBarButton( title, this );
59 b->setOrientation(orientation());
60 connect( b, TQ_SIGNAL(clicked()), TQ_SLOT(showButtonPage()) );
61 connect( b, TQ_SIGNAL(beginDrag()), TQ_SLOT(buttonBeginDrag()) );
62 connect( b, TQ_SIGNAL(finishDrag()), TQ_SLOT(buttonFinishDrag()) );
63 connect( b, TQ_SIGNAL(closeRequired(DragBarButton*)), TQ_SLOT(slotDeleteButton(DragBarButton*)) );
64 connect(this, TQ_SIGNAL(orientationChanged(TQt::Orientation)), b, TQ_SLOT(setOrientation(TQt::Orientation)));
65
66 boxLayout()->addWidget(b);
67 boxLayout()->addWidget(w, 1);
68
69 m_data.insert(b, w);
70 b->show();
71
72 if (m_data.count() == 1) {
73 showPage(w);
74 }
75}
76
77void KivioStackBar::slotDeleteButton( DragBarButton *b )
78{
79 TQWidget *pWidget = m_data[b];
80 kdDebug(43000) << "Emitting deleteButton" << endl;
81 emit deleteButton(b, pWidget, this);
82}
83
84void KivioStackBar::showPage( TQWidget* w )
85{
86 emit aboutToShow( w );
87
88 if(w == m_visiblePage) {
89 return;
90 }
91
92 if ( m_visiblePage ) {
93 m_visiblePage->hide();
94 w->show();
95 } else {
96 w->show();
97 }
98
99 m_visiblePage = w;
100}
101
102void KivioStackBar::showButtonPage()
103{
104 DragBarButton* b = (DragBarButton*)sender();
105 showPage(findPage(b));
106}
107
108TQWidget* KivioStackBar::findPage( DragBarButton* w )
109{
110 return m_data[w];
111}
112
113/*
114 * This does *NOT* delete the widget
115*/
116void KivioStackBar::removePage( TQWidget* widget )
117{
118 TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
119 DragBarButton* pBtn;
120 while ( it.current() ) {
121 if ( it.current() == widget ) {
122 widget->hide();
123 pBtn = (DragBarButton*)it.currentKey();
124 it.current()->reparent(0, TQPoint(0,0));
125 m_data.remove( it.currentKey() );
126 delete pBtn;
127 break;
128 }
129 ++it;
130 }
131
132 if ( it.toFirst() ) {
133 showPage( it.current() );
134 } else {
135 m_visiblePage = 0L;
136 }
137}
138
139void KivioStackBar::deletePageAndButton( DragBarButton *pBtn )
140{
141 TQWidget *pPage;
142
143 if( !pBtn ) {
144 kdDebug(43000) << "KivioStackBar::deletePageAndButton() - pBtn is NULL!" << endl;
145 return;
146 }
147
148 pPage = m_data[pBtn];
149 if( !pPage ) {
150 kdDebug(43000) << "KivioStackBar::deletePageAndButton() - failed to find the key/value pair" << endl;
151 return;
152 }
153
154 if( m_data.remove( pBtn )==false ) {
155 kdDebug(43000) << "KivioStackBar::deletePageAndButton() - remove failed" << endl;
156 return;
157 }
158
159 if(pPage == m_visiblePage) {
160 m_visiblePage = 0L;
161 }
162
163 delete pBtn;
164 delete pPage;
165
166
167 // Set the next current page, or set it to nothing
168 TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
169 if ( it.toFirst() ) {
170 showPage( it.current() );
171 }
172}
173
174TQWidget* KivioStackBar::findPage( const TQString& name )
175{
176 TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
177 while ( it.current() ) {
178 if ( it.current()->name() == name )
179 return it.current();
180 ++it;
181 }
182 return 0L;
183}
184
185void KivioStackBar::buttonBeginDrag()
186{
187 emit beginDragPage((DragBarButton*)sender());
188}
189
190void KivioStackBar::buttonFinishDrag()
191{
192 emit finishDragPage((DragBarButton*)sender());
193}
194
195void KivioStackBar::closeEvent(TQCloseEvent* ev)
196{
197 TQPtrDictIterator<TQWidget> it(m_data); // iterator for dict
198 while ( it.current() ) {
199 slotDeleteButton((DragBarButton*)it.currentKey());
200 if (it.current())
201 ++it;
202 }
203
204 ev->ignore();
205}
206
207void KivioStackBar::newPlace(TQDockWindow::Place place)
208{
209 if((place == OutsideDock) && (orientation() == TQt::Horizontal)) {
210 setOrientation(TQt::Vertical);
211 }
212}
213
214#include "kivio_stackbar.moc"