47 #include <QHBoxLayout>
49 #include <QPushButton>
51 #include <QStackedWidget>
53 #include <QToolButton>
56 #define YUILogComponent "qt-pkg"
60 #include "YUIException.h"
61 #include "YApplication.h"
62 #include "YQPkgFilterTab.h"
63 #include "YQPkgDiskUsageList.h"
64 #include "YQSignalBlocker.h"
65 #include "YQIconPool.h"
71 typedef vector<YQPkgFilterPage *> YQPkgFilterPageVector;
73 #define SHOW_ONLY_IMPORTANT_PAGES 1
74 #define VIEW_BUTTON_LEFT 1
76 #define SETTINGS_DIR "YaST2"
79 #define MARGIN 5 // inner margin between 3D borders and content
80 #define TOP_EXTRA_MARGIN 3
81 #define SPLITTER_HALF_SPACING 2
87 : settingsName( name )
88 , baseClassWidgetStack(0)
91 , filtersWidgetStack(0)
97 , tabContextMenuPage(0)
100 QString settingsName;
101 QStackedWidget * baseClassWidgetStack;
102 QSplitter * outerSplitter;
103 QSplitter * leftPaneSplitter;
104 QStackedWidget * filtersWidgetStack;
107 QPushButton * viewButton;
108 QToolButton * closeButton;
109 QMenu * tabContextMenu;
110 QAction * actionMovePageLeft;
111 QAction * actionMovePageRight;
112 QAction * actionClosePage;
114 YQPkgFilterPageVector pages;
121 : QTabWidget( parent )
124 YUI_CHECK_NEW( priv );
131 priv->baseClassWidgetStack = findChild<QStackedWidget*>();
132 YUI_CHECK_PTR( priv->baseClassWidgetStack );
144 priv->outerSplitter =
new QSplitter( Qt::Horizontal,
this );
145 YUI_CHECK_NEW( priv->outerSplitter );
147 priv->outerSplitter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
148 QSizePolicy::Expanding ) );
149 priv->baseClassWidgetStack->addWidget( priv->outerSplitter );
152 #if SHOW_ONLY_IMPORTANT_PAGES
158 QWidget * buttonBox =
new QWidget(
this );
159 YUI_CHECK_NEW( buttonBox );
160 setCornerWidget( buttonBox, Qt::TopRightCorner );
161 buttonBox->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
163 QHBoxLayout * buttonBoxLayout =
new QHBoxLayout( buttonBox );
164 YUI_CHECK_NEW( buttonBoxLayout );
165 buttonBox->setLayout( buttonBoxLayout );
166 buttonBoxLayout->setContentsMargins( 0, 0, 0, 0 );
174 priv->viewButton =
new QPushButton( _(
"&View" ),
this );
175 YUI_CHECK_NEW( priv->viewButton );
176 setCornerWidget( priv->viewButton, Qt::TopLeftCorner );
178 priv->viewButton =
new QPushButton( _(
"&View" ), buttonBox );
179 YUI_CHECK_NEW( priv->viewButton );
180 buttonBoxLayout->addWidget( priv->viewButton );
182 #endif // VIEW_BUTTON_LEFT
184 QMenu * menu =
new QMenu();
185 YUI_CHECK_NEW( menu );
186 priv->viewButton->setMenu( menu );
187 menu->setTearOffEnabled(
true );
189 connect( menu, SIGNAL( triggered( QAction * ) ),
190 this, SLOT (
showPage ( QAction * ) ) );
193 priv->closeButton =
new QToolButton( buttonBox );
194 YUI_CHECK_NEW( priv->closeButton );
195 buttonBoxLayout->addWidget( priv->closeButton );
196 priv->closeButton->setIcon( YQIconPool::tabRemove() );
197 priv->closeButton->setToolTip( _(
"Close the current page" ) );
199 connect( priv->closeButton, SIGNAL( clicked() ),
202 #endif // SHOW_ONLY_IMPORTANT_PAGES
209 priv->leftPaneSplitter =
new QSplitter( Qt::Vertical, priv->outerSplitter );
210 YUI_CHECK_NEW( priv->leftPaneSplitter );
217 priv->filtersWidgetStack =
new QStackedWidget( priv->leftPaneSplitter );
218 YUI_CHECK_NEW( priv->filtersWidgetStack );
221 YUI_CHECK_NEW( priv->diskUsageList );
224 QSplitter * sp = priv->leftPaneSplitter;
225 sp->setStretchFactor( sp->indexOf( priv->filtersWidgetStack ), 1 );
226 sp->setStretchFactor( sp->indexOf( priv->diskUsageList ), 2 );
231 sizes << priv->leftPaneSplitter->height();
233 sp->setSizes( sizes );
241 priv->rightPane =
new QWidget( priv->outerSplitter );
242 YUI_CHECK_NEW( priv->rightPane );
249 QSplitter * sp = priv->outerSplitter;
250 sp->setStretchFactor( sp->indexOf( priv->leftPaneSplitter ), 0 );
251 sp->setStretchFactor( sp->indexOf( priv->rightPane ), 1 );
260 tabBar()->installEventFilter(
this );
267 priv->baseClassWidgetStack->setContentsMargins( MARGIN,
268 MARGIN + TOP_EXTRA_MARGIN,
272 priv->leftPaneSplitter->setContentsMargins ( 0,
274 SPLITTER_HALF_SPACING,
285 for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
286 it != priv->pages.end();
299 return priv->rightPane;
306 return priv->diskUsageList;
312 QWidget * pageContent,
313 const QString & internalName )
318 YUI_CHECK_NEW( page );
320 priv->pages.push_back( page );
321 priv->filtersWidgetStack->addWidget( pageContent );
324 if ( priv->viewButton && priv->viewButton->menu() )
326 QAction * action =
new QAction( pageLabel,
this );
327 YUI_CHECK_NEW( action );
328 action->setData( qVariantFromValue( pageContent ) );
330 priv->viewButton->menu()->addAction( action );
333 #if ! SHOW_ONLY_IMPORTANT_PAGES
334 page->tabIndex = tabBar()->addTab( pageLabel );
335 priv->closeButton->setEnabled( tabBar()->count() > 1 && page->closeEnabled );
344 YUI_CHECK_PTR( page );
354 YUI_CHECK_PTR( page );
376 QWidget * pageContent = action->data().value<QWidget *>();
384 YUI_CHECK_PTR( page );
385 YQSignalBlocker sigBlocker( tabBar() );
387 if ( page->tabIndex < 0 )
390 page->tabIndex = tabBar()->addTab( page->label );
393 priv->filtersWidgetStack->setCurrentWidget( page->content );
394 tabBar()->setCurrentIndex( page->tabIndex );
395 priv->closeButton->setEnabled( tabBar()->count() > 1 && page->closeEnabled );
396 priv->tabContextMenuPage = page;
405 while ( tabBar()->count() > 0 )
407 tabBar()->removeTab( 0 );
410 for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
411 it != priv->pages.end();
414 (*it)->tabIndex = -1;
417 priv->closeButton->setEnabled(
false );
424 if ( tabBar()->count() > 1 )
426 int currentIndex = tabBar()->currentIndex();
430 currentPage->tabIndex = -1;
432 tabBar()->removeTab( currentIndex );
438 for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
439 it != priv->pages.end();
444 if ( page->tabIndex >= currentIndex )
448 showPage( tabBar()->currentIndex() );
456 for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
457 it != priv->pages.end();
460 if ( (*it)->content == pageContent )
471 for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
472 it != priv->pages.end();
475 if ( (*it)->id == internalName )
489 for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
490 it != priv->pages.end();
493 if ( (*it)->tabIndex == tabIndex )
504 return tabBar()->count();
511 if ( watchedObj == tabBar() &&
512 event && event->type() == QEvent::MouseButtonPress )
514 QMouseEvent * mouseEvent =
dynamic_cast<QMouseEvent *
> (event);
516 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
522 return QTabWidget::eventFilter( watchedObj, event );
529 int tabIndex = tabBar()->tabAt( pos );
533 priv->tabContextMenuPage =
findPage( tabIndex );
535 if ( priv->tabContextMenuPage )
537 if ( ! priv->tabContextMenu )
541 priv->tabContextMenu =
new QMenu(
this );
542 YUI_CHECK_NEW( priv->tabContextMenu );
545 priv->actionMovePageLeft =
new QAction( YUI::yApp()->reverseLayout() ?
546 YQIconPool::arrowRight() : YQIconPool::arrowLeft(),
547 _(
"Move page &left" ),
this );
548 YUI_CHECK_NEW( priv->actionMovePageLeft );
550 connect( priv->actionMovePageLeft, SIGNAL( triggered() ),
555 priv->actionMovePageRight =
new QAction( YUI::yApp()->reverseLayout() ?
556 YQIconPool::arrowLeft() : YQIconPool::arrowRight(),
557 _(
"Move page &right" ),
this );
558 YUI_CHECK_NEW( priv->actionMovePageRight );
560 connect( priv->actionMovePageRight, SIGNAL( triggered() ),
564 priv->actionClosePage =
new QAction( YQIconPool::tabRemove(), _(
"&Close page" ),
this );
565 YUI_CHECK_NEW( priv->actionClosePage );
567 connect( priv->actionClosePage, SIGNAL( triggered() ),
571 priv->tabContextMenu->addAction( priv->actionMovePageLeft );
572 priv->tabContextMenu->addAction( priv->actionMovePageRight );
573 priv->tabContextMenu->addAction( priv->actionClosePage );
578 priv->actionMovePageLeft->setEnabled( tabIndex > 0 );
579 priv->actionMovePageRight->setEnabled( tabIndex < ( tabBar()->count() - 1 ) );
580 priv->actionClosePage->setEnabled( tabBar()->count() > 1 && priv->tabContextMenuPage->closeEnabled );
582 priv->tabContextMenu->popup( tabBar()->mapToGlobal( pos ) );
595 if ( priv->tabContextMenuPage )
597 int contextPageIndex = priv->tabContextMenuPage->tabIndex;
598 int otherPageIndex = contextPageIndex-1;
600 if ( otherPageIndex >= 0 )
611 if ( priv->tabContextMenuPage )
613 int contextPageIndex = priv->tabContextMenuPage->tabIndex;
614 int otherPageIndex = contextPageIndex+1;
616 if ( otherPageIndex < tabBar()->count() )
627 if ( ! page1 or ! page2 )
630 int oldCurrentIndex = tabBar()->currentIndex();
631 std::swap( page1->tabIndex, page2->tabIndex );
632 tabBar()->setTabText( page1->tabIndex, page1->label );
633 tabBar()->setTabText( page2->tabIndex, page2->label );
639 if ( oldCurrentIndex == page1->tabIndex )
641 YQSignalBlocker sigBlocker( tabBar() );
642 tabBar()->setCurrentIndex( page2->tabIndex );
644 else if ( oldCurrentIndex == page2->tabIndex )
646 YQSignalBlocker sigBlocker( tabBar() );
647 tabBar()->setCurrentIndex( page1->tabIndex );
655 if ( priv->tabContextMenuPage )
657 int pageIndex = priv->tabContextMenuPage->tabIndex;
658 priv->tabContextMenuPage->tabIndex = -1;
659 tabBar()->removeTab( pageIndex );
666 for ( YQPkgFilterPageVector::iterator it = priv->pages.begin();
667 it != priv->pages.end();
672 if ( page->tabIndex >= pageIndex )
676 showPage( tabBar()->currentIndex() );
685 QSettings settings( QSettings::UserScope, SETTINGS_DIR, priv->settingsName );
687 int size = settings.beginReadArray(
"Tab_Pages" );
689 for (
int i=0; i < size; i++ )
691 settings.setArrayIndex(i);
692 QString
id = settings.value(
"Page_ID" ).toString();
697 yuiDebug() <<
"Restoring page \"" << toUTF8(
id ) <<
"\"" << std::endl;
701 yuiWarning() <<
"No page with ID \"" << toUTF8(
id ) <<
"\"" << std::endl;
706 QString
id = settings.value(
"Current_Page" ).toString();
708 if ( !
id.isEmpty() )
716 QSettings settings( QSettings::UserScope, SETTINGS_DIR, priv->settingsName );
718 settings.beginWriteArray(
"Tab_Pages" );
720 for (
int i=0; i < tabBar()->count(); i++ )
726 settings.setArrayIndex(i);
728 if ( page->id.isEmpty() )
729 yuiWarning() <<
"No ID for tab page \"" << page->label <<
"\"" << std::endl;
732 yuiDebug() <<
"Saving page #" << i <<
": \"" << toUTF8( page->id ) <<
"\"" << std::endl;
733 settings.setValue(
"Page_ID", page->id );
743 settings.setValue(
"Current_Page", currentPage->id );
748 #include "YQPkgFilterTab.moc"
void contextMovePageRight()
bool postTabContextMenu(const QPoint &pos)
void showPage(QWidget *page)
QWidget * rightPane() const
void addPage(const QString &pageLabel, QWidget *pageContent, const QString &internalName)
virtual ~YQPkgFilterTab()
YQPkgDiskUsageList * diskUsageList() const
YQPkgFilterTab(QWidget *parent, const QString &settingsName)
void swapTabs(YQPkgFilterPage *page1, YQPkgFilterPage *page2)
void currentChanged(QWidget *newPageContent)
virtual bool eventFilter(QObject *watchedObj, QEvent *event)
YQPkgFilterPage * findPage(QWidget *pageContent)
void contextMovePageLeft()
List of disk usage of all attached partitions.