summaryrefslogtreecommitdiff
authorthufir <thufir>2002-07-04 16:58:16 (UTC)
committer thufir <thufir>2002-07-04 16:58:16 (UTC)
commitd2b982a38091cbc7cd4eba0994ab6c5e3c7f7189 (patch) (unidiff)
treed1e0a5fa80a12717b46257936ee3f8bb1b3ef89e
parenta53847b7d27938551bb4f1c8891e7bacc93143ee (diff)
downloadopie-d2b982a38091cbc7cd4eba0994ab6c5e3c7f7189.zip
opie-d2b982a38091cbc7cd4eba0994ab6c5e3c7f7189.tar.gz
opie-d2b982a38091cbc7cd4eba0994ab6c5e3c7f7189.tar.bz2
added opie-sheet
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/cell-select.xpm23
-rw-r--r--noncore/apps/opie-sheet/cellformat.cpp585
-rw-r--r--noncore/apps/opie-sheet/cellformat.h106
-rw-r--r--noncore/apps/opie-sheet/edit-accept.xpm30
-rw-r--r--noncore/apps/opie-sheet/edit-cancel.xpm25
-rw-r--r--noncore/apps/opie-sheet/file-new.xpm24
-rw-r--r--noncore/apps/opie-sheet/file-open.xpm25
-rw-r--r--noncore/apps/opie-sheet/file-save.xpm24
-rw-r--r--noncore/apps/opie-sheet/finddlg.cpp70
-rw-r--r--noncore/apps/opie-sheet/finddlg.h35
-rw-r--r--noncore/apps/opie-sheet/func-comma.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-cross.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-divide.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-equal.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-func.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-minus.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-paran-close.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-paran-open.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-plus.xpm21
-rw-r--r--noncore/apps/opie-sheet/help-general.xpm25
-rw-r--r--noncore/apps/opie-sheet/main.cpp14
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp836
-rw-r--r--noncore/apps/opie-sheet/mainwindow.h120
-rw-r--r--noncore/apps/opie-sheet/numberdlg.cpp35
-rw-r--r--noncore/apps/opie-sheet/numberdlg.h24
-rw-r--r--noncore/apps/opie-sheet/opie-sheet.control10
-rw-r--r--noncore/apps/opie-sheet/opie-sheet.pro9
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp849
-rw-r--r--noncore/apps/opie-sheet/sheet.h120
-rw-r--r--noncore/apps/opie-sheet/sortdlg.cpp178
-rw-r--r--noncore/apps/opie-sheet/sortdlg.h45
-rw-r--r--noncore/apps/opie-sheet/textdlg.cpp32
-rw-r--r--noncore/apps/opie-sheet/textdlg.h24
-rw-r--r--pics/opie-sheet/sheetqt.pngbin0 -> 2105 bytes
34 files changed, 3457 insertions, 0 deletions
diff --git a/noncore/apps/opie-sheet/cell-select.xpm b/noncore/apps/opie-sheet/cell-select.xpm
new file mode 100644
index 0000000..2b0ab7e
--- a/dev/null
+++ b/noncore/apps/opie-sheet/cell-select.xpm
@@ -0,0 +1,23 @@
1/* XPM */
2static const char * cell_select_xpm[] = {
3"16 16 4 1",
4 " c None",
5 ".c #000000",
6 "+c #FFFFFF",
7 "@c #BEBEBE",
8". ",
9". ... ",
10" ... .+++. ",
11" ..+@+++. ",
12" .+++@++@. ",
13" .+@+++@@++. ",
14" .@++@++@+++. ",
15" .@@++@@+++++. ",
16" .++@+@+++++++. ",
17" .++@++++++++. ",
18" .++@+++++++. ",
19" .++@+++++@. ",
20" .++@+++@+. ",
21" .++@@@+. ",
22" .++++. ",
23" .... "};
diff --git a/noncore/apps/opie-sheet/cellformat.cpp b/noncore/apps/opie-sheet/cellformat.cpp
new file mode 100644
index 0000000..6a2ff72
--- a/dev/null
+++ b/noncore/apps/opie-sheet/cellformat.cpp
@@ -0,0 +1,585 @@
1#include "cellformat.h"
2
3#include <qlistbox.h>
4#include <qlabel.h>
5
6#define COMBO_WIDTHS 155
7#define COMBO_HEIGHTS 21
8
9#define COLOR_COUNT 17
10#define STYLE_COUNT 14
11#define HALIGN_COUNT 3
12#define VALIGN_COUNT 3
13
14QColor qtColors[COLOR_COUNT]={Qt::black, Qt::white, Qt::darkGray, Qt::gray, Qt::lightGray, Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow, Qt::darkRed, Qt::darkGreen, Qt::darkBlue, Qt::darkCyan, Qt::darkMagenta, Qt::darkYellow};
15Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern, Qt::Dense1Pattern, Qt::Dense2Pattern, Qt::Dense3Pattern, Qt::Dense4Pattern, Qt::Dense5Pattern, Qt::Dense6Pattern, Qt::Dense7Pattern, Qt::HorPattern, Qt::VerPattern, Qt::CrossPattern, Qt::BDiagPattern, Qt::FDiagPattern, Qt::DiagCrossPattern};
16QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"};
17QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"};
18Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter};
19Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, Qt::AlignBottom, Qt::AlignVCenter};
20
21CellFormat::CellFormat(QWidget *parent=0)
22 :QDialog(parent, 0, TRUE)
23{
24 // Main widget
25 tabs=new QTabWidget(this);
26 widgetBorders=new QWidget(tabs);
27 widgetBackground=new QWidget(tabs);
28 widgetFont=new QWidget(tabs);
29 widgetAlignment=new QWidget(tabs);
30 tabs->addTab(widgetBorders, tr("&Borders"));
31 tabs->addTab(widgetBackground, tr("Back&ground"));
32 tabs->addTab(widgetFont, tr("&Font"));
33 tabs->addTab(widgetAlignment, tr("&Alignment"));
34
35 fontDB.loadRenderers();
36 changedFont=changedAlign=changedBrush=FALSE;
37
38 // Borders tab
39 borderEditor=new BorderEditor(widgetBorders);
40 borderEditor->setGeometry(10, 10, 215, 145);
41 connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), this, SLOT(borderClicked(BorderEditor::BorderArea)));
42
43 comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165);
44 comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
45
46 buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders);
47 buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
48 connect(buttonBordersDefaults, SIGNAL(clicked()), this, SLOT(slotBordersDefaults()));
49
50 // Background tab
51 frameBackground=new QFrame(widgetBackground);
52 frameBackground->setGeometry(10, 10, 215, 145);
53 frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
54
55 comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165);
56 connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
57 comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
58 connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
59
60 buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground);
61 buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
62 connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults()));
63
64 // Font tab
65 frameFont=new QFrame(widgetFont);
66 frameFont->setGeometry(10, 10, 215, 125);
67 frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
68
69 comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145);
70 connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
71 comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10));
72 connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
73 comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10));
74 connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
75
76 checkFontBold=new QCheckBox(tr("&Bold"), widgetFont);
77 checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
78 connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
79 checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont);
80 checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
81 connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
82
83 buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont);
84 buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
85 connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults()));
86
87 // Alignment tab
88 frameAlignment=new QFrame(widgetAlignment);
89 frameAlignment->setGeometry(10, 10, 215, 145);
90 frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
91
92 comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165);
93 connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
94 comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10));
95 connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
96
97 checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment);
98 checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS);
99 connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool)));
100
101 buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment);
102 buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
103 connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults()));
104
105 // Main widget
106 box=new QVBoxLayout(this);
107 box->addWidget(tabs);
108
109 setCaption(tr("Format Cells"));
110}
111
112CellFormat::~CellFormat()
113{
114}
115
116int CellFormat::findColorIndex(const QColor &color)
117{
118 for (int i=0; i<COLOR_COUNT; ++i)
119 if (qtColors[i]==color)
120 return i;
121 return 0;
122}
123
124int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag)
125{
126 for (int i=0; i<VALIGN_COUNT; ++i)
127 if (flagsVAlign[i] & flag)
128 return i;
129 return 0;
130}
131
132int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag)
133{
134 for (int i=0; i<HALIGN_COUNT; ++i)
135 if (flagsHAlign[i] & flag)
136 return i;
137 return 0;
138}
139
140int CellFormat::findBrushStyleIndex(Qt::BrushStyle style)
141{
142 for (int i=0; i<STYLE_COUNT; ++i)
143 if (brushStyles[i]==style)
144 return i;
145 return 0;
146}
147
148void CellFormat::setBrushBackground(const QBrush &brush)
149{
150 comboBackgroundColor->setCurrentItem(findColorIndex(brush.color()));
151 comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style()));
152
153 QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height());
154 QPainter p(&pix);
155 pix.fill();
156 p.fillRect(pix.rect(), brush);
157 frameBackground->setBackgroundPixmap(pix);
158
159 brushBackground=brush;
160}
161
162void CellFormat::setTextFont(const QFont &font, const QColor &color)
163{
164 comboFontColor->setCurrentItem(findColorIndex(color));
165 comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family()));
166 comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize())));
167 checkFontBold->setChecked(font.weight()==QFont::Bold);
168 checkFontItalic->setChecked(font.italic());
169
170 QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height());
171 QPainter p(&pix);
172 pix.fill();
173 p.fillRect(pix.rect(), Qt::white);
174 p.setFont(font);
175 p.setPen(color);
176 p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet"));
177 frameFont->setBackgroundPixmap(pix);
178
179 fontFont=font;
180 fontColor=color;
181}
182
183void CellFormat::setTextAlign(Qt::AlignmentFlags flags)
184{
185 comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags));
186 comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags));
187 checkAlignmentWrap->setChecked(flags & Qt::WordBreak);
188
189 QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height());
190 QPainter p(&pix);
191 pix.fill();
192 p.fillRect(pix.rect(), Qt::white);
193 p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet"));
194 frameAlignment->setBackgroundPixmap(pix);
195
196 textAlignment=flags;
197}
198
199void CellFormat::slotFontDefaults()
200{
201 changedFont=TRUE;
202 setTextFont(font(), Qt::black);
203}
204
205void CellFormat::slotAlignmentDefaults()
206{
207 changedAlign=TRUE;
208 setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop));
209}
210
211void CellFormat::slotBackgroundDefaults()
212{
213 changedBrush=TRUE;
214 setBrushBackground(Qt::white);
215}
216
217void CellFormat::slotBordersDefaults()
218{
219 QPen defaultPen(Qt::gray, 1, Qt::SolidLine);
220 borderEditor->setPen(defaultPen, BorderEditor::Top);
221 borderEditor->setPen(defaultPen, BorderEditor::Bottom);
222 borderEditor->setPen(defaultPen, BorderEditor::Left);
223 borderEditor->setPen(defaultPen, BorderEditor::Right);
224 borderEditor->setPen(defaultPen, BorderEditor::Vert);
225 borderEditor->setPen(defaultPen, BorderEditor::Horz);
226}
227
228void CellFormat::backgroundClicked(int index)
229{
230 changedBrush=TRUE;
231 setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()]));
232}
233
234void CellFormat::fontClicked(bool on)
235{
236 fontClicked(0);
237}
238
239void CellFormat::fontClicked(int index)
240{
241 changedFont=TRUE;
242 setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]);
243}
244
245void CellFormat::alignClicked(bool on)
246{
247 alignClicked(0);
248}
249
250void CellFormat::alignClicked(int index)
251{
252 changedAlign=TRUE;
253 setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0)));
254}
255
256void CellFormat::createSizeCombo(QComboBox *combo)
257{
258 combo->clear();
259 QValueList<int> sizes=fontDB.standardSizes();
260 for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i)
261 combo->insertItem(QString::number(*i));
262}
263
264void CellFormat::borderClicked(BorderEditor::BorderArea area)
265{
266 QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine);
267 if (newPen==borderEditor->getPen(area))
268 borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area);
269 else
270 borderEditor->setPen(newPen, area);
271}
272
273int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item)
274{
275 for (int i=0; i<combo->count(); ++i)
276 if (combo->text(i)==item)
277 return i;
278 return 0;
279}
280
281QComboBox *CellFormat::createCombo(comboType type, QWidget *parent, const QString &caption, int y)
282{
283 QComboBox *combo=new QComboBox(FALSE, parent);
284 combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS);
285 combo->setSizeLimit(5);
286
287 switch (type)
288 {
289 case COMBO_WIDTH: createWidthCombo(combo); break;
290 case COMBO_STYLE: createStyleCombo(combo); break;
291 case COMBO_FONT: createFontCombo(combo); break;
292 case COMBO_SIZE: createSizeCombo(combo); break;
293 case COMBO_COLOR: createColorCombo(combo); break;
294 case COMBO_HALIGN: createHAlignCombo(combo); break;
295 case COMBO_VALIGN: createVAlignCombo(combo); break;
296 }
297
298 QLabel *label=new QLabel(combo, caption, parent);
299 label->setGeometry(10, y, 50, COMBO_HEIGHTS);
300
301 return combo;
302}
303
304void CellFormat::createHAlignCombo(QComboBox *combo)
305{
306 for (int i=0; i<HALIGN_COUNT; ++i)
307 combo->insertItem(namesHAlign[i]);
308}
309
310void CellFormat::createVAlignCombo(QComboBox *combo)
311{
312 for (int i=0; i<VALIGN_COUNT; ++i)
313 combo->insertItem(namesVAlign[i]);
314}
315
316void CellFormat::createWidthCombo(QComboBox *combo)
317{
318 int width=combo->listBox()->maxItemWidth();
319 QPixmap pix(width, COMBO_HEIGHTS);
320 QPainter p(&pix);
321
322 for (int i=1; i<=6; ++i)
323 {
324 pix.fill();
325 p.setPen(QPen(Qt::black, i, Qt::SolidLine));
326 p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
327 combo->insertItem(pix);
328 }
329}
330
331void CellFormat::createFontCombo(QComboBox *combo)
332{
333 combo->insertStringList(fontDB.families());
334}
335
336void CellFormat::createStyleCombo(QComboBox *combo)
337{
338 int width=combo->listBox()->maxItemWidth();
339 QPixmap pix(width, COMBO_HEIGHTS);
340 QPainter p(&pix);
341
342 for (int i=0; i<STYLE_COUNT; ++i)
343 {
344 pix.fill();
345 p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]);
346 combo->insertItem(pix);
347 }
348}
349
350void CellFormat::createColorCombo(QComboBox *combo)
351{
352 int width=combo->listBox()->maxItemWidth();
353 QPixmap pix(width, COMBO_HEIGHTS);
354 QPainter p(&pix);
355
356 for (int i=0; i<COLOR_COUNT; ++i)
357 {
358 pix.fill();
359 p.setPen(QPen(qtColors[i], 3, Qt::SolidLine));
360 p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
361 combo->insertItem(pix);
362 }
363}
364
365int CellFormat::exec(Sheet *s)
366{
367 sheet=s;
368 int row1, row2, col1, col2, row, col;
369 sheet->getSelection(&row1, &col1, &row2, &col2);
370
371 QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0),
372 penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1),
373 penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0),
374 penDefault=borderEditor->getDefaultPen();
375 for (row=row1+1; row<=row2; ++row)
376 if (sheet->getPen(row, col1-1, 1)!=penLeft)
377 {
378 penLeft=penDefault;
379 break;
380 }
381 for (row=row1+1; row<=row2; ++row)
382 if (sheet->getPen(row, col2, 1)!=penRight)
383 {
384 penRight=penDefault;
385 break;
386 }
387 for (col=col1+1; col<=col2; ++col)
388 if (sheet->getPen(row1-1, col, 0)!=penTop)
389 {
390 penTop=penDefault;
391 break;
392 }
393 for (col=col1+1; col<=col2; ++col)
394 if (sheet->getPen(row2, col, 0)!=penBottom)
395 {
396 penBottom=penDefault;
397 break;
398 }
399 for (row=row1; row<=row2; ++row)
400 for (col=col1; col<col2; ++col)
401 if (sheet->getPen(row, col, 1)!=penVert)
402 {
403 penVert=penDefault;
404 break;
405 }
406 for (row=row1; row<row2; ++row)
407 for (col=col1; col<=col2; ++col)
408 if (sheet->getPen(row, col, 0)!=penHorz)
409 {
410 penHorz=penDefault;
411 break;
412 }
413
414 borderEditor->setPen(penTop, BorderEditor::Top);
415 borderEditor->setPen(penBottom, BorderEditor::Bottom);
416 borderEditor->setPen(penLeft, BorderEditor::Left);
417 borderEditor->setPen(penRight, BorderEditor::Right);
418 borderEditor->setPen(penVert, BorderEditor::Vert);
419 borderEditor->setPen(penHorz, BorderEditor::Horz);
420
421 setBrushBackground(sheet->getBrush(row1, col1));
422 setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1));
423 setTextAlign(sheet->getAlignment(row1, col1));
424
425 if (QDialog::exec()==QDialog::Accepted)
426 {
427 penTop=borderEditor->getPen(BorderEditor::Top);
428 penBottom=borderEditor->getPen(BorderEditor::Bottom);
429 penLeft=borderEditor->getPen(BorderEditor::Left);
430 penRight=borderEditor->getPen(BorderEditor::Right);
431 penVert=borderEditor->getPen(BorderEditor::Vert);
432 penHorz=borderEditor->getPen(BorderEditor::Horz);
433
434 if (penTop!=penDefault)
435 for (col=col1; col<=col2; ++col)
436 sheet->setPen(row1-1, col, 0, penTop);
437 if (penBottom!=penDefault)
438 for (col=col1; col<=col2; ++col)
439 sheet->setPen(row2, col, 0, penBottom);
440 if (penLeft!=penDefault)
441 for (row=row1; row<=row2; ++row)
442 sheet->setPen(row, col1-1, 1, penLeft);
443 if (penRight!=penDefault)
444 for (row=row1; row<=row2; ++row)
445 sheet->setPen(row, col2, 1, penRight);
446 if (penVert!=penDefault)
447 for (row=row1; row<=row2; ++row)
448 for (col=col1; col<col2; ++col)
449 sheet->setPen(row, col, 1, penVert);
450 if (penHorz!=penDefault)
451 for (row=row1; row<row2; ++row)
452 for (col=col1; col<=col2; ++col)
453 sheet->setPen(row, col, 0, penHorz);
454
455 if (changedBrush)
456 {
457 for (row=row1; row<=row2; ++row)
458 for (col=col1; col<=col2; ++col)
459 sheet->setBrush(row, col, brushBackground);
460 }
461
462 if (changedAlign)
463 {
464 for (row=row1; row<=row2; ++row)
465 for (col=col1; col<=col2; ++col)
466 sheet->setTextAlign(row, col, textAlignment);
467 }
468
469 if (changedFont)
470 {
471 for (row=row1; row<=row2; ++row)
472 for (col=col1; col<=col2; ++col)
473 sheet->setTextFont(row, col, fontFont, fontColor);
474 }
475 return QDialog::Accepted;
476 }
477 return QDialog::Rejected;
478}
479
480//
481// Border Editor
482//
483
484BorderEditor::BorderEditor(QWidget *parent=0)
485 :QFrame(parent)
486{
487 setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
488}
489
490BorderEditor::~BorderEditor()
491{
492}
493
494void BorderEditor::drawContents(QPainter *p)
495{
496 QFrame::drawContents(p);
497
498 int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
499 int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6;
500
501 p->fillRect(contentsRect(), Qt::white);
502
503 p->fillRect(x+width/3, y+height/3, width, height, Qt::gray);
504 p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray);
505 p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray);
506 p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray);
507
508 if (penTop.width()>0)
509 {
510 p->setPen(penTop);
511 p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY);
512 }
513 if (penBottom.width()>0)
514 {
515 p->setPen(penBottom);
516 p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY);
517 }
518 if (penHorz.width()>0)
519 {
520 p->setPen(penHorz);
521 p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2);
522 }
523 if (penLeft.width()>0)
524 {
525 p->setPen(penLeft);
526 p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY);
527 }
528 if (penRight.width()>0)
529 {
530 p->setPen(penRight);
531 p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY);
532 }
533 if (penVert.width()>0)
534 {
535 p->setPen(penVert);
536 p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY);
537 }
538}
539
540void BorderEditor::setPen(const QPen &pen, BorderArea area)
541{
542 switch (area)
543 {
544 case Top: penTop=pen; break;
545 case Bottom: penBottom=pen; break;
546 case Left: penLeft=pen; break;
547 case Right: penRight=pen; break;
548 case Horz: penHorz=pen; break;
549 case Vert: penVert=pen; break;
550 };
551 update();
552}
553
554void BorderEditor::mouseReleaseEvent(QMouseEvent *e)
555{
556 QFrame::mouseReleaseEvent(e);
557
558 int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
559 BorderArea area=None;
560
561 if (e->x()<x+width/3) area=Left;
562 if (e->x()>x+(8*width)/3) area=Right;
563 if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert;
564
565 if (e->y()<y+height/3) area=Top;
566 if (e->y()>y+(8*height)/3) area=Bottom;
567 if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz;
568
569 if (area!=None)
570 emit clicked(area);
571}
572
573QPen BorderEditor::getPen(BorderArea area)
574{
575 switch (area)
576 {
577 case Top: return penTop;
578 case Bottom: return penBottom;
579 case Left: return penLeft;
580 case Right: return penRight;
581 case Horz: return penHorz;
582 case Vert: return penVert;
583 };
584 return getDefaultPen();
585}
diff --git a/noncore/apps/opie-sheet/cellformat.h b/noncore/apps/opie-sheet/cellformat.h
new file mode 100644
index 0000000..b552153
--- a/dev/null
+++ b/noncore/apps/opie-sheet/cellformat.h
@@ -0,0 +1,106 @@
1#ifndef CELLFORMAT_H
2#define CELLFORMAT_H
3
4#include <qpe/fontdatabase.h>
5#include <qdialog.h>
6#include <qtabwidget.h>
7#include <qlayout.h>
8#include <qcombobox.h>
9#include <qcheckbox.h>
10#include <qpushbutton.h>
11
12#include "sheet.h"
13
14class BorderEditor: public QFrame
15{
16 Q_OBJECT
17
18 // QT objects
19 QPen penTop, penBottom, penLeft, penRight, penHorz, penVert;
20
21 // Private functions
22 void drawContents(QPainter *p);
23
24 // Reimplemented QFrame functions
25 void mouseReleaseEvent(QMouseEvent *e);
26
27 public:
28 // Definitions
29 enum BorderArea {None, Top, Bottom, Left, Right, Horz, Vert};
30
31 BorderEditor(QWidget *parent=0);
32 ~BorderEditor();
33
34 void setPen(const QPen &pen, BorderArea area);
35 QPen getPen(BorderArea area);
36 QPen getDefaultPen() { return QPen(Qt::black, 1, Qt::DotLine); }
37
38 signals:
39 void clicked(BorderEditor::BorderArea);
40};
41
42class CellFormat: public QDialog
43{
44 Q_OBJECT
45
46 enum comboType {COMBO_OTHER, COMBO_WIDTH, COMBO_FONT, COMBO_SIZE, COMBO_STYLE, COMBO_COLOR, COMBO_VALIGN, COMBO_HALIGN};
47
48 // QT objects
49 QBoxLayout *box;
50 QTabWidget *tabs;
51 QWidget *widgetBorders, *widgetBackground, *widgetFont, *widgetAlignment;
52 QComboBox *comboBordersWidth, *comboBordersColor, *comboBackgroundColor, *comboBackgroundStyle, *comboFontColor, *comboFontSize, *comboFontFamily, *comboAlignmentVertical, *comboAlignmentHorizontal;
53 QCheckBox *checkFontBold, *checkFontItalic, *checkAlignmentWrap;
54 QPushButton *buttonBordersDefaults, *buttonBackgroundDefaults, *buttonFontDefaults, *buttonAlignmentDefaults;
55 QFrame *frameBackground, *frameFont, *frameAlignment;
56 QBrush brushBackground;
57 QFont fontFont;
58 QColor fontColor;
59 Qt::AlignmentFlags textAlignment;
60 FontDatabase fontDB;
61
62 // Other objects & variables
63 Sheet *sheet;
64 BorderEditor *borderEditor;
65 bool changedFont, changedAlign, changedBrush;
66
67 // Private functions
68 void createWidthCombo(QComboBox *combo);
69 void createFontCombo(QComboBox *combo);
70 void createHAlignCombo(QComboBox *combo);
71 void createVAlignCombo(QComboBox *combo);
72 void createStyleCombo(QComboBox *combo);
73 void createSizeCombo(QComboBox *combo);
74 void createColorCombo(QComboBox *combo);
75 QComboBox *createCombo(comboType type, QWidget *parent, const QString &caption, int y);
76
77 int findHAlignIndex(Qt::AlignmentFlags flag);
78 int findVAlignIndex(Qt::AlignmentFlags flag);
79 int findComboItemIndex(QComboBox *combo, const QString &item);
80 int findColorIndex(const QColor &color);
81 int findBrushStyleIndex(Qt::BrushStyle style);
82
83 private slots:
84 void borderClicked(BorderEditor::BorderArea area);
85 void backgroundClicked(int index);
86 void fontClicked(bool on);
87 void fontClicked(int index);
88 void alignClicked(bool on);
89 void alignClicked(int index);
90 void slotBordersDefaults();
91 void slotBackgroundDefaults();
92 void slotFontDefaults();
93 void slotAlignmentDefaults();
94
95 public:
96 CellFormat(QWidget *parent=0);
97 ~CellFormat();
98
99 int exec(Sheet *s);
100
101 void setTextAlign(Qt::AlignmentFlags flags);
102 void setTextFont(const QFont &font, const QColor &color);
103 void setBrushBackground(const QBrush &brush);
104};
105
106#endif
diff --git a/noncore/apps/opie-sheet/edit-accept.xpm b/noncore/apps/opie-sheet/edit-accept.xpm
new file mode 100644
index 0000000..5109281
--- a/dev/null
+++ b/noncore/apps/opie-sheet/edit-accept.xpm
@@ -0,0 +1,30 @@
1/* XPM */
2static const char *edit_accept_xpm[] = {
3/* columns rows colors chars-per-pixel */
4"16 16 8 1",
5" c #000000000000",
6". c #000040400000",
7"X c #404000000000",
8"o c #000080800000",
9"O c #0000c0c00000",
10"+ c #c0c0ffffc0c0",
11"@ c #ffffffffffff",
12"# c None",
13/* pixels */
14"################",
15"################",
16"##############+#",
17"#############+O#",
18"############+Oo#",
19"###########+Oo.#",
20"##+o######+Oo. #",
21"#+OOo####+Oo.X##",
22" .oOOo##+Oo. ###",
23"# .oOOo+Oo.X####",
24"##X.oOOOo.X#####",
25"### .oOo. ######",
26"#### .o. #######",
27"##### X ########",
28"################",
29"################",
30};
diff --git a/noncore/apps/opie-sheet/edit-cancel.xpm b/noncore/apps/opie-sheet/edit-cancel.xpm
new file mode 100644
index 0000000..8e1606e
--- a/dev/null
+++ b/noncore/apps/opie-sheet/edit-cancel.xpm
@@ -0,0 +1,25 @@
1/* XPM */
2static const char *edit_cancel_xpm[] = {
3/* columns rows colors chars-per-pixel */
4"16 16 3 1",
5". c red",
6"X c #ffffffffffff",
7" c None",
8/* pixels */
9" ",
10" ",
11" ..... ",
12" ......... ",
13" ........... ",
14" ..XX...XX.. ",
15" ...XXX.XXX... ",
16" ....XXXXX.... ",
17" .....XXX..... ",
18" ....XXXXX.... ",
19" ...XXX.XXX... ",
20" ..XX...XX.. ",
21" ........... ",
22" ......... ",
23" ..... ",
24" ",
25};
diff --git a/noncore/apps/opie-sheet/file-new.xpm b/noncore/apps/opie-sheet/file-new.xpm
new file mode 100644
index 0000000..ec8dd63
--- a/dev/null
+++ b/noncore/apps/opie-sheet/file-new.xpm
@@ -0,0 +1,24 @@
1/* XPM */
2static const char * file_new_xpm[] = {
3"16 16 5 1",
4 " c None",
5 ".c #808080",
6 "+c #FFFFFF",
7 "@c #C0C0C0",
8 "#c #000000",
9" .......... ",
10" .++++++++@. ",
11" .++++++++@+. ",
12" .++++++++#### ",
13" .++++++++++@# ",
14" .++++++++++@# ",
15" .++++++++++@# ",
16" .++++++++++@# ",
17" .++++++++++@# ",
18" .++++++++++@# ",
19" .++++++++++@# ",
20" .++++++++++@# ",
21" .++++++++++@# ",
22" .++++++++++@# ",
23" .@@@@@@@@@@@# ",
24" ############# "};
diff --git a/noncore/apps/opie-sheet/file-open.xpm b/noncore/apps/opie-sheet/file-open.xpm
new file mode 100644
index 0000000..8449d5b
--- a/dev/null
+++ b/noncore/apps/opie-sheet/file-open.xpm
@@ -0,0 +1,25 @@
1/* XPM */
2static const char * file_open_xpm[] = {
3"16 16 6 1",
4 " c None",
5 ".c #808080",
6 "+c #FFFFFF",
7 "@c #C0C0C0",
8 "#c #FFFF00",
9 "$c #000000",
10" ",
11" ..... ",
12" .+++++. ",
13" .+@#@#@+...... ",
14" .+#@#@#@+++++.$",
15" .+@#@#@#@#@#@.$",
16".............#.$",
17".++++++++++.$@.$",
18".+@#@#@#@#@#$..$",
19" .+@#@#@#@#@.$.$",
20" .+#@#@#@#@#@$.$",
21" .+#@#@#@#@#.$$",
22" ............$$",
23" $$$$$$$$$$$$$",
24" ",
25" "};
diff --git a/noncore/apps/opie-sheet/file-save.xpm b/noncore/apps/opie-sheet/file-save.xpm
new file mode 100644
index 0000000..039a174
--- a/dev/null
+++ b/noncore/apps/opie-sheet/file-save.xpm
@@ -0,0 +1,24 @@
1/* XPM */
2static const char * file_save_xpm[] = {
3"16 16 5 1",
4 " c None",
5 ".c #808080",
6 "+c #FFFFFF",
7 "@c #000000",
8 "#c #0000FF",
9" ",
10" ........ ",
11" .++++++.@ ",
12" .+....+.+@ #",
13" .++++++.@@@ ##",
14" .+....++++@ ##@",
15" .+++++++++@##@ ",
16" .+.......+##@ ",
17" .++++++++##@ ",
18" .+......@#@ ",
19" .++++++@@@@ ",
20" .+....@@@+@ ",
21" .++++@++++@ ",
22" .+++++++++@ ",
23" @@@@@@@@@@@ ",
24" "};
diff --git a/noncore/apps/opie-sheet/finddlg.cpp b/noncore/apps/opie-sheet/finddlg.cpp
new file mode 100644
index 0000000..cfe2f82
--- a/dev/null
+++ b/noncore/apps/opie-sheet/finddlg.cpp
@@ -0,0 +1,70 @@
1#include <qlabel.h>
2#include <qradiobutton.h>
3#include "finddlg.h"
4
5FindDialog::FindDialog(QWidget *parent=0)
6 :QDialog(parent, 0, TRUE)
7{
8 // Main widget
9 tabs=new QTabWidget(this);
10 widgetFind=new QWidget(tabs);
11 widgetOptions=new QWidget(tabs);
12 tabs->addTab(widgetFind, tr("&Find && Replace"));
13 tabs->addTab(widgetOptions, tr("&Options"));
14
15 // Find tab
16 QLabel *label=new QLabel(tr("&Search for:"), widgetFind);
17 label->setGeometry(10, 10, 215, 20);
18 editFind=new QLineEdit(widgetFind);
19 editFind->setGeometry(10, 40, 215, 20);
20 label->setBuddy(editFind);
21
22 label=new QLabel(tr("&Replace with:"), widgetFind);
23 label->setGeometry(10, 80, 215, 20);
24 editReplace=new QLineEdit(widgetFind);
25 editReplace->setGeometry(10, 110, 215, 20);
26 editReplace->setEnabled(FALSE);
27 label->setBuddy(editReplace);
28
29 groupType=new QVButtonGroup(tr("&Type"), widgetFind);
30 groupType->setGeometry(10, 150, 215, 90);
31 QRadioButton *radio=new QRadioButton(tr("&Find"), groupType);
32 radio=new QRadioButton(tr("&Replace"), groupType);
33 radio=new QRadioButton(tr("Replace &all"), groupType);
34 groupType->setButton(0);
35 connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int)));
36
37 // Options tab
38 checkCase=new QCheckBox(tr("Match &case"), widgetOptions);
39 checkCase->setGeometry(10, 10, 215, 20);
40 checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions);
41 checkSelection->setGeometry(10, 40, 215, 20);
42 checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions);
43 checkEntire->setGeometry(10, 70, 215, 20);
44
45 // Main widget
46 box=new QVBoxLayout(this);
47 box->addWidget(tabs);
48
49 setCaption(tr("Find & Replace"));
50}
51
52FindDialog::~FindDialog()
53{
54}
55
56void FindDialog::typeChanged(int id)
57{
58 editReplace->setEnabled(id>0);
59}
60
61int FindDialog::exec(Sheet *s)
62{
63 if (QDialog::exec()==QDialog::Accepted)
64 {
65 int id=groupType->id(groupType->selected());
66 s->dataFindReplace(editFind->text(), editReplace->text(), checkCase->isChecked(), !checkSelection->isChecked(), checkEntire->isChecked(), id>0, id>1);
67 return QDialog::Accepted;
68 }
69 return QDialog::Rejected;
70}
diff --git a/noncore/apps/opie-sheet/finddlg.h b/noncore/apps/opie-sheet/finddlg.h
new file mode 100644
index 0000000..02c9cdd
--- a/dev/null
+++ b/noncore/apps/opie-sheet/finddlg.h
@@ -0,0 +1,35 @@
1#ifndef FINDDLG_H
2#define FINDDLG_H
3
4#include <qdialog.h>
5#include <qtabwidget.h>
6#include <qlayout.h>
7#include <qlineedit.h>
8#include <qcheckbox.h>
9#include <qpushbutton.h>
10#include <qvbuttongroup.h>
11#include "sheet.h"
12
13class FindDialog: public QDialog
14{
15 Q_OBJECT
16
17 // QT objects
18 QBoxLayout *box;
19 QTabWidget *tabs;
20 QWidget *widgetFind, *widgetOptions;
21 QCheckBox *checkCase, *checkSelection, *checkEntire;
22 QLineEdit *editFind, *editReplace;
23 QVButtonGroup *groupType;
24
25 private slots:
26 void typeChanged(int id);
27
28 public:
29 FindDialog(QWidget *parent=0);
30 ~FindDialog();
31
32 int exec(Sheet *s);
33};
34
35#endif
diff --git a/noncore/apps/opie-sheet/func-comma.xpm b/noncore/apps/opie-sheet/func-comma.xpm
new file mode 100644
index 0000000..3b2bbf9
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-comma.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_comma_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" ",
8" ",
9" ... ",
10" ..... ",
11" ...... ",
12" ...... ",
13" ..... ",
14" .. ",
15" . ",
16" .. ",
17" .. ",
18" . ",
19" ",
20" ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-cross.xpm b/noncore/apps/opie-sheet/func-cross.xpm
new file mode 100644
index 0000000..6f77502
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-cross.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_cross_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" ",
8" ",
9" .. ",
10" .. ",
11" .. ",
12" ... .. ... ",
13" .......... ",
14" ...... ",
15" .... ",
16" ...... ",
17" ... ... ",
18" . . ",
19" ",
20" ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-divide.xpm b/noncore/apps/opie-sheet/func-divide.xpm
new file mode 100644
index 0000000..1ac6a07
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-divide.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_divide_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" ",
8" .. ",
9" .. ",
10" .. ",
11" .. ",
12" .. ",
13" .. ",
14" .. ",
15" .. ",
16" .. ",
17" .. ",
18" .. ",
19" .. ",
20" .. ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-equal.xpm b/noncore/apps/opie-sheet/func-equal.xpm
new file mode 100644
index 0000000..60f8710
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-equal.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_equal_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" ",
8" ",
9" ",
10" ",
11" .......... ",
12" .......... ",
13" ",
14" ",
15" .......... ",
16" .......... ",
17" ",
18" ",
19" ",
20" ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-func.xpm b/noncore/apps/opie-sheet/func-func.xpm
new file mode 100644
index 0000000..c1f7852
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-func.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_func_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" .. ",
8" .. ",
9" . ",
10" . ",
11" . ",
12" ..... ",
13" . ",
14" . . . ",
15" . . . ",
16" . . ",
17" . . . ",
18" . . . ",
19" . ",
20" . ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-minus.xpm b/noncore/apps/opie-sheet/func-minus.xpm
new file mode 100644
index 0000000..fa2cb4f
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-minus.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_minus_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" ",
8" ",
9" ",
10" ",
11" ",
12" ",
13" ....... ",
14" ....... ",
15" ",
16" ",
17" ",
18" ",
19" ",
20" ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-paran-close.xpm b/noncore/apps/opie-sheet/func-paran-close.xpm
new file mode 100644
index 0000000..85191d5
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-paran-close.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_paran_close_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" . ",
8" .. ",
9" . ",
10" .. ",
11" .. ",
12" .. ",
13" .. ",
14" .. ",
15" .. ",
16" .. ",
17" . ",
18" .. ",
19" . ",
20" ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-paran-open.xpm b/noncore/apps/opie-sheet/func-paran-open.xpm
new file mode 100644
index 0000000..3c7870b
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-paran-open.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_paran_open_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" . ",
8" .. ",
9" . ",
10" .. ",
11" .. ",
12" .. ",
13" .. ",
14" .. ",
15" .. ",
16" .. ",
17" . ",
18" .. ",
19" . ",
20" ",
21" "};
diff --git a/noncore/apps/opie-sheet/func-plus.xpm b/noncore/apps/opie-sheet/func-plus.xpm
new file mode 100644
index 0000000..a917c64
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-plus.xpm
@@ -0,0 +1,21 @@
1/* XPM */
2static const char * func_plus_xpm[] = {
3"16 16 2 1",
4 " c None",
5 ".c #000000",
6" ",
7" ",
8" .. ",
9" .. ",
10" .. ",
11" .. ",
12" .. ",
13" ............ ",
14" ............ ",
15" .. ",
16" .. ",
17" .. ",
18" .. ",
19" .. ",
20" ",
21" "};
diff --git a/noncore/apps/opie-sheet/help-general.xpm b/noncore/apps/opie-sheet/help-general.xpm
new file mode 100644
index 0000000..9f10527
--- a/dev/null
+++ b/noncore/apps/opie-sheet/help-general.xpm
@@ -0,0 +1,25 @@
1/* XPM */
2static const char * help_general_xpm[] = {
3"16 16 6 1",
4 " c None s None",
5 ".c #000000",
6 "Xc #FF0000",
7 "oc #FFFF00",
8 "Oc #808080",
9 "+c #FFFFFF",
10" ",
11" .. ",
12" .XX. ",
13" .XXXX. ",
14" .XXXoXX. ",
15" .XXXoXoXX. ",
16" .XXXXXoXoX. ",
17" .XXXXXXXoX.O ",
18" ..XXXXXXX.+.O ",
19" .+.XXXXX.+.O ",
20" .+.XXX.+.O ",
21" .+.X.+.O ",
22" .+.+.O ",
23" .+.O ",
24" .O ",
25" "};
diff --git a/noncore/apps/opie-sheet/main.cpp b/noncore/apps/opie-sheet/main.cpp
new file mode 100644
index 0000000..236a579
--- a/dev/null
+++ b/noncore/apps/opie-sheet/main.cpp
@@ -0,0 +1,14 @@
1#include <qpe/qpeapplication.h>
2
3#include "mainwindow.h"
4
5int main(int argc, char **argv)
6{
7 QPEApplication application(argc, argv);
8
9 MainWindow windowMain;
10 windowMain.setHelpFile(application.qpeDir()+"/help/html/"+QString(argv[0])+".html");
11 application.showMainDocumentWidget(&windowMain);
12
13 return application.exec();
14}
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp
new file mode 100644
index 0000000..a7441b1
--- a/dev/null
+++ b/noncore/apps/opie-sheet/mainwindow.cpp
@@ -0,0 +1,836 @@
1#include "mainwindow.h"
2
3#include <qpe/filemanager.h>
4#include <qpe/qcopenvelope_qws.h>
5#include <qmessagebox.h>
6#include <qfile.h>
7#include <qradiobutton.h>
8#include "cellformat.h"
9#include "numberdlg.h"
10#include "textdlg.h"
11#include "sortdlg.h"
12#include "finddlg.h"
13
14#include "file-new.xpm"
15#include "file-open.xpm"
16#include "file-save.xpm"
17#include "edit-cancel.xpm"
18#include "edit-accept.xpm"
19#include "help-general.xpm"
20#include "func-plus.xpm"
21#include "func-minus.xpm"
22#include "func-cross.xpm"
23#include "func-divide.xpm"
24#include "func-paran-open.xpm"
25#include "func-paran-close.xpm"
26#include "func-comma.xpm"
27#include "func-func.xpm"
28#include "func-equal.xpm"
29#include "cell-select.xpm"
30
31#define DEFAULT_NUM_ROWS 199
32#define DEFAULT_NUM_COLS (26*3)
33#define DEFAULT_NUM_SHEETS 3
34
35MainWindow::MainWindow()
36 :QMainWindow()
37{
38 // initialize variables
39 documentModified=FALSE;
40
41 // construct objects
42 fileSelector=new FileSelector("application/sheet-qt", this, QString::null);
43 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide()));
44 connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &)));
45 connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &)));
46
47 listSheets.setAutoDelete(TRUE);
48
49 initActions();
50 initMenu();
51 initEditToolbar();
52 initFunctionsToolbar();
53 initStandardToolbar();
54 initSheet();
55
56 // set window title
57 setCaption(tr("Opie Sheet"));
58
59 // create sheets
60 selectorFileNew(currentDoc);
61}
62
63MainWindow::~MainWindow()
64{
65}
66
67void MainWindow::documentSave(DocLnk &lnkDoc)
68{
69 FileManager fm;
70 QByteArray streamBuffer;
71 QDataStream stream(streamBuffer, IO_WriteOnly);
72
73 typeSheet *currentSheet=findSheet(sheet->getName());
74 if (!currentSheet)
75 {
76 QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!"));
77 return;
78 }
79 sheet->copySheetData(&currentSheet->data);
80 stream.writeRawBytes("SQT100", 6);
81 stream << (Q_UINT32)listSheets.count();
82 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
83 {
84 stream << tempSheet->name << (Q_UINT32)tempSheet->data.count();
85 for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next())
86 stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data;
87 }
88
89 lnkDoc.setType("application/sheet-qt");
90 if (!fm.saveFile(lnkDoc, streamBuffer))
91 {
92 QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!"));
93 return;
94 }
95 documentModified=FALSE;
96}
97
98void MainWindow::documentOpen(const DocLnk &lnkDoc)
99{
100 FileManager fm;
101 QByteArray streamBuffer;
102 if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer))
103 {
104 QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!"));
105 documentModified=FALSE;
106 selectorFileNew(DocLnk());
107 return;
108 }
109 QDataStream stream(streamBuffer, IO_ReadOnly);
110
111 Q_UINT32 countSheet, countCell, i, j, row, col, alignment;
112 typeSheet *newSheet;
113 typeCellData *newCell;
114
115 char fileFormat[7];
116 stream.readRawBytes(fileFormat, 6);
117 fileFormat[6]=0;
118 if ((QString)fileFormat!="SQT100")
119 {
120 QMessageBox::critical(this, tr("Error"), tr("Invalid file format!"));
121 documentModified=FALSE;
122 selectorFileNew(DocLnk());
123 return;
124 }
125
126 stream >> countSheet;
127 for (i=0; i<countSheet; ++i)
128 {
129 newSheet=new typeSheet;
130 newSheet->data.setAutoDelete(TRUE);
131 stream >> newSheet->name >> countCell;
132 comboSheets->insertItem(newSheet->name);
133
134 for (j=0; j<countCell; ++j)
135 {
136 newCell=new typeCellData;
137 stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data;
138 newCell->col=col;
139 newCell->row=row;
140 newCell->alignment=(Qt::AlignmentFlags)alignment;
141 newSheet->data.append(newCell);
142 }
143 listSheets.append(newSheet);
144
145 if (i==0)
146 {
147 sheet->setName(newSheet->name);
148 sheet->setSheetData(&newSheet->data);
149 }
150 }
151}
152
153int MainWindow::saveCurrentFile(bool ask=TRUE)
154{
155 if (ask)
156 {
157 int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
158 if (result!=QMessageBox::Yes) return result;
159 }
160
161 if (currentDoc.name().isEmpty() || !currentDoc.isValid())
162 {
163 TextDialog dialogText(this);
164 if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel;
165
166 currentDoc.setName(dialogText.getValue());
167 }
168
169 documentSave(currentDoc);
170 return QMessageBox::Yes;
171}
172
173void MainWindow::copyDocLnk(const DocLnk &source, DocLnk &target)
174{
175 target.setName(source.name());
176 target.setFile(source.file());
177 target.setLinkFile(source.linkFile());
178 target.setComment(source.comment());
179 target.setType(source.type());
180 target.setCategories(source.categories());
181}
182
183void MainWindow::selectorFileNew(const DocLnk &lnkDoc)
184{
185 selectorHide();
186
187 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
188 copyDocLnk(lnkDoc, currentDoc);
189 listSheets.clear();
190 comboSheets->clear();
191
192 typeSheet *newSheet=createNewSheet();
193 newSheet->data.setAutoDelete(TRUE);
194 sheet->setName(newSheet->name);
195 sheet->setSheetData(&newSheet->data);
196 for (int i=1; i<DEFAULT_NUM_SHEETS; ++i)
197 createNewSheet();
198 documentModified=FALSE;
199}
200
201void MainWindow::closeEvent(QCloseEvent *e)
202{
203 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore();
204 else e->accept();
205}
206
207void MainWindow::selectorFileOpen(const DocLnk &lnkDoc)
208{
209 selectorHide();
210
211 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
212 copyDocLnk(lnkDoc, currentDoc);
213 listSheets.clear();
214 comboSheets->clear();
215
216 documentOpen(lnkDoc);
217 documentModified=FALSE;
218}
219
220void MainWindow::selectorShow()
221{
222 sheet->hide();
223 setCentralWidget(fileSelector);
224 fileSelector->show();
225 fileSelector->reread();
226}
227
228void MainWindow::selectorHide()
229{
230 fileSelector->hide();
231 setCentralWidget(sheet);
232 sheet->show();
233}
234
235void MainWindow::slotFileNew()
236{
237 selectorFileNew(DocLnk());
238}
239
240void MainWindow::slotFileOpen()
241{
242 selectorShow();
243}
244
245void MainWindow::slotFileSave()
246{
247 saveCurrentFile(FALSE);
248}
249
250void MainWindow::setDocument(const QString &applnk_filename)
251{
252 selectorFileOpen(DocLnk(applnk_filename));
253}
254
255void MainWindow::initActions()
256{
257 fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this);
258 connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
259 fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this);
260 connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
261 fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this);
262 connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
263 fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this);
264 connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
265 fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this);
266 connect(fileQuit, SIGNAL(activated()), this, SLOT(close()));
267
268 helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this);
269 connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral()));
270 helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this);
271 connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
272
273 editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this);
274 connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept()));
275 editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this);
276 connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel()));
277 editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this);
278 editCellSelect->setToggleAction(TRUE);
279 connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool)));
280 editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this);
281 editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this);
282 editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this);
283 connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
284 editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this);
285 connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents()));
286 editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this);
287
288 insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this);
289 connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells()));
290 insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this);
291 connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows()));
292 insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this);
293 connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols()));
294 insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this);
295 connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets()));
296
297 formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this);
298 connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells()));
299
300 rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this);
301 connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight()));
302 rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this);
303 connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust()));
304 rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this);
305 connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow()));
306 rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this);
307 connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide()));
308
309 colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this);
310 connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth()));
311 colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this);
312 connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust()));
313 colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this);
314 connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow()));
315 colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this);
316 connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide()));
317
318 sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this);
319 connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename()));
320 sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this);
321 connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove()));
322
323 dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this);
324 connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort()));
325 dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this);
326 connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace()));
327
328 funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this);
329 funcEqual->setToolTip("=");
330 connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
331 funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this);
332 funcPlus->setToolTip("+");
333 connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
334 funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this);
335 funcMinus->setToolTip("-");
336 connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
337 funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this);
338 funcCross->setToolTip("*");
339 connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
340 funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this);
341 funcDivide->setToolTip("/");
342 connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
343 funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this);
344 funcParanOpen->setToolTip("(");
345 connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
346 funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this);
347 funcParanClose->setToolTip(")");
348 connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
349 funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this);
350 funcComma->setToolTip(",");
351 connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
352}
353
354void MainWindow::initMenu()
355{
356 menu=new QPEMenuBar(this);
357
358 menuFile=new QPopupMenu;
359 fileNew->addTo(menuFile);
360 fileOpen->addTo(menuFile);
361 fileSave->addTo(menuFile);
362 fileSaveAs->addTo(menuFile);
363 menuFile->insertSeparator();
364 fileQuit->addTo(menuFile);
365 menu->insertItem(tr("&File"), menuFile);
366
367 menuEdit=new QPopupMenu;
368 editAccept->addTo(menuEdit);
369 editCancel->addTo(menuEdit);
370 editCellSelect->addTo(menuEdit);
371 menuEdit->insertSeparator();
372 editCut->addTo(menuEdit);
373 editCopy->addTo(menuEdit);
374 editPaste->addTo(menuEdit);
375 editPasteContents->addTo(menuEdit);
376 editClear->addTo(menuEdit);
377 menu->insertItem(tr("&Edit"), menuEdit);
378
379 menuInsert=new QPopupMenu;
380 menu->insertItem(tr("&Insert"), menuInsert);
381
382 menuFormat=new QPopupMenu;
383 formatCells->addTo(menuFormat);
384 menu->insertItem(tr("&Format"), menuFormat);
385
386 menuData=new QPopupMenu;
387 dataSort->addTo(menuData);
388 dataFindReplace->addTo(menuData);
389 menu->insertItem(tr("&Data"), menuData);
390
391 menuHelp=new QPopupMenu;
392 helpGeneral->addTo(menuHelp);
393 helpAbout->addTo(menuHelp);
394 menu->insertItem(tr("&Help"), menuHelp);
395
396 submenuRow=new QPopupMenu;
397 rowHeight->addTo(submenuRow);
398 rowAdjust->addTo(submenuRow);
399 rowShow->addTo(submenuRow);
400 rowHide->addTo(submenuRow);
401 menuFormat->insertItem(tr("&Row"), submenuRow);
402
403 submenuCol=new QPopupMenu;
404 colWidth->addTo(submenuCol);
405 colAdjust->addTo(submenuCol);
406 colShow->addTo(submenuCol);
407 colHide->addTo(submenuCol);
408 menuFormat->insertItem(tr("Colum&n"), submenuCol);
409
410 submenuSheet=new QPopupMenu;
411 sheetRename->addTo(submenuSheet);
412 sheetRemove->addTo(submenuSheet);
413 menuFormat->insertItem(tr("&Sheet"), submenuSheet);
414
415 submenuFunc=new QPopupMenu;
416 menuInsert->insertItem(tr("&Function"), submenuFunc);
417
418 submenuFuncStd=new QPopupMenu;
419 funcPlus->addTo(submenuFuncStd);
420 funcMinus->addTo(submenuFuncStd);
421 funcCross->addTo(submenuFuncStd);
422 funcDivide->addTo(submenuFuncStd);
423 submenuFunc->insertItem(tr("&Standard"), submenuFuncStd);
424
425 submenuFuncMath=new QPopupMenu;
426 addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath);
427 addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath);
428 submenuFuncMath->insertSeparator();
429 addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath);
430 addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath);
431 addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath);
432 addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath);
433 addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath);
434 addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath);
435 addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath);
436 submenuFuncMath->insertSeparator();
437 addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath);
438 addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath);
439 addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath);
440 submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath);
441
442 submenuFuncStat=new QPopupMenu;
443 addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat);
444 addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat);
445 addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat);
446 addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat);
447 submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat);
448
449 menuInsert->insertSeparator();
450 insertCells->addTo(menuInsert);
451 insertRows->addTo(menuInsert);
452 insertCols->addTo(menuInsert);
453 insertSheets->addTo(menuInsert);
454}
455
456void MainWindow::initStandardToolbar()
457{
458 toolbarStandard=new QPEToolBar(this);
459 toolbarStandard->setHorizontalStretchable(TRUE);
460 moveToolBar(toolbarStandard, Top);
461
462 fileNew->addTo(toolbarStandard);
463 fileOpen->addTo(toolbarStandard);
464 fileSave->addTo(toolbarStandard);
465
466 comboSheets=new QComboBox(toolbarStandard);
467 toolbarStandard->setStretchableWidget(comboSheets);
468 connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &)));
469}
470
471void MainWindow::initFunctionsToolbar()
472{
473 toolbarFunctions=new QPEToolBar(this);
474 toolbarFunctions->setHorizontalStretchable(TRUE);
475 moveToolBar(toolbarFunctions, Bottom);
476
477 funcEqual->addTo(toolbarFunctions);
478 funcPlus->addTo(toolbarFunctions);
479 funcMinus->addTo(toolbarFunctions);
480 funcCross->addTo(toolbarFunctions);
481 funcDivide->addTo(toolbarFunctions);
482 funcParanOpen->addTo(toolbarFunctions);
483 funcParanClose->addTo(toolbarFunctions);
484 funcComma->addTo(toolbarFunctions);
485
486 toolFunction=new QToolButton(toolbarFunctions);
487 toolFunction->setPixmap(func_func_xpm);
488 toolFunction->setTextLabel(tr("Functions"));
489 toolFunction->setPopup(submenuFunc);
490 toolFunction->setPopupDelay(0);
491}
492
493void MainWindow::initEditToolbar()
494{
495 toolbarEdit=new QPEToolBar(this);
496 toolbarEdit->setHorizontalStretchable(TRUE);
497 moveToolBar(toolbarEdit, Bottom);
498
499 editAccept->addTo(toolbarEdit);
500 editCancel->addTo(toolbarEdit);
501
502 editData=new QLineEdit(toolbarEdit);
503 toolbarEdit->setStretchableWidget(editData);
504 connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept()));
505
506 editCellSelect->addTo(toolbarEdit);
507}
508
509void MainWindow::slotHelpGeneral()
510{
511 if (QFile::exists(helpFile))
512 {
513 QCopEnvelope e("QPE/Application/helpbrowser", "showFile(QString)");
514 e << helpFile;
515 }
516 else
517 QMessageBox::critical(this, tr("Error"), tr("Help file not found!"));
518}
519
520void MainWindow::slotHelpAbout()
521{
522 QDialog dialogAbout(this, 0, TRUE);
523 dialogAbout.resize(width()-40, height()-80);
524 dialogAbout.setCaption(tr("About Opie Sheet"));
525
526 QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nVersion: 1.0.1 (Final)\nRelease Date: July 4, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout);
527 label.setGeometry(dialogAbout.rect());
528 label.setAlignment(Qt::AlignCenter | Qt::WordBreak);
529
530 dialogAbout.exec();
531}
532
533void MainWindow::initSheet()
534{
535 sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this);
536 setCentralWidget(sheet);
537
538 connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &)));
539 connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &)));
540 connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified()));
541
542 connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut()));
543 connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy()));
544 connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear()));
545}
546
547void MainWindow::slotEditAccept()
548{
549 sheet->setData(editData->text());
550}
551
552void MainWindow::slotEditCancel()
553{
554 editData->setText(sheet->getData());
555}
556
557void MainWindow::slotCellSelect(bool lock)
558{
559 sheet->lockClicks(lock);
560}
561
562void MainWindow::addToData(const QString &data)
563{
564 editData->setText(editData->text().insert(editData->cursorPosition(), data));
565}
566
567void MainWindow::slotFuncOutput()
568{
569 if (sender()->isA("QAction"))
570 addToData(((QAction *)sender())->toolTip());
571}
572
573void MainWindow::slotInsertRows()
574{
575 NumberDialog dialogNumber(this);
576 if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted)
577 sheet->insertRows(dialogNumber.getValue());
578}
579
580void MainWindow::slotInsertCols()
581{
582 NumberDialog dialogNumber(this);
583 if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted)
584 sheet->insertColumns(dialogNumber.getValue());
585}
586
587void MainWindow::slotInsertSheets()
588{
589 NumberDialog dialogNumber(this);
590 if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted)
591 for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet();
592}
593
594void MainWindow::slotCellClicked(const QString &cell)
595{
596 editCellSelect->setOn(FALSE);
597 addToData(cell);
598}
599
600typeSheet *MainWindow::createNewSheet()
601{
602 typeSheet *newSheet=new typeSheet;
603 int currentNo=1, tempNo;
604 bool ok;
605
606 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
607 if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok)
608 currentNo=tempNo+1;
609
610 newSheet->name=tr("Sheet")+QString::number(currentNo);
611 newSheet->data.setAutoDelete(TRUE);
612
613 comboSheets->insertItem(newSheet->name);
614 listSheets.append(newSheet);
615 return newSheet;
616}
617
618typeSheet *MainWindow::findSheet(const QString &name)
619{
620 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
621 if (tempSheet->name==name)
622 return tempSheet;
623 return NULL;
624}
625
626void MainWindow::slotSheetChanged(const QString &name)
627{
628 sheet->copySheetData(&findSheet(sheet->getName())->data);
629 sheet->setName(name);
630 sheet->setSheetData(&findSheet(name)->data);
631}
632
633void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w)
634{
635 QAction *action=new QAction(text, menuText, 0, this);
636 action->setToolTip(tip);
637 connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
638 action->addTo(w);
639}
640
641void MainWindow::slotFormatCells()
642{
643 CellFormat dialogCellFormat(this);
644 dialogCellFormat.showMaximized();
645 dialogCellFormat.exec(sheet);
646}
647
648void MainWindow::slotEditPaste()
649{
650 sheet->editPaste();
651}
652
653void MainWindow::slotEditPasteContents()
654{
655 sheet->editPaste(TRUE);
656}
657
658void MainWindow::slotRowHeight()
659{
660 int row1, row2, col1, col2;
661 sheet->getSelection(&row1, &col1, &row2, &col2);
662
663 NumberDialog dialogNumber(this);
664 if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted)
665 {
666 int newHeight=dialogNumber.getValue(), row;
667 for (row=row1; row<=row2; ++row)
668 sheet->setRowHeight(row, newHeight);
669 }
670}
671
672void MainWindow::slotRowAdjust()
673{
674 int row1, row2, col1, col2;
675 sheet->getSelection(&row1, &col1, &row2, &col2);
676
677 for (int row=row1; row<=row2; ++row)
678 sheet->adjustRow(row);
679}
680
681void MainWindow::slotRowShow()
682{
683 int row1, row2, col1, col2;
684 sheet->getSelection(&row1, &col1, &row2, &col2);
685
686 for (int row=row1; row<=row2; ++row)
687 sheet->showRow(row);
688}
689
690void MainWindow::slotRowHide()
691{
692 int row1, row2, col1, col2;
693 sheet->getSelection(&row1, &col1, &row2, &col2);
694
695 for (int row=row1; row<=row2; ++row)
696 sheet->hideRow(row);
697}
698
699void MainWindow::slotColumnWidth()
700{
701 int row1, row2, col1, col2;
702 sheet->getSelection(&row1, &col1, &row2, &col2);
703
704 NumberDialog dialogNumber(this);
705 if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted)
706 {
707 int newWidth=dialogNumber.getValue(), col;
708 for (col=col1; col<=col2; ++col)
709 sheet->setColumnWidth(col, newWidth);
710 }
711}
712
713void MainWindow::slotColumnAdjust()
714{
715 int row1, row2, col1, col2;
716 sheet->getSelection(&row1, &col1, &row2, &col2);
717
718 for (int col=col1; col<=col2; ++col)
719 sheet->adjustColumn(col);
720}
721
722void MainWindow::slotColumnShow()
723{
724 int row1, row2, col1, col2;
725 sheet->getSelection(&row1, &col1, &row2, &col2);
726
727 for (int col=col1; col<=col2; ++col)
728 sheet->showColumn(col);
729}
730
731void MainWindow::slotColumnHide()
732{
733 int row1, row2, col1, col2;
734 sheet->getSelection(&row1, &col1, &row2, &col2);
735
736 for (int col=col1; col<=col2; ++col)
737 sheet->hideColumn(col);
738}
739
740void MainWindow::slotFileSaveAs()
741{
742 TextDialog dialogText(this);
743 if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc.name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
744
745 currentDoc.setName(dialogText.getValue());
746 documentSave(currentDoc);
747}
748
749void MainWindow::slotSheetRename()
750{
751 TextDialog dialogText(this);
752 if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
753 QString newName=dialogText.getValue();
754
755 typeSheet *tempSheet=findSheet(newName);
756 if (tempSheet)
757 {
758 QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\''));
759 return;
760 }
761
762 tempSheet=findSheet(sheet->getName());
763 for (int i=0; i<comboSheets->count(); ++i)
764 if (comboSheets->text(i)==tempSheet->name)
765 {
766 comboSheets->changeItem(newName, i);
767 break;
768 }
769 tempSheet->name=newName;
770 sheet->setName(newName);
771}
772
773void MainWindow::slotSheetRemove()
774{
775 if (comboSheets->count()<2)
776 {
777 QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!"));
778 return;
779 }
780 if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
781 {
782 typeSheet *tempSheet=findSheet(sheet->getName());
783 for (int i=0; i<comboSheets->count(); ++i)
784 if (comboSheets->text(i)==tempSheet->name)
785 {
786 comboSheets->removeItem(i);
787 break;
788 }
789 comboSheets->setCurrentItem(0);
790 slotSheetChanged(comboSheets->currentText());
791 listSheets.remove(tempSheet);
792 }
793}
794
795void MainWindow::slotDataSort()
796{
797 SortDialog dialogSort(this);
798 dialogSort.showMaximized();
799 dialogSort.exec(sheet);
800}
801
802void MainWindow::slotDocModified()
803{
804 documentModified=TRUE;
805}
806
807void MainWindow::slotInsertCells()
808{
809 QDialog dialogInsert(this, 0, TRUE);
810 dialogInsert.resize(180, 130);
811 dialogInsert.setCaption(tr("Insert Cells"));
812
813 QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert);
814 group->setGeometry(10, 10, 160, 110);
815 QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group);
816 radio=new QRadioButton(tr("Shift cells &right"), group);
817 radio=new QRadioButton(tr("Entire ro&w"), group);
818 radio=new QRadioButton(tr("Entire &column"), group);
819 group->setButton(0);
820
821 if (dialogInsert.exec()==QDialog::Accepted)
822 switch (group->id(group->selected()))
823 {
824 case 0: sheet->insertRows(1, FALSE); break;
825 case 1: sheet->insertColumns(1, FALSE); break;
826 case 2: sheet->insertRows(1, TRUE); break;
827 case 3: sheet->insertColumns(1, TRUE); break;
828 }
829}
830
831void MainWindow::slotDataFindReplace()
832{
833 FindDialog dialogFind(this);
834 dialogFind.showMaximized();
835 dialogFind.exec(sheet);
836}
diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h
new file mode 100644
index 0000000..ac90504
--- a/dev/null
+++ b/noncore/apps/opie-sheet/mainwindow.h
@@ -0,0 +1,120 @@
1#ifndef MAINWINDOW_H
2#define MAINWINDOW_H
3
4#include <qpe/applnk.h>
5#include <qpe/fileselector.h>
6#include <qpe/qpemenubar.h>
7#include <qpe/qpetoolbar.h>
8#include <qmainwindow.h>
9#include <qaction.h>
10#include <qlineedit.h>
11#include <qbutton.h>
12#include <qcombobox.h>
13#include <qtoolbutton.h>
14
15#include "sheet.h"
16
17typedef struct typeSheet
18{
19 QString name;
20 QList<typeCellData> data;
21};
22
23class MainWindow: public QMainWindow
24{
25 Q_OBJECT
26
27 // QPE objects
28 DocLnk currentDoc;
29 QPEMenuBar *menu;
30 QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard;
31 FileSelector *fileSelector;
32
33 // QT objects
34 QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp,
35 *submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat,
36 *submenuRow, *submenuCol, *submenuSheet;
37 QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells,
38 *funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual,
39 *editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells,
40 *rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove,
41 *dataSort, *dataFindReplace, *editCellSelect, *helpGeneral;
42 QLineEdit *editData;
43 QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight;
44 QComboBox *comboSheets;
45 QToolButton *toolFunction;
46 QList<typeSheet> listSheets;
47 QString helpFile;
48
49 // Other objects
50 Sheet *sheet;
51
52 // Variables
53 bool documentModified;
54
55 // Private functions
56 void initMenu();
57 void initActions();
58 void initFunctionsToolbar();
59 void initEditToolbar();
60 void initStandardToolbar();
61 void initSheet();
62 void addToData(const QString &data);
63 int saveCurrentFile(bool ask=TRUE);
64 void documentOpen(const DocLnk &lnkDoc);
65 void copyDocLnk(const DocLnk &source, DocLnk &target);
66 void documentSave(DocLnk &lnkDoc);
67 void closeEvent(QCloseEvent *e);
68 void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w);
69 typeSheet *createNewSheet();
70 typeSheet *findSheet(const QString &name);
71
72 private slots:
73 void slotFileNew();
74 void slotFileOpen();
75 void slotFileSave();
76 void slotFileSaveAs();
77 void slotHelpAbout();
78 void slotHelpGeneral();
79 void slotEditAccept();
80 void slotEditCancel();
81 void slotEditPaste();
82 void slotEditPasteContents();
83 void slotFormatCells();
84 void slotInsertCells();
85 void slotInsertRows();
86 void slotInsertCols();
87 void slotInsertSheets();
88 void slotDataSort();
89 void slotDataFindReplace();
90 void slotRowHeight();
91 void slotRowAdjust();
92 void slotRowShow();
93 void slotRowHide();
94 void slotColumnWidth();
95 void slotColumnAdjust();
96 void slotColumnShow();
97 void slotColumnHide();
98 void slotSheetRename();
99 void slotSheetRemove();
100 void slotFuncOutput();
101 void slotCellSelect(bool lock);
102 void slotCellClicked(const QString &cell);
103 void slotSheetChanged(const QString &name);
104 void slotDocModified();
105 void selectorShow();
106 void selectorHide();
107 void selectorFileNew(const DocLnk &lnkDoc);
108 void selectorFileOpen(const DocLnk &lnkDoc);
109
110 public:
111 MainWindow();
112 ~MainWindow();
113
114 void setHelpFile(const QString &help_filename) { helpFile=help_filename; }
115
116 public slots:
117 void setDocument(const QString &applnk_filename);
118};
119
120#endif
diff --git a/noncore/apps/opie-sheet/numberdlg.cpp b/noncore/apps/opie-sheet/numberdlg.cpp
new file mode 100644
index 0000000..de84378
--- a/dev/null
+++ b/noncore/apps/opie-sheet/numberdlg.cpp
@@ -0,0 +1,35 @@
1#include "numberdlg.h"
2
3NumberDialog::NumberDialog(QWidget *parent=0)
4 :QDialog(parent, 0, TRUE)
5{
6 edit=new QSpinBox(this);
7 edit->setGeometry(120, 10, 70, 25);
8
9 label=new QLabel(this);
10 label->setGeometry(10, 10, 100, 25);
11 label->setBuddy(edit);
12
13 resize(200, 45);
14}
15
16NumberDialog::~NumberDialog()
17{
18}
19
20int NumberDialog::exec(const QString &caption, const QString &text, int value=1, int min=1, int max=99, int step=1)
21{
22 setCaption(caption);
23 label->setText(text);
24 edit->setValue(value);
25 edit->setMinValue(min);
26 edit->setMaxValue(max);
27 edit->setLineStep(step);
28
29 return QDialog::exec();
30}
31
32int NumberDialog::getValue()
33{
34 return edit->value();
35}
diff --git a/noncore/apps/opie-sheet/numberdlg.h b/noncore/apps/opie-sheet/numberdlg.h
new file mode 100644
index 0000000..46af1d0
--- a/dev/null
+++ b/noncore/apps/opie-sheet/numberdlg.h
@@ -0,0 +1,24 @@
1#ifndef NUMBERDLG_H
2#define NUMBERDLG_H
3
4#include <qdialog.h>
5#include <qlabel.h>
6#include <qspinbox.h>
7
8class NumberDialog: public QDialog
9{
10 Q_OBJECT
11
12 // QT objects
13 QLabel *label;
14 QSpinBox *edit;
15
16 public:
17 NumberDialog(QWidget *parent=0);
18 ~NumberDialog();
19
20 int exec(const QString &caption, const QString &text, int value=1, int min=1, int max=99, int step=1);
21 int getValue();
22};
23
24#endif
diff --git a/noncore/apps/opie-sheet/opie-sheet.control b/noncore/apps/opie-sheet/opie-sheet.control
new file mode 100644
index 0000000..f772247
--- a/dev/null
+++ b/noncore/apps/opie-sheet/opie-sheet.control
@@ -0,0 +1,10 @@
1Files: bin/sheetqt apps/Applications/opie-sheet.desktop help/html/sheetqt.html help/html/sheetqt/* pics/opie-sheet/sheetqt.png
2Priority: optional
3Section: opie/applications
4Maintainer: Serdar Ozler <sozler@sitebest.com>
5Architecture: arm
6Version: 1.0.1
7Depends: opie-base ($QPE_VERSION)
8License: Public Domain
9Description: Opie Sheet
10 Spreadsheet software for Opie.
diff --git a/noncore/apps/opie-sheet/opie-sheet.pro b/noncore/apps/opie-sheet/opie-sheet.pro
new file mode 100644
index 0000000..b053975
--- a/dev/null
+++ b/noncore/apps/opie-sheet/opie-sheet.pro
@@ -0,0 +1,9 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS = mainwindow.h sheet.h cellformat.h finddlg.h numberdlg.h sortdlg.h textdlg.h
5 SOURCES = main.cpp mainwindow.cpp sheet.cpp cellformat.cpp finddlg.cpp numberdlg.cpp sortdlg.cpp textdlg.cpp
6 INCLUDEPATH+= $(OPIEDIR)/include
7 DEPENDPATH+= $(OPIEDIR)/include
8LIBS += -lqpe
9 TARGET = sheetqt
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp
new file mode 100644
index 0000000..9526937
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sheet.cpp
@@ -0,0 +1,849 @@
1#include "sheet.h"
2
3#include <qmainwindow.h>
4#include <qmessagebox.h>
5#include <math.h>
6
7#define DEFAULT_COL_WIDTH 50
8
9Sheet::Sheet(int numRows, int numCols, QWidget *parent)
10 :QTable(numRows, numCols, parent)
11{
12 defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine);
13 defaultCellData.data="";
14 defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern);
15 defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop);
16 defaultCellData.fontColor=Qt::black;
17 defaultCellData.font=font();
18 defaultCellData.borders=defaultBorders;
19
20 selectionNo=-1;
21 setSelectionMode(QTable::Single);
22
23 sheetData.setAutoDelete(TRUE);
24 clipboardData.setAutoDelete(TRUE);
25 for (int i=0; i<numCols; ++i)
26 horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH);
27
28 connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int)));
29 connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int)));
30}
31
32Sheet::~Sheet()
33{
34}
35
36typeCellData *Sheet::findCellData(int row, int col)
37{
38 typeCellData *tempCellData;
39 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
40 if (tempCellData->row==row && tempCellData->col==col)
41 return tempCellData;
42 return NULL;
43}
44
45void Sheet::slotCellSelected(int row, int col)
46{
47 typeCellData *cellData=findCellData(row, col);
48 if (cellData)
49 emit currentDataChanged(cellData->data);
50 else
51 emit currentDataChanged("");
52}
53
54typeCellData *Sheet::createCellData(int row, int col)
55{
56 if (row<0 || col<0) return NULL;
57 typeCellData *cellData=new typeCellData;
58 cellData->row=row;
59 cellData->col=col;
60 cellData->data=defaultCellData.data;
61 cellData->borders=defaultCellData.borders;
62 cellData->alignment=defaultCellData.alignment;
63 cellData->font=defaultCellData.font;
64 cellData->fontColor=defaultCellData.fontColor;
65 cellData->background=defaultCellData.background;
66 sheetData.append(cellData);
67 return cellData;
68}
69
70void Sheet::slotCellChanged(int row, int col)
71{
72 typeCellData *cellData=findCellData(row, col);
73 if (!cellData) cellData=createCellData(row, col);
74 if (cellData) cellData->data=text(row, col);
75 for (cellData=sheetData.first(); cellData; cellData=sheetData.next())
76 setText(cellData->row, cellData->col, dataParser(cellData->data));
77 emit sheetModified();
78}
79
80void Sheet::swapCells(int row1, int col1, int row2, int col2)
81{
82 typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2);
83 if (!cellData1) cellData1=createCellData(row1, col1);
84 if (!cellData2) cellData2=createCellData(row2, col2);
85 if (cellData1 && cellData2)
86 {
87 QString tempData(cellData1->data);
88 cellData1->data=cellData2->data;
89 cellData2->data=tempData;
90 setText(cellData1->row, cellData1->col, dataParser(cellData1->data));
91 setText(cellData2->row, cellData2->col, dataParser(cellData2->data));
92 emit sheetModified();
93 }
94}
95
96QString Sheet::getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName="")
97{
98 QString params(parameters);
99 int position;
100 for (int i=0; i<paramNo; ++i)
101 {
102 position=params.find(',');
103 if (position<0)
104 {
105 if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\''));
106 return QString();
107 }
108 params=params.mid(position+1);
109 }
110 position=params.find(',');
111 if (position<0) return params;
112 return params.left(position);
113}
114
115bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2)
116{
117 int row, col;
118 if (!findRowColumn(variable1, row1, col1, TRUE) || !findRowColumn(variable2, row2, col2, TRUE)) return FALSE;
119 if (*row1>*row2)
120 {
121 row=*row1;
122 *row1=*row2;
123 *row2=row;
124 }
125 if (*col1>*col2)
126 {
127 col=*col1;
128 *col1=*col2;
129 *col2=col;
130 }
131 return TRUE;
132}
133
134bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE)
135{
136 int position=variable.find(QRegExp("\\d"));
137 if (position<1)
138 {
139 if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\''));
140 return FALSE;
141 }
142 *row=variable.mid(position).toInt()-1;
143 *col=getHeaderColumn(variable.left(position))-1;
144 return TRUE;
145}
146
147double Sheet::calculateVariable(const QString &variable)
148{
149 bool ok;
150 double tempResult=variable.toDouble(&ok);
151 if (ok) return tempResult;
152
153 int row, col;
154 return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0);
155}
156
157double Sheet::functionSum(const QString &param1, const QString &param2)
158{
159 int row1, col1, row2, col2, row, col;
160 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
161
162 double result=0, tempResult;
163 bool ok;
164 for (row=row1; row<=row2; ++row)
165 for (col=col1; col<=col2; ++col)
166 {
167 tempResult=text(row, col).toDouble(&ok);
168 if (ok) result+=tempResult;
169 }
170
171 return result;
172}
173
174double Sheet::functionMin(const QString &param1, const QString &param2)
175{
176 int row1, col1, row2, col2, row, col;
177 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
178
179 double min=0, tempMin;
180 bool ok, init=FALSE;
181 for (row=row1; row<=row2; ++row)
182 for (col=col1; col<=col2; ++col)
183 {
184 tempMin=text(row, col).toDouble(&ok);
185 if (ok && (!init || tempMin<min))
186 {
187 min=tempMin;
188 init=TRUE;
189 }
190 }
191
192 return min;
193}
194
195double Sheet::functionMax(const QString &param1, const QString &param2)
196{
197 int row1, col1, row2, col2, row, col;
198 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
199
200 double max=0, tempMax;
201 bool ok, init=FALSE;
202 for (row=row1; row<=row2; ++row)
203 for (col=col1; col<=col2; ++col)
204 {
205 tempMax=text(row, col).toDouble(&ok);
206 if (ok && (!init || tempMax>max))
207 {
208 max=tempMax;
209 init=TRUE;
210 }
211 }
212
213 return max;
214}
215
216double Sheet::functionAvg(const QString &param1, const QString &param2)
217{
218 double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2);
219 return (resultCount>0 ? resultSum/resultCount : 0);
220}
221
222double Sheet::functionCount(const QString &param1, const QString &param2)
223{
224 int row1, col1, row2, col2, row, col;
225 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
226
227 int divider=0;
228 bool ok;
229 for (row=row1; row<=row2; ++row)
230 for (col=col1; col<=col2; ++col)
231 {
232 text(row, col).toDouble(&ok);
233 if (ok) ++divider;
234 }
235
236 return divider;
237}
238
239double Sheet::calculateFunction(const QString &function, const QString &parameters)
240{
241 if (function=="+")
242 return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1));
243 if (function=="-")
244 return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1));
245 if (function=="*")
246 return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1));
247 if (function=="/")
248 return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1));
249 if (function=="SUM")
250 return functionSum(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
251 if (function=="COUNT")
252 return functionCount(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
253 if (function=="MIN")
254 return functionMin(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
255 if (function=="MAX")
256 return functionMax(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
257 if (function=="AVG")
258 return functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
259 if (function=="ABS")
260 return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)));
261 if (function=="SIN")
262 return sin(calculateVariable(getParameter(parameters, 0, TRUE, function)));
263 if (function=="COS")
264 return cos(calculateVariable(getParameter(parameters, 0, TRUE, function)));
265 if (function=="TAN")
266 return tan(calculateVariable(getParameter(parameters, 0, TRUE, function)));
267 if (function=="ATAN")
268 return atan(calculateVariable(getParameter(parameters, 0, TRUE, function)));
269 if (function=="ATAN2")
270 return atan2(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function)));
271 if (function=="ASIN")
272 return asin(calculateVariable(getParameter(parameters, 0, TRUE, function)));
273 if (function=="ACOS")
274 return acos(calculateVariable(getParameter(parameters, 0, TRUE, function)));
275 if (function=="EXP")
276 return exp(calculateVariable(getParameter(parameters, 0, TRUE, function)));
277 if (function=="LOG")
278 return log(calculateVariable(getParameter(parameters, 0, TRUE, function)));
279 if (function=="POW")
280 return pow(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function)));
281 return 0;
282}
283
284int Sheet::getOperatorPriority(char oper)
285{
286 switch (oper)
287 {
288 case '+':
289 case '-':
290 return 1;
291
292 case '*':
293 case '/':
294 return 2;
295 }
296 return 0;
297}
298
299void Sheet::pushCharStack(QStack<QChar> *stackChars, const QChar &character)
300{
301 QChar *temp=new QChar(character);
302 stackChars->push(temp);
303}
304
305void Sheet::pushStringStack(QStack<QString> *stackStrings, const QString &string)
306{
307 QString *temp=new QString(string);
308 stackStrings->push(temp);
309}
310
311QChar Sheet::popCharStack(QStack<QChar> *stackChars)
312{
313 if (stackChars->isEmpty())
314 {
315 QMessageBox::critical(this, tr("Error"), tr("Syntax error!"));
316 return '0';
317 }
318
319 QChar *temp=stackChars->pop();
320 QChar temp2(*temp);
321 delete temp;
322 return temp2;
323}
324
325QString Sheet::popStringStack(QStack<QString> *stackStrings)
326{
327 if (stackStrings->isEmpty())
328 {
329 QMessageBox::critical(this, tr("Error"), tr("Syntax error!"));
330 return "0";
331 }
332
333 QString *temp=stackStrings->pop();
334 QString temp2(*temp);
335 delete temp;
336 return temp2;
337}
338
339QString Sheet::dataParserHelper(const QString &data)
340{
341 QStack<QString> stackElements;
342 QStack<QChar> stackOperators;
343 QString tempElement(""), temp2Element, firstElement, secondElement;
344 int paranCount;
345
346 for (unsigned int i=0; i<data.length(); ++i)
347 {
348 if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/')
349 {
350 pushStringStack(&stackElements, tempElement);
351 tempElement="";
352 if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i]))
353 {
354 secondElement=popStringStack(&stackElements);
355 firstElement=popStringStack(&stackElements);
356 pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement)));
357 }
358 pushCharStack(&stackOperators, data[i]);
359 }
360 else
361 if (data[i]==',')
362 {
363 if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement);
364 while (!stackOperators.isEmpty())
365 {
366 secondElement=popStringStack(&stackElements);
367 firstElement=popStringStack(&stackElements);
368 pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement)));
369 }
370 tempElement="";
371 }
372 else
373 if (data[i]=='(')
374 {
375 paranCount=1;
376 temp2Element="";
377 for (++i; paranCount>0; ++i)
378 {
379 temp2Element+=data[i];
380 if (data[i]=='(') ++paranCount;
381 if (data[i]==')') --paranCount;
382 }
383 temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1));
384 if (tempElement.isEmpty())
385 tempElement=temp2Element;
386 else
387 tempElement.setNum(calculateFunction(tempElement, temp2Element));
388 --i;
389 }
390 else
391 tempElement+=data[i];
392 }
393 if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement);
394 while (!stackOperators.isEmpty())
395 {
396 secondElement=popStringStack(&stackElements);
397 firstElement=popStringStack(&stackElements);
398 pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement)));
399 }
400
401 if (!stackElements.isEmpty())
402 tempElement=popStringStack(&stackElements);
403 while (!stackElements.isEmpty())
404 tempElement.prepend(popStringStack(&stackElements)+",");
405 return tempElement;
406}
407
408QString Sheet::dataParser(const QString &data)
409{
410 QString strippedData(data);
411 strippedData.replace(QRegExp("\\s"), "");
412 if (strippedData.isEmpty() || strippedData[0]!='=') return data;
413 strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ","));
414
415 int i=0;
416 QString tempParameter(getParameter(strippedData, i)), result="";
417 do
418 {
419 result+=","+QString::number(calculateVariable(tempParameter));
420 tempParameter=getParameter(strippedData, ++i);
421 }
422 while (!tempParameter.isNull());
423 return result.mid(1);
424}
425
426void Sheet::setData(const QString &data)
427{
428 setText(currentRow(), currentColumn(), data);
429 slotCellChanged(currentRow(), currentColumn());
430 activateNextCell();
431}
432
433QString Sheet::getData()
434{
435 typeCellData *cellData=findCellData(currentRow(), currentColumn());
436 if (cellData)
437 return cellData->data;
438 return "";
439}
440
441void Sheet::lockClicks(bool lock=TRUE)
442{
443 clicksLocked=lock;
444}
445
446void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected)
447{
448 if (selected && row==currentRow() && col==currentColumn()) selected=FALSE;
449
450 int sheetDataCurrent=sheetData.at();
451 typeCellData *cellData=findCellData(row, col);
452 if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent);
453 if (!cellData) cellData=&defaultCellData;
454 if (selected)
455 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight());
456 else
457 {
458 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base());
459 p->fillRect(0, 0, cr.width(), cr.height(), cellData->background);
460 }
461
462 QTableItem *cellItem=item(row, col);
463 if (cellItem)
464 {
465 p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor);
466 p->setFont(cellData->font);
467 p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text());
468 }
469
470 int rx=cr.width()-1, ry=cr.height()-1;
471 QPen pen(p->pen());
472 p->setPen(cellData->borders.right);
473 p->drawLine(rx, 0, rx, ry);
474 p->setPen(cellData->borders.bottom);
475 p->drawLine(0, ry, rx, ry);
476 p->setPen(pen);
477}
478
479void Sheet::viewportMousePressEvent(QMouseEvent *e)
480{
481 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
482 if (clicksLocked)
483 {
484 if (selectionNo<0)
485 {
486 clearSelection();
487 QTableSelection newSelection;
488 newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
489 newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol());
490 selectionNo=addSelection(newSelection);
491 }
492 }
493 else
494 QTable::contentsMousePressEvent(&ce);
495}
496
497void Sheet::viewportMouseMoveEvent(QMouseEvent *e)
498{
499 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
500 if (clicksLocked)
501 {
502 if (selectionNo>=0)
503 {
504 QTableSelection oldSelection(selection(selectionNo));
505 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
506 if (!(oldSelection==selection(selectionNo)))
507 {
508 removeSelection(selectionNo);
509 selectionNo=addSelection(oldSelection);
510 }
511 }
512 }
513 else
514 QTable::contentsMouseMoveEvent(&ce);
515}
516
517void Sheet::viewportMouseReleaseEvent(QMouseEvent *e)
518{
519 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
520 if (clicksLocked && selectionNo>=0)
521 {
522 QTableSelection oldSelection(selection(selectionNo));
523 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
524 removeSelection(selectionNo);
525 selectionNo=-1;
526 if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol())
527 emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1));
528 else
529 emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)+','+getHeaderString(oldSelection.rightCol()+1)+QString::number(oldSelection.bottomRow()+1));
530 }
531 else
532 QTable::contentsMouseReleaseEvent(&ce);
533}
534
535void Sheet::copySheetData(QList<typeCellData> *destSheetData)
536{
537 typeCellData *tempCellData, *newCellData;
538 destSheetData->clear();
539
540 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
541 {
542 newCellData=new typeCellData;
543 *newCellData=*tempCellData;
544 destSheetData->append(newCellData);
545 }
546}
547
548void Sheet::setSheetData(QList<typeCellData> *srcSheetData)
549{
550 typeCellData *tempCellData, *newCellData;
551
552 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
553 {
554 clearCell(tempCellData->row, tempCellData->col);
555 updateCell(tempCellData->row, tempCellData->col);
556 }
557 sheetData.clear();
558
559 for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next())
560 {
561 newCellData=new typeCellData;
562 *newCellData=*tempCellData;
563 sheetData.append(newCellData);
564 setText(newCellData->row, newCellData->col, dataParser(newCellData->data));
565 }
566 emit sheetModified();
567}
568
569void Sheet::setName(const QString &name)
570{
571 sheetName=name;
572 emit sheetModified();
573}
574
575QString Sheet::getName()
576{
577 return sheetName;
578}
579
580void Sheet::setBrush(int row, int col, const QBrush &brush)
581{
582 typeCellData *cellData=findCellData(row, col);
583 if (!cellData) cellData=createCellData(row, col);
584 if (cellData)
585 {
586 cellData->background=brush;
587 emit sheetModified();
588 }
589}
590
591QBrush Sheet::getBrush(int row, int col)
592{
593 typeCellData *cellData=findCellData(row, col);
594 if (!cellData) cellData=&defaultCellData;
595 return cellData->background;
596}
597
598void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags)
599{
600 typeCellData *cellData=findCellData(row, col);
601 if (!cellData) cellData=createCellData(row, col);
602 if (cellData)
603 {
604 cellData->alignment=flags;
605 emit sheetModified();
606 }
607}
608
609Qt::AlignmentFlags Sheet::getAlignment(int row, int col)
610{
611 typeCellData *cellData=findCellData(row, col);
612 if (!cellData) cellData=&defaultCellData;
613 return cellData->alignment;
614}
615
616void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color)
617{
618 typeCellData *cellData=findCellData(row, col);
619 if (!cellData) cellData=createCellData(row, col);
620 if (cellData)
621 {
622 cellData->font=font;
623 cellData->fontColor=color;
624 emit sheetModified();
625 }
626}
627
628QFont Sheet::getFont(int row, int col)
629{
630 typeCellData *cellData=findCellData(row, col);
631 if (!cellData) cellData=&defaultCellData;
632 return cellData->font;
633}
634
635QColor Sheet::getFontColor(int row, int col)
636{
637 typeCellData *cellData=findCellData(row, col);
638 if (!cellData) cellData=&defaultCellData;
639 return cellData->fontColor;
640}
641
642void Sheet::setPen(int row, int col, int vertical, const QPen &pen)
643{
644 typeCellData *cellData=findCellData(row, col);
645 if (!cellData) cellData=createCellData(row, col);
646 if (cellData)
647 {
648 if (vertical)
649 cellData->borders.right=pen;
650 else
651 cellData->borders.bottom=pen;
652 emit sheetModified();
653 }
654}
655
656QPen Sheet::getPen(int row, int col, int vertical)
657{
658 typeCellData *cellData=findCellData(row, col);
659 if (!cellData) cellData=&defaultCellData;
660 return (vertical ? cellData->borders.right : cellData->borders.bottom);
661}
662
663void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2)
664{
665 int selectionNo=currentSelection();
666 if (selectionNo>=0)
667 {
668 QTableSelection selection(selection(selectionNo));
669 *row1=selection.topRow();
670 *row2=selection.bottomRow();
671 *col1=selection.leftCol();
672 *col2=selection.rightCol();
673 }
674 else
675 {
676 *row1=*row2=currentRow();
677 *col1=*col2=currentColumn();
678 }
679}
680
681void Sheet::editClear()
682{
683 int row1, row2, col1, col2;
684 getSelection(&row1, &col1, &row2, &col2);
685
686 int row, col;
687 for (row=row1; row<=row2; ++row)
688 for (col=col1; col<=col2; ++col)
689 {
690 setText(row, col, "");
691 slotCellChanged(row, col);
692 }
693}
694
695void Sheet::editCopy()
696{
697 clipboardData.clear();
698
699 int row1, row2, col1, col2;
700 getSelection(&row1, &col1, &row2, &col2);
701
702 typeCellData *cellData, *newCellData;
703 int row, col;
704 for (row=row1; row<=row2; ++row)
705 for (col=col1; col<=col2; ++col)
706 {
707 cellData=findCellData(row, col);
708 if (cellData)
709 {
710 newCellData=new typeCellData;
711 *newCellData=*cellData;
712 newCellData->row-=row1;
713 newCellData->col-=col1;
714 clipboardData.append(newCellData);
715 }
716 }
717}
718
719void Sheet::editCut()
720{
721 editCopy();
722 editClear();
723}
724
725void Sheet::editPaste(bool onlyContents=FALSE)
726{
727 int row1=currentRow(), col1=currentColumn();
728 typeCellData *cellData, *tempCellData;
729
730 for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next())
731 {
732 cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1);
733 if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1);
734 if (cellData)
735 {
736 if (onlyContents)
737 cellData->data=tempCellData->data;
738 else
739 {
740 *cellData=*tempCellData;
741 cellData->row+=row1;
742 cellData->col+=col1;
743 }
744 setText(cellData->row, cellData->col, dataParser(cellData->data));
745 emit sheetModified();
746 }
747 }
748}
749
750void Sheet::insertRows(int no=1, bool allColumns=TRUE)
751{
752 setNumRows(numRows()+no);
753
754 typeCellData *tempCellData;
755 int row=currentRow(), col=currentColumn();
756
757 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
758 if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
759 {
760 clearCell(tempCellData->row, tempCellData->col);
761 tempCellData->row+=no;
762 }
763 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
764 if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
765 {
766 updateCell(tempCellData->row-no, tempCellData->col);
767 setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
768 }
769 emit sheetModified();
770}
771
772void Sheet::insertColumns(int no=1, bool allRows=TRUE)
773{
774 int noCols=numCols();
775 int newCols=noCols+no;
776 setNumCols(newCols);
777 for (int i=noCols; i<newCols; ++i)
778 horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH);
779
780 typeCellData *tempCellData;
781 int col=currentColumn(), row=currentRow();
782
783 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
784 if (tempCellData->col>=col && (allRows || tempCellData->row==row))
785 {
786 clearCell(tempCellData->row, tempCellData->col);
787 tempCellData->col+=no;
788 }
789 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
790 if (tempCellData->col>=col && (allRows || tempCellData->row==row))
791 {
792 updateCell(tempCellData->row, tempCellData->col-no);
793 setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
794 }
795 emit sheetModified();
796}
797
798void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE)
799{
800 typeCellData *tempCellData;
801 int row1, col1, row2, col2;
802 getSelection(&row1, &col1, &row2, &col2);
803 bool found=FALSE;
804
805 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
806 if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2))
807 {
808 QTableItem *cellItem=item(tempCellData->row, tempCellData->col);
809 if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0))
810 {
811 if (!found)
812 {
813 found=TRUE;
814 clearSelection();
815 }
816 setCurrentCell(tempCellData->row, tempCellData->col);
817 if (replace)
818 {
819 tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr);
820 setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
821 }
822 if (!replace || !replaceAll) break;
823 }
824 }
825
826 if (found)
827 {
828 if (replace)
829 slotCellChanged(currentRow(), currentColumn());
830 }
831 else
832 QMessageBox::warning(this, tr("Error"), tr("Search key not found!"));
833}
834
835//
836// Static functions
837//
838
839QString Sheet::getHeaderString(int section)
840{
841 if (section<1) return "";
842 return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26);
843}
844
845int Sheet::getHeaderColumn(const QString &section)
846{
847 if (section.isEmpty()) return 0;
848 return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26;
849}
diff --git a/noncore/apps/opie-sheet/sheet.h b/noncore/apps/opie-sheet/sheet.h
new file mode 100644
index 0000000..02899a0
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sheet.h
@@ -0,0 +1,120 @@
1#ifndef SHEET_H
2#define SHEET_H
3
4#include <qtable.h>
5#include <qstack.h>
6
7typedef struct typeCellBorders
8{
9 QPen right, bottom;
10};
11
12typedef struct typeCellData
13{
14 int col, row;
15 typeCellBorders borders;
16 QBrush background;
17 Qt::AlignmentFlags alignment;
18 QColor fontColor;
19 QFont font;
20 QString data;
21};
22
23class Sheet: public QTable
24{
25 Q_OBJECT
26
27 // Variables
28 bool clicksLocked;
29 int selectionNo;
30 typeCellBorders defaultBorders;
31 typeCellData defaultCellData;
32
33 // QT objects
34 QList<typeCellData> sheetData, clipboardData;
35 QString pressedCell, releasedCell, sheetName;
36
37 // Private functions
38 int getOperatorPriority(char oper);
39 bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE);
40 bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2);
41 double calculateVariable(const QString &variable);
42 double calculateFunction(const QString &function, const QString &parameters);
43 QChar popCharStack(QStack<QChar> *stackChars);
44 QString popStringStack(QStack<QString> *stackStrings);
45 QString getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName="");
46 QString dataParser(const QString &data);
47 QString dataParserHelper(const QString &data);
48 typeCellData *createCellData(int row, int col);
49 typeCellData *findCellData(int row, int col);
50 void pushCharStack(QStack<QChar> *stackChars, const QChar &character);
51 void pushStringStack(QStack<QString> *stackStrings, const QString &string);
52
53 // Sheet/Qt parser functions
54 double functionSum(const QString &param1, const QString &param2);
55 double functionAvg(const QString &param1, const QString &param2);
56 double functionMax(const QString &param1, const QString &param2);
57 double functionMin(const QString &param1, const QString &param2);
58 double functionCount(const QString &param1, const QString &param2);
59
60 // Reimplemented QTable functions
61 void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected);
62 void viewportMousePressEvent(QMouseEvent *e);
63 void viewportMouseMoveEvent(QMouseEvent *e);
64 void viewportMouseReleaseEvent(QMouseEvent *e);
65
66 private slots:
67 void slotCellSelected(int row, int col);
68 void slotCellChanged(int row, int col);
69
70 public:
71 Sheet(int numRows, int numCols, QWidget *parent);
72 ~Sheet();
73
74 void setData(const QString &data);
75 QString getData();
76
77 void setName(const QString &data);
78 QString getName();
79
80 void setPen(int row, int col, int vertical, const QPen &pen);
81 QPen getPen(int row, int col, int vertical);
82
83 void setBrush(int row, int col, const QBrush &brush);
84 QBrush getBrush(int row, int col);
85
86 void setTextAlign(int row, int col, Qt::AlignmentFlags flags);
87 Qt::AlignmentFlags getAlignment(int row, int col);
88
89 void setTextFont(int row, int col, const QFont &font, const QColor &color);
90 QFont getFont(int row, int col);
91 QColor getFontColor(int row, int col);
92
93 void lockClicks(bool lock=TRUE);
94 void copySheetData(QList<typeCellData> *destSheetData);
95 void setSheetData(QList<typeCellData> *srcSheetData);
96 void getSelection(int *row1, int *col1, int *row2, int *col2);
97
98 void insertRows(int no=1, bool allColumns=TRUE);
99 void insertColumns(int no=1, bool allRows=TRUE);
100
101 void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE);
102
103 // Static functions
104 static int getHeaderColumn(const QString &section);
105 static QString getHeaderString(int section);
106
107 public slots:
108 void editCut();
109 void editCopy();
110 void editPaste(bool onlyContents=FALSE);
111 void editClear();
112 void swapCells(int row1, int col1, int row2, int col2);
113
114 signals:
115 void currentDataChanged(const QString &data);
116 void cellClicked(const QString &cell);
117 void sheetModified();
118};
119
120#endif
diff --git a/noncore/apps/opie-sheet/sortdlg.cpp b/noncore/apps/opie-sheet/sortdlg.cpp
new file mode 100644
index 0000000..f46562e
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sortdlg.cpp
@@ -0,0 +1,178 @@
1#include <qlabel.h>
2#include <qradiobutton.h>
3#include <qmessagebox.h>
4#include "sortdlg.h"
5
6SortDialog::SortDialog(QWidget *parent=0)
7 :QDialog(parent, 0, TRUE)
8{
9 // Main widget
10 tabs=new QTabWidget(this);
11 widgetSort=new QWidget(tabs);
12 widgetOptions=new QWidget(tabs);
13 tabs->addTab(widgetSort, tr("&Sort"));
14 tabs->addTab(widgetOptions, tr("&Options"));
15
16 // Sort tab
17 comboFieldA=createFieldCombo(tr("&Sort by"), 10);
18 groupOrderA=createOrderButtons(10);
19 comboFieldB=createFieldCombo(tr("&Then by"), 90);
20 groupOrderB=createOrderButtons(90);
21 comboFieldC=createFieldCombo(tr("Then &by"), 170);
22 groupOrderC=createOrderButtons(170);
23
24 // Options tab
25 checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions);
26 checkCase->setGeometry(10, 10, 215, 20);
27 checkCase->setChecked(TRUE);
28
29 groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions);
30 groupDirection->setGeometry(10, 40, 215, 70);
31 QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection);
32 radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection);
33 groupDirection->setButton(0);
34 connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int)));
35
36 // Main widget
37 box=new QVBoxLayout(this);
38 box->addWidget(tabs);
39
40 setCaption(tr("Sort"));
41}
42
43SortDialog::~SortDialog()
44{
45}
46
47QComboBox *SortDialog::createFieldCombo(const QString &caption, int y)
48{
49 QLabel *label=new QLabel(caption, widgetSort);
50 label->setGeometry(10, y+5, 215, 20);
51 QComboBox *combo=new QComboBox(FALSE, widgetSort);
52 combo->setGeometry(10, y+35, 105, 20);
53 label->setBuddy(combo);
54 return combo;
55}
56
57QVButtonGroup *SortDialog::createOrderButtons(int y)
58{
59 QVButtonGroup *group=new QVButtonGroup(widgetSort);
60 group->setGeometry(125, y, 100, 60);
61 QRadioButton *radio=new QRadioButton(tr("&Ascending"), group);
62 radio=new QRadioButton(tr("&Descending"), group);
63 group->setButton(0);
64 return group;
65}
66
67void SortDialog::directionChanged(int id)
68{
69 direction=id;
70 fillFieldCombo(comboFieldA);
71 fillFieldCombo(comboFieldB);
72 fillFieldCombo(comboFieldC);
73}
74
75void SortDialog::fillFieldCombo(QComboBox *combo)
76{
77 combo->clear();
78 if (direction)
79 for (int row=row1; row<=row2; ++row)
80 combo->insertItem("Row "+QString::number(row+1));
81 else
82 for (int col=col1; col<=col2; ++col)
83 combo->insertItem("Column "+Sheet::getHeaderString(col+1));
84}
85
86int SortDialog::exec(Sheet *s)
87{
88 sheet=s;
89 sheet->getSelection(&row1, &col1, &row2, &col2);
90
91 direction=0;
92 fillFieldCombo(comboFieldA);
93 fillFieldCombo(comboFieldB);
94 fillFieldCombo(comboFieldC);
95
96 if (row1==row2 && col1==col2)
97 {
98 QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!"));
99 return QDialog::Rejected;
100 }
101 if (QDialog::exec()==QDialog::Accepted)
102 {
103 QString field1S=comboFieldA->currentText(), field2S=comboFieldA->currentText(), field3S=comboFieldA->currentText();
104 field1S=field1S.mid(field1S.find(' ')+1);
105 field2S=field2S.mid(field2S.find(' ')+1);
106 field3S=field3S.mid(field3S.find(' ')+1);
107 int field1, field2, field3;
108 if (direction)
109 {
110 field1=field1S.toInt()-1;
111 field2=field2S.toInt()-1;
112 field3=field3S.toInt()-1;
113 int i, j;
114 for (i=col2; i>=col1; --i)
115 for (j=col1+1; j<=i; ++j)
116 {
117 bool swap=FALSE;
118 int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
119 if (compareResult>0) swap=TRUE;
120 else if (compareResult==0)
121 {
122 compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked());
123 if (compareResult>0) swap=TRUE;
124 else if (compareResult==0)
125 {
126 compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked());
127 if (compareResult>0) swap=TRUE;
128 }
129 }
130 if (swap)
131 for (int row=row1; row<=row2; ++row)
132 s->swapCells(row, j-1, row, j);
133 }
134 }
135 else
136 {
137 field1=Sheet::getHeaderColumn(field1S)-1;
138 field2=Sheet::getHeaderColumn(field2S)-1;
139 field3=Sheet::getHeaderColumn(field3S)-1;
140 int i, j;
141 for (i=row2; i>=row1; --i)
142 for (j=row1+1; j<=i; ++j)
143 {
144 bool swap=FALSE;
145 int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
146 if (compareResult>0) swap=TRUE;
147 else if (compareResult==0)
148 {
149 compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked());
150 if (compareResult>0) swap=TRUE;
151 else if (compareResult==0)
152 {
153 compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked());
154 if (compareResult>0) swap=TRUE;
155 }
156 }
157 if (swap)
158 for (int col=col1; col<=col2; ++col)
159 s->swapCells(j-1, col, j, col);
160 }
161 }
162 return QDialog::Accepted;
163 }
164 return QDialog::Rejected;
165}
166
167int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE)
168{
169 int result=0;
170 if (item1)
171 {
172 if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper()));
173 else result=-1;
174 }
175 else
176 if (item2) result=1;
177 return (descending ? -result : result);
178}
diff --git a/noncore/apps/opie-sheet/sortdlg.h b/noncore/apps/opie-sheet/sortdlg.h
new file mode 100644
index 0000000..2c99f02
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sortdlg.h
@@ -0,0 +1,45 @@
1#ifndef SORTDLG_H
2#define SORTDLG_H
3
4#include <qdialog.h>
5#include <qtabwidget.h>
6#include <qlayout.h>
7#include <qcombobox.h>
8#include <qcheckbox.h>
9#include <qpushbutton.h>
10#include <qvbuttongroup.h>
11#include "sheet.h"
12
13class SortDialog: public QDialog
14{
15 Q_OBJECT
16
17 // QT objects
18 QBoxLayout *box;
19 QTabWidget *tabs;
20 QWidget *widgetSort, *widgetOptions;
21 QVButtonGroup *groupOrderA, *groupOrderB, *groupOrderC, *groupDirection;
22 QCheckBox *checkCase;
23 QComboBox *comboFieldA, *comboFieldB, *comboFieldC;
24
25 // Other objects & variables
26 int row1, col1, row2, col2, direction;
27 Sheet *sheet;
28
29 // Private functions
30 QVButtonGroup *createOrderButtons(int y);
31 QComboBox *createFieldCombo(const QString &caption, int y);
32 void fillFieldCombo(QComboBox *combo);
33 int compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE);
34
35 private slots:
36 void directionChanged(int id);
37
38 public:
39 SortDialog(QWidget *parent=0);
40 ~SortDialog();
41
42 int exec(Sheet *s);
43};
44
45#endif
diff --git a/noncore/apps/opie-sheet/textdlg.cpp b/noncore/apps/opie-sheet/textdlg.cpp
new file mode 100644
index 0000000..8245fe4
--- a/dev/null
+++ b/noncore/apps/opie-sheet/textdlg.cpp
@@ -0,0 +1,32 @@
1#include "textdlg.h"
2
3TextDialog::TextDialog(QWidget *parent=0)
4 :QDialog(parent, 0, TRUE)
5{
6 edit=new QLineEdit(this);
7 edit->setGeometry(90, 10, 100, 25);
8
9 label=new QLabel(this);
10 label->setGeometry(10, 10, 70, 25);
11 label->setBuddy(edit);
12
13 resize(200, 45);
14}
15
16TextDialog::~TextDialog()
17{
18}
19
20int TextDialog::exec(const QString &caption, const QString &text, const QString &value="")
21{
22 setCaption(caption);
23 label->setText(text);
24 edit->setText(value);
25
26 return QDialog::exec();
27}
28
29QString TextDialog::getValue()
30{
31 return edit->text();
32}
diff --git a/noncore/apps/opie-sheet/textdlg.h b/noncore/apps/opie-sheet/textdlg.h
new file mode 100644
index 0000000..f948228
--- a/dev/null
+++ b/noncore/apps/opie-sheet/textdlg.h
@@ -0,0 +1,24 @@
1#ifndef TEXTDLG_H
2#define TEXTDLG_H
3
4#include <qdialog.h>
5#include <qlabel.h>
6#include <qlineedit.h>
7
8class TextDialog: public QDialog
9{
10 Q_OBJECT
11
12 // QT objects
13 QLabel *label;
14 QLineEdit *edit;
15
16 public:
17 TextDialog(QWidget *parent=0);
18 ~TextDialog();
19
20 int exec(const QString &caption, const QString &text, const QString &value="");
21 QString getValue();
22};
23
24#endif
diff --git a/pics/opie-sheet/sheetqt.png b/pics/opie-sheet/sheetqt.png
new file mode 100644
index 0000000..9b4be29
--- a/dev/null
+++ b/pics/opie-sheet/sheetqt.png
Binary files differ