-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index d4419af..88847da 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp @@ -1900,389 +1900,389 @@ 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(findCellName(oldSelection.topRow(), oldSelection.leftCol())); else emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol())); } else QTable::contentsMouseReleaseEvent(&ce); } QString Sheet::findCellName(int row, int col) { return (getHeaderString(col+1)+QString::number(row+1)); } 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(findCellName(newCellData->row, newCellData->col), 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(); + QTableSelection select(selection(selectionNo)); + *row1=select.topRow(); + *row2=select.bottomRow(); + *col1=select.leftCol(); + *col2=select.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) { 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(findCellName(cellData->row, cellData->col), cellData->data)); emit sheetModified(); } } } void Sheet::insertRows(int no, bool allColumns) { 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(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); } emit sheetModified(); } void Sheet::insertColumns(int no, bool allRows) { 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(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); } emit sheetModified(); } void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll) { 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(findCellName(tempCellData->row, tempCellData->col), 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 §ion) { if (section.isEmpty()) return 0; return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; } //Expression Parser Class Definition QChar Expression::chunk0(void) { if(chunk.length()>0) return(chunk[0]); else return('\0'); }; Expression::Expression(QString expr1)// constructor { Body=expr1; SYMBOL="+-*/%^=()<>&|!,"; MATHSYMBOL="+-*/%^=<>&|!,"; |