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"
71 virtual void paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index )
const
81 QFont f = painter->font();
82 f.setWeight(QFont::Bold);
84 f.setPixelSize( (
int) ( fm.height() * 1.1 ) );
85 citem->setFont(_view->summaryCol(), f);
87 painter->fillRect(option.rect, option.palette.color(QPalette::AlternateBase));
88 QItemDelegate::paint(painter, option, index);
102 QColor background = option.palette.color(QPalette::Window);
103 painter->setBackground( background );
105 float percent = (item->totalPackages() > 0)
106 ? (((
float)item->installedPackages()*100) / (
float)item->totalPackages())
109 QColor fillColor = option.palette.color(QPalette::Mid);
111 if ( percent > 100.0 ) percent = 100.0;
112 if ( percent < 0.0 ) percent = 0.0;
113 int x = option.rect.left() + 1;
114 int y = option.rect.top() + 1;
115 int w = option.rect.width() - 2;
116 int h = (int) ( ( (
float) option.rect.height() )/2 );
120 fillWidth = (int) ( w * percent / 100.0 );
125 painter->fillRect( x, y, fillWidth, h,
128 QString percentageText;
129 percentageText.sprintf(
"%d/%d", item->installedPackages(), item->totalPackages());
131 painter->setPen( _view->palette().color( QPalette::Base ) );
132 painter->drawText( QRect( x, y,
134 Qt::AlignHCenter, percentageText );
145 QItemDelegate::paint(painter, option, index);
157 yuiDebug() <<
"Creating pattern list" << std::endl;
162 headers <<
""; _statusCol = numCol++;
171 headers <<
""; _iconCol = numCol++;
172 headers << _(
"Pattern" ); _summaryCol = numCol++;
176 setColumnCount( numCol );
177 setHeaderLabels(headers);
189 _satisfiedIconCol = -42;
190 _brokenIconCol = -42;
195 setSortingEnabled(
true );
196 sortByColumn( summaryCol(), Qt::AscendingOrder );
198 setAllColumnsShowFocus(
true );
200 header()->setResizeMode( statusCol(), QHeaderView::Fixed );
201 header()->setResizeMode( summaryCol(), QHeaderView::Stretch );
202 header()->setResizeMode( howmanyCol(), QHeaderView::Fixed );
204 header()->resizeSection( statusCol(), 25 );
205 setColumnWidth( statusCol(), 25 );
206 setColumnWidth( summaryCol(), 100 );
207 setColumnWidth( howmanyCol(), 15 );
216 this, SLOT (
filter() ) );
219 setIconSize(QSize(32,32));
220 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();
389 QTreeWidgetItem * listViewItem,
398 if ( button == Qt::LeftButton )
402 categoryItem->setExpanded( ! categoryItem->isExpanded() );
418 QTreeWidgetItemIterator it(
this );
422 QY2ListViewItem * item =
dynamic_cast<QY2ListViewItem *
> (*it);
426 if ( item && item->isSelectable() && ! categoryItem )
428 setSelected( item,
true );
439 ZyppPattern zyppPattern )
441 , _patternList( patternList )
442 , _zyppPattern( zyppPattern )
443 , _total(0), _installed(0)
452 ZyppPattern zyppPattern )
454 , _patternList( patternList )
455 , _zyppPattern( zyppPattern )
456 , _total(0), _installed(0)
466 if ( ! _zyppPattern )
467 _zyppPattern = tryCastToZyppPattern(
selectable()->theObj() );
471 string icon = _zyppPattern->icon().asString();
473 if ( (icon == zypp::Pathname(
"yast-system").asString()) ||
475 icon =
"pattern-generic";
480 setIcon(_patternList->iconCol(), QIcon(QString(iconpath.c_str())));
486 setFirstColumnSpanned (
false );
500 if ( ! _editable || ! _pkgObjList->
editable() )
503 ZyppStatus oldStatus =
status();
504 ZyppStatus newStatus = oldStatus;
509 newStatus = S_NoInst;
518 newStatus = S_Install;
522 newStatus = S_NoInst;
529 if ( oldStatus != newStatus )
551 std::string infoToolTip;
552 infoToolTip += (
"<p>" +
zyppPattern()->description() +
"</p>");
554 if ( totalPackages() > 0 )
556 infoToolTip += (
"<p>" + zypp::str::form(
"%d / %d", installedPackages(), totalPackages() ) +
"</p>");
559 setToolTip(_patternList->summaryCol(), fromUTF8(infoToolTip));
576 if ( _zyppPattern && otherPatternListitem && otherPatternListitem->
zyppPattern() )
578 if ( _zyppPattern->order() != otherPatternListitem->
zyppPattern()->order() )
579 return _zyppPattern->order() < otherPatternListitem->
zyppPattern()->order();
581 return _zyppPattern->name() < otherPatternListitem->
zyppPattern()->name();
586 if ( otherCategoryItem )
589 return QTreeWidgetItem::operator<( otherListViewItem );
593 const QString & category )
594 : QY2ListViewItem( patternList )
595 , _patternList( patternList )
597 setText( _patternList->summaryCol(), category );
612 if ( ! _firstPattern )
614 _firstPattern = pattern;
618 if ( _firstPattern->order().compare( pattern->order() ) < 0 )
619 _firstPattern = pattern;
625 YQPkgPatternCategoryItem::setExpanded(
bool open )
627 QTreeWidgetItem::setExpanded( open );
637 YQIconPool::treeMinus() :
638 YQIconPool::treePlus() );
647 if ( _firstPattern && otherCategoryItem && otherCategoryItem->
firstPattern() )
648 return _firstPattern->order() < otherCategoryItem->
firstPattern()->order();
653 if ( otherPatternListitem )
656 return QTreeWidgetItem::operator<( otherListViewItem );
661 #include "YQPkgPatternList.moc"