kspread

kspread_dlg_list.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002-2003 Ariya Hidayat <ariya@kde.org>
3 (C) 2001-2003 Laurent Montel <montel@kde.org>
4 (C) 1998, 1999 Torben Weis <weis@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include <tqlabel.h>
23#include <tqlayout.h>
24#include <tqlineedit.h>
25#include <tqlistbox.h>
26#include <tqmultilineedit.h>
27#include <tqpushbutton.h>
28
29#include <kbuttonbox.h>
30#include <tdeconfig.h>
31#include <kdebug.h>
32#include <tdemessagebox.h>
33
34#include "kspread_autofill.h"
35#include "kspread_factory.h"
36#include "kspread_locale.h"
37
38#include "kspread_dlg_list.h"
39
40using namespace KSpread;
41
42ListDialog::ListDialog( TQWidget* parent, const char* name )
43 : KDialogBase( parent, name, true, i18n("Custom Lists"), Ok|Cancel )
44{
45 TQWidget* page = new TQWidget( this );
46 setMainWidget( page );
47
48 TQGridLayout *grid1 = new TQGridLayout( page,10,3,KDialog::marginHint(), KDialog::spacingHint());
49
50 TQLabel *lab=new TQLabel(page);
51 lab->setText(i18n("List:" ));
52 grid1->addWidget(lab,0,0);
53
54 list=new TQListBox(page);
55 grid1->addMultiCellWidget(list,1,8,0,0);
56
57
58 lab=new TQLabel(page);
59 lab->setText(i18n("Entry:" ));
60 grid1->addWidget(lab,0,1);
61
62 entryList=new TQMultiLineEdit(page);
63 grid1->addMultiCellWidget(entryList,1,8,1,1);
64
65 m_pRemove=new TQPushButton(i18n("&Remove"),page);
66 grid1->addWidget(m_pRemove,3,2);
67
68 m_pAdd=new TQPushButton(i18n("&Add"),page);
69 grid1->addWidget(m_pAdd,1,2);
70
71 m_pNew=new TQPushButton(i18n("&New"),page);
72 grid1->addWidget(m_pNew,2,2);
73
74 m_pModify=new TQPushButton(i18n("&Modify"),page);
75 grid1->addWidget(m_pModify,4,2);
76
77 m_pCopy=new TQPushButton(i18n("Co&py"),page);
78 grid1->addWidget(m_pCopy,5,2);
79
80 m_pAdd->setEnabled(false);
81
82 connect( m_pRemove, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotRemove() ) );
83 connect( m_pAdd, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotAdd() ) );
84 connect( m_pNew, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotNew() ) );
85 connect( m_pModify, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotModify() ) );
86 connect( m_pCopy, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotCopy() ) );
87 connect( list, TQ_SIGNAL(doubleClicked(TQListBoxItem *)),this,TQ_SLOT(slotDoubleClicked(TQListBoxItem *)));
88 connect( list, TQ_SIGNAL(clicked ( TQListBoxItem * )),this,TQ_SLOT(slotTextClicked(TQListBoxItem * )));
89 init();
90 entryList->setEnabled(false);
91 m_pModify->setEnabled(false);
92 if(list->count()<=2)
93 m_pRemove->setEnabled(false);
94 resize( 600, 250 );
95 m_bChanged=false;
96}
97
98
99void ListDialog::slotTextClicked(TQListBoxItem*)
100{
101 //we can't remove the two first item
102 bool state=list->currentItem()>1;
103 m_pRemove->setEnabled(state);
104 m_pModify->setEnabled(state);
105
106}
107
108void ListDialog::init()
109{
110 TQString month;
111 month+=i18n("January")+", ";
112 month+=i18n("February")+", ";
113 month+=i18n("March") +", ";
114 month+=i18n("April")+", ";
115 month+=i18n("May")+", ";
116 month+=i18n("June")+", ";
117 month+=i18n("July")+", ";
118 month+=i18n("August")+", ";
119 month+=i18n("September")+", ";
120 month+=i18n("October")+", ";
121 month+=i18n("November")+", ";
122 month+=i18n("December");
123 TQStringList lst;
124 lst.append(month);
125
126 TQString smonth;
127 smonth+=i18n("Jan")+", ";
128 smonth+=i18n("Feb")+", ";
129 smonth+=i18n("Mar") +", ";
130 smonth+=i18n("Apr")+", ";
131 smonth+=i18n("May")+", ";
132 smonth+=i18n("Jun")+", ";
133 smonth+=i18n("Jul")+", ";
134 smonth+=i18n("Aug")+", ";
135 smonth+=i18n("Sep")+", ";
136 smonth+=i18n("Oct")+", ";
137 smonth+=i18n("Nov")+", ";
138 smonth+=i18n("Dec");
139 lst.append(smonth);
140
141 TQString day=i18n("Monday")+", ";
142 day+=i18n("Tuesday")+", ";
143 day+=i18n("Wednesday")+", ";
144 day+=i18n("Thursday")+", ";
145 day+=i18n("Friday")+", ";
146 day+=i18n("Saturday")+", ";
147 day+=i18n("Sunday");
148 lst.append(day);
149
150 TQString sday=i18n("Mon")+", ";
151 sday+=i18n("Tue")+", ";
152 sday+=i18n("Wed")+", ";
153 sday+=i18n("Thu")+", ";
154 sday+=i18n("Fri")+", ";
155 sday+=i18n("Sat")+", ";
156 sday+=i18n("Sun");
157 lst.append(sday);
158
159 config = Factory::global()->config();
160 config->setGroup( "Parameters" );
161 TQStringList other=config->readListEntry("Other list");
162 TQString tmp;
163 for ( TQStringList::Iterator it = other.begin(); it != other.end();++it )
164 {
165 if((*it)!="\\")
166 tmp+=(*it)+", ";
167 else if( it!=other.begin())
168 {
169 tmp=tmp.left(tmp.length()-2);
170 lst.append(tmp);
171 tmp="";
172 }
173 }
174 list->insertStringList(lst);
175}
176
177void ListDialog::slotDoubleClicked(TQListBoxItem *)
178{
179 //we can't modify the two first item
180 if(list->currentItem()<2)
181 return;
182 TQString tmp=list->currentText();
183 entryList->setText("");
184 TQStringList result=result.split(", ",tmp);
185 int index=0;
186 for ( TQStringList::Iterator it = result.begin(); it != result.end();++it )
187 {
188 entryList->insertLine((*it),index);
189 index++;
190 }
191 entryList->setEnabled(true);
192 m_pModify->setEnabled(true);
193}
194
195void ListDialog::slotAdd()
196{
197 m_pAdd->setEnabled(false);
198 list->setEnabled(true);
199 TQString tmp;
200 for(int i=0;i<entryList->numLines();i++)
201 {
202 if(!entryList->textLine(i).isEmpty())
203 {
204 if(tmp.isEmpty())
205 tmp=entryList->textLine(i);
206 else
207 tmp+=", "+entryList->textLine(i);
208 }
209 }
210 if(!tmp.isEmpty())
211 list->insertItem(tmp,list->count());
212
213 entryList->setText("");
214 entryList->setEnabled(false);
215 entryList->setFocus();
216 slotTextClicked(0L);
217 m_bChanged=true;
218}
219
220void ListDialog::slotNew()
221{
222 m_pAdd->setEnabled(true);
223 list->setEnabled(false);
224 entryList->setText("");
225 entryList->setEnabled(true);
226 entryList->setFocus();
227}
228
229void ListDialog::slotRemove()
230{
231 if(list->currentItem()==-1)
232 return;
233 //don't remove the two first line
234 if(list->currentItem()<2)
235 return;
236 int ret = KMessageBox::warningContinueCancel( this, i18n("Do you really want to remove this list?"),i18n("Remove List"),KStdGuiItem::del());
237 if(ret==Cancel) // reponse = No
238 return;
239 list->removeItem(list->currentItem ());
240 entryList->setEnabled(false);
241 entryList->setText("");
242 if(list->count()<=2)
243 m_pRemove->setEnabled(false);
244 m_bChanged=true;
245}
246
247void ListDialog::slotOk()
248{
249 if(!entryList->text().isEmpty())
250 {
251 int ret = KMessageBox::warningYesNo( this, i18n("Entry area is not empty.\nDo you want to continue?"));
252 if(ret==4) // reponse = No
253 return;
254 }
255 if(m_bChanged)
256 {
257 TQStringList result;
258 result.append("\\");
259
260 //don't save the two first line
261 for(unsigned int i=2;i<list->count();i++)
262 {
263 TQStringList tmp=result.split(", ",list->text(i));
264 if ( !tmp.isEmpty() )
265 {
266 result+=tmp;
267 result+="\\";
268 }
269 }
270 config->setGroup( "Parameters" );
271 config->writeEntry("Other list",result);
272 //todo refresh AutoFillSequenceItem::other
273 // I don't know how to do for the moment
274 if(AutoFillSequenceItem::other!=0L)
275 {
276 delete(AutoFillSequenceItem::other);
277 AutoFillSequenceItem::other=0L;
278 }
279 }
280 accept();
281}
282
283void ListDialog::slotModify()
284{
285 //you can modify list but not the two first list
286 if(list->currentItem ()>1 && !entryList->text().isEmpty())
287 {
288 TQString tmp;
289 for(int i=0;i<entryList->numLines();i++)
290 {
291 if(!entryList->textLine(i).isEmpty())
292 {
293 if(tmp.isEmpty())
294 tmp=entryList->textLine(i);
295 else
296 tmp+=", "+entryList->textLine(i);
297 }
298 }
299 list->insertItem(tmp,list->currentItem());
300 list->removeItem(list->currentItem());
301
302
303 entryList->setText("");
304 m_bChanged=true;
305
306 }
307 entryList->setEnabled(false);
308 m_pModify->setEnabled(false);
309
310}
311
312void ListDialog::slotCopy()
313{
314 if(list->currentItem()!=-1)
315 {
316 list->insertItem(list->currentText(),list->count());
317 }
318}
319
320
321#include "kspread_dlg_list.moc"
The KSpread namespace.
Definition commands.h:39