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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/* This file is part of the KDE project
Copyright (C) 2002-2003 Ariya Hidayat <[email protected]>
(C) 2001-2003 Laurent Montel <[email protected]>
(C) 1998, 1999 Torben Weis <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqlistbox.h>
#include <tqmultilineedit.h>
#include <tqpushbutton.h>
#include <kbuttonbox.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <tdemessagebox.h>
#include "kspread_autofill.h"
#include "kspread_factory.h"
#include "kspread_locale.h"
#include "kspread_dlg_list.h"
using namespace KSpread;
ListDialog::ListDialog( TQWidget* parent, const char* name )
: KDialogBase( parent, name, true, i18n("Custom Lists"), Ok|Cancel )
{
TQWidget* page = new TQWidget( this );
setMainWidget( page );
TQGridLayout *grid1 = new TQGridLayout( page,10,3,KDialog::marginHint(), KDialog::spacingHint());
TQLabel *lab=new TQLabel(page);
lab->setText(i18n("List:" ));
grid1->addWidget(lab,0,0);
list=new TQListBox(page);
grid1->addMultiCellWidget(list,1,8,0,0);
lab=new TQLabel(page);
lab->setText(i18n("Entry:" ));
grid1->addWidget(lab,0,1);
entryList=new TQMultiLineEdit(page);
grid1->addMultiCellWidget(entryList,1,8,1,1);
m_pRemove=new TQPushButton(i18n("&Remove"),page);
grid1->addWidget(m_pRemove,3,2);
m_pAdd=new TQPushButton(i18n("&Add"),page);
grid1->addWidget(m_pAdd,1,2);
m_pNew=new TQPushButton(i18n("&New"),page);
grid1->addWidget(m_pNew,2,2);
m_pModify=new TQPushButton(i18n("&Modify"),page);
grid1->addWidget(m_pModify,4,2);
m_pCopy=new TQPushButton(i18n("Co&py"),page);
grid1->addWidget(m_pCopy,5,2);
m_pAdd->setEnabled(false);
connect( m_pRemove, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotRemove() ) );
connect( m_pAdd, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotAdd() ) );
connect( m_pNew, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotNew() ) );
connect( m_pModify, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotModify() ) );
connect( m_pCopy, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotCopy() ) );
connect( list, TQT_SIGNAL(doubleClicked(TQListBoxItem *)),this,TQT_SLOT(slotDoubleClicked(TQListBoxItem *)));
connect( list, TQT_SIGNAL(clicked ( TQListBoxItem * )),this,TQT_SLOT(slotTextClicked(TQListBoxItem * )));
init();
entryList->setEnabled(false);
m_pModify->setEnabled(false);
if(list->count()<=2)
m_pRemove->setEnabled(false);
resize( 600, 250 );
m_bChanged=false;
}
void ListDialog::slotTextClicked(TQListBoxItem*)
{
//we can't remove the two first item
bool state=list->currentItem()>1;
m_pRemove->setEnabled(state);
m_pModify->setEnabled(state);
}
void ListDialog::init()
{
TQString month;
month+=i18n("January")+", ";
month+=i18n("February")+", ";
month+=i18n("March") +", ";
month+=i18n("April")+", ";
month+=i18n("May")+", ";
month+=i18n("June")+", ";
month+=i18n("July")+", ";
month+=i18n("August")+", ";
month+=i18n("September")+", ";
month+=i18n("October")+", ";
month+=i18n("November")+", ";
month+=i18n("December");
TQStringList lst;
lst.append(month);
TQString smonth;
smonth+=i18n("Jan")+", ";
smonth+=i18n("Feb")+", ";
smonth+=i18n("Mar") +", ";
smonth+=i18n("Apr")+", ";
smonth+=i18n("May")+", ";
smonth+=i18n("Jun")+", ";
smonth+=i18n("Jul")+", ";
smonth+=i18n("Aug")+", ";
smonth+=i18n("Sep")+", ";
smonth+=i18n("Oct")+", ";
smonth+=i18n("Nov")+", ";
smonth+=i18n("Dec");
lst.append(smonth);
TQString day=i18n("Monday")+", ";
day+=i18n("Tuesday")+", ";
day+=i18n("Wednesday")+", ";
day+=i18n("Thursday")+", ";
day+=i18n("Friday")+", ";
day+=i18n("Saturday")+", ";
day+=i18n("Sunday");
lst.append(day);
TQString sday=i18n("Mon")+", ";
sday+=i18n("Tue")+", ";
sday+=i18n("Wed")+", ";
sday+=i18n("Thu")+", ";
sday+=i18n("Fri")+", ";
sday+=i18n("Sat")+", ";
sday+=i18n("Sun");
lst.append(sday);
config = Factory::global()->config();
config->setGroup( "Parameters" );
TQStringList other=config->readListEntry("Other list");
TQString tmp;
for ( TQStringList::Iterator it = other.begin(); it != other.end();++it )
{
if((*it)!="\\")
tmp+=(*it)+", ";
else if( it!=other.begin())
{
tmp=tmp.left(tmp.length()-2);
lst.append(tmp);
tmp="";
}
}
list->insertStringList(lst);
}
void ListDialog::slotDoubleClicked(TQListBoxItem *)
{
//we can't modify the two first item
if(list->currentItem()<2)
return;
TQString tmp=list->currentText();
entryList->setText("");
TQStringList result=result.split(", ",tmp);
int index=0;
for ( TQStringList::Iterator it = result.begin(); it != result.end();++it )
{
entryList->insertLine((*it),index);
index++;
}
entryList->setEnabled(true);
m_pModify->setEnabled(true);
}
void ListDialog::slotAdd()
{
m_pAdd->setEnabled(false);
list->setEnabled(true);
TQString tmp;
for(int i=0;i<entryList->numLines();i++)
{
if(!entryList->textLine(i).isEmpty())
{
if(tmp.isEmpty())
tmp=entryList->textLine(i);
else
tmp+=", "+entryList->textLine(i);
}
}
if(!tmp.isEmpty())
list->insertItem(tmp,list->count());
entryList->setText("");
entryList->setEnabled(false);
entryList->setFocus();
slotTextClicked(0L);
m_bChanged=true;
}
void ListDialog::slotNew()
{
m_pAdd->setEnabled(true);
list->setEnabled(false);
entryList->setText("");
entryList->setEnabled(true);
entryList->setFocus();
}
void ListDialog::slotRemove()
{
if(list->currentItem()==-1)
return;
//don't remove the two first line
if(list->currentItem()<2)
return;
int ret = KMessageBox::warningContinueCancel( this, i18n("Do you really want to remove this list?"),i18n("Remove List"),KStdGuiItem::del());
if(ret==Cancel) // reponse = No
return;
list->removeItem(list->currentItem ());
entryList->setEnabled(false);
entryList->setText("");
if(list->count()<=2)
m_pRemove->setEnabled(false);
m_bChanged=true;
}
void ListDialog::slotOk()
{
if(!entryList->text().isEmpty())
{
int ret = KMessageBox::warningYesNo( this, i18n("Entry area is not empty.\nDo you want to continue?"));
if(ret==4) // reponse = No
return;
}
if(m_bChanged)
{
TQStringList result;
result.append("\\");
//don't save the two first line
for(unsigned int i=2;i<list->count();i++)
{
TQStringList tmp=result.split(", ",list->text(i));
if ( !tmp.isEmpty() )
{
result+=tmp;
result+="\\";
}
}
config->setGroup( "Parameters" );
config->writeEntry("Other list",result);
//todo refresh AutoFillSequenceItem::other
// I don't know how to do for the moment
if(AutoFillSequenceItem::other!=0L)
{
delete(AutoFillSequenceItem::other);
AutoFillSequenceItem::other=0L;
}
}
accept();
}
void ListDialog::slotModify()
{
//you can modify list but not the two first list
if(list->currentItem ()>1 && !entryList->text().isEmpty())
{
TQString tmp;
for(int i=0;i<entryList->numLines();i++)
{
if(!entryList->textLine(i).isEmpty())
{
if(tmp.isEmpty())
tmp=entryList->textLine(i);
else
tmp+=", "+entryList->textLine(i);
}
}
list->insertItem(tmp,list->currentItem());
list->removeItem(list->currentItem());
entryList->setText("");
m_bChanged=true;
}
entryList->setEnabled(false);
m_pModify->setEnabled(false);
}
void ListDialog::slotCopy()
{
if(list->currentItem()!=-1)
{
list->insertItem(list->currentText(),list->count());
}
}
#include "kspread_dlg_list.moc"
|