author | zecke <zecke> | 2005-03-06 14:04:57 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-03-06 14:04:57 (UTC) |
commit | 125fa91f604cf9b7f3272798e72b6725fca9e23f (patch) (side-by-side diff) | |
tree | f7d328df5173a56254b6d5c8627eb53f897d9ebe | |
parent | fe51b2ed0ec3bccbcac880623123d2abc5d71a4e (diff) | |
download | opie-125fa91f604cf9b7f3272798e72b6725fca9e23f.zip opie-125fa91f604cf9b7f3272798e72b6725fca9e23f.tar.gz opie-125fa91f604cf9b7f3272798e72b6725fca9e23f.tar.bz2 |
-When going back from BigScreen to SmallScreen we resize the widgetstack,
show it and raise the 'main widget'
This should fix all bugs alwin spotted while deploying OWidgetStack
on Opie-Eye
-rw-r--r-- | libopie2/opieui/big-screen/owidgetstack.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libopie2/opieui/big-screen/owidgetstack.cpp b/libopie2/opieui/big-screen/owidgetstack.cpp index 00194b4..ac46cca 100644 --- a/libopie2/opieui/big-screen/owidgetstack.cpp +++ b/libopie2/opieui/big-screen/owidgetstack.cpp @@ -120,321 +120,326 @@ void OWidgetStack::forceMode( enum Mode mode) { break; } m_mode = mode; } /** * Adds a widget to the stack. The first widget added is considered * to be the mainwindow. This is important because if Opie is in * BigScreen mode the sizeHint of the MainWindow will be returned. * In Small Screen the sizeHint of the QWidgetStack is returned. * See QWidgetStack::sizeHint. * This widget takes ownership of the widget and may even reparent. * All windows will be hidden * * @param wid The QWidget to be added * @param id An ID for the Widget. If the ID is duplicated the last set widget will be related to the id * */ void OWidgetStack::addWidget( QWidget* wid, int id) { if (!wid) return; /* set our main widget */ if (!m_mWidget) m_mWidget = wid; m_list.insert( id, wid ); /** * adding does not raise any widget * But for our mainwidget we prepare * the right position with the right parent */ if (m_mode == SmallScreen ) m_stack->addWidget( wid,id ); else if ( m_mWidget == wid ) { wid->reparent(this, 0, contentsRect().topLeft() ); wid->hide(); }else { wid->reparent(0, WType_TopLevel, QPoint(10, 10) ); wid->hide(); } } /** * Remove the widget from the stack it'll be reparented to 0 * and ownership is dropped. You need to delete it. * If the removed widget was the mainwindow consider * to call setMainWindow. * * @param wid The QWidget to be removed */ void OWidgetStack::removeWidget( QWidget* wid) { if (!wid) return; if (m_mode == SmallScreen ) m_stack->removeWidget( wid ); wid->reparent(0, 0, QPoint(0, 0) ); m_list.remove( id(wid) ); if ( wid == m_mWidget ) m_mWidget = 0; } #if 0 /** * @internal_resons */ QSizeHint OWidgetStack::sizeHint()const { } /** * @internal_reasons */ QSizeHint OWidgetStack::minimumSizeHint()const { } #endif /** * This function tries to find the widget with the id. * You supplied a possible id in addWIdget. Note that not * QWidget::winId() is used. * * @param id The id to search for * * @return The widget or null * @see addWidget */ QWidget* OWidgetStack::widget( int id) const { return m_list[id]; } /** * Tries to find the assigned id for the widget * or returns -1 if no widget could be found * @param wid The widget to look for */ int OWidgetStack::id( QWidget* wid)const{ if (m_list.isEmpty() ) return -1; QMap<int, QWidget*>::ConstIterator it = m_list.begin(); for ( ; it != m_list.end(); ++it ) if ( it.data() == wid ) break; /* if not at the end return the key */ return it == m_list.end() ? -1 : it.key(); } /** * This function returns the currently visible * widget. In BigScreen mode the mainwindow * is returned */ QWidget* OWidgetStack::visibleWidget()const { if (m_mode == SmallScreen ) return m_stack->visibleWidget(); else return m_mWidget; } /** * This method raises the widget wit the specefic id. * Note that in BigScreen mode the widget is made visible * but the other ( previous) visible widget(s) will not * be made invisible. If you need this use hideWidget(). * * @param id Raise the widget with id */ void OWidgetStack::raiseWidget( int id) { return raiseWidget( widget( id ) ); } /** * This is an overloaded function and only differs in its parameters. * @see raiseWidget( int ) */ void OWidgetStack::raiseWidget( QWidget* wid) { m_last = wid; if (m_mode == SmallScreen ) m_stack->raiseWidget( wid ); else { int ide; emit aboutToShow( wid ); /* if someone is connected and the widget is actually available */ if ( receivers( SIGNAL(aboutToShow(int) ) ) && ( (ide = id( wid ) ) != -1 ) ) emit aboutToShow( ide ); /* ### FIXME PLACE THE WIDGET right */ wid->show(); } } /** * This will hide the currently visible widget * and raise the widget specified by the parameter. * Note that this method does not use visibleWIdget but remembers * the last raisedWidget */ void OWidgetStack::hideWidget( int id) { /* hiding our main widget wouldn't be smart */ if ( m_mode == BigScreen && m_last != m_mWidget ) m_last->hide(); raiseWidget( id ); } /** * This is overloaded and only differs in the parameters * it takes. */ void OWidgetStack::hideWidget( QWidget* wid) { /* still not smart */ if ( m_mode == BigScreen && m_last != m_mWidget ) m_last->hide(); raiseWidget( wid ); } -bool OWidgetStack::eventFilter( QObject* obj, QEvent* e) { +bool OWidgetStack::eventFilter( QObject*, QEvent* e) { if ( e->type() == QEvent::Resize && !m_forced ) { QResizeEvent *res = static_cast<QResizeEvent*>( e ); QSize size = res->size(); if ( size.width() >= mode_size ) switchTop(); else switchStack(); } return false; } /** * @internal_resons */ void OWidgetStack::resizeEvent( QResizeEvent* ev ) { QFrame::resizeEvent( ev ); if (m_mode == SmallScreen ) m_stack->setGeometry( frameRect() ); else if (m_mWidget ) m_mWidget->setGeometry( frameRect() ); } /** * setMainWindow gives the OWidgetStack a hint which * window should always stay inside the stack. * Normally the first added widget is considered to be * the mainwindow but you can change this with this * function. * If in BigScreen mode the current mainwindow will be reparented * and hidden. The position will be taken by the new one. * If the old MainWindow was hidden the new window will * also be hidden. If the window was visible the new mainwindow * will be made visible too and the old one hidden. If there * was no mainwindow it will be hidden as well. * * @param wid The new mainwindow */ void OWidgetStack::setMainWindow( QWidget* wid ) { if (m_mode == BigScreen ) { bool wasVisible = false; if (m_mWidget ) { wasVisible = !m_mWidget->isHidden(); /* hidden by default */ m_mWidget->reparent(0, WType_TopLevel, QPoint(10, 10) ); } wid->reparent(this, 0, frameRect().topLeft() ); if (wasVisible) wid->show(); } m_mWidget = wid; } /** * this is an overloaded member and only differs * in the type of arguments. * @see setMainWindow(QWidget*) */ void OWidgetStack::setMainWindow( int id) { setMainWindow( widget( id ) ); } /* * this function switches to a stack ;) */ void OWidgetStack::switchStack() { if (m_stack ) { m_stack->setGeometry( frameRect() ); return; } m_mode = SmallScreen; m_stack = new QWidgetStack(this); + m_stack->setGeometry( frameRect() ); + m_stack->show(); connect(m_stack, SIGNAL(aboutToShow(QWidget*) ), this, SIGNAL(aboutToShow(QWidget*) ) ); connect(m_stack, SIGNAL(aboutToShow(int) ), this, SIGNAL(aboutToShow(int) ) ); /* now reparent the widgets... luckily QWidgetSatck does most of the work */ if (m_list.isEmpty() ) return; QMap<int, QWidget*>::Iterator it = m_list.begin(); for ( ; it != m_list.end(); ++it ) m_stack->addWidget( it.data(), it.key() ); + if ( m_mWidget ) + m_stack->raiseWidget( m_mWidget ); + } /* * we will switch to top level mode * reparent the list of widgets and then delete the stack */ void OWidgetStack::switchTop() { m_mode = BigScreen; /* this works because it is guaranteed that switchStack was called at least once*/ if (!m_stack && m_mWidget) { m_mWidget->setGeometry( frameRect() ); return; }else if (!m_stack) return; if (!m_list.isEmpty() ) { QMap<int, QWidget*>::Iterator it = m_list.begin(); for ( ; it != m_list.end(); ++it ) { /* better than reparenting twice */ if ( it.data() == m_mWidget ) { m_mWidget->reparent(this, 0, frameRect().topLeft() ); m_mWidget->setGeometry( frameRect() ); m_mWidget->show(); }else /* ### FIXME we need to place the widget better */ it.data()->reparent(0, WType_TopLevel, QPoint(10, 10) ); } } delete m_stack; m_stack = 0; } } } |