00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qlabel.h>
00024 #include <qlayout.h>
00025 #include <qlineedit.h>
00026 #include <qlistbox.h>
00027 #include <qmultilineedit.h>
00028 #include <qpushbutton.h>
00029
00030 #include <kbuttonbox.h>
00031 #include <kconfig.h>
00032 #include <kdebug.h>
00033 #include <kmessagebox.h>
00034
00035 #include <kspread_autofill.h>
00036 #include <kspread_factory.h>
00037
00038 #include "kspread_dlg_list.h"
00039
00040 #include <kspread_locale.h>
00041
00042 KSpreadList::KSpreadList( QWidget* parent, const char* name )
00043 : KDialogBase( parent, name, true, i18n("Custom Lists"), Ok|Cancel )
00044 {
00045 QWidget* page = new QWidget( this );
00046 setMainWidget( page );
00047
00048 QGridLayout *grid1 = new QGridLayout( page,10,3,KDialog::marginHint(), KDialog::spacingHint());
00049
00050 QLabel *lab=new QLabel(page);
00051 lab->setText(i18n("List:" ));
00052 grid1->addWidget(lab,0,0);
00053
00054 list=new QListBox(page);
00055 grid1->addMultiCellWidget(list,1,8,0,0);
00056
00057
00058 lab=new QLabel(page);
00059 lab->setText(i18n("Entry:" ));
00060 grid1->addWidget(lab,0,1);
00061
00062 entryList=new QMultiLineEdit(page);
00063 grid1->addMultiCellWidget(entryList,1,8,1,1);
00064
00065 m_pRemove=new QPushButton(i18n("&Remove"),page);
00066 grid1->addWidget(m_pRemove,3,2);
00067
00068 m_pAdd=new QPushButton(i18n("&Add"),page);
00069 grid1->addWidget(m_pAdd,1,2);
00070
00071 m_pNew=new QPushButton(i18n("&New"),page);
00072 grid1->addWidget(m_pNew,2,2);
00073
00074 m_pModify=new QPushButton(i18n("&Modify"),page);
00075 grid1->addWidget(m_pModify,4,2);
00076
00077 m_pCopy=new QPushButton(i18n("Co&py"),page);
00078 grid1->addWidget(m_pCopy,5,2);
00079
00080 m_pAdd->setEnabled(false);
00081
00082 connect( m_pRemove, SIGNAL( clicked() ), this, SLOT( slotRemove() ) );
00083 connect( m_pAdd, SIGNAL( clicked() ), this, SLOT( slotAdd() ) );
00084 connect( m_pNew, SIGNAL( clicked() ), this, SLOT( slotNew() ) );
00085 connect( m_pModify, SIGNAL( clicked() ), this, SLOT( slotModify() ) );
00086 connect( m_pCopy, SIGNAL( clicked() ), this, SLOT( slotCopy() ) );
00087 connect( list, SIGNAL(doubleClicked(QListBoxItem *)),this,SLOT(slotDoubleClicked(QListBoxItem *)));
00088 connect( list, SIGNAL(clicked ( QListBoxItem * )),this,SLOT(slotTextClicked(QListBoxItem * )));
00089 init();
00090 entryList->setEnabled(false);
00091 m_pModify->setEnabled(false);
00092 if(list->count()<=2)
00093 m_pRemove->setEnabled(false);
00094 resize( 600, 250 );
00095 m_bChanged=false;
00096 }
00097
00098
00099 void KSpreadList::slotTextClicked(QListBoxItem*)
00100 {
00101
00102 bool state=list->currentItem()>1;
00103 m_pRemove->setEnabled(state);
00104 m_pModify->setEnabled(state);
00105
00106 }
00107
00108 void KSpreadList::init()
00109 {
00110 QString month;
00111 month+=i18n("January")+", ";
00112 month+=i18n("February")+", ";
00113 month+=i18n("March") +", ";
00114 month+=i18n("April")+", ";
00115 month+=i18n("May")+", ";
00116 month+=i18n("June")+", ";
00117 month+=i18n("July")+", ";
00118 month+=i18n("August")+", ";
00119 month+=i18n("September")+", ";
00120 month+=i18n("October")+", ";
00121 month+=i18n("November")+", ";
00122 month+=i18n("December");
00123 QStringList lst;
00124 lst.append(month);
00125
00126 QString smonth;
00127 smonth+=i18n("Jan")+", ";
00128 smonth+=i18n("Feb")+", ";
00129 smonth+=i18n("Mar") +", ";
00130 smonth+=i18n("Apr")+", ";
00131 smonth+=i18n("May")+", ";
00132 smonth+=i18n("Jun")+", ";
00133 smonth+=i18n("Jul")+", ";
00134 smonth+=i18n("Aug")+", ";
00135 smonth+=i18n("Sep")+", ";
00136 smonth+=i18n("Oct")+", ";
00137 smonth+=i18n("Nov")+", ";
00138 smonth+=i18n("Dec");
00139 lst.append(smonth);
00140
00141 QString day=i18n("Monday")+", ";
00142 day+=i18n("Tuesday")+", ";
00143 day+=i18n("Wednesday")+", ";
00144 day+=i18n("Thursday")+", ";
00145 day+=i18n("Friday")+", ";
00146 day+=i18n("Saturday")+", ";
00147 day+=i18n("Sunday");
00148 lst.append(day);
00149
00150 QString sday=i18n("Mon")+", ";
00151 sday+=i18n("Tue")+", ";
00152 sday+=i18n("Wed")+", ";
00153 sday+=i18n("Thu")+", ";
00154 sday+=i18n("Fri")+", ";
00155 sday+=i18n("Sat")+", ";
00156 sday+=i18n("Sun");
00157 lst.append(sday);
00158
00159 config = KSpreadFactory::global()->config();
00160 config->setGroup( "Parameters" );
00161 QStringList other=config->readListEntry("Other list");
00162 QString tmp;
00163 for ( QStringList::Iterator it = other.begin(); it != other.end();++it )
00164 {
00165 if((*it)!="\\")
00166 tmp+=(*it)+", ";
00167 else if( it!=other.begin())
00168 {
00169 tmp=tmp.left(tmp.length()-2);
00170 lst.append(tmp);
00171 tmp="";
00172 }
00173 }
00174 list->insertStringList(lst);
00175 }
00176
00177 void KSpreadList::slotDoubleClicked(QListBoxItem *)
00178 {
00179
00180 if(list->currentItem()<2)
00181 return;
00182 QString tmp=list->currentText();
00183 entryList->setText("");
00184 QStringList result=result.split(", ",tmp);
00185 int index=0;
00186 for ( QStringList::Iterator it = result.begin(); it != result.end();++it )
00187 {
00188 entryList->insertLine((*it),index);
00189 index++;
00190 }
00191 entryList->setEnabled(true);
00192 m_pModify->setEnabled(true);
00193 }
00194
00195 void KSpreadList::slotAdd()
00196 {
00197 m_pAdd->setEnabled(false);
00198 list->setEnabled(true);
00199 QString tmp;
00200 for(int i=0;i<entryList->numLines();i++)
00201 {
00202 if(!entryList->textLine(i).isEmpty())
00203 {
00204 if(tmp.isEmpty())
00205 tmp=entryList->textLine(i);
00206 else
00207 tmp+=", "+entryList->textLine(i);
00208 }
00209 }
00210 if(!tmp.isEmpty())
00211 list->insertItem(tmp,list->count());
00212
00213 entryList->setText("");
00214 entryList->setEnabled(false);
00215 entryList->setFocus();
00216 slotTextClicked(0L);
00217 m_bChanged=true;
00218 }
00219
00220 void KSpreadList::slotNew()
00221 {
00222 m_pAdd->setEnabled(true);
00223 list->setEnabled(false);
00224 entryList->setText("");
00225 entryList->setEnabled(true);
00226 entryList->setFocus();
00227 }
00228
00229 void KSpreadList::slotRemove()
00230 {
00231 if(list->currentItem()==-1)
00232 return;
00233
00234 if(list->currentItem()<2)
00235 return;
00236 int ret = KMessageBox::warningContinueCancel( this, i18n("Do you really want to remove this list?"),i18n("Remove List"),KGuiItem(i18n("&Delete"),"editdelete"));
00237 if(ret==Cancel)
00238 return;
00239 list->removeItem(list->currentItem ());
00240 entryList->setEnabled(false);
00241 entryList->setText("");
00242 if(list->count()<=2)
00243 m_pRemove->setEnabled(false);
00244 m_bChanged=true;
00245 }
00246
00247 void KSpreadList::slotOk()
00248 {
00249 if(!entryList->text().isEmpty())
00250 {
00251 int ret = KMessageBox::warningYesNo( this, i18n("Entry area is not empty.\nDo you want to continue?"));
00252 if(ret==4)
00253 return;
00254 }
00255 if(m_bChanged)
00256 {
00257 QStringList result;
00258 result.append("\\");
00259
00260
00261 for(unsigned int i=2;i<list->count();i++)
00262 {
00263 QStringList tmp=result.split(", ",list->text(i));
00264 if ( !tmp.isEmpty() )
00265 {
00266 result+=tmp;
00267 result+="\\";
00268 }
00269 }
00270 config->setGroup( "Parameters" );
00271 config->writeEntry("Other list",result);
00272
00273
00274 if(AutoFillSequenceItem::other!=0L)
00275 {
00276 delete(AutoFillSequenceItem::other);
00277 AutoFillSequenceItem::other=0L;
00278 }
00279 }
00280 accept();
00281 }
00282
00283 void KSpreadList::slotModify()
00284 {
00285
00286 if(list->currentItem ()>1 && !entryList->text().isEmpty())
00287 {
00288 QString tmp;
00289 for(int i=0;i<entryList->numLines();i++)
00290 {
00291 if(!entryList->textLine(i).isEmpty())
00292 {
00293 if(tmp.isEmpty())
00294 tmp=entryList->textLine(i);
00295 else
00296 tmp+=", "+entryList->textLine(i);
00297 }
00298 }
00299 list->insertItem(tmp,list->currentItem());
00300 list->removeItem(list->currentItem());
00301
00302
00303 entryList->setText("");
00304 m_bChanged=true;
00305
00306 }
00307 entryList->setEnabled(false);
00308 m_pModify->setEnabled(false);
00309
00310 }
00311
00312 void KSpreadList::slotCopy()
00313 {
00314 if(list->currentItem()!=-1)
00315 {
00316 list->insertItem(list->currentText(),list->count());
00317 }
00318 }
00319
00320
00321 #include "kspread_dlg_list.moc"