-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.cpp | 12 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 4 |
2 files changed, 8 insertions, 8 deletions
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index 1fb2a3d..061748e 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp @@ -1,142 +1,142 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include "mainwindow.h" #include <qpe/resource.h> #include <qpe/qpeapplication.h> #include <qmessagebox.h> #include <qradiobutton.h> #include "cellformat.h" #include "numberdlg.h" #include "textdlg.h" #include "sortdlg.h" #include "finddlg.h" #define DEFAULT_NUM_ROWS 300 #define DEFAULT_NUM_COLS (26*3) #define DEFAULT_NUM_SHEETS 3 MainWindow::MainWindow(QWidget *parent, const char* n, WFlags fl) :QMainWindow(parent, n, fl) { // initialize variables documentModified=FALSE; // construct objects currentDoc=0; fileSelector=new FileSelector("application/sheet-qt", this, QString::null); ExcelSelector=new FileSelector("application/excel",this,QString::null,FALSE); connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); - connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); - connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); - connect(ExcelSelector,SIGNAL(fileSelected(const DocLnk &)),this,SLOT(slotImportExcel(const DocLnk &))); + connect(fileSelector, SIGNAL(newSelected(const DocLnk&)), this, SLOT(selectorFileNew(const DocLnk&))); + connect(fileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(selectorFileOpen(const DocLnk&))); + connect(ExcelSelector,SIGNAL(fileSelected(const DocLnk&)),this,SLOT(slotImportExcel(const DocLnk&))); connect(ExcelSelector,SIGNAL(closeMe()), this, SLOT(ExcelSelectorHide())); listSheets.setAutoDelete(TRUE); initActions(); initMenu(); initEditToolbar(); initFunctionsToolbar(); initStandardToolbar(); initSheet(); // set window title setCaption(tr("Opie Sheet")); // create sheets selectorFileNew(DocLnk()); } MainWindow::~MainWindow() { if (currentDoc) delete currentDoc; } void MainWindow::documentSave(DocLnk *lnkDoc) { FileManager fm; QByteArray streamBuffer; QDataStream stream(streamBuffer, IO_WriteOnly); typeSheet *currentSheet=findSheet(sheet->getName()); if (!currentSheet) { QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); return; } sheet->copySheetData(¤tSheet->data); stream.writeRawBytes("SQT100", 6); stream << (Q_UINT32)listSheets.count(); for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) { stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) 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; } lnkDoc->setType("application/sheet-qt"); if (!fm.saveFile(*lnkDoc, streamBuffer)) { QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); return; } documentModified=FALSE; } void MainWindow::documentOpen(const DocLnk &lnkDoc) { FileManager fm; QByteArray streamBuffer; if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) { QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); documentModified=FALSE; selectorFileNew(DocLnk()); return; } QDataStream stream(streamBuffer, IO_ReadOnly); Q_UINT32 countSheet, countCell, i, j, row, col, alignment; typeSheet *newSheet; typeCellData *newCell; char fileFormat[7]; stream.readRawBytes(fileFormat, 6); fileFormat[6]=0; if ((QString)fileFormat!="SQT100") { QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); documentModified=FALSE; selectorFileNew(DocLnk()); return; } stream >> countSheet; for (i=0; i<countSheet; ++i) { newSheet=new typeSheet; newSheet->data.setAutoDelete(TRUE); stream >> newSheet->name >> countCell; comboSheets->insertItem(newSheet->name); for (j=0; j<countCell; ++j) { newCell=new typeCellData; stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; newCell->col=col; @@ -487,253 +487,253 @@ void MainWindow::initMenu() addFlyAction(tr("COS(x)"), tr("COS(x)"), "COS(", submenuFuncTrig); addFlyAction(tr("TAN(x)"), tr("TAN(x)"), "TAN(", submenuFuncTrig); addFlyAction(tr("ASIN(x)"), tr("ASIN(x)"), "ASIN(", submenuFuncTrig); addFlyAction(tr("ACOS(x)"), tr("ACOS(x)"), "ACOS(", submenuFuncTrig); addFlyAction(tr("ATAN(x)"), tr("ATAN(x)"), "ATAN(", submenuFuncTrig); addFlyAction(tr("ATAN2(x,y)"), tr("ATAN2(x,y)"), "ATAN2(", submenuFuncTrig); submenuFuncTrig->insertSeparator(); addFlyAction(tr("SINH(x)"), tr("SINH(x)"), "SINH(", submenuFuncTrig); addFlyAction(tr("COSH(x)"), tr("COSH(x)"), "COSH(", submenuFuncTrig); addFlyAction(tr("TANH(x)"), tr("TANH(x)"), "TANH(", submenuFuncTrig); addFlyAction(tr("ACOSH(x)"), tr("ACOSH(x)"), "ACOSH(", submenuFuncTrig); addFlyAction(tr("ASINH(x)"), tr("ASINH(x)"), "ASINH(", submenuFuncTrig); addFlyAction(tr("ATANH(x)"), tr("ATANH(x)"), "ATANH(", submenuFuncTrig); submenuFunc->insertItem(tr("&Trigonometric"), submenuFuncTrig); submenuFuncString=new QPopupMenu; addFlyAction(tr("LEN(s)"), tr("LEN(s)"), "LEN(",submenuFuncString); addFlyAction(tr("LEFT(s,num)"), tr("LEFT(s,num)"), "LEFT(",submenuFuncString); addFlyAction(tr("RIGHT(s,num)"), tr("RIGHT(s,num)"), "RIGHT(",submenuFuncString); addFlyAction(tr("MID(s,pos,len)"), tr("MID(s,pos,len)"), "MID(",submenuFuncString); submenuFuncString->insertSeparator(); addFlyAction(tr("CONCATENATE(s1,s2..)"), tr("CONCATENATE(s1,s2..)"), "CONCATENATE(",submenuFuncString); addFlyAction(tr("EXACT(s1,s2)"), tr("EXACT(s1,s2)"), "EXACT(",submenuFuncString); addFlyAction(tr("FIND(what,where,pos)"), tr("FIND(what,where,pos)"), "FIND(",submenuFuncString); addFlyAction(tr("REPLACE(s,pos,len,ns)"), tr("REPLACE(s,pos,len,ns)"), "REPLACE(",submenuFuncString); addFlyAction(tr("REPT(s,n)"), tr("REPT(s,n)"), "REPT(",submenuFuncString); submenuFuncString->insertSeparator(); addFlyAction(tr("UPPER(s)"), tr("UPPER(s)"), "UPPER(",submenuFuncString); addFlyAction(tr("LOWER(s)"), tr("LOWER(s)"), "LOWER(",submenuFuncString); submenuFunc->insertItem(tr("&Strings"), submenuFuncString); submenuFuncStat=new QPopupMenu; addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat); addFlyAction(tr("COUNT(range)"), tr("COUNT(range)"), "COUNT(",submenuFuncStat); addFlyAction(tr("COUNTIF(range,eqls)"), tr("COUNTIF(range,eqls)"), "COUNTIF(",submenuFuncStat); addFlyAction(tr("MAX(range)"), tr("MAX(range)"), "MAX(",submenuFuncStat); addFlyAction(tr("MIN(range)"), tr("MIN(range)"), "MIN(",submenuFuncStat); addFlyAction(tr("SUM(range)"), tr("SUM(range)"), "SUM(",submenuFuncStat); addFlyAction(tr("SUMSQ(range)"), tr("SUMSQ(range)"), "SUMSQ(",submenuFuncStat); submenuFuncStat->insertSeparator(); addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat); addFlyAction(tr("VAR(range)"), tr("VAR(range)"), "VAR(",submenuFuncStat); addFlyAction(tr("VARP(range)"), tr("VARP(range)"), "VARP(",submenuFuncStat); addFlyAction(tr("STDEV(range)"), tr("STDEV(range)"), "STDEV(",submenuFuncStat); addFlyAction(tr("STDEVP(range)"), tr("STDEVP(range)"), "STDEVP(",submenuFuncStat); addFlyAction(tr("SKEW(range)"), tr("SKEW(range)"), "SKEW(",submenuFuncStat); addFlyAction(tr("KURT(range)"), tr("KURT(range)"), "KURT(",submenuFuncStat); submenuFunc->insertItem(tr("Sta&tistical"), submenuFuncStat); submenuFuncScientific=new QPopupMenu; addFlyAction(tr("BESSELI(x,n)"), tr("BESSELI(x,n)"), "BESSELI(",submenuFuncScientific); addFlyAction(tr("BESSELJ(x,n)"), tr("BESSELJ(x,n)"), "BESSELJ(",submenuFuncScientific); addFlyAction(tr("BESSELK(x,n)"), tr("BESSELK(x,n)"), "BESSELK(",submenuFuncScientific); addFlyAction(tr("BESSELY(x,n)"), tr("BESSELY(x,n)"), "BESSELY(",submenuFuncScientific); submenuFuncScientific->insertSeparator(); addFlyAction(tr("BETAI(x,a,b)"), tr("BETAI(x,a,b)"), "BETAI(",submenuFuncScientific); addFlyAction(tr("ERF(a,b)"), tr("ERF(a,b)"), "ERF(",submenuFuncScientific); addFlyAction(tr("ERFC(a,b)"), tr("ERFC(a,b)"), "ERFC(",submenuFuncScientific); addFlyAction(tr("GAMMALN(x)"), tr("GAMMALN(x)"), "GAMMALN(",submenuFuncScientific); addFlyAction(tr("GAMMAP(x,a)"), tr("GAMMAP(x,a)"), "GAMMAP(",submenuFuncScientific); addFlyAction(tr("GAMMAQ(x,a)"), tr("GAMMAQ(x,a)"), "GAMMAQ(",submenuFuncScientific); submenuFunc->insertItem(tr("Scienti&fic"), submenuFuncScientific); submenuFuncDistr=new QPopupMenu; addFlyAction(tr("BETADIST(z,a,b,Q?)"), tr("BETADIST(z,a,b,Q?)"), "BETADIST(",submenuFuncDistr); addFlyAction(tr("CHI2DIST(x,n,Q?)"), tr("CHI2DIST(x,n,Q?)"), "CHI2DIST(",submenuFuncDistr); addFlyAction(tr("CHIDIST(x,n,Q?)"), tr("CHIDIST(x,n,Q?)"), "CHIDIST(",submenuFuncDistr); addFlyAction(tr("FDIST(z,deg1,deg2,Q?)"), tr("FDIST(z,deg1,deg2,Q?)"), "FDIST(",submenuFuncDistr); addFlyAction(tr("GAMMADIST(x,a,b,Q?)"), tr("GAMMADIST(x,a,b,Q?)"), "GAMMADIST(",submenuFuncDistr); addFlyAction(tr("NORMALDIST(x,m,s,Q?)"), tr("NORMALDIST(x,m,s,Q?)"), "NORMALDIST(",submenuFuncDistr); addFlyAction(tr("PHI(x,Q?)"), tr("PHI(x,Q?)"), "PHI(",submenuFuncDistr); addFlyAction(tr("POISSON(x,n,Q?)"), tr("POISSON(x,n,Q?)"), "POISSON(",submenuFuncDistr); submenuFunc->insertItem(tr("&Distributions"), submenuFuncDistr); menuInsert->insertSeparator(); insertCells->addTo(menuInsert); insertRows->addTo(menuInsert); insertCols->addTo(menuInsert); insertSheets->addTo(menuInsert); } void MainWindow::initStandardToolbar() { toolbarStandard=new QToolBar(this); toolbarStandard->setHorizontalStretchable(TRUE); moveToolBar(toolbarStandard, Top); fileNew->addTo(toolbarStandard); fileOpen->addTo(toolbarStandard); fileSave->addTo(toolbarStandard); comboSheets=new QComboBox(toolbarStandard); toolbarStandard->setStretchableWidget(comboSheets); - connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &))); + connect(comboSheets, SIGNAL(activated(const QString&)), this, SLOT(slotSheetChanged(const QString&))); } void MainWindow::initFunctionsToolbar() { toolbarFunctions=new QToolBar(this); toolbarFunctions->setHorizontalStretchable(TRUE); moveToolBar(toolbarFunctions, Bottom); funcEqual->addTo(toolbarFunctions); funcPlus->addTo(toolbarFunctions); funcMinus->addTo(toolbarFunctions); funcCross->addTo(toolbarFunctions); funcDivide->addTo(toolbarFunctions); funcParanOpen->addTo(toolbarFunctions); funcParanClose->addTo(toolbarFunctions); funcComma->addTo(toolbarFunctions); toolFunction=new QToolButton(toolbarFunctions); toolFunction->setPixmap(Resource::loadPixmap( "opie-sheet/func-func" )); toolFunction->setTextLabel(tr("Functions")); toolFunction->setPopup(submenuFunc); toolFunction->setPopupDelay(0); } void MainWindow::initEditToolbar() { toolbarEdit=new QToolBar(this); toolbarEdit->setHorizontalStretchable(TRUE); moveToolBar(toolbarEdit, Bottom); editAccept->addTo(toolbarEdit); editCancel->addTo(toolbarEdit); editData=new QLineEdit(toolbarEdit); toolbarEdit->setStretchableWidget(editData); connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); editCellSelect->addTo(toolbarEdit); } void MainWindow::slotHelpAbout() { QDialog dialogAbout(this, 0, TRUE); dialogAbout.resize(width()-40, height()-80); dialogAbout.setCaption(tr("About Opie Sheet")); 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); label.setGeometry(dialogAbout.rect()); label.setAlignment(Qt::AlignCenter | Qt::WordBreak); dialogAbout.exec(); } void MainWindow::initSheet() { sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); setCentralWidget(sheet); - connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &))); - connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &))); + connect(sheet, SIGNAL(currentDataChanged(const QString&)), editData, SLOT(setText(const QString&))); + connect(sheet, SIGNAL(cellClicked(const QString&)), this, SLOT(slotCellClicked(const QString&))); connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); } void MainWindow::slotEditAccept() { sheet->setData(editData->text()); } void MainWindow::slotEditCancel() { editData->setText(sheet->getData()); } void MainWindow::slotCellSelect(bool lock) { sheet->lockClicks(lock); } void MainWindow::addToData(const QString &data) { editData->setText(editData->text().insert(editData->cursorPosition(), data)); } void MainWindow::slotFuncOutput() { if (sender()->isA("QAction")) addToData(((QAction *)sender())->toolTip()); } void MainWindow::slotInsertRows() { NumberDialog dialogNumber(this); if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) sheet->insertRows(dialogNumber.getValue()); } void MainWindow::slotInsertCols() { NumberDialog dialogNumber(this); if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) sheet->insertColumns(dialogNumber.getValue()); } void MainWindow::slotInsertSheets() { NumberDialog dialogNumber(this); if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); } void MainWindow::slotCellClicked(const QString &cell) { editCellSelect->setOn(FALSE); addToData(cell); } typeSheet *MainWindow::createNewSheet() { typeSheet *newSheet=new typeSheet; int currentNo=1, tempNo=0; bool ok; for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) currentNo=tempNo+1; newSheet->name=tr("Sheet")+QString::number(currentNo); newSheet->data.setAutoDelete(TRUE); comboSheets->insertItem(newSheet->name); listSheets.append(newSheet); return newSheet; } typeSheet *MainWindow::findSheet(const QString &name) { for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) if (tempSheet->name==name) return tempSheet; return NULL; } void MainWindow::slotSheetChanged(const QString &name) { sheet->copySheetData(&findSheet(sheet->getName())->data); sheet->setName(name); sheet->setSheetData(&findSheet(name)->data); sheet->ReCalc(); } void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) { diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index f303d33..d4419af 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp @@ -1,143 +1,143 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include "sheet.h" #include <qmessagebox.h> #include <math.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #define DEFAULT_COL_WIDTH 50 Sheet::Sheet(int numRows, int numCols, QWidget *parent) :QTable(numRows, numCols, parent) { defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); defaultCellData.data=""; defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); defaultCellData.fontColor=Qt::black; defaultCellData.font=font(); defaultCellData.borders=defaultBorders; clicksLocked=FALSE; selectionNo=-1; setSelectionMode(QTable::Single); sheetData.setAutoDelete(TRUE); clipboardData.setAutoDelete(TRUE); for (int i=0; i<numCols; ++i) horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); - connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCellSelected(int, int))); - connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(slotCellChanged(int, int))); + connect(this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int))); + connect(this, SIGNAL(valueChanged(int,int)), this, SLOT(slotCellChanged(int,int))); } Sheet::~Sheet() { } typeCellData *Sheet::findCellData(int row, int col) { typeCellData *tempCellData; for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) { if (tempCellData->row==row && tempCellData->col==col) return tempCellData; } return NULL; } void Sheet::slotCellSelected(int row, int col) { typeCellData *cellData=findCellData(row, col); if (cellData) { emit currentDataChanged(cellData->data); }else emit currentDataChanged(""); } typeCellData *Sheet::createCellData(int row, int col) { if (row<0 || col<0) return NULL; typeCellData *cellData=new typeCellData; cellData->row=row; cellData->col=col; cellData->data=defaultCellData.data; cellData->borders=defaultCellData.borders; cellData->alignment=defaultCellData.alignment; cellData->font=defaultCellData.font; cellData->fontColor=defaultCellData.fontColor; cellData->background=defaultCellData.background; sheetData.append(cellData); return cellData; } void Sheet::slotCellChanged(int row, int col) { typeCellData *cellData=findCellData(row, col); if (!cellData) cellData=createCellData(row, col); if (cellData) cellData->data=text(row, col); for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) { // modified by Toussis Manolis koppermind@panafonet.gr // the parser was crashing if there were no closed parenthesis. int w1,ii=0; for(w1=0;w1<=(int)text(row, col).length();w1++) { if(text(row,col)[w1]=='(') ii++; if(text(row,col)[w1]==')') ii--; }; if(ii==0) setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); //end of modification // old was plain: //setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); }; emit sheetModified(); } void Sheet::ReCalc(void) { typeCellData* cellData; for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) { //printf("cellchanged:%d, %d\r\n",cellData->row,cellData->col); slotCellChanged(cellData->row,cellData->col); }; }; void Sheet::swapCells(int row1, int col1, int row2, int col2) { typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); if (!cellData1) cellData1=createCellData(row1, col1); if (!cellData2) cellData2=createCellData(row2, col2); if (cellData1 && cellData2) { QString tempData(cellData1->data); cellData1->data=cellData2->data; cellData2->data=tempData; setText(cellData1->row, cellData1->col, dataParser(findCellName(cellData1->row, cellData1->col), cellData1->data)); setText(cellData2->row, cellData2->col, dataParser(findCellName(cellData2->row, cellData2->col), cellData2->data)); emit sheetModified(); } } |