26#include <tqcombobox.h>
30#include <tqpushbutton.h>
32#include <kbuttonbox.h>
33#include <tdemessagebox.h>
34#include <kstandarddirs.h>
35#include <ksimpleconfig.h>
37#include "kspread_dlg_format.h"
38#include "kspread_doc.h"
39#include "kspread_locale.h"
40#include "kspread_sheet.h"
41#include "kspread_style.h"
42#include "kspread_style_manager.h"
43#include "kspread_undo.h"
44#include "kspread_view.h"
50FormatDialog::FormatDialog(
View* view,
const char* name )
51 : KDialogBase( view, name, true,i18n(
"Sheet Style"),Ok|Cancel )
53 for(
int i = 0; i < 16; ++i )
57 TQWidget *page =
new TQWidget(
this );
59 TQVBoxLayout *vbox =
new TQVBoxLayout( page, 0, spacingHint() );
61 TQLabel *toplabel =
new TQLabel( i18n(
"Select the sheet style to apply:"), page );
62 m_combo =
new TQComboBox( page );
63 m_label =
new TQLabel( page );
65 vbox->addWidget( toplabel );
66 vbox->addWidget( m_combo );
67 vbox->addWidget( m_label );
70 TQStringList lst = Factory::global()->dirs()->findAllResources(
"sheet-styles",
"*.ksts",
true );
72 TQStringList::Iterator it = lst.begin();
73 for( ; it != lst.end(); ++it )
75 KSimpleConfig cfg( *it,
true );
76 cfg.setGroup(
"Sheet-Style" );
80 e.xml = cfg.readEntry(
"XML" );
81 e.image = cfg.readEntry(
"Image" );
82 e.name = cfg.readEntry(
"Name" );
84 m_entries.append( e );
86 m_combo->insertItem( e.name );
91 connect(
this, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( slotOk() ) );
92 connect( m_combo, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( slotActivated(
int ) ) );
95FormatDialog::~FormatDialog()
97 for(
int i = 0; i < 16; ++i )
101void FormatDialog::slotActivated(
int index )
103 enableButtonOK(
true);
105 TQString img = Factory::global()->dirs()->findResource(
"sheet-styles", m_entries[ index ].image );
108 TQString str( i18n(
"Could not find image %1." ) );
109 str = str.arg( m_entries[ index ].image );
110 KMessageBox::error(
this, str );
112 enableButtonOK(
false);
120 TQString str( i18n(
"Could not load image %1." ) );
121 str = str.arg( img );
122 KMessageBox::error(
this,str );
124 enableButtonOK(
false);
129 m_label->setPixmap( pix );
132void FormatDialog::slotOk()
137 TQString xml = Factory::global()->dirs()->findResource(
"sheet-styles", m_entries[ m_combo->currentItem() ].xml );
140 TQString str( i18n(
"Could not find sheet-style XML file '%1'." ) );
141 str = str.arg( m_entries[ m_combo->currentItem() ].xml );
142 KMessageBox::error(
this, str );
147 file.open( IO_ReadOnly );
149 doc.setContent( &file );
152 if ( !parseXML( doc ) )
154 TQString str( i18n(
"Parsing error in sheet-style XML file %1." ) );
155 str = str.arg( m_entries[ m_combo->currentItem() ].xml );
156 KMessageBox::error(
this, str );
160 TQRect r = m_view->selectionInfo()->selection();
164 TQString title=i18n(
"Change Format");
165 UndoCellFormat *undo =
new UndoCellFormat( m_view->doc(), m_view->activeSheet(), r, title);
173 Cell* cell = m_view->activeSheet()->nonDefaultCell( r.left(), r.top() );
174 cell->
format()->copy( *m_cells[0] );
178 for( x = r.left() + 1; x <= r.right(); ++x )
180 int pos = 1 + ( ( x - r.left() - 1 ) % 2 );
181 Cell* cell = m_view->activeSheet()->nonDefaultCell( x, r.top() );
184 cell->
format()->copy( *m_cells[ pos ] );
187 if ( x == r.right() )
195 if ( x == r.left() + 1 )
205 cell = m_view->activeSheet()->nonDefaultCell( r.right(), r.top() );
210 for( y = r.top() + 1; y <= r.bottom(); ++y )
212 int pos = 4 + ( ( y - r.top() - 1 ) % 2 ) * 4;
213 Cell* cell = m_view->activeSheet()->nonDefaultCell( r.left(), y );
216 cell->
format()->copy( *m_cells[ pos ] );
219 if ( y == r.bottom() )
227 if ( y == r.top() + 1 )
238 for( x = r.left() + 1; x <= r.right(); ++x )
239 for( y = r.top() + 1; y <= r.bottom(); ++y )
241 int pos = 5 + ( ( y - r.top() - 1 ) % 2 ) * 4 + ( ( x - r.left() - 1 ) % 2 );
242 Cell* cell = m_view->activeSheet()->nonDefaultCell( x, y );
245 cell->
format()->copy( *m_cells[ pos ] );
248 if ( x == r.left() + 1 )
249 c = m_cells[ 5 + ( ( y - r.top() - 1 ) % 2 ) * 4 ];
251 c = m_cells[ 6 + ( ( y - r.top() - 1 ) % 2 ) * 4 ];
256 if ( y == r.top() + 1 )
257 c = m_cells[ 5 + ( ( x - r.left() - 1 ) % 2 ) ];
259 c = m_cells[ 9 + ( ( x - r.left() - 1 ) % 2 ) ];
267 for( y = r.top(); y <= r.bottom(); ++y )
269 Cell* cell = m_view->activeSheet()->nonDefaultCell( r.right(), y );
277 else if ( y == r.right() )
291 for( x = r.left(); x <= r.right(); ++x )
293 Cell* cell = m_view->activeSheet()->nonDefaultCell( x, r.bottom() );
301 else if ( x == r.right() )
314 m_view->selectionInfo()->initialize(r);
315 m_view->doc()->setModified(
true );
316 m_view->slotUpdateView( m_view->activeSheet() );
320bool FormatDialog::parseXML(
const TQDomDocument& doc )
322 for(
int i = 0; i < 16; ++i )
328 TQDomElement e = doc.documentElement().firstChild().toElement();
329 for( ; !e.isNull(); e = e.nextSibling().toElement() )
331 if ( e.tagName() ==
"cell" )
333 Sheet* sheet = m_view->activeSheet();
334 Format* cell =
new Format( sheet, sheet->doc()->styleManager()->defaultStyle() );
336 if ( !cell->load( e.namedItem(
"format").toElement(),
Paste::Normal ) )
339 int row = e.attribute(
"row").toInt();
340 int column = e.attribute(
"column").toInt();
341 int i = (row-1)*4 + (column-1);
342 if ( i < 0 || i >= 16 )
352#include "kspread_dlg_format.moc"
For every cell in the spread sheet there is a Cell object.
void setRightBorderPen(const TQPen &p)
void setTopBorderPen(const TQPen &p)
Format * format() const
Returns the format object of this cell.
void setBottomBorderPen(const TQPen &p)
bool isPartOfMerged() const
If this cell is part of a merged cell, then the marker may never reside on this cell.
void setLeftBorderPen(const TQPen &p)
bool undoLocked() const
Returns true if undo buffer is locked.
void emitBeginOperation(bool waitCursor)
Functions to begin a kspread 'operation'.
void addCommand(KCommand *command)
Adds a command to the command history.
The View class displays a KSpread document.