kspread

kspread_dlg_area.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
00003              (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
00004              (C) 2002 John Dailey <dailey@vt.edu>
00005              (C) 1999-2001 Laurent Montel <montel@kde.org>
00006              (C) 1998-1999 Torben Weis <weis@kde.org>
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public License
00019    along with this library; see the file COPYING.LIB.  If not, write to
00020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qlineedit.h>
00027 
00028 #include <kmessagebox.h>
00029 
00030 #include "kspread_doc.h"
00031 #include "kspread_locale.h"
00032 #include "kspread_sheet.h"
00033 #include "kspread_view.h"
00034 #include "selection.h"
00035 
00036 #include "kspread_dlg_area.h"
00037 
00038 using namespace KSpread;
00039 
00040 AreaDialog::AreaDialog( View * parent, const char * name, const QPoint & _marker )
00041   : KDialogBase( parent, name, TRUE, i18n("Area Name"), Ok | Cancel )
00042 {
00043   m_pView  = parent;
00044   m_marker = _marker;
00045 
00046   QWidget * page = new QWidget( this );
00047   setMainWidget(page);
00048   QVBoxLayout * lay1 = new QVBoxLayout( page, 0, spacingHint() );
00049 
00050   QLabel * label = new QLabel( i18n("Enter the area name:"), page );
00051   lay1->addWidget( label );
00052 
00053   m_areaName = new QLineEdit(page);
00054   m_areaName->setMinimumWidth( m_areaName->sizeHint().width() * 3 );
00055 
00056   lay1->addWidget( m_areaName );
00057   m_areaName->setFocus();
00058   connect ( m_areaName, SIGNAL(textChanged ( const QString & )), this, SLOT(slotAreaNamechanged( const QString &)));
00059   connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00060   enableButtonOK(!m_areaName->text().isEmpty());
00061 
00062 }
00063 
00064 void AreaDialog::slotAreaNamechanged( const QString & text)
00065 {
00066   enableButtonOK(!text.isEmpty());
00067 }
00068 
00069 void AreaDialog::slotOk()
00070 {
00071   QString tmp(m_areaName->text());
00072   if( !tmp.isEmpty() )
00073   {
00074     tmp = tmp.lower();
00075 
00076     QRect rect( m_pView->selectionInfo()->selection() );
00077     bool newName = true;
00078     QValueList<Reference>::Iterator it;
00079     QValueList<Reference> area = m_pView->doc()->listArea();
00080     for ( it = area.begin(); it != area.end(); ++it )
00081     {
00082       if(tmp == (*it).ref_name)
00083         newName = false;
00084     }
00085     if (newName)
00086     {
00087       m_pView->doc()->emitBeginOperation( false );
00088       m_pView->doc()->addAreaName(rect, tmp, m_pView->activeSheet()->sheetName());
00089       m_pView->slotUpdateView( m_pView->activeSheet() );
00090       accept();
00091     }
00092     else
00093       KMessageBox::error( this, i18n("This name is already used."));
00094   }
00095   else
00096   {
00097     KMessageBox::error( this, i18n("Area text is empty.") );
00098   }
00099 }
00100 
00101 #include "kspread_dlg_area.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys