summaryrefslogtreecommitdiffabout
path: root/libkdepim/categoryselectdialog.cpp
Unidiff
Diffstat (limited to 'libkdepim/categoryselectdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkdepim/categoryselectdialog.cpp70
1 files changed, 68 insertions, 2 deletions
diff --git a/libkdepim/categoryselectdialog.cpp b/libkdepim/categoryselectdialog.cpp
index 7df9154..8b2bc4e 100644
--- a/libkdepim/categoryselectdialog.cpp
+++ b/libkdepim/categoryselectdialog.cpp
@@ -1,171 +1,237 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlistview.h> 24#include <qlistview.h>
25#include <qpushbutton.h> 25#include <qpushbutton.h>
26#include <qheader.h> 26#include <qheader.h>
27#include <qapp.h> 27#include <qapp.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <kmessagebox.h>
29 30
30 31
31#include "categoryeditdialog.h" 32#include "categoryeditdialog.h"
32#include "categoryselectdialog.h" 33#include "categoryselectdialog.h"
33 34
34#include "kpimprefs.h" 35#include "kpimprefs.h"
35 36
36using namespace KPIM; 37using namespace KPIM;
37 38
38CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, QWidget* parent, 39CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, QWidget* parent,
39 const char* name, 40 const char* name,
40 bool modal, WFlags fl ) 41 bool modal, WFlags fl )
41 : CategorySelectDialog_base( parent, name, true, fl ), 42 : CategorySelectDialog_base( parent, name, true, fl ),
42 mPrefs( prefs ) 43 mPrefs( prefs )
43{ 44{
45 mColorItem = 0;
46 mColorEnabled = false;
44 mCategories->header()->hide(); 47 mCategories->header()->hide();
45 48
46 setCategories(); 49 setCategories();
47 50
48 connect(mButtonEdit,SIGNAL(clicked()),this, SLOT(editCategoriesDialog())); 51 connect(mButtonEdit,SIGNAL(clicked()),this, SLOT(editCategoriesDialog()));
49 if ( QApplication::desktop()->width() > 460 ) 52 if ( QApplication::desktop()->width() > 460 )
50 resize( 300, 360 ); 53 resize( 300, 360 );
51 else 54 else
52 showMaximized(); 55 showMaximized();
56 connect( mSetColorCat, SIGNAL( clicked() ), this, SLOT( setColorCat() ) );
57 connect( mCategories, SIGNAL( clicked(QListViewItem *) ), this, SLOT( clicked(QListViewItem *) ) );
53} 58}
54void CategorySelectDialog::editCategoriesDialog() 59void CategorySelectDialog::editCategoriesDialog()
55{ 60{
56 KPIM::CategoryEditDialog* ced = new KPIM::CategoryEditDialog(mPrefs,this ); 61 KPIM::CategoryEditDialog* ced = new KPIM::CategoryEditDialog(mPrefs,this );
57 62
58 ced->exec(); 63 ced->exec();
59 delete ced; 64 delete ced;
60 setCategories(); 65 setCategories();
61} 66}
62void CategorySelectDialog::setCategories() 67void CategorySelectDialog::setCategories()
63{ 68{
69 mColorItem = 0;
64 mCategories->clear(); 70 mCategories->clear();
65 mCategoryList.clear(); 71 mCategoryList.clear();
66 72
67 QStringList::Iterator it; 73 QStringList::Iterator it;
68
69 for (it = mPrefs->mCustomCategories.begin(); 74 for (it = mPrefs->mCustomCategories.begin();
70 it != mPrefs->mCustomCategories.end(); ++it ) { 75 it != mPrefs->mCustomCategories.end(); ++it ) {
71 new QCheckListItem(mCategories,*it,QCheckListItem::CheckBox); 76 new QCheckListItem(mCategories,*it,QCheckListItem::CheckBox);
72 } 77 }
73} 78}
74 79
75CategorySelectDialog::~CategorySelectDialog() 80CategorySelectDialog::~CategorySelectDialog()
76{ 81{
77} 82}
78 83
79void CategorySelectDialog::setSelected(const QStringList &selList) 84void CategorySelectDialog::setSelected(const QStringList &selList)
80{ 85{
81 clear(); 86 clear();
82 87
83 QStringList::ConstIterator it; 88 QStringList::ConstIterator it;
84 QStringList notFound; 89 QStringList notFound;
85 bool found = false; 90 bool found = false;
86 for (it=selList.begin();it!=selList.end();++it) { 91 for (it=selList.begin();it!=selList.end();++it) {
87 //qDebug(" CategorySelectDialog::setSelected("); 92 //qDebug(" CategorySelectDialog::setSelected(");
88 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild(); 93 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
89 while (item) { 94 while (item) {
90 if (item->text() == *it) { 95 if (item->text() == *it) {
91 item->setOn(true); 96 item->setOn(true);
97 if ( ! found )
98 setColorItem( item );
92 found = true; 99 found = true;
93 break; 100 break;
94 } 101 }
95 item = (QCheckListItem *)item->nextSibling(); 102 item = (QCheckListItem *)item->nextSibling();
96 } 103 }
97// if ( ! found ) { 104// if ( ! found ) {
98 105
99//emit updateCategoriesGlobal(); 106//emit updateCategoriesGlobal();
100// QMessageBox::information( this, "KO/E: Information!", 107// QMessageBox::information( this, "KO/E: Information!",
101// "Categories found, which were not\n" 108// "Categories found, which were not\n"
102// "in list of categories!\n" 109// "in list of categories!\n"
103// "message", 110// "message",
104// "OK", "", 0, 111// "OK", "", 0,
105// 0, 1 ); 112// 0, 1 );
106// setSelected(selList); 113// setSelected(selList);
107// return; 114// return;
108// } 115// }
109 } 116 }
110} 117}
111 118
112QStringList CategorySelectDialog::selectedCategories() const 119QStringList CategorySelectDialog::selectedCategories() const
113{ 120{
114 return mCategoryList; 121 return mCategoryList;
115} 122}
123void CategorySelectDialog::setColorEnabled()
124{
125 mColorEnabled = true;
126 mSetColorCat->show();
127}
128void CategorySelectDialog::setColorCat()
129{
130 QCheckListItem * newColorItem = (QCheckListItem * )mCategories->currentItem ();
131 if ( !newColorItem ) {
132 KMessageBox::error(this,i18n("There is no current item."));
133 return;
134 }
135 if ( !newColorItem->isOn() )
136 newColorItem->setOn( true );
137 setColorItem( newColorItem );
116 138
139}
140void CategorySelectDialog::clicked ( QListViewItem * it )
141{
142 if ( ! it )
143 return;
144 QCheckListItem *i = (QCheckListItem *) it;
145 qDebug("click %d ", i->isOn());
146 if ( !i->isOn() && i==mColorItem) {
147 setColorItem( 0);
148 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
149 while (item) {
150 if (item->isOn()) {
151 setColorItem( item );
152 break;
153 }
154 item = (QCheckListItem *)item->nextSibling();
155 }
156 } else if ( i->isOn() && !mColorItem) {
157 setColorItem( i);
158 }
159}
160void CategorySelectDialog::setColorItem( QCheckListItem * newColorItem )
161{
162 if ( !mColorEnabled )
163 return;
164 if ( mColorItem == newColorItem)
165 return;
166 if ( mColorItem ) {
167 mColorItem->setPixmap ( 0, QPixmap() );
168 mColorItem = 0;
169 }
170 if ( newColorItem ) {
171 QPixmap pix (newColorItem->height()/2, newColorItem->height()/2 );
172 pix.fill(Qt::blue );
173 newColorItem->setPixmap ( 0, pix );
174 mColorItem = newColorItem;
175 }
176}
117void CategorySelectDialog::slotApply() 177void CategorySelectDialog::slotApply()
118{ 178{
119 QStringList categories; 179 QStringList categories;
120 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild(); 180 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
181 QString colcat;
121 while (item) { 182 while (item) {
122 if (item->isOn()) { 183 if (item->isOn()) {
184 if ( item == mColorItem)
185 colcat = item->text();
186 else
123 categories.append(item->text()); 187 categories.append(item->text());
124 } 188 }
125 item = (QCheckListItem *)item->nextSibling(); 189 item = (QCheckListItem *)item->nextSibling();
126 } 190 }
127 191 categories.sort();
192 if ( ! colcat.isEmpty() )
193 categories.prepend( colcat );
128 QString categoriesStr = categories.join(","); 194 QString categoriesStr = categories.join(",");
129 195
130 mCategoryList = categories; 196 mCategoryList = categories;
131 197
132 emit categoriesSelected(categories); 198 emit categoriesSelected(categories);
133 emit categoriesSelected(categoriesStr); 199 emit categoriesSelected(categoriesStr);
134} 200}
135void CategorySelectDialog::accept() 201void CategorySelectDialog::accept()
136{ 202{
137 slotOk(); 203 slotOk();
138} 204}
139 205
140void CategorySelectDialog::slotOk() 206void CategorySelectDialog::slotOk()
141{ 207{
142 slotApply(); 208 slotApply();
143 QDialog::accept(); 209 QDialog::accept();
144} 210}
145 211
146void CategorySelectDialog::clear() 212void CategorySelectDialog::clear()
147{ 213{
148 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild(); 214 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
149 while (item) { 215 while (item) {
150 item->setOn(false); 216 item->setOn(false);
151 item = (QCheckListItem *)item->nextSibling(); 217 item = (QCheckListItem *)item->nextSibling();
152 } 218 }
153} 219}
154 220
155void CategorySelectDialog::updateCategoryConfig() 221void CategorySelectDialog::updateCategoryConfig()
156{ 222{
157 QStringList selected; 223 QStringList selected;
158 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild(); 224 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
159 while (item) { 225 while (item) {
160 if (item->isOn()) { 226 if (item->isOn()) {
161 selected.append(item->text()); 227 selected.append(item->text());
162 } 228 }
163 item = (QCheckListItem *)item->nextSibling(); 229 item = (QCheckListItem *)item->nextSibling();
164 } 230 }
165 231
166 setCategories(); 232 setCategories();
167 233
168 setSelected(selected); 234 setSelected(selected);
169} 235}
170 236
171//#include "categoryselectdialog.moc" 237//#include "categoryselectdialog.moc"