kivio
kivio_stackbar.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kivio_stackbar.h"
00020 #include "stencilbarbutton.h"
00021
00022 #include <qlayout.h>
00023 #include <qpushbutton.h>
00024 #include <qapplication.h>
00025
00026 #include <kdebug.h>
00027
00028
00029 KivioStackBar::KivioStackBar(KivioView* view, QWidget* parent, const char* name)
00030 : QDockWindow(parent, name), m_view(view)
00031 {
00032 QDockWindow::boxLayout()->setSpacing(0);
00033 QDockWindow::boxLayout()->setMargin(0);
00034 setResizeEnabled(true);
00035 setNewLine(true);
00036 m_visiblePage = 0;
00037
00038 connect(this, SIGNAL(placeChanged(QDockWindow::Place)), this, SLOT(newPlace(QDockWindow::Place)));
00039 }
00040
00041 KivioStackBar::~KivioStackBar()
00042 {
00043 kdDebug(43000) << "KivioStackBar::~KivioStackBar()" << endl;
00044 }
00045
00046 void KivioStackBar::insertPage( QWidget* w, const QString& title )
00047 {
00048 if (w->parent() != this) {
00049 w->reparent(this,QPoint(0,0));
00050 }
00051
00052 w->hide();
00053 w->setFocusPolicy(NoFocus);
00054
00055 setMinimumWidth( QMAX(minimumSize().width(),w->minimumSize().width() ) );
00056 setMaximumWidth( QMAX(maximumSize().width(),w->maximumSize().width() ) );
00057
00058 DragBarButton* b = new DragBarButton( title, this );
00059 b->setOrientation(orientation());
00060 connect( b, SIGNAL(clicked()), SLOT(showButtonPage()) );
00061 connect( b, SIGNAL(beginDrag()), SLOT(buttonBeginDrag()) );
00062 connect( b, SIGNAL(finishDrag()), SLOT(buttonFinishDrag()) );
00063 connect( b, SIGNAL(closeRequired(DragBarButton*)), SLOT(slotDeleteButton(DragBarButton*)) );
00064 connect(this, SIGNAL(orientationChanged(Orientation)), b, SLOT(setOrientation(Orientation)));
00065
00066 boxLayout()->addWidget(b);
00067 boxLayout()->addWidget(w, 1);
00068
00069 m_data.insert(b, w);
00070 b->show();
00071
00072 if (m_data.count() == 1) {
00073 showPage(w);
00074 }
00075 }
00076
00077 void KivioStackBar::slotDeleteButton( DragBarButton *b )
00078 {
00079 QWidget *pWidget = m_data[b];
00080 kdDebug(43000) << "Emitting deleteButton" << endl;
00081 emit deleteButton(b, pWidget, this);
00082 }
00083
00084 void KivioStackBar::showPage( QWidget* w )
00085 {
00086 emit aboutToShow( w );
00087
00088 if(w == m_visiblePage) {
00089 return;
00090 }
00091
00092 if ( m_visiblePage ) {
00093 m_visiblePage->hide();
00094 w->show();
00095 } else {
00096 w->show();
00097 }
00098
00099 m_visiblePage = w;
00100 }
00101
00102 void KivioStackBar::showButtonPage()
00103 {
00104 DragBarButton* b = (DragBarButton*)sender();
00105 showPage(findPage(b));
00106 }
00107
00108 QWidget* KivioStackBar::findPage( DragBarButton* w )
00109 {
00110 return m_data[w];
00111 }
00112
00113
00114
00115
00116 void KivioStackBar::removePage( QWidget* widget )
00117 {
00118 QPtrDictIterator<QWidget> it(m_data);
00119 DragBarButton* pBtn;
00120 while ( it.current() ) {
00121 if ( it.current() == widget ) {
00122 widget->hide();
00123 pBtn = (DragBarButton*)it.currentKey();
00124 it.current()->reparent(0, QPoint(0,0));
00125 m_data.remove( it.currentKey() );
00126 delete pBtn;
00127 break;
00128 }
00129 ++it;
00130 }
00131
00132 if ( it.toFirst() ) {
00133 showPage( it.current() );
00134 } else {
00135 m_visiblePage = 0L;
00136 }
00137 }
00138
00139 void KivioStackBar::deletePageAndButton( DragBarButton *pBtn )
00140 {
00141 QWidget *pPage;
00142
00143 if( !pBtn ) {
00144 kdDebug(43000) << "KivioStackBar::deletePageAndButton() - pBtn is NULL!" << endl;
00145 return;
00146 }
00147
00148 pPage = m_data[pBtn];
00149 if( !pPage ) {
00150 kdDebug(43000) << "KivioStackBar::deletePageAndButton() - failed to find the key/value pair" << endl;
00151 return;
00152 }
00153
00154 if( m_data.remove( pBtn )==false ) {
00155 kdDebug(43000) << "KivioStackBar::deletePageAndButton() - remove failed" << endl;
00156 return;
00157 }
00158
00159 if(pPage == m_visiblePage) {
00160 m_visiblePage = 0L;
00161 }
00162
00163 delete pBtn;
00164 delete pPage;
00165
00166
00167
00168 QPtrDictIterator<QWidget> it(m_data);
00169 if ( it.toFirst() ) {
00170 showPage( it.current() );
00171 }
00172 }
00173
00174 QWidget* KivioStackBar::findPage( const QString& name )
00175 {
00176 QPtrDictIterator<QWidget> it(m_data);
00177 while ( it.current() ) {
00178 if ( it.current()->name() == name )
00179 return it.current();
00180 ++it;
00181 }
00182 return 0L;
00183 }
00184
00185 void KivioStackBar::buttonBeginDrag()
00186 {
00187 emit beginDragPage((DragBarButton*)sender());
00188 }
00189
00190 void KivioStackBar::buttonFinishDrag()
00191 {
00192 emit finishDragPage((DragBarButton*)sender());
00193 }
00194
00195 void KivioStackBar::closeEvent(QCloseEvent* ev)
00196 {
00197 QPtrDictIterator<QWidget> it(m_data);
00198 while ( it.current() ) {
00199 slotDeleteButton((DragBarButton*)it.currentKey());
00200 if (it.current())
00201 ++it;
00202 }
00203
00204 ev->ignore();
00205 }
00206
00207 void KivioStackBar::newPlace(QDockWindow::Place place)
00208 {
00209 if((place == OutsideDock) && (orientation() == Qt::Horizontal)) {
00210 setOrientation(Qt::Vertical);
00211 }
00212 }
00213
00214 #include "kivio_stackbar.moc"
|