-rw-r--r-- | noncore/apps/opie-sheet/ChangeLog | 11 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/opie-sheet.control | 2 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 32 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.h | 4 |
5 files changed, 36 insertions, 16 deletions
diff --git a/noncore/apps/opie-sheet/ChangeLog b/noncore/apps/opie-sheet/ChangeLog index c12a6db..90060e2 100644 --- a/noncore/apps/opie-sheet/ChangeLog +++ b/noncore/apps/opie-sheet/ChangeLog | |||
@@ -1,25 +1,34 @@ | |||
1 | October 08, 2002 | ||
2 | |||
3 | * Release 1.0.2 (by thufir) | ||
4 | - Fixed bug #250 (exhibiting re-calculation error in multi-level calculation). (by thufir) | ||
5 | |||
6 | October 06, 2002 | ||
7 | |||
8 | - Fixed data edit box clear problem. (by thufir) | ||
9 | |||
1 | October 05, 2002 | 10 | October 05, 2002 |
2 | 11 | ||
3 | - Fixed bug #252. (by thufir) | 12 | - Fixed bug #252 (starting up in 'mouse button' mode). (by thufir) |
4 | 13 | ||
5 | August 31, 2002 | 14 | August 31, 2002 |
6 | 15 | ||
7 | - Fixed and updated opie-sheet.pro file. (by cniehaus) | 16 | - Fixed and updated opie-sheet.pro file. (by cniehaus) |
8 | 17 | ||
9 | August 01, 2002 | 18 | August 01, 2002 |
10 | 19 | ||
11 | - Fixed gcc3 compile problems. (by harlekin) | 20 | - Fixed gcc3 compile problems. (by harlekin) |
12 | 21 | ||
13 | July 06, 2002 | 22 | July 06, 2002 |
14 | 23 | ||
15 | - Fixed DocLnk management to save documents correctly. (by leseb) | 24 | - Fixed DocLnk management to save documents correctly. (by leseb) |
16 | 25 | ||
17 | July 04, 2002 | 26 | July 04, 2002 |
18 | 27 | ||
19 | * Release 1.0.1 (by thufir) | 28 | * Release 1.0.1 (by thufir) |
20 | - Sheet/Qt is now a part of Opie, so its name is changed to Opie Sheet. (by thufir) | 29 | - Sheet/Qt is now a part of Opie, so its name is changed to Opie Sheet. (by thufir) |
21 | - Fixed sorting bug. (by thufir) | 30 | - Fixed sorting bug. (by thufir) |
22 | 31 | ||
23 | April 14, 2002 | 32 | April 14, 2002 |
24 | 33 | ||
25 | * Release 1.0.0 (by thufir) | 34 | * Release 1.0.0 (by thufir) |
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index 2f07bae..b9f8e57 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp | |||
@@ -6,723 +6,724 @@ | |||
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "mainwindow.h" | 15 | #include "mainwindow.h" |
16 | 16 | ||
17 | #include <qpe/filemanager.h> | 17 | #include <qpe/filemanager.h> |
18 | #include <qpe/qcopenvelope_qws.h> | 18 | #include <qpe/qcopenvelope_qws.h> |
19 | #include <qmessagebox.h> | 19 | #include <qmessagebox.h> |
20 | #include <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qradiobutton.h> | 21 | #include <qradiobutton.h> |
22 | #include "cellformat.h" | 22 | #include "cellformat.h" |
23 | #include "numberdlg.h" | 23 | #include "numberdlg.h" |
24 | #include "textdlg.h" | 24 | #include "textdlg.h" |
25 | #include "sortdlg.h" | 25 | #include "sortdlg.h" |
26 | #include "finddlg.h" | 26 | #include "finddlg.h" |
27 | 27 | ||
28 | #include "file-new.xpm" | 28 | #include "file-new.xpm" |
29 | #include "file-open.xpm" | 29 | #include "file-open.xpm" |
30 | #include "file-save.xpm" | 30 | #include "file-save.xpm" |
31 | #include "edit-cancel.xpm" | 31 | #include "edit-cancel.xpm" |
32 | #include "edit-accept.xpm" | 32 | #include "edit-accept.xpm" |
33 | #include "help-general.xpm" | 33 | #include "help-general.xpm" |
34 | #include "func-plus.xpm" | 34 | #include "func-plus.xpm" |
35 | #include "func-minus.xpm" | 35 | #include "func-minus.xpm" |
36 | #include "func-cross.xpm" | 36 | #include "func-cross.xpm" |
37 | #include "func-divide.xpm" | 37 | #include "func-divide.xpm" |
38 | #include "func-paran-open.xpm" | 38 | #include "func-paran-open.xpm" |
39 | #include "func-paran-close.xpm" | 39 | #include "func-paran-close.xpm" |
40 | #include "func-comma.xpm" | 40 | #include "func-comma.xpm" |
41 | #include "func-func.xpm" | 41 | #include "func-func.xpm" |
42 | #include "func-equal.xpm" | 42 | #include "func-equal.xpm" |
43 | #include "cell-select.xpm" | 43 | #include "cell-select.xpm" |
44 | 44 | ||
45 | #define DEFAULT_NUM_ROWS 199 | 45 | #define DEFAULT_NUM_ROWS 199 |
46 | #define DEFAULT_NUM_COLS (26*3) | 46 | #define DEFAULT_NUM_COLS (26*3) |
47 | #define DEFAULT_NUM_SHEETS 3 | 47 | #define DEFAULT_NUM_SHEETS 3 |
48 | 48 | ||
49 | MainWindow::MainWindow() | 49 | MainWindow::MainWindow() |
50 | :QMainWindow() | 50 | :QMainWindow() |
51 | { | 51 | { |
52 | // initialize variables | 52 | // initialize variables |
53 | documentModified=FALSE; | 53 | documentModified=FALSE; |
54 | 54 | ||
55 | // construct objects | 55 | // construct objects |
56 | currentDoc=0; | 56 | currentDoc=0; |
57 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); | 57 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); |
58 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); | 58 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); |
59 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); | 59 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); |
60 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); | 60 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); |
61 | 61 | ||
62 | listSheets.setAutoDelete(TRUE); | 62 | listSheets.setAutoDelete(TRUE); |
63 | 63 | ||
64 | initActions(); | 64 | initActions(); |
65 | initMenu(); | 65 | initMenu(); |
66 | initEditToolbar(); | 66 | initEditToolbar(); |
67 | initFunctionsToolbar(); | 67 | initFunctionsToolbar(); |
68 | initStandardToolbar(); | 68 | initStandardToolbar(); |
69 | initSheet(); | 69 | initSheet(); |
70 | 70 | ||
71 | // set window title | 71 | // set window title |
72 | setCaption(tr("Opie Sheet")); | 72 | setCaption(tr("Opie Sheet")); |
73 | 73 | ||
74 | // create sheets | 74 | // create sheets |
75 | selectorFileNew(DocLnk()); | 75 | selectorFileNew(DocLnk()); |
76 | } | 76 | } |
77 | 77 | ||
78 | MainWindow::~MainWindow() | 78 | MainWindow::~MainWindow() |
79 | { | 79 | { |
80 | if (currentDoc) delete currentDoc; | 80 | if (currentDoc) delete currentDoc; |
81 | } | 81 | } |
82 | 82 | ||
83 | void MainWindow::documentSave(DocLnk *lnkDoc) | 83 | void MainWindow::documentSave(DocLnk *lnkDoc) |
84 | { | 84 | { |
85 | FileManager fm; | 85 | FileManager fm; |
86 | QByteArray streamBuffer; | 86 | QByteArray streamBuffer; |
87 | QDataStream stream(streamBuffer, IO_WriteOnly); | 87 | QDataStream stream(streamBuffer, IO_WriteOnly); |
88 | 88 | ||
89 | typeSheet *currentSheet=findSheet(sheet->getName()); | 89 | typeSheet *currentSheet=findSheet(sheet->getName()); |
90 | if (!currentSheet) | 90 | if (!currentSheet) |
91 | { | 91 | { |
92 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); | 92 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); |
93 | return; | 93 | return; |
94 | } | 94 | } |
95 | sheet->copySheetData(¤tSheet->data); | 95 | sheet->copySheetData(¤tSheet->data); |
96 | stream.writeRawBytes("SQT100", 6); | 96 | stream.writeRawBytes("SQT100", 6); |
97 | stream << (Q_UINT32)listSheets.count(); | 97 | stream << (Q_UINT32)listSheets.count(); |
98 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 98 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
99 | { | 99 | { |
100 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); | 100 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); |
101 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) | 101 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) |
102 | 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; | 102 | 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; |
103 | } | 103 | } |
104 | 104 | ||
105 | lnkDoc->setType("application/sheet-qt"); | 105 | lnkDoc->setType("application/sheet-qt"); |
106 | if (!fm.saveFile(*lnkDoc, streamBuffer)) | 106 | if (!fm.saveFile(*lnkDoc, streamBuffer)) |
107 | { | 107 | { |
108 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); | 108 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); |
109 | return; | 109 | return; |
110 | } | 110 | } |
111 | documentModified=FALSE; | 111 | documentModified=FALSE; |
112 | } | 112 | } |
113 | 113 | ||
114 | void MainWindow::documentOpen(const DocLnk &lnkDoc) | 114 | void MainWindow::documentOpen(const DocLnk &lnkDoc) |
115 | { | 115 | { |
116 | FileManager fm; | 116 | FileManager fm; |
117 | QByteArray streamBuffer; | 117 | QByteArray streamBuffer; |
118 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) | 118 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) |
119 | { | 119 | { |
120 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); | 120 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); |
121 | documentModified=FALSE; | 121 | documentModified=FALSE; |
122 | selectorFileNew(DocLnk()); | 122 | selectorFileNew(DocLnk()); |
123 | return; | 123 | return; |
124 | } | 124 | } |
125 | QDataStream stream(streamBuffer, IO_ReadOnly); | 125 | QDataStream stream(streamBuffer, IO_ReadOnly); |
126 | 126 | ||
127 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; | 127 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; |
128 | typeSheet *newSheet; | 128 | typeSheet *newSheet; |
129 | typeCellData *newCell; | 129 | typeCellData *newCell; |
130 | 130 | ||
131 | char fileFormat[7]; | 131 | char fileFormat[7]; |
132 | stream.readRawBytes(fileFormat, 6); | 132 | stream.readRawBytes(fileFormat, 6); |
133 | fileFormat[6]=0; | 133 | fileFormat[6]=0; |
134 | if ((QString)fileFormat!="SQT100") | 134 | if ((QString)fileFormat!="SQT100") |
135 | { | 135 | { |
136 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); | 136 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); |
137 | documentModified=FALSE; | 137 | documentModified=FALSE; |
138 | selectorFileNew(DocLnk()); | 138 | selectorFileNew(DocLnk()); |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | 141 | ||
142 | stream >> countSheet; | 142 | stream >> countSheet; |
143 | for (i=0; i<countSheet; ++i) | 143 | for (i=0; i<countSheet; ++i) |
144 | { | 144 | { |
145 | newSheet=new typeSheet; | 145 | newSheet=new typeSheet; |
146 | newSheet->data.setAutoDelete(TRUE); | 146 | newSheet->data.setAutoDelete(TRUE); |
147 | stream >> newSheet->name >> countCell; | 147 | stream >> newSheet->name >> countCell; |
148 | comboSheets->insertItem(newSheet->name); | 148 | comboSheets->insertItem(newSheet->name); |
149 | 149 | ||
150 | for (j=0; j<countCell; ++j) | 150 | for (j=0; j<countCell; ++j) |
151 | { | 151 | { |
152 | newCell=new typeCellData; | 152 | newCell=new typeCellData; |
153 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; | 153 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; |
154 | newCell->col=col; | 154 | newCell->col=col; |
155 | newCell->row=row; | 155 | newCell->row=row; |
156 | newCell->alignment=(Qt::AlignmentFlags)alignment; | 156 | newCell->alignment=(Qt::AlignmentFlags)alignment; |
157 | newSheet->data.append(newCell); | 157 | newSheet->data.append(newCell); |
158 | } | 158 | } |
159 | listSheets.append(newSheet); | 159 | listSheets.append(newSheet); |
160 | 160 | ||
161 | if (i==0) | 161 | if (i==0) |
162 | { | 162 | { |
163 | sheet->setName(newSheet->name); | 163 | sheet->setName(newSheet->name); |
164 | sheet->setSheetData(&newSheet->data); | 164 | sheet->setSheetData(&newSheet->data); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | int MainWindow::saveCurrentFile(bool ask) | 169 | int MainWindow::saveCurrentFile(bool ask) |
170 | { | 170 | { |
171 | if (ask) | 171 | if (ask) |
172 | { | 172 | { |
173 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); | 173 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); |
174 | if (result!=QMessageBox::Yes) return result; | 174 | if (result!=QMessageBox::Yes) return result; |
175 | } | 175 | } |
176 | 176 | ||
177 | if (!currentDoc->isValid()) | 177 | if (!currentDoc->isValid()) |
178 | { | 178 | { |
179 | TextDialog dialogText(this); | 179 | TextDialog dialogText(this); |
180 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; | 180 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; |
181 | 181 | ||
182 | currentDoc->setName(dialogText.getValue()); | 182 | currentDoc->setName(dialogText.getValue()); |
183 | currentDoc->setFile(QString::null); | 183 | currentDoc->setFile(QString::null); |
184 | currentDoc->setLinkFile(QString::null); | 184 | currentDoc->setLinkFile(QString::null); |
185 | } | 185 | } |
186 | 186 | ||
187 | documentSave(currentDoc); | 187 | documentSave(currentDoc); |
188 | return QMessageBox::Yes; | 188 | return QMessageBox::Yes; |
189 | } | 189 | } |
190 | 190 | ||
191 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) | 191 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) |
192 | { | 192 | { |
193 | selectorHide(); | 193 | selectorHide(); |
194 | 194 | ||
195 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 195 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
196 | if (currentDoc) delete currentDoc; | 196 | if (currentDoc) delete currentDoc; |
197 | currentDoc = new DocLnk(lnkDoc); | 197 | currentDoc = new DocLnk(lnkDoc); |
198 | editData->clear(); | ||
198 | listSheets.clear(); | 199 | listSheets.clear(); |
199 | comboSheets->clear(); | 200 | comboSheets->clear(); |
200 | 201 | ||
201 | typeSheet *newSheet=createNewSheet(); | 202 | typeSheet *newSheet=createNewSheet(); |
202 | newSheet->data.setAutoDelete(TRUE); | 203 | newSheet->data.setAutoDelete(TRUE); |
203 | sheet->setName(newSheet->name); | 204 | sheet->setName(newSheet->name); |
204 | sheet->setSheetData(&newSheet->data); | 205 | sheet->setSheetData(&newSheet->data); |
205 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) | 206 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) |
206 | createNewSheet(); | 207 | createNewSheet(); |
207 | documentModified=FALSE; | 208 | documentModified=FALSE; |
208 | } | 209 | } |
209 | 210 | ||
210 | void MainWindow::closeEvent(QCloseEvent *e) | 211 | void MainWindow::closeEvent(QCloseEvent *e) |
211 | { | 212 | { |
212 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); | 213 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); |
213 | else e->accept(); | 214 | else e->accept(); |
214 | } | 215 | } |
215 | 216 | ||
216 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) | 217 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) |
217 | { | 218 | { |
218 | selectorHide(); | 219 | selectorHide(); |
219 | 220 | ||
220 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 221 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
221 | if (currentDoc) delete currentDoc; | 222 | if (currentDoc) delete currentDoc; |
222 | currentDoc = new DocLnk(lnkDoc); | 223 | currentDoc = new DocLnk(lnkDoc); |
223 | listSheets.clear(); | 224 | listSheets.clear(); |
224 | comboSheets->clear(); | 225 | comboSheets->clear(); |
225 | 226 | ||
226 | documentOpen(lnkDoc); | 227 | documentOpen(lnkDoc); |
227 | documentModified=FALSE; | 228 | documentModified=FALSE; |
228 | } | 229 | } |
229 | 230 | ||
230 | void MainWindow::selectorShow() | 231 | void MainWindow::selectorShow() |
231 | { | 232 | { |
232 | sheet->hide(); | 233 | sheet->hide(); |
233 | setCentralWidget(fileSelector); | 234 | setCentralWidget(fileSelector); |
234 | fileSelector->show(); | 235 | fileSelector->show(); |
235 | fileSelector->reread(); | 236 | fileSelector->reread(); |
236 | } | 237 | } |
237 | 238 | ||
238 | void MainWindow::selectorHide() | 239 | void MainWindow::selectorHide() |
239 | { | 240 | { |
240 | fileSelector->hide(); | 241 | fileSelector->hide(); |
241 | setCentralWidget(sheet); | 242 | setCentralWidget(sheet); |
242 | sheet->show(); | 243 | sheet->show(); |
243 | } | 244 | } |
244 | 245 | ||
245 | void MainWindow::slotFileNew() | 246 | void MainWindow::slotFileNew() |
246 | { | 247 | { |
247 | selectorFileNew(DocLnk()); | 248 | selectorFileNew(DocLnk()); |
248 | } | 249 | } |
249 | 250 | ||
250 | void MainWindow::slotFileOpen() | 251 | void MainWindow::slotFileOpen() |
251 | { | 252 | { |
252 | selectorShow(); | 253 | selectorShow(); |
253 | } | 254 | } |
254 | 255 | ||
255 | void MainWindow::slotFileSave() | 256 | void MainWindow::slotFileSave() |
256 | { | 257 | { |
257 | saveCurrentFile(FALSE); | 258 | saveCurrentFile(FALSE); |
258 | } | 259 | } |
259 | 260 | ||
260 | void MainWindow::setDocument(const QString &applnk_filename) | 261 | void MainWindow::setDocument(const QString &applnk_filename) |
261 | { | 262 | { |
262 | selectorFileOpen(DocLnk(applnk_filename)); | 263 | selectorFileOpen(DocLnk(applnk_filename)); |
263 | } | 264 | } |
264 | 265 | ||
265 | void MainWindow::initActions() | 266 | void MainWindow::initActions() |
266 | { | 267 | { |
267 | fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this); | 268 | fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this); |
268 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); | 269 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); |
269 | fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this); | 270 | fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this); |
270 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); | 271 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); |
271 | fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this); | 272 | fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this); |
272 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); | 273 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); |
273 | fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this); | 274 | fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this); |
274 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); | 275 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); |
275 | fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); | 276 | fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); |
276 | connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); | 277 | connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); |
277 | 278 | ||
278 | helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); | 279 | helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); |
279 | connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); | 280 | connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); |
280 | helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); | 281 | helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); |
281 | connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); | 282 | connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); |
282 | 283 | ||
283 | editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this); | 284 | editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this); |
284 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); | 285 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); |
285 | editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this); | 286 | editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this); |
286 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); | 287 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); |
287 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); | 288 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); |
288 | editCellSelect->setToggleAction(TRUE); | 289 | editCellSelect->setToggleAction(TRUE); |
289 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); | 290 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); |
290 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); | 291 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); |
291 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); | 292 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); |
292 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); | 293 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); |
293 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); | 294 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); |
294 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); | 295 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); |
295 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); | 296 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); |
296 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); | 297 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); |
297 | 298 | ||
298 | insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this); | 299 | insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this); |
299 | connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells())); | 300 | connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells())); |
300 | insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this); | 301 | insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this); |
301 | connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows())); | 302 | connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows())); |
302 | insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this); | 303 | insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this); |
303 | connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols())); | 304 | connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols())); |
304 | insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this); | 305 | insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this); |
305 | connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets())); | 306 | connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets())); |
306 | 307 | ||
307 | formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this); | 308 | formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this); |
308 | connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells())); | 309 | connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells())); |
309 | 310 | ||
310 | rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this); | 311 | rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this); |
311 | connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight())); | 312 | connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight())); |
312 | rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this); | 313 | rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this); |
313 | connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust())); | 314 | connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust())); |
314 | rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this); | 315 | rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this); |
315 | connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow())); | 316 | connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow())); |
316 | rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this); | 317 | rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this); |
317 | connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide())); | 318 | connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide())); |
318 | 319 | ||
319 | colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this); | 320 | colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this); |
320 | connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth())); | 321 | connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth())); |
321 | colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this); | 322 | colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this); |
322 | connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust())); | 323 | connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust())); |
323 | colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this); | 324 | colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this); |
324 | connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow())); | 325 | connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow())); |
325 | colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this); | 326 | colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this); |
326 | connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide())); | 327 | connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide())); |
327 | 328 | ||
328 | sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this); | 329 | sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this); |
329 | connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename())); | 330 | connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename())); |
330 | sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this); | 331 | sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this); |
331 | connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove())); | 332 | connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove())); |
332 | 333 | ||
333 | dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this); | 334 | dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this); |
334 | connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort())); | 335 | connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort())); |
335 | dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this); | 336 | dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this); |
336 | connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace())); | 337 | connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace())); |
337 | 338 | ||
338 | funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this); | 339 | funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this); |
339 | funcEqual->setToolTip("="); | 340 | funcEqual->setToolTip("="); |
340 | connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 341 | connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
341 | funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this); | 342 | funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this); |
342 | funcPlus->setToolTip("+"); | 343 | funcPlus->setToolTip("+"); |
343 | connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 344 | connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
344 | funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this); | 345 | funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this); |
345 | funcMinus->setToolTip("-"); | 346 | funcMinus->setToolTip("-"); |
346 | connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 347 | connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
347 | funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this); | 348 | funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this); |
348 | funcCross->setToolTip("*"); | 349 | funcCross->setToolTip("*"); |
349 | connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 350 | connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
350 | funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this); | 351 | funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this); |
351 | funcDivide->setToolTip("/"); | 352 | funcDivide->setToolTip("/"); |
352 | connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 353 | connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
353 | funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this); | 354 | funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this); |
354 | funcParanOpen->setToolTip("("); | 355 | funcParanOpen->setToolTip("("); |
355 | connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 356 | connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
356 | funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this); | 357 | funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this); |
357 | funcParanClose->setToolTip(")"); | 358 | funcParanClose->setToolTip(")"); |
358 | connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 359 | connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
359 | funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this); | 360 | funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this); |
360 | funcComma->setToolTip(","); | 361 | funcComma->setToolTip(","); |
361 | connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 362 | connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
362 | } | 363 | } |
363 | 364 | ||
364 | void MainWindow::initMenu() | 365 | void MainWindow::initMenu() |
365 | { | 366 | { |
366 | menu=new QPEMenuBar(this); | 367 | menu=new QPEMenuBar(this); |
367 | 368 | ||
368 | menuFile=new QPopupMenu; | 369 | menuFile=new QPopupMenu; |
369 | fileNew->addTo(menuFile); | 370 | fileNew->addTo(menuFile); |
370 | fileOpen->addTo(menuFile); | 371 | fileOpen->addTo(menuFile); |
371 | fileSave->addTo(menuFile); | 372 | fileSave->addTo(menuFile); |
372 | fileSaveAs->addTo(menuFile); | 373 | fileSaveAs->addTo(menuFile); |
373 | menuFile->insertSeparator(); | 374 | menuFile->insertSeparator(); |
374 | fileQuit->addTo(menuFile); | 375 | fileQuit->addTo(menuFile); |
375 | menu->insertItem(tr("&File"), menuFile); | 376 | menu->insertItem(tr("&File"), menuFile); |
376 | 377 | ||
377 | menuEdit=new QPopupMenu; | 378 | menuEdit=new QPopupMenu; |
378 | editAccept->addTo(menuEdit); | 379 | editAccept->addTo(menuEdit); |
379 | editCancel->addTo(menuEdit); | 380 | editCancel->addTo(menuEdit); |
380 | editCellSelect->addTo(menuEdit); | 381 | editCellSelect->addTo(menuEdit); |
381 | menuEdit->insertSeparator(); | 382 | menuEdit->insertSeparator(); |
382 | editCut->addTo(menuEdit); | 383 | editCut->addTo(menuEdit); |
383 | editCopy->addTo(menuEdit); | 384 | editCopy->addTo(menuEdit); |
384 | editPaste->addTo(menuEdit); | 385 | editPaste->addTo(menuEdit); |
385 | editPasteContents->addTo(menuEdit); | 386 | editPasteContents->addTo(menuEdit); |
386 | editClear->addTo(menuEdit); | 387 | editClear->addTo(menuEdit); |
387 | menu->insertItem(tr("&Edit"), menuEdit); | 388 | menu->insertItem(tr("&Edit"), menuEdit); |
388 | 389 | ||
389 | menuInsert=new QPopupMenu; | 390 | menuInsert=new QPopupMenu; |
390 | menu->insertItem(tr("&Insert"), menuInsert); | 391 | menu->insertItem(tr("&Insert"), menuInsert); |
391 | 392 | ||
392 | menuFormat=new QPopupMenu; | 393 | menuFormat=new QPopupMenu; |
393 | formatCells->addTo(menuFormat); | 394 | formatCells->addTo(menuFormat); |
394 | menu->insertItem(tr("&Format"), menuFormat); | 395 | menu->insertItem(tr("&Format"), menuFormat); |
395 | 396 | ||
396 | menuData=new QPopupMenu; | 397 | menuData=new QPopupMenu; |
397 | dataSort->addTo(menuData); | 398 | dataSort->addTo(menuData); |
398 | dataFindReplace->addTo(menuData); | 399 | dataFindReplace->addTo(menuData); |
399 | menu->insertItem(tr("&Data"), menuData); | 400 | menu->insertItem(tr("&Data"), menuData); |
400 | 401 | ||
401 | menuHelp=new QPopupMenu; | 402 | menuHelp=new QPopupMenu; |
402 | helpGeneral->addTo(menuHelp); | 403 | helpGeneral->addTo(menuHelp); |
403 | helpAbout->addTo(menuHelp); | 404 | helpAbout->addTo(menuHelp); |
404 | menu->insertItem(tr("&Help"), menuHelp); | 405 | menu->insertItem(tr("&Help"), menuHelp); |
405 | 406 | ||
406 | submenuRow=new QPopupMenu; | 407 | submenuRow=new QPopupMenu; |
407 | rowHeight->addTo(submenuRow); | 408 | rowHeight->addTo(submenuRow); |
408 | rowAdjust->addTo(submenuRow); | 409 | rowAdjust->addTo(submenuRow); |
409 | rowShow->addTo(submenuRow); | 410 | rowShow->addTo(submenuRow); |
410 | rowHide->addTo(submenuRow); | 411 | rowHide->addTo(submenuRow); |
411 | menuFormat->insertItem(tr("&Row"), submenuRow); | 412 | menuFormat->insertItem(tr("&Row"), submenuRow); |
412 | 413 | ||
413 | submenuCol=new QPopupMenu; | 414 | submenuCol=new QPopupMenu; |
414 | colWidth->addTo(submenuCol); | 415 | colWidth->addTo(submenuCol); |
415 | colAdjust->addTo(submenuCol); | 416 | colAdjust->addTo(submenuCol); |
416 | colShow->addTo(submenuCol); | 417 | colShow->addTo(submenuCol); |
417 | colHide->addTo(submenuCol); | 418 | colHide->addTo(submenuCol); |
418 | menuFormat->insertItem(tr("Colum&n"), submenuCol); | 419 | menuFormat->insertItem(tr("Colum&n"), submenuCol); |
419 | 420 | ||
420 | submenuSheet=new QPopupMenu; | 421 | submenuSheet=new QPopupMenu; |
421 | sheetRename->addTo(submenuSheet); | 422 | sheetRename->addTo(submenuSheet); |
422 | sheetRemove->addTo(submenuSheet); | 423 | sheetRemove->addTo(submenuSheet); |
423 | menuFormat->insertItem(tr("&Sheet"), submenuSheet); | 424 | menuFormat->insertItem(tr("&Sheet"), submenuSheet); |
424 | 425 | ||
425 | submenuFunc=new QPopupMenu; | 426 | submenuFunc=new QPopupMenu; |
426 | menuInsert->insertItem(tr("&Function"), submenuFunc); | 427 | menuInsert->insertItem(tr("&Function"), submenuFunc); |
427 | 428 | ||
428 | submenuFuncStd=new QPopupMenu; | 429 | submenuFuncStd=new QPopupMenu; |
429 | funcPlus->addTo(submenuFuncStd); | 430 | funcPlus->addTo(submenuFuncStd); |
430 | funcMinus->addTo(submenuFuncStd); | 431 | funcMinus->addTo(submenuFuncStd); |
431 | funcCross->addTo(submenuFuncStd); | 432 | funcCross->addTo(submenuFuncStd); |
432 | funcDivide->addTo(submenuFuncStd); | 433 | funcDivide->addTo(submenuFuncStd); |
433 | submenuFunc->insertItem(tr("&Standard"), submenuFuncStd); | 434 | submenuFunc->insertItem(tr("&Standard"), submenuFuncStd); |
434 | 435 | ||
435 | submenuFuncMath=new QPopupMenu; | 436 | submenuFuncMath=new QPopupMenu; |
436 | addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath); | 437 | addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath); |
437 | addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath); | 438 | addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath); |
438 | submenuFuncMath->insertSeparator(); | 439 | submenuFuncMath->insertSeparator(); |
439 | addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath); | 440 | addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath); |
440 | addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath); | 441 | addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath); |
441 | addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath); | 442 | addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath); |
442 | addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath); | 443 | addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath); |
443 | addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath); | 444 | addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath); |
444 | addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath); | 445 | addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath); |
445 | addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath); | 446 | addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath); |
446 | submenuFuncMath->insertSeparator(); | 447 | submenuFuncMath->insertSeparator(); |
447 | addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath); | 448 | addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath); |
448 | addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath); | 449 | addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath); |
449 | addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath); | 450 | addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath); |
450 | submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath); | 451 | submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath); |
451 | 452 | ||
452 | submenuFuncStat=new QPopupMenu; | 453 | submenuFuncStat=new QPopupMenu; |
453 | addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat); | 454 | addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat); |
454 | addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat); | 455 | addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat); |
455 | addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat); | 456 | addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat); |
456 | addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat); | 457 | addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat); |
457 | submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat); | 458 | submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat); |
458 | 459 | ||
459 | menuInsert->insertSeparator(); | 460 | menuInsert->insertSeparator(); |
460 | insertCells->addTo(menuInsert); | 461 | insertCells->addTo(menuInsert); |
461 | insertRows->addTo(menuInsert); | 462 | insertRows->addTo(menuInsert); |
462 | insertCols->addTo(menuInsert); | 463 | insertCols->addTo(menuInsert); |
463 | insertSheets->addTo(menuInsert); | 464 | insertSheets->addTo(menuInsert); |
464 | } | 465 | } |
465 | 466 | ||
466 | void MainWindow::initStandardToolbar() | 467 | void MainWindow::initStandardToolbar() |
467 | { | 468 | { |
468 | toolbarStandard=new QPEToolBar(this); | 469 | toolbarStandard=new QPEToolBar(this); |
469 | toolbarStandard->setHorizontalStretchable(TRUE); | 470 | toolbarStandard->setHorizontalStretchable(TRUE); |
470 | moveToolBar(toolbarStandard, Top); | 471 | moveToolBar(toolbarStandard, Top); |
471 | 472 | ||
472 | fileNew->addTo(toolbarStandard); | 473 | fileNew->addTo(toolbarStandard); |
473 | fileOpen->addTo(toolbarStandard); | 474 | fileOpen->addTo(toolbarStandard); |
474 | fileSave->addTo(toolbarStandard); | 475 | fileSave->addTo(toolbarStandard); |
475 | 476 | ||
476 | comboSheets=new QComboBox(toolbarStandard); | 477 | comboSheets=new QComboBox(toolbarStandard); |
477 | toolbarStandard->setStretchableWidget(comboSheets); | 478 | toolbarStandard->setStretchableWidget(comboSheets); |
478 | connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &))); | 479 | connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &))); |
479 | } | 480 | } |
480 | 481 | ||
481 | void MainWindow::initFunctionsToolbar() | 482 | void MainWindow::initFunctionsToolbar() |
482 | { | 483 | { |
483 | toolbarFunctions=new QPEToolBar(this); | 484 | toolbarFunctions=new QPEToolBar(this); |
484 | toolbarFunctions->setHorizontalStretchable(TRUE); | 485 | toolbarFunctions->setHorizontalStretchable(TRUE); |
485 | moveToolBar(toolbarFunctions, Bottom); | 486 | moveToolBar(toolbarFunctions, Bottom); |
486 | 487 | ||
487 | funcEqual->addTo(toolbarFunctions); | 488 | funcEqual->addTo(toolbarFunctions); |
488 | funcPlus->addTo(toolbarFunctions); | 489 | funcPlus->addTo(toolbarFunctions); |
489 | funcMinus->addTo(toolbarFunctions); | 490 | funcMinus->addTo(toolbarFunctions); |
490 | funcCross->addTo(toolbarFunctions); | 491 | funcCross->addTo(toolbarFunctions); |
491 | funcDivide->addTo(toolbarFunctions); | 492 | funcDivide->addTo(toolbarFunctions); |
492 | funcParanOpen->addTo(toolbarFunctions); | 493 | funcParanOpen->addTo(toolbarFunctions); |
493 | funcParanClose->addTo(toolbarFunctions); | 494 | funcParanClose->addTo(toolbarFunctions); |
494 | funcComma->addTo(toolbarFunctions); | 495 | funcComma->addTo(toolbarFunctions); |
495 | 496 | ||
496 | toolFunction=new QToolButton(toolbarFunctions); | 497 | toolFunction=new QToolButton(toolbarFunctions); |
497 | toolFunction->setPixmap(func_func_xpm); | 498 | toolFunction->setPixmap(func_func_xpm); |
498 | toolFunction->setTextLabel(tr("Functions")); | 499 | toolFunction->setTextLabel(tr("Functions")); |
499 | toolFunction->setPopup(submenuFunc); | 500 | toolFunction->setPopup(submenuFunc); |
500 | toolFunction->setPopupDelay(0); | 501 | toolFunction->setPopupDelay(0); |
501 | } | 502 | } |
502 | 503 | ||
503 | void MainWindow::initEditToolbar() | 504 | void MainWindow::initEditToolbar() |
504 | { | 505 | { |
505 | toolbarEdit=new QPEToolBar(this); | 506 | toolbarEdit=new QPEToolBar(this); |
506 | toolbarEdit->setHorizontalStretchable(TRUE); | 507 | toolbarEdit->setHorizontalStretchable(TRUE); |
507 | moveToolBar(toolbarEdit, Bottom); | 508 | moveToolBar(toolbarEdit, Bottom); |
508 | 509 | ||
509 | editAccept->addTo(toolbarEdit); | 510 | editAccept->addTo(toolbarEdit); |
510 | editCancel->addTo(toolbarEdit); | 511 | editCancel->addTo(toolbarEdit); |
511 | 512 | ||
512 | editData=new QLineEdit(toolbarEdit); | 513 | editData=new QLineEdit(toolbarEdit); |
513 | toolbarEdit->setStretchableWidget(editData); | 514 | toolbarEdit->setStretchableWidget(editData); |
514 | connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); | 515 | connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); |
515 | 516 | ||
516 | editCellSelect->addTo(toolbarEdit); | 517 | editCellSelect->addTo(toolbarEdit); |
517 | } | 518 | } |
518 | 519 | ||
519 | void MainWindow::slotHelpGeneral() | 520 | void MainWindow::slotHelpGeneral() |
520 | { | 521 | { |
521 | if (QFile::exists(helpFile)) | 522 | if (QFile::exists(helpFile)) |
522 | { | 523 | { |
523 | QCopEnvelope e("QPE/Application/helpbrowser", "showFile(QString)"); | 524 | QCopEnvelope e("QPE/Application/helpbrowser", "showFile(QString)"); |
524 | e << helpFile; | 525 | e << helpFile; |
525 | } | 526 | } |
526 | else | 527 | else |
527 | QMessageBox::critical(this, tr("Error"), tr("Help file not found!")); | 528 | QMessageBox::critical(this, tr("Error"), tr("Help file not found!")); |
528 | } | 529 | } |
529 | 530 | ||
530 | void MainWindow::slotHelpAbout() | 531 | void MainWindow::slotHelpAbout() |
531 | { | 532 | { |
532 | QDialog dialogAbout(this, 0, TRUE); | 533 | QDialog dialogAbout(this, 0, TRUE); |
533 | dialogAbout.resize(width()-40, height()-80); | 534 | dialogAbout.resize(width()-40, height()-80); |
534 | dialogAbout.setCaption(tr("About Opie Sheet")); | 535 | dialogAbout.setCaption(tr("About Opie Sheet")); |
535 | 536 | ||
536 | QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.1\nRelease Date: July 04, 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); | 537 | QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 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); |
537 | label.setGeometry(dialogAbout.rect()); | 538 | label.setGeometry(dialogAbout.rect()); |
538 | label.setAlignment(Qt::AlignCenter | Qt::WordBreak); | 539 | label.setAlignment(Qt::AlignCenter | Qt::WordBreak); |
539 | 540 | ||
540 | dialogAbout.exec(); | 541 | dialogAbout.exec(); |
541 | } | 542 | } |
542 | 543 | ||
543 | void MainWindow::initSheet() | 544 | void MainWindow::initSheet() |
544 | { | 545 | { |
545 | sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); | 546 | sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); |
546 | setCentralWidget(sheet); | 547 | setCentralWidget(sheet); |
547 | 548 | ||
548 | connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &))); | 549 | connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &))); |
549 | connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &))); | 550 | connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &))); |
550 | connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); | 551 | connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); |
551 | 552 | ||
552 | connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); | 553 | connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); |
553 | connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); | 554 | connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); |
554 | connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); | 555 | connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); |
555 | } | 556 | } |
556 | 557 | ||
557 | void MainWindow::slotEditAccept() | 558 | void MainWindow::slotEditAccept() |
558 | { | 559 | { |
559 | sheet->setData(editData->text()); | 560 | sheet->setData(editData->text()); |
560 | } | 561 | } |
561 | 562 | ||
562 | void MainWindow::slotEditCancel() | 563 | void MainWindow::slotEditCancel() |
563 | { | 564 | { |
564 | editData->setText(sheet->getData()); | 565 | editData->setText(sheet->getData()); |
565 | } | 566 | } |
566 | 567 | ||
567 | void MainWindow::slotCellSelect(bool lock) | 568 | void MainWindow::slotCellSelect(bool lock) |
568 | { | 569 | { |
569 | sheet->lockClicks(lock); | 570 | sheet->lockClicks(lock); |
570 | } | 571 | } |
571 | 572 | ||
572 | void MainWindow::addToData(const QString &data) | 573 | void MainWindow::addToData(const QString &data) |
573 | { | 574 | { |
574 | editData->setText(editData->text().insert(editData->cursorPosition(), data)); | 575 | editData->setText(editData->text().insert(editData->cursorPosition(), data)); |
575 | } | 576 | } |
576 | 577 | ||
577 | void MainWindow::slotFuncOutput() | 578 | void MainWindow::slotFuncOutput() |
578 | { | 579 | { |
579 | if (sender()->isA("QAction")) | 580 | if (sender()->isA("QAction")) |
580 | addToData(((QAction *)sender())->toolTip()); | 581 | addToData(((QAction *)sender())->toolTip()); |
581 | } | 582 | } |
582 | 583 | ||
583 | void MainWindow::slotInsertRows() | 584 | void MainWindow::slotInsertRows() |
584 | { | 585 | { |
585 | NumberDialog dialogNumber(this); | 586 | NumberDialog dialogNumber(this); |
586 | if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) | 587 | if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) |
587 | sheet->insertRows(dialogNumber.getValue()); | 588 | sheet->insertRows(dialogNumber.getValue()); |
588 | } | 589 | } |
589 | 590 | ||
590 | void MainWindow::slotInsertCols() | 591 | void MainWindow::slotInsertCols() |
591 | { | 592 | { |
592 | NumberDialog dialogNumber(this); | 593 | NumberDialog dialogNumber(this); |
593 | if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) | 594 | if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) |
594 | sheet->insertColumns(dialogNumber.getValue()); | 595 | sheet->insertColumns(dialogNumber.getValue()); |
595 | } | 596 | } |
596 | 597 | ||
597 | void MainWindow::slotInsertSheets() | 598 | void MainWindow::slotInsertSheets() |
598 | { | 599 | { |
599 | NumberDialog dialogNumber(this); | 600 | NumberDialog dialogNumber(this); |
600 | if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) | 601 | if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) |
601 | for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); | 602 | for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); |
602 | } | 603 | } |
603 | 604 | ||
604 | void MainWindow::slotCellClicked(const QString &cell) | 605 | void MainWindow::slotCellClicked(const QString &cell) |
605 | { | 606 | { |
606 | editCellSelect->setOn(FALSE); | 607 | editCellSelect->setOn(FALSE); |
607 | addToData(cell); | 608 | addToData(cell); |
608 | } | 609 | } |
609 | 610 | ||
610 | typeSheet *MainWindow::createNewSheet() | 611 | typeSheet *MainWindow::createNewSheet() |
611 | { | 612 | { |
612 | typeSheet *newSheet=new typeSheet; | 613 | typeSheet *newSheet=new typeSheet; |
613 | int currentNo=1, tempNo; | 614 | int currentNo=1, tempNo; |
614 | bool ok; | 615 | bool ok; |
615 | 616 | ||
616 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 617 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
617 | if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) | 618 | if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) |
618 | currentNo=tempNo+1; | 619 | currentNo=tempNo+1; |
619 | 620 | ||
620 | newSheet->name=tr("Sheet")+QString::number(currentNo); | 621 | newSheet->name=tr("Sheet")+QString::number(currentNo); |
621 | newSheet->data.setAutoDelete(TRUE); | 622 | newSheet->data.setAutoDelete(TRUE); |
622 | 623 | ||
623 | comboSheets->insertItem(newSheet->name); | 624 | comboSheets->insertItem(newSheet->name); |
624 | listSheets.append(newSheet); | 625 | listSheets.append(newSheet); |
625 | return newSheet; | 626 | return newSheet; |
626 | } | 627 | } |
627 | 628 | ||
628 | typeSheet *MainWindow::findSheet(const QString &name) | 629 | typeSheet *MainWindow::findSheet(const QString &name) |
629 | { | 630 | { |
630 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 631 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
631 | if (tempSheet->name==name) | 632 | if (tempSheet->name==name) |
632 | return tempSheet; | 633 | return tempSheet; |
633 | return NULL; | 634 | return NULL; |
634 | } | 635 | } |
635 | 636 | ||
636 | void MainWindow::slotSheetChanged(const QString &name) | 637 | void MainWindow::slotSheetChanged(const QString &name) |
637 | { | 638 | { |
638 | sheet->copySheetData(&findSheet(sheet->getName())->data); | 639 | sheet->copySheetData(&findSheet(sheet->getName())->data); |
639 | sheet->setName(name); | 640 | sheet->setName(name); |
640 | sheet->setSheetData(&findSheet(name)->data); | 641 | sheet->setSheetData(&findSheet(name)->data); |
641 | } | 642 | } |
642 | 643 | ||
643 | void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) | 644 | void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) |
644 | { | 645 | { |
645 | QAction *action=new QAction(text, menuText, 0, this); | 646 | QAction *action=new QAction(text, menuText, 0, this); |
646 | action->setToolTip(tip); | 647 | action->setToolTip(tip); |
647 | connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 648 | connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
648 | action->addTo(w); | 649 | action->addTo(w); |
649 | } | 650 | } |
650 | 651 | ||
651 | void MainWindow::slotFormatCells() | 652 | void MainWindow::slotFormatCells() |
652 | { | 653 | { |
653 | CellFormat dialogCellFormat(this); | 654 | CellFormat dialogCellFormat(this); |
654 | dialogCellFormat.showMaximized(); | 655 | dialogCellFormat.showMaximized(); |
655 | dialogCellFormat.exec(sheet); | 656 | dialogCellFormat.exec(sheet); |
656 | } | 657 | } |
657 | 658 | ||
658 | void MainWindow::slotEditPaste() | 659 | void MainWindow::slotEditPaste() |
659 | { | 660 | { |
660 | sheet->editPaste(); | 661 | sheet->editPaste(); |
661 | } | 662 | } |
662 | 663 | ||
663 | void MainWindow::slotEditPasteContents() | 664 | void MainWindow::slotEditPasteContents() |
664 | { | 665 | { |
665 | sheet->editPaste(TRUE); | 666 | sheet->editPaste(TRUE); |
666 | } | 667 | } |
667 | 668 | ||
668 | void MainWindow::slotRowHeight() | 669 | void MainWindow::slotRowHeight() |
669 | { | 670 | { |
670 | int row1, row2, col1, col2; | 671 | int row1, row2, col1, col2; |
671 | sheet->getSelection(&row1, &col1, &row2, &col2); | 672 | sheet->getSelection(&row1, &col1, &row2, &col2); |
672 | 673 | ||
673 | NumberDialog dialogNumber(this); | 674 | NumberDialog dialogNumber(this); |
674 | if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) | 675 | if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) |
675 | { | 676 | { |
676 | int newHeight=dialogNumber.getValue(), row; | 677 | int newHeight=dialogNumber.getValue(), row; |
677 | for (row=row1; row<=row2; ++row) | 678 | for (row=row1; row<=row2; ++row) |
678 | sheet->setRowHeight(row, newHeight); | 679 | sheet->setRowHeight(row, newHeight); |
679 | } | 680 | } |
680 | } | 681 | } |
681 | 682 | ||
682 | void MainWindow::slotRowAdjust() | 683 | void MainWindow::slotRowAdjust() |
683 | { | 684 | { |
684 | int row1, row2, col1, col2; | 685 | int row1, row2, col1, col2; |
685 | sheet->getSelection(&row1, &col1, &row2, &col2); | 686 | sheet->getSelection(&row1, &col1, &row2, &col2); |
686 | 687 | ||
687 | for (int row=row1; row<=row2; ++row) | 688 | for (int row=row1; row<=row2; ++row) |
688 | sheet->adjustRow(row); | 689 | sheet->adjustRow(row); |
689 | } | 690 | } |
690 | 691 | ||
691 | void MainWindow::slotRowShow() | 692 | void MainWindow::slotRowShow() |
692 | { | 693 | { |
693 | int row1, row2, col1, col2; | 694 | int row1, row2, col1, col2; |
694 | sheet->getSelection(&row1, &col1, &row2, &col2); | 695 | sheet->getSelection(&row1, &col1, &row2, &col2); |
695 | 696 | ||
696 | for (int row=row1; row<=row2; ++row) | 697 | for (int row=row1; row<=row2; ++row) |
697 | sheet->showRow(row); | 698 | sheet->showRow(row); |
698 | } | 699 | } |
699 | 700 | ||
700 | void MainWindow::slotRowHide() | 701 | void MainWindow::slotRowHide() |
701 | { | 702 | { |
702 | int row1, row2, col1, col2; | 703 | int row1, row2, col1, col2; |
703 | sheet->getSelection(&row1, &col1, &row2, &col2); | 704 | sheet->getSelection(&row1, &col1, &row2, &col2); |
704 | 705 | ||
705 | for (int row=row1; row<=row2; ++row) | 706 | for (int row=row1; row<=row2; ++row) |
706 | sheet->hideRow(row); | 707 | sheet->hideRow(row); |
707 | } | 708 | } |
708 | 709 | ||
709 | void MainWindow::slotColumnWidth() | 710 | void MainWindow::slotColumnWidth() |
710 | { | 711 | { |
711 | int row1, row2, col1, col2; | 712 | int row1, row2, col1, col2; |
712 | sheet->getSelection(&row1, &col1, &row2, &col2); | 713 | sheet->getSelection(&row1, &col1, &row2, &col2); |
713 | 714 | ||
714 | NumberDialog dialogNumber(this); | 715 | NumberDialog dialogNumber(this); |
715 | if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) | 716 | if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) |
716 | { | 717 | { |
717 | int newWidth=dialogNumber.getValue(), col; | 718 | int newWidth=dialogNumber.getValue(), col; |
718 | for (col=col1; col<=col2; ++col) | 719 | for (col=col1; col<=col2; ++col) |
719 | sheet->setColumnWidth(col, newWidth); | 720 | sheet->setColumnWidth(col, newWidth); |
720 | } | 721 | } |
721 | } | 722 | } |
722 | 723 | ||
723 | void MainWindow::slotColumnAdjust() | 724 | void MainWindow::slotColumnAdjust() |
724 | { | 725 | { |
725 | int row1, row2, col1, col2; | 726 | int row1, row2, col1, col2; |
726 | sheet->getSelection(&row1, &col1, &row2, &col2); | 727 | sheet->getSelection(&row1, &col1, &row2, &col2); |
727 | 728 | ||
728 | for (int col=col1; col<=col2; ++col) | 729 | for (int col=col1; col<=col2; ++col) |
diff --git a/noncore/apps/opie-sheet/opie-sheet.control b/noncore/apps/opie-sheet/opie-sheet.control index 38f9083..cc322bb 100644 --- a/noncore/apps/opie-sheet/opie-sheet.control +++ b/noncore/apps/opie-sheet/opie-sheet.control | |||
@@ -1,10 +1,10 @@ | |||
1 | Files: bin/sheetqt apps/Applications/opie-sheet.desktop help/sheetqt.html help/sheetqt/* pics/opie-sheet/sheetqt.png | 1 | Files: bin/sheetqt apps/Applications/opie-sheet.desktop help/sheetqt.html help/sheetqt/* pics/opie-sheet/sheetqt.png |
2 | Priority: optional | 2 | Priority: optional |
3 | Section: opie/applications | 3 | Section: opie/applications |
4 | Maintainer: Serdar Ozler <sozler@sitebest.com> | 4 | Maintainer: Serdar Ozler <sozler@sitebest.com> |
5 | Architecture: arm | 5 | Architecture: arm |
6 | Version: 1.0.1 | 6 | Version: 1.0.2 |
7 | Depends: opie-base ($QPE_VERSION) | 7 | Depends: opie-base ($QPE_VERSION) |
8 | License: Public Domain | 8 | License: Public Domain |
9 | Description: Opie Sheet | 9 | Description: Opie Sheet |
10 | Spreadsheet software for Opie. | 10 | Spreadsheet software for Opie. |
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index be4046b..c2563c2 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp | |||
@@ -1,864 +1,872 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "sheet.h" | 15 | #include "sheet.h" |
16 | 16 | ||
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | #include <qmessagebox.h> | 18 | #include <qmessagebox.h> |
19 | #include <math.h> | 19 | #include <math.h> |
20 | 20 | ||
21 | #define DEFAULT_COL_WIDTH 50 | 21 | #define DEFAULT_COL_WIDTH 50 |
22 | 22 | ||
23 | Sheet::Sheet(int numRows, int numCols, QWidget *parent) | 23 | Sheet::Sheet(int numRows, int numCols, QWidget *parent) |
24 | :QTable(numRows, numCols, parent) | 24 | :QTable(numRows, numCols, parent) |
25 | { | 25 | { |
26 | defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); | 26 | defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); |
27 | defaultCellData.data=""; | 27 | defaultCellData.data=""; |
28 | defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); | 28 | defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); |
29 | defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); | 29 | defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); |
30 | defaultCellData.fontColor=Qt::black; | 30 | defaultCellData.fontColor=Qt::black; |
31 | defaultCellData.font=font(); | 31 | defaultCellData.font=font(); |
32 | defaultCellData.borders=defaultBorders; | 32 | defaultCellData.borders=defaultBorders; |
33 | 33 | ||
34 | clicksLocked=FALSE; | 34 | clicksLocked=FALSE; |
35 | selectionNo=-1; | 35 | selectionNo=-1; |
36 | setSelectionMode(QTable::Single); | 36 | setSelectionMode(QTable::Single); |
37 | 37 | ||
38 | sheetData.setAutoDelete(TRUE); | 38 | sheetData.setAutoDelete(TRUE); |
39 | clipboardData.setAutoDelete(TRUE); | 39 | clipboardData.setAutoDelete(TRUE); |
40 | for (int i=0; i<numCols; ++i) | 40 | for (int i=0; i<numCols; ++i) |
41 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); | 41 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); |
42 | 42 | ||
43 | connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); | 43 | connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); |
44 | connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); | 44 | connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); |
45 | } | 45 | } |
46 | 46 | ||
47 | Sheet::~Sheet() | 47 | Sheet::~Sheet() |
48 | { | 48 | { |
49 | } | 49 | } |
50 | 50 | ||
51 | typeCellData *Sheet::findCellData(int row, int col) | 51 | typeCellData *Sheet::findCellData(int row, int col) |
52 | { | 52 | { |
53 | typeCellData *tempCellData; | 53 | typeCellData *tempCellData; |
54 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 54 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
55 | if (tempCellData->row==row && tempCellData->col==col) | 55 | if (tempCellData->row==row && tempCellData->col==col) |
56 | return tempCellData; | 56 | return tempCellData; |
57 | return NULL; | 57 | return NULL; |
58 | } | 58 | } |
59 | 59 | ||
60 | void Sheet::slotCellSelected(int row, int col) | 60 | void Sheet::slotCellSelected(int row, int col) |
61 | { | 61 | { |
62 | typeCellData *cellData=findCellData(row, col); | 62 | typeCellData *cellData=findCellData(row, col); |
63 | if (cellData) | 63 | if (cellData) |
64 | emit currentDataChanged(cellData->data); | 64 | emit currentDataChanged(cellData->data); |
65 | else | 65 | else |
66 | emit currentDataChanged(""); | 66 | emit currentDataChanged(""); |
67 | } | 67 | } |
68 | 68 | ||
69 | typeCellData *Sheet::createCellData(int row, int col) | 69 | typeCellData *Sheet::createCellData(int row, int col) |
70 | { | 70 | { |
71 | if (row<0 || col<0) return NULL; | 71 | if (row<0 || col<0) return NULL; |
72 | typeCellData *cellData=new typeCellData; | 72 | typeCellData *cellData=new typeCellData; |
73 | cellData->row=row; | 73 | cellData->row=row; |
74 | cellData->col=col; | 74 | cellData->col=col; |
75 | cellData->data=defaultCellData.data; | 75 | cellData->data=defaultCellData.data; |
76 | cellData->borders=defaultCellData.borders; | 76 | cellData->borders=defaultCellData.borders; |
77 | cellData->alignment=defaultCellData.alignment; | 77 | cellData->alignment=defaultCellData.alignment; |
78 | cellData->font=defaultCellData.font; | 78 | cellData->font=defaultCellData.font; |
79 | cellData->fontColor=defaultCellData.fontColor; | 79 | cellData->fontColor=defaultCellData.fontColor; |
80 | cellData->background=defaultCellData.background; | 80 | cellData->background=defaultCellData.background; |
81 | sheetData.append(cellData); | 81 | sheetData.append(cellData); |
82 | return cellData; | 82 | return cellData; |
83 | } | 83 | } |
84 | 84 | ||
85 | void Sheet::slotCellChanged(int row, int col) | 85 | void Sheet::slotCellChanged(int row, int col) |
86 | { | 86 | { |
87 | typeCellData *cellData=findCellData(row, col); | 87 | typeCellData *cellData=findCellData(row, col); |
88 | if (!cellData) cellData=createCellData(row, col); | 88 | if (!cellData) cellData=createCellData(row, col); |
89 | if (cellData) cellData->data=text(row, col); | 89 | if (cellData) cellData->data=text(row, col); |
90 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) | 90 | for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) |
91 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 91 | setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); |
92 | emit sheetModified(); | 92 | emit sheetModified(); |
93 | } | 93 | } |
94 | 94 | ||
95 | void Sheet::swapCells(int row1, int col1, int row2, int col2) | 95 | void Sheet::swapCells(int row1, int col1, int row2, int col2) |
96 | { | 96 | { |
97 | typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); | 97 | typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); |
98 | if (!cellData1) cellData1=createCellData(row1, col1); | 98 | if (!cellData1) cellData1=createCellData(row1, col1); |
99 | if (!cellData2) cellData2=createCellData(row2, col2); | 99 | if (!cellData2) cellData2=createCellData(row2, col2); |
100 | if (cellData1 && cellData2) | 100 | if (cellData1 && cellData2) |
101 | { | 101 | { |
102 | QString tempData(cellData1->data); | 102 | QString tempData(cellData1->data); |
103 | cellData1->data=cellData2->data; | 103 | cellData1->data=cellData2->data; |
104 | cellData2->data=tempData; | 104 | cellData2->data=tempData; |
105 | setText(cellData1->row, cellData1->col, dataParser(cellData1->data)); | 105 | setText(cellData1->row, cellData1->col, dataParser(findCellName(cellData1->row, cellData1->col), cellData1->data)); |
106 | setText(cellData2->row, cellData2->col, dataParser(cellData2->data)); | 106 | setText(cellData2->row, cellData2->col, dataParser(findCellName(cellData2->row, cellData2->col), cellData2->data)); |
107 | emit sheetModified(); | 107 | emit sheetModified(); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | QString Sheet::getParameter(const QString ¶meters, int paramNo, bool giveError, const QString funcName) | 111 | QString Sheet::getParameter(const QString ¶meters, int paramNo, bool giveError, const QString funcName) |
112 | { | 112 | { |
113 | QString params(parameters); | 113 | QString params(parameters); |
114 | int position; | 114 | int position; |
115 | for (int i=0; i<paramNo; ++i) | 115 | for (int i=0; i<paramNo; ++i) |
116 | { | 116 | { |
117 | position=params.find(','); | 117 | position=params.find(','); |
118 | if (position<0) | 118 | if (position<0) |
119 | { | 119 | { |
120 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\'')); | 120 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\'')); |
121 | return QString(); | 121 | return QString(); |
122 | } | 122 | } |
123 | params=params.mid(position+1); | 123 | params=params.mid(position+1); |
124 | } | 124 | } |
125 | position=params.find(','); | 125 | position=params.find(','); |
126 | if (position<0) return params; | 126 | if (position<0) return params; |
127 | return params.left(position); | 127 | return params.left(position); |
128 | } | 128 | } |
129 | 129 | ||
130 | bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2) | 130 | bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2) |
131 | { | 131 | { |
132 | int row, col; | 132 | int row, col; |
133 | if (!findRowColumn(variable1, row1, col1, TRUE) || !findRowColumn(variable2, row2, col2, TRUE)) return FALSE; | 133 | if (!findRowColumn(variable1, row1, col1, TRUE) || !findRowColumn(variable2, row2, col2, TRUE)) return FALSE; |
134 | if (*row1>*row2) | 134 | if (*row1>*row2) |
135 | { | 135 | { |
136 | row=*row1; | 136 | row=*row1; |
137 | *row1=*row2; | 137 | *row1=*row2; |
138 | *row2=row; | 138 | *row2=row; |
139 | } | 139 | } |
140 | if (*col1>*col2) | 140 | if (*col1>*col2) |
141 | { | 141 | { |
142 | col=*col1; | 142 | col=*col1; |
143 | *col1=*col2; | 143 | *col1=*col2; |
144 | *col2=col; | 144 | *col2=col; |
145 | } | 145 | } |
146 | return TRUE; | 146 | return TRUE; |
147 | } | 147 | } |
148 | 148 | ||
149 | bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError) | 149 | bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError) |
150 | { | 150 | { |
151 | int position=variable.find(QRegExp("\\d")); | 151 | int position=variable.find(QRegExp("\\d")); |
152 | if (position<1) | 152 | if (position<1) |
153 | { | 153 | { |
154 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\'')); | 154 | if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\'')); |
155 | return FALSE; | 155 | return FALSE; |
156 | } | 156 | } |
157 | *row=variable.mid(position).toInt()-1; | 157 | *row=variable.mid(position).toInt()-1; |
158 | *col=getHeaderColumn(variable.left(position))-1; | 158 | *col=getHeaderColumn(variable.left(position))-1; |
159 | return TRUE; | 159 | return TRUE; |
160 | } | 160 | } |
161 | 161 | ||
162 | double Sheet::calculateVariable(const QString &variable) | 162 | double Sheet::calculateVariable(const QString &variable) |
163 | { | 163 | { |
164 | bool ok; | 164 | bool ok; |
165 | double tempResult=variable.toDouble(&ok); | 165 | double tempResult=variable.toDouble(&ok); |
166 | if (ok) return tempResult; | 166 | if (ok) return tempResult; |
167 | 167 | ||
168 | int row, col; | 168 | int row, col; |
169 | return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0); | 169 | return (findRowColumn(variable, &row, &col, TRUE) ? dataParser(variable, text(row, col)).toDouble() : 0); |
170 | } | 170 | } |
171 | 171 | ||
172 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) | 172 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) |
173 | { | 173 | { |
174 | int row1, col1, row2, col2, row, col; | 174 | int row1, col1, row2, col2, row, col; |
175 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 175 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
176 | 176 | ||
177 | double result=0, tempResult; | 177 | double result=0, tempResult; |
178 | bool ok; | 178 | bool ok; |
179 | for (row=row1; row<=row2; ++row) | 179 | for (row=row1; row<=row2; ++row) |
180 | for (col=col1; col<=col2; ++col) | 180 | for (col=col1; col<=col2; ++col) |
181 | { | 181 | { |
182 | tempResult=text(row, col).toDouble(&ok); | 182 | tempResult=text(row, col).toDouble(&ok); |
183 | if (ok) result+=tempResult; | 183 | if (ok) result+=tempResult; |
184 | } | 184 | } |
185 | 185 | ||
186 | return result; | 186 | return result; |
187 | } | 187 | } |
188 | 188 | ||
189 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) | 189 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) |
190 | { | 190 | { |
191 | int row1, col1, row2, col2, row, col; | 191 | int row1, col1, row2, col2, row, col; |
192 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 192 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
193 | 193 | ||
194 | double min=0, tempMin; | 194 | double min=0, tempMin; |
195 | bool ok, init=FALSE; | 195 | bool ok, init=FALSE; |
196 | for (row=row1; row<=row2; ++row) | 196 | for (row=row1; row<=row2; ++row) |
197 | for (col=col1; col<=col2; ++col) | 197 | for (col=col1; col<=col2; ++col) |
198 | { | 198 | { |
199 | tempMin=text(row, col).toDouble(&ok); | 199 | tempMin=text(row, col).toDouble(&ok); |
200 | if (ok && (!init || tempMin<min)) | 200 | if (ok && (!init || tempMin<min)) |
201 | { | 201 | { |
202 | min=tempMin; | 202 | min=tempMin; |
203 | init=TRUE; | 203 | init=TRUE; |
204 | } | 204 | } |
205 | } | 205 | } |
206 | 206 | ||
207 | return min; | 207 | return min; |
208 | } | 208 | } |
209 | 209 | ||
210 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) | 210 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) |
211 | { | 211 | { |
212 | int row1, col1, row2, col2, row, col; | 212 | int row1, col1, row2, col2, row, col; |
213 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 213 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
214 | 214 | ||
215 | double max=0, tempMax; | 215 | double max=0, tempMax; |
216 | bool ok, init=FALSE; | 216 | bool ok, init=FALSE; |
217 | for (row=row1; row<=row2; ++row) | 217 | for (row=row1; row<=row2; ++row) |
218 | for (col=col1; col<=col2; ++col) | 218 | for (col=col1; col<=col2; ++col) |
219 | { | 219 | { |
220 | tempMax=text(row, col).toDouble(&ok); | 220 | tempMax=text(row, col).toDouble(&ok); |
221 | if (ok && (!init || tempMax>max)) | 221 | if (ok && (!init || tempMax>max)) |
222 | { | 222 | { |
223 | max=tempMax; | 223 | max=tempMax; |
224 | init=TRUE; | 224 | init=TRUE; |
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | return max; | 228 | return max; |
229 | } | 229 | } |
230 | 230 | ||
231 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) | 231 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) |
232 | { | 232 | { |
233 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); | 233 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); |
234 | return (resultCount>0 ? resultSum/resultCount : 0); | 234 | return (resultCount>0 ? resultSum/resultCount : 0); |
235 | } | 235 | } |
236 | 236 | ||
237 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) | 237 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) |
238 | { | 238 | { |
239 | int row1, col1, row2, col2, row, col; | 239 | int row1, col1, row2, col2, row, col; |
240 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 240 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
241 | 241 | ||
242 | int divider=0; | 242 | int divider=0; |
243 | bool ok; | 243 | bool ok; |
244 | for (row=row1; row<=row2; ++row) | 244 | for (row=row1; row<=row2; ++row) |
245 | for (col=col1; col<=col2; ++col) | 245 | for (col=col1; col<=col2; ++col) |
246 | { | 246 | { |
247 | text(row, col).toDouble(&ok); | 247 | text(row, col).toDouble(&ok); |
248 | if (ok) ++divider; | 248 | if (ok) ++divider; |
249 | } | 249 | } |
250 | 250 | ||
251 | return divider; | 251 | return divider; |
252 | } | 252 | } |
253 | 253 | ||
254 | double Sheet::calculateFunction(const QString &function, const QString ¶meters) | 254 | double Sheet::calculateFunction(const QString &function, const QString ¶meters) |
255 | { | 255 | { |
256 | if (function=="+") | 256 | if (function=="+") |
257 | return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1)); | 257 | return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1)); |
258 | if (function=="-") | 258 | if (function=="-") |
259 | return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1)); | 259 | return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1)); |
260 | if (function=="*") | 260 | if (function=="*") |
261 | return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1)); | 261 | return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1)); |
262 | if (function=="/") | 262 | if (function=="/") |
263 | return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1)); | 263 | return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1)); |
264 | if (function=="SUM") | 264 | if (function=="SUM") |
265 | return functionSum(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 265 | return functionSum(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
266 | if (function=="COUNT") | 266 | if (function=="COUNT") |
267 | return functionCount(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 267 | return functionCount(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
268 | if (function=="MIN") | 268 | if (function=="MIN") |
269 | return functionMin(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 269 | return functionMin(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
270 | if (function=="MAX") | 270 | if (function=="MAX") |
271 | return functionMax(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 271 | return functionMax(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
272 | if (function=="AVG") | 272 | if (function=="AVG") |
273 | return functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 273 | return functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
274 | if (function=="ABS") | 274 | if (function=="ABS") |
275 | return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 275 | return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
276 | if (function=="SIN") | 276 | if (function=="SIN") |
277 | return sin(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 277 | return sin(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
278 | if (function=="COS") | 278 | if (function=="COS") |
279 | return cos(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 279 | return cos(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
280 | if (function=="TAN") | 280 | if (function=="TAN") |
281 | return tan(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 281 | return tan(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
282 | if (function=="ATAN") | 282 | if (function=="ATAN") |
283 | return atan(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 283 | return atan(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
284 | if (function=="ATAN2") | 284 | if (function=="ATAN2") |
285 | return atan2(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); | 285 | return atan2(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); |
286 | if (function=="ASIN") | 286 | if (function=="ASIN") |
287 | return asin(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 287 | return asin(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
288 | if (function=="ACOS") | 288 | if (function=="ACOS") |
289 | return acos(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 289 | return acos(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
290 | if (function=="EXP") | 290 | if (function=="EXP") |
291 | return exp(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 291 | return exp(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
292 | if (function=="LOG") | 292 | if (function=="LOG") |
293 | return log(calculateVariable(getParameter(parameters, 0, TRUE, function))); | 293 | return log(calculateVariable(getParameter(parameters, 0, TRUE, function))); |
294 | if (function=="POW") | 294 | if (function=="POW") |
295 | return pow(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); | 295 | return pow(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function))); |
296 | return 0; | 296 | return 0; |
297 | } | 297 | } |
298 | 298 | ||
299 | int Sheet::getOperatorPriority(char oper) | 299 | int Sheet::getOperatorPriority(char oper) |
300 | { | 300 | { |
301 | switch (oper) | 301 | switch (oper) |
302 | { | 302 | { |
303 | case '+': | 303 | case '+': |
304 | case '-': | 304 | case '-': |
305 | return 1; | 305 | return 1; |
306 | 306 | ||
307 | case '*': | 307 | case '*': |
308 | case '/': | 308 | case '/': |
309 | return 2; | 309 | return 2; |
310 | } | 310 | } |
311 | return 0; | 311 | return 0; |
312 | } | 312 | } |
313 | 313 | ||
314 | void Sheet::pushCharStack(QStack<QChar> *stackChars, const QChar &character) | 314 | void Sheet::pushCharStack(QStack<QChar> *stackChars, const QChar &character) |
315 | { | 315 | { |
316 | QChar *temp=new QChar(character); | 316 | QChar *temp=new QChar(character); |
317 | stackChars->push(temp); | 317 | stackChars->push(temp); |
318 | } | 318 | } |
319 | 319 | ||
320 | void Sheet::pushStringStack(QStack<QString> *stackStrings, const QString &string) | 320 | void Sheet::pushStringStack(QStack<QString> *stackStrings, const QString &string) |
321 | { | 321 | { |
322 | QString *temp=new QString(string); | 322 | QString *temp=new QString(string); |
323 | stackStrings->push(temp); | 323 | stackStrings->push(temp); |
324 | } | 324 | } |
325 | 325 | ||
326 | QChar Sheet::popCharStack(QStack<QChar> *stackChars) | 326 | QChar Sheet::popCharStack(QStack<QChar> *stackChars) |
327 | { | 327 | { |
328 | if (stackChars->isEmpty()) | 328 | if (stackChars->isEmpty()) |
329 | { | 329 | { |
330 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); | 330 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); |
331 | return '0'; | 331 | return '0'; |
332 | } | 332 | } |
333 | 333 | ||
334 | QChar *temp=stackChars->pop(); | 334 | QChar *temp=stackChars->pop(); |
335 | QChar temp2(*temp); | 335 | QChar temp2(*temp); |
336 | delete temp; | 336 | delete temp; |
337 | return temp2; | 337 | return temp2; |
338 | } | 338 | } |
339 | 339 | ||
340 | QString Sheet::popStringStack(QStack<QString> *stackStrings) | 340 | QString Sheet::popStringStack(QStack<QString> *stackStrings) |
341 | { | 341 | { |
342 | if (stackStrings->isEmpty()) | 342 | if (stackStrings->isEmpty()) |
343 | { | 343 | { |
344 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); | 344 | QMessageBox::critical(this, tr("Error"), tr("Syntax error!")); |
345 | return "0"; | 345 | return "0"; |
346 | } | 346 | } |
347 | 347 | ||
348 | QString *temp=stackStrings->pop(); | 348 | QString *temp=stackStrings->pop(); |
349 | QString temp2(*temp); | 349 | QString temp2(*temp); |
350 | delete temp; | 350 | delete temp; |
351 | return temp2; | 351 | return temp2; |
352 | } | 352 | } |
353 | 353 | ||
354 | QString Sheet::dataParserHelper(const QString &data) | 354 | QString Sheet::dataParserHelper(const QString &data) |
355 | { | 355 | { |
356 | QStack<QString> stackElements; | 356 | QStack<QString> stackElements; |
357 | QStack<QChar> stackOperators; | 357 | QStack<QChar> stackOperators; |
358 | QString tempElement(""), temp2Element, firstElement, secondElement; | 358 | QString tempElement(""), temp2Element, firstElement, secondElement; |
359 | int paranCount; | 359 | int paranCount; |
360 | 360 | ||
361 | for (unsigned int i=0; i<data.length(); ++i) | 361 | for (unsigned int i=0; i<data.length(); ++i) |
362 | { | 362 | { |
363 | if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/') | 363 | if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/') |
364 | { | 364 | { |
365 | pushStringStack(&stackElements, tempElement); | 365 | pushStringStack(&stackElements, tempElement); |
366 | tempElement=""; | 366 | tempElement=""; |
367 | if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i])) | 367 | if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i])) |
368 | { | 368 | { |
369 | secondElement=popStringStack(&stackElements); | 369 | secondElement=popStringStack(&stackElements); |
370 | firstElement=popStringStack(&stackElements); | 370 | firstElement=popStringStack(&stackElements); |
371 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 371 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
372 | } | 372 | } |
373 | pushCharStack(&stackOperators, data[i]); | 373 | pushCharStack(&stackOperators, data[i]); |
374 | } | 374 | } |
375 | else | 375 | else |
376 | if (data[i]==',') | 376 | if (data[i]==',') |
377 | { | 377 | { |
378 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); | 378 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); |
379 | while (!stackOperators.isEmpty()) | 379 | while (!stackOperators.isEmpty()) |
380 | { | 380 | { |
381 | secondElement=popStringStack(&stackElements); | 381 | secondElement=popStringStack(&stackElements); |
382 | firstElement=popStringStack(&stackElements); | 382 | firstElement=popStringStack(&stackElements); |
383 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 383 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
384 | } | 384 | } |
385 | tempElement=""; | 385 | tempElement=""; |
386 | } | 386 | } |
387 | else | 387 | else |
388 | if (data[i]=='(') | 388 | if (data[i]=='(') |
389 | { | 389 | { |
390 | paranCount=1; | 390 | paranCount=1; |
391 | temp2Element=""; | 391 | temp2Element=""; |
392 | for (++i; paranCount>0; ++i) | 392 | for (++i; paranCount>0; ++i) |
393 | { | 393 | { |
394 | temp2Element+=data[i]; | 394 | temp2Element+=data[i]; |
395 | if (data[i]=='(') ++paranCount; | 395 | if (data[i]=='(') ++paranCount; |
396 | if (data[i]==')') --paranCount; | 396 | if (data[i]==')') --paranCount; |
397 | } | 397 | } |
398 | temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1)); | 398 | temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1)); |
399 | if (tempElement.isEmpty()) | 399 | if (tempElement.isEmpty()) |
400 | tempElement=temp2Element; | 400 | tempElement=temp2Element; |
401 | else | 401 | else |
402 | tempElement.setNum(calculateFunction(tempElement, temp2Element)); | 402 | tempElement.setNum(calculateFunction(tempElement, temp2Element)); |
403 | --i; | 403 | --i; |
404 | } | 404 | } |
405 | else | 405 | else |
406 | tempElement+=data[i]; | 406 | tempElement+=data[i]; |
407 | } | 407 | } |
408 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); | 408 | if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement); |
409 | while (!stackOperators.isEmpty()) | 409 | while (!stackOperators.isEmpty()) |
410 | { | 410 | { |
411 | secondElement=popStringStack(&stackElements); | 411 | secondElement=popStringStack(&stackElements); |
412 | firstElement=popStringStack(&stackElements); | 412 | firstElement=popStringStack(&stackElements); |
413 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); | 413 | pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement))); |
414 | } | 414 | } |
415 | 415 | ||
416 | if (!stackElements.isEmpty()) | 416 | if (!stackElements.isEmpty()) |
417 | tempElement=popStringStack(&stackElements); | 417 | tempElement=popStringStack(&stackElements); |
418 | while (!stackElements.isEmpty()) | 418 | while (!stackElements.isEmpty()) |
419 | tempElement.prepend(popStringStack(&stackElements)+","); | 419 | tempElement.prepend(popStringStack(&stackElements)+","); |
420 | return tempElement; | 420 | return tempElement; |
421 | } | 421 | } |
422 | 422 | ||
423 | QString Sheet::dataParser(const QString &data) | 423 | QString Sheet::dataParser(const QString &cell, const QString &data) |
424 | { | 424 | { |
425 | QString strippedData(data); | 425 | QString strippedData(data); |
426 | strippedData.replace(QRegExp("\\s"), ""); | 426 | strippedData.replace(QRegExp("\\s"), ""); |
427 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; | 427 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; |
428 | if (listDataParser.find(cell)!=listDataParser.end()) return "0"; | ||
429 | listDataParser.append(cell); | ||
428 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); | 430 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); |
429 | 431 | ||
430 | int i=0; | 432 | int i=0; |
431 | QString tempParameter(getParameter(strippedData, i)), result=""; | 433 | QString tempParameter(getParameter(strippedData, i)), result=""; |
432 | do | 434 | do |
433 | { | 435 | { |
434 | result+=","+QString::number(calculateVariable(tempParameter)); | 436 | result+=","+QString::number(calculateVariable(tempParameter)); |
435 | tempParameter=getParameter(strippedData, ++i); | 437 | tempParameter=getParameter(strippedData, ++i); |
436 | } | 438 | } |
437 | while (!tempParameter.isNull()); | 439 | while (!tempParameter.isNull()); |
440 | listDataParser.remove(cell); | ||
438 | return result.mid(1); | 441 | return result.mid(1); |
439 | } | 442 | } |
440 | 443 | ||
441 | void Sheet::setData(const QString &data) | 444 | void Sheet::setData(const QString &data) |
442 | { | 445 | { |
443 | setText(currentRow(), currentColumn(), data); | 446 | setText(currentRow(), currentColumn(), data); |
444 | slotCellChanged(currentRow(), currentColumn()); | 447 | slotCellChanged(currentRow(), currentColumn()); |
445 | activateNextCell(); | 448 | activateNextCell(); |
446 | } | 449 | } |
447 | 450 | ||
448 | QString Sheet::getData() | 451 | QString Sheet::getData() |
449 | { | 452 | { |
450 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); | 453 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); |
451 | if (cellData) | 454 | if (cellData) |
452 | return cellData->data; | 455 | return cellData->data; |
453 | return ""; | 456 | return ""; |
454 | } | 457 | } |
455 | 458 | ||
456 | void Sheet::lockClicks(bool lock) | 459 | void Sheet::lockClicks(bool lock) |
457 | { | 460 | { |
458 | clicksLocked=lock; | 461 | clicksLocked=lock; |
459 | } | 462 | } |
460 | 463 | ||
461 | void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) | 464 | void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) |
462 | { | 465 | { |
463 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; | 466 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; |
464 | 467 | ||
465 | int sheetDataCurrent=sheetData.at(); | 468 | int sheetDataCurrent=sheetData.at(); |
466 | typeCellData *cellData=findCellData(row, col); | 469 | typeCellData *cellData=findCellData(row, col); |
467 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); | 470 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); |
468 | if (!cellData) cellData=&defaultCellData; | 471 | if (!cellData) cellData=&defaultCellData; |
469 | if (selected) | 472 | if (selected) |
470 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); | 473 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); |
471 | else | 474 | else |
472 | { | 475 | { |
473 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); | 476 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); |
474 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); | 477 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); |
475 | } | 478 | } |
476 | 479 | ||
477 | QTableItem *cellItem=item(row, col); | 480 | QTableItem *cellItem=item(row, col); |
478 | if (cellItem) | 481 | if (cellItem) |
479 | { | 482 | { |
480 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); | 483 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); |
481 | p->setFont(cellData->font); | 484 | p->setFont(cellData->font); |
482 | p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); | 485 | p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); |
483 | } | 486 | } |
484 | 487 | ||
485 | int rx=cr.width()-1, ry=cr.height()-1; | 488 | int rx=cr.width()-1, ry=cr.height()-1; |
486 | QPen pen(p->pen()); | 489 | QPen pen(p->pen()); |
487 | p->setPen(cellData->borders.right); | 490 | p->setPen(cellData->borders.right); |
488 | p->drawLine(rx, 0, rx, ry); | 491 | p->drawLine(rx, 0, rx, ry); |
489 | p->setPen(cellData->borders.bottom); | 492 | p->setPen(cellData->borders.bottom); |
490 | p->drawLine(0, ry, rx, ry); | 493 | p->drawLine(0, ry, rx, ry); |
491 | p->setPen(pen); | 494 | p->setPen(pen); |
492 | } | 495 | } |
493 | 496 | ||
494 | void Sheet::viewportMousePressEvent(QMouseEvent *e) | 497 | void Sheet::viewportMousePressEvent(QMouseEvent *e) |
495 | { | 498 | { |
496 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 499 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
497 | if (clicksLocked) | 500 | if (clicksLocked) |
498 | { | 501 | { |
499 | if (selectionNo<0) | 502 | if (selectionNo<0) |
500 | { | 503 | { |
501 | clearSelection(); | 504 | clearSelection(); |
502 | QTableSelection newSelection; | 505 | QTableSelection newSelection; |
503 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 506 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
504 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); | 507 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); |
505 | selectionNo=addSelection(newSelection); | 508 | selectionNo=addSelection(newSelection); |
506 | } | 509 | } |
507 | } | 510 | } |
508 | else | 511 | else |
509 | QTable::contentsMousePressEvent(&ce); | 512 | QTable::contentsMousePressEvent(&ce); |
510 | } | 513 | } |
511 | 514 | ||
512 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) | 515 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) |
513 | { | 516 | { |
514 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 517 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
515 | if (clicksLocked) | 518 | if (clicksLocked) |
516 | { | 519 | { |
517 | if (selectionNo>=0) | 520 | if (selectionNo>=0) |
518 | { | 521 | { |
519 | QTableSelection oldSelection(selection(selectionNo)); | 522 | QTableSelection oldSelection(selection(selectionNo)); |
520 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 523 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
521 | if (!(oldSelection==selection(selectionNo))) | 524 | if (!(oldSelection==selection(selectionNo))) |
522 | { | 525 | { |
523 | removeSelection(selectionNo); | 526 | removeSelection(selectionNo); |
524 | selectionNo=addSelection(oldSelection); | 527 | selectionNo=addSelection(oldSelection); |
525 | } | 528 | } |
526 | } | 529 | } |
527 | } | 530 | } |
528 | else | 531 | else |
529 | QTable::contentsMouseMoveEvent(&ce); | 532 | QTable::contentsMouseMoveEvent(&ce); |
530 | } | 533 | } |
531 | 534 | ||
532 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) | 535 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) |
533 | { | 536 | { |
534 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 537 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
535 | if (clicksLocked && selectionNo>=0) | 538 | if (clicksLocked && selectionNo>=0) |
536 | { | 539 | { |
537 | QTableSelection oldSelection(selection(selectionNo)); | 540 | QTableSelection oldSelection(selection(selectionNo)); |
538 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 541 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
539 | removeSelection(selectionNo); | 542 | removeSelection(selectionNo); |
540 | selectionNo=-1; | 543 | selectionNo=-1; |
541 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) | 544 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) |
542 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)); | 545 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())); |
543 | else | 546 | else |
544 | emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)+','+getHeaderString(oldSelection.rightCol()+1)+QString::number(oldSelection.bottomRow()+1)); | 547 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol())); |
545 | } | 548 | } |
546 | else | 549 | else |
547 | QTable::contentsMouseReleaseEvent(&ce); | 550 | QTable::contentsMouseReleaseEvent(&ce); |
548 | } | 551 | } |
549 | 552 | ||
553 | QString Sheet::findCellName(int row, int col) | ||
554 | { | ||
555 | return (getHeaderString(col+1)+QString::number(row+1)); | ||
556 | } | ||
557 | |||
550 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) | 558 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) |
551 | { | 559 | { |
552 | typeCellData *tempCellData, *newCellData; | 560 | typeCellData *tempCellData, *newCellData; |
553 | destSheetData->clear(); | 561 | destSheetData->clear(); |
554 | 562 | ||
555 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 563 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
556 | { | 564 | { |
557 | newCellData=new typeCellData; | 565 | newCellData=new typeCellData; |
558 | *newCellData=*tempCellData; | 566 | *newCellData=*tempCellData; |
559 | destSheetData->append(newCellData); | 567 | destSheetData->append(newCellData); |
560 | } | 568 | } |
561 | } | 569 | } |
562 | 570 | ||
563 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) | 571 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) |
564 | { | 572 | { |
565 | typeCellData *tempCellData, *newCellData; | 573 | typeCellData *tempCellData, *newCellData; |
566 | 574 | ||
567 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 575 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
568 | { | 576 | { |
569 | clearCell(tempCellData->row, tempCellData->col); | 577 | clearCell(tempCellData->row, tempCellData->col); |
570 | updateCell(tempCellData->row, tempCellData->col); | 578 | updateCell(tempCellData->row, tempCellData->col); |
571 | } | 579 | } |
572 | sheetData.clear(); | 580 | sheetData.clear(); |
573 | 581 | ||
574 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) | 582 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) |
575 | { | 583 | { |
576 | newCellData=new typeCellData; | 584 | newCellData=new typeCellData; |
577 | *newCellData=*tempCellData; | 585 | *newCellData=*tempCellData; |
578 | sheetData.append(newCellData); | 586 | sheetData.append(newCellData); |
579 | setText(newCellData->row, newCellData->col, dataParser(newCellData->data)); | 587 | setText(newCellData->row, newCellData->col, dataParser(findCellName(newCellData->row, newCellData->col), newCellData->data)); |
580 | } | 588 | } |
581 | emit sheetModified(); | 589 | emit sheetModified(); |
582 | } | 590 | } |
583 | 591 | ||
584 | void Sheet::setName(const QString &name) | 592 | void Sheet::setName(const QString &name) |
585 | { | 593 | { |
586 | sheetName=name; | 594 | sheetName=name; |
587 | emit sheetModified(); | 595 | emit sheetModified(); |
588 | } | 596 | } |
589 | 597 | ||
590 | QString Sheet::getName() | 598 | QString Sheet::getName() |
591 | { | 599 | { |
592 | return sheetName; | 600 | return sheetName; |
593 | } | 601 | } |
594 | 602 | ||
595 | void Sheet::setBrush(int row, int col, const QBrush &brush) | 603 | void Sheet::setBrush(int row, int col, const QBrush &brush) |
596 | { | 604 | { |
597 | typeCellData *cellData=findCellData(row, col); | 605 | typeCellData *cellData=findCellData(row, col); |
598 | if (!cellData) cellData=createCellData(row, col); | 606 | if (!cellData) cellData=createCellData(row, col); |
599 | if (cellData) | 607 | if (cellData) |
600 | { | 608 | { |
601 | cellData->background=brush; | 609 | cellData->background=brush; |
602 | emit sheetModified(); | 610 | emit sheetModified(); |
603 | } | 611 | } |
604 | } | 612 | } |
605 | 613 | ||
606 | QBrush Sheet::getBrush(int row, int col) | 614 | QBrush Sheet::getBrush(int row, int col) |
607 | { | 615 | { |
608 | typeCellData *cellData=findCellData(row, col); | 616 | typeCellData *cellData=findCellData(row, col); |
609 | if (!cellData) cellData=&defaultCellData; | 617 | if (!cellData) cellData=&defaultCellData; |
610 | return cellData->background; | 618 | return cellData->background; |
611 | } | 619 | } |
612 | 620 | ||
613 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) | 621 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) |
614 | { | 622 | { |
615 | typeCellData *cellData=findCellData(row, col); | 623 | typeCellData *cellData=findCellData(row, col); |
616 | if (!cellData) cellData=createCellData(row, col); | 624 | if (!cellData) cellData=createCellData(row, col); |
617 | if (cellData) | 625 | if (cellData) |
618 | { | 626 | { |
619 | cellData->alignment=flags; | 627 | cellData->alignment=flags; |
620 | emit sheetModified(); | 628 | emit sheetModified(); |
621 | } | 629 | } |
622 | } | 630 | } |
623 | 631 | ||
624 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) | 632 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) |
625 | { | 633 | { |
626 | typeCellData *cellData=findCellData(row, col); | 634 | typeCellData *cellData=findCellData(row, col); |
627 | if (!cellData) cellData=&defaultCellData; | 635 | if (!cellData) cellData=&defaultCellData; |
628 | return cellData->alignment; | 636 | return cellData->alignment; |
629 | } | 637 | } |
630 | 638 | ||
631 | void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color) | 639 | void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color) |
632 | { | 640 | { |
633 | typeCellData *cellData=findCellData(row, col); | 641 | typeCellData *cellData=findCellData(row, col); |
634 | if (!cellData) cellData=createCellData(row, col); | 642 | if (!cellData) cellData=createCellData(row, col); |
635 | if (cellData) | 643 | if (cellData) |
636 | { | 644 | { |
637 | cellData->font=font; | 645 | cellData->font=font; |
638 | cellData->fontColor=color; | 646 | cellData->fontColor=color; |
639 | emit sheetModified(); | 647 | emit sheetModified(); |
640 | } | 648 | } |
641 | } | 649 | } |
642 | 650 | ||
643 | QFont Sheet::getFont(int row, int col) | 651 | QFont Sheet::getFont(int row, int col) |
644 | { | 652 | { |
645 | typeCellData *cellData=findCellData(row, col); | 653 | typeCellData *cellData=findCellData(row, col); |
646 | if (!cellData) cellData=&defaultCellData; | 654 | if (!cellData) cellData=&defaultCellData; |
647 | return cellData->font; | 655 | return cellData->font; |
648 | } | 656 | } |
649 | 657 | ||
650 | QColor Sheet::getFontColor(int row, int col) | 658 | QColor Sheet::getFontColor(int row, int col) |
651 | { | 659 | { |
652 | typeCellData *cellData=findCellData(row, col); | 660 | typeCellData *cellData=findCellData(row, col); |
653 | if (!cellData) cellData=&defaultCellData; | 661 | if (!cellData) cellData=&defaultCellData; |
654 | return cellData->fontColor; | 662 | return cellData->fontColor; |
655 | } | 663 | } |
656 | 664 | ||
657 | void Sheet::setPen(int row, int col, int vertical, const QPen &pen) | 665 | void Sheet::setPen(int row, int col, int vertical, const QPen &pen) |
658 | { | 666 | { |
659 | typeCellData *cellData=findCellData(row, col); | 667 | typeCellData *cellData=findCellData(row, col); |
660 | if (!cellData) cellData=createCellData(row, col); | 668 | if (!cellData) cellData=createCellData(row, col); |
661 | if (cellData) | 669 | if (cellData) |
662 | { | 670 | { |
663 | if (vertical) | 671 | if (vertical) |
664 | cellData->borders.right=pen; | 672 | cellData->borders.right=pen; |
665 | else | 673 | else |
666 | cellData->borders.bottom=pen; | 674 | cellData->borders.bottom=pen; |
667 | emit sheetModified(); | 675 | emit sheetModified(); |
668 | } | 676 | } |
669 | } | 677 | } |
670 | 678 | ||
671 | QPen Sheet::getPen(int row, int col, int vertical) | 679 | QPen Sheet::getPen(int row, int col, int vertical) |
672 | { | 680 | { |
673 | typeCellData *cellData=findCellData(row, col); | 681 | typeCellData *cellData=findCellData(row, col); |
674 | if (!cellData) cellData=&defaultCellData; | 682 | if (!cellData) cellData=&defaultCellData; |
675 | return (vertical ? cellData->borders.right : cellData->borders.bottom); | 683 | return (vertical ? cellData->borders.right : cellData->borders.bottom); |
676 | } | 684 | } |
677 | 685 | ||
678 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) | 686 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) |
679 | { | 687 | { |
680 | int selectionNo=currentSelection(); | 688 | int selectionNo=currentSelection(); |
681 | if (selectionNo>=0) | 689 | if (selectionNo>=0) |
682 | { | 690 | { |
683 | QTableSelection selection(selection(selectionNo)); | 691 | QTableSelection selection(selection(selectionNo)); |
684 | *row1=selection.topRow(); | 692 | *row1=selection.topRow(); |
685 | *row2=selection.bottomRow(); | 693 | *row2=selection.bottomRow(); |
686 | *col1=selection.leftCol(); | 694 | *col1=selection.leftCol(); |
687 | *col2=selection.rightCol(); | 695 | *col2=selection.rightCol(); |
688 | } | 696 | } |
689 | else | 697 | else |
690 | { | 698 | { |
691 | *row1=*row2=currentRow(); | 699 | *row1=*row2=currentRow(); |
692 | *col1=*col2=currentColumn(); | 700 | *col1=*col2=currentColumn(); |
693 | } | 701 | } |
694 | } | 702 | } |
695 | 703 | ||
696 | void Sheet::editClear() | 704 | void Sheet::editClear() |
697 | { | 705 | { |
698 | int row1, row2, col1, col2; | 706 | int row1, row2, col1, col2; |
699 | getSelection(&row1, &col1, &row2, &col2); | 707 | getSelection(&row1, &col1, &row2, &col2); |
700 | 708 | ||
701 | int row, col; | 709 | int row, col; |
702 | for (row=row1; row<=row2; ++row) | 710 | for (row=row1; row<=row2; ++row) |
703 | for (col=col1; col<=col2; ++col) | 711 | for (col=col1; col<=col2; ++col) |
704 | { | 712 | { |
705 | setText(row, col, ""); | 713 | setText(row, col, ""); |
706 | slotCellChanged(row, col); | 714 | slotCellChanged(row, col); |
707 | } | 715 | } |
708 | } | 716 | } |
709 | 717 | ||
710 | void Sheet::editCopy() | 718 | void Sheet::editCopy() |
711 | { | 719 | { |
712 | clipboardData.clear(); | 720 | clipboardData.clear(); |
713 | 721 | ||
714 | int row1, row2, col1, col2; | 722 | int row1, row2, col1, col2; |
715 | getSelection(&row1, &col1, &row2, &col2); | 723 | getSelection(&row1, &col1, &row2, &col2); |
716 | 724 | ||
717 | typeCellData *cellData, *newCellData; | 725 | typeCellData *cellData, *newCellData; |
718 | int row, col; | 726 | int row, col; |
719 | for (row=row1; row<=row2; ++row) | 727 | for (row=row1; row<=row2; ++row) |
720 | for (col=col1; col<=col2; ++col) | 728 | for (col=col1; col<=col2; ++col) |
721 | { | 729 | { |
722 | cellData=findCellData(row, col); | 730 | cellData=findCellData(row, col); |
723 | if (cellData) | 731 | if (cellData) |
724 | { | 732 | { |
725 | newCellData=new typeCellData; | 733 | newCellData=new typeCellData; |
726 | *newCellData=*cellData; | 734 | *newCellData=*cellData; |
727 | newCellData->row-=row1; | 735 | newCellData->row-=row1; |
728 | newCellData->col-=col1; | 736 | newCellData->col-=col1; |
729 | clipboardData.append(newCellData); | 737 | clipboardData.append(newCellData); |
730 | } | 738 | } |
731 | } | 739 | } |
732 | } | 740 | } |
733 | 741 | ||
734 | void Sheet::editCut() | 742 | void Sheet::editCut() |
735 | { | 743 | { |
736 | editCopy(); | 744 | editCopy(); |
737 | editClear(); | 745 | editClear(); |
738 | } | 746 | } |
739 | 747 | ||
740 | void Sheet::editPaste(bool onlyContents) | 748 | void Sheet::editPaste(bool onlyContents) |
741 | { | 749 | { |
742 | int row1=currentRow(), col1=currentColumn(); | 750 | int row1=currentRow(), col1=currentColumn(); |
743 | typeCellData *cellData, *tempCellData; | 751 | typeCellData *cellData, *tempCellData; |
744 | 752 | ||
745 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) | 753 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) |
746 | { | 754 | { |
747 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); | 755 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); |
748 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); | 756 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); |
749 | if (cellData) | 757 | if (cellData) |
750 | { | 758 | { |
751 | if (onlyContents) | 759 | if (onlyContents) |
752 | cellData->data=tempCellData->data; | 760 | cellData->data=tempCellData->data; |
753 | else | 761 | else |
754 | { | 762 | { |
755 | *cellData=*tempCellData; | 763 | *cellData=*tempCellData; |
756 | cellData->row+=row1; | 764 | cellData->row+=row1; |
757 | cellData->col+=col1; | 765 | cellData->col+=col1; |
758 | } | 766 | } |
759 | setText(cellData->row, cellData->col, dataParser(cellData->data)); | 767 | setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); |
760 | emit sheetModified(); | 768 | emit sheetModified(); |
761 | } | 769 | } |
762 | } | 770 | } |
763 | } | 771 | } |
764 | 772 | ||
765 | void Sheet::insertRows(int no, bool allColumns) | 773 | void Sheet::insertRows(int no, bool allColumns) |
766 | { | 774 | { |
767 | setNumRows(numRows()+no); | 775 | setNumRows(numRows()+no); |
768 | 776 | ||
769 | typeCellData *tempCellData; | 777 | typeCellData *tempCellData; |
770 | int row=currentRow(), col=currentColumn(); | 778 | int row=currentRow(), col=currentColumn(); |
771 | 779 | ||
772 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 780 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
773 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 781 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
774 | { | 782 | { |
775 | clearCell(tempCellData->row, tempCellData->col); | 783 | clearCell(tempCellData->row, tempCellData->col); |
776 | tempCellData->row+=no; | 784 | tempCellData->row+=no; |
777 | } | 785 | } |
778 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 786 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
779 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 787 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
780 | { | 788 | { |
781 | updateCell(tempCellData->row-no, tempCellData->col); | 789 | updateCell(tempCellData->row-no, tempCellData->col); |
782 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 790 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
783 | } | 791 | } |
784 | emit sheetModified(); | 792 | emit sheetModified(); |
785 | } | 793 | } |
786 | 794 | ||
787 | void Sheet::insertColumns(int no, bool allRows) | 795 | void Sheet::insertColumns(int no, bool allRows) |
788 | { | 796 | { |
789 | int noCols=numCols(); | 797 | int noCols=numCols(); |
790 | int newCols=noCols+no; | 798 | int newCols=noCols+no; |
791 | setNumCols(newCols); | 799 | setNumCols(newCols); |
792 | for (int i=noCols; i<newCols; ++i) | 800 | for (int i=noCols; i<newCols; ++i) |
793 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); | 801 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); |
794 | 802 | ||
795 | typeCellData *tempCellData; | 803 | typeCellData *tempCellData; |
796 | int col=currentColumn(), row=currentRow(); | 804 | int col=currentColumn(), row=currentRow(); |
797 | 805 | ||
798 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 806 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
799 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 807 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
800 | { | 808 | { |
801 | clearCell(tempCellData->row, tempCellData->col); | 809 | clearCell(tempCellData->row, tempCellData->col); |
802 | tempCellData->col+=no; | 810 | tempCellData->col+=no; |
803 | } | 811 | } |
804 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 812 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
805 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 813 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
806 | { | 814 | { |
807 | updateCell(tempCellData->row, tempCellData->col-no); | 815 | updateCell(tempCellData->row, tempCellData->col-no); |
808 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 816 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
809 | } | 817 | } |
810 | emit sheetModified(); | 818 | emit sheetModified(); |
811 | } | 819 | } |
812 | 820 | ||
813 | void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll) | 821 | void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll) |
814 | { | 822 | { |
815 | typeCellData *tempCellData; | 823 | typeCellData *tempCellData; |
816 | int row1, col1, row2, col2; | 824 | int row1, col1, row2, col2; |
817 | getSelection(&row1, &col1, &row2, &col2); | 825 | getSelection(&row1, &col1, &row2, &col2); |
818 | bool found=FALSE; | 826 | bool found=FALSE; |
819 | 827 | ||
820 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 828 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
821 | if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2)) | 829 | if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2)) |
822 | { | 830 | { |
823 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); | 831 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); |
824 | if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0)) | 832 | if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0)) |
825 | { | 833 | { |
826 | if (!found) | 834 | if (!found) |
827 | { | 835 | { |
828 | found=TRUE; | 836 | found=TRUE; |
829 | clearSelection(); | 837 | clearSelection(); |
830 | } | 838 | } |
831 | setCurrentCell(tempCellData->row, tempCellData->col); | 839 | setCurrentCell(tempCellData->row, tempCellData->col); |
832 | if (replace) | 840 | if (replace) |
833 | { | 841 | { |
834 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); | 842 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); |
835 | setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data)); | 843 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
836 | } | 844 | } |
837 | if (!replace || !replaceAll) break; | 845 | if (!replace || !replaceAll) break; |
838 | } | 846 | } |
839 | } | 847 | } |
840 | 848 | ||
841 | if (found) | 849 | if (found) |
842 | { | 850 | { |
843 | if (replace) | 851 | if (replace) |
844 | slotCellChanged(currentRow(), currentColumn()); | 852 | slotCellChanged(currentRow(), currentColumn()); |
845 | } | 853 | } |
846 | else | 854 | else |
847 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); | 855 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); |
848 | } | 856 | } |
849 | 857 | ||
850 | // | 858 | // |
851 | // Static functions | 859 | // Static functions |
852 | // | 860 | // |
853 | 861 | ||
854 | QString Sheet::getHeaderString(int section) | 862 | QString Sheet::getHeaderString(int section) |
855 | { | 863 | { |
856 | if (section<1) return ""; | 864 | if (section<1) return ""; |
857 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); | 865 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); |
858 | } | 866 | } |
859 | 867 | ||
860 | int Sheet::getHeaderColumn(const QString §ion) | 868 | int Sheet::getHeaderColumn(const QString §ion) |
861 | { | 869 | { |
862 | if (section.isEmpty()) return 0; | 870 | if (section.isEmpty()) return 0; |
863 | return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; | 871 | return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; |
864 | } | 872 | } |
diff --git a/noncore/apps/opie-sheet/sheet.h b/noncore/apps/opie-sheet/sheet.h index f78a684..f4e9d38 100644 --- a/noncore/apps/opie-sheet/sheet.h +++ b/noncore/apps/opie-sheet/sheet.h | |||
@@ -1,134 +1,136 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #ifndef SHEET_H | 15 | #ifndef SHEET_H |
16 | #define SHEET_H | 16 | #define SHEET_H |
17 | 17 | ||
18 | #include <qtable.h> | 18 | #include <qtable.h> |
19 | #include <qstack.h> | 19 | #include <qstack.h> |
20 | 20 | ||
21 | typedef struct typeCellBorders | 21 | typedef struct typeCellBorders |
22 | { | 22 | { |
23 | QPen right, bottom; | 23 | QPen right, bottom; |
24 | }; | 24 | }; |
25 | 25 | ||
26 | typedef struct typeCellData | 26 | typedef struct typeCellData |
27 | { | 27 | { |
28 | int col, row; | 28 | int col, row; |
29 | typeCellBorders borders; | 29 | typeCellBorders borders; |
30 | QBrush background; | 30 | QBrush background; |
31 | Qt::AlignmentFlags alignment; | 31 | Qt::AlignmentFlags alignment; |
32 | QColor fontColor; | 32 | QColor fontColor; |
33 | QFont font; | 33 | QFont font; |
34 | QString data; | 34 | QString data; |
35 | }; | 35 | }; |
36 | 36 | ||
37 | class Sheet: public QTable | 37 | class Sheet: public QTable |
38 | { | 38 | { |
39 | Q_OBJECT | 39 | Q_OBJECT |
40 | 40 | ||
41 | // Variables | 41 | // Variables |
42 | bool clicksLocked; | 42 | bool clicksLocked; |
43 | int selectionNo; | 43 | int selectionNo; |
44 | typeCellBorders defaultBorders; | 44 | typeCellBorders defaultBorders; |
45 | typeCellData defaultCellData; | 45 | typeCellData defaultCellData; |
46 | 46 | ||
47 | // QT objects | 47 | // QT objects |
48 | QList<typeCellData> sheetData, clipboardData; | 48 | QList<typeCellData> sheetData, clipboardData; |
49 | QString pressedCell, releasedCell, sheetName; | 49 | QString pressedCell, releasedCell, sheetName; |
50 | QStringList listDataParser; | ||
50 | 51 | ||
51 | // Private functions | 52 | // Private functions |
52 | int getOperatorPriority(char oper); | 53 | int getOperatorPriority(char oper); |
53 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); | 54 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); |
55 | QString findCellName(int row, int col); | ||
54 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); | 56 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); |
55 | double calculateVariable(const QString &variable); | 57 | double calculateVariable(const QString &variable); |
56 | double calculateFunction(const QString &function, const QString ¶meters); | 58 | double calculateFunction(const QString &function, const QString ¶meters); |
57 | QChar popCharStack(QStack<QChar> *stackChars); | 59 | QChar popCharStack(QStack<QChar> *stackChars); |
58 | QString popStringStack(QStack<QString> *stackStrings); | 60 | QString popStringStack(QStack<QString> *stackStrings); |
59 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); | 61 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); |
60 | QString dataParser(const QString &data); | 62 | QString dataParser(const QString &cell, const QString &data); |
61 | QString dataParserHelper(const QString &data); | 63 | QString dataParserHelper(const QString &data); |
62 | typeCellData *createCellData(int row, int col); | 64 | typeCellData *createCellData(int row, int col); |
63 | typeCellData *findCellData(int row, int col); | 65 | typeCellData *findCellData(int row, int col); |
64 | void pushCharStack(QStack<QChar> *stackChars, const QChar &character); | 66 | void pushCharStack(QStack<QChar> *stackChars, const QChar &character); |
65 | void pushStringStack(QStack<QString> *stackStrings, const QString &string); | 67 | void pushStringStack(QStack<QString> *stackStrings, const QString &string); |
66 | 68 | ||
67 | // Sheet/Qt parser functions | 69 | // Sheet/Qt parser functions |
68 | double functionSum(const QString ¶m1, const QString ¶m2); | 70 | double functionSum(const QString ¶m1, const QString ¶m2); |
69 | double functionAvg(const QString ¶m1, const QString ¶m2); | 71 | double functionAvg(const QString ¶m1, const QString ¶m2); |
70 | double functionMax(const QString ¶m1, const QString ¶m2); | 72 | double functionMax(const QString ¶m1, const QString ¶m2); |
71 | double functionMin(const QString ¶m1, const QString ¶m2); | 73 | double functionMin(const QString ¶m1, const QString ¶m2); |
72 | double functionCount(const QString ¶m1, const QString ¶m2); | 74 | double functionCount(const QString ¶m1, const QString ¶m2); |
73 | 75 | ||
74 | // Reimplemented QTable functions | 76 | // Reimplemented QTable functions |
75 | void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected); | 77 | void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected); |
76 | void viewportMousePressEvent(QMouseEvent *e); | 78 | void viewportMousePressEvent(QMouseEvent *e); |
77 | void viewportMouseMoveEvent(QMouseEvent *e); | 79 | void viewportMouseMoveEvent(QMouseEvent *e); |
78 | void viewportMouseReleaseEvent(QMouseEvent *e); | 80 | void viewportMouseReleaseEvent(QMouseEvent *e); |
79 | 81 | ||
80 | private slots: | 82 | private slots: |
81 | void slotCellSelected(int row, int col); | 83 | void slotCellSelected(int row, int col); |
82 | void slotCellChanged(int row, int col); | 84 | void slotCellChanged(int row, int col); |
83 | 85 | ||
84 | public: | 86 | public: |
85 | Sheet(int numRows, int numCols, QWidget *parent); | 87 | Sheet(int numRows, int numCols, QWidget *parent); |
86 | ~Sheet(); | 88 | ~Sheet(); |
87 | 89 | ||
88 | void setData(const QString &data); | 90 | void setData(const QString &data); |
89 | QString getData(); | 91 | QString getData(); |
90 | 92 | ||
91 | void setName(const QString &data); | 93 | void setName(const QString &data); |
92 | QString getName(); | 94 | QString getName(); |
93 | 95 | ||
94 | void setPen(int row, int col, int vertical, const QPen &pen); | 96 | void setPen(int row, int col, int vertical, const QPen &pen); |
95 | QPen getPen(int row, int col, int vertical); | 97 | QPen getPen(int row, int col, int vertical); |
96 | 98 | ||
97 | void setBrush(int row, int col, const QBrush &brush); | 99 | void setBrush(int row, int col, const QBrush &brush); |
98 | QBrush getBrush(int row, int col); | 100 | QBrush getBrush(int row, int col); |
99 | 101 | ||
100 | void setTextAlign(int row, int col, Qt::AlignmentFlags flags); | 102 | void setTextAlign(int row, int col, Qt::AlignmentFlags flags); |
101 | Qt::AlignmentFlags getAlignment(int row, int col); | 103 | Qt::AlignmentFlags getAlignment(int row, int col); |
102 | 104 | ||
103 | void setTextFont(int row, int col, const QFont &font, const QColor &color); | 105 | void setTextFont(int row, int col, const QFont &font, const QColor &color); |
104 | QFont getFont(int row, int col); | 106 | QFont getFont(int row, int col); |
105 | QColor getFontColor(int row, int col); | 107 | QColor getFontColor(int row, int col); |
106 | 108 | ||
107 | void lockClicks(bool lock=TRUE); | 109 | void lockClicks(bool lock=TRUE); |
108 | void copySheetData(QList<typeCellData> *destSheetData); | 110 | void copySheetData(QList<typeCellData> *destSheetData); |
109 | void setSheetData(QList<typeCellData> *srcSheetData); | 111 | void setSheetData(QList<typeCellData> *srcSheetData); |
110 | void getSelection(int *row1, int *col1, int *row2, int *col2); | 112 | void getSelection(int *row1, int *col1, int *row2, int *col2); |
111 | 113 | ||
112 | void insertRows(int no=1, bool allColumns=TRUE); | 114 | void insertRows(int no=1, bool allColumns=TRUE); |
113 | void insertColumns(int no=1, bool allRows=TRUE); | 115 | void insertColumns(int no=1, bool allRows=TRUE); |
114 | 116 | ||
115 | void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE); | 117 | void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE); |
116 | 118 | ||
117 | // Static functions | 119 | // Static functions |
118 | static int getHeaderColumn(const QString §ion); | 120 | static int getHeaderColumn(const QString §ion); |
119 | static QString getHeaderString(int section); | 121 | static QString getHeaderString(int section); |
120 | 122 | ||
121 | public slots: | 123 | public slots: |
122 | void editCut(); | 124 | void editCut(); |
123 | void editCopy(); | 125 | void editCopy(); |
124 | void editPaste(bool onlyContents=FALSE); | 126 | void editPaste(bool onlyContents=FALSE); |
125 | void editClear(); | 127 | void editClear(); |
126 | void swapCells(int row1, int col1, int row2, int col2); | 128 | void swapCells(int row1, int col1, int row2, int col2); |
127 | 129 | ||
128 | signals: | 130 | signals: |
129 | void currentDataChanged(const QString &data); | 131 | void currentDataChanged(const QString &data); |
130 | void cellClicked(const QString &cell); | 132 | void cellClicked(const QString &cell); |
131 | void sheetModified(); | 133 | void sheetModified(); |
132 | }; | 134 | }; |
133 | 135 | ||
134 | #endif | 136 | #endif |