1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQMainWinDock.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #define y2log_component "qt-ui"
21 #include <ycp/y2log.h>
23 #include <QResizeEvent>
27 #include "YQMainWinDock.h"
32 YQMainWinDock::mainWinDock()
34 static YQMainWinDock * mainWinDock = 0;
37 mainWinDock = new YQMainWinDock();
43 YQMainWinDock::YQMainWinDock()
44 : QWidget( 0, // parent, name
45 YQUI::ui()->noBorder() ?
49 setWindowTitle( "YaST2" );
51 setFocusPolicy( Qt::StrongFocus );
53 resize( YQUI::ui()->defaultSize( YD_HORIZ ),
54 YQUI::ui()->defaultSize( YD_VERT ) );
56 y2debug( "MainWinDock initial size: %d x %d",
57 size().width(), size().height() );
61 YQMainWinDock::~YQMainWinDock()
68 YQMainWinDock::childEvent( QChildEvent * event )
72 QWidget * widget = dynamic_cast<QWidget *> ( event->child() );
74 if ( widget && ( event->type() == QEvent::ChildAdded ) )
80 QWidget::childEvent( event );
85 YQMainWinDock::resizeEvent( QResizeEvent * event )
89 resize( event->size() );
96 YQMainWinDock::resizeVisibleChild()
98 if ( ! _widgetStack.empty() )
100 QWidget * dialog = _widgetStack.back();
102 if ( dialog->size() != size() )
104 // y2debug( "Resizing child dialog %p to %d x %d", dialog, size().width(), size().height() );
105 dialog->resize( size() );
112 YQMainWinDock::show()
116 if ( ! _widgetStack.empty() )
118 QWidget * dialog = _widgetStack.back();
121 if ( dialog->isHidden() )
128 YQMainWinDock::add( QWidget * dialog )
130 YUI_CHECK_PTR( dialog );
132 if ( dialog->isHidden() )
135 y2debug( "Adding dialog %p to mainWinDock", dialog );
136 _widgetStack.push_back( dialog );
137 resizeVisibleChild();
145 YQMainWinDock::showCurrentDialog()
147 if ( ! _widgetStack.empty() )
149 QWidget * dialog = _widgetStack.back();
150 y2debug( "Showing dialog %p", dialog );
158 YQMainWinDock::remove( QWidget * dialog )
160 if ( _widgetStack.empty() )
164 dialog = _widgetStack.back();
166 if ( dialog == _widgetStack.back() )
168 // The most common case:
169 // The topmost dialog is to be removed
171 _widgetStack.pop_back();
173 y2debug( "Removing dialog %p from mainWinDock", dialog );
175 else // The less common (but more generic) case: Remove any dialog
177 YQMainWinDock::YQWidgetStack::iterator pos = findInStack( dialog );
179 if ( pos == _widgetStack.end() )
182 y2warning( "Found dialog somewhere in the middle of the widget stack" );
183 y2debug( "Removing dialog %p from mainWinDock", dialog );
185 _widgetStack.erase( pos );
188 if ( _widgetStack.empty() ) // No more main dialog?
189 hide(); // -> hide dock
192 dialog = _widgetStack.back(); // Get the next dialog from the stack
193 dialog->raise(); // and raise it
194 resizeVisibleChild();
199 YQMainWinDock::YQWidgetStack::iterator
200 YQMainWinDock::findInStack( QWidget * dialog )
202 for ( YQMainWinDock::YQWidgetStack::iterator it = _widgetStack.begin();
203 it != _widgetStack.end();
210 return _widgetStack.end();
215 YQMainWinDock::topmostDialog() const
217 if ( _widgetStack.empty() )
220 return _widgetStack.back();
225 YQMainWinDock::couldDock()
227 YDialog * topDialog = YDialog::topmostDialog( false ); // don't throw
229 if ( ! topDialog ) // No dialog at all?
230 return true; // Can dock the next one without problems
232 // The next dialog can be docked if there is no popup dialog currently open.
233 // This is equivalent to the topmost dialog on the YDialog stack being the
234 // same dialog as the topmost dialog of this MainWinDock.
236 return topDialog->widgetRep() == this->topmostDialog();
241 YQMainWinDock::closeEvent( QCloseEvent * event )
243 // The window manager "close window" button (and WM menu, e.g. Alt-F4) will be
244 // handled just like the user had clicked on the `id`( `cancel ) button in
245 // that dialog. It's up to the YCP application to handle this (if desired).
247 y2milestone( "Caught window manager close event - returning with YCancelEvent" );
249 YQUI::ui()->sendEvent( new YCancelEvent() );
254 YQMainWinDock::paintEvent( QPaintEvent * event )
260 #include "YQMainWinDock.moc"