summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/cell-select.xpm23
-rw-r--r--noncore/apps/opie-sheet/cellformat.cpp585
-rw-r--r--noncore/apps/opie-sheet/cellformat.h106
-rw-r--r--noncore/apps/opie-sheet/edit-accept.xpm30
-rw-r--r--noncore/apps/opie-sheet/edit-cancel.xpm25
-rw-r--r--noncore/apps/opie-sheet/file-new.xpm24
-rw-r--r--noncore/apps/opie-sheet/file-open.xpm25
-rw-r--r--noncore/apps/opie-sheet/file-save.xpm24
-rw-r--r--noncore/apps/opie-sheet/finddlg.cpp70
-rw-r--r--noncore/apps/opie-sheet/finddlg.h35
-rw-r--r--noncore/apps/opie-sheet/func-comma.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-cross.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-divide.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-equal.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-func.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-minus.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-paran-close.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-paran-open.xpm21
-rw-r--r--noncore/apps/opie-sheet/func-plus.xpm21
-rw-r--r--noncore/apps/opie-sheet/help-general.xpm25
-rw-r--r--noncore/apps/opie-sheet/main.cpp14
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp836
-rw-r--r--noncore/apps/opie-sheet/mainwindow.h120
-rw-r--r--noncore/apps/opie-sheet/numberdlg.cpp35
-rw-r--r--noncore/apps/opie-sheet/numberdlg.h24
-rw-r--r--noncore/apps/opie-sheet/opie-sheet.control10
-rw-r--r--noncore/apps/opie-sheet/opie-sheet.pro9
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp849
-rw-r--r--noncore/apps/opie-sheet/sheet.h120
-rw-r--r--noncore/apps/opie-sheet/sortdlg.cpp178
-rw-r--r--noncore/apps/opie-sheet/sortdlg.h45
-rw-r--r--noncore/apps/opie-sheet/textdlg.cpp32
-rw-r--r--noncore/apps/opie-sheet/textdlg.h24
-rw-r--r--pics/opie-sheet/sheetqt.pngbin0 -> 2105 bytes
34 files changed, 3457 insertions, 0 deletions
diff --git a/noncore/apps/opie-sheet/cell-select.xpm b/noncore/apps/opie-sheet/cell-select.xpm
new file mode 100644
index 0000000..2b0ab7e
--- a/dev/null
+++ b/noncore/apps/opie-sheet/cell-select.xpm
@@ -0,0 +1,23 @@
+/* XPM */
+static const char * cell_select_xpm[] = {
+"16 16 4 1",
+" c None",
+". c #000000",
+"+ c #FFFFFF",
+"@ c #BEBEBE",
+". ",
+". ... ",
+" ... .+++. ",
+" ..+@+++. ",
+" .+++@++@. ",
+" .+@+++@@++. ",
+" .@++@++@+++. ",
+" .@@++@@+++++. ",
+" .++@+@+++++++. ",
+" .++@++++++++. ",
+" .++@+++++++. ",
+" .++@+++++@. ",
+" .++@+++@+. ",
+" .++@@@+. ",
+" .++++. ",
+" .... "};
diff --git a/noncore/apps/opie-sheet/cellformat.cpp b/noncore/apps/opie-sheet/cellformat.cpp
new file mode 100644
index 0000000..6a2ff72
--- a/dev/null
+++ b/noncore/apps/opie-sheet/cellformat.cpp
@@ -0,0 +1,585 @@
+#include "cellformat.h"
+
+#include <qlistbox.h>
+#include <qlabel.h>
+
+#define COMBO_WIDTHS 155
+#define COMBO_HEIGHTS 21
+
+#define COLOR_COUNT 17
+#define STYLE_COUNT 14
+#define HALIGN_COUNT 3
+#define VALIGN_COUNT 3
+
+QColor qtColors[COLOR_COUNT]={Qt::black, Qt::white, Qt::darkGray, Qt::gray, Qt::lightGray, Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow, Qt::darkRed, Qt::darkGreen, Qt::darkBlue, Qt::darkCyan, Qt::darkMagenta, Qt::darkYellow};
+Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern, Qt::Dense1Pattern, Qt::Dense2Pattern, Qt::Dense3Pattern, Qt::Dense4Pattern, Qt::Dense5Pattern, Qt::Dense6Pattern, Qt::Dense7Pattern, Qt::HorPattern, Qt::VerPattern, Qt::CrossPattern, Qt::BDiagPattern, Qt::FDiagPattern, Qt::DiagCrossPattern};
+QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"};
+QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"};
+Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter};
+Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, Qt::AlignBottom, Qt::AlignVCenter};
+
+CellFormat::CellFormat(QWidget *parent=0)
+ :QDialog(parent, 0, TRUE)
+{
+ // Main widget
+ tabs=new QTabWidget(this);
+ widgetBorders=new QWidget(tabs);
+ widgetBackground=new QWidget(tabs);
+ widgetFont=new QWidget(tabs);
+ widgetAlignment=new QWidget(tabs);
+ tabs->addTab(widgetBorders, tr("&Borders"));
+ tabs->addTab(widgetBackground, tr("Back&ground"));
+ tabs->addTab(widgetFont, tr("&Font"));
+ tabs->addTab(widgetAlignment, tr("&Alignment"));
+
+ fontDB.loadRenderers();
+ changedFont=changedAlign=changedBrush=FALSE;
+
+ // Borders tab
+ borderEditor=new BorderEditor(widgetBorders);
+ borderEditor->setGeometry(10, 10, 215, 145);
+ connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), this, SLOT(borderClicked(BorderEditor::BorderArea)));
+
+ comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165);
+ comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
+
+ buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders);
+ buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
+ connect(buttonBordersDefaults, SIGNAL(clicked()), this, SLOT(slotBordersDefaults()));
+
+ // Background tab
+ frameBackground=new QFrame(widgetBackground);
+ frameBackground->setGeometry(10, 10, 215, 145);
+ frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+
+ comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165);
+ connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
+ comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
+ connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
+
+ buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground);
+ buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
+ connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults()));
+
+ // Font tab
+ frameFont=new QFrame(widgetFont);
+ frameFont->setGeometry(10, 10, 215, 125);
+ frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+
+ comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145);
+ connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
+ comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10));
+ connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
+ comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10));
+ connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
+
+ checkFontBold=new QCheckBox(tr("&Bold"), widgetFont);
+ checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
+ connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
+ checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont);
+ checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
+ connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
+
+ buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont);
+ buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
+ connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults()));
+
+ // Alignment tab
+ frameAlignment=new QFrame(widgetAlignment);
+ frameAlignment->setGeometry(10, 10, 215, 145);
+ frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+
+ comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165);
+ connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
+ comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10));
+ connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
+
+ checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment);
+ checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS);
+ connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool)));
+
+ buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment);
+ buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
+ connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults()));
+
+ // Main widget
+ box=new QVBoxLayout(this);
+ box->addWidget(tabs);
+
+ setCaption(tr("Format Cells"));
+}
+
+CellFormat::~CellFormat()
+{
+}
+
+int CellFormat::findColorIndex(const QColor &color)
+{
+ for (int i=0; i<COLOR_COUNT; ++i)
+ if (qtColors[i]==color)
+ return i;
+ return 0;
+}
+
+int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag)
+{
+ for (int i=0; i<VALIGN_COUNT; ++i)
+ if (flagsVAlign[i] & flag)
+ return i;
+ return 0;
+}
+
+int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag)
+{
+ for (int i=0; i<HALIGN_COUNT; ++i)
+ if (flagsHAlign[i] & flag)
+ return i;
+ return 0;
+}
+
+int CellFormat::findBrushStyleIndex(Qt::BrushStyle style)
+{
+ for (int i=0; i<STYLE_COUNT; ++i)
+ if (brushStyles[i]==style)
+ return i;
+ return 0;
+}
+
+void CellFormat::setBrushBackground(const QBrush &brush)
+{
+ comboBackgroundColor->setCurrentItem(findColorIndex(brush.color()));
+ comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style()));
+
+ QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height());
+ QPainter p(&pix);
+ pix.fill();
+ p.fillRect(pix.rect(), brush);
+ frameBackground->setBackgroundPixmap(pix);
+
+ brushBackground=brush;
+}
+
+void CellFormat::setTextFont(const QFont &font, const QColor &color)
+{
+ comboFontColor->setCurrentItem(findColorIndex(color));
+ comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family()));
+ comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize())));
+ checkFontBold->setChecked(font.weight()==QFont::Bold);
+ checkFontItalic->setChecked(font.italic());
+
+ QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height());
+ QPainter p(&pix);
+ pix.fill();
+ p.fillRect(pix.rect(), Qt::white);
+ p.setFont(font);
+ p.setPen(color);
+ p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet"));
+ frameFont->setBackgroundPixmap(pix);
+
+ fontFont=font;
+ fontColor=color;
+}
+
+void CellFormat::setTextAlign(Qt::AlignmentFlags flags)
+{
+ comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags));
+ comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags));
+ checkAlignmentWrap->setChecked(flags & Qt::WordBreak);
+
+ QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height());
+ QPainter p(&pix);
+ pix.fill();
+ p.fillRect(pix.rect(), Qt::white);
+ p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet"));
+ frameAlignment->setBackgroundPixmap(pix);
+
+ textAlignment=flags;
+}
+
+void CellFormat::slotFontDefaults()
+{
+ changedFont=TRUE;
+ setTextFont(font(), Qt::black);
+}
+
+void CellFormat::slotAlignmentDefaults()
+{
+ changedAlign=TRUE;
+ setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop));
+}
+
+void CellFormat::slotBackgroundDefaults()
+{
+ changedBrush=TRUE;
+ setBrushBackground(Qt::white);
+}
+
+void CellFormat::slotBordersDefaults()
+{
+ QPen defaultPen(Qt::gray, 1, Qt::SolidLine);
+ borderEditor->setPen(defaultPen, BorderEditor::Top);
+ borderEditor->setPen(defaultPen, BorderEditor::Bottom);
+ borderEditor->setPen(defaultPen, BorderEditor::Left);
+ borderEditor->setPen(defaultPen, BorderEditor::Right);
+ borderEditor->setPen(defaultPen, BorderEditor::Vert);
+ borderEditor->setPen(defaultPen, BorderEditor::Horz);
+}
+
+void CellFormat::backgroundClicked(int index)
+{
+ changedBrush=TRUE;
+ setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()]));
+}
+
+void CellFormat::fontClicked(bool on)
+{
+ fontClicked(0);
+}
+
+void CellFormat::fontClicked(int index)
+{
+ changedFont=TRUE;
+ setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]);
+}
+
+void CellFormat::alignClicked(bool on)
+{
+ alignClicked(0);
+}
+
+void CellFormat::alignClicked(int index)
+{
+ changedAlign=TRUE;
+ setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0)));
+}
+
+void CellFormat::createSizeCombo(QComboBox *combo)
+{
+ combo->clear();
+ QValueList<int> sizes=fontDB.standardSizes();
+ for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i)
+ combo->insertItem(QString::number(*i));
+}
+
+void CellFormat::borderClicked(BorderEditor::BorderArea area)
+{
+ QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine);
+ if (newPen==borderEditor->getPen(area))
+ borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area);
+ else
+ borderEditor->setPen(newPen, area);
+}
+
+int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item)
+{
+ for (int i=0; i<combo->count(); ++i)
+ if (combo->text(i)==item)
+ return i;
+ return 0;
+}
+
+QComboBox *CellFormat::createCombo(comboType type, QWidget *parent, const QString &caption, int y)
+{
+ QComboBox *combo=new QComboBox(FALSE, parent);
+ combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS);
+ combo->setSizeLimit(5);
+
+ switch (type)
+ {
+ case COMBO_WIDTH: createWidthCombo(combo); break;
+ case COMBO_STYLE: createStyleCombo(combo); break;
+ case COMBO_FONT: createFontCombo(combo); break;
+ case COMBO_SIZE: createSizeCombo(combo); break;
+ case COMBO_COLOR: createColorCombo(combo); break;
+ case COMBO_HALIGN: createHAlignCombo(combo); break;
+ case COMBO_VALIGN: createVAlignCombo(combo); break;
+ }
+
+ QLabel *label=new QLabel(combo, caption, parent);
+ label->setGeometry(10, y, 50, COMBO_HEIGHTS);
+
+ return combo;
+}
+
+void CellFormat::createHAlignCombo(QComboBox *combo)
+{
+ for (int i=0; i<HALIGN_COUNT; ++i)
+ combo->insertItem(namesHAlign[i]);
+}
+
+void CellFormat::createVAlignCombo(QComboBox *combo)
+{
+ for (int i=0; i<VALIGN_COUNT; ++i)
+ combo->insertItem(namesVAlign[i]);
+}
+
+void CellFormat::createWidthCombo(QComboBox *combo)
+{
+ int width=combo->listBox()->maxItemWidth();
+ QPixmap pix(width, COMBO_HEIGHTS);
+ QPainter p(&pix);
+
+ for (int i=1; i<=6; ++i)
+ {
+ pix.fill();
+ p.setPen(QPen(Qt::black, i, Qt::SolidLine));
+ p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
+ combo->insertItem(pix);
+ }
+}
+
+void CellFormat::createFontCombo(QComboBox *combo)
+{
+ combo->insertStringList(fontDB.families());
+}
+
+void CellFormat::createStyleCombo(QComboBox *combo)
+{
+ int width=combo->listBox()->maxItemWidth();
+ QPixmap pix(width, COMBO_HEIGHTS);
+ QPainter p(&pix);
+
+ for (int i=0; i<STYLE_COUNT; ++i)
+ {
+ pix.fill();
+ p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]);
+ combo->insertItem(pix);
+ }
+}
+
+void CellFormat::createColorCombo(QComboBox *combo)
+{
+ int width=combo->listBox()->maxItemWidth();
+ QPixmap pix(width, COMBO_HEIGHTS);
+ QPainter p(&pix);
+
+ for (int i=0; i<COLOR_COUNT; ++i)
+ {
+ pix.fill();
+ p.setPen(QPen(qtColors[i], 3, Qt::SolidLine));
+ p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
+ combo->insertItem(pix);
+ }
+}
+
+int CellFormat::exec(Sheet *s)
+{
+ sheet=s;
+ int row1, row2, col1, col2, row, col;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0),
+ penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1),
+ penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0),
+ penDefault=borderEditor->getDefaultPen();
+ for (row=row1+1; row<=row2; ++row)
+ if (sheet->getPen(row, col1-1, 1)!=penLeft)
+ {
+ penLeft=penDefault;
+ break;
+ }
+ for (row=row1+1; row<=row2; ++row)
+ if (sheet->getPen(row, col2, 1)!=penRight)
+ {
+ penRight=penDefault;
+ break;
+ }
+ for (col=col1+1; col<=col2; ++col)
+ if (sheet->getPen(row1-1, col, 0)!=penTop)
+ {
+ penTop=penDefault;
+ break;
+ }
+ for (col=col1+1; col<=col2; ++col)
+ if (sheet->getPen(row2, col, 0)!=penBottom)
+ {
+ penBottom=penDefault;
+ break;
+ }
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<col2; ++col)
+ if (sheet->getPen(row, col, 1)!=penVert)
+ {
+ penVert=penDefault;
+ break;
+ }
+ for (row=row1; row<row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ if (sheet->getPen(row, col, 0)!=penHorz)
+ {
+ penHorz=penDefault;
+ break;
+ }
+
+ borderEditor->setPen(penTop, BorderEditor::Top);
+ borderEditor->setPen(penBottom, BorderEditor::Bottom);
+ borderEditor->setPen(penLeft, BorderEditor::Left);
+ borderEditor->setPen(penRight, BorderEditor::Right);
+ borderEditor->setPen(penVert, BorderEditor::Vert);
+ borderEditor->setPen(penHorz, BorderEditor::Horz);
+
+ setBrushBackground(sheet->getBrush(row1, col1));
+ setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1));
+ setTextAlign(sheet->getAlignment(row1, col1));
+
+ if (QDialog::exec()==QDialog::Accepted)
+ {
+ penTop=borderEditor->getPen(BorderEditor::Top);
+ penBottom=borderEditor->getPen(BorderEditor::Bottom);
+ penLeft=borderEditor->getPen(BorderEditor::Left);
+ penRight=borderEditor->getPen(BorderEditor::Right);
+ penVert=borderEditor->getPen(BorderEditor::Vert);
+ penHorz=borderEditor->getPen(BorderEditor::Horz);
+
+ if (penTop!=penDefault)
+ for (col=col1; col<=col2; ++col)
+ sheet->setPen(row1-1, col, 0, penTop);
+ if (penBottom!=penDefault)
+ for (col=col1; col<=col2; ++col)
+ sheet->setPen(row2, col, 0, penBottom);
+ if (penLeft!=penDefault)
+ for (row=row1; row<=row2; ++row)
+ sheet->setPen(row, col1-1, 1, penLeft);
+ if (penRight!=penDefault)
+ for (row=row1; row<=row2; ++row)
+ sheet->setPen(row, col2, 1, penRight);
+ if (penVert!=penDefault)
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<col2; ++col)
+ sheet->setPen(row, col, 1, penVert);
+ if (penHorz!=penDefault)
+ for (row=row1; row<row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ sheet->setPen(row, col, 0, penHorz);
+
+ if (changedBrush)
+ {
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ sheet->setBrush(row, col, brushBackground);
+ }
+
+ if (changedAlign)
+ {
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ sheet->setTextAlign(row, col, textAlignment);
+ }
+
+ if (changedFont)
+ {
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ sheet->setTextFont(row, col, fontFont, fontColor);
+ }
+ return QDialog::Accepted;
+ }
+ return QDialog::Rejected;
+}
+
+//
+// Border Editor
+//
+
+BorderEditor::BorderEditor(QWidget *parent=0)
+ :QFrame(parent)
+{
+ setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+}
+
+BorderEditor::~BorderEditor()
+{
+}
+
+void BorderEditor::drawContents(QPainter *p)
+{
+ QFrame::drawContents(p);
+
+ int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
+ int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6;
+
+ p->fillRect(contentsRect(), Qt::white);
+
+ p->fillRect(x+width/3, y+height/3, width, height, Qt::gray);
+ p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray);
+ p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray);
+ p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray);
+
+ if (penTop.width()>0)
+ {
+ p->setPen(penTop);
+ p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY);
+ }
+ if (penBottom.width()>0)
+ {
+ p->setPen(penBottom);
+ p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY);
+ }
+ if (penHorz.width()>0)
+ {
+ p->setPen(penHorz);
+ p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2);
+ }
+ if (penLeft.width()>0)
+ {
+ p->setPen(penLeft);
+ p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY);
+ }
+ if (penRight.width()>0)
+ {
+ p->setPen(penRight);
+ p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY);
+ }
+ if (penVert.width()>0)
+ {
+ p->setPen(penVert);
+ p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY);
+ }
+}
+
+void BorderEditor::setPen(const QPen &pen, BorderArea area)
+{
+ switch (area)
+ {
+ case Top: penTop=pen; break;
+ case Bottom: penBottom=pen; break;
+ case Left: penLeft=pen; break;
+ case Right: penRight=pen; break;
+ case Horz: penHorz=pen; break;
+ case Vert: penVert=pen; break;
+ };
+ update();
+}
+
+void BorderEditor::mouseReleaseEvent(QMouseEvent *e)
+{
+ QFrame::mouseReleaseEvent(e);
+
+ int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
+ BorderArea area=None;
+
+ if (e->x()<x+width/3) area=Left;
+ if (e->x()>x+(8*width)/3) area=Right;
+ if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert;
+
+ if (e->y()<y+height/3) area=Top;
+ if (e->y()>y+(8*height)/3) area=Bottom;
+ if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz;
+
+ if (area!=None)
+ emit clicked(area);
+}
+
+QPen BorderEditor::getPen(BorderArea area)
+{
+ switch (area)
+ {
+ case Top: return penTop;
+ case Bottom: return penBottom;
+ case Left: return penLeft;
+ case Right: return penRight;
+ case Horz: return penHorz;
+ case Vert: return penVert;
+ };
+ return getDefaultPen();
+}
diff --git a/noncore/apps/opie-sheet/cellformat.h b/noncore/apps/opie-sheet/cellformat.h
new file mode 100644
index 0000000..b552153
--- a/dev/null
+++ b/noncore/apps/opie-sheet/cellformat.h
@@ -0,0 +1,106 @@
+#ifndef CELLFORMAT_H
+#define CELLFORMAT_H
+
+#include <qpe/fontdatabase.h>
+#include <qdialog.h>
+#include <qtabwidget.h>
+#include <qlayout.h>
+#include <qcombobox.h>
+#include <qcheckbox.h>
+#include <qpushbutton.h>
+
+#include "sheet.h"
+
+class BorderEditor: public QFrame
+{
+ Q_OBJECT
+
+ // QT objects
+ QPen penTop, penBottom, penLeft, penRight, penHorz, penVert;
+
+ // Private functions
+ void drawContents(QPainter *p);
+
+ // Reimplemented QFrame functions
+ void mouseReleaseEvent(QMouseEvent *e);
+
+ public:
+ // Definitions
+ enum BorderArea {None, Top, Bottom, Left, Right, Horz, Vert};
+
+ BorderEditor(QWidget *parent=0);
+ ~BorderEditor();
+
+ void setPen(const QPen &pen, BorderArea area);
+ QPen getPen(BorderArea area);
+ QPen getDefaultPen() { return QPen(Qt::black, 1, Qt::DotLine); }
+
+ signals:
+ void clicked(BorderEditor::BorderArea);
+};
+
+class CellFormat: public QDialog
+{
+ Q_OBJECT
+
+ enum comboType {COMBO_OTHER, COMBO_WIDTH, COMBO_FONT, COMBO_SIZE, COMBO_STYLE, COMBO_COLOR, COMBO_VALIGN, COMBO_HALIGN};
+
+ // QT objects
+ QBoxLayout *box;
+ QTabWidget *tabs;
+ QWidget *widgetBorders, *widgetBackground, *widgetFont, *widgetAlignment;
+ QComboBox *comboBordersWidth, *comboBordersColor, *comboBackgroundColor, *comboBackgroundStyle, *comboFontColor, *comboFontSize, *comboFontFamily, *comboAlignmentVertical, *comboAlignmentHorizontal;
+ QCheckBox *checkFontBold, *checkFontItalic, *checkAlignmentWrap;
+ QPushButton *buttonBordersDefaults, *buttonBackgroundDefaults, *buttonFontDefaults, *buttonAlignmentDefaults;
+ QFrame *frameBackground, *frameFont, *frameAlignment;
+ QBrush brushBackground;
+ QFont fontFont;
+ QColor fontColor;
+ Qt::AlignmentFlags textAlignment;
+ FontDatabase fontDB;
+
+ // Other objects & variables
+ Sheet *sheet;
+ BorderEditor *borderEditor;
+ bool changedFont, changedAlign, changedBrush;
+
+ // Private functions
+ void createWidthCombo(QComboBox *combo);
+ void createFontCombo(QComboBox *combo);
+ void createHAlignCombo(QComboBox *combo);
+ void createVAlignCombo(QComboBox *combo);
+ void createStyleCombo(QComboBox *combo);
+ void createSizeCombo(QComboBox *combo);
+ void createColorCombo(QComboBox *combo);
+ QComboBox *createCombo(comboType type, QWidget *parent, const QString &caption, int y);
+
+ int findHAlignIndex(Qt::AlignmentFlags flag);
+ int findVAlignIndex(Qt::AlignmentFlags flag);
+ int findComboItemIndex(QComboBox *combo, const QString &item);
+ int findColorIndex(const QColor &color);
+ int findBrushStyleIndex(Qt::BrushStyle style);
+
+ private slots:
+ void borderClicked(BorderEditor::BorderArea area);
+ void backgroundClicked(int index);
+ void fontClicked(bool on);
+ void fontClicked(int index);
+ void alignClicked(bool on);
+ void alignClicked(int index);
+ void slotBordersDefaults();
+ void slotBackgroundDefaults();
+ void slotFontDefaults();
+ void slotAlignmentDefaults();
+
+ public:
+ CellFormat(QWidget *parent=0);
+ ~CellFormat();
+
+ int exec(Sheet *s);
+
+ void setTextAlign(Qt::AlignmentFlags flags);
+ void setTextFont(const QFont &font, const QColor &color);
+ void setBrushBackground(const QBrush &brush);
+};
+
+#endif
diff --git a/noncore/apps/opie-sheet/edit-accept.xpm b/noncore/apps/opie-sheet/edit-accept.xpm
new file mode 100644
index 0000000..5109281
--- a/dev/null
+++ b/noncore/apps/opie-sheet/edit-accept.xpm
@@ -0,0 +1,30 @@
+/* XPM */
+static const char *edit_accept_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"16 16 8 1",
+" c #000000000000",
+". c #000040400000",
+"X c #404000000000",
+"o c #000080800000",
+"O c #0000c0c00000",
+"+ c #c0c0ffffc0c0",
+"@ c #ffffffffffff",
+"# c None",
+/* pixels */
+"################",
+"################",
+"##############+#",
+"#############+O#",
+"############+Oo#",
+"###########+Oo.#",
+"##+o######+Oo. #",
+"#+OOo####+Oo.X##",
+" .oOOo##+Oo. ###",
+"# .oOOo+Oo.X####",
+"##X.oOOOo.X#####",
+"### .oOo. ######",
+"#### .o. #######",
+"##### X ########",
+"################",
+"################",
+};
diff --git a/noncore/apps/opie-sheet/edit-cancel.xpm b/noncore/apps/opie-sheet/edit-cancel.xpm
new file mode 100644
index 0000000..8e1606e
--- a/dev/null
+++ b/noncore/apps/opie-sheet/edit-cancel.xpm
@@ -0,0 +1,25 @@
+/* XPM */
+static const char *edit_cancel_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"16 16 3 1",
+". c red",
+"X c #ffffffffffff",
+" c None",
+/* pixels */
+" ",
+" ",
+" ..... ",
+" ......... ",
+" ........... ",
+" ..XX...XX.. ",
+" ...XXX.XXX... ",
+" ....XXXXX.... ",
+" .....XXX..... ",
+" ....XXXXX.... ",
+" ...XXX.XXX... ",
+" ..XX...XX.. ",
+" ........... ",
+" ......... ",
+" ..... ",
+" ",
+};
diff --git a/noncore/apps/opie-sheet/file-new.xpm b/noncore/apps/opie-sheet/file-new.xpm
new file mode 100644
index 0000000..ec8dd63
--- a/dev/null
+++ b/noncore/apps/opie-sheet/file-new.xpm
@@ -0,0 +1,24 @@
+/* XPM */
+static const char * file_new_xpm[] = {
+"16 16 5 1",
+" c None",
+". c #808080",
+"+ c #FFFFFF",
+"@ c #C0C0C0",
+"# c #000000",
+" .......... ",
+" .++++++++@. ",
+" .++++++++@+. ",
+" .++++++++#### ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .++++++++++@# ",
+" .@@@@@@@@@@@# ",
+" ############# "};
diff --git a/noncore/apps/opie-sheet/file-open.xpm b/noncore/apps/opie-sheet/file-open.xpm
new file mode 100644
index 0000000..8449d5b
--- a/dev/null
+++ b/noncore/apps/opie-sheet/file-open.xpm
@@ -0,0 +1,25 @@
+/* XPM */
+static const char * file_open_xpm[] = {
+"16 16 6 1",
+" c None",
+". c #808080",
+"+ c #FFFFFF",
+"@ c #C0C0C0",
+"# c #FFFF00",
+"$ c #000000",
+" ",
+" ..... ",
+" .+++++. ",
+" .+@#@#@+...... ",
+" .+#@#@#@+++++.$",
+" .+@#@#@#@#@#@.$",
+".............#.$",
+".++++++++++.$@.$",
+".+@#@#@#@#@#$..$",
+" .+@#@#@#@#@.$.$",
+" .+#@#@#@#@#@$.$",
+" .+#@#@#@#@#.$$",
+" ............$$",
+" $$$$$$$$$$$$$",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/file-save.xpm b/noncore/apps/opie-sheet/file-save.xpm
new file mode 100644
index 0000000..039a174
--- a/dev/null
+++ b/noncore/apps/opie-sheet/file-save.xpm
@@ -0,0 +1,24 @@
+/* XPM */
+static const char * file_save_xpm[] = {
+"16 16 5 1",
+" c None",
+". c #808080",
+"+ c #FFFFFF",
+"@ c #000000",
+"# c #0000FF",
+" ",
+" ........ ",
+" .++++++.@ ",
+" .+....+.+@ #",
+" .++++++.@@@ ##",
+" .+....++++@ ##@",
+" .+++++++++@##@ ",
+" .+.......+##@ ",
+" .++++++++##@ ",
+" .+......@#@ ",
+" .++++++@@@@ ",
+" .+....@@@+@ ",
+" .++++@++++@ ",
+" .+++++++++@ ",
+" @@@@@@@@@@@ ",
+" "};
diff --git a/noncore/apps/opie-sheet/finddlg.cpp b/noncore/apps/opie-sheet/finddlg.cpp
new file mode 100644
index 0000000..cfe2f82
--- a/dev/null
+++ b/noncore/apps/opie-sheet/finddlg.cpp
@@ -0,0 +1,70 @@
+#include <qlabel.h>
+#include <qradiobutton.h>
+#include "finddlg.h"
+
+FindDialog::FindDialog(QWidget *parent=0)
+ :QDialog(parent, 0, TRUE)
+{
+ // Main widget
+ tabs=new QTabWidget(this);
+ widgetFind=new QWidget(tabs);
+ widgetOptions=new QWidget(tabs);
+ tabs->addTab(widgetFind, tr("&Find && Replace"));
+ tabs->addTab(widgetOptions, tr("&Options"));
+
+ // Find tab
+ QLabel *label=new QLabel(tr("&Search for:"), widgetFind);
+ label->setGeometry(10, 10, 215, 20);
+ editFind=new QLineEdit(widgetFind);
+ editFind->setGeometry(10, 40, 215, 20);
+ label->setBuddy(editFind);
+
+ label=new QLabel(tr("&Replace with:"), widgetFind);
+ label->setGeometry(10, 80, 215, 20);
+ editReplace=new QLineEdit(widgetFind);
+ editReplace->setGeometry(10, 110, 215, 20);
+ editReplace->setEnabled(FALSE);
+ label->setBuddy(editReplace);
+
+ groupType=new QVButtonGroup(tr("&Type"), widgetFind);
+ groupType->setGeometry(10, 150, 215, 90);
+ QRadioButton *radio=new QRadioButton(tr("&Find"), groupType);
+ radio=new QRadioButton(tr("&Replace"), groupType);
+ radio=new QRadioButton(tr("Replace &all"), groupType);
+ groupType->setButton(0);
+ connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int)));
+
+ // Options tab
+ checkCase=new QCheckBox(tr("Match &case"), widgetOptions);
+ checkCase->setGeometry(10, 10, 215, 20);
+ checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions);
+ checkSelection->setGeometry(10, 40, 215, 20);
+ checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions);
+ checkEntire->setGeometry(10, 70, 215, 20);
+
+ // Main widget
+ box=new QVBoxLayout(this);
+ box->addWidget(tabs);
+
+ setCaption(tr("Find & Replace"));
+}
+
+FindDialog::~FindDialog()
+{
+}
+
+void FindDialog::typeChanged(int id)
+{
+ editReplace->setEnabled(id>0);
+}
+
+int FindDialog::exec(Sheet *s)
+{
+ if (QDialog::exec()==QDialog::Accepted)
+ {
+ int id=groupType->id(groupType->selected());
+ s->dataFindReplace(editFind->text(), editReplace->text(), checkCase->isChecked(), !checkSelection->isChecked(), checkEntire->isChecked(), id>0, id>1);
+ return QDialog::Accepted;
+ }
+ return QDialog::Rejected;
+}
diff --git a/noncore/apps/opie-sheet/finddlg.h b/noncore/apps/opie-sheet/finddlg.h
new file mode 100644
index 0000000..02c9cdd
--- a/dev/null
+++ b/noncore/apps/opie-sheet/finddlg.h
@@ -0,0 +1,35 @@
+#ifndef FINDDLG_H
+#define FINDDLG_H
+
+#include <qdialog.h>
+#include <qtabwidget.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qpushbutton.h>
+#include <qvbuttongroup.h>
+#include "sheet.h"
+
+class FindDialog: public QDialog
+{
+ Q_OBJECT
+
+ // QT objects
+ QBoxLayout *box;
+ QTabWidget *tabs;
+ QWidget *widgetFind, *widgetOptions;
+ QCheckBox *checkCase, *checkSelection, *checkEntire;
+ QLineEdit *editFind, *editReplace;
+ QVButtonGroup *groupType;
+
+ private slots:
+ void typeChanged(int id);
+
+ public:
+ FindDialog(QWidget *parent=0);
+ ~FindDialog();
+
+ int exec(Sheet *s);
+};
+
+#endif
diff --git a/noncore/apps/opie-sheet/func-comma.xpm b/noncore/apps/opie-sheet/func-comma.xpm
new file mode 100644
index 0000000..3b2bbf9
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-comma.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_comma_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" ",
+" ",
+" ... ",
+" ..... ",
+" ...... ",
+" ...... ",
+" ..... ",
+" .. ",
+" . ",
+" .. ",
+" .. ",
+" . ",
+" ",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-cross.xpm b/noncore/apps/opie-sheet/func-cross.xpm
new file mode 100644
index 0000000..6f77502
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-cross.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_cross_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" ",
+" ",
+" .. ",
+" .. ",
+" .. ",
+" ... .. ... ",
+" .......... ",
+" ...... ",
+" .... ",
+" ...... ",
+" ... ... ",
+" . . ",
+" ",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-divide.xpm b/noncore/apps/opie-sheet/func-divide.xpm
new file mode 100644
index 0000000..1ac6a07
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-divide.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_divide_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-equal.xpm b/noncore/apps/opie-sheet/func-equal.xpm
new file mode 100644
index 0000000..60f8710
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-equal.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_equal_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" ",
+" ",
+" ",
+" ",
+" .......... ",
+" .......... ",
+" ",
+" ",
+" .......... ",
+" .......... ",
+" ",
+" ",
+" ",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-func.xpm b/noncore/apps/opie-sheet/func-func.xpm
new file mode 100644
index 0000000..c1f7852
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-func.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_func_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" .. ",
+" .. ",
+" . ",
+" . ",
+" . ",
+" ..... ",
+" . ",
+" . . . ",
+" . . . ",
+" . . ",
+" . . . ",
+" . . . ",
+" . ",
+" . ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-minus.xpm b/noncore/apps/opie-sheet/func-minus.xpm
new file mode 100644
index 0000000..fa2cb4f
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-minus.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_minus_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ....... ",
+" ....... ",
+" ",
+" ",
+" ",
+" ",
+" ",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-paran-close.xpm b/noncore/apps/opie-sheet/func-paran-close.xpm
new file mode 100644
index 0000000..85191d5
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-paran-close.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_paran_close_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" . ",
+" .. ",
+" . ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" . ",
+" .. ",
+" . ",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-paran-open.xpm b/noncore/apps/opie-sheet/func-paran-open.xpm
new file mode 100644
index 0000000..3c7870b
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-paran-open.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_paran_open_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" . ",
+" .. ",
+" . ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" . ",
+" .. ",
+" . ",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/func-plus.xpm b/noncore/apps/opie-sheet/func-plus.xpm
new file mode 100644
index 0000000..a917c64
--- a/dev/null
+++ b/noncore/apps/opie-sheet/func-plus.xpm
@@ -0,0 +1,21 @@
+/* XPM */
+static const char * func_plus_xpm[] = {
+"16 16 2 1",
+" c None",
+". c #000000",
+" ",
+" ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" ............ ",
+" ............ ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" .. ",
+" ",
+" "};
diff --git a/noncore/apps/opie-sheet/help-general.xpm b/noncore/apps/opie-sheet/help-general.xpm
new file mode 100644
index 0000000..9f10527
--- a/dev/null
+++ b/noncore/apps/opie-sheet/help-general.xpm
@@ -0,0 +1,25 @@
+/* XPM */
+static const char * help_general_xpm[] = {
+"16 16 6 1",
+" c None s None",
+". c #000000",
+"X c #FF0000",
+"o c #FFFF00",
+"O c #808080",
+"+ c #FFFFFF",
+" ",
+" .. ",
+" .XX. ",
+" .XXXX. ",
+" .XXXoXX. ",
+" .XXXoXoXX. ",
+" .XXXXXoXoX. ",
+" .XXXXXXXoX.O ",
+" ..XXXXXXX.+.O ",
+" .+.XXXXX.+.O ",
+" .+.XXX.+.O ",
+" .+.X.+.O ",
+" .+.+.O ",
+" .+.O ",
+" .O ",
+" "};
diff --git a/noncore/apps/opie-sheet/main.cpp b/noncore/apps/opie-sheet/main.cpp
new file mode 100644
index 0000000..236a579
--- a/dev/null
+++ b/noncore/apps/opie-sheet/main.cpp
@@ -0,0 +1,14 @@
+#include <qpe/qpeapplication.h>
+
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ QPEApplication application(argc, argv);
+
+ MainWindow windowMain;
+ windowMain.setHelpFile(application.qpeDir()+"/help/html/"+QString(argv[0])+".html");
+ application.showMainDocumentWidget(&windowMain);
+
+ return application.exec();
+}
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp
new file mode 100644
index 0000000..a7441b1
--- a/dev/null
+++ b/noncore/apps/opie-sheet/mainwindow.cpp
@@ -0,0 +1,836 @@
+#include "mainwindow.h"
+
+#include <qpe/filemanager.h>
+#include <qpe/qcopenvelope_qws.h>
+#include <qmessagebox.h>
+#include <qfile.h>
+#include <qradiobutton.h>
+#include "cellformat.h"
+#include "numberdlg.h"
+#include "textdlg.h"
+#include "sortdlg.h"
+#include "finddlg.h"
+
+#include "file-new.xpm"
+#include "file-open.xpm"
+#include "file-save.xpm"
+#include "edit-cancel.xpm"
+#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
+ 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);
+}
+
+MainWindow::~MainWindow()
+{
+}
+
+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))
+ {
+ 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;
+ 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())
+ {
+ 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());
+ }
+
+ 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);
+ 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);
+ 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()
+{
+ selectorFileNew(DocLnk());
+}
+
+void MainWindow::slotFileOpen()
+{
+ selectorShow();
+}
+
+void MainWindow::slotFileSave()
+{
+ saveCurrentFile(FALSE);
+}
+
+void MainWindow::setDocument(const QString &applnk_filename)
+{
+ selectorFileOpen(DocLnk(applnk_filename));
+}
+
+void MainWindow::initActions()
+{
+ fileNew=new QAction(tr("New File"), QPixmap(file_new_xpm), tr("&New"), 0, this);
+ connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
+ fileOpen=new QAction(tr("Open File"), QPixmap(file_open_xpm), tr("&Open"), 0, this);
+ connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
+ fileSave=new QAction(tr("Save File"), QPixmap(file_save_xpm), tr("&Save"), 0, this);
+ connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
+ fileSaveAs=new QAction(tr("Save File As"), QPixmap(file_save_xpm), tr("Save &As"), 0, this);
+ connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
+ fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this);
+ connect(fileQuit, SIGNAL(activated()), this, SLOT(close()));
+
+ helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this);
+ connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral()));
+ helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this);
+ connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
+
+ editAccept=new QAction(tr("Accept"), QPixmap(edit_accept_xpm), tr("&Accept"), 0, this);
+ connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept()));
+ editCancel=new QAction(tr("Cancel"), QPixmap(edit_cancel_xpm), tr("&Cancel"), 0, this);
+ connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel()));
+ editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this);
+ editCellSelect->setToggleAction(TRUE);
+ connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool)));
+ editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this);
+ editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this);
+ editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this);
+ connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
+ editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this);
+ connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents()));
+ editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this);
+
+ insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this);
+ connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells()));
+ insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this);
+ connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows()));
+ insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this);
+ connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols()));
+ insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this);
+ connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets()));
+
+ formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this);
+ connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells()));
+
+ rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this);
+ connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight()));
+ rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this);
+ connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust()));
+ rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this);
+ connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow()));
+ rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this);
+ connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide()));
+
+ colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this);
+ connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth()));
+ colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this);
+ connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust()));
+ colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this);
+ connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow()));
+ colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this);
+ connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide()));
+
+ sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this);
+ connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename()));
+ sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this);
+ connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove()));
+
+ dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this);
+ connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort()));
+ dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this);
+ connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace()));
+
+ funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this);
+ funcEqual->setToolTip("=");
+ connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this);
+ funcPlus->setToolTip("+");
+ connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this);
+ funcMinus->setToolTip("-");
+ connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this);
+ funcCross->setToolTip("*");
+ connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this);
+ funcDivide->setToolTip("/");
+ connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this);
+ funcParanOpen->setToolTip("(");
+ connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this);
+ funcParanClose->setToolTip(")");
+ connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this);
+ funcComma->setToolTip(",");
+ connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+}
+
+void MainWindow::initMenu()
+{
+ menu=new QPEMenuBar(this);
+
+ menuFile=new QPopupMenu;
+ fileNew->addTo(menuFile);
+ fileOpen->addTo(menuFile);
+ fileSave->addTo(menuFile);
+ fileSaveAs->addTo(menuFile);
+ menuFile->insertSeparator();
+ fileQuit->addTo(menuFile);
+ menu->insertItem(tr("&File"), menuFile);
+
+ menuEdit=new QPopupMenu;
+ editAccept->addTo(menuEdit);
+ editCancel->addTo(menuEdit);
+ editCellSelect->addTo(menuEdit);
+ menuEdit->insertSeparator();
+ editCut->addTo(menuEdit);
+ editCopy->addTo(menuEdit);
+ editPaste->addTo(menuEdit);
+ editPasteContents->addTo(menuEdit);
+ editClear->addTo(menuEdit);
+ menu->insertItem(tr("&Edit"), menuEdit);
+
+ menuInsert=new QPopupMenu;
+ menu->insertItem(tr("&Insert"), menuInsert);
+
+ menuFormat=new QPopupMenu;
+ formatCells->addTo(menuFormat);
+ menu->insertItem(tr("&Format"), menuFormat);
+
+ menuData=new QPopupMenu;
+ dataSort->addTo(menuData);
+ dataFindReplace->addTo(menuData);
+ menu->insertItem(tr("&Data"), menuData);
+
+ menuHelp=new QPopupMenu;
+ helpGeneral->addTo(menuHelp);
+ helpAbout->addTo(menuHelp);
+ menu->insertItem(tr("&Help"), menuHelp);
+
+ submenuRow=new QPopupMenu;
+ rowHeight->addTo(submenuRow);
+ rowAdjust->addTo(submenuRow);
+ rowShow->addTo(submenuRow);
+ rowHide->addTo(submenuRow);
+ menuFormat->insertItem(tr("&Row"), submenuRow);
+
+ submenuCol=new QPopupMenu;
+ colWidth->addTo(submenuCol);
+ colAdjust->addTo(submenuCol);
+ colShow->addTo(submenuCol);
+ colHide->addTo(submenuCol);
+ menuFormat->insertItem(tr("Colum&n"), submenuCol);
+
+ submenuSheet=new QPopupMenu;
+ sheetRename->addTo(submenuSheet);
+ sheetRemove->addTo(submenuSheet);
+ menuFormat->insertItem(tr("&Sheet"), submenuSheet);
+
+ submenuFunc=new QPopupMenu;
+ menuInsert->insertItem(tr("&Function"), submenuFunc);
+
+ submenuFuncStd=new QPopupMenu;
+ funcPlus->addTo(submenuFuncStd);
+ funcMinus->addTo(submenuFuncStd);
+ funcCross->addTo(submenuFuncStd);
+ funcDivide->addTo(submenuFuncStd);
+ submenuFunc->insertItem(tr("&Standard"), submenuFuncStd);
+
+ submenuFuncMath=new QPopupMenu;
+ addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath);
+ addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath);
+ submenuFuncMath->insertSeparator();
+ addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath);
+ addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath);
+ addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath);
+ addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath);
+ addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath);
+ addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath);
+ addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath);
+ submenuFuncMath->insertSeparator();
+ addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath);
+ addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath);
+ addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath);
+ submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath);
+
+ submenuFuncStat=new QPopupMenu;
+ addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat);
+ addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat);
+ addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat);
+ addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat);
+ submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat);
+
+ menuInsert->insertSeparator();
+ insertCells->addTo(menuInsert);
+ insertRows->addTo(menuInsert);
+ insertCols->addTo(menuInsert);
+ insertSheets->addTo(menuInsert);
+}
+
+void MainWindow::initStandardToolbar()
+{
+ toolbarStandard=new QPEToolBar(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 &)));
+}
+
+void MainWindow::initFunctionsToolbar()
+{
+ toolbarFunctions=new QPEToolBar(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(func_func_xpm);
+ toolFunction->setTextLabel(tr("Functions"));
+ toolFunction->setPopup(submenuFunc);
+ toolFunction->setPopupDelay(0);
+}
+
+void MainWindow::initEditToolbar()
+{
+ toolbarEdit=new QPEToolBar(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::slotHelpGeneral()
+{
+ if (QFile::exists(helpFile))
+ {
+ QCopEnvelope e("QPE/Application/helpbrowser", "showFile(QString)");
+ e << helpFile;
+ }
+ else
+ QMessageBox::critical(this, tr("Error"), tr("Help file not found!"));
+}
+
+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\nVersion: 1.0.1 (Final)\nRelease Date: July 4, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout);
+ 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(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;
+ 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);
+}
+
+void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w)
+{
+ QAction *action=new QAction(text, menuText, 0, this);
+ action->setToolTip(tip);
+ connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
+ action->addTo(w);
+}
+
+void MainWindow::slotFormatCells()
+{
+ CellFormat dialogCellFormat(this);
+ dialogCellFormat.showMaximized();
+ dialogCellFormat.exec(sheet);
+}
+
+void MainWindow::slotEditPaste()
+{
+ sheet->editPaste();
+}
+
+void MainWindow::slotEditPasteContents()
+{
+ sheet->editPaste(TRUE);
+}
+
+void MainWindow::slotRowHeight()
+{
+ int row1, row2, col1, col2;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ NumberDialog dialogNumber(this);
+ if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted)
+ {
+ int newHeight=dialogNumber.getValue(), row;
+ for (row=row1; row<=row2; ++row)
+ sheet->setRowHeight(row, newHeight);
+ }
+}
+
+void MainWindow::slotRowAdjust()
+{
+ int row1, row2, col1, col2;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ for (int row=row1; row<=row2; ++row)
+ sheet->adjustRow(row);
+}
+
+void MainWindow::slotRowShow()
+{
+ int row1, row2, col1, col2;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ for (int row=row1; row<=row2; ++row)
+ sheet->showRow(row);
+}
+
+void MainWindow::slotRowHide()
+{
+ int row1, row2, col1, col2;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ for (int row=row1; row<=row2; ++row)
+ sheet->hideRow(row);
+}
+
+void MainWindow::slotColumnWidth()
+{
+ int row1, row2, col1, col2;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ NumberDialog dialogNumber(this);
+ if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted)
+ {
+ int newWidth=dialogNumber.getValue(), col;
+ for (col=col1; col<=col2; ++col)
+ sheet->setColumnWidth(col, newWidth);
+ }
+}
+
+void MainWindow::slotColumnAdjust()
+{
+ int row1, row2, col1, col2;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ for (int col=col1; col<=col2; ++col)
+ 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;
+
+ currentDoc.setName(dialogText.getValue());
+ 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;
+ sheet->setName(newName);
+}
+
+void MainWindow::slotSheetRemove()
+{
+ if (comboSheets->count()<2)
+ {
+ QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!"));
+ return;
+ }
+ if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
+ {
+ typeSheet *tempSheet=findSheet(sheet->getName());
+ for (int i=0; i<comboSheets->count(); ++i)
+ if (comboSheets->text(i)==tempSheet->name)
+ {
+ comboSheets->removeItem(i);
+ break;
+ }
+ comboSheets->setCurrentItem(0);
+ slotSheetChanged(comboSheets->currentText());
+ listSheets.remove(tempSheet);
+ }
+}
+
+void MainWindow::slotDataSort()
+{
+ SortDialog dialogSort(this);
+ dialogSort.showMaximized();
+ dialogSort.exec(sheet);
+}
+
+void MainWindow::slotDocModified()
+{
+ documentModified=TRUE;
+}
+
+void MainWindow::slotInsertCells()
+{
+ QDialog dialogInsert(this, 0, TRUE);
+ dialogInsert.resize(180, 130);
+ dialogInsert.setCaption(tr("Insert Cells"));
+
+ QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert);
+ group->setGeometry(10, 10, 160, 110);
+ QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group);
+ radio=new QRadioButton(tr("Shift cells &right"), group);
+ radio=new QRadioButton(tr("Entire ro&w"), group);
+ radio=new QRadioButton(tr("Entire &column"), group);
+ group->setButton(0);
+
+ if (dialogInsert.exec()==QDialog::Accepted)
+ switch (group->id(group->selected()))
+ {
+ case 0: sheet->insertRows(1, FALSE); break;
+ case 1: sheet->insertColumns(1, FALSE); break;
+ case 2: sheet->insertRows(1, TRUE); break;
+ case 3: sheet->insertColumns(1, TRUE); break;
+ }
+}
+
+void MainWindow::slotDataFindReplace()
+{
+ FindDialog dialogFind(this);
+ dialogFind.showMaximized();
+ dialogFind.exec(sheet);
+}
diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h
new file mode 100644
index 0000000..ac90504
--- a/dev/null
+++ b/noncore/apps/opie-sheet/mainwindow.h
@@ -0,0 +1,120 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#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;
+ 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 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();
+ void slotRowAdjust();
+ void slotRowShow();
+ void slotRowHide();
+ void slotColumnWidth();
+ void slotColumnAdjust();
+ void slotColumnShow();
+ void slotColumnHide();
+ void slotSheetRename();
+ void slotSheetRemove();
+ void slotFuncOutput();
+ void slotCellSelect(bool lock);
+ void slotCellClicked(const QString &cell);
+ void slotSheetChanged(const QString &name);
+ void slotDocModified();
+ void selectorShow();
+ void selectorHide();
+ void selectorFileNew(const DocLnk &lnkDoc);
+ void selectorFileOpen(const DocLnk &lnkDoc);
+
+ public:
+ MainWindow();
+ ~MainWindow();
+
+ void setHelpFile(const QString &help_filename) { helpFile=help_filename; }
+
+ public slots:
+ void setDocument(const QString &applnk_filename);
+};
+
+#endif
diff --git a/noncore/apps/opie-sheet/numberdlg.cpp b/noncore/apps/opie-sheet/numberdlg.cpp
new file mode 100644
index 0000000..de84378
--- a/dev/null
+++ b/noncore/apps/opie-sheet/numberdlg.cpp
@@ -0,0 +1,35 @@
+#include "numberdlg.h"
+
+NumberDialog::NumberDialog(QWidget *parent=0)
+ :QDialog(parent, 0, TRUE)
+{
+ edit=new QSpinBox(this);
+ edit->setGeometry(120, 10, 70, 25);
+
+ label=new QLabel(this);
+ label->setGeometry(10, 10, 100, 25);
+ label->setBuddy(edit);
+
+ resize(200, 45);
+}
+
+NumberDialog::~NumberDialog()
+{
+}
+
+int NumberDialog::exec(const QString &caption, const QString &text, int value=1, int min=1, int max=99, int step=1)
+{
+ setCaption(caption);
+ label->setText(text);
+ edit->setValue(value);
+ edit->setMinValue(min);
+ edit->setMaxValue(max);
+ edit->setLineStep(step);
+
+ return QDialog::exec();
+}
+
+int NumberDialog::getValue()
+{
+ return edit->value();
+}
diff --git a/noncore/apps/opie-sheet/numberdlg.h b/noncore/apps/opie-sheet/numberdlg.h
new file mode 100644
index 0000000..46af1d0
--- a/dev/null
+++ b/noncore/apps/opie-sheet/numberdlg.h
@@ -0,0 +1,24 @@
+#ifndef NUMBERDLG_H
+#define NUMBERDLG_H
+
+#include <qdialog.h>
+#include <qlabel.h>
+#include <qspinbox.h>
+
+class NumberDialog: public QDialog
+{
+ Q_OBJECT
+
+ // QT objects
+ QLabel *label;
+ QSpinBox *edit;
+
+ public:
+ NumberDialog(QWidget *parent=0);
+ ~NumberDialog();
+
+ int exec(const QString &caption, const QString &text, int value=1, int min=1, int max=99, int step=1);
+ int getValue();
+};
+
+#endif
diff --git a/noncore/apps/opie-sheet/opie-sheet.control b/noncore/apps/opie-sheet/opie-sheet.control
new file mode 100644
index 0000000..f772247
--- a/dev/null
+++ b/noncore/apps/opie-sheet/opie-sheet.control
@@ -0,0 +1,10 @@
+Files: bin/sheetqt apps/Applications/opie-sheet.desktop help/html/sheetqt.html help/html/sheetqt/* pics/opie-sheet/sheetqt.png
+Priority: optional
+Section: opie/applications
+Maintainer: Serdar Ozler <sozler@sitebest.com>
+Architecture: arm
+Version: 1.0.1
+Depends: opie-base ($QPE_VERSION)
+License: Public Domain
+Description: Opie Sheet
+ Spreadsheet software for Opie.
diff --git a/noncore/apps/opie-sheet/opie-sheet.pro b/noncore/apps/opie-sheet/opie-sheet.pro
new file mode 100644
index 0000000..b053975
--- a/dev/null
+++ b/noncore/apps/opie-sheet/opie-sheet.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+CONFIG = qt warn_on release
+DESTDIR = $(OPIEDIR)/bin
+HEADERS = mainwindow.h sheet.h cellformat.h finddlg.h numberdlg.h sortdlg.h textdlg.h
+SOURCES = main.cpp mainwindow.cpp sheet.cpp cellformat.cpp finddlg.cpp numberdlg.cpp sortdlg.cpp textdlg.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lqpe
+TARGET = sheetqt
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp
new file mode 100644
index 0000000..9526937
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sheet.cpp
@@ -0,0 +1,849 @@
+#include "sheet.h"
+
+#include <qmainwindow.h>
+#include <qmessagebox.h>
+#include <math.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;
+
+ 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)));
+}
+
+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())
+ setText(cellData->row, cellData->col, dataParser(cellData->data));
+ emit sheetModified();
+}
+
+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(cellData1->data));
+ setText(cellData2->row, cellData2->col, dataParser(cellData2->data));
+ emit sheetModified();
+ }
+}
+
+QString Sheet::getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName="")
+{
+ QString params(parameters);
+ int position;
+ for (int i=0; i<paramNo; ++i)
+ {
+ position=params.find(',');
+ if (position<0)
+ {
+ if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\''));
+ return QString();
+ }
+ params=params.mid(position+1);
+ }
+ position=params.find(',');
+ if (position<0) return params;
+ return params.left(position);
+}
+
+bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2)
+{
+ int row, col;
+ if (!findRowColumn(variable1, row1, col1, TRUE) || !findRowColumn(variable2, row2, col2, TRUE)) return FALSE;
+ if (*row1>*row2)
+ {
+ row=*row1;
+ *row1=*row2;
+ *row2=row;
+ }
+ if (*col1>*col2)
+ {
+ col=*col1;
+ *col1=*col2;
+ *col2=col;
+ }
+ return TRUE;
+}
+
+bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE)
+{
+ int position=variable.find(QRegExp("\\d"));
+ if (position<1)
+ {
+ if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\''));
+ return FALSE;
+ }
+ *row=variable.mid(position).toInt()-1;
+ *col=getHeaderColumn(variable.left(position))-1;
+ return TRUE;
+}
+
+double Sheet::calculateVariable(const QString &variable)
+{
+ bool ok;
+ double tempResult=variable.toDouble(&ok);
+ if (ok) return tempResult;
+
+ int row, col;
+ return (findRowColumn(variable, &row, &col, TRUE) ? text(row, col).toDouble() : 0);
+}
+
+double Sheet::functionSum(const QString &param1, const QString &param2)
+{
+ int row1, col1, row2, col2, row, col;
+ if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
+
+ double result=0, tempResult;
+ bool ok;
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ {
+ tempResult=text(row, col).toDouble(&ok);
+ if (ok) result+=tempResult;
+ }
+
+ return result;
+}
+
+double Sheet::functionMin(const QString &param1, const QString &param2)
+{
+ int row1, col1, row2, col2, row, col;
+ if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
+
+ double min=0, tempMin;
+ bool ok, init=FALSE;
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ {
+ tempMin=text(row, col).toDouble(&ok);
+ if (ok && (!init || tempMin<min))
+ {
+ min=tempMin;
+ init=TRUE;
+ }
+ }
+
+ return min;
+}
+
+double Sheet::functionMax(const QString &param1, const QString &param2)
+{
+ int row1, col1, row2, col2, row, col;
+ if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
+
+ double max=0, tempMax;
+ bool ok, init=FALSE;
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ {
+ tempMax=text(row, col).toDouble(&ok);
+ if (ok && (!init || tempMax>max))
+ {
+ max=tempMax;
+ init=TRUE;
+ }
+ }
+
+ return max;
+}
+
+double Sheet::functionAvg(const QString &param1, const QString &param2)
+{
+ double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2);
+ return (resultCount>0 ? resultSum/resultCount : 0);
+}
+
+double Sheet::functionCount(const QString &param1, const QString &param2)
+{
+ int row1, col1, row2, col2, row, col;
+ if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
+
+ int divider=0;
+ bool ok;
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ {
+ text(row, col).toDouble(&ok);
+ if (ok) ++divider;
+ }
+
+ return divider;
+}
+
+double Sheet::calculateFunction(const QString &function, const QString &parameters)
+{
+ if (function=="+")
+ return calculateVariable(getParameter(parameters, 0))+calculateVariable(getParameter(parameters, 1));
+ if (function=="-")
+ return calculateVariable(getParameter(parameters, 0))-calculateVariable(getParameter(parameters, 1));
+ if (function=="*")
+ return calculateVariable(getParameter(parameters, 0))*calculateVariable(getParameter(parameters, 1));
+ if (function=="/")
+ return calculateVariable(getParameter(parameters, 0))/calculateVariable(getParameter(parameters, 1));
+ if (function=="SUM")
+ return functionSum(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
+ if (function=="COUNT")
+ return functionCount(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
+ if (function=="MIN")
+ return functionMin(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
+ if (function=="MAX")
+ return functionMax(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
+ if (function=="AVG")
+ return functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
+ if (function=="ABS")
+ return fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="SIN")
+ return sin(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="COS")
+ return cos(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="TAN")
+ return tan(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="ATAN")
+ return atan(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="ATAN2")
+ return atan2(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function)));
+ if (function=="ASIN")
+ return asin(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="ACOS")
+ return acos(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="EXP")
+ return exp(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="LOG")
+ return log(calculateVariable(getParameter(parameters, 0, TRUE, function)));
+ if (function=="POW")
+ return pow(calculateVariable(getParameter(parameters, 0, TRUE, function)), calculateVariable(getParameter(parameters, 1, TRUE, function)));
+ return 0;
+}
+
+int Sheet::getOperatorPriority(char oper)
+{
+ switch (oper)
+ {
+ case '+':
+ case '-':
+ return 1;
+
+ case '*':
+ case '/':
+ return 2;
+ }
+ return 0;
+}
+
+void Sheet::pushCharStack(QStack<QChar> *stackChars, const QChar &character)
+{
+ QChar *temp=new QChar(character);
+ stackChars->push(temp);
+}
+
+void Sheet::pushStringStack(QStack<QString> *stackStrings, const QString &string)
+{
+ QString *temp=new QString(string);
+ stackStrings->push(temp);
+}
+
+QChar Sheet::popCharStack(QStack<QChar> *stackChars)
+{
+ if (stackChars->isEmpty())
+ {
+ QMessageBox::critical(this, tr("Error"), tr("Syntax error!"));
+ return '0';
+ }
+
+ QChar *temp=stackChars->pop();
+ QChar temp2(*temp);
+ delete temp;
+ return temp2;
+}
+
+QString Sheet::popStringStack(QStack<QString> *stackStrings)
+{
+ if (stackStrings->isEmpty())
+ {
+ QMessageBox::critical(this, tr("Error"), tr("Syntax error!"));
+ return "0";
+ }
+
+ QString *temp=stackStrings->pop();
+ QString temp2(*temp);
+ delete temp;
+ return temp2;
+}
+
+QString Sheet::dataParserHelper(const QString &data)
+{
+ QStack<QString> stackElements;
+ QStack<QChar> stackOperators;
+ QString tempElement(""), temp2Element, firstElement, secondElement;
+ int paranCount;
+
+ for (unsigned int i=0; i<data.length(); ++i)
+ {
+ if (data[i]=='+' || data[i]=='-' || data[i]=='*' || data[i]=='/')
+ {
+ pushStringStack(&stackElements, tempElement);
+ tempElement="";
+ if (!stackOperators.isEmpty() && getOperatorPriority(*stackOperators.top())>getOperatorPriority(data[i]))
+ {
+ secondElement=popStringStack(&stackElements);
+ firstElement=popStringStack(&stackElements);
+ pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement)));
+ }
+ pushCharStack(&stackOperators, data[i]);
+ }
+ else
+ if (data[i]==',')
+ {
+ if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement);
+ while (!stackOperators.isEmpty())
+ {
+ secondElement=popStringStack(&stackElements);
+ firstElement=popStringStack(&stackElements);
+ pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement)));
+ }
+ tempElement="";
+ }
+ else
+ if (data[i]=='(')
+ {
+ paranCount=1;
+ temp2Element="";
+ for (++i; paranCount>0; ++i)
+ {
+ temp2Element+=data[i];
+ if (data[i]=='(') ++paranCount;
+ if (data[i]==')') --paranCount;
+ }
+ temp2Element=dataParserHelper(temp2Element.left(temp2Element.length()-1));
+ if (tempElement.isEmpty())
+ tempElement=temp2Element;
+ else
+ tempElement.setNum(calculateFunction(tempElement, temp2Element));
+ --i;
+ }
+ else
+ tempElement+=data[i];
+ }
+ if (!tempElement.isEmpty()) pushStringStack(&stackElements, tempElement);
+ while (!stackOperators.isEmpty())
+ {
+ secondElement=popStringStack(&stackElements);
+ firstElement=popStringStack(&stackElements);
+ pushStringStack(&stackElements, QString::number(calculateFunction(popCharStack(&stackOperators), firstElement+","+secondElement)));
+ }
+
+ if (!stackElements.isEmpty())
+ tempElement=popStringStack(&stackElements);
+ while (!stackElements.isEmpty())
+ tempElement.prepend(popStringStack(&stackElements)+",");
+ return tempElement;
+}
+
+QString Sheet::dataParser(const QString &data)
+{
+ QString strippedData(data);
+ strippedData.replace(QRegExp("\\s"), "");
+ if (strippedData.isEmpty() || strippedData[0]!='=') return data;
+ strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ","));
+
+ int i=0;
+ QString tempParameter(getParameter(strippedData, i)), result="";
+ do
+ {
+ result+=","+QString::number(calculateVariable(tempParameter));
+ tempParameter=getParameter(strippedData, ++i);
+ }
+ while (!tempParameter.isNull());
+ return result.mid(1);
+}
+
+void Sheet::setData(const QString &data)
+{
+ setText(currentRow(), currentColumn(), data);
+ slotCellChanged(currentRow(), currentColumn());
+ activateNextCell();
+}
+
+QString Sheet::getData()
+{
+ typeCellData *cellData=findCellData(currentRow(), currentColumn());
+ if (cellData)
+ return cellData->data;
+ return "";
+}
+
+void Sheet::lockClicks(bool lock=TRUE)
+{
+ clicksLocked=lock;
+}
+
+void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected)
+{
+ if (selected && row==currentRow() && col==currentColumn()) selected=FALSE;
+
+ int sheetDataCurrent=sheetData.at();
+ typeCellData *cellData=findCellData(row, col);
+ if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent);
+ if (!cellData) cellData=&defaultCellData;
+ if (selected)
+ p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight());
+ else
+ {
+ p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base());
+ p->fillRect(0, 0, cr.width(), cr.height(), cellData->background);
+ }
+
+ QTableItem *cellItem=item(row, col);
+ if (cellItem)
+ {
+ p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor);
+ p->setFont(cellData->font);
+ p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text());
+ }
+
+ int rx=cr.width()-1, ry=cr.height()-1;
+ QPen pen(p->pen());
+ p->setPen(cellData->borders.right);
+ p->drawLine(rx, 0, rx, ry);
+ p->setPen(cellData->borders.bottom);
+ p->drawLine(0, ry, rx, ry);
+ p->setPen(pen);
+}
+
+void Sheet::viewportMousePressEvent(QMouseEvent *e)
+{
+ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
+ if (clicksLocked)
+ {
+ if (selectionNo<0)
+ {
+ clearSelection();
+ QTableSelection newSelection;
+ newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
+ newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol());
+ selectionNo=addSelection(newSelection);
+ }
+ }
+ else
+ QTable::contentsMousePressEvent(&ce);
+}
+
+void Sheet::viewportMouseMoveEvent(QMouseEvent *e)
+{
+ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
+ if (clicksLocked)
+ {
+ if (selectionNo>=0)
+ {
+ QTableSelection oldSelection(selection(selectionNo));
+ oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
+ if (!(oldSelection==selection(selectionNo)))
+ {
+ removeSelection(selectionNo);
+ selectionNo=addSelection(oldSelection);
+ }
+ }
+ }
+ else
+ QTable::contentsMouseMoveEvent(&ce);
+}
+
+void Sheet::viewportMouseReleaseEvent(QMouseEvent *e)
+{
+ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
+ if (clicksLocked && selectionNo>=0)
+ {
+ QTableSelection oldSelection(selection(selectionNo));
+ oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
+ removeSelection(selectionNo);
+ selectionNo=-1;
+ if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol())
+ emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1));
+ else
+ emit cellClicked(getHeaderString(oldSelection.leftCol()+1)+QString::number(oldSelection.topRow()+1)+','+getHeaderString(oldSelection.rightCol()+1)+QString::number(oldSelection.bottomRow()+1));
+ }
+ else
+ QTable::contentsMouseReleaseEvent(&ce);
+}
+
+void Sheet::copySheetData(QList<typeCellData> *destSheetData)
+{
+ typeCellData *tempCellData, *newCellData;
+ destSheetData->clear();
+
+ for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
+ {
+ newCellData=new typeCellData;
+ *newCellData=*tempCellData;
+ destSheetData->append(newCellData);
+ }
+}
+
+void Sheet::setSheetData(QList<typeCellData> *srcSheetData)
+{
+ typeCellData *tempCellData, *newCellData;
+
+ for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
+ {
+ clearCell(tempCellData->row, tempCellData->col);
+ updateCell(tempCellData->row, tempCellData->col);
+ }
+ sheetData.clear();
+
+ for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next())
+ {
+ newCellData=new typeCellData;
+ *newCellData=*tempCellData;
+ sheetData.append(newCellData);
+ setText(newCellData->row, newCellData->col, dataParser(newCellData->data));
+ }
+ emit sheetModified();
+}
+
+void Sheet::setName(const QString &name)
+{
+ sheetName=name;
+ emit sheetModified();
+}
+
+QString Sheet::getName()
+{
+ return sheetName;
+}
+
+void Sheet::setBrush(int row, int col, const QBrush &brush)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=createCellData(row, col);
+ if (cellData)
+ {
+ cellData->background=brush;
+ emit sheetModified();
+ }
+}
+
+QBrush Sheet::getBrush(int row, int col)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=&defaultCellData;
+ return cellData->background;
+}
+
+void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=createCellData(row, col);
+ if (cellData)
+ {
+ cellData->alignment=flags;
+ emit sheetModified();
+ }
+}
+
+Qt::AlignmentFlags Sheet::getAlignment(int row, int col)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=&defaultCellData;
+ return cellData->alignment;
+}
+
+void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=createCellData(row, col);
+ if (cellData)
+ {
+ cellData->font=font;
+ cellData->fontColor=color;
+ emit sheetModified();
+ }
+}
+
+QFont Sheet::getFont(int row, int col)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=&defaultCellData;
+ return cellData->font;
+}
+
+QColor Sheet::getFontColor(int row, int col)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=&defaultCellData;
+ return cellData->fontColor;
+}
+
+void Sheet::setPen(int row, int col, int vertical, const QPen &pen)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=createCellData(row, col);
+ if (cellData)
+ {
+ if (vertical)
+ cellData->borders.right=pen;
+ else
+ cellData->borders.bottom=pen;
+ emit sheetModified();
+ }
+}
+
+QPen Sheet::getPen(int row, int col, int vertical)
+{
+ typeCellData *cellData=findCellData(row, col);
+ if (!cellData) cellData=&defaultCellData;
+ return (vertical ? cellData->borders.right : cellData->borders.bottom);
+}
+
+void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2)
+{
+ int selectionNo=currentSelection();
+ if (selectionNo>=0)
+ {
+ QTableSelection selection(selection(selectionNo));
+ *row1=selection.topRow();
+ *row2=selection.bottomRow();
+ *col1=selection.leftCol();
+ *col2=selection.rightCol();
+ }
+ else
+ {
+ *row1=*row2=currentRow();
+ *col1=*col2=currentColumn();
+ }
+}
+
+void Sheet::editClear()
+{
+ int row1, row2, col1, col2;
+ getSelection(&row1, &col1, &row2, &col2);
+
+ int row, col;
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ {
+ setText(row, col, "");
+ slotCellChanged(row, col);
+ }
+}
+
+void Sheet::editCopy()
+{
+ clipboardData.clear();
+
+ int row1, row2, col1, col2;
+ getSelection(&row1, &col1, &row2, &col2);
+
+ typeCellData *cellData, *newCellData;
+ int row, col;
+ for (row=row1; row<=row2; ++row)
+ for (col=col1; col<=col2; ++col)
+ {
+ cellData=findCellData(row, col);
+ if (cellData)
+ {
+ newCellData=new typeCellData;
+ *newCellData=*cellData;
+ newCellData->row-=row1;
+ newCellData->col-=col1;
+ clipboardData.append(newCellData);
+ }
+ }
+}
+
+void Sheet::editCut()
+{
+ editCopy();
+ editClear();
+}
+
+void Sheet::editPaste(bool onlyContents=FALSE)
+{
+ int row1=currentRow(), col1=currentColumn();
+ typeCellData *cellData, *tempCellData;
+
+ for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next())
+ {
+ cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1);
+ if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1);
+ if (cellData)
+ {
+ if (onlyContents)
+ cellData->data=tempCellData->data;
+ else
+ {
+ *cellData=*tempCellData;
+ cellData->row+=row1;
+ cellData->col+=col1;
+ }
+ setText(cellData->row, cellData->col, dataParser(cellData->data));
+ emit sheetModified();
+ }
+ }
+}
+
+void Sheet::insertRows(int no=1, bool allColumns=TRUE)
+{
+ setNumRows(numRows()+no);
+
+ typeCellData *tempCellData;
+ int row=currentRow(), col=currentColumn();
+
+ for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
+ if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
+ {
+ clearCell(tempCellData->row, tempCellData->col);
+ tempCellData->row+=no;
+ }
+ for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
+ if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
+ {
+ updateCell(tempCellData->row-no, tempCellData->col);
+ setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
+ }
+ emit sheetModified();
+}
+
+void Sheet::insertColumns(int no=1, bool allRows=TRUE)
+{
+ int noCols=numCols();
+ int newCols=noCols+no;
+ setNumCols(newCols);
+ for (int i=noCols; i<newCols; ++i)
+ horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH);
+
+ typeCellData *tempCellData;
+ int col=currentColumn(), row=currentRow();
+
+ for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
+ if (tempCellData->col>=col && (allRows || tempCellData->row==row))
+ {
+ clearCell(tempCellData->row, tempCellData->col);
+ tempCellData->col+=no;
+ }
+ for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
+ if (tempCellData->col>=col && (allRows || tempCellData->row==row))
+ {
+ updateCell(tempCellData->row, tempCellData->col-no);
+ setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
+ }
+ emit sheetModified();
+}
+
+void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE)
+{
+ typeCellData *tempCellData;
+ int row1, col1, row2, col2;
+ getSelection(&row1, &col1, &row2, &col2);
+ bool found=FALSE;
+
+ for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
+ if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2))
+ {
+ QTableItem *cellItem=item(tempCellData->row, tempCellData->col);
+ if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0))
+ {
+ if (!found)
+ {
+ found=TRUE;
+ clearSelection();
+ }
+ setCurrentCell(tempCellData->row, tempCellData->col);
+ if (replace)
+ {
+ tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr);
+ setText(tempCellData->row, tempCellData->col, dataParser(tempCellData->data));
+ }
+ if (!replace || !replaceAll) break;
+ }
+ }
+
+ if (found)
+ {
+ if (replace)
+ slotCellChanged(currentRow(), currentColumn());
+ }
+ else
+ QMessageBox::warning(this, tr("Error"), tr("Search key not found!"));
+}
+
+//
+// Static functions
+//
+
+QString Sheet::getHeaderString(int section)
+{
+ if (section<1) return "";
+ return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26);
+}
+
+int Sheet::getHeaderColumn(const QString &section)
+{
+ if (section.isEmpty()) return 0;
+ return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26;
+}
diff --git a/noncore/apps/opie-sheet/sheet.h b/noncore/apps/opie-sheet/sheet.h
new file mode 100644
index 0000000..02899a0
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sheet.h
@@ -0,0 +1,120 @@
+#ifndef SHEET_H
+#define SHEET_H
+
+#include <qtable.h>
+#include <qstack.h>
+
+typedef struct typeCellBorders
+{
+ QPen right, bottom;
+};
+
+typedef struct typeCellData
+{
+ int col, row;
+ typeCellBorders borders;
+ QBrush background;
+ Qt::AlignmentFlags alignment;
+ QColor fontColor;
+ QFont font;
+ QString data;
+};
+
+class Sheet: public QTable
+{
+ Q_OBJECT
+
+ // Variables
+ bool clicksLocked;
+ int selectionNo;
+ typeCellBorders defaultBorders;
+ typeCellData defaultCellData;
+
+ // QT objects
+ QList<typeCellData> sheetData, clipboardData;
+ QString pressedCell, releasedCell, sheetName;
+
+ // Private functions
+ int getOperatorPriority(char oper);
+ bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE);
+ bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2);
+ double calculateVariable(const QString &variable);
+ double calculateFunction(const QString &function, const QString &parameters);
+ QChar popCharStack(QStack<QChar> *stackChars);
+ QString popStringStack(QStack<QString> *stackStrings);
+ QString getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName="");
+ QString dataParser(const QString &data);
+ QString dataParserHelper(const QString &data);
+ typeCellData *createCellData(int row, int col);
+ typeCellData *findCellData(int row, int col);
+ void pushCharStack(QStack<QChar> *stackChars, const QChar &character);
+ void pushStringStack(QStack<QString> *stackStrings, const QString &string);
+
+ // Sheet/Qt parser functions
+ double functionSum(const QString &param1, const QString &param2);
+ double functionAvg(const QString &param1, const QString &param2);
+ double functionMax(const QString &param1, const QString &param2);
+ double functionMin(const QString &param1, const QString &param2);
+ double functionCount(const QString &param1, const QString &param2);
+
+ // Reimplemented QTable functions
+ void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected);
+ void viewportMousePressEvent(QMouseEvent *e);
+ void viewportMouseMoveEvent(QMouseEvent *e);
+ void viewportMouseReleaseEvent(QMouseEvent *e);
+
+ private slots:
+ void slotCellSelected(int row, int col);
+ void slotCellChanged(int row, int col);
+
+ public:
+ Sheet(int numRows, int numCols, QWidget *parent);
+ ~Sheet();
+
+ void setData(const QString &data);
+ QString getData();
+
+ void setName(const QString &data);
+ QString getName();
+
+ void setPen(int row, int col, int vertical, const QPen &pen);
+ QPen getPen(int row, int col, int vertical);
+
+ void setBrush(int row, int col, const QBrush &brush);
+ QBrush getBrush(int row, int col);
+
+ void setTextAlign(int row, int col, Qt::AlignmentFlags flags);
+ Qt::AlignmentFlags getAlignment(int row, int col);
+
+ void setTextFont(int row, int col, const QFont &font, const QColor &color);
+ QFont getFont(int row, int col);
+ QColor getFontColor(int row, int col);
+
+ void lockClicks(bool lock=TRUE);
+ void copySheetData(QList<typeCellData> *destSheetData);
+ void setSheetData(QList<typeCellData> *srcSheetData);
+ void getSelection(int *row1, int *col1, int *row2, int *col2);
+
+ void insertRows(int no=1, bool allColumns=TRUE);
+ void insertColumns(int no=1, bool allRows=TRUE);
+
+ void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE);
+
+ // Static functions
+ static int getHeaderColumn(const QString &section);
+ static QString getHeaderString(int section);
+
+ public slots:
+ void editCut();
+ void editCopy();
+ void editPaste(bool onlyContents=FALSE);
+ void editClear();
+ void swapCells(int row1, int col1, int row2, int col2);
+
+ signals:
+ void currentDataChanged(const QString &data);
+ void cellClicked(const QString &cell);
+ void sheetModified();
+};
+
+#endif
diff --git a/noncore/apps/opie-sheet/sortdlg.cpp b/noncore/apps/opie-sheet/sortdlg.cpp
new file mode 100644
index 0000000..f46562e
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sortdlg.cpp
@@ -0,0 +1,178 @@
+#include <qlabel.h>
+#include <qradiobutton.h>
+#include <qmessagebox.h>
+#include "sortdlg.h"
+
+SortDialog::SortDialog(QWidget *parent=0)
+ :QDialog(parent, 0, TRUE)
+{
+ // Main widget
+ tabs=new QTabWidget(this);
+ widgetSort=new QWidget(tabs);
+ widgetOptions=new QWidget(tabs);
+ tabs->addTab(widgetSort, tr("&Sort"));
+ tabs->addTab(widgetOptions, tr("&Options"));
+
+ // Sort tab
+ comboFieldA=createFieldCombo(tr("&Sort by"), 10);
+ groupOrderA=createOrderButtons(10);
+ comboFieldB=createFieldCombo(tr("&Then by"), 90);
+ groupOrderB=createOrderButtons(90);
+ comboFieldC=createFieldCombo(tr("Then &by"), 170);
+ groupOrderC=createOrderButtons(170);
+
+ // Options tab
+ checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions);
+ checkCase->setGeometry(10, 10, 215, 20);
+ checkCase->setChecked(TRUE);
+
+ groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions);
+ groupDirection->setGeometry(10, 40, 215, 70);
+ QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection);
+ radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection);
+ groupDirection->setButton(0);
+ connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int)));
+
+ // Main widget
+ box=new QVBoxLayout(this);
+ box->addWidget(tabs);
+
+ setCaption(tr("Sort"));
+}
+
+SortDialog::~SortDialog()
+{
+}
+
+QComboBox *SortDialog::createFieldCombo(const QString &caption, int y)
+{
+ QLabel *label=new QLabel(caption, widgetSort);
+ label->setGeometry(10, y+5, 215, 20);
+ QComboBox *combo=new QComboBox(FALSE, widgetSort);
+ combo->setGeometry(10, y+35, 105, 20);
+ label->setBuddy(combo);
+ return combo;
+}
+
+QVButtonGroup *SortDialog::createOrderButtons(int y)
+{
+ QVButtonGroup *group=new QVButtonGroup(widgetSort);
+ group->setGeometry(125, y, 100, 60);
+ QRadioButton *radio=new QRadioButton(tr("&Ascending"), group);
+ radio=new QRadioButton(tr("&Descending"), group);
+ group->setButton(0);
+ return group;
+}
+
+void SortDialog::directionChanged(int id)
+{
+ direction=id;
+ fillFieldCombo(comboFieldA);
+ fillFieldCombo(comboFieldB);
+ fillFieldCombo(comboFieldC);
+}
+
+void SortDialog::fillFieldCombo(QComboBox *combo)
+{
+ combo->clear();
+ if (direction)
+ for (int row=row1; row<=row2; ++row)
+ combo->insertItem("Row "+QString::number(row+1));
+ else
+ for (int col=col1; col<=col2; ++col)
+ combo->insertItem("Column "+Sheet::getHeaderString(col+1));
+}
+
+int SortDialog::exec(Sheet *s)
+{
+ sheet=s;
+ sheet->getSelection(&row1, &col1, &row2, &col2);
+
+ direction=0;
+ fillFieldCombo(comboFieldA);
+ fillFieldCombo(comboFieldB);
+ fillFieldCombo(comboFieldC);
+
+ if (row1==row2 && col1==col2)
+ {
+ QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!"));
+ return QDialog::Rejected;
+ }
+ if (QDialog::exec()==QDialog::Accepted)
+ {
+ QString field1S=comboFieldA->currentText(), field2S=comboFieldA->currentText(), field3S=comboFieldA->currentText();
+ field1S=field1S.mid(field1S.find(' ')+1);
+ field2S=field2S.mid(field2S.find(' ')+1);
+ field3S=field3S.mid(field3S.find(' ')+1);
+ int field1, field2, field3;
+ if (direction)
+ {
+ field1=field1S.toInt()-1;
+ field2=field2S.toInt()-1;
+ field3=field3S.toInt()-1;
+ int i, j;
+ for (i=col2; i>=col1; --i)
+ for (j=col1+1; j<=i; ++j)
+ {
+ bool swap=FALSE;
+ int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
+ if (compareResult>0) swap=TRUE;
+ else if (compareResult==0)
+ {
+ compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked());
+ if (compareResult>0) swap=TRUE;
+ else if (compareResult==0)
+ {
+ compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked());
+ if (compareResult>0) swap=TRUE;
+ }
+ }
+ if (swap)
+ for (int row=row1; row<=row2; ++row)
+ s->swapCells(row, j-1, row, j);
+ }
+ }
+ else
+ {
+ field1=Sheet::getHeaderColumn(field1S)-1;
+ field2=Sheet::getHeaderColumn(field2S)-1;
+ field3=Sheet::getHeaderColumn(field3S)-1;
+ int i, j;
+ for (i=row2; i>=row1; --i)
+ for (j=row1+1; j<=i; ++j)
+ {
+ bool swap=FALSE;
+ int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
+ if (compareResult>0) swap=TRUE;
+ else if (compareResult==0)
+ {
+ compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked());
+ if (compareResult>0) swap=TRUE;
+ else if (compareResult==0)
+ {
+ compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked());
+ if (compareResult>0) swap=TRUE;
+ }
+ }
+ if (swap)
+ for (int col=col1; col<=col2; ++col)
+ s->swapCells(j-1, col, j, col);
+ }
+ }
+ return QDialog::Accepted;
+ }
+ return QDialog::Rejected;
+}
+
+int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE)
+{
+ int result=0;
+ if (item1)
+ {
+ if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper()));
+ else result=-1;
+ }
+ else
+ if (item2) result=1;
+ return (descending ? -result : result);
+}
diff --git a/noncore/apps/opie-sheet/sortdlg.h b/noncore/apps/opie-sheet/sortdlg.h
new file mode 100644
index 0000000..2c99f02
--- a/dev/null
+++ b/noncore/apps/opie-sheet/sortdlg.h
@@ -0,0 +1,45 @@
+#ifndef SORTDLG_H
+#define SORTDLG_H
+
+#include <qdialog.h>
+#include <qtabwidget.h>
+#include <qlayout.h>
+#include <qcombobox.h>
+#include <qcheckbox.h>
+#include <qpushbutton.h>
+#include <qvbuttongroup.h>
+#include "sheet.h"
+
+class SortDialog: public QDialog
+{
+ Q_OBJECT
+
+ // QT objects
+ QBoxLayout *box;
+ QTabWidget *tabs;
+ QWidget *widgetSort, *widgetOptions;
+ QVButtonGroup *groupOrderA, *groupOrderB, *groupOrderC, *groupDirection;
+ QCheckBox *checkCase;
+ QComboBox *comboFieldA, *comboFieldB, *comboFieldC;
+
+ // Other objects & variables
+ int row1, col1, row2, col2, direction;
+ Sheet *sheet;
+
+ // Private functions
+ QVButtonGroup *createOrderButtons(int y);
+ QComboBox *createFieldCombo(const QString &caption, int y);
+ void fillFieldCombo(QComboBox *combo);
+ int compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE);
+
+ private slots:
+ void directionChanged(int id);
+
+ public:
+ SortDialog(QWidget *parent=0);
+ ~SortDialog();
+
+ int exec(Sheet *s);
+};
+
+#endif
diff --git a/noncore/apps/opie-sheet/textdlg.cpp b/noncore/apps/opie-sheet/textdlg.cpp
new file mode 100644
index 0000000..8245fe4
--- a/dev/null
+++ b/noncore/apps/opie-sheet/textdlg.cpp
@@ -0,0 +1,32 @@
+#include "textdlg.h"
+
+TextDialog::TextDialog(QWidget *parent=0)
+ :QDialog(parent, 0, TRUE)
+{
+ edit=new QLineEdit(this);
+ edit->setGeometry(90, 10, 100, 25);
+
+ label=new QLabel(this);
+ label->setGeometry(10, 10, 70, 25);
+ label->setBuddy(edit);
+
+ resize(200, 45);
+}
+
+TextDialog::~TextDialog()
+{
+}
+
+int TextDialog::exec(const QString &caption, const QString &text, const QString &value="")
+{
+ setCaption(caption);
+ label->setText(text);
+ edit->setText(value);
+
+ return QDialog::exec();
+}
+
+QString TextDialog::getValue()
+{
+ return edit->text();
+}
diff --git a/noncore/apps/opie-sheet/textdlg.h b/noncore/apps/opie-sheet/textdlg.h
new file mode 100644
index 0000000..f948228
--- a/dev/null
+++ b/noncore/apps/opie-sheet/textdlg.h
@@ -0,0 +1,24 @@
+#ifndef TEXTDLG_H
+#define TEXTDLG_H
+
+#include <qdialog.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+
+class TextDialog: public QDialog
+{
+ Q_OBJECT
+
+ // QT objects
+ QLabel *label;
+ QLineEdit *edit;
+
+ public:
+ TextDialog(QWidget *parent=0);
+ ~TextDialog();
+
+ int exec(const QString &caption, const QString &text, const QString &value="");
+ QString getValue();
+};
+
+#endif
diff --git a/pics/opie-sheet/sheetqt.png b/pics/opie-sheet/sheetqt.png
new file mode 100644
index 0000000..9b4be29
--- a/dev/null
+++ b/pics/opie-sheet/sheetqt.png
Binary files differ