Example #1
0
  /*!
  * \author Anders Fernstrom
  * \date 2005-11-30
  * \date 2006-01-17 (update)
  *
  * \brief Parse an input cell in the xml file.
  *
  * 2005-12-01 AF, Implement function
  * 2006-01-17 AF, Added support for closed value in the inputcell
  *
  * \param parent The parent cell to the input cell
  * \param element The current QDomElement being parsed
  */
  void XMLParser::traverseInputCell( Cell *parent, QDomElement &element )
  {
    // Get the style value
    QString style = element.attribute( XML_STYLE, "Input" );

    // create inputcell with the saved style
    Cell *inputcell = factory_->createCell( style, parent );

    // 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();
          inputcell->setText( text );
        }
        else if( e.tagName() == XML_OUTPUTPART )
        {
          InputCell *iCell = dynamic_cast<InputCell*>(inputcell);
          iCell->setTextOutput( e.text() );
        }
        else if( e.tagName() == XML_RULE )
        {
          inputcell->addRule(
            new Rule( e.attribute( XML_NAME, "" ), e.text() ));
        }
        else if( e.tagName() == XML_IMAGE )
        {
          addImage( inputcell, e );
        }
        else
        {
          string msg = "Unknown tagname " + e.tagName().toStdString() + ", in input cell";
          throw runtime_error( msg.c_str() );
        }
      }

      node = node.nextSibling();
    }

    // set style, before set text, so all rules are applied to the style
    inputcell->setStyle( *inputcell->style() );
    inputcell->setText( text );

    // 2006-01-17 AF, check if the inputcell is open or closed
    QString closed = element.attribute( XML_CLOSED, XML_FALSE );
    if( closed == XML_TRUE )
      inputcell->setClosed( true );
    else if( closed == XML_FALSE )
      inputcell->setClosed( false );
    else
      throw runtime_error( "Unknown closed value in inputcell" );

    parent->addChild( inputcell );
  }
Example #2
0
  /*!
     * \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();
        }
      }
    }
  }
Example #3
0
  /*!
  * \author Ingemar Axelsson and Anders Fernström
  *
  *
  * \todo Remove document dependency from Cellstructure. It is only
  * used to point to a commandcenter (in this case the current
  * document) and for the click event to get the current
  * cursor. This can be done in some better way. Maybe by sending a
  * signal to the document instead.(Ingemar Axelsson)
  */
  Cell *CellFactory::createCell(const QString &style, Cell *parent)
  {
    if(style == "input" || style == "Input" || style == "ModelicaInput")
    {
      InputCell *text = new InputCell(doc_, parent);

      try
      {
        Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" );
        CellStyle cstyle = sheet->getStyle( "Input" );

        if( cstyle.name() != "null" )
          text->setStyle( cstyle );
        else
          throw runtime_error("No Input style defened, the inputcell may not work correctly, please define a Input style in stylesheet.xml");
      }
      catch( exception e )
      {
        QMessageBox::warning( 0, "Warning", e.what(), "OK" );
      }

      try
      {
        text->setDelegate(OmcInteractiveEnvironment::getInstance());
      }
      catch( exception e )
      {}

      QObject::connect(text, SIGNAL(cellselected(Cell *,Qt::KeyboardModifiers)),
        doc_, SLOT(selectedACell(Cell*,Qt::KeyboardModifiers)));
      QObject::connect(text, SIGNAL(clicked(Cell *)),
        doc_, SLOT(mouseClickedOnCell(Cell*)));
      QObject::connect(text, SIGNAL(clickedOutput(Cell *)),
        doc_, SLOT(mouseClickedOnCellOutput(Cell*)));

      // 2005-11-29 AF
      QObject::connect( text, SIGNAL( heightChanged() ),
        doc_, SLOT( updateScrollArea() ));

      // 2006-01-17 AF
      QObject::connect( text, SIGNAL( textChanged(bool) ),
        doc_, SLOT( setChanged(bool) ));

      // 2006-04-27 AF
      QObject::connect( text, SIGNAL( forwardAction(int) ),
        doc_, SIGNAL( forwardAction(int) ));

      //      CellDocument* d = dynamic_cast<CellDocument*>(doc_);
      //      DocumentView* d2 = d->observers_[0];
      //      NotebookWindow *d3 = dynamic_cast<NotebookWindow*>(d2);
      QObject::connect(text->input_, SIGNAL(copyAvailable(bool)), doc_, SIGNAL(copyAvailable(bool)));
      QObject::connect(text->input_, SIGNAL(undoAvailable(bool)), doc_, SIGNAL(undoAvailable(bool)));
      QObject::connect(text->input_, SIGNAL(redoAvailable(bool)), doc_, SIGNAL(redoAvailable(bool)));
      QObject::connect(text->output_, SIGNAL(copyAvailable(bool)), doc_, SIGNAL(copyAvailable(bool)));

      //QObject::connect(doc_, SIGNAL(evaluate()), text->input_, SIGNAL(eval()));

      /*
      QObject::connect(text->input_, SIGNAL(copyAvailable(bool)), d3->copyAction, SLOT(setEnabled(bool)));
      QObject::connect(text->input_, SIGNAL(copyAvailable(bool)), d3->cutAction, SLOT(setEnabled(bool)));
      QObject::connect(text->input_, SIGNAL(undoAvailable(bool)), d3->undoAction, SLOT(setEnabled(bool)));
      QObject::connect(text->input_, SIGNAL(redoAvailable(bool)), d3->redoAction, SLOT(setEnabled(bool)));

      QObject::connect(text->output_, SIGNAL(copyAvailable(bool)), d3->copyAction, SLOT(setEnabled(bool)));
      */
      return text;
    }
Example #4
0
/*!
 * \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();
}
Example #5
0
  // 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);
    }
  }