summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/listviewpwm.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/listviewpwm.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/listviewpwm.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/listviewpwm.cpp b/pwmanager/pwmanager/listviewpwm.cpp
new file mode 100644
index 0000000..b987c9e
--- a/dev/null
+++ b/pwmanager/pwmanager/listviewpwm.cpp
@@ -0,0 +1,86 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "listviewpwm.h"
21#include "pwmexception.h"
22
23#include <qpainter.h>
24#include <qpixmap.h>
25
26#include <kiconloader.h>
27
28
29ListViewPwM::ListViewPwM(QWidget *parent, const char *name)
30 : KListView(parent, name)
31{
32 //setResizeMode(QListView::AllColumns);
33}
34
35bool ListViewPwM::event(QEvent *e)
36{
37 if (e->type() == QEvent::LayoutHint)
38 emit layoutChanged();
39 return KListView::event(e);
40}
41
42
43QPixmap * ListViewItemPwM::onPix = 0;
44QPixmap * ListViewItemPwM::offPix = 0;
45
46ListViewItemPwM::ListViewItemPwM(QListView *parent)
47 : QCheckListItem(parent, "", QCheckListItem::CheckBox)
48{
49 if (!onPix) {
50 PWM_ASSERT(!offPix);
51 KIconLoader il;
52 static QPixmap onP(il.loadIcon("button_ok", KIcon::Small));
53 onPix = &onP;
54 static QPixmap offP(il.loadIcon("encrypted", KIcon::Small));
55 offPix = &offP;
56 }
57}
58
59void ListViewItemPwM::paintCell(QPainter *p, const QColorGroup &cg,
60 int column, int width, int align)
61{
62 if (!p)
63 return;
64 if (column != 0) {
65 QCheckListItem::paintCell(p, cg, column, width, align);
66 return;
67 }
68 QPixmap *curPix = isOn() ? onPix : offPix;
69 int pixSpace = curPix->width();
70 pixSpace += 4;
71#ifndef PWM_EMBEDDED
72 QRect window(p->viewport());
73 // clear the rectangle (we have to clear it first. see QT doc)
74 p->eraseRect(0, 0, pixSpace, window.height());
75 // now draw the pixmap
76 int y = (height() - curPix->height()) / 2;
77 p->drawPixmap(1, y, *curPix);
78 window.moveLeft(pixSpace);
79 p->setViewport(window);
80#endif
81 QListViewItem::paintCell(p, cg, column, width - pixSpace, align);
82}
83
84#ifndef PWM_EMBEDDED
85#include "listviewpwm.moc"
86#endif