kspread

kspread_dlg_area.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002-2003 Norbert Andres <nandres@web.de>
3 (C) 2002 Philipp Mueller <philipp.mueller@gmx.de>
4 (C) 2002 John Dailey <dailey@vt.edu>
5 (C) 1999-2001 Laurent Montel <montel@kde.org>
6 (C) 1998-1999 Torben Weis <weis@kde.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#include <tqlayout.h>
25#include <tqlabel.h>
26#include <tqlineedit.h>
27
28#include <tdemessagebox.h>
29
30#include "kspread_doc.h"
31#include "kspread_locale.h"
32#include "kspread_sheet.h"
33#include "kspread_view.h"
34#include "selection.h"
35
36#include "kspread_dlg_area.h"
37
38using namespace KSpread;
39
40AreaDialog::AreaDialog( View * parent, const char * name, const TQPoint & _marker )
41 : KDialogBase( parent, name, true, i18n("Area Name"), Ok | Cancel )
42{
43 m_pView = parent;
44 m_marker = _marker;
45
46 TQWidget * page = new TQWidget( this );
47 setMainWidget(page);
48 TQVBoxLayout * lay1 = new TQVBoxLayout( page, 0, spacingHint() );
49
50 TQLabel * label = new TQLabel( i18n("Enter the area name:"), page );
51 lay1->addWidget( label );
52
53 m_areaName = new TQLineEdit(page);
54 m_areaName->setMinimumWidth( m_areaName->sizeHint().width() * 3 );
55
56 lay1->addWidget( m_areaName );
57 m_areaName->setFocus();
58 connect ( m_areaName, TQ_SIGNAL(textChanged ( const TQString & )), this, TQ_SLOT(slotAreaNamechanged( const TQString &)));
59 connect( this, TQ_SIGNAL( okClicked() ), this, TQ_SLOT( slotOk() ) );
60 enableButtonOK(!m_areaName->text().isEmpty());
61
62}
63
64void AreaDialog::slotAreaNamechanged( const TQString & text)
65{
66 enableButtonOK(!text.isEmpty());
67}
68
69void AreaDialog::slotOk()
70{
71 TQString tmp(m_areaName->text());
72 if( !tmp.isEmpty() )
73 {
74 tmp = tmp.lower();
75
76 TQRect rect( m_pView->selectionInfo()->selection() );
77 bool newName = true;
78 TQValueList<Reference>::Iterator it;
79 TQValueList<Reference> area = m_pView->doc()->listArea();
80 for ( it = area.begin(); it != area.end(); ++it )
81 {
82 if(tmp == (*it).ref_name)
83 newName = false;
84 }
85 if (newName)
86 {
87 m_pView->doc()->emitBeginOperation( false );
88 m_pView->doc()->addAreaName(rect, tmp, m_pView->activeSheet()->sheetName());
89 m_pView->slotUpdateView( m_pView->activeSheet() );
90 accept();
91 }
92 else
93 KMessageBox::error( this, i18n("This name is already used."));
94 }
95 else
96 {
97 KMessageBox::error( this, i18n("Area text is empty.") );
98 }
99}
100
101#include "kspread_dlg_area.moc"
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39