Diffstat (limited to 'noncore/unsupported/oipkg/packagelistitem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/oipkg/packagelistitem.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/noncore/unsupported/oipkg/packagelistitem.cpp b/noncore/unsupported/oipkg/packagelistitem.cpp new file mode 100644 index 0000000..5d08bb1 --- a/dev/null +++ b/noncore/unsupported/oipkg/packagelistitem.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | #include "packagelistitem.h" | ||
2 | |||
3 | #include <qpe/resource.h> | ||
4 | |||
5 | static QPixmap *pm_uninstalled=0; | ||
6 | static QPixmap *pm_installed=0; | ||
7 | static QPixmap *pm_uninstall=0; | ||
8 | static QPixmap *pm_install=0; | ||
9 | |||
10 | PackageListItem::PackageListItem(QListView* lv, Package *pi) | ||
11 | :QCheckListItem(lv,pi->name(),CheckBox) | ||
12 | { | ||
13 | package = pi; | ||
14 | if (!pm_uninstalled) { | ||
15 | pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled")); | ||
16 | pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed")); | ||
17 | pm_install = new QPixmap(Resource::loadPixmap("oipkg/install")); | ||
18 | pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall")); | ||
19 | } | ||
20 | setText(1, package->shortDesc() ); | ||
21 | setText(2, package->size() ); | ||
22 | } | ||
23 | |||
24 | void PackageListItem::paintCell( QPainter *p, const QColorGroup & cg, | ||
25 | int column, int width, int alignment ) | ||
26 | { | ||
27 | if ( !p ) | ||
28 | return; | ||
29 | |||
30 | p->fillRect( 0, 0, width, height(), | ||
31 | isSelected()? cg.highlight() : cg.base() ); | ||
32 | |||
33 | if ( column != 0 ) { | ||
34 | // The rest is text | ||
35 | QListViewItem::paintCell( p, cg, column, width, alignment ); | ||
36 | return; | ||
37 | } | ||
38 | |||
39 | QListView *lv = listView(); | ||
40 | if ( !lv ) | ||
41 | return; | ||
42 | int marg = lv->itemMargin(); | ||
43 | int r = marg; | ||
44 | |||
45 | QPixmap pm = statePixmap(); | ||
46 | p->drawPixmap(marg,(height()-pm.height())/2,pm); | ||
47 | r += pm.width()+1; | ||
48 | |||
49 | p->translate( r, 0 ); | ||
50 | QListViewItem::paintCell( p, cg, column, width - r, alignment ); | ||
51 | } | ||
52 | |||
53 | |||
54 | void PackageListItem::paintFocus( QPainter *p, const QColorGroup & cg, | ||
55 | const QRect & r ) | ||
56 | { | ||
57 | // Skip QCheckListItem | ||
58 | // (makes you wonder what we're getting from QCheckListItem) | ||
59 | QListViewItem::paintFocus(p,cg,r); | ||
60 | } | ||
61 | |||
62 | QPixmap PackageListItem::statePixmap() const | ||
63 | { | ||
64 | bool installed = package->installed(); | ||
65 | if ( !package->toProcess() ) { | ||
66 | if ( !installed ) | ||
67 | return *pm_uninstalled; | ||
68 | else | ||
69 | return *pm_installed; | ||
70 | } else { | ||
71 | if ( !installed ) | ||
72 | return *pm_install; | ||
73 | else | ||
74 | return *pm_uninstall; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | QString PackageListItem::key( int column, bool ascending ) const | ||
79 | { | ||
80 | if ( column == 2 ) { | ||
81 | QString t = text(2); | ||
82 | double bytes=t.toDouble(); | ||
83 | if ( t.contains('M') ) bytes*=1024*1024; | ||
84 | else if ( t.contains('K') || t.contains('k') ) bytes*=1024; | ||
85 | if ( !ascending ) bytes=999999999-bytes; | ||
86 | return QString().sprintf("%09d",(int)bytes); | ||
87 | } else { | ||
88 | return QListViewItem::key(column,ascending); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | void PackageListItem::setOn( bool b ) | ||
93 | { | ||
94 | QCheckListItem::setOn( b ); | ||
95 | package->toggleProcess(); | ||
96 | repaint(); | ||
97 | } | ||