28#include "kspread_dlg_reference.h"
29#include "kspread_canvas.h"
30#include "kspread_doc.h"
31#include "kspread_util.h"
32#include "kspread_map.h"
33#include "kspread_view.h"
34#include "kspread_sheet.h"
36#include "kspread_locale.h"
39#include <tqcombobox.h>
41#include <tqlineedit.h>
42#include <tqpushbutton.h>
45#include <kbuttonbox.h>
46#include <tdemessagebox.h>
49#include <kstdguiitem.h>
53reference::reference(
View* parent,
const char* name )
54 : TQDialog( parent, name,true )
57 TQVBoxLayout *lay1 =
new TQVBoxLayout(
this );
58 lay1->setMargin( KDialog::marginHint() );
59 lay1->setSpacing( KDialog::spacingHint() );
60 m_list =
new TQListBox(
this);
61 lay1->addWidget( m_list );
63 setCaption( i18n(
"Area Name") );
65 m_rangeName =
new TQLabel(
this);
66 lay1->addWidget(m_rangeName);
68 m_pRemove =
new TQPushButton(i18n(
"&Remove"),
this);
69 lay1->addWidget( m_pRemove );
71 KButtonBox *bb =
new KButtonBox(
this );
73 m_pEdit = bb->addButton( i18n(
"&Edit...") );
74 m_pOk = bb->addButton( KStdGuiItem::ok() );
75 m_pCancel = bb->addButton( KStdGuiItem::cancel() );
76 m_pOk->setDefault(
true );
78 lay1->addWidget( bb );
81 TQStringList sheetName;
82 TQPtrListIterator<Sheet> it2 ( m_pView->doc()->map()->sheetList() );
83 for( ; it2.current(); ++it2 )
85 sheetName.append( it2.current()->sheetName());
88 TQValueList<Reference>::Iterator it;
89 TQValueList<Reference> area = m_pView->doc()->listArea();
90 for ( it = area.begin(); it != area.end(); ++it )
92 text = (*it).ref_name;
93 if ( sheetName.contains((*it).sheet_name ))
94 m_list->insertItem(text);
97 if ( !m_list->count() )
99 m_pOk->setEnabled(
false );
100 m_pRemove->setEnabled(
false );
101 m_pEdit->setEnabled(
false );
104 connect( m_pOk, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotOk() ) );
105 connect( m_pCancel, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotCancel() ) );
106 connect( m_pEdit, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotEdit() ) );
107 connect( m_pRemove, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotRemove() ) );
108 connect( m_list, TQ_SIGNAL(doubleClicked(TQListBoxItem *)),
this,
109 TQ_SLOT(slotDoubleClicked(TQListBoxItem *)));
110 connect( m_list, TQ_SIGNAL(highlighted ( TQListBoxItem * ) ),
this,
111 TQ_SLOT(slotHighlighted(TQListBoxItem * )));
112 m_rangeName->setText(i18n(
"Area: %1").arg(
""));
117void reference::displayAreaValues(TQString
const & areaName)
120 TQValueList<Reference>::Iterator it;
121 TQValueList<Reference> area( m_pView->doc()->listArea() );
122 for ( it = area.begin(); it != area.end(); ++it )
124 if ((*it).ref_name == areaName)
126 if (!m_pView->doc()->map()->findSheet( (*it).sheet_name))
127 kdDebug(36001) <<
"(*it).table_name '" << (*it).sheet_name
128 <<
"' not found!*********" << endl;
130 tmpName = util_rangeName(m_pView->doc()->map()->findSheet( (*it).sheet_name),
136 tmpName = i18n(
"Area: %1").arg(tmpName);
137 m_rangeName->setText(tmpName);
140void reference::slotHighlighted(TQListBoxItem * )
142 TQString tmp = m_list->text(m_list->currentItem());
143 displayAreaValues(tmp);
146void reference::slotDoubleClicked(TQListBoxItem *)
151void reference::slotRemove()
153 if (m_list->currentItem() == -1)
156 int ret = KMessageBox::warningContinueCancel(
this, i18n(
"Do you really want to remove this area name?"),i18n(
"Remove Area"),KStdGuiItem::del());
157 if (ret == KMessageBox::Cancel)
161 if ( m_list->currentItem() != -1)
163 m_pView->doc()->emitBeginOperation(
false );
165 TQString textRemove = m_list->text(m_list->currentItem());
166 m_pView->doc()->removeArea(textRemove );
167 m_pView->doc()->setModified(
true);
180 m_list->removeItem(m_list->currentItem());
184 for ( tbl = m_pView->doc()->map()->firstSheet(); tbl != 0L; tbl = m_pView->doc()->map()->nextSheet() )
186 tbl->refreshRemoveAreaName(textRemove);
189 m_pView->slotUpdateView( m_pView->activeSheet() );
192 if ( !m_list->count() )
194 m_pOk->setEnabled(
false );
195 m_pRemove->setEnabled(
false );
196 m_pEdit->setEnabled(
false );
200void reference::slotEdit()
202 TQString name(m_list->text(m_list->currentItem()));
203 if ( name.isEmpty() )
205 EditAreaName editDlg( m_pView,
"EditArea", name );
208 m_rangeName->setText(i18n(
"Area: %1").arg(
""));
209 TQString tmp = m_list->text(m_list->currentItem());
211 displayAreaValues( tmp );
214void reference::slotOk()
216 m_pView->doc()->emitBeginOperation(
false );
219 if (m_list->currentItem() != -1)
221 int index = m_list->currentItem();
222 text = m_list->text(index);
223 TQValueList<Reference> area = m_pView->doc()->listArea();
225 if (m_pView->activeSheet()->sheetName() != area[ index ].sheet_name)
227 Sheet *sheet = m_pView->doc()->map()->
findSheet(area[ index ].sheet_name);
229 m_pView->setActiveSheet(sheet);
232 Region region(m_pView,
Cell::fullName(m_pView->activeSheet(), area[index].rect.left(), area[index].rect.top()));
233 m_pView->selectionInfo()->initialize(region);
234 m_pView->selectionInfo()->initialize(area[ index ].rect);
237 m_pView->slotUpdateView( m_pView->activeSheet() );
241void reference::slotCancel()
248EditAreaName::EditAreaName(
View * parent,
250 TQString
const & areaname )
251 : KDialogBase( parent, name ,true,i18n(
"Edit Area" ) , Ok|Cancel )
256 setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)5,
257 (TQSizePolicy::SizeType)4, 0, 0,
258 sizePolicy().hasHeightForWidth() ) );
260 TQWidget * page =
new TQWidget(
this );
263 TQGridLayout * EditAreaNameLayout
264 =
new TQGridLayout( page, 1, 1, 11, 6,
"EditAreaNameLayout");
266 TQHBoxLayout * Layout1 =
new TQHBoxLayout( 0, 0, 6,
"Layout1");
267 TQSpacerItem * spacer =
new TQSpacerItem( 0, 0, TQSizePolicy::Expanding,
268 TQSizePolicy::Minimum );
269 Layout1->addItem( spacer );
271 EditAreaNameLayout->addMultiCellLayout( Layout1, 3, 3, 0, 1 );
273 TQLabel * TextLabel4 =
new TQLabel( page,
"TextLabel4" );
274 TextLabel4->setText( i18n(
"Cells:" ) );
276 EditAreaNameLayout->addWidget( TextLabel4, 2, 0 );
278 m_area =
new TQLineEdit( page,
"m_area" );
280 EditAreaNameLayout->addWidget( m_area, 2, 1 );
282 TQLabel * TextLabel1 =
new TQLabel( page,
"TextLabel1" );
283 TextLabel1->setText( i18n(
"Sheet:" ) );
285 EditAreaNameLayout->addWidget( TextLabel1, 1, 0 );
287 m_sheets =
new TQComboBox(
false, page,
"m_sheets" );
289 EditAreaNameLayout->addWidget( m_sheets, 1, 1 );
291 TQLabel * TextLabel2 =
new TQLabel( page,
"TextLabel2" );
292 TextLabel2->setText( i18n(
"Area name:" ) );
294 EditAreaNameLayout->addWidget( TextLabel2, 0, 0 );
296 m_areaName =
new TQLabel( page,
"m_areaName" );
297 m_areaName->setText( areaname );
299 EditAreaNameLayout->addWidget( m_areaName, 0, 1 );
301 TQPtrList<Sheet> sheetList = m_pView->doc()->map()->sheetList();
302 for (
unsigned int c = 0; c < sheetList.count(); ++c)
304 Sheet * t = sheetList.at(c);
307 m_sheets->insertItem( t->sheetName() );
311 TQValueList<Reference>::Iterator it;
312 TQValueList<Reference> area(m_pView->doc()->listArea());
313 for ( it = area.begin(); it != area.end(); ++it )
315 if ((*it).ref_name == areaname)
317 if (!m_pView->doc()->map()->findSheet( (*it).sheet_name))
318 kdDebug(36001) <<
"(*it).table_name '" << (*it).sheet_name
319 <<
"' not found!*********" << endl;
321 tmpName = util_rangeName( (*it).rect );
326 m_sheets->setCurrentText( (*it).sheet_name );
327 m_area->setText( tmpName );
331EditAreaName::~EditAreaName()
335void EditAreaName::slotOk()
337 Range range( m_area->text() );
339 if ( !range.isValid() )
341 Point point( m_area->text() );
342 if ( !point.isValid() )
345 m_area->setText( m_area->text() +
":" + m_area->text() );
347 range = Range( m_area->text() );
350 m_pView->doc()->emitBeginOperation(
false );
352 m_pView->doc()->removeArea( m_areaName->text() );
353 m_pView->doc()->addAreaName(range.range(), m_areaName->text(), m_sheets->currentText() );
357 for ( sheet = m_pView->doc()->map()->firstSheet(); sheet != 0L;
358 sheet = m_pView->doc()->map()->nextSheet() )
360 sheet->refreshChangeAreaName( m_areaName->text() );
363 m_pView->slotUpdateView( m_pView->activeSheet() );
367#include "kspread_dlg_reference.moc"
TQString fullName() const
Returns the full name of the cell, i.e.
Sheet * findSheet(const TQString &_name)
searches for a sheet named _name
The View class displays a KSpread document.