Author: sh-sh-sh
Date: Wed Feb 4 13:55:01 2009
New Revision: 55238
URL: http://svn.opensuse.org/viewcvs/yast?rev=55238&view=rev
Log:
Added tab context menu (move left, move right, close)
Modified:
trunk/qt-pkg/package/yast2-qt-pkg.changes
trunk/qt-pkg/src/YQPkgFilterTab.cc
trunk/qt-pkg/src/YQPkgFilterTab.h
Modified: trunk/qt-pkg/package/yast2-qt-pkg.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-pkg/package/yast2-qt-pkg.changes?rev=55238&r1=55237&r2=55238&view=diff
==============================================================================
--- trunk/qt-pkg/package/yast2-qt-pkg.changes (original)
+++ trunk/qt-pkg/package/yast2-qt-pkg.changes Wed Feb 4 13:55:01 2009
@@ -1,4 +1,9 @@
-------------------------------------------------------------------
+Wed Feb 4 13:54:08 CET 2009 - sh@suse.de
+
+- Added tab context menu (move left, move right, close)
+
+-------------------------------------------------------------------
Thu Jan 29 11:59:13 CET 2009 - sh@suse.de
- Use tabs instead of combo box for switching filter views
Modified: trunk/qt-pkg/src/YQPkgFilterTab.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-pkg/src/YQPkgFilterTab.cc?rev=55238&r1=55237&r2=55238&view=diff
==============================================================================
--- trunk/qt-pkg/src/YQPkgFilterTab.cc (original)
+++ trunk/qt-pkg/src/YQPkgFilterTab.cc Wed Feb 4 13:55:01 2009
@@ -20,6 +20,7 @@
#include <vector>
+#include <algorithm> // std::swap()
#include <QAction>
#include <QHBoxLayout>
@@ -64,6 +65,8 @@
, rightPane(0)
, viewButton(0)
, closeButton(0)
+ , tabContextMenu(0)
+ , tabContextMenuPage(0)
{}
QStackedWidget * baseClassWidgetStack;
@@ -74,6 +77,11 @@
QWidget * rightPane;
QPushButton * viewButton;
QToolButton * closeButton;
+ QMenu * tabContextMenu;
+ QAction * actionMovePageLeft;
+ QAction * actionMovePageRight;
+ QAction * actionClosePage;
+ YQPkgFilterPage * tabContextMenuPage;
YQPkgFilterPageVector pages;
};
@@ -141,7 +149,8 @@
priv->viewButton = new QPushButton( _( "&View" ), buttonBox );
YUI_CHECK_NEW( priv->viewButton );
buttonBoxLayout->addWidget( priv->viewButton );
-#endif
+
+#endif // VIEW_BUTTON_LEFT
QMenu * menu = new QMenu();
YUI_CHECK_NEW( menu );
@@ -160,7 +169,8 @@
connect( priv->closeButton, SIGNAL( clicked() ),
this, SLOT ( closeCurrentPage() ) );
-#endif
+
+#endif // SHOW_ONLY_IMPORTANT_PAGES
//
@@ -218,6 +228,9 @@
connect( tabBar(), SIGNAL( currentChanged( int ) ),
this, SLOT ( showPage ( int ) ) );
+ tabBar()->installEventFilter( this ); // for tab context menu
+
+
//
// Cosmetics
//
@@ -293,6 +306,7 @@
#endif
{
page->tabIndex = tabBar()->addTab( pageLabel );
+ priv->closeButton->setEnabled( tabBar()->count() > 1 && page->closeEnabled );
}
}
@@ -352,6 +366,7 @@
priv->filtersWidgetStack->setCurrentWidget( page->content );
tabBar()->setCurrentIndex( page->tabIndex );
+ priv->closeButton->setEnabled( tabBar()->count() > 1 && page->closeEnabled );
emit currentChanged( page->content );
}
@@ -437,6 +452,185 @@
}
+int
+YQPkgFilterTab::tabCount() const
+{
+ return tabBar()->count();
+}
+
+
+bool
+YQPkgFilterTab::eventFilter ( QObject * watchedObj, QEvent * event )
+{
+ if ( watchedObj == tabBar() &&
+ event && event->type() == QEvent::MouseButtonPress )
+ {
+ QMouseEvent * mouseEvent = dynamic_cast (event);
+
+ if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
+ {
+ return postTabContextMenu( mouseEvent->pos() );
+ }
+ }
+
+ return QTabWidget::eventFilter( watchedObj, event );
+}
+
+
+bool
+YQPkgFilterTab::postTabContextMenu( const QPoint & pos )
+{
+ int tabIndex = tabBar()->tabAt( pos );
+
+ if ( tabIndex >= 0 ) // -1 means "no tab at that position"
+ {
+ priv->tabContextMenuPage = findPage( tabIndex );
+
+ if ( priv->tabContextMenuPage )
+ {
+ if ( ! priv->tabContextMenu )
+ {
+ // On-demand menu creation
+
+ priv->tabContextMenu = new QMenu( this );
+ YUI_CHECK_NEW( priv->tabContextMenu );
+
+ priv->actionMovePageLeft = new QAction( _( "Move page &left" ), this );
+ YUI_CHECK_NEW( priv->actionMovePageLeft );
+
+ connect( priv->actionMovePageLeft, SIGNAL( triggered() ),
+ this, SLOT ( contextMovePageLeft() ) );
+
+
+ priv->actionMovePageRight = new QAction( _( "Move page &right" ), this );
+ YUI_CHECK_NEW( priv->actionMovePageRight );
+
+ connect( priv->actionMovePageRight, SIGNAL( triggered() ),
+ this, SLOT ( contextMovePageRight() ) );
+
+
+ priv->actionClosePage = new QAction( _( "&Close page" ), this );
+ YUI_CHECK_NEW( priv->actionClosePage );
+
+ connect( priv->actionClosePage, SIGNAL( triggered() ),
+ this, SLOT ( contextClosePage() ) );
+
+
+ priv->tabContextMenu->addAction( priv->actionMovePageLeft );
+ priv->tabContextMenu->addAction( priv->actionMovePageRight );
+ priv->tabContextMenu->addAction( priv->actionClosePage );
+ }
+
+ // Enable / disable actions
+
+ priv->actionMovePageLeft->setEnabled( tabIndex > 0 );
+ priv->actionMovePageRight->setEnabled( tabIndex < ( tabBar()->count() - 1 ) );
+ priv->actionClosePage->setEnabled( tabBar()->count() > 0 && priv->tabContextMenuPage->closeEnabled );
+
+ priv->tabContextMenu->popup( mapToGlobal( pos ) );
+
+ return true; // event consumed - no further processing
+ }
+ }
+
+ return false; // no tab at that position
+}
+
+
+void
+YQPkgFilterTab::contextMovePageLeft()
+{
+ if ( priv->tabContextMenuPage )
+ {
+ int contextPageIndex = priv->tabContextMenuPage->tabIndex;
+ int otherPageIndex = contextPageIndex-1;
+
+ if ( otherPageIndex >= 0 )
+ {
+ swapTabs( priv->tabContextMenuPage, findPage( otherPageIndex ) );
+ }
+ }
+}
+
+
+void
+YQPkgFilterTab::contextMovePageRight()
+{
+ if ( priv->tabContextMenuPage )
+ {
+ int contextPageIndex = priv->tabContextMenuPage->tabIndex;
+ int otherPageIndex = contextPageIndex+1;
+
+ if ( otherPageIndex < tabBar()->count() )
+ {
+ swapTabs( priv->tabContextMenuPage, findPage( otherPageIndex ) );
+ }
+ }
+}
+
+
+void
+YQPkgFilterTab::swapTabs( YQPkgFilterPage * page1, YQPkgFilterPage * page2 )
+{
+ if ( ! page1 or ! page2 )
+ return;
+
+ int oldCurrentIndex = tabBar()->currentIndex();
+ std::swap( page1->tabIndex, page2->tabIndex );
+ tabBar()->setTabText( page1->tabIndex, page1->label );
+ tabBar()->setTabText( page2->tabIndex, page2->label );
+
+ yuiDebug() << "Swapping tabs \"" << toUTF8( page1->label )
+ << "\" and \"" << toUTF8( page2->label ) << "\""
+ << endl;
+
+
+ // If one of the two pages was the currently displayed one,
+ // make sure the same one is still displayed
+
+ if ( oldCurrentIndex == page1->tabIndex )
+ {
+ YQSignalBlocker sigBlocker( tabBar() );
+ tabBar()->setCurrentIndex( page2->tabIndex );
+ }
+ else if ( oldCurrentIndex == page2->tabIndex )
+ {
+ YQSignalBlocker sigBlocker( tabBar() );
+ tabBar()->setCurrentIndex( page1->tabIndex );
+ }
+}
+
+
+void
+YQPkgFilterTab::contextClosePage()
+{
+ if ( priv->tabContextMenuPage )
+ {
+ int pageIndex = priv->tabContextMenuPage->tabIndex;
+ int oldCurrentIndex = tabBar()->currentIndex();
+ tabBar()->removeTab( pageIndex );
+
+
+ //
+ // Adjust tab index of the active pages to the right of that page
+ //
+
+ for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
+ it != priv->pages.end();
+ ++it )
+ {
+ YQPkgFilterPage * page = *it;
+
+ if ( page->tabIndex >= pageIndex )
+ page->tabIndex--;
+ }
+
+ if ( oldCurrentIndex == pageIndex ) // this page was the current page
+ showPage( tabBar()->currentIndex() ); // display the new current page
+ }
+}
+
+
#include "YQPkgFilterTab.moc"
Modified: trunk/qt-pkg/src/YQPkgFilterTab.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-pkg/src/YQPkgFilterTab.h?rev=55238&r1=55237&r2=55238&view=diff
==============================================================================
--- trunk/qt-pkg/src/YQPkgFilterTab.h (original)
+++ trunk/qt-pkg/src/YQPkgFilterTab.h Wed Feb 4 13:55:01 2009
@@ -101,6 +101,39 @@
**/
YQPkgDiskUsageList * diskUsageList() const;
+ /**
+ * Find a filter page by its content widget (the widget that was passed
+ * to addPage() ).
+ * Return 0 if there is no such page.
+ **/
+ YQPkgFilterPage * findPage( QWidget * pageContent );
+
+ /**
+ * Find a filter page by its internal name.
+ * Return 0 if there is no such page.
+ **/
+ YQPkgFilterPage * findPage( const QString & internalName );
+
+ /**
+ * Find a filter page by its tab index.
+ * Return 0 if there is no such page.
+ **/
+ YQPkgFilterPage * findPage( int tabIndex );
+
+ /**
+ * Return the number of open tabs.
+ **/
+ int tabCount() const;
+
+ /**
+ * Event filter to catch mouse right clicks on open tabs for the tab
+ * context menu. Returns 'true' if the event is processed and consumed,
+ * 'false' if processed should be continued by the watched object itself.
+ *
+ * Reimplemented from QObject.
+ **/
+ virtual bool eventFilter ( QObject * watchedObj, QEvent * event );
+
signals:
@@ -123,7 +156,8 @@
* Close the current page unless this is the last visible page.
**/
void closeCurrentPage();
-
+
+
protected slots:
/**
@@ -136,7 +170,24 @@
**/
void showPage( QAction * action );
+ /**
+ * Move the current tab page (from the context menu) one position to the
+ * left.
+ **/
+ void contextMovePageLeft();
+
+ /**
+ * Move the current tab page (from the context menu) one position to the
+ * right.
+ **/
+ void contextMovePageRight();
+
+ /**
+ * Close the current tab page (from the context menu).
+ **/
+ void contextClosePage();
+
protected:
/**
@@ -145,25 +196,18 @@
void showPage( YQPkgFilterPage * page );
/**
- * Find a filter page by its content widget (the widget that was passed
- * to addPage() ).
- * Return 0 if there is no such page.
- **/
- YQPkgFilterPage * findPage( QWidget * pageContent );
-
- /**
- * Find a filter page by its internal name.
- * Return 0 if there is no such page.
+ * Open the tab context menu for the tab at the specified position.
+ * Return 'true' upon success (i.e., there is a tab at that position),
+ * 'false' upon failure.
**/
- YQPkgFilterPage * findPage( const QString & internalName );
+ bool postTabContextMenu( const QPoint & pos );
/**
- * Find a filter page by its tab index.
- * Return 0 if there is no such page.
+ * Swap two tabs and adjust their tab indices accordingly.
**/
- YQPkgFilterPage * findPage( int tabIndex );
-
-
+ void swapTabs( YQPkgFilterPage * page1, YQPkgFilterPage * page2 );
+
+
private:
ImplPtr<YQPkgFilterTabPrivate> priv;
@@ -184,6 +228,7 @@
, label( pageLabel )
, id( internalName )
, showAlways( showAlways )
+ , closeEnabled( true )
, tabIndex( -1 )
{}
@@ -191,6 +236,7 @@
QString label; // user visible text
QString id; // internal name
bool showAlways;
+ bool closeEnabled;
int tabIndex; // index of the corresponding tab or -1 if none
};
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org