summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/listobjselectwnd.cpp
blob: 7da7e958172c98b5872561cfb87eea30625c0298 (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
133
134
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2003, 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 "listobjselectwnd.h"

#include <klocale.h>
//Added by qt3to4:
#include <QResizeEvent>
#include <QLabel>


ListObjSelectWnd::ListObjSelectWnd(const QString &caption, const QString &titleText,
				   QWidget *parent, bool multiSel, const char *name,
				   bool modal, Qt::WFlags f)
 : QDialog(parent, name, modal, f)
{
	vbox1 = new Q3VBox(this);
	title = new QLabel(vbox1);
	list = new Q3ListBox(vbox1);
	if (multiSel) {
		hbox2 = new Q3HBox(vbox1);
		selAllButton = new QPushButton(i18n("&Select all"), hbox2);
		unselAllButton = new QPushButton(i18n("&Unselect all"), hbox2);
	}
	hbox1 = new Q3HBox(vbox1);
	okButton = new QPushButton(i18n("&Ok"), hbox1);
	cancelButton = new QPushButton(i18n("&Cancel"), hbox1);

	vbox1->setSpacing(10);
	vbox1->setMargin(10);
	hbox1->setSpacing(10);
	resize(250, 300);
	setCaption(caption);
	if (multiSel) {
		list->setSelectionMode(Q3ListBox::Multi);
	}

	title->setAlignment(Qt::AlignHCenter | Qt::WordBreak);
	title->setText(titleText);

	connect(okButton, SIGNAL(clicked()),
		this, SLOT(okButton_slot()));
	connect(cancelButton, SIGNAL(clicked()),
		this, SLOT(cancelButton_slot()));
	if (multiSel) {
		connect(selAllButton, SIGNAL(clicked()),
			this, SLOT(selAllButton_slot()));
		connect(unselAllButton, SIGNAL(clicked()),
			this, SLOT(unselAllButton_slot()));
	}
}

ListObjSelectWnd::~ListObjSelectWnd()
{
}

void ListObjSelectWnd::resizeEvent(QResizeEvent *)
{
	vbox1->resize(size());
}

void ListObjSelectWnd::okButton_slot()
{
	unsigned int cnt = list->count(), i;
	for (i = 0; i < cnt; ++i) {
		if (list->isSelected(i)) {
			done(1);
			return;
		}
	}
}

void ListObjSelectWnd::cancelButton_slot()
{
	done(2);
}

void ListObjSelectWnd::selAllButton_slot()
{
	unsigned int cnt = list->count(), i;
	for (i = 0; i < cnt; ++i) {
		list->setSelected(i, true);
	}
}

void ListObjSelectWnd::unselAllButton_slot()
{
	unsigned int cnt = list->count(), i;
	for (i = 0; i < cnt; ++i) {
		list->setSelected(i, false);
	}
}

QStringList ListObjSelectWnd::getSelectedList()
{
	QStringList ret;
	unsigned int cnt = list->count(), i;
	for (i = 0; i < cnt; ++i) {
		if (list->isSelected(i)) {
#ifndef PWM_EMBEDDED
			ret.push_back(list->text(i));
#else
			ret.append(list->text(i));
#endif
		}
	}
	return ret;
}

void ListObjSelectWnd::setList(const QStringList &_list)
{
	list->clear();
	list->insertStringList(_list);
}

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