-rw-r--r-- | noncore/apps/opie-sheet/cellformat.cpp | 47 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/finddlg.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/numberdlg.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sortdlg.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/textdlg.cpp | 5 |
7 files changed, 55 insertions, 25 deletions
diff --git a/noncore/apps/opie-sheet/cellformat.cpp b/noncore/apps/opie-sheet/cellformat.cpp index 597502c..342ebe9 100644 --- a/noncore/apps/opie-sheet/cellformat.cpp +++ b/noncore/apps/opie-sheet/cellformat.cpp @@ -1,110 +1,135 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include "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}; +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) +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) :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))); + 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())); + 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))); @@ -247,111 +272,113 @@ void CellFormat::backgroundClicked(int index) 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 *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; + default: 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) { @@ -450,97 +477,97 @@ int CellFormat::exec(Sheet *s) 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) +BorderEditor::BorderEditor(QWidget *parent) :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); } diff --git a/noncore/apps/opie-sheet/finddlg.cpp b/noncore/apps/opie-sheet/finddlg.cpp index d1237ca..e4c6ec8 100644 --- a/noncore/apps/opie-sheet/finddlg.cpp +++ b/noncore/apps/opie-sheet/finddlg.cpp @@ -1,67 +1,67 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include <qlabel.h> #include <qradiobutton.h> #include "finddlg.h" -FindDialog::FindDialog(QWidget *parent=0) +FindDialog::FindDialog(QWidget *parent) :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() { diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index 09ee68b..2f07bae 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp @@ -121,97 +121,97 @@ void MainWindow::documentOpen(const DocLnk &lnkDoc) 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) +int MainWindow::saveCurrentFile(bool ask) { 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->isValid()) { TextDialog dialogText(this); if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; currentDoc->setName(dialogText.getValue()); currentDoc->setFile(QString::null); currentDoc->setLinkFile(QString::null); } documentSave(currentDoc); return QMessageBox::Yes; } void MainWindow::selectorFileNew(const DocLnk &lnkDoc) { selectorHide(); if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; if (currentDoc) delete currentDoc; currentDoc = new DocLnk(lnkDoc); listSheets.clear(); comboSheets->clear(); typeSheet *newSheet=createNewSheet(); newSheet->data.setAutoDelete(TRUE); sheet->setName(newSheet->name); sheet->setSheetData(&newSheet->data); for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) createNewSheet(); documentModified=FALSE; } void MainWindow::closeEvent(QCloseEvent *e) { if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); else e->accept(); } void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) { diff --git a/noncore/apps/opie-sheet/numberdlg.cpp b/noncore/apps/opie-sheet/numberdlg.cpp index e8de639..90fbaa2 100644 --- a/noncore/apps/opie-sheet/numberdlg.cpp +++ b/noncore/apps/opie-sheet/numberdlg.cpp @@ -1,49 +1,50 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include "numberdlg.h" -NumberDialog::NumberDialog(QWidget *parent=0) +NumberDialog::NumberDialog(QWidget *parent) :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) +int NumberDialog::exec(const QString &caption, const QString &text, + int value, int min, int max, int step) { 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/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index 1d7ec6f..2279191 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp @@ -62,135 +62,135 @@ void Sheet::slotCellSelected(int row, int 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 ¶meters, int paramNo, bool giveError=FALSE, const QString funcName="") +QString Sheet::getParameter(const QString ¶meters, int paramNo, bool giveError, 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) +bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError) { 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 ¶m1, const QString ¶m2) { 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 ¶m1, const QString ¶m2) { 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) @@ -407,97 +407,97 @@ QString Sheet::dataParserHelper(const QString &data) 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) +void Sheet::lockClicks(bool lock) { 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()); @@ -691,170 +691,170 @@ void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) *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) +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(cellData->data)); emit sheetModified(); } } } -void Sheet::insertRows(int no=1, bool allColumns=TRUE) +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(tempCellData->data)); } emit sheetModified(); } -void Sheet::insertColumns(int no=1, bool allRows=TRUE) +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(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) +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(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) { diff --git a/noncore/apps/opie-sheet/sortdlg.cpp b/noncore/apps/opie-sheet/sortdlg.cpp index c60be0d..c2cdec8 100644 --- a/noncore/apps/opie-sheet/sortdlg.cpp +++ b/noncore/apps/opie-sheet/sortdlg.cpp @@ -1,68 +1,68 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include <qlabel.h> #include <qradiobutton.h> #include <qmessagebox.h> #include "sortdlg.h" -SortDialog::SortDialog(QWidget *parent=0) +SortDialog::SortDialog(QWidget *parent) :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; @@ -133,60 +133,61 @@ int SortDialog::exec(Sheet *s) if (compareResult>0) swap=TRUE; else if (compareResult==0) { compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderB->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), groupOrderC->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), groupOrderB->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), groupOrderC->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 SortDialog::compareItems(QTableItem *item1, QTableItem *item2, + int descending, bool caseSensitive) { 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/textdlg.cpp b/noncore/apps/opie-sheet/textdlg.cpp index 0810eb2..34cec29 100644 --- a/noncore/apps/opie-sheet/textdlg.cpp +++ b/noncore/apps/opie-sheet/textdlg.cpp @@ -1,46 +1,47 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* * Opie Sheet (formerly Sheet/Qt) * by Serdar Ozler <sozler@sitebest.com> */ #include "textdlg.h" -TextDialog::TextDialog(QWidget *parent=0) +TextDialog::TextDialog(QWidget *parent) :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="") +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(); } |