Diffstat (limited to 'pwmanager/pwmanager/listobjselectwnd.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/listobjselectwnd.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/listobjselectwnd.cpp b/pwmanager/pwmanager/listobjselectwnd.cpp new file mode 100644 index 0000000..59729f1 --- a/dev/null +++ b/pwmanager/pwmanager/listobjselectwnd.cpp | |||
@@ -0,0 +1,131 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * copyright (C) 2003, 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 "listobjselectwnd.h" | ||
21 | |||
22 | #include <klocale.h> | ||
23 | |||
24 | |||
25 | ListObjSelectWnd::ListObjSelectWnd(const QString &caption, const QString &titleText, | ||
26 | QWidget *parent, bool multiSel, const char *name, | ||
27 | bool modal, WFlags f) | ||
28 | : QDialog(parent, name, modal, f) | ||
29 | { | ||
30 | vbox1 = new QVBox(this); | ||
31 | title = new QLabel(vbox1); | ||
32 | list = new QListBox(vbox1); | ||
33 | if (multiSel) { | ||
34 | hbox2 = new QHBox(vbox1); | ||
35 | selAllButton = new QPushButton(i18n("&Select all"), hbox2); | ||
36 | unselAllButton = new QPushButton(i18n("&Unselect all"), hbox2); | ||
37 | } | ||
38 | hbox1 = new QHBox(vbox1); | ||
39 | okButton = new QPushButton(i18n("&Ok"), hbox1); | ||
40 | cancelButton = new QPushButton(i18n("&Cancel"), hbox1); | ||
41 | |||
42 | vbox1->setSpacing(10); | ||
43 | vbox1->setMargin(10); | ||
44 | hbox1->setSpacing(10); | ||
45 | resize(250, 300); | ||
46 | setCaption(caption); | ||
47 | if (multiSel) { | ||
48 | list->setSelectionMode(QListBox::Multi); | ||
49 | } | ||
50 | |||
51 | title->setAlignment(Qt::AlignHCenter | Qt::WordBreak); | ||
52 | title->setText(titleText); | ||
53 | |||
54 | connect(okButton, SIGNAL(clicked()), | ||
55 | this, SLOT(okButton_slot())); | ||
56 | connect(cancelButton, SIGNAL(clicked()), | ||
57 | this, SLOT(cancelButton_slot())); | ||
58 | if (multiSel) { | ||
59 | connect(selAllButton, SIGNAL(clicked()), | ||
60 | this, SLOT(selAllButton_slot())); | ||
61 | connect(unselAllButton, SIGNAL(clicked()), | ||
62 | this, SLOT(unselAllButton_slot())); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | ListObjSelectWnd::~ListObjSelectWnd() | ||
67 | { | ||
68 | } | ||
69 | |||
70 | void ListObjSelectWnd::resizeEvent(QResizeEvent *) | ||
71 | { | ||
72 | vbox1->resize(size()); | ||
73 | } | ||
74 | |||
75 | void ListObjSelectWnd::okButton_slot() | ||
76 | { | ||
77 | unsigned int cnt = list->count(), i; | ||
78 | for (i = 0; i < cnt; ++i) { | ||
79 | if (list->isSelected(i)) { | ||
80 | done(1); | ||
81 | return; | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void ListObjSelectWnd::cancelButton_slot() | ||
87 | { | ||
88 | done(2); | ||
89 | } | ||
90 | |||
91 | void ListObjSelectWnd::selAllButton_slot() | ||
92 | { | ||
93 | unsigned int cnt = list->count(), i; | ||
94 | for (i = 0; i < cnt; ++i) { | ||
95 | list->setSelected(i, true); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void ListObjSelectWnd::unselAllButton_slot() | ||
100 | { | ||
101 | unsigned int cnt = list->count(), i; | ||
102 | for (i = 0; i < cnt; ++i) { | ||
103 | list->setSelected(i, false); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | QStringList ListObjSelectWnd::getSelectedList() | ||
108 | { | ||
109 | QStringList ret; | ||
110 | unsigned int cnt = list->count(), i; | ||
111 | for (i = 0; i < cnt; ++i) { | ||
112 | if (list->isSelected(i)) { | ||
113 | #ifndef PWM_EMBEDDED | ||
114 | ret.push_back(list->text(i)); | ||
115 | #else | ||
116 | ret.append(list->text(i)); | ||
117 | #endif | ||
118 | } | ||
119 | } | ||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | void ListObjSelectWnd::setList(const QStringList &_list) | ||
124 | { | ||
125 | list->clear(); | ||
126 | list->insertStringList(_list); | ||
127 | } | ||
128 | |||
129 | #ifndef PWM_EMBEDDED | ||
130 | #include "listobjselectwnd.moc" | ||
131 | #endif | ||