42 #define YUILogComponent "qt-pkg"
45 #include <zypp/ZYppFactory.h>
46 #include <zypp/Resolver.h>
48 #include <QHeaderView>
51 #include <QItemDelegate>
55 #include "YQPackageSelector.h"
56 #include "YQPkgPatternList.h"
57 #include "YQIconPool.h"
58 #include "YQApplication.h"
76 virtual void paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index )
const
85 QFont f = painter->font();
86 f.setWeight( QFont::Bold );
88 f.setPixelSize( (
int) ( fm.height() * 1.1 ) );
89 citem->setFont( _view->summaryCol(), f );
91 QItemDelegate::paint( painter, option, index );
96 YQPkgPatternListItem *item = dynamic_cast<YQPkgPatternListItem *>( _view->itemFromIndex( index ) );
103 QColor background = option.palette.color(QPalette::Window);
104 painter->setBackground( background );
106 float percent = (item->totalPackages() > 0)
107 ? (((
float)item->installedPackages()*100) / (
float)item->totalPackages())
110 QColor fillColor = option.palette.color(QPalette::Mid);
112 if ( percent > 100.0 ) percent = 100.0;
113 if ( percent < 0.0 ) percent = 0.0;
114 int x = option.rect.left() + 1;
115 int y = option.rect.top() + 1;
116 int w = option.rect.width() - 2;
117 int h = (int) ( ( (
float) option.rect.height() )/2 );
121 fillWidth = (int) ( w * percent / 100.0 );
125 painter->fillRect( x, y, fillWidth, h, fillColor );
127 QString percentageText = QString(
"%1/%2" )
128 .arg( item->installedPackages() )
129 .arg( item->totalPackages() );
131 painter->setPen( _view->palette().color( QPalette::Base ) );
132 painter->drawText( QRect( x, y,
134 Qt::AlignHCenter, percentageText );
144 QItemDelegate::paint( painter, option, index );
155 yuiDebug() <<
"Creating pattern list" << std::endl;
160 headers <<
""; _statusCol = numCol++;
169 headers <<
""; _iconCol = numCol++;
170 headers << _(
"Pattern" ); _summaryCol = numCol++;
174 setColumnCount( numCol );
175 setHeaderLabels(headers);
187 _satisfiedIconCol = -42;
188 _brokenIconCol = -42;
193 setSortingEnabled(
true );
194 sortByColumn( summaryCol(), Qt::AscendingOrder );
196 setAllColumnsShowFocus(
true );
198 header()->setSectionResizeMode( statusCol(), QHeaderView::Fixed );
199 header()->setSectionResizeMode( summaryCol(), QHeaderView::Stretch );
200 header()->setSectionResizeMode( howmanyCol(), QHeaderView::Fixed );
202 header()->resizeSection( statusCol(), 25 );
203 setColumnWidth( statusCol(), 25 );
204 setColumnWidth( summaryCol(), 100 );
205 setColumnWidth( howmanyCol(), 15 );
214 QTreeWidgetItem * ) ),
215 this, SLOT (
filter() ) );
218 setIconSize(QSize(32,32));
219 header()->resizeSection( iconCol(), 34 );
228 yuiDebug() <<
"Creating pattern list done" << std::endl;
244 yuiDebug() <<
"Filling pattern list" << std::endl;
246 for ( ZyppPoolIterator it = zyppPatternsBegin();
247 it != zyppPatternsEnd();
250 ZyppPattern zyppPattern = tryCastToZyppPattern( (*it)->theObj() );
254 if ( zyppPattern->userVisible() )
259 yuiDebug() <<
"Pattern " << zyppPattern->name()
260 <<
" is not user-visible" << std::endl;
264 yuiError() <<
"Found non-Pattern selectable" << std::endl;
268 yuiDebug() <<
"Pattern list filled" << std::endl;
269 resizeColumnToContents(_iconCol);
270 resizeColumnToContents(_statusCol);
271 resizeColumnToContents(_howmanyCol);
278 if ( categoryName.isEmpty() )
285 yuiDebug() <<
"New pattern category \""<< categoryName <<
"\"" << std::endl;
289 _categories.insert( categoryName, cat );
319 zypp::Pattern::Contents c(zyppPattern->contents());
320 for ( zypp::Pattern::Contents::Selectable_iterator it = c.selectableBegin();
321 it != c.selectableEnd();
324 ZyppPkg zyppPkg = tryCastToZyppPkg( (*it)->theObj() );
327 if ( (*it)->installedSize() > 0 )
334 selection()->setInstalledPackages(installed);
341 resizeColumnToContents(_howmanyCol);
347 ZyppPattern zyppPattern )
351 yuiError() <<
"NULL ZyppSelectable!" << std::endl;
367 resizeColumnToContents(_howmanyCol);
368 resizeColumnToContents(_summaryCol);
370 addTopLevelItem(item);
378 QTreeWidgetItem * item = currentItem();
383 return dynamic_cast<YQPkgPatternListItem *> (item);
389 QTreeWidgetItem * listViewItem,
394 = dynamic_cast<YQPkgPatternCategoryItem *> (listViewItem);
398 if ( button == Qt::LeftButton )
402 categoryItem->setExpanded( ! categoryItem->isExpanded() );
418 QTreeWidgetItemIterator it(
this );
422 QY2ListViewItem * item = dynamic_cast<QY2ListViewItem *> (*it);
424 dynamic_cast<YQPkgPatternCategoryItem *> (*it);
426 if ( item && item->isSelectable() && ! categoryItem )
428 setSelected( item,
true );
440 ZyppPattern zyppPattern )
442 , _patternList( patternList )
443 , _zyppPattern( zyppPattern )
444 , _total(0), _installed(0)
453 ZyppPattern zyppPattern )
455 , _patternList( patternList )
456 , _zyppPattern( zyppPattern )
457 , _total(0), _installed(0)
467 if ( ! _zyppPattern )
468 _zyppPattern = tryCastToZyppPattern(
selectable()->theObj() );
472 string iconName = _zyppPattern->icon().basename();
473 if ( iconName.empty() )
474 iconName =
"pattern-generic";
476 setIcon( _patternList->iconCol(), YQUI::ui()->loadIcon( iconName ) );
482 setFirstColumnSpanned (
false );
496 if ( ! _editable || ! _pkgObjList->
editable() )
499 ZyppStatus oldStatus =
status();
500 ZyppStatus newStatus = oldStatus;
505 newStatus = S_NoInst;
514 newStatus = S_Install;
518 newStatus = S_NoInst;
525 if ( oldStatus != newStatus )
547 std::string infoToolTip;
548 infoToolTip += (
"<p>" +
zyppPattern()->description() +
"</p>");
550 if ( totalPackages() > 0 )
552 infoToolTip += (
"<p>" + zypp::str::form(
"%d / %d", installedPackages(), totalPackages() ) +
"</p>");
555 setToolTip(_patternList->summaryCol(), fromUTF8(infoToolTip));
568 const YQPkgPatternListItem * otherPatternListitem = dynamic_cast<const YQPkgPatternListItem *>(&otherListViewItem);
570 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->
zyppPattern() )
572 if ( _zyppPattern->order() != otherPatternListitem->
zyppPattern()->order() )
573 return _zyppPattern->order() < otherPatternListitem->
zyppPattern()->order();
575 return _zyppPattern->name() < otherPatternListitem->
zyppPattern()->name();
578 const YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<const YQPkgPatternCategoryItem *>(&otherListViewItem);
580 if ( otherCategoryItem )
583 return QTreeWidgetItem::operator<( otherListViewItem );
588 const QString & category )
589 : QY2ListViewItem( patternList )
590 , _patternList( patternList )
592 setText( _patternList->summaryCol(), category );
608 if ( ! _firstPattern )
610 _firstPattern = pattern;
614 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
615 _firstPattern = pattern;
621 YQPkgPatternCategoryItem::setExpanded(
bool open )
623 QTreeWidgetItem::setExpanded( open );
633 YQIconPool::arrowDown() :
634 YQIconPool::arrowRight() );
641 const YQPkgPatternCategoryItem * otherCategoryItem = dynamic_cast<const YQPkgPatternCategoryItem *>(&otherListViewItem);
643 if ( _firstPattern && otherCategoryItem && otherCategoryItem->
firstPattern() )
644 return _firstPattern->order() < otherCategoryItem->
firstPattern()->order();
647 const YQPkgPatternListItem * otherPatternListitem = dynamic_cast<const YQPkgPatternListItem *>(&otherListViewItem);
649 if ( otherPatternListitem )
652 return QTreeWidgetItem::operator<( otherListViewItem );