Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mainwindow.cpp

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the Opie Project
00003              .=l.            Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
00004            .>+-=
00005  _;:,     .>    :=|.         This program is free software; you can
00006 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00007 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%`+i>       _;_.
00012     .i_,=:_.      -<s.       This program is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .`     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=`           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 /*
00030  * Opie Sheet (formerly Sheet/Qt)
00031  * by Serdar Ozler <sozler@sitebest.com>
00032  */
00033 
00034 #include "mainwindow.h"
00035 
00036 /* OPIE */
00037 #include <opie2/oresource.h>
00038 #include <qpe/qpeapplication.h>
00039 
00040 /* QT */
00041 #include <qmessagebox.h>
00042 #include <qradiobutton.h>
00043 
00044 /* STD */
00045 #include "cellformat.h"
00046 #include "numberdlg.h"
00047 #include "textdlg.h"
00048 #include "sortdlg.h"
00049 #include "finddlg.h"
00050 
00051 #define DEFAULT_NUM_ROWS 300
00052 #define DEFAULT_NUM_COLS (26*3)
00053 #define DEFAULT_NUM_SHEETS 3
00054 
00055 MainWindow::MainWindow(QWidget *parent, const char* n, WFlags fl)
00056         :QMainWindow(parent, n, fl)
00057 {
00058     // initialize variables
00059     documentModified=FALSE;
00060 
00061     // construct objects
00062     currentDoc=0;
00063     fileSelector=new FileSelector("application/opie-sheet", this, QString::null);
00064     ExcelSelector=new FileSelector("application/excel",this,QString::null,FALSE);
00065     connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide()));
00066     connect(fileSelector, SIGNAL(newSelected(const DocLnk&)), this, SLOT(selectorFileNew(const DocLnk&)));
00067     connect(fileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(selectorFileOpen(const DocLnk&)));
00068     connect(ExcelSelector,SIGNAL(fileSelected(const DocLnk&)),this,SLOT(slotImportExcel(const DocLnk&)));
00069     connect(ExcelSelector,SIGNAL(closeMe()), this, SLOT(ExcelSelectorHide()));
00070 
00071     listSheets.setAutoDelete(TRUE);
00072 
00073     initActions();
00074     initMenu();
00075     initEditToolbar();
00076     initFunctionsToolbar();
00077     initStandardToolbar();
00078     initSheet();
00079 
00080     // set window title
00081     setCaption(tr("Opie Sheet"));
00082 
00083     // create sheets
00084     selectorFileNew(DocLnk());
00085 }
00086 
00087 MainWindow::~MainWindow()
00088 {
00089     if (currentDoc) delete currentDoc;
00090 }
00091 
00092 void MainWindow::documentSave(DocLnk *lnkDoc)
00093 {
00094     FileManager fm;
00095     QByteArray streamBuffer;
00096     QDataStream stream(streamBuffer, IO_WriteOnly);
00097 
00098     typeSheet *currentSheet=findSheet(sheet->getName());
00099     if (!currentSheet)
00100     {
00101         QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!"));
00102         return;
00103     }
00104     sheet->copySheetData(&currentSheet->data);
00105     stream.writeRawBytes("SQT100", 6);
00106     stream << (Q_UINT32)listSheets.count();
00107     for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
00108     {
00109         stream << tempSheet->name << (Q_UINT32)tempSheet->data.count();
00110         for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next())
00111             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;
00112     }
00113 
00114     lnkDoc->setType("application/opie-sheet");
00115     if (!fm.saveFile(*lnkDoc, streamBuffer))
00116     {
00117         QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!"));
00118         return;
00119     }
00120     documentModified=FALSE;
00121 }
00122 
00123 void MainWindow::documentOpen(const DocLnk &lnkDoc)
00124 {
00125     FileManager fm;
00126     QByteArray streamBuffer;
00127     if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer))
00128     {
00129         QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!"));
00130         documentModified=FALSE;
00131         selectorFileNew(DocLnk());
00132         return;
00133     }
00134     QDataStream stream(streamBuffer, IO_ReadOnly);
00135 
00136     Q_UINT32 countSheet, countCell, i, j, row, col, alignment;
00137     typeSheet *newSheet;
00138     typeCellData *newCell;
00139 
00140     char fileFormat[7];
00141     stream.readRawBytes(fileFormat, 6);
00142     fileFormat[6]=0;
00143     if ((QString)fileFormat!="SQT100")
00144     {
00145         QMessageBox::critical(this, tr("Error"), tr("Invalid file format!"));
00146         documentModified=FALSE;
00147         selectorFileNew(DocLnk());
00148         return;
00149     }
00150 
00151     stream >> countSheet;
00152     for (i=0; i<countSheet; ++i)
00153     {
00154         newSheet=new typeSheet;
00155         newSheet->data.setAutoDelete(TRUE);
00156         stream >> newSheet->name >> countCell;
00157         comboSheets->insertItem(newSheet->name);
00158 
00159         for (j=0; j<countCell; ++j)
00160         {
00161             newCell=new typeCellData;
00162             stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data;
00163             newCell->col=col;
00164             newCell->row=row;
00165             newCell->alignment=(Qt::AlignmentFlags)alignment;
00166             newSheet->data.append(newCell);
00167         }
00168         listSheets.append(newSheet);
00169 
00170         if (i==0)
00171         {
00172             sheet->setName(newSheet->name);
00173             sheet->setSheetData(&newSheet->data);
00174         }
00175     }
00176 }
00177 
00178 int MainWindow::saveCurrentFile(bool ask)
00179 {
00180     if (ask)
00181     {
00182         int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
00183         if (result!=QMessageBox::Yes) return result;
00184     }
00185 
00186     if (!currentDoc->isValid())
00187     {
00188         TextDialog dialogText(this);
00189         if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel;
00190 
00191         currentDoc->setName(dialogText.getValue());
00192         currentDoc->setFile(QString::null);
00193         currentDoc->setLinkFile(QString::null);
00194     }
00195 
00196     documentSave(currentDoc);
00197     return QMessageBox::Yes;
00198 }
00199 
00200 void MainWindow::selectorFileNew(const DocLnk &lnkDoc)
00201 {
00202     selectorHide();
00203 
00204     if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
00205     if (currentDoc) delete currentDoc;
00206     currentDoc = new DocLnk(lnkDoc);
00207     editData->clear();
00208     listSheets.clear();
00209     comboSheets->clear();
00210 
00211     typeSheet *newSheet=createNewSheet();
00212     newSheet->data.setAutoDelete(TRUE);
00213     sheet->setName(newSheet->name);
00214     sheet->setSheetData(&newSheet->data);
00215     for (int i=1; i<DEFAULT_NUM_SHEETS; ++i)
00216         createNewSheet();
00217     documentModified=FALSE;
00218 }
00219 
00220 void MainWindow::closeEvent(QCloseEvent *e)
00221 {
00222     if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore();
00223     else e->accept();
00224 }
00225 
00226 void MainWindow::selectorFileOpen(const DocLnk &lnkDoc)
00227 {
00228     selectorHide();
00229 
00230     if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
00231     if (currentDoc) delete currentDoc;
00232     currentDoc = new DocLnk( lnkDoc );
00233     listSheets.clear();
00234     comboSheets->clear();
00235 
00236     documentOpen(lnkDoc);
00237     documentModified=FALSE;
00238 }
00239 
00240 void MainWindow::selectorShow()
00241 {
00242     sheet->hide();
00243     setCentralWidget(fileSelector);
00244     fileSelector->show();
00245     fileSelector->reread();
00246 }
00247 
00248 void MainWindow::selectorHide()
00249 {
00250     fileSelector->hide();
00251     setCentralWidget(sheet);
00252     sheet->show();
00253 }
00254 
00255 void MainWindow::slotFileNew()
00256 {
00257     selectorFileNew(DocLnk());
00258 }
00259 
00260 void MainWindow::slotFileOpen()
00261 {
00262     selectorShow();
00263 }
00264 
00265 void MainWindow::slotImportExcelOpen()
00266 {
00267     sheet->hide();
00268     setCentralWidget(ExcelSelector);
00269     ExcelSelector->show();
00270     ExcelSelector->reread();
00271 }
00272 
00273 void MainWindow::ExcelSelectorHide()
00274 {
00275     ExcelSelector->hide();
00276     setCentralWidget(sheet);
00277     sheet->show();
00278 }
00279 
00280 void MainWindow::slotFileSave()
00281 {
00282     saveCurrentFile(FALSE);
00283 }
00284 
00285 void MainWindow::setDocument(const QString &applnk_filename)
00286 {
00287     selectorFileOpen(DocLnk(applnk_filename));
00288 }
00289 
00290 void MainWindow::initActions()
00291 {
00292     fileNew=new QAction(tr("New File"),
00293                         Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
00294                         tr("&New"), 0, this);
00295     connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
00296     fileOpen=new QAction(tr("Open File"),
00297                          Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ),
00298                          tr("&Open"), 0, this);
00299     connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
00300     fileSave=new QAction(tr("Save File"),
00301                          Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ),
00302                          tr("&Save"), 0, this);
00303     connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
00304     fileSaveAs=new QAction(tr("Save File As"),
00305                            Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ),
00306                            tr("Save &As"), 0, this);
00307     connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
00308 
00309     //fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this);
00310     //connect(fileQuit, SIGNAL(activated()), this, SLOT(close()));
00311     fileExcelImport=new QAction(tr("Import Excel file"),
00312                                 Opie::Core::OResource::loadPixmap( "opie-sheet/excel16", Opie::Core::OResource::SmallIcon ),
00313                                 tr("Import E&xcel file"),0,this);
00314     connect(fileExcelImport, SIGNAL(activated()), this, SLOT(slotImportExcelOpen()));
00315 
00316     // helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this);
00317     //connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral()));
00318     //helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this);
00319     //connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
00320 
00321     editAccept=new QAction(tr("Accept"),
00322                            Opie::Core::OResource::loadPixmap( "enter", Opie::Core::OResource::SmallIcon ),
00323                            tr("&Accept"), 0, this);
00324     connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept()));
00325     editCancel=new QAction(tr("Cancel"),
00326                            Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),
00327                            tr("&Cancel"), 0, this);
00328     connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel()));
00329     editCellSelect=new QAction(tr("Cell Selector"),
00330                                Opie::Core::OResource::loadPixmap( "opie-sheet/cell-select", Opie::Core::OResource::SmallIcon ),
00331                                tr("Cell &Selector"), 0, this);
00332     editCellSelect->setToggleAction(TRUE);
00333     connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool)));
00334     editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this);
00335     editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this);
00336     editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this);
00337     connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
00338     editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this);
00339     connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents()));
00340     editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this);
00341 
00342     insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this);
00343     connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells()));
00344     insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this);
00345     connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows()));
00346     insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this);
00347     connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols()));
00348     insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this);
00349     connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets()));
00350 
00351     formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this);
00352     connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells()));
00353 
00354     rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this);
00355     connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight()));
00356     rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this);
00357     connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust()));
00358     rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this);
00359     connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow()));
00360     rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this);
00361     connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide()));
00362 
00363     colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this);
00364     connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth()));
00365     colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this);
00366     connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust()));
00367     colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this);
00368     connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow()));
00369     colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this);
00370     connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide()));
00371 
00372     sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this);
00373     connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename()));
00374     sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this);
00375     connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove()));
00376 
00377     dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this);
00378     connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort()));
00379     dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this);
00380     connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace()));
00381 
00382     funcEqual=new QAction(tr("Equal To"),
00383                           Opie::Core::OResource::loadPixmap( "opie-sheet/func-equal", Opie::Core::OResource::SmallIcon ),
00384                           tr("&Equal To"), 0, this);
00385     funcEqual->setToolTip("=");
00386     connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00387     funcPlus=new QAction(tr("Addition"),
00388                          Opie::Core::OResource::loadPixmap( "opie-sheet/func-plus", Opie::Core::OResource::SmallIcon ),
00389                          tr("&Addition"), 0, this);
00390     funcPlus->setToolTip("+");
00391     connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00392     funcMinus=new QAction(tr("Subtraction"),
00393                           Opie::Core::OResource::loadPixmap( "opie-sheet/func-minus", Opie::Core::OResource::SmallIcon ),
00394                           tr("&Subtraction"), 0, this);
00395     funcMinus->setToolTip("-");
00396     connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00397     funcCross=new QAction(tr("Multiplication"),
00398                           Opie::Core::OResource::loadPixmap ("opie-sheet/func-cross", Opie::Core::OResource::SmallIcon ),
00399                           tr("&Multiplication"), 0, this);
00400     funcCross->setToolTip("*");
00401     connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00402     funcDivide=new QAction(tr("Division"),
00403                            Opie::Core::OResource::loadPixmap( "opie-sheet/func-divide", Opie::Core::OResource::SmallIcon ),
00404                            tr("&Division"), 0, this);
00405     funcDivide->setToolTip("/");
00406     connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00407     funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"),
00408                               Opie::Core::OResource::loadPixmap( "opie-sheet/func-paran-open", Opie::Core::OResource::SmallIcon ),
00409                               tr("&Open Paranthesis"), 0, this);
00410     funcParanOpen->setToolTip("(");
00411     connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00412     funcParanClose=new QAction(tr("Close Paranthesis"),
00413                                Opie::Core::OResource::loadPixmap( "opie-sheet/func-paran-close", Opie::Core::OResource::SmallIcon ),
00414                                tr("&Close Paranthesis"), 0, this);
00415     funcParanClose->setToolTip(")");
00416     connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00417     funcComma=new QAction(tr("Comma"),
00418                           Opie::Core::OResource::loadPixmap( "opie-sheet/func-comma", Opie::Core::OResource::SmallIcon ),
00419                           tr("&Comma"), 0, this);
00420     funcComma->setToolTip(",");
00421     connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00422 }
00423 
00424 void MainWindow::initMenu()
00425 {
00426     menu=new QMenuBar(this);
00427 
00428     menuFile=new QPopupMenu;
00429     fileNew->addTo(menuFile);
00430     fileOpen->addTo(menuFile);
00431     fileSave->addTo(menuFile);
00432     fileSaveAs->addTo(menuFile);
00433     //  menuFile->insertSeparator();
00434     //  fileQuit->addTo(menuFile);
00435     menuFile->insertSeparator();
00436     fileExcelImport->addTo(menuFile);
00437     menu->insertItem(tr("&File"), menuFile);
00438 
00439     menuEdit=new QPopupMenu;
00440     editAccept->addTo(menuEdit);
00441     editCancel->addTo(menuEdit);
00442     editCellSelect->addTo(menuEdit);
00443     menuEdit->insertSeparator();
00444     editCut->addTo(menuEdit);
00445     editCopy->addTo(menuEdit);
00446     editPaste->addTo(menuEdit);
00447     editPasteContents->addTo(menuEdit);
00448     editClear->addTo(menuEdit);
00449     menu->insertItem(tr("&Edit"), menuEdit);
00450 
00451     menuInsert=new QPopupMenu;
00452     menu->insertItem(tr("&Insert"), menuInsert);
00453 
00454     menuFormat=new QPopupMenu;
00455     formatCells->addTo(menuFormat);
00456     menu->insertItem(tr("&Format"), menuFormat);
00457 
00458     menuData=new QPopupMenu;
00459     dataSort->addTo(menuData);
00460     dataFindReplace->addTo(menuData);
00461     menu->insertItem(tr("&Data"), menuData);
00462 
00463     //  menuHelp=new QPopupMenu;
00464     // helpGeneral->addTo(menuHelp);
00465     //  helpAbout->addTo(menuHelp);
00466     //  menu->insertItem(tr("&Help"), menuHelp);
00467 
00468     submenuRow=new QPopupMenu;
00469     rowHeight->addTo(submenuRow);
00470     rowAdjust->addTo(submenuRow);
00471     rowShow->addTo(submenuRow);
00472     rowHide->addTo(submenuRow);
00473     menuFormat->insertItem(tr("&Row"), submenuRow);
00474 
00475     submenuCol=new QPopupMenu;
00476     colWidth->addTo(submenuCol);
00477     colAdjust->addTo(submenuCol);
00478     colShow->addTo(submenuCol);
00479     colHide->addTo(submenuCol);
00480     menuFormat->insertItem(tr("Colum&n"), submenuCol);
00481 
00482     submenuSheet=new QPopupMenu;
00483     sheetRename->addTo(submenuSheet);
00484     sheetRemove->addTo(submenuSheet);
00485     menuFormat->insertItem(tr("&Sheet"), submenuSheet);
00486 
00487     submenuFunc=new QPopupMenu;
00488     menuInsert->insertItem(tr("&Function"), submenuFunc);
00489 
00490     submenuFuncStd=new QPopupMenu;
00491     funcPlus->addTo(submenuFuncStd);
00492     funcMinus->addTo(submenuFuncStd);
00493     funcCross->addTo(submenuFuncStd);
00494     funcDivide->addTo(submenuFuncStd);
00495     submenuFunc->insertItem(tr("&Simple"), submenuFuncStd);
00496 
00497 
00498 
00499     submenuFuncStandard=new QPopupMenu;
00500     addFlyAction(tr("ABS(x)"), tr("ABS(x)"), "ABS(", submenuFuncStandard);
00501     addFlyAction(tr("CEILING(x,acc)"), tr("CEILING(x,acc)"), "CEILING(", submenuFuncStandard);
00502     addFlyAction(tr("FACT(x)"), tr("FACT(x)"), "FACT(", submenuFuncStandard);
00503     addFlyAction(tr("FLOOR(x,acc)"), tr("FLOOR(x,acc)"), "FLOOR(", submenuFuncStandard);
00504     addFlyAction(tr("INT(x)"), tr("INT(x)"), "INT(", submenuFuncStandard);
00505     addFlyAction(tr("MOD(x,y)"), tr("MOD(x,y)"), "MOD(", submenuFuncStandard);
00506     addFlyAction(tr("ROUND(x,digits)"), tr("ROUND(x,digits)"), "ROUND(", submenuFuncStandard);
00507     addFlyAction(tr("SIGN(x)"), tr("SIGN(x)"), "SIGN(", submenuFuncStandard);
00508     submenuFuncStandard->insertSeparator();
00509     addFlyAction(tr("EXP(x)"), tr("EXP(x)"), "EXP(", submenuFuncStandard);
00510     addFlyAction(tr("LN(x)"), tr("LN(x)"), "LN(", submenuFuncStandard);
00511     addFlyAction(tr("LOG(x,b)"), tr("LOG(x,b)"), "LOG(", submenuFuncStandard);
00512     addFlyAction(tr("LOG10(x)"), tr("LOG10(x)"), "LOG10(", submenuFuncStandard);
00513     addFlyAction(tr("POWER(x,y)"), tr("POWER(x,y)"), "POWER(", submenuFuncStandard);
00514     addFlyAction(tr("SQRT(x)"), tr("SQRT(x)"), "SQRT(", submenuFuncStandard);
00515     submenuFuncStandard->insertSeparator();
00516     addFlyAction(tr("DEGREES(x)"), tr("DEGREES(x)"), "DEGREES(", submenuFuncStandard);
00517     addFlyAction(tr("RADIANS(x)"), tr("RADIANS(x)"), "RADIANS(", submenuFuncStandard);
00518     addFlyAction(tr("PI()"), tr("PI()"), "PI()", submenuFuncStandard);
00519     addFlyAction(tr("RAND()"), tr("RAND()"), "RAND(", submenuFuncStandard);
00520     addFlyAction(tr("RANDBETWEEN(a,b)"), tr("RANDBETWEEN(a,b)"), "RANDBETWEEN(", submenuFuncStandard);
00521     submenuFunc->insertItem(tr("S&tandard"), submenuFuncStandard);
00522 
00523     submenuFuncLogic=new QPopupMenu;
00524     addFlyAction(tr("AND(x1,x2)"), tr("AND(x1,x2)"), "AND(", submenuFuncLogic);
00525     addFlyAction(tr("NOT(x)"), tr("NOT(x)"), "NOT(", submenuFuncLogic);
00526     addFlyAction(tr("OR(x1,x2)"), tr("OR(x1,x2)"), "OR(", submenuFuncLogic);
00527     submenuFuncLogic->insertSeparator();
00528     addFlyAction(tr("IF(compare,val1,val2)"), tr("IF(compare,val1,val2)"), "IF(", submenuFuncLogic);
00529     addFlyAction(tr("INDEX(range,index)"),tr("INDEX(range,index)"), "INDEX(", submenuFuncLogic);
00530     addFlyAction(tr("ISBLANK(x)"), tr("ISBLANK(x)"), "ISBLANK(", submenuFuncLogic);
00531     addFlyAction(tr("ISNUMBER(x)"), tr("ISNUMBER(x)"), "ISNUMBER(", submenuFuncLogic);
00532     addFlyAction(tr("EVEN(x)"), tr("EVEN(x)"), "EVEN(", submenuFuncLogic);
00533     addFlyAction(tr("ISEVEN(x)"), tr("ISEVEN(x)"), "ISEVEN(", submenuFuncLogic);
00534     addFlyAction(tr("ODD(x)"), tr("ODD(x)"), "ODD(", submenuFuncLogic);
00535     addFlyAction(tr("ISODD(x)"), tr("ISODD(x)"), "ISODD(", submenuFuncLogic);
00536     submenuFunc->insertItem(tr("Logical-&Information"), submenuFuncLogic);
00537 
00538     submenuFuncTrig=new QPopupMenu;
00539     addFlyAction(tr("SIN(x)"), tr("SIN(x)"), "SIN(", submenuFuncTrig);
00540     addFlyAction(tr("COS(x)"), tr("COS(x)"), "COS(", submenuFuncTrig);
00541     addFlyAction(tr("TAN(x)"), tr("TAN(x)"), "TAN(", submenuFuncTrig);
00542     addFlyAction(tr("ASIN(x)"), tr("ASIN(x)"), "ASIN(", submenuFuncTrig);
00543     addFlyAction(tr("ACOS(x)"), tr("ACOS(x)"), "ACOS(", submenuFuncTrig);
00544     addFlyAction(tr("ATAN(x)"), tr("ATAN(x)"), "ATAN(", submenuFuncTrig);
00545     addFlyAction(tr("ATAN2(x,y)"), tr("ATAN2(x,y)"), "ATAN2(", submenuFuncTrig);
00546     submenuFuncTrig->insertSeparator();
00547     addFlyAction(tr("SINH(x)"), tr("SINH(x)"), "SINH(", submenuFuncTrig);
00548     addFlyAction(tr("COSH(x)"), tr("COSH(x)"), "COSH(", submenuFuncTrig);
00549     addFlyAction(tr("TANH(x)"), tr("TANH(x)"), "TANH(", submenuFuncTrig);
00550     addFlyAction(tr("ACOSH(x)"), tr("ACOSH(x)"), "ACOSH(", submenuFuncTrig);
00551     addFlyAction(tr("ASINH(x)"), tr("ASINH(x)"), "ASINH(", submenuFuncTrig);
00552     addFlyAction(tr("ATANH(x)"), tr("ATANH(x)"), "ATANH(", submenuFuncTrig);
00553     submenuFunc->insertItem(tr("&Trigonometric"), submenuFuncTrig);
00554 
00555     submenuFuncString=new QPopupMenu;
00556     addFlyAction(tr("LEN(s)"), tr("LEN(s)"), "LEN(",submenuFuncString);
00557     addFlyAction(tr("LEFT(s,num)"), tr("LEFT(s,num)"), "LEFT(",submenuFuncString);
00558     addFlyAction(tr("RIGHT(s,num)"), tr("RIGHT(s,num)"), "RIGHT(",submenuFuncString);
00559     addFlyAction(tr("MID(s,pos,len)"), tr("MID(s,pos,len)"), "MID(",submenuFuncString);
00560     submenuFuncString->insertSeparator();
00561     addFlyAction(tr("CONCATENATE(s1,s2..)"), tr("CONCATENATE(s1,s2..)"), "CONCATENATE(",submenuFuncString);
00562     addFlyAction(tr("EXACT(s1,s2)"), tr("EXACT(s1,s2)"), "EXACT(",submenuFuncString);
00563     addFlyAction(tr("FIND(what,where,pos)"),
00564                  tr("FIND(what,where,pos)"), "FIND(",submenuFuncString);
00565     addFlyAction(tr("REPLACE(s,pos,len,ns)"), tr("REPLACE(s,pos,len,ns)"), "REPLACE(",submenuFuncString);
00566     addFlyAction(tr("REPT(s,n)"), tr("REPT(s,n)"), "REPT(",submenuFuncString);
00567     submenuFuncString->insertSeparator();
00568     addFlyAction(tr("UPPER(s)"), tr("UPPER(s)"), "UPPER(",submenuFuncString);
00569     addFlyAction(tr("LOWER(s)"), tr("LOWER(s)"), "LOWER(",submenuFuncString);
00570     submenuFunc->insertItem(tr("&Strings"), submenuFuncString);
00571 
00572     submenuFuncStat=new QPopupMenu;
00573     addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat);
00574     addFlyAction(tr("COUNT(range)"), tr("COUNT(range)"), "COUNT(",submenuFuncStat);
00575     addFlyAction(tr("COUNTIF(range,eqls)"), tr("COUNTIF(range,eqls)"), "COUNTIF(",submenuFuncStat);
00576     addFlyAction(tr("MAX(range)"), tr("MAX(range)"), "MAX(",submenuFuncStat);
00577     addFlyAction(tr("MIN(range)"), tr("MIN(range)"), "MIN(",submenuFuncStat);
00578     addFlyAction(tr("SUM(range)"), tr("SUM(range)"), "SUM(",submenuFuncStat);
00579     addFlyAction(tr("SUMSQ(range)"), tr("SUMSQ(range)"), "SUMSQ(",submenuFuncStat);
00580     submenuFuncStat->insertSeparator();
00581     addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat);
00582     addFlyAction(tr("VAR(range)"), tr("VAR(range)"), "VAR(",submenuFuncStat);
00583     addFlyAction(tr("VARP(range)"), tr("VARP(range)"), "VARP(",submenuFuncStat);
00584     addFlyAction(tr("STDEV(range)"), tr("STDEV(range)"), "STDEV(",submenuFuncStat);
00585     addFlyAction(tr("STDEVP(range)"), tr("STDEVP(range)"), "STDEVP(",submenuFuncStat);
00586     addFlyAction(tr("SKEW(range)"), tr("SKEW(range)"), "SKEW(",submenuFuncStat);
00587     addFlyAction(tr("KURT(range)"), tr("KURT(range)"), "KURT(",submenuFuncStat);
00588     submenuFunc->insertItem(tr("Sta&tistical"), submenuFuncStat);
00589 
00590     submenuFuncScientific=new QPopupMenu;
00591     addFlyAction(tr("BESSELI(x,n)"), tr("BESSELI(x,n)"), "BESSELI(",submenuFuncScientific);
00592     addFlyAction(tr("BESSELJ(x,n)"), tr("BESSELJ(x,n)"), "BESSELJ(",submenuFuncScientific);
00593     addFlyAction(tr("BESSELK(x,n)"), tr("BESSELK(x,n)"), "BESSELK(",submenuFuncScientific);
00594     addFlyAction(tr("BESSELY(x,n)"), tr("BESSELY(x,n)"), "BESSELY(",submenuFuncScientific);
00595     submenuFuncScientific->insertSeparator();
00596     addFlyAction(tr("BETAI(x,a,b)"), tr("BETAI(x,a,b)"), "BETAI(",submenuFuncScientific);
00597     addFlyAction(tr("ERF(a,b)"), tr("ERF(a,b)"), "ERF(",submenuFuncScientific);
00598     addFlyAction(tr("ERFC(a,b)"), tr("ERFC(a,b)"), "ERFC(",submenuFuncScientific);
00599     addFlyAction(tr("GAMMALN(x)"), tr("GAMMALN(x)"), "GAMMALN(",submenuFuncScientific);
00600     addFlyAction(tr("GAMMAP(x,a)"), tr("GAMMAP(x,a)"), "GAMMAP(",submenuFuncScientific);
00601     addFlyAction(tr("GAMMAQ(x,a)"), tr("GAMMAQ(x,a)"), "GAMMAQ(",submenuFuncScientific);
00602     submenuFunc->insertItem(tr("Scienti&fic"), submenuFuncScientific);
00603 
00604     submenuFuncDistr=new QPopupMenu;
00605     addFlyAction(tr("BETADIST(z,a,b,Q?)"), tr("BETADIST(z,a,b,Q?)"), "BETADIST(",submenuFuncDistr);
00606     addFlyAction(tr("CHI2DIST(x,n,Q?)"), tr("CHI2DIST(x,n,Q?)"), "CHI2DIST(",submenuFuncDistr);
00607     addFlyAction(tr("CHIDIST(x,n,Q?)"), tr("CHIDIST(x,n,Q?)"), "CHIDIST(",submenuFuncDistr);
00608     addFlyAction(tr("FDIST(z,deg1,deg2,Q?)"), tr("FDIST(z,deg1,deg2,Q?)"), "FDIST(",submenuFuncDistr);
00609     addFlyAction(tr("GAMMADIST(x,a,b,Q?)"), tr("GAMMADIST(x,a,b,Q?)"), "GAMMADIST(",submenuFuncDistr);
00610     addFlyAction(tr("NORMALDIST(x,m,s,Q?)"), tr("NORMALDIST(x,m,s,Q?)"), "NORMALDIST(",submenuFuncDistr);
00611     addFlyAction(tr("PHI(x,Q?)"), tr("PHI(x,Q?)"), "PHI(",submenuFuncDistr);
00612     addFlyAction(tr("POISSON(x,n,Q?)"), tr("POISSON(x,n,Q?)"), "POISSON(",submenuFuncDistr);
00613     submenuFunc->insertItem(tr("&Distributions"), submenuFuncDistr);
00614 
00615 
00616 
00617     menuInsert->insertSeparator();
00618     insertCells->addTo(menuInsert);
00619     insertRows->addTo(menuInsert);
00620     insertCols->addTo(menuInsert);
00621     insertSheets->addTo(menuInsert);
00622 }
00623 
00624 void MainWindow::initStandardToolbar()
00625 {
00626     toolbarStandard=new QToolBar(this);
00627     toolbarStandard->setHorizontalStretchable(TRUE);
00628     moveToolBar(toolbarStandard, Top);
00629 
00630     fileNew->addTo(toolbarStandard);
00631     fileOpen->addTo(toolbarStandard);
00632     fileSave->addTo(toolbarStandard);
00633 
00634     comboSheets=new QComboBox(toolbarStandard);
00635     toolbarStandard->setStretchableWidget(comboSheets);
00636     connect(comboSheets, SIGNAL(activated(const QString&)), this, SLOT(slotSheetChanged(const QString&)));
00637 }
00638 
00639 void MainWindow::initFunctionsToolbar()
00640 {
00641     toolbarFunctions=new QToolBar(this);
00642     toolbarFunctions->setHorizontalStretchable(TRUE);
00643     moveToolBar(toolbarFunctions, Bottom);
00644 
00645     funcEqual->addTo(toolbarFunctions);
00646     funcPlus->addTo(toolbarFunctions);
00647     funcMinus->addTo(toolbarFunctions);
00648     funcCross->addTo(toolbarFunctions);
00649     funcDivide->addTo(toolbarFunctions);
00650     funcParanOpen->addTo(toolbarFunctions);
00651     funcParanClose->addTo(toolbarFunctions);
00652     funcComma->addTo(toolbarFunctions);
00653 
00654     toolFunction=new QToolButton(toolbarFunctions);
00655     toolFunction->setUsesBigPixmap( qApp->desktop()->size().width() > 330 );
00656     toolFunction->setPixmap(Opie::Core::OResource::loadPixmap( "opie-sheet/func-func", Opie::Core::OResource::SmallIcon ));
00657     toolFunction->setTextLabel(tr("Functions"));
00658     toolFunction->setPopup(submenuFunc);
00659     toolFunction->setPopupDelay(0);
00660 }
00661 
00662 void MainWindow::initEditToolbar()
00663 {
00664     toolbarEdit=new QToolBar(this);
00665     toolbarEdit->setHorizontalStretchable(TRUE);
00666     moveToolBar(toolbarEdit, Bottom);
00667 
00668     editAccept->addTo(toolbarEdit);
00669     editCancel->addTo(toolbarEdit);
00670 
00671     editData=new QLineEdit(toolbarEdit);
00672     toolbarEdit->setStretchableWidget(editData);
00673     connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept()));
00674 
00675     editCellSelect->addTo(toolbarEdit);
00676 }
00677 
00678 void MainWindow::slotHelpAbout()
00679 {
00680     QDialog dialogAbout(this, 0, TRUE);
00681     dialogAbout.resize(width()-40, height()-80);
00682     dialogAbout.setCaption(tr("About Opie Sheet"));
00683 
00684     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);
00685     label.setGeometry(dialogAbout.rect());
00686     label.setAlignment(Qt::AlignCenter | Qt::WordBreak);
00687 
00688     dialogAbout.exec();
00689 }
00690 
00691 void MainWindow::initSheet()
00692 {
00693     sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this);
00694     setCentralWidget(sheet);
00695 
00696     connect(sheet, SIGNAL(currentDataChanged(const QString&)), editData, SLOT(setText(const QString&)));
00697     connect(sheet, SIGNAL(cellClicked(const QString&)), this, SLOT(slotCellClicked(const QString&)));
00698     connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified()));
00699 
00700     connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut()));
00701     connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy()));
00702     connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear()));
00703 }
00704 
00705 void MainWindow::slotEditAccept()
00706 {
00707     sheet->setData(editData->text());
00708 }
00709 
00710 void MainWindow::slotEditCancel()
00711 {
00712     editData->setText(sheet->getData());
00713 }
00714 
00715 void MainWindow::slotCellSelect(bool lock)
00716 {
00717     sheet->lockClicks(lock);
00718 }
00719 
00720 void MainWindow::addToData(const QString &data)
00721 {
00722     editData->setText(editData->text().insert(editData->cursorPosition(), data));
00723 }
00724 
00725 void MainWindow::slotFuncOutput()
00726 {
00727     if (sender()->isA("QAction"))
00728         addToData(((QAction *)sender())->toolTip());
00729 }
00730 
00731 void MainWindow::slotInsertRows()
00732 {
00733     NumberDialog dialogNumber(this);
00734     if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted)
00735         sheet->insertRows(dialogNumber.getValue());
00736 }
00737 
00738 void MainWindow::slotInsertCols()
00739 {
00740     NumberDialog dialogNumber(this);
00741     if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted)
00742         sheet->insertColumns(dialogNumber.getValue());
00743 }
00744 
00745 void MainWindow::slotInsertSheets()
00746 {
00747     NumberDialog dialogNumber(this);
00748     if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted)
00749         for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet();
00750 }
00751 
00752 void MainWindow::slotCellClicked(const QString &cell)
00753 {
00754     editCellSelect->setOn(FALSE);
00755     addToData(cell);
00756 }
00757 
00758 typeSheet *MainWindow::createNewSheet()
00759 {
00760     typeSheet *newSheet=new typeSheet;
00761     int currentNo=1, tempNo=0;
00762     bool ok;
00763 
00764     for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
00765         if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok)
00766             currentNo=tempNo+1;
00767 
00768     newSheet->name=tr("Sheet")+QString::number(currentNo);
00769     newSheet->data.setAutoDelete(TRUE);
00770 
00771     comboSheets->insertItem(newSheet->name);
00772     listSheets.append(newSheet);
00773     return newSheet;
00774 }
00775 
00776 typeSheet *MainWindow::findSheet(const QString &name)
00777 {
00778     for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
00779         if (tempSheet->name==name)
00780             return tempSheet;
00781     return NULL;
00782 }
00783 
00784 void MainWindow::slotSheetChanged(const QString &name)
00785 {
00786     sheet->copySheetData(&findSheet(sheet->getName())->data);
00787     sheet->setName(name);
00788     sheet->setSheetData(&findSheet(name)->data);
00789     sheet->ReCalc();
00790 }
00791 
00792 void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w)
00793 {
00794     QAction *action=new QAction(text, menuText, 0, this);
00795     action->setToolTip(tip);
00796     connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
00797     action->addTo(w);
00798 }
00799 
00800 void MainWindow::slotFormatCells()
00801 {
00802     CellFormat dialogCellFormat(this);
00803     QPEApplication::showDialog( &dialogCellFormat );
00804     dialogCellFormat.exec(sheet);
00805 }
00806 
00807 void MainWindow::slotEditPaste()
00808 {
00809     sheet->editPaste();
00810 }
00811 
00812 void MainWindow::slotEditPasteContents()
00813 {
00814     sheet->editPaste(TRUE);
00815 }
00816 
00817 void MainWindow::slotRowHeight()
00818 {
00819     int row1, row2, col1, col2;
00820     sheet->getSelection(&row1, &col1, &row2, &col2);
00821 
00822     NumberDialog dialogNumber(this);
00823     if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted)
00824     {
00825         int newHeight=dialogNumber.getValue(), row;
00826         for (row=row1; row<=row2; ++row)
00827             sheet->setRowHeight(row, newHeight);
00828     }
00829 }
00830 
00831 void MainWindow::slotRowAdjust()
00832 {
00833     int row1, row2, col1, col2;
00834     sheet->getSelection(&row1, &col1, &row2, &col2);
00835 
00836     for (int row=row1; row<=row2; ++row)
00837         sheet->adjustRow(row);
00838 }
00839 
00840 void MainWindow::slotRowShow()
00841 {
00842     int row1, row2, col1, col2;
00843     sheet->getSelection(&row1, &col1, &row2, &col2);
00844 
00845     for (int row=row1; row<=row2; ++row)
00846         sheet->showRow(row);
00847 }
00848 
00849 void MainWindow::slotRowHide()
00850 {
00851     int row1, row2, col1, col2;
00852     sheet->getSelection(&row1, &col1, &row2, &col2);
00853 
00854     for (int row=row1; row<=row2; ++row)
00855         sheet->hideRow(row);
00856 }
00857 
00858 void MainWindow::slotColumnWidth()
00859 {
00860     int row1, row2, col1, col2;
00861     sheet->getSelection(&row1, &col1, &row2, &col2);
00862 
00863     NumberDialog dialogNumber(this);
00864     if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted)
00865     {
00866         int newWidth=dialogNumber.getValue(), col;
00867         for (col=col1; col<=col2; ++col)
00868             sheet->setColumnWidth(col, newWidth);
00869     }
00870 }
00871 
00872 void MainWindow::slotColumnAdjust()
00873 {
00874     int row1, row2, col1, col2;
00875     sheet->getSelection(&row1, &col1, &row2, &col2);
00876 
00877     for (int col=col1; col<=col2; ++col)
00878         sheet->adjustColumn(col);
00879 }
00880 
00881 void MainWindow::slotColumnShow()
00882 {
00883     int row1, row2, col1, col2;
00884     sheet->getSelection(&row1, &col1, &row2, &col2);
00885 
00886     for (int col=col1; col<=col2; ++col)
00887         sheet->showColumn(col);
00888 }
00889 
00890 void MainWindow::slotColumnHide()
00891 {
00892     int row1, row2, col1, col2;
00893     sheet->getSelection(&row1, &col1, &row2, &col2);
00894 
00895     for (int col=col1; col<=col2; ++col)
00896         sheet->hideColumn(col);
00897 }
00898 
00899 void MainWindow::slotFileSaveAs()
00900 {
00901     TextDialog dialogText(this);
00902     if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
00903 
00904     currentDoc->setName(dialogText.getValue());
00905     currentDoc->setFile(QString::null);
00906     currentDoc->setLinkFile(QString::null);
00907     documentSave(currentDoc);
00908 }
00909 
00910 void MainWindow::slotImportExcel(const DocLnk &lnkDoc)
00911 {
00912     ExcelBook file1;
00913     if ( !file1.ParseBook((char *)lnkDoc.file().ascii()) ){
00914             QMessageBox::critical(this, tr("Error"), tr("<td>Unable to open or parse file!</td>"));
00915             return;
00916     }
00917     int NumOfSheets=file1.Sheets.count();
00918     printf("OpieSheet::NumberOfSheets:%d\r\n",NumOfSheets);
00919     if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
00920     if (currentDoc) delete currentDoc;
00921     currentDoc = new DocLnk();
00922     listSheets.clear();
00923     comboSheets->clear();
00924     int w1,r,c;
00925     ExcelSheet* sh1;
00926     typeSheet* newSheet;
00927     QString* str;
00928     typeCellData* newCell;
00929     for(w1=1;w1<=NumOfSheets;w1++)
00930     {
00931         sh1=file1.Sheets[w1-1];
00932         // printf("OpieSheet:newSheet:%x,r=%d,c=%d\r\n",sh1, sh1->rows,sh1->cols);
00933         newSheet=new typeSheet;
00934         newSheet->data.setAutoDelete(TRUE);
00935         newSheet->name=sh1->name;
00936         printf("OpieSheet:Sheetname:%s\r\n",sh1->name.ascii());
00937         comboSheets->insertItem(newSheet->name);
00938         for(r=1; r <= sh1->rows; r++)
00939         {
00940             for(c=1;c <= sh1->cols; c++)
00941             {
00942                 str=file1.CellDataString(sh1,r-1,c-1);
00943                 if(str!=NULL && r<DEFAULT_NUM_ROWS && c<DEFAULT_NUM_COLS)
00944                 {
00945                     newCell=new typeCellData;
00946                     newCell->row=r-1;
00947                     newCell->col=c-1;
00948                     if(str!=NULL) newCell->data=QString(*str); else newCell->data=QString("");
00949                     newCell->background=QBrush(Qt::white, Qt::SolidPattern);
00950                     newCell->alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop);
00951                     newCell->fontColor=Qt::black;
00952                     newCell->font=font();
00953                     newCell->borders.right=QPen(Qt::gray, 1, Qt::SolidLine);
00954                     newCell->borders.bottom=QPen(Qt::gray, 1, Qt::SolidLine);
00955                     newSheet->data.append(newCell);
00956                     //there is no format parsing at the moment or style parsing
00957                     //printf("OpieSheetNumber:row=%d,col=%d,val=%s\r\n",r,c,str->latin1());
00958                 };
00959             };
00960         };
00961         listSheets.append(newSheet);
00962         if (w1==1)//if i==0 link sheet1 with sheetview
00963         {
00964             sheet->setName(newSheet->name);
00965             sheet->setSheetData(&newSheet->data);
00966             sheet->ReCalc();
00967         };
00968 
00969     };
00970     file1.CloseFile();
00971     printf("Excel FILE read OK\r\n");
00972     documentModified=TRUE;
00973 
00974 
00975 }
00976 
00977 void MainWindow::slotSheetRename()
00978 {
00979     TextDialog dialogText(this);
00980     if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
00981     QString newName=dialogText.getValue();
00982 
00983     typeSheet *tempSheet=findSheet(newName);
00984     if (tempSheet)
00985     {
00986         QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\''));
00987         return;
00988     }
00989 
00990     tempSheet=findSheet(sheet->getName());
00991     for (int i=0; i<comboSheets->count(); ++i)
00992         if (comboSheets->text(i)==tempSheet->name)
00993         {
00994             comboSheets->changeItem(newName, i);
00995             break;
00996         }
00997     tempSheet->name=newName;
00998     sheet->setName(newName);
00999 }
01000 
01001 void MainWindow::slotSheetRemove()
01002 {
01003     if (comboSheets->count()<2)
01004     {
01005         QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!"));
01006         return;
01007     }
01008     if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
01009     {
01010         typeSheet *tempSheet=findSheet(sheet->getName());
01011         for (int i=0; i<comboSheets->count(); ++i)
01012             if (comboSheets->text(i)==tempSheet->name)
01013             {
01014                 comboSheets->removeItem(i);
01015                 break;
01016             }
01017         comboSheets->setCurrentItem(0);
01018         slotSheetChanged(comboSheets->currentText());
01019         listSheets.remove(tempSheet);
01020     }
01021 }
01022 
01023 void MainWindow::slotDataSort()
01024 {
01025     SortDialog dialogSort(this);
01026     QPEApplication::showDialog( &dialogSort );
01027     dialogSort.exec(sheet);
01028 }
01029 
01030 void MainWindow::slotDocModified()
01031 {
01032     documentModified=TRUE;
01033 }
01034 
01035 void MainWindow::slotInsertCells()
01036 {
01037     QDialog dialogInsert(this, 0, TRUE);
01038     dialogInsert.resize(180, 130);
01039     dialogInsert.setCaption(tr("Insert Cells"));
01040 
01041     QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert);
01042     group->setGeometry(10, 10, 160, 110);
01043     QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group);
01044     radio=new QRadioButton(tr("Shift cells &right"), group);
01045     radio=new QRadioButton(tr("Entire ro&w"), group);
01046     radio=new QRadioButton(tr("Entire &column"), group);
01047     group->setButton(0);
01048 
01049     if (dialogInsert.exec()==QDialog::Accepted)
01050         switch (group->id(group->selected()))
01051         {
01052         case 0: sheet->insertRows(1, FALSE); break;
01053         case 1: sheet->insertColumns(1, FALSE); break;
01054         case 2: sheet->insertRows(1, TRUE); break;
01055         case 3: sheet->insertColumns(1, TRUE); break;
01056         }
01057 }
01058 
01059 void MainWindow::slotDataFindReplace()
01060 {
01061     FindDialog dialogFind(this);
01062     QPEApplication::showDialog( &dialogFind );
01063     dialogFind.exec(sheet);
01064 }

Generated on Sat Nov 5 16:15:51 2005 for OPIE by  doxygen 1.4.2