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() ?
46 Qt::FramelessWindowHint :
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::resizeEvent( QResizeEvent * event )
72 resize( event->size() );
79 YQMainWinDock::resizeVisibleChild()
81 if ( ! _widgetStack.empty() )
83 QWidget * dialog = _widgetStack.back();
85 if ( dialog->size() != size() )
87 // y2debug( "Resizing child dialog %p to %d x %d", dialog, size().width(), size().height() );
88 dialog->resize( size() );
99 if ( ! _widgetStack.empty() )
101 QWidget * dialog = _widgetStack.back();
109 YQMainWinDock::add( QWidget * dialog )
111 YUI_CHECK_PTR( dialog );
113 if ( !_widgetStack.empty() )
114 _widgetStack.back()->hide();
119 y2debug( "Adding dialog %p to mainWinDock", dialog );
120 _widgetStack.push_back( dialog );
121 resizeVisibleChild();
128 YQMainWinDock::showCurrentDialog()
130 if ( ! _widgetStack.empty() )
132 QWidget * dialog = _widgetStack.back();
133 y2debug( "Showing dialog %p", dialog );
141 YQMainWinDock::remove( QWidget * dialog )
143 if ( _widgetStack.empty() )
147 dialog = _widgetStack.back();
149 if ( dialog == _widgetStack.back() )
151 // The most common case:
152 // The topmost dialog is to be removed
154 _widgetStack.pop_back();
156 y2debug( "Removing dialog %p from mainWinDock", dialog );
158 else // The less common (but more generic) case: Remove any dialog
160 YQMainWinDock::YQWidgetStack::iterator pos = findInStack( dialog );
162 if ( pos == _widgetStack.end() )
165 y2warning( "Found dialog somewhere in the middle of the widget stack" );
166 y2debug( "Removing dialog %p from mainWinDock", dialog );
168 _widgetStack.erase( pos );
171 if ( _widgetStack.empty() ) // No more main dialog?
172 hide(); // -> hide dock
175 dialog = _widgetStack.back(); // Get the next dialog from the stack
176 dialog->raise(); // and raise it
178 resizeVisibleChild();
183 YQMainWinDock::YQWidgetStack::iterator
184 YQMainWinDock::findInStack( QWidget * dialog )
186 for ( YQMainWinDock::YQWidgetStack::iterator it = _widgetStack.begin();
187 it != _widgetStack.end();
194 return _widgetStack.end();
199 YQMainWinDock::topmostDialog() const
201 if ( _widgetStack.empty() )
204 return _widgetStack.back();
209 YQMainWinDock::couldDock()
211 YDialog * topDialog = YDialog::topmostDialog( false ); // don't throw
213 if ( ! topDialog ) // No dialog at all?
214 return true; // Can dock the next one without problems
216 // The next dialog can be docked if there is no popup dialog currently open.
217 // This is equivalent to the topmost dialog on the YDialog stack being the
218 // same dialog as the topmost dialog of this MainWinDock.
220 return topDialog->widgetRep() == this->topmostDialog();
225 YQMainWinDock::closeEvent( QCloseEvent * event )
227 // The window manager "close window" button (and WM menu, e.g. Alt-F4) will be
228 // handled just like the user had clicked on the `id`( `cancel ) button in
229 // that dialog. It's up to the YCP application to handle this (if desired).
231 y2milestone( "Caught window manager close event - returning with YCancelEvent" );
233 YQUI::ui()->sendEvent( new YCancelEvent() );
238 YQMainWinDock::paintEvent( QPaintEvent * event )
244 #include "YQMainWinDock.moc"