예제 #1
0
  /*!
   * \author Anders Fernström
   * \date 2006-04-21
   *
   * \brief Set the output style
   */
  void InputCell::setOutputStyle()
  {
    // Set the correct style for the QTextEdit output_
    output_->selectAll();

    Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" );
    CellStyle style = sheet->getStyle( "Output" );

    if( style.name() != "null" )
    {
      output_->setAlignment( (Qt::AlignmentFlag)style.alignment() );
      output_->mergeCurrentCharFormat( (*style.textCharFormat()) );
      output_->document()->rootFrame()->setFrameFormat( (*style.textFrameFormat()) );
    }
    else
    {
      // 2006-01-30 AF, add message box
      QString msg = "No Output style defened, please define a Output style in stylesheet.xml";
      QMessageBox::warning( 0, "Warning", msg, "OK" );
    }

    QTextCursor cursor = output_->textCursor();
    cursor.clearSelection();
    output_->setTextCursor( cursor );
  }
예제 #2
0
 /*
  * \author Anders Fernström
  * \date 2005-10-26
  *
  * \brief Returns the CellStyle that correspondence with the
  * style name. The function retuns a CellStyle with the name
  * null if no CellStyle is found with the style name.
  *
  * \param style The name of the style you looking for
  * \return A CellStyle
  */
 CellStyle Stylesheet::getStyle( const QString &style )
 {
   if( styles_.contains( style ))
     return styles_.value( style );
   else
   {
     CellStyle tmp;
     tmp.setName( "null" );
     return tmp;
   }
 }
예제 #3
0
파일: cell.cpp 프로젝트: adrpo/OMNotebook
  /*!
   * \author Anders Fernström
   * \date 2005-10-28
   *
   * \brief Set cell style
   *
   * \param stylename The style name of the style that is to be applyed to the cell
   */
  void Cell::setStyle(const QString &stylename)
  {

    Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" );
    CellStyle style = sheet->getStyle( stylename );

    if( style.name() != "null" )
      setStyle( style );
    else
    {
      cout << "Can't set style, style name: " << stylename.toStdString() << " is not valid" << endl;
    }
  }
예제 #4
0
  /*
   * \author Anders Fernström
   * \date 2005-10-26
   *
   * \brief loop through the DOM tree and creates CellStyle after
   * specified styles.
   */
  void Stylesheet::initializeStyle()
  {
    QDomElement root = doc_->documentElement();
    QDomNode n = root.firstChild();

    // loop through the DOM tree
    while( !n.isNull() )
    {
      QDomElement e = n.toElement();
      if( !e.isNull() )
      {
        if( e.tagName() == "style" )
        {
          CellStyle style;
          style.setName( e.attribute( "name" ));

          // get visibility
          if( e.attribute( "visible", "true" ).indexOf( "false", 0, Qt::CaseInsensitive ) < 0 )
                        style.setVisible( true );
          else
            style.setVisible( false );

          QDomNode node = e.firstChild();
          traverseStyleSettings(node, &style);

          styles_.insert( style.name(), style );

          // 2006-03-02 AF, only add styles that are visible
          if( style.visible() )
            styleNames_.push_back( style.name() );
        }
      }
      n = n.nextSibling();
    }
  }
예제 #5
0
  /*!
   * \author Anders Fernström
   * \date 2005-10-27
   * \date 2006-03-02 (update)
   *
   * \brief Set cell style
   *
   * IMPORTANT: User shouldn't be able to change style on inputcells
   * so this function always use "Input" as style.
   *
   * 2005-11-03 AF, updated so the text is selected when the style
   * is changed, after the text is unselected.
   * 2006-03-02 AF, set chapter style
   *
   * \param style The cell style that is to be applyed to the cell
   */
  void InputCell::setStyle(CellStyle style)
  {
    if( style.name() == "Input" )
    {
      Cell::setStyle( style );

      // select all the text
      input_->selectAll();

      // set the new style settings
      input_->setAlignment( (Qt::AlignmentFlag)style_.alignment() );
      input_->mergeCurrentCharFormat( (*style_.textCharFormat()) );
      input_->document()->rootFrame()->setFrameFormat( (*style_.textFrameFormat()) );

      // unselect the text
      QTextCursor cursor(  input_->textCursor() );
      cursor.clearSelection();
      input_->setTextCursor( cursor );

      // 2006-03-02 AF, set chapter counter style
      chaptercounter_->selectAll();
      chaptercounter_->mergeCurrentCharFormat( (*style_.textCharFormat()) );

      QTextFrameFormat format = chaptercounter_->document()->rootFrame()->frameFormat();
      format.setMargin( style_.textFrameFormat()->margin() +
      style_.textFrameFormat()->border() +
      style_.textFrameFormat()->padding()  );
      chaptercounter_->document()->rootFrame()->setFrameFormat( format );

      chaptercounter_->setAlignment( (Qt::AlignmentFlag)Qt::AlignRight );

      cursor = chaptercounter_->textCursor();
      cursor.clearSelection();
      chaptercounter_->setTextCursor( cursor );
    }
    else
    {
      setStyle( "Input" );
    }
  }
예제 #6
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;
    }
예제 #7
0
   /*!
    * \class AddCellCommand
  * \author Ingemar Axelsson and Anders Fernström
    *
    * \brief Command for adding a new cell to the cellstructure.
    */
  void AddCellCommand::execute()
  {
    try
    {
      CellCursor *cursor = document()->getCursor();

      Factory *fac = document()->cellFactory();

      // 2005-10-28 AF, changed style from QString to CellStyle
      CellStyle style;

      if(cursor->currentCell()->hasChilds())
        style = *cursor->currentCell()->child()->style();
      else
        style = *cursor->currentCell()->style();


      //This does not work.
      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);
      }

      // 2005-11-21 AF, Added check if the current cell is a
      // inputcell, set style to 'text' insted.
      // 2006-02-03 AF, added check if the current cell is a
      // groupcell
      if( style.name() == "input" || style.name() == "Input" || style.name() == "ModelicaInput" ||
        style.name() == "cellgroup" )
        cursor->addBefore(fac->createCell( "Text" ));
      else
        cursor->addBefore(fac->createCell(style.name()));

      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);
      }

      //2006-01-18 AF, set docuement changed
      document()->setChanged( true );
    }
    catch(exception &e)
    {
      // 2006-01-30 AF, add exception
      string str = string("AddCellCommand(), Exception: \n") + e.what();
      throw runtime_error( str.c_str() );
    }
  }
예제 #8
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);
    }
  }