summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/mainwindow.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-sheet/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp836
1 files changed, 836 insertions, 0 deletions
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}