/*! What happens if a Groupcell is removed? */ void DeleteCurrentCellCommand::execute() { try { CellCursor *c = document()->getCursor(); vector<Cell *> cells = document()->getSelection(); if(cells.empty()) { return; //Empty pasteboard. //application()->clearPasteboard(); //application()->addToPasteboard(c->currentCell()); //c->removeCurrentCell(); } else { document()->clearSelection(); //Notice application()->clearPasteboard(); vector<Cell *>::iterator i = cells.begin(); for(;i != cells.end();++i) { c->moveAfter((*i)); //1. Copy cell to pasteboard. application()->addToPasteboard(c->currentCell()); //2. Delete Cell. c->removeCurrentCell(); } } //2006-01-18 AF, set docuement changed document()->setChanged( true ); } catch(exception &e) { // 2006-01-30 AF, add message box string str = string("DeleteCurrentCellsCommand(), Exception: \n") + e.what(); throw runtime_error( str.c_str() ); } }
void MakeGroupCellCommand::execute() { try { Factory *fac = document()->cellFactory(); CellCursor *cursor = document()->getCursor(); Cell *prev = cursor->currentCell(); cursor->currentCell()->parentCell()->removeChild(prev); Cell *group = fac->createCell("cellgroup", cursor->parentCell()); group->addChild(prev); cursor->addBefore(group); cursor->moveToLastChild(group); //2006-01-18 AF, set docuement changed document()->setChanged( true ); } catch(exception &e) { // 2006-01-30 AF, add exception string str = string("MakeGroupCellCommand(), Exception: \n") + e.what(); throw runtime_error( str.c_str() ); } }
/*! * \author Anders Fernström * \date 2005-11-29 * \date 2006-03-03 (update) * * \brief Update the scrollarea so the correct area is displayed * * 2005-12-08 AF, remade function becuase the earlier version hade * some large bugs. Didn't calculate cells position correct, becuase * qt:s layout system reset position to 0 in every groupcell and * layout are probobly not set correctly. * 2006-03-03 AF, ignore move if the cursor it at the end of the * document */ void CellDocument::updateScrollArea() { if( scroll_->verticalScrollBar()->isVisible() ) { CellCursor *cursor = getCursor(); if( cursor ) { // ignore, if selected cell is a groupcell if( typeid( *cursor->currentCell() ) != typeid( CellGroup ) ) { // calculate the position of the cursor, by adding the height // of all the cells before the cellcursor, using a visitor CursorPosVisitor visitor; runVisitor( visitor ); int pos = visitor.position(); // size of scrollarea int scrollTop = scroll_->widget()->visibleRegion().boundingRect().top(); int scrollBottom = scroll_->widget()->visibleRegion().boundingRect().bottom(); // cell height int height = cursor->currentCell()->height(); #ifndef QT_NO_DEBUG_OUTPUT cout << "*********************************************" << endl; cout << "SCROLL TOP: " << scrollTop << endl; cout << "SCROLL BOTTOM: " << scrollBottom << endl; cout << "CELL CURSOR: " << pos << endl; cout << "CELL HEIGHT: " << height << endl; #endif // TO BIG if( height > (scrollBottom-scrollTop) ) { qDebug( "TO BIG" ); // cell so big that it span over entire viewarea return; } // END OF DOCUMENT else if( pos > (scroll_->widget()->height() - 2 ) && scrollBottom > (scroll_->widget()->height() - 2 ) ) { #ifndef QT_NO_DEBUG_OUTPUT cout << "END OF DOCUMENT, widget height(" << scroll_->widget()->height() << ")" << endl; #endif // 2006-03-03 AF, ignore if cursor at end of document return; } // UP else if( (pos - height) < scrollTop ) { // cursor have moved above the viewarea of the // scrollbar, move up the scrollbar // remove cell height + a little extra pos -= (height + 10); if( pos < 0 ) pos = 0; // set new scrollvalue cout << "UP: old(" << scroll_->verticalScrollBar()->value() << "), new(" << pos << ")" << endl; scroll_->verticalScrollBar()->setValue( pos ); } // DOWN else if( pos > (scrollBottom - 10) ) { // cursor have moved below the viewarea of the // scrollbar, move down the scrollbar // add cell height + a little extra to scrollbar //pos = height + 20 + scroll_->verticalScrollBar()->value(); // add differens between cell cursor position och scroll bottom // to the scroll value pos = scroll_->verticalScrollBar()->value() + (pos - (scrollBottom - 10)); if( pos >= scroll_->verticalScrollBar()->maximum() ) { #ifndef QT_NO_DEBUG_OUTPUT cout << "more then max!" << endl; #endif scroll_->verticalScrollBar()->triggerAction( QAbstractSlider::SliderToMaximum ); //pos = scroll_->verticalScrollBar()->maximum(); // a little extra to the max value of the scrollbar //scroll_->verticalScrollBar()->setMaximum( 5 + // scroll_->verticalScrollBar()->maximum() ); } else { // set new scrollvalue #ifndef QT_NO_DEBUG_OUTPUT cout << "DOWN: old(" << scroll_->verticalScrollBar()->value() << "), new(" << pos << ")" << endl; #endif scroll_->verticalScrollBar()->setValue( pos ); } } } } } }
/*! * \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() ); } }
// 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); } }
/*! * \class CreateNewCellCommand * \author Ingemar Axelsson * * \brief Command for creating a new cell. */ void CreateNewCellCommand::execute() { try { CellCursor *cursor = document()->getCursor(); Factory *fac = document()->cellFactory(); //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); } cursor->addBefore(fac->createCell(style_)); 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("CreateNewCommand(), Exception: \n") + e.what(); throw runtime_error( str.c_str() ); } }