summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp38
-rw-r--r--noncore/apps/opie-sheet/mainwindow.h5
2 files changed, 20 insertions, 23 deletions
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp
index efbcc20..09ee68b 100644
--- a/noncore/apps/opie-sheet/mainwindow.cpp
+++ b/noncore/apps/opie-sheet/mainwindow.cpp
@@ -32,97 +32,99 @@
#include "edit-accept.xpm"
#include "help-general.xpm"
#include "func-plus.xpm"
#include "func-minus.xpm"
#include "func-cross.xpm"
#include "func-divide.xpm"
#include "func-paran-open.xpm"
#include "func-paran-close.xpm"
#include "func-comma.xpm"
#include "func-func.xpm"
#include "func-equal.xpm"
#include "cell-select.xpm"
#define DEFAULT_NUM_ROWS 199
#define DEFAULT_NUM_COLS (26*3)
#define DEFAULT_NUM_SHEETS 3
MainWindow::MainWindow()
:QMainWindow()
{
// initialize variables
documentModified=FALSE;
// construct objects
+ currentDoc=0;
fileSelector=new FileSelector("application/sheet-qt", this, QString::null);
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 &)));
listSheets.setAutoDelete(TRUE);
initActions();
initMenu();
initEditToolbar();
initFunctionsToolbar();
initStandardToolbar();
initSheet();
// set window title
setCaption(tr("Opie Sheet"));
// create sheets
- selectorFileNew(currentDoc);
+ selectorFileNew(DocLnk());
}
MainWindow::~MainWindow()
{
+ if (currentDoc) delete currentDoc;
}
-void MainWindow::documentSave(DocLnk &lnkDoc)
+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(&currentSheet->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))
+ 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;
@@ -151,100 +153,94 @@ void MainWindow::documentOpen(const DocLnk &lnkDoc)
stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data;
newCell->col=col;
newCell->row=row;
newCell->alignment=(Qt::AlignmentFlags)alignment;
newSheet->data.append(newCell);
}
listSheets.append(newSheet);
if (i==0)
{
sheet->setName(newSheet->name);
sheet->setSheetData(&newSheet->data);
}
}
}
int MainWindow::saveCurrentFile(bool ask=TRUE)
{
if (ask)
{
int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
if (result!=QMessageBox::Yes) return result;
}
- if (currentDoc.name().isEmpty() || !currentDoc.isValid())
+ if (!currentDoc->isValid())
{
TextDialog dialogText(this);
if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel;
- currentDoc.setName(dialogText.getValue());
+ currentDoc->setName(dialogText.getValue());
+ currentDoc->setFile(QString::null);
+ currentDoc->setLinkFile(QString::null);
}
documentSave(currentDoc);
return QMessageBox::Yes;
}
-void MainWindow::copyDocLnk(const DocLnk &source, DocLnk &target)
-{
- target.setName(source.name());
- target.setFile(source.file());
- target.setLinkFile(source.linkFile());
- target.setComment(source.comment());
- target.setType(source.type());
- target.setCategories(source.categories());
-}
-
void MainWindow::selectorFileNew(const DocLnk &lnkDoc)
{
selectorHide();
if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
- copyDocLnk(lnkDoc, currentDoc);
+ if (currentDoc) delete currentDoc;
+ currentDoc = new DocLnk(lnkDoc);
listSheets.clear();
comboSheets->clear();
typeSheet *newSheet=createNewSheet();
newSheet->data.setAutoDelete(TRUE);
sheet->setName(newSheet->name);
sheet->setSheetData(&newSheet->data);
for (int i=1; i<DEFAULT_NUM_SHEETS; ++i)
createNewSheet();
documentModified=FALSE;
}
void MainWindow::closeEvent(QCloseEvent *e)
{
if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore();
else e->accept();
}
void MainWindow::selectorFileOpen(const DocLnk &lnkDoc)
{
selectorHide();
if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
- copyDocLnk(lnkDoc, currentDoc);
+ if (currentDoc) delete currentDoc;
+ currentDoc = new DocLnk(lnkDoc);
listSheets.clear();
comboSheets->clear();
documentOpen(lnkDoc);
documentModified=FALSE;
}
void MainWindow::selectorShow()
{
sheet->hide();
setCentralWidget(fileSelector);
fileSelector->show();
fileSelector->reread();
}
void MainWindow::selectorHide()
{
fileSelector->hide();
setCentralWidget(sheet);
sheet->show();
}
void MainWindow::slotFileNew()
{
@@ -733,51 +729,53 @@ void MainWindow::slotColumnAdjust()
sheet->adjustColumn(col);
}
void MainWindow::slotColumnShow()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int col=col1; col<=col2; ++col)
sheet->showColumn(col);
}
void MainWindow::slotColumnHide()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int col=col1; col<=col2; ++col)
sheet->hideColumn(col);
}
void MainWindow::slotFileSaveAs()
{
TextDialog dialogText(this);
- if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc.name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
+ if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
- currentDoc.setName(dialogText.getValue());
+ currentDoc->setName(dialogText.getValue());
+ currentDoc->setFile(QString::null);
+ currentDoc->setLinkFile(QString::null);
documentSave(currentDoc);
}
void MainWindow::slotSheetRename()
{
TextDialog dialogText(this);
if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
QString newName=dialogText.getValue();
typeSheet *tempSheet=findSheet(newName);
if (tempSheet)
{
QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\''));
return;
}
tempSheet=findSheet(sheet->getName());
for (int i=0; i<comboSheets->count(); ++i)
if (comboSheets->text(i)==tempSheet->name)
{
comboSheets->changeItem(newName, i);
break;
}
tempSheet->name=newName;
diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h
index 554e6f6..d68e25c 100644
--- a/noncore/apps/opie-sheet/mainwindow.h
+++ b/noncore/apps/opie-sheet/mainwindow.h
@@ -18,87 +18,86 @@
#include <qpe/applnk.h>
#include <qpe/fileselector.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
#include <qmainwindow.h>
#include <qaction.h>
#include <qlineedit.h>
#include <qbutton.h>
#include <qcombobox.h>
#include <qtoolbutton.h>
#include "sheet.h"
typedef struct typeSheet
{
QString name;
QList<typeCellData> data;
};
class MainWindow: public QMainWindow
{
Q_OBJECT
// QPE objects
- DocLnk currentDoc;
+ DocLnk* currentDoc;
QPEMenuBar *menu;
QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard;
FileSelector *fileSelector;
// QT objects
QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp,
*submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat,
*submenuRow, *submenuCol, *submenuSheet;
QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells,
*funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual,
*editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells,
*rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove,
*dataSort, *dataFindReplace, *editCellSelect, *helpGeneral;
QLineEdit *editData;
QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight;
QComboBox *comboSheets;
QToolButton *toolFunction;
QList<typeSheet> listSheets;
QString helpFile;
// Other objects
Sheet *sheet;
// Variables
bool documentModified;
// Private functions
void initMenu();
void initActions();
void initFunctionsToolbar();
void initEditToolbar();
void initStandardToolbar();
void initSheet();
void addToData(const QString &data);
int saveCurrentFile(bool ask=TRUE);
void documentOpen(const DocLnk &lnkDoc);
- void copyDocLnk(const DocLnk &source, DocLnk &target);
- void documentSave(DocLnk &lnkDoc);
+ void documentSave(DocLnk *lnkDoc);
void closeEvent(QCloseEvent *e);
void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w);
typeSheet *createNewSheet();
typeSheet *findSheet(const QString &name);
private slots:
void slotFileNew();
void slotFileOpen();
void slotFileSave();
void slotFileSaveAs();
void slotHelpAbout();
void slotHelpGeneral();
void slotEditAccept();
void slotEditCancel();
void slotEditPaste();
void slotEditPasteContents();
void slotFormatCells();
void slotInsertCells();
void slotInsertRows();
void slotInsertCols();
void slotInsertSheets();
void slotDataSort();
void slotDataFindReplace();
void slotRowHeight();