You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
322 lines
8.5 KiB
322 lines
8.5 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2002-2003 Ariya Hidayat <ariya@kde.org>
|
||
|
(C) 2001-2003 Laurent Montel <montel@kde.org>
|
||
|
(C) 1998, 1999 Torben Weis <weis@kde.org>
|
||
|
|
||
|
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.
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqlineedit.h>
|
||
|
#include <tqlistbox.h>
|
||
|
#include <tqmultilineedit.h>
|
||
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
|
#include <kbuttonbox.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
|
||
|
#include "kspread_autofill.h"
|
||
|
#include "kspread_factory.h"
|
||
|
#include "kspread_locale.h"
|
||
|
|
||
|
#include "kspread_dlg_list.h"
|
||
|
|
||
|
using namespace KSpread;
|
||
|
|
||
14 years ago
|
ListDialog::ListDialog( TQWidget* parent, const char* name )
|
||
|
: KDialogBase( parent, name, true, i18n("Custom Lists"), Ok|Cancel )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQWidget* page = new TQWidget( this );
|
||
15 years ago
|
setMainWidget( page );
|
||
|
|
||
14 years ago
|
TQGridLayout *grid1 = new TQGridLayout( page,10,3,KDialog::marginHint(), KDialog::spacingHint());
|
||
15 years ago
|
|
||
14 years ago
|
TQLabel *lab=new TQLabel(page);
|
||
15 years ago
|
lab->setText(i18n("List:" ));
|
||
|
grid1->addWidget(lab,0,0);
|
||
|
|
||
14 years ago
|
list=new TQListBox(page);
|
||
15 years ago
|
grid1->addMultiCellWidget(list,1,8,0,0);
|
||
|
|
||
|
|
||
14 years ago
|
lab=new TQLabel(page);
|
||
15 years ago
|
lab->setText(i18n("Entry:" ));
|
||
|
grid1->addWidget(lab,0,1);
|
||
|
|
||
14 years ago
|
entryList=new TQMultiLineEdit(page);
|
||
15 years ago
|
grid1->addMultiCellWidget(entryList,1,8,1,1);
|
||
|
|
||
14 years ago
|
m_pRemove=new TQPushButton(i18n("&Remove"),page);
|
||
15 years ago
|
grid1->addWidget(m_pRemove,3,2);
|
||
|
|
||
14 years ago
|
m_pAdd=new TQPushButton(i18n("&Add"),page);
|
||
15 years ago
|
grid1->addWidget(m_pAdd,1,2);
|
||
|
|
||
14 years ago
|
m_pNew=new TQPushButton(i18n("&New"),page);
|
||
15 years ago
|
grid1->addWidget(m_pNew,2,2);
|
||
|
|
||
14 years ago
|
m_pModify=new TQPushButton(i18n("&Modify"),page);
|
||
15 years ago
|
grid1->addWidget(m_pModify,4,2);
|
||
|
|
||
14 years ago
|
m_pCopy=new TQPushButton(i18n("Co&py"),page);
|
||
15 years ago
|
grid1->addWidget(m_pCopy,5,2);
|
||
|
|
||
|
m_pAdd->setEnabled(false);
|
||
|
|
||
14 years ago
|
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 * )));
|
||
15 years ago
|
init();
|
||
|
entryList->setEnabled(false);
|
||
|
m_pModify->setEnabled(false);
|
||
|
if(list->count()<=2)
|
||
|
m_pRemove->setEnabled(false);
|
||
|
resize( 600, 250 );
|
||
|
m_bChanged=false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void ListDialog::slotTextClicked(TQListBoxItem*)
|
||
15 years ago
|
{
|
||
|
//we can't remove the two first item
|
||
|
bool state=list->currentItem()>1;
|
||
|
m_pRemove->setEnabled(state);
|
||
|
m_pModify->setEnabled(state);
|
||
|
|
||
|
}
|
||
|
|
||
|
void ListDialog::init()
|
||
|
{
|
||
14 years ago
|
TQString month;
|
||
15 years ago
|
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");
|
||
14 years ago
|
TQStringList lst;
|
||
15 years ago
|
lst.append(month);
|
||
|
|
||
14 years ago
|
TQString smonth;
|
||
15 years ago
|
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);
|
||
|
|
||
14 years ago
|
TQString day=i18n("Monday")+", ";
|
||
15 years ago
|
day+=i18n("Tuesday")+", ";
|
||
|
day+=i18n("Wednesday")+", ";
|
||
|
day+=i18n("Thursday")+", ";
|
||
|
day+=i18n("Friday")+", ";
|
||
|
day+=i18n("Saturday")+", ";
|
||
|
day+=i18n("Sunday");
|
||
|
lst.append(day);
|
||
|
|
||
14 years ago
|
TQString sday=i18n("Mon")+", ";
|
||
15 years ago
|
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" );
|
||
14 years ago
|
TQStringList other=config->readListEntry("Other list");
|
||
|
TQString tmp;
|
||
|
for ( TQStringList::Iterator it = other.begin(); it != other.end();++it )
|
||
15 years ago
|
{
|
||
|
if((*it)!="\\")
|
||
|
tmp+=(*it)+", ";
|
||
|
else if( it!=other.begin())
|
||
|
{
|
||
|
tmp=tmp.left(tmp.length()-2);
|
||
|
lst.append(tmp);
|
||
|
tmp="";
|
||
|
}
|
||
|
}
|
||
|
list->insertStringList(lst);
|
||
|
}
|
||
|
|
||
14 years ago
|
void ListDialog::slotDoubleClicked(TQListBoxItem *)
|
||
15 years ago
|
{
|
||
|
//we can't modify the two first item
|
||
|
if(list->currentItem()<2)
|
||
|
return;
|
||
14 years ago
|
TQString tmp=list->currentText();
|
||
15 years ago
|
entryList->setText("");
|
||
14 years ago
|
TQStringList result=result.split(", ",tmp);
|
||
15 years ago
|
int index=0;
|
||
14 years ago
|
for ( TQStringList::Iterator it = result.begin(); it != result.end();++it )
|
||
15 years ago
|
{
|
||
|
entryList->insertLine((*it),index);
|
||
|
index++;
|
||
|
}
|
||
|
entryList->setEnabled(true);
|
||
|
m_pModify->setEnabled(true);
|
||
|
}
|
||
|
|
||
|
void ListDialog::slotAdd()
|
||
|
{
|
||
|
m_pAdd->setEnabled(false);
|
||
|
list->setEnabled(true);
|
||
14 years ago
|
TQString tmp;
|
||
15 years ago
|
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)
|
||
|
{
|
||
14 years ago
|
TQStringList result;
|
||
15 years ago
|
result.append("\\");
|
||
|
|
||
|
//don't save the two first line
|
||
|
for(unsigned int i=2;i<list->count();i++)
|
||
|
{
|
||
14 years ago
|
TQStringList tmp=result.split(", ",list->text(i));
|
||
15 years ago
|
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())
|
||
|
{
|
||
14 years ago
|
TQString tmp;
|
||
15 years ago
|
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"
|