summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/listviewpwm.cpp
blob: 4253ab144c2ab4a229c0ebd0a5b933617215c167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2004 by Michael Buesch                                  *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 1.0.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#include "listviewpwm.h"
#include "pwmexception.h"
#include "pwmview.h"

#include <qpainter.h>
#include <qpixmap.h>
//Added by qt3to4:
#include <QEvent>
#include <QKeyEvent>

#include <kiconloader.h>

#ifdef PWM_EMBEDDED
#include <kglobal.h>
#endif 

ListViewPwM::ListViewPwM(QWidget *parent, const char *name)
 : KListView(parent, name)
{
//	setResizeMode(QListView::AllColumns);
  setAllColumnsShowFocus (true );
}

bool ListViewPwM::event(QEvent *e)
{
	if (e->type() == QEvent::LayoutRequest)
		emit layoutChanged();
	if (e->type() == QEvent::KeyPress) {
        QKeyEvent* ke = (QKeyEvent*) e;
        if ( ke->key() == Qt::Key_Space) {
            emit toggleOverview();
            return true;
        }
        if ( ke->key() == Qt::Key_I || ke->key() == Qt::Key_N || ke->key() == Qt::Key_Insert) {
            emit insertPW();
            return true;
        }
        if ( ke->key() == Qt::Key_Delete || ke->key() == Qt::Key_Backspace) {
            emit deletePW();
            return true;
        }

    }
	return KListView::event(e);
}


QPixmap * ListViewItemPwM::onPix = 0;
QPixmap * ListViewItemPwM::offPix = 0;

ListViewItemPwM::ListViewItemPwM(Q3ListView *parent)
 : Q3CheckListItem(parent, "", Q3CheckListItem::CheckBox)
{
	if (!onPix) {
		PWM_ASSERT(!offPix);
		KIconLoader* picons;
#ifndef PWM_EMBEDDED
		KIconLoader il;
		picons = &il;
#else
		picons = KGlobal::iconLoader();
#endif

		KIconLoader il;
#ifndef PWM_EMBEDDED
		static QPixmap onP(picons->loadIcon("button_ok", KIcon::Small));
#else
		static QPixmap onP(picons->loadIcon("decrypted", KIcon::Small));
#endif
		onPix = &onP;
		static QPixmap offP(picons->loadIcon("encrypted", KIcon::Small));
		offPix = &offP;
	}
}

void ListViewItemPwM::paintCell(QPainter *p, const QColorGroup &cg,
				int column, int width, int align)
{
  //  qDebug("ListViewItemPwM::paintCell column=%i", column);
	if (!p)
		return;
	//US BUG: 
	if (column != COLUMN_DESC) {
		Q3CheckListItem::paintCell(p, cg, column, width, align);
		return;
	}
	QPixmap *curPix = isOn() ? onPix : offPix;
	int pixSpace = curPix->width();
	pixSpace += 4;
#ifndef PWM_EMBEDDED
	QRect window(p->viewport());
	// clear the rectangle (we have to clear it first. see QT doc)
	p->eraseRect(0, 0, pixSpace, window.height());
	// now draw the pixmap
	int y = (height() - curPix->height()) / 2;
	p->drawPixmap(1, y, *curPix);
	window.moveLeft(pixSpace);
	p->setViewport(window);
#else
	p->eraseRect(0, 0, pixSpace, height());
	// now draw the pixmap
	int y = (height() - curPix->height()) / 2;
	p->drawPixmap(1, y, *curPix);
	p->translate( pixSpace, 0 );

#endif
	Q3ListViewItem::paintCell(p, cg, column, width - pixSpace, align);

}

#ifndef PWM_EMBEDDED_
#include "moc_listviewpwm.cpp"
#endif