Author: sh-sh-sh
Date: Wed Dec 5 16:12:41 2007
New Revision: 42715
URL: http://svn.opensuse.org/viewcvs/yast?rev=42715&view=rev
Log:
initial version
Added:
trunk/qt/src/YQMainWinDock.cc
trunk/qt/src/YQMainWinDock.h
Added: trunk/qt/src/YQMainWinDock.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQMainWinDock.cc?rev=42715&view=auto
==============================================================================
--- trunk/qt/src/YQMainWinDock.cc (added)
+++ trunk/qt/src/YQMainWinDock.cc Wed Dec 5 16:12:41 2007
@@ -0,0 +1,230 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YQMainWinDock.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#define y2log_component "qt-ui"
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include "YQMainWinDock.h"
+
+
+
+YQMainWinDock *
+YQMainWinDock::mainWinDock()
+{
+ static YQMainWinDock * mainWinDock = 0;
+
+ if ( ! mainWinDock )
+ {
+ mainWinDock = new YQMainWinDock();
+ mainWinDock->show();
+ }
+
+ return mainWinDock;
+}
+
+
+YQMainWinDock::YQMainWinDock()
+ : QVBox()
+{
+ _qWidgetStack = new QWidgetStack( this );
+
+ resize( YQUI::ui()->defaultSize( YD_HORIZ ),
+ YQUI::ui()->defaultSize( YD_VERT ) );
+}
+
+
+YQMainWinDock::~YQMainWinDock()
+{
+ // NOP
+}
+
+
+void
+YQMainWinDock::show()
+{
+ y2debug( "Showing" );
+
+ QWidget::show();
+
+ if ( ! _widgetStack.empty() )
+ {
+ QWidget * dialog = _widgetStack.back();
+ dialog->raise();
+
+ if ( ! dialog->isShown() )
+ dialog->show();
+ }
+}
+
+
+void
+YQMainWinDock::add( QWidget * dialog )
+{
+ YUI_CHECK_PTR( dialog );
+
+#if 0
+ if ( dialog->parent() )
+ {
+ y2error( "Dialog already has a parent" );
+ return;
+ }
+#endif
+
+ if ( ! dialog->isShown() )
+ dialog->show();
+
+ _widgetStack.push_back( dialog );
+ _qWidgetStack->addWidget( dialog );
+ _qWidgetStack->raiseWidget( dialog );
+
+ if ( ! isShown() )
+ show();
+
+#if 0
+ QTimer::singleShot( 3*1000, this, SLOT( showCurrentDialog() ) );
+#endif
+}
+
+
+void
+YQMainWinDock::showCurrentDialog()
+{
+ if ( ! _widgetStack.empty() )
+ {
+ QWidget * dialog = _widgetStack.back();
+ y2debug( "Showing dialog %p", dialog );
+#if 0
+ _qWidgetStack->raiseWidget( dialog );
+#endif
+ dialog->raise();
+ update();
+ }
+}
+
+
+void
+YQMainWinDock::remove( QWidget * dialog )
+{
+ if ( _widgetStack.empty() )
+ return;
+
+ if ( ! dialog )
+ dialog = _widgetStack.back();
+
+ if ( dialog == _widgetStack.back() )
+ {
+ // The most common case:
+ // The topmost dialog is to be removed
+
+ _widgetStack.pop_back();
+ _qWidgetStack->removeWidget( dialog );
+
+ y2debug( "removing dialog %p", dialog );
+ }
+ else // The less common (but more generic) case: Remove any dialog
+ {
+ YQMainWinDock::YQWidgetStack::iterator pos = findInStack( dialog );
+
+ if ( pos == _widgetStack.end() )
+ return;
+
+ y2warning( "Found dialog somewhere in the middle of the widget stack" );
+
+ _widgetStack.erase( pos );
+ _qWidgetStack->removeWidget( dialog );
+
+ y2debug( "removing dialog %p", dialog );
+ }
+
+ if ( _widgetStack.empty() )
+ hide();
+ else
+ {
+ _qWidgetStack->raiseWidget( _widgetStack.back() );
+ }
+}
+
+
+YQMainWinDock::YQWidgetStack::iterator
+YQMainWinDock::findInStack( QWidget * dialog )
+{
+ for ( YQMainWinDock::YQWidgetStack::iterator it = _widgetStack.begin();
+ it != _widgetStack.end();
+ ++it )
+ {
+ if ( *it == dialog )
+ return it;
+ }
+
+ return _widgetStack.end();
+}
+
+
+QWidget *
+YQMainWinDock::topmostDialog() const
+{
+ if ( _widgetStack.empty() )
+ return 0;
+ else
+ return _widgetStack.back();
+}
+
+
+bool
+YQMainWinDock::couldDock()
+{
+ YDialog * topDialog = YDialog::topmostDialog( false ); // don't throw
+
+ if ( ! topDialog ) // No dialog at all?
+ return true; // Can dock the next one without problems
+
+ // The next dialog can be docked if there is no popup dialog currently open.
+ // This is equivalent to the topmost dialog on the YDialog stack being the
+ // same dialog as the topmost dialog of this MainWinDock.
+
+ return topDialog->widgetRep() == this->topmostDialog();
+}
+
+
+void
+YQMainWinDock::closeEvent( QCloseEvent * event )
+{
+ // The window manager "close window" button (and WM menu, e.g. Alt-F4) will be
+ // handled just like the user had clicked on the `id`( `cancel ) button in
+ // that dialog. It's up to the YCP application to handle this (if desired).
+
+ y2debug( "Caught window manager close event - returning with YCancelEvent" );
+ event->ignore();
+ YQUI::ui()->sendEvent( new YCancelEvent() );
+}
+
+
+void
+YQMainWinDock::paintEvent( QPaintEvent * event )
+{
+ // NOP
+}
+
+
+#include "YQMainWinDock.moc"
Added: trunk/qt/src/YQMainWinDock.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQMainWinDock.h?rev=42715&view=auto
==============================================================================
--- trunk/qt/src/YQMainWinDock.h (added)
+++ trunk/qt/src/YQMainWinDock.h Wed Dec 5 16:12:41 2007
@@ -0,0 +1,155 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YQMainWinDock.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#ifndef YQMainWinDock_h
+#define YQMainWinDock_h
+
+#include <deque>
+#include
+
+class QWidgetStack;
+
+
+/**
+ * Container window for YQDialogs of type YMainWindowDialog:
+ *
+ * This widget "swallows" any main dialogs it gets so only the topmost of them
+ * is visible at any given time. It acts as a window stack for main dialogs,
+ * making the next lower dialog on the stack visible as when the (previously)
+ * topmost main dialog is closed.
+ *
+ * This widget also handles its own visibility accordingly: It is visible if
+ * and only if it has a main dialog to display. It makes itself invisible when
+ * there is no more main dialog to display, and it makes itself visible again
+ * when a new main dialog appears.
+ *
+ * This widget can swallow an arbitrary number of main dialogs as they are
+ * opened as long as there is no popup dialog in between.
+ **/
+class YQMainWinDock : public QVBox
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Static method to access the singleton for this class.
+ *
+ * This creates the (one and only) instance of this class in the first
+ * call. Subsequent calls simply return this instance.
+ **/
+ static YQMainWinDock * mainWinDock();
+
+ /**
+ * Add a dialog (the widgetRep() of a YQDialog) to the MainWinDock (on top
+ * of its widget stack. The widget stack does not assume ownership of the
+ * widget.
+ *
+ * If the MainWinDock is not visible yet, this operation makes it visible.
+ **/
+ void add( QWidget * dialog );
+
+ /**
+ * Remove a dialog from the MainWinDock (if it belongs to the
+ * MainWinDock). If dialog is 0, this removes the topmost dialog from the
+ * MainWinDock.
+ *
+ * This can safely be called in the destructor of all dialogs, even those
+ * that were never added to the MainWinDock.
+ *
+ * If that was the last main dialog in the MainWinDock, the MainWinDock
+ * will be hidden (until another main dialog is added).
+ **/
+ void remove( QWidget * dialog = 0 );
+
+ /**
+ * Return the current topmost dialog (the widgetRep() of a YQDialog)
+ * or 0 if there is none.
+ **/
+ QWidget * topmostDialog() const;
+
+ /**
+ * Return 'true' if the next main dialog could be docked,
+ * i.e., if there is either no open dialog at all or only main dialogs.
+ **/
+ bool couldDock();
+
+ /**
+ * Show the widget (make it visible).
+ *
+ * Reimplemented from QWidget.
+ **/
+ virtual void show();
+
+ /**
+ * Window manager close event (Alt-F4):
+ * Send a YCancelEvent and let the application handle that event.
+ *
+ * Reimplemented from QWidget.
+ **/
+ virtual void closeEvent( QCloseEvent * event );
+
+protected:
+ /**
+ * Constructor.
+ *
+ * Use the static mainWinDock() method to access the singleton for this
+ * class.
+ **/
+ YQMainWinDock();
+
+ /**
+ * Destructor.
+ **/
+ virtual ~YQMainWinDock();
+
+ /**
+ * Paint event.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void paintEvent( QPaintEvent * event );
+
+
+protected slots:
+
+ /**
+ * Show the current dialog.
+ **/
+ void showCurrentDialog();
+
+
+private:
+
+ typedef std::deque YQWidgetStack;
+
+ /**
+ * Return an iterator to the specified dialog in the internal
+ * widgetstack or _widgetStack::end() if not found.
+ **/
+ YQWidgetStack::iterator findInStack( QWidget * dialog );
+
+
+ YQWidgetStack _widgetStack;
+ QWidgetStack * _qWidgetStack;
+};
+
+
+#endif // YQMainWinDock_h
+
+
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org