/*! * \class TextCursorCutText * \author Anders Fernström * \date 2006-02-07 * * \brief Command for cuting text */ void TextCursorCutText::execute() { Cell *cell = document()->getCursor()->currentCell(); if( cell ) { if( typeid(InputCell) == typeid(*cell) ) { InputCell *inputcell = dynamic_cast<InputCell*>(cell); if( inputcell->textEditOutput()->hasFocus() && inputcell->isEvaluated() ) { inputcell->textEditOutput()->copy(); } else inputcell->textEdit()->cut(); } else if( typeid(GraphCell) == typeid(*cell) ) { GraphCell *graphcell = dynamic_cast<GraphCell*>(cell); if( graphcell->textEditOutput()->hasFocus() && graphcell->isEvaluated() ) { graphcell->textEditOutput()->copy(); } else graphcell->textEdit()->cut(); } else if( typeid(LatexCell) == typeid(*cell) ) { LatexCell *latexcell = dynamic_cast<LatexCell*>(cell); if( latexcell->textEditOutput()->hasFocus() && latexcell->isEvaluated() ) { latexcell->textEditOutput()->cut(); } else latexcell->textEdit()->cut(); } else { QTextEdit *editor = cell->textEdit(); if( editor ) { editor->cut(); } } } }
/*! * \author Anders Fernström * \date 2006-02-03 * * \brief set focus on output part in inputcell */ void CellDocument::mouseClickedOnCellOutput(Cell *clickedCell) { clearSelection(); //Remove focus from old cell. if(getCursor()->currentCell()->isClosed()) { getCursor()->currentCell()->child()->setReadOnly(true); getCursor()->currentCell()->child()->setFocus(false); } else { getCursor()->currentCell()->setReadOnly(true); } //Add focus to the cell clicked on. if(clickedCell->parentCell()->isClosed()) { getCursor()->moveAfter(clickedCell->parentCell()); } else { getCursor()->moveAfter(clickedCell); //Results in bus error why? } if( typeid(InputCell) == typeid(*clickedCell)) { InputCell *inputcell = dynamic_cast<InputCell*>(clickedCell); inputcell->setReadOnly(false); inputcell->setFocusOutput(true); } else if(typeid(GraphCell) == typeid(*clickedCell)) { GraphCell *graphcell = dynamic_cast<GraphCell*>(clickedCell); graphcell->setReadOnly(false); graphcell->setFocusOutput(true); } else if(typeid(LatexCell) == typeid(*clickedCell)) { LatexCell *latexcell = dynamic_cast<LatexCell*>(clickedCell); //latexcell->setReadOnly(false); latexcell->setFocusOutput(true); latexcell->output_->setReadOnly(false); /* QString text=latexcell->textOutput(); if(!text.isEmpty()) { latexcell->output_->hide(); latexcell->input_->show(); latexcell->hideButton->show(); } */ } else { clickedCell->setReadOnly(false); clickedCell->setFocus(true); } emit cursorChanged(); }
void XMLParser::traverseGraphCell( Cell *parent, QDomElement &element ) { // Get the style value QString style = element.attribute( XML_STYLE, "Graph" ); // create inputcell with the saved style Cell *graphcell = factory_->createCell( style, parent ); graphcell->setStyle(QString("Input")); // graphcell->setStyle(style); // go through all children in input cell/element QString text; QDomNode node = element.firstChild(); while( !node.isNull() ) { QDomElement e = node.toElement(); if( !e.isNull() ) { if( e.tagName() == XML_INPUTPART ) { text = e.text(); GraphCell *gCell = dynamic_cast<GraphCell*>(graphcell); gCell->setText(text); } else if( e.tagName() == XML_OUTPUTPART ) { GraphCell *iCell = dynamic_cast<GraphCell*>(graphcell); iCell->setTextOutput( e.text() ); } else if( e.tagName() == XML_IMAGE ) { addImage( graphcell, e ); } else if( e.tagName() == XML_RULE ) { graphcell->addRule( new Rule( e.attribute( XML_NAME, "" ), e.text() )); } else if( e.tagName() == XML_GRAPHCELL_DATA ) {} else if( e.tagName() == XML_GRAPHCELL_GRAPH ) {} else if( e.tagName() == XML_GRAPHCELL_SHAPE ) {} else if( e.tagName() == XML_GRAPHCELL_OMCPLOT ) { GraphCell *gCell = dynamic_cast<GraphCell*>(graphcell); // read attributes and set the plotwindow values gCell->mpPlotWindow->setTitle(e.attribute(XML_GRAPHCELL_TITLE)); gCell->mpPlotWindow->setGrid(e.attribute(XML_GRAPHCELL_GRID)); int type = e.attribute(XML_GRAPHCELL_PLOTTYPE).toInt(); if (type == 1) gCell->mpPlotWindow->setPlotType(PlotWindow::PLOTALL); else if (type == 2) gCell->mpPlotWindow->setPlotType(PlotWindow::PLOTPARAMETRIC); else gCell->mpPlotWindow->setPlotType(PlotWindow::PLOT); gCell->mpPlotWindow->setLogX((e.attribute(XML_GRAPHCELL_LOGX) == XML_TRUE) ? true : false); gCell->mpPlotWindow->setLogY((e.attribute(XML_GRAPHCELL_LOGY) == XML_TRUE) ? true : false); gCell->mpPlotWindow->setXRange(e.attribute(XML_GRAPHCELL_XRANGE_MIN).toDouble(), e.attribute(XML_GRAPHCELL_XRANGE_MAX).toDouble()); gCell->mpPlotWindow->setYRange(e.attribute(XML_GRAPHCELL_YRANGE_MIN).toDouble(), e.attribute(XML_GRAPHCELL_YRANGE_MAX).toDouble()); gCell->mpPlotWindow->setXLabel(e.attribute(XML_GRAPHCELL_XLABEL)); gCell->mpPlotWindow->setYLabel(e.attribute(XML_GRAPHCELL_YLABEL)); gCell->mpPlotWindow->setCurveWidth(e.attribute(XML_GRAPHCELL_CURVE_WIDTH).toDouble()); gCell->mpPlotWindow->setCurveStyle(e.attribute(XML_GRAPHCELL_CURVE_STYLE).toDouble()); gCell->mpPlotWindow->setLegendPosition(e.attribute(XML_GRAPHCELL_LEGENDPOSITION)); gCell->mpPlotWindow->setFooter(e.attribute(XML_GRAPHCELL_FOOTER)); gCell->mpPlotWindow->setAutoScale((e.attribute(XML_GRAPHCELL_AUTOSCALE) == XML_TRUE) ? true : false); // read curves for (QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement curveElement = n.toElement(); if (curveElement.tagName() == XML_GRAPHCELL_CURVE) { PlotCurve *pPlotCurve = new PlotCurve("", curveElement.attribute(XML_GRAPHCELL_TITLE), "", gCell->mpPlotWindow->getPlot()); // read the curve data if (curveElement.hasAttribute(XML_GRAPHCELL_XDATA) && curveElement.hasAttribute(XML_GRAPHCELL_YDATA)) { QByteArray xByteArray = QByteArray::fromBase64(curveElement.attribute(XML_GRAPHCELL_XDATA).toStdString().c_str()); QDataStream xInStream(xByteArray); while (!xInStream.atEnd()) { double d; xInStream >> d; pPlotCurve->addXAxisValue(d); } QByteArray yByteArray = QByteArray::fromBase64(curveElement.attribute(XML_GRAPHCELL_YDATA).toStdString().c_str()); QDataStream yInStream(yByteArray); while (!yInStream.atEnd()) { double d; yInStream >> d; pPlotCurve->addYAxisValue(d); } // set the curve data pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(), pPlotCurve->getSize()); } gCell->mpPlotWindow->getPlot()->addPlotCurve(pPlotCurve); pPlotCurve->attach(gCell->mpPlotWindow->getPlot()); // read the curve attributes pPlotCurve->setCustomColor(true); QPen customPen = pPlotCurve->pen(); customPen.setColor(curveElement.attribute(XML_GRAPHCELL_COLOR).toUInt()); customPen.setWidthF(gCell->mpPlotWindow->getCurveWidth()); customPen.setStyle(pPlotCurve->getPenStyle(gCell->mpPlotWindow->getCurveStyle())); pPlotCurve->setPen(customPen); if (gCell->mpPlotWindow->getCurveStyle() > 5) pPlotCurve->setStyle(pPlotCurve->getCurveStyle(gCell->mpPlotWindow->getCurveStyle())); if (gCell->mpPlotWindow->getPlot()->legend()) { if (curveElement.attribute(XML_GRAPHCELL_VISIBLE) == XML_FALSE) { pPlotCurve->setVisible(false); } } } } gCell->mpPlotWindow->show(); gCell->mpPlotWindow->fitInView(); gCell->mpPlotWindow->getPlot()->getPlotZoomer()->setZoomBase(false); }
// 2006-01-16 AF, move this code to a seperated function // 2006-09-04 AF, redid entire function, so groupcells are created, have there // children added and THEN add to the documnet void PasteCellsCommand::pasteCell( Cell *cell, CellGroup *groupcell ) { // get cursor, factory and cell style CellCursor *cursor = document()->getCursor(); Factory *factory = document()->cellFactory(); CellStyle style = *cell->style(); // set focus and readonly stuff (from old implementation, IA) if(cursor->currentCell()->isClosed()) { if(cursor->currentCell()->hasChilds()) { cursor->currentCell()->child()->setReadOnly(true); cursor->currentCell()->child()->setFocus(false); } } else { cursor->currentCell()->setReadOnly(true); cursor->currentCell()->setFocus(false); } // create the new cell, if there exists a groupcell add the new cell to // that groupcell. Cell* newCell = factory->createCell( style.name() ); // if( groupcell ) // groupcell->addChild( newCell ); // set content of cell // ************************************************************************* // COPY - EVERY CELL TYPE // ---------------------- newCell->setCellTag( cell->cellTag() ); // rules rules_t rules = cell->rules(); rules_t::iterator current = rules.begin(); while( current != rules.end() ) { newCell->addRule( (*current) ); ++current; } // COPY - SPECIFIC FOR CELL TYPE // ----------------------------- if( typeid(CellGroup) == typeid( *newCell )) { CellGroup *newCellGroup = dynamic_cast<CellGroup *>( newCell ); newCellGroup->setClosed( cell->isClosed() ); if( cell->hasChilds() ) { Cell* child = cell->child(); while( child ) { pasteCell( child, newCellGroup ); child = child->next(); } } } else if( typeid(InputCell) == typeid( *newCell )) { InputCell *newInputCell = dynamic_cast<InputCell *>( newCell ); InputCell *oldInputCell = dynamic_cast<InputCell *>( cell ); newInputCell->setStyle( style ); newInputCell->setText( oldInputCell->text() ); if( oldInputCell->isEvaluated() ) { newInputCell->setEvaluated( true ); newInputCell->setTextOutput( oldInputCell->textOutput() ); } else newInputCell->setEvaluated( false ); newInputCell->setClosed( oldInputCell->isClosed() ); } else if( typeid(GraphCell) == typeid( *newCell )) { GraphCell *newGraphCell = dynamic_cast<GraphCell *>( newCell ); GraphCell *oldGraphCell = dynamic_cast<GraphCell *>( cell ); newGraphCell->setStyle( style ); newGraphCell->setText( oldGraphCell->text() ); if( oldGraphCell->isEvaluated() ) { newGraphCell->setEvaluated( true ); newGraphCell->setTextOutput( oldGraphCell->textOutput() ); } else newGraphCell->setEvaluated( false ); newGraphCell->setClosed( oldGraphCell->isClosed() ); } else if( typeid(TextCell) == typeid( *newCell )) { newCell->setStyle( style ); newCell->setTextHtml( cell->textHtml() ); } else { // Error throw runtime_error("pasteCell(): Unknown celltype."); } // ************************************************************************* // Add cell to document if( !groupcell ) cursor->addBefore( newCell ); else //if there exists a groupcell add the new cell to that groupcell. groupcell->addChild( newCell ); // set focus and readonly stuff (from old implementation, IA) if(cursor->currentCell()->isClosed()) { if(cursor->currentCell()->hasChilds()) { cursor->currentCell()->child()->setReadOnly(false); cursor->currentCell()->child()->setFocus(true); } } else { cursor->currentCell()->setReadOnly(false); cursor->currentCell()->setFocus(true); } }